use of android.view.MenuItem.OnMenuItemClickListener in project android_frameworks_base by DirtyUnicorns.
the class HelpUtils method prepareHelpMenuItem.
/**
* Prepares the help menu item by doing the following.
* - If the helpUrlString is empty or null, the help menu item is made invisible.
* - Otherwise, this makes the help menu item visible and sets the intent for the help menu
* item to view the URL.
*
* @return returns whether the help menu item has been made visible.
*/
public static boolean prepareHelpMenuItem(final Activity activity, MenuItem helpMenuItem, String helpUriString, String backupContext) {
if (Global.getInt(activity.getContentResolver(), Global.DEVICE_PROVISIONED, 0) == 0) {
return false;
}
if (TextUtils.isEmpty(helpUriString)) {
// The help url string is empty or null, so set the help menu item to be invisible.
helpMenuItem.setVisible(false);
// return that the help menu item is not visible (i.e. false)
return false;
} else {
final Intent intent = getHelpIntent(activity, helpUriString, backupContext);
// menu, and make it visible.
if (intent != null) {
helpMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MetricsLogger.action(activity, MetricsEvent.ACTION_SETTING_HELP_AND_FEEDBACK, intent.getStringExtra(EXTRA_CONTEXT));
try {
activity.startActivityForResult(intent, 0);
} catch (ActivityNotFoundException exc) {
Log.e(TAG, "No activity found for intent: " + intent);
}
return true;
}
});
helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
helpMenuItem.setVisible(true);
} else {
helpMenuItem.setVisible(false);
return false;
}
// return that the help menu item is visible (i.e., true)
return true;
}
}
use of android.view.MenuItem.OnMenuItemClickListener in project android_frameworks_base by AOSPA.
the class HelpUtils method prepareHelpMenuItem.
/**
* Prepares the help menu item by doing the following.
* - If the helpUrlString is empty or null, the help menu item is made invisible.
* - Otherwise, this makes the help menu item visible and sets the intent for the help menu
* item to view the URL.
*
* @return returns whether the help menu item has been made visible.
*/
public static boolean prepareHelpMenuItem(final Activity activity, MenuItem helpMenuItem, String helpUriString, String backupContext) {
if (Global.getInt(activity.getContentResolver(), Global.DEVICE_PROVISIONED, 0) == 0) {
return false;
}
if (TextUtils.isEmpty(helpUriString)) {
// The help url string is empty or null, so set the help menu item to be invisible.
helpMenuItem.setVisible(false);
// return that the help menu item is not visible (i.e. false)
return false;
} else {
final Intent intent = getHelpIntent(activity, helpUriString, backupContext);
// menu, and make it visible.
if (intent != null) {
helpMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MetricsLogger.action(activity, MetricsEvent.ACTION_SETTING_HELP_AND_FEEDBACK, intent.getStringExtra(EXTRA_CONTEXT));
try {
activity.startActivityForResult(intent, 0);
} catch (ActivityNotFoundException exc) {
Log.e(TAG, "No activity found for intent: " + intent);
}
return true;
}
});
helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
helpMenuItem.setVisible(true);
} else {
helpMenuItem.setVisible(false);
return false;
}
// return that the help menu item is visible (i.e., true)
return true;
}
}
use of android.view.MenuItem.OnMenuItemClickListener in project android_frameworks_base by ResurrectionRemix.
the class HelpUtils method prepareHelpMenuItem.
/**
* Prepares the help menu item by doing the following.
* - If the helpUrlString is empty or null, the help menu item is made invisible.
* - Otherwise, this makes the help menu item visible and sets the intent for the help menu
* item to view the URL.
*
* @return returns whether the help menu item has been made visible.
*/
public static boolean prepareHelpMenuItem(final Activity activity, MenuItem helpMenuItem, String helpUriString, String backupContext) {
if (Global.getInt(activity.getContentResolver(), Global.DEVICE_PROVISIONED, 0) == 0) {
return false;
}
if (TextUtils.isEmpty(helpUriString)) {
// The help url string is empty or null, so set the help menu item to be invisible.
helpMenuItem.setVisible(false);
// return that the help menu item is not visible (i.e. false)
return false;
} else {
final Intent intent = getHelpIntent(activity, helpUriString, backupContext);
// menu, and make it visible.
if (intent != null) {
helpMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MetricsLogger.action(activity, MetricsEvent.ACTION_SETTING_HELP_AND_FEEDBACK, intent.getStringExtra(EXTRA_CONTEXT));
try {
activity.startActivityForResult(intent, 0);
} catch (ActivityNotFoundException exc) {
Log.e(TAG, "No activity found for intent: " + intent);
}
return true;
}
});
helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
helpMenuItem.setVisible(true);
} else {
helpMenuItem.setVisible(false);
return false;
}
// return that the help menu item is visible (i.e., true)
return true;
}
}
use of android.view.MenuItem.OnMenuItemClickListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DreamSettings method createMenuItem.
private MenuItem createMenuItem(Menu menu, int titleRes, int actionEnum, boolean isEnabled, final Runnable onClick) {
MenuItem item = menu.add(titleRes);
item.setShowAsAction(actionEnum);
item.setEnabled(isEnabled);
item.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
onClick.run();
return true;
}
});
return item;
}
use of android.view.MenuItem.OnMenuItemClickListener in project AndroidChromium by JackyAndroid.
the class SnippetArticleViewHolder method createContextMenu.
@Override
protected void createContextMenu(ContextMenu menu) {
RecordHistogram.recordSparseSlowlyHistogram("NewTabPage.Snippets.CardLongPressed", mArticle.mPosition);
mArticle.recordAgeAndScore("NewTabPage.Snippets.CardLongPressed");
OnMenuItemClickListener listener = new ContextMenuItemClickListener(mArticle, mNewTabPageManager, getRecyclerView());
// Create a context menu akin to the one shown for MostVisitedItems.
if (mNewTabPageManager.isOpenInNewWindowEnabled()) {
addContextMenuItem(menu, ID_OPEN_IN_NEW_WINDOW, R.string.contextmenu_open_in_other_window, listener);
}
addContextMenuItem(menu, ID_OPEN_IN_NEW_TAB, R.string.contextmenu_open_in_new_tab, listener);
if (mNewTabPageManager.isOpenInIncognitoEnabled()) {
addContextMenuItem(menu, ID_OPEN_IN_INCOGNITO_TAB, R.string.contextmenu_open_in_incognito_tab, listener);
}
// TODO(peconn): Only show 'Save for Offline' for appropriate snippet types.
if (SnippetsConfig.isSaveToOfflineEnabled() && OfflinePageBridge.canSavePage(mArticle.mUrl)) {
addContextMenuItem(menu, ID_SAVE_FOR_OFFLINE, R.string.contextmenu_save_link, listener);
}
addContextMenuItem(menu, ID_REMOVE, R.string.remove, listener);
// Disable touch events on the RecyclerView while the context menu is open. This is to
// prevent the user long pressing to get the context menu then on the same press scrolling
// or swiping to dismiss an item (eg. https://crbug.com/638854, 638555, 636296)
final NewTabPageRecyclerView recyclerView = (NewTabPageRecyclerView) itemView.getParent();
recyclerView.setTouchEnabled(false);
mNewTabPageManager.addContextMenuCloseCallback(new Callback<Menu>() {
@Override
public void onResult(Menu result) {
recyclerView.setTouchEnabled(true);
mNewTabPageManager.removeContextMenuCloseCallback(this);
}
});
}
Aggregations