Search in sources :

Example 1 with ContextMenu

use of android.view.ContextMenu 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);
        }
    });
}
Also used : NewTabPageRecyclerView(org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) ContextMenu(android.view.ContextMenu) Menu(android.view.Menu)

Example 2 with ContextMenu

use of android.view.ContextMenu in project XPrivacy by M66B.

the class ActivityApp method onCreateContextMenu.

// Application context menu
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    // Check if running
    boolean running = false;
    ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    for (RunningAppProcessInfo info : activityManager.getRunningAppProcesses()) if (info.uid == mAppInfo.getUid())
        running = true;
    PackageManager pm = getPackageManager();
    List<String> listPackageNames = mAppInfo.getPackageName();
    List<String> listApplicationName = mAppInfo.getApplicationName();
    for (int i = 0; i < listPackageNames.size(); i++) {
        Menu appMenu = (listPackageNames.size() == 1) ? menu : menu.addSubMenu(i, Menu.NONE, Menu.NONE, listApplicationName.get(i));
        // Launch
        MenuItem launch = appMenu.add(i, MENU_LAUNCH, Menu.NONE, getString(R.string.menu_app_launch));
        if (pm.getLaunchIntentForPackage(listPackageNames.get(i)) == null)
            launch.setEnabled(false);
        // Settings
        appMenu.add(i, MENU_SETTINGS, Menu.NONE, getString(R.string.menu_app_settings));
        // Kill
        MenuItem kill = appMenu.add(i, MENU_KILL, Menu.NONE, getString(R.string.menu_app_kill));
        kill.setEnabled(running && PrivacyManager.isApplication(mAppInfo.getUid()));
        // Play store
        MenuItem store = appMenu.add(i, MENU_STORE, Menu.NONE, getString(R.string.menu_app_store));
        if (!Util.hasMarketLink(this, listPackageNames.get(i)))
            store.setEnabled(false);
    }
}
Also used : PackageManager(android.content.pm.PackageManager) RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) MenuItem(android.view.MenuItem) ContextMenu(android.view.ContextMenu) Menu(android.view.Menu) ActivityManager(android.app.ActivityManager) SuppressLint(android.annotation.SuppressLint)

Example 3 with ContextMenu

use of android.view.ContextMenu in project CodenameOne by codenameone.

the class ResetableTextWatcher method startEditing.

/**
 * Start editing the given text-area
 * This method is executed on the UI thread, so UI manipulation is safe here.
 * @param activity Current running activity
 * @param textArea The TextAreaData instance that wraps the CN1 TextArea that our internal EditText needs to overlap.  We use
 *                 a TextAreaData so that the text area properties can be accessed off the EDT safely.
 * @param codenameOneInputType One of the input type constants in com.codename1.ui.TextArea
 * @param initialText The text that appears in the Codename One text are before the call to startEditing
 * @param isEditedFieldSwitch if true, then special case for async edit mode - the native editing is already active, no need to show
 *                            native field, just change the connected field
 */
private synchronized void startEditing(Activity activity, TextAreaData textArea, String initialText, int codenameOneInputType, final boolean isEditedFieldSwitch) {
    int txty = lastTextAreaY = textArea.getAbsoluteY() + textArea.getScrollY();
    int txtx = lastTextAreaX = textArea.getAbsoluteX() + textArea.getScrollX();
    lastTextAreaWidth = textArea.getWidth();
    lastTextAreaHeight = textArea.getHeight();
    int paddingTop = 0;
    int paddingLeft = textArea.paddingLeft;
    int paddingRight = textArea.paddingRight;
    int paddingBottom = textArea.paddingBottom;
    if (textArea.isTextField) {
        switch(textArea.getVerticalAlignment()) {
            case Component.BOTTOM:
                paddingTop = textArea.getHeight() - textArea.paddingBottom - textArea.fontHeight;
                break;
            case Component.CENTER:
                paddingTop = textArea.getHeight() / 2 - textArea.fontHeight / 2;
                break;
            default:
                paddingTop = textArea.paddingTop;
                break;
        }
    } else {
        paddingTop = textArea.paddingTop;
    }
    int id = activity.getResources().getIdentifier("cn1Style", "attr", activity.getApplicationInfo().packageName);
    if (!isEditedFieldSwitch) {
        mEditText = new EditView(activity, textArea.textArea, this, id);
    } else {
        mEditText.switchToTextArea(textArea.textArea);
    }
    if (textArea.getClientProperty("blockCopyPaste") != null || Display.getInstance().getProperty("blockCopyPaste", "false").equals("true")) {
        // The code below is taken from this stackoverflow answer: http://stackoverflow.com/a/22756538/756809
        if (android.os.Build.VERSION.SDK_INT < 11) {
            mEditText.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

                @Override
                public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
                    menu.clear();
                }
            });
        } else {
            mEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {

                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                public void onDestroyActionMode(ActionMode mode) {
                }

                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    return false;
                }
            });
        }
    } else if (isEditedFieldSwitch) {
        // reset copy-paste protection
        if (android.os.Build.VERSION.SDK_INT < 11) {
            mEditText.setOnCreateContextMenuListener(null);
        } else {
            mEditText.setCustomSelectionActionModeCallback(null);
        }
    }
    if (!isEditedFieldSwitch) {
        mEditText.addTextChangedListener(mEditText.mTextWatcher);
    }
    mEditText.setBackgroundDrawable(null);
    mEditText.setFocusableInTouchMode(true);
    mEditLayoutParams = new FrameLayout.LayoutParams(0, 0);
    // Set the appropriate gravity so that the left and top margins will be
    // taken into account
    mEditLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
    mEditLayoutParams.setMargins(txtx, txty, 0, 0);
    mEditLayoutParams.width = textArea.getWidth();
    mEditLayoutParams.height = textArea.getHeight();
    mEditText.setLayoutParams(mEditLayoutParams);
    if (textArea.isRTL()) {
        mEditText.setGravity(Gravity.RIGHT | Gravity.TOP);
    } else {
        mEditText.setGravity(Gravity.LEFT | Gravity.TOP);
    }
    mEditText.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
    Component nextDown = textArea.nextDown;
    boolean imeOptionTaken = true;
    int ime = EditorInfo.IME_FLAG_NO_EXTRACT_UI;
    if (textArea.isSingleLineTextArea()) {
        if (textArea.getClientProperty("searchField") != null) {
            mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_SEARCH);
        } else {
            if (textArea.getClientProperty("sendButton") != null) {
                mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_SEND);
            } else {
                if (textArea.getClientProperty("goButton") != null) {
                    mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_GO);
                } else {
                    if (textArea.isTextField && textArea.getDoneListener() != null) {
                        mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_DONE);
                    } else if (nextDown != null && nextDown instanceof TextArea && ((TextArea) nextDown).isEditable() && ((TextArea) nextDown).isEnabled()) {
                        mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_NEXT);
                    } else {
                        mEditText.setImeOptions(ime | EditorInfo.IME_ACTION_DONE);
                        imeOptionTaken = false;
                    }
                }
            }
        }
    }
    mEditText.setSingleLine(textArea.isSingleLineTextArea());
    mEditText.setAdapter((ArrayAdapter<String>) null);
    mEditText.setText(initialText);
    if (!textArea.isSingleLineTextArea() && textArea.textArea.isGrowByContent() && textArea.textArea.getGrowLimit() > -1) {
        defaultMaxLines = mEditText.getMaxLines();
        mEditText.setMaxLines(textArea.textArea.getGrowLimit());
    }
    if (textArea.nativeHintBool && textArea.getHint() != null) {
        mEditText.setHint(textArea.getHint());
    }
    if (!isEditedFieldSwitch) {
        addView(mEditText, mEditLayoutParams);
    }
    invalidate();
    setVisibility(VISIBLE);
    bringToFront();
    mEditText.requestFocus();
    Object nativeFont = textArea.nativeFont;
    if (nativeFont == null) {
        nativeFont = impl.getDefaultFont();
    }
    Paint p = (Paint) ((AndroidImplementation.NativeFont) nativeFont).font;
    mEditText.setTypeface(p.getTypeface());
    mEditText.setTextScaleX(p.getTextScaleX());
    mEditText.setTextSize(TypedValue.COMPLEX_UNIT_PX, p.getTextSize());
    int fgColor = textArea.fgColor;
    mEditText.setTextColor(Color.rgb(fgColor >> 16, (fgColor & 0x00ff00) >> 8, (fgColor & 0x0000ff)));
    boolean password = false;
    if ((codenameOneInputType & TextArea.PASSWORD) == TextArea.PASSWORD) {
        codenameOneInputType = codenameOneInputType ^ TextArea.PASSWORD;
        password = true;
    }
    if (textArea.isSingleLineTextArea()) {
        mEditText.setInputType(getAndroidInputType(codenameOneInputType));
        // if not ime was explicity requested and this is a single line textfield of type ANY add the emoji keyboard.
        if (!imeOptionTaken && codenameOneInputType == TextArea.ANY) {
            mEditText.setInputType(getAndroidInputType(codenameOneInputType) | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
        }
        if (Display.getInstance().getProperty("andAddComma", "false").equals("true") && (codenameOneInputType & TextArea.DECIMAL) == TextArea.DECIMAL) {
            defaultKeyListener = mEditText.getKeyListener();
            mEditText.setKeyListener(DigitsKeyListener.getInstance("0123456789.,"));
        }
    }
    if (password) {
        int type = mInputTypeMap.get(codenameOneInputType, InputType.TYPE_CLASS_TEXT);
        if ((type & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) == InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) {
            type = type ^ InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
        }
        // turn off suggestions for passwords
        mEditText.setInputType(type | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
        mEditText.setTransformationMethod(new MyPasswordTransformationMethod());
    }
    int maxLength = textArea.maxSize;
    InputFilter[] FilterArray = new InputFilter[1];
    FilterArray[0] = new InputFilter.LengthFilter(maxLength);
    mEditText.setFilters(FilterArray);
    mEditText.setSelection(mEditText.getText().length());
    showVirtualKeyboard(true);
    if (Boolean.FALSE.equals(textArea.getClientProperty("android.cursorVisible"))) {
        // This provides an imperfect workaround for this issue:
        // https://github.com/codenameone/CodenameOne/issues/2317
        // Blinking cursor causes text to disappear on some versions of android
        // Can't seem to find how to detect whether device is affected, so
        // just providing a client property to disable the blinking cursor
        // on a particular text field.
        mEditText.setCursorVisible(false);
    }
/*
        // Leaving this hack here for posterity.  It seems that this manually
        // blinking cursor causes the paste menu to disappear
        // https://github.com/codenameone/CodenameOne/issues/2147
        // Removing the hack below, fixes this issue.  And in the test device
        // I'm using the blinking of text doesn't seem to occur, so perhaps
        // it was fixed via other means.  Test device:
        // Name: Samsung Galaxy S3 (T-Mobile)
        //    OS: 4.3
        //    Manufacturer: Samsung
        //    Model: 4.3
        //    Chipset: armeabi-v7a 1512MHz
        //    Memory: 16000000000
        //    Heap: 256000000
        //    Display: 720 x 1280
        //
        // UPDATE Feb. 13, 2018:
        // This issue seems to be still present in some devices, but it isn't clear even
        // how to detect it.
        // Issue reported and reproduced here https://github.com/codenameone/CodenameOne/issues/2317
        // Issue has been observed in a Virtual Box installation with 5.1.1, but
        // cannot be reproduced in a Nexus 5 running 5.1.1.
        // 
        if (Build.VERSION.SDK_INT < 21) {
            // HACK!!!  On Android 4.4, it seems that the natural blinking cursor
            // causes text to disappear when it blinks.  Manually blinking the
            // cursor seems to work around this issue, so that's what we do here.
            // This issue is described here: http://stackoverflow.com/questions/41305052/textfields-content-disappears-during-typing?noredirect=1#comment69977316_41305052
            mEditText.setCursorVisible(false);
            final boolean[] cursorVisible = new boolean[]{false};
            if (cursorTimer != null) {
                cursorTimer.cancel();
            }
            cursorTimer = new Timer();
            cursorTimerTask = new TimerTask() {
                public void run() {
                    AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() {
                        public void run() {
                            EditView v = mEditText;
                            if (v != null) {
                                cursorVisible[0] = !cursorVisible[0];
                                v.setCursorVisible(cursorVisible[0]);
                            }
                        }
                    });

                }
            };
            cursorTimer.schedule(cursorTimerTask, 100, 500);
        }
        */
}
Also used : InputFilter(android.text.InputFilter) TextArea(com.codename1.ui.TextArea) ContextMenu(android.view.ContextMenu) MenuItem(android.view.MenuItem) Paint(android.graphics.Paint) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) Paint(android.graphics.Paint) ActionMode(android.view.ActionMode) FrameLayout(android.widget.FrameLayout) ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo) ContextMenu(android.view.ContextMenu) Menu(android.view.Menu) Component(com.codename1.ui.Component)

Example 4 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 5 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)

Aggregations

ContextMenu (android.view.ContextMenu)6 Menu (android.view.Menu)4 View (android.view.View)3 MenuItem (android.view.MenuItem)2 OnMenuItemClickListener (android.view.MenuItem.OnMenuItemClickListener)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 ContextMenuInfo (android.view.ContextMenu.ContextMenuInfo)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 FrameLayout (android.widget.FrameLayout)1 FragmentActivity (androidx.fragment.app.FragmentActivity)1 AccessPoint (com.android.settingslib.wifi.AccessPoint)1