Merge "Adding background protection to icons and apps button."
diff --git a/res/layout-xlarge-land/all_apps_tabbed.xml b/res/layout-xlarge-land/all_apps_tabbed.xml
index eb506d1..bb30c11 100644
--- a/res/layout-xlarge-land/all_apps_tabbed.xml
+++ b/res/layout-xlarge-land/all_apps_tabbed.xml
@@ -31,12 +31,36 @@
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:tabStripEnabled="false" />
- <ImageView
- android:id="@+id/market_button"
+ <FrameLayout
+ android:id="@+id/market_info_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
- android:onClick="onClickAppMarketButton" />
+ android:layout_centerVertical="true">
+ <com.android.launcher2.ApplicationInfoDropTarget
+ android:id="@+id/all_apps_info_target"
+ android:src="@drawable/info_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:visibility="invisible"/>
+ <ImageView
+ android:id="@+id/market_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:onClick="onClickAppMarketButton"/>
+ </FrameLayout>
+ <com.android.launcher2.DeleteZone
+ android:id="@+id/all_apps_delete_zone"
+ android:src="@drawable/delete_zone_selector"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_toLeftOf="@id/market_info_frame"
+ android:layout_centerVertical="true"
+ android:visibility="invisible"
+ android:paddingRight="22dp"
+ launcher:direction="horizontal" />
</RelativeLayout>
<FrameLayout
android:id="@android:id/tabcontent"
diff --git a/res/layout-xlarge-land/customization_drawer.xml b/res/layout-xlarge-land/customization_drawer.xml
index 304aaf7..3fff2b0 100644
--- a/res/layout-xlarge-land/customization_drawer.xml
+++ b/res/layout-xlarge-land/customization_drawer.xml
@@ -19,7 +19,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
- launcher:wallpaperCellSpanX="4"
+ launcher:wallpaperCellSpanX="3"
launcher:widgetCellCountX="16"
launcher:cellCountX="8"
launcher:cellCountY="3"
diff --git a/res/layout-xlarge-port/all_apps_tabbed.xml b/res/layout-xlarge-port/all_apps_tabbed.xml
index 038a9a0..5571634 100644
--- a/res/layout-xlarge-port/all_apps_tabbed.xml
+++ b/res/layout-xlarge-port/all_apps_tabbed.xml
@@ -31,12 +31,36 @@
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:tabStripEnabled="false" />
- <ImageView
- android:id="@+id/market_button"
+ <FrameLayout
+ android:id="@+id/market_info_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
- android:onClick="onClickAppMarketButton" />
+ android:layout_centerVertical="true">
+ <com.android.launcher2.ApplicationInfoDropTarget
+ android:id="@+id/all_apps_info_target"
+ android:src="@drawable/info_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:visibility="invisible"/>
+ <ImageView
+ android:id="@+id/market_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:onClick="onClickAppMarketButton"/>
+ </FrameLayout>
+ <com.android.launcher2.DeleteZone
+ android:id="@+id/all_apps_delete_zone"
+ android:src="@drawable/delete_zone_selector"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_toLeftOf="@id/market_info_frame"
+ android:layout_centerVertical="true"
+ android:visibility="invisible"
+ android:paddingRight="22dp"
+ launcher:direction="horizontal" />
</RelativeLayout>
<FrameLayout
android:id="@android:id/tabcontent"
diff --git a/res/layout-xlarge/customize_paged_view_wallpaper.xml b/res/layout-xlarge/customize_paged_view_wallpaper.xml
index 6cf248a..e3be86d 100644
--- a/res/layout-xlarge/customize_paged_view_wallpaper.xml
+++ b/res/layout-xlarge/customize_paged_view_wallpaper.xml
@@ -13,8 +13,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<LinearLayout
+<com.android.launcher2.PagedViewWidget
xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
android:layout_width="wrap_content"
android:layout_height="365dp"
@@ -22,7 +23,10 @@
android:paddingRight="12.5dp"
android:paddingBottom="50dp"
android:gravity="top"
- android:orientation="vertical">
+ android:orientation="vertical"
+
+ launcher:blurColor="#FF6B8CF0"
+ launcher:outlineColor="#FF8CD2FF">
<!-- The preview image for the wallpaper. -->
<ImageView
@@ -57,4 +61,4 @@
android:maxLines="2"
android:fadingEdge="horizontal" />
-</LinearLayout>
+</com.android.launcher2.PagedViewWidget>
diff --git a/res/layout-xlarge/customize_paged_view_widget.xml b/res/layout-xlarge/customize_paged_view_widget.xml
index deeeb3d..3b95ebc 100644
--- a/res/layout-xlarge/customize_paged_view_widget.xml
+++ b/res/layout-xlarge/customize_paged_view_widget.xml
@@ -13,20 +13,21 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<LinearLayout
+<com.android.launcher2.PagedViewWidget
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
android:layout_width="wrap_content"
android:layout_height="365dp"
android:paddingLeft="12.5dp"
+ android:paddingTop="12.5dp"
android:paddingRight="12.5dp"
android:paddingBottom="50dp"
android:gravity="top"
android:orientation="vertical"
- launcher:checkedBlurColor="#FFDAFF71"
- launcher:checkedOutlineColor="#FFCFFF9C">
+ launcher:blurColor="#FF6B8CF0"
+ launcher:outlineColor="#FF8CD2FF">
<!-- The icon of the widget. -->
<ImageView
@@ -76,4 +77,4 @@
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0" />
-</LinearLayout>
+</com.android.launcher2.PagedViewWidget>
diff --git a/res/values-xlarge/dimens.xml b/res/values-xlarge/dimens.xml
index 7033553..a9ba1d5 100644
--- a/res/values-xlarge/dimens.xml
+++ b/res/values-xlarge/dimens.xml
@@ -48,8 +48,7 @@
<!-- height & width of the drop rectangle for the trash icon -->
<dimen name="delete_zone_size">50dip</dimen>
- <dimen name="delete_zone_min_padding">10dip</dimen>
- <dimen name="delete_zone_max_padding">20dip</dimen>
+ <dimen name="delete_zone_padding">20dip</dimen>
<!-- dimensions for the wallpaper picker wallpaper thumbnail width -->
<dimen name="wallpaper_small_width">170dp</dimen>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 975548e..853d49e 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -74,6 +74,15 @@
<attr name="checkedOutlineColor" format="color" />
</declare-styleable>
+ <!-- PagedViewWidget specific attributes. These attributes are used to
+ customize a PagedViewWidget view in XML files. -->
+ <declare-styleable name="PagedViewWidget">
+ <!-- The blur color of the holographic outline -->
+ <attr name="blurColor" />
+ <!-- The outline color of the holographic outline -->
+ <attr name="outlineColor" />
+ </declare-styleable>
+
<!-- PagedView specific attributes. These attributes are used to customize
a PagedView view in XML files. -->
<declare-styleable name="PagedView">
diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java
index 4ca5b47..ecdb7b3 100644
--- a/src/com/android/launcher2/AllAppsPagedView.java
+++ b/src/com/android/launcher2/AllAppsPagedView.java
@@ -24,12 +24,8 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
-import android.view.ActionMode;
import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuItem;
import android.view.View;
-import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.Checkable;
import android.widget.TextView;
@@ -42,7 +38,7 @@
*/
public class AllAppsPagedView extends PagedView
implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource,
- DropTarget, ActionMode.Callback {
+ DropTarget {
private static final String TAG = "AllAppsPagedView";
private static final boolean DEBUG = false;
@@ -69,11 +65,6 @@
private final LayoutInflater mInflater;
- private ViewGroup mOrigInfoButtonParent;
- private LayoutParams mOrigInfoButtonLayoutParams;
-
- private ViewGroup mOrigDeleteZoneParent;
- private LayoutParams mOrigDeleteZoneLayoutParams;
public AllAppsPagedView(Context context) {
this(context, null);
@@ -207,6 +198,47 @@
}
}
+ private void setupDragMode() {
+ mLauncher.getWorkspace().shrinkToBottomVisible();
+
+ ApplicationInfoDropTarget infoButton =
+ (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
+ infoButton.setDragAndDropEnabled(false);
+ DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
+ deleteZone.setDragAndDropEnabled(false);
+
+ ApplicationInfoDropTarget allAppsInfoButton =
+ (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
+ allAppsInfoButton.setDragAndDropEnabled(true);
+ DeleteZone allAppsDeleteZone = (DeleteZone)
+ mLauncher.findViewById(R.id.all_apps_delete_zone);
+ allAppsDeleteZone.setDragAndDropEnabled(true);
+ }
+
+ private void tearDownDragMode() {
+ post(new Runnable() {
+ // Once the drag operation has fully completed, hence the post, we want to disable the
+ // deleteZone and the appInfoButton in all apps, and re-enable the instance which
+ // live in the workspace
+ public void run() {
+ ApplicationInfoDropTarget infoButton =
+ (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
+ infoButton.setDragAndDropEnabled(true);
+ DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
+ deleteZone.setDragAndDropEnabled(true);
+
+ ApplicationInfoDropTarget allAppsInfoButton =
+ (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
+ allAppsInfoButton.setDragAndDropEnabled(false);
+ DeleteZone allAppsDeleteZone =
+ (DeleteZone) mLauncher.findViewById(R.id.all_apps_delete_zone);
+ allAppsDeleteZone.setDragAndDropEnabled(false);
+ }
+ });
+ resetCheckedGrandchildren();
+ mDragController.removeDropTarget(this);
+ }
+
@Override
public boolean onLongClick(View v) {
if (!v.isInTouchMode()) {
@@ -223,10 +255,8 @@
c.toggle();
}
- // Start choice mode AFTER the item is selected
- if (isChoiceMode(CHOICE_MODE_NONE)) {
- startChoiceMode(CHOICE_MODE_SINGLE, this);
- }
+ // Start drag mode after the item is selected
+ setupDragMode();
ApplicationInfo app = (ApplicationInfo) v.getTag();
app = new ApplicationInfo(app);
@@ -246,6 +276,7 @@
if (target != this) {
endChoiceMode();
}
+ tearDownDragMode();
mLauncher.getWorkspace().onDragStopped();
}
@@ -467,83 +498,6 @@
new PagedViewCellLayout.LayoutParams(0, 0, 2, 1));
}
}
- @Override
- public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
- mode.setTitle(R.string.cab_app_selection_text);
-
- // Until the workspace has a selection mode and the CAB supports drag-and-drop, we
- // take a hybrid approach: grab the views from the workspace and stuff them into the CAB.
- // When the action mode is done, restore the views to their original place in the toolbar.
-
- ApplicationInfoDropTarget infoButton =
- (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
- mOrigInfoButtonParent = (ViewGroup) infoButton.getParent();
- mOrigInfoButtonLayoutParams = infoButton.getLayoutParams();
- mOrigInfoButtonParent.removeView(infoButton);
- infoButton.setManageVisibility(false);
- infoButton.setVisibility(View.VISIBLE);
- infoButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- final ApplicationInfo appInfo = (ApplicationInfo) getChosenItem();
- mLauncher.startApplicationDetailsActivity(appInfo.componentName);
- }
- });
-
- DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
- mOrigDeleteZoneParent = (ViewGroup) deleteZone.getParent();
- mOrigDeleteZoneLayoutParams = deleteZone.getLayoutParams();
- mOrigDeleteZoneParent.removeView(deleteZone);
- deleteZone.setManageVisibility(false);
- deleteZone.setVisibility(View.VISIBLE);
- deleteZone.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- final ApplicationInfo appInfo = (ApplicationInfo) getChosenItem();
- mLauncher.startApplicationUninstallActivity(appInfo);
- }
- });
-
- menu.add(0, MENU_DELETE_APP, 0, R.string.cab_menu_delete_app).setActionView(deleteZone);
- menu.add(0, MENU_APP_INFO, 0, R.string.cab_menu_app_info).setActionView(infoButton);
-
- mLauncher.getWorkspace().shrinkToBottomVisible();
-
- return true;
- }
-
- @Override
- public boolean onCreateActionMode(ActionMode mode, Menu menu) {
- mDragController.addDropTarget(this);
- return true;
- }
-
- @Override
- public void onDestroyActionMode(ActionMode mode) {
- final Menu menu = mode.getMenu();
-
- // Re-parent the drop targets into the toolbar, and restore their layout params
-
- ApplicationInfoDropTarget infoButton =
- (ApplicationInfoDropTarget) menu.findItem(MENU_APP_INFO).getActionView();
- ((ViewGroup) infoButton.getParent()).removeView(infoButton);
- mOrigInfoButtonParent.addView(infoButton, mOrigInfoButtonLayoutParams);
- infoButton.setVisibility(View.GONE);
- infoButton.setManageVisibility(true);
-
- DeleteZone deleteZone = (DeleteZone) menu.findItem(MENU_DELETE_APP).getActionView();
- ((ViewGroup) deleteZone.getParent()).removeView(deleteZone);
- mOrigDeleteZoneParent.addView(deleteZone, mOrigDeleteZoneLayoutParams);
- deleteZone.setVisibility(View.GONE);
- deleteZone.setManageVisibility(true);
-
- mDragController.removeDropTarget(this);
- endChoiceMode();
- }
-
- @Override
- public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- // This is never called. Because we use setActionView(), we handle our own click events.
- return false;
- }
/*
* We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop
diff --git a/src/com/android/launcher2/ApplicationInfoDropTarget.java b/src/com/android/launcher2/ApplicationInfoDropTarget.java
index c2922ab..849d2b5 100644
--- a/src/com/android/launcher2/ApplicationInfoDropTarget.java
+++ b/src/com/android/launcher2/ApplicationInfoDropTarget.java
@@ -16,8 +16,6 @@
package com.android.launcher2;
-import com.android.launcher.R;
-
import android.content.ComponentName;
import android.content.Context;
import android.graphics.Paint;
@@ -28,6 +26,8 @@
import android.view.View;
import android.widget.ImageView;
+import com.android.launcher.R;
+
/**
* Implements a DropTarget which allows applications to be dropped on it,
* in order to launch the application info for that app.
@@ -41,7 +41,7 @@
* This is generally the case, but it will be set to false when this is part of the
* Contextual Action Bar.
*/
- private boolean mManageVisibility = true;
+ private boolean mDragAndDropEnabled = true;
/** The view that this view should appear in the place of. */
private View mHandle = null;
@@ -69,6 +69,7 @@
// acceptDrop is called just before onDrop. We do the work here, rather than
// in onDrop, because it allows us to reject the drop (by returning false)
// so that the object being dragged isn't removed from the home screen.
+ if (getVisibility() != VISIBLE) return false;
ComponentName componentName = null;
if (dragInfo instanceof ApplicationInfo) {
@@ -87,6 +88,7 @@
public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
+ if (!mDragAndDropEnabled) return;
dragView.setPaint(mPaint);
}
@@ -96,18 +98,20 @@
public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
+ if (!mDragAndDropEnabled) return;
dragView.setPaint(null);
}
public void onDragStart(DragSource source, Object info, int dragAction) {
- if (info != null) {
+ if (info != null && mDragAndDropEnabled) {
final int itemType = ((ItemInfo)info).itemType;
mActive = (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION);
- if (mManageVisibility) {
- // Only show the info icon when an application is selected
- if (mActive) {
- setVisibility(VISIBLE);
- }
+
+ // Only show the info icon when an application is selected
+ if (mActive) {
+ setVisibility(VISIBLE);
+ }
+ if (mHandle != null) {
mHandle.setVisibility(INVISIBLE);
}
}
@@ -118,11 +122,13 @@
}
public void onDragEnd() {
+ if (!mDragAndDropEnabled) return;
+
if (mActive) {
mActive = false;
}
- if (mManageVisibility) {
- setVisibility(GONE);
+ setVisibility(GONE);
+ if (mHandle != null) {
mHandle.setVisibility(VISIBLE);
}
}
@@ -131,16 +137,10 @@
public void getHitRect(Rect outRect) {
super.getHitRect(outRect);
if (LauncherApplication.isScreenXLarge()) {
- // TODO: This is a temporary hack. mManageVisiblity = false when you're in CAB mode.
- // In that case, this icon is more tightly spaced next to the delete icon so we want
- // it to have a smaller drag region. When the new drag&drop system comes in, we'll
- // dispatch the drag/drop by calculating what target you're overlapping
- final int minPadding = R.dimen.delete_zone_min_padding;
- final int maxPadding = R.dimen.delete_zone_max_padding;
+ final int padding = R.dimen.delete_zone_padding;
final int outerDragPadding =
getResources().getDimensionPixelSize(R.dimen.delete_zone_size);
- final int innerDragPadding = getResources().getDimensionPixelSize(
- mManageVisibility ? maxPadding : minPadding);
+ final int innerDragPadding = getResources().getDimensionPixelSize(padding);
outRect.top -= outerDragPadding;
outRect.left -= innerDragPadding;
outRect.bottom += outerDragPadding;
@@ -156,8 +156,8 @@
mHandle = view;
}
- void setManageVisibility(boolean value) {
- mManageVisibility = value;
+ void setDragAndDropEnabled(boolean enabled) {
+ mDragAndDropEnabled = enabled;
}
@Override
diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java
index b48d4ab..50ec64b 100644
--- a/src/com/android/launcher2/CustomizePagedView.java
+++ b/src/com/android/launcher2/CustomizePagedView.java
@@ -569,7 +569,7 @@
* This method will extract the preview image specified by the wallpaper source provider (if it
* exists) otherwise, it will try to generate a default image preview.
*/
- private Drawable getWallpaperPreview(ResolveInfo info) {
+ private FastBitmapDrawable getWallpaperPreview(ResolveInfo info) {
// To be implemented later: resolving the up-to-date wallpaper thumbnail
final int minDim = mWorkspaceWidgetLayout.estimateCellWidth(1);
@@ -597,7 +597,7 @@
// if we can't find the icon, then just don't draw it
}
- Drawable drawable = new FastBitmapDrawable(bitmap);
+ FastBitmapDrawable drawable = new FastBitmapDrawable(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
return drawable;
}
@@ -607,10 +607,11 @@
* otherwise, it will try to generate a default image preview with the widget's package icon.
* @return the drawable that will be used and sized in the ImageView to represent the widget
*/
- private Drawable getWidgetPreview(AppWidgetProviderInfo info) {
+ private FastBitmapDrawable getWidgetPreview(AppWidgetProviderInfo info) {
final PackageManager packageManager = mPackageManager;
String packageName = info.provider.getPackageName();
Drawable drawable = null;
+ FastBitmapDrawable newDrawable = null;
if (info.previewImage != 0) {
drawable = packageManager.getDrawable(packageName, info.previewImage, null);
if (drawable == null) {
@@ -649,7 +650,7 @@
// if we can't find the icon, then just don't draw it
}
- drawable = new FastBitmapDrawable(bitmap);
+ newDrawable = new FastBitmapDrawable(bitmap);
} else {
// Scale down the preview if necessary
final float imageWidth = drawable.getIntrinsicWidth();
@@ -672,10 +673,11 @@
final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
renderDrawableToBitmap(drawable, bitmap, 0, 0, width, height);
- drawable = new FastBitmapDrawable(bitmap);
+ newDrawable = new FastBitmapDrawable(bitmap);
}
- drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
- return drawable;
+ newDrawable.setBounds(0, 0, newDrawable.getIntrinsicWidth(),
+ newDrawable.getIntrinsicHeight());
+ return newDrawable;
}
private void setupPage(PagedViewCellLayout layout) {
@@ -720,28 +722,18 @@
for (int i = 0; i < count; ++i) {
final AppWidgetProviderInfo info = (AppWidgetProviderInfo) list.get(i);
final PendingAddWidgetInfo createItemInfo = new PendingAddWidgetInfo(info, null, null);
+ final int[] cellSpans = CellLayout.rectToCell(getResources(), info.minWidth,
+ info.minHeight, null);
+ final FastBitmapDrawable icon = getWidgetPreview(info);
- LinearLayout l = (LinearLayout) mInflater.inflate(
+ PagedViewWidget l = (PagedViewWidget) mInflater.inflate(
R.layout.customize_paged_view_widget, layout, false);
+ l.applyFromAppWidgetProviderInfo(info, icon, mMaxWidgetWidth, cellSpans);
l.setTag(createItemInfo);
l.setOnClickListener(this);
l.setOnTouchListener(this);
l.setOnLongClickListener(this);
- final Drawable icon = getWidgetPreview(info);
-
- int[] spans = CellLayout.rectToCell(getResources(), info.minWidth, info.minHeight, null);
- final int hSpan = spans[0];
- final int vSpan = spans[1];
-
- ImageView image = (ImageView) l.findViewById(R.id.widget_preview);
- image.setMaxWidth(mMaxWidgetWidth);
- image.setImageDrawable(icon);
- TextView name = (TextView) l.findViewById(R.id.widget_name);
- name.setText(info.label);
- TextView dims = (TextView) l.findViewById(R.id.widget_dims);
- dims.setText(mContext.getString(R.string.widget_dims_format, hSpan, vSpan));
-
layout.addView(l);
}
}
@@ -775,20 +767,14 @@
final int endIndex = Math.min(count, startIndex + numItemsPerPage);
for (int i = startIndex; i < endIndex; ++i) {
final ResolveInfo info = mWallpaperList.get(i);
+ final FastBitmapDrawable icon = getWallpaperPreview(info);
- LinearLayout l = (LinearLayout) mInflater.inflate(
+ PagedViewWidget l = (PagedViewWidget) mInflater.inflate(
R.layout.customize_paged_view_wallpaper, layout, false);
+ l.applyFromWallpaperInfo(info, mPackageManager, icon, mMaxWidgetWidth);
l.setTag(info);
l.setOnClickListener(this);
- final Drawable icon = getWallpaperPreview(info);
-
- ImageView image = (ImageView) l.findViewById(R.id.wallpaper_preview);
- image.setMaxWidth(mMaxWidgetWidth);
- image.setImageDrawable(icon);
- TextView name = (TextView) l.findViewById(R.id.wallpaper_name);
- name.setText(info.loadLabel(mPackageManager));
-
layout.addView(l);
}
}
diff --git a/src/com/android/launcher2/DeleteZone.java b/src/com/android/launcher2/DeleteZone.java
index be651b2..33f384f 100644
--- a/src/com/android/launcher2/DeleteZone.java
+++ b/src/com/android/launcher2/DeleteZone.java
@@ -16,8 +16,6 @@
package com.android.launcher2;
-import com.android.launcher.R;
-
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Paint;
@@ -35,6 +33,8 @@
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
+import com.android.launcher.R;
+
public class DeleteZone extends ImageView implements DropTarget, DragController.DragListener {
private static final int ORIENTATION_HORIZONTAL = 1;
private static final int TRANSITION_DURATION = 250;
@@ -50,7 +50,7 @@
* This is generally the case, but it will be set to false when this is part of the
* Contextual Action Bar.
*/
- private boolean mManageVisibility = true;
+ private boolean mDragAndDropEnabled = true;
private AnimationSet mInAnimation;
private AnimationSet mOutAnimation;
@@ -81,7 +81,6 @@
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DeleteZone, defStyle, 0);
mOrientation = a.getInt(R.styleable.DeleteZone_direction, ORIENTATION_HORIZONTAL);
a.recycle();
-
}
@Override
@@ -97,6 +96,8 @@
public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
+ if (!mDragAndDropEnabled) return;
+
final ItemInfo item = (ItemInfo) dragInfo;
// On x-large screens, you can uninstall an app by dragging from all apps
@@ -142,6 +143,7 @@
public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
+ if (!mDragAndDropEnabled) return;
mTransition.reverseTransition(TRANSITION_DURATION);
dragView.setPaint(mTrashPaint);
}
@@ -152,13 +154,14 @@
public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
DragView dragView, Object dragInfo) {
+ if (!mDragAndDropEnabled) return;
mTransition.reverseTransition(TRANSITION_DURATION);
dragView.setPaint(null);
}
public void onDragStart(DragSource source, Object info, int dragAction) {
final ItemInfo item = (ItemInfo) info;
- if (item != null) {
+ if (item != null && mDragAndDropEnabled) {
mTrashMode = true;
getHitRect(mRegion);
mRegionF.set(mRegion);
@@ -175,26 +178,25 @@
// Make sure the icon is set to the default drawable, not the hover drawable
mTransition.resetTransition();
- if (mManageVisibility) {
- createAnimations();
- startAnimation(mInAnimation);
+ createAnimations();
+ startAnimation(mInAnimation);
+ if (mHandle != null) {
mHandle.startAnimation(mHandleOutAnimation);
- setVisibility(VISIBLE);
}
+ setVisibility(VISIBLE);
}
}
public void onDragEnd() {
- if (mTrashMode) {
+ if (mTrashMode && mDragAndDropEnabled) {
mTrashMode = false;
mDragController.setDeleteRegion(null);
if (mOutAnimation != null) startAnimation(mOutAnimation);
- if (mHandleInAnimation != null) mHandle.startAnimation(mHandleInAnimation);
-
- if (mManageVisibility) {
- setVisibility(GONE);
+ if (mHandleInAnimation != null && mHandle != null) {
+ mHandle.startAnimation(mHandleInAnimation);
}
+ setVisibility(GONE);
}
}
@@ -210,12 +212,10 @@
// In that case, this icon is more tightly spaced next to the delete icon so we want
// it to have a smaller drag region. When the new drag&drop system comes in, we'll
// dispatch the drag/drop by calculating what target you're overlapping
- final int minPadding = R.dimen.delete_zone_min_padding;
- final int maxPadding = R.dimen.delete_zone_max_padding;
+ final int padding = R.dimen.delete_zone_padding;
final int outerDragPadding =
getResources().getDimensionPixelSize(R.dimen.delete_zone_size);
- final int innerDragPadding = getResources().getDimensionPixelSize(
- mManageVisibility ? maxPadding : minPadding);
+ final int innerDragPadding = getResources().getDimensionPixelSize(padding);
outRect.top -= outerDragPadding;
outRect.left -= innerDragPadding;
outRect.bottom += outerDragPadding;
@@ -290,8 +290,8 @@
mHandle = view;
}
- void setManageVisibility(boolean value) {
- mManageVisibility = value;
+ void setDragAndDropEnabled(boolean enabled) {
+ mDragAndDropEnabled = enabled;
}
private static class FastTranslateAnimation extends TranslateAnimation {
diff --git a/src/com/android/launcher2/FastBitmapDrawable.java b/src/com/android/launcher2/FastBitmapDrawable.java
index 1aa8b35..a453294 100644
--- a/src/com/android/launcher2/FastBitmapDrawable.java
+++ b/src/com/android/launcher2/FastBitmapDrawable.java
@@ -26,11 +26,13 @@
class FastBitmapDrawable extends Drawable {
private Bitmap mBitmap;
+ private int mAlpha;
private int mWidth;
private int mHeight;
private final Paint mPaint = new Paint();
FastBitmapDrawable(Bitmap b) {
+ mAlpha = 255;
mBitmap = b;
if (b != null) {
mWidth = mBitmap.getWidth();
@@ -53,9 +55,14 @@
@Override
public void setAlpha(int alpha) {
+ mAlpha = alpha;
mPaint.setAlpha(alpha);
}
+ public int getAlpha() {
+ return mAlpha;
+ }
+
@Override
public void setColorFilter(ColorFilter cf) {
}
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index eacaef9..8a8ef59 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -59,6 +59,7 @@
import android.database.ContentObserver;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
@@ -90,8 +91,6 @@
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnLongClickListener;
-import android.view.animation.AccelerateInterpolator;
-import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.InputMethodManager;
import android.widget.Advanceable;
import android.widget.EditText;
@@ -960,6 +959,29 @@
deleteZone.setHandle(findViewById(deleteZoneHandleId));
dragController.addDragListener(deleteZone);
+ DeleteZone allAppsDeleteZone = (DeleteZone) findViewById(R.id.all_apps_delete_zone);
+ if (allAppsDeleteZone != null) {
+ allAppsDeleteZone.setLauncher(this);
+ allAppsDeleteZone.setDragController(dragController);
+ allAppsDeleteZone.setDragAndDropEnabled(false);
+ dragController.addDragListener(allAppsDeleteZone);
+ dragController.addDropTarget(allAppsDeleteZone);
+ }
+
+ ApplicationInfoDropTarget allAppsInfoTarget = (ApplicationInfoDropTarget)
+ findViewById(R.id.all_apps_info_target);
+ if (allAppsInfoTarget != null) {
+ allAppsInfoTarget.setLauncher(this);
+ dragController.addDragListener(allAppsInfoTarget);
+ allAppsInfoTarget.setDragColor(getResources().getColor(R.color.app_info_filter));
+ allAppsInfoTarget.setDragAndDropEnabled(false);
+ View marketButton = findViewById(R.id.market_button);
+ if (marketButton != null) {
+ marketButton.setBackgroundColor(Color.RED);
+ allAppsInfoTarget.setHandle(marketButton);
+ }
+ }
+
ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button);
if (infoButton != null) {
infoButton.setLauncher(this);
@@ -978,6 +1000,12 @@
if (infoButton != null) {
dragController.addDropTarget(infoButton);
}
+ if (allAppsInfoTarget != null) {
+ dragController.addDropTarget(allAppsInfoTarget);
+ }
+ if (allAppsDeleteZone != null) {
+ dragController.addDropTarget(allAppsDeleteZone);
+ }
}
@SuppressWarnings({"UnusedDeclaration"})
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index d24eef4..31cfb5b 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -566,9 +566,15 @@
rightScreen = Math.min(getChildCount() - 1, rightScreen);
final long drawingTime = getDrawingTime();
+ // Clip to the bounds
+ canvas.save();
+ canvas.clipRect(mScrollX, mScrollY, mScrollX + mRight - mLeft,
+ mScrollY + mBottom - mTop);
+
for (int i = leftScreen; i <= rightScreen; i++) {
drawChild(canvas, getChildAt(i), drawingTime);
}
+ canvas.restore();
}
}
diff --git a/src/com/android/launcher2/PagedViewIcon.java b/src/com/android/launcher2/PagedViewIcon.java
index 9e48351..0e72598 100644
--- a/src/com/android/launcher2/PagedViewIcon.java
+++ b/src/com/android/launcher2/PagedViewIcon.java
@@ -52,7 +52,7 @@
private Object mIconCacheKey;
private PagedViewIconCache mIconCache;
- private int mAlpha = -1;
+ private int mAlpha;
private int mHolographicAlpha;
private boolean mIsChecked;
@@ -104,12 +104,13 @@
public PagedViewIcon(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
+
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedViewIcon, defStyle, 0);
+ mAlpha = 255;
mHoloBlurColor = a.getColor(R.styleable.PagedViewIcon_blurColor, 0);
mHoloOutlineColor = a.getColor(R.styleable.PagedViewIcon_outlineColor, 0);
mCheckedBlurColor = a.getColor(R.styleable.PagedViewIcon_checkedBlurColor, 0);
mCheckedOutlineColor = a.getColor(R.styleable.PagedViewIcon_checkedOutlineColor, 0);
-
a.recycle();
if (sHolographicOutlineHelper == null) {
diff --git a/src/com/android/launcher2/PagedViewWidget.java b/src/com/android/launcher2/PagedViewWidget.java
new file mode 100644
index 0000000..40e507b
--- /dev/null
+++ b/src/com/android/launcher2/PagedViewWidget.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2010 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.launcher2;
+
+import android.appwidget.AppWidgetProviderInfo;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.res.TypedArray;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.drawable.Drawable;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Message;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.android.launcher.R;
+import com.android.launcher2.PagedView.PagedViewIconCache;
+
+/**
+ * The linear layout used strictly for the widget/wallpaper tab of the customization tray
+ */
+public class PagedViewWidget extends LinearLayout {
+ static final String TAG = "PagedViewWidgetLayout";
+
+ private final Paint mPaint = new Paint();
+ private static HolographicOutlineHelper sHolographicOutlineHelper;
+ private Bitmap mHolographicOutline;
+ private final Canvas mHolographicOutlineCanvas = new Canvas();
+ private FastBitmapDrawable mPreview;
+
+ private int mAlpha = 255;
+ private int mHolographicAlpha;
+
+ // Highlight colors
+ private int mHoloBlurColor;
+ private int mHoloOutlineColor;
+
+ private static final HandlerThread sWorkerThread = new HandlerThread("pagedviewwidget-helper");
+ static {
+ sWorkerThread.start();
+ }
+
+ private static final int MESSAGE_CREATE_HOLOGRAPHIC_OUTLINE = 1;
+
+ private static final Handler sWorker = new Handler(sWorkerThread.getLooper()) {
+ private DeferredHandler mHandler = new DeferredHandler();
+ public void handleMessage(Message msg) {
+ final PagedViewWidget widget = (PagedViewWidget) msg.obj;
+ final int prevAlpha = widget.mPreview.getAlpha();
+ final Bitmap outline = Bitmap.createBitmap(widget.getWidth(), widget.getHeight(),
+ Bitmap.Config.ARGB_8888);
+
+ widget.mHolographicOutlineCanvas.setBitmap(outline);
+ widget.mHolographicOutlineCanvas.save();
+ widget.mHolographicOutlineCanvas.translate(widget.mPaddingLeft, widget.mPaddingTop);
+ widget.mPreview.setAlpha(255);
+ widget.mPreview.draw(widget.mHolographicOutlineCanvas);
+ widget.mPreview.setAlpha(prevAlpha);
+ widget.mHolographicOutlineCanvas.restore();
+
+ sHolographicOutlineHelper.applyExpensiveOutlineWithBlur(outline,
+ widget.mHolographicOutlineCanvas, widget.mHoloBlurColor,
+ widget.mHoloOutlineColor);
+
+ mHandler.post(new Runnable() {
+ public void run() {
+ widget.mHolographicOutline = outline;
+ widget.invalidate();
+ }
+ });
+ }
+ };
+
+ public PagedViewWidget(Context context) {
+ this(context, null);
+ }
+
+ public PagedViewWidget(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public PagedViewWidget(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedViewWidget,
+ defStyle, 0);
+ mHoloBlurColor = a.getColor(R.styleable.PagedViewWidget_blurColor, 0);
+ mHoloOutlineColor = a.getColor(R.styleable.PagedViewWidget_outlineColor, 0);
+ a.recycle();
+
+ if (sHolographicOutlineHelper == null) {
+ sHolographicOutlineHelper = new HolographicOutlineHelper();
+ }
+
+ setFocusable(true);
+ setWillNotDraw(false);
+ setClipToPadding(false);
+ }
+
+ private void queueHolographicOutlineCreation() {
+ // Generate the outline in the background
+ if (mHolographicOutline == null) {
+ Message m = sWorker.obtainMessage(MESSAGE_CREATE_HOLOGRAPHIC_OUTLINE);
+ m.obj = this;
+ sWorker.sendMessage(m);
+ }
+ }
+
+ public void applyFromAppWidgetProviderInfo(AppWidgetProviderInfo info,
+ FastBitmapDrawable preview, int maxWidth, int[] cellSpan) {
+ final ImageView image = (ImageView) findViewById(R.id.widget_preview);
+ image.setMaxWidth(maxWidth);
+ image.setImageDrawable(preview);
+ final TextView name = (TextView) findViewById(R.id.widget_name);
+ name.setText(info.label);
+ final TextView dims = (TextView) findViewById(R.id.widget_dims);
+ dims.setText(mContext.getString(R.string.widget_dims_format, cellSpan[0], cellSpan[1]));
+ mPreview = preview;
+ }
+
+ public void applyFromWallpaperInfo(ResolveInfo info, PackageManager packageManager,
+ FastBitmapDrawable preview, int maxWidth) {
+ ImageView image = (ImageView) findViewById(R.id.wallpaper_preview);
+ image.setMaxWidth(maxWidth);
+ image.setImageDrawable(preview);
+ TextView name = (TextView) findViewById(R.id.wallpaper_name);
+ name.setText(info.loadLabel(packageManager));
+ mPreview = preview;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ // We eat up the touch events here, since the PagedView (which uses the same swiping
+ // touch code as Workspace previously) uses onInterceptTouchEvent() to determine when
+ // the user is scrolling between pages. This means that if the pages themselves don't
+ // handle touch events, it gets forwarded up to PagedView itself, and it's own
+ // onTouchEvent() handling will prevent further intercept touch events from being called
+ // (it's the same view in that case). This is not ideal, but to prevent more changes,
+ // we just always mark the touch event as handled.
+ return super.onTouchEvent(event) || true;
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ if (mAlpha > 0) {
+ super.onDraw(canvas);
+ }
+
+ // draw any blended overlays
+ if (mHolographicOutline != null && mHolographicAlpha > 0) {
+ mPaint.setAlpha(mHolographicAlpha);
+ canvas.drawBitmap(mHolographicOutline, 0, 0, mPaint);
+ }
+ }
+
+ @Override
+ protected boolean onSetAlpha(int alpha) {
+ return true;
+ }
+
+ @Override
+ public void setAlpha(float alpha) {
+ final float viewAlpha = sHolographicOutlineHelper.viewAlphaInterpolator(alpha);
+ final float holographicAlpha = sHolographicOutlineHelper.highlightAlphaInterpolator(alpha);
+ int newViewAlpha = (int) (viewAlpha * 255);
+ int newHolographicAlpha = (int) (holographicAlpha * 255);
+ if ((mAlpha != newViewAlpha) || (mHolographicAlpha != newHolographicAlpha)) {
+ mAlpha = newViewAlpha;
+ mHolographicAlpha = newHolographicAlpha;
+ setChildrenAlpha(viewAlpha);
+ super.setAlpha(viewAlpha);
+ }
+ }
+
+ private void setChildrenAlpha(float alpha) {
+ final int childCount = getChildCount();
+ for (int i = 0; i < childCount; i++) {
+ getChildAt(i).setAlpha(alpha);
+ }
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ if (w > 0 && h > 0) {
+ queueHolographicOutlineCreation();
+ }
+
+ super.onSizeChanged(w, h, oldw, oldh);
+ }
+
+ @Override
+ public void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+ sWorker.removeMessages(MESSAGE_CREATE_HOLOGRAPHIC_OUTLINE, this);
+ }
+}