android: Settings: move display rotation out of HdmiSettings

Signed-off-by: hmz007 <hmz007@gmail.com>
master
hmz007 4 years ago
parent 7c287c2cb2
commit 7c5aef864f

@ -1475,17 +1475,17 @@
<item>720x576p-50\n</item>
<item>720x480p-60\n</item>
</string-array>
<string-array name="hdmi_rotation_entries">
<string-array name="user_rotation_entries">
<item>0</item>
<item>90</item>
<item>180</item>
<item>270</item>
</string-array>
<string-array name="hdmi_rotation_values">
<string-array name="user_rotation_values">
<item>0</item>
<item>90</item>
<item>180</item>
<item>270</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
<string-array name="dual_screen_ver_hor_entries">
<item>0</item>

@ -12380,9 +12380,9 @@
<string name="help_url_screenshot" translatable="false"></string>
<!--hdmi settings-->
<string name="hdmi_settings">HDMI &amp; Rotation</string>
<string name="hdmi_dashboard_summary">Set preferred Resolution, Overscan and Rotation</string>
<string name="system_rotation">Display Rotation</string>
<string name="hdmi_settings">External Display</string>
<string name="hdmi_dashboard_summary">Set preferred Resolution, Overscan</string>
<string name="system_rotation">Lock rotation</string>
<string name="screen_title">Screen Setting</string>
<string name="screen_main_title">Main Screen</string>
<string name="screen_aux_title">Aux Screen</string>

@ -132,6 +132,14 @@
settings:keywords="@string/keywords_screen_resolution"
settings:controller="com.android.settings.display.ScreenResolutionController"/>
<ListPreference
android:key="system_rotation"
android:title="@string/system_rotation"
android:persistent="false"
android:entries="@array/user_rotation_entries"
android:entryValues="@array/user_rotation_values"
settings:controller="com.android.settings.display.LockUserRotationPreferenceController" />
<SwitchPreference
android:key="display_white_balance"
android:title="@string/display_white_balance_title"
@ -229,4 +237,5 @@
settings:controller="com.android.settings.display.DisplayHuePreferenceController"/>
<!-- ======================================== -->
</PreferenceCategory>
</PreferenceScreen>

@ -13,12 +13,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:entries="@array/hdmi_rotation_entries"
android:entryValues="@array/hdmi_rotation_values"
android:key="system_rotation"
android:title="@string/system_rotation" />
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/hdmi_settings">
<PreferenceCategory
android:key="aux_category"
android:title="@string/screen_title">
@ -31,4 +30,5 @@
android:key="aux_screen_vhlist"
android:title="@string/screen_rotation" />
</PreferenceCategory>
</PreferenceScreen>

@ -26,12 +26,10 @@ import android.hardware.display.DisplayManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.preference.Preference.OnPreferenceChangeListener;
import android.text.TextUtils;
import android.util.Log;
import android.view.IWindowManager;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.View;
@ -66,7 +64,6 @@ public class HdmiSettings extends SettingsPreferenceFragment
* Called when the activity is first created.
*/
private static final String TAG = "HdmiSettings";
private static final String KEY_SYSTEM_ROTATION = "system_rotation";
private static final String KEY_PRE_CATE = "Display";
private static final String KEY_PRE_RESOLUTION = "Resolution";
private static final String KEY_PRE_SCREEN_SCALE = "ScreenScale";
@ -100,8 +97,6 @@ public class HdmiSettings extends SettingsPreferenceFragment
private String main_switch_node = SYS_NODE_HDMI_STATUS;
private String aux_switch_node = SYS_NODE_DP_STATUS;
private boolean mShowSystemRotation = true;
private ListPreference mSystemRotation;
private PreferenceCategory mAuxCategory;
private CheckBoxPreference mAuxScreenVH;
private ListPreference mAuxScreenVHList;
@ -109,14 +104,13 @@ public class HdmiSettings extends SettingsPreferenceFragment
private DisplayInfo mSelectDisplayInfo;
private DisplayManager mDisplayManager;
private DisplayListener mDisplayListener;
private IWindowManager mWindowManager;
private ProgressDialog mProgressDialog;
private boolean mDestory;
private boolean mEnableDisplayListener;
private Object mLock = new Object();//maybe android reboot if not lock with new thread
private boolean mResume;
private long mWaitDialogCountTime;
private int mRotation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
private int mOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
private final String HDMI_ACTION = "android.intent.action.HDMI_PLUGGED";
private final String DP_ACTION = "android.intent.action.DP_PLUGGED";
@ -256,11 +250,9 @@ public class HdmiSettings extends SettingsPreferenceFragment
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getActivity();
mRotation = getActivity().getRequestedOrientation();
mOrientation = getActivity().getRequestedOrientation();
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
mDisplayManager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
mWindowManager = IWindowManager.Stub.asInterface(
ServiceManager.getService(Context.WINDOW_SERVICE));
mDisplayListener = new DisplayListener();
addPreferencesFromResource(R.xml.hdmi_settings);
init();
@ -319,7 +311,7 @@ public class HdmiSettings extends SettingsPreferenceFragment
public void onDestroy() {
mDestory = true;
getActivity().setRequestedOrientation(mRotation);
getActivity().setRequestedOrientation(mOrientation);
super.onDestroy();
mHandler.removeMessages(MSG_UPDATE_STATUS);
mHandler.removeMessages(MSG_SWITCH_DEVICE_STATUS);
@ -330,34 +322,6 @@ public class HdmiSettings extends SettingsPreferenceFragment
}
private void init() {
if (mShowSystemRotation) {
mSystemRotation = (ListPreference) findPreference(KEY_SYSTEM_ROTATION);
mSystemRotation.setOnPreferenceChangeListener(this);
try {
int rotation = mWindowManager.getDefaultDisplayRotation();
switch (rotation) {
case Surface.ROTATION_0:
mSystemRotation.setValue("0");
break;
case Surface.ROTATION_90:
mSystemRotation.setValue("90");
break;
case Surface.ROTATION_180:
mSystemRotation.setValue("180");
break;
case Surface.ROTATION_270:
mSystemRotation.setValue("270");
break;
default:
mSystemRotation.setValue("0");
}
} catch (Exception e) {
Log.e(TAG, e.toString());
}
} else {
removePreference(KEY_SYSTEM_ROTATION);
}
int displayNumber = DrmDisplaySetting.getDisplayNumber();
Log.v(TAG, "displayNumber=" + displayNumber);
String[] connectorInfos = DrmDisplaySetting.getConnectorInfo();
@ -394,6 +358,7 @@ public class HdmiSettings extends SettingsPreferenceFragment
category.setTitle(typeName + "-" + id);
}
getPreferenceScreen().addPreference(category);
//add resolution preference
HdmiListPreference resolutionPreference = new HdmiListPreference(mContext);
resolutionPreference.setKey(KEY_PRE_RESOLUTION + display);
@ -401,6 +366,7 @@ public class HdmiSettings extends SettingsPreferenceFragment
resolutionPreference.setOnPreferenceClickListener(this);
resolutionPreference.setOnPreferenceChangeListener(this);
category.addPreference(resolutionPreference);
//add scale preference
Preference scalePreference = new Preference(mContext);
scalePreference.setKey(KEY_PRE_SCREEN_SCALE + display);
@ -675,28 +641,6 @@ public class HdmiSettings extends SettingsPreferenceFragment
}
preference.getParent().setEnabled(false);
updateResolution(ITEM_CONTROL.CHANGE_RESOLUTION, index);
} else if (preference == mSystemRotation) {
if (KEY_SYSTEM_ROTATION.equals(key)) {
try {
int value = Integer.parseInt((String) obj);
android.os.SystemProperties.set("persist.sys.orientation", (String) obj);
Log.d(TAG, "freezeRotation~~~value:" + (String) obj);
if (value == 0) {
mWindowManager.freezeRotation(Surface.ROTATION_0);
} else if (value == 90) {
mWindowManager.freezeRotation(Surface.ROTATION_90);
} else if (value == 180) {
mWindowManager.freezeRotation(Surface.ROTATION_180);
} else if (value == 270) {
mWindowManager.freezeRotation(Surface.ROTATION_270);
} else {
return true;
}
//android.os.SystemProperties.set("sys.boot_completed", "1");
} catch (Exception e) {
Log.e(TAG, "freezeRotation error");
}
}
} else if (preference == mAuxScreenVH) {
mEnableDisplayListener = false;
showWaitingDialog(R.string.dialog_wait_screen_connect);

@ -0,0 +1,124 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.display;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.IWindowManager;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import java.util.HashMap;
import java.util.Map;
public class LockUserRotationPreferenceController extends BasePreferenceController implements
Preference.OnPreferenceChangeListener {
private static final String TAG = "LockRotation";
private final Map<String, String> mRotationValueToTitleMap;
private int mUserRotation;
private Handler mHandler;
private IWindowManager mWindowManager;
public LockUserRotationPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
mHandler = new Handler(Looper.getMainLooper());
mWindowManager = IWindowManager.Stub.asInterface(
ServiceManager.getService(Context.WINDOW_SERVICE));
mRotationValueToTitleMap = new HashMap<>();
initDisplayRotation();
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public boolean onPreferenceChange(Preference preference, Object object) {
if (!(preference instanceof ListPreference)) {
return false;
}
final ListPreference listPreference = (ListPreference) preference;
mUserRotation = Integer.parseInt((String) object);
updateState(listPreference);
Log.d(TAG, "freeze Rotation to " + mUserRotation);
mHandler.postDelayed(() -> {
try {
mWindowManager.freezeRotation(mUserRotation);
} catch (Exception e) {
Log.e(TAG, "Failed to set user rotation", e);
}
}, 150);
return true;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (!(preference instanceof ListPreference)) {
return;
}
final ListPreference listPreference = (ListPreference) preference;
listPreference.setValue(getUserRotationValue());
}
@Override
public CharSequence getSummary() {
return mRotationValueToTitleMap.get(getUserRotationValue());
}
private String getUserRotationValue() {
return String.valueOf(mUserRotation);
}
private void initDisplayRotation() {
if (mRotationValueToTitleMap.size() == 0) {
final String[] rotationValues = mContext.getResources().getStringArray(
R.array.user_rotation_values);
final String[] rotationTitles = mContext.getResources().getStringArray(
R.array.user_rotation_entries);
final int rotationValueCount = rotationValues.length;
mRotationValueToTitleMap.put(rotationValues[0], "natural orientation");
for (int i = 1; i < rotationValueCount; i++) {
mRotationValueToTitleMap.put(rotationValues[i],
"clockwise " + rotationTitles[i] + "-degree");
}
try {
mUserRotation = mWindowManager.getDefaultDisplayRotation();
} catch (Exception e) {
Log.e(TAG, "Failed to get default rotation", e);
mUserRotation = Integer.parseInt(rotationValues[0]);
}
}
}
}
Loading…
Cancel
Save