diff options
author | Winson Chung <winsonc@google.com> | 2011-01-17 14:01:04 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-01-17 14:01:04 -0800 |
commit | 0b5888e8283a5e0aeae16ac5ea344bac046522c9 (patch) | |
tree | 030b4eeee7beda7eca0d08cf98b8ddd27a15e053 /src | |
parent | 6c7a03a858d6a695d0f6005398cc6f9b3e7dd18d (diff) | |
parent | 400438b79fe412cb625c96297edeea9c6155349e (diff) | |
download | packages_apps_trebuchet-0b5888e8283a5e0aeae16ac5ea344bac046522c9.zip packages_apps_trebuchet-0b5888e8283a5e0aeae16ac5ea344bac046522c9.tar.gz packages_apps_trebuchet-0b5888e8283a5e0aeae16ac5ea344bac046522c9.tar.bz2 |
Merge "Preventing screen rotations when dragging." into honeycomb
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher2/AllAppsPagedView.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher2/CustomizePagedView.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher2/Launcher.java | 83 | ||||
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 3 |
4 files changed, 71 insertions, 19 deletions
diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java index a15b73b..8ed1f46 100644 --- a/src/com/android/launcher2/AllAppsPagedView.java +++ b/src/com/android/launcher2/AllAppsPagedView.java @@ -271,6 +271,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All } // Start the drag + mLauncher.lockScreenOrientation(); mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b); mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, null); b.recycle(); @@ -289,6 +290,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All } tearDownDragMode(); mLauncher.getWorkspace().onDragStopped(); + mLauncher.unlockScreenOrientation(); } @Override diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java index 6a563f2..0aef4dd 100644 --- a/src/com/android/launcher2/CustomizePagedView.java +++ b/src/com/android/launcher2/CustomizePagedView.java @@ -328,6 +328,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems public void onDropCompleted(View target, boolean success) { resetCheckedGrandchildren(); mLauncher.getWorkspace().onDragStopped(); + mLauncher.unlockScreenOrientation(); } @Override @@ -500,6 +501,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems endChoiceMode(); } boolean result = false; + mLauncher.lockScreenOrientation(); switch (mCustomizationType) { case WidgetCustomization: { // Get the widget preview as the drag representation diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index bef4e84..4b8b682 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -17,17 +17,19 @@ package com.android.launcher2; -import com.android.common.Search; -import com.android.launcher.R; -import com.android.launcher2.CustomizePagedView.CustomizationType; -import com.android.launcher2.Workspace.ShrinkState; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; -import android.animation.TimeInterpolator; import android.animation.ValueAnimator; import android.app.Activity; import android.app.AlertDialog; @@ -45,12 +47,12 @@ import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.IntentFilter; import android.content.Intent.ShortcutIconResource; +import android.content.IntentFilter; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; import android.content.pm.PackageManager.NameNotFoundException; +import android.content.pm.ResolveInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; @@ -77,16 +79,18 @@ import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.method.TextKeyListener; import android.util.Log; +import android.view.Display; import android.view.HapticFeedbackConstants; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; +import android.view.Surface; import android.view.View; +import android.view.View.OnLongClickListener; import android.view.ViewGroup; import android.view.WindowManager; -import android.view.View.OnLongClickListener; import android.view.accessibility.AccessibilityEvent; import android.view.animation.DecelerateInterpolator; import android.view.inputmethod.InputMethodManager; @@ -96,20 +100,16 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.TabHost; +import android.widget.TabHost.OnTabChangeListener; +import android.widget.TabHost.TabContentFactory; import android.widget.TabWidget; import android.widget.TextView; import android.widget.Toast; -import android.widget.TabHost.OnTabChangeListener; -import android.widget.TabHost.TabContentFactory; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import com.android.common.Search; +import com.android.launcher.R; +import com.android.launcher2.CustomizePagedView.CustomizationType; +import com.android.launcher2.Workspace.ShrinkState; /** @@ -264,6 +264,10 @@ public final class Launcher extends Activity private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = new HashMap<View, AppWidgetProviderInfo>(); + // Determines how long to wait after a rotation before restoring the screen orientation to + // match the sensor state. + private final int mRestoreScreenOrientationDelay = 500; + // External icons saved in case of resource changes, orientation, etc. private static Drawable.ConstantState sGlobalSearchIcon; private static Drawable.ConstantState sVoiceSearchIcon; @@ -3576,6 +3580,49 @@ public final class Launcher extends Activity } } + private int mapConfigurationOriActivityInfoOri(int configOri) { + final Display d = getWindowManager().getDefaultDisplay(); + int naturalOri = Configuration.ORIENTATION_LANDSCAPE; + switch (d.getRotation()) { + case Surface.ROTATION_0: + case Surface.ROTATION_180: + // We are currently in the same basic orientation as the natural orientation + naturalOri = configOri; + break; + case Surface.ROTATION_90: + case Surface.ROTATION_270: + // We are currently in the other basic orientation to the natural orientation + naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? + Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; + break; + } + + int[] oriMap = { + ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, + ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, + ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, + ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE + }; + // Since the map starts at portrait, we need to offset if this device's natural orientation + // is landscape. + int indexOffset = 0; + if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { + indexOffset = 1; + } + return oriMap[(d.getRotation() + indexOffset) % 4]; + } + public void lockScreenOrientation() { + setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() + .getConfiguration().orientation)); + } + public void unlockScreenOrientation() { + mHandler.postDelayed(new Runnable() { + public void run() { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); + } + }, mRestoreScreenOrientationDelay); + } + /** * Prints out out state for debugging. */ diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 89de2da..058885f 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -1648,6 +1648,7 @@ public class Workspace extends SmoothPagedView child.getLocationOnScreen(mTempXY); final int screenX = (int) mTempXY[0] + (child.getWidth() - bmpWidth) / 2; final int screenY = (int) mTempXY[1] + (child.getHeight() - bmpHeight) / 2; + mLauncher.lockScreenOrientation(); mDragController.startDrag(b, screenX, screenY, 0, 0, bmpWidth, bmpHeight, this, child.getTag(), DragController.DRAG_ACTION_MOVE, null); b.recycle(); @@ -2447,7 +2448,7 @@ public class Workspace extends SmoothPagedView boolean animateDrop = !mWasSpringLoadedOnDragExit; ((CellLayout) getChildAt(mDragInfo.screen)).onDropChild(mDragInfo.cell, animateDrop); } - + mLauncher.unlockScreenOrientation(); mDragOutline = null; mDragInfo = null; } |