Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
| index e274e12fdfd6a1d426085a661718498a8d8be92e..6dee18f257b075125406aca2ace5fc62648a8549 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
| @@ -9,6 +9,7 @@ import android.content.Context; |
| import android.content.Intent; |
| import android.content.pm.PackageManager; |
| import android.content.pm.ResolveInfo; |
| +import android.content.res.Resources; |
| import android.graphics.Bitmap; |
| import android.graphics.BitmapFactory; |
| import android.graphics.Canvas; |
| @@ -35,17 +36,20 @@ import org.chromium.base.Log; |
| import org.chromium.base.VisibleForTesting; |
| import org.chromium.base.annotations.CalledByNative; |
| import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.webapps.WebappDataStorage; |
| import org.chromium.chrome.browser.webapps.WebappLauncherActivity; |
| +import org.chromium.chrome.browser.webapps.WebappRegistry; |
| import org.chromium.chrome.browser.widget.RoundedIconGenerator; |
| import org.chromium.content_public.common.ScreenOrientationConstants; |
| import org.chromium.ui.widget.Toast; |
| import java.io.ByteArrayOutputStream; |
| import java.util.List; |
| -import java.util.UUID; |
| /** |
| - * This is a helper class to create shortcuts on the Android home screen. |
| + * This class contains functions related to adding shortcuts to the Android Home |
| + * screen. These shortcuts are used to either open a page in the main browser |
| + * or open a web app. |
| */ |
| public class ShortcutHelper { |
| public static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp_icon"; |
| @@ -115,9 +119,9 @@ public class ShortcutHelper { |
| */ |
| @SuppressWarnings("unused") |
| @CalledByNative |
| - private static void addShortcut(Context context, String url, String userTitle, String name, |
| - String shortName, Bitmap icon, boolean isWebappCapable, int orientation, int source, |
| - long themeColor, long backgroundColor) { |
| + private static void addShortcut(Context context, String id, String url, String userTitle, |
| + String name, String shortName, Bitmap icon, boolean isWebappCapable, int orientation, |
| + int source, long themeColor, long backgroundColor) { |
| Intent shortcutIntent; |
| if (isWebappCapable) { |
| // Encode the icon as a base64 string (Launcher drops Bitmaps in the Intent). |
| @@ -127,7 +131,7 @@ public class ShortcutHelper { |
| shortcutIntent = new Intent(); |
| shortcutIntent.setAction(sDelegate.getFullscreenAction()); |
| shortcutIntent.putExtra(EXTRA_ICON, encodedIcon); |
| - shortcutIntent.putExtra(EXTRA_ID, UUID.randomUUID().toString()); |
| + shortcutIntent.putExtra(EXTRA_ID, id); |
| shortcutIntent.putExtra(EXTRA_NAME, name); |
| shortcutIntent.putExtra(EXTRA_SHORT_NAME, shortName); |
| shortcutIntent.putExtra(EXTRA_URL, url); |
| @@ -163,6 +167,20 @@ public class ShortcutHelper { |
| } |
| /** |
| + * Stores data for a web app inside its {@link WebappDataStorage}. |
| + * @param context Context to open the WebappDataStorage with. |
| + * @param id ID of the webapp whose data is being updated. |
|
mlamouri (slow - plz ping)
2015/09/02 16:56:57
I don't think the data is being updated.
Lalit Maganti
2015/09/02 17:15:42
Changed to match what you suggest elsewhere.
|
| + * @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 storeWebappData(Context context, String id, Bitmap splashImage) { |
| + WebappRegistry.registerWebapp(context, id); |
| + WebappDataStorage.open(context, id).updateSplashScreenImage(splashImage); |
| + } |
| + |
| + /** |
| * Creates an intent that will add a shortcut to the home screen. |
| * @param shortcutIntent Intent to fire when the shortcut is activated. |
| * @param url URL of the shortcut. |
| @@ -278,6 +296,42 @@ public class ShortcutHelper { |
| return BitmapFactory.decodeByteArray(decoded, 0, decoded.length); |
| } |
| + /** |
| + * Returns the ideal size for an image displayed on a web app's splash screen. |
| + * @param resources Resources to retrieve the dimension from. |
| + * @return the dimensions in dp which the image should have. |
| + */ |
| + public static int getIdealSplashImageSizeInDp(Resources resources) { |
| + return getIdealSizeFromResource(resources, R.dimen.webapp_splash_image_size); |
| + } |
| + |
| + /** |
| + * Returns the ideal size for an icon representing a web app. This size is used on app banners, |
| + * the Android Home screen, and in Android's recent tasks list, among other places. |
| + * @param resources Resources to retrieve the dimension from. |
| + * @return the dimensions in dp which the icon should have. |
| + */ |
| + public static int getIdealIconSizeInDp(Resources resources) { |
| + return getIdealSizeFromResource(resources, R.dimen.app_banner_icon_size); |
| + } |
| + |
| + /** |
| + * @return String that can be used to verify that a WebappActivity is being started by Chrome. |
| + */ |
| + public static String getEncodedMac(Context context, String url) { |
| + // The only reason we convert to a String here is because Android inexplicably eats a |
| + // byte[] when adding the shortcut -- the Bundle received by the launched Activity even |
| + // lacks the key for the extra. |
| + byte[] mac = WebappAuthenticator.getMacForUrl(context, url); |
| + return Base64.encodeToString(mac, Base64.DEFAULT); |
| + } |
| + |
| + private static int getIdealSizeFromResource(Resources resources, int resource) { |
| + int splashSizePx = resources.getDimensionPixelSize(resource); |
|
mlamouri (slow - plz ping)
2015/09/02 16:56:57
nit: "int sizeInPx = ";
Lalit Maganti
2015/09/02 17:15:42
Done.
|
| + float density = resources.getDisplayMetrics().density; |
| + return (int) (splashSizePx / density); |
| + } |
| + |
| private static Bitmap getBitmapFromResourceId(Context context, int id, int density) { |
| Drawable drawable = ApiCompatibilityUtils.getDrawableForDensity( |
| context.getResources(), id, density); |
| @@ -343,15 +397,4 @@ public class ShortcutHelper { |
| canvas.drawBitmap(icon, iconBounds.exactCenterX() - icon.getWidth() / 2.0f, |
| iconBounds.exactCenterY() - icon.getHeight() / 2.0f, null); |
| } |
| - |
| - /** |
| - * @return String that can be used to verify that a WebappActivity is being started by Chrome. |
| - */ |
| - public static String getEncodedMac(Context context, String url) { |
| - // The only reason we convert to a String here is because Android inexplicably eats a |
| - // byte[] when adding the shortcut -- the Bundle received by the launched Activity even |
| - // lacks the key for the extra. |
| - byte[] mac = WebappAuthenticator.getMacForUrl(context, url); |
| - return Base64.encodeToString(mac, Base64.DEFAULT); |
| - } |
| } |