Search in sources :

Example 76 with DisplayMetrics

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));
}
Also used : FrameLayout(android.widget.FrameLayout) DisplayMetrics(android.util.DisplayMetrics)

Example 77 with DisplayMetrics

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);
}
Also used : DisplayMetrics(android.util.DisplayMetrics) Display(android.view.Display) Test(org.junit.Test)

Example 78 with DisplayMetrics

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);
}
Also used : DisplayMetrics(android.util.DisplayMetrics)

Example 79 with DisplayMetrics

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);
}
Also used : DisplayMetrics(android.util.DisplayMetrics)

Example 80 with DisplayMetrics

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;
}
Also used : Activity(android.app.Activity) DisplayMetrics(android.util.DisplayMetrics)

Aggregations

DisplayMetrics (android.util.DisplayMetrics)772 WindowManager (android.view.WindowManager)107 Resources (android.content.res.Resources)99 Display (android.view.Display)78 Configuration (android.content.res.Configuration)61 Point (android.graphics.Point)57 View (android.view.View)52 SuppressLint (android.annotation.SuppressLint)47 Bitmap (android.graphics.Bitmap)42 Paint (android.graphics.Paint)42 Activity (android.app.Activity)32 ImageView (android.widget.ImageView)27 AssetManager (android.content.res.AssetManager)25 TypedArray (android.content.res.TypedArray)25 Context (android.content.Context)23 TypedValue (android.util.TypedValue)23 ViewGroup (android.view.ViewGroup)23 TextView (android.widget.TextView)22 Intent (android.content.Intent)21 RelativeLayout (android.widget.RelativeLayout)20