Search in sources :

Example 6 with ContextMenu

use of android.view.ContextMenu in project newsrob by marianokamp.

the class ArticleViewHelper method createArticleMenu.

static void createArticleMenu(final Menu menu, final Activity owningActivity, final Entry selectedEntry) {
    final EntryManager entryManager = EntryManager.getInstance(owningActivity);
    final boolean isArticleContextMenu = menu instanceof ContextMenu;
    if (isArticleContextMenu)
        ((ContextMenu) menu).setHeaderTitle("Article");
    final boolean alternateHRefAvailable = (selectedEntry != null && selectedEntry.getAlternateHRef() != null);
    if (selectedEntry == null) {
        Log.e(TAG, "Oops. SelectedEntry was null.");
        return;
    }
    final boolean isProVersion = entryManager.isProVersion();
    if (isProVersion && entryManager.isGoogleTv() && (selectedEntry.getReadState() == ReadState.READ || selectedEntry.getReadState() == ReadState.UNREAD))
        menu.add(0, MENU_ITEM_PIN_ARTICLE_ID, 1, "Pin").setIcon(android.R.drawable.btn_star);
    if (selectedEntry.getReadState() == ReadState.READ)
        menu.add(0, MENU_ITEM_MARK_ENTRY_UNREAD_ID, 2, R.string.menu_mark_as_unread).setIcon(android.R.drawable.checkbox_on_background);
    else
        menu.add(0, MENU_ITEM_MARK_ENTRY_READ_ID, 2, R.string.menu_mark_as_read).setIcon(android.R.drawable.checkbox_on_background);
    if (isArticleContextMenu) {
        if (selectedEntry.isStarred())
            menu.add(0, MENU_ITEM_UNSTAR_ID, 3, R.string.menu_item_unstar).setIcon(android.R.drawable.btn_star_big_off);
        else
            menu.add(0, MENU_ITEM_STAR_ID, 3, R.string.menu_item_star).setIcon(android.R.drawable.btn_star_big_off);
    }
    Uri uri = null;
    if (alternateHRefAvailable)
        uri = Uri.parse(selectedEntry.getAlternateHRef());
    menu.add(0, MENU_ITEM_SHOW_IN_BROWSER_ID, 5, R.string.menu_show_in_browser).setTitleCondensed(U.t(owningActivity, R.string.menu_show_in_browser_condensed)).setIntent(new Intent(Intent.ACTION_VIEW, uri)).setIcon(android.R.drawable.ic_menu_view).setEnabled(alternateHRefAvailable);
    menu.add(0, MENU_ITEM_SHARE_LINK_ID, 6, R.string.menu_item_share_link).setIntent(Intent.createChooser(createShareLinkSendIntent(selectedEntry), "Share Link")).setIcon(android.R.drawable.ic_menu_share).setEnabled(alternateHRefAvailable);
    if (selectedEntry.getContent() != null)
        System.out.println("selectedEntry.getContent().length() > 100=" + (selectedEntry.getContent().length() > 100));
    if (false)
        menu.add(0, MENU_ITEM_SHARE_ARTICLE_ID, 7, "Share Article").setIntent(Intent.createChooser(createShareArticleSendIntent(selectedEntry), "Share Article")).setIcon(android.R.drawable.ic_menu_share).setEnabled(false && alternateHRefAvailable && selectedEntry.getContent() != null && selectedEntry.getContent().length() > 100);
    menu.add(0, MENU_ITEM_REFRESH_CONTENT_ID, 13, "Refresh Content").setIcon(android.R.drawable.ic_menu_close_clear_cancel).setEnabled(selectedEntry.getDownloaded() != Entry.STATE_NOT_DOWNLOADED && entryManager.getStorageAdapter().canWrite());
    menu.add(0, MENU_ITEM_MANAGE_FEED_ID, 14, R.string.menu_item_manage_feed).setIcon(android.R.drawable.ic_menu_manage).setEnabled(selectedEntry.getFeedId() != 0l);
    menu.add(0, MENU_ITEM_SHOW_ARTICLE_INFO_ID, 15, R.string.menu_item_show_article_info);
    if ("1".equals(NewsRob.getDebugProperties(owningActivity).getProperty("enableBoom", "0")))
        menu.add(0, MENU_ITEM_BOOM_ID, 21, "Boom!");
    if (entryManager.canNewsRobProBeBought()) {
        final Intent viewIntent = new Intent(Intent.ACTION_VIEW);
        viewIntent.setData(Uri.parse("market://details?id=" + EntryManager.PRO_PACKAGE_NAME));
        menu.add(0, MENU_ITEM_BUY_NEWSROB_PRO, 31, "Buy NewsRob Pro!").setIntent(viewIntent);
    }
}
Also used : ContextMenu(android.view.ContextMenu) Intent(android.content.Intent) EntryManager(com.newsrob.EntryManager) Uri(android.net.Uri)

Example 7 with ContextMenu

use of android.view.ContextMenu in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiSettingsTest method onCreateContextMenu_shouldHaveForgetMenuForConnectedAccessPreference.

@Test
public void onCreateContextMenu_shouldHaveForgetMenuForConnectedAccessPreference() {
    final FragmentActivity mockActivity = mock(FragmentActivity.class);
    when(mockActivity.getApplicationContext()).thenReturn(mContext);
    when(mWifiSettings.getActivity()).thenReturn(mockActivity);
    final AccessPoint accessPoint = mock(AccessPoint.class);
    when(accessPoint.isConnectable()).thenReturn(false);
    when(accessPoint.isSaved()).thenReturn(true);
    when(accessPoint.isActive()).thenReturn(true);
    final ConnectedAccessPointPreference connectedPreference = mWifiSettings.createConnectedAccessPointPreference(accessPoint, mContext);
    final View view = mock(View.class);
    when(view.getTag()).thenReturn(connectedPreference);
    final ContextMenu menu = mock(ContextMenu.class);
    mWifiSettings.onCreateContextMenu(menu, view, null);
    verify(menu).add(anyInt(), eq(WifiSettings.MENU_ID_FORGET), anyInt(), anyInt());
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) AccessPoint(com.android.settingslib.wifi.AccessPoint) ContextMenu(android.view.ContextMenu) View(android.view.View) Test(org.junit.Test)

Example 8 with ContextMenu

use of android.view.ContextMenu in project android_packages_apps_Settings by omnirom.

the class NetworkProviderSettingsTest method onCreateContextMenu_shouldHaveForgetAndDisconnectMenuForConnectedWifiEntry.

@Test
public void onCreateContextMenu_shouldHaveForgetAndDisconnectMenuForConnectedWifiEntry() {
    final FragmentActivity activity = mock(FragmentActivity.class);
    when(activity.getApplicationContext()).thenReturn(mContext);
    when(mNetworkProviderSettings.getActivity()).thenReturn(activity);
    final WifiEntry wifiEntry = mock(WifiEntry.class);
    when(wifiEntry.canDisconnect()).thenReturn(true);
    when(wifiEntry.canForget()).thenReturn(true);
    when(wifiEntry.isSaved()).thenReturn(true);
    when(wifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
    final LongPressWifiEntryPreference connectedWifiEntryPreference = mNetworkProviderSettings.createLongPressWifiEntryPreference(wifiEntry);
    final View view = mock(View.class);
    when(view.getTag()).thenReturn(connectedWifiEntryPreference);
    final ContextMenu menu = mock(ContextMenu.class);
    mNetworkProviderSettings.onCreateContextMenu(menu, view, null);
    verify(menu).add(anyInt(), eq(NetworkProviderSettings.MENU_ID_FORGET), anyInt(), anyInt());
    verify(menu).add(anyInt(), eq(NetworkProviderSettings.MENU_ID_DISCONNECT), anyInt(), anyInt());
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference) WifiEntry(com.android.wifitrackerlib.WifiEntry) ContextMenu(android.view.ContextMenu) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Test(org.junit.Test)

Aggregations

ContextMenu (android.view.ContextMenu)8 View (android.view.View)5 Menu (android.view.Menu)4 FragmentActivity (androidx.fragment.app.FragmentActivity)3 Test (org.junit.Test)3 MenuItem (android.view.MenuItem)2 OnMenuItemClickListener (android.view.MenuItem.OnMenuItemClickListener)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 LongPressWifiEntryPreference (com.android.settingslib.wifi.LongPressWifiEntryPreference)2 WifiEntry (com.android.wifitrackerlib.WifiEntry)2 SuppressLint (android.annotation.SuppressLint)1 ActivityManager (android.app.ActivityManager)1 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 Paint (android.graphics.Paint)1 Uri (android.net.Uri)1 StringRes (android.support.annotation.StringRes)1 InputFilter (android.text.InputFilter)1 ActionMode (android.view.ActionMode)1