List of usage examples for android.view ActionMode getMenuInflater
public abstract MenuInflater getMenuInflater();
From source file:com.fortysevendeg.android.swipelistview.sample.activities.SwipeListViewExampleActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.swipe_list_view_activity); data = new ArrayList<PackageItem>(); adapter = new PackageAdapter(this, data); swipeListView = (SwipeListView) findViewById(R.id.example_lv_list); swipeListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { swipeListView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override/*from w w w . j av a2 s. c o m*/ public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { mode.setTitle("Selected (" + swipeListView.getCountSelected() + ")"); } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.menu_delete: swipeListView.dismissSelected(); mode.finish(); return true; default: return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.menu_choice_items, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { swipeListView.unselectedChoiceStates(); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); } swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() { @Override public void onOpened(int position, boolean toRight) { } @Override public void onClosed(int position, boolean fromRight) { } @Override public void onListChanged() { } @Override public void onMove(int position, float x) { } @Override public void onStartOpen(int position, int action, boolean right) { Log.d("swipe", String.format("onStartOpen %d - action %d", position, action)); } @Override public void onStartClose(int position, boolean right) { Log.d("swipe", String.format("onStartClose %d", position)); } @Override public void onClickFrontView(int position) { Log.d("swipe", String.format("onClickFrontView %d", position)); } @Override public void onClickBackView(int position) { Log.d("swipe", String.format("onClickBackView %d", position)); } @Override public void onDismiss(int[] reverseSortedPositions) { for (int position : reverseSortedPositions) { data.remove(position); } adapter.notifyDataSetChanged(); } }); swipeListView.setAdapter(adapter); reload(); new ListAppTask().execute(); progressDialog = new ProgressDialog(this); progressDialog.setMessage(getString(R.string.loading)); progressDialog.setCancelable(false); progressDialog.show(); }
From source file:com.parking.swipelistview.sample.activities.SwipeListViewExampleActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.swipe_list_view_activity); ctx = SwipeListViewExampleActivity.this; data = new ArrayList<MallItem>(); adapter = new MallAdapter(this, data); swipeListView = (SwipeListView) findViewById(R.id.example_lv_list); swipeListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { swipeListView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { @Override// ww w . j a v a 2 s . c o m public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { mode.setTitle("Selected (" + swipeListView.getCountSelected() + ")"); } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.menu_delete: swipeListView.dismissSelected(); mode.finish(); return true; default: return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.menu_choice_items, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { swipeListView.unselectedChoiceStates(); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); } swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() { @Override public void onOpened(int position, boolean toRight) { } @Override public void onClosed(int position, boolean fromRight) { } @Override public void onListChanged() { } @Override public void onMove(int position, float x) { } @Override public void onStartOpen(int position, int action, boolean right) { Log.d("swipe", String.format("onStartOpen %d - action %d", position, action)); } @Override public void onStartClose(int position, boolean right) { Log.d("swipe", String.format("onStartClose %d", position)); } @Override public void onClickFrontView(int position) { Log.d("swipe", String.format("onClickFrontView %d", position)); } @Override public void onClickBackView(int position) { Log.d("swipe", String.format("onClickBackView %d", position)); } @Override public void onDismiss(int[] reverseSortedPositions) { for (int position : reverseSortedPositions) { data.remove(position); } adapter.notifyDataSetChanged(); } }); swipeListView.setAdapter(adapter); reload(); new ListAppTask().execute(); progressDialog = new ProgressDialog(this); progressDialog.setMessage(getString(R.string.loading)); progressDialog.setCancelable(false); progressDialog.show(); }
From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvUserIdsFragment.java
public void enterEditMode() { FragmentActivity activity = getActivity(); if (activity == null) { return;/*from www . j a v a2s . c om*/ } activity.startActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mEditModeSaveKeyringParcel = new SaveKeyringParcel(mMasterKeyId, mFingerprint); mUserIdsAddedAdapter = new UserIdsAddedAdapter(getActivity(), mEditModeSaveKeyringParcel.mAddUserIds, false); mUserIdsAddedList.setAdapter(mUserIdsAddedAdapter); mUserIdsAddedLayout.setVisibility(View.VISIBLE); mUserIdAddFabLayout.setDisplayedChild(1); mUserIdsAdapter.setEditMode(mEditModeSaveKeyringParcel); getLoaderManager().restartLoader(LOADER_ID_USER_IDS, null, ViewKeyAdvUserIdsFragment.this); mode.setTitle(R.string.title_edit_identities); mode.getMenuInflater().inflate(R.menu.action_edit_uids, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { editKey(mode); return true; } @Override public void onDestroyActionMode(ActionMode mode) { mEditModeSaveKeyringParcel = null; mUserIdsAdapter.setEditMode(null); mUserIdsAddedLayout.setVisibility(View.GONE); mUserIdAddFabLayout.setDisplayedChild(0); getLoaderManager().restartLoader(LOADER_ID_USER_IDS, null, ViewKeyAdvUserIdsFragment.this); } }); }
From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvSubkeysFragment.java
public void enterEditMode() { FragmentActivity activity = getActivity(); if (activity == null) { return;/*w w w. jav a 2 s . c o m*/ } activity.startActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mEditModeSaveKeyringParcel = new SaveKeyringParcel(mMasterKeyId, mFingerprint); mSubkeysAddedAdapter = new SubkeysAddedAdapter(getActivity(), mEditModeSaveKeyringParcel.mAddSubKeys, false); mSubkeysAddedList.setAdapter(mSubkeysAddedAdapter); mSubkeysAddedLayout.setVisibility(View.VISIBLE); mSubkeyAddFabLayout.setDisplayedChild(1); mSubkeysAdapter.setEditMode(mEditModeSaveKeyringParcel); getLoaderManager().restartLoader(LOADER_ID_SUBKEYS, null, ViewKeyAdvSubkeysFragment.this); mode.setTitle(R.string.title_edit_subkeys); mode.getMenuInflater().inflate(R.menu.action_edit_uids, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { editKey(mode); return true; } @Override public void onDestroyActionMode(ActionMode mode) { mEditModeSaveKeyringParcel = null; mSubkeysAdapter.setEditMode(null); mSubkeysAddedLayout.setVisibility(View.GONE); mSubkeyAddFabLayout.setDisplayedChild(0); getLoaderManager().restartLoader(LOADER_ID_SUBKEYS, null, ViewKeyAdvSubkeysFragment.this); } }); }
From source file:com.example.android.contactslist.ui.groupsEditor.GroupsEditorFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mActionModeCallback = new ActionMode.Callback() { // Called when the action mode is created; startActionMode() was called @Override//from w ww . j a v a2 s. c om public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Inflate a menu resource providing context menu items //MenuInflater inflater = mode.getMenuInflater(); //inflater.inflate(R.menu.contextual_actionbar, menu); mode.getMenuInflater().inflate(R.menu.contextual_actionbar, menu); return true; } // Called each time the action mode is shown. Always called after onCreateActionMode, but // may be called multiple times if the mode is invalidated. @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; // Return false if nothing is done } // Called when the user selects a contextual menu item @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.menu_remove_contact: GoogleGroupMaker googleGroupMaker = new GoogleGroupMaker(getActivity()); googleGroupMaker.removeGoogleGroup(mDeleteGroupID); // method to remove group from app DB final ContactStatsContract statsDb = new ContactStatsContract(getActivity()); final GroupStatsHelper groupStatsHelper = new GroupStatsHelper(getActivity()); // delete group from the app Database final int records_updated = groupStatsHelper.removeGroupFromDB(mDeleteGroupID, statsDb); Toast.makeText(getActivity(), Long.toString(records_updated) + " Record(s) Updated", Toast.LENGTH_SHORT).show(); mode.finish(); // Action picked, so close the CAB return true; default: mode.finish(); // Action picked, so close the CAB Toast.makeText(getActivity(), "End Action Mode", Toast.LENGTH_SHORT).show(); return false; } } // Called when the user exits the action mode @Override public void onDestroyActionMode(ActionMode mode) { mActionMode = null; } }; getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View view, int position, long id) { if (mActionMode != null) { return false; } // Gets the Cursor object currently bound to the ListView final Cursor cursor = mAdapter.getCursor(); // Moves to the Cursor row corresponding to the ListView item that was clicked cursor.moveToPosition(position); // Using the lookupKey because the wrong ID was being returned mDeleteGroupID = cursor.getLong(GroupsListStatsQuery.GROUP_ID); // Start the CAB using the ActionMode.Callback defined above mActionMode = getActivity().startActionMode(mActionModeCallback); view.setSelected(true); return true; } }); }
From source file:foundme.uniroma2.it.professore.ReadMessageActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_read_message); context = this; Bundle passed = getIntent().getExtras(); Title = passed.getString(Variables_it.COURSE); swipeMsg = (SwipeRefreshLayout) findViewById(R.id.swipe_msg); swipeMsg.setEnabled(false);//from w w w. j ava2 s . c o m lvMessaggi = (ListView) findViewById(R.id.lvmes); modeCallBack = new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.delete: if (!toEdit.equalsIgnoreCase(Variables_it.NO_MSG)) { try { deleteMsg(toEdit); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } toEdit = null; mode.finish(); break; } return false; } public void onDestroyActionMode(ActionMode mode) { viewList.setBackgroundColor(Color.TRANSPARENT); mode = null; } public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.setTitle(Variables_it.OPTION); mode.getMenuInflater().inflate(R.menu.context, menu); return true; } }; try { getMsg(Title, true); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:cat.wuyingren.rorhelper.fragments.GameListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); dataSource = new GameDataSource(getActivity()); dataSource.open();/*from w ww . j a v a 2 s. com*/ values = dataSource.getAllGames(); adapter = new MultipleRowAdapter(getActivity(), values); setListAdapter(adapter); final ListView listView = getListView(); listView.setItemsCanFocus(false); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); listView.setMultiChoiceModeListener(new ListView.MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { // Here you can do something when items are selected/de-selected, // such as update the title in the CAB //mode.setTag(); int selectionColor = getResources().getColor(R.color.colorPrimary); Log.w("TAG", "onItemCheckedStateChanged() " + checked + " " + position); mode.setSubtitle(listView.getCheckedItemCount() + " selected"); if (checked) { listView.getChildAt(position).setBackgroundColor(selectionColor); } else { listView.getChildAt(position) .setBackgroundColor(getResources().getColor(android.R.color.transparent)); } } @Override public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) { // Inflate the menu for the CAB Log.w("TAG", "onCreateActionMode"); MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.menu_context, menu); mode.setTitle(getString(R.string.action_choose)); return true; } @Override public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) { // Here you can perform updates to the CAB due to // an invalidate() request return false; } @Override public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) { // Respond to clicks on the actions in the CAB switch (item.getItemId()) { case R.id.action_delete: deleteItems(listView.getCheckedItemPositions()); mode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(android.view.ActionMode mode) { // Here you can make any necessary updates to the activity when // the CAB is removed. By default, selected items are deselected/unchecked. SparseBooleanArray checked = listView.getCheckedItemPositions(); for (int i = 0; i < listView.getAdapter().getCount(); i++) { if (checked.get(i)) { listView.getChildAt(i) .setBackgroundColor(getResources().getColor(android.R.color.transparent)); } } } }); // dataSource.close(); }
From source file:com.makotojava.android.debate.PolicySpeechFragment.java
private void createSpeechTimerOnLongClickListener(TextView speechTimer) { speechTimer.setOnLongClickListener(new OnLongClickListener() { @Override/*from w w w . jav a2 s . c o m*/ public boolean onLongClick(View v) { getActivity().startActionMode(new ActionMode.Callback() { @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { // Nothing to do } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Inflate the menu MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.speech_timer_context_menu, menu); return true; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { boolean ret = false; switch (item.getItemId()) { case R.id.speech_context_menu_item_reset: Log.i(TAG, "CONTEXT MENU: Speech Timer **RESET**"); long originalDurationInMillis = _speechTimer.reset(); updateTimerTextView(_speechTimerTextView, originalDurationInMillis); _speechTimerTextView.setTextColor(Color.BLACK); ret = true; break; case R.id.speech_context_menu_item_set: Log.i(TAG, "CONTEXT MENU: Speech Timer **SET**"); // Display dialog to set Timer FragmentManager fragMan = getActivity().getFragmentManager(); TimePickerFragment dialog = TimePickerFragment.newInstance( _speechTimer.getMillisUntilFinished(), _speech.getDurationInMinutes(), RQID_SPEECHTIMER); dialog.setTargetFragment(PolicySpeechFragment.this, 0); dialog.show(fragMan, MINUTES_SECONDS_PICKER_TITLE); _speechTimerTextView.setTextColor(Color.BLACK); ret = true; break; } return ret; } }); return true; } }); }
From source file:com.makotojava.android.debate.PolicySpeechFragment.java
private void createAffPrepTimerOnLongClickListener(TextView speechTimer) { speechTimer.setOnLongClickListener(new OnLongClickListener() { @Override/*w w w . ja v a 2 s . c om*/ public boolean onLongClick(View v) { getActivity().startActionMode(new ActionMode.Callback() { @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { // Nothing to do } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Inflate the menu MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.affprep_timer_context_menu, menu); return true; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { boolean ret = false; switch (item.getItemId()) { case R.id.affprep_context_menu_reset: Log.i(TAG, "CONTEXT MENU: Aff Prep Timer **RESET**"); long originalDurationInMillis = getAffirmativePrepTimer().reset(); updateTimerTextView(_affirmativePrepTimerTextView, originalDurationInMillis); getPolicySpeechSingleton().setAffirmativePrepRemainingTime(originalDurationInMillis); _affirmativePrepTimerTextView.setTextColor(Color.BLACK); ret = true; break; case R.id.affprep_context_menu_set: Log.i(TAG, "CONTEXT MENU: Aff Prep Timer **SET**"); // Display dialog to set Timer FragmentManager fragMan = getActivity().getFragmentManager(); TimePickerFragment dialog = TimePickerFragment.newInstance( getAffirmativePrepTimer().getMillisUntilFinished(), PolicySpeechFactory.PREP_TIME_IN_MINUTES, RQID_AFFPREPTIMER); dialog.setTargetFragment(PolicySpeechFragment.this, 0); dialog.show(fragMan, MINUTES_SECONDS_PICKER_TITLE); _affirmativePrepTimerTextView.setTextColor(Color.BLACK); ret = true; break; } return ret; } }); return true; } }); }
From source file:com.makotojava.android.debate.PolicySpeechFragment.java
private void createNegPrepTimerOnLongClickListener(TextView speechTimer) { speechTimer.setOnLongClickListener(new OnLongClickListener() { @Override/* ww w. j a v a2 s.co m*/ public boolean onLongClick(View v) { getActivity().startActionMode(new ActionMode.Callback() { @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { // Nothing to do } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Inflate the menu MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.negprep_timer_context_menu, menu); return true; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { boolean ret = false; switch (item.getItemId()) { case R.id.negprep_context_menu_reset: Log.i(TAG, "CONTEXT MENU: Neg Prep Timer **RESET**"); long originalDurationInMillis = getNegativePrepTimer().reset(); updateTimerTextView(_negativePrepTimerTextView, originalDurationInMillis); getPolicySpeechSingleton().setNegativePrepRemainingTime(originalDurationInMillis); _negativePrepTimerTextView.setTextColor(Color.BLACK); ret = true; break; case R.id.negprep_context_menu_set: Log.i(TAG, "CONTEXT MENU: Neg Prep Timer **SET**"); // Display dialog to set Timer FragmentManager fragMan = getActivity().getFragmentManager(); TimePickerFragment dialog = TimePickerFragment.newInstance( getNegativePrepTimer().getMillisUntilFinished(), PolicySpeechFactory.PREP_TIME_IN_MINUTES, RQID_NEGPREPTIMER); dialog.setTargetFragment(PolicySpeechFragment.this, 0); dialog.show(fragMan, MINUTES_SECONDS_PICKER_TITLE); _negativePrepTimerTextView.setTextColor(Color.BLACK); ret = true; break; } return ret; } }); return true; } }); }