Merge "Updating Launcher rotation logic" into ub-launcher3-master
This commit is contained in:
commit
d90d04b1ec
|
@ -71,7 +71,7 @@
|
|||
android:clearTaskOnLaunch="true"
|
||||
android:stateNotNeeded="true"
|
||||
android:windowSoftInputMode="adjustPan"
|
||||
android:screenOrientation="nosensor"
|
||||
android:screenOrientation="unspecified"
|
||||
android:configChanges="keyboard|keyboardHidden|navigation"
|
||||
android:resizeableActivity="true"
|
||||
android:resumeWhilePausing="true"
|
||||
|
|
|
@ -17,6 +17,7 @@ package com.android.launcher3.uioverrides;
|
|||
|
||||
import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS;
|
||||
import static com.android.launcher3.anim.Interpolators.ACCEL_2;
|
||||
import static com.android.launcher3.states.RotationHelper.REQUEST_ROTATE;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.view.View;
|
||||
|
@ -73,6 +74,11 @@ public class OverviewState extends LauncherState {
|
|||
rv.setOverviewStateEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateTransitionEnd(Launcher launcher) {
|
||||
launcher.getRotationHelper().setCurrentStateRequest(REQUEST_ROTATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getFinalFocus(Launcher launcher) {
|
||||
return launcher.getOverviewPanel();
|
||||
|
|
|
@ -19,6 +19,8 @@ import static com.android.launcher3.LauncherState.FAST_OVERVIEW;
|
|||
import static com.android.launcher3.LauncherState.OVERVIEW;
|
||||
import static com.android.launcher3.allapps.AllAppsTransitionController.ALL_APPS_PROGRESS;
|
||||
import static com.android.launcher3.anim.Interpolators.LINEAR;
|
||||
import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK;
|
||||
import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
|
||||
import static com.android.quickstep.QuickScrubController.QUICK_SWITCH_START_DURATION;
|
||||
import static com.android.quickstep.TouchConsumer.INTERACTION_NORMAL;
|
||||
import static com.android.quickstep.TouchConsumer.INTERACTION_QUICK_SCRUB;
|
||||
|
@ -33,7 +35,6 @@ import android.animation.ObjectAnimator;
|
|||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityManager.RunningTaskInfo;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Matrix.ScaleToFit;
|
||||
|
@ -364,7 +365,8 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {
|
|||
|
||||
// For the duration of the gesture, lock the screen orientation to ensure that we do not
|
||||
// rotate mid-quickscrub
|
||||
mLauncher.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
|
||||
mLauncher.getRotationHelper().setStateHandlerRequest(REQUEST_LOCK);
|
||||
|
||||
mRecentsView = mLauncher.getOverviewPanel();
|
||||
mQuickScrubController = mRecentsView.getQuickScrubController();
|
||||
mLauncherLayoutListener = new LauncherLayoutListener(mLauncher);
|
||||
|
@ -755,7 +757,8 @@ public class WindowTransformSwipeHandler extends BaseSwipeInteractionHandler {
|
|||
mLauncherLayoutListener.close(false);
|
||||
|
||||
// Restore the requested orientation to the user preference after the gesture has ended
|
||||
mLauncher.updateRequestedOrientation();
|
||||
mLauncher.getRotationHelper().setStateHandlerRequest(REQUEST_NONE);
|
||||
|
||||
mRecentsView.setFirstTaskIconScaledDown(false /* isScaledDown */, false /* animate */);
|
||||
}
|
||||
|
||||
|
|
|
@ -173,12 +173,6 @@
|
|||
<string name="accessibility_action_overview">Overview</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] -->
|
||||
|
|
|
@ -37,13 +37,6 @@
|
|||
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"
|
||||
android:title="@string/icon_shape_override_label"
|
||||
|
|
|
@ -18,8 +18,7 @@ package com.android.launcher3;
|
|||
|
||||
import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
|
||||
import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
|
||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
|
||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
|
||||
import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_BY_PUBLISHER;
|
||||
import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_LOCKED_USER;
|
||||
import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_QUIET_USER;
|
||||
|
@ -53,7 +52,6 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
import android.content.IntentSender;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
@ -116,6 +114,7 @@ import com.android.launcher3.popup.PopupContainerWithArrow;
|
|||
import com.android.launcher3.popup.PopupDataProvider;
|
||||
import com.android.launcher3.shortcuts.DeepShortcutManager;
|
||||
import com.android.launcher3.states.InternalStateHandler;
|
||||
import com.android.launcher3.states.RotationHelper;
|
||||
import com.android.launcher3.uioverrides.UiFactory;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto;
|
||||
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
|
||||
|
@ -272,10 +271,9 @@ public class Launcher extends BaseActivity
|
|||
private final PointF mLastDispatchTouchEvent = new PointF();
|
||||
|
||||
public ViewGroupFocusHelper mFocusHandler;
|
||||
private boolean mRotationEnabled = false;
|
||||
private boolean mAppLaunchSuccess;
|
||||
|
||||
private RotationPrefChangeHandler mRotationPrefChangeHandler;
|
||||
private RotationHelper mRotationHelper;
|
||||
private ActionMode mCurrentActionMode;
|
||||
|
||||
@Override
|
||||
|
@ -327,20 +325,10 @@ public class Launcher extends BaseActivity
|
|||
setupViews();
|
||||
mPopupDataProvider = new PopupDataProvider(this);
|
||||
|
||||
mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
|
||||
// In case we are on a device with locked rotation, we should look at preferences to check
|
||||
// if the user has specifically allowed rotation.
|
||||
if (!mRotationEnabled) {
|
||||
mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
|
||||
mRotationPrefChangeHandler = new RotationPrefChangeHandler();
|
||||
mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
|
||||
}
|
||||
mRotationHelper = new RotationHelper(this);
|
||||
|
||||
boolean internalStateHandled = InternalStateHandler.handleCreate(this, getIntent());
|
||||
if (internalStateHandled) {
|
||||
// Temporarily enable the rotation
|
||||
mRotationEnabled = true;
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
// InternalStateHandler has already set the appropriate state.
|
||||
// We dont need to do anything.
|
||||
|
@ -372,7 +360,6 @@ public class Launcher extends BaseActivity
|
|||
// For handling default keys
|
||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||
|
||||
updateRequestedOrientation();
|
||||
setContentView(mLauncherView);
|
||||
getRootView().dispatchInsets();
|
||||
|
||||
|
@ -391,17 +378,11 @@ public class Launcher extends BaseActivity
|
|||
if (mLauncherCallbacks != null) {
|
||||
mLauncherCallbacks.onCreate(savedInstanceState);
|
||||
}
|
||||
mRotationHelper.initialize();
|
||||
|
||||
TraceHelper.endSection("Launcher-onCreate");
|
||||
}
|
||||
|
||||
public void updateRequestedOrientation() {
|
||||
// On large interfaces, or on devices that a user has specifically enabled screen rotation,
|
||||
// we want the screen to auto-rotate based on the current orientation
|
||||
setRequestedOrientation(mRotationEnabled
|
||||
? SCREEN_ORIENTATION_UNSPECIFIED : SCREEN_ORIENTATION_NOSENSOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
int diff = newConfig.diff(mOldConfig);
|
||||
|
@ -442,6 +423,10 @@ public class Launcher extends BaseActivity
|
|||
mModelWriter = mModel.getWriter(mDeviceProfile.isVerticalBarLayout());
|
||||
}
|
||||
|
||||
public RotationHelper getRotationHelper() {
|
||||
return mRotationHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onThemeChanged() {
|
||||
recreate();
|
||||
|
@ -1381,10 +1366,7 @@ public class Launcher extends BaseActivity
|
|||
mModel.stopLoader();
|
||||
LauncherAppState.getInstance(this).setLauncher(null);
|
||||
}
|
||||
|
||||
if (mRotationPrefChangeHandler != null) {
|
||||
mSharedPrefs.unregisterOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
|
||||
}
|
||||
mRotationHelper.destroy();
|
||||
|
||||
try {
|
||||
mAppWidgetHost.stopListening();
|
||||
|
@ -2727,10 +2709,6 @@ public class Launcher extends BaseActivity
|
|||
mModel.refreshAndBindWidgetsAndShortcuts(packageUser);
|
||||
}
|
||||
|
||||
public boolean isRotationEnabled () {
|
||||
return mRotationEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* $ adb shell dumpsys activity com.android.launcher3.Launcher [--all]
|
||||
*/
|
||||
|
@ -2868,18 +2846,6 @@ public class Launcher extends BaseActivity
|
|||
return ((Launcher) ((ContextWrapper) context).getBaseContext());
|
||||
}
|
||||
|
||||
private class RotationPrefChangeHandler implements OnSharedPreferenceChangeListener {
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(
|
||||
SharedPreferences sharedPreferences, String key) {
|
||||
if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(key)) {
|
||||
// Recreate the activity so that it initializes the rotation preference again.
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionModeStarted(ActionMode mode) {
|
||||
super.onActionModeStarted(mode);
|
||||
|
|
|
@ -20,12 +20,13 @@ import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
|
|||
import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
|
||||
|
||||
import static com.android.launcher3.anim.Interpolators.ACCEL_2;
|
||||
import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import com.android.launcher3.uioverrides.AllAppsState;
|
||||
import com.android.launcher3.states.SpringLoadedState;
|
||||
import com.android.launcher3.uioverrides.AllAppsState;
|
||||
import com.android.launcher3.uioverrides.FastOverviewState;
|
||||
import com.android.launcher3.uioverrides.OverviewState;
|
||||
import com.android.launcher3.uioverrides.UiFactory;
|
||||
|
@ -211,6 +212,8 @@ public class LauncherState {
|
|||
public void onStateTransitionEnd(Launcher launcher) {
|
||||
if (this == NORMAL) {
|
||||
UiFactory.resetOverview(launcher);
|
||||
// Clear any rotation locks when going to normal state
|
||||
launcher.getRotationHelper().setCurrentStateRequest(REQUEST_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,6 @@ public class SettingsActivity extends Activity {
|
|||
*/
|
||||
public static class LauncherSettingsFragment extends PreferenceFragment {
|
||||
|
||||
private SystemDisplayRotationLockObserver mRotationLockObserver;
|
||||
private IconBadgingObserver mIconBadgingObserver;
|
||||
|
||||
@Override
|
||||
|
@ -76,22 +75,6 @@ public class SettingsActivity extends Activity {
|
|||
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
|
||||
// Setup allow rotation preference
|
||||
Preference rotationPref = findPreference(Utilities.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 SystemDisplayRotationLockObserver(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(Utilities.getAllowRotationDefaultValue(getActivity()));
|
||||
}
|
||||
|
||||
ButtonPreference iconBadgingPref =
|
||||
(ButtonPreference) findPreference(ICON_BADGING_PREFERENCE_KEY);
|
||||
if (!Utilities.ATLEAST_OREO) {
|
||||
|
@ -119,10 +102,6 @@ public class SettingsActivity extends Activity {
|
|||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (mRotationLockObserver != null) {
|
||||
mRotationLockObserver.unregister();
|
||||
mRotationLockObserver = null;
|
||||
}
|
||||
if (mIconBadgingObserver != null) {
|
||||
mIconBadgingObserver.unregister();
|
||||
mIconBadgingObserver = null;
|
||||
|
@ -131,28 +110,6 @@ public class SettingsActivity extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Content observer which listens for system auto-rotate setting changes, and enables/disables
|
||||
* the launcher rotation setting accordingly.
|
||||
*/
|
||||
private static class SystemDisplayRotationLockObserver extends SettingsObserver.System {
|
||||
|
||||
private final Preference mRotationPref;
|
||||
|
||||
public SystemDisplayRotationLockObserver(
|
||||
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.
|
||||
|
|
|
@ -125,29 +125,10 @@ public final class Utilities {
|
|||
CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
|
||||
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
|
||||
|
||||
public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";
|
||||
|
||||
public static boolean isPropertyEnabled(String propertyName) {
|
||||
return Log.isLoggable(propertyName, Log.VERBOSE);
|
||||
}
|
||||
|
||||
public static boolean isAllowRotationPrefEnabled(Context context) {
|
||||
return getPrefs(context).getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
|
||||
getAllowRotationDefaultValue(context));
|
||||
}
|
||||
|
||||
public static boolean getAllowRotationDefaultValue(Context context) {
|
||||
if (ATLEAST_NOUGAT) {
|
||||
// If the device was scaled, used the original dimensions to determine if rotation
|
||||
// is allowed of not.
|
||||
Resources res = context.getResources();
|
||||
int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
|
||||
* res.getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEVICE_STABLE;
|
||||
return originalSmallestWidth >= 600;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a coordinate relative to the descendant, find the coordinate in a parent view's
|
||||
* coordinates.
|
||||
|
|
|
@ -16,6 +16,11 @@
|
|||
|
||||
package com.android.launcher3.dragndrop;
|
||||
|
||||
import static com.android.launcher3.logging.LoggerUtils.newCommandAction;
|
||||
import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
|
||||
import static com.android.launcher3.logging.LoggerUtils.newItemTarget;
|
||||
import static com.android.launcher3.logging.LoggerUtils.newLauncherEvent;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityOptions;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
|
@ -23,7 +28,6 @@ import android.content.ClipData;
|
|||
import android.content.ClipDescription;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.LauncherApps.PinItemRequest;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
|
@ -43,7 +47,6 @@ import com.android.launcher3.LauncherAppState;
|
|||
import com.android.launcher3.LauncherAppWidgetHost;
|
||||
import com.android.launcher3.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.compat.AppWidgetManagerCompat;
|
||||
import com.android.launcher3.compat.LauncherAppsCompatVO;
|
||||
import com.android.launcher3.model.WidgetItem;
|
||||
|
@ -55,11 +58,6 @@ import com.android.launcher3.widget.PendingAddWidgetInfo;
|
|||
import com.android.launcher3.widget.WidgetHostViewLoader;
|
||||
import com.android.launcher3.widget.WidgetImageView;
|
||||
|
||||
import static com.android.launcher3.logging.LoggerUtils.newCommandAction;
|
||||
import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
|
||||
import static com.android.launcher3.logging.LoggerUtils.newItemTarget;
|
||||
import static com.android.launcher3.logging.LoggerUtils.newLauncherEvent;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
public class AddItemActivity extends BaseActivity implements OnLongClickListener, OnTouchListener {
|
||||
|
||||
|
@ -154,15 +152,7 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener
|
|||
.setPackage(getPackageName())
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
|
||||
if (!getResources().getBoolean(R.bool.allow_rotation) &&
|
||||
!Utilities.isAllowRotationPrefEnabled(this) &&
|
||||
(getResources().getConfiguration().orientation ==
|
||||
Configuration.ORIENTATION_LANDSCAPE && !isInMultiWindowMode())) {
|
||||
// If we are starting the drag in landscape even though home is locked in portrait,
|
||||
// restart the home activity to temporarily allow rotation.
|
||||
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
}
|
||||
|
||||
listener.initWhenReady();
|
||||
startActivity(homeIntent,
|
||||
ActivityOptions.makeCustomAnimation(this, 0, android.R.anim.fade_out).toBundle());
|
||||
mFinishOnPause = true;
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
package com.android.launcher3.dragndrop;
|
||||
|
||||
import static com.android.launcher3.LauncherState.NORMAL;
|
||||
import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK;
|
||||
import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
|
||||
|
||||
import android.content.ClipDescription;
|
||||
import android.content.Intent;
|
||||
|
@ -79,6 +81,7 @@ public abstract class BaseItemDragListener extends InternalStateHandler implemen
|
|||
AbstractFloatingView.closeAllOpenViews(launcher, alreadyOnHome);
|
||||
launcher.getStateManager().goToState(NORMAL, alreadyOnHome /* animated */);
|
||||
launcher.getDragLayer().setOnDragListener(this);
|
||||
launcher.getRotationHelper().setStateHandlerRequest(REQUEST_LOCK);
|
||||
|
||||
mLauncher = launcher;
|
||||
mDragController = launcher.getDragController();
|
||||
|
@ -157,6 +160,7 @@ public abstract class BaseItemDragListener extends InternalStateHandler implemen
|
|||
}
|
||||
|
||||
private void postCleanup() {
|
||||
clearReference();
|
||||
if (mLauncher != null) {
|
||||
// Remove any drag params from the launcher intent since the drag operation is complete.
|
||||
Intent newIntent = new Intent(mLauncher.getIntent());
|
||||
|
@ -164,16 +168,12 @@ public abstract class BaseItemDragListener extends InternalStateHandler implemen
|
|||
mLauncher.setIntent(newIntent);
|
||||
}
|
||||
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
removeListener();
|
||||
}
|
||||
});
|
||||
new Handler(Looper.getMainLooper()).post(this::removeListener);
|
||||
}
|
||||
|
||||
public void removeListener() {
|
||||
if (mLauncher != null) {
|
||||
mLauncher.getRotationHelper().setStateHandlerRequest(REQUEST_NONE);
|
||||
mLauncher.getDragLayer().setOnDragListener(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright (C) 2018 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.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 android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
|
||||
/**
|
||||
* Utility class to manage launcher rotation
|
||||
*/
|
||||
public class RotationHelper extends ContentObserver {
|
||||
|
||||
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 boolean mIgnoreAutoRotateSettings;
|
||||
private boolean mAutoRotateEnabled;
|
||||
|
||||
/**
|
||||
* Rotation request made by {@link InternalStateHandler}. This supersedes any other request.
|
||||
*/
|
||||
private int mStateHandlerRequest = REQUEST_NONE;
|
||||
/**
|
||||
* Rotation request made by a Launcher State
|
||||
*/
|
||||
private int mCurrentStateRequest = REQUEST_NONE;
|
||||
|
||||
// This is used to defer setting rotation flags until the activity is being created
|
||||
private boolean mInitialized;
|
||||
public boolean mDestroyed;
|
||||
|
||||
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;
|
||||
} else {
|
||||
mCr = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
mAutoRotateEnabled = Settings.System.getInt(mCr, ACCELEROMETER_ROTATION, 1) == 1;
|
||||
notifyChange();
|
||||
}
|
||||
|
||||
public void setStateHandlerRequest(int request) {
|
||||
if (mStateHandlerRequest != request) {
|
||||
mStateHandlerRequest = request;
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentStateRequest(int request) {
|
||||
if (mCurrentStateRequest != request) {
|
||||
mCurrentStateRequest = request;
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
if (!mInitialized) {
|
||||
mInitialized = true;
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (!mDestroyed) {
|
||||
mDestroyed = true;
|
||||
if (mCr != null) {
|
||||
mCr.unregisterContentObserver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyChange() {
|
||||
if (!mInitialized || mDestroyed) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int activityFlags;
|
||||
if (mStateHandlerRequest != REQUEST_NONE) {
|
||||
activityFlags = mStateHandlerRequest == REQUEST_LOCK ?
|
||||
SCREEN_ORIENTATION_LOCKED : SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
} else if (mCurrentStateRequest == REQUEST_LOCK) {
|
||||
activityFlags = SCREEN_ORIENTATION_LOCKED;
|
||||
} else if (mIgnoreAutoRotateSettings || mCurrentStateRequest == REQUEST_ROTATE) {
|
||||
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;
|
||||
}
|
||||
if (activityFlags != mLastActivityFlags) {
|
||||
mLastActivityFlags = activityFlags;
|
||||
mActivity.setRequestedOrientation(mLastActivityFlags);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,10 +16,9 @@
|
|||
package com.android.launcher3.states;
|
||||
|
||||
import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_TRANSITION_MS;
|
||||
import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK;
|
||||
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
|
@ -38,10 +37,6 @@ public class SpringLoadedState extends LauncherState {
|
|||
FLAG_DISABLE_ACCESSIBILITY | FLAG_DISABLE_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED |
|
||||
FLAG_DISABLE_PAGE_CLIPPING | FLAG_PAGE_BACKGROUNDS;
|
||||
|
||||
// Determines how long to wait after a rotation before restoring the screen orientation to
|
||||
// match the sensor state.
|
||||
private static final int RESTORE_SCREEN_ORIENTATION_DELAY = 500;
|
||||
|
||||
public SpringLoadedState(int id) {
|
||||
super(id, ContainerType.OVERVIEW, SPRING_LOADED_TRANSITION_MS, STATE_FLAGS);
|
||||
}
|
||||
|
@ -84,30 +79,16 @@ public class SpringLoadedState extends LauncherState {
|
|||
ws.showPageIndicatorAtCurrentScroll();
|
||||
ws.getPageIndicator().setShouldAutoHide(false);
|
||||
|
||||
// Lock the orientation:
|
||||
if (launcher.isRotationEnabled()) {
|
||||
launcher.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
|
||||
}
|
||||
|
||||
// Prevent any Un/InstallShortcutReceivers from updating the db while we are
|
||||
// in spring loaded mode
|
||||
InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_DRAG_AND_DROP);
|
||||
launcher.getRotationHelper().setCurrentStateRequest(REQUEST_LOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateDisabled(final Launcher launcher) {
|
||||
launcher.getWorkspace().getPageIndicator().setShouldAutoHide(true);
|
||||
|
||||
// Unlock rotation lock
|
||||
if (launcher.isRotationEnabled()) {
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
launcher.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||
}
|
||||
}, RESTORE_SCREEN_ORIENTATION_DELAY);
|
||||
}
|
||||
|
||||
// Re-enable any Un/InstallShortcutReceiver and now process any queued items
|
||||
InstallShortcutReceiver.disableAndFlushInstallQueue(
|
||||
InstallShortcutReceiver.FLAG_DRAG_AND_DROP, launcher);
|
||||
|
|
|
@ -78,11 +78,6 @@ public abstract class AbstractLauncherUiTest {
|
|||
}
|
||||
|
||||
protected void lockRotation(boolean naturalOrientation) throws RemoteException {
|
||||
Utilities.getPrefs(mTargetContext)
|
||||
.edit()
|
||||
.putBoolean(Utilities.ALLOW_ROTATION_PREFERENCE_KEY, !naturalOrientation)
|
||||
.commit();
|
||||
|
||||
if (naturalOrientation) {
|
||||
mDevice.setOrientationNatural();
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue