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; | |
11 import android.app.PendingIntent; | 10 import android.app.PendingIntent; |
12 import android.content.ContentResolver; | 11 import android.content.ContentResolver; |
13 import android.content.Context; | 12 import android.content.Context; |
14 import android.content.Intent; | 13 import android.content.Intent; |
15 import android.content.pm.PackageManager; | 14 import android.content.pm.PackageManager; |
16 import android.content.res.ColorStateList; | 15 import android.content.res.ColorStateList; |
17 import android.content.res.Configuration; | 16 import android.content.res.Configuration; |
18 import android.content.res.Resources; | 17 import android.content.res.Resources; |
19 import android.content.res.Resources.NotFoundException; | 18 import android.content.res.Resources.NotFoundException; |
20 import android.graphics.Bitmap; | 19 import android.graphics.Bitmap; |
21 import android.graphics.Color; | 20 import android.graphics.Color; |
22 import android.graphics.ColorFilter; | 21 import android.graphics.ColorFilter; |
23 import android.graphics.Rect; | 22 import android.graphics.Rect; |
24 import android.graphics.drawable.Drawable; | 23 import android.graphics.drawable.Drawable; |
25 import android.net.Uri; | 24 import android.net.Uri; |
26 import android.os.Build; | 25 import android.os.Build; |
27 import android.os.PowerManager; | 26 import android.os.PowerManager; |
28 import android.os.Process; | 27 import android.os.Process; |
29 import android.os.StatFs; | 28 import android.os.StatFs; |
30 import android.os.UserManager; | 29 import android.os.UserManager; |
31 import android.provider.Settings; | 30 import android.provider.Settings; |
32 import android.view.View; | 31 import android.view.View; |
33 import android.view.ViewGroup.MarginLayoutParams; | 32 import android.view.ViewGroup.MarginLayoutParams; |
34 import android.view.Window; | 33 import android.view.Window; |
35 import android.view.WindowManager; | 34 import android.view.WindowManager; |
36 import android.view.inputmethod.InputMethodSubtype; | 35 import android.view.inputmethod.InputMethodSubtype; |
37 import android.widget.RemoteViews; | |
38 import android.widget.TextView; | 36 import android.widget.TextView; |
39 | 37 |
40 import java.io.File; | 38 import java.io.File; |
41 import java.lang.reflect.Method; | 39 import java.lang.reflect.Method; |
42 | 40 |
43 /** | 41 /** |
44 * Utility class to use new APIs that were added after ICS (API level 14). | 42 * Utility class to use new APIs that were added after ICS (API level 14). |
45 */ | 43 */ |
46 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 44 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
47 public class ApiCompatibilityUtils { | 45 public class ApiCompatibilityUtils { |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 return context.checkPermission(permission, pid, uid); | 599 return context.checkPermission(permission, pid, uid); |
602 } catch (RuntimeException e) { | 600 } catch (RuntimeException e) { |
603 // Some older versions of Android throw odd errors when checking for
permissions, so | 601 // Some older versions of Android throw odd errors when checking for
permissions, so |
604 // just swallow the exception and treat it as the permission is deni
ed. | 602 // just swallow the exception and treat it as the permission is deni
ed. |
605 // crbug.com/639099 | 603 // crbug.com/639099 |
606 return PackageManager.PERMISSION_DENIED; | 604 return PackageManager.PERMISSION_DENIED; |
607 } | 605 } |
608 } | 606 } |
609 | 607 |
610 /** | 608 /** |
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() | 609 * @see android.view.inputmethod.InputMethodSubType#getLocate() |
640 */ | 610 */ |
641 @SuppressWarnings("deprecation") | 611 @SuppressWarnings("deprecation") |
642 public static String getLocale(InputMethodSubtype inputMethodSubType) { | 612 public static String getLocale(InputMethodSubtype inputMethodSubType) { |
643 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 613 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
644 return inputMethodSubType.getLanguageTag(); | 614 return inputMethodSubType.getLanguageTag(); |
645 } else { | 615 } else { |
646 return inputMethodSubType.getLocale(); | 616 return inputMethodSubType.getLocale(); |
647 } | 617 } |
648 } | 618 } |
(...skipping 20 matching lines...) Expand all Loading... |
669 @SuppressWarnings("deprecation") | 639 @SuppressWarnings("deprecation") |
670 int featureNumber = Window.FEATURE_INDETERMINATE_PROGRESS; | 640 int featureNumber = Window.FEATURE_INDETERMINATE_PROGRESS; |
671 | 641 |
672 @SuppressWarnings("deprecation") | 642 @SuppressWarnings("deprecation") |
673 int featureValue = Window.PROGRESS_VISIBILITY_OFF; | 643 int featureValue = Window.PROGRESS_VISIBILITY_OFF; |
674 | 644 |
675 window.setFeatureInt(featureNumber, featureValue); | 645 window.setFeatureInt(featureNumber, featureValue); |
676 } | 646 } |
677 } | 647 } |
678 } | 648 } |
OLD | NEW |