Merge "Use isolated display context to get display info" into rvc-dev am: 7f5a670cc3 am: f58ec22c1c am: 0891adf289
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/11969858 Change-Id: I0264709ff4310de7136e253d1c5279ef39fb88e1
This commit is contained in:
@@ -49,20 +49,25 @@ public class DefaultDisplay implements DisplayListener {
|
|||||||
|
|
||||||
public static final int CHANGE_ALL = CHANGE_SIZE | CHANGE_ROTATION | CHANGE_FRAME_DELAY;
|
public static final int CHANGE_ALL = CHANGE_SIZE | CHANGE_ROTATION | CHANGE_FRAME_DELAY;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mDisplayContext;
|
||||||
private final int mId;
|
private final int mId;
|
||||||
private final ArrayList<DisplayInfoChangeListener> mListeners = new ArrayList<>();
|
private final ArrayList<DisplayInfoChangeListener> mListeners = new ArrayList<>();
|
||||||
private final Handler mChangeHandler;
|
private final Handler mChangeHandler;
|
||||||
private Info mInfo;
|
private Info mInfo;
|
||||||
|
|
||||||
private DefaultDisplay(Context context) {
|
private DefaultDisplay(Context context) {
|
||||||
mContext = context;
|
DisplayManager dm = context.getSystemService(DisplayManager.class);
|
||||||
mInfo = new Info(context);
|
// Use application context to create display context so that it can have its own Resources.
|
||||||
|
mDisplayContext = context.getApplicationContext().createDisplayContext(
|
||||||
|
dm.getDisplay(DEFAULT_DISPLAY));
|
||||||
|
// Note that the Display object must be obtained from DisplayManager which is associated to
|
||||||
|
// the display context, so the Display is isolated from Activity and Application to provide
|
||||||
|
// the actual state of device that excludes the additional adjustment and override.
|
||||||
|
mInfo = new Info(mDisplayContext);
|
||||||
mId = mInfo.id;
|
mId = mInfo.id;
|
||||||
mChangeHandler = new Handler(this::onChange);
|
mChangeHandler = new Handler(this::onChange);
|
||||||
|
|
||||||
context.getSystemService(DisplayManager.class)
|
dm.registerDisplayListener(this, UI_HELPER_EXECUTOR.getHandler());
|
||||||
.registerDisplayListener(this, UI_HELPER_EXECUTOR.getHandler());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -78,7 +83,7 @@ public class DefaultDisplay implements DisplayListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Info oldInfo = mInfo;
|
Info oldInfo = mInfo;
|
||||||
Info info = new Info(mContext);
|
Info info = new Info(mDisplayContext);
|
||||||
|
|
||||||
int change = 0;
|
int change = 0;
|
||||||
if (info.hasDifferentSize(oldInfo)) {
|
if (info.hasDifferentSize(oldInfo)) {
|
||||||
@@ -162,8 +167,7 @@ public class DefaultDisplay implements DisplayListener {
|
|||||||
display.getRealSize(realSize);
|
display.getRealSize(realSize);
|
||||||
display.getCurrentSizeRange(smallestSize, largestSize);
|
display.getCurrentSizeRange(smallestSize, largestSize);
|
||||||
|
|
||||||
Context defaultDisplayContext = context.createDisplayContext(display);
|
metrics = context.getResources().getDisplayMetrics();
|
||||||
metrics = defaultDisplayContext.getResources().getDisplayMetrics();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasDifferentSize(Info info) {
|
private boolean hasDifferentSize(Info info) {
|
||||||
|
|||||||
Reference in New Issue
Block a user