mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-28 15:56:49 +00:00
Refresh DisplayContext to prevent getting stale DisplayMetrics
Bug: 176656141 Test: Change font size or display size, it should reflect on home screen icon/text sizes. Change-Id: I39bb9d11d246c7ccea1ea4d5af37fba3ce0001be
This commit is contained in:
@@ -648,8 +648,13 @@ public class DeviceProfile {
|
||||
public boolean updateIsSeascape(Context context) {
|
||||
if (isVerticalBarLayout()) {
|
||||
// Check an up-to-date info.
|
||||
boolean isSeascape = DisplayController.getDefaultDisplay(context)
|
||||
.createInfoForContext(context).rotation == Surface.ROTATION_270;
|
||||
DisplayController.Info displayInfo = DisplayController.getDefaultDisplay(context)
|
||||
.createInfoForContext(context);
|
||||
if (displayInfo == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean isSeascape = displayInfo.rotation == Surface.ROTATION_270;
|
||||
if (mIsSeascape != isSeascape) {
|
||||
mIsSeascape = isSeascape;
|
||||
return true;
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.Display;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.launcher3.Utilities;
|
||||
@@ -182,20 +183,26 @@ public class DisplayController implements DisplayListener {
|
||||
}
|
||||
|
||||
/** Creates and up-to-date DisplayController.Info for the given context. */
|
||||
@Nullable
|
||||
public Info createInfoForContext(Context context) {
|
||||
Display display = Utilities.ATLEAST_R
|
||||
? context.getDisplay()
|
||||
: context
|
||||
.getSystemService(DisplayManager.class)
|
||||
.getDisplay(mId);
|
||||
return display == null
|
||||
? new Info(context)
|
||||
: new Info(context, display);
|
||||
Display display = Utilities.ATLEAST_R ? context.getDisplay() : null;
|
||||
if (display == null) {
|
||||
display = context.getSystemService(DisplayManager.class).getDisplay(mId);
|
||||
}
|
||||
if (display == null) {
|
||||
return null;
|
||||
}
|
||||
// Refresh the Context the prevent stale DisplayMetrics.
|
||||
Context displayContext = context.getApplicationContext().createDisplayContext(display);
|
||||
return new Info(displayContext, display);
|
||||
}
|
||||
|
||||
protected void handleOnChange() {
|
||||
Info oldInfo = mInfo;
|
||||
Info newInfo = createInfoForContext(mDisplayContext);
|
||||
if (newInfo == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int change = 0;
|
||||
if (newInfo.hasDifferentSize(oldInfo)) {
|
||||
|
||||
Reference in New Issue
Block a user