Java Code Examples for android.view.View#showContextMenu()

The following examples show how to use android.view.View#showContextMenu() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContextMenuHelper.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Starts showing a context menu for {@code view} based on {@code params}.
 * @param contentViewCore The {@link ContentViewCore} to show the menu to.
 * @param params          The {@link ContextMenuParams} that indicate what menu items to show.
 */
@CalledByNative
private boolean showContextMenu(ContentViewCore contentViewCore, ContextMenuParams params) {
    final View view = contentViewCore.getContainerView();

    if (view == null
            || view.getVisibility() != View.VISIBLE
            || view.getParent() == null) {
        return false;
    }

    mCurrentContextMenuParams = params;

    view.setOnCreateContextMenuListener(this);
    if (view.showContextMenu()) {
        WebContents webContents = contentViewCore.getWebContents();
        RecordHistogram.recordBooleanHistogram(
                "ContextMenu.Shown", webContents != null);
        if (webContents != null) webContents.onContextMenuOpened();
        return true;
    }
    return false;
}
 
Example 2
Source File: ContextMenuHelper.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Starts showing a context menu for {@code view} based on {@code params}.
 * @param contentViewCore The {@link ContentViewCore} to show the menu to.
 * @param params          The {@link ContextMenuParams} that indicate what menu items to show.
 */
@CalledByNative
private void showContextMenu(ContentViewCore contentViewCore, ContextMenuParams params) {
    final View view = contentViewCore.getContainerView();

    if (view == null
            || view.getVisibility() != View.VISIBLE
            || view.getParent() == null) {
        return;
    }

    mCurrentContextMenuParams = params;

    view.setOnCreateContextMenuListener(this);
    if (view.showContextMenu()) {
        WebContents webContents = contentViewCore.getWebContents();
        RecordHistogram.recordBooleanHistogram(
                "ContextMenu.Shown", webContents != null);
    }
}
 
Example 3
Source File: UIManagerAppCompat.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
public static void openOptionsMenu(final AppCompatActivity activity, final View view) {
    if (activity.getSupportActionBar().isShowing()) {
        activity.getSupportActionBar().openOptionsMenu();
    } else {
        view.showContextMenu();
    }
}
 
Example 4
Source File: Dialog.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * @see Activity#openContextMenu(View)
 */
public void openContextMenu(@NonNull View view) {
    view.showContextMenu();
}
 
Example 5
Source File: MusicListAdapter.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
    v.showContextMenu();
}
 
Example 6
Source File: ListViewAdapter.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
    v.showContextMenu();
}
 
Example 7
Source File: DragSortListViewAdapter.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
    v.showContextMenu();
}
 
Example 8
Source File: ContextMenuHelper.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Starts showing a context menu for {@code view} based on {@code params}.
 * @param contentViewCore The {@link ContentViewCore} to show the menu to.
 * @param params          The {@link ContextMenuParams} that indicate what menu items to show.
 */
@CalledByNative
private void showContextMenu(final ContentViewCore contentViewCore, ContextMenuParams params) {
    if (params.isFile()) return;
    View view = contentViewCore.getContainerView();
    final WindowAndroid windowAndroid = contentViewCore.getWindowAndroid();

    if (view == null || view.getVisibility() != View.VISIBLE || view.getParent() == null
            || windowAndroid == null || windowAndroid.getActivity().get() == null
            || mPopulator == null) {
        return;
    }

    mCurrentContextMenuParams = params;
    mActivity = windowAndroid.getActivity().get();
    mCallback = new Callback<Integer>() {
        @Override
        public void onResult(Integer result) {
            mPopulator.onItemSelected(
                    ContextMenuHelper.this, mCurrentContextMenuParams, result);
        }
    };
    mOnMenuShown = new Runnable() {
        @Override
        public void run() {
            WebContents webContents = contentViewCore.getWebContents();
            RecordHistogram.recordBooleanHistogram("ContextMenu.Shown", webContents != null);
        }
    };
    mOnMenuClosed = new Runnable() {
        @Override
        public void run() {
            if (mNativeContextMenuHelper == 0) return;
            nativeOnContextMenuClosed(mNativeContextMenuHelper);
        }
    };

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CUSTOM_CONTEXT_MENU)) {
        List<Pair<Integer, List<ContextMenuItem>>> items =
                mPopulator.buildContextMenu(null, mActivity, mCurrentContextMenuParams);
        if (items.isEmpty()) {
            ThreadUtils.postOnUiThread(mOnMenuClosed);
            return;
        }

        final ContextMenuUi menuUi = new TabularContextMenuUi(new Runnable() {
            @Override
            public void run() {
                shareImageDirectly(ShareHelper.getLastShareComponentName());
            }
        });
        menuUi.displayMenu(mActivity, mCurrentContextMenuParams, items, mCallback, mOnMenuShown,
                mOnMenuClosed);
        if (mCurrentContextMenuParams.isImage()) {
            getThumbnail(new Callback<Bitmap>() {
                @Override
                public void onResult(Bitmap result) {
                    ((TabularContextMenuUi) menuUi).onImageThumbnailRetrieved(result);
                }
            });
        }
        return;
    }

    // The Platform Context Menu requires the listener within this hepler since this helper and
    // provides context menu for us to show.
    view.setOnCreateContextMenuListener(this);
    if (view.showContextMenu()) {
        mOnMenuShown.run();
        windowAndroid.addContextMenuCloseListener(new OnCloseContextMenuListener() {
            @Override
            public void onContextMenuClosed() {
                mOnMenuClosed.run();
                windowAndroid.removeContextMenuCloseListener(this);
            }
        });
    }
}
 
Example 9
Source File: BrowserActionsContextMenuHelper.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void onViewAttachedToWindow(View view) {
    if (view.showContextMenu()) {
        mOnMenuShown.run();
    }
}
 
Example 10
Source File: Dialog.java    From PreferenceFragment with Apache License 2.0 4 votes vote down vote up
/**
 * @see Activity#openContextMenu(View)
 */
public void openContextMenu(View view) {
    view.showContextMenu();
}