Merge change 7106 into donut
* changes: Return adjusted display for WindowManager.getDefaultDisplay()
This commit is contained in:
@ -34,6 +34,7 @@ import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.util.TypedValue;
|
||||
import android.util.LongSparseArray;
|
||||
import android.view.Display;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -87,6 +88,7 @@ public class Resources {
|
||||
PluralRules mPluralRule;
|
||||
|
||||
private final CompatibilityInfo mCompatibilityInfo;
|
||||
private Display mDefaultDisplay;
|
||||
|
||||
private static final LongSparseArray<Object> EMPTY_ARRAY = new LongSparseArray<Object>() {
|
||||
@Override
|
||||
@ -1915,6 +1917,24 @@ public class Resources {
|
||||
+ Integer.toHexString(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the display adjusted for the Resources' metrics.
|
||||
* @hide
|
||||
*/
|
||||
public Display getDefaultDisplay(Display defaultDisplay) {
|
||||
if (mDefaultDisplay == null) {
|
||||
if (!mCompatibilityInfo.isScalingRequired() && mCompatibilityInfo.supportsScreen()) {
|
||||
// the app supports the display. just use the default one.
|
||||
mDefaultDisplay = defaultDisplay;
|
||||
} else {
|
||||
// display needs adjustment.
|
||||
mDefaultDisplay = Display.createMetricsBasedDisplay(
|
||||
defaultDisplay.getDisplayId(), mMetrics);
|
||||
}
|
||||
}
|
||||
return mDefaultDisplay;
|
||||
}
|
||||
|
||||
private TypedArray getCachedStyledAttributes(int len) {
|
||||
synchronized (mTmpValue) {
|
||||
TypedArray attrs = mCachedStyledAttributes;
|
||||
|
@ -117,5 +117,32 @@ public class Display
|
||||
|
||||
private static final Object mStaticInit = new Object();
|
||||
private static boolean mInitialized = false;
|
||||
|
||||
/**
|
||||
* Returns a display object which uses the metric's width/height instead.
|
||||
* @hide
|
||||
*/
|
||||
public static Display createMetricsBasedDisplay(int displayId, DisplayMetrics metrics) {
|
||||
return new CompatibleDisplay(displayId, metrics);
|
||||
}
|
||||
|
||||
private static class CompatibleDisplay extends Display {
|
||||
private final DisplayMetrics mMetrics;
|
||||
|
||||
private CompatibleDisplay(int displayId, DisplayMetrics metrics) {
|
||||
super(displayId);
|
||||
mMetrics = metrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return mMetrics.widthPixels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return mMetrics.heightPixels;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -358,6 +358,8 @@ public abstract class Window {
|
||||
private class LocalWindowManager implements WindowManager {
|
||||
LocalWindowManager(WindowManager wm) {
|
||||
mWindowManager = wm;
|
||||
mDefaultDisplay = mContext.getResources().getDefaultDisplay(
|
||||
mWindowManager.getDefaultDisplay());
|
||||
}
|
||||
|
||||
public final void addView(View view, ViewGroup.LayoutParams params) {
|
||||
@ -420,10 +422,12 @@ public abstract class Window {
|
||||
}
|
||||
|
||||
public Display getDefaultDisplay() {
|
||||
return mWindowManager.getDefaultDisplay();
|
||||
return mDefaultDisplay;
|
||||
}
|
||||
|
||||
WindowManager mWindowManager;
|
||||
private final WindowManager mWindowManager;
|
||||
|
||||
private final Display mDefaultDisplay;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user