am 0b5888e8: Merge "Preventing screen rotations when dragging." into honeycomb

* commit '0b5888e8283a5e0aeae16ac5ea344bac046522c9':
  Preventing screen rotations when dragging.
This commit is contained in:
Winson Chung
2011-01-17 14:42:17 -08:00
committed by Android Git Automerger
4 changed files with 71 additions and 19 deletions
@@ -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
@@ -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
+65 -18
View File
@@ -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.
*/
+2 -1
View File
@@ -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;
}