Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3514)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java

Issue 1308533006: webapps: allow callers of icon downloader/selector to specify a minimum size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webapps-splashscreen-icon
Patch Set: Fix non-compiling test Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 b3ea693de296e41db8b0d694e5d917cdb47f29e3..9a5caecf264221d764a9fa0134fc67bc03983410 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java
@@ -9,7 +9,6 @@ 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;
@@ -301,8 +300,19 @@ public class ShortcutHelper {
* @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);
+ @CalledByNative
+ public static int getIdealSplashImageSizeInDp(Context context) {
+ return getIdealSizeFromResource(context, R.dimen.webapp_splash_image_size);
+ }
+
+ /**
+ * Returns the minimum size for an image displayed on a web app's splash screen.
+ * @param resources Resources to retrieve the dimension from.
+ * @return the lower bound of the size which the image should have in dp.
+ */
+ @CalledByNative
+ public static int getMinimumSplashImageSizeInDp(Context context) {
+ return getIdealSizeFromResource(context, R.dimen.webapp_splash_image_min_size);
}
/**
@@ -311,8 +321,25 @@ public class ShortcutHelper {
* @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.webapp_home_screen_icon_size);
+ @CalledByNative
+ public static int getIdealIconSizeInDp(Context context) {
+ return getIdealSizeFromResource(context, R.dimen.webapp_home_screen_icon_size);
+ }
+
+ /**
+ * Returns the minimum 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 lower bound of the size which the icon should have in dp.
+ */
+ @CalledByNative
+ public static int getMinimumIconSizeInDp(Context context) {
+ int idealIconSizeInPx = context.getResources().getDimensionPixelSize(
+ R.dimen.webapp_home_screen_icon_size);
+ float density = context.getResources().getDisplayMetrics().density;
+ float idealIconSizeInDp = idealIconSizeInPx / density;
gone 2015/09/08 21:01:57 does it make sense to reuse part of getIdealSizeFr
Lalit Maganti 2015/09/11 13:06:00 It would have but not any more since I want to kee
+ float minimumIconSizeInPx = idealIconSizeInDp * (density - 1);
+ return (int) (minimumIconSizeInPx / density);
}
/**
@@ -326,9 +353,9 @@ public class ShortcutHelper {
return Base64.encodeToString(mac, Base64.DEFAULT);
}
- private static int getIdealSizeFromResource(Resources resources, int resource) {
- int sizeInPx = resources.getDimensionPixelSize(resource);
- float density = resources.getDisplayMetrics().density;
+ private static int getIdealSizeFromResource(Context context, int resource) {
gone 2015/09/08 21:01:57 say that this returns in Dp somewhere.
Lalit Maganti 2015/09/11 13:06:00 Added to function name.
+ int sizeInPx = context.getResources().getDimensionPixelSize(resource);
+ float density = context.getResources().getDisplayMetrics().density;
return (int) (sizeInPx / density);
}

Powered by Google App Engine
This is Rietveld 408576698