Java Code Examples for org.chromium.chrome.browser.ChromeTabbedActivity#getClass()

The following examples show how to use org.chromium.chrome.browser.ChromeTabbedActivity#getClass() . 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: MultiWindowUtils.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Determines the correct ChromeTabbedActivity class to use for an incoming intent.
 * @param intent The incoming intent that is starting ChromeTabbedActivity.
 * @param context The current Context, used to retrieve the ActivityManager system service.
 * @return The ChromeTabbedActivity to use for the incoming intent.
 */
public Class<? extends ChromeTabbedActivity> getTabbedActivityForIntent(Intent intent,
        Context context) {
    // 1. Exit early if the build version doesn't support Android N+ multi-window mode or
    // ChromeTabbedActivity2 isn't running.
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M
            || (mTabbedActivity2TaskRunning != null && !mTabbedActivity2TaskRunning)) {
        return ChromeTabbedActivity.class;
    }

    // 2. If the intent has a window id set, use that.
    if (intent.hasExtra(IntentHandler.EXTRA_WINDOW_ID)) {
        int windowId = IntentUtils.safeGetIntExtra(intent, IntentHandler.EXTRA_WINDOW_ID, 0);
        if (windowId == 1) return ChromeTabbedActivity.class;
        if (windowId == 2) return ChromeTabbedActivity2.class;
    }

    // 3. If only one ChromeTabbedActivity is currently in Android recents, use it.
    boolean tabbed2TaskRunning = isActivityTaskInRecents(
            ChromeTabbedActivity2.class.getName(), context);

    // Exit early if ChromeTabbedActivity2 isn't running.
    if (!tabbed2TaskRunning) {
        mTabbedActivity2TaskRunning = false;
        return ChromeTabbedActivity.class;
    }

    boolean tabbedTaskRunning = isActivityTaskInRecents(
            ChromeTabbedActivity.class.getName(), context);
    if (!tabbedTaskRunning) {
        return ChromeTabbedActivity2.class;
    }

    // 4. If only one of the ChromeTabbedActivity's is currently visible use it.
    // e.g. ChromeTabbedActivity is docked to the top of the screen and another app is docked
    // to the bottom.

    // Find the activities.
    Activity tabbedActivity = null;
    Activity tabbedActivity2 = null;
    for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) {
        Activity activity = reference.get();
        if (activity == null) continue;
        if (activity.getClass().equals(ChromeTabbedActivity.class)) {
            tabbedActivity = activity;
        } else if (activity.getClass().equals(ChromeTabbedActivity2.class)) {
            tabbedActivity2 = activity;
        }
    }

    // Determine if only one is visible.
    boolean tabbedActivityVisible = isActivityVisible(tabbedActivity);
    boolean tabbedActivity2Visible = isActivityVisible(tabbedActivity2);
    if (tabbedActivityVisible ^ tabbedActivity2Visible) {
        if (tabbedActivityVisible) return ChromeTabbedActivity.class;
        return ChromeTabbedActivity2.class;
    }

    // 5. Use the ChromeTabbedActivity that was resumed most recently if it's still running.
    if (mLastResumedTabbedActivity != null) {
        ChromeTabbedActivity lastResumedActivity = mLastResumedTabbedActivity.get();
        if (lastResumedActivity != null) {
            Class<?> lastResumedClassName = lastResumedActivity.getClass();
            if (tabbedTaskRunning
                    && lastResumedClassName.equals(ChromeTabbedActivity.class)) {
                return ChromeTabbedActivity.class;
            }
            if (tabbed2TaskRunning
                    && lastResumedClassName.equals(ChromeTabbedActivity2.class)) {
                return ChromeTabbedActivity2.class;
            }
        }
    }

    // 6. Default to regular ChromeTabbedActivity.
    return ChromeTabbedActivity.class;
}
 
Example 2
Source File: MultiWindowUtils.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Determines the correct ChromeTabbedActivity class to use for an incoming intent.
 * @param intent The incoming intent that is starting ChromeTabbedActivity.
 * @param context The current Context, used to retrieve the ActivityManager system service.
 * @return The ChromeTabbedActivity to use for the incoming intent.
 */
public Class<? extends ChromeTabbedActivity> getTabbedActivityForIntent(Intent intent,
        Context context) {
    // 1. Exit early if the build version doesn't support Android N+ multi-window mode or
    // ChromeTabbedActivity2 isn't running.
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M
            || (mTabbedActivity2TaskRunning != null && !mTabbedActivity2TaskRunning)) {
        return ChromeTabbedActivity.class;
    }

    // 2. If the intent has a window id set, use that.
    if (intent.hasExtra(IntentHandler.EXTRA_WINDOW_ID)) {
        int windowId = IntentUtils.safeGetIntExtra(intent, IntentHandler.EXTRA_WINDOW_ID, 0);
        if (windowId == 1) return ChromeTabbedActivity.class;
        if (windowId == 2) return ChromeTabbedActivity2.class;
    }

    // 3. If only one ChromeTabbedActivity is currently in Android recents, use it.
    boolean tabbed2TaskRunning = isActivityTaskInRecents(
            ChromeTabbedActivity2.class.getName(), context);

    // Exit early if ChromeTabbedActivity2 isn't running.
    if (!tabbed2TaskRunning) {
        mTabbedActivity2TaskRunning = false;
        return ChromeTabbedActivity.class;
    }

    boolean tabbedTaskRunning = isActivityTaskInRecents(
            ChromeTabbedActivity.class.getName(), context);
    if (!tabbedTaskRunning) {
        return ChromeTabbedActivity2.class;
    }

    // 4. If only one of the ChromeTabbedActivity's is currently visible use it.
    // e.g. ChromeTabbedActivity is docked to the top of the screen and another app is docked
    // to the bottom.

    // Find the activities.
    Activity tabbedActivity = null;
    Activity tabbedActivity2 = null;
    for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) {
        Activity activity = reference.get();
        if (activity == null) continue;
        if (activity.getClass().equals(ChromeTabbedActivity.class)) {
            tabbedActivity = activity;
        } else if (activity.getClass().equals(ChromeTabbedActivity2.class)) {
            tabbedActivity2 = activity;
        }
    }

    // Determine if only one is visible.
    boolean tabbedActivityVisible = isActivityVisible(tabbedActivity);
    boolean tabbedActivity2Visible = isActivityVisible(tabbedActivity2);
    if (tabbedActivityVisible ^ tabbedActivity2Visible) {
        if (tabbedActivityVisible) return ChromeTabbedActivity.class;
        return ChromeTabbedActivity2.class;
    }

    // 5. Use the ChromeTabbedActivity that was resumed most recently if it's still running.
    if (mLastResumedTabbedActivity != null) {
        ChromeTabbedActivity lastResumedActivity = mLastResumedTabbedActivity.get();
        if (lastResumedActivity != null) {
            Class<?> lastResumedClassName = lastResumedActivity.getClass();
            if (tabbedTaskRunning
                    && lastResumedClassName.equals(ChromeTabbedActivity.class)) {
                return ChromeTabbedActivity.class;
            }
            if (tabbed2TaskRunning
                    && lastResumedClassName.equals(ChromeTabbedActivity2.class)) {
                return ChromeTabbedActivity2.class;
            }
        }
    }

    // 6. Default to regular ChromeTabbedActivity.
    return ChromeTabbedActivity.class;
}
 
Example 3
Source File: MultiWindowUtils.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Determines the correct ChromeTabbedActivity class to use for an incoming intent.
 * @param intent The incoming intent that is starting ChromeTabbedActivity.
 * @param context The current Context, used to retrieve the ActivityManager system service.
 * @return The ChromeTabbedActivity to use for the incoming intent.
 */
public Class<? extends ChromeTabbedActivity> getTabbedActivityForIntent(
        @Nullable Intent intent, Context context) {
    // 1. Exit early if the build version doesn't support Android N+ multi-window mode or
    // ChromeTabbedActivity2 isn't running.
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M
            || (mTabbedActivity2TaskRunning != null && !mTabbedActivity2TaskRunning)) {
        return ChromeTabbedActivity.class;
    }

    // 2. If the intent has a window id set, use that.
    if (intent != null && IntentUtils.safeHasExtra(intent, IntentHandler.EXTRA_WINDOW_ID)) {
        int windowId = IntentUtils.safeGetIntExtra(intent, IntentHandler.EXTRA_WINDOW_ID, 0);
        if (windowId == 1) return ChromeTabbedActivity.class;
        if (windowId == 2) return ChromeTabbedActivity2.class;
    }

    // 3. If only one ChromeTabbedActivity is currently in Android recents, use it.
    boolean tabbed2TaskRunning = isActivityTaskInRecents(
            ChromeTabbedActivity2.class.getName(), context);

    // Exit early if ChromeTabbedActivity2 isn't running.
    if (!tabbed2TaskRunning) {
        mTabbedActivity2TaskRunning = false;
        return ChromeTabbedActivity.class;
    }

    boolean tabbedTaskRunning = isActivityTaskInRecents(
            ChromeTabbedActivity.class.getName(), context);
    if (!tabbedTaskRunning) {
        return ChromeTabbedActivity2.class;
    }

    // 4. If only one of the ChromeTabbedActivity's is currently visible use it.
    // e.g. ChromeTabbedActivity is docked to the top of the screen and another app is docked
    // to the bottom.

    // Find the activities.
    Activity tabbedActivity = null;
    Activity tabbedActivity2 = null;
    for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) {
        Activity activity = reference.get();
        if (activity == null) continue;
        if (activity.getClass().equals(ChromeTabbedActivity.class)) {
            tabbedActivity = activity;
        } else if (activity.getClass().equals(ChromeTabbedActivity2.class)) {
            tabbedActivity2 = activity;
        }
    }

    // Determine if only one is visible.
    boolean tabbedActivityVisible = isActivityVisible(tabbedActivity);
    boolean tabbedActivity2Visible = isActivityVisible(tabbedActivity2);
    if (tabbedActivityVisible ^ tabbedActivity2Visible) {
        if (tabbedActivityVisible) return ChromeTabbedActivity.class;
        return ChromeTabbedActivity2.class;
    }

    // 5. Use the ChromeTabbedActivity that was resumed most recently if it's still running.
    if (mLastResumedTabbedActivity != null) {
        ChromeTabbedActivity lastResumedActivity = mLastResumedTabbedActivity.get();
        if (lastResumedActivity != null) {
            Class<?> lastResumedClassName = lastResumedActivity.getClass();
            if (tabbedTaskRunning
                    && lastResumedClassName.equals(ChromeTabbedActivity.class)) {
                return ChromeTabbedActivity.class;
            }
            if (tabbed2TaskRunning
                    && lastResumedClassName.equals(ChromeTabbedActivity2.class)) {
                return ChromeTabbedActivity2.class;
            }
        }
    }

    // 6. Default to regular ChromeTabbedActivity.
    return ChromeTabbedActivity.class;
}