List of usage examples for android.util DisplayMetrics DENSITY_MEDIUM
int DENSITY_MEDIUM
To view the source code for android.util DisplayMetrics DENSITY_MEDIUM.
Click Source Link
From source file:com.mruddy.devdataviewer.DevDataListFragment.java
@SuppressLint("InlinedApi") private static void initMaps() { DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_LOW, "LDPI"); DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_MEDIUM, "MDPI"); DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_HIGH, "HDPI"); DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_XHIGH, "XHDPI"); DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_XXHIGH, "XXHDPI"); DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_XXXHIGH, "XXXHDPI"); DevDataListFragment.ROTATION.append(Surface.ROTATION_0, "0"); DevDataListFragment.ROTATION.append(Surface.ROTATION_90, "90"); DevDataListFragment.ROTATION.append(Surface.ROTATION_180, "180"); DevDataListFragment.ROTATION.append(Surface.ROTATION_270, "270"); DevDataListFragment.ORIENTATION.append(Configuration.ORIENTATION_UNDEFINED, "undefined"); DevDataListFragment.ORIENTATION.append(Configuration.ORIENTATION_PORTRAIT, "portrait"); DevDataListFragment.ORIENTATION.append(Configuration.ORIENTATION_LANDSCAPE, "landscape"); DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_UNDEFINED, "undefined"); DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_SMALL, "small"); DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_NORMAL, "normal"); DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_LARGE, "large"); DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_XLARGE, "xlarge"); }
From source file:Main.java
public static void getDisplayDpi(Context ctx) { DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(dm); double x = Math.pow(dm.widthPixels / dm.xdpi, 2); double y = Math.pow(dm.heightPixels / dm.ydpi, 2); double screenInches = Math.sqrt(x + y); int screenInch = (int) Math.round(screenInches); Log.d("screeninch", String.valueOf(screenInch)); int dapi = dm.densityDpi; Log.d("dapi", String.valueOf(dapi)); try {// ww w . ja v a 2s .com switch (dm.densityDpi) { case DisplayMetrics.DENSITY_LOW: UI_DENSITY = 120; if (screenInch <= 7) { UI_SIZE = 4; } else { UI_SIZE = 10; } break; case DisplayMetrics.DENSITY_MEDIUM: UI_DENSITY = 160; if (screenInch <= 7) { UI_SIZE = 4; } else { UI_SIZE = 10; } break; case DisplayMetrics.DENSITY_HIGH: UI_DENSITY = 240; if (screenInch <= 7) { UI_SIZE = 4; } else { UI_SIZE = 10; } break; default: break; } } catch (Exception e) { // Caught exception here } }
From source file:Main.java
/** * Reports to the log information about the device's display. This information includes * the width and height, and density (low, medium, high). * @param activity The Activity to report on. *///ww w.ja va 2 s. c o m public static void reportDisplayInformation(Activity activity) { DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); int displayWidth = metrics.widthPixels; int displayHeight = metrics.heightPixels; String density = "unknown"; switch (metrics.densityDpi) { case DisplayMetrics.DENSITY_LOW: density = "Low"; break; case DisplayMetrics.DENSITY_MEDIUM: density = "Medium"; break; case DisplayMetrics.DENSITY_HIGH: density = "High"; break; } Log.i(TAG, "Display is " + displayWidth + "x" + displayHeight + ", Density: " + density); }
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; }/* ww w. j ava2 s . co m*/ } 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 a v a 2s.c om*/ } Log.d(LOG_TAG, "Is NOT Tablet Device"); return false; }
From source file:com.tct.fw.ex.photo.loaders.PhotoBitmapLoader.java
@Override public BitmapResult loadInBackground() { BitmapResult result = new BitmapResult(); Context context = getContext(); if (context != null && mPhotoUri != null) { final ContentResolver resolver = context.getContentResolver(); try {/*from w ww. ja v a 2s . c o m*/ result = ImageUtils.createLocalBitmap(resolver, Uri.parse(mPhotoUri), PhotoViewController.sMaxPhotoSize); if (result.bitmap != null) { result.bitmap.setDensity(DisplayMetrics.DENSITY_MEDIUM); } } catch (UnsupportedOperationException ex) { // We got image bytes, but unable to decode to a Bitmap result.status = BitmapResult.STATUS_EXCEPTION; } } return result; }
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 w w w. j ava 2s .c om*/ 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 */// w ww . j ava 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; //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 .ja v a 2s .c om*/ 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)); }