Example usage for android.view Display getMetrics

List of usage examples for android.view Display getMetrics

Introduction

In this page you can find the example usage for android.view Display getMetrics.

Prototype

public void getMetrics(DisplayMetrics outMetrics) 

Source Link

Document

Gets display metrics that describe the size and density of this display.

Usage

From source file:me.wimanacra.collector.DisplayManagerCollector.java

@NonNull
private JSONObject collectDisplayData(@NonNull Display display) throws JSONException {
    final DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);

    final JSONObject result = new JSONObject();
    collectCurrentSizeRange(display, result);
    collectFlags(display, result);/* w  w  w .j a v  a  2s  .c  o m*/
    collectMetrics(display, result);
    collectRealMetrics(display, result);
    collectName(display, result);
    collectRealSize(display, result);
    collectRectSize(display, result);
    collectSize(display, result);
    collectRotation(display, result);
    collectIsValid(display, result);
    result.put("orientation", display.getRotation()).put("refreshRate", display.getRefreshRate());
    //noinspection deprecation
    result.put("height", display.getHeight()).put("width", display.getWidth()).put("pixelFormat",
            display.getPixelFormat());
    return result;
}

From source file:com.example.androidmillgame.GamePanel.java

public GamePanel(Context context, long period) {
    super(context);
    this.period = period;

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display wsize = wm.getDefaultDisplay();
    Point size = new Point();
    wsize.getSize(size);/*from w  w  w .  ja v a2s  . c om*/
    DisplayMetrics displayMetrics = new DisplayMetrics();
    wsize.getMetrics(displayMetrics);
    this.dpi = displayMetrics.densityDpi;
    this.PWIDTH = size.x;
    this.PHEIGHT = size.y;

    setFocusable(true);
    requestFocus();// ...............................................the.JPane.now.has.focus,.so.receives.key.events
    imgres = new Images(context);// ..............................................................preload.resources
    generatedJoints = new SmartJointFactory(context);
    DraggablePoint = new DragPlayer();
    backgroundRect = new Rect(PWIDTH / 2 - PHEIGHT / 2, 0, PWIDTH / 2 + PHEIGHT / 2, PHEIGHT);
    background = new Rect(0, 0, imgres.getImage("background").getWidth(),
            imgres.getImage("background").getHeight());
    scale = imgres.getImage("background").getHeight() / PHEIGHT;
    int resumescaled = imgres.getImage("resumenop").getWidth();
    resumeRect = new Rect(PWIDTH / 2 - resumescaled / 2, PHEIGHT / 2 - resumescaled / 2 + Pd2px.pd2px(50),
            PWIDTH / 2 + resumescaled / 2, PHEIGHT / 2 + resumescaled / 2 + Pd2px.pd2px(50));
    GC = new GameController(generatedJoints.Joints, DraggablePoint, context);
    Display = new HUD(PWIDTH / 2, PHEIGHT / 2, imgres.getImage("hud"));
    this.startGame();
}

From source file:com.msted.lensrocket.activities.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    super.onCreate(savedInstanceState);
    // Show the Up button in the action bar.
    setupActionBar();/* ww  w  .  j a va 2s.c o  m*/
    mSettingsFragment = new SettingsFragment();

    Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);

    float density = getResources().getDisplayMetrics().density;
    float dpHeight = outMetrics.heightPixels / density;
    float dpWidth = outMetrics.widthPixels / density;

    int actionBarHeight;
    TypedValue tv = new TypedValue();
    if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    }

    getFragmentManager().beginTransaction().replace(android.R.id.content, mSettingsFragment).commit();
}

From source file:com.abiansoftware.lib.reader.AbianReaderApplication.java

@Override
public void onCreate() {
    s_singleton = this;

    ImageLoader theImageLoader = ImageLoader.getInstance();

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
            .threadPoolSize(4).threadPriority(Thread.NORM_PRIORITY - 1).memoryCacheSize(2 * 1024 * 1024)
            .denyCacheImageMultipleSizesInMemory()
            //.enableLogging()
            .build();/*from   ww  w.  j a v  a 2  s  .  co m*/

    theImageLoader.init(config);

    s_asyncHttpClient = new AsyncHttpClient();
    s_asyncHttpClient.getHttpClient().getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);

    m_data = new AbianReaderData();
    m_dataFetcher = new AbianReaderDataFetcher();

    WindowManager theWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display theDefaultDisplay = theWindowManager.getDefaultDisplay();

    DisplayMetrics theDisplayMetrics = new DisplayMetrics();
    theDefaultDisplay.getMetrics(theDisplayMetrics);
    s_width = theDisplayMetrics.widthPixels;
    s_height = theDisplayMetrics.heightPixels;

    m_handlerVector = new Vector<Handler>();
    m_adapterVector = new Vector<BaseAdapter>();

    m_bSplashScreenHasBeenShown = false;

    m_readUrlArrayList = null;

    loadReadUrlList();

    super.onCreate();
}

From source file:org.chromium.ChromeSystemDisplay.java

private JSONObject getBounds(final Display display) throws JSONException {
    JSONObject ret = new JSONObject();
    int widthPixels = 0;
    int heightPixels = 0;
    final DisplayMetrics displayMetrics = new DisplayMetrics();

    try {/*from w w  w.  ja  v a 2s.  c  o m*/
        display.getRealMetrics(displayMetrics);
    } catch (NoSuchMethodError e) {
        display.getMetrics(displayMetrics);
    }
    widthPixels = displayMetrics.widthPixels;
    heightPixels = displayMetrics.heightPixels;

    ret.put("left", 0);
    ret.put("top", 0);
    ret.put("width", widthPixels);
    ret.put("height", heightPixels);

    return ret;
}

From source file:com.imagine.BaseActivity.java

DisplayMetrics getDisplayMetrics(Display display) {
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);
    return metrics;
}

From source file:it.angrydroids.epub3reader.TextSelectionSupport.java

private float getDensityDependentValue(float val, Context ctx) {
    Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);
    return val * (metrics.densityDpi / 160f);
}

From source file:it.angrydroids.epub3reader.TextSelectionSupport.java

private float getDensityIndependentValue(float val, Context ctx) {
    Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);
    return val / (metrics.densityDpi / 160f);
}

From source file:ch.fhnw.comgr.GLES3Activity.java

@Override
public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR && GLES3Lib.usesRotation()) {
        // The ROTATION_VECTOR sensor is a virtual fusion sensor
        // The quality strongly depends on the underlying algorithm and on
        // the sensor manufacturer. (See also chapter 7 in the book:
        // "Professional Sensor Programming (WROX Publishing)"

        // Get 3x3 rotation matrix from XYZ-rotation vector (see docs)
        float R[] = new float[9];
        SensorManager.getRotationMatrixFromVector(R, event.values);

        // Get yaw, pitch & roll rotation angles in radians from rotation matrix
        float[] YPR = new float[3];
        SensorManager.getOrientation(R, YPR);

        // Check display orientation (a preset orientation is set in the AndroidManifext.xml)
        Display display = getWindowManager().getDefaultDisplay();
        DisplayMetrics displaymetrics = new DisplayMetrics();
        display.getMetrics(displaymetrics);
        int screenWidth = displaymetrics.widthPixels;
        int screenHeight = displaymetrics.heightPixels;

        if (screenWidth < screenHeight) { // Map pitch, yaw and roll to portrait display orientation
            final float p = YPR[1] * -1.0f - (float) Math.PI * 0.5f;
            final float y = YPR[0] * -1.0f;
            final float r = YPR[2] * -1.0f;
            myView.queueEvent(new Runnable() {
                public void run() {
                    GLES3Lib.onRotationPYR(p, y, r);
                }/*from   ww  w.j a  va 2s  . co m*/
            });
        } else { // Map pitch, yaw and roll to landscape display orientation for Oculus Rift conformance
            final float p = YPR[2] * -1.0f - (float) Math.PI * 0.5f;
            final float y = YPR[0] * -1.0f;
            final float r = YPR[1];
            myView.queueEvent(new Runnable() {
                public void run() {
                    GLES3Lib.onRotationPYR(p, y, r);
                }
            });
        }

        /*
           // Get the rotation quaternion from the XYZ-rotation vector (see docs)
        final float Q[] = new float[4];
        SensorManager.getQuaternionFromVector(Q, event.values);
        myView.queueEvent(new Runnable() {public void run() {GLES3Lib.onRotationQUAT(Q[1],Q[2],Q[3],Q[0]);}});
        */
    }
}

From source file:nl.privacybarometer.privacyvandaag.activity.HomeActivity.java

@Override
public void finish() {
    // On wide screens (tablets) the left menu drawer is always open,
    // so back button should finish the app immediately.
    // TODO: There should be an easier way to check if the wide-layout for tablets is used.
    Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);
    float density = getResources().getDisplayMetrics().density;
    float dpWidth = outMetrics.widthPixels / density;
    if (dpWidth >= 700f) { // on wide screen (tablet) finish immediately
        super.finish();
    } else { // on small screens if left menu drawer is open, close only left menu drawer.
        if (mDrawerLayout.isDrawerOpen(mLeftDrawer)) {
            mDrawerLayout.closeDrawer(mLeftDrawer);
        } else { // If left menu drawer is already closed, finish the app.
            super.finish();
        }//from  w w w .ja va  2  s  .  c o m
    }
}