Loading quickstep/res/xml/indexable_launcher_prefs.xml +8 −2 Original line number Diff line number Diff line Loading @@ -20,8 +20,14 @@ android:key="pref_add_icon_to_home" android:title="@string/auto_add_shortcuts_label" android:summary="@string/auto_add_shortcuts_description" android:defaultValue="true" /> android:defaultValue="true" /> <SwitchPreference android:key="pref_allowRotation" android:title="@string/allow_rotation_title" android:summary="@string/allow_rotation_desc" android:defaultValue="@bool/allow_rotation" android:persistent="true" /> <ListPreference android:key="pref_override_icon_shape" Loading res/values/strings.xml +6 −0 Original line number Diff line number Diff line Loading @@ -179,6 +179,12 @@ <string name="msg_disabled_by_admin">Disabled by your admin</string> <!-- Strings for settings --> <!-- Title for Allow Rotation setting. [CHAR LIMIT=50] --> <string name="allow_rotation_title">Allow Home screen rotation</string> <!-- Text explaining when the home screen will get rotated. [CHAR LIMIT=100] --> <string name="allow_rotation_desc">When phone is rotated</string> <!-- Text explaining that rotation is disabled in Display settings. 'Display' refers to the Display section in system settings [CHAR LIMIT=100] --> <string name="allow_rotation_blocked_desc">Current Display setting doesn\'t permit rotation</string> <!-- Title for Notification dots setting. Tapping this will link to the system Notifications settings screen where the user can turn off notification dots globally. [CHAR LIMIT=50] --> <string name="icon_badging_title">Notification dots</string> <!-- Text to indicate that the system icon badging setting is on [CHAR LIMIT=100] --> Loading res/xml/launcher_preferences.xml +7 −2 Original line number Diff line number Diff line Loading @@ -34,8 +34,13 @@ android:title="@string/auto_add_shortcuts_label" android:summary="@string/auto_add_shortcuts_description" android:defaultValue="true" android:persistent="true" /> android:persistent="true" /> <SwitchPreference android:key="pref_allowRotation" android:title="@string/allow_rotation_title" android:defaultValue="@bool/allow_rotation" android:persistent="true" /> <ListPreference android:key="pref_override_icon_shape" Loading src/com/android/launcher3/SettingsActivity.java +41 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package com.android.launcher3; import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY; import static com.android.launcher3.states.RotationHelper.getAllowRotationDefaultValue; import android.annotation.TargetApi; import android.app.Activity; import android.app.AlertDialog; Loading Loading @@ -84,6 +87,7 @@ public class SettingsActivity extends Activity { public static class LauncherSettingsFragment extends PreferenceFragment { private IconBadgingObserver mIconBadgingObserver; private RotationLockObserver mRotationLockObserver; private String mPreferenceKey; private boolean mPreferenceHighlighted = false; Loading Loading @@ -123,6 +127,22 @@ public class SettingsActivity extends Activity { getPreferenceScreen().removePreference(iconShapeOverride); } } // Setup allow rotation preference Preference rotationPref = findPreference(ALLOW_ROTATION_PREFERENCE_KEY); if (getResources().getBoolean(R.bool.allow_rotation)) { // Launcher supports rotation by default. No need to show this setting. getPreferenceScreen().removePreference(rotationPref); } else { mRotationLockObserver = new RotationLockObserver(rotationPref, resolver); // Register a content observer to listen for system setting changes while // this UI is active. mRotationLockObserver.register(Settings.System.ACCELEROMETER_ROTATION); // Initialize the UI once rotationPref.setDefaultValue(getAllowRotationDefaultValue()); } } @Override Loading Loading @@ -181,6 +201,10 @@ public class SettingsActivity extends Activity { mIconBadgingObserver.unregister(); mIconBadgingObserver = null; } if (mRotationLockObserver != null) { mRotationLockObserver.unregister(); mRotationLockObserver = null; } super.onDestroy(); } Loading @@ -204,6 +228,23 @@ public class SettingsActivity extends Activity { } } private static class RotationLockObserver extends SettingsObserver.System { private final Preference mRotationPref; public RotationLockObserver(Preference rotationPref, ContentResolver resolver) { super(resolver); mRotationPref = rotationPref; } @Override public void onSettingChanged(boolean enabled) { mRotationPref.setEnabled(enabled); mRotationPref.setSummary(enabled ? R.string.allow_rotation_desc : R.string.allow_rotation_blocked_desc); } } /** * Content observer which listens for system badging setting changes, * and updates the launcher badging setting subtext accordingly. Loading src/com/android/launcher3/states/RotationHelper.java +37 −23 Original line number Diff line number Diff line Loading @@ -18,28 +18,43 @@ package com.android.launcher3.states; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LOCKED; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; import static android.provider.Settings.System.ACCELEROMETER_ROTATION; import static android.provider.Settings.System.getUriFor; import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE; import static com.android.launcher3.Utilities.ATLEAST_NOUGAT; import android.app.Activity; import android.content.ContentResolver; import android.database.ContentObserver; import android.os.Handler; import android.provider.Settings; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.res.Resources; import com.android.launcher3.R; import com.android.launcher3.Utilities; /** * Utility class to manage launcher rotation */ public class RotationHelper extends ContentObserver { public class RotationHelper implements OnSharedPreferenceChangeListener { public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation"; public static boolean getAllowRotationDefaultValue() { if (ATLEAST_NOUGAT) { // If the device was scaled, used the original dimensions to determine if rotation // is allowed of not. Resources res = Resources.getSystem(); int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp * res.getDisplayMetrics().densityDpi / DENSITY_DEVICE_STABLE; return originalSmallestWidth >= 600; } return false; } public static final int REQUEST_NONE = 0; public static final int REQUEST_ROTATE = 1; public static final int REQUEST_LOCK = 2; private final Activity mActivity; private final ContentResolver mCr; private final SharedPreferences mPrefs; private final boolean mIgnoreAutoRotateSettings; private boolean mAutoRotateEnabled; Loading @@ -60,23 +75,24 @@ public class RotationHelper extends ContentObserver { private int mLastActivityFlags = -1; public RotationHelper(Activity activity) { super(new Handler()); mActivity = activity; // On large devices we do not handle auto-rotate differently. mIgnoreAutoRotateSettings = mActivity.getResources().getBoolean(R.bool.allow_rotation); if (!mIgnoreAutoRotateSettings) { mCr = mActivity.getContentResolver(); mCr.registerContentObserver(getUriFor(ACCELEROMETER_ROTATION), false, this); mAutoRotateEnabled = Settings.System.getInt(mCr, ACCELEROMETER_ROTATION, 1) == 1; mPrefs = Utilities.getPrefs(mActivity); mPrefs.registerOnSharedPreferenceChangeListener(this); mAutoRotateEnabled = mPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, getAllowRotationDefaultValue()); } else { mCr = null; mPrefs = null; } } @Override public void onChange(boolean selfChange) { mAutoRotateEnabled = Settings.System.getInt(mCr, ACCELEROMETER_ROTATION, 1) == 1; public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { mAutoRotateEnabled = mPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, getAllowRotationDefaultValue()); notifyChange(); } Loading Loading @@ -104,8 +120,8 @@ public class RotationHelper extends ContentObserver { public void destroy() { if (!mDestroyed) { mDestroyed = true; if (mCr != null) { mCr.unregisterContentObserver(this); if (mPrefs != null) { mPrefs.unregisterOnSharedPreferenceChangeListener(this); } } } Loading @@ -121,19 +137,17 @@ public class RotationHelper extends ContentObserver { SCREEN_ORIENTATION_LOCKED : SCREEN_ORIENTATION_UNSPECIFIED; } else if (mCurrentStateRequest == REQUEST_LOCK) { activityFlags = SCREEN_ORIENTATION_LOCKED; } else if (mIgnoreAutoRotateSettings || mCurrentStateRequest == REQUEST_ROTATE) { } else if (mIgnoreAutoRotateSettings || mCurrentStateRequest == REQUEST_ROTATE || mAutoRotateEnabled) { activityFlags = SCREEN_ORIENTATION_UNSPECIFIED; } else if (mAutoRotateEnabled) { // If auto rotation is on, lock to device orientation activityFlags = SCREEN_ORIENTATION_NOSENSOR; } else { // If auto rotation is off, allow rotation on the activity, in case the user is using // forced rotation. activityFlags = SCREEN_ORIENTATION_UNSPECIFIED; activityFlags = SCREEN_ORIENTATION_NOSENSOR; } if (activityFlags != mLastActivityFlags) { mLastActivityFlags = activityFlags; mActivity.setRequestedOrientation(mLastActivityFlags); mActivity.setRequestedOrientation(activityFlags); } } } Loading
quickstep/res/xml/indexable_launcher_prefs.xml +8 −2 Original line number Diff line number Diff line Loading @@ -20,8 +20,14 @@ android:key="pref_add_icon_to_home" android:title="@string/auto_add_shortcuts_label" android:summary="@string/auto_add_shortcuts_description" android:defaultValue="true" /> android:defaultValue="true" /> <SwitchPreference android:key="pref_allowRotation" android:title="@string/allow_rotation_title" android:summary="@string/allow_rotation_desc" android:defaultValue="@bool/allow_rotation" android:persistent="true" /> <ListPreference android:key="pref_override_icon_shape" Loading
res/values/strings.xml +6 −0 Original line number Diff line number Diff line Loading @@ -179,6 +179,12 @@ <string name="msg_disabled_by_admin">Disabled by your admin</string> <!-- Strings for settings --> <!-- Title for Allow Rotation setting. [CHAR LIMIT=50] --> <string name="allow_rotation_title">Allow Home screen rotation</string> <!-- Text explaining when the home screen will get rotated. [CHAR LIMIT=100] --> <string name="allow_rotation_desc">When phone is rotated</string> <!-- Text explaining that rotation is disabled in Display settings. 'Display' refers to the Display section in system settings [CHAR LIMIT=100] --> <string name="allow_rotation_blocked_desc">Current Display setting doesn\'t permit rotation</string> <!-- Title for Notification dots setting. Tapping this will link to the system Notifications settings screen where the user can turn off notification dots globally. [CHAR LIMIT=50] --> <string name="icon_badging_title">Notification dots</string> <!-- Text to indicate that the system icon badging setting is on [CHAR LIMIT=100] --> Loading
res/xml/launcher_preferences.xml +7 −2 Original line number Diff line number Diff line Loading @@ -34,8 +34,13 @@ android:title="@string/auto_add_shortcuts_label" android:summary="@string/auto_add_shortcuts_description" android:defaultValue="true" android:persistent="true" /> android:persistent="true" /> <SwitchPreference android:key="pref_allowRotation" android:title="@string/allow_rotation_title" android:defaultValue="@bool/allow_rotation" android:persistent="true" /> <ListPreference android:key="pref_override_icon_shape" Loading
src/com/android/launcher3/SettingsActivity.java +41 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package com.android.launcher3; import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY; import static com.android.launcher3.states.RotationHelper.getAllowRotationDefaultValue; import android.annotation.TargetApi; import android.app.Activity; import android.app.AlertDialog; Loading Loading @@ -84,6 +87,7 @@ public class SettingsActivity extends Activity { public static class LauncherSettingsFragment extends PreferenceFragment { private IconBadgingObserver mIconBadgingObserver; private RotationLockObserver mRotationLockObserver; private String mPreferenceKey; private boolean mPreferenceHighlighted = false; Loading Loading @@ -123,6 +127,22 @@ public class SettingsActivity extends Activity { getPreferenceScreen().removePreference(iconShapeOverride); } } // Setup allow rotation preference Preference rotationPref = findPreference(ALLOW_ROTATION_PREFERENCE_KEY); if (getResources().getBoolean(R.bool.allow_rotation)) { // Launcher supports rotation by default. No need to show this setting. getPreferenceScreen().removePreference(rotationPref); } else { mRotationLockObserver = new RotationLockObserver(rotationPref, resolver); // Register a content observer to listen for system setting changes while // this UI is active. mRotationLockObserver.register(Settings.System.ACCELEROMETER_ROTATION); // Initialize the UI once rotationPref.setDefaultValue(getAllowRotationDefaultValue()); } } @Override Loading Loading @@ -181,6 +201,10 @@ public class SettingsActivity extends Activity { mIconBadgingObserver.unregister(); mIconBadgingObserver = null; } if (mRotationLockObserver != null) { mRotationLockObserver.unregister(); mRotationLockObserver = null; } super.onDestroy(); } Loading @@ -204,6 +228,23 @@ public class SettingsActivity extends Activity { } } private static class RotationLockObserver extends SettingsObserver.System { private final Preference mRotationPref; public RotationLockObserver(Preference rotationPref, ContentResolver resolver) { super(resolver); mRotationPref = rotationPref; } @Override public void onSettingChanged(boolean enabled) { mRotationPref.setEnabled(enabled); mRotationPref.setSummary(enabled ? R.string.allow_rotation_desc : R.string.allow_rotation_blocked_desc); } } /** * Content observer which listens for system badging setting changes, * and updates the launcher badging setting subtext accordingly. Loading
src/com/android/launcher3/states/RotationHelper.java +37 −23 Original line number Diff line number Diff line Loading @@ -18,28 +18,43 @@ package com.android.launcher3.states; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LOCKED; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; import static android.provider.Settings.System.ACCELEROMETER_ROTATION; import static android.provider.Settings.System.getUriFor; import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE; import static com.android.launcher3.Utilities.ATLEAST_NOUGAT; import android.app.Activity; import android.content.ContentResolver; import android.database.ContentObserver; import android.os.Handler; import android.provider.Settings; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.res.Resources; import com.android.launcher3.R; import com.android.launcher3.Utilities; /** * Utility class to manage launcher rotation */ public class RotationHelper extends ContentObserver { public class RotationHelper implements OnSharedPreferenceChangeListener { public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation"; public static boolean getAllowRotationDefaultValue() { if (ATLEAST_NOUGAT) { // If the device was scaled, used the original dimensions to determine if rotation // is allowed of not. Resources res = Resources.getSystem(); int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp * res.getDisplayMetrics().densityDpi / DENSITY_DEVICE_STABLE; return originalSmallestWidth >= 600; } return false; } public static final int REQUEST_NONE = 0; public static final int REQUEST_ROTATE = 1; public static final int REQUEST_LOCK = 2; private final Activity mActivity; private final ContentResolver mCr; private final SharedPreferences mPrefs; private final boolean mIgnoreAutoRotateSettings; private boolean mAutoRotateEnabled; Loading @@ -60,23 +75,24 @@ public class RotationHelper extends ContentObserver { private int mLastActivityFlags = -1; public RotationHelper(Activity activity) { super(new Handler()); mActivity = activity; // On large devices we do not handle auto-rotate differently. mIgnoreAutoRotateSettings = mActivity.getResources().getBoolean(R.bool.allow_rotation); if (!mIgnoreAutoRotateSettings) { mCr = mActivity.getContentResolver(); mCr.registerContentObserver(getUriFor(ACCELEROMETER_ROTATION), false, this); mAutoRotateEnabled = Settings.System.getInt(mCr, ACCELEROMETER_ROTATION, 1) == 1; mPrefs = Utilities.getPrefs(mActivity); mPrefs.registerOnSharedPreferenceChangeListener(this); mAutoRotateEnabled = mPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, getAllowRotationDefaultValue()); } else { mCr = null; mPrefs = null; } } @Override public void onChange(boolean selfChange) { mAutoRotateEnabled = Settings.System.getInt(mCr, ACCELEROMETER_ROTATION, 1) == 1; public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { mAutoRotateEnabled = mPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, getAllowRotationDefaultValue()); notifyChange(); } Loading Loading @@ -104,8 +120,8 @@ public class RotationHelper extends ContentObserver { public void destroy() { if (!mDestroyed) { mDestroyed = true; if (mCr != null) { mCr.unregisterContentObserver(this); if (mPrefs != null) { mPrefs.unregisterOnSharedPreferenceChangeListener(this); } } } Loading @@ -121,19 +137,17 @@ public class RotationHelper extends ContentObserver { SCREEN_ORIENTATION_LOCKED : SCREEN_ORIENTATION_UNSPECIFIED; } else if (mCurrentStateRequest == REQUEST_LOCK) { activityFlags = SCREEN_ORIENTATION_LOCKED; } else if (mIgnoreAutoRotateSettings || mCurrentStateRequest == REQUEST_ROTATE) { } else if (mIgnoreAutoRotateSettings || mCurrentStateRequest == REQUEST_ROTATE || mAutoRotateEnabled) { activityFlags = SCREEN_ORIENTATION_UNSPECIFIED; } else if (mAutoRotateEnabled) { // If auto rotation is on, lock to device orientation activityFlags = SCREEN_ORIENTATION_NOSENSOR; } else { // If auto rotation is off, allow rotation on the activity, in case the user is using // forced rotation. activityFlags = SCREEN_ORIENTATION_UNSPECIFIED; activityFlags = SCREEN_ORIENTATION_NOSENSOR; } if (activityFlags != mLastActivityFlags) { mLastActivityFlags = activityFlags; mActivity.setRequestedOrientation(mLastActivityFlags); mActivity.setRequestedOrientation(activityFlags); } } }