OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.chromoting; | 5 package org.chromium.chromoting; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
11 import android.graphics.PorterDuff; | 11 import android.graphics.PorterDuff; |
12 import android.graphics.drawable.Drawable; | 12 import android.graphics.drawable.Drawable; |
13 import android.net.Uri; | 13 import android.net.Uri; |
| 14 import android.support.v4.content.ContextCompat; |
14 import android.util.TypedValue; | 15 import android.util.TypedValue; |
15 import android.view.Menu; | 16 import android.view.Menu; |
16 import android.view.MenuItem; | 17 import android.view.MenuItem; |
17 | 18 |
18 import org.chromium.base.ApiCompatibilityUtils; | |
19 import org.chromium.base.Log; | 19 import org.chromium.base.Log; |
20 | 20 |
21 /** Utility methods for chromoting code. */ | 21 /** Utility methods for chromoting code. */ |
22 public abstract class ChromotingUtil { | 22 public abstract class ChromotingUtil { |
23 private static final String TAG = "Chromoting"; | 23 private static final String TAG = "Chromoting"; |
24 | 24 |
25 /** | 25 /** |
26 * Tints all icons of a toolbar menu so they have the same color as the 'bac
k' navigation icon | 26 * Tints all icons of a toolbar menu so they have the same color as the 'bac
k' navigation icon |
27 * and the three-dots overflow icon. | 27 * and the three-dots overflow icon. |
28 * @param context Context for getting theme and resource information. | 28 * @param context Context for getting theme and resource information. |
(...skipping 27 matching lines...) Expand all Loading... |
56 * @throws Resources.NotFoundException | 56 * @throws Resources.NotFoundException |
57 */ | 57 */ |
58 public static int getColorAttribute(Context context, int attribute) { | 58 public static int getColorAttribute(Context context, int attribute) { |
59 TypedValue typedValue = new TypedValue(); | 59 TypedValue typedValue = new TypedValue(); |
60 if (!context.getTheme().resolveAttribute(attribute, typedValue, true)) { | 60 if (!context.getTheme().resolveAttribute(attribute, typedValue, true)) { |
61 throw new Resources.NotFoundException("Attribute not found."); | 61 throw new Resources.NotFoundException("Attribute not found."); |
62 } | 62 } |
63 | 63 |
64 if (typedValue.resourceId != 0) { | 64 if (typedValue.resourceId != 0) { |
65 // Attribute is a resource. | 65 // Attribute is a resource. |
66 return ApiCompatibilityUtils.getColor(context.getResources(), typedV
alue.resourceId); | 66 return ContextCompat.getColor(context, typedValue.resourceId); |
67 } else if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT | 67 } else if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT |
68 && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { | 68 && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { |
69 // Attribute is a raw color value. | 69 // Attribute is a raw color value. |
70 return typedValue.data; | 70 return typedValue.data; |
71 } else { | 71 } else { |
72 throw new Resources.NotFoundException("Attribute not a color."); | 72 throw new Resources.NotFoundException("Attribute not a color."); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 /** | 76 /** |
(...skipping 10 matching lines...) Expand all Loading... |
87 } | 87 } |
88 context.startActivity(intent); | 88 context.startActivity(intent); |
89 return true; | 89 return true; |
90 } | 90 } |
91 | 91 |
92 /** Launches an external web browser or application. */ | 92 /** Launches an external web browser or application. */ |
93 public static boolean openUrl(Activity parentActivity, Uri uri) { | 93 public static boolean openUrl(Activity parentActivity, Uri uri) { |
94 return startActivitySafely(parentActivity, new Intent(Intent.ACTION_VIEW
, uri)); | 94 return startActivitySafely(parentActivity, new Intent(Intent.ACTION_VIEW
, uri)); |
95 } | 95 } |
96 } | 96 } |
OLD | NEW |