summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDvTonder <david.vantonder@gmail.com>2012-11-24 14:54:53 -0500
committerDvTonder <david.vantonder@gmail.com>2012-11-24 14:54:53 -0500
commit3b18eb7c377a6b79369942ceb3fc672b8543b868 (patch)
tree4b6e6cd57adb87a9f884ec79a862ff89c30be1e4
parentf2c359c08b1de60d0bdc00d5c9da8e0a13665bf6 (diff)
downloadpackages_apps_settings-3b18eb7c377a6b79369942ceb3fc672b8543b868.zip
packages_apps_settings-3b18eb7c377a6b79369942ceb3fc672b8543b868.tar.gz
packages_apps_settings-3b18eb7c377a6b79369942ceb3fc672b8543b868.tar.bz2
Settings: Add Utility function
Change-Id: Ic5316765d3db48351a9feaa9b3cce286d256071e
-rw-r--r--src/com/android/settings/Utils.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 6d76bed..29dcbf4 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -56,9 +56,12 @@ import android.provider.ContactsContract.Profile;
import android.provider.ContactsContract.RawContacts;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
+import android.util.DisplayMetrics;
import android.util.Log;
+import android.view.DisplayInfo;
import android.view.View;
import android.view.ViewGroup;
+import android.view.WindowManager;
import android.widget.ListView;
import android.widget.TabWidget;
@@ -97,6 +100,14 @@ public class Utils {
*/
private static final String META_DATA_PREFERENCE_SUMMARY = "com.android.settings.summary";
+ // Device types
+ private static final int DEVICE_PHONE = 0;
+ private static final int DEVICE_HYBRID = 1;
+ private static final int DEVICE_TABLET = 2;
+
+ // Device type reference
+ private static int mDeviceType = -1;
+
/**
* Finds a matching activity for a preference's intent. If a matching
* activity is not found, it will remove the preference.
@@ -587,4 +598,37 @@ public class Utils {
return ((UserManager) context.getSystemService(Context.USER_SERVICE))
.getUsers().size() > 1;
}
+
+ private static int getScreenType(Context con) {
+ if (mDeviceType == -1) {
+ WindowManager wm = (WindowManager)con.getSystemService(Context.WINDOW_SERVICE);
+ DisplayInfo outDisplayInfo = new DisplayInfo();
+ wm.getDefaultDisplay().getDisplayInfo(outDisplayInfo);
+ int shortSize = Math.min(outDisplayInfo.logicalHeight, outDisplayInfo.logicalWidth);
+ int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / outDisplayInfo.logicalDensityDpi;
+ if (shortSizeDp < 600) {
+ // 0-599dp: "phone" UI with a separate status & navigation bar
+ mDeviceType = DEVICE_PHONE;
+ } else if (shortSizeDp < 720) {
+ // 600-719dp: "phone" UI with modifications for larger screens
+ mDeviceType = DEVICE_HYBRID;
+ } else {
+ // 720dp: "tablet" UI with a single combined status & navigation bar
+ mDeviceType = DEVICE_TABLET;
+ }
+ }
+ return mDeviceType;
+ }
+
+ public static boolean isPhone(Context con) {
+ return getScreenType(con) == DEVICE_PHONE;
+ }
+
+ public static boolean isHybrid(Context con) {
+ return getScreenType(con) == DEVICE_HYBRID;
+ }
+
+ public static boolean isTablet(Context con) {
+ return getScreenType(con) == DEVICE_TABLET;
+ }
}