OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.ui.base; | 5 package org.chromium.ui.base; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.os.Build; | 8 import android.os.Build; |
9 import android.util.DisplayMetrics; | 9 import android.util.DisplayMetrics; |
10 import android.view.WindowManager; | 10 import android.view.WindowManager; |
11 | 11 |
12 import org.chromium.base.annotations.CalledByNative; | 12 import org.chromium.base.annotations.CalledByNative; |
13 | 13 |
14 /** | 14 /** |
15 * UI utilities for accessing form factor information. | 15 * UI utilities for accessing form factor information. |
16 */ | 16 */ |
17 public class DeviceFormFactor { | 17 public class DeviceFormFactor { |
18 | 18 |
19 /** | 19 /** |
20 * The minimum width that would classify the device as a tablet or a large t
ablet. | 20 * The minimum width that would classify the device as a tablet or a large t
ablet. |
21 */ | 21 */ |
22 public static final int MINIMUM_TABLET_WIDTH_DP = 600; | 22 public static final int MINIMUM_TABLET_WIDTH_DP = 600; |
23 private static final int MINIMUM_LARGE_TABLET_WIDTH_DP = 720; | 23 private static final int MINIMUM_LARGE_TABLET_WIDTH_DP = 720; |
24 | 24 |
25 private static Boolean sIsTablet = null; | 25 private static Boolean sIsTablet; |
26 private static Boolean sIsLargeTablet = null; | 26 private static Boolean sIsLargeTablet; |
27 private static Integer sMinimumTabletWidthPx = null; | 27 private static Integer sMinimumTabletWidthPx; |
28 private static Float sDensity = null; | 28 private static Float sDensity; |
29 | 29 |
30 /** | 30 /** |
31 * @param context {@link Context} used to get the Application Context. | 31 * @param context {@link Context} used to get the Application Context. |
32 * @return Whether the app should treat the device as a tablet for layout. T
his method is not | 32 * @return Whether the app should treat the device as a tablet for layout. T
his method is not |
33 * affected by Android N multi-window. | 33 * affected by Android N multi-window. |
34 */ | 34 */ |
35 @CalledByNative | 35 @CalledByNative |
36 public static boolean isTablet(Context context) { | 36 public static boolean isTablet(Context context) { |
37 if (sIsTablet == null) { | 37 if (sIsTablet == null) { |
38 sIsTablet = getSmallestDeviceWidthDp(context) >= MINIMUM_TABLET_WIDT
H_DP; | 38 sIsTablet = getSmallestDeviceWidthDp(context) >= MINIMUM_TABLET_WIDT
H_DP; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 * Sets whether the device is a tablet. | 110 * Sets whether the device is a tablet. |
111 * @param isTablet Whether the app should treat the device as a tablet for l
ayout. | 111 * @param isTablet Whether the app should treat the device as a tablet for l
ayout. |
112 * @param isLargeTablet Whether the app should treat the device as a large t
ablet for layout. | 112 * @param isLargeTablet Whether the app should treat the device as a large t
ablet for layout. |
113 * If this is true, isTablet should also be true. | 113 * If this is true, isTablet should also be true. |
114 */ | 114 */ |
115 public static void setIsTablet(boolean isTablet, boolean isLargeTablet) { | 115 public static void setIsTablet(boolean isTablet, boolean isLargeTablet) { |
116 sIsTablet = isTablet; | 116 sIsTablet = isTablet; |
117 sIsLargeTablet = isLargeTablet; | 117 sIsLargeTablet = isLargeTablet; |
118 } | 118 } |
119 } | 119 } |
OLD | NEW |