Merge "Revert "[RRS] show resolution option on Settings page.""
This commit is contained in:
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.settings.display;
|
||||
|
||||
import static com.android.settings.display.ScreenResolutionController.FHD_WIDTH;
|
||||
import static com.android.settings.display.ScreenResolutionController.QHD_WIDTH;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
@@ -45,6 +48,7 @@ import com.android.settingslib.widget.IllustrationPreference;
|
||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -55,6 +59,8 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
private static final String TAG = "ScreenResolution";
|
||||
|
||||
private Resources mResources;
|
||||
private static final int FHD_INDEX = 0;
|
||||
private static final int QHD_INDEX = 1;
|
||||
private static final String SCREEN_RESOLUTION = "user_selected_resolution";
|
||||
private Display mDefaultDisplay;
|
||||
private String[] mScreenResolutionOptions;
|
||||
@@ -65,9 +71,6 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
private DisplayObserver mDisplayObserver;
|
||||
private AccessibilityManager mAccessibilityManager;
|
||||
|
||||
private int mHighWidth;
|
||||
private int mFullWidth;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
@@ -78,18 +81,11 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
mResources = context.getResources();
|
||||
mScreenResolutionOptions =
|
||||
mResources.getStringArray(R.array.config_screen_resolution_options_strings);
|
||||
mScreenResolutionSummaries =
|
||||
mResources.getStringArray(R.array.config_screen_resolution_summaries_strings);
|
||||
mResolutions = getAllSupportedResolution();
|
||||
mImagePreference = new IllustrationPreference(context);
|
||||
mDisplayObserver = new DisplayObserver(context);
|
||||
ScreenResolutionController mController =
|
||||
new ScreenResolutionController(context, "fragment");
|
||||
mResolutions = mController.getAllSupportedResolutions();
|
||||
mHighWidth = mController.getHighWidth();
|
||||
mFullWidth = mController.getFullWidth();
|
||||
mScreenResolutionSummaries =
|
||||
new String[] {
|
||||
mHighWidth + " x " + mController.getHighHeight(),
|
||||
mFullWidth + " x " + mController.getFullHeight()
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -137,6 +133,16 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
return candidates;
|
||||
}
|
||||
|
||||
/** Get all supported resolutions on the device. */
|
||||
private Set<Point> getAllSupportedResolution() {
|
||||
Set<Point> resolutions = new HashSet<>();
|
||||
for (Display.Mode mode : mDefaultDisplay.getSupportedModes()) {
|
||||
resolutions.add(new Point(mode.getPhysicalWidth(), mode.getPhysicalHeight()));
|
||||
}
|
||||
|
||||
return resolutions;
|
||||
}
|
||||
|
||||
/** Get prefer display mode. */
|
||||
private Display.Mode getPreferMode(int width) {
|
||||
for (Point resolution : mResolutions) {
|
||||
@@ -171,7 +177,6 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
|
||||
try {
|
||||
/** Apply the resolution change. */
|
||||
Log.i(TAG, "setUserPreferredDisplayMode: " + mode);
|
||||
mDefaultDisplay.setUserPreferredDisplayMode(mode);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "setUserPreferredDisplayMode() failed", e);
|
||||
@@ -189,19 +194,16 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
/** Get the key corresponding to the resolution. */
|
||||
@VisibleForTesting
|
||||
String getKeyForResolution(int width) {
|
||||
return width == mHighWidth
|
||||
? mScreenResolutionOptions[ScreenResolutionController.HIGHRESOLUTION_IDX]
|
||||
: width == mFullWidth
|
||||
? mScreenResolutionOptions[ScreenResolutionController.FULLRESOLUTION_IDX]
|
||||
: null;
|
||||
return width == FHD_WIDTH
|
||||
? mScreenResolutionOptions[FHD_INDEX]
|
||||
: width == QHD_WIDTH ? mScreenResolutionOptions[QHD_INDEX] : null;
|
||||
}
|
||||
|
||||
/** Get the width corresponding to the resolution key. */
|
||||
int getWidthForResoluitonKey(String key) {
|
||||
return mScreenResolutionOptions[ScreenResolutionController.HIGHRESOLUTION_IDX].equals(key)
|
||||
? mHighWidth
|
||||
: mScreenResolutionOptions[ScreenResolutionController.FULLRESOLUTION_IDX].equals(
|
||||
key) ? mFullWidth : -1;
|
||||
return mScreenResolutionOptions[FHD_INDEX].equals(key)
|
||||
? FHD_WIDTH
|
||||
: mScreenResolutionOptions[QHD_INDEX].equals(key) ? QHD_WIDTH : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -246,11 +248,9 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
private void updateIllustrationImage(IllustrationPreference preference) {
|
||||
String key = getDefaultKey();
|
||||
|
||||
if (TextUtils.equals(
|
||||
mScreenResolutionOptions[ScreenResolutionController.HIGHRESOLUTION_IDX], key)) {
|
||||
if (TextUtils.equals(mScreenResolutionOptions[FHD_INDEX], key)) {
|
||||
preference.setLottieAnimationResId(R.drawable.screen_resolution_1080p);
|
||||
} else if (TextUtils.equals(
|
||||
mScreenResolutionOptions[ScreenResolutionController.FULLRESOLUTION_IDX], key)) {
|
||||
} else if (TextUtils.equals(mScreenResolutionOptions[QHD_INDEX], key)) {
|
||||
preference.setLottieAnimationResId(R.drawable.screen_resolution_1440p);
|
||||
}
|
||||
}
|
||||
@@ -408,8 +408,6 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
return false;
|
||||
}
|
||||
|
||||
Log.i(TAG,
|
||||
"resolution changed from " + mPreviousWidth.get() + " to " + getCurrentWidth());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user