Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.app.ActivityManager; | 8 import android.app.ActivityManager; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 byte[] decoded = Base64.decode(encodedString, Base64.DEFAULT); | 495 byte[] decoded = Base64.decode(encodedString, Base64.DEFAULT); |
| 496 return BitmapFactory.decodeByteArray(decoded, 0, decoded.length); | 496 return BitmapFactory.decodeByteArray(decoded, 0, decoded.length); |
| 497 } | 497 } |
| 498 | 498 |
| 499 /** | 499 /** |
| 500 * Returns the ideal size for an icon representing a web app. This size is used on app banners, | 500 * Returns the ideal size for an icon representing a web app. This size is used on app banners, |
| 501 * the Android Home screen, and in Android's recent tasks list, among other places. | 501 * the Android Home screen, and in Android's recent tasks list, among other places. |
| 502 * @param resources Resources to retrieve the dimension from. | 502 * @param resources Resources to retrieve the dimension from. |
| 503 * @return the dimensions in dp which the icon should have. | 503 * @return the dimensions in dp which the icon should have. |
| 504 */ | 504 */ |
| 505 public static int getIdealHomescreenIconSizeInDp(Context context) { | 505 public static int getIdealHomescreenIconSizeInPx(Context context) { |
| 506 return getIdealSizeFromResourceInDp(context, R.dimen.webapp_home_screen_ icon_size); | 506 return getIdealSizeFromResourceInPx(context, R.dimen.webapp_home_screen_ icon_size); |
| 507 } | 507 } |
| 508 | 508 |
| 509 /** | 509 /** |
| 510 * Returns the minimum size for an icon representing a web app. This size i s used on app | 510 * Returns the minimum size for an icon representing a web app. This size i s used on app |
| 511 * banners, the Android Home screen, and in Android's recent tasks list, amo ng other places. | 511 * banners, the Android Home screen, and in Android's recent tasks list, amo ng other places. |
| 512 * @param resources Resources to retrieve the dimension from. | 512 * @param resources Resources to retrieve the dimension from. |
| 513 * @return the lower bound of the size which the icon should have in dp. | 513 * @return the lower bound of the size which the icon should have in dp. |
| 514 */ | 514 */ |
| 515 public static int getMinimumHomescreenIconSizeInDp(Context context) { | 515 public static int getMinimumHomescreenIconSizeInPx(Context context) { |
| 516 float sizeInPx = context.getResources().getDimension(R.dimen.webapp_home _screen_icon_size); | 516 float sizeInPx = context.getResources().getDimension(R.dimen.webapp_home _screen_icon_size); |
| 517 float density = context.getResources().getDisplayMetrics().density; | 517 float density = context.getResources().getDisplayMetrics().density; |
| 518 float idealIconSizeInDp = sizeInPx / density; | 518 float idealIconSizeInDp = sizeInPx / density; |
| 519 | 519 |
| 520 float minimumIconSizeInPx = idealIconSizeInDp * (density - 1); | 520 return Math.round(idealIconSizeInDp * (density - 1)); |
| 521 return Math.round(minimumIconSizeInPx / density); | |
| 522 } | 521 } |
| 523 | 522 |
| 524 /** | 523 /** |
| 525 * Returns the ideal size for an image displayed on a web app's splash scree n. | 524 * Returns the ideal size for an image displayed on a web app's splash scree n. |
| 526 * @param resources Resources to retrieve the dimension from. | 525 * @param resources Resources to retrieve the dimension from. |
| 527 * @return the dimensions in dp which the image should have. | 526 * @return the dimensions in dp which the image should have. |
| 528 */ | 527 */ |
| 529 public static int getIdealSplashImageSizeInDp(Context context) { | 528 public static int getIdealSplashImageSizeInPx(Context context) { |
| 530 return getIdealSizeFromResourceInDp(context, R.dimen.webapp_splash_image _size_ideal); | 529 return getIdealSizeFromResourceInPx(context, R.dimen.webapp_splash_image _size_ideal); |
| 531 } | 530 } |
| 532 | 531 |
| 533 /** | 532 /** |
| 534 * Returns the minimum size for an image displayed on a web app's splash scr een. | 533 * Returns the minimum size for an image displayed on a web app's splash scr een. |
| 535 * @param resources Resources to retrieve the dimension from. | 534 * @param resources Resources to retrieve the dimension from. |
| 536 * @return the lower bound of the size which the image should have in dp. | 535 * @return the lower bound of the size which the image should have in dp. |
| 537 */ | 536 */ |
| 538 public static int getMinimumSplashImageSizeInDp(Context context) { | 537 public static int getMinimumSplashImageSizeInPx(Context context) { |
| 539 return getIdealSizeFromResourceInDp(context, R.dimen.webapp_splash_image _size_minimum); | 538 return getIdealSizeFromResourceInPx(context, R.dimen.webapp_splash_image _size_minimum); |
| 540 } | 539 } |
| 541 | 540 |
| 542 /** | 541 /** |
| 543 * @return String that can be used to verify that a WebappActivity is being started by Chrome. | 542 * @return String that can be used to verify that a WebappActivity is being started by Chrome. |
| 544 */ | 543 */ |
| 545 public static String getEncodedMac(Context context, String url) { | 544 public static String getEncodedMac(Context context, String url) { |
| 546 // The only reason we convert to a String here is because Android inexpl icably eats a | 545 // The only reason we convert to a String here is because Android inexpl icably eats a |
| 547 // byte[] when adding the shortcut -- the Bundle received by the launche d Activity even | 546 // byte[] when adding the shortcut -- the Bundle received by the launche d Activity even |
| 548 // lacks the key for the extra. | 547 // lacks the key for the extra. |
| 549 byte[] mac = WebappAuthenticator.getMacForUrl(context, url); | 548 byte[] mac = WebappAuthenticator.getMacForUrl(context, url); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 | 585 |
| 587 /** | 586 /** |
| 588 * Returns an array of sizes which describe the ideal size and minimum size of the Home screen | 587 * Returns an array of sizes which describe the ideal size and minimum size of the Home screen |
| 589 * icon and the ideal and minimum sizes of the splash screen image in that o rder. | 588 * icon and the ideal and minimum sizes of the splash screen image in that o rder. |
| 590 */ | 589 */ |
| 591 @CalledByNative | 590 @CalledByNative |
| 592 private static int[] getHomeScreenIconAndSplashImageSizes() { | 591 private static int[] getHomeScreenIconAndSplashImageSizes() { |
| 593 Context context = ContextUtils.getApplicationContext(); | 592 Context context = ContextUtils.getApplicationContext(); |
| 594 // This ordering must be kept up to date with the C++ ShortcutHelper. | 593 // This ordering must be kept up to date with the C++ ShortcutHelper. |
| 595 return new int[] { | 594 return new int[] { |
| 596 getIdealHomescreenIconSizeInDp(context), | 595 getIdealHomescreenIconSizeInPx(context), |
| 597 getMinimumHomescreenIconSizeInDp(context), | 596 getMinimumHomescreenIconSizeInPx(context), |
| 598 getIdealSplashImageSizeInDp(context), | 597 getIdealSplashImageSizeInPx(context), |
| 599 getMinimumSplashImageSizeInDp(context) | 598 getMinimumSplashImageSizeInPx(context) |
| 600 }; | 599 }; |
| 601 } | 600 } |
| 602 | 601 |
| 603 /** | 602 /** |
| 604 * Returns true if we should add padding to this icon. We use a heuristic th at if the pixels in | 603 * Returns true if we should add padding to this icon. We use a heuristic th at if the pixels in |
| 605 * all four corners of the icon are not transparent, we assume the icon is s quare and maximally | 604 * all four corners of the icon are not transparent, we assume the icon is s quare and maximally |
| 606 * sized, i.e. in need of padding. Otherwise, no padding is added. | 605 * sized, i.e. in need of padding. Otherwise, no padding is added. |
| 607 */ | 606 */ |
| 608 private static boolean shouldPadIcon(Bitmap icon) { | 607 private static boolean shouldPadIcon(Bitmap icon) { |
| 609 int maxX = icon.getWidth() - 1; | 608 int maxX = icon.getWidth() - 1; |
| 610 int maxY = icon.getHeight() - 1; | 609 int maxY = icon.getHeight() - 1; |
| 611 | 610 |
| 612 if ((Color.alpha(icon.getPixel(0, 0)) != 0) && (Color.alpha(icon.getPixe l(maxX, maxY)) != 0) | 611 if ((Color.alpha(icon.getPixel(0, 0)) != 0) && (Color.alpha(icon.getPixe l(maxX, maxY)) != 0) |
| 613 && (Color.alpha(icon.getPixel(0, maxY)) != 0) | 612 && (Color.alpha(icon.getPixel(0, maxY)) != 0) |
| 614 && (Color.alpha(icon.getPixel(maxX, 0)) != 0)) { | 613 && (Color.alpha(icon.getPixel(maxX, 0)) != 0)) { |
| 615 return true; | 614 return true; |
| 616 } | 615 } |
| 617 return false; | 616 return false; |
| 618 } | 617 } |
| 619 | 618 |
| 620 private static int getIdealSizeFromResourceInDp(Context context, int resourc e) { | 619 private static int getIdealSizeFromResourceInPx(Context context, int resourc e) { |
|
dominickn
2016/12/19 06:23:32
Nit: rename this to getSizeFromResourceInPx (it's
| |
| 621 float sizeInPx = context.getResources().getDimension(resource); | 620 return Math.round(context.getResources().getDimension(resource)); |
| 622 float density = context.getResources().getDisplayMetrics().density; | |
| 623 return Math.round(sizeInPx / density); | |
| 624 } | 621 } |
| 625 | 622 |
| 626 private static Bitmap getBitmapFromResourceId(Context context, int id, int d ensity) { | 623 private static Bitmap getBitmapFromResourceId(Context context, int id, int d ensity) { |
| 627 Drawable drawable = ApiCompatibilityUtils.getDrawableForDensity( | 624 Drawable drawable = ApiCompatibilityUtils.getDrawableForDensity( |
| 628 context.getResources(), id, density); | 625 context.getResources(), id, density); |
| 629 | 626 |
| 630 if (drawable instanceof BitmapDrawable) { | 627 if (drawable instanceof BitmapDrawable) { |
| 631 BitmapDrawable bd = (BitmapDrawable) drawable; | 628 BitmapDrawable bd = (BitmapDrawable) drawable; |
| 632 return bd.getBitmap(); | 629 return bd.getBitmap(); |
| 633 } | 630 } |
| 634 assert false : "The drawable was not a bitmap drawable as expected"; | 631 assert false : "The drawable was not a bitmap drawable as expected"; |
| 635 return null; | 632 return null; |
| 636 } | 633 } |
| 637 | 634 |
| 638 private static native void nativeOnWebappDataStored(long callbackPointer); | 635 private static native void nativeOnWebappDataStored(long callbackPointer); |
| 639 } | 636 } |
| OLD | NEW |