List of usage examples for android.util DisplayMetrics DENSITY_TV
int DENSITY_TV
To view the source code for android.util DisplayMetrics DENSITY_TV.
Click Source Link
From source file:Main.java
/** * The screen density expressed as dots-per-inch. * @param density_dpi "densityDpi"//from ww w . ja v a 2 s. c om */ public static String getDensityDPIStr(int density_dpi) { switch (density_dpi) { case DisplayMetrics.DENSITY_LOW://120 return "DENSITY_LOW"; case DisplayMetrics.DENSITY_MEDIUM://160 return "DENSITY_MEDIUM/DENSITY_DEFAULT"; //case DisplayMetrics.DENSITY_DEFAULT://160 // return "DENSITY_DEFAULT"; case DisplayMetrics.DENSITY_TV://213 return "DENSITY_TV"; case DisplayMetrics.DENSITY_HIGH://240 return "DENSITY_HIGH"; case DisplayMetrics.DENSITY_280://280 return "DENSITY_280"; case DisplayMetrics.DENSITY_XHIGH://320 return "DENSITY_XHIGH"; case DisplayMetrics.DENSITY_360://360 return "DENSITY_360"; case DisplayMetrics.DENSITY_400://400 return "DENSITY_400"; case DisplayMetrics.DENSITY_420://420 return "DENSITY_420"; case DisplayMetrics.DENSITY_XXHIGH://480 return "DENSITY_XXHDPI"; case DisplayMetrics.DENSITY_560://560 return "DENSITY_560"; case DisplayMetrics.DENSITY_XXXHIGH://640 return "DENSITY_XXXHDPI"; default: return UNKNOWN; } }
From source file:Main.java
public static Drawable getIconFromPackageName(String packageName, Context context) { PackageManager pm = context.getPackageManager(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { try {//from ww w .ja va2s. c om PackageInfo pi = pm.getPackageInfo(packageName, 0); Context otherAppCtx = context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY); int displayMetrics[] = { DisplayMetrics.DENSITY_XXXHIGH, DisplayMetrics.DENSITY_XXHIGH, DisplayMetrics.DENSITY_XHIGH, DisplayMetrics.DENSITY_HIGH, DisplayMetrics.DENSITY_MEDIUM, DisplayMetrics.DENSITY_TV }; for (int displayMetric : displayMetrics) { try { Drawable d = otherAppCtx.getResources().getDrawableForDensity(pi.applicationInfo.icon, displayMetric); if (d != null) { return d; } } catch (Resources.NotFoundException e) { } } } catch (Exception e) { // Handle Error here } } ApplicationInfo appInfo = null; try { appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { return null; } return appInfo.loadIcon(pm); }
From source file:Main.java
public static String getDensity(Context ctx) { String densityStr = null;//from w ww . j av a 2 s . com final int density = ctx.getResources().getDisplayMetrics().densityDpi; switch (density) { case DisplayMetrics.DENSITY_LOW: densityStr = "LDPI"; break; case DisplayMetrics.DENSITY_MEDIUM: densityStr = "MDPI"; break; case DisplayMetrics.DENSITY_TV: densityStr = "TVDPI"; break; case DisplayMetrics.DENSITY_HIGH: densityStr = "HDPI"; break; case DisplayMetrics.DENSITY_XHIGH: densityStr = "XHDPI"; break; case DisplayMetrics.DENSITY_400: densityStr = "XMHDPI"; break; case DisplayMetrics.DENSITY_XXHIGH: densityStr = "XXHDPI"; break; case DisplayMetrics.DENSITY_XXXHIGH: densityStr = "XXXHDPI"; break; } return densityStr; }
From source file:Main.java
/** * Checks if the device is a tablet or a phone * * @param activityContext// ww w . j a v a 2s. c om * The Activity Context. * @return Returns true if the device is a Tablet */ public static boolean isTabletDevice(Context activityContext) { // Verifies if the Generalized Size of the device is XLARGE to be // considered a Tablet boolean xlarge = ((activityContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE); // If XLarge, checks if the Generalized Density is at least MDPI // (160dpi) if (xlarge) { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = (Activity) activityContext; activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160, // DENSITY_TV=213, DENSITY_XHIGH=320 if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == DisplayMetrics.DENSITY_TV || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) { // Yes, this is a tablet! return true; } } // No, this is not a tablet! return false; }
From source file:ch.rts.cordova.is.tablet.IsTablet.java
private boolean isTabletDevice(Context applicationContext) { boolean device_large = ((applicationContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE); if (device_large) { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = this.cordova.getActivity(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == DisplayMetrics.DENSITY_TV || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) { Log.d(LOG_TAG, "Is Tablet Device"); return true; }/* w w w. j a va 2s .c om*/ } Log.d(LOG_TAG, "Is NOT Tablet Device"); return false; }
From source file:uk.co.workingedge.phonegap.plugin.IsTablet.java
private boolean isTabletDevice(Context applicationContext) { boolean device_large = ((applicationContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE); if (device_large) { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = this.cordova.getActivity(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == DisplayMetrics.DENSITY_TV || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH || metrics.densityDpi == DisplayMetrics.DENSITY_XXHIGH) { Log.d(LOG_TAG, "Is Tablet Device"); return true; }/*from w w w.j ava 2 s. c o m*/ } Log.d(LOG_TAG, "Is NOT Tablet Device"); return false; }
From source file:count.ly.messaging.DeviceInfo.java
/** * Maps the current display density to a string constant. * @param context context to use to retrieve the current display metrics * @return a string constant representing the current display density, or the * empty string if the density is unknown *///from www. j a v a 2 s. co m static String getDensity(final Context context) { String densityStr = ""; final int density = context.getResources().getDisplayMetrics().densityDpi; switch (density) { case DisplayMetrics.DENSITY_LOW: densityStr = "LDPI"; break; case DisplayMetrics.DENSITY_MEDIUM: densityStr = "MDPI"; break; case DisplayMetrics.DENSITY_TV: densityStr = "TVDPI"; break; case DisplayMetrics.DENSITY_HIGH: densityStr = "HDPI"; break; case DisplayMetrics.DENSITY_XHIGH: densityStr = "XHDPI"; break; case DisplayMetrics.DENSITY_400: densityStr = "XMHDPI"; break; case DisplayMetrics.DENSITY_XXHIGH: densityStr = "XXHDPI"; break; case DisplayMetrics.DENSITY_XXXHIGH: densityStr = "XXXHDPI"; break; } return densityStr; }
From source file:ly.count.android.sdk.DeviceInfo.java
/** * Maps the current display density to a string constant. * @param context context to use to retrieve the current display metrics * @return a string constant representing the current display density, or the * empty string if the density is unknown *///ww w . j a v a 2 s. com static String getDensity(final Context context) { String densityStr = ""; final int density = context.getResources().getDisplayMetrics().densityDpi; switch (density) { case DisplayMetrics.DENSITY_LOW: densityStr = "LDPI"; break; case DisplayMetrics.DENSITY_MEDIUM: densityStr = "MDPI"; break; case DisplayMetrics.DENSITY_TV: densityStr = "TVDPI"; break; case DisplayMetrics.DENSITY_HIGH: densityStr = "HDPI"; break; //todo uncomment in android sdk 25 //case DisplayMetrics.DENSITY_260: // densityStr = "XHDPI"; // break; case DisplayMetrics.DENSITY_280: densityStr = "XHDPI"; break; //todo uncomment in android sdk 25 //case DisplayMetrics.DENSITY_300: // densityStr = "XHDPI"; // break; case DisplayMetrics.DENSITY_XHIGH: densityStr = "XHDPI"; break; //todo uncomment in android sdk 25 //case DisplayMetrics.DENSITY_340: // densityStr = "XXHDPI"; // break; case DisplayMetrics.DENSITY_360: densityStr = "XXHDPI"; break; case DisplayMetrics.DENSITY_400: densityStr = "XXHDPI"; break; case DisplayMetrics.DENSITY_420: densityStr = "XXHDPI"; break; case DisplayMetrics.DENSITY_XXHIGH: densityStr = "XXHDPI"; break; case DisplayMetrics.DENSITY_560: densityStr = "XXXHDPI"; break; case DisplayMetrics.DENSITY_XXXHIGH: densityStr = "XXXHDPI"; break; default: densityStr = "other"; break; } return densityStr; }
From source file:com.iangclifton.auid.appendixc.sections.VariousDemosFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.various_demos, container, false); final StringBuilder sb = new StringBuilder(); // Create a String for the device physical size switch (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) { case Configuration.SCREENLAYOUT_SIZE_XLARGE: // Extra large (most 10" tablets) sb.append(getString(R.string.configuration_xlarge)); break;/*from ww w. java2s.c o m*/ case Configuration.SCREENLAYOUT_SIZE_LARGE: // Large (most 7" tablets) sb.append(getString(R.string.configuration_large)); break; case Configuration.SCREENLAYOUT_SIZE_NORMAL: // Normal (most phones) sb.append(getString(R.string.configuration_normal)); break; case Configuration.SCREENLAYOUT_SIZE_SMALL: // Small (very uncommon) sb.append(getString(R.string.configuration_small)); break; default: sb.append(getString(R.string.configuration_unknown)); break; } sb.append('\n'); // Create a String for the display density switch (getResources().getDisplayMetrics().densityDpi) { case DisplayMetrics.DENSITY_XXHIGH: // Display is around 480 pixels per inch sb.append(getString(R.string.density_xxhdpi)); break; case DisplayMetrics.DENSITY_XHIGH: // Display is around 320 pixels per inch sb.append(getString(R.string.density_xhdpi)); break; case DisplayMetrics.DENSITY_HIGH: // Display is around 240 pixels per inch sb.append(getString(R.string.density_hdpi)); break; case DisplayMetrics.DENSITY_MEDIUM: // Display is around 160 pixels per inch sb.append(getString(R.string.density_mdpi)); break; case DisplayMetrics.DENSITY_LOW: // Display is around 120 pixels per inch sb.append(getString(R.string.density_ldpi)); break; case DisplayMetrics.DENSITY_TV: // Display is a 720p TV screen // Sometimes also used for 1280x720 7" tablets // Rarely should you ever specifically target this density sb.append(getString(R.string.density_tv)); break; default: sb.append(getString(R.string.density_unknown)); break; } sb.append('\n'); // Create a String for the thread we're on // Obviously this method is always called on the main thread but this technique can be used anywhere. if (Utils.isUiThread()) { // UI Thread sb.append(getString(R.string.main_thread_true)); } else { // Other Thread sb.append(getString(R.string.main_thread_false)); } sb.append(" (Thread name: ").append(Thread.currentThread().getName()).append(')'); // Set text final TextView tv = (TextView) rootView.findViewById(R.id.main_text); tv.setText(sb); return rootView; }
From source file:ly.count.android.api.DeviceInfoTests.java
public void testGetDensity() { Context mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_LOW); assertEquals("LDPI", DeviceInfo.getDensity(mockContext)); mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_MEDIUM); assertEquals("MDPI", DeviceInfo.getDensity(mockContext)); mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_TV); assertEquals("TVDPI", DeviceInfo.getDensity(mockContext)); mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_HIGH); assertEquals("HDPI", DeviceInfo.getDensity(mockContext)); mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_XHIGH); assertEquals("XHDPI", DeviceInfo.getDensity(mockContext)); mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_XXHIGH); assertEquals("XXHDPI", DeviceInfo.getDensity(mockContext)); mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_XXXHIGH); assertEquals("XXXHDPI", DeviceInfo.getDensity(mockContext)); mockContext = mockContextForTestingDensity(DisplayMetrics.DENSITY_400); assertEquals("XMHDPI", DeviceInfo.getDensity(mockContext)); mockContext = mockContextForTestingDensity(0); assertEquals("", DeviceInfo.getDensity(mockContext)); }