| 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.base; | 5 package org.chromium.base; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.app.ActivityManager; | 9 import android.app.ActivityManager; |
| 10 import android.app.Notification; |
| 10 import android.app.PendingIntent; | 11 import android.app.PendingIntent; |
| 11 import android.content.ContentResolver; | 12 import android.content.ContentResolver; |
| 12 import android.content.Context; | 13 import android.content.Context; |
| 13 import android.content.Intent; | 14 import android.content.Intent; |
| 14 import android.content.pm.PackageManager; | 15 import android.content.pm.PackageManager; |
| 15 import android.content.res.ColorStateList; | 16 import android.content.res.ColorStateList; |
| 16 import android.content.res.Configuration; | 17 import android.content.res.Configuration; |
| 17 import android.content.res.Resources; | 18 import android.content.res.Resources; |
| 18 import android.content.res.Resources.NotFoundException; | 19 import android.content.res.Resources.NotFoundException; |
| 19 import android.graphics.Bitmap; | 20 import android.graphics.Bitmap; |
| 20 import android.graphics.Color; | 21 import android.graphics.Color; |
| 21 import android.graphics.ColorFilter; | 22 import android.graphics.ColorFilter; |
| 22 import android.graphics.Rect; | 23 import android.graphics.Rect; |
| 23 import android.graphics.drawable.Drawable; | 24 import android.graphics.drawable.Drawable; |
| 25 import android.net.Uri; |
| 24 import android.os.Build; | 26 import android.os.Build; |
| 25 import android.os.PowerManager; | 27 import android.os.PowerManager; |
| 26 import android.os.Process; | 28 import android.os.Process; |
| 27 import android.os.StatFs; | 29 import android.os.StatFs; |
| 28 import android.os.UserManager; | 30 import android.os.UserManager; |
| 29 import android.provider.Settings; | 31 import android.provider.Settings; |
| 30 import android.view.View; | 32 import android.view.View; |
| 31 import android.view.ViewGroup.MarginLayoutParams; | 33 import android.view.ViewGroup.MarginLayoutParams; |
| 32 import android.view.Window; | 34 import android.view.Window; |
| 33 import android.view.WindowManager; | 35 import android.view.WindowManager; |
| 36 import android.view.inputmethod.InputMethodSubtype; |
| 37 import android.widget.RemoteViews; |
| 34 import android.widget.TextView; | 38 import android.widget.TextView; |
| 35 | 39 |
| 40 import java.io.File; |
| 36 import java.lang.reflect.Method; | 41 import java.lang.reflect.Method; |
| 37 | 42 |
| 38 /** | 43 /** |
| 39 * Utility class to use new APIs that were added after ICS (API level 14). | 44 * Utility class to use new APIs that were added after ICS (API level 14). |
| 40 */ | 45 */ |
| 41 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 46 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| 42 public class ApiCompatibilityUtils { | 47 public class ApiCompatibilityUtils { |
| 43 private ApiCompatibilityUtils() { | 48 private ApiCompatibilityUtils() { |
| 44 } | 49 } |
| 45 | 50 |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 public static int checkPermission(Context context, String permission, int pi
d, int uid) { | 599 public static int checkPermission(Context context, String permission, int pi
d, int uid) { |
| 595 try { | 600 try { |
| 596 return context.checkPermission(permission, pid, uid); | 601 return context.checkPermission(permission, pid, uid); |
| 597 } catch (RuntimeException e) { | 602 } catch (RuntimeException e) { |
| 598 // Some older versions of Android throw odd errors when checking for
permissions, so | 603 // Some older versions of Android throw odd errors when checking for
permissions, so |
| 599 // just swallow the exception and treat it as the permission is deni
ed. | 604 // just swallow the exception and treat it as the permission is deni
ed. |
| 600 // crbug.com/639099 | 605 // crbug.com/639099 |
| 601 return PackageManager.PERMISSION_DENIED; | 606 return PackageManager.PERMISSION_DENIED; |
| 602 } | 607 } |
| 603 } | 608 } |
| 609 |
| 610 /** |
| 611 * @see android.app.Notification.Builder#setContent(RemoteViews) |
| 612 */ |
| 613 @SuppressWarnings("deprecation") |
| 614 public static void setContentViewForNotificationBuilder( |
| 615 Notification.Builder builder, RemoteViews views) { |
| 616 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| 617 builder.setCustomContentView(views); |
| 618 } else { |
| 619 builder.setContent(views); |
| 620 } |
| 621 } |
| 622 |
| 623 /** |
| 624 * @see android.app.Notification#bigContentView |
| 625 */ |
| 626 @SuppressWarnings("deprecation") |
| 627 public static Notification notificationWithBigContentView( |
| 628 Notification.Builder builder, RemoteViews view) { |
| 629 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| 630 return builder.setCustomBigContentView(view).build(); |
| 631 } else { |
| 632 Notification notification = builder.build(); |
| 633 notification.bigContentView = view; |
| 634 return notification; |
| 635 } |
| 636 } |
| 637 |
| 638 /** |
| 639 * @see android.view.inputmethod.InputMethodSubType#getLocate() |
| 640 */ |
| 641 @SuppressWarnings("deprecation") |
| 642 public static String getLocale(InputMethodSubtype inputMethodSubType) { |
| 643 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| 644 return inputMethodSubType.getLanguageTag(); |
| 645 } else { |
| 646 return inputMethodSubType.getLocale(); |
| 647 } |
| 648 } |
| 649 |
| 650 /** |
| 651 * Get a URI for |file| which has the image capture. This function assumes t
hat path of |file| |
| 652 * is based on the result of UiUtils.getDirectoryForImageCapture(). |
| 653 * |
| 654 * @param context The application context. |
| 655 * @param file image capture file. |
| 656 * @return URI for |file|. |
| 657 */ |
| 658 public static Uri getUriForImageCaptureFile(Context context, File file) { |
| 659 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 |
| 660 ? ContentUriUtils.getContentUriFromFile(context, file) |
| 661 : Uri.fromFile(file); |
| 662 } |
| 663 |
| 664 /** |
| 665 * @see android.view.Window#FEATURE_INDETERMINATE_PROGRESS |
| 666 */ |
| 667 public static void setWindowIndeterminateProgress(Window window) { |
| 668 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
| 669 @SuppressWarnings("deprecation") |
| 670 int featureNumber = Window.FEATURE_INDETERMINATE_PROGRESS; |
| 671 |
| 672 @SuppressWarnings("deprecation") |
| 673 int featureValue = Window.PROGRESS_VISIBILITY_OFF; |
| 674 |
| 675 window.setFeatureInt(featureNumber, featureValue); |
| 676 } |
| 677 } |
| 604 } | 678 } |
| OLD | NEW |