Java Code Examples for org.chromium.chrome.browser.util.IntentUtils#safeGetParcelable()

The following examples show how to use org.chromium.chrome.browser.util.IntentUtils#safeGetParcelable() . 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: CustomTabsConnection.java    From delion with Apache License 2.0 6 votes vote down vote up
private boolean preconnectUrls(List<Bundle> likelyBundles) {
    boolean atLeastOneUrl = false;
    if (likelyBundles == null) return false;
    WarmupManager warmupManager = WarmupManager.getInstance();
    Profile profile = Profile.getLastUsedProfile();
    for (Bundle bundle : likelyBundles) {
        Uri uri;
        try {
            uri = IntentUtils.safeGetParcelable(bundle, CustomTabsService.KEY_URL);
        } catch (ClassCastException e) {
            continue;
        }
        String url = checkAndConvertUri(uri);
        if (url != null) {
            warmupManager.maybePreconnectUrlAndSubResources(profile, url);
            atLeastOneUrl = true;
        }
    }
    return atLeastOneUrl;
}
 
Example 2
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private boolean preconnectUrls(List<Bundle> likelyBundles) {
    boolean atLeastOneUrl = false;
    if (likelyBundles == null) return false;
    WarmupManager warmupManager = WarmupManager.getInstance();
    Profile profile = Profile.getLastUsedProfile();
    for (Bundle bundle : likelyBundles) {
        Uri uri;
        try {
            uri = IntentUtils.safeGetParcelable(bundle, CustomTabsService.KEY_URL);
        } catch (ClassCastException e) {
            continue;
        }
        String url = checkAndConvertUri(uri);
        if (url != null) {
            warmupManager.maybePreconnectUrlAndSubResources(profile, url);
            atLeastOneUrl = true;
        }
    }
    return atLeastOneUrl;
}
 
Example 3
Source File: CustomTabsConnection.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private boolean preconnectUrls(List<Bundle> likelyBundles) {
    boolean atLeastOneUrl = false;
    if (likelyBundles == null) return false;
    WarmupManager warmupManager = WarmupManager.getInstance();
    Profile profile = Profile.getLastUsedProfile();
    for (Bundle bundle : likelyBundles) {
        Uri uri;
        try {
            uri = IntentUtils.safeGetParcelable(bundle, CustomTabsService.KEY_URL);
        } catch (ClassCastException e) {
            continue;
        }
        String url = checkAndConvertUri(uri);
        if (url != null) {
            warmupManager.maybePreconnectUrlAndSubResources(profile, url);
            atLeastOneUrl = true;
        }
    }
    return atLeastOneUrl;
}
 
Example 4
Source File: BrowserActionActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Gets custom item list for browser action menu.
 * @param bundles Data for custom items from {@link BrowserActionsIntent}.
 */
private void parseBrowserActionItems(ArrayList<Bundle> bundles) {
    for (int i = 0; i < bundles.size(); i++) {
        Bundle bundle = bundles.get(i);
        String title = IntentUtils.safeGetString(bundle, BrowserActionsIntent.KEY_TITLE);
        PendingIntent action =
                IntentUtils.safeGetParcelable(bundle, BrowserActionsIntent.KEY_ACTION);
        Bitmap icon = IntentUtils.safeGetParcelable(bundle, BrowserActionsIntent.KEY_ICON);
        if (title != null && action != null) {
            BrowserActionItem item = new BrowserActionItem(title, action);
            if (icon != null) {
                item.setIcon(icon);
            }
            mActions.add(item);
        } else if (title != null) {
            Log.e(TAG, "Missing action for item: " + i);
        } else if (action != null) {
            Log.e(TAG, "Missing title for item: " + i);
        } else {
            Log.e(TAG, "Missing title and action for item: " + i);
        }
    }
}
 
Example 5
Source File: CustomButtonParams.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @return The bitmap contained in the given {@link Bundle}. Will return null if input is
 *         invalid.
 */
static Bitmap parseBitmapFromBundle(Bundle bundle) {
    if (bundle == null) return null;
    Bitmap bitmap = IntentUtils.safeGetParcelable(bundle, CustomTabsIntent.KEY_ICON);
    if (bitmap == null) return null;
    return bitmap;
}
 
Example 6
Source File: CustomButtonParams.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return The bitmap contained in the given {@link Bundle}. Will return null if input is
 *         invalid.
 */
static Bitmap parseBitmapFromBundle(Bundle bundle) {
    if (bundle == null) return null;
    Bitmap bitmap = IntentUtils.safeGetParcelable(bundle, CustomTabsIntent.KEY_ICON);
    if (bitmap == null) return null;
    return bitmap;
}
 
Example 7
Source File: CustomButtonParams.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return The bitmap contained in the given {@link Bundle}. Will return null if input is
 *         invalid.
 */
static Bitmap parseBitmapFromBundle(Bundle bundle) {
    if (bundle == null) return null;
    Bitmap bitmap = IntentUtils.safeGetParcelable(bundle, CustomTabsIntent.KEY_ICON);
    if (bitmap == null) return null;
    return bitmap;
}
 
Example 8
Source File: CustomButtonParams.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Parses params out of a bundle. Note if a custom button contains a bitmap that does not fit
 * into the toolbar, it will be put to the bottom bar.
 * @param fromList Whether the bundle is contained in a list or it is the single bundle that
 *                 directly comes from the intent.
 */
private static CustomButtonParams fromBundle(Context context, Bundle bundle, boolean tinted,
        boolean fromList) {
    if (bundle == null) return null;

    if (fromList && !bundle.containsKey(CustomTabsIntent.KEY_ID)) return null;
    int id = IntentUtils.safeGetInt(bundle, CustomTabsIntent.KEY_ID,
            CustomTabsIntent.TOOLBAR_ACTION_BUTTON_ID);

    Bitmap bitmap = parseBitmapFromBundle(bundle);
    if (bitmap == null) {
        Log.e(TAG, "Invalid action button: bitmap not present in bundle!");
        return null;
    }

    String description = parseDescriptionFromBundle(bundle);
    if (TextUtils.isEmpty(description)) {
        Log.e(TAG, "Invalid action button: content description not present in bundle!");
        bitmap.recycle();
        return null;
    }

    boolean onToolbar = id == CustomTabsIntent.TOOLBAR_ACTION_BUTTON_ID;
    if (onToolbar && !doesIconFitToolbar(context, bitmap)) {
        onToolbar = false;
        Log.w(TAG, "Button's icon not suitable for toolbar, putting it to bottom bar instead."
                + "See: https://developer.android.com/reference/android/support/customtabs/"
                + "CustomTabsIntent.html#KEY_ICON");
    }

    PendingIntent pendingIntent = IntentUtils.safeGetParcelable(bundle,
            CustomTabsIntent.KEY_PENDING_INTENT);
    // PendingIntent is a must for buttons on the toolbar, but it's optional for bottom bar.
    if (onToolbar && pendingIntent == null) {
        Log.w(TAG, "Invalid action button on toolbar: pending intent not present in bundle!");
        bitmap.recycle();
        return null;
    }

    return new CustomButtonParams(id, bitmap, description, pendingIntent, tinted, onToolbar);
}
 
Example 9
Source File: CustomButtonParams.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Parses params out of a bundle. Note if a custom button contains a bitmap that does not fit
 * into the toolbar, it will be put to the bottom bar.
 * @param fromList Whether the bundle is contained in a list or it is the single bundle that
 *                 directly comes from the intent.
 */
private static CustomButtonParams fromBundle(Context context, Bundle bundle, boolean tinted,
        boolean fromList) {
    if (bundle == null) return null;

    if (fromList && !bundle.containsKey(CustomTabsIntent.KEY_ID)) return null;
    int id = IntentUtils.safeGetInt(bundle, CustomTabsIntent.KEY_ID,
            CustomTabsIntent.TOOLBAR_ACTION_BUTTON_ID);

    Bitmap bitmap = parseBitmapFromBundle(bundle);
    if (bitmap == null) {
        Log.e(TAG, "Invalid action button: bitmap not present in bundle!");
        return null;
    }

    String description = parseDescriptionFromBundle(bundle);
    if (TextUtils.isEmpty(description)) {
        Log.e(TAG, "Invalid action button: content description not present in bundle!");
        removeBitmapFromBundle(bundle);
        bitmap.recycle();
        return null;
    }

    boolean onToolbar = id == CustomTabsIntent.TOOLBAR_ACTION_BUTTON_ID;
    if (onToolbar && !doesIconFitToolbar(context, bitmap)) {
        onToolbar = false;
        Log.w(TAG, "Button's icon not suitable for toolbar, putting it to bottom bar instead."
                + "See: https://developer.android.com/reference/android/support/customtabs/"
                + "CustomTabsIntent.html#KEY_ICON");
    }

    PendingIntent pendingIntent = IntentUtils.safeGetParcelable(bundle,
            CustomTabsIntent.KEY_PENDING_INTENT);
    // PendingIntent is a must for buttons on the toolbar, but it's optional for bottom bar.
    if (onToolbar && pendingIntent == null) {
        Log.w(TAG, "Invalid action button on toolbar: pending intent not present in bundle!");
        removeBitmapFromBundle(bundle);
        bitmap.recycle();
        return null;
    }

    return new CustomButtonParams(id, bitmap, description, pendingIntent, tinted, onToolbar);
}
 
Example 10
Source File: CustomButtonParams.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Parses params out of a bundle. Note if a custom button contains a bitmap that does not fit
 * into the toolbar, it will be put to the bottom bar.
 * @param fromList Whether the bundle is contained in a list or it is the single bundle that
 *                 directly comes from the intent.
 */
private static CustomButtonParams fromBundle(Context context, Bundle bundle, boolean tinted,
        boolean fromList) {
    if (bundle == null) return null;

    if (fromList && !bundle.containsKey(CustomTabsIntent.KEY_ID)) return null;
    int id = IntentUtils.safeGetInt(bundle, CustomTabsIntent.KEY_ID,
            CustomTabsIntent.TOOLBAR_ACTION_BUTTON_ID);

    Bitmap bitmap = parseBitmapFromBundle(bundle);
    if (bitmap == null) {
        Log.e(TAG, "Invalid action button: bitmap not present in bundle!");
        return null;
    }

    String description = parseDescriptionFromBundle(bundle);
    if (TextUtils.isEmpty(description)) {
        Log.e(TAG, "Invalid action button: content description not present in bundle!");
        removeBitmapFromBundle(bundle);
        bitmap.recycle();
        return null;
    }

    boolean onToolbar = id == CustomTabsIntent.TOOLBAR_ACTION_BUTTON_ID;
    if (onToolbar && !doesIconFitToolbar(context, bitmap)) {
        onToolbar = false;
        Log.w(TAG, "Button's icon not suitable for toolbar, putting it to bottom bar instead."
                + "See: https://developer.android.com/reference/android/support/customtabs/"
                + "CustomTabsIntent.html#KEY_ICON");
    }

    PendingIntent pendingIntent = IntentUtils.safeGetParcelable(bundle,
            CustomTabsIntent.KEY_PENDING_INTENT);
    // PendingIntent is a must for buttons on the toolbar, but it's optional for bottom bar.
    if (onToolbar && pendingIntent == null) {
        Log.w(TAG, "Invalid action button on toolbar: pending intent not present in bundle!");
        removeBitmapFromBundle(bundle);
        bitmap.recycle();
        return null;
    }

    return new CustomButtonParams(id, bitmap, description, pendingIntent, tinted, onToolbar);
}