List of usage examples for android.widget AbsListView CHOICE_MODE_MULTIPLE_MODAL
int CHOICE_MODE_MULTIPLE_MODAL
To view the source code for android.widget AbsListView CHOICE_MODE_MULTIPLE_MODAL.
Click Source Link
From source file:com.myapps.xyzreader.ui.ItemChoiceManager.java
public void onClick(RecyclerView.ViewHolder vh) { if (mChoiceMode == AbsListView.CHOICE_MODE_NONE) return;/* ww w . j a v a 2 s. c om*/ int checkedItemCount = mCheckStates.size(); int position = vh.getAdapterPosition(); if (position == RecyclerView.NO_POSITION) { Log.d(LOG_TAG, "Unable to Set Item State"); return; } switch (mChoiceMode) { case AbsListView.CHOICE_MODE_NONE: break; case AbsListView.CHOICE_MODE_SINGLE: { boolean checked = mCheckStates.get(position, false); if (!checked) { mCheckStates.clear(); mCheckStates.put(position, true); mCheckedIdStates.clear(); mCheckedIdStates.put(mAdapter.getItemId(position), position); mAdapter.notifyDataSetChanged(); // select & unselect } // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE: { boolean checked = mCheckStates.get(position, false); mCheckStates.put(position, !checked); // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: { throw new RuntimeException("Multiple Modal not implemented in ItemChoiceManager."); } } }
From source file:com.example.radioplayer.adapter.ItemChoiceManager.java
public void onClick(RecyclerView.ViewHolder vh) { if (mChoiceMode == AbsListView.CHOICE_MODE_NONE) { return;// w ww . ja v a 2 s. c o m } int checkedItemCount = mCheckStates.size(); int position = vh.getAdapterPosition(); if (position == RecyclerView.NO_POSITION) { Log.d(LOG_TAG, "Unable to Set Item State"); return; } switch (mChoiceMode) { case AbsListView.CHOICE_MODE_NONE: break; case AbsListView.CHOICE_MODE_SINGLE: { boolean checked = mCheckStates.get(position, false); if (!checked) { for (int i = 0; i < checkedItemCount; i++) { mAdapter.notifyItemChanged(mCheckStates.keyAt(i)); } mCheckStates.clear(); mCheckStates.put(position, true); mCheckedIdStates.clear(); mCheckedIdStates.put(mAdapter.getItemId(position), position); } // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE: { boolean checked = mCheckStates.get(position, false); mCheckStates.put(position, !checked); // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: { throw new RuntimeException("Multiple Modal not implemented in ItemChoiceManager."); } } }
From source file:com.hangulo.xyzreader2.ui.ItemChoiceManager.java
public void onClick(RecyclerView.ViewHolder vh) { if (mChoiceMode == AbsListView.CHOICE_MODE_NONE) return;/*from w ww.j a v a 2s. c om*/ int checkedItemCount = mCheckStates.size(); int position = vh.getAdapterPosition(); if (position == RecyclerView.NO_POSITION) { Log.d(LOG_TAG, "Unable to Set Item State"); return; } switch (mChoiceMode) { case AbsListView.CHOICE_MODE_NONE: break; case AbsListView.CHOICE_MODE_SINGLE: { boolean checked = mCheckStates.get(position, false); if (!checked) { // for (int i = 0; i < checkedItemCount; i++) { // mAdapter.notifyItemChanged(mCheckStates.keyAt(i)); // this original code is occured some UI delay problem, so I've changed to notifyDataSetChanged(). // } mCheckStates.clear(); mCheckStates.put(position, true); mCheckedIdStates.clear(); mCheckedIdStates.put(mAdapter.getItemId(position), position); mAdapter.notifyDataSetChanged(); // select & unselect } // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE: { boolean checked = mCheckStates.get(position, false); mCheckStates.put(position, !checked); // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); break; } case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: { throw new RuntimeException("Multiple Modal not implemented in ItemChoiceManager."); } } }
From source file:com.harlie.android.sunshine.app.ItemChoiceManager.java
@SuppressWarnings("unchecked") public void onClick(RecyclerView.ViewHolder vh) { if (mChoiceMode == AbsListView.CHOICE_MODE_NONE) return;/*from ww w . j a va 2 s .com*/ int checkedItemCount = mCheckStates.size(); int position = vh.getAdapterPosition(); if (position == RecyclerView.NO_POSITION) { Log.d(LOG_TAG, "Unable to Set Item State"); return; } switch (mChoiceMode) { case AbsListView.CHOICE_MODE_NONE: break; case AbsListView.CHOICE_MODE_SINGLE: { boolean checked = mCheckStates.get(position, false); if (!checked) { for (int i = 0; i < checkedItemCount; i++) { mAdapter.notifyItemChanged(mCheckStates.keyAt(i)); } mCheckStates.clear(); mCheckStates.put(position, true); mCheckedIdStates.clear(); mCheckedIdStates.put(mAdapter.getItemId(position), position); } // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); // warning: Unchecked call to 'onBindViewHolder(VH, int)' as a member of raw type 'android.support.v7.widget.RecyclerView.Adapter' break; } case AbsListView.CHOICE_MODE_MULTIPLE: { boolean checked = mCheckStates.get(position, false); mCheckStates.put(position, !checked); // We directly call onBindViewHolder here because notifying that an item has // changed on an item that has the focus causes it to lose focus, which makes // keyboard navigation a bit annoying mAdapter.onBindViewHolder(vh, position); // warning: Unchecked call to 'onBindViewHolder(VH, int)' as a member of raw type 'android.support.v7.widget.RecyclerView.Adapter' break; } case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: { throw new RuntimeException("Multiple Modal not implemented in ItemChoiceManager."); } } }
From source file:com.theelix.libreexplorer.FileManagerActivity.java
/** This function reads the current Folder, and populates the ListView with the content of that folder */ public void refresh() { ((ViewGroup) findViewById(R.id.list_layout)).removeView(itemView); if (FileManager.getCurrentDirectory().getName().equals("")) { mActionBar.setTitle(getString(R.string.app_name)); } else {/*w ww. j a v a 2 s . co m*/ mActionBar.setTitle(getString(R.string.app_name) + ": " + FileManager.getCurrentDirectory().getName()); } boolean useGrid = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_layout_grid", false); int itemLayout; if (useGrid) { itemView = new GridView(this); itemLayout = R.layout.file_grid_element; ((GridView) itemView).setNumColumns(4); ((GridView) itemView).setHorizontalSpacing(0); } else { itemView = new ListView(this); itemLayout = R.layout.file_list_element; } boolean hideHiddenFiles = !PreferenceManager.getDefaultSharedPreferences(this) .getBoolean("pref_show_hidden_files", false); try { ArrayList<File> fileList = new ArrayList<>( Arrays.asList(FileManager.getCurrentDirectory().listFiles())); for (int i = 0; i < fileList.size(); i++) { if (fileList.get(i).isHidden() && hideHiddenFiles) { fileList.remove(fileList.get(i)); } } ArrayAdapter<File> filelistAdapter = new FileListArrayAdapter(this, itemLayout, fileList); filelistAdapter.sort(new FileComparator()); itemView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); ActionModeCallback callback = new ActionModeCallback(); callback.setListView(itemView); callback.setContext(this); itemView.setMultiChoiceModeListener(callback); mDrawerLayout.closeDrawers(); itemView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { File file = (File) adapter.getItemAtPosition(position); if (file.isDirectory()) { FileManager.setCurrentDirectory(file); } else { FileManager.openFile(file); } } }); itemView.setAdapter(filelistAdapter); itemView.setTextFilterEnabled(true); ((ViewGroup) findViewById(R.id.list_layout)).addView(itemView, new AbsListView.LayoutParams( AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.MATCH_PARENT)); } catch (NullPointerException e) { Toast.makeText(this, "Unable to Access File", Toast.LENGTH_LONG).show(); } //Check if SDCard is mounted, if so shows External Storage on the Sidebar if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Environment.getExternalStorageState(new File(System.getenv("SECONDARY_STORAGE"))) .equals(Environment.MEDIA_MOUNTED)) { findViewById(R.id.menu_external_storage).setVisibility(View.VISIBLE); } else { findViewById(R.id.menu_external_storage).setVisibility(View.GONE); } } else { //Dirty method, but I think is the only option for devices before L if (new File(System.getenv("SECONDARY_STORAGE")).canRead()) { findViewById(R.id.menu_external_storage).setVisibility(View.VISIBLE); } else { findViewById(R.id.menu_external_storage).setVisibility(View.GONE); } } }
From source file:com.gigathinking.simpleapplock.AppListFragment.java
@Override public void onStart() { super.onStart(); if (!noAds) { final AdView adView = (AdView) getActivity().findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().addTestDevice("YOUR DEVICE 1") .addTestDevice("YOUR DEVICE 2").build(); adView.loadAd(adRequest);/*from w w w.j a v a 2s. c o m*/ adView.setAdListener(new AdListener() { @Override public void onAdLoaded() { LinearLayout ll = (LinearLayout) getActivity().findViewById(R.id.id_ll_app_list); ll.findViewById(R.id.adView).setVisibility(View.VISIBLE); } }); } else { (getActivity().findViewById(R.id.adView)).setVisibility(View.GONE); } interstitial = new InterstitialAd(getActivity()); interstitial.setAdUnitId("YOUR AD UNIT ID"); interstitial.setAdListener(new AdListener() { @Override public void onAdClosed() { super.onAdClosed(); mPrefs.edit().putInt("ad_count", (mPrefs.getInt("ad_count", 0) + 1)).commit(); } }); // Create ad request. AdRequest adRequestInterestial = new AdRequest.Builder().addTestDevice("YOUR DEVICE 1") .addTestDevice("YOUR DEVICE 2").build(); // Begin loading your interstitial. if (!noAds) { interstitial.loadAd(adRequestInterestial); } if (!mList.isEmpty()) { showInitialStart(false); } else { showInitialStart(true); } AbsListView listView = (AbsListView) getActivity().findViewById(R.id.lv_app_list); listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(this); mAdapter = new AppListAdapter(getActivity(), R.layout.layout_applist_item, mList); listView.setAdapter(mAdapter); listView.setOnItemClickListener(this); receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (isAdded()) { startActivityForResult(new Intent(context, AppPicker.class), 22); } } }; LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, new IntentFilter(AppLockApplication.LAUNCH_PICKER)); //Limit 5 interstitial ads per day. int today = Integer.parseInt(DateFormat.format("d", Calendar.getInstance()).toString()); if (mPrefs.getInt("today", 0) != today) { mPrefs.edit().putInt("ad_count", 0).commit(); mPrefs.edit().putInt("today", today).commit(); } }
From source file:com.lovejoy777sarootool.rootool.fragments.BrowserFragment.java
private void initList(LayoutInflater inflater, View rootView) { final BrowserActivity context = (BrowserActivity) getActivity(); mListAdapter = new BrowserListAdapter(context, inflater); mListView = (ListView) rootView.findViewById(android.R.id.list); mListView.setEmptyView(rootView.findViewById(android.R.id.empty)); mListView.setAdapter(mListAdapter);//from w ww. ja va 2 s. c om mListView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final File file = new File((mListView.getAdapter().getItem(position)).toString()); if (file.isDirectory()) { navigateTo(file.getAbsolutePath()); // go to the top of the ListView mListView.setSelection(0); } else { listItemAction(file); } } }); FloatingActionButton mFab = (FloatingActionButton) rootView.findViewById(R.id.fabbutton); mFab.setColor(getResources().getColor(R.color.fab_background)); mFab.setDrawable(getResources().getDrawable(R.drawable.holo_light_ic_action_new)); mFab.listenTo(mListView); mFab.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { showMenu(view); } }); }
From source file:com.shafiq.mytwittle.view.UserFeedFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); mContentHandle = TwitterManager.get().getContentHandle(getContentHandleBase(), getScreenName(), getLaneIdentifier(), getApp().getCurrentAccountKey()); if (mContentHandle == null) { // Occurs when coming back after the app was sleeping. Force refresh // of the adapter in this instance to ensure Fragments are created // correctly. showToast("No Content Handle found, forcing refresh"); Intent intent = new Intent("" + SystemEvent.FORCE_FRAGMENT_PAGER_ADAPTER_REFRESH); LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent); return null; }/*from w w w.ja va 2 s . c om*/ // // // View resultView = inflater.inflate(R.layout.lane, null); configureLaneWidth(resultView); mViewSwitcher = (ViewSwitcher) resultView.findViewById(R.id.profileSwitcher); mUserFeedListAdapter = new UserFeedListAdapter(inflater); mMultipleUserSelectionCallback = new MultipleUserSelectionCallback(); mUserFeedListView = (PullToRefreshListView) resultView.findViewById(R.id.pull_to_refresh_listview); mUserFeedListView.getRefreshableView().setOnItemClickListener(mOnUserFeedItemClickListener); mUserFeedListView.getRefreshableView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); mUserFeedListView.getRefreshableView().setMultiChoiceModeListener(mMultipleUserSelectionCallback); mUserFeedListView.getRefreshableView().setOnScrollListener(mUserFeedOnScrollListener); mUserFeedListView.getRefreshableView().setAdapter(mUserFeedListAdapter); mUserFeedListView.setOnRefreshListener(mUserFeedOnRefreshListener); mUserFeedListView.setOnLastItemVisibleListener(mUserFeedOnLastItemVisibleListener); // // // TwitterUsers cachedUsers = null; if (mContentHandle.getUsersType() == UsersType.RETWEETED_BY) { cachedUsers = TwitterManager.get().getUsers(mContentHandle, TwitterPaging.createGetMostRecent(20)); } else { cachedUsers = TwitterManager.get().getUsers(mContentHandle, null); } if (cachedUsers != null) { setUserFeed(cachedUsers); } else { setUserFeed(null); } if (getUserFeed() == null || getUserFeed().getUserCount() == 0) { updateViewVisibility(false); setInitialDownloadState(InitialDownloadState.WAITING); } else { setInitialDownloadState(InitialDownloadState.DOWNLOADED); updateViewVisibility(true); } return resultView; }
From source file:com.dnielfe.manager.Browser.java
private void init(Intent intent) { fm = getFragmentManager();//ww w.jav a 2 s . c o m mDataSource = new ArrayList<String>(); mObserverCache = FileObserverCache.getInstance(); mNavigation = new ActionBarNavigation(this); mActionController = new ActionModeController(this); // new ArrayAdapter mListAdapter = new BrowserListAdapter(this, mDataSource); if (sHandler == null) { sHandler = new Handler(this.getMainLooper()); } initActionBar(); setupDrawer(); initDrawerLists(); // get the browser list mListView = (ListView) findViewById(android.R.id.list); mListView.setEmptyView(findViewById(android.R.id.empty)); mListView.setAdapter(mListAdapter); mListView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); mListView.setOnItemClickListener(mOnItemClickListener); mActionController.setListView(mListView); }
From source file:org.tigase.mobile.bookmarks.BookmarksActivity.java
@TargetApi(11) private void initializeContextActions() { listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new MultiChoiceModeListener() { private Bookmark getBookmarkFromFlatPosition(int pos) { long packed = listView.getExpandableListPosition(pos); int child = ExpandableListView.getPackedPositionChild(packed); int group = ExpandableListView.getPackedPositionGroup(packed); return (Bookmark) adapter.getChild(group, child); }//from w ww . j av a 2 s .c o m @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { SparseBooleanArray selection = listView.getCheckedItemPositions(); if (item.getItemId() == R.id.edit) { for (int i = 0; i < selection.size(); i++) { if (selection.valueAt(i)) { int pos = selection.keyAt(i); Bookmark bookmark = getBookmarkFromFlatPosition(pos); editItem(bookmark); } } mode.finish(); // Action picked, so close the CAB return true; } else if (item.getItemId() == R.id.remove) { List<Bookmark> items = new ArrayList<Bookmark>(); for (int i = 0; i < selection.size(); i++) { if (selection.valueAt(i)) { int pos = selection.keyAt(i); Bookmark bookmark = getBookmarkFromFlatPosition(pos); if (bookmark != null) { items.add(bookmark); } } } removeItems(items); mode.finish(); return true; } else { return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.bookmarks_context_menu, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { // TODO Auto-generated method stub } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { Menu menu = mode.getMenu(); for (int i = 0; i < menu.size(); i++) { MenuItem mi = menu.getItem(i); if (mi.getItemId() == R.id.edit) { mi.setVisible(listView.getCheckedItemCount() < 2); } } } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { // TODO Auto-generated method stub return true; } }); }