Java Code Examples for org.chromium.chrome.browser.ShortcutHelper#WEBAPP_SHORTCUT_VERSION

The following examples show how to use org.chromium.chrome.browser.ShortcutHelper#WEBAPP_SHORTCUT_VERSION . 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: WebappDataStorage.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the data stored in this object to match that in the supplied intent.
 * @param shortcutIntent The intent to pull web app data from.
 */
public void updateFromShortcutIntent(Intent shortcutIntent) {
    if (shortcutIntent == null) return;

    SharedPreferences.Editor editor = mPreferences.edit();
    boolean updated = false;

    // The URL and scope may have been deleted by the user clearing their history. Check whether
    // they are present, and update if necessary.
    String url = mPreferences.getString(KEY_URL, URL_INVALID);
    if (url.equals(URL_INVALID)) {
        url = IntentUtils.safeGetStringExtra(shortcutIntent, ShortcutHelper.EXTRA_URL);
        editor.putString(KEY_URL, url);
        updated = true;
    }

    if (mPreferences.getString(KEY_SCOPE, URL_INVALID).equals(URL_INVALID)) {
        String scope = IntentUtils.safeGetStringExtra(
                shortcutIntent, ShortcutHelper.EXTRA_SCOPE);
        if (scope == null) {
            scope = ShortcutHelper.getScopeFromUrl(url);
        }
        editor.putString(KEY_SCOPE, scope);
        updated = true;
    }

    // For all other fields, assume that if the version key is present and equal to
    // ShortcutHelper.WEBAPP_SHORTCUT_VERSION, then all fields are present and do not need to be
    // updated. All fields except for the last used time, scope, and URL are either set or
    // cleared together.
    if (mPreferences.getInt(KEY_VERSION, VERSION_INVALID)
            != ShortcutHelper.WEBAPP_SHORTCUT_VERSION) {
        editor.putString(KEY_NAME, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_NAME));
        editor.putString(KEY_SHORT_NAME, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_SHORT_NAME));
        editor.putString(KEY_ICON, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_ICON));
        editor.putInt(KEY_VERSION, ShortcutHelper.WEBAPP_SHORTCUT_VERSION);

        // "Standalone" was the original assumed default for all web apps.
        editor.putInt(KEY_DISPLAY_MODE, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_DISPLAY_MODE,
                    WebDisplayMode.Standalone));
        editor.putInt(KEY_ORIENTATION, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_ORIENTATION,
                    ScreenOrientationValues.DEFAULT));
        editor.putLong(KEY_THEME_COLOR, IntentUtils.safeGetLongExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_THEME_COLOR,
                    ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING));
        editor.putLong(KEY_BACKGROUND_COLOR, IntentUtils.safeGetLongExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_BACKGROUND_COLOR,
                    ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING));
        editor.putBoolean(KEY_IS_ICON_GENERATED, IntentUtils.safeGetBooleanExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_IS_ICON_GENERATED, false));
        editor.putString(KEY_ACTION, shortcutIntent.getAction());
        editor.putInt(KEY_SOURCE, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_SOURCE,
                    ShortcutSource.UNKNOWN));
        updated = true;
    }
    if (updated) editor.apply();
}
 
Example 2
Source File: WebappDataStorage.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the data stored in this object to match that in the supplied intent.
 * @param shortcutIntent The intent to pull web app data from.
 */
public void updateFromShortcutIntent(Intent shortcutIntent) {
    if (shortcutIntent == null) return;

    SharedPreferences.Editor editor = mPreferences.edit();
    boolean updated = false;

    // The URL and scope may have been deleted by the user clearing their history. Check whether
    // they are present, and update if necessary.
    String url = mPreferences.getString(KEY_URL, URL_INVALID);
    if (url.equals(URL_INVALID)) {
        url = IntentUtils.safeGetStringExtra(shortcutIntent, ShortcutHelper.EXTRA_URL);
        editor.putString(KEY_URL, url);
        updated = true;
    }

    if (mPreferences.getString(KEY_SCOPE, URL_INVALID).equals(URL_INVALID)) {
        String scope = IntentUtils.safeGetStringExtra(
                shortcutIntent, ShortcutHelper.EXTRA_SCOPE);
        if (scope == null) {
            scope = ShortcutHelper.getScopeFromUrl(url);
        }
        editor.putString(KEY_SCOPE, scope);
        updated = true;
    }

    // For all other fields, assume that if the version key is present and equal to
    // ShortcutHelper.WEBAPP_SHORTCUT_VERSION, then all fields are present and do not need to be
    // updated. All fields except for the last used time, scope, and URL are either set or
    // cleared together.
    if (mPreferences.getInt(KEY_VERSION, VERSION_INVALID)
            != ShortcutHelper.WEBAPP_SHORTCUT_VERSION) {
        editor.putString(KEY_NAME, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_NAME));
        editor.putString(KEY_SHORT_NAME, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_SHORT_NAME));
        editor.putString(KEY_ICON, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_ICON));
        editor.putInt(KEY_VERSION, ShortcutHelper.WEBAPP_SHORTCUT_VERSION);

        // "Standalone" was the original assumed default for all web apps.
        editor.putInt(KEY_DISPLAY_MODE, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_DISPLAY_MODE,
                    WebDisplayMode.Standalone));
        editor.putInt(KEY_ORIENTATION, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_ORIENTATION,
                    ScreenOrientationValues.DEFAULT));
        editor.putLong(KEY_THEME_COLOR, IntentUtils.safeGetLongExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_THEME_COLOR,
                    ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING));
        editor.putLong(KEY_BACKGROUND_COLOR, IntentUtils.safeGetLongExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_BACKGROUND_COLOR,
                    ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING));
        editor.putBoolean(KEY_IS_ICON_GENERATED, IntentUtils.safeGetBooleanExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_IS_ICON_GENERATED, false));
        editor.putString(KEY_ACTION, shortcutIntent.getAction());
        editor.putInt(KEY_SOURCE, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_SOURCE,
                    ShortcutSource.UNKNOWN));
        editor.putString(KEY_WEBAPK_PACKAGE_NAME, IntentUtils.safeGetStringExtra(
                shortcutIntent, ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME));
        updated = true;
    }
    if (updated) editor.apply();
}
 
Example 3
Source File: WebappDataStorage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the data stored in this object to match that in the supplied intent.
 * @param shortcutIntent The intent to pull web app data from.
 */
public void updateFromShortcutIntent(Intent shortcutIntent) {
    if (shortcutIntent == null) return;

    SharedPreferences.Editor editor = mPreferences.edit();
    boolean updated = false;

    // The URL and scope may have been deleted by the user clearing their history. Check whether
    // they are present, and update if necessary.
    String url = mPreferences.getString(KEY_URL, URL_INVALID);
    if (url.equals(URL_INVALID)) {
        url = IntentUtils.safeGetStringExtra(shortcutIntent, ShortcutHelper.EXTRA_URL);
        editor.putString(KEY_URL, url);
        updated = true;
    }

    if (mPreferences.getString(KEY_SCOPE, URL_INVALID).equals(URL_INVALID)) {
        String scope = IntentUtils.safeGetStringExtra(
                shortcutIntent, ShortcutHelper.EXTRA_SCOPE);
        if (scope == null) {
            scope = ShortcutHelper.getScopeFromUrl(url);
        }
        editor.putString(KEY_SCOPE, scope);
        updated = true;
    }

    // For all other fields, assume that if the version key is present and equal to
    // ShortcutHelper.WEBAPP_SHORTCUT_VERSION, then all fields are present and do not need to be
    // updated. All fields except for the last used time, scope, and URL are either set or
    // cleared together.
    if (mPreferences.getInt(KEY_VERSION, VERSION_INVALID)
            != ShortcutHelper.WEBAPP_SHORTCUT_VERSION) {
        editor.putString(KEY_NAME, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_NAME));
        editor.putString(KEY_SHORT_NAME, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_SHORT_NAME));
        editor.putString(KEY_ICON, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_ICON));
        editor.putInt(KEY_VERSION, ShortcutHelper.WEBAPP_SHORTCUT_VERSION);

        // "Standalone" was the original assumed default for all web apps.
        editor.putInt(KEY_DISPLAY_MODE,
                IntentUtils.safeGetIntExtra(shortcutIntent, ShortcutHelper.EXTRA_DISPLAY_MODE,
                        WebDisplayMode.STANDALONE));
        editor.putInt(KEY_ORIENTATION, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_ORIENTATION,
                    ScreenOrientationValues.DEFAULT));
        editor.putLong(KEY_THEME_COLOR, IntentUtils.safeGetLongExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_THEME_COLOR,
                    ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING));
        editor.putLong(KEY_BACKGROUND_COLOR, IntentUtils.safeGetLongExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_BACKGROUND_COLOR,
                    ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING));
        editor.putBoolean(KEY_IS_ICON_GENERATED, IntentUtils.safeGetBooleanExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_IS_ICON_GENERATED, false));
        editor.putString(KEY_ACTION, shortcutIntent.getAction());

        String webApkPackageName = IntentUtils.safeGetStringExtra(
                shortcutIntent, WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME);
        editor.putString(KEY_WEBAPK_PACKAGE_NAME, webApkPackageName);

        if (TextUtils.isEmpty(webApkPackageName)) {
            editor.putInt(KEY_SOURCE,
                    IntentUtils.safeGetIntExtra(shortcutIntent, ShortcutHelper.EXTRA_SOURCE,
                            ShortcutSource.UNKNOWN));
        }
        updated = true;
    }
    if (updated) editor.apply();
}