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

The following examples show how to use android.view.View#showContextMenu() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: delion   File: ContextMenuHelper.java    License: 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
/**
 * 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
public static void openOptionsMenu(final AppCompatActivity activity, final View view) {
    if (activity.getSupportActionBar().isShowing()) {
        activity.getSupportActionBar().openOptionsMenu();
    } else {
        view.showContextMenu();
    }
}
 
Example 4
Source Project: android_9.0.0_r45   File: Dialog.java    License: 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 Project: mobile-manager-tool   File: MusicListAdapter.java    License: MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
    v.showContextMenu();
}
 
Example 6
Source Project: mobile-manager-tool   File: ListViewAdapter.java    License: MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
    v.showContextMenu();
}
 
Example 7
@Override
public void onClick(View v) {
    v.showContextMenu();
}
 
Example 8
Source Project: 365browser   File: ContextMenuHelper.java    License: 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
@Override
public void onViewAttachedToWindow(View view) {
    if (view.showContextMenu()) {
        mOnMenuShown.run();
    }
}
 
Example 10
Source Project: PreferenceFragment   File: Dialog.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @see Activity#openContextMenu(View)
 */
public void openContextMenu(View view) {
    view.showContextMenu();
}