Search in sources :

Example 1 with CustomTabActivity

use of org.chromium.chrome.browser.customtabs.CustomTabActivity in project AndroidChromium by JackyAndroid.

the class Tab method createBringTabToFrontIntent.

/**
     * @return Intent that tells Chrome to bring an Activity for a particular Tab back to the
     *         foreground, or null if this isn't possible.
     */
@Nullable
public static Intent createBringTabToFrontIntent(int tabId) {
    // Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a
    // {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded.
    List<WeakReference<Activity>> list = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> ref : list) {
        Activity activity = ref.get();
        if (activity instanceof CustomTabActivity && ((CustomTabActivity) activity).getActivityTab() != null && tabId == ((CustomTabActivity) activity).getActivityTab().getId()) {
            return null;
        }
    }
    String packageName = ContextUtils.getApplicationContext().getPackageName();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, packageName);
    intent.putExtra(TabOpenType.BRING_TAB_TO_FRONT.name(), tabId);
    intent.setPackage(packageName);
    return intent;
}
Also used : WeakReference(java.lang.ref.WeakReference) ChromeLauncherActivity(org.chromium.chrome.browser.document.ChromeLauncherActivity) ChromeActivity(org.chromium.chrome.browser.ChromeActivity) CustomTabActivity(org.chromium.chrome.browser.customtabs.CustomTabActivity) Activity(android.app.Activity) CustomTabActivity(org.chromium.chrome.browser.customtabs.CustomTabActivity) Intent(android.content.Intent) Nullable(android.support.annotation.Nullable)

Example 2 with CustomTabActivity

use of org.chromium.chrome.browser.customtabs.CustomTabActivity in project AndroidChromium by JackyAndroid.

the class ChromeLauncherActivity method createCustomTabActivityIntent.

/**
     * Creates an Intent that can be used to launch a {@link CustomTabActivity}.
     */
public static Intent createCustomTabActivityIntent(Context context, Intent intent, boolean addHerbExtras) {
    // Use the copy constructor to carry over the myriad of extras.
    Uri uri = Uri.parse(IntentHandler.getUrlFromIntent(intent));
    Intent newIntent = new Intent(intent);
    newIntent.setAction(Intent.ACTION_VIEW);
    newIntent.setClassName(context, CustomTabActivity.class.getName());
    newIntent.setData(uri);
    // so explicitly remove it to ensure the CCT does not get lost in recents.
    if ((newIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0 || (newIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) {
        newIntent.setFlags(newIntent.getFlags() & ~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    }
    if (addHerbExtras) {
        // TODO(tedchoc|mariakhomenko): Specifically not marking the intent is from Chrome via
        //                              IntentHandler.addTrustedIntentExtras as it breaks the
        //                              redirect logic for triggering instant apps.  See if
        //                              this is better addressed in TabRedirectHandler long
        //                              term.
        newIntent.putExtra(CustomTabIntentDataProvider.EXTRA_IS_OPENED_BY_CHROME, true);
    } else {
        IntentUtils.safeRemoveExtra(intent, CustomTabIntentDataProvider.EXTRA_IS_OPENED_BY_CHROME);
    }
    if (addHerbExtras)
        updateHerbIntent(context, newIntent);
    return newIntent;
}
Also used : CustomTabActivity(org.chromium.chrome.browser.customtabs.CustomTabActivity) SeparateTaskCustomTabActivity(org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) Uri(android.net.Uri)

Aggregations

Intent (android.content.Intent)2 CustomTabActivity (org.chromium.chrome.browser.customtabs.CustomTabActivity)2 Activity (android.app.Activity)1 Uri (android.net.Uri)1 Nullable (android.support.annotation.Nullable)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 WeakReference (java.lang.ref.WeakReference)1 ChromeActivity (org.chromium.chrome.browser.ChromeActivity)1 SeparateTaskCustomTabActivity (org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity)1 ChromeLauncherActivity (org.chromium.chrome.browser.document.ChromeLauncherActivity)1