use of android.support.v7.view.ActionMode in project HoloEverywhere by Prototik.
the class ActionBarContextView method initForMode.
public void initForMode(final ActionMode mode) {
if (mClose == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
mClose = inflater.inflate(R.layout.abc_action_mode_close_item, this, false);
addView(mClose);
} else if (mClose.getParent() == null) {
addView(mClose);
}
View closeButton = mClose.findViewById(R.id.action_mode_close_button);
closeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mode.finish();
}
});
final MenuBuilder menu = (MenuBuilder) mode.getMenu();
if (mActionMenuPresenter != null) {
mActionMenuPresenter.dismissPopupMenus();
}
mActionMenuPresenter = new ActionMenuPresenter(getContext());
mActionMenuPresenter.setReserveOverflow(true);
final ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.FILL_PARENT);
if (!mSplitActionBar) {
menu.addMenuPresenter(mActionMenuPresenter);
mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
mMenuView.setBackgroundDrawable(null);
addView(mMenuView, layoutParams);
} else {
// Allow full screen width in split mode.
mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true);
// No limit to the item count; use whatever will fit.
mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
// Span the whole width
layoutParams.width = ViewGroup.LayoutParams.FILL_PARENT;
layoutParams.height = mContentHeight;
menu.addMenuPresenter(mActionMenuPresenter);
mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
mMenuView.setBackgroundDrawable(mSplitBackground);
mSplitView.addView(mMenuView, layoutParams);
}
}
use of android.support.v7.view.ActionMode in project Signal-Android by WhisperSystems.
the class ConversationListFragment method handleDeleteAllSelected.
private void handleDeleteAllSelected() {
int conversationsCount = getListAdapter().getBatchSelections().size();
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setIconAttribute(R.attr.dialog_alert_icon);
alert.setTitle(getActivity().getResources().getQuantityString(R.plurals.ConversationListFragment_delete_selected_conversations, conversationsCount, conversationsCount));
alert.setMessage(getActivity().getResources().getQuantityString(R.plurals.ConversationListFragment_this_will_permanently_delete_all_n_selected_conversations, conversationsCount, conversationsCount));
alert.setCancelable(true);
alert.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final Set<Long> selectedConversations = (getListAdapter()).getBatchSelections();
if (!selectedConversations.isEmpty()) {
new AsyncTask<Void, Void, Void>() {
private ProgressDialog dialog;
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(getActivity(), getActivity().getString(R.string.ConversationListFragment_deleting), getActivity().getString(R.string.ConversationListFragment_deleting_selected_conversations), true, false);
}
@Override
protected Void doInBackground(Void... params) {
DatabaseFactory.getThreadDatabase(getActivity()).deleteConversations(selectedConversations);
MessageNotifier.updateNotification(getActivity(), masterSecret);
return null;
}
@Override
protected void onPostExecute(Void result) {
dialog.dismiss();
if (actionMode != null) {
actionMode.finish();
actionMode = null;
}
}
}.execute();
}
}
});
alert.setNegativeButton(android.R.string.cancel, null);
alert.show();
}
use of android.support.v7.view.ActionMode in project Shuttle by timusus.
the class DetailFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_detail, container, false);
recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
if (canEdit()) {
itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback((from, to) -> {
long songViewCount = Stream.of(adapter.items).filter(adaptableItem -> adaptableItem instanceof SongView).count();
int offset = (int) (adapter.getItemCount() - songViewCount);
if (to >= offset) {
adapter.moveItem(from, to);
}
}, (from, to) -> {
// The 'offset' here is the number of items in the list which are not
// SongViews. We need this to determine the actual playlist positions of the items.
long songViewCount = Stream.of(adapter.items).filter(adaptableItem -> adaptableItem instanceof SongView).count();
int offset = (int) (adapter.getItemCount() - songViewCount);
from -= offset;
to -= offset;
try {
MediaStore.Audio.Playlists.Members.moveItem(getActivity().getContentResolver(), playlist.id, from, to);
} catch (IllegalArgumentException e) {
CrashlyticsCore.getInstance().log(String.format("Failed to move playlist item from %s to %s. Adapter count: %s. Error:%s", from, to, adapter.getItemCount(), e.getMessage()));
}
}, null));
itemTouchHelper.attachToRecyclerView(recyclerView);
}
fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
fab.setOnClickListener(this);
lineOne = (TextView) rootView.findViewById(R.id.line_one);
lineTwo = (TextView) rootView.findViewById(R.id.line_two);
overflowButton = (NonScrollImageButton) rootView.findViewById(R.id.btn_overflow);
overflowButton.setOnClickListener(this);
if (albumArtist != null) {
lineOne.setText(albumArtist.name);
overflowButton.setContentDescription(getString(R.string.btn_options, albumArtist.name));
} else if (album != null) {
lineOne.setText(album.name);
overflowButton.setContentDescription(getString(R.string.btn_options, album.name));
} else if (genre != null) {
lineOne.setText(genre.name);
overflowButton.setVisibility(View.GONE);
} else if (playlist != null) {
lineOne.setText(playlist.name);
overflowButton.setContentDescription(getString(R.string.btn_options, playlist.name));
}
textProtectionScrim = rootView.findViewById(R.id.textProtectionScrim);
headerImageView = (ImageView) rootView.findViewById(R.id.background);
String transitionName = getArguments().getString(ARG_TRANSITION_NAME);
ViewCompat.setTransitionName(headerImageView, transitionName);
if (transitionName != null) {
textProtectionScrim.setVisibility(View.GONE);
fab.setVisibility(View.GONE);
}
int width = ResourceUtils.getScreenSize().width + ResourceUtils.toPixels(60);
int height = getResources().getDimensionPixelSize(R.dimen.header_view_height);
if (albumArtist != null || album != null) {
requestManager.load(albumArtist == null ? album : albumArtist).override(width, height).diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.HIGH).placeholder(GlideUtils.getPlaceHolderDrawable(albumArtist == null ? album.name : albumArtist.name, false)).centerCrop().animate(new AlwaysCrossFade(false)).into(headerImageView);
}
actionMode = null;
//Set the RecyclerView HeaderView height equal to the headerItem height
headerView = rootView.findViewById(R.id.headerView);
headerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
headerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
DetailFragment.this.headerItem.height = headerView.getHeight();
}
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
headerTranslation = headerView.getTranslationY() - dy;
headerImageTranslation = headerImageView.getTranslationY() + dy / 2;
//the header translation.
if (headerTranslation == 0) {
headerImageTranslation = 0;
}
float ratio = Math.min(1, -headerTranslation / headerView.getHeight());
headerView.setTranslationY(headerTranslation);
headerImageView.setTranslationY(headerImageTranslation);
//when recreating this fragment.
if (getActivity() != null) {
if (((MainActivity) getActivity()).canSetAlpha()) {
((MainActivity) getActivity()).setActionBarAlpha(ratio, true);
}
}
}
});
themeUIComponents();
headerView.setTranslationY(headerTranslation);
headerImageView.setTranslationY(headerImageTranslation);
return rootView;
}
use of android.support.v7.view.ActionMode in project RoboBinding-gallery by RoboBinding.
the class ContextualActionModeActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MemoryProductStore productStore = MemoryProductStore.getInstance();
productStore.reset();
presentationModel = new ContextualActionModePresentationModel(productStore);
initializeContentView(R.layout.activity_contextual_action_mode, presentationModel);
ListView productListView = (ListView) findViewById(R.id.productList);
productListView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
startSupportActionMode(new ActionMode.Callback() {
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
return false;
}
@Override
public void onDestroyActionMode(ActionMode actionMode) {
}
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
MenuBinder menuBinder = createMenuBinder(menu, getMenuInflater());
menuBinder.inflateAndBind(R.menu.contextual_action_mode, presentationModel);
return true;
}
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
return false;
}
});
return true;
}
});
}
use of android.support.v7.view.ActionMode in project ForPDA by RadiationX.
the class ThemeFragmentWeb method addShowingView.
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void addShowingView() {
messagePanel.setHeightChangeListener(newHeight -> {
webView.setPaddingBottom(newHeight);
});
webView = getMainActivity().getWebViewsProvider().pull(getContext());
attachWebView(webView);
webView.setJsLifeCycleListener(this);
refreshLayout.addView(webView);
refreshLayoutLongTrigger(refreshLayout);
webView.addJavascriptInterface(this, JS_INTERFACE);
webView.addJavascriptInterface(this, JS_POSTS_FUNCTIONS);
registerForContextMenu(webView);
fab.setOnClickListener(v -> {
if (webView.getDirection() == ExtendedWebView.DIRECTION_DOWN) {
webView.pageDown(true);
} else if (webView.getDirection() == ExtendedWebView.DIRECTION_UP) {
webView.pageUp(true);
}
});
webView.setOnDirectionListener(direction -> {
if (webView.getDirection() == ExtendedWebView.DIRECTION_DOWN) {
fab.setImageDrawable(App.getVecDrawable(fab.getContext(), R.drawable.ic_arrow_down));
} else if (webView.getDirection() == ExtendedWebView.DIRECTION_UP) {
fab.setImageDrawable(App.getVecDrawable(fab.getContext(), R.drawable.ic_arrow_up));
}
});
// Кастомизация менюхи при выделении текста
webView.setActionModeListener((actionMode, callback, type) -> {
Menu menu = actionMode.getMenu();
ArrayList<MenuItem> items = new ArrayList<>();
for (int i = 0; i < menu.size(); i++) {
items.add(menu.getItem(i));
}
menu.clear();
menu.add(R.string.copy).setIcon(App.getVecDrawable(getContext(), R.drawable.ic_toolbar_content_copy)).setOnMenuItemClickListener(item -> {
webView.evalJs("copySelectedText()");
actionMode.finish();
return true;
}).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
if (currentPage.canQuote())
menu.add(R.string.quote).setIcon(App.getVecDrawable(getContext(), R.drawable.ic_toolbar_quote_post)).setOnMenuItemClickListener(item -> {
webView.evalJs("selectionToQuote()");
actionMode.finish();
return true;
}).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(R.string.all_text).setIcon(App.getVecDrawable(getContext(), R.drawable.ic_toolbar_select_all)).setOnMenuItemClickListener(item -> {
webView.evalJs("selectAllPostText()");
return true;
}).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.add(R.string.share).setIcon(App.getVecDrawable(getContext(), R.drawable.ic_toolbar_share)).setOnMenuItemClickListener(item -> {
webView.evalJs("shareSelectedText()");
return true;
}).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
for (MenuItem item : items) {
if (item.getIntent() != null) {
menu.add(item.getGroupId(), item.getItemId(), item.getOrder(), item.getTitle()).setIntent(item.getIntent()).setNumericShortcut(item.getNumericShortcut()).setAlphabeticShortcut(item.getAlphabeticShortcut());
}
}
});
}
Aggregations