use of android.util.DisplayMetrics in project Genius-Android by qiujuer.
the class BalloonMarker method resetSizes.
public void resetSizes(String maxValue) {
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
//Account for negative numbers... is there any proper way of getting the biggest string between our range????
mNumber.setText(String.format("-%s", maxValue));
//Do a first forced measure call for the TextView (with the biggest text content),
//to calculate the max width and use always the same.
//this avoids the TextView from shrinking and growing when the text content changes
int wSpec = MeasureSpec.makeMeasureSpec(displayMetrics.widthPixels, MeasureSpec.AT_MOST);
int hSpec = MeasureSpec.makeMeasureSpec(displayMetrics.heightPixels, MeasureSpec.AT_MOST);
mNumber.measure(wSpec, hSpec);
mWidth = Math.max(mNumber.getMeasuredWidth(), mNumber.getMeasuredHeight());
removeView(mNumber);
addView(mNumber, new FrameLayout.LayoutParams(mWidth, mWidth, Gravity.LEFT | Gravity.TOP));
}
use of android.util.DisplayMetrics in project robolectric by robolectric.
the class ShadowDisplayTest method shouldProvideDisplayMetrics.
@Test
public void shouldProvideDisplayMetrics() throws Exception {
Display display = Shadow.newInstanceOf(Display.class);
ShadowDisplay shadow = Shadows.shadowOf(display);
shadow.setDensity(1.5f);
shadow.setDensityDpi(DisplayMetrics.DENSITY_MEDIUM);
shadow.setScaledDensity(1.6f);
shadow.setWidth(1024);
shadow.setHeight(600);
shadow.setRealWidth(1400);
shadow.setRealHeight(900);
shadow.setXdpi(183.0f);
shadow.setYdpi(184.0f);
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
assertEquals(1.5f, metrics.density, 0.05);
assertEquals(DisplayMetrics.DENSITY_MEDIUM, metrics.densityDpi);
assertEquals(1.6f, metrics.scaledDensity, 0.05);
assertEquals(1024, metrics.widthPixels);
assertEquals(600, metrics.heightPixels);
assertEquals(183.0f, metrics.xdpi, 0.05);
assertEquals(184.0f, metrics.ydpi, 0.05);
metrics = new DisplayMetrics();
display.getRealMetrics(metrics);
assertEquals(1.5f, metrics.density, 0.05);
assertEquals(DisplayMetrics.DENSITY_MEDIUM, metrics.densityDpi);
assertEquals(1.6f, metrics.scaledDensity, 0.05);
assertEquals(1400, metrics.widthPixels);
assertEquals(900, metrics.heightPixels);
assertEquals(183.0f, metrics.xdpi, 0.05);
assertEquals(184.0f, metrics.ydpi, 0.05);
}
use of android.util.DisplayMetrics in project Libraries-for-Android-Developers by eoecn.
the class ResourcesCompat method getResources_getInteger.
/**
* Support implementation of {@code getResources().getInteger()} that we
* can use to simulate filtering based on width qualifiers on pre-3.2.
*
* @param context Context to load integers from on 3.2+ and to fetch the
* display metrics.
* @param id Id of integer to load.
* @return Associated integer value as reflected by the current display
* metrics.
*/
public static int getResources_getInteger(Context context, int id) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
return context.getResources().getInteger(id);
}
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
float widthDp = metrics.widthPixels / metrics.density;
if (id == R.integer.abs__max_action_buttons) {
if (widthDp >= 600) {
//values-w600dp
return 5;
}
if (widthDp >= 500) {
//values-w500dp
return 4;
}
if (widthDp >= 360) {
//values-w360dp
return 3;
}
//values
return 2;
}
throw new IllegalArgumentException("Unknown integer resource ID " + id);
}
use of android.util.DisplayMetrics in project android-app by eoecn.
the class Utility method getScreenParams.
public static String getScreenParams(Activity activity) {
DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
return "&screen=" + (dm.heightPixels > dm.widthPixels ? dm.widthPixels + "*" + dm.heightPixels : dm.heightPixels + "*" + dm.widthPixels);
}
use of android.util.DisplayMetrics in project MyDiary by erttyy8821.
the class ScreenHelper method getScreenHeight.
public static int getScreenHeight(Context context) {
DisplayMetrics metrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
return metrics.heightPixels;
}
Aggregations