Merge "Set the same density to all displays" into main

This commit is contained in:
Piotr Wilczyński
2024-10-17 15:17:59 +00:00
committed by Android (Google) Code Review
6 changed files with 27 additions and 32 deletions

View File

@@ -35,7 +35,7 @@ class DisplaySizeData extends PreviewSizeData<Integer> {
super(context); super(context);
mDensity = new DisplayDensityUtils(getContext()); mDensity = new DisplayDensityUtils(getContext());
final int initialIndex = mDensity.getCurrentIndexForDefaultDisplay(); final int initialIndex = mDensity.getCurrentIndex();
if (initialIndex < 0) { if (initialIndex < 0) {
// Failed to obtain default density, which means we failed to // Failed to obtain default density, which means we failed to
// connect to the window manager service. Just use the current // connect to the window manager service. Just use the current
@@ -46,9 +46,9 @@ class DisplaySizeData extends PreviewSizeData<Integer> {
setInitialIndex(0); setInitialIndex(0);
setValues(Collections.singletonList(densityDpi)); setValues(Collections.singletonList(densityDpi));
} else { } else {
setDefaultValue(mDensity.getDefaultDensityForDefaultDisplay()); setDefaultValue(mDensity.getDefaultDensity());
setInitialIndex(initialIndex); setInitialIndex(initialIndex);
setValues(Arrays.stream(mDensity.getDefaultDisplayDensityValues()).boxed() setValues(Arrays.stream(mDensity.getValues()).boxed()
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
} }

View File

@@ -207,10 +207,9 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
@VisibleForTesting @VisibleForTesting
protected boolean shouldShowLottie() { protected boolean shouldShowLottie() {
DisplayDensityUtils displayDensity = new DisplayDensityUtils(getApplicationContext()); DisplayDensityUtils displayDensity = new DisplayDensityUtils(getApplicationContext());
int currentDensityIndex = displayDensity.getCurrentIndexForDefaultDisplay(); int currentDensityIndex = displayDensity.getCurrentIndex();
final int currentDensity = displayDensity.getDefaultDisplayDensityValues() final int currentDensity = displayDensity.getValues()[currentDensityIndex];
[currentDensityIndex]; final int defaultDensity = displayDensity.getDefaultDensity();
final int defaultDensity = displayDensity.getDefaultDensityForDefaultDisplay();
if (getResources().getConfiguration().fontScale > 1) { if (getResources().getConfiguration().fontScale > 1) {
return false; return false;

View File

@@ -42,7 +42,7 @@ interface DisplayDensityInteractor {
val fontScale: Flow<Float> val fontScale: Flow<Float>
/** A flow that propagates displayDensity. */ /** A flow that propagates displayDensity. */
val displayDensity: Flow<Int> val displayDensity: Flow<Int?>
/** A flow that propagates the default display density. */ /** A flow that propagates the default display density. */
val defaultDisplayDensity: Flow<Int> val defaultDisplayDensity: Flow<Int>
@@ -67,16 +67,14 @@ class DisplayDensityInteractorImpl(context: Context, scope: CoroutineScope) :
private val _fontScale = MutableStateFlow(context.resources.configuration.fontScale) private val _fontScale = MutableStateFlow(context.resources.configuration.fontScale)
private val _displayDensity = private val _displayDensity =
MutableStateFlow( MutableStateFlow(displayDensityUtils.values?.let{
displayDensityUtils.defaultDisplayDensityValues[ it[displayDensityUtils.currentIndex]
displayDensityUtils.currentIndexForDefaultDisplay] })
)
override val fontScale: Flow<Float> = _fontScale.asStateFlow() override val fontScale: Flow<Float> = _fontScale.asStateFlow()
override val displayDensity: Flow<Int> = _displayDensity.asStateFlow() override val displayDensity: Flow<Int?> = _displayDensity.asStateFlow()
override val defaultDisplayDensity: Flow<Int> = override val defaultDisplayDensity: Flow<Int> =
flowOf(displayDensityUtils.defaultDensityForDefaultDisplay) flowOf(displayDensityUtils.defaultDensity).shareIn(scope, SharingStarted.Eagerly, 1)
.shareIn(scope, SharingStarted.Eagerly, 1)
} }

View File

@@ -149,11 +149,11 @@ class FingerprintEnrollmentV2Activity : FragmentActivity() {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
foldStateInteractor.onConfigurationChange(newConfig) foldStateInteractor.onConfigurationChange(newConfig)
val displayDensityUtils = DisplayDensityUtils(applicationContext) val displayDensityUtils = DisplayDensityUtils(applicationContext)
val currIndex = displayDensityUtils.currentIndexForDefaultDisplay val currIndex = displayDensityUtils.currentIndex
displayDensityInteractor.updateFontScale(resources.configuration.fontScale) displayDensityInteractor.updateFontScale(resources.configuration.fontScale)
displayDensityInteractor.updateDisplayDensity( displayDensityUtils.values?.let {
displayDensityUtils.defaultDisplayDensityValues[currIndex] displayDensityInteractor.updateDisplayDensity(it[currIndex])
) }
} }
private fun onConfirmDevice(resultCode: Int, data: Intent?) { private fun onConfirmDevice(resultCode: Int, data: Intent?) {

View File

@@ -325,11 +325,10 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
} }
final DisplayDensityUtils density = new DisplayDensityUtils(mContext); final DisplayDensityUtils density = new DisplayDensityUtils(mContext);
final int currentIndex = density.getCurrentIndexForDefaultDisplay(); final int currentIndex = density.getCurrentIndex();
final int defaultDensity = density.getDefaultDensityForDefaultDisplay(); final int defaultDensity = density.getDefaultDensity();
if (density.getDefaultDisplayDensityValues()[mCurrentIndex] if (density.getValues()[mCurrentIndex] == density.getDefaultDensity()) {
== density.getDefaultDensityForDefaultDisplay()) {
return; return;
} }
@@ -373,20 +372,19 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
/* If current density is the same as a default density of other resolutions, /* If current density is the same as a default density of other resolutions,
* then mCurrentIndex may be out of boundary. * then mCurrentIndex may be out of boundary.
*/ */
if (density.getDefaultDisplayDensityValues().length <= mCurrentIndex) { if (density.getValues().length <= mCurrentIndex) {
mCurrentIndex = density.getCurrentIndexForDefaultDisplay(); mCurrentIndex = density.getCurrentIndex();
} }
if (density.getDefaultDisplayDensityValues()[mCurrentIndex] if (density.getValues()[mCurrentIndex] != density.getDefaultDensity()) {
!= density.getDefaultDensityForDefaultDisplay()) {
density.setForcedDisplayDensity(mCurrentIndex); density.setForcedDisplayDensity(mCurrentIndex);
} }
mDefaultDensity = density.getDefaultDensityForDefaultDisplay(); mDefaultDensity = density.getDefaultDensity();
} }
private boolean isDensityChanged() { private boolean isDensityChanged() {
final DisplayDensityUtils density = new DisplayDensityUtils(mContext); final DisplayDensityUtils density = new DisplayDensityUtils(mContext);
if (density.getDefaultDensityForDefaultDisplay() == mDefaultDensity) { if (density.getDefaultDensity() == mDefaultDensity) {
return false; return false;
} }

View File

@@ -36,13 +36,13 @@ public class ScreenZoomPreference extends Preference {
android.R.attr.preferenceStyle)); android.R.attr.preferenceStyle));
final DisplayDensityUtils density = new DisplayDensityUtils(context); final DisplayDensityUtils density = new DisplayDensityUtils(context);
final int defaultIndex = density.getCurrentIndexForDefaultDisplay(); final int defaultIndex = density.getCurrentIndex();
if (defaultIndex < 0) { if (defaultIndex < 0) {
setVisible(false); setVisible(false);
setEnabled(false); setEnabled(false);
} else if (TextUtils.isEmpty(getSummary())) { } else if (TextUtils.isEmpty(getSummary())) {
final String[] entries = density.getDefaultDisplayDensityEntries(); final String[] entries = density.getEntries();
final int currentIndex = density.getCurrentIndexForDefaultDisplay(); final int currentIndex = density.getCurrentIndex();
setSummary(entries[currentIndex]); setSummary(entries[currentIndex]);
} }
} }