Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21fa8d31 authored by Android (Google) Code Review's avatar Android (Google) Code Review Committed by The Android Open Source Project
Browse files

am 7e3e04c1: Merge change 1408 into donut

Merge commit '7e3e04c1'

* commit '7e3e04c1':
  * update all metrics data when updating density.
parents a571e4e3 7e3e04c1
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -191,16 +191,11 @@ public final class ActivityThread {
                usePreloaded = false;
                DisplayMetrics newMetrics = new DisplayMetrics();
                newMetrics.setTo(metrics);
                float invertedScale = 1.0f / applicationScale;
                newMetrics.density *= invertedScale;
                newMetrics.xdpi *= invertedScale;
                newMetrics.ydpi *= invertedScale;
                newMetrics.widthPixels *= invertedScale;
                newMetrics.heightPixels *= invertedScale;
                float newDensity = metrics.density / applicationScale;
                newMetrics.updateDensity(newDensity);
                metrics = newMetrics;
            }
            //Log.i(TAG, "Resource:" + appDir + ", density " + newMetrics.density + ", orig density:" +
            //      metrics.density);
            //Log.i(TAG, "Resource:" + appDir + ", display metrics=" + metrics);
            r = new Resources(assets, metrics, getConfiguration(), usePreloaded);
            //Log.i(TAG, "Created app resources " + r + ": " + r.getConfiguration());
            // XXX need to remove entries when weak references go away
@@ -3502,8 +3497,11 @@ public final class ActivityThread {
                    Resources r = v.get();
                    if (r != null) {
                        // keep the original density based on application cale.
                        appDm.density = r.getDisplayMetrics().density;
                        appDm.updateDensity(r.getDisplayMetrics().density);
                        Log.i("oshima", "Updated app display metrics " + appDm);
                        r.updateConfiguration(config, appDm);
                        // reset
                        appDm.setTo(dm);
                        //Log.i(TAG, "Updated app resources " + v.getKey()
                        //        + " " + r + ": " + r.getConfiguration());
                    } else {
+6 −6
Original line number Diff line number Diff line
@@ -27,8 +27,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.util.Xml;
import android.view.Display;
import android.view.WindowManager;
import android.util.DisplayMetrics;

import java.io.IOException;
import java.util.ArrayList;
@@ -510,10 +509,11 @@ public class Keyboard {
     * @param modeId keyboard mode identifier
     */
    public Keyboard(Context context, int xmlLayoutResId, int modeId) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        final Display display = wm.getDefaultDisplay();
        mDisplayWidth = display.getWidth();
        mDisplayHeight = display.getHeight();
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        mDisplayWidth = dm.widthPixels;
        mDisplayHeight = dm.heightPixels;
        //Log.v(TAG, "keyboard's display metrics:" + dm);

        mDefaultHorizontalGap = 0;
        mDefaultWidth = mDisplayWidth / 10;
        mDefaultVerticalGap = 0;
+20 −0
Original line number Diff line number Diff line
@@ -99,4 +99,24 @@ public class DisplayMetrics {
        xdpi = DEVICE_DENSITY;
        ydpi = DEVICE_DENSITY;
    }

    /**
     * Set the display metrics' density and update parameters depend on it.
     * @hide
     */
    public void updateDensity(float newDensity) {
        float ratio = newDensity / density;
        density = newDensity;
        scaledDensity = density;
        widthPixels *= ratio;
        heightPixels *= ratio;
        xdpi *= ratio;
        ydpi *= ratio;
    }

    public String toString() {
        return "DisplayMetrics{density=" + density + ", width=" + widthPixels +
            ", height=" + heightPixels + ", scaledDensity=" + scaledDensity +
            ", xdpi=" + xdpi + ", ydpi=" + ydpi + "}";
    }
}