use of android.view.ActionMode in project AntennaPod by AntennaPod.
the class SelectableAdapter method startSelectMode.
public void startSelectMode(int pos) {
if (inActionMode()) {
endSelectMode();
}
if (onSelectModeListener != null) {
onSelectModeListener.onStartSelectMode();
}
selectedIds.clear();
selectedIds.add(getItemId(pos));
notifyDataSetChanged();
actionMode = activity.startActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.multi_select_options, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
updateTitle();
toggleSelectAllIcon(menu.findItem(R.id.select_toggle), false);
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (item.getItemId() == R.id.select_toggle) {
boolean allSelected = selectedIds.size() == getItemCount();
setSelected(0, getItemCount(), !allSelected);
toggleSelectAllIcon(item, !allSelected);
updateTitle();
return true;
}
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
callOnEndSelectMode();
actionMode = null;
selectedIds.clear();
notifyDataSetChanged();
}
});
updateTitle();
}
use of android.view.ActionMode in project Launcher3 by chislon.
the class WallpaperPickerActivity method init.
// called by onCreate; this is subclassed to overwrite WallpaperCropActivity
protected void init() {
setContentView(R.layout.wallpaper_picker);
mCropView = (CropView) findViewById(R.id.cropView);
mWallpaperStrip = findViewById(R.id.wallpaper_strip);
mCropView.setTouchCallback(new CropView.TouchCallback() {
LauncherViewPropertyAnimator mAnim;
@Override
public void onTouchDown() {
if (mAnim != null) {
mAnim.cancel();
}
if (mWallpaperStrip.getAlpha() == 1f) {
mIgnoreNextTap = true;
}
mAnim = new LauncherViewPropertyAnimator(mWallpaperStrip);
mAnim.alpha(0f).setDuration(150).addListener(new Animator.AnimatorListener() {
public void onAnimationStart(Animator animator) {
}
public void onAnimationEnd(Animator animator) {
mWallpaperStrip.setVisibility(View.INVISIBLE);
}
public void onAnimationCancel(Animator animator) {
}
public void onAnimationRepeat(Animator animator) {
}
});
mAnim.setInterpolator(new AccelerateInterpolator(0.75f));
mAnim.start();
}
@Override
public void onTouchUp() {
mIgnoreNextTap = false;
}
@Override
public void onTap() {
boolean ignoreTap = mIgnoreNextTap;
mIgnoreNextTap = false;
if (!ignoreTap) {
if (mAnim != null) {
mAnim.cancel();
}
mWallpaperStrip.setVisibility(View.VISIBLE);
mAnim = new LauncherViewPropertyAnimator(mWallpaperStrip);
mAnim.alpha(1f).setDuration(150).setInterpolator(new DecelerateInterpolator(0.75f));
mAnim.start();
}
}
});
mThumbnailOnClickListener = new OnClickListener() {
public void onClick(View v) {
if (mActionMode != null) {
// When CAB is up, clicking toggles the item instead
if (v.isLongClickable()) {
mLongClickListener.onLongClick(v);
}
return;
}
WallpaperTileInfo info = (WallpaperTileInfo) v.getTag();
if (info.isSelectable()) {
if (mSelectedThumb != null) {
mSelectedThumb.setSelected(false);
mSelectedThumb = null;
}
mSelectedThumb = v;
v.setSelected(true);
// TODO: Remove this once the accessibility framework and
// services have better support for selection state.
v.announceForAccessibility(getString(R.string.announce_selection, v.getContentDescription()));
}
info.onClick(WallpaperPickerActivity.this);
}
};
mLongClickListener = new View.OnLongClickListener() {
// Called when the user long-clicks on someView
public boolean onLongClick(View view) {
CheckableFrameLayout c = (CheckableFrameLayout) view;
c.toggle();
if (mActionMode != null) {
mActionMode.invalidate();
} else {
// Start the CAB using the ActionMode.Callback defined below
mActionMode = startActionMode(mActionModeCallback);
int childCount = mWallpapersView.getChildCount();
for (int i = 0; i < childCount; i++) {
mWallpapersView.getChildAt(i).setSelected(false);
}
}
return true;
}
};
// Populate the built-in wallpapers
ArrayList<ResourceWallpaperInfo> wallpapers = findBundledWallpapers();
mWallpapersView = (LinearLayout) findViewById(R.id.wallpaper_list);
BuiltInWallpapersAdapter ia = new BuiltInWallpapersAdapter(this, wallpapers);
populateWallpapersFromAdapter(mWallpapersView, ia, false, true);
// Populate the saved wallpapers
mSavedImages = new SavedWallpaperImages(this);
mSavedImages.loadThumbnailsAndImageIdList();
populateWallpapersFromAdapter(mWallpapersView, mSavedImages, true, true);
// Populate the live wallpapers
final LinearLayout liveWallpapersView = (LinearLayout) findViewById(R.id.live_wallpaper_list);
final LiveWallpaperListAdapter a = new LiveWallpaperListAdapter(this);
a.registerDataSetObserver(new DataSetObserver() {
public void onChanged() {
liveWallpapersView.removeAllViews();
populateWallpapersFromAdapter(liveWallpapersView, a, false, false);
initializeScrollForRtl();
updateTileIndices();
}
});
// Populate the third-party wallpaper pickers
final LinearLayout thirdPartyWallpapersView = (LinearLayout) findViewById(R.id.third_party_wallpaper_list);
final ThirdPartyWallpaperPickerListAdapter ta = new ThirdPartyWallpaperPickerListAdapter(this);
populateWallpapersFromAdapter(thirdPartyWallpapersView, ta, false, false);
// Add a tile for the Gallery
LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list);
FrameLayout pickImageTile = (FrameLayout) getLayoutInflater().inflate(R.layout.wallpaper_picker_image_picker_item, masterWallpaperList, false);
setWallpaperItemPaddingToZero(pickImageTile);
masterWallpaperList.addView(pickImageTile, 0);
// Make its background the last photo taken on external storage
Bitmap lastPhoto = getThumbnailOfLastPhoto();
if (lastPhoto != null) {
ImageView galleryThumbnailBg = (ImageView) pickImageTile.findViewById(R.id.wallpaper_image);
galleryThumbnailBg.setImageBitmap(getThumbnailOfLastPhoto());
int colorOverlay = getResources().getColor(R.color.wallpaper_picker_translucent_gray);
galleryThumbnailBg.setColorFilter(colorOverlay, PorterDuff.Mode.SRC_ATOP);
}
PickImageInfo pickImageInfo = new PickImageInfo();
pickImageTile.setTag(pickImageInfo);
pickImageInfo.setView(pickImageTile);
pickImageTile.setOnClickListener(mThumbnailOnClickListener);
pickImageInfo.setView(pickImageTile);
updateTileIndices();
// Update the scroll for RTL
initializeScrollForRtl();
// Create smooth layout transitions for when items are deleted
final LayoutTransition transitioner = new LayoutTransition();
transitioner.setDuration(200);
transitioner.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0);
transitioner.setAnimator(LayoutTransition.DISAPPEARING, null);
mWallpapersView.setLayoutTransition(transitioner);
// Action bar
// Show the custom action bar view
final ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.actionbar_set_wallpaper);
actionBar.getCustomView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mSelectedThumb != null) {
WallpaperTileInfo info = (WallpaperTileInfo) mSelectedThumb.getTag();
info.onSave(WallpaperPickerActivity.this);
}
}
});
// CAB for deleting items
mActionModeCallback = new ActionMode.Callback() {
// Called when the action mode is created; startActionMode() was called
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Inflate a menu resource providing context menu items
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.cab_delete_wallpapers, menu);
return true;
}
private int numCheckedItems() {
int childCount = mWallpapersView.getChildCount();
int numCheckedItems = 0;
for (int i = 0; i < childCount; i++) {
CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i);
if (c.isChecked()) {
numCheckedItems++;
}
}
return numCheckedItems;
}
// 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) {
int numCheckedItems = numCheckedItems();
if (numCheckedItems == 0) {
mode.finish();
return true;
} else {
mode.setTitle(getResources().getQuantityString(R.plurals.number_of_items_selected, numCheckedItems, numCheckedItems));
return true;
}
}
// Called when the user selects a contextual menu item
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
int itemId = item.getItemId();
if (itemId == R.id.menu_delete) {
int childCount = mWallpapersView.getChildCount();
ArrayList<View> viewsToRemove = new ArrayList<View>();
for (int i = 0; i < childCount; i++) {
CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i);
if (c.isChecked()) {
WallpaperTileInfo info = (WallpaperTileInfo) c.getTag();
info.onDelete(WallpaperPickerActivity.this);
viewsToRemove.add(c);
}
}
for (View v : viewsToRemove) {
mWallpapersView.removeView(v);
}
updateTileIndices();
// Action picked, so close the CAB
mode.finish();
return true;
} else {
return false;
}
}
// Called when the user exits the action mode
@Override
public void onDestroyActionMode(ActionMode mode) {
int childCount = mWallpapersView.getChildCount();
for (int i = 0; i < childCount; i++) {
CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i);
c.setChecked(false);
}
mSelectedThumb.setSelected(true);
mActionMode = null;
}
};
}
use of android.view.ActionMode in project Gadgetbridge by Freeyourgadget.
the class ActivitySummariesActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
Bundle extras = getIntent().getExtras();
if (extras != null) {
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
} else {
throw new IllegalArgumentException("Must provide a device when invoking this activity");
}
deviceFilter = getDeviceId(mGBDevice);
IntentFilter filterLocal = new IntentFilter();
filterLocal.addAction(GBDevice.ACTION_DEVICE_CHANGED);
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
super.onCreate(savedInstanceState);
ActivitySummariesAdapter activitySummariesAdapter = new ActivitySummariesAdapter(this, mGBDevice, activityFilter, dateFromFilter, dateToFilter, nameContainsFilter, deviceFilter, itemsFilter);
int backgroundColor = getBackgroundColor(ActivitySummariesActivity.this);
activitySummariesAdapter.setBackgroundColor(backgroundColor);
activitySummariesAdapter.setShowTime(false);
setItemAdapter(activitySummariesAdapter);
getItemListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// item 0 is empty for dashboard
if (position == 0)
return;
Object item = parent.getItemAtPosition(position);
if (item != null) {
ActivitySummary summary = (ActivitySummary) item;
try {
showActivityDetail(position);
} catch (Exception e) {
GB.toast(getApplicationContext(), "Unable to display Activity Detail, maybe the activity is not available yet: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e);
}
}
}
});
getItemListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
getItemListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
@Override
public void onItemCheckedStateChanged(ActionMode actionMode, int position, long id, boolean checked) {
if (position == 0 && checked)
subtrackDashboard = 1;
if (position == 0 && !checked)
subtrackDashboard = 0;
final int selectedItems = getItemListView().getCheckedItemCount() - subtrackDashboard;
actionMode.setTitle(selectedItems + " selected");
}
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
getMenuInflater().inflate(R.menu.activity_list_context_menu, menu);
findViewById(R.id.fab).setVisibility(View.INVISIBLE);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
boolean processed = false;
SparseBooleanArray checked = getItemListView().getCheckedItemPositions();
switch(menuItem.getItemId()) {
case R.id.activity_action_delete:
List<BaseActivitySummary> toDelete = new ArrayList<>();
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
toDelete.add(getItemAdapter().getItem(checked.keyAt(i)));
}
}
deleteItems(toDelete);
processed = true;
break;
case R.id.activity_action_export:
List<String> paths = new ArrayList<>();
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
BaseActivitySummary item = getItemAdapter().getItem(checked.keyAt(i));
if (item != null) {
ActivitySummary summary = item;
String gpxTrack = summary.getGpxTrack();
if (gpxTrack != null) {
paths.add(gpxTrack);
}
}
}
}
shareMultiple(paths);
processed = true;
break;
case R.id.activity_action_select_all:
for (int i = 0; i < getItemListView().getCount(); i++) {
getItemListView().setItemChecked(i, true);
}
// don't finish actionmode in this case!
return true;
case R.id.activity_action_addto_filter:
List<Long> toFilter = new ArrayList<>();
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
BaseActivitySummary item = getItemAdapter().getItem(checked.keyAt(i));
if (item != null && item.getId() != null) {
ActivitySummary summary = item;
Long id = summary.getId();
toFilter.add(id);
}
}
}
itemsFilter = toFilter;
setItemsFilter(itemsFilter);
refresh();
processed = true;
break;
default:
break;
}
actionMode.finish();
return processed;
}
@Override
public void onDestroyActionMode(ActionMode actionMode) {
findViewById(R.id.fab).setVisibility(View.VISIBLE);
}
});
swipeLayout = findViewById(R.id.list_activity_swipe_layout);
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
fetchTrackData();
}
});
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fetchTrackData();
}
});
activityKindMap = fillKindMap();
}
use of android.view.ActionMode in project Klyph by jonathangerbaud.
the class AbsHListView method setChoiceMode.
/**
* Defines the choice behavior for the List. By default, Lists do not have any choice behavior ({@link #CHOICE_MODE_NONE}). By
* setting the choiceMode to {@link #CHOICE_MODE_SINGLE}, the List allows up to one item to be in a chosen state. By setting the
* choiceMode to {@link #CHOICE_MODE_MULTIPLE}, the list allows any number of items to be chosen.
*
* @param choiceMode
* One of {@link #CHOICE_MODE_NONE}, {@link #CHOICE_MODE_SINGLE}, or {@link #CHOICE_MODE_MULTIPLE}
*/
@TargetApi(11)
public void setChoiceMode(int choiceMode) {
mChoiceMode = choiceMode;
if (android.os.Build.VERSION.SDK_INT >= 11) {
if (mChoiceActionMode != null) {
if (android.os.Build.VERSION.SDK_INT >= 11) {
((ActionMode) mChoiceActionMode).finish();
}
mChoiceActionMode = null;
}
}
if (mChoiceMode != ListView.CHOICE_MODE_NONE) {
if (mCheckStates == null) {
mCheckStates = new SparseBooleanArray();
}
if (mCheckedIdStates == null && mAdapter != null && mAdapter.hasStableIds()) {
mCheckedIdStates = new LongSparseArray<Integer>();
}
// Modal multi-choice mode only has choices when the mode is active. Clear them.
if (android.os.Build.VERSION.SDK_INT >= 11) {
if (mChoiceMode == ListView.CHOICE_MODE_MULTIPLE_MODAL) {
clearChoices();
setLongClickable(true);
}
}
}
}
use of android.view.ActionMode in project apps-android-wikipedia by wikimedia.
the class PageFragment method showFindInPage.
public void showFindInPage() {
if (model.getPage() == null) {
return;
}
final FindInPageFunnel funnel = new FindInPageFunnel(app, model.getTitle().getWikiSite(), model.getPage().getPageProperties().getPageId());
final FindInWebPageActionProvider findInPageActionProvider = new FindInWebPageActionProvider(this, funnel);
startSupportActionMode(new ActionMode.Callback() {
private final String actionModeTag = "actionModeFindInPage";
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
findInPageActionMode = mode;
MenuItem menuItem = menu.add(R.string.menu_page_find_in_page);
menuItem.setActionProvider(findInPageActionProvider);
menuItem.expandActionView();
setToolbarElevationEnabled(false);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
mode.setTag(actionModeTag);
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
if (webView == null || !isAdded()) {
return;
}
findInPageActionMode = null;
funnel.setPageHeight(webView.getContentHeight());
funnel.logDone();
webView.clearMatches();
showToolbar();
hideSoftKeyboard();
setToolbarElevationEnabled(true);
}
});
}
Aggregations