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 ecb2acdea553ba595f9bc8bddd9d754555f935c8..3e13a9f5d757ed55bde58102fb6f473e97474489 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.Canvas; |
| import android.graphics.Color; |
| @@ -33,6 +34,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; |
| @@ -40,10 +42,10 @@ 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 is a helper class which has various utility functions related to adding |
| + * shortcuts (both webapps and non webapps) to homescreen. |
|
gone
2015/08/26 21:39:25
If you're going to change this class comment anywa
Lalit Maganti
2015/08/26 22:55:00
Done.
|
| */ |
| public class ShortcutHelper { |
| public static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp_icon"; |
| @@ -113,9 +115,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). |
| @@ -131,7 +133,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); |
| @@ -167,6 +169,19 @@ public class ShortcutHelper { |
| } |
| /** |
| + * Stores the webpp data inside WebappDataStorage for the specified webapp. |
|
gone
2015/08/26 21:39:25
Can you please do a typo pass before sending any C
Lalit Maganti
2015/08/26 22:55:00
:/
Will do.
|
| + * @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 splashscreen 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).update(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. |
| @@ -257,6 +272,43 @@ public class ShortcutHelper { |
| return bitmap; |
| } |
| + /** |
| + * Returns the ideal size that the website's icon which is displayed on the splashscreen |
| + * should have. |
|
gone
2015/08/26 21:39:25
"ideal" and "should have" are redundant. The comm
Lalit Maganti
2015/08/26 22:55:00
Changed as suggested.
|
| + * @param resources Resources to retrieve the dimenstion from. |
| + * @return the dimensions in dp which the icon should have. |
| + */ |
| + public static int getIdealSplashImageSizeInDp(Resources resources) { |
| + return getIdealSizeFromResource(resources, R.dimen.webapp_splash_image_size); |
| + } |
| + |
| + /** |
| + * Returns the ideal size that the website's icon which is displayed on the homescreen |
| + * and app banners should have. |
|
gone
2015/08/26 21:39:25
Same as above. Doesn't make sense.
Returns the i
Lalit Maganti
2015/08/26 22:55:00
Changed as suggested.
|
| + * @param resources Resources to retrieve the dimenstion 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) { |
|
Lalit Maganti
2015/08/26 13:19:31
This was moved because it was actually below the p
|
| + // 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); |
| @@ -322,15 +374,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); |
| - } |
| } |