summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher2')
-rw-r--r--src/com/android/launcher2/AppsCustomizeTabHost.java13
-rw-r--r--src/com/android/launcher2/CellLayout.java64
-rw-r--r--src/com/android/launcher2/DragController.java4
-rw-r--r--src/com/android/launcher2/DragLayer.java47
-rw-r--r--src/com/android/launcher2/InstallShortcutReceiver.java4
-rw-r--r--src/com/android/launcher2/Launcher.java8
-rw-r--r--src/com/android/launcher2/LauncherModel.java9
-rw-r--r--src/com/android/launcher2/PagedView.java6
-rw-r--r--src/com/android/launcher2/Workspace.java40
9 files changed, 140 insertions, 55 deletions
diff --git a/src/com/android/launcher2/AppsCustomizeTabHost.java b/src/com/android/launcher2/AppsCustomizeTabHost.java
index 01c08c916..7a2c247c6 100644
--- a/src/com/android/launcher2/AppsCustomizeTabHost.java
+++ b/src/com/android/launcher2/AppsCustomizeTabHost.java
@@ -164,8 +164,9 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona
}
public boolean onInterceptTouchEvent(MotionEvent ev) {
- // If we are mid transition then intercept touch events here so we can ignore them
- if (mInTransition) {
+ // If we are mid transitioning to the workspace, then intercept touch events here so we
+ // can ignore them, otherwise we just let all apps handle the touch events.
+ if (mInTransition && mTransitioningToWorkspace) {
return true;
}
return super.onInterceptTouchEvent(ev);
@@ -173,11 +174,9 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona
@Override
public boolean onTouchEvent(MotionEvent event) {
- // Allow touch events to fall through if we are transitioning to the workspace
- if (mInTransition) {
- if (mTransitioningToWorkspace) {
- return super.onTouchEvent(event);
- }
+ // Allow touch events to fall through to the workspace if we are transitioning there
+ if (mInTransition && mTransitioningToWorkspace) {
+ return super.onTouchEvent(event);
}
// Intercept all touch events up to the bottom of the AppsCustomizePane so they do not fall
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 10eb8f8a4..24e4047eb 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -58,8 +58,6 @@ public class CellLayout extends ViewGroup {
static final String TAG = "CellLayout";
private Launcher mLauncher;
- private int mOriginalCellWidth;
- private int mOriginalCellHeight;
private int mCellWidth;
private int mCellHeight;
@@ -178,10 +176,8 @@ public class CellLayout extends ViewGroup {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);
- mOriginalCellWidth =
- mCellWidth = a.getDimensionPixelSize(R.styleable.CellLayout_cellWidth, 10);
- mOriginalCellHeight =
- mCellHeight = a.getDimensionPixelSize(R.styleable.CellLayout_cellHeight, 10);
+ mCellWidth = a.getDimensionPixelSize(R.styleable.CellLayout_cellWidth, 10);
+ mCellHeight = a.getDimensionPixelSize(R.styleable.CellLayout_cellHeight, 10);
mWidthGap = mOriginalWidthGap = a.getDimensionPixelSize(R.styleable.CellLayout_widthGap, 0);
mHeightGap = mOriginalHeightGap = a.getDimensionPixelSize(R.styleable.CellLayout_heightGap, 0);
mMaxGap = a.getDimensionPixelSize(R.styleable.CellLayout_maxGap, 0);
@@ -914,6 +910,54 @@ public class CellLayout extends ViewGroup {
return r;
}
+ final int LANDSCAPE = 0;
+ final int PORTRAIT = 1;
+ void getCellLayoutMetrics(int measureWidth, int measureHeight, int orientation, Rect metrics) {
+ int numWidthGaps = mCountX - 1;
+ int numHeightGaps = mCountY - 1;
+
+ int widthGap;
+ int heightGap;
+ int cellWidth;
+ int cellHeight;
+ int paddingLeft;
+ int paddingRight;
+ int paddingTop;
+ int paddingBottom;
+
+ Resources res = getContext().getResources();
+ if (orientation == LANDSCAPE) {
+ cellWidth = res.getDimensionPixelSize(R.dimen.workspace_cell_width_land);
+ cellHeight = res.getDimensionPixelSize(R.dimen.workspace_cell_height_land);
+ widthGap = res.getDimensionPixelSize(R.dimen.workspace_width_gap_land);
+ heightGap = res.getDimensionPixelSize(R.dimen.workspace_height_gap_land);
+ paddingLeft = res.getDimensionPixelSize(R.dimen.cell_layout_left_padding_land);
+ paddingRight = res.getDimensionPixelSize(R.dimen.cell_layout_right_padding_land);
+ paddingTop = res.getDimensionPixelSize(R.dimen.cell_layout_top_padding_land);
+ paddingBottom = res.getDimensionPixelSize(R.dimen.cell_layout_bottom_padding_land);
+ } else {
+ // PORTRAIT
+ cellWidth = res.getDimensionPixelSize(R.dimen.workspace_cell_width_port);
+ cellHeight = res.getDimensionPixelSize(R.dimen.workspace_cell_height_port);
+ widthGap = res.getDimensionPixelSize(R.dimen.workspace_width_gap_port);
+ heightGap = res.getDimensionPixelSize(R.dimen.workspace_height_gap_port);
+ paddingLeft = res.getDimensionPixelSize(R.dimen.cell_layout_left_padding_port);
+ paddingRight = res.getDimensionPixelSize(R.dimen.cell_layout_right_padding_port);
+ paddingTop = res.getDimensionPixelSize(R.dimen.cell_layout_top_padding_port);
+ paddingBottom = res.getDimensionPixelSize(R.dimen.cell_layout_bottom_padding_port);
+ }
+
+ if (widthGap < 0 || heightGap < 0) {
+ int hSpace = measureWidth - paddingLeft - paddingRight;
+ int vSpace = measureHeight - paddingTop - paddingBottom;
+ int hFreeSpace = hSpace - (mCountX * cellWidth);
+ int vFreeSpace = vSpace - (mCountY * cellHeight);
+ widthGap = Math.min(mMaxGap, numWidthGaps > 0 ? (hFreeSpace / numWidthGaps) : 0);
+ heightGap = Math.min(mMaxGap, numHeightGaps > 0 ? (vFreeSpace / numHeightGaps) : 0);
+ }
+ metrics.set(cellWidth, cellHeight, widthGap, heightGap);
+ }
+
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO: currently ignoring padding
@@ -932,10 +976,10 @@ public class CellLayout extends ViewGroup {
int numHeightGaps = mCountY - 1;
if (mOriginalWidthGap < 0 || mOriginalHeightGap < 0) {
- int hSpace = widthSpecSize - getPaddingLeft() - getPaddingRight();
- int vSpace = heightSpecSize - getPaddingTop() - getPaddingBottom();
- int hFreeSpace = hSpace - (mCountX * mOriginalCellWidth);
- int vFreeSpace = vSpace - (mCountY * mOriginalCellHeight);
+ int hSpace = widthSpecSize - mPaddingLeft - mPaddingRight;
+ int vSpace = heightSpecSize - mPaddingTop - mPaddingBottom;
+ int hFreeSpace = hSpace - (mCountX * mCellWidth);
+ int vFreeSpace = vSpace - (mCountY * mCellHeight);
mWidthGap = Math.min(mMaxGap, numWidthGaps > 0 ? (hFreeSpace / numWidthGaps) : 0);
mHeightGap = Math.min(mMaxGap,numHeightGaps > 0 ? (vFreeSpace / numHeightGaps) : 0);
mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap);
diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java
index 4be4e8f7b..b9d7dd4f9 100644
--- a/src/com/android/launcher2/DragController.java
+++ b/src/com/android/launcher2/DragController.java
@@ -520,6 +520,7 @@ public class DragController {
mScrollState = SCROLL_OUTSIDE_ZONE;
mScrollRunnable.setDirection(SCROLL_RIGHT);
mDragScroller.onExitScrollArea();
+ mLauncher.getDragLayer().onExitScrollArea();
}
}
@@ -564,6 +565,7 @@ public class DragController {
if (mScrollState == SCROLL_OUTSIDE_ZONE) {
mScrollState = SCROLL_WAITING_IN_ZONE;
if (mDragScroller.onEnterScrollArea(x, y, SCROLL_LEFT)) {
+ mLauncher.getDragLayer().onEnterScrollArea(SCROLL_LEFT);
mScrollRunnable.setDirection(SCROLL_LEFT);
mHandler.postDelayed(mScrollRunnable, delay);
}
@@ -572,6 +574,7 @@ public class DragController {
if (mScrollState == SCROLL_OUTSIDE_ZONE) {
mScrollState = SCROLL_WAITING_IN_ZONE;
if (mDragScroller.onEnterScrollArea(x, y, SCROLL_RIGHT)) {
+ mLauncher.getDragLayer().onEnterScrollArea(SCROLL_RIGHT);
mScrollRunnable.setDirection(SCROLL_RIGHT);
mHandler.postDelayed(mScrollRunnable, delay);
}
@@ -834,6 +837,7 @@ public class DragController {
mScrollState = SCROLL_OUTSIDE_ZONE;
mDistanceSinceScroll = 0;
mDragScroller.onExitScrollArea();
+ mLauncher.getDragLayer().onExitScrollArea();
if (isDragging()) {
// Force an update so that we can requeue the scroller if necessary
diff --git a/src/com/android/launcher2/DragLayer.java b/src/com/android/launcher2/DragLayer.java
index 69ed05363..379e59976 100644
--- a/src/com/android/launcher2/DragLayer.java
+++ b/src/com/android/launcher2/DragLayer.java
@@ -23,7 +23,11 @@ import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.content.res.Resources;
+import android.graphics.Canvas;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -85,6 +89,9 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
setMotionEventSplittingEnabled(false);
setChildrenDrawingOrderEnabled(true);
setOnHierarchyChangeListener(this);
+
+ mLeftHoverDrawable = getResources().getDrawable(R.drawable.page_hover_left_holo);
+ mRightHoverDrawable = getResources().getDrawable(R.drawable.page_hover_right_holo);
}
public void setup(Launcher launcher, DragController controller) {
@@ -720,4 +727,44 @@ public class DragLayer extends FrameLayout implements ViewGroup.OnHierarchyChang
return i;
}
}
+
+ private boolean mInScrollArea;
+ private Drawable mLeftHoverDrawable;
+ private Drawable mRightHoverDrawable;
+
+ void onEnterScrollArea(int direction) {
+ mInScrollArea = true;
+ invalidate();
+ }
+
+ void onExitScrollArea() {
+ mInScrollArea = false;
+ invalidate();
+ }
+
+ @Override
+ protected void dispatchDraw(Canvas canvas) {
+ super.dispatchDraw(canvas);
+
+ if (mInScrollArea && !LauncherApplication.isScreenLarge()) {
+ Workspace workspace = mLauncher.getWorkspace();
+ int width = workspace.getWidth();
+ Rect childRect = new Rect();
+ getDescendantRectRelativeToSelf(workspace.getChildAt(0), childRect);
+
+ int page = workspace.getNextPage();
+ CellLayout leftPage = (CellLayout) workspace.getChildAt(page - 1);
+ CellLayout rightPage = (CellLayout) workspace.getChildAt(page + 1);
+
+ if (leftPage != null && leftPage.getIsDragOverlapping()) {
+ mLeftHoverDrawable.setBounds(0, childRect.top,
+ mLeftHoverDrawable.getIntrinsicWidth(), childRect.bottom);
+ mLeftHoverDrawable.draw(canvas);
+ } else if (rightPage != null && rightPage.getIsDragOverlapping()) {
+ mRightHoverDrawable.setBounds(width - mRightHoverDrawable.getIntrinsicWidth(),
+ childRect.top, width, childRect.bottom);
+ mRightHoverDrawable.draw(canvas);
+ }
+ }
+ }
}
diff --git a/src/com/android/launcher2/InstallShortcutReceiver.java b/src/com/android/launcher2/InstallShortcutReceiver.java
index eda82e098..66b3f5f67 100644
--- a/src/com/android/launcher2/InstallShortcutReceiver.java
+++ b/src/com/android/launcher2/InstallShortcutReceiver.java
@@ -113,6 +113,10 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
if (intent != null) {
if (intent.getAction() == null) {
intent.setAction(Intent.ACTION_VIEW);
+ } else if (intent.getAction().equals(Intent.ACTION_MAIN) &&
+ intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) {
+ intent.addFlags(
+ Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
}
// By default, we allow for duplicate entries (located in
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index ea974d3d1..967254b8b 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -568,7 +568,13 @@ public final class Launcher extends Activity
if (isWidgetDrop) {
int appWidgetId = data != null ?
data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
- completeTwoStageWidgetDrop(resultCode, appWidgetId);
+ if (appWidgetId < 0) {
+ Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" +
+ "widget configuration activity.");
+ completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
+ } else {
+ completeTwoStageWidgetDrop(resultCode, appWidgetId);
+ }
return;
}
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index 892faf01f..6d1cc7591 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -1070,6 +1070,15 @@ public class LauncherModel extends BroadcastReceiver {
info = getShortcutInfo(c, context, iconTypeIndex,
iconPackageIndex, iconResourceIndex, iconIndex,
titleIndex);
+
+ // App shortcuts that used to be automatically added to Launcher
+ // didn't always have the correct intent flags set, so do that here
+ if (intent.getAction().equals(Intent.ACTION_MAIN) &&
+ intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) {
+ intent.addFlags(
+ Intent.FLAG_ACTIVITY_NEW_TASK |
+ Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+ }
}
if (info != null) {
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index 83b688d24..4bcb4c7d4 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -270,6 +270,9 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
int getCurrentPage() {
return mCurrentPage;
}
+ int getNextPage() {
+ return (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage;
+ }
int getPageCount() {
return getChildCount();
@@ -1858,9 +1861,8 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
}
protected String getCurrentPageDescription() {
- int page = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage;
return String.format(getContext().getString(R.string.default_scroll_format),
- page + 1, getChildCount());
+ getNextPage() + 1, getChildCount());
}
@Override
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index aa378dfd2..84787a251 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -38,6 +38,8 @@ import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PointF;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.Region.Op;
import android.graphics.drawable.Drawable;
@@ -1314,38 +1316,6 @@ public class Workspace extends SmoothPagedView
}
@Override
- protected void dispatchDraw(Canvas canvas) {
- super.dispatchDraw(canvas);
-
- if (mInScrollArea && !LauncherApplication.isScreenLarge()) {
- final int width = getWidth();
- final int height = getHeight();
- final int pageHeight = getChildAt(0).getHeight();
-
- // Set the height of the outline to be the height of the page
- final int offset = (height - pageHeight - getPaddingTop() - getPaddingBottom()) / 2;
- final int paddingTop = getPaddingTop() + offset;
- final int paddingBottom = getPaddingBottom() + offset;
-
- final int page = (mNextPage != INVALID_PAGE ? mNextPage : mCurrentPage);
- final CellLayout leftPage = (CellLayout) getChildAt(page - 1);
- final CellLayout rightPage = (CellLayout) getChildAt(page + 1);
-
- if (leftPage != null && leftPage.getIsDragOverlapping()) {
- final Drawable d = getResources().getDrawable(R.drawable.page_hover_left_holo);
- d.setBounds(getScrollX(), paddingTop, getScrollX() + d.getIntrinsicWidth(),
- height - paddingBottom);
- d.draw(canvas);
- } else if (rightPage != null && rightPage.getIsDragOverlapping()) {
- final Drawable d = getResources().getDrawable(R.drawable.page_hover_right_holo);
- d.setBounds(getScrollX() + width - d.getIntrinsicWidth(), paddingTop,
- getScrollX() + width, height - paddingBottom);
- d.draw(canvas);
- }
- }
- }
-
- @Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
if (!mLauncher.isAllAppsVisible()) {
final Folder openFolder = getOpenFolder();
@@ -1564,7 +1534,7 @@ public class Workspace extends SmoothPagedView
AnimatorSet anim = animated ? new AnimatorSet() : null;
// Stop any scrolling, move to the current page right away
- setCurrentPage((mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage);
+ setCurrentPage(getNextPage());
final State oldState = mState;
final boolean oldStateIsNormal = (oldState == State.NORMAL);
@@ -3289,7 +3259,7 @@ public class Workspace extends SmoothPagedView
* screen while a scroll is in progress.
*/
public CellLayout getCurrentDropLayout() {
- return (CellLayout) getChildAt(mNextPage == INVALID_PAGE ? mCurrentPage : mNextPage);
+ return (CellLayout) getChildAt(getNextPage());
}
/**
@@ -3441,7 +3411,7 @@ public class Workspace extends SmoothPagedView
if (!isSmall() && !mIsSwitchingState) {
mInScrollArea = true;
- final int page = (mNextPage != INVALID_PAGE ? mNextPage : mCurrentPage) +
+ final int page = getNextPage() +
(direction == DragController.SCROLL_LEFT ? -1 : 1);
// We always want to exit the current layout to ensure parity of enter / exit