diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2017-03-30 19:27:29 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-03-30 19:27:29 +0000 |
commit | dd64c3d66947a5ef16e102e5c6c415429948299e (patch) | |
tree | ef1eb20920785592772fb16f8ce7b7a91647b1c5 | |
parent | 4f209caed5d174a9d9e4c88fd6e7afcea5e7ea2e (diff) | |
parent | 1188b89dc421afabd06c1bbf23e3c7f281cfec36 (diff) | |
download | android_packages_apps_Trebuchet-dd64c3d66947a5ef16e102e5c6c415429948299e.tar.gz android_packages_apps_Trebuchet-dd64c3d66947a5ef16e102e5c6c415429948299e.tar.bz2 android_packages_apps_Trebuchet-dd64c3d66947a5ef16e102e5c6c415429948299e.zip |
Merge "Fixing multiwindow drag operation during with rotation." into ub-launcher3-dorval
am: 1188b89dc4
Change-Id: Ib2f0988d944dff201767d5e85686416aa966e96b
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 29 | ||||
-rw-r--r-- | src/com/android/launcher3/dragndrop/AddItemActivity.java | 12 | ||||
-rw-r--r-- | src/com/android/launcher3/dragndrop/PinItemDragListener.java | 23 |
3 files changed, 45 insertions, 19 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 0d56c5afa..d007fc304 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -49,7 +49,6 @@ import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.Handler; -import android.os.Parcelable; import android.os.Process; import android.os.StrictMode; import android.os.SystemClock; @@ -443,6 +442,11 @@ public class Launcher extends BaseActivity mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler); } + if (PinItemDragListener.handleDragRequest(this, getIntent())) { + // Temporarily enable the rotation + mRotationEnabled = true; + } + // 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 setOrientation(); @@ -1768,15 +1772,8 @@ public class Launcher extends BaseActivity if (mLauncherCallbacks != null) { mLauncherCallbacks.onHomeIntent(); } - - Parcelable dragExtra = intent - .getParcelableExtra(PinItemDragListener.EXTRA_PIN_ITEM_DRAG_LISTENER); - if (dragExtra instanceof PinItemDragListener) { - PinItemDragListener dragListener = (PinItemDragListener) dragExtra; - dragListener.setLauncher(this); - mDragLayer.setOnDragListener(dragListener); - } } + PinItemDragListener.handleDragRequest(this, intent); if (mLauncherCallbacks != null) { mLauncherCallbacks.onNewIntent(intent); @@ -4120,22 +4117,16 @@ public class Launcher extends BaseActivity return ((Launcher) ((ContextWrapper) context).getBaseContext()); } - private class RotationPrefChangeHandler implements OnSharedPreferenceChangeListener, Runnable { + private class RotationPrefChangeHandler implements OnSharedPreferenceChangeListener { @Override public void onSharedPreferenceChanged( SharedPreferences sharedPreferences, String key) { if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(key)) { - mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext()); - if (!waitUntilResume(this, true)) { - run(); - } + // Finish this instance of the activity. When the activity is recreated, + // it will initialize the rotation preference again. + finish(); } } - - @Override - public void run() { - setOrientation(); - } } } diff --git a/src/com/android/launcher3/dragndrop/AddItemActivity.java b/src/com/android/launcher3/dragndrop/AddItemActivity.java index 6b27a9992..09592a846 100644 --- a/src/com/android/launcher3/dragndrop/AddItemActivity.java +++ b/src/com/android/launcher3/dragndrop/AddItemActivity.java @@ -28,6 +28,7 @@ import android.appwidget.AppWidgetManager; import android.content.ClipData; import android.content.ClipDescription; import android.content.Intent; +import android.content.res.Configuration; import android.graphics.Canvas; import android.graphics.Point; import android.graphics.PointF; @@ -47,6 +48,7 @@ import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; 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.PinItemRequestCompat; import com.android.launcher3.model.WidgetItem; @@ -148,6 +150,16 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener .setPackage(getPackageName()) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .putExtra(PinItemDragListener.EXTRA_PIN_ITEM_DRAG_LISTENER, listener); + + 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); + } + startActivity(homeIntent, ActivityOptions.makeCustomAnimation(this, 0, android.R.anim.fade_out).toBundle()); diff --git a/src/com/android/launcher3/dragndrop/PinItemDragListener.java b/src/com/android/launcher3/dragndrop/PinItemDragListener.java index dfc65660e..4b402f4ac 100644 --- a/src/com/android/launcher3/dragndrop/PinItemDragListener.java +++ b/src/com/android/launcher3/dragndrop/PinItemDragListener.java @@ -18,6 +18,7 @@ package com.android.launcher3.dragndrop; import android.appwidget.AppWidgetManager; import android.content.ClipDescription; +import android.content.Intent; import android.graphics.Point; import android.graphics.Rect; import android.os.Bundle; @@ -245,6 +246,13 @@ public class PinItemDragListener } private void postCleanup() { + if (mLauncher != null) { + // Remove any drag params from the launcher intent since the drag operation is complete. + Intent newIntent = new Intent(mLauncher.getIntent()); + newIntent.removeExtra(EXTRA_PIN_ITEM_DRAG_LISTENER); + mLauncher.setIntent(newIntent); + } + new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { @@ -268,6 +276,21 @@ public class PinItemDragListener return null; } + public static boolean handleDragRequest(Launcher launcher, Intent intent) { + if (intent == null || !Intent.ACTION_MAIN.equals(intent.getAction())) { + return false; + } + Parcelable dragExtra = intent.getParcelableExtra(EXTRA_PIN_ITEM_DRAG_LISTENER); + if (dragExtra instanceof PinItemDragListener) { + PinItemDragListener dragListener = (PinItemDragListener) dragExtra; + dragListener.setLauncher(launcher); + + launcher.getDragLayer().setOnDragListener(dragListener); + return true; + } + return false; + } + public static final Parcelable.Creator<PinItemDragListener> CREATOR = new Parcelable.Creator<PinItemDragListener>() { public PinItemDragListener createFromParcel(Parcel source) { |