Java Code Examples for android.widget.listview#CHOICE_MODE_MULTIPLE_MODAL

The following examples show how to use android.widget.listview#CHOICE_MODE_MULTIPLE_MODAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbsHListView.java    From Klyph with MIT License 5 votes vote down vote up
boolean performLongPress( final View child, final int longPressPosition, final long longPressId ) {

		// CHOICE_MODE_MULTIPLE_MODAL takes over long press.
		if ( android.os.Build.VERSION.SDK_INT >= 11 ) {
			if ( mChoiceMode == ListView.CHOICE_MODE_MULTIPLE_MODAL ) {
				if ( mChoiceActionMode == null &&
						( mChoiceActionMode = startActionMode( (MultiChoiceModeWrapper)mMultiChoiceModeCallback ) ) != null ) {
					setItemChecked( longPressPosition, true );
					performHapticFeedback( HapticFeedbackConstants.LONG_PRESS );
				}
				return true;
			}
		}

		boolean handled = false;
		if ( mOnItemLongClickListener != null ) {
			handled = mOnItemLongClickListener.onItemLongClick( AbsHListView.this, child,
					longPressPosition, longPressId );
		}
		if ( !handled ) {
			mContextMenuInfo = createContextMenuInfo( child, longPressPosition, longPressId );
			handled = super.showContextMenuForChild( AbsHListView.this );
		}
		if ( handled ) {
			performHapticFeedback( HapticFeedbackConstants.LONG_PRESS );
		}
		return handled;
	}
 
Example 2
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
private void updateDisplayState() {
	final State state = getDisplayState(this);

       mDefaultColor = SettingsActivity.getPrimaryColor(getActivity());
       int accentColor = SettingsActivity.getAccentColor();
       if (mLastMode == state.derivedMode &&  mLastSortOrder == state.derivedSortOrder
               && mLastShowSize == state.showSize
               && mLastShowFolderSize == state.showFolderSize
			&& mLastShowThumbnail == state.showThumbnail
			&& mLastShowHiddenFiles == state.showHiddenFiles
               && (mLastShowColor != 0 && mLastShowColor == mDefaultColor)
               && (mLastShowAccentColor != 0 && mLastShowAccentColor == accentColor))
		return;
       boolean refreshData = mLastShowHiddenFiles != state.showHiddenFiles;
	mLastMode = state.derivedMode;
       mLastSortOrder = state.derivedSortOrder;
	mLastShowSize = state.showSize;
	mLastShowFolderSize = state.showFolderSize;
	mLastShowThumbnail = state.showThumbnail;
	mLastShowHiddenFiles = state.showHiddenFiles;

       mLastShowColor = mDefaultColor;
       mProgressBar.setColor(mLastShowColor);
	mListView.setVisibility(state.derivedMode == MODE_LIST ? View.VISIBLE : View.GONE);
	mGridView.setVisibility(state.derivedMode == MODE_GRID ? View.VISIBLE : View.GONE);

	final int choiceMode;
	if (state.allowMultiple) {
		choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL;
	} else {
		choiceMode = ListView.CHOICE_MODE_NONE;
	}

	final int thumbSize;
	if (state.derivedMode == MODE_GRID) {
		thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width);
		mListView.setAdapter(null);
		mListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
		mGridView.setAdapter(mAdapter);
		mGridView.setColumnWidth(thumbSize);
		mGridView.setNumColumns(GridView.AUTO_FIT);
		mGridView.setChoiceMode(choiceMode);
		mCurrentView = mGridView;
	} else if (state.derivedMode == MODE_LIST) {
		thumbSize = getResources().getDimensionPixelSize(R.dimen.icon_size);
		mGridView.setAdapter(null);
		mGridView.setChoiceMode(ListView.CHOICE_MODE_NONE);
		mListView.setAdapter(mAdapter);
		mListView.setChoiceMode(choiceMode);
		mCurrentView = mListView;
	} else {
		throw new IllegalStateException("Unknown state " + state.derivedMode);
	}

       ((BaseActivity) getActivity()).upadateActionItems(mCurrentView);
	mThumbSize = new Point(thumbSize, thumbSize);

       if(refreshData) {
           onUserSortOrderChanged();
       }
}
 
Example 3
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
private void updateDisplayState() {
	final State state = getDisplayState(this);

       mDefaultColor = SettingsActivity.getPrimaryColor(getActivity());
       int accentColor = SettingsActivity.getAccentColor();
       if (mLastMode == state.derivedMode &&  mLastSortOrder == state.derivedSortOrder
               && mLastShowSize == state.showSize
               && mLastShowFolderSize == state.showFolderSize
			&& mLastShowThumbnail == state.showThumbnail
			&& mLastShowHiddenFiles == state.showHiddenFiles
               && (mLastShowColor != 0 && mLastShowColor == mDefaultColor)
               && (mLastShowAccentColor != 0 && mLastShowAccentColor == accentColor))
		return;
       boolean refreshData = mLastShowHiddenFiles != state.showHiddenFiles;
	mLastMode = state.derivedMode;
       mLastSortOrder = state.derivedSortOrder;
	mLastShowSize = state.showSize;
	mLastShowFolderSize = state.showFolderSize;
	mLastShowThumbnail = state.showThumbnail;
	mLastShowHiddenFiles = state.showHiddenFiles;

       mLastShowColor = mDefaultColor;
       mProgressBar.setColor(mLastShowColor);
	mListView.setVisibility(state.derivedMode == MODE_LIST ? View.VISIBLE : View.GONE);
	mGridView.setVisibility(state.derivedMode == MODE_GRID ? View.VISIBLE : View.GONE);

	final int choiceMode;
	if (state.allowMultiple) {
		choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL;
	} else {
		choiceMode = ListView.CHOICE_MODE_NONE;
	}

	final int thumbSize;
	if (state.derivedMode == MODE_GRID) {
		thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width);
		mListView.setAdapter(null);
		mListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
		mGridView.setAdapter(mAdapter);
		mGridView.setColumnWidth(thumbSize);
		mGridView.setNumColumns(GridView.AUTO_FIT);
		mGridView.setChoiceMode(choiceMode);
		mCurrentView = mGridView;
	} else if (state.derivedMode == MODE_LIST) {
		thumbSize = getResources().getDimensionPixelSize(R.dimen.icon_size);
		mGridView.setAdapter(null);
		mGridView.setChoiceMode(ListView.CHOICE_MODE_NONE);
		mListView.setAdapter(mAdapter);
		mListView.setChoiceMode(choiceMode);
		mCurrentView = mListView;
	} else {
		throw new IllegalStateException("Unknown state " + state.derivedMode);
	}

       ((BaseActivity) getActivity()).upadateActionItems(mCurrentView);
	mThumbSize = new Point(thumbSize, thumbSize);

       if(refreshData) {
           onUserSortOrderChanged();
       }
}
 
Example 4
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
private void updateDisplayState() {
	final State state = getDisplayState(this);

       mDefaultColor = SettingsActivity.getPrimaryColor(getActivity());
       int accentColor = SettingsActivity.getAccentColor();
       if (mLastMode == state.derivedMode &&  mLastSortOrder == state.derivedSortOrder
               && mLastShowSize == state.showSize
               && mLastShowFolderSize == state.showFolderSize
			&& mLastShowThumbnail == state.showThumbnail
			&& mLastShowHiddenFiles == state.showHiddenFiles
               && (mLastShowColor != 0 && mLastShowColor == mDefaultColor)
               && (mLastShowAccentColor != 0 && mLastShowAccentColor == accentColor))
		return;
       boolean refreshData = mLastShowHiddenFiles != state.showHiddenFiles;
	mLastMode = state.derivedMode;
       mLastSortOrder = state.derivedSortOrder;
	mLastShowSize = state.showSize;
	mLastShowFolderSize = state.showFolderSize;
	mLastShowThumbnail = state.showThumbnail;
	mLastShowHiddenFiles = state.showHiddenFiles;

       mLastShowColor = mDefaultColor;
       mProgressBar.setColor(mLastShowColor);
	mListView.setVisibility(state.derivedMode == MODE_LIST ? View.VISIBLE : View.GONE);
	mGridView.setVisibility(state.derivedMode == MODE_GRID ? View.VISIBLE : View.GONE);

	final int choiceMode;
	if (state.allowMultiple) {
		choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL;
	} else {
		choiceMode = ListView.CHOICE_MODE_NONE;
	}

	final int thumbSize;
	if (state.derivedMode == MODE_GRID) {
		thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width);
		mListView.setAdapter(null);
		mListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
		mGridView.setAdapter(mAdapter);
		mGridView.setColumnWidth(thumbSize);
		mGridView.setNumColumns(GridView.AUTO_FIT);
		mGridView.setChoiceMode(choiceMode);
		mCurrentView = mGridView;
	} else if (state.derivedMode == MODE_LIST) {
		thumbSize = getResources().getDimensionPixelSize(R.dimen.icon_size);
		mGridView.setAdapter(null);
		mGridView.setChoiceMode(ListView.CHOICE_MODE_NONE);
		mListView.setAdapter(mAdapter);
		mListView.setChoiceMode(choiceMode);
		mCurrentView = mListView;
	} else {
		throw new IllegalStateException("Unknown state " + state.derivedMode);
	}

       ((BaseActivity) getActivity()).upadateActionItems(mCurrentView);
	mThumbSize = new Point(thumbSize, thumbSize);

       if(refreshData) {
           onUserSortOrderChanged();
       }
}
 
Example 5
Source File: AbsHListView.java    From Klyph with MIT License 4 votes vote down vote up
/**
 * Sets the checked state of the specified position. The is only valid if the choice mode has been set to
 * {@link #CHOICE_MODE_SINGLE} or {@link #CHOICE_MODE_MULTIPLE}.
 * 
 * @param position
 *           The item whose checked state is to be checked
 * @param value
 *           The new checked state for the item
 */
public void setItemChecked( int position, boolean value ) {
	if ( mChoiceMode == ListView.CHOICE_MODE_NONE ) {
		return;
	}

	// Start selection mode if needed. We don't need to if we're unchecking something.
	if ( android.os.Build.VERSION.SDK_INT >= 11 ) {
		if ( value && mChoiceMode == ListView.CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode == null ) {
			if ( mMultiChoiceModeCallback == null ||
					!((MultiChoiceModeWrapper)mMultiChoiceModeCallback).hasWrappedCallback() ) {
				throw new IllegalStateException( "AbsListView: attempted to start selection mode " +
						"for CHOICE_MODE_MULTIPLE_MODAL but no choice mode callback was " +
						"supplied. Call setMultiChoiceModeListener to set a callback." );
			}
			mChoiceActionMode = startActionMode( (MultiChoiceModeWrapper)mMultiChoiceModeCallback );
		}
	}

	if ( mChoiceMode == ListView.CHOICE_MODE_MULTIPLE
			|| ( android.os.Build.VERSION.SDK_INT >= 11 && mChoiceMode == ListView.CHOICE_MODE_MULTIPLE_MODAL ) ) {
		boolean oldValue = mCheckStates.get( position );
		mCheckStates.put( position, value );
		if ( mCheckedIdStates != null && mAdapter.hasStableIds() ) {
			if ( value ) {
				mCheckedIdStates.put( mAdapter.getItemId( position ), position );
			} else {
				mCheckedIdStates.delete( mAdapter.getItemId( position ) );
			}
		}
		if ( oldValue != value ) {
			if ( value ) {
				mCheckedItemCount++;
			} else {
				mCheckedItemCount--;
			}
		}
		if ( mChoiceActionMode != null ) {
			final long id = mAdapter.getItemId( position );
			((MultiChoiceModeWrapper)mMultiChoiceModeCallback).onItemCheckedStateChanged( (ActionMode) mChoiceActionMode, position, id, value );
		}
	} else {
		boolean updateIds = mCheckedIdStates != null && mAdapter.hasStableIds();
		// Clear all values if we're checking something, or unchecking the currently
		// selected item
		if ( value || isItemChecked( position ) ) {
			mCheckStates.clear();
			if ( updateIds ) {
				mCheckedIdStates.clear();
			}
		}
		// this may end up selecting the value we just cleared but this way
		// we ensure length of mCheckStates is 1, a fact getCheckedItemPosition relies on
		if ( value ) {
			mCheckStates.put( position, true );
			if ( updateIds ) {
				mCheckedIdStates.put( mAdapter.getItemId( position ), position );
			}
			mCheckedItemCount = 1;
		} else if ( mCheckStates.size() == 0 || !mCheckStates.valueAt( 0 ) ) {
			mCheckedItemCount = 0;
		}
	}

	// Do not generate a data change while we are in the layout phase
	if ( !mInLayout && !mBlockLayoutRequests ) {
		mDataChanged = true;
		rememberSyncState();
		requestLayout();
	}
}
 
Example 6
Source File: AbsHListView.java    From Klyph with MIT License 4 votes vote down vote up
@Override
public void onRestoreInstanceState( Parcelable state ) {
	SavedState ss = (SavedState) state;

	super.onRestoreInstanceState( ss.getSuperState() );
	mDataChanged = true;

	mSyncWidth = ss.width;

	if ( ss.selectedId >= 0 ) {
		mNeedSync = true;
		mPendingSync = ss;
		mSyncColId = ss.selectedId;
		mSyncPosition = ss.position;
		mSpecificLeft = ss.viewLeft;
		mSyncMode = SYNC_SELECTED_POSITION;
	} else if ( ss.firstId >= 0 ) {
		setSelectedPositionInt( INVALID_POSITION );
		// Do this before setting mNeedSync since setNextSelectedPosition looks at mNeedSync
		setNextSelectedPositionInt( INVALID_POSITION );
		mSelectorPosition = INVALID_POSITION;
		mNeedSync = true;
		mPendingSync = ss;
		mSyncColId = ss.firstId;
		mSyncPosition = ss.position;
		mSpecificLeft = ss.viewLeft;
		mSyncMode = SYNC_FIRST_POSITION;
	}

	if ( ss.checkState != null ) {
		mCheckStates = ss.checkState;
	}

	if ( ss.checkIdState != null ) {
		mCheckedIdStates = ss.checkIdState;
	}

	mCheckedItemCount = ss.checkedItemCount;

	if ( android.os.Build.VERSION.SDK_INT >= 11 ) {
		if ( ss.inActionMode && mChoiceMode == ListView.CHOICE_MODE_MULTIPLE_MODAL && mMultiChoiceModeCallback != null ) {
			mChoiceActionMode = startActionMode( (MultiChoiceModeWrapper)mMultiChoiceModeCallback );
		}
	}

	requestLayout();
}