org.chromium.chrome.browser.webapps.WebappDataStorage Java Examples

The following examples show how to use org.chromium.chrome.browser.webapps.WebappDataStorage. 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: ShortcutHelper.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Stores the specified bitmap as the splash screen for a web app.
 * @param id          ID of the web app which is storing data.
 * @param splashImage Image which should be displayed on the splash screen of
 *                    the web app. This can be null of there is no image to show.
 */
@SuppressWarnings("unused")
@CalledByNative
private static void storeWebappSplashImage(final String id, final Bitmap splashImage) {
    final WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorage(id);
    if (storage != null) {
        new AsyncTask<Void, Void, String>() {
            @Override
            protected String doInBackground(Void... args0) {
                return encodeBitmapAsString(splashImage);
            }

            @Override
            protected void onPostExecute(String encodedImage) {
                storage.updateSplashScreenImage(encodedImage);
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
 
Example #2
Source File: ShortcutHelper.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Stores the specified bitmap as the splash screen for a web app.
 * @param id          ID of the web app which is storing data.
 * @param splashImage Image which should be displayed on the splash screen of
 *                    the web app. This can be null of there is no image to show.
 */
@SuppressWarnings("unused")
@CalledByNative
private static void storeWebappSplashImage(final String id, final Bitmap splashImage) {
    final WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorage(id);
    if (storage != null) {
        new AsyncTask<Void, Void, String>() {
            @Override
            protected String doInBackground(Void... args0) {
                return encodeBitmapAsString(splashImage);
            }

            @Override
            protected void onPostExecute(String encodedImage) {
                storage.updateSplashScreenImage(encodedImage);
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
 
Example #3
Source File: ShortcutHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a storage location and stores the data for a web app using {@link WebappDataStorage}.
 * @param id          ID of the webapp which is storing data.
 * @param splashImage Image which should be displayed on the splash screen of
 *                    the webapp. This can be null of there is no image to show.
 */
@SuppressWarnings("unused")
@CalledByNative
private static void storeWebappSplashImage(final String id, final Bitmap splashImage) {
    WebappRegistry.getWebappDataStorage(ContextUtils.getApplicationContext(), id,
            new WebappRegistry.FetchWebappDataStorageCallback() {
                @Override
                public void onWebappDataStorageRetrieved(WebappDataStorage storage) {
                    if (storage == null) return;

                    storage.updateSplashScreenImage(splashImage);
                }

            });
}
 
Example #4
Source File: ShortcutHelper.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Adds home screen shortcut which opens in a {@link WebappActivity}. Creates web app
 * home screen shortcut and registers web app asynchronously. Calls
 * ShortcutHelper::OnWebappDataStored() when done.
 */
@SuppressWarnings("unused")
@CalledByNative
private static void addWebapp(final String id, final String url, final String scopeUrl,
        final String userTitle, final String name, final String shortName, final String iconUrl,
        final Bitmap icon, final int displayMode, final int orientation, final int source,
        final long themeColor, final long backgroundColor, final long callbackPointer) {
    new AsyncTask<Void, Void, Intent>() {
        @Override
        protected Intent doInBackground(Void... args0) {
            // Encoding {@link icon} as a string and computing the mac are expensive.

            Context context = ContextUtils.getApplicationContext();
            String nonEmptyScopeUrl =
                    TextUtils.isEmpty(scopeUrl) ? getScopeFromUrl(url) : scopeUrl;
            Intent shortcutIntent = createWebappShortcutIntent(id,
                    sDelegate.getFullscreenAction(), url, nonEmptyScopeUrl, name, shortName,
                    icon, WEBAPP_SHORTCUT_VERSION, displayMode, orientation, themeColor,
                    backgroundColor, iconUrl.isEmpty());
            shortcutIntent.putExtra(EXTRA_MAC, getEncodedMac(context, url));
            shortcutIntent.putExtra(EXTRA_SOURCE, source);
            shortcutIntent.setPackage(context.getPackageName());
            return shortcutIntent;
        }
        @Override
        protected void onPostExecute(final Intent resultIntent) {
            sDelegate.addShortcutToHomescreen(userTitle, icon, resultIntent);

            // Store the webapp data so that it is accessible without the intent. Once this
            // process is complete, call back to native code to start the splash image
            // download.
            WebappRegistry.getInstance().register(
                    id, new WebappRegistry.FetchWebappDataStorageCallback() {
                        @Override
                        public void onWebappDataStorageRetrieved(WebappDataStorage storage) {
                            storage.updateFromShortcutIntent(resultIntent);
                            nativeOnWebappDataStored(callbackPointer);
                        }
                    });
            if (shouldShowToastWhenAddingShortcut()) {
                showAddedToHomescreenToast(userTitle);
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}