List of usage examples for android.view ActionMode.Callback ActionMode.Callback
ActionMode.Callback
From source file:com.github.capone.controller.discovery.DiscoveryListFragment.java
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final Server to = adapter.getItem(position); getActivity().startActionMode(new ActionMode.Callback() { @Override//from w w w. j a v a 2 s .c o m public boolean onCreateActionMode(ActionMode mode, Menu menu) { getActivity().getMenuInflater().inflate(R.menu.discovery, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { ServerRecord server = ServerRecord.findByTo(to); if (server == null) { menu.findItem(R.id.remove).setVisible(false); } else { menu.findItem(R.id.add).setVisible(false); } return true; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.add: onAddClicked(to); mode.finish(); return true; case R.id.remove: onRemoveClicked(to); mode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode mode) { } }); return true; }
From source file:com.github.capone.controller.favorites.FavoritesFragment.java
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final ServerRecord server = adapter.getItem(position); getActivity().startActionMode(new ActionMode.Callback() { @Override//w w w. j av a 2 s .c om public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.favorites, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.edit: onEditClicked(server); mode.finish(); return true; case R.id.remove: onRemoveClicked(server); mode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode mode) { } }); return true; }
From source file:com.acbelter.scheduleview.ScheduleView.java
public ScheduleView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); mClipRect = new Rect(); mClickedViewBounds = new Rect(); mSelectedIds = new HashSet<Long>(); mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mTopEdgeEffect = new EdgeEffectCompat(context); mBottomEdgeEffect = new EdgeEffectCompat(context); mDataSetObserver = new DataSetObserver() { @Override//from w w w . ja va 2s . co m public void onChanged() { super.onChanged(); removeAllViewsInLayout(); requestLayout(); } @Override public void onInvalidated() { super.onInvalidated(); removeAllViewsInLayout(); requestLayout(); } }; init(context); setVerticalScrollBarEnabled(true); setHorizontalScrollBarEnabled(false); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScheduleView, defStyle, 0); try { if (a != null) { DisplayMetrics dm = context.getResources().getDisplayMetrics(); mInternalPaddingTop = (int) a.getDimension(R.styleable.ScheduleView_internalPaddingTop, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm)); mInternalPaddingBottom = (int) a.getDimension(R.styleable.ScheduleView_internalPaddingBottom, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm)); mTimeMarksDistance = (int) a.getDimension(R.styleable.ScheduleView_timeMarksDistance, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, dm)); mItemPaddingLeft = (int) a.getDimension(R.styleable.ScheduleView_itemPaddingLeft, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm)); mItemPaddingRight = (int) a.getDimension(R.styleable.ScheduleView_itemPaddingRight, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm)); initializeScrollbars(a); } } finally { if (a != null) { a.recycle(); } } // Draw the background even if no items to display setWillNotDraw(false); mActionModeCallback = new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(R.menu.menu_context, menu); mIsActionMode = true; return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { if (item.getItemId() == R.id.delete_items) { deleteSelectedItems(); } return false; } @Override public void onDestroyActionMode(ActionMode mode) { clearSelection(); mIsActionMode = false; mActionMode = null; invalidate(); } }; }
From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java
public void onBookmarkClick(final Bookmark bookmark) { getSherlockActivity().startActionMode(new ActionMode.Callback() { private MenuItem delete; @Override//w ww . j a va2 s . c o m public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { this.delete = menu.add(R.string.delete); this.delete.setIcon(R.drawable.trash_can); return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { actionMode.setTitle(R.string.bookmark_options); return true; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { boolean result = false; if (menuItem == delete) { bookmarkDatabaseHelper.deleteBookmark(bookmark); Toast.makeText(context, R.string.bookmark_deleted, Toast.LENGTH_SHORT).show(); result = true; } if (result) { actionMode.finish(); } return result; } @Override public void onDestroyActionMode(ActionMode actionMode) { } }); }
From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java
@Override public void onHighLightClick(final HighLight highLight) { LOG.debug("onHighLightClick"); getSherlockActivity().startActionMode(new ActionMode.Callback() { private MenuItem edit; private MenuItem delete; private MenuItem colour; @Override//w ww . j a v a2s .c o m public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { this.edit = menu.add(R.string.edit); this.edit.setIcon(R.drawable.edit); this.colour = menu.add(R.string.set_colour); this.colour.setIcon(R.drawable.color); this.delete = menu.add(R.string.delete); this.delete.setIcon(R.drawable.trash_can); return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { actionMode.setTitle(R.string.highlight_options); return true; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { boolean result = false; if (menuItem == edit) { showHighlightEditDialog(highLight); result = true; } else if (menuItem == delete) { deleteHightlight(highLight); result = true; } else if (menuItem == colour) { showHighlightColourDialog(highLight); result = true; } if (result) { actionMode.finish(); } return result; } @Override public void onDestroyActionMode(ActionMode actionMode) { } }); }