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..6594f02ccf2705e73b09ad185878f5a99ec36379 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,6 +36,7 @@ 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.widget.RoundedIconGenerator; |
| import org.chromium.content_public.common.ScreenOrientationConstants; |
| @@ -42,10 +44,11 @@ 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 +118,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 +130,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 +166,19 @@ public class ShortcutHelper { |
| } |
| /** |
| + * Stores the webapp data inside WebappDataStorage for the specified webapp. |
|
gone
2015/09/01 18:33:51
nit: Stores data for a web app inside its {@link W
Lalit Maganti
2015/09/01 19:45:51
Done.
|
| + * @param context Context to open the WebappDataStorage with. |
| + * @param id ID of the webapp whose data is being updated. |
| + * @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) { |
| + 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 +294,43 @@ 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 |
|
gone
2015/09/01 18:33:51
nit: indent at 100
Lalit Maganti
2015/09/01 19:45:52
Done.
|
| + * 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); |
| + 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 +396,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); |
| - } |
| } |