Java Code Examples for org.chromium.ui.base.WindowAndroid#activityFromContext()

The following examples show how to use org.chromium.ui.base.WindowAndroid#activityFromContext() . 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: Tab.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @return {@link ChromeActivity} that currently contains this {@link Tab} in its
 *         {@link TabModel}.
 */
ChromeActivity getActivity() {
    Activity activity = WindowAndroid.activityFromContext(
            getWindowAndroid().getContext().get());
    if (activity instanceof ChromeActivity) return (ChromeActivity) activity;
    return null;
}
 
Example 2
Source File: ExternalNavigationDelegateImpl.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Get a {@link Context} linked to this delegate with preference to {@link Activity}.
 * The tab this delegate associates with can swap the {@link Activity} it is hosted in and
 * during the swap, there might not be an available {@link Activity}.
 * @return The activity {@link Context} if it can be reached.
 *         Application {@link Context} if not.
 */
protected final Context getAvailableContext() {
    if (mTab.getWindowAndroid() == null) return mApplicationContext;
    Context activityContext = WindowAndroid.activityFromContext(
            mTab.getWindowAndroid().getContext().get());
    if (activityContext == null) return mApplicationContext;
    return activityContext;
}
 
Example 3
Source File: Tab.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return {@link ChromeActivity} that currently contains this {@link Tab} in its
 *         {@link TabModel}.
 */
ChromeActivity getActivity() {
    if (getWindowAndroid() == null) return null;
    Activity activity = WindowAndroid.activityFromContext(
            getWindowAndroid().getContext().get());
    if (activity instanceof ChromeActivity) return (ChromeActivity) activity;
    return null;
}
 
Example 4
Source File: ExternalNavigationDelegateImpl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Get a {@link Context} linked to this delegate with preference to {@link Activity}.
 * The tab this delegate associates with can swap the {@link Activity} it is hosted in and
 * during the swap, there might not be an available {@link Activity}.
 * @return The activity {@link Context} if it can be reached.
 *         Application {@link Context} if not.
 */
protected final Context getAvailableContext() {
    if (mTab.getWindowAndroid() == null) return mApplicationContext;
    Context activityContext = WindowAndroid.activityFromContext(
            mTab.getWindowAndroid().getContext().get());
    if (activityContext == null) return mApplicationContext;
    return activityContext;
}
 
Example 5
Source File: VrDaydreamApiImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean exitFromVr(int requestCode, final Intent intent) {
    Activity activity = WindowAndroid.activityFromContext(mContext);
    Assert.assertNotNull(activity);
    DaydreamApi daydreamApi = DaydreamApi.create(activity);
    if (daydreamApi == null) return false;
    daydreamApi.exitFromVr(activity, requestCode, intent);
    daydreamApi.close();
    return true;
}
 
Example 6
Source File: Tab.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return {@link ChromeActivity} that currently contains this {@link Tab} in its
 *         {@link TabModel}.
 */
public ChromeActivity getActivity() {
    if (getWindowAndroid() == null) return null;
    Activity activity = WindowAndroid.activityFromContext(
            getWindowAndroid().getContext().get());
    if (activity instanceof ChromeActivity) return (ChromeActivity) activity;
    return null;
}
 
Example 7
Source File: ExternalNavigationDelegateImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Get a {@link Context} linked to this delegate with preference to {@link Activity}.
 * The tab this delegate associates with can swap the {@link Activity} it is hosted in and
 * during the swap, there might not be an available {@link Activity}.
 * @return The activity {@link Context} if it can be reached.
 *         Application {@link Context} if not.
 */
protected final Context getAvailableContext() {
    if (mTab.getWindowAndroid() == null) return mApplicationContext;
    Context activityContext = WindowAndroid.activityFromContext(
            mTab.getWindowAndroid().getContext().get());
    if (activityContext == null) return mApplicationContext;
    return activityContext;
}
 
Example 8
Source File: ColorChooserAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
public static ColorChooserAndroid createColorChooserAndroid(
        long nativeColorChooserAndroid,
        ContentViewCore contentViewCore,
        int initialColor,
        ColorSuggestion[] suggestions) {
    if (contentViewCore.getWindowAndroid() == null) return null;
    Context windowContext = contentViewCore.getWindowAndroid().getContext().get();
    if (WindowAndroid.activityFromContext(windowContext) == null) return null;
    ColorChooserAndroid chooser = new ColorChooserAndroid(nativeColorChooserAndroid,
            windowContext, initialColor, suggestions);
    chooser.openColorChooser();
    return chooser;
}
 
Example 9
Source File: ContentVideoView.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@CalledByNative
public void onMediaPlayerError(int errorType) {
    Log.d(TAG, "OnMediaPlayerError: %d", errorType);
    if (mCurrentState == STATE_ERROR) {
        return;
    }

    // Ignore some invalid error codes.
    if (errorType == MEDIA_ERROR_INVALID_CODE) {
        return;
    }

    mCurrentState = STATE_ERROR;

    if (WindowAndroid.activityFromContext(getContext()) == null) {
        Log.w(TAG, "Unable to show alert dialog because it requires an activity context");
        return;
    }

    /* Pop up an error dialog so the user knows that
     * something bad has happened. Only try and pop up the dialog
     * if we're attached to a window. When we're going away and no
     * longer have a window, don't bother showing the user an error.
     *
     * TODO(qinmin): We need to review whether this Dialog is OK with
     * the rest of the browser UI elements.
     */
    if (getWindowToken() != null) {
        String message;

        if (errorType == MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK) {
            message = mPlaybackErrorText;
        } else {
            message = mUnknownErrorText;
        }

        try {
            new AlertDialog.Builder(getContext())
                    .setTitle(mErrorTitle)
                    .setMessage(message)
                    .setPositiveButton(mErrorButton,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int whichButton) {}
                            })
                    .setCancelable(false)
                    .show();
        } catch (RuntimeException e) {
            Log.e(TAG, "Cannot show the alert dialog, error message: %s", message, e);
        }
    }
}