Merge "Revert "Setting hotseat padding to the container for symmetry"" into ub-launcher3-burnaby
diff --git a/Android.mk b/Android.mk
index 632dd09..d7bfdd4 100644
--- a/Android.mk
+++ b/Android.mk
@@ -23,6 +23,8 @@
LOCAL_MODULE_TAGS := optional
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
+
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
$(call all-java-files-under, WallpaperPicker/src) \
$(call all-renderscript-files-under, src) \
@@ -35,6 +37,9 @@
LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/protos/
LOCAL_SDK_VERSION := 21
+LOCAL_STATIC_JAVA_LIBRARIES := \
+ android-support-v4 \
+ android-support-v7-recyclerview
LOCAL_PACKAGE_NAME := Launcher3
#LOCAL_CERTIFICATE := shared
@@ -45,8 +50,6 @@
include $(BUILD_PACKAGE)
-include $(call all-makefiles-under,$(LOCAL_PATH))
-
#
# Protocol Buffer Debug Utility in Java
#
@@ -84,3 +87,6 @@
$(hide) chmod 755 $@
INTERNAL_DALVIK_MODULES += $(LOCAL_INSTALLED_MODULE)
+
+# ==================================================
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index fb7ac3f..f43106f 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -29,12 +29,6 @@
android:label="@string/permlab_install_shortcut"
android:description="@string/permdesc_install_shortcut" />
<permission
- android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"
- android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
- android:protectionLevel="dangerous"
- android:label="@string/permlab_uninstall_shortcut"
- android:description="@string/permdesc_uninstall_shortcut"/>
- <permission
android:name="com.android.launcher3.permission.READ_SETTINGS"
android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
android:protectionLevel="normal"
@@ -128,7 +122,7 @@
</activity>
<activity
- android:name="com.android.launcher3.LauncherWallpaperPickerActivity"
+ android:name="com.android.launcher3.WallpaperPickerActivity"
android:theme="@style/Theme.WallpaperPicker"
android:label="@string/pick_wallpaper"
android:icon="@mipmap/ic_launcher_wallpaper"
@@ -191,15 +185,6 @@
</intent-filter>
</receiver>
- <!-- Intent received used to uninstall shortcuts from other applications -->
- <receiver
- android:name="com.android.launcher3.UninstallShortcutReceiver"
- android:permission="com.android.launcher.permission.UNINSTALL_SHORTCUT">
- <intent-filter>
- <action android:name="com.android.launcher.action.UNINSTALL_SHORTCUT" />
- </intent-filter>
- </receiver>
-
<!-- Intent received used to initialize a restored widget -->
<receiver android:name="com.android.launcher3.AppWidgetsRestoredReceiver" >
<intent-filter>
@@ -216,15 +201,6 @@
</intent-filter>
</receiver>
- <receiver android:name="com.android.launcher3.PackageChangedReceiver" >
- <intent-filter>
- <action android:name="android.intent.action.PACKAGE_CHANGED"/>
- <action android:name="android.intent.action.PACKAGE_REPLACED"/>
- <action android:name="android.intent.action.PACKAGE_REMOVED"/>
- <data android:scheme="package"></data>
- </intent-filter>
- </receiver>
-
<receiver android:name="com.android.launcher3.StartupReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
diff --git a/WallpaperPicker/src/com/android/gallery3d/common/BitmapUtils.java b/WallpaperPicker/src/com/android/gallery3d/common/BitmapUtils.java
index 3470017..9ac5c1b 100644
--- a/WallpaperPicker/src/com/android/gallery3d/common/BitmapUtils.java
+++ b/WallpaperPicker/src/com/android/gallery3d/common/BitmapUtils.java
@@ -16,20 +16,12 @@
package com.android.gallery3d.common;
-import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.Point;
import android.net.Uri;
-import android.os.Build;
import android.util.Log;
-import android.view.WindowManager;
import com.android.gallery3d.exif.ExifInterface;
-import com.android.launcher3.WallpaperCropActivity;
import java.io.BufferedInputStream;
import java.io.IOException;
@@ -49,92 +41,6 @@
: initialSize / 8 * 8;
}
- public static Bitmap resizeBitmapByScale(
- Bitmap bitmap, float scale, boolean recycle) {
- int width = Math.round(bitmap.getWidth() * scale);
- int height = Math.round(bitmap.getHeight() * scale);
- if (width == bitmap.getWidth()
- && height == bitmap.getHeight()) return bitmap;
- Bitmap target = Bitmap.createBitmap(width, height, getConfig(bitmap));
- Canvas canvas = new Canvas(target);
- canvas.scale(scale, scale);
- Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
- canvas.drawBitmap(bitmap, 0, 0, paint);
- if (recycle) bitmap.recycle();
- return target;
- }
-
- private static Bitmap.Config getConfig(Bitmap bitmap) {
- Bitmap.Config config = bitmap.getConfig();
- if (config == null) {
- config = Bitmap.Config.ARGB_8888;
- }
- return config;
- }
-
- /**
- * As a ratio of screen height, the total distance we want the parallax effect to span
- * horizontally
- */
- public static float wallpaperTravelToScreenWidthRatio(int width, int height) {
- float aspectRatio = width / (float) height;
-
- // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
- // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
- // We will use these two data points to extrapolate how much the wallpaper parallax effect
- // to span (ie travel) at any aspect ratio:
-
- final float ASPECT_RATIO_LANDSCAPE = 16/10f;
- final float ASPECT_RATIO_PORTRAIT = 10/16f;
- final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
- final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
-
- // To find out the desired width at different aspect ratios, we use the following two
- // formulas, where the coefficient on x is the aspect ratio (width/height):
- // (16/10)x + y = 1.5
- // (10/16)x + y = 1.2
- // We solve for x and y and end up with a final formula:
- final float x =
- (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
- (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
- final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
- return x * aspectRatio + y;
- }
-
- private static Point sDefaultWallpaperSize;
-
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
- public static Point getDefaultWallpaperSize(Resources res, WindowManager windowManager) {
- if (sDefaultWallpaperSize == null) {
- Point minDims = new Point();
- Point maxDims = new Point();
- windowManager.getDefaultDisplay().getCurrentSizeRange(minDims, maxDims);
-
- int maxDim = Math.max(maxDims.x, maxDims.y);
- int minDim = Math.max(minDims.x, minDims.y);
-
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
- Point realSize = new Point();
- windowManager.getDefaultDisplay().getRealSize(realSize);
- maxDim = Math.max(realSize.x, realSize.y);
- minDim = Math.min(realSize.x, realSize.y);
- }
-
- // We need to ensure that there is enough extra space in the wallpaper
- // for the intended parallax effects
- final int defaultWidth, defaultHeight;
- if (res.getConfiguration().smallestScreenWidthDp >= 720) {
- defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
- defaultHeight = maxDim;
- } else {
- defaultWidth = Math.max((int) (minDim * WallpaperCropActivity.WALLPAPER_SCREENS_SPAN), maxDim);
- defaultHeight = maxDim;
- }
- sDefaultWallpaperSize = new Point(defaultWidth, defaultHeight);
- }
- return sDefaultWallpaperSize;
- }
-
public static int getRotationFromExif(Context context, Uri uri) {
return BitmapUtils.getRotationFromExifHelper(null, 0, context, uri);
}
diff --git a/WallpaperPicker/src/com/android/gallery3d/glrenderer/UploadedTexture.java b/WallpaperPicker/src/com/android/gallery3d/glrenderer/UploadedTexture.java
index f41a979..67abf65 100644
--- a/WallpaperPicker/src/com/android/gallery3d/glrenderer/UploadedTexture.java
+++ b/WallpaperPicker/src/com/android/gallery3d/glrenderer/UploadedTexture.java
@@ -20,6 +20,8 @@
import android.graphics.Bitmap.Config;
import android.opengl.GLUtils;
+import com.android.launcher3.util.Thunk;
+
import junit.framework.Assert;
import java.util.HashMap;
@@ -82,7 +84,7 @@
return mIsUploading;
}
- private static class BorderKey implements Cloneable {
+ @Thunk static class BorderKey implements Cloneable {
public boolean vertical;
public Config config;
public int length;
diff --git a/src/com/android/launcher3/LauncherWallpaperPickerActivity.java b/WallpaperPicker/src/com/android/launcher3/LauncherWallpaperPickerActivity.java
similarity index 69%
rename from src/com/android/launcher3/LauncherWallpaperPickerActivity.java
rename to WallpaperPicker/src/com/android/launcher3/LauncherWallpaperPickerActivity.java
index 10fe013..091c054 100644
--- a/src/com/android/launcher3/LauncherWallpaperPickerActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/LauncherWallpaperPickerActivity.java
@@ -16,15 +16,6 @@
package com.android.launcher3;
-import android.content.Intent;
-
+// TODO: Remove this class
public class LauncherWallpaperPickerActivity extends WallpaperPickerActivity {
- @Override
- public void startActivityForResultSafely(Intent intent, int requestCode) {
- Utilities.startActivityForResultSafely(this, intent, requestCode);
- }
- @Override
- public boolean enableRotation() {
- return Utilities.isRotationEnabled(this);
- }
-}
+}
\ No newline at end of file
diff --git a/WallpaperPicker/src/com/android/launcher3/LiveWallpaperListAdapter.java b/WallpaperPicker/src/com/android/launcher3/LiveWallpaperListAdapter.java
index 72f2d7e..b53fce1 100644
--- a/WallpaperPicker/src/com/android/launcher3/LiveWallpaperListAdapter.java
+++ b/WallpaperPicker/src/com/android/launcher3/LiveWallpaperListAdapter.java
@@ -30,11 +30,12 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
-import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;
+import com.android.launcher3.util.Thunk;
+
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
@@ -50,7 +51,7 @@
private final LayoutInflater mInflater;
private final PackageManager mPackageManager;
- private List<LiveWallpaperTile> mWallpapers;
+ @Thunk List<LiveWallpaperTile> mWallpapers;
@SuppressWarnings("unchecked")
public LiveWallpaperListAdapter(Context context) {
@@ -109,8 +110,8 @@
}
public static class LiveWallpaperTile extends WallpaperPickerActivity.WallpaperTileInfo {
- private Drawable mThumbnail;
- private WallpaperInfo mInfo;
+ @Thunk Drawable mThumbnail;
+ @Thunk WallpaperInfo mInfo;
public LiveWallpaperTile(Drawable thumbnail, WallpaperInfo info, Intent intent) {
mThumbnail = thumbnail;
mInfo = info;
diff --git a/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java b/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java
index 9f92bc1..64b0ac4 100644
--- a/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java
+++ b/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java
@@ -16,7 +16,6 @@
package com.android.launcher3;
-import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
@@ -60,13 +59,13 @@
}
}
- public SavedWallpaperImages(Activity context) {
+ public SavedWallpaperImages(Context context) {
// We used to store the saved images in the cache directory, but that meant they'd get
// deleted sometimes-- move them to the data directory
ImageDb.moveFromCacheDirectoryIfNecessary(context);
mDb = new ImageDb(context);
mContext = context;
- mLayoutInflater = context.getLayoutInflater();
+ mLayoutInflater = LayoutInflater.from(context);
}
public void loadThumbnailsAndImageIdList() {
diff --git a/WallpaperPicker/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java b/WallpaperPicker/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java
index 27e65aa..f46da53 100644
--- a/WallpaperPicker/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java
+++ b/WallpaperPicker/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java
@@ -28,16 +28,15 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
-import android.widget.FrameLayout;
import android.widget.ListAdapter;
import android.widget.TextView;
+import com.android.launcher3.util.Thunk;
+
import java.util.ArrayList;
import java.util.List;
public class ThirdPartyWallpaperPickerListAdapter extends BaseAdapter implements ListAdapter {
- private static final String LOG_TAG = "LiveWallpaperListAdapter";
-
private final LayoutInflater mInflater;
private final PackageManager mPackageManager;
private final int mIconSize;
@@ -46,7 +45,7 @@
new ArrayList<ThirdPartyWallpaperTile>();
public static class ThirdPartyWallpaperTile extends WallpaperPickerActivity.WallpaperTileInfo {
- private ResolveInfo mResolveInfo;
+ @Thunk ResolveInfo mResolveInfo;
public ThirdPartyWallpaperTile(ResolveInfo resolveInfo) {
mResolveInfo = resolveInfo;
}
@@ -62,7 +61,7 @@
}
public ThirdPartyWallpaperPickerListAdapter(Context context) {
- mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ mInflater = LayoutInflater.from(context);
mPackageManager = context.getPackageManager();
mIconSize = context.getResources().getDimensionPixelSize(R.dimen.wallpaperItemIconSize);
final PackageManager pm = mPackageManager;
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
index a3a3c53..142a9cb 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
@@ -38,12 +38,14 @@
import android.util.Log;
import android.view.Display;
import android.view.View;
-import android.view.WindowManager;
import android.widget.Toast;
import com.android.gallery3d.common.BitmapCropTask;
import com.android.gallery3d.common.BitmapUtils;
import com.android.gallery3d.common.Utils;
+import com.android.launcher3.base.BaseActivity;
+import com.android.launcher3.util.Thunk;
+import com.android.launcher3.util.WallpaperUtils;
import com.android.photos.BitmapRegionTileSource;
import com.android.photos.BitmapRegionTileSource.BitmapSource;
import com.android.photos.BitmapRegionTileSource.BitmapSource.InBitmapProvider;
@@ -53,11 +55,11 @@
import java.util.Set;
import java.util.WeakHashMap;
-public class WallpaperCropActivity extends Activity implements Handler.Callback {
+public class WallpaperCropActivity extends BaseActivity implements Handler.Callback {
private static final String LOGTAG = "Launcher3.CropActivity";
- protected static final String WALLPAPER_WIDTH_KEY = "wallpaper.width";
- protected static final String WALLPAPER_HEIGHT_KEY = "wallpaper.height";
+ protected static final String WALLPAPER_WIDTH_KEY = WallpaperUtils.WALLPAPER_WIDTH_KEY;
+ protected static final String WALLPAPER_HEIGHT_KEY = WallpaperUtils.WALLPAPER_HEIGHT_KEY;
/**
* The maximum bitmap size we allow to be returned through the intent.
@@ -67,7 +69,7 @@
* array instead of a Bitmap instance to avoid overhead.
*/
public static final int MAX_BMAP_IN_INTENT = 750000;
- public static final float WALLPAPER_SCREENS_SPAN = 2f;
+ public static final float WALLPAPER_SCREENS_SPAN = WallpaperUtils.WALLPAPER_SCREENS_SPAN;
private static final int MSG_LOAD_IMAGE = 1;
@@ -78,14 +80,14 @@
private HandlerThread mLoaderThread;
private Handler mLoaderHandler;
- private LoadRequest mCurrentLoadRequest;
+ @Thunk LoadRequest mCurrentLoadRequest;
private byte[] mTempStorageForDecoding = new byte[16 * 1024];
// A weak-set of reusable bitmaps
- private Set<Bitmap> mReusableBitmaps =
+ @Thunk Set<Bitmap> mReusableBitmaps =
Collections.newSetFromMap(new WeakHashMap<Bitmap, Boolean>());
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLoaderThread = new HandlerThread("wallpaper_loader");
@@ -129,13 +131,12 @@
// Load image in background
final BitmapRegionTileSource.UriBitmapSource bitmapSource =
- new BitmapRegionTileSource.UriBitmapSource(this, imageUri, 1024);
+ new BitmapRegionTileSource.UriBitmapSource(getContext(), imageUri, 1024);
mSetWallpaperButton.setEnabled(false);
Runnable onLoad = new Runnable() {
public void run() {
if (bitmapSource.getLoadingState() != BitmapSource.State.LOADED) {
- Toast.makeText(WallpaperCropActivity.this,
- getString(R.string.wallpaper_load_fail),
+ Toast.makeText(getContext(), R.string.wallpaper_load_fail,
Toast.LENGTH_LONG).show();
finish();
} else {
@@ -147,7 +148,7 @@
}
@Override
- protected void onDestroy() {
+ public void onDestroy() {
if (mCropView != null) {
mCropView.destroy();
}
@@ -202,7 +203,7 @@
}
}
- req.result = new BitmapRegionTileSource(this, req.src, mTempStorageForDecoding);
+ req.result = new BitmapRegionTileSource(getContext(), req.src, mTempStorageForDecoding);
runOnUiThread(new Runnable() {
@Override
@@ -220,7 +221,7 @@
return false;
}
- private void addReusableBitmap(TileSource src) {
+ @Thunk void addReusableBitmap(TileSource src) {
synchronized (mReusableBitmaps) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
&& src instanceof BitmapRegionTileSource) {
@@ -289,14 +290,10 @@
return getResources().getBoolean(R.bool.allow_rotation);
}
- public static String getSharedPreferencesKey() {
- return LauncherFiles.WALLPAPER_CROP_PREFERENCES_KEY;
- }
-
protected void setWallpaper(Uri uri, final boolean finishActivityWhenDone) {
- int rotation = BitmapUtils.getRotationFromExif(this, uri);
+ int rotation = BitmapUtils.getRotationFromExif(getContext(), uri);
BitmapCropTask cropTask = new BitmapCropTask(
- this, uri, null, rotation, 0, 0, true, false, null);
+ getContext(), uri, null, rotation, 0, 0, true, false, null);
final Point bounds = cropTask.getImageBounds();
Runnable onEndCrop = new Runnable() {
public void run() {
@@ -318,7 +315,7 @@
// this device
int rotation = BitmapUtils.getRotationFromExif(res, resId);
Point inSize = mCropView.getSourceDimensions();
- Point outSize = BitmapUtils.getDefaultWallpaperSize(getResources(),
+ Point outSize = WallpaperUtils.getDefaultWallpaperSize(getResources(),
getWindowManager());
RectF crop = Utils.getMaxCropRect(
inSize.x, inSize.y, outSize.x, outSize.y, false);
@@ -333,7 +330,7 @@
}
}
};
- BitmapCropTask cropTask = new BitmapCropTask(this, res, resId,
+ BitmapCropTask cropTask = new BitmapCropTask(getContext(), res, resId,
crop, rotation, outSize.x, outSize.y, true, false, onEndCrop);
cropTask.execute();
}
@@ -351,7 +348,7 @@
d.getSize(displaySize);
boolean isPortrait = displaySize.x < displaySize.y;
- Point defaultWallpaperSize = BitmapUtils.getDefaultWallpaperSize(getResources(),
+ Point defaultWallpaperSize = WallpaperUtils.getDefaultWallpaperSize(getResources(),
getWindowManager());
// Get the crop
RectF cropRect = mCropView.getCrop();
@@ -425,7 +422,7 @@
}
}
};
- BitmapCropTask cropTask = new BitmapCropTask(this, uri,
+ BitmapCropTask cropTask = new BitmapCropTask(getContext(), uri,
cropRect, cropRotation, outWidth, outHeight, true, false, onEndCrop);
if (onBitmapCroppedHandler != null) {
cropTask.setOnBitmapCropped(onBitmapCroppedHandler);
@@ -434,8 +431,8 @@
}
protected void updateWallpaperDimensions(int width, int height) {
- String spKey = getSharedPreferencesKey();
- SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
+ String spKey = LauncherFiles.WALLPAPER_CROP_PREFERENCES_KEY;
+ SharedPreferences sp = getContext().getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
SharedPreferences.Editor editor = sp.edit();
if (width != 0 && height != 0) {
editor.putInt(WALLPAPER_WIDTH_KEY, width);
@@ -445,34 +442,8 @@
editor.remove(WALLPAPER_HEIGHT_KEY);
}
editor.commit();
-
- suggestWallpaperDimension(getResources(),
- sp, getWindowManager(), WallpaperManager.getInstance(this), true);
- }
-
- public static void suggestWallpaperDimension(Resources res,
- final SharedPreferences sharedPrefs,
- WindowManager windowManager,
- final WallpaperManager wallpaperManager, boolean fallBackToDefaults) {
- final Point defaultWallpaperSize = BitmapUtils.getDefaultWallpaperSize(res, windowManager);
- // If we have saved a wallpaper width/height, use that instead
-
- int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, -1);
- int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, -1);
-
- if (savedWidth == -1 || savedHeight == -1) {
- if (!fallBackToDefaults) {
- return;
- } else {
- savedWidth = defaultWallpaperSize.x;
- savedHeight = defaultWallpaperSize.y;
- }
- }
-
- if (savedWidth != wallpaperManager.getDesiredMinimumWidth() ||
- savedHeight != wallpaperManager.getDesiredMinimumHeight()) {
- wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight);
- }
+ WallpaperUtils.suggestWallpaperDimension(getResources(),
+ sp, getWindowManager(), WallpaperManager.getInstance(getContext()), true);
}
static class LoadRequest {
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
index d16fc31..c49286a 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -21,6 +21,7 @@
import android.app.ActionBar;
import android.app.Activity;
import android.app.WallpaperManager;
+import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
@@ -70,6 +71,8 @@
import com.android.gallery3d.common.BitmapCropTask;
import com.android.gallery3d.common.BitmapUtils;
import com.android.gallery3d.common.Utils;
+import com.android.launcher3.util.Thunk;
+import com.android.launcher3.util.WallpaperUtils;
import com.android.photos.BitmapRegionTileSource;
import com.android.photos.BitmapRegionTileSource.BitmapSource;
import com.android.photos.views.TiledImageRenderer.TileSource;
@@ -88,21 +91,21 @@
private static final String SELECTED_INDEX = "SELECTED_INDEX";
private static final int FLAG_POST_DELAY_MILLIS = 200;
- private View mSelectedTile;
- private boolean mIgnoreNextTap;
- private OnClickListener mThumbnailOnClickListener;
+ @Thunk View mSelectedTile;
+ @Thunk boolean mIgnoreNextTap;
+ @Thunk OnClickListener mThumbnailOnClickListener;
- private LinearLayout mWallpapersView;
- private HorizontalScrollView mWallpaperScrollContainer;
+ @Thunk LinearLayout mWallpapersView;
+ @Thunk HorizontalScrollView mWallpaperScrollContainer;
- private ActionMode.Callback mActionModeCallback;
- private ActionMode mActionMode;
+ @Thunk ActionMode.Callback mActionModeCallback;
+ @Thunk ActionMode mActionMode;
- private View.OnLongClickListener mLongClickListener;
+ @Thunk View.OnLongClickListener mLongClickListener;
ArrayList<Uri> mTempWallpaperTiles = new ArrayList<Uri>();
private SavedWallpaperImages mSavedImages;
- private int mSelectedIndex = -1;
+ @Thunk int mSelectedIndex = -1;
public static abstract class WallpaperTileInfo {
protected View mView;
@@ -135,7 +138,7 @@
public static class UriWallpaperInfo extends WallpaperTileInfo {
private Uri mUri;
private boolean mFirstClick = true;
- private BitmapRegionTileSource.UriBitmapSource mBitmapSource;
+ @Thunk BitmapRegionTileSource.UriBitmapSource mBitmapSource;
public UriWallpaperInfo(Uri uri) {
mUri = uri;
}
@@ -157,8 +160,7 @@
ViewGroup parent = (ViewGroup) mView.getParent();
if (parent != null) {
parent.removeView(mView);
- Toast.makeText(a,
- a.getString(R.string.image_load_fail),
+ Toast.makeText(a.getContext(), R.string.image_load_fail,
Toast.LENGTH_SHORT).show();
}
}
@@ -166,7 +168,7 @@
};
}
mBitmapSource = new BitmapRegionTileSource.UriBitmapSource(
- a, mUri, BitmapRegionTileSource.MAX_PREVIEW_SIZE);
+ a.getContext(), mUri, BitmapRegionTileSource.MAX_PREVIEW_SIZE);
a.setCropViewTileSource(mBitmapSource, true, false, null, onLoad);
}
@Override
@@ -203,7 +205,8 @@
@Override
public void onClick(WallpaperPickerActivity a) {
BitmapRegionTileSource.UriBitmapSource bitmapSource =
- new BitmapRegionTileSource.UriBitmapSource(a, Uri.fromFile(mFile), 1024);
+ new BitmapRegionTileSource.UriBitmapSource(a.getContext(),
+ Uri.fromFile(mFile), 1024);
a.setCropViewTileSource(bitmapSource, false, true, null, null);
}
@Override
@@ -238,7 +241,7 @@
@Override
public float getScale(TileSource src) {
- Point wallpaperSize = BitmapUtils.getDefaultWallpaperSize(
+ Point wallpaperSize = WallpaperUtils.getDefaultWallpaperSize(
a.getResources(), a.getWindowManager());
RectF crop = Utils.getMaxCropRect(
src.getImageWidth(), src.getImageHeight(),
@@ -270,8 +273,8 @@
@Override
public void onClick(WallpaperPickerActivity a) {
CropView c = a.getCropView();
- Drawable defaultWallpaper = WallpaperManager.getInstance(a).getBuiltInDrawable(
- c.getWidth(), c.getHeight(), false, 0.5f, 0.5f);
+ Drawable defaultWallpaper = WallpaperManager.getInstance(a.getContext())
+ .getBuiltInDrawable(c.getWidth(), c.getHeight(), false, 0.5f, 0.5f);
if (defaultWallpaper == null) {
Log.w(TAG, "Null default wallpaper encountered.");
c.setTileSource(null, null);
@@ -288,14 +291,15 @@
return 1f;
}
};
- req.result = new DrawableTileSource(a, defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE);
+ req.result = new DrawableTileSource(a.getContext(),
+ defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE);
a.onLoadRequestComplete(req, true);
}
@Override
public void onSave(WallpaperPickerActivity a) {
try {
- WallpaperManager.getInstance(a).clear();
- a.setResult(RESULT_OK);
+ WallpaperManager.getInstance(a.getContext()).clear();
+ a.setResult(Activity.RESULT_OK);
} catch (IOException e) {
Log.w("Setting wallpaper to default threw exception", e);
}
@@ -337,7 +341,7 @@
}, FLAG_POST_DELAY_MILLIS);
}
- private void changeWallpaperFlags(boolean visible) {
+ @Thunk void changeWallpaperFlags(boolean visible) {
int desiredWallpaperFlag = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
int currentWallpaperFlag = getWindow().getAttributes().flags
& WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
@@ -447,18 +451,18 @@
// Populate the built-in wallpapers
ArrayList<WallpaperTileInfo> wallpapers = findBundledWallpapers();
mWallpapersView = (LinearLayout) findViewById(R.id.wallpaper_list);
- SimpleWallpapersAdapter ia = new SimpleWallpapersAdapter(this, wallpapers);
+ SimpleWallpapersAdapter ia = new SimpleWallpapersAdapter(getContext(), wallpapers);
populateWallpapersFromAdapter(mWallpapersView, ia, false);
// Populate the saved wallpapers
- mSavedImages = new SavedWallpaperImages(this);
+ mSavedImages = new SavedWallpaperImages(getContext());
mSavedImages.loadThumbnailsAndImageIdList();
populateWallpapersFromAdapter(mWallpapersView, mSavedImages, true);
// Populate the live wallpapers
final LinearLayout liveWallpapersView =
(LinearLayout) findViewById(R.id.live_wallpaper_list);
- final LiveWallpaperListAdapter a = new LiveWallpaperListAdapter(this);
+ final LiveWallpaperListAdapter a = new LiveWallpaperListAdapter(getContext());
a.registerDataSetObserver(new DataSetObserver() {
public void onChanged() {
liveWallpapersView.removeAllViews();
@@ -472,7 +476,7 @@
final LinearLayout thirdPartyWallpapersView =
(LinearLayout) findViewById(R.id.third_party_wallpaper_list);
final ThirdPartyWallpaperPickerListAdapter ta =
- new ThirdPartyWallpaperPickerListAdapter(this);
+ new ThirdPartyWallpaperPickerListAdapter(getContext());
populateWallpapersFromAdapter(thirdPartyWallpapersView, ta, false);
// Add a tile for the Gallery
@@ -635,7 +639,7 @@
};
}
- private void selectTile(View v) {
+ @Thunk void selectTile(View v) {
if (mSelectedTile != null) {
mSelectedTile.setSelected(false);
mSelectedTile = null;
@@ -646,10 +650,10 @@
// TODO: Remove this once the accessibility framework and
// services have better support for selection state.
v.announceForAccessibility(
- getString(R.string.announce_selection, v.getContentDescription()));
+ getContext().getString(R.string.announce_selection, v.getContentDescription()));
}
- private void initializeScrollForRtl() {
+ @Thunk void initializeScrollForRtl() {
if (mWallpaperScrollContainer.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
final ViewTreeObserver observer = mWallpaperScrollContainer.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@@ -664,7 +668,7 @@
}
protected Bitmap getThumbnailOfLastPhoto() {
- Cursor cursor = MediaStore.Images.Media.query(getContentResolver(),
+ Cursor cursor = MediaStore.Images.Media.query(getContext().getContentResolver(),
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATE_TAKEN},
@@ -674,7 +678,7 @@
if (cursor != null) {
if (cursor.moveToNext()) {
int id = cursor.getInt(0);
- thumb = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(),
+ thumb = MediaStore.Images.Thumbnails.getThumbnail(getContext().getContentResolver(),
id, MediaStore.Images.Thumbnails.MINI_KIND, null);
}
cursor.close();
@@ -682,7 +686,7 @@
return thumb;
}
- protected void onStop() {
+ public void onStop() {
super.onStop();
mWallpaperScrollContainer = (HorizontalScrollView) findViewById(R.id.wallpaper_scroll_container);
if (mWallpaperScrollContainer.getAlpha() < 1f) {
@@ -691,7 +695,7 @@
}
}
- protected void onSaveInstanceState(Bundle outState) {
+ public void onSaveInstanceState(Bundle outState) {
outState.putParcelableArrayList(TEMP_WALLPAPER_TILES, mTempWallpaperTiles);
outState.putInt(SELECTED_INDEX, mSelectedIndex);
}
@@ -704,7 +708,7 @@
mSelectedIndex = savedInstanceState.getInt(SELECTED_INDEX, -1);
}
- private void populateWallpapersFromAdapter(ViewGroup parent, BaseAdapter adapter,
+ @Thunk void populateWallpapersFromAdapter(ViewGroup parent, BaseAdapter adapter,
boolean addLongPressHandler) {
for (int i = 0; i < adapter.getCount(); i++) {
FrameLayout thumbnail = (FrameLayout) adapter.getView(i, null, parent);
@@ -719,7 +723,7 @@
}
}
- private void updateTileIndices() {
+ @Thunk void updateTileIndices() {
LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list);
final int childCount = masterWallpaperList.getChildCount();
final Resources res = getResources();
@@ -760,13 +764,13 @@
}
}
- private static Point getDefaultThumbnailSize(Resources res) {
+ @Thunk static Point getDefaultThumbnailSize(Resources res) {
return new Point(res.getDimensionPixelSize(R.dimen.wallpaperThumbnailWidth),
res.getDimensionPixelSize(R.dimen.wallpaperThumbnailHeight));
}
- private static Bitmap createThumbnail(Point size, Context context, Uri uri, byte[] imageBytes,
+ @Thunk static Bitmap createThumbnail(Point size, Context context, Uri uri, byte[] imageBytes,
Resources res, int resId, int rotation, boolean leftAligned) {
int width = size.x;
int height = size.y;
@@ -816,7 +820,7 @@
// Load the thumbnail
final ImageView image = (ImageView) pickedImageThumbnail.findViewById(R.id.wallpaper_image);
final Point defaultSize = getDefaultThumbnailSize(this.getResources());
- final Context context = this;
+ final Context context = getContext();
new AsyncTask<Void, Bitmap, Bitmap>() {
protected Bitmap doInBackground(Void...args) {
try {
@@ -860,15 +864,16 @@
}
}
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == IMAGE_PICK && resultCode == RESULT_OK) {
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == IMAGE_PICK && resultCode == Activity.RESULT_OK) {
if (data != null && data.getData() != null) {
Uri uri = data.getData();
addTemporaryWallpaperTile(uri, false);
}
- } else if (requestCode == PICK_WALLPAPER_THIRD_PARTY_ACTIVITY && resultCode == RESULT_OK) {
+ } else if (requestCode == PICK_WALLPAPER_THIRD_PARTY_ACTIVITY
+ && resultCode == Activity.RESULT_OK) {
// Something was set on the third-party activity.
- setResult(RESULT_OK);
+ setResult(Activity.RESULT_OK);
finish();
}
}
@@ -878,7 +883,7 @@
}
private ArrayList<WallpaperTileInfo> findBundledWallpapers() {
- final PackageManager pm = getPackageManager();
+ final PackageManager pm = getContext().getPackageManager();
final ArrayList<WallpaperTileInfo> bundled = new ArrayList<WallpaperTileInfo>(24);
Partner partner = Partner.get(pm);
@@ -922,7 +927,8 @@
Pair<ApplicationInfo, Integer> r = getWallpaperArrayResourceId();
if (r != null) {
try {
- Resources wallpaperRes = getPackageManager().getResourcesForApplication(r.first);
+ Resources wallpaperRes = getContext().getPackageManager()
+ .getResourcesForApplication(r.first);
addWallpapers(bundled, wallpaperRes, r.first.packageName, r.second);
} catch (PackageManager.NameNotFoundException e) {
}
@@ -945,7 +951,7 @@
try {
f.createNewFile();
FileOutputStream thumbFileStream =
- openFileOutput(f.getName(), Context.MODE_PRIVATE);
+ getContext().openFileOutput(f.getName(), Context.MODE_PRIVATE);
b.compress(Bitmap.CompressFormat.JPEG, 95, thumbFileStream);
thumbFileStream.close();
return true;
@@ -957,17 +963,18 @@
}
private File getDefaultThumbFile() {
- return new File(getFilesDir(), Build.VERSION.SDK_INT
+ return new File(getContext().getFilesDir(), Build.VERSION.SDK_INT
+ "_" + LauncherFiles.DEFAULT_WALLPAPER_THUMBNAIL);
}
private boolean saveDefaultWallpaperThumb(Bitmap b) {
// Delete old thumbnails.
- new File(getFilesDir(), LauncherFiles.DEFAULT_WALLPAPER_THUMBNAIL_OLD).delete();
- new File(getFilesDir(), LauncherFiles.DEFAULT_WALLPAPER_THUMBNAIL).delete();
+ new File(getContext().getFilesDir(), LauncherFiles.DEFAULT_WALLPAPER_THUMBNAIL_OLD).delete();
+ new File(getContext().getFilesDir(), LauncherFiles.DEFAULT_WALLPAPER_THUMBNAIL).delete();
for (int i = Build.VERSION_CODES.JELLY_BEAN; i < Build.VERSION.SDK_INT; i++) {
- new File(getFilesDir(), i + "_" + LauncherFiles.DEFAULT_WALLPAPER_THUMBNAIL).delete();
+ new File(getContext().getFilesDir(), i + "_"
+ + LauncherFiles.DEFAULT_WALLPAPER_THUMBNAIL).delete();
}
return writeImageToFileAsJpeg(getDefaultThumbFile(), b);
}
@@ -987,7 +994,7 @@
Point defaultThumbSize = getDefaultThumbnailSize(res);
int rotation = BitmapUtils.getRotationFromExif(res, resId);
thumb = createThumbnail(
- defaultThumbSize, this, null, null, sysRes, resId, rotation, false);
+ defaultThumbSize, getContext(), null, null, sysRes, resId, rotation, false);
if (thumb != null) {
defaultWallpaperExists = saveDefaultWallpaperThumb(thumb);
}
@@ -1009,7 +1016,7 @@
} else {
Resources res = getResources();
Point defaultThumbSize = getDefaultThumbnailSize(res);
- Drawable wallpaperDrawable = WallpaperManager.getInstance(this).getBuiltInDrawable(
+ Drawable wallpaperDrawable = WallpaperManager.getInstance(getContext()).getBuiltInDrawable(
defaultThumbSize.x, defaultThumbSize.y, true, 0.5f, 0.5f);
if (wallpaperDrawable != null) {
thumb = Bitmap.createBitmap(
@@ -1036,7 +1043,7 @@
// package name should be.
final String packageName = getResources().getResourcePackageName(R.array.wallpapers);
try {
- ApplicationInfo info = getPackageManager().getApplicationInfo(packageName, 0);
+ ApplicationInfo info = getContext().getPackageManager().getApplicationInfo(packageName, 0);
return new Pair<ApplicationInfo, Integer>(info, R.array.wallpapers);
} catch (PackageManager.NameNotFoundException e) {
return null;
@@ -1074,9 +1081,9 @@
private static class SimpleWallpapersAdapter extends ArrayAdapter<WallpaperTileInfo> {
private final LayoutInflater mLayoutInflater;
- SimpleWallpapersAdapter(Activity activity, ArrayList<WallpaperTileInfo> wallpapers) {
- super(activity, R.layout.wallpaper_picker_item, wallpapers);
- mLayoutInflater = activity.getLayoutInflater();
+ SimpleWallpapersAdapter(Context context, ArrayList<WallpaperTileInfo> wallpapers) {
+ super(context, R.layout.wallpaper_picker_item, wallpapers);
+ mLayoutInflater = LayoutInflater.from(context);
}
public View getView(int position, View convertView, ViewGroup parent) {
@@ -1108,9 +1115,12 @@
return view;
}
- // In Launcher3, we override this with a method that catches exceptions
- // from starting activities; didn't want to copy and paste code into here
public void startActivityForResultSafely(Intent intent, int requestCode) {
- startActivityForResult(intent, requestCode);
+ Utilities.startActivityForResultSafely(getActivity(), intent, requestCode);
+ }
+
+ @Override
+ public boolean enableRotation() {
+ return Utilities.isRotationEnabled(getContext());
}
}
diff --git a/WallpaperPicker/src/com/android/launcher3/base/BaseActivity.java b/WallpaperPicker/src/com/android/launcher3/base/BaseActivity.java
new file mode 100644
index 0000000..f854118
--- /dev/null
+++ b/WallpaperPicker/src/com/android/launcher3/base/BaseActivity.java
@@ -0,0 +1,21 @@
+package com.android.launcher3.base;
+
+import android.app.Activity;
+import android.content.Context;
+
+/**
+ * A wrapper over {@link Activity} which allows to override some methods.
+ * The base implementation can change from an Activity to a Fragment (or any other custom
+ * implementation), Callers should not assume that the base class extends Context, instead use
+ * either {@link #getContext} or {@link #getActivity}
+ */
+public class BaseActivity extends Activity {
+
+ public Context getContext() {
+ return this;
+ }
+
+ public Activity getActivity() {
+ return this;
+ }
+}
diff --git a/WallpaperPicker/src/com/android/photos/views/TiledImageRenderer.java b/WallpaperPicker/src/com/android/photos/views/TiledImageRenderer.java
index f9b7ab4..39a73b9 100644
--- a/WallpaperPicker/src/com/android/photos/views/TiledImageRenderer.java
+++ b/WallpaperPicker/src/com/android/photos/views/TiledImageRenderer.java
@@ -30,6 +30,7 @@
import com.android.gallery3d.glrenderer.BasicTexture;
import com.android.gallery3d.glrenderer.GLCanvas;
import com.android.gallery3d.glrenderer.UploadedTexture;
+import com.android.launcher3.util.Thunk;
import com.android.photos.views.Pools.Pool;
import com.android.photos.views.Pools.SynchronizedPool;
@@ -67,12 +68,12 @@
private static final int STATE_RECYCLING = 0x20;
private static final int STATE_RECYCLED = 0x40;
- private static Pool<Bitmap> sTilePool = new SynchronizedPool<Bitmap>(64);
+ @Thunk static Pool<Bitmap> sTilePool = new SynchronizedPool<Bitmap>(64);
// TILE_SIZE must be 2^N
- private int mTileSize;
+ @Thunk int mTileSize;
- private TileSource mModel;
+ @Thunk TileSource mModel;
private BasicTexture mPreview;
protected int mLevelCount; // cache the value of mScaledBitmaps.length
@@ -82,7 +83,7 @@
// half size of the previous one). If the value is in [0, mLevelCount), we
// use the bitmap in mScaledBitmaps[mLevel] for display, otherwise the value
// is mLevelCount
- private int mLevel = 0;
+ @Thunk int mLevel = 0;
private int mOffsetX;
private int mOffsetY;
@@ -96,10 +97,10 @@
private final LongSparseArray<Tile> mActiveTiles = new LongSparseArray<Tile>();
// The following three queue are guarded by mQueueLock
- private final Object mQueueLock = new Object();
+ @Thunk final Object mQueueLock = new Object();
private final TileQueue mRecycledQueue = new TileQueue();
private final TileQueue mUploadQueue = new TileQueue();
- private final TileQueue mDecodeQueue = new TileQueue();
+ @Thunk final TileQueue mDecodeQueue = new TileQueue();
// The width and height of the full-sized bitmap
protected int mImageWidth = SIZE_UNKNOWN;
@@ -489,7 +490,7 @@
}
}
- private void decodeTile(Tile tile) {
+ @Thunk void decodeTile(Tile tile) {
synchronized (mQueueLock) {
if (tile.mTileState != STATE_IN_QUEUE) {
return;
@@ -556,7 +557,7 @@
mActiveTiles.put(key, tile);
}
- private Tile getTile(int x, int y, int level) {
+ @Thunk Tile getTile(int x, int y, int level) {
return mActiveTiles.get(makeTileKey(x, y, level));
}
@@ -748,7 +749,7 @@
}
}
- private static class TileQueue {
+ @Thunk static class TileQueue {
private Tile mHead;
public Tile pop() {
@@ -786,7 +787,7 @@
}
}
- private class TileDecoder extends Thread {
+ @Thunk class TileDecoder extends Thread {
public void finishAndWait() {
interrupt();
diff --git a/WallpaperPicker/src/com/android/photos/views/TiledImageView.java b/WallpaperPicker/src/com/android/photos/views/TiledImageView.java
index 56ee7a6..7e3e1a9 100644
--- a/WallpaperPicker/src/com/android/photos/views/TiledImageView.java
+++ b/WallpaperPicker/src/com/android/photos/views/TiledImageView.java
@@ -33,6 +33,7 @@
import com.android.gallery3d.glrenderer.BasicTexture;
import com.android.gallery3d.glrenderer.GLES20Canvas;
+import com.android.launcher3.util.Thunk;
import com.android.photos.views.TiledImageRenderer.TileSource;
import javax.microedition.khronos.egl.EGLConfig;
@@ -43,8 +44,8 @@
*/
public class TiledImageView extends FrameLayout {
- private GLSurfaceView mGLSurfaceView;
- private boolean mInvalPending = false;
+ @Thunk GLSurfaceView mGLSurfaceView;
+ @Thunk boolean mInvalPending = false;
private FrameCallback mFrameCallback;
protected static class ImageRendererWrapper {
@@ -203,7 +204,7 @@
}
}
- private class TileRenderer implements Renderer {
+ @Thunk class TileRenderer implements Renderer {
private GLES20Canvas mCanvas;
diff --git a/res/anim/fade_in_fast.xml b/res/anim/fade_in_fast.xml
deleted file mode 100644
index 4fa9847..0000000
--- a/res/anim/fade_in_fast.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<alpha xmlns:android="http://schemas.android.com/apk/res/android"
- android:interpolator="@android:anim/accelerate_interpolator"
-
- android:fromAlpha="0.0"
- android:toAlpha="1.0"
-
- android:duration="@android:integer/config_mediumAnimTime" />
diff --git a/res/anim/fade_out_fast.xml b/res/anim/fade_out_fast.xml
deleted file mode 100644
index a061a6c..0000000
--- a/res/anim/fade_out_fast.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<alpha xmlns:android="http://schemas.android.com/apk/res/android"
- android:interpolator="@android:anim/accelerate_interpolator"
-
- android:fromAlpha="1.0"
- android:toAlpha="0.0"
-
- android:duration="@android:integer/config_mediumAnimTime" />
diff --git a/res/drawable-hdpi/ic_pageindicator_add.png b/res/drawable-hdpi/ic_pageindicator_add.png
index ab0e5db..971361d 100644
--- a/res/drawable-hdpi/ic_pageindicator_add.png
+++ b/res/drawable-hdpi/ic_pageindicator_add.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_pageindicator_current.png b/res/drawable-hdpi/ic_pageindicator_current.png
index 283f44d..09405d8 100644
--- a/res/drawable-hdpi/ic_pageindicator_current.png
+++ b/res/drawable-hdpi/ic_pageindicator_current.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_pageindicator_current_folder.png b/res/drawable-hdpi/ic_pageindicator_current_folder.png
new file mode 100644
index 0000000..c3a6f69
--- /dev/null
+++ b/res/drawable-hdpi/ic_pageindicator_current_folder.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_pageindicator_default.png b/res/drawable-hdpi/ic_pageindicator_default.png
index 47b9989..251de44 100644
--- a/res/drawable-hdpi/ic_pageindicator_default.png
+++ b/res/drawable-hdpi/ic_pageindicator_default.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_pageindicator_default_folder.png b/res/drawable-hdpi/ic_pageindicator_default_folder.png
new file mode 100644
index 0000000..48a3218
--- /dev/null
+++ b/res/drawable-hdpi/ic_pageindicator_default_folder.png
Binary files differ
diff --git a/res/drawable-ldrtl/apps_list_fastscroll_bg.xml b/res/drawable-ldrtl/apps_list_fastscroll_bg.xml
new file mode 100644
index 0000000..772975a
--- /dev/null
+++ b/res/drawable-ldrtl/apps_list_fastscroll_bg.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2015 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.
+-->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <solid android:color="@color/apps_view_scrollbar_thumb_color" />
+ <size
+ android:width="64dp"
+ android:height="64dp" />
+ <corners
+ android:topLeftRadius="64dp"
+ android:topRightRadius="64dp"
+ android:bottomRightRadius="64dp" />
+</shape>
\ No newline at end of file
diff --git a/res/drawable-mdpi/ic_pageindicator_add.png b/res/drawable-mdpi/ic_pageindicator_add.png
index 11659a3..50e1ba5 100644
--- a/res/drawable-mdpi/ic_pageindicator_add.png
+++ b/res/drawable-mdpi/ic_pageindicator_add.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_pageindicator_current.png b/res/drawable-mdpi/ic_pageindicator_current.png
index b41e1bb..19a8972 100644
--- a/res/drawable-mdpi/ic_pageindicator_current.png
+++ b/res/drawable-mdpi/ic_pageindicator_current.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_pageindicator_current_folder.png b/res/drawable-mdpi/ic_pageindicator_current_folder.png
new file mode 100644
index 0000000..8d6c0b1
--- /dev/null
+++ b/res/drawable-mdpi/ic_pageindicator_current_folder.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_pageindicator_default.png b/res/drawable-mdpi/ic_pageindicator_default.png
index e36c25c..6b0a9c9 100644
--- a/res/drawable-mdpi/ic_pageindicator_default.png
+++ b/res/drawable-mdpi/ic_pageindicator_default.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_pageindicator_default_folder.png b/res/drawable-mdpi/ic_pageindicator_default_folder.png
new file mode 100644
index 0000000..c9edf8d
--- /dev/null
+++ b/res/drawable-mdpi/ic_pageindicator_default_folder.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_pageindicator_add.png b/res/drawable-xhdpi/ic_pageindicator_add.png
index af1da2d..9fb5359 100644
--- a/res/drawable-xhdpi/ic_pageindicator_add.png
+++ b/res/drawable-xhdpi/ic_pageindicator_add.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_pageindicator_current.png b/res/drawable-xhdpi/ic_pageindicator_current.png
index 8fa774d..c44b88f 100644
--- a/res/drawable-xhdpi/ic_pageindicator_current.png
+++ b/res/drawable-xhdpi/ic_pageindicator_current.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_pageindicator_current_folder.png b/res/drawable-xhdpi/ic_pageindicator_current_folder.png
new file mode 100644
index 0000000..fa2168f
--- /dev/null
+++ b/res/drawable-xhdpi/ic_pageindicator_current_folder.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_pageindicator_default.png b/res/drawable-xhdpi/ic_pageindicator_default.png
index 8eb5eb0..6d1b5be 100644
--- a/res/drawable-xhdpi/ic_pageindicator_default.png
+++ b/res/drawable-xhdpi/ic_pageindicator_default.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_pageindicator_default_folder.png b/res/drawable-xhdpi/ic_pageindicator_default_folder.png
new file mode 100644
index 0000000..ff0ed39
--- /dev/null
+++ b/res/drawable-xhdpi/ic_pageindicator_default_folder.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_pageindicator_add.png b/res/drawable-xxhdpi/ic_pageindicator_add.png
index c288952..f3f6fbe 100644
--- a/res/drawable-xxhdpi/ic_pageindicator_add.png
+++ b/res/drawable-xxhdpi/ic_pageindicator_add.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_pageindicator_current.png b/res/drawable-xxhdpi/ic_pageindicator_current.png
index 22b290e..3a3a3ae 100644
--- a/res/drawable-xxhdpi/ic_pageindicator_current.png
+++ b/res/drawable-xxhdpi/ic_pageindicator_current.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_pageindicator_current_folder.png b/res/drawable-xxhdpi/ic_pageindicator_current_folder.png
new file mode 100644
index 0000000..4ff8ec6
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_pageindicator_current_folder.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_pageindicator_default.png b/res/drawable-xxhdpi/ic_pageindicator_default.png
index e608cae..b057c63 100644
--- a/res/drawable-xxhdpi/ic_pageindicator_default.png
+++ b/res/drawable-xxhdpi/ic_pageindicator_default.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_pageindicator_default_folder.png b/res/drawable-xxhdpi/ic_pageindicator_default_folder.png
new file mode 100644
index 0000000..756ad09
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_pageindicator_default_folder.png
Binary files differ
diff --git a/res/anim/no_anim.xml b/res/drawable/apps_list_bg.xml
similarity index 67%
copy from res/anim/no_anim.xml
copy to res/drawable/apps_list_bg.xml
index 02b1625..64177c1 100644
--- a/res/anim/no_anim.xml
+++ b/res/drawable/apps_list_bg.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<!--
+ Copyright (C) 2015 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.
@@ -13,6 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
-<alpha xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="417" />
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+ android:drawable="@drawable/apps_list_bg_inset"
+ android:insetLeft="@dimen/apps_container_inset"
+ android:insetRight="@dimen/apps_container_inset" />
\ No newline at end of file
diff --git a/res/anim/no_anim.xml b/res/drawable/apps_list_bg_inset.xml
similarity index 66%
copy from res/anim/no_anim.xml
copy to res/drawable/apps_list_bg_inset.xml
index 02b1625..5ea7895 100644
--- a/res/anim/no_anim.xml
+++ b/res/drawable/apps_list_bg_inset.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<!--
+ Copyright (C) 2015 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.
@@ -13,6 +14,10 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
-<alpha xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="417" />
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <solid android:color="#ffffff" />
+ <corners
+ android:bottomLeftRadius="3dp"
+ android:bottomRightRadius="3dp" />
+</shape>
\ No newline at end of file
diff --git a/res/drawable/apps_list_fastscroll_bg.xml b/res/drawable/apps_list_fastscroll_bg.xml
new file mode 100644
index 0000000..780d3b0
--- /dev/null
+++ b/res/drawable/apps_list_fastscroll_bg.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2015 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.
+-->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <solid android:color="@color/apps_view_scrollbar_thumb_color" />
+ <size
+ android:width="64dp"
+ android:height="64dp" />
+ <corners
+ android:topLeftRadius="64dp"
+ android:topRightRadius="64dp"
+ android:bottomLeftRadius="64dp" />
+</shape>
\ No newline at end of file
diff --git a/res/anim/no_anim.xml b/res/drawable/apps_list_scrollbar_thumb.xml
similarity index 66%
copy from res/anim/no_anim.xml
copy to res/drawable/apps_list_scrollbar_thumb.xml
index 02b1625..318d406 100644
--- a/res/anim/no_anim.xml
+++ b/res/drawable/apps_list_scrollbar_thumb.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<!--
+ Copyright (C) 2015 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.
@@ -13,6 +14,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
-<alpha xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="417" />
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <solid android:color="@color/apps_view_scrollbar_thumb_color" />
+ <size android:width="@dimen/apps_view_fast_scroll_bar_width" />
+</shape>
\ No newline at end of file
diff --git a/res/anim/no_anim.xml b/res/drawable/apps_list_search_bg.xml
similarity index 67%
copy from res/anim/no_anim.xml
copy to res/drawable/apps_list_search_bg.xml
index 02b1625..eda33a9 100644
--- a/res/anim/no_anim.xml
+++ b/res/drawable/apps_list_search_bg.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<!--
+ Copyright (C) 2015 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.
@@ -13,6 +14,10 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
-<alpha xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="417" />
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <solid android:color="#ffffff" />
+ <corners
+ android:topLeftRadius="3dp"
+ android:topRightRadius="3dp" />
+</shape>
\ No newline at end of file
diff --git a/res/anim/no_anim.xml b/res/drawable/apps_reveal_bg.xml
similarity index 67%
copy from res/anim/no_anim.xml
copy to res/drawable/apps_reveal_bg.xml
index 02b1625..47c608f 100644
--- a/res/anim/no_anim.xml
+++ b/res/drawable/apps_reveal_bg.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<!--
+ Copyright (C) 2015 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.
@@ -13,6 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
-<alpha xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="417" />
+<inset xmlns:android="http://schemas.android.com/apk/res/android"
+ android:drawable="@drawable/apps_reveal_bg_inset"
+ android:insetLeft="@dimen/apps_container_inset"
+ android:insetRight="@dimen/apps_container_inset" />
\ No newline at end of file
diff --git a/res/anim/no_anim.xml b/res/drawable/apps_reveal_bg_inset.xml
similarity index 71%
rename from res/anim/no_anim.xml
rename to res/drawable/apps_reveal_bg_inset.xml
index 02b1625..61f1c08 100644
--- a/res/anim/no_anim.xml
+++ b/res/drawable/apps_reveal_bg_inset.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<!--
+ Copyright (C) 2015 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.
@@ -13,6 +14,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
-<alpha xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="417" />
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <solid android:color="#ffffff" />
+ <corners android:radius="3dp" />
+</shape>
\ No newline at end of file
diff --git a/res/layout-land/launcher.xml b/res/layout-land/launcher.xml
index 6f95bd5..b13984a 100644
--- a/res/layout-land/launcher.xml
+++ b/res/layout-land/launcher.xml
@@ -62,6 +62,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
+
+ <include layout="@layout/apps_view"
+ android:id="@+id/apps_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="invisible" />
</com.android.launcher3.DragLayer>
<ViewStub
diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml
index af30a32..3cb338e 100644
--- a/res/layout-port/launcher.xml
+++ b/res/layout-port/launcher.xml
@@ -71,6 +71,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
+
+ <include layout="@layout/apps_view"
+ android:id="@+id/apps_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="invisible" />
</com.android.launcher3.DragLayer>
<ViewStub
diff --git a/res/layout-sw600dp/apps_view.xml b/res/layout-sw600dp/apps_view.xml
new file mode 100644
index 0000000..6f22460
--- /dev/null
+++ b/res/layout-sw600dp/apps_view.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+<com.android.launcher3.AppsContainerView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/apps_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#22000000"
+ android:descendantFocusability="afterDescendants">
+ <include
+ layout="@layout/apps_reveal_view"
+ android:layout_width="@dimen/apps_container_width"
+ android:layout_height="540dp"
+ android:layout_gravity="center" />
+ <include
+ layout="@layout/apps_list_view"
+ android:layout_width="@dimen/apps_container_width"
+ android:layout_height="540dp"
+ android:layout_gravity="center" />
+</com.android.launcher3.AppsContainerView>
\ No newline at end of file
diff --git a/res/layout-sw720dp/launcher.xml b/res/layout-sw720dp/launcher.xml
index 960ccf3..a3d502c 100644
--- a/res/layout-sw720dp/launcher.xml
+++ b/res/layout-sw720dp/launcher.xml
@@ -71,6 +71,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
+
+ <include layout="@layout/apps_view"
+ android:id="@+id/apps_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="invisible" />
</com.android.launcher3.DragLayer>
<ViewStub
diff --git a/res/layout/apps_empty_view.xml b/res/layout/apps_empty_view.xml
new file mode 100644
index 0000000..8408077
--- /dev/null
+++ b/res/layout/apps_empty_view.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+<TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/empty_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:paddingTop="24dp"
+ android:paddingBottom="24dp"
+ android:paddingRight="@dimen/apps_grid_view_start_margin"
+ android:textSize="16sp"
+ android:textColor="#4c4c4c"
+ android:focusable="false" />
+
diff --git a/res/layout/apps_grid_row_icon_view.xml b/res/layout/apps_grid_row_icon_view.xml
new file mode 100644
index 0000000..81e74b9
--- /dev/null
+++ b/res/layout/apps_grid_row_icon_view.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+<com.android.launcher3.BubbleTextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:launcher="http://schemas.android.com/apk/res-auto"
+ style="@style/WorkspaceIcon.AppsCustomize"
+ android:id="@+id/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="left|center_vertical"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"
+ android:focusable="true"
+ android:background="@drawable/focusable_view_bg"
+ launcher:deferShadowGeneration="true" />
+
diff --git a/res/layout/apps_list_row_icon_view.xml b/res/layout/apps_list_row_icon_view.xml
new file mode 100644
index 0000000..867dbdc
--- /dev/null
+++ b/res/layout/apps_list_row_icon_view.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+
+<com.android.launcher3.BubbleTextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:launcher="http://schemas.android.com/apk/res-auto"
+ style="@style/WorkspaceIcon.AppsCustomize"
+ android:id="@+id/application_icon"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:focusable="true"
+ android:background="@drawable/focusable_view_bg"
+ launcher:iconPaddingOverride="24dp"
+ launcher:textSizeOverride="16dp"
+ launcher:layoutHorizontal="true"
+ launcher:deferShadowGeneration="true" />
diff --git a/res/layout/apps_list_row_view.xml b/res/layout/apps_list_row_view.xml
new file mode 100644
index 0000000..83c175b
--- /dev/null
+++ b/res/layout/apps_list_row_view.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/apps_view_row_height"
+ android:orientation="horizontal"
+ android:focusable="true"
+ android:background="@drawable/focusable_view_bg"
+ android:descendantFocusability="afterDescendants">
+ <TextView
+ android:id="@+id/section"
+ android:layout_width="64dp"
+ android:layout_height="match_parent"
+ android:paddingLeft="16dp"
+ android:gravity="start|center_vertical"
+ android:textColor="@color/apps_view_section_text_color"
+ android:textSize="@dimen/apps_view_section_text_size"
+ android:focusable="false" />
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/apps_list_view.xml b/res/layout/apps_list_view.xml
new file mode 100644
index 0000000..3e42f84
--- /dev/null
+++ b/res/layout/apps_list_view.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/apps_list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:elevation="15dp"
+ android:visibility="gone">
+ <EditText
+ android:id="@+id/app_search_box"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/apps_container_inset"
+ android:layout_marginRight="@dimen/apps_container_inset"
+ android:padding="16dp"
+ android:hint="@string/apps_view_search_bar_hint"
+ android:maxLines="1"
+ android:singleLine="true"
+ android:scrollHorizontally="true"
+ android:gravity="fill_horizontal"
+ android:textSize="16sp"
+ android:textColor="#4c4c4c"
+ android:textColorHint="#9c9c9c"
+ android:imeOptions="actionDone|flagNoExtractUi"
+ android:background="@drawable/apps_list_search_bg"
+ android:elevation="4dp" />
+ <com.android.launcher3.AppsContainerRecyclerView
+ android:id="@+id/apps_list_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_gravity="center"
+ android:paddingTop="12dp"
+ android:paddingBottom="12dp"
+ android:clipToPadding="false"
+ android:focusable="true"
+ android:descendantFocusability="afterDescendants"
+ android:background="@drawable/apps_list_bg" />
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/apps_reveal_view.xml b/res/layout/apps_reveal_view.xml
new file mode 100644
index 0000000..bc93359
--- /dev/null
+++ b/res/layout/apps_reveal_view.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/apps_view_transition_overlay"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_gravity="center"
+ android:elevation="15dp"
+ android:visibility="invisible"
+ android:background="@drawable/apps_reveal_bg"
+ android:focusable="false" />
\ No newline at end of file
diff --git a/res/layout/apps_view.xml b/res/layout/apps_view.xml
new file mode 100644
index 0000000..86d67e1
--- /dev/null
+++ b/res/layout/apps_view.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+<!-- The top and bottom paddings are defined in this container, but since we want
+ the list view to span the full width (for touch interception purposes), we
+ will bake the left/right padding into that view's background itself. -->
+<com.android.launcher3.AppsContainerView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/apps_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingTop="@dimen/apps_container_inset"
+ android:paddingBottom="@dimen/apps_container_inset"
+ android:background="@drawable/apps_customize_bg"
+ android:descendantFocusability="afterDescendants">
+ <include
+ layout="@layout/apps_reveal_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_gravity="center" />
+ <include
+ layout="@layout/apps_list_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_gravity="center" />
+</com.android.launcher3.AppsContainerView>
\ No newline at end of file
diff --git a/res/layout/user_folder.xml b/res/layout/user_folder.xml
index 74cdf11..7a4d5e8 100644
--- a/res/layout/user_folder.xml
+++ b/res/layout/user_folder.xml
@@ -46,7 +46,6 @@
android:id="@+id/folder_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
android:background="#00000000"
android:fontFamily="sans-serif-condensed"
android:gravity="center_horizontal"
diff --git a/res/layout/user_folder_scroll.xml b/res/layout/user_folder_scroll.xml
new file mode 100644
index 0000000..12e5097
--- /dev/null
+++ b/res/layout/user_folder_scroll.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2015 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.
+-->
+
+<com.android.launcher3.Folder xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:launcher="http://schemas.android.com/apk/res-auto"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/quantum_panel"
+ android:orientation="vertical" >
+
+ <FrameLayout
+ android:id="@+id/folder_content_wrapper"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <!-- Actual size of the indicator doesn't matter as it is scaled to match the view size -->
+
+ <com.android.launcher3.FocusIndicatorView
+ android:id="@+id/focus_indicator"
+ android:layout_width="20dp"
+ android:layout_height="20dp" />
+
+ <com.android.launcher3.FolderPagedView
+ android:id="@+id/folder_content"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ launcher:pageIndicator="@+id/folder_page_indicator" />
+ </FrameLayout>
+
+ <LinearLayout
+ android:id="@+id/folder_footer"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:paddingStart="12dp"
+ android:paddingEnd="8dp" >
+
+ <com.android.launcher3.FolderEditText
+ android:id="@+id/folder_name"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_weight="1"
+ android:background="#00000000"
+ android:fontFamily="sans-serif-condensed"
+ android:gravity="start"
+ android:hint="@string/folder_hint_text"
+ android:imeOptions="flagNoExtractUi"
+ android:paddingBottom="@dimen/folder_name_padding"
+ android:paddingTop="@dimen/folder_name_padding"
+ android:singleLine="true"
+ android:textColor="#ff777777"
+ android:textColorHighlight="#ffCCCCCC"
+ android:textColorHint="#ff808080"
+ android:textCursorDrawable="@null"
+ android:textSize="14sp" />
+
+ <include
+ android:id="@+id/folder_page_indicator"
+ android:layout_width="wrap_content"
+ android:layout_height="12dp"
+ android:layout_gravity="top"
+ android:layout_marginTop="5dp"
+ layout="@layout/page_indicator" />
+
+ <LinearLayout
+ android:id="@+id/folder_sort"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="center_vertical"
+ android:gravity="end|center_vertical" >
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginEnd="8dp"
+ android:text="@string/sort_alphabetical"
+ android:textColor="#ff777777"
+ android:textSize="14sp" />
+
+ <Switch
+ android:id="@+id/folder_sort_switch"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:clickable="false"
+ android:duplicateParentState="true"
+ android:focusable="false" />
+ </LinearLayout>
+ </LinearLayout>
+
+</com.android.launcher3.Folder>
\ No newline at end of file
diff --git a/res/values-be/strings.xml b/res/values-be/strings.xml
index 2015158..2d3c633 100644
--- a/res/values-be/strings.xml
+++ b/res/values-be/strings.xml
@@ -199,10 +199,6 @@
<skip />
<!-- no translation found for folder_name_format (6629239338071103179) -->
<skip />
- <string name="custom_workspace_cling_title_1" msgid="3750880082935033085"></string>
- <string name="custom_workspace_cling_description_1" msgid="939966842147696724"></string>
- <string name="custom_workspace_cling_title_2" msgid="662588444436552198"></string>
- <string name="custom_workspace_cling_description_2" msgid="8097921091798539310"></string>
<!-- no translation found for widget_button_text (2880537293434387943) -->
<skip />
<!-- no translation found for wallpaper_button_text (8404103075899945851) -->
diff --git a/res/values-et/strings.xml b/res/values-et/strings.xml
index 3b0deb8..a4955ce 100644
--- a/res/values-et/strings.xml
+++ b/res/values-et/strings.xml
@@ -23,13 +23,11 @@
<string name="home" msgid="5921706419368316758">"Kodu"</string>
<string name="uid_name" msgid="3371120195364560632">"Androidi tuumrakendused"</string>
<string name="folder_name" msgid="8551881338202938211"></string>
- <string name="chooser_wallpaper" msgid="6063168087625352235">"Taustapildi valimiskoht:"</string>
<string name="wallpaper_instructions" msgid="4215640646180727542">"Määra taustapilt"</string>
<string name="pick_wallpaper" msgid="5630222540525626723">"Taustapildid"</string>
<string name="activity_not_found" msgid="217823393239365967">"Rakendus pole installitud."</string>
<string name="widgets_tab_label" msgid="9145860100000983599">"Vidinad"</string>
<string name="long_press_widget_to_add" msgid="7395697462851217506">"Vidina valimiseks puudutage seda pikalt."</string>
- <string name="market" msgid="2652226429823445833">"Pood"</string>
<string name="widget_dims_format" msgid="1386418557719032947">"%1$d × %2$d"</string>
<string name="external_drop_widget_error" msgid="2285187188524172774">"Üksust ei saa sellele avaekraanile tuua."</string>
<string name="external_drop_widget_pick_title" msgid="7040647073452295370">"Valige loomiseks vidin"</string>
@@ -52,23 +50,13 @@
<string name="title_select_application" msgid="1793455815754848652">"Rakenduse valimine"</string>
<string name="all_apps_button_label" msgid="2578400570124163469">"Rakendused"</string>
<string name="all_apps_home_button_label" msgid="1022222300329398558">"Kodu"</string>
- <string name="delete_zone_label_workspace" msgid="7153615831493049150">"Eemalda"</string>
<string name="delete_zone_label_all_apps" msgid="6664588234817475108">"Desinstalli"</string>
<string name="delete_target_label" msgid="665300185123139530">"Eemalda"</string>
<string name="delete_target_uninstall_label" msgid="748894921183769150">"Desinstalli"</string>
<string name="info_target_label" msgid="4019495079517426980">"Rakenduse teave"</string>
- <string name="accessibility_search_button" msgid="816822994629942611">"Otsing"</string>
- <string name="accessibility_voice_search_button" msgid="3938249215065842475">"Häälotsing"</string>
<string name="accessibility_all_apps_button" msgid="8803738611398979849">"Rakendused"</string>
<string name="accessibility_delete_button" msgid="3628162007991023603">"Eemalda"</string>
<string name="delete_zone_label_all_apps_system_app" msgid="3683920959591819044">"Desinstalli värskendus"</string>
- <string name="menu_add" msgid="3065046628354640854">"Lisa"</string>
- <string name="menu_manage_apps" msgid="2308685199463588895">"Rakenduste haldamine"</string>
- <string name="menu_wallpaper" msgid="5837429080911269832">"Taustapilt"</string>
- <string name="menu_search" msgid="4826514464423239041">"Otsing"</string>
- <string name="menu_notifications" msgid="6424587053194766192">"Teadistused"</string>
- <string name="menu_settings" msgid="3946232973327980394">"Süsteemiseaded"</string>
- <string name="menu_help" msgid="4901160661634590633">"Abi"</string>
<string name="cab_menu_delete_app" msgid="4089398025537640349">"Rakenduse desinstallimine"</string>
<string name="cab_menu_app_info" msgid="914548323652698884">"Rakenduse üksikasjad"</string>
<string name="cab_app_selection_text" msgid="6378522164293415735">"Valitud on 1 rakendus"</string>
@@ -94,11 +82,7 @@
<string name="apps_customize_widgets_scroll_format" msgid="5383009742241717437">"Vidinate leht %1$d/%2$d"</string>
<string name="workspace_cling_title" msgid="738396473989890567">"Tunne end nagu kodus"</string>
<string name="workspace_cling_move_item" msgid="791013895761065070">"Võite panna oma lemmikrakendused siia."</string>
- <string name="workspace_cling_open_all_apps" msgid="2459977609848572588">"Kõikide oma rakenduste nägemiseks puudutage ringi."</string>
- <string name="all_apps_cling_title" msgid="2559734712581447107">"Valige mõned rakendused"</string>
- <string name="all_apps_cling_add_item" msgid="5665035103260318891">"Rakenduse lisamiseks avakuvale puudutage seda pikalt."</string>
<string name="folder_cling_title" msgid="4308949882377840953">"Korraldage oma rakendused kaustadesse"</string>
- <string name="folder_cling_move_item" msgid="270598675060435169">"Rakenduse liigutamiseks pange sõrm rakendusele ja hoidke seda."</string>
<string name="folder_cling_create_folder" msgid="8352867485656129478">"Avakuval uue kausta tegemiseks virnastage üks rakendus teisele."</string>
<string name="cling_dismiss" msgid="2780907108735868381">"OK"</string>
<string name="folder_opened" msgid="1262064100943801533">"Kaust on avatud, <xliff:g id="WIDTH">%1$d</xliff:g> x <xliff:g id="HEIGHT">%2$d</xliff:g>"</string>
@@ -107,8 +91,4 @@
<string name="folder_closed" msgid="3130534551370511932">"Kaust suletud"</string>
<string name="folder_renamed" msgid="7951233572858053642">"Kausta uus nimi: <xliff:g id="NAME">%1$s</xliff:g>"</string>
<string name="folder_name_format" msgid="3051680259794759037">"<xliff:g id="NAME">%1$s</xliff:g>"</string>
- <string name="custom_workspace_cling_title_1" msgid="1433009175359948587"></string>
- <string name="custom_workspace_cling_description_1" msgid="6875529190849858047"></string>
- <string name="custom_workspace_cling_title_2" msgid="5516006164661020362"></string>
- <string name="custom_workspace_cling_description_2" msgid="2758258454975288377"></string>
</resources>
diff --git a/res/values-ms/strings.xml b/res/values-ms/strings.xml
index f50a5db..248ca15 100644
--- a/res/values-ms/strings.xml
+++ b/res/values-ms/strings.xml
@@ -23,13 +23,11 @@
<string name="home" msgid="5921706419368316758">"Laman Utama"</string>
<string name="uid_name" msgid="3371120195364560632">"Apl Teras Android"</string>
<string name="folder_name" msgid="8551881338202938211"></string>
- <string name="chooser_wallpaper" msgid="6063168087625352235">"Pilih kertas dinding dari"</string>
<string name="wallpaper_instructions" msgid="4215640646180727542">"Tetapkan kertas dinding"</string>
<string name="pick_wallpaper" msgid="5630222540525626723">"Kertas dinding"</string>
<string name="activity_not_found" msgid="217823393239365967">"Aplikasi tidak dipasang."</string>
<string name="widgets_tab_label" msgid="9145860100000983599">"Widget"</string>
<string name="long_press_widget_to_add" msgid="7395697462851217506">"Sentuh & tahan untuk mengambil widget."</string>
- <string name="market" msgid="2652226429823445833">"Kedai"</string>
<string name="widget_dims_format" msgid="1386418557719032947">"%1$d × %2$d"</string>
<string name="external_drop_widget_error" msgid="2285187188524172774">"Tidak dapat melepaskan item pada skrin Utama ini."</string>
<string name="external_drop_widget_pick_title" msgid="7040647073452295370">"Pilih widget untuk dibuat"</string>
@@ -52,23 +50,13 @@
<string name="title_select_application" msgid="1793455815754848652">"Pilih aplikasi"</string>
<string name="all_apps_button_label" msgid="2578400570124163469">"Apl"</string>
<string name="all_apps_home_button_label" msgid="1022222300329398558">"Laman Utama"</string>
- <string name="delete_zone_label_workspace" msgid="7153615831493049150">"Alih keluar"</string>
<string name="delete_zone_label_all_apps" msgid="6664588234817475108">"Nyahpasang"</string>
<string name="delete_target_label" msgid="665300185123139530">"Alih keluar"</string>
<string name="delete_target_uninstall_label" msgid="748894921183769150">"Nyahpasang"</string>
<string name="info_target_label" msgid="4019495079517426980">"Maklumat apl"</string>
- <string name="accessibility_search_button" msgid="816822994629942611">"Carian"</string>
- <string name="accessibility_voice_search_button" msgid="3938249215065842475">"Carian Suara"</string>
<string name="accessibility_all_apps_button" msgid="8803738611398979849">"Aplikasi"</string>
<string name="accessibility_delete_button" msgid="3628162007991023603">"Alih keluar"</string>
<string name="delete_zone_label_all_apps_system_app" msgid="3683920959591819044">"Nyahpasang kemas kini"</string>
- <string name="menu_add" msgid="3065046628354640854">"Tambah"</string>
- <string name="menu_manage_apps" msgid="2308685199463588895">"Mengurus apl"</string>
- <string name="menu_wallpaper" msgid="5837429080911269832">"Kertas dinding"</string>
- <string name="menu_search" msgid="4826514464423239041">"Cari"</string>
- <string name="menu_notifications" msgid="6424587053194766192">"Pemberitahuan"</string>
- <string name="menu_settings" msgid="3946232973327980394">"Tetapan sistem"</string>
- <string name="menu_help" msgid="4901160661634590633">"Bantuan"</string>
<string name="cab_menu_delete_app" msgid="4089398025537640349">"Nyahpasang aplikasi"</string>
<string name="cab_menu_app_info" msgid="914548323652698884">"Butiran aplikasi"</string>
<string name="cab_app_selection_text" msgid="6378522164293415735">"1 aplikasi dipilih"</string>
@@ -94,11 +82,7 @@
<string name="apps_customize_widgets_scroll_format" msgid="5383009742241717437">"Halaman widget %1$d dari %2$d"</string>
<string name="workspace_cling_title" msgid="738396473989890567">"Buat diri anda seperti di rumah"</string>
<string name="workspace_cling_move_item" msgid="791013895761065070">"Anda boleh meletakkan aplikasi kegemaran anda di sini."</string>
- <string name="workspace_cling_open_all_apps" msgid="2459977609848572588">"Untuk melihat semua aplikasi anda, sentuh bulatan."</string>
- <string name="all_apps_cling_title" msgid="2559734712581447107">"Pilih beberapa aplikasi"</string>
- <string name="all_apps_cling_add_item" msgid="5665035103260318891">"Untuk menambahkan aplikasi pada skrin Utama anda, sentuh & tahankannya."</string>
<string name="folder_cling_title" msgid="4308949882377840953">"Susun aplikasi anda dengan folder"</string>
- <string name="folder_cling_move_item" msgid="270598675060435169">"Untuk memindahkan aplikasi, sentuh & tahankannya."</string>
<string name="folder_cling_create_folder" msgid="8352867485656129478">"Untuk membuat folder baharu pada skrin Utama anda, tindihkan satu aplikasi di atas yang lain."</string>
<string name="cling_dismiss" msgid="2780907108735868381">"OK"</string>
<string name="folder_opened" msgid="1262064100943801533">"Folder dibuka, <xliff:g id="WIDTH">%1$d</xliff:g> kali <xliff:g id="HEIGHT">%2$d</xliff:g>"</string>
@@ -107,8 +91,4 @@
<string name="folder_closed" msgid="3130534551370511932">"Folder ditutup"</string>
<string name="folder_renamed" msgid="7951233572858053642">"Folder dinamakan semula kepada <xliff:g id="NAME">%1$s</xliff:g>"</string>
<string name="folder_name_format" msgid="3051680259794759037">"Folder: <xliff:g id="NAME">%1$s</xliff:g>"</string>
- <string name="custom_workspace_cling_title_1" msgid="1433009175359948587"></string>
- <string name="custom_workspace_cling_description_1" msgid="6875529190849858047"></string>
- <string name="custom_workspace_cling_title_2" msgid="5516006164661020362"></string>
- <string name="custom_workspace_cling_description_2" msgid="2758258454975288377"></string>
</resources>
diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml
index 28679be..d907587 100644
--- a/res/values-sw600dp/dimens.xml
+++ b/res/values-sw600dp/dimens.xml
@@ -17,6 +17,10 @@
<resources>
<dimen name="app_icon_size">64dp</dimen>
+<!-- Apps view -->
+ <dimen name="apps_container_width">480dp</dimen>
+ <dimen name="apps_view_row_height">76dp</dimen>
+
<!-- AppsCustomize -->
<dimen name="apps_customize_tab_bar_height">60dp</dimen>
<dimen name="apps_customize_tab_bar_margin_top">8dp</dimen>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 3331cde..a1f2845 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -18,6 +18,16 @@
<resources>
+ <!-- BubbleTextView specific attributes. -->
+ <declare-styleable name="BubbleTextView">
+ <attr name="layoutHorizontal" format="boolean" />
+ <attr name="iconSizeOverride" format="dimension" />
+ <attr name="iconPaddingOverride" format="dimension" />
+ <attr name="textSizeOverride" format="dimension" />
+ <attr name="deferShadowGeneration" format="boolean" />
+ <attr name="customShadows" format="boolean" />
+ </declare-styleable>
+
<!-- Page Indicator specific attributes. -->
<declare-styleable name="PageIndicator">
<attr name="windowSize" format="integer" />
@@ -80,11 +90,6 @@
<attr name="pageIndicator" format="reference" />
</declare-styleable>
- <declare-styleable name="BubbleTextView">
- <!-- A spacing override for the icons within a page -->
- <attr name="customShadows" format="boolean" />
- </declare-styleable>
-
<!-- AppsCustomizePagedView specific attributes. These attributes are used to
customize an AppsCustomizePagedView in xml files. -->
<declare-styleable name="AppsCustomizePagedView">
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 2daf9fe..590a887 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -36,4 +36,8 @@
<color name="outline_color">#FFFFFFFF</color>
<color name="widget_text_panel">#FF374248</color>
+<!-- Apps view -->
+ <color name="apps_view_scrollbar_thumb_color">#009688</color>
+ <color name="apps_view_section_text_color">#009688</color>
+
</resources>
diff --git a/res/values/config.xml b/res/values/config.xml
index cbec512..1acace6 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -104,4 +104,5 @@
<item type="id" name="action_uninstall" />
<item type="id" name="action_info" />
<item type="id" name="action_add_to_workspace" />
+ <item type="id" name="action_move" />
</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index d6fc508..c327ec2 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -46,6 +46,18 @@
<dimen name="toolbar_button_vertical_padding">4dip</dimen>
<dimen name="toolbar_button_horizontal_padding">12dip</dimen>
+<!-- Apps view -->
+ <dimen name="apps_container_width">0dp</dimen>
+ <dimen name="apps_container_inset">8dp</dimen>
+ <dimen name="apps_grid_view_start_margin">52dp</dimen>
+ <dimen name="apps_view_row_height">64dp</dimen>
+ <dimen name="apps_view_section_text_size">24sp</dimen>
+ <dimen name="apps_view_fast_scroll_bar_width">6dp</dimen>
+ <dimen name="apps_view_fast_scroll_bar_min_height">64dp</dimen>
+ <dimen name="apps_view_fast_scroll_scrubber_touch_inset">-16dp</dimen>
+ <dimen name="apps_view_fast_scroll_popup_size">64dp</dimen>
+ <dimen name="apps_view_fast_scroll_text_size">40dp</dimen>
+
<!-- AllApps/Customize/AppsCustomize -->
<!-- The height of the tab bar - if this changes, we should update the
external icon width/height above to compensate -->
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8b7e6c1..7f79b98 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -71,6 +71,14 @@
drop if there are multiple choices. [CHAR_LIMIT=35] -->
<string name="external_drop_widget_pick_title">Choose widget to create</string>
+ <!-- Apps view -->
+ <!-- Search bar text in the apps view. [CHAR_LIMIT=50] -->
+ <string name="apps_view_search_bar_hint">Search Apps</string>
+ <!-- Loading apps text. [CHAR_LIMIT=50] -->
+ <string name="loading_apps_message">Loading Apps...</string>
+ <!-- No-search-results text. [CHAR_LIMIT=50] -->
+ <string name="apps_view_no_search_results">No Apps found matching \"<xliff:g id="query" example="Android">%1$s</xliff:g>\"</string>
+
<!-- Folders -->
<skip />
<!-- Label of Folder name field in Rename folder dialog box -->
@@ -81,6 +89,8 @@
<string name="rename_action">OK</string>
<!-- Buttons in Rename folder dialog box -->
<string name="cancel_action">Cancel</string>
+ <!-- Label for button to sort folder contents. [CHAR_LIMIT=10] -->
+ <string name="sort_alphabetical">A-Z</string>
<!-- Shortcuts -->
<skip />
@@ -103,8 +113,6 @@
<string name="invalid_hotseat_item">This widget is too large for the Favorites tray</string>
<!-- Message displayed when a shortcut is created by an external application -->
<string name="shortcut_installed">Shortcut \"<xliff:g id="name" example="Browser">%s</xliff:g>\" created.</string>
- <!-- Message displayed when a shortcut is uninstalled by an external application -->
- <string name="shortcut_uninstalled">Shortcut \"<xliff:g id="name" example="Browser">%s</xliff:g>\" was removed.</string>
<!-- Message displayed when an external application attemps to create a shortcut that already exists -->
<string name="shortcut_duplicate">Shortcut \"<xliff:g id="name" example="Browser">%s</xliff:g>\" already exists.</string>
@@ -303,6 +311,34 @@
</string>
<!-- Strings for accessibility actions -->
- <!-- Accessibility action to add an app to workspace. [CHAR_LIMIT=30] -->
+ <!-- Accessibility action to add an app to workspace. [CHAR_LIMIT=30] [DO NOT TRANSLATE] -->
<string name="action_add_to_workspace">Add To Workspace</string>
+
+ <!-- Accessibility confirmation for item added to workspace [DO NOT TRANSLATE] -->
+ <string name="item_added_to_workspace">Item added to workspace</string>
+
+ <!-- Accessibility confirmation for item removed [DO NOT TRANSLATE] -->
+ <string name="item_removed_from_workspace">Item removed from workspace</string>
+
+ <!-- Accessibility action to move an item on the workspace. [CHAR_LIMIT=30] [DO NOT TRANSLATE] -->
+ <string name="action_move">Move Item</string>
+
+ <!-- Accessibility description to move item to empty cell. [DO NOT TRANSLATE] -->
+ <string name="move_to_empty_cell">Move to empty cell <xliff:g id="number" example="1">%1$s</xliff:g>, <xliff:g id="number" example="1">%2$s</xliff:g></string>
+
+ <!-- Accessibility confirmation for item move [DO NOT TRANSLATE]-->
+ <string name="item_moved">Item moved</string>
+
+ <!-- Accessibility description to move item into an existing folder. [DO NOT TRANSLATE]-->
+ <string name="add_to_folder">Add to folder: <xliff:g id="name" example="Games">%1$s</xliff:g></string>
+
+ <!-- Accessibility confirmation for item added to folder [DO NOT TRANSLATE] -->
+ <string name="added_to_folder">Item added to folder</string>
+
+ <!-- Accessibility description to create folder with another item. [DO NOT TRANSLATE] -->
+ <string name="create_folder_with">Create folder with: <xliff:g id="name" example="Game">%1$s</xliff:g></string>
+
+ <!-- Accessibility confirmation for folder created [DO NOT TRANSLATE] -->
+ <string name="folder_created">Folder created</string>
+
</resources>
diff --git a/src/com/android/launcher3/AllAppsList.java b/src/com/android/launcher3/AllAppsList.java
index 5ed7a62..dd646bb 100644
--- a/src/com/android/launcher3/AllAppsList.java
+++ b/src/com/android/launcher3/AllAppsList.java
@@ -148,7 +148,7 @@
if (applicationInfo == null) {
add(new AppInfo(context, info, user, mIconCache));
} else {
- mIconCache.getTitleAndIcon(applicationInfo, info);
+ mIconCache.getTitleAndIcon(applicationInfo, info, true /* useLowResIcon */);
modified.add(applicationInfo);
}
}
diff --git a/src/com/android/launcher3/AlphabeticalAppsList.java b/src/com/android/launcher3/AlphabeticalAppsList.java
new file mode 100644
index 0000000..8d1db63
--- /dev/null
+++ b/src/com/android/launcher3/AlphabeticalAppsList.java
@@ -0,0 +1,348 @@
+package com.android.launcher3;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+import com.android.launcher3.compat.AlphabeticIndexCompat;
+import com.android.launcher3.compat.UserHandleCompat;
+import com.android.launcher3.compat.UserManagerCompat;
+
+import java.text.Collator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+
+
+/**
+ * A private class to manage access to an app name comparator.
+ */
+class AppNameComparator {
+ private UserManagerCompat mUserManager;
+ private Comparator<AppInfo> mAppNameComparator;
+ private HashMap<UserHandleCompat, Long> mUserSerialCache = new HashMap<>();
+
+ public AppNameComparator(Context context) {
+ final Collator collator = Collator.getInstance();
+ mUserManager = UserManagerCompat.getInstance(context);
+ mAppNameComparator = new Comparator<AppInfo>() {
+ public final int compare(AppInfo a, AppInfo b) {
+ // Order by the title
+ int result = collator.compare(a.title.toString().trim(),
+ b.title.toString().trim());
+ if (result == 0) {
+ // If two apps have the same title, then order by the component name
+ result = a.componentName.compareTo(b.componentName);
+ if (result == 0) {
+ // If the two apps are the same component, then prioritize by the order that
+ // the app user was created (prioritizing the main user's apps)
+ if (UserHandleCompat.myUserHandle().equals(a.user)) {
+ return -1;
+ } else {
+ Long aUserSerial = getAndCacheUserSerial(a.user);
+ Long bUserSerial = getAndCacheUserSerial(b.user);
+ return aUserSerial.compareTo(bUserSerial);
+ }
+ }
+ }
+ return result;
+ }
+ };
+ }
+
+ /**
+ * Returns a locale-aware comparator that will alphabetically order a list of applications.
+ */
+ public Comparator<AppInfo> getComparator() {
+ // Clear the user serial cache so that we get serials as needed in the comparator
+ mUserSerialCache.clear();
+ return mAppNameComparator;
+ }
+
+ /**
+ * Returns the user serial for this user, using a cached serial if possible.
+ */
+ private Long getAndCacheUserSerial(UserHandleCompat user) {
+ Long userSerial = mUserSerialCache.get(user);
+ if (userSerial == null) {
+ userSerial = mUserManager.getSerialNumberForUser(user);
+ mUserSerialCache.put(user, userSerial);
+ }
+ return userSerial;
+ }
+}
+
+/**
+ * The alphabetically sorted list of applications.
+ */
+public class AlphabeticalAppsList {
+
+ /**
+ * Info about a section in the alphabetic list
+ */
+ public static class SectionInfo {
+ // The name of this section
+ public String sectionName;
+ // The number of applications in this section
+ public int numAppsInSection;
+ // The first app AdapterItem for this section
+ public AdapterItem firstAppItem;
+
+ public SectionInfo(String name) {
+ sectionName = name;
+ }
+ }
+
+ /**
+ * Info about a particular adapter item (can be either section or app)
+ */
+ public static class AdapterItem {
+ // The index of this adapter item in the list
+ public int position;
+ // Whether or not the item at this adapter position is a section or not
+ public boolean isSectionHeader;
+ // The name of this section, or the section that this app is contained in
+ public String sectionName;
+ // The associated AppInfo, or null if this adapter item is a section
+ public AppInfo appInfo;
+ // The index of this app (not including sections), or -1 if this adapter item is a section
+ public int appIndex;
+
+ public static AdapterItem asSection(int pos, String name) {
+ AdapterItem item = new AdapterItem();
+ item.position = pos;
+ item.isSectionHeader = true;
+ item.sectionName = name;
+ item.appInfo = null;
+ item.appIndex = -1;
+ return item;
+ }
+
+ public static AdapterItem asApp(int pos, String sectionName, AppInfo appInfo, int appIndex) {
+ AdapterItem item = new AdapterItem();
+ item.position = pos;
+ item.isSectionHeader = false;
+ item.sectionName = sectionName;
+ item.appInfo = appInfo;
+ item.appIndex = appIndex;
+ return item;
+ }
+ }
+
+ /**
+ * A filter interface to limit the set of applications in the apps list.
+ */
+ public interface Filter {
+ public boolean retainApp(AppInfo info, String sectionName);
+ }
+
+ private List<AppInfo> mApps = new ArrayList<>();
+ private List<AppInfo> mFilteredApps = new ArrayList<>();
+ private List<AdapterItem> mSectionedFilteredApps = new ArrayList<>();
+ private List<SectionInfo> mSections = new ArrayList<>();
+ private RecyclerView.Adapter mAdapter;
+ private Filter mFilter;
+ private AlphabeticIndexCompat mIndexer;
+ private AppNameComparator mAppNameComparator;
+
+ public AlphabeticalAppsList(Context context) {
+ mIndexer = new AlphabeticIndexCompat(context);
+ mAppNameComparator = new AppNameComparator(context);
+ }
+
+ /**
+ * Sets the adapter to notify when this dataset changes.
+ */
+ public void setAdapter(RecyclerView.Adapter adapter) {
+ mAdapter = adapter;
+ }
+
+ /**
+ * Returns sections of all the current filtered applications.
+ */
+ public List<SectionInfo> getSections() {
+ return mSections;
+ }
+
+ /**
+ * Returns the current filtered list of applications broken down into their sections.
+ */
+ public List<AdapterItem> getAdapterItems() {
+ return mSectionedFilteredApps;
+ }
+
+ /**
+ * Returns the number of applications in this list.
+ */
+ public int getSize() {
+ return mFilteredApps.size();
+ }
+
+ /**
+ * Returns whether there are no filtered results.
+ */
+ public boolean hasNoFilteredResults() {
+ return (mFilter != null) && mFilteredApps.isEmpty();
+ }
+
+ /**
+ * Sets the current filter for this list of apps.
+ */
+ public void setFilter(Filter f) {
+ mFilter = f;
+ onAppsUpdated();
+ mAdapter.notifyDataSetChanged();
+ }
+
+ /**
+ * Sets the current set of apps.
+ */
+ public void setApps(List<AppInfo> apps) {
+ Collections.sort(apps, mAppNameComparator.getComparator());
+ mApps.clear();
+ mApps.addAll(apps);
+ onAppsUpdated();
+ mAdapter.notifyDataSetChanged();
+ }
+
+ /**
+ * Adds new apps to the list.
+ */
+ public void addApps(List<AppInfo> apps) {
+ // We add it in place, in alphabetical order
+ for (AppInfo info : apps) {
+ addApp(info);
+ }
+ }
+
+ /**
+ * Updates existing apps in the list
+ */
+ public void updateApps(List<AppInfo> apps) {
+ for (AppInfo info : apps) {
+ int index = mApps.indexOf(info);
+ if (index != -1) {
+ mApps.set(index, info);
+ onAppsUpdated();
+ mAdapter.notifyItemChanged(index);
+ } else {
+ addApp(info);
+ }
+ }
+ }
+
+ /**
+ * Removes some apps from the list.
+ */
+ public void removeApps(List<AppInfo> apps) {
+ for (AppInfo info : apps) {
+ int removeIndex = findAppByComponent(mApps, info);
+ if (removeIndex != -1) {
+ int sectionedIndex = mSectionedFilteredApps.indexOf(info);
+ int numAppsInSection = numAppsInSection(info);
+ mApps.remove(removeIndex);
+ onAppsUpdated();
+ if (numAppsInSection == 1) {
+ // Remove the section and the icon
+ mAdapter.notifyItemRemoved(sectionedIndex - 1);
+ mAdapter.notifyItemRemoved(sectionedIndex - 1);
+ } else {
+ mAdapter.notifyItemRemoved(sectionedIndex);
+ }
+ }
+ }
+ }
+
+ /**
+ * Finds the index of an app given a target AppInfo.
+ */
+ private int findAppByComponent(List<AppInfo> apps, AppInfo targetInfo) {
+ ComponentName targetComponent = targetInfo.intent.getComponent();
+ int length = apps.size();
+ for (int i = 0; i < length; ++i) {
+ AppInfo info = apps.get(i);
+ if (info.user.equals(info.user)
+ && info.intent.getComponent().equals(targetComponent)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Implementation to actually add an app to the alphabetic list
+ */
+ private void addApp(AppInfo info) {
+ int index = Collections.binarySearch(mApps, info, mAppNameComparator.getComparator());
+ if (index < 0) {
+ mApps.add(-(index + 1), info);
+ onAppsUpdated();
+
+ int sectionedIndex = mSectionedFilteredApps.indexOf(info);
+ int numAppsInSection = numAppsInSection(info);
+ if (numAppsInSection == 1) {
+ // New section added along with icon
+ mAdapter.notifyItemInserted(sectionedIndex - 1);
+ mAdapter.notifyItemInserted(sectionedIndex - 1);
+ } else {
+ mAdapter.notifyItemInserted(sectionedIndex);
+ }
+ }
+ }
+
+ /**
+ * Returns the number of apps in the section that the given info is in.
+ */
+ private int numAppsInSection(AppInfo info) {
+ int appIndex = mFilteredApps.indexOf(info);
+ int appCount = 0;
+ for (SectionInfo section : mSections) {
+ if (appCount + section.numAppsInSection > appIndex) {
+ return section.numAppsInSection;
+ }
+ appCount += section.numAppsInSection;
+ }
+ return 1;
+ }
+
+ /**
+ * Updates internals when the set of apps are updated.
+ */
+ private void onAppsUpdated() {
+ // Recreate the filtered and sectioned apps (for convenience for the grid layout)
+ mFilteredApps.clear();
+ mSections.clear();
+ mSectionedFilteredApps.clear();
+ SectionInfo lastSectionInfo = null;
+ int position = 0;
+ int appIndex = 0;
+ for (AppInfo info : mApps) {
+ String sectionName = mIndexer.computeSectionName(info.title.toString().trim());
+
+ // Check if we want to retain this app
+ if (mFilter != null && !mFilter.retainApp(info, sectionName)) {
+ continue;
+ }
+
+ // Create a new section if necessary
+ if (lastSectionInfo == null || !lastSectionInfo.sectionName.equals(sectionName)) {
+ lastSectionInfo = new SectionInfo(sectionName);
+ mSections.add(lastSectionInfo);
+
+ // Create a new section item
+ AdapterItem sectionItem = AdapterItem.asSection(position++, sectionName);
+ mSectionedFilteredApps.add(sectionItem);
+ }
+
+ // Create an app item
+ AdapterItem appItem = AdapterItem.asApp(position++, sectionName, info, appIndex++);
+ lastSectionInfo.numAppsInSection++;
+ if (lastSectionInfo.firstAppItem == null) {
+ lastSectionInfo.firstAppItem = appItem;
+ }
+ mSectionedFilteredApps.add(appItem);
+ mFilteredApps.add(info);
+ }
+ }
+}
diff --git a/src/com/android/launcher3/AppInfo.java b/src/com/android/launcher3/AppInfo.java
index 455c6d1..a1391b2 100644
--- a/src/com/android/launcher3/AppInfo.java
+++ b/src/com/android/launcher3/AppInfo.java
@@ -46,6 +46,11 @@
Bitmap iconBitmap;
/**
+ * Indicates whether we're using a low res icon
+ */
+ boolean usingLowResIcon;
+
+ /**
* The time at which the app was first installed.
*/
long firstInstallTime;
@@ -79,7 +84,7 @@
flags = initFlags(info);
firstInstallTime = info.getFirstInstallTime();
- iconCache.getTitleAndIcon(this, info);
+ iconCache.getTitleAndIcon(this, info, true /* useLowResIcon */);
intent = makeLaunchIntent(context, info, user);
this.user = user;
}
diff --git a/src/com/android/launcher3/AppWidgetsRestoredReceiver.java b/src/com/android/launcher3/AppWidgetsRestoredReceiver.java
index 880aaf1..5e7a012 100644
--- a/src/com/android/launcher3/AppWidgetsRestoredReceiver.java
+++ b/src/com/android/launcher3/AppWidgetsRestoredReceiver.java
@@ -90,5 +90,10 @@
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
+
+ LauncherAppState app = LauncherAppState.getInstanceNoCreate();
+ if (app != null) {
+ app.reloadWorkspace();
+ }
}
}
diff --git a/src/com/android/launcher3/AppsContainerRecyclerView.java b/src/com/android/launcher3/AppsContainerRecyclerView.java
new file mode 100644
index 0000000..63e7fe4
--- /dev/null
+++ b/src/com/android/launcher3/AppsContainerRecyclerView.java
@@ -0,0 +1,413 @@
+/*
+ * Copyright (C) 2015 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.launcher3;
+
+import android.animation.ObjectAnimator;
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewConfiguration;
+
+import java.util.List;
+
+/**
+ * A RecyclerView with custom fastscroll support. This is the main container for the all apps
+ * icons.
+ */
+public class AppsContainerRecyclerView extends RecyclerView
+ implements RecyclerView.OnItemTouchListener {
+
+ private static final float FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR = 1.5f;
+
+ private AlphabeticalAppsList mApps;
+ private int mNumAppsPerRow;
+
+ private Drawable mScrollbar;
+ private Drawable mFastScrollerBg;
+ private Rect mVerticalScrollbarBounds = new Rect();
+ private boolean mDraggingFastScroller;
+ private String mFastScrollSectionName;
+ private Paint mFastScrollTextPaint;
+ private Rect mFastScrollTextBounds = new Rect();
+ private float mFastScrollAlpha;
+ private int mDownX;
+ private int mDownY;
+ private int mLastX;
+ private int mLastY;
+ private int mScrollbarWidth;
+ private int mScrollbarMinHeight;
+ private int mScrollbarInset;
+
+ public AppsContainerRecyclerView(Context context) {
+ this(context, null);
+ }
+
+ public AppsContainerRecyclerView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public AppsContainerRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) {
+ this(context, attrs, defStyleAttr, 0);
+ }
+
+ public AppsContainerRecyclerView(Context context, AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ super(context, attrs, defStyleAttr);
+
+ Resources res = context.getResources();
+ int fastScrollerSize = res.getDimensionPixelSize(R.dimen.apps_view_fast_scroll_popup_size);
+ mScrollbar = res.getDrawable(R.drawable.apps_list_scrollbar_thumb);
+ mFastScrollerBg = res.getDrawable(R.drawable.apps_list_fastscroll_bg);
+ mFastScrollerBg.setBounds(0, 0, fastScrollerSize, fastScrollerSize);
+ mFastScrollTextPaint = new Paint();
+ mFastScrollTextPaint.setColor(Color.WHITE);
+ mFastScrollTextPaint.setAntiAlias(true);
+ mFastScrollTextPaint.setTextSize(res.getDimensionPixelSize(
+ R.dimen.apps_view_fast_scroll_text_size));
+ mScrollbarWidth = res.getDimensionPixelSize(R.dimen.apps_view_fast_scroll_bar_width);
+ mScrollbarMinHeight =
+ res.getDimensionPixelSize(R.dimen.apps_view_fast_scroll_bar_min_height);
+ mScrollbarInset =
+ res.getDimensionPixelSize(R.dimen.apps_view_fast_scroll_scrubber_touch_inset);
+ setFastScrollerAlpha(getFastScrollerAlpha());
+ }
+
+ /**
+ * Sets the list of apps in this view, used to determine the fastscroll position.
+ */
+ public void setApps(AlphabeticalAppsList apps) {
+ mApps = apps;
+ }
+
+ /**
+ * Sets the number of apps per row in this recycler view.
+ */
+ public void setNumAppsPerRow(int rowSize) {
+ mNumAppsPerRow = rowSize;
+ }
+
+ /**
+ * Sets the fast scroller alpha.
+ */
+ public void setFastScrollerAlpha(float alpha) {
+ mFastScrollAlpha = alpha;
+ invalidateFastScroller();
+ }
+
+ /**
+ * Gets the fast scroller alpha.
+ */
+ public float getFastScrollerAlpha() {
+ return mFastScrollAlpha;
+ }
+
+ /**
+ * Returns the scroll bar width.
+ */
+ public int getScrollbarWidth() {
+ return mScrollbarWidth;
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ addOnItemTouchListener(this);
+ }
+
+ @Override
+ protected void dispatchDraw(Canvas canvas) {
+ super.dispatchDraw(canvas);
+ drawVerticalScrubber(canvas);
+ drawFastScrollerPopup(canvas);
+ }
+
+ /**
+ * We intercept the touch handling only to support fast scrolling when initiated from the
+ * scroll bar. Otherwise, we fall back to the default RecyclerView touch handling.
+ */
+ @Override
+ public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent ev) {
+ return handleTouchEvent(ev);
+ }
+
+ @Override
+ public void onTouchEvent(RecyclerView rv, MotionEvent ev) {
+ handleTouchEvent(ev);
+ }
+
+ /**
+ * Handles the touch event and determines whether to show the fast scroller (or updates it if
+ * it is already showing).
+ */
+ private boolean handleTouchEvent(MotionEvent ev) {
+ ViewConfiguration config = ViewConfiguration.get(getContext());
+
+ int action = ev.getAction();
+ int x = (int) ev.getX();
+ int y = (int) ev.getY();
+ switch (action) {
+ case MotionEvent.ACTION_DOWN:
+ // Keep track of the down positions
+ mDownX = mLastX = x;
+ mDownY = mLastY = y;
+ stopScroll();
+ break;
+ case MotionEvent.ACTION_MOVE:
+ // Check if we are scrolling
+ if (!mDraggingFastScroller && isPointNearScrollbar(mDownX, mDownY) &&
+ Math.abs(y - mDownY) > config.getScaledTouchSlop()) {
+ getParent().requestDisallowInterceptTouchEvent(true);
+ mDraggingFastScroller = true;
+ animateFastScrollerVisibility(true);
+ }
+ if (mDraggingFastScroller) {
+ mLastX = x;
+ mLastY = y;
+
+ // Scroll to the right position, and update the section name
+ int top = getPaddingTop() + (mFastScrollerBg.getBounds().height() / 2);
+ int bottom = getHeight() - getPaddingBottom() -
+ (mFastScrollerBg.getBounds().height() / 2);
+ float boundedY = (float) Math.max(top, Math.min(bottom, y));
+ mFastScrollSectionName = scrollToPositionAtProgress((boundedY - top) /
+ (bottom - top));
+ invalidateFastScroller();
+ }
+ break;
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ mDraggingFastScroller = false;
+ animateFastScrollerVisibility(false);
+ break;
+ }
+ return mDraggingFastScroller;
+
+ }
+
+ /**
+ * Animates the visibility of the fast scroller popup.
+ */
+ private void animateFastScrollerVisibility(boolean visible) {
+ ObjectAnimator anim = ObjectAnimator.ofFloat(this, "fastScrollerAlpha", visible ? 1f : 0f);
+ anim.setDuration(visible ? 200 : 150);
+ anim.start();
+ }
+
+ /**
+ * Returns whether a given point is near the scrollbar.
+ */
+ private boolean isPointNearScrollbar(int x, int y) {
+ // Check if we are scrolling
+ updateVerticalScrollbarBounds();
+ mVerticalScrollbarBounds.inset(mScrollbarInset, mScrollbarInset);
+ return mVerticalScrollbarBounds.contains(x, y);
+ }
+
+ /**
+ * Draws the fast scroller popup.
+ */
+ private void drawFastScrollerPopup(Canvas canvas) {
+ if (mFastScrollAlpha > 0f) {
+ int x;
+ int y;
+ boolean isRtl = (getResources().getConfiguration().getLayoutDirection() ==
+ LAYOUT_DIRECTION_RTL);
+
+ // Calculate the position for the fast scroller popup
+ Rect bgBounds = mFastScrollerBg.getBounds();
+ if (isRtl) {
+ x = getPaddingLeft() + getScrollBarSize();
+ } else {
+ x = getWidth() - getPaddingRight() - getScrollBarSize() - bgBounds.width();
+ }
+ y = mLastY - (int) (FAST_SCROLL_OVERLAY_Y_OFFSET_FACTOR * bgBounds.height());
+ y = Math.max(getPaddingTop(), Math.min(y, getHeight() - getPaddingBottom() -
+ bgBounds.height()));
+
+ // Draw the fast scroller popup
+ int restoreCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
+ canvas.translate(x, y);
+ mFastScrollerBg.setAlpha((int) (mFastScrollAlpha * 255));
+ mFastScrollerBg.draw(canvas);
+ mFastScrollTextPaint.setAlpha((int) (mFastScrollAlpha * 255));
+ mFastScrollTextPaint.getTextBounds(mFastScrollSectionName, 0,
+ mFastScrollSectionName.length(), mFastScrollTextBounds);
+ canvas.drawText(mFastScrollSectionName,
+ (bgBounds.width() - mFastScrollTextBounds.width()) / 2,
+ bgBounds.height() - (bgBounds.height() - mFastScrollTextBounds.height()) / 2,
+ mFastScrollTextPaint);
+ canvas.restoreToCount(restoreCount);
+ }
+ }
+
+ /**
+ * Draws the vertical scrollbar.
+ */
+ private void drawVerticalScrubber(Canvas canvas) {
+ updateVerticalScrollbarBounds();
+
+ // Draw the scroll bar
+ int restoreCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
+ canvas.translate(mVerticalScrollbarBounds.left, mVerticalScrollbarBounds.top);
+ mScrollbar.setBounds(0, 0, mScrollbarWidth, mVerticalScrollbarBounds.height());
+ mScrollbar.draw(canvas);
+ canvas.restoreToCount(restoreCount);
+ }
+
+ /**
+ * Invalidates the fast scroller popup.
+ */
+ private void invalidateFastScroller() {
+ invalidate(getWidth() - getPaddingRight() - getScrollBarSize() -
+ mFastScrollerBg.getIntrinsicWidth(), 0, getWidth(), getHeight());
+ }
+
+ /**
+ * Maps the progress (from 0..1) to the position that should be visible
+ */
+ private String scrollToPositionAtProgress(float progress) {
+ List<AlphabeticalAppsList.SectionInfo> sections = mApps.getSections();
+ if (sections.isEmpty()) {
+ return "";
+ }
+
+ // Find the position of the first application in the section that contains the row at the
+ // current progress
+ int rowAtProgress = (int) (progress * getNumRows());
+ int rowCount = 0;
+ AlphabeticalAppsList.SectionInfo lastSectionInfo = null;
+ for (AlphabeticalAppsList.SectionInfo section : sections) {
+ int numRowsInSection = (int) Math.ceil((float) section.numAppsInSection / mNumAppsPerRow);
+ if (rowCount + numRowsInSection >= rowAtProgress) {
+ lastSectionInfo = section;
+ break;
+ }
+ rowCount += numRowsInSection;
+ }
+ int position = mApps.getAdapterItems().indexOf(lastSectionInfo.firstAppItem);
+
+ // Scroll the position into view, anchored at the top of the screen if possible. We call the
+ // scroll method on the LayoutManager directly since it is not exposed by RecyclerView.
+ LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager();
+ stopScroll();
+ layoutManager.scrollToPositionWithOffset(position, 0);
+
+ // Return the section name of the row
+ return mApps.getAdapterItems().get(position).sectionName;
+ }
+
+ /**
+ * Returns the bounds for the scrollbar.
+ */
+ private void updateVerticalScrollbarBounds() {
+ // Skip early if there are no items
+ if (mApps.getAdapterItems().isEmpty()) {
+ mVerticalScrollbarBounds.setEmpty();
+ return;
+ }
+
+ // Find the index and height of the first visible row (all rows have the same height)
+ int x;
+ int y;
+ boolean isRtl = (getResources().getConfiguration().getLayoutDirection() ==
+ LAYOUT_DIRECTION_RTL);
+ int rowIndex = -1;
+ int rowTopOffset = -1;
+ int rowHeight = -1;
+ int rowCount = getNumRows();
+ int childCount = getChildCount();
+ for (int i = 0; i < childCount; i++) {
+ View child = getChildAt(i);
+ int position = getChildAdapterPosition(child);
+ if (position != NO_POSITION) {
+ AlphabeticalAppsList.AdapterItem item = mApps.getAdapterItems().get(position);
+ if (!item.isSectionHeader) {
+ rowIndex = findRowForAppIndex(item.appIndex);
+ rowTopOffset = getLayoutManager().getDecoratedTop(child);
+ rowHeight = child.getHeight();
+ break;
+ }
+ }
+ }
+
+ if (rowIndex != -1) {
+ int height = getHeight() - getPaddingTop() - getPaddingBottom();
+ int totalScrollHeight = rowCount * rowHeight;
+ if (totalScrollHeight > height) {
+ int scrollbarHeight = Math.max(mScrollbarMinHeight,
+ (int) (height / ((float) totalScrollHeight / height)));
+
+ // Calculate the position and size of the scroll bar
+ if (isRtl) {
+ x = getPaddingLeft();
+ } else {
+ x = getWidth() - getPaddingRight() - mScrollbarWidth;
+ }
+
+ // To calculate the offset, we compute the percentage of the total scrollable height
+ // that the user has already scrolled and then map that to the scroll bar bounds
+ int availableY = totalScrollHeight - height;
+ int availableScrollY = height - scrollbarHeight;
+ y = (rowIndex * rowHeight) - rowTopOffset;
+ y = getPaddingTop() +
+ (int) (((float) (getPaddingTop() + y) / availableY) * availableScrollY);
+
+ mVerticalScrollbarBounds.set(x, y, x + mScrollbarWidth, y + scrollbarHeight);
+ return;
+ }
+ }
+ mVerticalScrollbarBounds.setEmpty();
+ }
+
+ /**
+ * Returns the row index for a given position in the list.
+ */
+ private int findRowForAppIndex(int position) {
+ List<AlphabeticalAppsList.SectionInfo> sections = mApps.getSections();
+ int appIndex = 0;
+ int rowCount = 0;
+ for (AlphabeticalAppsList.SectionInfo info : sections) {
+ int numRowsInSection = (int) Math.ceil((float) info.numAppsInSection / mNumAppsPerRow);
+ if (appIndex + info.numAppsInSection > position) {
+ return rowCount + ((position - appIndex) / mNumAppsPerRow);
+ }
+ appIndex += info.numAppsInSection;
+ rowCount += numRowsInSection;
+ }
+ return appIndex;
+ }
+
+ /**
+ * Returns the total number of rows in the list.
+ */
+ private int getNumRows() {
+ List<AlphabeticalAppsList.SectionInfo> sections = mApps.getSections();
+ int rowCount = 0;
+ for (AlphabeticalAppsList.SectionInfo info : sections) {
+ int numRowsInSection = (int) Math.ceil((float) info.numAppsInSection / mNumAppsPerRow);
+ rowCount += numRowsInSection;
+ }
+ return rowCount;
+ }
+}
diff --git a/src/com/android/launcher3/AppsContainerView.java b/src/com/android/launcher3/AppsContainerView.java
new file mode 100644
index 0000000..2de45cb
--- /dev/null
+++ b/src/com/android/launcher3/AppsContainerView.java
@@ -0,0 +1,385 @@
+/*
+ * Copyright (C) 2015 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.launcher3;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.support.v7.widget.RecyclerView;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.util.AttributeSet;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+import android.widget.FrameLayout;
+import android.widget.TextView;
+
+import com.android.launcher3.util.Thunk;
+
+import java.util.List;
+
+
+/**
+ * The all apps list view container.
+ */
+public class AppsContainerView extends FrameLayout implements DragSource, Insettable, TextWatcher,
+ TextView.OnEditorActionListener, LauncherTransitionable, View.OnTouchListener,
+ View.OnLongClickListener {
+
+ private static final boolean ALLOW_SINGLE_APP_LAUNCH = true;
+
+ private static final int GRID_LAYOUT = 0;
+ private static final int LIST_LAYOUT = 1;
+ private static final int USE_LAYOUT = GRID_LAYOUT;
+
+ @Thunk Launcher mLauncher;
+ @Thunk AlphabeticalAppsList mApps;
+ private RecyclerView.Adapter mAdapter;
+ private RecyclerView.LayoutManager mLayoutManager;
+ private RecyclerView.ItemDecoration mItemDecoration;
+ @Thunk AppsContainerRecyclerView mAppsListView;
+ private EditText mSearchBar;
+ private int mNumAppsPerRow;
+ private Point mLastTouchDownPos = new Point();
+ private Rect mPadding = new Rect();
+ private int mContentMarginStart;
+
+ public AppsContainerView(Context context) {
+ this(context, null);
+ }
+
+ public AppsContainerView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public AppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ LauncherAppState app = LauncherAppState.getInstance();
+ DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
+ Resources res = context.getResources();
+
+ mLauncher = (Launcher) context;
+ mApps = new AlphabeticalAppsList(context);
+ if (USE_LAYOUT == GRID_LAYOUT) {
+ mNumAppsPerRow = grid.appsViewNumCols;
+ AppsGridAdapter adapter = new AppsGridAdapter(context, mApps, mNumAppsPerRow, this,
+ mLauncher, this);
+ adapter.setEmptySearchText(res.getString(R.string.loading_apps_message));
+ mLayoutManager = adapter.getLayoutManager(context);
+ mItemDecoration = adapter.getItemDecoration();
+ mAdapter = adapter;
+ mContentMarginStart = adapter.getContentMarginStart();
+ } else if (USE_LAYOUT == LIST_LAYOUT) {
+ mNumAppsPerRow = 1;
+ AppsListAdapter adapter = new AppsListAdapter(context, mApps, this, mLauncher, this);
+ adapter.setEmptySearchText(res.getString(R.string.loading_apps_message));
+ mLayoutManager = adapter.getLayoutManager(context);
+ mAdapter = adapter;
+ }
+ mApps.setAdapter(mAdapter);
+ }
+
+ /**
+ * Sets the current set of apps.
+ */
+ public void setApps(List<AppInfo> apps) {
+ mApps.setApps(apps);
+ }
+
+ /**
+ * Adds new apps to the list.
+ */
+ public void addApps(List<AppInfo> apps) {
+ mApps.addApps(apps);
+ }
+
+ /**
+ * Updates existing apps in the list
+ */
+ public void updateApps(List<AppInfo> apps) {
+ mApps.updateApps(apps);
+ }
+
+ /**
+ * Removes some apps from the list.
+ */
+ public void removeApps(List<AppInfo> apps) {
+ mApps.removeApps(apps);
+ }
+
+ /**
+ * Scrolls this list view to the top.
+ */
+ public void scrollToTop() {
+ mAppsListView.scrollToPosition(0);
+ }
+
+ /**
+ * Returns the content view used for the launcher transitions.
+ */
+ public View getContentView() {
+ return findViewById(R.id.apps_list);
+ }
+
+ /**
+ * Returns the reveal view used for the launcher transitions.
+ */
+ public View getRevealView() {
+ return findViewById(R.id.apps_view_transition_overlay);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ boolean isRtl = (getResources().getConfiguration().getLayoutDirection() ==
+ LAYOUT_DIRECTION_RTL);
+ if (USE_LAYOUT == GRID_LAYOUT) {
+ ((AppsGridAdapter) mAdapter).setRtl(isRtl);
+ }
+ mSearchBar = (EditText) findViewById(R.id.app_search_box);
+ mSearchBar.addTextChangedListener(this);
+ mSearchBar.setOnEditorActionListener(this);
+ mAppsListView = (AppsContainerRecyclerView) findViewById(R.id.apps_list_view);
+ mAppsListView.setApps(mApps);
+ mAppsListView.setNumAppsPerRow(mNumAppsPerRow);
+ mAppsListView.setLayoutManager(mLayoutManager);
+ mAppsListView.setAdapter(mAdapter);
+ mAppsListView.setHasFixedSize(true);
+ if (isRtl) {
+ mAppsListView.setPadding(
+ mAppsListView.getPaddingLeft(),
+ mAppsListView.getPaddingTop(),
+ mAppsListView.getPaddingRight() + mContentMarginStart,
+ mAppsListView.getPaddingBottom());
+ } else {
+ mAppsListView.setPadding(
+ mAppsListView.getPaddingLeft() + mContentMarginStart,
+ mAppsListView.getPaddingTop(),
+ mAppsListView.getPaddingRight(),
+ mAppsListView.getPaddingBottom());
+ }
+ if (mItemDecoration != null) {
+ mAppsListView.addItemDecoration(mItemDecoration);
+ }
+ mPadding.set(getPaddingLeft(), getPaddingTop(), getPaddingRight(),
+ getPaddingBottom());
+ }
+
+ @Override
+ public void setInsets(Rect insets) {
+ setPadding(mPadding.left + insets.left, mPadding.top + insets.top,
+ mPadding.right + insets.right, mPadding.bottom + insets.bottom);
+ }
+
+ @Override
+ public boolean onTouch(View v, MotionEvent ev) {
+ if (ev.getAction() == MotionEvent.ACTION_DOWN ||
+ ev.getAction() == MotionEvent.ACTION_MOVE) {
+ mLastTouchDownPos.set((int) ev.getX(), (int) ev.getY());
+ }
+ return false;
+ }
+
+ @Override
+ public boolean onLongClick(View v) {
+ // Return early if this is not initiated from a touch
+ if (!v.isInTouchMode()) return false;
+ // When we have exited all apps or are in transition, disregard long clicks
+ if (!mLauncher.isAppsViewVisible() ||
+ mLauncher.getWorkspace().isSwitchingState()) return false;
+ // Return if global dragging is not enabled
+ if (!mLauncher.isDraggingEnabled()) return false;
+
+ // Start the drag
+ mLauncher.getWorkspace().beginDragShared(v, mLastTouchDownPos, this, false);
+
+ // We delay entering spring-loaded mode slightly to make sure the UI
+ // thready is free of any work.
+ postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ // We don't enter spring-loaded mode if the drag has been cancelled
+ if (mLauncher.getDragController().isDragging()) {
+ // Go into spring loaded mode (must happen before we startDrag())
+ mLauncher.enterSpringLoadedDragMode();
+ }
+ }
+ }, 150);
+
+ return false;
+ }
+
+ @Override
+ public boolean supportsFlingToDelete() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsAppInfoDropTarget() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsDeleteDropTarget() {
+ return true;
+ }
+
+ @Override
+ public float getIntrinsicIconScaleFactor() {
+ LauncherAppState app = LauncherAppState.getInstance();
+ DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
+ return (float) grid.allAppsIconSizePx / grid.iconSizePx;
+ }
+
+ @Override
+ public void onFlingToDeleteCompleted() {
+ // We just dismiss the drag when we fling, so cleanup here
+ mLauncher.exitSpringLoadedDragModeDelayed(true,
+ Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
+ mLauncher.unlockScreenOrientation(false);
+ }
+
+ @Override
+ public void onDropCompleted(View target, DropTarget.DragObject d, boolean isFlingToDelete,
+ boolean success) {
+ if (isFlingToDelete || !success || (target != mLauncher.getWorkspace() &&
+ !(target instanceof DeleteDropTarget) && !(target instanceof Folder))) {
+ // Exit spring loaded mode if we have not successfully dropped or have not handled the
+ // drop in Workspace
+ mLauncher.exitSpringLoadedDragModeDelayed(true,
+ Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
+ }
+ mLauncher.unlockScreenOrientation(false);
+
+ // Display an error message if the drag failed due to there not being enough space on the
+ // target layout we were dropping on.
+ if (!success) {
+ boolean showOutOfSpaceMessage = false;
+ if (target instanceof Workspace) {
+ int currentScreen = mLauncher.getCurrentWorkspaceScreen();
+ Workspace workspace = (Workspace) target;
+ CellLayout layout = (CellLayout) workspace.getChildAt(currentScreen);
+ ItemInfo itemInfo = (ItemInfo) d.dragInfo;
+ if (layout != null) {
+ layout.calculateSpans(itemInfo);
+ showOutOfSpaceMessage =
+ !layout.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY);
+ }
+ }
+ if (showOutOfSpaceMessage) {
+ mLauncher.showOutOfSpaceMessage(false);
+ }
+
+ d.deferDragViewCleanupPostAnimation = false;
+ }
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ // Do nothing
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ // Do nothing
+ }
+
+ @Override
+ public void afterTextChanged(final Editable s) {
+ if (s.toString().isEmpty()) {
+ mApps.setFilter(null);
+ } else {
+ String formatStr = getResources().getString(R.string.apps_view_no_search_results);
+ if (USE_LAYOUT == GRID_LAYOUT) {
+ ((AppsGridAdapter) mAdapter).setEmptySearchText(String.format(formatStr,
+ s.toString()));
+ } else {
+ ((AppsListAdapter) mAdapter).setEmptySearchText(String.format(formatStr,
+ s.toString()));
+ }
+
+ final String filterText = s.toString().toLowerCase().replaceAll("\\s+", "");
+ mApps.setFilter(new AlphabeticalAppsList.Filter() {
+ @Override
+ public boolean retainApp(AppInfo info, String sectionName) {
+ String title = info.title.toString();
+ return sectionName.toLowerCase().contains(filterText) ||
+ title.toLowerCase().replaceAll("\\s+", "").contains(filterText);
+ }
+ });
+ }
+ }
+
+ @Override
+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+ if (ALLOW_SINGLE_APP_LAUNCH && actionId == EditorInfo.IME_ACTION_DONE) {
+ // Skip the quick-launch if there isn't exactly one item
+ if (mApps.getSize() != 1) {
+ return false;
+ }
+
+ List<AlphabeticalAppsList.AdapterItem> items = mApps.getAdapterItems();
+ for (int i = 0; i < items.size(); i++) {
+ AlphabeticalAppsList.AdapterItem item = items.get(i);
+ if (!item.isSectionHeader) {
+ mAppsListView.getChildAt(i).performClick();
+ InputMethodManager imm = (InputMethodManager)
+ getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(getWindowToken(), 0);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public View getContent() {
+ return null;
+ }
+
+ @Override
+ public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) {
+ if (!toWorkspace) {
+ // Disable the focus so that the search bar doesn't get focus
+ mSearchBar.setFocusableInTouchMode(false);
+ }
+ }
+
+ @Override
+ public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) {
+ // Do nothing
+ }
+
+ @Override
+ public void onLauncherTransitionStep(Launcher l, float t) {
+ // Do nothing
+ }
+
+ @Override
+ public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
+ if (toWorkspace) {
+ // Clear the search bar
+ mSearchBar.setText("");
+ } else {
+ mSearchBar.setFocusableInTouchMode(true);
+ }
+ }
+}
diff --git a/src/com/android/launcher3/AppsCustomizePagedView.java b/src/com/android/launcher3/AppsCustomizePagedView.java
index c1aa19a..58bcf1d 100644
--- a/src/com/android/launcher3/AppsCustomizePagedView.java
+++ b/src/com/android/launcher3/AppsCustomizePagedView.java
@@ -29,133 +29,45 @@
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
-import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
-import android.os.Process;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
-import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.Toast;
import com.android.launcher3.DropTarget.DragObject;
+import com.android.launcher3.FocusHelper.PagedViewKeyListener;
import com.android.launcher3.compat.AppWidgetManagerCompat;
+import com.android.launcher3.util.Thunk;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * A simple callback interface which also provides the results of the task.
- */
-interface AsyncTaskCallback {
- void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data);
-}
-
-/**
- * The data needed to perform either of the custom AsyncTasks.
- */
-class AsyncTaskPageData {
- enum Type {
- LoadWidgetPreviewData
- }
-
- AsyncTaskPageData(int p, ArrayList<Object> l, int cw, int ch, AsyncTaskCallback bgR,
- AsyncTaskCallback postR, WidgetPreviewLoader w) {
- page = p;
- items = l;
- generatedImages = new ArrayList<Bitmap>();
- maxImageWidth = cw;
- maxImageHeight = ch;
- doInBackgroundCallback = bgR;
- postExecuteCallback = postR;
- widgetPreviewLoader = w;
- }
- void cleanup(boolean cancelled) {
- // Clean up any references to source/generated bitmaps
- if (generatedImages != null) {
- if (cancelled) {
- for (int i = 0; i < generatedImages.size(); i++) {
- widgetPreviewLoader.recycleBitmap(items.get(i), generatedImages.get(i));
- }
- }
- generatedImages.clear();
- }
- }
- int page;
- ArrayList<Object> items;
- ArrayList<Bitmap> sourceImages;
- ArrayList<Bitmap> generatedImages;
- int maxImageWidth;
- int maxImageHeight;
- AsyncTaskCallback doInBackgroundCallback;
- AsyncTaskCallback postExecuteCallback;
- WidgetPreviewLoader widgetPreviewLoader;
-}
-
-/**
- * A generic template for an async task used in AppsCustomize.
- */
-class AppsCustomizeAsyncTask extends AsyncTask<AsyncTaskPageData, Void, AsyncTaskPageData> {
- AppsCustomizeAsyncTask(int p, AsyncTaskPageData.Type ty) {
- page = p;
- threadPriority = Process.THREAD_PRIORITY_DEFAULT;
- dataType = ty;
- }
- @Override
- protected AsyncTaskPageData doInBackground(AsyncTaskPageData... params) {
- if (params.length != 1) return null;
- // Load each of the widget previews in the background
- params[0].doInBackgroundCallback.run(this, params[0]);
- return params[0];
- }
- @Override
- protected void onPostExecute(AsyncTaskPageData result) {
- // All the widget previews are loaded, so we can just callback to inflate the page
- result.postExecuteCallback.run(this, result);
- }
-
- void setThreadPriority(int p) {
- threadPriority = p;
- }
- void syncThreadPriority() {
- Process.setThreadPriority(threadPriority);
- }
-
- // The page that this async task is associated with
- AsyncTaskPageData.Type dataType;
- int page;
- int threadPriority;
-}
/**
* The Apps/Customize page that displays all the applications, widgets, and shortcuts.
*/
public class AppsCustomizePagedView extends PagedViewWithDraggableItems implements
- View.OnClickListener, View.OnKeyListener, DragSource,
+ View.OnClickListener, DragSource,
PagedViewWidget.ShortPressListener, LauncherTransitionable {
static final String TAG = "AppsCustomizePagedView";
private static Rect sTmpRect = new Rect();
+ private static final int[] sTempPosArray = new int[2];
/**
* The different content types that this paged view can show.
*/
public enum ContentType {
- Applications,
Widgets
}
- private ContentType mContentType = ContentType.Applications;
+ private ContentType mContentType = ContentType.Widgets;
// Refs
- private Launcher mLauncher;
+ @Thunk Launcher mLauncher;
private DragController mDragController;
private final LayoutInflater mLayoutInflater;
private final PackageManager mPackageManager;
@@ -164,7 +76,6 @@
private int mSaveInstanceStateItemIndex = -1;
// Content
- private ArrayList<AppInfo> mApps;
private ArrayList<Object> mWidgets;
// Caching
@@ -172,15 +83,10 @@
// Dimens
private int mContentWidth, mContentHeight;
- private int mWidgetCountX, mWidgetCountY;
- private PagedViewCellLayout mWidgetSpacingLayout;
- private int mNumAppsPages;
+ @Thunk int mWidgetCountX, mWidgetCountY;
private int mNumWidgetPages;
- private Rect mAllAppsPadding = new Rect();
- // Previews & outlines
- ArrayList<AppsCustomizeAsyncTask> mRunningTasks;
- private static final int sPageSleepDelay = 200;
+ private final PagedViewKeyListener mKeyListener = new PagedViewKeyListener();
private Runnable mInflateWidgetRunnable = null;
private Runnable mBindWidgetRunnable = null;
@@ -198,10 +104,6 @@
// Deferral of loading widget previews during launcher transitions
private boolean mInTransition;
- private ArrayList<AsyncTaskPageData> mDeferredSyncWidgetPageItems =
- new ArrayList<AsyncTaskPageData>();
- private ArrayList<Runnable> mDeferredPrepareLoadWidgetPreviewsTasks =
- new ArrayList<Runnable>();
WidgetPreviewLoader mWidgetPreviewLoader;
@@ -212,17 +114,14 @@
super(context, attrs);
mLayoutInflater = LayoutInflater.from(context);
mPackageManager = context.getPackageManager();
- mApps = new ArrayList<AppInfo>();
- mWidgets = new ArrayList<Object>();
+ mWidgets = new ArrayList<>();
mIconCache = (LauncherAppState.getInstance()).getIconCache();
- mRunningTasks = new ArrayList<AppsCustomizeAsyncTask>();
// Save the default widget preview background
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppsCustomizePagedView, 0, 0);
mWidgetCountX = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountX, 2);
mWidgetCountY = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountY, 2);
a.recycle();
- mWidgetSpacingLayout = new PagedViewCellLayout(getContext());
// The padding on the non-matched dimension for the default widget preview icons
// (top + bottom)
@@ -254,17 +153,13 @@
grid.edgeMarginPx, 2 * grid.edgeMarginPx);
}
- void setAllAppsPadding(Rect r) {
- mAllAppsPadding.set(r);
- }
-
void setWidgetsPageIndicatorPadding(int pageIndicatorHeight) {
setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), pageIndicatorHeight);
}
WidgetPreviewLoader getWidgetPreviewLoader() {
if (mWidgetPreviewLoader == null) {
- mWidgetPreviewLoader = new WidgetPreviewLoader(mLauncher);
+ mWidgetPreviewLoader = LauncherAppState.getInstance().getWidgetCache();
}
return mWidgetPreviewLoader;
}
@@ -275,22 +170,12 @@
int i = -1;
if (getPageCount() > 0) {
int currentPage = getCurrentPage();
- if (mContentType == ContentType.Applications) {
- AppsCustomizeCellLayout layout = (AppsCustomizeCellLayout) getPageAt(currentPage);
- ShortcutAndWidgetContainer childrenLayout = layout.getShortcutsAndWidgets();
- int numItemsPerPage = mCellCountX * mCellCountY;
- int childCount = childrenLayout.getChildCount();
- if (childCount > 0) {
- i = (currentPage * numItemsPerPage) + (childCount / 2);
- }
- } else if (mContentType == ContentType.Widgets) {
- int numApps = mApps.size();
+ if (mContentType == ContentType.Widgets) {
PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(currentPage);
int numItemsPerPage = mWidgetCountX * mWidgetCountY;
int childCount = layout.getChildCount();
if (childCount > 0) {
- i = numApps +
- (currentPage * numItemsPerPage) + (childCount / 2);
+ i = (currentPage * numItemsPerPage) + (childCount / 2);
}
} else {
throw new RuntimeException("Invalid ContentType");
@@ -312,13 +197,8 @@
int getPageForComponent(int index) {
if (index < 0) return 0;
- if (index < mApps.size()) {
- int numItemsPerPage = mCellCountX * mCellCountY;
- return (index / numItemsPerPage);
- } else {
- int numItemsPerPage = mWidgetCountX * mWidgetCountY;
- return (index - mApps.size()) / numItemsPerPage;
- }
+ int numItemsPerPage = mWidgetCountX * mWidgetCountY;
+ return index / numItemsPerPage;
}
/** Restores the page for an item at the specified index */
@@ -330,24 +210,14 @@
private void updatePageCounts() {
mNumWidgetPages = (int) Math.ceil(mWidgets.size() /
(float) (mWidgetCountX * mWidgetCountY));
- mNumAppsPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY));
}
protected void onDataReady(int width, int height) {
- // Now that the data is ready, we can calculate the content width, the number of cells to
- // use for each page
- LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
- mCellCountX = (int) grid.allAppsNumCols;
- mCellCountY = (int) grid.allAppsNumRows;
updatePageCounts();
// Force a measure to update recalculate the gaps
mContentWidth = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
mContentHeight = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();
- int widthSpec = MeasureSpec.makeMeasureSpec(mContentWidth, MeasureSpec.AT_MOST);
- int heightSpec = MeasureSpec.makeMeasureSpec(mContentHeight, MeasureSpec.AT_MOST);
- mWidgetSpacingLayout.measure(widthSpec, heightSpec);
final boolean hostIsTransitioning = getTabHost().isInTransition();
int page = getPageForComponent(mSaveInstanceStateItemIndex);
@@ -358,7 +228,7 @@
super.onLayout(changed, l, t, r, b);
if (!isDataReady()) {
- if ((!mApps.isEmpty()) && !mWidgets.isEmpty()) {
+ if (!mWidgets.isEmpty()) {
post(new Runnable() {
// This code triggers requestLayout so must be posted outside of the
// layout pass.
@@ -436,7 +306,7 @@
@Override
public void onClick(View v) {
// When we have exited all apps or are in transition, disregard clicks
- if (!mLauncher.isAllAppsVisible()
+ if (!mLauncher.isWidgetsViewVisible()
|| mLauncher.getWorkspace().isSwitchingState()
|| !(v instanceof PagedViewWidget)) return;
@@ -449,20 +319,11 @@
mWidgetInstructionToast.show();
}
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- return FocusHelper.handleAppsCustomizeKeyEvent(v, keyCode, event);
- }
-
/*
* PagedViewWithDraggableItems implementation
*/
@Override
protected void determineDraggingStart(android.view.MotionEvent ev) {
- // Disable dragging by pulling an app down for now.
- }
-
- private void beginDraggingApplication(View v) {
- mLauncher.getWorkspace().beginDragShared(v, this);
}
static Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) {
@@ -529,8 +390,7 @@
info.boundWidget = hostView;
mWidgetCleanupState = WIDGET_INFLATED;
hostView.setVisibility(INVISIBLE);
- int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(info.spanX,
- info.spanY, info, false);
+ int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(info, false);
// We want the first widget layout to be the correct size. This will be important
// for width size reporting to the AppWidgetManager.
@@ -599,7 +459,7 @@
}
}
- private boolean beginDraggingWidget(View v) {
+ private boolean beginDraggingWidget(PagedViewWidget v) {
mDraggingWidget = true;
// Get the widget preview as the drag representation
ImageView image = (ImageView) v.findViewById(R.id.widget_preview);
@@ -627,24 +487,18 @@
PendingAddWidgetInfo createWidgetInfo = mCreateWidgetInfo;
createItemInfo = createWidgetInfo;
- int spanX = createItemInfo.spanX;
- int spanY = createItemInfo.spanY;
- int[] size = mLauncher.getWorkspace().estimateItemSize(spanX, spanY,
- createWidgetInfo, true);
+ int[] size = mLauncher.getWorkspace().estimateItemSize(createWidgetInfo, true);
FastBitmapDrawable previewDrawable = (FastBitmapDrawable) image.getDrawable();
float minScale = 1.25f;
- int maxWidth, maxHeight;
- maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]);
- maxHeight = Math.min((int) (previewDrawable.getIntrinsicHeight() * minScale), size[1]);
+ int maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]);
int[] previewSizeBeforeScale = new int[1];
preview = getWidgetPreviewLoader().generateWidgetPreview(createWidgetInfo.info,
- spanX, spanY, maxWidth, maxHeight, null, previewSizeBeforeScale);
-
+ maxWidth, null, previewSizeBeforeScale);
// Compare the size of the drag preview to the preview in the AppsCustomize tray
int previewWidthInAppsCustomize = Math.min(previewSizeBeforeScale[0],
- getWidgetPreviewLoader().maxWidthForWidgetPreview(spanX));
+ v.getActualItemWidth());
scale = previewWidthInAppsCustomize / (float) preview.getWidth();
// The bitmap in the AppsCustomize tray is always the the same size, so there
@@ -683,12 +537,12 @@
protected boolean beginDragging(final View v) {
if (!super.beginDragging(v)) return false;
- if (v instanceof BubbleTextView) {
- beginDraggingApplication(v);
- } else if (v instanceof PagedViewWidget) {
- if (!beginDraggingWidget(v)) {
+ if (v instanceof PagedViewWidget) {
+ if (!beginDraggingWidget((PagedViewWidget) v)) {
return false;
}
+ } else {
+ Log.e(TAG, "Unexpected dragging view: " + v);
}
// We delay entering spring-loaded mode slightly to make sure the UI
@@ -737,7 +591,7 @@
public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) {
mInTransition = true;
if (toWorkspace) {
- cancelAllTasks();
+ cancelAllTasks(false);
}
}
@@ -752,15 +606,10 @@
@Override
public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
mInTransition = false;
- for (AsyncTaskPageData d : mDeferredSyncWidgetPageItems) {
- onSyncWidgetPageItems(d, false);
- }
- mDeferredSyncWidgetPageItems.clear();
- for (Runnable r : mDeferredPrepareLoadWidgetPreviewsTasks) {
- r.run();
- }
- mDeferredPrepareLoadWidgetPreviewsTasks.clear();
mForceDrawAllChildrenNextFrame = !toWorkspace;
+ if (!toWorkspace) {
+ loadPreviewsForPage(getNextPage());
+ }
}
@Override
@@ -829,45 +678,26 @@
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- cancelAllTasks();
+ cancelAllTasks(true);
}
@Override
public void trimMemory() {
super.trimMemory();
- clearAllWidgetPages();
+ cancelAllTasks(true);
}
- public void clearAllWidgetPages() {
- cancelAllTasks();
- int count = getChildCount();
- for (int i = 0; i < count; i++) {
- View v = getPageAt(i);
- if (v instanceof PagedViewGridLayout) {
- ((PagedViewGridLayout) v).removeAllViewsOnPage();
- mDirtyPageContent.set(i, true);
+ private void cancelAllTasks(boolean clearCompletedTasks) {
+ for (int page = getPageCount() - 1; page >= 0; page--) {
+ final PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page);
+ if (layout != null) {
+ for (int i = 0; i < layout.getChildCount(); i++) {
+ ((PagedViewWidget) layout.getChildAt(i)).deletePreview(clearCompletedTasks);
+ }
}
}
}
- private void cancelAllTasks() {
- // Clean up all the async tasks
- Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
- while (iter.hasNext()) {
- AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
- task.cancel(false);
- iter.remove();
- mDirtyPageContent.set(task.page, true);
-
- // We've already preallocated the views for the data to load into, so clear them as well
- View v = getPageAt(task.page);
- if (v instanceof PagedViewGridLayout) {
- ((PagedViewGridLayout) v).removeAllViewsOnPage();
- }
- }
- mDeferredSyncWidgetPageItems.clear();
- mDeferredPrepareLoadWidgetPreviewsTasks.clear();
- }
public void setContentType(ContentType type) {
// Widgets appear to be cleared every time you leave, always force invalidate for them
@@ -882,53 +712,6 @@
return mContentType;
}
- protected void snapToPage(int whichPage, int delta, int duration) {
- super.snapToPage(whichPage, delta, duration);
-
- // Update the thread priorities given the direction lookahead
- Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
- while (iter.hasNext()) {
- AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
- int pageIndex = task.page;
- if ((mNextPage > mCurrentPage && pageIndex >= mCurrentPage) ||
- (mNextPage < mCurrentPage && pageIndex <= mCurrentPage)) {
- task.setThreadPriority(getThreadPriorityForPage(pageIndex));
- } else {
- task.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
- }
- }
- }
-
- /*
- * Apps PagedView implementation
- */
- private void setVisibilityOnChildren(ViewGroup layout, int visibility) {
- int childCount = layout.getChildCount();
- for (int i = 0; i < childCount; ++i) {
- layout.getChildAt(i).setVisibility(visibility);
- }
- }
- private void setupPage(AppsCustomizeCellLayout layout) {
- layout.setGridSize(mCellCountX, mCellCountY);
-
- // Note: We force a measure here to get around the fact that when we do layout calculations
- // immediately after syncing, we don't have a proper width. That said, we already know the
- // expected page width, so we can actually optimize by hiding all the TextView-based
- // children that are expensive to measure, and let that happen naturally later.
- setVisibilityOnChildren(layout, View.GONE);
- int widthSpec = MeasureSpec.makeMeasureSpec(mContentWidth, MeasureSpec.AT_MOST);
- int heightSpec = MeasureSpec.makeMeasureSpec(mContentHeight, MeasureSpec.AT_MOST);
- layout.measure(widthSpec, heightSpec);
-
- Drawable bg = getContext().getResources().getDrawable(R.drawable.quantum_panel);
- if (bg != null) {
- bg.setAlpha(mPageBackgroundsVisible ? 255: 0);
- layout.setBackground(bg);
- }
-
- setVisibilityOnChildren(layout, View.VISIBLE);
- }
-
public void setPageBackgroundsVisible(boolean visible) {
mPageBackgroundsVisible = visible;
int childCount = getChildCount();
@@ -940,141 +723,6 @@
}
}
- public void syncAppsPageItems(int page, boolean immediate) {
- // ensure that we have the right number of items on the pages
- final boolean isRtl = isLayoutRtl();
- int numCells = mCellCountX * mCellCountY;
- int startIndex = page * numCells;
- int endIndex = Math.min(startIndex + numCells, mApps.size());
- AppsCustomizeCellLayout layout = (AppsCustomizeCellLayout) getPageAt(page);
-
- layout.removeAllViewsOnPage();
- ArrayList<Object> items = new ArrayList<Object>();
- ArrayList<Bitmap> images = new ArrayList<Bitmap>();
- for (int i = startIndex; i < endIndex; ++i) {
- AppInfo info = mApps.get(i);
- BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(
- R.layout.apps_customize_application, layout, false);
- icon.applyFromApplicationInfo(info);
- icon.setOnClickListener(mLauncher);
- icon.setOnLongClickListener(this);
- icon.setOnTouchListener(this);
- icon.setOnKeyListener(this);
- icon.setOnFocusChangeListener(layout.mFocusHandlerView);
-
- int index = i - startIndex;
- int x = index % mCellCountX;
- int y = index / mCellCountX;
- if (isRtl) {
- x = mCellCountX - x - 1;
- }
- layout.addViewToCellLayout(icon, -1, i, new CellLayout.LayoutParams(x,y, 1,1), false);
-
- items.add(info);
- images.add(info.iconBitmap);
- }
-
- enableHwLayersOnVisiblePages();
- }
-
- /**
- * A helper to return the priority for loading of the specified widget page.
- */
- private int getWidgetPageLoadPriority(int page) {
- // If we are snapping to another page, use that index as the target page index
- int toPage = mCurrentPage;
- if (mNextPage > -1) {
- toPage = mNextPage;
- }
-
- // We use the distance from the target page as an initial guess of priority, but if there
- // are no pages of higher priority than the page specified, then bump up the priority of
- // the specified page.
- Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
- int minPageDiff = Integer.MAX_VALUE;
- while (iter.hasNext()) {
- AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
- minPageDiff = Math.abs(task.page - toPage);
- }
-
- int rawPageDiff = Math.abs(page - toPage);
- return rawPageDiff - Math.min(rawPageDiff, minPageDiff);
- }
- /**
- * Return the appropriate thread priority for loading for a given page (we give the current
- * page much higher priority)
- */
- private int getThreadPriorityForPage(int page) {
- // TODO-APPS_CUSTOMIZE: detect number of cores and set thread priorities accordingly below
- int pageDiff = getWidgetPageLoadPriority(page);
- if (pageDiff <= 0) {
- return Process.THREAD_PRIORITY_LESS_FAVORABLE;
- } else if (pageDiff <= 1) {
- return Process.THREAD_PRIORITY_LOWEST;
- } else {
- return Process.THREAD_PRIORITY_LOWEST;
- }
- }
- private int getSleepForPage(int page) {
- int pageDiff = getWidgetPageLoadPriority(page);
- return Math.max(0, pageDiff * sPageSleepDelay);
- }
- /**
- * Creates and executes a new AsyncTask to load a page of widget previews.
- */
- private void prepareLoadWidgetPreviewsTask(int page, ArrayList<Object> widgets,
- int cellWidth, int cellHeight, int cellCountX) {
-
- // Prune all tasks that are no longer needed
- Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
- while (iter.hasNext()) {
- AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
- int taskPage = task.page;
- if (taskPage < getAssociatedLowerPageBound(mCurrentPage) ||
- taskPage > getAssociatedUpperPageBound(mCurrentPage)) {
- task.cancel(false);
- iter.remove();
- } else {
- task.setThreadPriority(getThreadPriorityForPage(taskPage));
- }
- }
-
- // We introduce a slight delay to order the loading of side pages so that we don't thrash
- final int sleepMs = getSleepForPage(page);
- AsyncTaskPageData pageData = new AsyncTaskPageData(page, widgets, cellWidth, cellHeight,
- new AsyncTaskCallback() {
- @Override
- public void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data) {
- try {
- try {
- Thread.sleep(sleepMs);
- } catch (Exception e) {}
- loadWidgetPreviewsInBackground(task, data);
- } finally {
- if (task.isCancelled()) {
- data.cleanup(true);
- }
- }
- }
- },
- new AsyncTaskCallback() {
- @Override
- public void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data) {
- mRunningTasks.remove(task);
- if (task.isCancelled()) return;
- // do cleanup inside onSyncWidgetPageItems
- onSyncWidgetPageItems(data, false);
- }
- }, getWidgetPreviewLoader());
-
- // Ensure that the task is appropriately prioritized and runs in parallel
- AppsCustomizeAsyncTask t = new AppsCustomizeAsyncTask(page,
- AsyncTaskPageData.Type.LoadWidgetPreviewData);
- t.setThreadPriority(getThreadPriorityForPage(page));
- t.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, pageData);
- mRunningTasks.add(t);
- }
-
/*
* Widgets PagedView implementation
*/
@@ -1141,7 +789,7 @@
widget.setOnClickListener(this);
widget.setOnLongClickListener(this);
widget.setOnTouchListener(this);
- widget.setOnKeyListener(this);
+ widget.setOnKeyListener(mKeyListener);
// Layout each widget
int ix = i % mWidgetCountX;
@@ -1165,96 +813,18 @@
layout.addView(widget, lp);
}
- // wait until a call on onLayout to start loading, because
- // PagedViewWidget.getPreviewSize() will return 0 if it hasn't been laid out
- // TODO: can we do a measure/layout immediately?
- layout.setOnLayoutListener(new Runnable() {
- public void run() {
- // Load the widget previews
- int maxPreviewWidth = cellWidth;
- int maxPreviewHeight = cellHeight;
- if (layout.getChildCount() > 0) {
- PagedViewWidget w = (PagedViewWidget) layout.getChildAt(0);
- int[] maxSize = w.getPreviewSize();
- maxPreviewWidth = maxSize[0];
- maxPreviewHeight = maxSize[1];
- }
-
- getWidgetPreviewLoader().setPreviewSize(
- maxPreviewWidth, maxPreviewHeight, mWidgetSpacingLayout);
- if (immediate) {
- AsyncTaskPageData data = new AsyncTaskPageData(page, items,
- maxPreviewWidth, maxPreviewHeight, null, null, getWidgetPreviewLoader());
- loadWidgetPreviewsInBackground(null, data);
- onSyncWidgetPageItems(data, immediate);
- } else {
- if (mInTransition) {
- mDeferredPrepareLoadWidgetPreviewsTasks.add(this);
- } else {
- prepareLoadWidgetPreviewsTask(page, items,
- maxPreviewWidth, maxPreviewHeight, mWidgetCountX);
- }
- }
- layout.setOnLayoutListener(null);
- }
- });
- }
- private void loadWidgetPreviewsInBackground(AppsCustomizeAsyncTask task,
- AsyncTaskPageData data) {
- // loadWidgetPreviewsInBackground can be called without a task to load a set of widget
- // previews synchronously
- if (task != null) {
- // Ensure that this task starts running at the correct priority
- task.syncThreadPriority();
- }
-
- // Load each of the widget/shortcut previews
- ArrayList<Object> items = data.items;
- ArrayList<Bitmap> images = data.generatedImages;
- int count = items.size();
- for (int i = 0; i < count; ++i) {
- if (task != null) {
- // Ensure we haven't been cancelled yet
- if (task.isCancelled()) break;
- // Before work on each item, ensure that this task is running at the correct
- // priority
- task.syncThreadPriority();
- }
-
- images.add(getWidgetPreviewLoader().getPreview(items.get(i)));
+ if (immediate && !mInTransition) {
+ loadPreviewsForPage(page);
}
}
- private void onSyncWidgetPageItems(AsyncTaskPageData data, boolean immediatelySyncItems) {
- if (!immediatelySyncItems && mInTransition) {
- mDeferredSyncWidgetPageItems.add(data);
- return;
- }
- try {
- int page = data.page;
- PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page);
+ private void loadPreviewsForPage(int page) {
+ final PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page);
- ArrayList<Object> items = data.items;
- int count = items.size();
- for (int i = 0; i < count; ++i) {
- PagedViewWidget widget = (PagedViewWidget) layout.getChildAt(i);
- if (widget != null) {
- Bitmap preview = data.generatedImages.get(i);
- widget.applyPreview(new FastBitmapDrawable(preview), i);
- }
+ if (layout != null) {
+ for (int i = 0; i < layout.getChildCount(); i++) {
+ ((PagedViewWidget) layout.getChildAt(i)).ensurePreview();
}
-
- enableHwLayersOnVisiblePages();
-
- // Update all thread priorities
- Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
- while (iter.hasNext()) {
- AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
- int pageIndex = task.page;
- task.setThreadPriority(getThreadPriorityForPage(pageIndex));
- }
- } finally {
- data.cleanup(false);
}
}
@@ -1263,17 +833,10 @@
disablePagedViewAnimations();
removeAllViews();
- cancelAllTasks();
+ cancelAllTasks(true);
Context context = getContext();
- if (mContentType == ContentType.Applications) {
- for (int i = 0; i < mNumAppsPages; ++i) {
- AppsCustomizeCellLayout layout = new AppsCustomizeCellLayout(context);
- setupPage(layout);
- addView(layout, new PagedView.LayoutParams(LayoutParams.MATCH_PARENT,
- LayoutParams.MATCH_PARENT));
- }
- } else if (mContentType == ContentType.Widgets) {
+ if (mContentType == ContentType.Widgets) {
for (int j = 0; j < mNumWidgetPages; ++j) {
PagedViewGridLayout layout = new PagedViewGridLayout(context, mWidgetCountX,
mWidgetCountY);
@@ -1293,7 +856,7 @@
if (mContentType == ContentType.Widgets) {
syncWidgetPageItems(page, immediate);
} else {
- syncAppsPageItems(page, immediate);
+ Log.e(TAG, "Unexpected ContentType");
}
}
@@ -1376,6 +939,17 @@
mSaveInstanceStateItemIndex = -1;
}
+ @Override
+ protected void onPageBeginMoving() {
+ super.onPageBeginMoving();
+ if (!mInTransition) {
+ getVisiblePages(sTempPosArray);
+ for (int i = sTempPosArray[0]; i <= sTempPosArray[1]; i++) {
+ loadPreviewsForPage(i);
+ }
+ }
+ }
+
/*
* AllAppsView implementation
*/
@@ -1385,7 +959,7 @@
}
/**
- * We should call thise method whenever the core data changes (mApps, mWidgets) so that we can
+ * We should call thise method whenever the core data changes (mWidgets) so that we can
* appropriately determine when to invalidate the PagedView page data. In cases where the data
* has yet to be set, we can requestLayout() and wait for onDataReady() to be called in the
* next onMeasure() pass, which will trigger an invalidatePageData() itself.
@@ -1396,78 +970,17 @@
// request a layout to trigger the page data when ready.
requestLayout();
} else {
- cancelAllTasks();
+ cancelAllTasks(false);
invalidatePageData();
}
}
- public void setApps(ArrayList<AppInfo> list) {
- mApps = list;
- Collections.sort(mApps, LauncherModel.getAppNameComparator());
- updatePageCountsAndInvalidateData();
- }
-
- public ArrayList<AppInfo> getApps() {
- return mApps;
- }
-
- private void addAppsWithoutInvalidate(ArrayList<AppInfo> list) {
- // We add it in place, in alphabetical order
- int count = list.size();
- for (int i = 0; i < count; ++i) {
- AppInfo info = list.get(i);
- int index = Collections.binarySearch(mApps, info, LauncherModel.getAppNameComparator());
- if (index < 0) {
- mApps.add(-(index + 1), info);
- }
- }
- }
- public void addApps(ArrayList<AppInfo> list) {
- addAppsWithoutInvalidate(list);
- updatePageCountsAndInvalidateData();
- }
- private int findAppByComponent(List<AppInfo> list, AppInfo item) {
- ComponentName removeComponent = item.intent.getComponent();
- int length = list.size();
- for (int i = 0; i < length; ++i) {
- AppInfo info = list.get(i);
- if (info.user.equals(item.user)
- && info.intent.getComponent().equals(removeComponent)) {
- return i;
- }
- }
- return -1;
- }
- private void removeAppsWithoutInvalidate(ArrayList<AppInfo> list) {
- // loop through all the apps and remove apps that have the same component
- int length = list.size();
- for (int i = 0; i < length; ++i) {
- AppInfo info = list.get(i);
- int removeIndex = findAppByComponent(mApps, info);
- if (removeIndex > -1) {
- mApps.remove(removeIndex);
- }
- }
- }
- public void removeApps(ArrayList<AppInfo> appInfos) {
- removeAppsWithoutInvalidate(appInfos);
- updatePageCountsAndInvalidateData();
- }
- public void updateApps(ArrayList<AppInfo> list) {
- // We remove and re-add the updated applications list because it's properties may have
- // changed (ie. the title), and this will ensure that the items will be in their proper
- // place in the list.
- removeAppsWithoutInvalidate(list);
- addAppsWithoutInvalidate(list);
- updatePageCountsAndInvalidateData();
- }
-
public void reset() {
// If we have reset, then we should not continue to restore the previous state
mSaveInstanceStateItemIndex = -1;
- if (mContentType != ContentType.Applications) {
- setContentType(ContentType.Applications);
+ if (mContentType != ContentType.Widgets) {
+ setContentType(ContentType.Widgets);
}
if (mCurrentPage != 0) {
@@ -1481,7 +994,6 @@
public void dumpState() {
// TODO: Dump information related to current list of Applications, Widgets, etc.
- AppInfo.dumpApplicationInfoList(TAG, "mApps", mApps);
dumpAppWidgetProviderInfoList(TAG, "mWidgets", mWidgets);
}
@@ -1508,7 +1020,7 @@
// should stop this now.
// Stop all background tasks
- cancelAllTasks();
+ cancelAllTasks(true);
}
/*
@@ -1536,10 +1048,7 @@
int stringId = R.string.default_scroll_format;
int count = 0;
- if (mContentType == ContentType.Applications) {
- stringId = R.string.apps_customize_apps_scroll_format;
- count = mNumAppsPages;
- } else if (mContentType == ContentType.Widgets) {
+ if (mContentType == ContentType.Widgets) {
stringId = R.string.apps_customize_widgets_scroll_format;
count = mNumWidgetPages;
} else {
diff --git a/src/com/android/launcher3/AppsCustomizeTabHost.java b/src/com/android/launcher3/AppsCustomizeTabHost.java
index a271712..5e2f05c 100644
--- a/src/com/android/launcher3/AppsCustomizeTabHost.java
+++ b/src/com/android/launcher3/AppsCustomizeTabHost.java
@@ -27,7 +27,6 @@
public class AppsCustomizeTabHost extends FrameLayout implements LauncherTransitionable, Insettable {
static final String LOG_TAG = "AppsCustomizeTabHost";
- private static final String APPS_TAB_TAG = "APPS";
private static final String WIDGETS_TAB_TAG = "WIDGETS";
private AppsCustomizePagedView mPagedView;
@@ -50,10 +49,6 @@
mPagedView.setContentType(type);
}
- public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) {
- setContentTypeImmediate(type);
- }
-
@Override
public void setInsets(Rect insets) {
mInsets.set(insets);
@@ -79,27 +74,38 @@
}
/**
+ * Returns the content view used for the launcher transitions.
+ */
+ public View getContentView() {
+ return findViewById(R.id.apps_customize_pane_content);
+ }
+
+ /**
+ * Returns the reveal view used for the launcher transitions.
+ */
+ public View getRevealView() {
+ return findViewById(R.id.fake_page);
+ }
+
+ /**
+ * Returns the page indicators view.
+ */
+ public View getPageIndicators() {
+ return findViewById(R.id.apps_customize_page_indicator);
+ }
+
+ /**
* Returns the content type for the specified tab tag.
*/
public AppsCustomizePagedView.ContentType getContentTypeForTabTag(String tag) {
- if (tag.equals(APPS_TAB_TAG)) {
- return AppsCustomizePagedView.ContentType.Applications;
- } else if (tag.equals(WIDGETS_TAB_TAG)) {
- return AppsCustomizePagedView.ContentType.Widgets;
- }
- return AppsCustomizePagedView.ContentType.Applications;
+ return AppsCustomizePagedView.ContentType.Widgets;
}
/**
* Returns the tab tag for a given content type.
*/
public String getTabTagForContentType(AppsCustomizePagedView.ContentType type) {
- if (type == AppsCustomizePagedView.ContentType.Applications) {
- return APPS_TAB_TAG;
- } else if (type == AppsCustomizePagedView.ContentType.Widgets) {
- return WIDGETS_TAB_TAG;
- }
- return APPS_TAB_TAG;
+ return WIDGETS_TAB_TAG;
}
/**
@@ -199,6 +205,7 @@
ViewGroup parent = (ViewGroup) getParent();
if (parent == null) return;
+ View appsView = ((Launcher) getContext()).getAppsView();
View overviewPanel = ((Launcher) getContext()).getOverviewPanel();
final int count = parent.getChildCount();
if (!isChildrenDrawingOrderEnabled()) {
@@ -207,7 +214,8 @@
if (child == this) {
break;
} else {
- if (child.getVisibility() == GONE || child == overviewPanel) {
+ if (child.getVisibility() == GONE || child == overviewPanel ||
+ child == appsView) {
continue;
}
child.setVisibility(visibility);
diff --git a/src/com/android/launcher3/AppsGridAdapter.java b/src/com/android/launcher3/AppsGridAdapter.java
new file mode 100644
index 0000000..96d9716
--- /dev/null
+++ b/src/com/android/launcher3/AppsGridAdapter.java
@@ -0,0 +1,245 @@
+package com.android.launcher3;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.support.v7.widget.GridLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.android.launcher3.util.Thunk;
+
+import java.util.List;
+
+
+/**
+ * The grid view adapter of all the apps.
+ */
+class AppsGridAdapter extends RecyclerView.Adapter<AppsGridAdapter.ViewHolder> {
+
+ public static final String TAG = "AppsGridAdapter";
+
+ private static final int SECTION_BREAK_VIEW_TYPE = 0;
+ private static final int ICON_VIEW_TYPE = 1;
+ private static final int EMPTY_VIEW_TYPE = 2;
+
+ /**
+ * ViewHolder for each icon.
+ */
+ public static class ViewHolder extends RecyclerView.ViewHolder {
+ public View mContent;
+ public boolean mIsSectionRow;
+ public boolean mIsEmptyRow;
+
+ public ViewHolder(View v, boolean isSectionRow, boolean isEmptyRow) {
+ super(v);
+ mContent = v;
+ mIsSectionRow = isSectionRow;
+ mIsEmptyRow = isEmptyRow;
+ }
+ }
+
+ /**
+ * Helper class to size the grid items.
+ */
+ public class GridSpanSizer extends GridLayoutManager.SpanSizeLookup {
+ @Override
+ public int getSpanSize(int position) {
+ if (mApps.hasNoFilteredResults()) {
+ // Empty view spans full width
+ return mAppsPerRow;
+ }
+
+ if (mApps.getAdapterItems().get(position).isSectionHeader) {
+ // Section break spans full width
+ return mAppsPerRow;
+ } else {
+ return 1;
+ }
+ }
+ }
+
+ /**
+ * Helper class to draw the section headers
+ */
+ public class GridItemDecoration extends RecyclerView.ItemDecoration {
+
+ @Override
+ public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
+ List<AlphabeticalAppsList.AdapterItem> items = mApps.getAdapterItems();
+ for (int i = 0; i < parent.getChildCount(); i++) {
+ View child = parent.getChildAt(i);
+ ViewHolder holder = (ViewHolder) parent.getChildViewHolder(child);
+ if (holder != null) {
+ GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams)
+ child.getLayoutParams();
+ if (!holder.mIsSectionRow && !holder.mIsEmptyRow && !lp.isItemRemoved()) {
+ if (items.get(holder.getAdapterPosition() - 1).isSectionHeader) {
+ // Draw at the parent
+ AlphabeticalAppsList.AdapterItem item =
+ items.get(holder.getAdapterPosition());
+ String section = item.sectionName;
+ mSectionTextPaint.getTextBounds(section, 0, section.length(),
+ mTmpBounds);
+ if (mIsRtl) {
+ int left = parent.getWidth() - mPaddingStart - mStartMargin;
+ c.drawText(section, left + (mStartMargin - mTmpBounds.width()) / 2,
+ child.getTop() + (2 * child.getPaddingTop()) +
+ mTmpBounds.height(), mSectionTextPaint);
+ } else {
+ int left = mPaddingStart;
+ c.drawText(section, left + (mStartMargin - mTmpBounds.width()) / 2,
+ child.getTop() + (2 * child.getPaddingTop()) +
+ mTmpBounds.height(), mSectionTextPaint);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
+ RecyclerView.State state) {
+ // Do nothing
+ }
+ }
+
+ private LayoutInflater mLayoutInflater;
+ @Thunk AlphabeticalAppsList mApps;
+ private GridSpanSizer mGridSizer;
+ private GridItemDecoration mItemDecoration;
+ private View.OnTouchListener mTouchListener;
+ private View.OnClickListener mIconClickListener;
+ private View.OnLongClickListener mIconLongClickListener;
+ @Thunk int mAppsPerRow;
+ @Thunk boolean mIsRtl;
+ private String mEmptySearchText;
+
+ // Section drawing
+ @Thunk int mPaddingStart;
+ @Thunk int mStartMargin;
+ @Thunk Paint mSectionTextPaint;
+ @Thunk Rect mTmpBounds = new Rect();
+
+
+ public AppsGridAdapter(Context context, AlphabeticalAppsList apps, int appsPerRow,
+ View.OnTouchListener touchListener, View.OnClickListener iconClickListener,
+ View.OnLongClickListener iconLongClickListener) {
+ Resources res = context.getResources();
+ mApps = apps;
+ mAppsPerRow = appsPerRow;
+ mGridSizer = new GridSpanSizer();
+ mItemDecoration = new GridItemDecoration();
+ mLayoutInflater = LayoutInflater.from(context);
+ mTouchListener = touchListener;
+ mIconClickListener = iconClickListener;
+ mIconLongClickListener = iconLongClickListener;
+ mStartMargin = res.getDimensionPixelSize(R.dimen.apps_grid_view_start_margin);
+ mPaddingStart = res.getDimensionPixelSize(R.dimen.apps_container_inset);
+ mSectionTextPaint = new Paint();
+ mSectionTextPaint.setTextSize(res.getDimensionPixelSize(
+ R.dimen.apps_view_section_text_size));
+ mSectionTextPaint.setColor(res.getColor(R.color.apps_view_section_text_color));
+ mSectionTextPaint.setAntiAlias(true);
+ }
+
+ /**
+ * Sets whether we are in RTL mode.
+ */
+ public void setRtl(boolean rtl) {
+ mIsRtl = rtl;
+ }
+
+ /**
+ * Sets the text to show when there are no apps.
+ */
+ public void setEmptySearchText(String query) {
+ mEmptySearchText = query;
+ }
+
+ /**
+ * Returns the grid layout manager.
+ */
+ public GridLayoutManager getLayoutManager(Context context) {
+ GridLayoutManager layoutMgr = new GridLayoutManager(context, mAppsPerRow,
+ GridLayoutManager.VERTICAL, false);
+ layoutMgr.setSpanSizeLookup(mGridSizer);
+ return layoutMgr;
+ }
+
+ /**
+ * Returns the item decoration for the recycler view.
+ */
+ public RecyclerView.ItemDecoration getItemDecoration() {
+ return mItemDecoration;
+ }
+
+ /**
+ * Returns the left padding for the recycler view.
+ */
+ public int getContentMarginStart() {
+ return mStartMargin;
+ }
+
+ @Override
+ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ switch (viewType) {
+ case EMPTY_VIEW_TYPE:
+ return new ViewHolder(mLayoutInflater.inflate(R.layout.apps_empty_view, parent,
+ false), false /* isSectionRow */, true /* isEmptyRow */);
+ case SECTION_BREAK_VIEW_TYPE:
+ return new ViewHolder(new View(parent.getContext()), true /* isSectionRow */,
+ false /* isEmptyRow */);
+ case ICON_VIEW_TYPE:
+ BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(
+ R.layout.apps_grid_row_icon_view, parent, false);
+ icon.setOnTouchListener(mTouchListener);
+ icon.setOnClickListener(mIconClickListener);
+ icon.setOnLongClickListener(mIconLongClickListener);
+ icon.setFocusable(true);
+ return new ViewHolder(icon, false /* isSectionRow */, false /* isEmptyRow */);
+ default:
+ throw new RuntimeException("Unexpected view type");
+ }
+ }
+
+ @Override
+ public void onBindViewHolder(ViewHolder holder, int position) {
+ switch (holder.getItemViewType()) {
+ case ICON_VIEW_TYPE:
+ AppInfo info = mApps.getAdapterItems().get(position).appInfo;
+ BubbleTextView icon = (BubbleTextView) holder.mContent;
+ icon.applyFromApplicationInfo(info);
+ break;
+ case EMPTY_VIEW_TYPE:
+ TextView emptyViewText = (TextView) holder.mContent.findViewById(R.id.empty_text);
+ emptyViewText.setText(mEmptySearchText);
+ break;
+ }
+ }
+
+ @Override
+ public int getItemCount() {
+ if (mApps.hasNoFilteredResults()) {
+ // For the empty view
+ return 1;
+ }
+ return mApps.getAdapterItems().size();
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ if (mApps.hasNoFilteredResults()) {
+ return EMPTY_VIEW_TYPE;
+ } else if (mApps.getAdapterItems().get(position).isSectionHeader) {
+ return SECTION_BREAK_VIEW_TYPE;
+ }
+ return ICON_VIEW_TYPE;
+ }
+}
diff --git a/src/com/android/launcher3/AppsListAdapter.java b/src/com/android/launcher3/AppsListAdapter.java
new file mode 100644
index 0000000..ffd3092
--- /dev/null
+++ b/src/com/android/launcher3/AppsListAdapter.java
@@ -0,0 +1,143 @@
+package com.android.launcher3;
+
+import android.content.Context;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+/**
+ * The linear list view adapter for all the apps.
+ */
+class AppsListAdapter extends RecyclerView.Adapter<AppsListAdapter.ViewHolder> {
+
+ /**
+ * ViewHolder for each row.
+ */
+ public static class ViewHolder extends RecyclerView.ViewHolder {
+ public View mContent;
+
+ public ViewHolder(View v) {
+ super(v);
+ mContent = v;
+ }
+ }
+
+ private static final int SECTION_BREAK_VIEW_TYPE = 0;
+ private static final int ICON_VIEW_TYPE = 1;
+ private static final int EMPTY_VIEW_TYPE = 2;
+
+ private LayoutInflater mLayoutInflater;
+ private AlphabeticalAppsList mApps;
+ private View.OnTouchListener mTouchListener;
+ private View.OnClickListener mIconClickListener;
+ private View.OnLongClickListener mIconLongClickListener;
+ private String mEmptySearchText;
+
+ public AppsListAdapter(Context context, AlphabeticalAppsList apps,
+ View.OnTouchListener touchListener, View.OnClickListener iconClickListener,
+ View.OnLongClickListener iconLongClickListener) {
+ mApps = apps;
+ mLayoutInflater = LayoutInflater.from(context);
+ mTouchListener = touchListener;
+ mIconClickListener = iconClickListener;
+ mIconLongClickListener = iconLongClickListener;
+ }
+
+ public RecyclerView.LayoutManager getLayoutManager(Context context) {
+ return new LinearLayoutManager(context);
+ }
+
+ /**
+ * Sets the text to show when there are no apps.
+ */
+ public void setEmptySearchText(String query) {
+ mEmptySearchText = query;
+ }
+
+ @Override
+ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ switch (viewType) {
+ case EMPTY_VIEW_TYPE:
+ return new ViewHolder(mLayoutInflater.inflate(R.layout.apps_empty_view, parent,
+ false));
+ case SECTION_BREAK_VIEW_TYPE:
+ return new ViewHolder(new View(parent.getContext()));
+ case ICON_VIEW_TYPE:
+ // Inflate the row and all the icon children necessary
+ ViewGroup row = (ViewGroup) mLayoutInflater.inflate(R.layout.apps_list_row_view,
+ parent, false);
+ BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(
+ R.layout.apps_list_row_icon_view, row, false);
+ LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0,
+ ViewGroup.LayoutParams.WRAP_CONTENT, 1);
+ lp.gravity = Gravity.CENTER_VERTICAL;
+ icon.setLayoutParams(lp);
+ icon.setOnTouchListener(mTouchListener);
+ icon.setOnClickListener(mIconClickListener);
+ icon.setOnLongClickListener(mIconLongClickListener);
+ icon.setFocusable(true);
+ row.addView(icon);
+ return new ViewHolder(row);
+ default:
+ throw new RuntimeException("Unexpected view type");
+ }
+ }
+
+ @Override
+ public void onBindViewHolder(ViewHolder holder, int position) {
+ switch (holder.getItemViewType()) {
+ case ICON_VIEW_TYPE:
+ AlphabeticalAppsList.AdapterItem item = mApps.getAdapterItems().get(position);
+ ViewGroup content = (ViewGroup) holder.mContent;
+ String sectionDescription = item.sectionName;
+
+ // Bind the section header
+ boolean showSectionHeader = true;
+ if (position > 0) {
+ AlphabeticalAppsList.AdapterItem prevItem =
+ mApps.getAdapterItems().get(position - 1);
+ showSectionHeader = prevItem.isSectionHeader;
+ }
+ TextView tv = (TextView) content.findViewById(R.id.section);
+ if (showSectionHeader) {
+ tv.setText(sectionDescription);
+ tv.setVisibility(View.VISIBLE);
+ } else {
+ tv.setVisibility(View.INVISIBLE);
+ }
+
+ // Bind the icon
+ BubbleTextView icon = (BubbleTextView) content.getChildAt(1);
+ icon.applyFromApplicationInfo(item.appInfo);
+ break;
+ case EMPTY_VIEW_TYPE:
+ TextView emptyViewText = (TextView) holder.mContent.findViewById(R.id.empty_text);
+ emptyViewText.setText(mEmptySearchText);
+ break;
+ }
+ }
+
+ @Override
+ public int getItemCount() {
+ if (mApps.hasNoFilteredResults()) {
+ // For the empty view
+ return 1;
+ }
+ return mApps.getAdapterItems().size();
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ if (mApps.hasNoFilteredResults()) {
+ return EMPTY_VIEW_TYPE;
+ } else if (mApps.getAdapterItems().get(position).isSectionHeader) {
+ return SECTION_BREAK_VIEW_TYPE;
+ }
+ return ICON_VIEW_TYPE;
+ }
+}
diff --git a/src/com/android/launcher3/AutoInstallsLayout.java b/src/com/android/launcher3/AutoInstallsLayout.java
index 908bd3d..dac79a8 100644
--- a/src/com/android/launcher3/AutoInstallsLayout.java
+++ b/src/com/android/launcher3/AutoInstallsLayout.java
@@ -37,6 +37,7 @@
import com.android.launcher3.LauncherProvider.SqlArguments;
import com.android.launcher3.LauncherSettings.Favorites;
+import com.android.launcher3.util.Thunk;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -44,6 +45,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Locale;
/**
* Layout parsing code for auto installs layout
@@ -56,6 +58,11 @@
static final String ACTION_LAUNCHER_CUSTOMIZATION =
"android.autoinstalls.config.action.PLAY_AUTO_INSTALL";
+ /**
+ * Layout resource which also includes grid size and hotseat count, e.g., default_layout_6x6_h5
+ */
+ private static final String FORMATTED_LAYOUT_RES_WITH_HOSTEAT = "default_layout_%dx%d_h%s";
+ private static final String FORMATTED_LAYOUT_RES = "default_layout_%dx%d";
private static final String LAYOUT_RES = "default_layout";
static AutoInstallsLayout get(Context context, AppWidgetHost appWidgetHost,
@@ -65,15 +72,39 @@
if (customizationApkInfo == null) {
return null;
}
+ return get(context, customizationApkInfo.first, customizationApkInfo.second,
+ appWidgetHost, callback);
+ }
- String pkg = customizationApkInfo.first;
- Resources res = customizationApkInfo.second;
- int layoutId = res.getIdentifier(LAYOUT_RES, "xml", pkg);
+ static AutoInstallsLayout get(Context context, String pkg, Resources targetRes,
+ AppWidgetHost appWidgetHost, LayoutParserCallback callback) {
+ DeviceProfile grid = LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile();
+
+ // Try with grid size and hotseat count
+ String layoutName = String.format(Locale.ENGLISH, FORMATTED_LAYOUT_RES_WITH_HOSTEAT,
+ (int) grid.numColumns, (int) grid.numRows, (int) grid.numHotseatIcons);
+ int layoutId = targetRes.getIdentifier(layoutName, "xml", pkg);
+
+ // Try with only grid size
+ if (layoutId == 0) {
+ Log.d(TAG, "Formatted layout: " + layoutName
+ + " not found. Trying layout without hosteat");
+ layoutName = String.format(Locale.ENGLISH, FORMATTED_LAYOUT_RES,
+ (int) grid.numColumns, (int) grid.numRows);
+ layoutId = targetRes.getIdentifier(layoutName, "xml", pkg);
+ }
+
+ // Try the default layout
+ if (layoutId == 0) {
+ Log.d(TAG, "Formatted layout: " + layoutName + " not found. Trying the default layout");
+ layoutId = targetRes.getIdentifier(LAYOUT_RES, "xml", pkg);
+ }
+
if (layoutId == 0) {
Log.e(TAG, "Layout definition not found in package: " + pkg);
return null;
}
- return new AutoInstallsLayout(context, appWidgetHost, callback, res, layoutId,
+ return new AutoInstallsLayout(context, appWidgetHost, callback, targetRes, layoutId,
TAG_WORKSPACE);
}
@@ -114,8 +145,8 @@
private static final String ACTION_APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE =
"com.android.launcher.action.APPWIDGET_DEFAULT_WORKSPACE_CONFIGURE";
- private final Context mContext;
- private final AppWidgetHost mAppWidgetHost;
+ @Thunk final Context mContext;
+ @Thunk final AppWidgetHost mAppWidgetHost;
protected final LayoutParserCallback mCallback;
protected final PackageManager mPackageManager;
@@ -125,7 +156,7 @@
private final int mHotseatAllAppsRank;
private final long[] mTemp = new long[2];
- private final ContentValues mValues;
+ @Thunk final ContentValues mValues;
protected final String mRootTag;
protected SQLiteDatabase mDb;
@@ -575,7 +606,7 @@
// failed to add, and less than 2 were actually added
if (folderItems.size() < 2) {
// Delete the folder
- Uri uri = Favorites.getContentUri(folderId, false);
+ Uri uri = Favorites.getContentUri(folderId);
SqlArguments args = new SqlArguments(uri, null, null);
mDb.delete(args.table, args.where, args.args);
addedId = -1;
@@ -648,7 +679,7 @@
long insertAndCheck(SQLiteDatabase db, ContentValues values);
}
- private static void copyInteger(ContentValues from, ContentValues to, String key) {
+ @Thunk static void copyInteger(ContentValues from, ContentValues to, String key) {
to.put(key, from.getAsInteger(key));
}
}
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index f9255e6..ae6ebba 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -28,11 +28,14 @@
import android.util.AttributeSet;
import android.util.SparseArray;
import android.util.TypedValue;
+import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.widget.TextView;
+import com.android.launcher3.IconCache.IconLoadRequest;
+
/**
* TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
* because we want to make the bubble taller than the text and TextView's clip is
@@ -49,7 +52,7 @@
private static final int SHADOW_SMALL_COLOUR = 0xCC000000;
static final float PADDING_V = 3.0f;
-
+ private Drawable mIcon;
private final Drawable mBackground;
private final CheckLongPressHelper mLongPressHelper;
private final HolographicOutlineHelper mOutlineHelper;
@@ -62,13 +65,19 @@
private float mSlop;
- private int mTextColor;
+ private final boolean mDeferShadowGenerationOnTouch;
private final boolean mCustomShadowsEnabled;
- private boolean mIsTextVisible;
+ private final boolean mLayoutHorizontal;
+ private final int mIconSize;
+ private final int mIconPaddingSize;
+ private final int mTextSize;
+ private int mTextColor;
private boolean mStayPressed;
private boolean mIgnorePressedStateChange;
+ private IconLoadRequest mIconLoadRequest;
+
public BubbleTextView(Context context) {
this(context, null, 0);
}
@@ -79,10 +88,21 @@
public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
+ LauncherAppState app = LauncherAppState.getInstance();
+ DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.BubbleTextView, defStyle, 0);
mCustomShadowsEnabled = a.getBoolean(R.styleable.BubbleTextView_customShadows, true);
+ mLayoutHorizontal = a.getBoolean(R.styleable.BubbleTextView_layoutHorizontal, false);
+ mIconSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconSizeOverride,
+ grid.allAppsIconSizePx);
+ mIconPaddingSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconPaddingOverride,
+ grid.iconDrawablePaddingPx);
+ mTextSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_textSizeOverride,
+ grid.allAppsIconTextSizePx);
+ mDeferShadowGenerationOnTouch =
+ a.getBoolean(R.styleable.BubbleTextView_deferShadowGeneration, false);
a.recycle();
if (mCustomShadowsEnabled) {
@@ -92,6 +112,12 @@
} else {
mBackground = null;
}
+
+ // If we are laying out horizontal, then center the text vertically
+ if (mLayoutHorizontal) {
+ setGravity(Gravity.CENTER_VERTICAL);
+ }
+
mLongPressHelper = new CheckLongPressHelper(this);
mOutlineHelper = HolographicOutlineHelper.obtain(getContext());
@@ -106,9 +132,7 @@
super.onFinishInflate();
// Ensure we are using the right text size
- LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
- setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx);
+ setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
}
public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
@@ -119,16 +143,11 @@
public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
boolean setDefaultPadding, boolean promiseStateChanged) {
Bitmap b = info.getIcon(iconCache);
- LauncherAppState app = LauncherAppState.getInstance();
FastBitmapDrawable iconDrawable = Utilities.createIconDrawable(b);
iconDrawable.setGhostModeEnabled(info.isDisabled != 0);
- setCompoundDrawables(null, iconDrawable, null, null);
- if (setDefaultPadding) {
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
- setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
- }
+ setIcon(iconDrawable, mIconSize, setDefaultPadding ? mIconPaddingSize : -1);
if (info.contentDescription != null) {
setContentDescription(info.contentDescription);
}
@@ -141,20 +160,17 @@
}
public void applyFromApplicationInfo(AppInfo info) {
- LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
-
- Drawable topDrawable = Utilities.createIconDrawable(info.iconBitmap);
- topDrawable.setBounds(0, 0, grid.allAppsIconSizePx, grid.allAppsIconSizePx);
- setCompoundDrawables(null, topDrawable, null, null);
- setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
+ setIcon(Utilities.createIconDrawable(info.iconBitmap), mIconSize, mIconPaddingSize);
setText(info.title);
if (info.contentDescription != null) {
setContentDescription(info.contentDescription);
}
- setTag(info);
- }
+ // We don't need to check the info since it's not a ShortcutInfo
+ super.setTag(info);
+ // Verify high res immediately
+ verifyHighRes();
+ }
@Override
protected boolean setFrame(int left, int top, int right, int bottom) {
@@ -186,10 +202,19 @@
}
}
+ /** Returns the icon for this view. */
+ public Drawable getIcon() {
+ return mIcon;
+ }
+
+ /** Returns whether the layout is horizontal. */
+ public boolean isLayoutHorizontal() {
+ return mLayoutHorizontal;
+ }
+
private void updateIconState() {
- Drawable top = getCompoundDrawables()[1];
- if (top instanceof FastBitmapDrawable) {
- ((FastBitmapDrawable) top).setPressed(isPressed() || mStayPressed);
+ if (mIcon instanceof FastBitmapDrawable) {
+ ((FastBitmapDrawable) mIcon).setPressed(isPressed() || mStayPressed);
}
}
@@ -204,7 +229,7 @@
// So that the pressed outline is visible immediately on setStayPressed(),
// we pre-create it on ACTION_DOWN (it takes a small but perceptible amount of time
// to create it)
- if (mPressedBackground == null) {
+ if (!mDeferShadowGenerationOnTouch && mPressedBackground == null) {
mPressedBackground = mOutlineHelper.createMediumDropShadow(this);
}
@@ -233,6 +258,10 @@
mStayPressed = stayPressed;
if (!stayPressed) {
mPressedBackground = null;
+ } else {
+ if (mPressedBackground == null) {
+ mPressedBackground = mOutlineHelper.createMediumDropShadow(this);
+ }
}
// Only show the shadow effect when persistent pressed state is set.
@@ -325,10 +354,9 @@
super.onAttachedToWindow();
if (mBackground != null) mBackground.setCallback(this);
- Drawable top = getCompoundDrawables()[1];
- if (top instanceof PreloadIconDrawable) {
- ((PreloadIconDrawable) top).applyPreloaderTheme(getPreloaderTheme());
+ if (mIcon instanceof PreloadIconDrawable) {
+ ((PreloadIconDrawable) mIcon).applyPreloaderTheme(getPreloaderTheme());
}
mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
}
@@ -358,16 +386,6 @@
} else {
super.setTextColor(res.getColor(android.R.color.transparent));
}
- mIsTextVisible = visible;
- }
-
- public boolean isTextVisible() {
- return mIsTextVisible;
- }
-
- @Override
- protected boolean onSetAlpha(int alpha) {
- return true;
}
@Override
@@ -385,15 +403,13 @@
((info.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE) ?
info.getInstallProgress() : 0)) : 100;
- Drawable[] drawables = getCompoundDrawables();
- Drawable top = drawables[1];
- if (top != null) {
+ if (mIcon != null) {
final PreloadIconDrawable preloadDrawable;
- if (top instanceof PreloadIconDrawable) {
- preloadDrawable = (PreloadIconDrawable) top;
+ if (mIcon instanceof PreloadIconDrawable) {
+ preloadDrawable = (PreloadIconDrawable) mIcon;
} else {
- preloadDrawable = new PreloadIconDrawable(top, getPreloaderTheme());
- setCompoundDrawables(drawables[0], preloadDrawable, drawables[2], drawables[3]);
+ preloadDrawable = new PreloadIconDrawable(mIcon, getPreloaderTheme());
+ setIcon(preloadDrawable, mIconSize, -1);
}
preloadDrawable.setLevel(progressLevel);
@@ -417,4 +433,61 @@
}
return theme;
}
+
+ /**
+ * Sets the icon for this view based on the layout direction.
+ */
+ private Drawable setIcon(Drawable icon, int iconSize, int drawablePadding) {
+ mIcon = icon;
+ if (iconSize != -1) {
+ mIcon.setBounds(0, 0, iconSize, iconSize);
+ }
+ if (mLayoutHorizontal) {
+ setCompoundDrawablesRelative(mIcon, null, null, null);
+ } else {
+ setCompoundDrawablesRelative(null, mIcon, null, null);
+ }
+ if (drawablePadding != -1) {
+ setCompoundDrawablePadding(drawablePadding);
+ }
+ return icon;
+ }
+
+ /**
+ * Applies the item info if it is same as what the view is pointing to currently.
+ */
+ public void reapplyItemInfo(final ItemInfo info) {
+ if (getTag() == info) {
+ mIconLoadRequest = null;
+ if (info instanceof AppInfo) {
+ applyFromApplicationInfo((AppInfo) info);
+ } else if (info instanceof ShortcutInfo) {
+ applyFromShortcutInfo((ShortcutInfo) info,
+ LauncherAppState.getInstance().getIconCache(), false);
+ }
+ }
+ }
+
+ /**
+ * Verifies that the current icon is high-res otherwise posts a request to load the icon.
+ */
+ public void verifyHighRes() {
+ if (mIconLoadRequest != null) {
+ mIconLoadRequest.cancel();
+ mIconLoadRequest = null;
+ }
+ if (getTag() instanceof AppInfo) {
+ AppInfo info = (AppInfo) getTag();
+ if (info.usingLowResIcon) {
+ mIconLoadRequest = LauncherAppState.getInstance().getIconCache()
+ .updateIconInBackground(BubbleTextView.this, info);
+ }
+ } else if (getTag() instanceof ShortcutInfo) {
+ ShortcutInfo info = (ShortcutInfo) getTag();
+ if (info.usingLowResIcon) {
+ mIconLoadRequest = LauncherAppState.getInstance().getIconCache()
+ .updateIconInBackground(BubbleTextView.this, info);
+ }
+ }
+ }
}
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index a3500aa..63afa30 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -22,6 +22,7 @@
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
+import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -33,43 +34,53 @@
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
+import android.os.Build;
+import android.os.Bundle;
import android.os.Parcelable;
+import android.support.v4.view.ViewCompat;
+import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
+import android.support.v4.widget.ExploreByTouchHelper;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.MotionEvent;
import android.view.View;
+import android.view.View.OnClickListener;
import android.view.ViewDebug;
import android.view.ViewGroup;
+import android.view.accessibility.AccessibilityEvent;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LayoutAnimationController;
import com.android.launcher3.FolderIcon.FolderRingAnimator;
+import com.android.launcher3.LauncherAccessibilityDelegate.DragType;
+import com.android.launcher3.util.Thunk;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.List;
import java.util.Stack;
public class CellLayout extends ViewGroup {
static final String TAG = "CellLayout";
private Launcher mLauncher;
- private int mCellWidth;
- private int mCellHeight;
+ @Thunk int mCellWidth;
+ @Thunk int mCellHeight;
private int mFixedCellWidth;
private int mFixedCellHeight;
- private int mCountX;
- private int mCountY;
+ @Thunk int mCountX;
+ @Thunk int mCountY;
private int mOriginalWidthGap;
private int mOriginalHeightGap;
- private int mWidthGap;
- private int mHeightGap;
+ @Thunk int mWidthGap;
+ @Thunk int mHeightGap;
private int mMaxGap;
private boolean mDropPending = false;
private boolean mIsDragTarget = true;
@@ -77,7 +88,7 @@
// These are temporary variables to prevent having to allocate a new object just to
// return an (x, y) value from helper functions. Do NOT use them to maintain other state.
private final int[] mTmpXY = new int[2];
- private final int[] mTmpPoint = new int[2];
+ @Thunk final int[] mTmpPoint = new int[2];
int[] mTempLocation = new int[2];
boolean[][] mOccupied;
@@ -114,8 +125,8 @@
// These arrays are used to implement the drag visualization on x-large screens.
// They are used as circular arrays, indexed by mDragOutlineCurrent.
- private Rect[] mDragOutlines = new Rect[4];
- private float[] mDragOutlineAlphas = new float[mDragOutlines.length];
+ @Thunk Rect[] mDragOutlines = new Rect[4];
+ @Thunk float[] mDragOutlineAlphas = new float[mDragOutlines.length];
private InterruptibleInOutAnimator[] mDragOutlineAnims =
new InterruptibleInOutAnimator[mDragOutlines.length];
@@ -125,7 +136,7 @@
private final FastBitmapView mTouchFeedbackView;
- private HashMap<CellLayout.LayoutParams, Animator> mReorderAnimators = new
+ @Thunk HashMap<CellLayout.LayoutParams, Animator> mReorderAnimators = new
HashMap<CellLayout.LayoutParams, Animator>();
private HashMap<View, ReorderPreviewAnimation>
mShakeAnimators = new HashMap<View, ReorderPreviewAnimation>();
@@ -156,7 +167,7 @@
private static final float REORDER_PREVIEW_MAGNITUDE = 0.12f;
private static final int REORDER_ANIMATION_DURATION = 150;
- private float mReorderPreviewAnimationMagnitude;
+ @Thunk float mReorderPreviewAnimationMagnitude;
private ArrayList<View> mIntersectingViews = new ArrayList<View>();
private Rect mOccupiedRect = new Rect();
@@ -169,6 +180,14 @@
private final static Paint sPaint = new Paint();
+ // Related to accessible drag and drop
+ DragAndDropAccessibilityDelegate mTouchHelper = new DragAndDropAccessibilityDelegate(this);
+ private boolean mUseTouchHelper = false;
+ OnClickListener mOldClickListener = null;
+ OnClickListener mOldWorkspaceListener = null;
+ @Thunk int mDownX = 0;
+ @Thunk int mDownY = 0;
+
public CellLayout(Context context) {
this(context, null);
}
@@ -294,6 +313,301 @@
addView(mShortcutsAndWidgets);
}
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public void enableAccessibleDrag(boolean enable) {
+ mUseTouchHelper = enable;
+ if (!enable) {
+ ViewCompat.setAccessibilityDelegate(this, null);
+ setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
+ getShortcutsAndWidgets().setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
+ setOnClickListener(mLauncher);
+ } else {
+ ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
+ setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
+ getShortcutsAndWidgets().setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
+ setOnClickListener(mTouchHelper);
+ }
+
+ // Invalidate the accessibility hierarchy
+ if (getParent() != null) {
+ getParent().notifySubtreeAccessibilityStateChanged(
+ this, this, AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE);
+ }
+ }
+
+ @Override
+ public boolean dispatchHoverEvent(MotionEvent event) {
+ // Always attempt to dispatch hover events to accessibility first.
+ if (mUseTouchHelper && mTouchHelper.dispatchHoverEvent(event)) {
+ return true;
+ }
+ return super.dispatchHoverEvent(event);
+ }
+
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent event) {
+ if (event.getAction() == MotionEvent.ACTION_DOWN) {
+ mDownX = (int) event.getX();
+ mDownY = (int) event.getY();
+ }
+ return super.dispatchTouchEvent(event);
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ if (mUseTouchHelper ||
+ (mInterceptTouchListener != null && mInterceptTouchListener.onTouch(this, ev))) {
+ return true;
+ }
+ return false;
+ }
+
+ class DragAndDropAccessibilityDelegate extends ExploreByTouchHelper implements OnClickListener {
+ private final Rect mTempRect = new Rect();
+
+ public DragAndDropAccessibilityDelegate(View forView) {
+ super(forView);
+ }
+
+ private int getViewIdAt(float x, float y) {
+ if (x < 0 || y < 0 || x > getMeasuredWidth() || y > getMeasuredHeight()) {
+ return ExploreByTouchHelper.INVALID_ID;
+ }
+
+ // Map coords to cell
+ int cellX = (int) Math.floor(x / (mCellWidth + mWidthGap));
+ int cellY = (int) Math.floor(y / (mCellHeight + mHeightGap));
+
+ // Map cell to id
+ int id = cellX * mCountY + cellY;
+ return id;
+ }
+
+ @Override
+ protected int getVirtualViewAt(float x, float y) {
+ return nearestDropLocation(getViewIdAt(x, y));
+ }
+
+ protected int nearestDropLocation(int id) {
+ int count = mCountX * mCountY;
+ for (int delta = 0; delta < count; delta++) {
+ if (id + delta <= (count - 1)) {
+ int target = intersectsValidDropTarget(id + delta);
+ if (target >= 0) {
+ return target;
+ }
+ } else if (id - delta >= 0) {
+ int target = intersectsValidDropTarget(id - delta);
+ if (target >= 0) {
+ return target;
+ }
+ }
+ }
+ return ExploreByTouchHelper.INVALID_ID;
+ }
+
+ /**
+ * Find the virtual view id corresponding to the top left corner of any drop region by which
+ * the passed id is contained. For an icon, this is simply
+ *
+ * @param id the id we're interested examining (ie. does it fit there?)
+ * @return the view id of the top left corner of a valid drop region or -1 if there is no
+ * such valid region. For the icon, this can just be -1 or id.
+ */
+ protected int intersectsValidDropTarget(int id) {
+ LauncherAccessibilityDelegate delegate =
+ LauncherAppState.getInstance().getAccessibilityDelegate();
+ if (delegate == null) {
+ return -1;
+ }
+
+ int y = id % mCountY;
+ int x = id / mCountY;
+ LauncherAccessibilityDelegate.DragInfo dragInfo = delegate.getDragInfo();
+
+ if (dragInfo.dragType == DragType.WIDGET) {
+ // For a widget, every cell must be vacant. In addition, we will return any valid
+ // drop target by which the passed id is contained.
+ boolean fits = false;
+
+ // These represent the amount that we can back off if we hit a problem. They
+ // get consumed as we move up and to the right, trying new regions.
+ int spanX = dragInfo.info.spanX;
+ int spanY = dragInfo.info.spanY;
+
+ for (int m = 0; m < spanX; m++) {
+ for (int n = 0; n < spanY; n++) {
+
+ fits = true;
+ int x0 = x - m;
+ int y0 = y - n;
+
+ if (x0 < 0 || y0 < 0) continue;
+
+ for (int i = x0; i < x0 + spanX; i++) {
+ if (!fits) break;
+ for (int j = y0; j < y0 + spanY; j++) {
+ if (i >= mCountX || j >= mCountY || mOccupied[i][j]) {
+ fits = false;
+ break;
+ }
+ }
+ }
+ if (fits) {
+ return x0 * mCountY + y0;
+ }
+ }
+ }
+ return -1;
+ } else {
+ // For an icon, we simply check the view directly below
+ View child = getChildAt(x, y);
+ if (child == null || child == dragInfo.item) {
+ // Empty cell. Good for an icon or folder.
+ return id;
+ } else if (dragInfo.dragType != DragType.FOLDER) {
+ // For icons, we can consider cells that have another icon or a folder.
+ ItemInfo info = (ItemInfo) child.getTag();
+ if (info instanceof AppInfo || info instanceof FolderInfo ||
+ info instanceof ShortcutInfo) {
+ return id;
+ }
+ }
+ return -1;
+ }
+ }
+
+ @Override
+ protected void getVisibleVirtualViews(List<Integer> virtualViews) {
+ // We create a virtual view for each cell of the grid
+ // The cell ids correspond to cells in reading order.
+ int nCells = mCountX * mCountY;
+
+ for (int i = 0; i < nCells; i++) {
+ if (intersectsValidDropTarget(i) >= 0) {
+ virtualViews.add(i);
+ }
+ }
+ }
+
+ @Override
+ protected boolean onPerformActionForVirtualView(int viewId, int action, Bundle args) {
+ LauncherAccessibilityDelegate delegate =
+ LauncherAppState.getInstance().getAccessibilityDelegate();
+ if (delegate == null) {
+ return false;
+ }
+
+ if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
+ String confirmation = getConfirmationForIconDrop(viewId);
+ delegate.handleAccessibleDrop(CellLayout.this, getItemBounds(viewId), confirmation);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void onClick(View arg0) {
+ LauncherAccessibilityDelegate delegate =
+ LauncherAppState.getInstance().getAccessibilityDelegate();
+ if (delegate == null) {
+ return;
+ }
+
+ int viewId = getViewIdAt(mDownX, mDownY);
+
+ String confirmation = getConfirmationForIconDrop(viewId);
+ delegate.handleAccessibleDrop(CellLayout.this, getItemBounds(viewId), confirmation);
+ }
+
+ @Override
+ protected void onPopulateEventForVirtualView(int id, AccessibilityEvent event) {
+ if (id == ExploreByTouchHelper.INVALID_ID) {
+ throw new IllegalArgumentException("Invalid virtual view id");
+ }
+ // We're required to set something here.
+ event.setContentDescription("");
+ }
+
+ @Override
+ protected void onPopulateNodeForVirtualView(int id, AccessibilityNodeInfoCompat node) {
+ if (id == ExploreByTouchHelper.INVALID_ID) {
+ throw new IllegalArgumentException("Invalid virtual view id");
+ }
+
+ node.setContentDescription(getLocationDescriptionForIconDrop(id));
+ node.setBoundsInParent(getItemBounds(id));
+
+ node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
+ node.setClickable(true);
+ node.setFocusable(true);
+ }
+
+ private String getLocationDescriptionForIconDrop(int id) {
+ LauncherAccessibilityDelegate delegate =
+ LauncherAppState.getInstance().getAccessibilityDelegate();
+ if (delegate == null) {
+ return "";
+ }
+
+ int y = id % mCountY;
+ int x = id / mCountY;
+ LauncherAccessibilityDelegate.DragInfo dragInfo = delegate.getDragInfo();
+
+ Resources res = getContext().getResources();
+ View child = getChildAt(x, y);
+ if (child == null || child == dragInfo.item) {
+ return res.getString(R.string.move_to_empty_cell, x, y);
+ } else {
+ ItemInfo info = (ItemInfo) child.getTag();
+ if (info instanceof AppInfo || info instanceof ShortcutInfo) {
+ return res.getString(R.string.create_folder_with, info.title);
+ } else if (info instanceof FolderInfo) {
+ return res.getString(R.string.add_to_folder, info.title);
+ }
+ }
+ return "";
+ }
+
+ private String getConfirmationForIconDrop(int id) {
+ LauncherAccessibilityDelegate delegate =
+ LauncherAppState.getInstance().getAccessibilityDelegate();
+ if (delegate == null) {
+ return "";
+ }
+
+ int y = id % mCountY;
+ int x = id / mCountY;
+ LauncherAccessibilityDelegate.DragInfo dragInfo = delegate.getDragInfo();
+
+ Resources res = getContext().getResources();
+ View child = getChildAt(x, y);
+ if (child == null || child == dragInfo.item) {
+ return res.getString(R.string.item_moved);
+ } else {
+ ItemInfo info = (ItemInfo) child.getTag();
+ if (info instanceof AppInfo || info instanceof ShortcutInfo) {
+ return res.getString(R.string.folder_created);
+
+ } else if (info instanceof FolderInfo) {
+ return res.getString(R.string.added_to_folder);
+ }
+ }
+ return "";
+ }
+
+ private Rect getItemBounds(int id) {
+ int cellY = id % mCountY;
+ int cellX = id / mCountY;
+ int x = getPaddingLeft() + (int) (cellX * (mCellWidth + mWidthGap));
+ int y = getPaddingTop() + (int) (cellY * (mCellHeight + mHeightGap));
+
+ Rect bounds = mTempRect;
+ bounds.set(x, y, x + mCellWidth, y + mCellHeight);
+ return bounds;
+ }
+ }
+
public void enableHardwareLayer(boolean hasLayer) {
mShortcutsAndWidgets.setLayerType(hasLayer ? LAYER_TYPE_HARDWARE : LAYER_TYPE_NONE, sPaint);
}
@@ -679,18 +993,6 @@
mShortcutsAndWidgets.removeViewsInLayout(start, count);
}
- @Override
- public boolean onInterceptTouchEvent(MotionEvent ev) {
- // First we clear the tag to ensure that on every touch down we start with a fresh slate,
- // even in the case where we return early. Not clearing here was causing bugs whereby on
- // long-press we'd end up picking up an item from a previous drag operation.
- if (mInterceptTouchListener != null && mInterceptTouchListener.onTouch(this, ev)) {
- return true;
- }
-
- return false;
- }
-
/**
* Given a point, return the cell that strictly encloses that point
* @param x X coordinate of the point
@@ -2268,7 +2570,7 @@
}
}
- private void completeAnimationImmediately() {
+ @Thunk void completeAnimationImmediately() {
if (a != null) {
a.cancel();
}
@@ -2589,7 +2891,7 @@
return mItemPlacementDirty;
}
- private class ItemConfiguration {
+ @Thunk class ItemConfiguration {
HashMap<View, CellAndSpan> map = new HashMap<View, CellAndSpan>();
private HashMap<View, CellAndSpan> savedMap = new HashMap<View, CellAndSpan>();
ArrayList<View> sortedViews = new ArrayList<View>();
diff --git a/src/com/android/launcher3/CheckLongPressHelper.java b/src/com/android/launcher3/CheckLongPressHelper.java
index 8114979..10ca6a3 100644
--- a/src/com/android/launcher3/CheckLongPressHelper.java
+++ b/src/com/android/launcher3/CheckLongPressHelper.java
@@ -18,9 +18,11 @@
import android.view.View;
+import com.android.launcher3.util.Thunk;
+
public class CheckLongPressHelper {
- private View mView;
- private boolean mHasPerformedLongPress;
+ @Thunk View mView;
+ @Thunk boolean mHasPerformedLongPress;
private CheckForLongPress mPendingCheckForLongPress;
class CheckForLongPress implements Runnable {
diff --git a/src/com/android/launcher3/CommonAppTypeParser.java b/src/com/android/launcher3/CommonAppTypeParser.java
index fe2fbd7..3164179 100644
--- a/src/com/android/launcher3/CommonAppTypeParser.java
+++ b/src/com/android/launcher3/CommonAppTypeParser.java
@@ -91,8 +91,8 @@
private class MyLayoutParser extends DefaultLayoutParser {
public MyLayoutParser() {
- super(mContext, null, CommonAppTypeParser.this,
- mContext.getResources(), mResId, TAG_RESOLVE, 0);
+ super(CommonAppTypeParser.this.mContext, null, CommonAppTypeParser.this,
+ CommonAppTypeParser.this.mContext.getResources(), mResId, TAG_RESOLVE, 0);
}
@Override
diff --git a/src/com/android/launcher3/DefaultLayoutParser.java b/src/com/android/launcher3/DefaultLayoutParser.java
index 6c3008b..7b91c67 100644
--- a/src/com/android/launcher3/DefaultLayoutParser.java
+++ b/src/com/android/launcher3/DefaultLayoutParser.java
@@ -13,6 +13,7 @@
import android.util.Log;
import com.android.launcher3.LauncherSettings.Favorites;
+import com.android.launcher3.util.Thunk;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -57,7 +58,7 @@
return getFolderElementsMap(mSourceRes);
}
- private HashMap<String, TagParser> getFolderElementsMap(Resources res) {
+ @Thunk HashMap<String, TagParser> getFolderElementsMap(Resources res) {
HashMap<String, TagParser> parsers = new HashMap<String, TagParser>();
parsers.put(TAG_FAVORITE, new AppShortcutWithUriParser());
parsers.put(TAG_SHORTCUT, new UriShortcutParser(res));
@@ -89,7 +90,7 @@
/**
* AppShortcutParser which also supports adding URI based intents
*/
- private class AppShortcutWithUriParser extends AppShortcutParser {
+ @Thunk class AppShortcutWithUriParser extends AppShortcutParser {
@Override
protected long invalidPackageOrClass(XmlResourceParser parser) {
@@ -231,7 +232,7 @@
/**
* A parser which adds a folder whose contents come from partner apk.
*/
- private class PartnerFolderParser implements TagParser {
+ @Thunk class PartnerFolderParser implements TagParser {
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
@@ -257,7 +258,7 @@
/**
* An extension of FolderParser which allows adding items from a different xml.
*/
- private class MyFolderParser extends FolderParser {
+ @Thunk class MyFolderParser extends FolderParser {
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
diff --git a/src/com/android/launcher3/DeferredHandler.java b/src/com/android/launcher3/DeferredHandler.java
index a2d121d..eb7c26a 100644
--- a/src/com/android/launcher3/DeferredHandler.java
+++ b/src/com/android/launcher3/DeferredHandler.java
@@ -22,6 +22,8 @@
import android.os.MessageQueue;
import android.util.Pair;
+import com.android.launcher3.util.Thunk;
+
import java.util.LinkedList;
import java.util.ListIterator;
@@ -33,11 +35,11 @@
* This class is fifo.
*/
public class DeferredHandler {
- private LinkedList<Pair<Runnable, Integer>> mQueue = new LinkedList<Pair<Runnable, Integer>>();
+ @Thunk LinkedList<Pair<Runnable, Integer>> mQueue = new LinkedList<Pair<Runnable, Integer>>();
private MessageQueue mMessageQueue = Looper.myQueue();
private Impl mHandler = new Impl();
- private class Impl extends Handler implements MessageQueue.IdleHandler {
+ @Thunk class Impl extends Handler implements MessageQueue.IdleHandler {
public void handleMessage(Message msg) {
Pair<Runnable, Integer> p;
Runnable r;
diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java
index 1ada1a9..1f0dad2 100644
--- a/src/com/android/launcher3/DeleteDropTarget.java
+++ b/src/com/android/launcher3/DeleteDropTarget.java
@@ -41,6 +41,7 @@
import android.view.animation.LinearInterpolator;
import com.android.launcher3.compat.UserHandleCompat;
+import com.android.launcher3.util.Thunk;
public class DeleteDropTarget extends ButtonDropTarget {
private static int DELETE_ANIMATION_DURATION = 285;
@@ -56,7 +57,7 @@
private TransitionDrawable mRemoveDrawable;
private TransitionDrawable mCurrentDrawable;
- private boolean mWaitingForUninstall = false;
+ @Thunk boolean mWaitingForUninstall = false;
public DeleteDropTarget(Context context, AttributeSet attrs) {
this(context, attrs, 0);
@@ -272,7 +273,7 @@
return false;
}
- private void completeDrop(DragObject d) {
+ @Thunk void completeDrop(DragObject d) {
ItemInfo item = (ItemInfo) d.dragInfo;
boolean wasWaitingForUninstall = mWaitingForUninstall;
mWaitingForUninstall = false;
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index b97f0f2..73f54ab 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -38,6 +38,8 @@
import android.widget.FrameLayout;
import android.widget.LinearLayout;
+import com.android.launcher3.util.Thunk;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -81,6 +83,7 @@
boolean isTablet;
boolean isLargeTablet;
boolean isLayoutRtl;
+
boolean transposeLayoutWithOrientation;
int desiredWorkspaceLeftRightMarginPx;
@@ -122,6 +125,7 @@
int hotseatAllAppsRank;
int allAppsNumRows;
int allAppsNumCols;
+ int appsViewNumCols;
int searchBarSpaceWidthPx;
int searchBarSpaceHeightPx;
int pageIndicatorHeightPx;
@@ -363,7 +367,7 @@
}
}
- private void updateIconSize(float scale, int drawablePadding, Resources resources,
+ private void updateIconSize(float scale, int drawablePadding, Resources res,
DisplayMetrics dm) {
iconSizePx = (int) (DynamicGrid.pxFromDp(iconSize, dm) * scale);
iconTextSizePx = (int) (DynamicGrid.pxFromSp(iconTextSize, dm) * scale);
@@ -372,9 +376,9 @@
// Search Bar
searchBarSpaceWidthPx = Math.min(widthPx,
- resources.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_max_width));
+ res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_max_width));
searchBarSpaceHeightPx = getSearchBarTopOffset()
- + resources.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_height);
+ + res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_height);
// Calculate the actual text height
Paint textPaint = new Paint();
@@ -382,7 +386,7 @@
FontMetrics fm = textPaint.getFontMetrics();
cellWidthPx = iconSizePx;
cellHeightPx = iconSizePx + iconDrawablePaddingPx + (int) Math.ceil(fm.bottom - fm.top);
- final float scaleDps = resources.getDimensionPixelSize(R.dimen.dragViewScale);
+ final float scaleDps = res.getDimensionPixelSize(R.dimen.dragViewScale);
dragViewScale = (iconSizePx + scaleDps) / iconSizePx;
// Hotseat
@@ -400,11 +404,11 @@
allAppsCellWidthPx = allAppsIconSizePx;
allAppsCellHeightPx = allAppsIconSizePx + drawablePadding + iconTextSizePx;
int maxLongEdgeCellCount =
- resources.getInteger(R.integer.config_dynamic_grid_max_long_edge_cell_count);
+ res.getInteger(R.integer.config_dynamic_grid_max_long_edge_cell_count);
int maxShortEdgeCellCount =
- resources.getInteger(R.integer.config_dynamic_grid_max_short_edge_cell_count);
+ res.getInteger(R.integer.config_dynamic_grid_max_short_edge_cell_count);
int minEdgeCellCount =
- resources.getInteger(R.integer.config_dynamic_grid_min_edge_cell_count);
+ res.getInteger(R.integer.config_dynamic_grid_min_edge_cell_count);
int maxRows = (isLandscape ? maxShortEdgeCellCount : maxLongEdgeCellCount);
int maxCols = (isLandscape ? maxLongEdgeCellCount : maxShortEdgeCellCount);
@@ -415,10 +419,17 @@
allAppsNumRows = (availableHeightPx - pageIndicatorHeightPx) /
(allAppsCellHeightPx + allAppsCellPaddingPx);
allAppsNumRows = Math.max(minEdgeCellCount, Math.min(maxRows, allAppsNumRows));
- allAppsNumCols = (availableWidthPx) /
- (allAppsCellWidthPx + allAppsCellPaddingPx);
+ allAppsNumCols = (availableWidthPx) / (allAppsCellWidthPx + allAppsCellPaddingPx);
allAppsNumCols = Math.max(minEdgeCellCount, Math.min(maxCols, allAppsNumCols));
}
+
+ int appsContainerViewPx = res.getDimensionPixelSize(R.dimen.apps_container_width);
+ int appsViewLeftMarginPx =
+ res.getDimensionPixelSize(R.dimen.apps_grid_view_start_margin);
+ int availableAppsWidthPx = (appsContainerViewPx > 0) ? appsContainerViewPx :
+ availableWidthPx;
+ appsViewNumCols = (availableAppsWidthPx - appsViewLeftMarginPx) /
+ (allAppsCellWidthPx + allAppsCellPaddingPx);
}
void updateFromConfiguration(Context context, Resources resources, int wPx, int hPx,
@@ -440,7 +451,7 @@
updateAvailableDimensions(context);
}
- private float dist(PointF p0, PointF p1) {
+ @Thunk float dist(PointF p0, PointF p1) {
return (float) Math.sqrt((p1.x - p0.x)*(p1.x-p0.x) +
(p1.y-p0.y)*(p1.y-p0.y));
}
@@ -691,6 +702,10 @@
return isLargeTablet;
}
+ /**
+ * When {@code true}, hotseat is on the bottom row when in landscape mode.
+ * If {@code false}, hotseat is on the right column when in landscape mode.
+ */
boolean isVerticalBarLayout() {
return isLandscape && transposeLayoutWithOrientation;
}
diff --git a/src/com/android/launcher3/DragController.java b/src/com/android/launcher3/DragController.java
index 480dce9..eb16861 100644
--- a/src/com/android/launcher3/DragController.java
+++ b/src/com/android/launcher3/DragController.java
@@ -34,6 +34,8 @@
import android.view.ViewConfiguration;
import android.view.inputmethod.InputMethodManager;
+import com.android.launcher3.util.Thunk;
+
import java.util.ArrayList;
import java.util.HashSet;
@@ -49,8 +51,8 @@
/** Indicates the drag is a copy. */
public static int DRAG_ACTION_COPY = 1;
- private static final int SCROLL_DELAY = 500;
- private static final int RESCROLL_DELAY = PagedView.PAGE_SNAP_ANIMATION_DURATION + 150;
+ public static final int SCROLL_DELAY = 500;
+ public static final int RESCROLL_DELAY = PagedView.PAGE_SNAP_ANIMATION_DURATION + 150;
private static final boolean PROFILE_DRAWING_DURING_DRAG = false;
@@ -63,7 +65,7 @@
private static final float MAX_FLING_DEGREES = 35f;
- private Launcher mLauncher;
+ @Thunk Launcher mLauncher;
private Handler mHandler;
// temporaries to avoid gc thrash
@@ -73,6 +75,9 @@
/** Whether or not we're dragging. */
private boolean mDragging;
+ /** Whether or not this is an accessible drag operation */
+ private boolean mIsAccessibleDrag;
+
/** X coordinate of the down event. */
private int mMotionDownX;
@@ -99,17 +104,17 @@
private View mMoveTarget;
- private DragScroller mDragScroller;
- private int mScrollState = SCROLL_OUTSIDE_ZONE;
+ @Thunk DragScroller mDragScroller;
+ @Thunk int mScrollState = SCROLL_OUTSIDE_ZONE;
private ScrollRunnable mScrollRunnable = new ScrollRunnable();
private DropTarget mLastDropTarget;
private InputMethodManager mInputMethodManager;
- private int mLastTouch[] = new int[2];
- private long mLastTouchUpTime = -1;
- private int mDistanceSinceScroll = 0;
+ @Thunk int mLastTouch[] = new int[2];
+ @Thunk long mLastTouchUpTime = -1;
+ @Thunk int mDistanceSinceScroll = 0;
private int mTmpPoint[] = new int[2];
private Rect mDragLayerRect = new Rect();
@@ -182,7 +187,7 @@
(int) ((initialDragViewScale * bmp.getHeight() - bmp.getHeight()) / 2);
startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, dragAction, null,
- null, initialDragViewScale);
+ null, initialDragViewScale, false);
if (dragAction == DRAG_ACTION_MOVE) {
v.setVisibility(View.GONE);
@@ -202,10 +207,11 @@
* {@link #DRAG_ACTION_COPY}
* @param dragRegion Coordinates within the bitmap b for the position of item being dragged.
* Makes dragging feel more precise, e.g. you can clip out a transparent border
+ * @param accessible whether this drag should occur in accessibility mode
*/
public DragView startDrag(Bitmap b, int dragLayerX, int dragLayerY,
DragSource source, Object dragInfo, int dragAction, Point dragOffset, Rect dragRegion,
- float initialDragViewScale) {
+ float initialDragViewScale, boolean accessible) {
if (PROFILE_DRAWING_DURING_DRAG) {
android.os.Debug.startMethodTracing("Launcher");
}
@@ -228,12 +234,21 @@
final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top;
mDragging = true;
+ mIsAccessibleDrag = accessible;
mDragObject = new DropTarget.DragObject();
mDragObject.dragComplete = false;
- mDragObject.xOffset = mMotionDownX - (dragLayerX + dragRegionLeft);
- mDragObject.yOffset = mMotionDownY - (dragLayerY + dragRegionTop);
+ if (mIsAccessibleDrag) {
+ // For an accessible drag, we assume the view is being dragged from the center.
+ mDragObject.xOffset = b.getWidth() / 2;
+ mDragObject.yOffset = b.getHeight() / 2;
+ mDragObject.accessibleDrag = true;
+ } else {
+ mDragObject.xOffset = mMotionDownX - (dragLayerX + dragRegionLeft);
+ mDragObject.yOffset = mMotionDownY - (dragLayerY + dragRegionTop);
+ }
+
mDragObject.dragSource = source;
mDragObject.dragInfo = dragInfo;
@@ -349,6 +364,7 @@
private void endDrag() {
if (mDragging) {
mDragging = false;
+ mIsAccessibleDrag = false;
clearScrollRunnable();
boolean isDeferred = false;
if (mDragObject.dragView != null) {
@@ -421,6 +437,10 @@
+ mDragging);
}
+ if (mIsAccessibleDrag) {
+ return false;
+ }
+
// Update the velocity tracker
acquireVelocityTrackerAndAddMovement(ev);
@@ -525,7 +545,7 @@
mLastDropTarget = dropTarget;
}
- private void checkScrollState(int x, int y) {
+ @Thunk void checkScrollState(int x, int y) {
final int slop = ViewConfiguration.get(mLauncher).getScaledWindowTouchSlop();
final int delay = mDistanceSinceScroll < slop ? RESCROLL_DELAY : SCROLL_DELAY;
final DragLayer dragLayer = mLauncher.getDragLayer();
@@ -560,7 +580,7 @@
* Call this from a drag source view.
*/
public boolean onTouchEvent(MotionEvent ev) {
- if (!mDragging) {
+ if (!mDragging || mIsAccessibleDrag) {
return false;
}
@@ -617,6 +637,34 @@
}
/**
+ * Since accessible drag and drop won't cause the same sequence of touch events, we manually
+ * inject the appropriate state.
+ */
+ public void prepareAccessibleDrag(int x, int y) {
+ mMotionDownX = x;
+ mMotionDownY = y;
+ mLastDropTarget = null;
+ }
+
+ /**
+ * As above, since accessible drag and drop won't cause the same sequence of touch events,
+ * we manually ensure appropriate drag and drop events get emulated for accessible drag.
+ */
+ public void completeAccessibleDrag(int[] location) {
+ final int[] coordinates = mCoordinatesTemp;
+
+ // We make sure that we prime the target for drop.
+ DropTarget dropTarget = findDropTarget(location[0], location[1], coordinates);
+ mDragObject.x = coordinates[0];
+ mDragObject.y = coordinates[1];
+ checkTouchMove(dropTarget);
+
+ // Perform the drop
+ drop(location[0], location[1]);
+ endDrag();
+ }
+
+ /**
* Determines whether the user flung the current item to delete it.
*
* @return the vector at which the item was flung, or null if no fling was detected.
diff --git a/src/com/android/launcher3/DragLayer.java b/src/com/android/launcher3/DragLayer.java
index a352b79..ab2e094 100644
--- a/src/com/android/launcher3/DragLayer.java
+++ b/src/com/android/launcher3/DragLayer.java
@@ -39,6 +39,7 @@
import android.widget.TextView;
import com.android.launcher3.InsettableFrameLayout.LayoutParams;
+import com.android.launcher3.util.Thunk;
import java.util.ArrayList;
@@ -46,7 +47,7 @@
* A ViewGroup that coordinates dragging across its descendants
*/
public class DragLayer extends InsettableFrameLayout {
- private DragController mDragController;
+ @Thunk DragController mDragController;
private int[] mTmpXY = new int[2];
private int mXDown, mYDown;
@@ -61,9 +62,9 @@
private ValueAnimator mDropAnim = null;
private ValueAnimator mFadeOutAnim = null;
private TimeInterpolator mCubicEaseOutInterpolator = new DecelerateInterpolator(1.5f);
- private DragView mDropView = null;
- private int mAnchorViewInitialScrollX = 0;
- private View mAnchorView = null;
+ @Thunk DragView mDropView = null;
+ @Thunk int mAnchorViewInitialScrollX = 0;
+ @Thunk View mAnchorView = null;
private boolean mHoverPointClosesFolder = false;
private Rect mHitRect = new Rect();
@@ -779,7 +780,7 @@
return mDropView;
}
- private void fadeOutDragView() {
+ @Thunk void fadeOutDragView() {
mFadeOutAnim = new ValueAnimator();
mFadeOutAnim.setDuration(150);
mFadeOutAnim.setFloatValues(0f, 1f);
diff --git a/src/com/android/launcher3/DragView.java b/src/com/android/launcher3/DragView.java
index 78d72b3..b1a6266 100644
--- a/src/com/android/launcher3/DragView.java
+++ b/src/com/android/launcher3/DragView.java
@@ -29,8 +29,10 @@
import android.view.View;
import android.view.animation.DecelerateInterpolator;
+import com.android.launcher3.util.Thunk;
+
public class DragView extends View {
- private static float sDragAlpha = 1f;
+ @Thunk static float sDragAlpha = 1f;
private Bitmap mBitmap;
private Bitmap mCrossFadeBitmap;
@@ -42,11 +44,11 @@
private Rect mDragRegion = null;
private DragLayer mDragLayer = null;
private boolean mHasDrawn = false;
- private float mCrossFadeProgress = 0f;
+ @Thunk float mCrossFadeProgress = 0f;
ValueAnimator mAnim;
- private float mOffsetX = 0.0f;
- private float mOffsetY = 0.0f;
+ @Thunk float mOffsetX = 0.0f;
+ @Thunk float mOffsetY = 0.0f;
private float mInitialScale = 1f;
// The intrinsic icon scale factor is the scale factor for a drag icon over the workspace
// size. This is ignored for non-icons.
diff --git a/src/com/android/launcher3/DropTarget.java b/src/com/android/launcher3/DropTarget.java
index 7ede427..94ae82b 100644
--- a/src/com/android/launcher3/DropTarget.java
+++ b/src/com/android/launcher3/DropTarget.java
@@ -54,6 +54,9 @@
/** Where the drag originated */
public DragSource dragSource = null;
+ /** The object is part of an accessible drag operation */
+ public boolean accessibleDrag;
+
/** Post drag animation runnable */
public Runnable postAnimationRunnable = null;
diff --git a/src/com/android/launcher3/FirstFrameAnimatorHelper.java b/src/com/android/launcher3/FirstFrameAnimatorHelper.java
index 095c563..a51ddd4 100644
--- a/src/com/android/launcher3/FirstFrameAnimatorHelper.java
+++ b/src/com/android/launcher3/FirstFrameAnimatorHelper.java
@@ -24,6 +24,8 @@
import android.view.ViewPropertyAnimator;
import android.view.ViewTreeObserver;
+import com.android.launcher3.util.Thunk;
+
/*
* This is a helper class that listens to updates from the corresponding animation.
* For the first two frames, it adjusts the current play time of the animation to
@@ -41,7 +43,7 @@
private boolean mAdjustedSecondFrameTime;
private static ViewTreeObserver.OnDrawListener sGlobalDrawListener;
- private static long sGlobalFrameCounter;
+ @Thunk static long sGlobalFrameCounter;
private static boolean sVisible;
public FirstFrameAnimatorHelper(ValueAnimator animator, View target) {
diff --git a/src/com/android/launcher3/FocusHelper.java b/src/com/android/launcher3/FocusHelper.java
index 737f6cc..327fac4 100644
--- a/src/com/android/launcher3/FocusHelper.java
+++ b/src/com/android/launcher3/FocusHelper.java
@@ -23,7 +23,9 @@
import android.view.View;
import android.view.ViewGroup;
+import com.android.launcher3.FocusHelper.PagedViewKeyListener;
import com.android.launcher3.util.FocusLogic;
+import com.android.launcher3.util.Thunk;
/**
* A keyboard listener we set on all the workspace icons.
@@ -65,9 +67,32 @@
//
/**
+ * A keyboard listener for scrollable folders
+ */
+ public static class PagedFolderKeyEventListener extends PagedViewKeyListener {
+
+ private final Folder mFolder;
+
+ public PagedFolderKeyEventListener(Folder folder) {
+ mFolder = folder;
+ }
+
+ @Override
+ public void handleNoopKey(int keyCode, View v) {
+ if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
+ mFolder.mFolderName.requestFocus();
+ playSoundEffect(keyCode, v);
+ }
+ }
+ }
+
+ /**
* Handles key events in the all apps screen.
*/
- static boolean handleAppsCustomizeKeyEvent(View v, int keyCode, KeyEvent e) {
+ public static class PagedViewKeyListener implements View.OnKeyListener {
+
+ @Override
+ public boolean onKey(View v, int keyCode, KeyEvent e) {
boolean consume = FocusLogic.shouldConsume(keyCode);
if (e.getAction() == KeyEvent.ACTION_UP) {
return consume;
@@ -87,15 +112,14 @@
parentLayout = (ViewGroup) itemContainer.getParent();
countX = ((CellLayout) parentLayout).getCountX();
countY = ((CellLayout) parentLayout).getCountY();
- } else if (v.getParent() instanceof ViewGroup) {
- //TODO(hyunyoungs): figure out when this needs to be called.
- itemContainer = parentLayout = (ViewGroup) v.getParent();
- countX = ((PagedViewGridLayout) parentLayout).getCellCountX();
- countY = ((PagedViewGridLayout) parentLayout).getCellCountY();
} else {
- throw new IllegalStateException(
- "Parent of the focused item inside all apps screen is not a supported type.");
+ if (LauncherAppState.isDogfoodBuild()) {
+ throw new IllegalStateException("Parent of the focused item is not supported.");
+ } else {
+ return false;
+ }
}
+
final int iconIndex = itemContainer.indexOfChild(v);
final PagedView container = (PagedView) parentLayout.getParent();
final int pageIndex = container.indexToPage(container.indexOfChild(parentLayout));
@@ -109,6 +133,7 @@
int newIconIndex = FocusLogic.handleKeyEvent(keyCode, countX, countY, matrix,
iconIndex, pageIndex, pageCount);
if (newIconIndex == FocusLogic.NOOP) {
+ handleNoopKey(keyCode, v);
return consume;
}
switch (newIconIndex) {
@@ -163,10 +188,15 @@
if (child != null) {
child.requestFocus();
playSoundEffect(keyCode, v);
+ } else {
+ handleNoopKey(keyCode, v);
}
return consume;
}
+ public void handleNoopKey(int keyCode, View v) { }
+ }
+
/**
* Handles key events in the workspace hot seat (bottom of the screen).
* <p>Currently we don't special case for the phone UI in different orientations, even though
@@ -178,12 +208,13 @@
if (e.getAction() == KeyEvent.ACTION_UP || !consume) {
return consume;
}
- int orientation = v.getResources().getConfiguration().orientation;
+ LauncherAppState app = LauncherAppState.getInstance();
+ DeviceProfile profile = app.getDynamicGrid().getDeviceProfile();
if (DEBUG) {
Log.v(TAG, String.format(
- "Handle HOTSEAT BUTTONS keyevent=[%s] on hotseat buttons, orientation=%d",
- KeyEvent.keyCodeToString(keyCode), orientation));
+ "Handle HOTSEAT BUTTONS keyevent=[%s] on hotseat buttons, isVertical=%s",
+ KeyEvent.keyCodeToString(keyCode), profile.isVerticalBarLayout()));
}
// Initialize the variables.
@@ -197,6 +228,8 @@
int countX = -1;
int countY = -1;
int iconIndex = findIndexOfView(hotseatParent, v);
+ int iconRank = ((CellLayout.LayoutParams) hotseatLayout.getShortcutsAndWidgets()
+ .getChildAt(iconIndex).getLayoutParams()).cellX;
final CellLayout iconLayout = (CellLayout) workspace.getChildAt(pageIndex);
final ViewGroup iconParent = iconLayout.getShortcutsAndWidgets();
@@ -205,23 +238,25 @@
int[][] matrix = null;
if (keyCode == KeyEvent.KEYCODE_DPAD_UP &&
- orientation == Configuration.ORIENTATION_PORTRAIT) {
- matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, orientation,
- hotseat.getAllAppsButtonRank(), true /* include all apps icon */);
+ !profile.isVerticalBarLayout()) {
+ matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout,
+ true /* hotseat horizontal */, hotseat.getAllAppsButtonRank(),
+ iconRank == hotseat.getAllAppsButtonRank() /* include all apps icon */);
iconIndex += iconParent.getChildCount();
countX = iconLayout.getCountX();
countY = iconLayout.getCountY() + hotseatLayout.getCountY();
parent = iconParent;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT &&
- orientation == Configuration.ORIENTATION_LANDSCAPE) {
- matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, orientation,
- hotseat.getAllAppsButtonRank(), true /* include all apps icon */);
+ profile.isVerticalBarLayout()) {
+ matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout,
+ false /* hotseat horizontal */, hotseat.getAllAppsButtonRank(),
+ iconRank == hotseat.getAllAppsButtonRank() /* include all apps icon */);
iconIndex += iconParent.getChildCount();
countX = iconLayout.getCountX() + hotseatLayout.getCountX();
countY = iconLayout.getCountY();
parent = iconParent;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT &&
- orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ profile.isVerticalBarLayout()) {
keyCode = KeyEvent.KEYCODE_PAGE_DOWN;
}else {
// For other KEYCODE_DPAD_LEFT and KEYCODE_DPAD_RIGHT navigation, do not use the
@@ -267,10 +302,13 @@
if (e.getAction() == KeyEvent.ACTION_UP || !consume) {
return consume;
}
- int orientation = v.getResources().getConfiguration().orientation;
+
+ LauncherAppState app = LauncherAppState.getInstance();
+ DeviceProfile profile = app.getDynamicGrid().getDeviceProfile();
+
if (DEBUG) {
- Log.v(TAG, String.format("Handle WORKSPACE ICONS keyevent=[%s] orientation=%d",
- KeyEvent.keyCodeToString(keyCode), orientation));
+ Log.v(TAG, String.format("Handle WORKSPACE ICONS keyevent=[%s] isVerticalBar=%s",
+ KeyEvent.keyCodeToString(keyCode), profile.isVerticalBarLayout()));
}
// Initialize the variables.
@@ -293,14 +331,13 @@
// KEYCODE_DPAD_DOWN in portrait (KEYCODE_DPAD_RIGHT in landscape) is the only key allowed
// to take a user to the hotseat. For other dpad navigation, do not use the matrix extended
// with the hotseat.
- if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN &&
- orientation == Configuration.ORIENTATION_PORTRAIT) {
- matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, orientation,
+ if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && !profile.isVerticalBarLayout()) {
+ matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, true /* horizontal */,
hotseat.getAllAppsButtonRank(), false /* all apps icon is ignored */);
countY = countY + 1;
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT &&
- orientation == Configuration.ORIENTATION_LANDSCAPE) {
- matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, orientation,
+ profile.isVerticalBarLayout()) {
+ matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, false /* horizontal */,
hotseat.getAllAppsButtonRank(), false /* all apps icon is ignored */);
countX = countX + 1;
} else if (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) {
@@ -444,7 +481,7 @@
/**
* Returns the Viewgroup containing page contents for the page at the index specified.
*/
- private static ViewGroup getAppsCustomizePage(ViewGroup container, int index) {
+ @Thunk static ViewGroup getAppsCustomizePage(ViewGroup container, int index) {
ViewGroup page = (ViewGroup) ((PagedView) container).getPageAt(index);
if (page instanceof CellLayout) {
// There are two layers, a PagedViewCellLayout and PagedViewCellLayoutChildren
@@ -474,7 +511,7 @@
/**
* Helper method to be used for playing sound effects.
*/
- private static void playSoundEffect(int keyCode, View v) {
+ @Thunk static void playSoundEffect(int keyCode, View v) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
diff --git a/src/com/android/launcher3/FocusIndicatorView.java b/src/com/android/launcher3/FocusIndicatorView.java
index 7d4664a..ab21c90 100644
--- a/src/com/android/launcher3/FocusIndicatorView.java
+++ b/src/com/android/launcher3/FocusIndicatorView.java
@@ -23,7 +23,8 @@
import android.util.AttributeSet;
import android.util.Pair;
import android.view.View;
-import android.view.ViewParent;
+
+import com.android.launcher3.util.Thunk;
public class FocusIndicatorView extends View implements View.OnFocusChangeListener {
@@ -32,9 +33,6 @@
private static final float MIN_VISIBLE_ALPHA = 0.2f;
private static final long ANIM_DURATION = 150;
- private static final int[] sTempPos = new int[2];
- private static final int[] sTempShift = new int[2];
-
private final int[] mIndicatorPos = new int[2];
private final int[] mTargetViewPos = new int[2];
@@ -80,7 +78,8 @@
}
if (!mInitiated) {
- getLocationRelativeToParentPagedView(this, mIndicatorPos);
+ // The parent view should always the a parent of the target view.
+ computeLocationRelativeToParent(this, (View) getParent(), mIndicatorPos);
mInitiated = true;
}
@@ -93,7 +92,7 @@
nextState.scaleX = v.getScaleX() * v.getWidth() / indicatorWidth;
nextState.scaleY = v.getScaleY() * v.getHeight() / indicatorHeight;
- getLocationRelativeToParentPagedView(v, mTargetViewPos);
+ computeLocationRelativeToParent(v, (View) getParent(), mTargetViewPos);
nextState.x = mTargetViewPos[0] - mIndicatorPos[0] - (1 - nextState.scaleX) * indicatorWidth / 2;
nextState.y = mTargetViewPos[1] - mIndicatorPos[1] - (1 - nextState.scaleY) * indicatorHeight / 2;
@@ -150,31 +149,36 @@
}
/**
- * Gets the location of a view relative in the window, off-setting any shift due to
- * page view scroll
+ * Computes the location of a view relative to {@link #mCommonParent}, off-setting
+ * any shift due to page view scroll.
+ * @param pos an array of two integers in which to hold the coordinates
*/
- private static void getLocationRelativeToParentPagedView(View v, int[] pos) {
- getPagedViewScrollShift(v, sTempShift);
- v.getLocationInWindow(sTempPos);
- pos[0] = sTempPos[0] + sTempShift[0];
- pos[1] = sTempPos[1] + sTempShift[1];
+ private static void computeLocationRelativeToParent(View v, View parent, int[] pos) {
+ pos[0] = pos[1] = 0;
+ computeLocationRelativeToParentHelper(v, parent, pos);
+
+ // If a view is scaled, its position will also shift accordingly. For optimization, only
+ // consider this for the last node.
+ pos[0] += (1 - v.getScaleX()) * v.getWidth() / 2;
+ pos[1] += (1 - v.getScaleY()) * v.getHeight() / 2;
}
- private static void getPagedViewScrollShift(View child, int[] shift) {
- ViewParent parent = child.getParent();
+ private static void computeLocationRelativeToParentHelper(View child,
+ View commonParent, int[] shift) {
+ View parent = (View) child.getParent();
if (parent instanceof PagedView) {
- View parentView = (View) parent;
- child.getLocationInWindow(sTempPos);
- shift[0] = parentView.getPaddingLeft() - sTempPos[0];
- shift[1] = -(int) child.getTranslationY();
- } else if (parent instanceof View) {
- getPagedViewScrollShift((View) parent, shift);
- } else {
- shift[0] = shift[1] = 0;
+ child = ((PagedView) parent).getPageAt(0);
+ }
+
+ shift[0] += child.getLeft();
+ shift[1] += child.getTop();
+
+ if (parent != commonParent) {
+ computeLocationRelativeToParentHelper(parent, commonParent, shift);
}
}
- private static final class ViewAnimState {
+ @Thunk static final class ViewAnimState {
float x, y, scaleX, scaleY;
}
}
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index 4414672..4529a94 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -24,6 +24,7 @@
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
+import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Build;
@@ -39,6 +40,7 @@
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
+import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.AccelerateInterpolator;
@@ -49,6 +51,7 @@
import com.android.launcher3.FolderInfo.FolderListener;
import com.android.launcher3.Workspace.ItemOperator;
+import com.android.launcher3.util.Thunk;
import java.util.ArrayList;
import java.util.Collections;
@@ -66,12 +69,34 @@
* results in CellLayout being measured as UNSPECIFIED, which it does not support.
*/
private static final int MIN_CONTENT_DIMEN = 5;
+ private static final boolean ALLOW_FOLDER_SCROLL = true;
static final int STATE_NONE = -1;
static final int STATE_SMALL = 0;
static final int STATE_ANIMATING = 1;
static final int STATE_OPEN = 2;
+ /**
+ * Fraction of the width to scroll when showing the next page hint.
+ */
+ private static final float SCROLL_HINT_FRACTION = 0.07f;
+
+ /**
+ * Time for which the scroll hint is shown before automatically changing page.
+ */
+ public static final int SCROLL_HINT_DURATION = DragController.SCROLL_DELAY;
+
+ /**
+ * Time in milliseconds for which an icon sticks to the target position
+ * in case of a sorted folder.
+ */
+ private static final int SORTED_STICKY_REORDER_DELAY = 1500;
+
+ /**
+ * Fraction of icon width which behave as scroll region.
+ */
+ private static final float ICON_OVERSCROLL_WIDTH_FACTOR = 0.45f;
+
private static final int REORDER_DELAY = 250;
private static final int ON_EXIT_CLOSE_DELAY = 400;
private static final Rect sTempRect = new Rect();
@@ -82,7 +107,7 @@
private final Alarm mReorderAlarm = new Alarm();
private final Alarm mOnExitAlarm = new Alarm();
- private final ArrayList<View> mItemsInReadingOrder = new ArrayList<View>();
+ @Thunk final ArrayList<View> mItemsInReadingOrder = new ArrayList<View>();
private final int mExpandDuration;
private final int mMaterialExpandDuration;
@@ -94,19 +119,19 @@
protected DragController mDragController;
protected FolderInfo mInfo;
- private FolderIcon mFolderIcon;
+ @Thunk FolderIcon mFolderIcon;
- private FolderContent mContent;
- private View mContentWrapper;
+ @Thunk FolderContent mContent;
+ @Thunk View mContentWrapper;
FolderEditText mFolderName;
- private View mBottomContent;
- private int mBottomContentHeight;
+ private View mFooter;
+ private int mFooterHeight;
// Cell ranks used for drag and drop
- private int mTargetRank, mPrevTargetRank, mEmptyCellRank;
+ @Thunk int mTargetRank, mPrevTargetRank, mEmptyCellRank;
- private int mState = STATE_NONE;
+ @Thunk int mState = STATE_NONE;
private boolean mRearrangeOnClose = false;
boolean mItemsInvalidated = false;
private ShortcutInfo mCurrentDragInfo;
@@ -117,16 +142,27 @@
private boolean mDeleteFolderOnDropCompleted = false;
private boolean mSuppressFolderDeletion = false;
private boolean mItemAddedBackToSelfViaIcon = false;
- private float mFolderIconPivotX;
- private float mFolderIconPivotY;
+ @Thunk float mFolderIconPivotX;
+ @Thunk float mFolderIconPivotY;
private boolean mIsEditingName = false;
private boolean mDestroyed;
- private Runnable mDeferredAction;
+ @Thunk Runnable mDeferredAction;
private boolean mDeferDropAfterUninstall;
private boolean mUninstallSuccessful;
+ // Folder scrolling
+ private int mScrollAreaOffset;
+ private Alarm mOnScrollHintAlarm;
+ @Thunk Alarm mScrollPauseAlarm;
+
+ // TODO: Use {@link #mContent} once {@link #ALLOW_FOLDER_SCROLL} is removed.
+ @Thunk FolderPagedView mPagedView;
+
+ @Thunk int mScrollHintDir = DragController.SCROLL_NONE;
+ @Thunk int mCurrentScrollDir = DragController.SCROLL_NONE;
+
/**
* Used to inflate the Workspace from XML.
*
@@ -155,6 +191,11 @@
// name is complete, we have something to focus on, thus hiding the cursor and giving
// reliable behavior when clicking the text field (since it will always gain focus on click).
setFocusableInTouchMode(true);
+
+ if (ALLOW_FOLDER_SCROLL) {
+ mOnScrollHintAlarm = new Alarm();
+ mScrollPauseAlarm = new Alarm();
+ }
}
@Override
@@ -175,13 +216,16 @@
mFolderName.setInputType(mFolderName.getInputType() |
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
- // We only have the folder name at the bottom for now
- mBottomContent = mFolderName;
- // We find out how tall the bottom content wants to be (it is set to wrap_content), so that
+ mFooter = ALLOW_FOLDER_SCROLL ? findViewById(R.id.folder_footer) : mFolderName;
+ // We find out how tall footer wants to be (it is set to wrap_content), so that
// we can allocate the appropriate amount of space for it.
int measureSpec = MeasureSpec.UNSPECIFIED;
- mBottomContent.measure(measureSpec, measureSpec);
- mBottomContentHeight = mBottomContent.getMeasuredHeight();
+ mFooter.measure(measureSpec, measureSpec);
+ mFooterHeight = mFooter.getMeasuredHeight();
+
+ if (ALLOW_FOLDER_SCROLL) {
+ mPagedView = (FolderPagedView) mContent;
+ }
}
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
@@ -219,13 +263,13 @@
return false;
}
- mLauncher.getWorkspace().beginDragShared(v, this);
+ mLauncher.getWorkspace().beginDragShared(v, new Point(), this, false);
mCurrentDragInfo = item;
mEmptyCellRank = item.rank;
mCurrentDragView = v;
- mContent.removeView(mCurrentDragView);
+ mContent.removeItem(mCurrentDragView);
mInfo.remove(mCurrentDragInfo);
mDragInProgress = true;
mItemAddedBackToSelfViaIcon = false;
@@ -359,7 +403,8 @@
* @return A new UserFolder.
*/
static Folder fromXml(Context context) {
- return (Folder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
+ return (Folder) LayoutInflater.from(context).inflate(
+ ALLOW_FOLDER_SCROLL ? R.layout.user_folder_scroll : R.layout.user_folder, null);
}
/**
@@ -384,6 +429,14 @@
public void animateOpen() {
if (!(getParent() instanceof DragLayer)) return;
+ if (ALLOW_FOLDER_SCROLL) {
+ mPagedView.completePendingPageChanges();
+ if (!(mDragInProgress && mPagedView.mIsSorted)) {
+ // Open on the first page.
+ mPagedView.snapToPageImmediately(0);
+ }
+ }
+
Animator openFolderAnim = null;
final Runnable onCompleteRunnable;
if (!Utilities.isLmpOrAbove()) {
@@ -434,8 +487,8 @@
iconsAlpha.setStartDelay(mMaterialExpandStagger);
iconsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
- mBottomContent.setAlpha(0f);
- Animator textAlpha = LauncherAnimUtils.ofFloat(mBottomContent, "alpha", 0f, 1f);
+ mFooter.setAlpha(0f);
+ Animator textAlpha = LauncherAnimUtils.ofFloat(mFooter, "alpha", 0f, 1f);
textAlpha.setDuration(mMaterialExpandDuration);
textAlpha.setStartDelay(mMaterialExpandStagger);
textAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
@@ -484,16 +537,27 @@
if (mDragController.isDragging()) {
mDragController.forceTouchMove();
}
+
+ if (ALLOW_FOLDER_SCROLL) {
+ FolderPagedView pages = (FolderPagedView) mContent;
+ pages.verifyVisibleHighResIcons(pages.getNextPage());
+ }
}
public void beginExternalDrag(ShortcutInfo item) {
mCurrentDragInfo = item;
- mEmptyCellRank = mContent.allocateNewLastItemRank();
+ mEmptyCellRank = mContent.allocateRankForNewItem(item);
mIsExternalDrag = true;
mDragInProgress = true;
+ if (ALLOW_FOLDER_SCROLL && mPagedView.mIsSorted) {
+ mScrollPauseAlarm.setOnAlarmListener(null);
+ mScrollPauseAlarm.cancelAlarm();
+ mScrollPauseAlarm.setAlarm(SORTED_STICKY_REORDER_DELAY);
+ }
+
}
- private void sendCustomAccessibilityEvent(int type, String text) {
+ @Thunk void sendCustomAccessibilityEvent(int type, String text) {
AccessibilityManager accessibilityManager = (AccessibilityManager)
getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
if (accessibilityManager.isEnabled()) {
@@ -542,6 +606,11 @@
public void onDragEnter(DragObject d) {
mPrevTargetRank = -1;
mOnExitAlarm.cancelAlarm();
+ if (ALLOW_FOLDER_SCROLL) {
+ // Get the area offset such that the folder only closes if half the drag icon width
+ // is outside the folder area
+ mScrollAreaOffset = d.dragView.getDragRegionWidth() / 2 - d.xOffset;
+ }
}
OnAlarmListener mReorderAlarmListener = new OnAlarmListener() {
@@ -556,18 +625,80 @@
return (getLayoutDirection() == LAYOUT_DIRECTION_RTL);
}
+ @Override
public void onDragOver(DragObject d) {
- final float[] r = d.getVisualCenter(null);
- r[0] -= getPaddingLeft();
- r[1] -= getPaddingTop();
+ onDragOver(d, REORDER_DELAY);
+ }
- mTargetRank = mContent.findNearestArea((int) r[0], (int) r[1]);
+ private int getTargetRank(DragObject d, float[] recycle) {
+ recycle = d.getVisualCenter(recycle);
+ return mContent.findNearestArea(
+ (int) recycle[0] - getPaddingLeft(), (int) recycle[1] - getPaddingTop());
+ }
+
+ @Thunk void onDragOver(DragObject d, int reorderDelay) {
+ if (ALLOW_FOLDER_SCROLL && mScrollPauseAlarm.alarmPending()) {
+ return;
+ }
+ final float[] r = new float[2];
+ mTargetRank = getTargetRank(d, r);
+
if (mTargetRank != mPrevTargetRank) {
mReorderAlarm.cancelAlarm();
mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
mReorderAlarm.setAlarm(REORDER_DELAY);
mPrevTargetRank = mTargetRank;
}
+
+ if (!ALLOW_FOLDER_SCROLL) {
+ return;
+ }
+
+ float x = r[0];
+ int currentPage = mPagedView.getNextPage();
+ int cellWidth = mPagedView.getCurrentCellLayout().getCellWidth();
+ if (currentPage > 0 && x < cellWidth * ICON_OVERSCROLL_WIDTH_FACTOR) {
+ // Show scroll hint on the left
+ if (mScrollHintDir != DragController.SCROLL_LEFT) {
+ mPagedView.showScrollHint(-SCROLL_HINT_FRACTION);
+ mScrollHintDir = DragController.SCROLL_LEFT;
+ }
+
+ // Set alarm for when the hint is complete
+ if (!mOnScrollHintAlarm.alarmPending() || mCurrentScrollDir != DragController.SCROLL_LEFT) {
+ mCurrentScrollDir = DragController.SCROLL_LEFT;
+ mOnScrollHintAlarm.cancelAlarm();
+ mOnScrollHintAlarm.setOnAlarmListener(new OnScrollHintListener(d));
+ mOnScrollHintAlarm.setAlarm(SCROLL_HINT_DURATION);
+
+ mReorderAlarm.cancelAlarm();
+ mTargetRank = mEmptyCellRank;
+ }
+ } else if (currentPage < (mPagedView.getPageCount() - 1) &&
+ (x > (getWidth() - cellWidth * ICON_OVERSCROLL_WIDTH_FACTOR))) {
+ // Show scroll hint on the right
+ if (mScrollHintDir != DragController.SCROLL_RIGHT) {
+ mPagedView.showScrollHint(SCROLL_HINT_FRACTION);
+ mScrollHintDir = DragController.SCROLL_RIGHT;
+ }
+
+ // Set alarm for when the hint is complete
+ if (!mOnScrollHintAlarm.alarmPending() || mCurrentScrollDir != DragController.SCROLL_RIGHT) {
+ mCurrentScrollDir = DragController.SCROLL_RIGHT;
+ mOnScrollHintAlarm.cancelAlarm();
+ mOnScrollHintAlarm.setOnAlarmListener(new OnScrollHintListener(d));
+ mOnScrollHintAlarm.setAlarm(SCROLL_HINT_DURATION);
+
+ mReorderAlarm.cancelAlarm();
+ mTargetRank = mEmptyCellRank;
+ }
+ } else {
+ mOnScrollHintAlarm.cancelAlarm();
+ if (mScrollHintDir != DragController.SCROLL_NONE) {
+ mPagedView.clearScrollHint();
+ mScrollHintDir = DragController.SCROLL_NONE;
+ }
+ }
}
OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
@@ -593,6 +724,15 @@
mOnExitAlarm.setAlarm(ON_EXIT_CLOSE_DELAY);
}
mReorderAlarm.cancelAlarm();
+
+ if (ALLOW_FOLDER_SCROLL) {
+ mOnScrollHintAlarm.cancelAlarm();
+ mScrollPauseAlarm.cancelAlarm();
+ if (mScrollHintDir != DragController.SCROLL_NONE) {
+ mPagedView.clearScrollHint();
+ mScrollHintDir = DragController.SCROLL_NONE;
+ }
+ }
}
public void onDropCompleted(final View target, final DragObject d,
@@ -628,6 +768,7 @@
if (!successfulDrop) {
mSuppressFolderDeletion = true;
}
+ mScrollPauseAlarm.cancelAlarm();
completeDragExit();
}
}
@@ -704,7 +845,7 @@
View v = list.get(i);
ItemInfo info = (ItemInfo) v.getTag();
LauncherModel.addItemToDatabase(mLauncher, info, mInfo.id, 0,
- info.cellX, info.cellY, false);
+ info.cellX, info.cellY);
}
}
@@ -795,7 +936,7 @@
CellLayout.LANDSCAPE : CellLayout.PORTRAIT);
int maxContentAreaHeight = grid.availableHeightPx -
workspacePadding.top - workspacePadding.bottom -
- mBottomContentHeight;
+ mFooterHeight;
int height = Math.min(maxContentAreaHeight,
mContent.getDesiredHeight());
return Math.max(height, MIN_CONTENT_DIMEN);
@@ -810,7 +951,7 @@
}
private int getFolderHeight(int contentAreaHeight) {
- return getPaddingTop() + getPaddingBottom() + contentAreaHeight + mBottomContentHeight;
+ return getPaddingTop() + getPaddingBottom() + contentAreaHeight + mFooterHeight;
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@@ -822,10 +963,8 @@
mContent.setFixedSize(contentWidth, contentHeight);
mContentWrapper.measure(contentAreaWidthSpec, contentAreaHeightSpec);
-
- // Move the bottom content below mContent
- mBottomContent.measure(contentAreaWidthSpec,
- MeasureSpec.makeMeasureSpec(mBottomContentHeight, MeasureSpec.EXACTLY));
+ mFooter.measure(contentAreaWidthSpec,
+ MeasureSpec.makeMeasureSpec(mFooterHeight, MeasureSpec.EXACTLY));
int folderWidth = getPaddingLeft() + getPaddingRight() + contentWidth;
int folderHeight = getFolderHeight(contentHeight);
@@ -850,11 +989,16 @@
mItemsInvalidated = true;
}
+ // TODO remove this once GSA code fix is submitted
+ public ViewGroup getContent() {
+ return (ViewGroup) mContent;
+ }
+
public int getItemCount() {
return mContent.getItemCount();
}
- private void onCloseComplete() {
+ @Thunk void onCloseComplete() {
DragLayer parent = (DragLayer) getParent();
if (parent != null) {
parent.removeView(this);
@@ -877,7 +1021,7 @@
mSuppressFolderDeletion = false;
}
- private void replaceFolderWithFinalItem() {
+ @Thunk void replaceFolderWithFinalItem() {
// Add the last remaining child to the workspace in place of the folder
Runnable onCompleteRunnable = new Runnable() {
@Override
@@ -929,7 +1073,7 @@
// This method keeps track of the last item in the folder for the purposes
// of keyboard focus
- private void updateTextViewFocus() {
+ public void updateTextViewFocus() {
View lastChild = mContent.getLastItem();
if (lastChild != null) {
mFolderName.setNextFocusDownId(lastChild.getId());
@@ -955,6 +1099,22 @@
};
}
+ if (ALLOW_FOLDER_SCROLL) {
+ // If the icon was dropped while the page was being scrolled, we need to compute
+ // the target location again such that the icon is placed of the final page.
+ if (!mPagedView.rankOnCurrentPage(mEmptyCellRank)) {
+ // Reorder again.
+ mTargetRank = getTargetRank(d, null);
+
+ // Rearrange items immediately.
+ mReorderAlarmListener.onAlarm(mReorderAlarm);
+
+ mOnScrollHintAlarm.cancelAlarm();
+ mScrollPauseAlarm.cancelAlarm();
+ }
+ mPagedView.completePendingPageChanges();
+ }
+
View currentDragView;
ShortcutInfo si = mCurrentDragInfo;
if (mIsExternalDrag) {
@@ -1013,11 +1173,11 @@
}
public void onAdd(ShortcutInfo item) {
- mItemsInvalidated = true;
// If the item was dropped onto this open folder, we have done the work associated
// with adding the item to the folder, as indicated by mSuppressOnAdd being set
if (mSuppressOnAdd) return;
- mContent.createAndAddViewForRank(item, mContent.allocateNewLastItemRank());
+ mContent.createAndAddViewForRank(item, mContent.allocateRankForNewItem(item));
+ mItemsInvalidated = true;
LauncherModel.addOrMoveItemInDatabase(
mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
}
@@ -1028,7 +1188,7 @@
// the work associated with removing the item, so we don't have to do anything here.
if (item == mCurrentDragInfo) return;
View v = getViewForInfo(item);
- mContent.removeView(v);
+ mContent.removeItem(v);
if (mState == STATE_ANIMATING) {
mRearrangeOnClose = true;
} else {
@@ -1085,12 +1245,63 @@
@Override
public void getHitRectRelativeToDragLayer(Rect outRect) {
getHitRect(outRect);
+ outRect.left -= mScrollAreaOffset;
+ outRect.right += mScrollAreaOffset;
+ }
+
+ private class OnScrollHintListener implements OnAlarmListener {
+
+ private final DragObject mDragObject;
+
+ OnScrollHintListener(DragObject object) {
+ mDragObject = object;
+ }
+
+ /**
+ * Scroll hint has been shown long enough. Now scroll to appropriate page.
+ */
+ @Override
+ public void onAlarm(Alarm alarm) {
+ if (mCurrentScrollDir == DragController.SCROLL_LEFT) {
+ mPagedView.scrollLeft();
+ mScrollHintDir = DragController.SCROLL_NONE;
+ } else if (mCurrentScrollDir == DragController.SCROLL_RIGHT) {
+ mPagedView.scrollRight();
+ mScrollHintDir = DragController.SCROLL_NONE;
+ } else {
+ // This should not happen
+ return;
+ }
+ mCurrentScrollDir = DragController.SCROLL_NONE;
+
+ // Pause drag event until the scrolling is finished
+ mScrollPauseAlarm.setOnAlarmListener(new OnScrollFinishedListener(mDragObject));
+ mScrollPauseAlarm.setAlarm(DragController.RESCROLL_DELAY);
+ }
+ }
+
+ private class OnScrollFinishedListener implements OnAlarmListener {
+
+ private final DragObject mDragObject;
+
+ OnScrollFinishedListener(DragObject object) {
+ mDragObject = object;
+ }
+
+ /**
+ * Page scroll is complete.
+ */
+ @Override
+ public void onAlarm(Alarm alarm) {
+ // Reorder immediately on page change.
+ onDragOver(mDragObject, 1);
+ }
}
public static interface FolderContent {
void setFolder(Folder f);
- void removeView(View v);
+ void removeItem(View v);
boolean isFull();
int getItemCount();
@@ -1115,10 +1326,10 @@
ArrayList<ShortcutInfo> bindItems(ArrayList<ShortcutInfo> children);
/**
- * Create space for a new item at the end, and returns the rank for that item.
+ * Create space for a new item, and returns the rank for that item.
* Resizes the content if necessary.
*/
- int allocateNewLastItemRank();
+ int allocateRankForNewItem(ShortcutInfo info);
View createAndAddViewForRank(ShortcutInfo item, int rank);
diff --git a/src/com/android/launcher3/FolderCellLayout.java b/src/com/android/launcher3/FolderCellLayout.java
index 21f2a11..8585add 100644
--- a/src/com/android/launcher3/FolderCellLayout.java
+++ b/src/com/android/launcher3/FolderCellLayout.java
@@ -1,3 +1,19 @@
+/**
+ * Copyright (C) 2015 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.launcher3;
import android.content.Context;
@@ -117,7 +133,7 @@
}
@Override
- public int allocateNewLastItemRank() {
+ public int allocateRankForNewItem(ShortcutInfo info) {
int rank = getItemCount();
mFolder.rearrangeChildren(rank + 1);
return rank;
@@ -135,7 +151,12 @@
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams();
lp.cellX = item.cellX;
lp.cellY = item.cellY;
- addViewToCellLayout(view, -1, (int) item.id, lp, true);
+ addViewToCellLayout(view, -1, mFolder.mLauncher.getViewIdForItem(item), lp, true);
+ }
+
+ @Override
+ public void removeItem(View v) {
+ removeView(v);
}
/**
@@ -159,7 +180,7 @@
CellLayout.LayoutParams lp = new CellLayout.LayoutParams(
item.cellX, item.cellY, item.spanX, item.spanY);
- addViewToCellLayout(textView, -1, (int)item.id, lp, true);
+ addViewToCellLayout(textView, -1, mFolder.mLauncher.getViewIdForItem(item), lp, true);
return textView;
}
@@ -211,7 +232,7 @@
lp.cellX = info.cellX;
lp.cellY = info.cellY;
rank ++;
- addViewToCellLayout(v, -1, (int)info.id, lp, true);
+ addViewToCellLayout(v, -1, mFolder.mLauncher.getViewIdForItem(info), lp, true);
}
}
@@ -244,8 +265,14 @@
@Override
public View getLastItem() {
- int total = getShortcutsAndWidgets().getChildCount();
- return getShortcutsAndWidgets().getChildAt(total % getCountX(), total / getCountX());
+ int lastRank = getShortcutsAndWidgets().getChildCount() - 1;
+ // count can be zero if the folder is not yet laid out.
+ int count = getCountX();
+ if (count > 0) {
+ return getShortcutsAndWidgets().getChildAt(lastRank % count, lastRank / count);
+ } else {
+ return getShortcutsAndWidgets().getChildAt(lastRank);
+ }
}
@Override
diff --git a/src/com/android/launcher3/FolderIcon.java b/src/com/android/launcher3/FolderIcon.java
index a3e8295..f5836c2 100644
--- a/src/com/android/launcher3/FolderIcon.java
+++ b/src/com/android/launcher3/FolderIcon.java
@@ -43,6 +43,7 @@
import com.android.launcher3.DropTarget.DragObject;
import com.android.launcher3.FolderInfo.FolderListener;
+import com.android.launcher3.util.Thunk;
import java.util.ArrayList;
@@ -50,15 +51,15 @@
* An icon that can appear on in the workspace representing an {@link UserFolder}.
*/
public class FolderIcon extends FrameLayout implements FolderListener {
- private Launcher mLauncher;
- private Folder mFolder;
+ @Thunk Launcher mLauncher;
+ @Thunk Folder mFolder;
private FolderInfo mInfo;
- private static boolean sStaticValuesDirty = true;
+ @Thunk static boolean sStaticValuesDirty = true;
private CheckLongPressHelper mLongPressHelper;
// The number of icons to display in the
- private static final int NUM_ITEMS_IN_PREVIEW = 3;
+ public static final int NUM_ITEMS_IN_PREVIEW = 3;
private static final int CONSUMPTION_ANIMATION_DURATION = 100;
private static final int DROP_IN_ANIMATION_DURATION = 400;
private static final int INITIAL_ITEM_ANIMATION_DURATION = 350;
@@ -88,8 +89,8 @@
public static Drawable sSharedFolderLeaveBehind = null;
- private ImageView mPreviewBackground;
- private BubbleTextView mFolderName;
+ @Thunk ImageView mPreviewBackground;
+ @Thunk BubbleTextView mFolderName;
FolderRingAnimator mFolderRingAnimator = null;
@@ -109,11 +110,11 @@
private float mSlop;
private PreviewItemDrawingParams mParams = new PreviewItemDrawingParams(0, 0, 0, 0);
- private PreviewItemDrawingParams mAnimParams = new PreviewItemDrawingParams(0, 0, 0, 0);
- private ArrayList<ShortcutInfo> mHiddenItems = new ArrayList<ShortcutInfo>();
+ @Thunk PreviewItemDrawingParams mAnimParams = new PreviewItemDrawingParams(0, 0, 0, 0);
+ @Thunk ArrayList<ShortcutInfo> mHiddenItems = new ArrayList<ShortcutInfo>();
private Alarm mOpenAlarm = new Alarm();
- private ItemInfo mDragInfo;
+ @Thunk ItemInfo mDragInfo;
public FolderIcon(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -192,7 +193,7 @@
public static class FolderRingAnimator {
public int mCellX;
public int mCellY;
- private CellLayout mCellLayout;
+ @Thunk CellLayout mCellLayout;
public float mOuterRingSize;
public float mInnerRingSize;
public FolderIcon mFolderIcon = null;
diff --git a/src/com/android/launcher3/FolderInfo.java b/src/com/android/launcher3/FolderInfo.java
index 85a792f..3240cbf 100644
--- a/src/com/android/launcher3/FolderInfo.java
+++ b/src/com/android/launcher3/FolderInfo.java
@@ -29,11 +29,20 @@
*/
public class FolderInfo extends ItemInfo {
+ public static final int NO_FLAGS = 0x00000000;
+
+ /**
+ * The folder is locked in sorted mode
+ */
+ public static final int FLAG_ITEMS_SORTED = 0x00000001;
+
/**
* Whether this folder has been opened
*/
boolean opened;
+ public int options;
+
/**
* The apps and shortcuts
*/
@@ -83,6 +92,8 @@
void onAddToDatabase(Context context, ContentValues values) {
super.onAddToDatabase(context, values);
values.put(LauncherSettings.Favorites.TITLE, title.toString());
+ values.put(LauncherSettings.Favorites.OPTIONS, options);
+
}
void addListener(FolderListener listener) {
@@ -121,4 +132,25 @@
+ " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX
+ " spanY=" + spanY + " dropPos=" + Arrays.toString(dropPos) + ")";
}
+
+ public boolean hasOption(int optionFlag) {
+ return (options & optionFlag) != 0;
+ }
+
+ /**
+ * @param option flag to set or clear
+ * @param isEnabled whether to set or clear the flag
+ * @param context if not null, save changes to the db.
+ */
+ public void setOption(int option, boolean isEnabled, Context context) {
+ int oldOptions = options;
+ if (isEnabled) {
+ options |= option;
+ } else {
+ options &= ~option;
+ }
+ if (context != null && oldOptions != options) {
+ LauncherModel.updateItemInDatabase(context, this);
+ }
+ }
}
diff --git a/src/com/android/launcher3/FolderPagedView.java b/src/com/android/launcher3/FolderPagedView.java
new file mode 100644
index 0000000..61ad10d
--- /dev/null
+++ b/src/com/android/launcher3/FolderPagedView.java
@@ -0,0 +1,803 @@
+/**
+ * Copyright (C) 2015 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.launcher3;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.animation.DecelerateInterpolator;
+import android.view.animation.Interpolator;
+import android.view.animation.OvershootInterpolator;
+import android.widget.Switch;
+
+import com.android.launcher3.FocusHelper.PagedFolderKeyEventListener;
+import com.android.launcher3.PageIndicator.PageMarkerResources;
+import com.android.launcher3.Workspace.ItemOperator;
+import com.android.launcher3.util.Thunk;
+
+import java.text.Collator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class FolderPagedView extends PagedView implements Folder.FolderContent {
+
+ private static final String TAG = "FolderPagedView";
+
+ private static final int REORDER_ANIMATION_DURATION = 230;
+ private static final int START_VIEW_REORDER_DELAY = 30;
+ private static final float VIEW_REORDER_DELAY_FACTOR = 0.9f;
+
+ private static final int SPAN_TO_PAGE_DURATION = 350;
+ private static final int SORT_ANIM_HIDE_DURATION = 130;
+ private static final int SORT_ANIM_SHOW_DURATION = 160;
+
+ private static final int[] sTempPosArray = new int[2];
+
+ // TODO: Remove this restriction
+ private static final int MAX_ITEMS_PER_PAGE = 4;
+
+ private final LayoutInflater mInflater;
+ private final IconCache mIconCache;
+
+ @Thunk final HashMap<View, Runnable> mPendingAnimations = new HashMap<>();
+
+ private final int mMaxCountX;
+ private final int mMaxCountY;
+ private final int mMaxItemsPerPage;
+
+ private int mAllocatedContentSize;
+ private int mGridCountX;
+ private int mGridCountY;
+
+ private Folder mFolder;
+ private FocusIndicatorView mFocusIndicatorView;
+ private PagedFolderKeyEventListener mKeyListener;
+
+ private View mSortButton;
+ private Switch mSortSwitch;
+ private View mPageIndicator;
+
+ private boolean mSortOperationPending;
+ boolean mIsSorted;
+
+ public FolderPagedView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ LauncherAppState app = LauncherAppState.getInstance();
+ setDataIsReady();
+
+ DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
+ mMaxCountX = Math.min((int) grid.numColumns, MAX_ITEMS_PER_PAGE);
+ mMaxCountY = Math.min((int) grid.numRows, MAX_ITEMS_PER_PAGE);
+ mMaxItemsPerPage = mMaxCountX * mMaxCountY;
+
+ mInflater = LayoutInflater.from(context);
+ mIconCache = app.getIconCache();
+ }
+
+ @Override
+ public void setFolder(Folder folder) {
+ mFolder = folder;
+ mFocusIndicatorView = (FocusIndicatorView) folder.findViewById(R.id.focus_indicator);
+ mKeyListener = new PagedFolderKeyEventListener(folder);
+
+ mSortButton = folder.findViewById(R.id.folder_sort);
+ mSortButton.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ onSortClicked();
+ }
+ });
+ mPageIndicator = folder.findViewById(R.id.folder_page_indicator);
+ mSortSwitch = (Switch) folder.findViewById(R.id.folder_sort_switch);
+ }
+
+ private void onSortClicked() {
+ if (mSortOperationPending) {
+ return;
+ }
+ if (mIsSorted) {
+ setIsSorted(false, true);
+ } else {
+ mSortOperationPending = true;
+ doSort();
+ }
+ }
+
+ private void setIsSorted(boolean isSorted, boolean saveChanges) {
+ mIsSorted = isSorted;
+ mSortSwitch.setChecked(isSorted);
+ mFolder.mInfo.setOption(FolderInfo.FLAG_ITEMS_SORTED, isSorted,
+ saveChanges ? mFolder.mLauncher : null);
+ }
+
+ /**
+ * Sorts the contents of the folder and animates the icons on the first page to reflect
+ * the changes.
+ * Steps:
+ * 1. Scroll to first page
+ * 2. Sort all icons in one go
+ * 3. Re-apply the old IconInfos on the first page (so that there is no instant change)
+ * 4. Animate each view individually to reflect the new icon.
+ */
+ private void doSort() {
+ if (!mSortOperationPending) {
+ return;
+ }
+ if (getNextPage() != 0) {
+ snapToPage(0, SPAN_TO_PAGE_DURATION, new DecelerateInterpolator());
+ return;
+ }
+
+ mSortOperationPending = false;
+ ShortcutInfo[][] oldItems = new ShortcutInfo[mGridCountX][mGridCountY];
+ CellLayout currentPage = getCurrentCellLayout();
+ for (int x = 0; x < mGridCountX; x++) {
+ for (int y = 0; y < mGridCountY; y++) {
+ View v = currentPage.getChildAt(x, y);
+ if (v != null) {
+ oldItems[x][y] = (ShortcutInfo) v.getTag();
+ }
+ }
+ }
+
+ ArrayList<View> views = new ArrayList<View>(mFolder.getItemsInReadingOrder());
+ Collections.sort(views, new ViewComparator());
+ arrangeChildren(views, views.size());
+
+ int delay = 0;
+ float delayAmount = START_VIEW_REORDER_DELAY;
+ final Interpolator hideInterpolator = new DecelerateInterpolator(2);
+ final Interpolator showInterpolator = new OvershootInterpolator(0.8f);
+
+ currentPage = getCurrentCellLayout();
+ for (int x = 0; x < mGridCountX; x++) {
+ for (int y = 0; y < mGridCountY; y++) {
+ final BubbleTextView v = (BubbleTextView) currentPage.getChildAt(x, y);
+ if (v != null) {
+ final ShortcutInfo info = (ShortcutInfo) v.getTag();
+ final Runnable clearPending = new Runnable() {
+
+ @Override
+ public void run() {
+ mPendingAnimations.remove(v);
+ v.setScaleX(1);
+ v.setScaleY(1);
+ }
+ };
+ if (oldItems[x][y] == null) {
+ v.setScaleX(0);
+ v.setScaleY(0);
+ v.animate().setDuration(SORT_ANIM_SHOW_DURATION)
+ .setStartDelay(SORT_ANIM_HIDE_DURATION + delay)
+ .scaleX(1).scaleY(1).setInterpolator(showInterpolator)
+ .withEndAction(clearPending);
+ mPendingAnimations.put(v, clearPending);
+ } else {
+ // Apply the old iconInfo so that there is no sudden change.
+ v.applyFromShortcutInfo(oldItems[x][y], mIconCache, false);
+ v.animate().setStartDelay(delay).setDuration(SORT_ANIM_HIDE_DURATION)
+ .scaleX(0).scaleY(0)
+ .setInterpolator(hideInterpolator)
+ .withEndAction(new Runnable() {
+
+ @Override
+ public void run() {
+ // Apply the new iconInfo as part of the animation.
+ v.applyFromShortcutInfo(info, mIconCache, false);
+ v.animate().scaleX(1).scaleY(1)
+ .setDuration(SORT_ANIM_SHOW_DURATION).setStartDelay(0)
+ .setInterpolator(showInterpolator)
+ .withEndAction(clearPending);
+ }
+ });
+ mPendingAnimations.put(v, new Runnable() {
+
+ @Override
+ public void run() {
+ clearPending.run();
+ v.applyFromShortcutInfo(info, mIconCache, false);
+ }
+ });
+ }
+ delay += delayAmount;
+ delayAmount *= VIEW_REORDER_DELAY_FACTOR;
+ }
+ }
+ }
+
+ setIsSorted(true, true);
+ }
+
+ /**
+ * Sets up the grid size such that {@param count} items can fit in the grid.
+ * The grid size is calculated such that countY <= countX and countX = ceil(sqrt(count)) while
+ * maintaining the restrictions of {@link #mMaxCountX} & {@link #mMaxCountY}.
+ */
+ private void setupContentDimensions(int count) {
+ mAllocatedContentSize = count;
+ boolean done;
+ if (count >= mMaxItemsPerPage) {
+ mGridCountX = mMaxCountX;
+ mGridCountY = mMaxCountY;
+ done = true;
+ } else {
+ done = false;
+ }
+
+ while (!done) {
+ int oldCountX = mGridCountX;
+ int oldCountY = mGridCountY;
+ if (mGridCountX * mGridCountY < count) {
+ // Current grid is too small, expand it
+ if ((mGridCountX <= mGridCountY || mGridCountY == mMaxCountY) && mGridCountX < mMaxCountX) {
+ mGridCountX++;
+ } else if (mGridCountY < mMaxCountY) {
+ mGridCountY++;
+ }
+ if (mGridCountY == 0) mGridCountY++;
+ } else if ((mGridCountY - 1) * mGridCountX >= count && mGridCountY >= mGridCountX) {
+ mGridCountY = Math.max(0, mGridCountY - 1);
+ } else if ((mGridCountX - 1) * mGridCountY >= count) {
+ mGridCountX = Math.max(0, mGridCountX - 1);
+ }
+ done = mGridCountX == oldCountX && mGridCountY == oldCountY;
+ }
+
+ // Update grid size
+ for (int i = getPageCount() - 1; i >= 0; i--) {
+ getPageAt(i).setGridSize(mGridCountX, mGridCountY);
+ }
+ }
+
+ @Override
+ public ArrayList<ShortcutInfo> bindItems(ArrayList<ShortcutInfo> items) {
+ mIsSorted = mFolder.mInfo.hasOption(FolderInfo.FLAG_ITEMS_SORTED);
+ ArrayList<View> icons = new ArrayList<View>();
+ for (ShortcutInfo item : items) {
+ icons.add(createNewView(item));
+ }
+ arrangeChildren(icons, icons.size(), false);
+ return new ArrayList<ShortcutInfo>();
+ }
+
+ /**
+ * Create space for a new item at the end, and returns the rank for that item.
+ * Also sets the current page to the last page.
+ */
+ @Override
+ public int allocateRankForNewItem(ShortcutInfo info) {
+ int rank = getItemCount();
+ ArrayList<View> views = new ArrayList<View>(mFolder.getItemsInReadingOrder());
+ if (mIsSorted) {
+ View tmp = new View(getContext());
+ tmp.setTag(info);
+ int index = Collections.binarySearch(views, tmp, new ViewComparator());
+ if (index < 0) {
+ rank = -index - 1;
+ } else {
+ // Item with same name already exists.
+ // We will just insert it before that item.
+ rank = index;
+ }
+
+ }
+
+ views.add(rank, null);
+ arrangeChildren(views, views.size(), false);
+ setCurrentPage(rank / mMaxItemsPerPage);
+ return rank;
+ }
+
+ @Override
+ public View createAndAddViewForRank(ShortcutInfo item, int rank) {
+ View icon = createNewView(item);
+ addViewForRank(icon, item, rank);
+ return icon;
+ }
+
+ @Override
+ public void addViewForRank(View view, ShortcutInfo item, int rank) {
+ int pagePos = rank % mMaxItemsPerPage;
+ int pageNo = rank / mMaxItemsPerPage;
+
+ item.rank = rank;
+ item.cellX = pagePos % mGridCountX;
+ item.cellY = pagePos / mGridCountX;
+
+ CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams();
+ lp.cellX = item.cellX;
+ lp.cellY = item.cellY;
+ getPageAt(pageNo).addViewToCellLayout(
+ view, -1, mFolder.mLauncher.getViewIdForItem(item), lp, true);
+ }
+
+ @SuppressLint("InflateParams")
+ private View createNewView(ShortcutInfo item) {
+ final BubbleTextView textView = (BubbleTextView) mInflater.inflate(
+ R.layout.folder_application, null, false);
+ textView.applyFromShortcutInfo(item, mIconCache, false);
+ textView.setOnClickListener(mFolder);
+ textView.setOnLongClickListener(mFolder);
+ textView.setOnFocusChangeListener(mFocusIndicatorView);
+ textView.setOnKeyListener(mKeyListener);
+
+ textView.setLayoutParams(new CellLayout.LayoutParams(
+ item.cellX, item.cellY, item.spanX, item.spanY));
+ return textView;
+ }
+
+ @Override
+ public CellLayout getPageAt(int index) {
+ return (CellLayout) getChildAt(index);
+ }
+
+ public void removeCellLayoutView(View view) {
+ for (int i = getChildCount() - 1; i >= 0; i --) {
+ getPageAt(i).removeView(view);
+ }
+ }
+
+ public CellLayout getCurrentCellLayout() {
+ return getPageAt(getNextPage());
+ }
+
+ private CellLayout createAndAddNewPage() {
+ DeviceProfile grid = LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile();
+ CellLayout page = new CellLayout(getContext());
+ page.setCellDimensions(grid.folderCellWidthPx, grid.folderCellHeightPx);
+ page.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);
+ page.setInvertIfRtl(true);
+ page.setGridSize(mGridCountX, mGridCountY);
+
+ LayoutParams lp = generateDefaultLayoutParams();
+ lp.isFullScreenPage = true;
+ addView(page, -1, lp);
+ return page;
+ }
+
+ @Override
+ public void setFixedSize(int width, int height) {
+ for (int i = getChildCount() - 1; i >= 0; i --) {
+ ((CellLayout) getChildAt(i)).setFixedSize(width, height);
+ }
+ }
+
+ @Override
+ public void removeItem(View v) {
+ for (int i = getChildCount() - 1; i >= 0; i --) {
+ getPageAt(i).removeView(v);
+ }
+ }
+
+ /**
+ * Updates position and rank of all the children in the view.
+ * It essentially removes all views from all the pages and then adds them again in appropriate
+ * page.
+ *
+ * @param list the ordered list of children.
+ * @param itemCount if greater than the total children count, empty spaces are left
+ * at the end, otherwise it is ignored.
+ *
+ */
+ @Override
+ public void arrangeChildren(ArrayList<View> list, int itemCount) {
+ arrangeChildren(list, itemCount, true);
+ }
+
+ private void arrangeChildren(ArrayList<View> list, int itemCount, boolean saveChanges) {
+ ArrayList<CellLayout> pages = new ArrayList<CellLayout>();
+ for (int i = 0; i < getChildCount(); i++) {
+ CellLayout page = (CellLayout) getChildAt(i);
+ page.removeAllViews();
+ pages.add(page);
+ }
+ setupContentDimensions(itemCount);
+
+ Iterator<CellLayout> pageItr = pages.iterator();
+ CellLayout currentPage = null;
+
+ int position = 0;
+ int newX, newY, rank;
+
+ boolean isSorted = mIsSorted;
+
+ ViewComparator comparator = new ViewComparator();
+ View lastView = null;
+ rank = 0;
+ for (int i = 0; i < itemCount; i++) {
+ View v = list.size() > i ? list.get(i) : null;
+ if (currentPage == null || position >= mMaxItemsPerPage) {
+ // Next page
+ if (pageItr.hasNext()) {
+ currentPage = pageItr.next();
+ } else {
+ currentPage = createAndAddNewPage();
+ }
+ position = 0;
+ }
+
+ if (v != null) {
+ if (lastView != null) {
+ isSorted &= comparator.compare(lastView, v) <= 0;
+ }
+
+ CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
+ newX = position % mGridCountX;
+ newY = position / mGridCountX;
+ ItemInfo info = (ItemInfo) v.getTag();
+ if (info.cellX != newX || info.cellY != newY || info.rank != rank) {
+ info.cellX = newX;
+ info.cellY = newY;
+ info.rank = rank;
+ if (saveChanges) {
+ LauncherModel.addOrMoveItemInDatabase(getContext(), info,
+ mFolder.mInfo.id, 0, info.cellX, info.cellY);
+ }
+ }
+ lp.cellX = info.cellX;
+ lp.cellY = info.cellY;
+ currentPage.addViewToCellLayout(
+ v, -1, mFolder.mLauncher.getViewIdForItem(info), lp, true);
+ }
+
+ lastView = v;
+ rank ++;
+ position++;
+ }
+
+ // Remove extra views.
+ boolean removed = false;
+ while (pageItr.hasNext()) {
+ removeView(pageItr.next());
+ removed = true;
+ }
+ if (removed) {
+ setCurrentPage(0);
+ }
+
+ setIsSorted(isSorted, saveChanges);
+
+ // Update footer
+ if (getPageCount() > 1) {
+ mPageIndicator.setVisibility(View.VISIBLE);
+ mSortButton.setVisibility(View.VISIBLE);
+ mFolder.mFolderName.setGravity(Gravity.START);
+ setEnableOverscroll(true);
+ } else {
+ mPageIndicator.setVisibility(View.GONE);
+ mSortButton.setVisibility(View.GONE);
+ mFolder.mFolderName.setGravity(Gravity.CENTER_HORIZONTAL);
+ setEnableOverscroll(false);
+ }
+ }
+
+ @Override
+ protected void loadAssociatedPages(int page, boolean immediateAndOnly) { }
+
+ @Override
+ public void syncPages() { }
+
+ @Override
+ public void syncPageItems(int page, boolean immediate) { }
+
+ public int getDesiredWidth() {
+ return getPageCount() > 0 ? getPageAt(0).getDesiredWidth() : 0;
+ }
+
+ public int getDesiredHeight() {
+ return getPageCount() > 0 ? getPageAt(0).getDesiredHeight() : 0;
+ }
+
+ @Override
+ public int getItemCount() {
+ int lastPageIndex = getChildCount() - 1;
+ if (lastPageIndex < 0) {
+ // If there are no pages, nothing has yet been added to the folder.
+ return 0;
+ }
+ return getPageAt(lastPageIndex).getShortcutsAndWidgets().getChildCount()
+ + lastPageIndex * mMaxItemsPerPage;
+ }
+
+ @Override
+ public int findNearestArea(int pixelX, int pixelY) {
+ int pageIndex = getNextPage();
+ CellLayout page = getPageAt(pageIndex);
+ page.findNearestArea(pixelX, pixelY, 1, 1, null, false, sTempPosArray);
+ if (mFolder.isLayoutRtl()) {
+ sTempPosArray[0] = page.getCountX() - sTempPosArray[0] - 1;
+ }
+ return Math.min(mAllocatedContentSize - 1,
+ pageIndex * mMaxItemsPerPage + sTempPosArray[1] * mGridCountX + sTempPosArray[0]);
+ }
+
+ @Override
+ protected PageMarkerResources getPageIndicatorMarker(int pageIndex) {
+ return new PageMarkerResources(R.drawable.ic_pageindicator_current_folder,
+ R.drawable.ic_pageindicator_default_folder);
+ }
+
+ @Override
+ public boolean isFull() {
+ return false;
+ }
+
+ @Override
+ public View getLastItem() {
+ if (getChildCount() < 1) {
+ return null;
+ }
+ ShortcutAndWidgetContainer lastContainer = getCurrentCellLayout().getShortcutsAndWidgets();
+ int lastRank = lastContainer.getChildCount() - 1;
+ if (mGridCountX > 0) {
+ return lastContainer.getChildAt(lastRank % mGridCountX, lastRank / mGridCountX);
+ } else {
+ return lastContainer.getChildAt(lastRank);
+ }
+ }
+
+ @Override
+ public View iterateOverItems(ItemOperator op) {
+ for (int k = 0 ; k < getChildCount(); k++) {
+ CellLayout page = getPageAt(k);
+ for (int j = 0; j < page.getCountY(); j++) {
+ for (int i = 0; i < page.getCountX(); i++) {
+ View v = page.getChildAt(i, j);
+ if ((v != null) && op.evaluate((ItemInfo) v.getTag(), v, this)) {
+ return v;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String getAccessibilityDescription() {
+ return String.format(getContext().getString(R.string.folder_opened),
+ mGridCountX, mGridCountY);
+ }
+
+ @Override
+ public void setFocusOnFirstChild() {
+ View firstChild = getCurrentCellLayout().getChildAt(0, 0);
+ if (firstChild != null) {
+ firstChild.requestFocus();
+ }
+ }
+
+ @Override
+ protected void notifyPageSwitchListener() {
+ super.notifyPageSwitchListener();
+ if (mFolder != null) {
+ mFolder.updateTextViewFocus();
+ }
+ if (mSortOperationPending && getNextPage() == 0) {
+ post(new Runnable() {
+
+ @Override
+ public void run() {
+ if (mSortOperationPending) {
+ doSort();
+ }
+ }
+ });
+ }
+ }
+
+ /**
+ * Scrolls the current view by a fraction
+ */
+ public void showScrollHint(float fraction) {
+ int hint = (int) (fraction * getWidth());
+ int scroll = getScrollForPage(getNextPage()) + hint;
+ int delta = scroll - mUnboundedScrollX;
+ if (delta != 0) {
+ mScroller.setInterpolator(new DecelerateInterpolator());
+ mScroller.startScroll(mUnboundedScrollX, 0, delta, 0, Folder.SCROLL_HINT_DURATION);
+ invalidate();
+ }
+ }
+
+ public void clearScrollHint() {
+ if (mUnboundedScrollX != getScrollForPage(getNextPage())) {
+ snapToPage(getNextPage());
+ }
+ }
+
+ /**
+ * Finish animation all the views which are animating across pages
+ */
+ public void completePendingPageChanges() {
+ if (!mPendingAnimations.isEmpty()) {
+ HashMap<View, Runnable> pendingViews = new HashMap<>(mPendingAnimations);
+ for (Map.Entry<View, Runnable> e : pendingViews.entrySet()) {
+ e.getKey().animate().cancel();
+ e.getValue().run();
+ }
+ }
+ }
+
+ public boolean rankOnCurrentPage(int rank) {
+ int p = rank / mMaxItemsPerPage;
+ return p == getNextPage();
+ }
+
+ @Override
+ protected void onPageBeginMoving() {
+ super.onPageBeginMoving();
+ getVisiblePages(sTempPosArray);
+ for (int i = sTempPosArray[0]; i <= sTempPosArray[1]; i++) {
+ verifyVisibleHighResIcons(i);
+ }
+ }
+
+ /**
+ * Ensures that all the icons on the given page are of high-res
+ */
+ public void verifyVisibleHighResIcons(int pageNo) {
+ CellLayout page = getPageAt(pageNo);
+ if (page != null) {
+ ShortcutAndWidgetContainer parent = page.getShortcutsAndWidgets();
+ for (int i = parent.getChildCount() - 1; i >= 0; i--) {
+ ((BubbleTextView) parent.getChildAt(i)).verifyHighRes();
+ }
+ }
+ }
+
+ @Override
+ public void realTimeReorder(int empty, int target) {
+ completePendingPageChanges();
+ int delay = 0;
+ float delayAmount = START_VIEW_REORDER_DELAY;
+
+ // Animation only happens on the current page.
+ int pageToAnimate = getNextPage();
+
+ int pageT = target / mMaxItemsPerPage;
+ int pagePosT = target % mMaxItemsPerPage;
+
+ if (pageT != pageToAnimate) {
+ Log.e(TAG, "Cannot animate when the target cell is invisible");
+ }
+ int pagePosE = empty % mMaxItemsPerPage;
+ int pageE = empty / mMaxItemsPerPage;
+
+ int startPos, endPos;
+ int moveStart, moveEnd;
+ int direction;
+
+ if (target == empty) {
+ // No animation
+ return;
+ } else if (target > empty) {
+ // Items will move backwards to make room for the empty cell.
+ direction = 1;
+
+ // If empty cell is in a different page, move them instantly.
+ if (pageE < pageToAnimate) {
+ moveStart = empty;
+ // Instantly move the first item in the current page.
+ moveEnd = pageToAnimate * mMaxItemsPerPage;
+ // Animate the 2nd item in the current page, as the first item was already moved to
+ // the last page.
+ startPos = 0;
+ } else {
+ moveStart = moveEnd = -1;
+ startPos = pagePosE;
+ }
+
+ endPos = pagePosT;
+ } else {
+ // The items will move forward.
+ direction = -1;
+
+ if (pageE > pageToAnimate) {
+ // Move the items immediately.
+ moveStart = empty;
+ // Instantly move the last item in the current page.
+ moveEnd = (pageToAnimate + 1) * mMaxItemsPerPage - 1;
+
+ // Animations start with the second last item in the page
+ startPos = mMaxItemsPerPage - 1;
+ } else {
+ moveStart = moveEnd = -1;
+ startPos = pagePosE;
+ }
+
+ endPos = pagePosT;
+ }
+
+ // Instant moving views.
+ while (moveStart != moveEnd) {
+ int rankToMove = moveStart + direction;
+ int p = rankToMove / mMaxItemsPerPage;
+ int pagePos = rankToMove % mMaxItemsPerPage;
+ int x = pagePos % mGridCountX;
+ int y = pagePos / mGridCountX;
+
+ final CellLayout page = getPageAt(p);
+ final View v = page.getChildAt(x, y);
+ if (v != null) {
+ if (pageToAnimate != p) {
+ page.removeView(v);
+ addViewForRank(v, (ShortcutInfo) v.getTag(), moveStart);
+ } else {
+ // Do a fake animation before removing it.
+ final int newRank = moveStart;
+ final float oldTranslateX = v.getTranslationX();
+
+ Runnable endAction = new Runnable() {
+
+ @Override
+ public void run() {
+ mPendingAnimations.remove(v);
+ v.setTranslationX(oldTranslateX);
+ ((CellLayout) v.getParent().getParent()).removeView(v);
+ addViewForRank(v, (ShortcutInfo) v.getTag(), newRank);
+ }
+ };
+ v.animate()
+ .translationXBy(direction > 0 ? -v.getWidth() : v.getWidth())
+ .setDuration(REORDER_ANIMATION_DURATION)
+ .setStartDelay(0)
+ .withEndAction(endAction);
+ mPendingAnimations.put(v, endAction);
+ }
+ }
+ moveStart = rankToMove;
+ }
+
+ if ((endPos - startPos) * direction <= 0) {
+ // No animation
+ return;
+ }
+
+ CellLayout page = getPageAt(pageToAnimate);
+ for (int i = startPos; i != endPos; i += direction) {
+ int nextPos = i + direction;
+ View v = page.getChildAt(nextPos % mGridCountX, nextPos / mGridCountX);
+ if (v != null) {
+ ((ItemInfo) v.getTag()).rank -= direction;
+ }
+ if (page.animateChildToPosition(v, i % mGridCountX, i / mGridCountX,
+ REORDER_ANIMATION_DURATION, delay, true, true)) {
+ delay += delayAmount;
+ delayAmount *= VIEW_REORDER_DELAY_FACTOR;
+ }
+ }
+ }
+
+ private static class ViewComparator implements Comparator<View> {
+ private final Collator mCollator = Collator.getInstance();
+
+ @Override
+ public int compare(View lhs, View rhs) {
+ return mCollator.compare( ((ShortcutInfo) lhs.getTag()).title.toString(),
+ ((ShortcutInfo) rhs.getTag()).title.toString());
+ }
+ }
+}
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java
index 91d4aaf..f4af7f5 100644
--- a/src/com/android/launcher3/IconCache.java
+++ b/src/com/android/launcher3/IconCache.java
@@ -31,8 +31,10 @@
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
+import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
@@ -40,11 +42,14 @@
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
+import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.util.Thunk;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.Map.Entry;
/**
@@ -61,44 +66,29 @@
private static final boolean DEBUG = false;
- private static class CacheEntry {
+ private static final int LOW_RES_SCALE_FACTOR = 8;
+
+ @Thunk static class CacheEntry {
public Bitmap icon;
public CharSequence title;
public CharSequence contentDescription;
+ public boolean isLowResIcon;
}
- private static class CacheKey {
- public ComponentName componentName;
- public UserHandleCompat user;
+ private final HashMap<UserHandleCompat, Bitmap> mDefaultIcons = new HashMap<>();
+ private final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
- CacheKey(ComponentName componentName, UserHandleCompat user) {
- this.componentName = componentName;
- this.user = user;
- }
-
- @Override
- public int hashCode() {
- return componentName.hashCode() + user.hashCode();
- }
-
- @Override
- public boolean equals(Object o) {
- CacheKey other = (CacheKey) o;
- return other.componentName.equals(componentName) && other.user.equals(user);
- }
- }
-
- private final HashMap<UserHandleCompat, Bitmap> mDefaultIcons =
- new HashMap<UserHandleCompat, Bitmap>();
private final Context mContext;
private final PackageManager mPackageManager;
private final UserManagerCompat mUserManager;
private final LauncherAppsCompat mLauncherApps;
- private final HashMap<CacheKey, CacheEntry> mCache =
- new HashMap<CacheKey, CacheEntry>(INITIAL_ICON_CACHE_CAPACITY);
+ private final HashMap<ComponentKey, CacheEntry> mCache =
+ new HashMap<ComponentKey, CacheEntry>(INITIAL_ICON_CACHE_CAPACITY);
private final int mIconDpi;
private final IconDB mIconDb;
+ private final Handler mWorkerHandler;
+
public IconCache(Context context) {
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
@@ -109,6 +99,8 @@
mLauncherApps = LauncherAppsCompat.getInstance(mContext);
mIconDpi = activityManager.getLauncherLargeIconDensity();
mIconDb = new IconDB(context);
+
+ mWorkerHandler = new Handler(LauncherModel.sWorkerThread.getLooper());
}
private Drawable getFullResDefaultActivityIcon() {
@@ -180,21 +172,21 @@
* Remove any records for the supplied ComponentName.
*/
public synchronized void remove(ComponentName componentName, UserHandleCompat user) {
- mCache.remove(new CacheKey(componentName, user));
+ mCache.remove(new ComponentKey(componentName, user));
}
/**
* Remove any records for the supplied package name from memory.
*/
private void removeFromMemCacheLocked(String packageName, UserHandleCompat user) {
- HashSet<CacheKey> forDeletion = new HashSet<CacheKey>();
- for (CacheKey key: mCache.keySet()) {
+ HashSet<ComponentKey> forDeletion = new HashSet<ComponentKey>();
+ for (ComponentKey key: mCache.keySet()) {
if (key.componentName.getPackageName().equals(packageName)
&& key.user.equals(user)) {
forDeletion.add(key);
}
}
- for (CacheKey condemned: forDeletion) {
+ for (ComponentKey condemned: forDeletion) {
mCache.remove(condemned);
}
}
@@ -209,7 +201,7 @@
PackageManager.GET_UNINSTALLED_PACKAGES);
long userSerial = mUserManager.getSerialNumberForUser(user);
for (LauncherActivityInfoCompat app : mLauncherApps.getActivityList(packageName, user)) {
- addIconToDB(app, info, userSerial);
+ addIconToDBAndMemCache(app, info, userSerial);
}
} catch (NameNotFoundException e) {
Log.d(TAG, "Package not found", e);
@@ -234,6 +226,7 @@
* @return The set of packages for which icons have updated.
*/
public HashSet<String> updateDBIcons(UserHandleCompat user, List<LauncherActivityInfoCompat> apps) {
+ mIconDb.updateSystemStateString(mContext);
long userSerial = mUserManager.getSerialNumberForUser(user);
PackageManager pm = mContext.getPackageManager();
HashMap<String, PackageInfo> pkgInfoMap = new HashMap<String, PackageInfo>();
@@ -248,7 +241,8 @@
Cursor c = mIconDb.getReadableDatabase().query(IconDB.TABLE_NAME,
new String[] {IconDB.COLUMN_ROWID, IconDB.COLUMN_COMPONENT,
- IconDB.COLUMN_LAST_UPDATED, IconDB.COLUMN_VERSION},
+ IconDB.COLUMN_LAST_UPDATED, IconDB.COLUMN_VERSION,
+ IconDB.COLUMN_SYSTEM_STATE},
IconDB.COLUMN_USER + " = ? ",
new String[] {Long.toString(userSerial)},
null, null, null);
@@ -257,6 +251,7 @@
final int indexLastUpdate = c.getColumnIndex(IconDB.COLUMN_LAST_UPDATED);
final int indexVersion = c.getColumnIndex(IconDB.COLUMN_VERSION);
final int rowIndex = c.getColumnIndex(IconDB.COLUMN_ROWID);
+ final int systemStateIndex = c.getColumnIndex(IconDB.COLUMN_SYSTEM_STATE);
HashSet<Integer> itemsToRemove = new HashSet<Integer>();
HashSet<String> updatedPackages = new HashSet<String>();
@@ -277,7 +272,8 @@
long updateTime = c.getLong(indexLastUpdate);
int version = c.getInt(indexVersion);
LauncherActivityInfoCompat app = componentMap.remove(component);
- if (version == info.versionCode && updateTime == info.lastUpdateTime) {
+ if (version == info.versionCode && updateTime == info.lastUpdateTime &&
+ TextUtils.equals(mIconDb.mSystemState, c.getString(systemStateIndex))) {
continue;
}
if (app == null) {
@@ -304,14 +300,25 @@
if (info == null) {
continue;
}
- addIconToDB(app, info, userSerial);
+ addIconToDBAndMemCache(app, info, userSerial);
}
return updatedPackages;
}
- private void addIconToDB(LauncherActivityInfoCompat app, PackageInfo info, long userSerial) {
+ private void addIconToDBAndMemCache(LauncherActivityInfoCompat app, PackageInfo info,
+ long userSerial) {
ContentValues values = updateCacheAndGetContentValues(app);
+ addIconToDB(values, app.getComponentName(), info, userSerial);
values.put(IconDB.COLUMN_COMPONENT, app.getComponentName().flattenToString());
+ }
+
+ /**
+ * Updates {@param values} to contain versoning information and adds it to the DB.
+ * @param values {@link ContentValues} containing icon & title
+ */
+ private void addIconToDB(ContentValues values, ComponentName key,
+ PackageInfo info, long userSerial) {
+ values.put(IconDB.COLUMN_COMPONENT, key.flattenToString());
values.put(IconDB.COLUMN_USER, userSerial);
values.put(IconDB.COLUMN_LAST_UPDATED, info.lastUpdateTime);
values.put(IconDB.COLUMN_VERSION, info.versionCode);
@@ -324,15 +331,11 @@
entry.icon = Utilities.createIconBitmap(app.getBadgedIcon(mIconDpi), mContext);
entry.title = app.getLabel();
entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser());
- mCache.put(new CacheKey(app.getComponentName(), app.getUser()), entry);
+ mCache.put(new ComponentKey(app.getComponentName(), app.getUser()), entry);
- ContentValues values = new ContentValues();
- values.put(IconDB.COLUMN_ICON, ItemInfo.flattenBitmap(entry.icon));
- values.put(IconDB.COLUMN_LABEL, entry.title.toString());
- return values;
+ return mIconDb.newContentValues(entry.icon, entry.title.toString());
}
-
/**
* Empty out the cache.
*/
@@ -344,7 +347,7 @@
* Empty out the cache that aren't of the correct grid size
*/
public synchronized void flushInvalidIcons(DeviceProfile grid) {
- Iterator<Entry<CacheKey, CacheEntry>> it = mCache.entrySet().iterator();
+ Iterator<Entry<ComponentKey, CacheEntry>> it = mCache.entrySet().iterator();
while (it.hasNext()) {
final CacheEntry e = it.next().getValue();
if ((e.icon != null) && (e.icon.getWidth() < grid.iconSizePx
@@ -355,16 +358,52 @@
}
/**
+ * Fetches high-res icon for the provided ItemInfo and updates the caller when done.
+ * @return a request ID that can be used to cancel the request.
+ */
+ public IconLoadRequest updateIconInBackground(final BubbleTextView caller, final ItemInfo info) {
+ Runnable request = new Runnable() {
+
+ @Override
+ public void run() {
+ if (info instanceof AppInfo) {
+ getTitleAndIcon((AppInfo) info, null, false);
+ } else if (info instanceof ShortcutInfo) {
+ ShortcutInfo st = (ShortcutInfo) info;
+ getTitleAndIcon(st,
+ st.promisedIntent != null ? st.promisedIntent : st.intent,
+ st.user, false);
+ }
+ mMainThreadExecutor.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ caller.reapplyItemInfo(info);
+ }
+ });
+ }
+ };
+ mWorkerHandler.post(request);
+ return new IconLoadRequest(request, mWorkerHandler);
+ }
+
+ /**
* Fill in "application" with the icon and label for "info."
*/
- public synchronized void getTitleAndIcon(AppInfo application, LauncherActivityInfoCompat info) {
- CacheEntry entry = cacheLocked(application.componentName, info, info.getUser(), false);
-
+ public synchronized void getTitleAndIcon(AppInfo application,
+ LauncherActivityInfoCompat info, boolean useLowResIcon) {
+ CacheEntry entry = cacheLocked(application.componentName, info,
+ info == null ? application.user : info.getUser(),
+ false, useLowResIcon);
application.title = entry.title;
application.iconBitmap = entry.icon;
application.contentDescription = entry.contentDescription;
+ application.usingLowResIcon = entry.isLowResIcon;
}
+ /**
+ * Returns a high res icon for the given intent and user
+ */
public synchronized Bitmap getIcon(Intent intent, UserHandleCompat user) {
ComponentName component = intent.getComponent();
// null info means not installed, but if we have a component from the intent then
@@ -374,7 +413,7 @@
}
LauncherActivityInfoCompat launcherActInfo = mLauncherApps.resolveActivity(intent, user);
- CacheEntry entry = cacheLocked(component, launcherActInfo, user, true);
+ CacheEntry entry = cacheLocked(component, launcherActInfo, user, true, true);
return entry.icon;
}
@@ -383,7 +422,7 @@
* corresponding activity is not found, it reverts to the package icon.
*/
public synchronized void getTitleAndIcon(ShortcutInfo shortcutInfo, Intent intent,
- UserHandleCompat user) {
+ UserHandleCompat user, boolean useLowResIcon) {
ComponentName component = intent.getComponent();
// null info means not installed, but if we have a component from the intent then
// we should still look in the cache for restored app icons.
@@ -391,9 +430,10 @@
shortcutInfo.setIcon(getDefaultIcon(user));
shortcutInfo.title = "";
shortcutInfo.usingFallbackIcon = true;
+ shortcutInfo.usingLowResIcon = false;
} else {
LauncherActivityInfoCompat info = mLauncherApps.resolveActivity(intent, user);
- getTitleAndIcon(shortcutInfo, component, info, user, true);
+ getTitleAndIcon(shortcutInfo, component, info, user, true, useLowResIcon);
}
}
@@ -402,11 +442,24 @@
*/
public synchronized void getTitleAndIcon(
ShortcutInfo shortcutInfo, ComponentName component, LauncherActivityInfoCompat info,
- UserHandleCompat user, boolean usePkgIcon) {
- CacheEntry entry = cacheLocked(component, info, user, usePkgIcon);
+ UserHandleCompat user, boolean usePkgIcon, boolean useLowResIcon) {
+ CacheEntry entry = cacheLocked(component, info, user, usePkgIcon, useLowResIcon);
shortcutInfo.setIcon(entry.icon);
shortcutInfo.title = entry.title;
shortcutInfo.usingFallbackIcon = isDefaultIcon(entry.icon, user);
+ shortcutInfo.usingLowResIcon = entry.isLowResIcon;
+ }
+
+ /**
+ * Fill in {@param appInfo} with the icon and label for {@param packageName}
+ */
+ public synchronized void getTitleAndIconForApp(
+ String packageName, UserHandleCompat user, boolean useLowResIcon, AppInfo appInfoOut) {
+ CacheEntry entry = getEntryForPackageLocked(packageName, user, useLowResIcon);
+ appInfoOut.iconBitmap = entry.icon;
+ appInfoOut.title = entry.title;
+ appInfoOut.usingLowResIcon = entry.isLowResIcon;
+ appInfoOut.contentDescription = entry.contentDescription;
}
public synchronized Bitmap getDefaultIcon(UserHandleCompat user) {
@@ -425,21 +478,21 @@
* This method is not thread safe, it must be called from a synchronized method.
*/
private CacheEntry cacheLocked(ComponentName componentName, LauncherActivityInfoCompat info,
- UserHandleCompat user, boolean usePackageIcon) {
- CacheKey cacheKey = new CacheKey(componentName, user);
+ UserHandleCompat user, boolean usePackageIcon, boolean useLowResIcon) {
+ ComponentKey cacheKey = new ComponentKey(componentName, user);
CacheEntry entry = mCache.get(cacheKey);
- if (entry == null) {
+ if (entry == null || (entry.isLowResIcon && !useLowResIcon)) {
entry = new CacheEntry();
mCache.put(cacheKey, entry);
// Check the DB first.
- if (!getEntryFromDB(componentName, user, entry)) {
+ if (!getEntryFromDB(componentName, user, entry, useLowResIcon)) {
if (info != null) {
entry.icon = Utilities.createIconBitmap(info.getBadgedIcon(mIconDpi), mContext);
} else {
if (usePackageIcon) {
- CacheEntry packageEntry = getEntryForPackage(
- componentName.getPackageName(), user);
+ CacheEntry packageEntry = getEntryForPackageLocked(
+ componentName.getPackageName(), user, false);
if (packageEntry != null) {
if (DEBUG) Log.d(TAG, "using package default icon for " +
componentName.toShortString());
@@ -472,7 +525,7 @@
Bitmap icon, CharSequence title) {
removeFromMemCacheLocked(packageName, user);
- CacheEntry entry = getEntryForPackage(packageName, user);
+ CacheEntry entry = getEntryForPackageLocked(packageName, user, false);
if (!TextUtils.isEmpty(title)) {
entry.title = title;
}
@@ -484,24 +537,41 @@
/**
* Gets an entry for the package, which can be used as a fallback entry for various components.
* This method is not thread safe, it must be called from a synchronized method.
+ *
*/
- private CacheEntry getEntryForPackage(String packageName, UserHandleCompat user) {
- ComponentName cn = new ComponentName(packageName, EMPTY_CLASS_NAME);;
- CacheKey cacheKey = new CacheKey(cn, user);
+ private CacheEntry getEntryForPackageLocked(String packageName, UserHandleCompat user,
+ boolean useLowResIcon) {
+ ComponentName cn = new ComponentName(packageName, EMPTY_CLASS_NAME);
+ ComponentKey cacheKey = new ComponentKey(cn, user);
CacheEntry entry = mCache.get(cacheKey);
- if (entry == null) {
+ if (entry == null || (entry.isLowResIcon && !useLowResIcon)) {
entry = new CacheEntry();
- entry.title = "";
- entry.contentDescription = "";
mCache.put(cacheKey, entry);
- try {
- ApplicationInfo info = mPackageManager.getApplicationInfo(packageName, 0);
- entry.icon = Utilities.createIconBitmap(info.loadIcon(mPackageManager), mContext);
- entry.title = info.loadLabel(mPackageManager);
- entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
- } catch (NameNotFoundException e) {
- if (DEBUG) Log.d(TAG, "Application not installed " + packageName);
+ // Check the DB first.
+ if (!getEntryFromDB(cn, user, entry, useLowResIcon)) {
+ try {
+ PackageInfo info = mPackageManager.getPackageInfo(packageName, 0);
+ ApplicationInfo appInfo = info.applicationInfo;
+ if (appInfo == null) {
+ throw new NameNotFoundException("ApplicationInfo is null");
+ }
+ Drawable drawable = mUserManager.getBadgedDrawableForUser(
+ appInfo.loadIcon(mPackageManager), user);
+ entry.icon = Utilities.createIconBitmap(drawable, mContext);
+ entry.title = appInfo.loadLabel(mPackageManager);
+ entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
+ entry.isLowResIcon = false;
+
+ // Add the icon in the DB here, since these do not get written during
+ // package updates.
+ ContentValues values =
+ mIconDb.newContentValues(entry.icon, entry.title.toString());
+ addIconToDB(values, cn, info, mUserManager.getSerialNumberForUser(user));
+
+ } catch (NameNotFoundException e) {
+ if (DEBUG) Log.d(TAG, "Application not installed " + packageName);
+ }
}
}
return entry;
@@ -529,25 +599,26 @@
// pass
}
- ContentValues values = new ContentValues();
+ ContentValues values = mIconDb.newContentValues(icon, label);
values.put(IconDB.COLUMN_COMPONENT, componentName.flattenToString());
values.put(IconDB.COLUMN_USER, userSerial);
- values.put(IconDB.COLUMN_ICON, ItemInfo.flattenBitmap(icon));
- values.put(IconDB.COLUMN_LABEL, label);
mIconDb.getWritableDatabase().insertWithOnConflict(IconDB.TABLE_NAME, null, values,
SQLiteDatabase.CONFLICT_REPLACE);
}
- private boolean getEntryFromDB(ComponentName component, UserHandleCompat user, CacheEntry entry) {
+ private boolean getEntryFromDB(ComponentName component, UserHandleCompat user,
+ CacheEntry entry, boolean lowRes) {
Cursor c = mIconDb.getReadableDatabase().query(IconDB.TABLE_NAME,
- new String[] {IconDB.COLUMN_ICON, IconDB.COLUMN_LABEL},
+ new String[] {lowRes ? IconDB.COLUMN_ICON_LOW_RES : IconDB.COLUMN_ICON,
+ IconDB.COLUMN_LABEL},
IconDB.COLUMN_COMPONENT + " = ? AND " + IconDB.COLUMN_USER + " = ?",
new String[] {component.flattenToString(),
Long.toString(mUserManager.getSerialNumberForUser(user))},
null, null, null);
try {
if (c.moveToNext()) {
- entry.icon = Utilities.createIconBitmap(c, 0, mContext);
+ entry.icon = loadIconNoResize(c, 0);
+ entry.isLowResIcon = lowRes;
entry.title = c.getString(1);
if (entry.title == null) {
entry.title = "";
@@ -563,8 +634,22 @@
return false;
}
+ public static class IconLoadRequest {
+ private final Runnable mRunnable;
+ private final Handler mHandler;
+
+ IconLoadRequest(Runnable runnable, Handler handler) {
+ mRunnable = runnable;
+ mHandler = handler;
+ }
+
+ public void cancel() {
+ mHandler.removeCallbacks(mRunnable);
+ }
+ }
+
private static final class IconDB extends SQLiteOpenHelper {
- private final static int DB_VERSION = 1;
+ private final static int DB_VERSION = 3;
private final static String TABLE_NAME = "icons";
private final static String COLUMN_ROWID = "rowid";
@@ -573,12 +658,23 @@
private final static String COLUMN_LAST_UPDATED = "lastUpdated";
private final static String COLUMN_VERSION = "version";
private final static String COLUMN_ICON = "icon";
+ private final static String COLUMN_ICON_LOW_RES = "icon_low_res";
private final static String COLUMN_LABEL = "label";
+ private final static String COLUMN_SYSTEM_STATE = "system_state";
+
+ public String mSystemState;
public IconDB(Context context) {
super(context, LauncherFiles.APP_ICONS_DB, null, DB_VERSION);
+ updateSystemStateString(context);
}
+ public void updateSystemStateString(Context c) {
+ mSystemState = Locale.getDefault().toString() + ","
+ + c.getResources().getConfiguration().mcc;
+ }
+
+
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" +
@@ -587,7 +683,9 @@
COLUMN_LAST_UPDATED + " INTEGER NOT NULL DEFAULT 0, " +
COLUMN_VERSION + " INTEGER NOT NULL DEFAULT 0, " +
COLUMN_ICON + " BLOB, " +
+ COLUMN_ICON_LOW_RES + " BLOB, " +
COLUMN_LABEL + " TEXT, " +
+ COLUMN_SYSTEM_STATE + " TEXT, " +
"PRIMARY KEY (" + COLUMN_COMPONENT + ", " + COLUMN_USER + ") " +
");");
}
@@ -610,5 +708,26 @@
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
+
+ public ContentValues newContentValues(Bitmap icon, String label) {
+ ContentValues values = new ContentValues();
+ values.put(COLUMN_ICON, Utilities.flattenBitmap(icon));
+ values.put(COLUMN_ICON_LOW_RES, Utilities.flattenBitmap(
+ Bitmap.createScaledBitmap(icon,
+ icon.getWidth() / LOW_RES_SCALE_FACTOR,
+ icon.getHeight() / LOW_RES_SCALE_FACTOR, true)));
+ values.put(COLUMN_LABEL, label);
+ values.put(COLUMN_SYSTEM_STATE, mSystemState);
+ return values;
+ }
+ }
+
+ private static Bitmap loadIconNoResize(Cursor c, int iconIndex) {
+ byte[] data = c.getBlob(iconIndex);
+ try {
+ return BitmapFactory.decodeByteArray(data, 0, data.length);
+ } catch (Exception e) {
+ return null;
+ }
}
}
diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java
index 201531e..0db22a4 100644
--- a/src/com/android/launcher3/InstallShortcutReceiver.java
+++ b/src/com/android/launcher3/InstallShortcutReceiver.java
@@ -32,6 +32,7 @@
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
+import com.android.launcher3.util.Thunk;
import org.json.JSONException;
import org.json.JSONObject;
@@ -240,7 +241,7 @@
* Ensures that we have a valid, non-null name. If the provided name is null, we will return
* the application name instead.
*/
- private static CharSequence ensureValidName(Context context, Intent intent, CharSequence name) {
+ @Thunk static CharSequence ensureValidName(Context context, Intent intent, CharSequence name) {
if (name == null) {
try {
PackageManager pm = context.getPackageManager();
@@ -330,7 +331,7 @@
.key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
.key(NAME_KEY).value(name);
if (icon != null) {
- byte[] iconByteArray = ItemInfo.flattenBitmap(icon);
+ byte[] iconByteArray = Utilities.flattenBitmap(icon);
json = json.key(ICON_KEY).value(
Base64.encodeToString(
iconByteArray, 0, iconByteArray.length, Base64.DEFAULT));
diff --git a/src/com/android/launcher3/InterruptibleInOutAnimator.java b/src/com/android/launcher3/InterruptibleInOutAnimator.java
index 2898b34..29df38b 100644
--- a/src/com/android/launcher3/InterruptibleInOutAnimator.java
+++ b/src/com/android/launcher3/InterruptibleInOutAnimator.java
@@ -21,6 +21,8 @@
import android.animation.ValueAnimator;
import android.view.View;
+import com.android.launcher3.util.Thunk;
+
/**
* A convenience class for two-way animations, e.g. a fadeIn/fadeOut animation.
* With a regular ValueAnimator, if you call reverse to show the 'out' animation, you'll get
@@ -43,7 +45,7 @@
private static final int OUT = 2;
// TODO: This isn't really necessary, but is here to help diagnose a bug in the drag viz
- private int mDirection = STOPPED;
+ @Thunk int mDirection = STOPPED;
public InterruptibleInOutAnimator(View view, long duration, float fromValue, float toValue) {
mAnimator = LauncherAnimUtils.ofFloat(view, fromValue, toValue).setDuration(duration);
diff --git a/src/com/android/launcher3/ItemInfo.java b/src/com/android/launcher3/ItemInfo.java
index aff8323..f114de2 100644
--- a/src/com/android/launcher3/ItemInfo.java
+++ b/src/com/android/launcher3/ItemInfo.java
@@ -20,13 +20,10 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
-import android.util.Log;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.util.Arrays;
/**
@@ -177,25 +174,9 @@
}
}
- static byte[] flattenBitmap(Bitmap bitmap) {
- // Try go guesstimate how much space the icon will take when serialized
- // to avoid unnecessary allocations/copies during the write.
- int size = bitmap.getWidth() * bitmap.getHeight() * 4;
- ByteArrayOutputStream out = new ByteArrayOutputStream(size);
- try {
- bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
- out.flush();
- out.close();
- return out.toByteArray();
- } catch (IOException e) {
- Log.w("Favorite", "Could not write icon");
- return null;
- }
- }
-
static void writeBitmap(ContentValues values, Bitmap bitmap) {
if (bitmap != null) {
- byte[] data = flattenBitmap(bitmap);
+ byte[] data = Utilities.flattenBitmap(bitmap);
values.put(LauncherSettings.Favorites.ICON, data);
}
}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index ab6ebd3..2fa2f4a 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1,4 +1,3 @@
-
/*
* Copyright (C) 2008 The Android Open Source Project
*
@@ -22,7 +21,6 @@
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
-import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.app.Activity;
@@ -42,13 +40,13 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.IntentSender;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
-import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
@@ -82,15 +80,12 @@
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
-import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
-import android.view.animation.AccelerateInterpolator;
-import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.InputMethodManager;
import android.widget.Advanceable;
import android.widget.FrameLayout;
@@ -107,6 +102,7 @@
import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
+import com.android.launcher3.util.Thunk;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -116,7 +112,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
-import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DateFormat;
@@ -133,7 +128,8 @@
*/
public class Launcher extends Activity
implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
- View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
+ View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener,
+ LauncherStateTransitionAnimation.Callbacks {
static final String TAG = "Launcher";
static final boolean LOGD = false;
@@ -147,7 +143,6 @@
private static final int REQUEST_CREATE_SHORTCUT = 1;
private static final int REQUEST_CREATE_APPWIDGET = 5;
- private static final int REQUEST_PICK_SHORTCUT = 7;
private static final int REQUEST_PICK_APPWIDGET = 9;
private static final int REQUEST_PICK_WALLPAPER = 10;
@@ -215,9 +210,10 @@
public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
/** The different states that Launcher can be in. */
- private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
- private State mState = State.WORKSPACE;
- private AnimatorSet mStateAnimation;
+ enum State { NONE, WORKSPACE, APPS, APPS_SPRING_LOADED, WIDGETS, WIDGETS_SPRING_LOADED };
+ @Thunk State mState = State.WORKSPACE;
+ @Thunk AnimatorSet mStateAnimation;
+ @Thunk LauncherStateTransitionAnimation mStateTransitionAnimation;
private boolean mIsSafeModeEnabled;
@@ -236,8 +232,7 @@
// How long to wait before the new-shortcut animation automatically pans the workspace
private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
- private static int NEW_APPS_ANIMATION_DELAY = 500;
- private static final int SINGLE_FRAME_DELAY = 16;
+ @Thunk static int NEW_APPS_ANIMATION_DELAY = 500;
private final BroadcastReceiver mCloseSystemDialogsReceiver
= new CloseSystemDialogsIntentReceiver();
@@ -245,17 +240,17 @@
private LayoutInflater mInflater;
- private Workspace mWorkspace;
+ @Thunk Workspace mWorkspace;
private View mLauncherView;
private View mPageIndicators;
- private DragLayer mDragLayer;
+ @Thunk DragLayer mDragLayer;
private DragController mDragController;
private View mWeightWatcher;
private AppWidgetManagerCompat mAppWidgetManager;
private LauncherAppWidgetHost mAppWidgetHost;
- private ItemInfo mPendingAddInfo = new ItemInfo();
+ @Thunk ItemInfo mPendingAddInfo = new ItemInfo();
private LauncherAppWidgetProviderInfo mPendingAddWidgetInfo;
private int mPendingAddWidgetId = -1;
@@ -269,7 +264,8 @@
private View mAllAppsButton;
private SearchDropTargetBar mSearchDropTargetBar;
- private AppsCustomizeTabHost mAppsCustomizeTabHost;
+ @Thunk AppsContainerView mAppsView;
+ @Thunk AppsCustomizeTabHost mAppsCustomizeTabHost;
private AppsCustomizePagedView mAppsCustomizeContent;
private boolean mAutoAdvanceRunning = false;
private AppWidgetHostView mQsb;
@@ -282,7 +278,7 @@
private SpannableStringBuilder mDefaultKeySsb = null;
- private boolean mWorkspaceLoading = true;
+ @Thunk boolean mWorkspaceLoading = true;
private boolean mPaused = true;
private boolean mRestoring;
@@ -296,34 +292,31 @@
private LauncherModel mModel;
private IconCache mIconCache;
- private boolean mUserPresent = true;
+ @Thunk boolean mUserPresent = true;
private boolean mVisible = false;
private boolean mHasFocus = false;
private boolean mAttached = false;
- private static LocaleConfiguration sLocaleConfiguration = null;
+ @Thunk static LocaleConfiguration sLocaleConfiguration = null;
private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
private View.OnTouchListener mHapticFeedbackTouchListener;
- public static final int BUILD_LAYER = 0;
- public static final int BUILD_AND_SET_LAYER = 1;
-
// Related to the auto-advancing of widgets
private final int ADVANCE_MSG = 1;
private final int mAdvanceInterval = 20000;
private final int mAdvanceStagger = 250;
private long mAutoAdvanceSentTime;
private long mAutoAdvanceTimeLeft = -1;
- private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
+ @Thunk 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;
- private Drawable mWorkspaceBackgroundDrawable;
+ @Thunk Drawable mWorkspaceBackgroundDrawable;
private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
@@ -341,7 +334,7 @@
// Holds the page that we need to animate to, and the icon views that we need to animate up
// when we scroll to that page on resume.
- private ImageView mFolderIconImageView;
+ @Thunk ImageView mFolderIconImageView;
private Bitmap mFolderIconBitmap;
private Canvas mFolderIconCanvas;
private Rect mRectForFolderAnimation = new Rect();
@@ -370,7 +363,7 @@
}
}
- private Runnable mBuildLayersRunnable = new Runnable() {
+ @Thunk Runnable mBuildLayersRunnable = new Runnable() {
public void run() {
if (mWorkspace != null) {
mWorkspace.buildPageHardwareLayers();
@@ -380,7 +373,7 @@
private static PendingAddArguments sPendingAddItem;
- private static class PendingAddArguments {
+ @Thunk static class PendingAddArguments {
int requestCode;
Intent intent;
long container;
@@ -433,6 +426,7 @@
mIconCache.flushInvalidIcons(grid);
mDragController = new DragController(this);
mInflater = getLayoutInflater();
+ mStateTransitionAnimation = new LauncherStateTransitionAnimation(this, this);
mStats = new Stats(this);
@@ -568,7 +562,7 @@
}
}
- private void checkForLocaleChange() {
+ @Thunk void checkForLocaleChange() {
if (sLocaleConfiguration == null) {
new AsyncTask<Void, Void, LocaleConfiguration>() {
@Override
@@ -617,13 +611,13 @@
}
}
- private static class LocaleConfiguration {
+ @Thunk static class LocaleConfiguration {
public String locale;
public int mcc = -1;
public int mnc = -1;
}
- private static void readConfiguration(Context context, LocaleConfiguration configuration) {
+ @Thunk static void readConfiguration(Context context, LocaleConfiguration configuration) {
DataInputStream in = null;
try {
in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES));
@@ -645,7 +639,7 @@
}
}
- private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
+ @Thunk static void writeConfiguration(Context context, LocaleConfiguration configuration) {
DataOutputStream out = null;
try {
out = new DataOutputStream(context.openFileOutput(
@@ -922,7 +916,7 @@
}
}
- private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
+ @Thunk void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
CellLayout cellLayout =
(CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
Runnable onCompleteRunnable = null;
@@ -992,10 +986,12 @@
super.onResume();
// Restore the previous launcher state
- if (mOnResumeState == State.WORKSPACE) {
+ if (mOnResumeState == State.WORKSPACE || mOnResumeState == State.NONE) {
showWorkspace(false);
- } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
- showAllApps(false, mAppsCustomizeContent.getContentType(), false);
+ } else if (mOnResumeState == State.APPS) {
+ showAppsView(false /* animated */, false /* resetListToTop */);
+ } else if (mOnResumeState == State.WIDGETS) {
+ showWidgetsView(false, false);
}
mOnResumeState = State.NONE;
@@ -1051,6 +1047,7 @@
// (framework issue). On resuming, we ensure that any widgets are inflated for the current
// orientation.
getWorkspace().reinflateWidgetsIfNecessary();
+ reinflateQSBIfNecessary();
// Process any items that were added while Launcher was away.
InstallShortcutReceiver.disableAndFlushInstallQueue(this);
@@ -1304,8 +1301,8 @@
}
State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
- if (state == State.APPS_CUSTOMIZE) {
- mOnResumeState = State.APPS_CUSTOMIZE;
+ if (state == State.APPS || state == State.WIDGETS) {
+ mOnResumeState = state;
}
int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
@@ -1324,7 +1321,9 @@
mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
- mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
+ AppWidgetProviderInfo info = savedState.getParcelable(
+ RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
+ mPendingAddWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(this, info);
mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
setWaitingForResult(true);
mRestoring = true;
@@ -1431,6 +1430,9 @@
mSearchDropTargetBar = (SearchDropTargetBar)
mDragLayer.findViewById(R.id.search_drop_target_bar);
+ // Setup Apps
+ mAppsView = (AppsContainerView) findViewById(R.id.apps_view);
+
// Setup AppsCustomize
mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
mAppsCustomizeContent = (AppsCustomizePagedView)
@@ -1444,7 +1446,7 @@
dragController.addDropTarget(mWorkspace);
if (mSearchDropTargetBar != null) {
mSearchDropTargetBar.setup(this, dragController);
- mSearchDropTargetBar.setQsbSearchBar(getQsbBar());
+ mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
}
if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
@@ -1553,7 +1555,7 @@
return;
}
- LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
+ LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1]);
if (!mRestoring) {
mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
@@ -1593,7 +1595,7 @@
*
* @param appWidgetId The app widget id
*/
- private void completeAddAppWidget(int appWidgetId, long container, long screenId,
+ @Thunk void completeAddAppWidget(int appWidgetId, long container, long screenId,
AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
ItemInfo info = mPendingAddInfo;
@@ -1615,7 +1617,7 @@
launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
LauncherModel.addItemToDatabase(this, launcherInfo,
- container, screenId, info.cellX, info.cellY, false);
+ container, screenId, info.cellX, info.cellY);
if (!mRestoring) {
if (hostView == null) {
@@ -1645,16 +1647,17 @@
if (Intent.ACTION_SCREEN_OFF.equals(action)) {
mUserPresent = false;
mDragLayer.clearAllResizeFrames();
- updateRunning();
+ updateAutoAdvanceState();
// Reset AllApps to its initial state only if we are not in the middle of
// processing a multi-step drop
- if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
+ if (mAppsView != null && mAppsCustomizeTabHost != null &&
+ mPendingAddInfo.container == ItemInfo.NO_ID) {
showWorkspace(false);
}
} else if (Intent.ACTION_USER_PRESENT.equals(action)) {
mUserPresent = true;
- updateRunning();
+ updateAutoAdvanceState();
} else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
mModel.resetLoadedState(false, true);
mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
@@ -1722,12 +1725,12 @@
unregisterReceiver(mReceiver);
mAttached = false;
}
- updateRunning();
+ updateAutoAdvanceState();
}
public void onWindowVisibilityChanged(int visibility) {
mVisible = visibility == View.VISIBLE;
- updateRunning();
+ updateAutoAdvanceState();
// The following code used to be in onResume, but it turns out onResume is called when
// you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
// is a more appropriate event to handle
@@ -1767,14 +1770,14 @@
}
}
- private void sendAdvanceMessage(long delay) {
+ @Thunk void sendAdvanceMessage(long delay) {
mHandler.removeMessages(ADVANCE_MSG);
Message msg = mHandler.obtainMessage(ADVANCE_MSG);
mHandler.sendMessageDelayed(msg, delay);
mAutoAdvanceSentTime = System.currentTimeMillis();
}
- private void updateRunning() {
+ @Thunk void updateAutoAdvanceState() {
boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
if (autoAdvanceRunning != mAutoAdvanceRunning) {
mAutoAdvanceRunning = autoAdvanceRunning;
@@ -1820,14 +1823,14 @@
if (v instanceof Advanceable) {
mWidgetsToAdvance.put(hostView, appWidgetInfo);
((Advanceable) v).fyiWillBeAdvancedByHostKThx();
- updateRunning();
+ updateAutoAdvanceState();
}
}
void removeWidgetToAutoAdvance(View hostView) {
if (mWidgetsToAdvance.containsKey(hostView)) {
mWidgetsToAdvance.remove(hostView);
- updateRunning();
+ updateAutoAdvanceState();
}
}
@@ -1841,14 +1844,18 @@
Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
}
- public ArrayList<AppInfo> getAllAppsList() {
- return mAppsCustomizeContent.getApps();
- }
-
public DragLayer getDragLayer() {
return mDragLayer;
}
+ public AppsContainerView getAppsView() {
+ return mAppsView;
+ }
+
+ public AppsCustomizeTabHost getWidgetsView() {
+ return mAppsCustomizeTabHost;
+ }
+
public Workspace getWorkspace() {
return mWorkspace;
}
@@ -1934,6 +1941,11 @@
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
+ // Reset the apps view
+ if (!alreadyOnHome && mAppsView != null) {
+ mAppsView.scrollToTop();
+ }
+
// Reset the apps customize page
if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
mAppsCustomizeTabHost.reset();
@@ -2066,10 +2078,26 @@
@Override
public void startActivityForResult(Intent intent, int requestCode) {
+ onStartForResult(requestCode);
+ super.startActivityForResult(intent, requestCode);
+ }
+
+ @Override
+ public void startIntentSenderForResult (IntentSender intent, int requestCode,
+ Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) {
+ onStartForResult(requestCode);
+ try {
+ super.startIntentSenderForResult(intent, requestCode,
+ fillInIntent, flagsMask, flagsValues, extraFlags, options);
+ } catch (IntentSender.SendIntentException e) {
+ throw new ActivityNotFoundException();
+ }
+ }
+
+ private void onStartForResult(int requestCode) {
if (requestCode >= 0) {
setWaitingForResult(true);
}
- super.startActivityForResult(intent, requestCode);
}
/**
@@ -2382,8 +2410,8 @@
folderInfo.title = getText(R.string.folder_name);
// Update the model
- LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
- false);
+ LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId,
+ cellX, cellY);
sFolders.put(folderInfo.id, folderInfo);
// Create the view
@@ -2401,13 +2429,6 @@
sFolders.remove(folder.id);
}
- protected ComponentName getWallpaperPickerComponent() {
- if (mLauncherCallbacks != null) {
- return mLauncherCallbacks.getWallpaperPickerComponent();
- }
- return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
- }
-
/**
* Registers various content observers. The current implementation registers
* only a favorites observer to keep track of the favorites applications.
@@ -2447,13 +2468,16 @@
return;
}
- if (isAllAppsVisible()) {
- if (mAppsCustomizeContent.getContentType() ==
- AppsCustomizePagedView.ContentType.Applications) {
- showWorkspace(true);
- } else {
- showOverviewMode(true);
- }
+ LauncherAccessibilityDelegate delegate =
+ LauncherAppState.getInstance().getAccessibilityDelegate();
+ if (delegate != null && delegate.onBackPressed()) {
+ return;
+ }
+
+ if (isAppsViewVisible()) {
+ showWorkspace(true);
+ } else if (isWidgetsViewVisible()) {
+ showOverviewMode(true);
} else if (mWorkspace.isInOverviewMode()) {
mWorkspace.exitOverviewMode(true);
} else if (mWorkspace.getOpenFolder() != null) {
@@ -2474,7 +2498,7 @@
/**
* Re-listen when widgets are reset.
*/
- private void onAppWidgetReset() {
+ @Thunk void onAppWidgetReset() {
if (mAppWidgetHost != null) {
mAppWidgetHost.startListening();
}
@@ -2584,10 +2608,10 @@
*/
protected void onClickAllAppsButton(View v) {
if (LOGD) Log.d(TAG, "onClickAllAppsButton");
- if (isAllAppsVisible()) {
+ if (isAppsViewVisible()) {
showWorkspace(true);
} else {
- showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
+ showAppsView(true /* animated */, false /* resetListToTop */);
}
if (mLauncherCallbacks != null) {
mLauncherCallbacks.onClickAllAppsButton(v);
@@ -2672,7 +2696,7 @@
}
}
- private void startAppShortcutOrInfoActivity(View v) {
+ @Thunk void startAppShortcutOrInfoActivity(View v) {
Object tag = v.getTag();
final ShortcutInfo shortcut;
final Intent intent;
@@ -2758,7 +2782,7 @@
if (mIsSafeModeEnabled) {
Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
} else {
- showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
+ showWidgetsView(true /* animated */, true /* resetPageToZero */);
if (mLauncherCallbacks != null) {
mLauncherCallbacks.onClickAddWidgetButton(view);
}
@@ -2771,9 +2795,8 @@
*/
protected void onClickWallpaperPicker(View v) {
if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
- final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
- pickWallpaper.setComponent(getWallpaperPickerComponent());
- startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
+ startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER).setPackage(getPackageName()),
+ REQUEST_PICK_WALLPAPER);
if (mLauncherCallbacks != null) {
mLauncherCallbacks.onClickWallpaperPicker(v);
@@ -2915,12 +2938,11 @@
int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
if (v instanceof TextView) {
// Launch from center of icon, not entire view
- TextView tv = (TextView) v;
- Drawable[] drawables = tv.getCompoundDrawables();
- if (drawables != null && drawables[1] != null) {
- Rect bounds = drawables[1].getBounds();
+ Drawable icon = Workspace.getTextViewIcon((TextView) v);
+ if (icon != null) {
+ Rect bounds = icon.getBounds();
left = (width - bounds.width()) / 2;
- top = tv.getPaddingTop();
+ top = v.getPaddingTop();
width = bounds.width();
height = bounds.height();
}
@@ -2936,14 +2958,11 @@
sClipRevealMethod = null;
}
}
- if (opts == null) {
- opts = Utilities.isLmpOrAbove() ?
- ActivityOptions.makeCustomAnimation(this,
- R.anim.task_open_enter, R.anim.no_anim) :
- ActivityOptions.makeScaleUpAnimation(v, 0, 0,
+ if (opts == null && !Utilities.isLmpOrAbove()) {
+ opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
v.getMeasuredWidth(), v.getMeasuredHeight());
}
- optsBundle = opts.toBundle();
+ optsBundle = opts != null ? opts.toBundle() : null;
}
if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
@@ -3165,7 +3184,7 @@
View itemUnderLongClick = null;
if (v.getTag() instanceof ItemInfo) {
ItemInfo info = (ItemInfo) v.getTag();
- longClickCellInfo = new CellLayout.CellInfo(v, info);;
+ longClickCellInfo = new CellLayout.CellInfo(v, info);
itemUnderLongClick = longClickCellInfo.cell;
resetAddInfo();
}
@@ -3214,12 +3233,23 @@
return null;
}
} else {
- return (CellLayout) mWorkspace.getScreenWithId(screenId);
+ return mWorkspace.getScreenWithId(screenId);
}
}
+ /**
+ * For overridden classes.
+ */
public boolean isAllAppsVisible() {
- return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
+ return isAppsViewVisible();
+ }
+
+ public boolean isAppsViewVisible() {
+ return (mState == State.APPS) || (mOnResumeState == State.APPS);
+ }
+
+ public boolean isWidgetsViewVisible() {
+ return (mState == State.WIDGETS) || (mOnResumeState == State.WIDGETS);
}
private void setWorkspaceBackground(boolean workspace) {
@@ -3237,578 +3267,6 @@
setWorkspaceBackground(visible);
}
- private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
- if (v instanceof LauncherTransitionable) {
- ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
- }
- }
-
- private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
- if (v instanceof LauncherTransitionable) {
- ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
- }
-
- // Update the workspace transition step as well
- dispatchOnLauncherTransitionStep(v, 0f);
- }
-
- private void dispatchOnLauncherTransitionStep(View v, float t) {
- if (v instanceof LauncherTransitionable) {
- ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
- }
- }
-
- private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
- if (v instanceof LauncherTransitionable) {
- ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
- }
-
- // Update the workspace transition step as well
- dispatchOnLauncherTransitionStep(v, 1f);
- }
-
- /**
- * Things to test when changing the following seven functions.
- * - Home from workspace
- * - from center screen
- * - from other screens
- * - Home from all apps
- * - from center screen
- * - from other screens
- * - Back from all apps
- * - from center screen
- * - from other screens
- * - Launch app from workspace and quit
- * - with back
- * - with home
- * - Launch app from all apps and quit
- * - with back
- * - with home
- * - Go to a screen that's not the default, then all
- * apps, and launch and app, and go back
- * - with back
- * -with home
- * - On workspace, long press power and go back
- * - with back
- * - with home
- * - On all apps, long press power and go back
- * - with back
- * - with home
- * - On workspace, power off
- * - On all apps, power off
- * - Launch an app and turn off the screen while in that app
- * - Go back with home key
- * - Go back with back key TODO: make this not go to workspace
- * - From all apps
- * - From workspace
- * - Enter and exit car mode (becuase it causes an extra configuration changed)
- * - From all apps
- * - From the center workspace
- * - From another workspace
- */
-
- /**
- * Zoom the camera out from the workspace to reveal 'toView'.
- * Assumes that the view to show is anchored at either the very top or very bottom
- * of the screen.
- */
- private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
- AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
- showAppsCustomizeHelper(animated, springLoaded, contentType);
- }
-
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)
- private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
- final AppsCustomizePagedView.ContentType contentType) {
- if (mStateAnimation != null) {
- mStateAnimation.setDuration(0);
- mStateAnimation.cancel();
- mStateAnimation = null;
- }
-
- boolean material = Utilities.isLmpOrAbove();
-
- final Resources res = getResources();
-
- final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
- final int itemsAlphaStagger =
- res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
-
- final View fromView = mWorkspace;
- final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
-
- final HashMap<View, Integer> layerViews = new HashMap<View, Integer>();
-
- Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
- Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
- Animator workspaceAnim =
- mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews);
- if (contentType == AppsCustomizePagedView.ContentType.Widgets) {
- // Set the content type for the all apps/widgets space
- mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
- }
-
- // If for some reason our views aren't initialized, don't animate
- boolean initialized = getAllAppsButton() != null;
-
- if (animated && initialized) {
- mStateAnimation = LauncherAnimUtils.createAnimatorSet();
- final AppsCustomizePagedView content = (AppsCustomizePagedView)
- toView.findViewById(R.id.apps_customize_pane_content);
-
- final View page = content.getPageAt(content.getCurrentPage());
- final View revealView = toView.findViewById(R.id.fake_page);
-
- final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
- if (isWidgetTray) {
- revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
- } else {
- revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
- }
-
- // Hide the real page background, and swap in the fake one
- content.setPageBackgroundsVisible(false);
- revealView.setVisibility(View.VISIBLE);
- // We need to hide this view as the animation start will be posted.
- revealView.setAlpha(0);
-
- int width = revealView.getMeasuredWidth();
- int height = revealView.getMeasuredHeight();
- float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
-
- revealView.setTranslationY(0);
- revealView.setTranslationX(0);
-
- // Get the y delta between the center of the page and the center of the all apps button
- int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
- getAllAppsButton(), null);
-
- float alpha = 0;
- float xDrift = 0;
- float yDrift = 0;
- if (material) {
- alpha = isWidgetTray ? 0.3f : 1f;
- yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
- xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
- } else {
- yDrift = 2 * height / 3;
- xDrift = 0;
- }
- final float initAlpha = alpha;
-
- layerViews.put(revealView, BUILD_AND_SET_LAYER);
- PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
- PropertyValuesHolder panelDriftY =
- PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
- PropertyValuesHolder panelDriftX =
- PropertyValuesHolder.ofFloat("translationX", xDrift, 0);
-
- ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView,
- panelAlpha, panelDriftY, panelDriftX);
-
- panelAlphaAndDrift.setDuration(revealDuration);
- panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
-
- mStateAnimation.play(panelAlphaAndDrift);
-
- if (page != null) {
- page.setVisibility(View.VISIBLE);
- layerViews.put(page, BUILD_AND_SET_LAYER);
-
- ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
- page.setTranslationY(yDrift);
- pageDrift.setDuration(revealDuration);
- pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
- pageDrift.setStartDelay(itemsAlphaStagger);
- mStateAnimation.play(pageDrift);
-
- page.setAlpha(0f);
- ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f);
- itemsAlpha.setDuration(revealDuration);
- itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
- itemsAlpha.setStartDelay(itemsAlphaStagger);
- mStateAnimation.play(itemsAlpha);
- }
-
- View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
- pageIndicators.setAlpha(0.01f);
- ObjectAnimator indicatorsAlpha =
- ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
- indicatorsAlpha.setDuration(revealDuration);
- mStateAnimation.play(indicatorsAlpha);
-
- if (material) {
- final View allApps = getAllAppsButton();
- int allAppsButtonSize = LauncherAppState.getInstance().
- getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
- float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
- Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2,
- height / 2, startRadius, revealRadius);
- reveal.setDuration(revealDuration);
- reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
-
- reveal.addListener(new AnimatorListenerAdapter() {
- public void onAnimationStart(Animator animation) {
- if (!isWidgetTray) {
- allApps.setVisibility(View.INVISIBLE);
- }
- }
- public void onAnimationEnd(Animator animation) {
- if (!isWidgetTray) {
- allApps.setVisibility(View.VISIBLE);
- }
- }
- });
- mStateAnimation.play(reveal);
- }
-
- mStateAnimation.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- dispatchOnLauncherTransitionEnd(fromView, animated, false);
- dispatchOnLauncherTransitionEnd(toView, animated, false);
-
- revealView.setVisibility(View.INVISIBLE);
-
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_NONE, null);
- }
- }
- content.setPageBackgroundsVisible(true);
-
- // Hide the search bar
- if (mSearchDropTargetBar != null) {
- mSearchDropTargetBar.hideSearchBar(false);
- }
-
- // This can hold unnecessary references to views.
- mStateAnimation = null;
- }
-
- });
-
- if (workspaceAnim != null) {
- mStateAnimation.play(workspaceAnim);
- }
-
- dispatchOnLauncherTransitionPrepare(fromView, animated, false);
- dispatchOnLauncherTransitionPrepare(toView, animated, false);
- final AnimatorSet stateAnimation = mStateAnimation;
- final Runnable startAnimRunnable = new Runnable() {
- public void run() {
- // Check that mStateAnimation hasn't changed while
- // we waited for a layout/draw pass
- if (mStateAnimation != stateAnimation)
- return;
- dispatchOnLauncherTransitionStart(fromView, animated, false);
- dispatchOnLauncherTransitionStart(toView, animated, false);
-
- revealView.setAlpha(initAlpha);
-
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
- }
- }
-
- if (Utilities.isLmpOrAbove()) {
- for (View v : layerViews.keySet()) {
- if (Utilities.isViewAttachedToWindow(v)) v.buildLayer();
- }
- }
- mStateAnimation.start();
- }
- };
- toView.bringToFront();
- toView.setVisibility(View.VISIBLE);
- toView.post(startAnimRunnable);
- } else {
- toView.setTranslationX(0.0f);
- toView.setTranslationY(0.0f);
- toView.setScaleX(1.0f);
- toView.setScaleY(1.0f);
- toView.setVisibility(View.VISIBLE);
- toView.bringToFront();
-
- if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
- // Hide the search bar
- if (mSearchDropTargetBar != null) {
- mSearchDropTargetBar.hideSearchBar(false);
- }
- }
- dispatchOnLauncherTransitionPrepare(fromView, animated, false);
- dispatchOnLauncherTransitionStart(fromView, animated, false);
- dispatchOnLauncherTransitionEnd(fromView, animated, false);
- dispatchOnLauncherTransitionPrepare(toView, animated, false);
- dispatchOnLauncherTransitionStart(toView, animated, false);
- dispatchOnLauncherTransitionEnd(toView, animated, false);
- }
- }
-
- /**
- * Zoom the camera back into the workspace, hiding 'fromView'.
- * This is the opposite of showAppsCustomizeHelper.
- * @param animated If true, the transition will be animated.
- */
- private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
- final boolean springLoaded, final Runnable onCompleteRunnable) {
-
- if (mStateAnimation != null) {
- mStateAnimation.setDuration(0);
- mStateAnimation.cancel();
- mStateAnimation = null;
- }
-
- boolean material = Utilities.isLmpOrAbove();
- Resources res = getResources();
-
- final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
- final int itemsAlphaStagger =
- res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
-
- final View fromView = mAppsCustomizeTabHost;
- final View toView = mWorkspace;
- Animator workspaceAnim = null;
- final HashMap<View, Integer> layerViews = new HashMap<View, Integer>();
-
- if (toState == Workspace.State.NORMAL) {
- workspaceAnim = mWorkspace.getChangeStateAnimation(
- toState, animated, layerViews);
- } else if (toState == Workspace.State.SPRING_LOADED ||
- toState == Workspace.State.OVERVIEW) {
- workspaceAnim = mWorkspace.getChangeStateAnimation(
- toState, animated, layerViews);
- }
-
- // If for some reason our views aren't initialized, don't animate
- boolean initialized = getAllAppsButton() != null;
-
- if (animated && initialized) {
- mStateAnimation = LauncherAnimUtils.createAnimatorSet();
- if (workspaceAnim != null) {
- mStateAnimation.play(workspaceAnim);
- }
-
- final AppsCustomizePagedView content = (AppsCustomizePagedView)
- fromView.findViewById(R.id.apps_customize_pane_content);
-
- final View page = content.getPageAt(content.getNextPage());
-
- // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases
- int count = content.getChildCount();
- for (int i = 0; i < count; i++) {
- View child = content.getChildAt(i);
- if (child != page) {
- child.setVisibility(View.INVISIBLE);
- }
- }
- final View revealView = fromView.findViewById(R.id.fake_page);
-
- // hideAppsCustomizeHelper is called in some cases when it is already hidden
- // don't perform all these no-op animations. In particularly, this was causing
- // the all-apps button to pop in and out.
- if (fromView.getVisibility() == View.VISIBLE) {
- AppsCustomizePagedView.ContentType contentType = content.getContentType();
- final boolean isWidgetTray =
- contentType == AppsCustomizePagedView.ContentType.Widgets;
-
- if (isWidgetTray) {
- revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
- } else {
- revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
- }
-
- int width = revealView.getMeasuredWidth();
- int height = revealView.getMeasuredHeight();
- float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
-
- // Hide the real page background, and swap in the fake one
- revealView.setVisibility(View.VISIBLE);
- content.setPageBackgroundsVisible(false);
-
- final View allAppsButton = getAllAppsButton();
- revealView.setTranslationY(0);
- int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
- allAppsButton, null);
-
- float xDrift = 0;
- float yDrift = 0;
- if (material) {
- yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
- xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
- } else {
- yDrift = 2 * height / 3;
- xDrift = 0;
- }
-
- layerViews.put(revealView, BUILD_AND_SET_LAYER);
- TimeInterpolator decelerateInterpolator = material ?
- new LogDecelerateInterpolator(100, 0) :
- new DecelerateInterpolator(1f);
-
- // The vertical motion of the apps panel should be delayed by one frame
- // from the conceal animation in order to give the right feel. We correpsondingly
- // shorten the duration so that the slide and conceal end at the same time.
- ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY",
- 0, yDrift);
- panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
- panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
- panelDriftY.setInterpolator(decelerateInterpolator);
- mStateAnimation.play(panelDriftY);
-
- ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX",
- 0, xDrift);
- panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
- panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
- panelDriftX.setInterpolator(decelerateInterpolator);
- mStateAnimation.play(panelDriftX);
-
- if (isWidgetTray || !material) {
- float finalAlpha = material ? 0.4f : 0f;
- revealView.setAlpha(1f);
- ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha",
- 1f, finalAlpha);
- panelAlpha.setDuration(material ? revealDuration : 150);
- panelAlpha.setInterpolator(decelerateInterpolator);
- panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY);
- mStateAnimation.play(panelAlpha);
- }
-
- if (page != null) {
- layerViews.put(page, BUILD_AND_SET_LAYER);
-
- ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
- 0, yDrift);
- page.setTranslationY(0);
- pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
- pageDrift.setInterpolator(decelerateInterpolator);
- pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
- mStateAnimation.play(pageDrift);
-
- page.setAlpha(1f);
- ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
- itemsAlpha.setDuration(100);
- itemsAlpha.setInterpolator(decelerateInterpolator);
- mStateAnimation.play(itemsAlpha);
- }
-
- View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
- pageIndicators.setAlpha(1f);
- ObjectAnimator indicatorsAlpha =
- LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
- indicatorsAlpha.setDuration(revealDuration);
- indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
- mStateAnimation.play(indicatorsAlpha);
-
- width = revealView.getMeasuredWidth();
-
- if (material) {
- if (!isWidgetTray) {
- allAppsButton.setVisibility(View.INVISIBLE);
- }
- int allAppsButtonSize = LauncherAppState.getInstance().
- getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
- float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
- Animator reveal =
- LauncherAnimUtils.createCircularReveal(revealView, width / 2,
- height / 2, revealRadius, finalRadius);
- reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
- reveal.setDuration(revealDuration);
- reveal.setStartDelay(itemsAlphaStagger);
-
- reveal.addListener(new AnimatorListenerAdapter() {
- public void onAnimationEnd(Animator animation) {
- revealView.setVisibility(View.INVISIBLE);
- if (!isWidgetTray) {
- allAppsButton.setVisibility(View.VISIBLE);
- }
- }
- });
-
- mStateAnimation.play(reveal);
- }
-
- dispatchOnLauncherTransitionPrepare(fromView, animated, true);
- dispatchOnLauncherTransitionPrepare(toView, animated, true);
- mAppsCustomizeContent.stopScrolling();
- }
-
- mStateAnimation.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- fromView.setVisibility(View.GONE);
- dispatchOnLauncherTransitionEnd(fromView, animated, true);
- dispatchOnLauncherTransitionEnd(toView, animated, true);
- if (onCompleteRunnable != null) {
- onCompleteRunnable.run();
- }
-
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_NONE, null);
- }
- }
-
- content.setPageBackgroundsVisible(true);
- // Unhide side pages
- int count = content.getChildCount();
- for (int i = 0; i < count; i++) {
- View child = content.getChildAt(i);
- child.setVisibility(View.VISIBLE);
- }
-
- // Reset page transforms
- if (page != null) {
- page.setTranslationX(0);
- page.setTranslationY(0);
- page.setAlpha(1);
- }
- content.setCurrentPage(content.getNextPage());
-
- mAppsCustomizeContent.updateCurrentPageScroll();
-
- // This can hold unnecessary references to views.
- mStateAnimation = null;
- }
- });
-
- final AnimatorSet stateAnimation = mStateAnimation;
- final Runnable startAnimRunnable = new Runnable() {
- public void run() {
- // Check that mStateAnimation hasn't changed while
- // we waited for a layout/draw pass
- if (mStateAnimation != stateAnimation)
- return;
- dispatchOnLauncherTransitionStart(fromView, animated, false);
- dispatchOnLauncherTransitionStart(toView, animated, false);
-
- for (View v : layerViews.keySet()) {
- if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
- v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
- }
- }
-
- if (Utilities.isLmpOrAbove()) {
- for (View v : layerViews.keySet()) {
- if (Utilities.isViewAttachedToWindow(v)) v.buildLayer();
- }
- }
- mStateAnimation.start();
- }
- };
- fromView.post(startAnimRunnable);
- } else {
- fromView.setVisibility(View.GONE);
- dispatchOnLauncherTransitionPrepare(fromView, animated, true);
- dispatchOnLauncherTransitionStart(fromView, animated, true);
- dispatchOnLauncherTransitionEnd(fromView, animated, true);
- dispatchOnLauncherTransitionPrepare(toView, animated, true);
- dispatchOnLauncherTransitionStart(toView, animated, true);
- dispatchOnLauncherTransitionEnd(toView, animated, true);
- }
- }
-
@Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
@@ -3822,21 +3280,29 @@
mAppsCustomizeTabHost.trimMemory();
}
}
+ if (mLauncherCallbacks != null) {
+ mLauncherCallbacks.onTrimMemory(level);
+ }
+ }
+
+ @Override
+ public void onStateTransitionHideSearchBar() {
+ // Hide the search bar
+ if (mSearchDropTargetBar != null) {
+ mSearchDropTargetBar.hideSearchBar(false /* animated */);
+ }
}
protected void showWorkspace(boolean animated) {
showWorkspace(animated, null);
}
- protected void showWorkspace() {
- showWorkspace(true);
- }
-
void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
mWorkspace.setVisibility(View.VISIBLE);
- hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
+ mStateTransitionAnimation.startAnimationToWorkspace(mState, Workspace.State.NORMAL,
+ animated, onCompleteRunnable);
// Show the search bar (only animate if we were showing the drop target bar in spring
// loaded mode)
@@ -3855,7 +3321,7 @@
// Resume the auto-advance of widgets
mUserPresent = true;
- updateRunning();
+ updateAutoAdvanceState();
// Send an accessibility event to announce the context change
getWindow().getDecorView()
@@ -3866,7 +3332,8 @@
void showOverviewMode(boolean animated) {
mWorkspace.setVisibility(View.VISIBLE);
- hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
+ mStateTransitionAnimation.startAnimationToWorkspace(mState, Workspace.State.OVERVIEW,
+ animated, null /* onCompleteRunnable */);
mState = State.WORKSPACE;
onWorkspaceShown(animated);
}
@@ -3874,14 +3341,24 @@
public void onWorkspaceShown(boolean animated) {
}
- void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
- boolean resetPageToZero) {
- if (mState != State.WORKSPACE) return;
+ /**
+ * Shows the apps view.
+ */
+ void showAppsView(boolean animated, boolean resetListToTop) {
+ if (resetListToTop) {
+ mAppsView.scrollToTop();
+ }
+ showAppsOrWidgets(animated, State.APPS);
+ }
+ /**
+ * Shows the widgets view.
+ */
+ void showWidgetsView(boolean animated, boolean resetPageToZero) {
if (resetPageToZero) {
mAppsCustomizeTabHost.reset();
}
- showAppsCustomizeHelper(animated, false, contentType);
+ showAppsOrWidgets(animated, State.WIDGETS);
mAppsCustomizeTabHost.post(new Runnable() {
@Override
public void run() {
@@ -3889,13 +3366,27 @@
mAppsCustomizeTabHost.requestFocus();
}
});
+ }
+
+ /**
+ * Sets up the transition to show the apps/widgets view.
+ */
+ private void showAppsOrWidgets(boolean animated, State toState) {
+ if (mState != State.WORKSPACE) return;
+ if (toState != State.APPS && toState != State.WIDGETS) return;
+
+ if (toState == State.APPS) {
+ mStateTransitionAnimation.startAnimationToAllApps(animated);
+ } else {
+ mStateTransitionAnimation.startAnimationToWidgets(animated);
+ }
// Change the state *after* we've called all the transition code
- mState = State.APPS_CUSTOMIZE;
+ mState = toState;
// Pause the auto-advance of widgets until we are out of AllApps
mUserPresent = false;
- updateRunning();
+ updateAutoAdvanceState();
closeFolder();
// Send an accessibility event to announce the context change
@@ -3904,15 +3395,19 @@
}
void enterSpringLoadedDragMode() {
- if (isAllAppsVisible()) {
- hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
- mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
+ if (mState == State.WORKSPACE || mState == State.APPS_SPRING_LOADED ||
+ mState == State.WIDGETS_SPRING_LOADED) {
+ return;
}
+
+ mStateTransitionAnimation.startAnimationToWorkspace(mState, Workspace.State.SPRING_LOADED,
+ true /* animated */, null /* onCompleteRunnable */);
+ mState = isAppsViewVisible() ? State.APPS_SPRING_LOADED : State.WIDGETS_SPRING_LOADED;
}
void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
final Runnable onCompleteRunnable) {
- if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
+ if (mState != State.APPS_SPRING_LOADED && mState != State.WIDGETS_SPRING_LOADED) return;
mHandler.postDelayed(new Runnable() {
@Override
@@ -3931,11 +3426,12 @@
}
void exitSpringLoadedDragMode() {
- if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
- final boolean animated = true;
- final boolean springLoaded = true;
- showAppsCustomizeHelper(animated, springLoaded);
- mState = State.APPS_CUSTOMIZE;
+ if (mState == State.APPS_SPRING_LOADED) {
+ mStateTransitionAnimation.startAnimationToAllApps(true /* animated */);
+ mState = State.APPS;
+ } else if (mState == State.WIDGETS_SPRING_LOADED) {
+ mStateTransitionAnimation.startAnimationToWidgets(true /* animated */);
+ mState = State.WIDGETS;
}
// Otherwise, we are not in spring loaded mode, so don't do anything.
}
@@ -3952,7 +3448,7 @@
// NO-OP
}
- public View getQsbBar() {
+ public View getOrCreateQsbBar() {
if (mLauncherCallbacks != null && mLauncherCallbacks.providesSearch()) {
return mLauncherCallbacks.getQsbBar();
}
@@ -4001,19 +3497,31 @@
mQsb.updateAppWidgetOptions(opts);
mQsb.setPadding(0, 0, 0, 0);
mSearchDropTargetBar.addView(mQsb);
+ mSearchDropTargetBar.setQsbSearchBar(mQsb);
}
}
return mQsb;
}
+ private void reinflateQSBIfNecessary() {
+ if (mQsb instanceof LauncherAppWidgetHostView &&
+ ((LauncherAppWidgetHostView) mQsb).isReinflateRequired()) {
+ mSearchDropTargetBar.removeView(mQsb);
+ mQsb = null;
+ mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
+ }
+ }
+
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
final boolean result = super.dispatchPopulateAccessibilityEvent(event);
final List<CharSequence> text = event.getText();
text.clear();
// Populate event with a fake title based on the current state.
- if (mState == State.APPS_CUSTOMIZE) {
- text.add(mAppsCustomizeTabHost.getContentTag());
+ if (mState == State.APPS) {
+ text.add("Apps");
+ } else if (mState == State.WIDGETS) {
+ text.add("Widgets");
} else {
text.add(getString(R.string.all_apps_home_button_label));
}
@@ -4023,7 +3531,7 @@
/**
* Receives notifications when system dialogs are to be closed.
*/
- private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
+ @Thunk class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
closeSystemDialogs();
@@ -4236,8 +3744,8 @@
// Remove the extra empty screen
mWorkspace.removeExtraEmptyScreen(false, false);
- if (addedApps != null && mAppsCustomizeContent != null) {
- mAppsCustomizeContent.addApps(addedApps);
+ if (addedApps != null && mAppsView != null) {
+ mAppsView.addApps(addedApps);
}
}
@@ -4388,7 +3896,7 @@
final Workspace workspace = mWorkspace;
LauncherAppWidgetProviderInfo appWidgetInfo =
- LauncherModel.getProviderInfo(this, item.providerName);
+ LauncherModel.getProviderInfo(this, item.providerName, item.user);
if (!mIsSafeModeEnabled
&& ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0)
@@ -4602,7 +4110,7 @@
mSearchDropTargetBar.removeView(mQsb);
mQsb = null;
}
- mSearchDropTargetBar.setQsbSearchBar(getQsbBar());
+ mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
}
/**
@@ -4611,10 +4119,12 @@
* Implementation of the method from LauncherModel.Callbacks.
*/
public void bindAllApplications(final ArrayList<AppInfo> apps) {
+ if (mAppsView != null) {
+ mAppsView.setApps(apps);
+ }
if (mAppsCustomizeContent != null) {
- mAppsCustomizeContent.setApps(apps);
mAppsCustomizeContent.onPackagesUpdated(
- LauncherModel.getSortedWidgetsAndShortcuts(this));
+ LauncherModel.getSortedWidgetsAndShortcuts(this, false /* refresh */));
}
if (mLauncherCallbacks != null) {
mLauncherCallbacks.bindAllApplications(apps);
@@ -4636,8 +4146,8 @@
return;
}
- if (mAppsCustomizeContent != null) {
- mAppsCustomizeContent.updateApps(apps);
+ if (mAppsView != null) {
+ mAppsView.updateApps(apps);
}
}
@@ -4751,15 +4261,15 @@
}
// Update AllApps
- if (mAppsCustomizeContent != null) {
- mAppsCustomizeContent.removeApps(appInfos);
+ if (mAppsView != null) {
+ mAppsView.removeApps(appInfos);
}
}
/**
* A number of packages were updated.
*/
- private ArrayList<Object> mWidgetsAndShortcuts;
+ @Thunk ArrayList<Object> mWidgetsAndShortcuts;
private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
public void run() {
bindPackagesUpdated(mWidgetsAndShortcuts);
@@ -4984,7 +4494,7 @@
editor.apply();
}
- private void showFirstRunClings() {
+ @Thunk void showFirstRunClings() {
// The two first run cling paths are mutually exclusive, if the launcher is preinstalled
// on the device, then we always show the first run cling experience (or if there is no
// launcher2). Otherwise, we prompt the user upon started for migration
diff --git a/src/com/android/launcher3/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/LauncherAccessibilityDelegate.java
index c9e277e..42f1914 100644
--- a/src/com/android/launcher3/LauncherAccessibilityDelegate.java
+++ b/src/com/android/launcher3/LauncherAccessibilityDelegate.java
@@ -1,15 +1,21 @@
package com.android.launcher3;
import android.annotation.TargetApi;
+import android.content.res.Resources;
+import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
+import android.support.v4.view.accessibility.AccessibilityEventCompat;
+import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.util.SparseArray;
import android.view.View;
import android.view.View.AccessibilityDelegate;
+import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import com.android.launcher3.LauncherModel.ScreenPosProvider;
+import com.android.launcher3.util.Thunk;
import java.util.ArrayList;
@@ -20,10 +26,25 @@
public static final int INFO = R.id.action_info;
public static final int UNINSTALL = R.id.action_uninstall;
public static final int ADD_TO_WORKSPACE = R.id.action_add_to_workspace;
+ public static final int MOVE = R.id.action_move;
+
+ enum DragType {
+ ICON,
+ FOLDER,
+ WIDGET
+ }
+
+ public static class DragInfo {
+ DragType dragType;
+ ItemInfo info;
+ View item;
+ }
+
+ private DragInfo mDragInfo = null;
private final SparseArray<AccessibilityAction> mActions =
new SparseArray<AccessibilityAction>();
- private final Launcher mLauncher;
+ @Thunk final Launcher mLauncher;
public LauncherAccessibilityDelegate(Launcher launcher) {
mLauncher = launcher;
@@ -36,6 +57,9 @@
launcher.getText(R.string.delete_target_uninstall_label)));
mActions.put(ADD_TO_WORKSPACE, new AccessibilityAction(ADD_TO_WORKSPACE,
launcher.getText(R.string.action_add_to_workspace)));
+ mActions.put(MOVE, new AccessibilityAction(MOVE,
+ launcher.getText(R.string.action_move)));
+
}
@Override
@@ -49,6 +73,7 @@
|| (item instanceof FolderInfo)) {
// Workspace shortcut / widget
info.addAction(mActions.get(REMOVE));
+ info.addAction(mActions.get(MOVE));
} else if ((item instanceof AppInfo) || (item instanceof PendingAddItemInfo)) {
// App or Widget from customization tray
if (item instanceof AppInfo) {
@@ -69,14 +94,21 @@
}
public boolean performAction(View host, ItemInfo item, int action) {
+ Resources res = mLauncher.getResources();
if (action == REMOVE) {
- return DeleteDropTarget.removeWorkspaceOrFolderItem(mLauncher, item, host);
+ if (DeleteDropTarget.removeWorkspaceOrFolderItem(mLauncher, item, host)) {
+ announceConfirmation(R.string.item_removed_from_workspace);
+ return true;
+ }
+ return false;
} else if (action == INFO) {
InfoDropTarget.startDetailsActivityForInfo(item, mLauncher);
return true;
} else if (action == UNINSTALL) {
DeleteDropTarget.uninstallApp(mLauncher, (AppInfo) item);
return true;
+ } else if (action == MOVE) {
+ beginAccessibleDrag(host, item);
} else if (action == ADD_TO_WORKSPACE) {
final int preferredPage = mLauncher.getWorkspace().getCurrentPage();
final ScreenPosProvider screenProvider = new ScreenPosProvider() {
@@ -90,20 +122,92 @@
final ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>();
addShortcuts.add(((AppInfo) item).makeShortcut());
mLauncher.showWorkspace(true, new Runnable() {
-
@Override
public void run() {
mLauncher.getModel().addAndBindAddedWorkspaceApps(
mLauncher, addShortcuts, screenProvider, 0, true);
+ announceConfirmation(R.string.item_added_to_workspace);
}
});
return true;
} else if (item instanceof PendingAddItemInfo) {
mLauncher.getModel().addAndBindPendingItem(
mLauncher, (PendingAddItemInfo) item, screenProvider, 0);
+ announceConfirmation(R.string.item_added_to_workspace);
return true;
}
}
return false;
}
+
+ @Thunk void announceConfirmation(int resId) {
+ announceConfirmation(mLauncher.getResources().getString(resId));
+ }
+
+ @Thunk void announceConfirmation(String confirmation) {
+ mLauncher.getDragLayer().announceForAccessibility(confirmation);
+
+ }
+
+ public boolean isInAccessibleDrag() {
+ return mDragInfo != null;
+ }
+
+ public DragInfo getDragInfo() {
+ return mDragInfo;
+ }
+
+ public void handleAccessibleDrop(CellLayout targetContainer, Rect dropLocation,
+ String confirmation) {
+ if (!isInAccessibleDrag()) return;
+
+ int[] loc = new int[2];
+ loc[0] = dropLocation.centerX();
+ loc[1] = dropLocation.centerY();
+
+ mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(targetContainer, loc);
+ mLauncher.getDragController().completeAccessibleDrag(loc);
+
+ endAccessibleDrag();
+ announceConfirmation(confirmation);
+ }
+
+ public void beginAccessibleDrag(View item, ItemInfo info) {
+ mDragInfo = new DragInfo();
+ mDragInfo.info = info;
+ mDragInfo.item = item;
+ mDragInfo.dragType = DragType.ICON;
+ if (info instanceof FolderInfo) {
+ mDragInfo.dragType = DragType.FOLDER;
+ } else if (info instanceof LauncherAppWidgetInfo) {
+ mDragInfo.dragType = DragType.WIDGET;
+ }
+
+ CellLayout.CellInfo cellInfo = new CellLayout.CellInfo(item, info);
+
+ Rect pos = new Rect();
+ mLauncher.getDragLayer().getDescendantRectRelativeToSelf(item, pos);
+
+ mLauncher.getDragController().prepareAccessibleDrag(pos.centerX(), pos.centerY());
+ mLauncher.getWorkspace().enableAccessibleDrag(true);
+ mLauncher.getWorkspace().startDrag(cellInfo, true);
+ }
+
+ public boolean onBackPressed() {
+ if (isInAccessibleDrag()) {
+ cancelAccessibleDrag();
+ return true;
+ }
+ return false;
+ }
+
+ private void cancelAccessibleDrag() {
+ mLauncher.getDragController().cancelDrag();
+ endAccessibleDrag();
+ }
+
+ private void endAccessibleDrag() {
+ mDragInfo = null;
+ mLauncher.getWorkspace().enableAccessibleDrag(false);
+ }
}
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index 8e6557f..2a08b81 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -19,25 +19,22 @@
import android.annotation.TargetApi;
import android.app.SearchManager;
import android.content.ComponentName;
-import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.res.Resources;
-import android.database.ContentObserver;
import android.graphics.Point;
import android.os.Build;
-import android.os.Handler;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
-import android.view.View.AccessibilityDelegate;
import android.view.WindowManager;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
+import com.android.launcher3.util.Thunk;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
@@ -46,14 +43,14 @@
private final AppFilter mAppFilter;
private final BuildInfo mBuildInfo;
- private final LauncherModel mModel;
+ @Thunk final LauncherModel mModel;
private final IconCache mIconCache;
+ private final WidgetPreviewLoader mWidgetCache;
private final boolean mIsScreenLarge;
private final float mScreenDensity;
private final int mLongPressTimeout = 300;
- private WidgetPreviewLoader.CacheDb mWidgetPreviewCacheDb;
private boolean mWallpaperChangedSinceLastCheck;
private static WeakReference<LauncherProvider> sLauncherProvider;
@@ -62,7 +59,7 @@
private static LauncherAppState INSTANCE;
private DynamicGrid mDynamicGrid;
- private AccessibilityDelegate mAccessibilityDelegate;
+ private LauncherAccessibilityDelegate mAccessibilityDelegate;
public static LauncherAppState getInstance() {
if (INSTANCE == null) {
@@ -100,39 +97,22 @@
// set sIsScreenXLarge and mScreenDensity *before* creating icon cache
mIsScreenLarge = isScreenLarge(sContext.getResources());
mScreenDensity = sContext.getResources().getDisplayMetrics().density;
-
- recreateWidgetPreviewDb();
mIconCache = new IconCache(sContext);
+ mWidgetCache = new WidgetPreviewLoader(sContext, mIconCache);
mAppFilter = AppFilter.loadByName(sContext.getString(R.string.app_filter_class));
mBuildInfo = BuildInfo.loadByName(sContext.getString(R.string.build_info_class));
mModel = new LauncherModel(this, mIconCache, mAppFilter);
- final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(sContext);
- launcherApps.addOnAppsChangedCallback(mModel);
+
+ LauncherAppsCompat.getInstance(sContext).addOnAppsChangedCallback(mModel);
// Register intent receivers
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_LOCALE_CHANGED);
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
- sContext.registerReceiver(mModel, filter);
- filter = new IntentFilter();
filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
- sContext.registerReceiver(mModel, filter);
- filter = new IntentFilter();
filter.addAction(SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED);
sContext.registerReceiver(mModel, filter);
-
- // Register for changes to the favorites
- ContentResolver resolver = sContext.getContentResolver();
- resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true,
- mFavoritesObserver);
- }
-
- public void recreateWidgetPreviewDb() {
- if (mWidgetPreviewCacheDb != null) {
- mWidgetPreviewCacheDb.close();
- }
- mWidgetPreviewCacheDb = new WidgetPreviewLoader.CacheDb(sContext);
}
/**
@@ -143,23 +123,16 @@
final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(sContext);
launcherApps.removeOnAppsChangedCallback(mModel);
PackageInstallerCompat.getInstance(sContext).onStop();
-
- ContentResolver resolver = sContext.getContentResolver();
- resolver.unregisterContentObserver(mFavoritesObserver);
}
/**
- * Receives notifications whenever the user favorites have changed.
+ * Reloads the workspace items from the DB and re-binds the workspace. This should generally
+ * not be called as DB updates are automatically followed by UI update
*/
- private final ContentObserver mFavoritesObserver = new ContentObserver(new Handler()) {
- @Override
- public void onChange(boolean selfChange) {
- // If the database has ever changed, then we really need to force a reload of the
- // workspace on the next load
- mModel.resetLoadedState(false, true);
- mModel.startLoaderFromBackground();
- }
- };
+ public void reloadWorkspace() {
+ mModel.resetLoadedState(false, true);
+ mModel.startLoaderFromBackground();
+ }
LauncherModel setLauncher(Launcher launcher) {
mModel.initialize(launcher);
@@ -168,7 +141,7 @@
return mModel;
}
- AccessibilityDelegate getAccessibilityDelegate() {
+ LauncherAccessibilityDelegate getAccessibilityDelegate() {
return mAccessibilityDelegate;
}
@@ -184,10 +157,6 @@
return mAppFilter == null || mAppFilter.shouldShowApp(componentName);
}
- WidgetPreviewLoader.CacheDb getWidgetPreviewCacheDb() {
- return mWidgetPreviewCacheDb;
- }
-
static void setLauncherProvider(LauncherProvider provider) {
sLauncherProvider = new WeakReference<LauncherProvider>(provider);
}
@@ -243,6 +212,10 @@
return mDynamicGrid;
}
+ public WidgetPreviewLoader getWidgetCache() {
+ return mWidgetCache;
+ }
+
public boolean isScreenLarge() {
return mIsScreenLarge;
}
diff --git a/src/com/android/launcher3/LauncherAppWidgetHost.java b/src/com/android/launcher3/LauncherAppWidgetHost.java
index 840508a..a28fd25 100644
--- a/src/com/android/launcher3/LauncherAppWidgetHost.java
+++ b/src/com/android/launcher3/LauncherAppWidgetHost.java
@@ -81,7 +81,8 @@
protected void onProvidersChanged() {
// Once we get the message that widget packages are updated, we need to rebind items
// in AppsCustomize accordingly.
- mLauncher.bindPackagesUpdated(LauncherModel.getSortedWidgetsAndShortcuts(mLauncher));
+ mLauncher.bindPackagesUpdated(LauncherModel.getSortedWidgetsAndShortcuts(mLauncher,
+ true /* refresh */));
for (Runnable callback : mProviderChangeListeners) {
callback.run();
diff --git a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
index e7f49b2..aeef0da 100644
--- a/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
+++ b/src/com/android/launcher3/LauncherAppWidgetProviderInfo.java
@@ -7,8 +7,6 @@
import android.graphics.drawable.Drawable;
import android.os.Parcel;
-import java.lang.reflect.Field;
-
/**
* This class is a thin wrapper around the framework AppWidgetProviderInfo class. This class affords
* a common object for describing both framework provided AppWidgets as well as custom widgets
diff --git a/src/com/android/launcher3/LauncherBackupAgentHelper.java b/src/com/android/launcher3/LauncherBackupAgentHelper.java
index ddfd70d..5f7173f 100644
--- a/src/com/android/launcher3/LauncherBackupAgentHelper.java
+++ b/src/com/android/launcher3/LauncherBackupAgentHelper.java
@@ -78,7 +78,7 @@
super.onRestore(data, appVersionCode, newState);
// If no favorite was migrated, clear the data and start fresh.
final Cursor c = getContentResolver().query(
- LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, null, null, null, null);
+ LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
hasData = c.moveToNext();
c.close();
} catch (Exception e) {
diff --git a/src/com/android/launcher3/LauncherBackupHelper.java b/src/com/android/launcher3/LauncherBackupHelper.java
index 97ff327..064f436 100644
--- a/src/com/android/launcher3/LauncherBackupHelper.java
+++ b/src/com/android/launcher3/LauncherBackupHelper.java
@@ -462,7 +462,7 @@
ContentResolver cr = mContext.getContentResolver();
ContentValues values = unpackFavorite(buffer, dataSize);
- cr.insert(Favorites.CONTENT_URI_NO_NOTIFICATION, values);
+ cr.insert(Favorites.CONTENT_URI, values);
}
/**
@@ -630,8 +630,7 @@
return;
}
final ContentResolver cr = mContext.getContentResolver();
- final WidgetPreviewLoader previewLoader = new WidgetPreviewLoader(mContext);
- final PagedViewCellLayout widgetSpacingLayout = new PagedViewCellLayout(mContext);
+ final WidgetPreviewLoader previewLoader = appState.getWidgetCache();
final int dpi = mContext.getResources().getDisplayMetrics().densityDpi;
final DeviceProfile profile = appState.getDynamicGrid().getDeviceProfile();
if (DEBUG) Log.d(TAG, "cellWidthPx: " + profile.cellWidthPx);
@@ -647,7 +646,6 @@
final long id = cursor.getLong(ID_INDEX);
final String providerName = cursor.getString(APPWIDGET_PROVIDER_INDEX);
final int spanX = cursor.getInt(SPANX_INDEX);
- final int spanY = cursor.getInt(SPANY_INDEX);
final ComponentName provider = ComponentName.unflattenFromString(providerName);
Key key = null;
String backupKey = null;
@@ -666,9 +664,11 @@
if (DEBUG) Log.d(TAG, "I can count this high: " + backupWidgetCount);
if (backupWidgetCount < MAX_WIDGETS_PER_PASS) {
if (DEBUG) Log.d(TAG, "saving widget " + backupKey);
- previewLoader.setPreviewSize(spanX * profile.cellWidthPx,
- spanY * profile.cellHeightPx, widgetSpacingLayout);
- writeRowToBackup(key, packWidget(dpi, previewLoader, mIconCache, provider), data);
+ UserHandleCompat user = UserHandleCompat.myUserHandle();
+ writeRowToBackup(key,
+ packWidget(dpi, previewLoader,spanX * profile.cellWidthPx,
+ mIconCache, provider, user),
+ data);
mKeys.add(key);
backupWidgetCount ++;
} else {
@@ -977,10 +977,11 @@
}
/** Serialize a widget for persistence, including a checksum wrapper. */
- private Widget packWidget(int dpi, WidgetPreviewLoader previewLoader, IconCache iconCache,
- ComponentName provider) {
+ private Widget packWidget(int dpi, WidgetPreviewLoader previewLoader,
+ int previewWidth, IconCache iconCache,
+ ComponentName provider, UserHandleCompat user) {
final LauncherAppWidgetProviderInfo info =
- LauncherModel.getProviderInfo(mContext, provider);
+ LauncherModel.getProviderInfo(mContext, provider, user);
Widget widget = new Widget();
widget.provider = provider.flattenToShortString();
widget.label = info.label;
@@ -997,7 +998,7 @@
}
if (info.previewImage != 0) {
widget.preview = new Resource();
- Bitmap preview = previewLoader.generateWidgetPreview(info, null);
+ Bitmap preview = previewLoader.generateWidgetPreview(info, previewWidth, null);
ByteArrayOutputStream os = new ByteArrayOutputStream();
if (preview.compress(IMAGE_FORMAT, IMAGE_COMPRESSION_QUALITY, os)) {
widget.preview.data = os.toByteArray();
diff --git a/src/com/android/launcher3/LauncherCallbacks.java b/src/com/android/launcher3/LauncherCallbacks.java
index a1f4e0b..d8128d6 100644
--- a/src/com/android/launcher3/LauncherCallbacks.java
+++ b/src/com/android/launcher3/LauncherCallbacks.java
@@ -42,6 +42,7 @@
public void dump(String prefix, FileDescriptor fd, PrintWriter w, String[] args);
public void onHomeIntent();
public boolean handleBackPressed();
+ public void onTrimMemory(int level);
/*
* Extension points for providing custom behavior on certain user interactions.
diff --git a/src/com/android/launcher3/LauncherClings.java b/src/com/android/launcher3/LauncherClings.java
index ef8e8ab..2ce8b1c 100644
--- a/src/com/android/launcher3/LauncherClings.java
+++ b/src/com/android/launcher3/LauncherClings.java
@@ -35,6 +35,8 @@
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.accessibility.AccessibilityManager;
+import com.android.launcher3.util.Thunk;
+
class LauncherClings implements OnClickListener {
private static final String MIGRATION_CLING_DISMISSED_KEY = "cling_gel.migration.dismissed";
private static final String WORKSPACE_CLING_DISMISSED_KEY = "cling_gel.workspace.dismissed";
@@ -49,7 +51,7 @@
// New Secure Setting in L
private static final String SKIP_FIRST_USE_HINTS = "skip_first_use_hints";
- private Launcher mLauncher;
+ @Thunk Launcher mLauncher;
private LayoutInflater mInflater;
/** Ctor */
@@ -174,7 +176,7 @@
});
}
- private void dismissLongPressCling() {
+ @Thunk void dismissLongPressCling() {
Runnable dismissCb = new Runnable() {
public void run() {
dismissCling(mLauncher.findViewById(R.id.longpress_cling), null,
@@ -185,7 +187,7 @@
}
/** Hides the specified Cling */
- private void dismissCling(final View cling, final Runnable postAnimationCb,
+ @Thunk void dismissCling(final View cling, final Runnable postAnimationCb,
final String flag, int duration) {
// To catch cases where siblings of top-level views are made invisible, just check whether
// the cling is directly set to GONE before dismissing it.
diff --git a/src/com/android/launcher3/LauncherExtension.java b/src/com/android/launcher3/LauncherExtension.java
index b264042..fe9bd6c 100644
--- a/src/com/android/launcher3/LauncherExtension.java
+++ b/src/com/android/launcher3/LauncherExtension.java
@@ -108,6 +108,10 @@
}
@Override
+ public void onTrimMemory(int level) {
+ }
+
+ @Override
public void onLauncherProviderChange() {
}
diff --git a/src/com/android/launcher3/LauncherFiles.java b/src/com/android/launcher3/LauncherFiles.java
index cedb397..699cb37 100644
--- a/src/com/android/launcher3/LauncherFiles.java
+++ b/src/com/android/launcher3/LauncherFiles.java
@@ -18,11 +18,10 @@
public static final String DEFAULT_WALLPAPER_THUMBNAIL_OLD = "default_thumb.jpg";
public static final String LAUNCHER_DB = "launcher.db";
public static final String LAUNCHER_PREFERENCES = "launcher.preferences";
- public static final String LAUNCHES_LOG = "launches.log";
public static final String SHARED_PREFERENCES_KEY = "com.android.launcher3.prefs";
- public static final String STATS_LOG = "stats.log";
public static final String WALLPAPER_CROP_PREFERENCES_KEY =
- WallpaperCropActivity.class.getName();
+ "com.android.launcher3.WallpaperCropActivity";
+
public static final String WALLPAPER_IMAGES_DB = "saved_wallpaper_images.db";
public static final String WIDGET_PREVIEWS_DB = "widgetpreviews.db";
public static final String APP_ICONS_DB = "app_icons.db";
@@ -32,11 +31,14 @@
DEFAULT_WALLPAPER_THUMBNAIL_OLD,
LAUNCHER_DB,
LAUNCHER_PREFERENCES,
- LAUNCHES_LOG,
SHARED_PREFERENCES_KEY + XML,
- STATS_LOG,
WALLPAPER_CROP_PREFERENCES_KEY + XML,
WALLPAPER_IMAGES_DB,
WIDGET_PREVIEWS_DB,
APP_ICONS_DB));
+
+ // TODO: Delete these files on upgrade
+ public static final List<String> OBSOLETE_FILES = Collections.unmodifiableList(Arrays.asList(
+ "launches.log",
+ "stats.log"));
}
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index cb9d12e..1f36331 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -58,6 +58,8 @@
import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
+import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.util.Thunk;
import java.lang.ref.WeakReference;
import java.net.URISyntaxException;
@@ -96,14 +98,14 @@
private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons
private static final long INVALID_SCREEN_ID = -1L;
- private final boolean mAppsCanBeOnRemoveableStorage;
+ @Thunk final boolean mAppsCanBeOnRemoveableStorage;
private final boolean mOldContentProviderExists;
- private final LauncherAppState mApp;
- private final Object mLock = new Object();
- private DeferredHandler mHandler = new DeferredHandler();
- private LoaderTask mLoaderTask;
- private boolean mIsLoaderTaskRunning;
+ @Thunk final LauncherAppState mApp;
+ @Thunk final Object mLock = new Object();
+ @Thunk DeferredHandler mHandler = new DeferredHandler();
+ @Thunk LoaderTask mLoaderTask;
+ @Thunk boolean mIsLoaderTaskRunning;
/**
* Maintain a set of packages per user, for which we added a shortcut on the workspace.
@@ -117,17 +119,17 @@
private static final String MIGRATE_AUTHORITY = "com.android.launcher2.settings";
- private static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader");
+ @Thunk static final HandlerThread sWorkerThread = new HandlerThread("launcher-loader");
static {
sWorkerThread.start();
}
- private static final Handler sWorker = new Handler(sWorkerThread.getLooper());
+ @Thunk static final Handler sWorker = new Handler(sWorkerThread.getLooper());
// We start off with everything not loaded. After that, we assume that
// our monitoring of the package manager provides all updates and we never
// need to do a requery. These are only ever touched from the loader thread.
- private boolean mWorkspaceLoaded;
- private boolean mAllAppsLoaded;
+ @Thunk boolean mWorkspaceLoaded;
+ @Thunk boolean mAllAppsLoaded;
// When we are loading pages synchronously, we can't just post the binding of items on the side
// pages as this delays the rotation process. Instead, we wait for a callback from the first
@@ -135,7 +137,7 @@
// a normal load, we also clear this set of Runnables.
static final ArrayList<Runnable> mDeferredBindRunnables = new ArrayList<Runnable>();
- private WeakReference<Callbacks> mCallbacks;
+ @Thunk WeakReference<Callbacks> mCallbacks;
// < only access in worker thread >
AllAppsList mBgAllAppsList;
@@ -166,8 +168,7 @@
static final ArrayList<Long> sBgWorkspaceScreens = new ArrayList<Long>();
// sBgWidgetProviders is the set of widget providers including custom internal widgets
- public static HashMap<ComponentName, LauncherAppWidgetProviderInfo> sBgWidgetProviders;
- public static boolean sWidgetProvidersDirty;
+ public static HashMap<ComponentKey, LauncherAppWidgetProviderInfo> sBgWidgetProviders;
// sPendingPackages is a set of packages which could be on sdcard and are not available yet
static final HashMap<UserHandleCompat, HashSet<String>> sPendingPackages =
@@ -175,12 +176,12 @@
// </ only access in worker thread >
- private IconCache mIconCache;
+ @Thunk IconCache mIconCache;
protected int mPreviousConfigMcc;
- private final LauncherAppsCompat mLauncherApps;
- private final UserManagerCompat mUserManager;
+ @Thunk final LauncherAppsCompat mLauncherApps;
+ @Thunk final UserManagerCompat mUserManager;
public interface Callbacks {
public boolean setLoadOnResume();
@@ -258,10 +259,10 @@
/** Runs the specified runnable immediately if called from the main thread, otherwise it is
* posted on the main thread handler. */
- private void runOnMainThread(Runnable r) {
+ @Thunk void runOnMainThread(Runnable r) {
runOnMainThread(r, 0);
}
- private void runOnMainThread(Runnable r, int type) {
+ @Thunk void runOnMainThread(Runnable r, int type) {
if (sWorkerThread.getThreadId() == Process.myTid()) {
// If we are on the worker thread, post onto the main handler
mHandler.post(r);
@@ -372,7 +373,7 @@
* Find a position on the screen for the given size or adds a new screen.
* @return screenId and the coordinates for the item.
*/
- private static Pair<Long, int[]> findSpaceForItem(
+ @Thunk static Pair<Long, int[]> findSpaceForItem(
Context context,
ScreenPosProvider preferredScreen,
int fallbackStartScreen,
@@ -565,7 +566,7 @@
// Add the shortcut to the db
addItemToDatabase(context, shortcutInfo,
LauncherSettings.Favorites.CONTAINER_DESKTOP,
- screenId, cordinates[0], cordinates[1], false);
+ screenId, cordinates[0], cordinates[1]);
// Save the ShortcutInfo for binding in the workspace
addedShortcutsFinal.add(shortcutInfo);
}
@@ -651,7 +652,7 @@
long screenId, int cellX, int cellY) {
if (item.container == ItemInfo.NO_ID) {
// From all apps
- addItemToDatabase(context, item, container, screenId, cellX, cellY, false);
+ addItemToDatabase(context, item, container, screenId, cellX, cellY);
} else {
// From somewhere else
moveItemInDatabase(context, item, container, screenId, cellX, cellY);
@@ -717,7 +718,7 @@
static void updateItemInDatabaseHelper(Context context, final ContentValues values,
final ItemInfo item, final String callingFunction) {
final long itemId = item.id;
- final Uri uri = LauncherSettings.Favorites.getContentUri(itemId, false);
+ final Uri uri = LauncherSettings.Favorites.getContentUri(itemId);
final ContentResolver cr = context.getContentResolver();
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
@@ -743,7 +744,7 @@
for (int i = 0; i < count; i++) {
ItemInfo item = items.get(i);
final long itemId = item.id;
- final Uri uri = LauncherSettings.Favorites.getContentUri(itemId, false);
+ final Uri uri = LauncherSettings.Favorites.getContentUri(itemId);
ContentValues values = valuesList.get(i);
ops.add(ContentProviderOperation.newUpdate(uri).withValues(values).build());
@@ -962,6 +963,7 @@
final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
+ final int optionsIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.OPTIONS);
FolderInfo folderInfo = null;
switch (c.getInt(itemTypeIndex)) {
@@ -976,6 +978,7 @@
folderInfo.screenId = c.getInt(screenIndex);
folderInfo.cellX = c.getInt(cellXIndex);
folderInfo.cellY = c.getInt(cellYIndex);
+ folderInfo.options = c.getInt(optionsIndex);
return folderInfo;
}
@@ -991,7 +994,7 @@
* cellY fields of the item. Also assigns an ID to the item.
*/
static void addItemToDatabase(Context context, final ItemInfo item, final long container,
- final long screenId, final int cellX, final int cellY, final boolean notify) {
+ final long screenId, final int cellX, final int cellY) {
item.container = container;
item.cellX = cellX;
item.cellY = cellY;
@@ -1014,8 +1017,7 @@
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
Runnable r = new Runnable() {
public void run() {
- cr.insert(notify ? LauncherSettings.Favorites.CONTENT_URI :
- LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values);
+ cr.insert(LauncherSettings.Favorites.CONTENT_URI, values);
// Lock on mBgLock *after* the db operation
synchronized (sBgLock) {
@@ -1099,7 +1101,7 @@
Runnable r = new Runnable() {
public void run() {
for (ItemInfo item : items) {
- final Uri uri = LauncherSettings.Favorites.getContentUri(item.id, false);
+ final Uri uri = LauncherSettings.Favorites.getContentUri(item.id);
cr.delete(uri, null, null);
// Lock on mBgLock *after* the db operation
@@ -1194,7 +1196,7 @@
Runnable r = new Runnable() {
public void run() {
- cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null);
+ cr.delete(LauncherSettings.Favorites.getContentUri(info.id), null, null);
// Lock on mBgLock *after* the db operation
synchronized (sBgLock) {
sBgItemsIdMap.remove(info.id);
@@ -1202,7 +1204,7 @@
sBgWorkspaceItems.remove(info);
}
- cr.delete(LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
+ cr.delete(LauncherSettings.Favorites.CONTENT_URI,
LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
// Lock on mBgLock *after* the db operation
synchronized (sBgLock) {
@@ -1423,7 +1425,7 @@
/**
* Loads the workspace screen ids in an ordered list.
*/
- private static ArrayList<Long> loadWorkspaceScreensDb(Context context) {
+ @Thunk static ArrayList<Long> loadWorkspaceScreensDb(Context context) {
final ContentResolver contentResolver = context.getContentResolver();
final Uri screensUri = LauncherSettings.WorkspaceScreens.CONTENT_URI;
@@ -1469,9 +1471,9 @@
private class LoaderTask implements Runnable {
private Context mContext;
private boolean mIsLaunching;
- private boolean mIsLoadingAndBindingWorkspace;
+ @Thunk boolean mIsLoadingAndBindingWorkspace;
private boolean mStopped;
- private boolean mLoadAndBindStepFinished;
+ @Thunk boolean mLoadAndBindStepFinished;
private int mFlags;
LoaderTask(Context context, boolean isLaunching, int flags) {
@@ -1619,6 +1621,9 @@
if (DEBUG_LOADERS) Log.d(TAG, "step 2: loading all apps");
loadAndBindAllApps();
+ // Remove entries for packages which changed while the launcher was dead.
+ LauncherAppState.getInstance().getWidgetCache().removeObsoletePreviews();
+
// Restore the default thread priority after we are done loading items
synchronized (mLock) {
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
@@ -1817,7 +1822,7 @@
final ArrayList<Long> itemsToRemove = new ArrayList<Long>();
final ArrayList<Long> restoredRows = new ArrayList<Long>();
- final Uri contentUri = LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION;
+ final Uri contentUri = LauncherSettings.Favorites.CONTENT_URI;
if (DEBUG_LOADERS) Log.d(TAG, "loading model from " + contentUri);
final Cursor c = contentResolver.query(contentUri, null, null, null, null);
@@ -1863,15 +1868,15 @@
LauncherSettings.Favorites.RESTORED);
final int profileIdIndex = c.getColumnIndexOrThrow(
LauncherSettings.Favorites.PROFILE_ID);
- //final int uriIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.URI);
- //final int displayModeIndex = c.getColumnIndexOrThrow(
- // LauncherSettings.Favorites.DISPLAY_MODE);
+ final int optionsIndex = c.getColumnIndexOrThrow(
+ LauncherSettings.Favorites.OPTIONS);
ShortcutInfo info;
String intentDescription;
LauncherAppWidgetInfo appWidgetInfo;
int container;
long id;
+ long serialNumber;
Intent intent;
UserHandleCompat user;
@@ -1886,7 +1891,7 @@
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
id = c.getLong(idIndex);
intentDescription = c.getString(intentIndex);
- long serialNumber = c.getInt(profileIdIndex);
+ serialNumber = c.getInt(profileIdIndex);
user = mUserManager.getUserForSerialNumber(serialNumber);
int promiseType = c.getInt(restoredIndex);
int disabledState = 0;
@@ -2018,10 +2023,14 @@
continue;
}
+ container = c.getInt(containerIndex);
+ boolean useLowResIcon = container >= 0 &&
+ c.getInt(rankIndex) >= FolderIcon.NUM_ITEMS_IN_PREVIEW;
+
if (itemReplaced) {
if (user.equals(UserHandleCompat.myUserHandle())) {
info = getAppShortcutInfo(manager, intent, user, context, null,
- iconIndex, titleIndex, false);
+ iconIndex, titleIndex, false, useLowResIcon);
} else {
// Don't replace items for other profiles.
itemsToRemove.add(id);
@@ -2032,7 +2041,8 @@
Launcher.addDumpLog(TAG,
"constructing info for partially restored package",
true);
- info = getRestoredItemInfo(c, titleIndex, intent, promiseType);
+ info = getRestoredItemInfo(c, titleIndex, intent,
+ promiseType, useLowResIcon);
intent = getRestoredItemIntent(c, context, intent);
} else {
// Don't restore items for other profiles.
@@ -2042,7 +2052,7 @@
} else if (itemType ==
LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
info = getAppShortcutInfo(manager, intent, user, context, c,
- iconIndex, titleIndex, allowMissingTarget);
+ iconIndex, titleIndex, allowMissingTarget, useLowResIcon);
} else {
info = getShortcutInfo(c, context, iconTypeIndex,
iconPackageIndex, iconResourceIndex, iconIndex,
@@ -2064,7 +2074,6 @@
if (info != null) {
info.id = id;
info.intent = intent;
- container = c.getInt(containerIndex);
info.container = container;
info.screenId = c.getInt(screenIndex);
info.cellX = c.getInt(cellXIndex);
@@ -2115,6 +2124,7 @@
folderInfo.cellY = c.getInt(cellYIndex);
folderInfo.spanX = 1;
folderInfo.spanY = 1;
+ folderInfo.options = c.getInt(optionsIndex);
// check & update map of what's occupied
if (!checkItemPlacement(occupied, folderInfo)) {
@@ -2145,6 +2155,7 @@
LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
int appWidgetId = c.getInt(appWidgetIdIndex);
+ serialNumber= c.getLong(profileIdIndex);
String savedProvider = c.getString(appWidgetProviderIndex);
id = c.getLong(idIndex);
final ComponentName component =
@@ -2159,7 +2170,8 @@
final LauncherAppWidgetProviderInfo provider =
LauncherModel.getProviderInfo(context,
- ComponentName.unflattenFromString(savedProvider));
+ ComponentName.unflattenFromString(savedProvider),
+ mUserManager.getUserForSerialNumber(serialNumber));
final boolean isProviderReady = isValidProvider(provider);
if (!isSafeMode && !customWidget &&
@@ -2291,8 +2303,7 @@
}
// Don't notify content observers
try {
- client.delete(LauncherSettings.Favorites.getContentUri(id, false),
- null, null);
+ client.delete(LauncherSettings.Favorites.getContentUri(id), null, null);
} catch (RemoteException e) {
Log.w(TAG, "Could not remove id = " + id);
}
@@ -2311,7 +2322,7 @@
selectionBuilder.append(")");
ContentValues values = new ContentValues();
values.put(LauncherSettings.Favorites.RESTORED, 0);
- updater.update(LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
+ updater.update(LauncherSettings.Favorites.CONTENT_URI,
values, selectionBuilder.toString(), null);
} catch (RemoteException e) {
Log.w(TAG, "Could not update restored rows");
@@ -2382,7 +2393,7 @@
*/
private void updateItem(long itemId, ContentValues update) {
mContext.getContentResolver().update(
- LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
+ LauncherSettings.Favorites.CONTENT_URI,
update,
BaseColumns._ID + "= ?",
new String[]{Long.toString(itemId)});
@@ -2895,7 +2906,7 @@
sWorker.post(task);
}
- private class AppsAvailabilityCheck extends BroadcastReceiver {
+ @Thunk class AppsAvailabilityCheck extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
@@ -2997,8 +3008,7 @@
if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
mIconCache.updateIconsForPkg(packages[i], mUser);
mBgAllAppsList.updatePackage(context, packages[i], mUser);
- WidgetPreviewLoader.removePackageFromDb(
- mApp.getWidgetPreviewCacheDb(), packages[i]);
+ mApp.getWidgetCache().removePackage(packages[i], mUser);
}
break;
case OP_REMOVE:
@@ -3024,8 +3034,7 @@
for (int i=0; i<N; i++) {
if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
mBgAllAppsList.removePackage(packages[i], mUser);
- WidgetPreviewLoader.removePackageFromDb(
- mApp.getWidgetPreviewCacheDb(), packages[i]);
+ mApp.getWidgetCache().removePackage(packages[i], mUser);
}
break;
}
@@ -3252,7 +3261,7 @@
}
final ArrayList<Object> widgetsAndShortcuts =
- getSortedWidgetsAndShortcuts(context);
+ getSortedWidgetsAndShortcuts(context, true /* refresh */);
mHandler.post(new Runnable() {
@Override
public void run() {
@@ -3275,51 +3284,54 @@
}
}
- public static List<LauncherAppWidgetProviderInfo> getWidgetProviders(Context context) {
+ public static List<LauncherAppWidgetProviderInfo> getWidgetProviders(Context context,
+ boolean refresh) {
synchronized (sBgLock) {
- if (sBgWidgetProviders != null && !sWidgetProvidersDirty) {
- return new ArrayList<LauncherAppWidgetProviderInfo>(sBgWidgetProviders.values());
- }
- sBgWidgetProviders = new HashMap<ComponentName, LauncherAppWidgetProviderInfo>();
- List<AppWidgetProviderInfo> widgets =
- AppWidgetManagerCompat.getInstance(context).getAllProviders();
- LauncherAppWidgetProviderInfo info;
- for (AppWidgetProviderInfo pInfo : widgets) {
- info = LauncherAppWidgetProviderInfo.fromProviderInfo(context, pInfo);
- sBgWidgetProviders.put(info.provider, info);
- }
+ if (sBgWidgetProviders == null || refresh) {
+ sBgWidgetProviders = new HashMap<>();
+ AppWidgetManagerCompat wm = AppWidgetManagerCompat.getInstance(context);
+ LauncherAppWidgetProviderInfo info;
- Collection<CustomAppWidget> customWidgets = Launcher.getCustomAppWidgets().values();
- for (CustomAppWidget widget : customWidgets) {
- info = new LauncherAppWidgetProviderInfo(context, widget);
- sBgWidgetProviders.put(info.provider, info);
+ List<AppWidgetProviderInfo> widgets = wm.getAllProviders();
+ for (AppWidgetProviderInfo pInfo : widgets) {
+ info = LauncherAppWidgetProviderInfo.fromProviderInfo(context, pInfo);
+ UserHandleCompat user = wm.getUser(info);
+ sBgWidgetProviders.put(new ComponentKey(info.provider, user), info);
+ }
+
+ Collection<CustomAppWidget> customWidgets = Launcher.getCustomAppWidgets().values();
+ for (CustomAppWidget widget : customWidgets) {
+ info = new LauncherAppWidgetProviderInfo(context, widget);
+ UserHandleCompat user = wm.getUser(info);
+ sBgWidgetProviders.put(new ComponentKey(info.provider, user), info);
+ }
}
- sWidgetProvidersDirty = false;
return new ArrayList<LauncherAppWidgetProviderInfo>(sBgWidgetProviders.values());
}
}
- public static LauncherAppWidgetProviderInfo getProviderInfo(Context ctx, ComponentName name) {
+ public static LauncherAppWidgetProviderInfo getProviderInfo(Context ctx, ComponentName name,
+ UserHandleCompat user) {
synchronized (sBgLock) {
if (sBgWidgetProviders == null) {
- getWidgetProviders(ctx);
+ getWidgetProviders(ctx, false /* refresh */);
}
- return sBgWidgetProviders.get(name);
+ return sBgWidgetProviders.get(new ComponentKey(name, user));
}
}
- // Returns a list of ResolveInfos/AppWindowInfos in sorted order
- public static ArrayList<Object> getSortedWidgetsAndShortcuts(Context context) {
+ // Returns a list of ResolveInfos/AppWidgetInfos in sorted order
+ public static ArrayList<Object> getSortedWidgetsAndShortcuts(Context context, boolean refresh) {
PackageManager packageManager = context.getPackageManager();
final ArrayList<Object> widgetsAndShortcuts = new ArrayList<Object>();
- widgetsAndShortcuts.addAll(getWidgetProviders(context));
+ widgetsAndShortcuts.addAll(getWidgetProviders(context, refresh));
Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
widgetsAndShortcuts.addAll(packageManager.queryIntentActivities(shortcutsIntent, 0));
Collections.sort(widgetsAndShortcuts, new WidgetAndShortcutNameComparator(context));
return widgetsAndShortcuts;
}
- private static boolean isPackageDisabled(Context context, String packageName,
+ @Thunk static boolean isPackageDisabled(Context context, String packageName,
UserHandleCompat user) {
final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
return !launcherApps.isPackageEnabledForProfile(packageName, user);
@@ -3351,10 +3363,10 @@
* to a package that is not yet installed on the system.
*/
public ShortcutInfo getRestoredItemInfo(Cursor cursor, int titleIndex, Intent intent,
- int promiseType) {
+ int promiseType, boolean useLowResIcon) {
final ShortcutInfo info = new ShortcutInfo();
info.user = UserHandleCompat.myUserHandle();
- mIconCache.getTitleAndIcon(info, intent, info.user);
+ mIconCache.getTitleAndIcon(info, intent, info.user, useLowResIcon);
if ((promiseType & ShortcutInfo.FLAG_RESTORED_ICON) != 0) {
String title = (cursor != null) ? cursor.getString(titleIndex) : null;
@@ -3382,7 +3394,7 @@
* Make an Intent object for a restored application or shortcut item that points
* to the market page for the item.
*/
- private Intent getRestoredItemIntent(Cursor c, Context context, Intent intent) {
+ @Thunk Intent getRestoredItemIntent(Cursor c, Context context, Intent intent) {
ComponentName componentName = intent.getComponent();
return getMarketIntent(componentName.getPackageName());
}
@@ -3403,7 +3415,7 @@
*/
public ShortcutInfo getAppShortcutInfo(PackageManager manager, Intent intent,
UserHandleCompat user, Context context, Cursor c, int iconIndex, int titleIndex,
- boolean allowMissingTarget) {
+ boolean allowMissingTarget, boolean useLowResIcon) {
if (user == null) {
Log.d(TAG, "Null user found in getShortcutInfo");
return null;
@@ -3425,7 +3437,7 @@
}
final ShortcutInfo info = new ShortcutInfo();
- mIconCache.getTitleAndIcon(info, componentName, lai, user, false);
+ mIconCache.getTitleAndIcon(info, componentName, lai, user, false, useLowResIcon);
if (mIconCache.isDefaultIcon(info.getIcon(mIconCache), user) && c != null) {
Bitmap icon = Utilities.createIconBitmap(c, iconIndex, context);
info.setIcon(icon == null ? mIconCache.getDefaultIcon(user) : icon);
@@ -3477,7 +3489,7 @@
return new ArrayList<ItemInfo>(filtered);
}
- private ArrayList<ItemInfo> getItemInfoForComponentName(final ComponentName cname,
+ @Thunk ArrayList<ItemInfo> getItemInfoForComponentName(final ComponentName cname,
final UserHandleCompat user) {
ItemInfoFilter filter = new ItemInfoFilter() {
@Override
@@ -3495,7 +3507,7 @@
/**
* Make an ShortcutInfo object for a shortcut that isn't an application.
*/
- private ShortcutInfo getShortcutInfo(Cursor c, Context context,
+ @Thunk ShortcutInfo getShortcutInfo(Cursor c, Context context,
int iconTypeIndex, int iconPackageIndex, int iconResourceIndex, int iconIndex,
int titleIndex) {
@@ -3599,7 +3611,7 @@
* Return an existing FolderInfo object if we have encountered this ID previously,
* or make a new one.
*/
- private static FolderInfo findOrMakeFolder(HashMap<Long, FolderInfo> folders, long id) {
+ @Thunk static FolderInfo findOrMakeFolder(HashMap<Long, FolderInfo> folders, long id) {
// See if a placeholder was created for us already
FolderInfo folderInfo = folders.get(id);
if (folderInfo == null) {
@@ -3610,41 +3622,6 @@
return folderInfo;
}
- public static final Comparator<AppInfo> getAppNameComparator() {
- final Collator collator = Collator.getInstance();
- return new Comparator<AppInfo>() {
- public final int compare(AppInfo a, AppInfo b) {
- if (a.user.equals(b.user)) {
- int result = collator.compare(a.title.toString().trim(),
- b.title.toString().trim());
- if (result == 0) {
- result = a.componentName.compareTo(b.componentName);
- }
- return result;
- } else {
- // TODO Need to figure out rules for sorting
- // profiles, this puts work second.
- return a.user.toString().compareTo(b.user.toString());
- }
- }
- };
- }
- public static final Comparator<AppInfo> APP_INSTALL_TIME_COMPARATOR
- = new Comparator<AppInfo>() {
- public final int compare(AppInfo a, AppInfo b) {
- if (a.firstInstallTime < b.firstInstallTime) return 1;
- if (a.firstInstallTime > b.firstInstallTime) return -1;
- return 0;
- }
- };
- static ComponentName getComponentNameFromResolveInfo(ResolveInfo info) {
- if (info.activityInfo != null) {
- return new ComponentName(info.activityInfo.packageName, info.activityInfo.name);
- } else {
- return new ComponentName(info.serviceInfo.packageName, info.serviceInfo.name);
- }
- }
-
public static class WidgetAndShortcutNameComparator implements Comparator<Object> {
private final AppWidgetManagerCompat mManager;
private final PackageManager mPackageManager;
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index 747d7ef..1f59533 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -16,6 +16,7 @@
package com.android.launcher3;
+import android.annotation.TargetApi;
import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
@@ -29,6 +30,7 @@
import android.content.Intent;
import android.content.OperationApplicationException;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.SQLException;
@@ -36,7 +38,10 @@
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
+import android.os.Build;
+import android.os.Bundle;
import android.os.StrictMode;
+import android.os.UserManager;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
@@ -46,6 +51,7 @@
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.ProviderConfig;
+import com.android.launcher3.util.Thunk;
import java.io.File;
import java.net.URISyntaxException;
@@ -57,18 +63,19 @@
private static final String TAG = "Launcher.LauncherProvider";
private static final boolean LOGD = false;
- private static final int DATABASE_VERSION = 22;
+ private static final int DATABASE_VERSION = 23;
static final String OLD_AUTHORITY = "com.android.launcher2.settings";
static final String AUTHORITY = ProviderConfig.AUTHORITY;
static final String TABLE_FAVORITES = "favorites";
static final String TABLE_WORKSPACE_SCREENS = "workspaceScreens";
- static final String PARAMETER_NOTIFY = "notify";
static final String EMPTY_DATABASE_CREATED = "EMPTY_DATABASE_CREATED";
private static final String URI_PARAM_IS_EXTERNAL_ADD = "isExternalAdd";
+ private static final String RESTRICTION_PACKAGE_NAME = "workspace.configuration.package.name";
+
private LauncherProviderChangeListener mListener;
/**
@@ -124,7 +131,7 @@
return result;
}
- private static long dbInsertAndCheck(DatabaseHelper helper,
+ @Thunk static long dbInsertAndCheck(DatabaseHelper helper,
SQLiteDatabase db, String table, String nullColumnHack, ContentValues values) {
if (values == null) {
throw new RuntimeException("Error: attempting to insert null values");
@@ -142,7 +149,8 @@
// In very limited cases, we support system|signature permission apps to add to the db
String externalAdd = uri.getQueryParameter(URI_PARAM_IS_EXTERNAL_ADD);
- if (externalAdd != null && "true".equals(externalAdd)) {
+ final boolean isExternalAll = externalAdd != null && "true".equals(externalAdd);
+ if (isExternalAll) {
if (!mOpenHelper.initializeExternalAdd(initialValues)) {
return null;
}
@@ -154,7 +162,14 @@
if (rowId < 0) return null;
uri = ContentUris.withAppendedId(uri, rowId);
- sendNotify(uri);
+ notifyListeners();
+
+ if (isExternalAll) {
+ LauncherAppState app = LauncherAppState.getInstanceNoCreate();
+ if (app != null) {
+ app.reloadWorkspace();
+ }
+ }
return uri;
}
@@ -179,7 +194,7 @@
db.endTransaction();
}
- sendNotify(uri);
+ notifyListeners();
return values.length;
}
@@ -203,7 +218,7 @@
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
int count = db.delete(args.table, args.where, args.args);
- if (count > 0) sendNotify(uri);
+ if (count > 0) notifyListeners();
return count;
}
@@ -215,17 +230,12 @@
addModifiedTime(values);
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
int count = db.update(args.table, values, args.where, args.args);
- if (count > 0) sendNotify(uri);
+ if (count > 0) notifyListeners();
return count;
}
- private void sendNotify(Uri uri) {
- String notify = uri.getQueryParameter(PARAMETER_NOTIFY);
- if (notify == null || "true".equals(notify)) {
- getContext().getContentResolver().notifyChange(uri, null);
- }
-
+ private void notifyListeners() {
// always notify the backup agent
LauncherBackupAgentHelper.dataChanged(getContext());
if (mListener != null) {
@@ -233,7 +243,7 @@
}
}
- private static void addModifiedTime(ContentValues values) {
+ @Thunk static void addModifiedTime(ContentValues values) {
values.put(LauncherSettings.ChangeLogColumns.MODIFIED, System.currentTimeMillis());
}
@@ -266,9 +276,10 @@
/**
* Loads the default workspace based on the following priority scheme:
- * 1) From a package provided by play store
- * 2) From a partner configuration APK, already in the system image
- * 3) The default configuration for the particular device
+ * 1) From the app restrictions
+ * 2) From a package provided by play store
+ * 3) From a partner configuration APK, already in the system image
+ * 4) The default configuration for the particular device
*/
synchronized public void loadDefaultFavoritesIfNecessary() {
String spKey = LauncherAppState.getSharedPreferencesKey();
@@ -277,9 +288,11 @@
if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) {
Log.d(TAG, "loading default workspace");
- AutoInstallsLayout loader = AutoInstallsLayout.get(getContext(),
- mOpenHelper.mAppWidgetHost, mOpenHelper);
-
+ AutoInstallsLayout loader = createWorkspaceLoaderFromAppRestriction();
+ if (loader == null) {
+ loader = AutoInstallsLayout.get(getContext(),
+ mOpenHelper.mAppWidgetHost, mOpenHelper);
+ }
if (loader == null) {
final Partner partner = Partner.get(getContext().getPackageManager());
if (partner != null && partner.hasDefaultLayout()) {
@@ -313,6 +326,40 @@
}
}
+ /**
+ * Creates workspace loader from an XML resource listed in the app restrictions.
+ *
+ * @return the loader if the restrictions are set and the resource exists; null otherwise.
+ */
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
+ private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction() {
+ // UserManager.getApplicationRestrictions() requires minSdkVersion >= 18
+ if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ return null;
+ }
+
+ Context ctx = getContext();
+ UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE);
+ Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName());
+ if (bundle == null) {
+ return null;
+ }
+
+ String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME);
+ if (packageName != null) {
+ try {
+ Resources targetResources = ctx.getPackageManager()
+ .getResourcesForApplication(packageName);
+ return AutoInstallsLayout.get(ctx, packageName, targetResources,
+ mOpenHelper.mAppWidgetHost, mOpenHelper);
+ } catch (NameNotFoundException e) {
+ Log.e(TAG, "Target package for restricted profile not found", e);
+ return null;
+ }
+ }
+ return null;
+ }
+
private DefaultLayoutParser getDefaultLayoutParser() {
int defaultLayout = LauncherAppState.getInstance()
.getDynamicGrid().getDeviceProfile().defaultLayoutId;
@@ -342,7 +389,7 @@
private static class DatabaseHelper extends SQLiteOpenHelper implements LayoutParserCallback {
private final Context mContext;
- private final AppWidgetHost mAppWidgetHost;
+ @Thunk final AppWidgetHost mAppWidgetHost;
private long mMaxItemId = -1;
private long mMaxScreenId = -1;
@@ -413,7 +460,8 @@
"modified INTEGER NOT NULL DEFAULT 0," +
"restored INTEGER NOT NULL DEFAULT 0," +
"profileId INTEGER DEFAULT " + userSerialNumber + "," +
- "rank INTEGER NOT NULL DEFAULT 0" +
+ "rank INTEGER NOT NULL DEFAULT 0," +
+ "options INTEGER NOT NULL DEFAULT 0" +
");");
addWorkspacesTable(db);
@@ -524,18 +572,9 @@
}
}
case 15: {
- db.beginTransaction();
- try {
- // Insert new column for holding restore status
- db.execSQL("ALTER TABLE favorites " +
- "ADD COLUMN restored INTEGER NOT NULL DEFAULT 0;");
- db.setTransactionSuccessful();
- } catch (SQLException ex) {
- Log.e(TAG, ex.getMessage(), ex);
+ if (!addIntegerColumn(db, Favorites.RESTORED, 0)) {
// Old version remains, which means we wipe old data
break;
- } finally {
- db.endTransaction();
}
}
case 16: {
@@ -573,6 +612,12 @@
break;
}
case 22: {
+ if (!addIntegerColumn(db, Favorites.OPTIONS, 0)) {
+ // Old version remains, which means we wipe old data
+ break;
+ }
+ }
+ case 23: {
// DB Upgraded successfully
return;
}
@@ -649,7 +694,7 @@
return true;
}
- private boolean updateFolderItemsRank(SQLiteDatabase db, boolean addRankColumn) {
+ @Thunk boolean updateFolderItemsRank(SQLiteDatabase db, boolean addRankColumn) {
db.beginTransaction();
try {
if (addRankColumn) {
@@ -682,20 +727,21 @@
}
private boolean addProfileColumn(SQLiteDatabase db) {
+ UserManagerCompat userManager = UserManagerCompat.getInstance(mContext);
+ // Default to the serial number of this user, for older
+ // shortcuts.
+ long userSerialNumber = userManager.getSerialNumberForUser(
+ UserHandleCompat.myUserHandle());
+ return addIntegerColumn(db, Favorites.PROFILE_ID, userSerialNumber);
+ }
+
+ private boolean addIntegerColumn(SQLiteDatabase db, String columnName, long defaultValue) {
db.beginTransaction();
try {
- UserManagerCompat userManager = UserManagerCompat.getInstance(mContext);
- // Default to the serial number of this user, for older
- // shortcuts.
- long userSerialNumber = userManager.getSerialNumberForUser(
- UserHandleCompat.myUserHandle());
- // Insert new column for holding user serial number
- db.execSQL("ALTER TABLE favorites " +
- "ADD COLUMN profileId INTEGER DEFAULT "
- + userSerialNumber + ";");
+ db.execSQL("ALTER TABLE favorites ADD COLUMN "
+ + columnName + " INTEGER NOT NULL DEFAULT " + defaultValue + ";");
db.setTransactionSuccessful();
} catch (SQLException ex) {
- // Old version remains, which means we wipe old data
Log.e(TAG, ex.getMessage(), ex);
return false;
} finally {
@@ -737,23 +783,7 @@
}
private long initializeMaxItemId(SQLiteDatabase db) {
- Cursor c = db.rawQuery("SELECT MAX(_id) FROM favorites", null);
-
- // get the result
- final int maxIdIndex = 0;
- long id = -1;
- if (c != null && c.moveToNext()) {
- id = c.getLong(maxIdIndex);
- }
- if (c != null) {
- c.close();
- }
-
- if (id == -1) {
- throw new RuntimeException("Error: could not query max item id");
- }
-
- return id;
+ return getMaxId(db, TABLE_FAVORITES);
}
// Generates a new ID to use for an workspace screen in your database. This method
@@ -772,28 +802,10 @@
}
private long initializeMaxScreenId(SQLiteDatabase db) {
- Cursor c = db.rawQuery("SELECT MAX(" + LauncherSettings.WorkspaceScreens._ID + ") FROM " + TABLE_WORKSPACE_SCREENS, null);
-
- // get the result
- final int maxIdIndex = 0;
- long id = -1;
- if (c != null && c.moveToNext()) {
- id = c.getLong(maxIdIndex);
- }
- if (c != null) {
- c.close();
- }
-
- if (id == -1) {
- throw new RuntimeException("Error: could not query max screen id");
- }
-
- // Log to disk
- Launcher.addDumpLog(TAG, "11683562 - initializeMaxScreenId(): " + id, true);
- return id;
+ return getMaxId(db, TABLE_WORKSPACE_SCREENS);
}
- private boolean initializeExternalAdd(ContentValues values) {
+ @Thunk boolean initializeExternalAdd(ContentValues values) {
// 1. Ensure that externally added items have a valid item id
long id = generateNewItemId();
values.put(LauncherSettings.Favorites._ID, id);
@@ -880,7 +892,7 @@
return rank;
}
- private int loadFavorites(SQLiteDatabase db, AutoInstallsLayout loader) {
+ @Thunk int loadFavorites(SQLiteDatabase db, AutoInstallsLayout loader) {
ArrayList<Long> screenIds = new ArrayList<Long>();
// TODO: Use multiple loaders with fall-back and transaction.
int count = loader.loadLayout(db, screenIds);
@@ -907,7 +919,7 @@
return count;
}
- private void migrateLauncher2Shortcuts(SQLiteDatabase db, Uri uri) {
+ @Thunk void migrateLauncher2Shortcuts(SQLiteDatabase db, Uri uri) {
final ContentResolver resolver = mContext.getContentResolver();
Cursor c = null;
int count = 0;
@@ -1203,6 +1215,27 @@
}
}
+ /**
+ * @return the max _id in the provided table.
+ */
+ @Thunk static long getMaxId(SQLiteDatabase db, String table) {
+ Cursor c = db.rawQuery("SELECT MAX(_id) FROM " + table, null);
+ // get the result
+ long id = -1;
+ if (c != null && c.moveToNext()) {
+ id = c.getLong(0);
+ }
+ if (c != null) {
+ c.close();
+ }
+
+ if (id == -1) {
+ throw new RuntimeException("Error: could not query max id in " + table);
+ }
+
+ return id;
+ }
+
static class SqlArguments {
public final String table;
public final String where;
diff --git a/src/com/android/launcher3/LauncherSettings.java b/src/com/android/launcher3/LauncherSettings.java
index 13fd7ee..d657cb5 100644
--- a/src/com/android/launcher3/LauncherSettings.java
+++ b/src/com/android/launcher3/LauncherSettings.java
@@ -109,8 +109,7 @@
* The content:// style URL for this table
*/
static final Uri CONTENT_URI = Uri.parse("content://" +
- LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_WORKSPACE_SCREENS +
- "?" + LauncherProvider.PARAMETER_NOTIFY + "=true");
+ LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_WORKSPACE_SCREENS);
/**
* The rank of this screen -- ie. how it is ordered relative to the other screens.
@@ -127,36 +126,18 @@
* The content:// style URL for this table
*/
static final Uri CONTENT_URI = Uri.parse("content://" +
- LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_FAVORITES +
- "?" + LauncherProvider.PARAMETER_NOTIFY + "=true");
-
- /**
- * The content:// style URL for this table
- */
- static final Uri OLD_CONTENT_URI = Uri.parse("content://" +
- LauncherProvider.OLD_AUTHORITY + "/" + LauncherProvider.TABLE_FAVORITES +
- "?" + LauncherProvider.PARAMETER_NOTIFY + "=true");
-
- /**
- * The content:// style URL for this table. When this Uri is used, no notification is
- * sent if the content changes.
- */
- static final Uri CONTENT_URI_NO_NOTIFICATION = Uri.parse("content://" +
- LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_FAVORITES +
- "?" + LauncherProvider.PARAMETER_NOTIFY + "=false");
+ LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_FAVORITES);
/**
* The content:// style URL for a given row, identified by its id.
*
* @param id The row id.
- * @param notify True to send a notification is the content changes.
*
* @return The unique content URL for the specified row.
*/
- static Uri getContentUri(long id, boolean notify) {
+ static Uri getContentUri(long id) {
return Uri.parse("content://" + LauncherProvider.AUTHORITY +
- "/" + LauncherProvider.TABLE_FAVORITES + "/" + id + "?" +
- LauncherProvider.PARAMETER_NOTIFY + "=" + notify);
+ "/" + LauncherProvider.TABLE_FAVORITES + "/" + id);
}
/**
@@ -309,5 +290,11 @@
* <p>Type: INTEGER</p>
*/
static final String RANK = "rank";
+
+ /**
+ * Stores general flag based options for {@link ItemInfo}s.
+ * <p>Type: INTEGER</p>
+ */
+ static final String OPTIONS = "options";
}
}
diff --git a/src/com/android/launcher3/LauncherStateTransitionAnimation.java b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
new file mode 100644
index 0000000..eacf341
--- /dev/null
+++ b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
@@ -0,0 +1,836 @@
+/*
+ * Copyright (C) 2015 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.launcher3;
+
+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.content.res.Resources;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewAnimationUtils;
+import android.view.animation.AccelerateInterpolator;
+import android.view.animation.DecelerateInterpolator;
+
+import com.android.launcher3.util.Thunk;
+
+import java.util.HashMap;
+
+/**
+ * TODO: figure out what kind of tests we can write for this
+ *
+ * Things to test when changing the following class.
+ * - Home from workspace
+ * - from center screen
+ * - from other screens
+ * - Home from all apps
+ * - from center screen
+ * - from other screens
+ * - Back from all apps
+ * - from center screen
+ * - from other screens
+ * - Launch app from workspace and quit
+ * - with back
+ * - with home
+ * - Launch app from all apps and quit
+ * - with back
+ * - with home
+ * - Go to a screen that's not the default, then all
+ * apps, and launch and app, and go back
+ * - with back
+ * -with home
+ * - On workspace, long press power and go back
+ * - with back
+ * - with home
+ * - On all apps, long press power and go back
+ * - with back
+ * - with home
+ * - On workspace, power off
+ * - On all apps, power off
+ * - Launch an app and turn off the screen while in that app
+ * - Go back with home key
+ * - Go back with back key TODO: make this not go to workspace
+ * - From all apps
+ * - From workspace
+ * - Enter and exit car mode (becuase it causes an extra configuration changed)
+ * - From all apps
+ * - From the center workspace
+ * - From another workspace
+ */
+public class LauncherStateTransitionAnimation {
+
+ /**
+ * Callbacks made during the state transition
+ */
+ interface Callbacks {
+ public void onStateTransitionHideSearchBar();
+ }
+
+ /**
+ * Private callbacks made during transition setup.
+ */
+ static abstract class PrivateTransitionCallbacks {
+ void onRevealViewVisible(View revealView, View contentView, View allAppsButtonView) {}
+ void onAnimationComplete(View revealView, View contentView, View allAppsButtonView) {}
+ float getMaterialRevealViewFinalAlpha(View revealView) {
+ return 0;
+ }
+ float getMaterialRevealViewFinalXDrift(View revealView) {
+ return 0;
+ }
+ float getMaterialRevealViewFinalYDrift(View revealView) {
+ return 0;
+ }
+ float getMaterialRevealViewStartFinalRadius() {
+ return 0;
+ }
+ AnimatorListenerAdapter getMaterialRevealViewAnimatorListener(View revealView,
+ View allAppsButtonView) {
+ return null;
+ }
+ }
+
+ public static final String TAG = "LauncherStateTransitionAnimation";
+
+ // Flags to determine how to set the layers on views before the transition animation
+ public static final int BUILD_LAYER = 0;
+ public static final int BUILD_AND_SET_LAYER = 1;
+ public static final int SINGLE_FRAME_DELAY = 16;
+
+ @Thunk Launcher mLauncher;
+ @Thunk Callbacks mCb;
+ @Thunk AnimatorSet mStateAnimation;
+
+ public LauncherStateTransitionAnimation(Launcher l, Callbacks cb) {
+ mLauncher = l;
+ mCb = cb;
+ }
+
+ /**
+ * Starts an animation to the apps view.
+ */
+ public void startAnimationToAllApps(final boolean animated) {
+ final AppsContainerView toView = mLauncher.getAppsView();
+ PrivateTransitionCallbacks cb = new PrivateTransitionCallbacks() {
+ private int[] mAllAppsToPanelDelta;
+
+ @Override
+ public void onRevealViewVisible(View revealView, View contentView,
+ View allAppsButtonView) {
+ toView.setBackground(null);
+ // Get the y delta between the center of the page and the center of the all apps
+ // button
+ mAllAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
+ allAppsButtonView, null);
+ }
+ @Override
+ public float getMaterialRevealViewFinalAlpha(View revealView) {
+ return 1f;
+ }
+ @Override
+ public float getMaterialRevealViewFinalXDrift(View revealView) {
+ return mAllAppsToPanelDelta[0];
+ }
+ @Override
+ public float getMaterialRevealViewFinalYDrift(View revealView) {
+ return mAllAppsToPanelDelta[1];
+ }
+ @Override
+ public float getMaterialRevealViewStartFinalRadius() {
+ int allAppsButtonSize = LauncherAppState.getInstance().
+ getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
+ return allAppsButtonSize / 2;
+ }
+ @Override
+ public AnimatorListenerAdapter getMaterialRevealViewAnimatorListener(
+ final View revealView, final View allAppsButtonView) {
+ return new AnimatorListenerAdapter() {
+ public void onAnimationStart(Animator animation) {
+ allAppsButtonView.setVisibility(View.INVISIBLE);
+ }
+ public void onAnimationEnd(Animator animation) {
+ allAppsButtonView.setVisibility(View.VISIBLE);
+ }
+ };
+ }
+ };
+ startAnimationToOverlay(Workspace.State.NORMAL_HIDDEN, toView, toView.getContentView(),
+ toView.getRevealView(), null, animated, cb);
+ }
+
+ /**
+ * Starts an animation to the widgets view.
+ */
+ public void startAnimationToWidgets(final boolean animated) {
+ final AppsCustomizeTabHost toView = mLauncher.getWidgetsView();
+ PrivateTransitionCallbacks cb = new PrivateTransitionCallbacks() {
+ @Override
+ public void onRevealViewVisible(View revealView, View contentView,
+ View allAppsButtonView) {
+ // Hide the real page background, and swap in the fake one
+ ((AppsCustomizePagedView) contentView).setPageBackgroundsVisible(false);
+ revealView.setBackground(
+ mLauncher.getResources().getDrawable(R.drawable.quantum_panel_dark));
+ }
+ @Override
+ public void onAnimationComplete(View revealView, View contentView, View allAppsButtonView) {
+ // Show the real page background
+ ((AppsCustomizePagedView) contentView).setPageBackgroundsVisible(true);
+ }
+ @Override
+ public float getMaterialRevealViewFinalAlpha(View revealView) {
+ return 0.3f;
+ }
+ @Override
+ public float getMaterialRevealViewFinalYDrift(View revealView) {
+ return revealView.getMeasuredHeight() / 2;
+ }
+ };
+ startAnimationToOverlay(Workspace.State.OVERVIEW_HIDDEN, toView, toView.getContentView(),
+ toView.getRevealView(), toView.getPageIndicators(), animated, cb);
+ }
+
+ /**
+ * Starts and animation to the workspace from the current overlay view.
+ */
+ public void startAnimationToWorkspace(final Launcher.State fromState,
+ final Workspace.State toWorkspaceState, final boolean animated,
+ final Runnable onCompleteRunnable) {
+ if (toWorkspaceState != Workspace.State.NORMAL &&
+ toWorkspaceState != Workspace.State.SPRING_LOADED &&
+ toWorkspaceState != Workspace.State.OVERVIEW) {
+ Log.e(TAG, "Unexpected call to startAnimationToWorkspace");
+ }
+
+ if (fromState == Launcher.State.APPS || fromState == Launcher.State.APPS_SPRING_LOADED) {
+ startAnimationToWorkspaceFromAllApps(fromState, toWorkspaceState, animated,
+ onCompleteRunnable);
+ } else {
+ startAnimationToWorkspaceFromWidgets(fromState, toWorkspaceState, animated,
+ onCompleteRunnable);
+ }
+ }
+
+ /**
+ * Creates and starts a new animation to a particular overlay view.
+ */
+ private void startAnimationToOverlay(final Workspace.State toWorkspaceState, final View toView,
+ final View contentView, final View revealView, final View pageIndicatorsView,
+ final boolean animated, final PrivateTransitionCallbacks pCb) {
+ final Resources res = mLauncher.getResources();
+ final boolean material = Utilities.isLmpOrAbove();
+ final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
+ final int itemsAlphaStagger =
+ res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
+
+ final View allAppsButtonView = mLauncher.getAllAppsButton();
+ final View fromView = mLauncher.getWorkspace();
+
+ final HashMap<View, Integer> layerViews = new HashMap<>();
+
+ // If for some reason our views aren't initialized, don't animate
+ boolean initialized = allAppsButtonView != null;
+
+ // Cancel the current animation
+ cancelAnimation();
+
+ // Create the workspace animation.
+ // NOTE: this call apparently also sets the state for the workspace if !animated
+ Animator workspaceAnim = mLauncher.getWorkspace().getChangeStateAnimation(
+ toWorkspaceState, animated, layerViews);
+
+ if (animated && initialized) {
+ mStateAnimation = LauncherAnimUtils.createAnimatorSet();
+
+ // Setup the reveal view animation
+ int width = revealView.getMeasuredWidth();
+ int height = revealView.getMeasuredHeight();
+ float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
+ revealView.setVisibility(View.VISIBLE);
+ revealView.setAlpha(0f);
+ revealView.setTranslationY(0f);
+ revealView.setTranslationX(0f);
+ pCb.onRevealViewVisible(revealView, contentView, allAppsButtonView);
+
+ // Calculate the final animation values
+ final float revealViewToAlpha;
+ final float revealViewToXDrift;
+ final float revealViewToYDrift;
+ if (material) {
+ revealViewToAlpha = pCb.getMaterialRevealViewFinalAlpha(revealView);
+ revealViewToYDrift = pCb.getMaterialRevealViewFinalYDrift(revealView);
+ revealViewToXDrift = pCb.getMaterialRevealViewFinalXDrift(revealView);
+ } else {
+ revealViewToAlpha = 0f;
+ revealViewToYDrift = 2 * height / 3;
+ revealViewToXDrift = 0;
+ }
+
+ // Create the animators
+ PropertyValuesHolder panelAlpha =
+ PropertyValuesHolder.ofFloat("alpha", revealViewToAlpha, 1f);
+ PropertyValuesHolder panelDriftY =
+ PropertyValuesHolder.ofFloat("translationY", revealViewToYDrift, 0);
+ PropertyValuesHolder panelDriftX =
+ PropertyValuesHolder.ofFloat("translationX", revealViewToXDrift, 0);
+ ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView,
+ panelAlpha, panelDriftY, panelDriftX);
+ panelAlphaAndDrift.setDuration(revealDuration);
+ panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
+
+ // Play the animation
+ layerViews.put(revealView, BUILD_AND_SET_LAYER);
+ mStateAnimation.play(panelAlphaAndDrift);
+
+ // Setup the animation for the page indicators
+ if (pageIndicatorsView != null) {
+ pageIndicatorsView.setAlpha(0.01f);
+ ObjectAnimator indicatorsAlpha =
+ ObjectAnimator.ofFloat(pageIndicatorsView, "alpha", 1f);
+ indicatorsAlpha.setDuration(revealDuration);
+ mStateAnimation.play(indicatorsAlpha);
+ }
+
+ // Setup the animation for the content view
+ contentView.setVisibility(View.VISIBLE);
+ contentView.setAlpha(0f);
+ contentView.setTranslationY(revealViewToYDrift);
+ layerViews.put(contentView, BUILD_AND_SET_LAYER);
+
+ // Create the individual animators
+ ObjectAnimator pageDrift = ObjectAnimator.ofFloat(contentView, "translationY",
+ revealViewToYDrift, 0);
+ pageDrift.setDuration(revealDuration);
+ pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
+ pageDrift.setStartDelay(itemsAlphaStagger);
+ mStateAnimation.play(pageDrift);
+
+ ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(contentView, "alpha", 0f, 1f);
+ itemsAlpha.setDuration(revealDuration);
+ itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
+ itemsAlpha.setStartDelay(itemsAlphaStagger);
+ mStateAnimation.play(itemsAlpha);
+
+ if (material) {
+ // Animate the all apps button
+ float startRadius = pCb.getMaterialRevealViewStartFinalRadius();
+ AnimatorListenerAdapter listener = pCb.getMaterialRevealViewAnimatorListener(
+ revealView, allAppsButtonView);
+ Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2,
+ height / 2, startRadius, revealRadius);
+ reveal.setDuration(revealDuration);
+ reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
+ if (listener != null) {
+ reveal.addListener(listener);
+ }
+ mStateAnimation.play(reveal);
+ }
+
+ mStateAnimation.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ dispatchOnLauncherTransitionEnd(fromView, animated, false);
+ dispatchOnLauncherTransitionEnd(toView, animated, false);
+
+ // Hide the reveal view
+ revealView.setVisibility(View.INVISIBLE);
+ pCb.onAnimationComplete(revealView, contentView, allAppsButtonView);
+
+ // Disable all necessary layers
+ for (View v : layerViews.keySet()) {
+ if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
+ v.setLayerType(View.LAYER_TYPE_NONE, null);
+ }
+ }
+
+ // Hide the search bar
+ mCb.onStateTransitionHideSearchBar();
+
+ // This can hold unnecessary references to views.
+ mStateAnimation = null;
+ }
+
+ });
+
+ // Play the workspace animation
+ if (workspaceAnim != null) {
+ mStateAnimation.play(workspaceAnim);
+ }
+
+ // Dispatch the prepare transition signal
+ dispatchOnLauncherTransitionPrepare(fromView, animated, false);
+ dispatchOnLauncherTransitionPrepare(toView, animated, false);
+
+
+ final AnimatorSet stateAnimation = mStateAnimation;
+ final Runnable startAnimRunnable = new Runnable() {
+ public void run() {
+ // Check that mStateAnimation hasn't changed while
+ // we waited for a layout/draw pass
+ if (mStateAnimation != stateAnimation)
+ return;
+ dispatchOnLauncherTransitionStart(fromView, animated, false);
+ dispatchOnLauncherTransitionStart(toView, animated, false);
+
+ // Enable all necessary layers
+ for (View v : layerViews.keySet()) {
+ if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
+ v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
+ }
+ if (Utilities.isViewAttachedToWindow(v)) {
+ v.buildLayer();
+ }
+ }
+
+ // Focus the new view
+ toView.requestFocus();
+
+ mStateAnimation.start();
+ }
+ };
+
+ toView.bringToFront();
+ toView.setVisibility(View.VISIBLE);
+ toView.post(startAnimRunnable);
+ } else {
+ toView.setTranslationX(0.0f);
+ toView.setTranslationY(0.0f);
+ toView.setScaleX(1.0f);
+ toView.setScaleY(1.0f);
+ toView.setVisibility(View.VISIBLE);
+ toView.bringToFront();
+
+ // Show the content view
+ contentView.setVisibility(View.VISIBLE);
+
+ // Hide the search bar
+ mCb.onStateTransitionHideSearchBar();
+
+ dispatchOnLauncherTransitionPrepare(fromView, animated, false);
+ dispatchOnLauncherTransitionStart(fromView, animated, false);
+ dispatchOnLauncherTransitionEnd(fromView, animated, false);
+ dispatchOnLauncherTransitionPrepare(toView, animated, false);
+ dispatchOnLauncherTransitionStart(toView, animated, false);
+ dispatchOnLauncherTransitionEnd(toView, animated, false);
+ }
+ }
+
+ /**
+ * Starts and animation to the workspace from the apps view.
+ */
+ private void startAnimationToWorkspaceFromAllApps(final Launcher.State fromState,
+ final Workspace.State toWorkspaceState, final boolean animated,
+ final Runnable onCompleteRunnable) {
+ AppsContainerView appsView = mLauncher.getAppsView();
+ PrivateTransitionCallbacks cb = new PrivateTransitionCallbacks() {
+ int[] mAllAppsToPanelDelta;
+
+ @Override
+ public void onRevealViewVisible(View revealView, View contentView,
+ View allAppsButtonView) {
+ // Get the y delta between the center of the page and the center of the all apps
+ // button
+ mAllAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
+ allAppsButtonView, null);
+ }
+ @Override
+ public float getMaterialRevealViewFinalXDrift(View revealView) {
+ return mAllAppsToPanelDelta[0];
+ }
+ @Override
+ public float getMaterialRevealViewFinalYDrift(View revealView) {
+ return mAllAppsToPanelDelta[1];
+ }
+ @Override
+ float getMaterialRevealViewFinalAlpha(View revealView) {
+ // No alpha anim from all apps
+ return 1f;
+ }
+ @Override
+ float getMaterialRevealViewStartFinalRadius() {
+ int allAppsButtonSize = LauncherAppState.getInstance().
+ getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
+ return allAppsButtonSize / 2;
+ }
+ @Override
+ public AnimatorListenerAdapter getMaterialRevealViewAnimatorListener(
+ final View revealView, final View allAppsButtonView) {
+ return new AnimatorListenerAdapter() {
+ public void onAnimationStart(Animator animation) {
+ // We set the alpha instead of visibility to ensure that the focus does not
+ // get taken from the all apps view
+ allAppsButtonView.setVisibility(View.VISIBLE);
+ allAppsButtonView.setAlpha(0f);
+ }
+ public void onAnimationEnd(Animator animation) {
+ // Hide the reveal view
+ revealView.setVisibility(View.INVISIBLE);
+
+ // Show the all apps button, and focus it
+ allAppsButtonView.setAlpha(1f);
+ }
+ };
+ }
+ };
+ startAnimationToWorkspaceFromOverlay(toWorkspaceState, appsView, appsView.getContentView(),
+ appsView.getRevealView(), null /* pageIndicatorsView */, animated,
+ onCompleteRunnable, cb);
+ }
+
+ /**
+ * Starts and animation to the workspace from the widgets view.
+ */
+ private void startAnimationToWorkspaceFromWidgets(final Launcher.State fromState,
+ final Workspace.State toWorkspaceState, final boolean animated,
+ final Runnable onCompleteRunnable) {
+ AppsCustomizeTabHost widgetsView = mLauncher.getWidgetsView();
+ PrivateTransitionCallbacks cb = new PrivateTransitionCallbacks() {
+ @Override
+ public void onRevealViewVisible(View revealView, View contentView, View allAppsButtonView) {
+ AppsCustomizePagedView pagedView = ((AppsCustomizePagedView) contentView);
+
+ // Hide the real page background, and swap in the fake one
+ pagedView.stopScrolling();
+ pagedView.setPageBackgroundsVisible(false);
+ revealView.setBackground(
+ mLauncher.getResources().getDrawable(R.drawable.quantum_panel_dark));
+
+ // Hide the side pages of the Widget tray to avoid some ugly edge cases
+ final View currentPage = pagedView.getPageAt(pagedView.getNextPage());
+ int count = pagedView.getChildCount();
+ for (int i = 0; i < count; i++) {
+ View child = pagedView.getChildAt(i);
+ if (child != currentPage) {
+ child.setVisibility(View.INVISIBLE);
+ }
+ }
+ }
+ @Override
+ public void onAnimationComplete(View revealView, View contentView, View allAppsButtonView) {
+ AppsCustomizePagedView pagedView = ((AppsCustomizePagedView) contentView);
+
+ // Show the real page background and force-update the page
+ pagedView.setPageBackgroundsVisible(true);
+ pagedView.setCurrentPage(pagedView.getNextPage());
+ pagedView.updateCurrentPageScroll();
+
+ // Unhide the side pages
+ int count = pagedView.getChildCount();
+ for (int i = 0; i < count; i++) {
+ View child = pagedView.getChildAt(i);
+ child.setVisibility(View.VISIBLE);
+ }
+ }
+ @Override
+ public float getMaterialRevealViewFinalYDrift(View revealView) {
+ return revealView.getMeasuredHeight() / 2;
+ }
+ @Override
+ float getMaterialRevealViewFinalAlpha(View revealView) {
+ return 0.4f;
+ }
+ @Override
+ public AnimatorListenerAdapter getMaterialRevealViewAnimatorListener(
+ final View revealView, final View allAppsButtonView) {
+ return new AnimatorListenerAdapter() {
+ public void onAnimationEnd(Animator animation) {
+ // Hide the reveal view
+ revealView.setVisibility(View.INVISIBLE);
+ }
+ };
+ }
+ };
+ startAnimationToWorkspaceFromOverlay(toWorkspaceState, widgetsView,
+ widgetsView.getContentView(), widgetsView.getRevealView(),
+ widgetsView.getPageIndicators(), animated, onCompleteRunnable, cb);
+ }
+
+ /**
+ * Creates and starts a new animation to the workspace.
+ */
+ private void startAnimationToWorkspaceFromOverlay(final Workspace.State toWorkspaceState,
+ final View fromView, final View contentView, final View revealView,
+ final View pageIndicatorsView, final boolean animated,
+ final Runnable onCompleteRunnable, final PrivateTransitionCallbacks pCb) {
+ final Resources res = mLauncher.getResources();
+ final boolean material = Utilities.isLmpOrAbove();
+ final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
+ final int itemsAlphaStagger =
+ res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
+
+ final View allAppsButtonView = mLauncher.getAllAppsButton();
+ final View toView = mLauncher.getWorkspace();
+
+ final HashMap<View, Integer> layerViews = new HashMap<>();
+
+ // If for some reason our views aren't initialized, don't animate
+ boolean initialized = allAppsButtonView != null;
+
+ // Cancel the current animation
+ cancelAnimation();
+
+ // Create the workspace animation.
+ // NOTE: this call apparently also sets the state for the workspace if !animated
+ Animator workspaceAnim = mLauncher.getWorkspace().getChangeStateAnimation(
+ toWorkspaceState, animated, layerViews);
+
+ if (animated && initialized) {
+ mStateAnimation = LauncherAnimUtils.createAnimatorSet();
+
+ // Play the workspace animation
+ if (workspaceAnim != null) {
+ mStateAnimation.play(workspaceAnim);
+ }
+
+ // hideAppsCustomizeHelper is called in some cases when it is already hidden
+ // don't perform all these no-op animations. In particularly, this was causing
+ // the all-apps button to pop in and out.
+ if (fromView.getVisibility() == View.VISIBLE) {
+ int width = revealView.getMeasuredWidth();
+ int height = revealView.getMeasuredHeight();
+ float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
+ revealView.setVisibility(View.VISIBLE);
+ revealView.setAlpha(1f);
+ revealView.setTranslationY(0);
+ layerViews.put(revealView, BUILD_AND_SET_LAYER);
+ pCb.onRevealViewVisible(revealView, contentView, allAppsButtonView);
+
+ // Calculate the final animation values
+ final float revealViewToXDrift;
+ final float revealViewToYDrift;
+ if (material) {
+ revealViewToYDrift = pCb.getMaterialRevealViewFinalYDrift(revealView);
+ revealViewToXDrift = pCb.getMaterialRevealViewFinalXDrift(revealView);
+ } else {
+ revealViewToYDrift = 2 * height / 3;
+ revealViewToXDrift = 0;
+ }
+
+ // The vertical motion of the apps panel should be delayed by one frame
+ // from the conceal animation in order to give the right feel. We correspondingly
+ // shorten the duration so that the slide and conceal end at the same time.
+ TimeInterpolator decelerateInterpolator = material ?
+ new LogDecelerateInterpolator(100, 0) :
+ new DecelerateInterpolator(1f);
+ ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY",
+ 0, revealViewToYDrift);
+ panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
+ panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
+ panelDriftY.setInterpolator(decelerateInterpolator);
+ mStateAnimation.play(panelDriftY);
+
+ ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX",
+ 0, revealViewToXDrift);
+ panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
+ panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
+ panelDriftX.setInterpolator(decelerateInterpolator);
+ mStateAnimation.play(panelDriftX);
+
+ // Setup animation for the reveal panel alpha
+ final float revealViewToAlpha = !material ? 0f :
+ pCb.getMaterialRevealViewFinalAlpha(revealView);
+ if (revealViewToAlpha != 1f) {
+ ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha",
+ 1f, revealViewToAlpha);
+ panelAlpha.setDuration(material ? revealDuration : 150);
+ panelAlpha.setStartDelay(material ? 0 : itemsAlphaStagger + SINGLE_FRAME_DELAY);
+ panelAlpha.setInterpolator(decelerateInterpolator);
+ mStateAnimation.play(panelAlpha);
+ }
+
+ // Setup the animation for the content view
+ layerViews.put(contentView, BUILD_AND_SET_LAYER);
+
+ // Create the individual animators
+ ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(contentView, "translationY",
+ 0, revealViewToYDrift);
+ contentView.setTranslationY(0);
+ pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
+ pageDrift.setInterpolator(decelerateInterpolator);
+ pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
+ mStateAnimation.play(pageDrift);
+
+ contentView.setAlpha(1f);
+ ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(contentView, "alpha", 1f, 0f);
+ itemsAlpha.setDuration(100);
+ itemsAlpha.setInterpolator(decelerateInterpolator);
+ mStateAnimation.play(itemsAlpha);
+
+ // Setup the page indicators animation
+ if (pageIndicatorsView != null) {
+ pageIndicatorsView.setAlpha(1f);
+ ObjectAnimator indicatorsAlpha =
+ LauncherAnimUtils.ofFloat(pageIndicatorsView, "alpha", 0f);
+ indicatorsAlpha.setDuration(revealDuration);
+ indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
+ mStateAnimation.play(indicatorsAlpha);
+ }
+
+ if (material) {
+ // Animate the all apps button
+ float finalRadius = pCb.getMaterialRevealViewStartFinalRadius();
+ AnimatorListenerAdapter listener =
+ pCb.getMaterialRevealViewAnimatorListener(revealView, allAppsButtonView);
+ Animator reveal =
+ LauncherAnimUtils.createCircularReveal(revealView, width / 2,
+ height / 2, revealRadius, finalRadius);
+ reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
+ reveal.setDuration(revealDuration);
+ reveal.setStartDelay(itemsAlphaStagger);
+ if (listener != null) {
+ reveal.addListener(listener);
+ }
+ mStateAnimation.play(reveal);
+ }
+
+ dispatchOnLauncherTransitionPrepare(fromView, animated, true);
+ dispatchOnLauncherTransitionPrepare(toView, animated, true);
+ }
+
+ mStateAnimation.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ fromView.setVisibility(View.GONE);
+ dispatchOnLauncherTransitionEnd(fromView, animated, true);
+ dispatchOnLauncherTransitionEnd(toView, animated, true);
+
+ // Run any queued runnables
+ if (onCompleteRunnable != null) {
+ onCompleteRunnable.run();
+ }
+
+ // Animation complete callback
+ pCb.onAnimationComplete(revealView, contentView, allAppsButtonView);
+
+ // Disable all necessary layers
+ for (View v : layerViews.keySet()) {
+ if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
+ v.setLayerType(View.LAYER_TYPE_NONE, null);
+ }
+ }
+
+ // Reset page transforms
+ if (contentView != null) {
+ contentView.setTranslationX(0);
+ contentView.setTranslationY(0);
+ contentView.setAlpha(1);
+ }
+
+ // This can hold unnecessary references to views.
+ mStateAnimation = null;
+ }
+ });
+
+ final AnimatorSet stateAnimation = mStateAnimation;
+ final Runnable startAnimRunnable = new Runnable() {
+ public void run() {
+ // Check that mStateAnimation hasn't changed while
+ // we waited for a layout/draw pass
+ if (mStateAnimation != stateAnimation)
+ return;
+ dispatchOnLauncherTransitionStart(fromView, animated, false);
+ dispatchOnLauncherTransitionStart(toView, animated, false);
+
+ // Enable all necessary layers
+ for (View v : layerViews.keySet()) {
+ if (layerViews.get(v) == BUILD_AND_SET_LAYER) {
+ v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
+ }
+ if (Utilities.isLmpOrAbove()) {
+ v.buildLayer();
+ }
+ }
+ mStateAnimation.start();
+ }
+ };
+ fromView.post(startAnimRunnable);
+ } else {
+ fromView.setVisibility(View.GONE);
+ dispatchOnLauncherTransitionPrepare(fromView, animated, true);
+ dispatchOnLauncherTransitionStart(fromView, animated, true);
+ dispatchOnLauncherTransitionEnd(fromView, animated, true);
+ dispatchOnLauncherTransitionPrepare(toView, animated, true);
+ dispatchOnLauncherTransitionStart(toView, animated, true);
+ dispatchOnLauncherTransitionEnd(toView, animated, true);
+
+ // Run any queued runnables
+ if (onCompleteRunnable != null) {
+ onCompleteRunnable.run();
+ }
+ }
+ }
+
+
+ /**
+ * Dispatches the prepare-transition event to suitable views.
+ */
+ void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
+ if (v instanceof LauncherTransitionable) {
+ ((LauncherTransitionable) v).onLauncherTransitionPrepare(mLauncher, animated,
+ toWorkspace);
+ }
+ }
+
+ /**
+ * Dispatches the start-transition event to suitable views.
+ */
+ void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
+ if (v instanceof LauncherTransitionable) {
+ ((LauncherTransitionable) v).onLauncherTransitionStart(mLauncher, animated,
+ toWorkspace);
+ }
+
+ // Update the workspace transition step as well
+ dispatchOnLauncherTransitionStep(v, 0f);
+ }
+
+ /**
+ * Dispatches the step-transition event to suitable views.
+ */
+ void dispatchOnLauncherTransitionStep(View v, float t) {
+ if (v instanceof LauncherTransitionable) {
+ ((LauncherTransitionable) v).onLauncherTransitionStep(mLauncher, t);
+ }
+ }
+
+ /**
+ * Dispatches the end-transition event to suitable views.
+ */
+ void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
+ if (v instanceof LauncherTransitionable) {
+ ((LauncherTransitionable) v).onLauncherTransitionEnd(mLauncher, animated,
+ toWorkspace);
+ }
+
+ // Update the workspace transition step as well
+ dispatchOnLauncherTransitionStep(v, 1f);
+ }
+
+ /**
+ * Cancels the current animation.
+ */
+ private void cancelAnimation() {
+ if (mStateAnimation != null) {
+ mStateAnimation.setDuration(0);
+ mStateAnimation.cancel();
+ mStateAnimation = null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/launcher3/PackageChangedReceiver.java b/src/com/android/launcher3/PackageChangedReceiver.java
index e59f6d8..b98f472 100644
--- a/src/com/android/launcher3/PackageChangedReceiver.java
+++ b/src/com/android/launcher3/PackageChangedReceiver.java
@@ -4,18 +4,10 @@
import android.content.Context;
import android.content.Intent;
+// TODO: Remove this
public class PackageChangedReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
- final String packageName = intent.getData().getSchemeSpecificPart();
- if (packageName == null || packageName.length() == 0) {
- // they sent us a bad intent
- return;
- }
- // in rare cases the receiver races with the application to set up LauncherAppState
- LauncherAppState.setApplicationContext(context.getApplicationContext());
- LauncherAppState app = LauncherAppState.getInstance();
- WidgetPreviewLoader.removePackageFromDb(app.getWidgetPreviewCacheDb(), packageName);
}
}
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 7d65f46..158a30c 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -51,6 +51,8 @@
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
+import com.android.launcher3.util.Thunk;
+
import java.util.ArrayList;
interface Page {
@@ -124,7 +126,7 @@
protected LauncherScroller mScroller;
private Interpolator mDefaultInterpolator;
private VelocityTracker mVelocityTracker;
- private int mPageSpacing = 0;
+ @Thunk int mPageSpacing = 0;
private float mParentDownMotionX;
private float mParentDownMotionY;
@@ -207,8 +209,8 @@
private boolean mWasInOverscroll = false;
// Page Indicator
- private int mPageIndicatorViewId;
- private PageIndicator mPageIndicator;
+ @Thunk int mPageIndicatorViewId;
+ @Thunk PageIndicator mPageIndicator;
private boolean mAllowPagedViewAnimations = true;
// The viewport whether the pages are to be contained (the actual view may be larger than the
@@ -227,7 +229,7 @@
protected View mDragView;
protected AnimatorSet mZoomInOutAnim;
private Runnable mSidePageHoverRunnable;
- private int mSidePageHoverIndex = -1;
+ @Thunk int mSidePageHoverIndex = -1;
// This variable's scope is only for the duration of startReordering() and endReordering()
private boolean mReorderingStarted = false;
// This variable's scope is for the duration of startReordering() and after the zoomIn()
@@ -246,14 +248,14 @@
private Rect mAltTmpRect = new Rect();
// Fling to delete
- private int FLING_TO_DELETE_FADE_OUT_DURATION = 350;
+ @Thunk int FLING_TO_DELETE_FADE_OUT_DURATION = 350;
private float FLING_TO_DELETE_FRICTION = 0.035f;
// The degrees specifies how much deviation from the up vector to still consider a fling "up"
private float FLING_TO_DELETE_MAX_FLING_DEGREES = 65f;
protected int mFlingToDeleteThresholdVelocity = -1400;
// Drag to delete
- private boolean mDeferringForDelete = false;
- private int DELETE_SLIDE_IN_SIDE_PAGE_DURATION = 250;
+ @Thunk boolean mDeferringForDelete = false;
+ @Thunk int DELETE_SLIDE_IN_SIDE_PAGE_DURATION = 250;
private int DRAG_TO_DELETE_FADE_OUT_DURATION = 350;
// Drop to delete
@@ -1700,7 +1702,7 @@
setEnableOverscroll(!freeScroll);
}
- private void setEnableOverscroll(boolean enable) {
+ protected void setEnableOverscroll(boolean enable) {
mAllowOverScroll = enable;
}
@@ -2356,7 +2358,7 @@
super(superState);
}
- private SavedState(Parcel in) {
+ @Thunk SavedState(Parcel in) {
super(in);
currentPage = in.readInt();
}
@@ -2514,7 +2516,7 @@
invalidate();
}
- private void onPostReorderingAnimationCompleted() {
+ @Thunk void onPostReorderingAnimationCompleted() {
// Trigger the callback when reordering has settled
--mPostReorderingPreZoomInRemainingAnimationCount;
if (mPostReorderingPreZoomInRunnable != null &&
diff --git a/src/com/android/launcher3/PagedViewCellLayout.java b/src/com/android/launcher3/PagedViewCellLayout.java
deleted file mode 100644
index 2d9e10b..0000000
--- a/src/com/android/launcher3/PagedViewCellLayout.java
+++ /dev/null
@@ -1,492 +0,0 @@
-/*
- * 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.launcher3;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewDebug;
-import android.view.ViewGroup;
-
-/**
- * An abstraction of the original CellLayout which supports laying out items
- * which span multiple cells into a grid-like layout. Also supports dimming
- * to give a preview of its contents.
- */
-public class PagedViewCellLayout extends ViewGroup implements Page {
- static final String TAG = "PagedViewCellLayout";
-
- private int mCellCountX;
- private int mCellCountY;
- private int mOriginalCellWidth;
- private int mOriginalCellHeight;
- private int mCellWidth;
- private int mCellHeight;
- private int mOriginalWidthGap;
- private int mOriginalHeightGap;
- private int mWidthGap;
- private int mHeightGap;
- protected PagedViewCellLayoutChildren mChildren;
-
- public PagedViewCellLayout(Context context) {
- this(context, null);
- }
-
- public PagedViewCellLayout(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public PagedViewCellLayout(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
-
- setAlwaysDrawnWithCacheEnabled(false);
-
- // setup default cell parameters
- LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
- mOriginalCellWidth = mCellWidth = grid.cellWidthPx;
- mOriginalCellHeight = mCellHeight = grid.cellHeightPx;
- mCellCountX = (int) grid.numColumns;
- mCellCountY = (int) grid.numRows;
- mOriginalWidthGap = mOriginalHeightGap = mWidthGap = mHeightGap = -1;
-
- mChildren = new PagedViewCellLayoutChildren(context);
- mChildren.setCellDimensions(mCellWidth, mCellHeight);
- mChildren.setGap(mWidthGap, mHeightGap);
-
- addView(mChildren);
- }
-
- public int getCellWidth() {
- return mCellWidth;
- }
-
- public int getCellHeight() {
- return mCellHeight;
- }
-
- @Override
- public void cancelLongPress() {
- super.cancelLongPress();
-
- // Cancel long press for all children
- final int count = getChildCount();
- for (int i = 0; i < count; i++) {
- final View child = getChildAt(i);
- child.cancelLongPress();
- }
- }
-
- public boolean addViewToCellLayout(View child, int index, int childId,
- PagedViewCellLayout.LayoutParams params) {
- final PagedViewCellLayout.LayoutParams lp = params;
-
- // Generate an id for each view, this assumes we have at most 256x256 cells
- // per workspace screen
- if (lp.cellX >= 0 && lp.cellX <= (mCellCountX - 1) &&
- lp.cellY >= 0 && (lp.cellY <= mCellCountY - 1)) {
- // If the horizontal or vertical span is set to -1, it is taken to
- // mean that it spans the extent of the CellLayout
- if (lp.cellHSpan < 0) lp.cellHSpan = mCellCountX;
- if (lp.cellVSpan < 0) lp.cellVSpan = mCellCountY;
-
- child.setId(childId);
- mChildren.addView(child, index, lp);
-
- return true;
- }
- return false;
- }
-
- @Override
- public void removeAllViewsOnPage() {
- mChildren.removeAllViews();
- setLayerType(LAYER_TYPE_NONE, null);
- }
-
- @Override
- public void removeViewOnPageAt(int index) {
- mChildren.removeViewAt(index);
- }
-
- /**
- * Clears all the key listeners for the individual icons.
- */
- public void resetChildrenOnKeyListeners() {
- int childCount = mChildren.getChildCount();
- for (int j = 0; j < childCount; ++j) {
- mChildren.getChildAt(j).setOnKeyListener(null);
- }
- }
-
- @Override
- public int getPageChildCount() {
- return mChildren.getChildCount();
- }
-
- public PagedViewCellLayoutChildren getChildrenLayout() {
- return mChildren;
- }
-
- @Override
- public View getChildOnPageAt(int i) {
- return mChildren.getChildAt(i);
- }
-
- @Override
- public int indexOfChildOnPage(View v) {
- return mChildren.indexOfChild(v);
- }
-
- public int getCellCountX() {
- return mCellCountX;
- }
-
- public int getCellCountY() {
- return mCellCountY;
- }
-
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
- int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
-
- int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
- int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
-
- if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) {
- throw new RuntimeException("CellLayout cannot have UNSPECIFIED dimensions");
- }
-
- int numWidthGaps = mCellCountX - 1;
- int numHeightGaps = mCellCountY - 1;
-
- if (mOriginalWidthGap < 0 || mOriginalHeightGap < 0) {
- int hSpace = widthSpecSize - getPaddingLeft() - getPaddingRight();
- int vSpace = heightSpecSize - getPaddingTop() - getPaddingBottom();
- int hFreeSpace = hSpace - (mCellCountX * mOriginalCellWidth);
- int vFreeSpace = vSpace - (mCellCountY * mOriginalCellHeight);
- mWidthGap = numWidthGaps > 0 ? (hFreeSpace / numWidthGaps) : 0;
- mHeightGap = numHeightGaps > 0 ? (vFreeSpace / numHeightGaps) : 0;
-
- mChildren.setGap(mWidthGap, mHeightGap);
- } else {
- mWidthGap = mOriginalWidthGap;
- mHeightGap = mOriginalHeightGap;
- }
-
- // Initial values correspond to widthSpecMode == MeasureSpec.EXACTLY
- int newWidth = widthSpecSize;
- int newHeight = heightSpecSize;
- if (widthSpecMode == MeasureSpec.AT_MOST) {
- newWidth = getPaddingLeft() + getPaddingRight() + (mCellCountX * mCellWidth) +
- ((mCellCountX - 1) * mWidthGap);
- newHeight = getPaddingTop() + getPaddingBottom() + (mCellCountY * mCellHeight) +
- ((mCellCountY - 1) * mHeightGap);
- setMeasuredDimension(newWidth, newHeight);
- }
-
- final int count = getChildCount();
- for (int i = 0; i < count; i++) {
- View child = getChildAt(i);
- int childWidthMeasureSpec =
- MeasureSpec.makeMeasureSpec(newWidth - getPaddingLeft() -
- getPaddingRight(), MeasureSpec.EXACTLY);
- int childheightMeasureSpec =
- MeasureSpec.makeMeasureSpec(newHeight - getPaddingTop() -
- getPaddingBottom(), MeasureSpec.EXACTLY);
- child.measure(childWidthMeasureSpec, childheightMeasureSpec);
- }
-
- setMeasuredDimension(newWidth, newHeight);
- }
-
- int getContentWidth() {
- return getWidthBeforeFirstLayout() + getPaddingLeft() + getPaddingRight();
- }
-
- int getContentHeight() {
- if (mCellCountY > 0) {
- return mCellCountY * mCellHeight + (mCellCountY - 1) * Math.max(0, mHeightGap);
- }
- return 0;
- }
-
- int getWidthBeforeFirstLayout() {
- if (mCellCountX > 0) {
- return mCellCountX * mCellWidth + (mCellCountX - 1) * Math.max(0, mWidthGap);
- }
- return 0;
- }
-
- @Override
- protected void onLayout(boolean changed, int l, int t, int r, int b) {
- int count = getChildCount();
- for (int i = 0; i < count; i++) {
- View child = getChildAt(i);
- child.layout(getPaddingLeft(), getPaddingTop(),
- r - l - getPaddingRight(), b - t - getPaddingBottom());
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- boolean result = super.onTouchEvent(event);
- int count = getPageChildCount();
- if (count > 0) {
- // We only intercept the touch if we are tapping in empty space after the final row
- View child = getChildOnPageAt(count - 1);
- int bottom = child.getBottom();
- int numRows = (int) Math.ceil((float) getPageChildCount() / getCellCountX());
- if (numRows < getCellCountY()) {
- // Add a little bit of buffer if there is room for another row
- bottom += mCellHeight / 2;
- }
- result = result || (event.getY() < bottom);
- }
- return result;
- }
-
- public void enableCenteredContent(boolean enabled) {
- mChildren.enableCenteredContent(enabled);
- }
-
- @Override
- protected void setChildrenDrawingCacheEnabled(boolean enabled) {
- mChildren.setChildrenDrawingCacheEnabled(enabled);
- }
-
- public void setCellCount(int xCount, int yCount) {
- mCellCountX = xCount;
- mCellCountY = yCount;
- requestLayout();
- }
-
- public void setGap(int widthGap, int heightGap) {
- mOriginalWidthGap = mWidthGap = widthGap;
- mOriginalHeightGap = mHeightGap = heightGap;
- mChildren.setGap(widthGap, heightGap);
- }
-
- public int[] getCellCountForDimensions(int width, int height) {
- // Always assume we're working with the smallest span to make sure we
- // reserve enough space in both orientations
- int smallerSize = Math.min(mCellWidth, mCellHeight);
-
- // Always round up to next largest cell
- int spanX = (width + smallerSize) / smallerSize;
- int spanY = (height + smallerSize) / smallerSize;
-
- return new int[] { spanX, spanY };
- }
-
- /**
- * Start dragging the specified child
- *
- * @param child The child that is being dragged
- */
- void onDragChild(View child) {
- PagedViewCellLayout.LayoutParams lp = (PagedViewCellLayout.LayoutParams) child.getLayoutParams();
- lp.isDragging = true;
- }
-
- /**
- * Estimates the number of cells that the specified width would take up.
- */
- public int estimateCellHSpan(int width) {
- // We don't show the next/previous pages any more, so we use the full width, minus the
- // padding
- int availWidth = width - (getPaddingLeft() + getPaddingRight());
-
- // We know that we have to fit N cells with N-1 width gaps, so we just juggle to solve for N
- int n = Math.max(1, (availWidth + mWidthGap) / (mCellWidth + mWidthGap));
-
- // We don't do anything fancy to determine if we squeeze another row in.
- return n;
- }
-
- /**
- * Estimates the number of cells that the specified height would take up.
- */
- public int estimateCellVSpan(int height) {
- // The space for a page is the height - top padding (current page) - bottom padding (current
- // page)
- int availHeight = height - (getPaddingTop() + getPaddingBottom());
-
- // We know that we have to fit N cells with N-1 height gaps, so we juggle to solve for N
- int n = Math.max(1, (availHeight + mHeightGap) / (mCellHeight + mHeightGap));
-
- // We don't do anything fancy to determine if we squeeze another row in.
- return n;
- }
-
- /** Returns an estimated center position of the cell at the specified index */
- public int[] estimateCellPosition(int x, int y) {
- return new int[] {
- getPaddingLeft() + (x * mCellWidth) + (x * mWidthGap) + (mCellWidth / 2),
- getPaddingTop() + (y * mCellHeight) + (y * mHeightGap) + (mCellHeight / 2)
- };
- }
-
- public void calculateCellCount(int width, int height, int maxCellCountX, int maxCellCountY) {
- mCellCountX = Math.min(maxCellCountX, estimateCellHSpan(width));
- mCellCountY = Math.min(maxCellCountY, estimateCellVSpan(height));
- requestLayout();
- }
-
- /**
- * Estimates the width that the number of hSpan cells will take up.
- */
- public int estimateCellWidth(int hSpan) {
- // TODO: we need to take widthGap into effect
- return hSpan * mCellWidth;
- }
-
- /**
- * Estimates the height that the number of vSpan cells will take up.
- */
- public int estimateCellHeight(int vSpan) {
- // TODO: we need to take heightGap into effect
- return vSpan * mCellHeight;
- }
-
- @Override
- public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
- return new PagedViewCellLayout.LayoutParams(getContext(), attrs);
- }
-
- @Override
- protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
- return p instanceof PagedViewCellLayout.LayoutParams;
- }
-
- @Override
- protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
- return new PagedViewCellLayout.LayoutParams(p);
- }
-
- public static class LayoutParams extends ViewGroup.MarginLayoutParams {
- /**
- * Horizontal location of the item in the grid.
- */
- @ViewDebug.ExportedProperty
- public int cellX;
-
- /**
- * Vertical location of the item in the grid.
- */
- @ViewDebug.ExportedProperty
- public int cellY;
-
- /**
- * Number of cells spanned horizontally by the item.
- */
- @ViewDebug.ExportedProperty
- public int cellHSpan;
-
- /**
- * Number of cells spanned vertically by the item.
- */
- @ViewDebug.ExportedProperty
- public int cellVSpan;
-
- /**
- * Is this item currently being dragged
- */
- public boolean isDragging;
-
- // a data object that you can bind to this layout params
- private Object mTag;
-
- // X coordinate of the view in the layout.
- @ViewDebug.ExportedProperty
- int x;
- // Y coordinate of the view in the layout.
- @ViewDebug.ExportedProperty
- int y;
-
- public LayoutParams() {
- super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
- cellHSpan = 1;
- cellVSpan = 1;
- }
-
- public LayoutParams(Context c, AttributeSet attrs) {
- super(c, attrs);
- cellHSpan = 1;
- cellVSpan = 1;
- }
-
- public LayoutParams(ViewGroup.LayoutParams source) {
- super(source);
- cellHSpan = 1;
- cellVSpan = 1;
- }
-
- public LayoutParams(LayoutParams source) {
- super(source);
- this.cellX = source.cellX;
- this.cellY = source.cellY;
- this.cellHSpan = source.cellHSpan;
- this.cellVSpan = source.cellVSpan;
- }
-
- public LayoutParams(int cellX, int cellY, int cellHSpan, int cellVSpan) {
- super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
- this.cellX = cellX;
- this.cellY = cellY;
- this.cellHSpan = cellHSpan;
- this.cellVSpan = cellVSpan;
- }
-
- public void setup(Context context,
- int cellWidth, int cellHeight, int widthGap, int heightGap,
- int hStartPadding, int vStartPadding) {
-
- final int myCellHSpan = cellHSpan;
- final int myCellVSpan = cellVSpan;
- final int myCellX = cellX;
- final int myCellY = cellY;
-
- width = myCellHSpan * cellWidth + ((myCellHSpan - 1) * widthGap) -
- leftMargin - rightMargin;
- height = myCellVSpan * cellHeight + ((myCellVSpan - 1) * heightGap) -
- topMargin - bottomMargin;
-
- if (LauncherAppState.getInstance().isScreenLarge()) {
- x = hStartPadding + myCellX * (cellWidth + widthGap) + leftMargin;
- y = vStartPadding + myCellY * (cellHeight + heightGap) + topMargin;
- } else {
- x = myCellX * (cellWidth + widthGap) + leftMargin;
- y = myCellY * (cellHeight + heightGap) + topMargin;
- }
- }
-
- public Object getTag() {
- return mTag;
- }
-
- public void setTag(Object tag) {
- mTag = tag;
- }
-
- public String toString() {
- return "(" + this.cellX + ", " + this.cellY + ", " +
- this.cellHSpan + ", " + this.cellVSpan + ")";
- }
- }
-}
\ No newline at end of file
diff --git a/src/com/android/launcher3/PagedViewCellLayoutChildren.java b/src/com/android/launcher3/PagedViewCellLayoutChildren.java
deleted file mode 100644
index 84d2b1d..0000000
--- a/src/com/android/launcher3/PagedViewCellLayoutChildren.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * 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.launcher3;
-
-import android.content.Context;
-import android.graphics.Rect;
-import android.view.View;
-import android.view.ViewGroup;
-
-/**
- * An abstraction of the original CellLayout which supports laying out items
- * which span multiple cells into a grid-like layout. Also supports dimming
- * to give a preview of its contents.
- */
-public class PagedViewCellLayoutChildren extends ViewGroup {
- static final String TAG = "PagedViewCellLayout";
-
- private boolean mCenterContent;
-
- private int mCellWidth;
- private int mCellHeight;
- private int mWidthGap;
- private int mHeightGap;
-
- public PagedViewCellLayoutChildren(Context context) {
- super(context);
- }
-
- @Override
- public void cancelLongPress() {
- super.cancelLongPress();
-
- // Cancel long press for all children
- final int count = getChildCount();
- for (int i = 0; i < count; i++) {
- final View child = getChildAt(i);
- child.cancelLongPress();
- }
- }
-
- public void setGap(int widthGap, int heightGap) {
- mWidthGap = widthGap;
- mHeightGap = heightGap;
- requestLayout();
- }
-
- public void setCellDimensions(int width, int height) {
- mCellWidth = width;
- mCellHeight = height;
- requestLayout();
- }
-
- @Override
- public void requestChildFocus(View child, View focused) {
- super.requestChildFocus(child, focused);
- if (child != null) {
- Rect r = new Rect();
- child.getDrawingRect(r);
- requestRectangleOnScreen(r);
- }
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
- int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
-
- int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
- int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
-
- if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) {
- throw new RuntimeException("CellLayout cannot have UNSPECIFIED dimensions");
- }
-
- final int count = getChildCount();
- for (int i = 0; i < count; i++) {
- View child = getChildAt(i);
- PagedViewCellLayout.LayoutParams lp =
- (PagedViewCellLayout.LayoutParams) child.getLayoutParams();
- lp.setup(getContext(),
- mCellWidth, mCellHeight, mWidthGap, mHeightGap,
- getPaddingLeft(),
- getPaddingTop());
-
- int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width,
- MeasureSpec.EXACTLY);
- int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(lp.height,
- MeasureSpec.EXACTLY);
-
- child.measure(childWidthMeasureSpec, childheightMeasureSpec);
- }
-
- setMeasuredDimension(widthSpecSize, heightSpecSize);
- }
-
- @Override
- protected void onLayout(boolean changed, int l, int t, int r, int b) {
- int count = getChildCount();
-
- int offsetX = 0;
- if (mCenterContent && count > 0) {
- // determine the max width of all the rows and center accordingly
- int maxRowX = 0;
- int minRowX = Integer.MAX_VALUE;
- for (int i = 0; i < count; i++) {
- View child = getChildAt(i);
- if (child.getVisibility() != GONE) {
- PagedViewCellLayout.LayoutParams lp =
- (PagedViewCellLayout.LayoutParams) child.getLayoutParams();
- minRowX = Math.min(minRowX, lp.x);
- maxRowX = Math.max(maxRowX, lp.x + lp.width);
- }
- }
- int maxRowWidth = maxRowX - minRowX;
- offsetX = (getMeasuredWidth() - maxRowWidth) / 2;
- }
-
- for (int i = 0; i < count; i++) {
- View child = getChildAt(i);
- if (child.getVisibility() != GONE) {
- PagedViewCellLayout.LayoutParams lp =
- (PagedViewCellLayout.LayoutParams) child.getLayoutParams();
-
- int childLeft = offsetX + lp.x;
- int childTop = lp.y;
- child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
- }
- }
- }
-
- public void enableCenteredContent(boolean enabled) {
- mCenterContent = enabled;
- }
-
- @Override
- protected void setChildrenDrawingCacheEnabled(boolean enabled) {
- final int count = getChildCount();
- for (int i = 0; i < count; i++) {
- final View view = getChildAt(i);
- view.setDrawingCacheEnabled(enabled);
- // Update the drawing caches
- if (!view.isHardwareAccelerated()) {
- view.buildDrawingCache(true);
- }
- }
- }
-}
diff --git a/src/com/android/launcher3/PagedViewWidget.java b/src/com/android/launcher3/PagedViewWidget.java
index 107069b..d9ca7be 100644
--- a/src/com/android/launcher3/PagedViewWidget.java
+++ b/src/com/android/launcher3/PagedViewWidget.java
@@ -20,35 +20,38 @@
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
+import android.graphics.Bitmap;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
+import android.view.View.OnLayoutChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
+import com.android.launcher3.WidgetPreviewLoader.PreviewLoadRequest;
import com.android.launcher3.compat.AppWidgetManagerCompat;
/**
* The linear layout used strictly for the widget/wallpaper tab of the customization tray
*/
-public class PagedViewWidget extends LinearLayout {
- static final String TAG = "PagedViewWidgetLayout";
+public class PagedViewWidget extends LinearLayout implements OnLayoutChangeListener {
- private static boolean sDeletePreviewsWhenDetachedFromWindow = true;
- private static boolean sRecyclePreviewsWhenDetachedFromWindow = true;
+ private static PagedViewWidget sShortpressTarget = null;
+
+ private final Rect mOriginalImagePadding = new Rect();
private String mDimensionsFormatString;
- CheckForShortPress mPendingCheckForShortPress = null;
- ShortPressListener mShortPressListener = null;
- boolean mShortPressTriggered = false;
- static PagedViewWidget sShortpressTarget = null;
- boolean mIsAppWidget;
- private final Rect mOriginalImagePadding = new Rect();
+ private CheckForShortPress mPendingCheckForShortPress = null;
+ private ShortPressListener mShortPressListener = null;
+ private boolean mShortPressTriggered = false;
+ private boolean mIsAppWidget;
private Object mInfo;
+
private WidgetPreviewLoader mWidgetPreviewLoader;
+ private PreviewLoadRequest mActiveRequest;
public PagedViewWidget(Context context) {
this(context, null);
@@ -92,29 +95,24 @@
}
}
- public static void setDeletePreviewsWhenDetachedFromWindow(boolean value) {
- sDeletePreviewsWhenDetachedFromWindow = value;
- }
-
- public static void setRecyclePreviewsWhenDetachedFromWindow(boolean value) {
- sRecyclePreviewsWhenDetachedFromWindow = value;
- }
-
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
+ deletePreview(true);
+ }
- if (sDeletePreviewsWhenDetachedFromWindow) {
+ public void deletePreview(boolean recycleImage) {
+ if (recycleImage) {
final ImageView image = (ImageView) findViewById(R.id.widget_preview);
if (image != null) {
- FastBitmapDrawable preview = (FastBitmapDrawable) image.getDrawable();
- if (sRecyclePreviewsWhenDetachedFromWindow &&
- mInfo != null && preview != null && preview.getBitmap() != null) {
- mWidgetPreviewLoader.recycleBitmap(mInfo, preview.getBitmap());
- }
image.setImageDrawable(null);
}
}
+
+ if (mActiveRequest != null) {
+ mActiveRequest.cancel(recycleImage);
+ mActiveRequest = null;
+ }
}
public void applyFromAppWidgetProviderInfo(LauncherAppWidgetProviderInfo info,
@@ -161,7 +159,8 @@
return maxSize;
}
- void applyPreview(FastBitmapDrawable preview, int index) {
+ public void applyPreview(Bitmap bitmap) {
+ FastBitmapDrawable preview = new FastBitmapDrawable(bitmap);
final PagedViewWidgetImageView image =
(PagedViewWidgetImageView) findViewById(R.id.widget_preview);
if (preview != null) {
@@ -259,4 +258,38 @@
// we just always mark the touch event as handled.
return true;
}
+
+ public void ensurePreview() {
+ if (mActiveRequest != null) {
+ return;
+ }
+ int[] size = getPreviewSize();
+
+ if (size[0] <= 0 || size[1] <= 0) {
+ addOnLayoutChangeListener(this);
+ return;
+ }
+ Bitmap[] immediateResult = new Bitmap[1];
+ mActiveRequest = mWidgetPreviewLoader.getPreview(mInfo, size[0], size[1], this,
+ immediateResult);
+ if (immediateResult[0] != null) {
+ applyPreview(immediateResult[0]);
+ }
+ }
+
+ @Override
+ public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
+ int oldTop, int oldRight, int oldBottom) {
+ removeOnLayoutChangeListener(this);
+ ensurePreview();
+ }
+
+ public int getActualItemWidth() {
+ ItemInfo info = (ItemInfo) getTag();
+ int[] size = getPreviewSize();
+ int cellWidth = LauncherAppState.getInstance()
+ .getDynamicGrid().getDeviceProfile().cellWidthPx;
+
+ return Math.min(size[0], info.spanX * cellWidth);
+ }
}
diff --git a/src/com/android/launcher3/PagedViewWithDraggableItems.java b/src/com/android/launcher3/PagedViewWithDraggableItems.java
index 0e59369..f0743cf 100644
--- a/src/com/android/launcher3/PagedViewWithDraggableItems.java
+++ b/src/com/android/launcher3/PagedViewWithDraggableItems.java
@@ -109,7 +109,7 @@
// Return early if we are still animating the pages
if (mNextPage != INVALID_PAGE) return false;
// When we have exited all apps or are in transition, disregard long clicks
- if (!mLauncher.isAllAppsVisible() ||
+ if (!mLauncher.isWidgetsViewVisible() ||
mLauncher.getWorkspace().isSwitchingState()) return false;
// Return if global dragging is not enabled
if (!mLauncher.isDraggingEnabled()) return false;
diff --git a/src/com/android/launcher3/SearchDropTargetBar.java b/src/com/android/launcher3/SearchDropTargetBar.java
index 99c2e08..cc17820 100644
--- a/src/com/android/launcher3/SearchDropTargetBar.java
+++ b/src/com/android/launcher3/SearchDropTargetBar.java
@@ -197,6 +197,10 @@
*/
@Override
public void onDragStart(DragSource source, Object info, int dragAction) {
+ showDeleteTarget();
+ }
+
+ public void showDeleteTarget() {
// Animate out the QSB search bar, and animate in the drop target bar
prepareStartAnimation(mDropTargetBar);
mDropTargetBarAnim.start();
@@ -206,6 +210,16 @@
}
}
+ public void hideDeleteTarget() {
+ // Restore the QSB search bar, and animate out the drop target bar
+ prepareStartAnimation(mDropTargetBar);
+ mDropTargetBarAnim.reverse();
+ if (!mIsSearchBarHidden) {
+ prepareStartAnimation(mQSBSearchBar);
+ mQSBSearchBarAnim.reverse();
+ }
+ }
+
public void deferOnDragEnd() {
mDeferOnDragEnd = true;
}
@@ -213,13 +227,7 @@
@Override
public void onDragEnd() {
if (!mDeferOnDragEnd) {
- // Restore the QSB search bar, and animate out the drop target bar
- prepareStartAnimation(mDropTargetBar);
- mDropTargetBarAnim.reverse();
- if (!mIsSearchBarHidden) {
- prepareStartAnimation(mQSBSearchBar);
- mQSBSearchBarAnim.reverse();
- }
+ hideDeleteTarget();
} else {
mDeferOnDragEnd = false;
}
diff --git a/src/com/android/launcher3/ShortcutInfo.java b/src/com/android/launcher3/ShortcutInfo.java
index 08ffaa2..9f7da6c 100644
--- a/src/com/android/launcher3/ShortcutInfo.java
+++ b/src/com/android/launcher3/ShortcutInfo.java
@@ -84,6 +84,11 @@
boolean usingFallbackIcon;
/**
+ * Indicates whether we're using a low res icon
+ */
+ boolean usingLowResIcon;
+
+ /**
* If isShortcut=true and customIcon=false, this contains a reference to the
* shortcut icon as an application's resource.
*/
@@ -192,7 +197,8 @@
public void updateIcon(IconCache iconCache) {
if (itemType == Favorites.ITEM_TYPE_APPLICATION) {
- iconCache.getTitleAndIcon(this, promisedIntent != null ? promisedIntent : intent, user);
+ iconCache.getTitleAndIcon(this, promisedIntent != null ? promisedIntent : intent, user,
+ shouldUseLowResIcon());
}
}
@@ -264,5 +270,9 @@
mInstallProgress = progress;
status |= FLAG_INSTALL_SESSION_ACTIVE;
}
+
+ public boolean shouldUseLowResIcon() {
+ return usingLowResIcon && container >= 0 && rank >= FolderIcon.NUM_ITEMS_IN_PREVIEW;
+ }
}
diff --git a/src/com/android/launcher3/Stats.java b/src/com/android/launcher3/Stats.java
index a879865..9d06f75 100644
--- a/src/com/android/launcher3/Stats.java
+++ b/src/com/android/launcher3/Stats.java
@@ -22,14 +22,8 @@
import android.content.IntentFilter;
import android.util.Log;
-import java.io.*;
-import java.util.ArrayList;
-
public class Stats {
private static final boolean DEBUG_BROADCASTS = false;
- private static final String TAG = "Launcher3/Stats";
-
- private static final boolean LOCAL_LAUNCH_LOG = true;
public static final String ACTION_LAUNCH = "com.android.launcher3.action.LAUNCH";
public static final String EXTRA_INTENT = "intent";
@@ -38,54 +32,20 @@
public static final String EXTRA_CELLX = "cellX";
public static final String EXTRA_CELLY = "cellY";
- private static final int LOG_VERSION = 1;
- private static final int LOG_TAG_VERSION = 0x1;
- private static final int LOG_TAG_LAUNCH = 0x1000;
-
- private static final int STATS_VERSION = 1;
- private static final int INITIAL_STATS_SIZE = 100;
-
- // TODO: delayed/batched writes
- private static final boolean FLUSH_IMMEDIATELY = true;
-
private final Launcher mLauncher;
-
private final String mLaunchBroadcastPermission;
- DataOutputStream mLog;
-
- ArrayList<String> mIntents;
- ArrayList<Integer> mHistogram;
-
public Stats(Launcher launcher) {
mLauncher = launcher;
-
mLaunchBroadcastPermission =
launcher.getResources().getString(R.string.receive_launch_broadcasts_permission);
- loadStats();
-
- if (LOCAL_LAUNCH_LOG) {
- try {
- mLog = new DataOutputStream(mLauncher.openFileOutput(
- LauncherFiles.LAUNCHES_LOG, Context.MODE_APPEND));
- mLog.writeInt(LOG_TAG_VERSION);
- mLog.writeInt(LOG_VERSION);
- } catch (FileNotFoundException e) {
- Log.e(TAG, "unable to create stats log: " + e);
- mLog = null;
- } catch (IOException e) {
- Log.e(TAG, "unable to write to stats log: " + e);
- mLog = null;
- }
- }
-
if (DEBUG_BROADCASTS) {
launcher.registerReceiver(
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- android.util.Log.v("Stats", "got broadcast: " + intent + " for launched intent: "
+ Log.v("Stats", "got broadcast: " + intent + " for launched intent: "
+ intent.getStringExtra(EXTRA_INTENT));
}
},
@@ -96,16 +56,6 @@
}
}
- public void incrementLaunch(String intentStr) {
- int pos = mIntents.indexOf(intentStr);
- if (pos < 0) {
- mIntents.add(intentStr);
- mHistogram.add(1);
- } else {
- mHistogram.set(pos, mHistogram.get(pos) + 1);
- }
- }
-
public void recordLaunch(Intent intent) {
recordLaunch(intent, null);
}
@@ -115,7 +65,6 @@
intent.setSourceBounds(null);
final String flat = intent.toUri(0);
-
Intent broadcastIntent = new Intent(ACTION_LAUNCH).putExtra(EXTRA_INTENT, flat);
if (shortcut != null) {
broadcastIntent.putExtra(EXTRA_CONTAINER, shortcut.container)
@@ -124,94 +73,5 @@
.putExtra(EXTRA_CELLY, shortcut.cellY);
}
mLauncher.sendBroadcast(broadcastIntent, mLaunchBroadcastPermission);
-
- incrementLaunch(flat);
-
- if (FLUSH_IMMEDIATELY) {
- saveStats();
- }
-
- if (LOCAL_LAUNCH_LOG && mLog != null) {
- try {
- mLog.writeInt(LOG_TAG_LAUNCH);
- mLog.writeLong(System.currentTimeMillis());
- if (shortcut == null) {
- mLog.writeShort(0);
- mLog.writeShort(0);
- mLog.writeShort(0);
- mLog.writeShort(0);
- } else {
- mLog.writeShort((short) shortcut.container);
- mLog.writeShort((short) shortcut.screenId);
- mLog.writeShort((short) shortcut.cellX);
- mLog.writeShort((short) shortcut.cellY);
- }
- mLog.writeUTF(flat);
- if (FLUSH_IMMEDIATELY) {
- mLog.flush(); // TODO: delayed writes
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- private void saveStats() {
- DataOutputStream stats = null;
- try {
- stats = new DataOutputStream(mLauncher.openFileOutput(
- LauncherFiles.STATS_LOG + ".tmp", Context.MODE_PRIVATE));
- stats.writeInt(STATS_VERSION);
- final int N = mHistogram.size();
- stats.writeInt(N);
- for (int i=0; i<N; i++) {
- stats.writeUTF(mIntents.get(i));
- stats.writeInt(mHistogram.get(i));
- }
- stats.close();
- stats = null;
- mLauncher.getFileStreamPath(LauncherFiles.STATS_LOG + ".tmp")
- .renameTo(mLauncher.getFileStreamPath(LauncherFiles.STATS_LOG));
- } catch (FileNotFoundException e) {
- Log.e(TAG, "unable to create stats data: " + e);
- } catch (IOException e) {
- Log.e(TAG, "unable to write to stats data: " + e);
- } finally {
- if (stats != null) {
- try {
- stats.close();
- } catch (IOException e) { }
- }
- }
- }
-
- private void loadStats() {
- mIntents = new ArrayList<String>(INITIAL_STATS_SIZE);
- mHistogram = new ArrayList<Integer>(INITIAL_STATS_SIZE);
- DataInputStream stats = null;
- try {
- stats = new DataInputStream(mLauncher.openFileInput(LauncherFiles.STATS_LOG));
- final int version = stats.readInt();
- if (version == STATS_VERSION) {
- final int N = stats.readInt();
- for (int i=0; i<N; i++) {
- final String pkg = stats.readUTF();
- final int count = stats.readInt();
- mIntents.add(pkg);
- mHistogram.add(count);
- }
- }
- } catch (FileNotFoundException e) {
- // not a problem
- } catch (IOException e) {
- // more of a problem
-
- } finally {
- if (stats != null) {
- try {
- stats.close();
- } catch (IOException e) { }
- }
- }
}
}
diff --git a/src/com/android/launcher3/UninstallShortcutReceiver.java b/src/com/android/launcher3/UninstallShortcutReceiver.java
index c9d0bb5..59e4cb5 100644
--- a/src/com/android/launcher3/UninstallShortcutReceiver.java
+++ b/src/com/android/launcher3/UninstallShortcutReceiver.java
@@ -17,117 +17,11 @@
package com.android.launcher3;
import android.content.BroadcastReceiver;
-import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
-import android.database.Cursor;
-import android.net.Uri;
-import android.widget.Toast;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Iterator;
-
+//TODO: Remove this
public class UninstallShortcutReceiver extends BroadcastReceiver {
- private static final String ACTION_UNINSTALL_SHORTCUT =
- "com.android.launcher.action.UNINSTALL_SHORTCUT";
-
- // The set of shortcuts that are pending uninstall
- private static ArrayList<PendingUninstallShortcutInfo> mUninstallQueue =
- new ArrayList<PendingUninstallShortcutInfo>();
-
- // Determines whether to defer uninstalling shortcuts immediately until
- // disableAndFlushUninstallQueue() is called.
- private static boolean mUseUninstallQueue = false;
-
- private static class PendingUninstallShortcutInfo {
- Intent data;
-
- public PendingUninstallShortcutInfo(Intent rawData) {
- data = rawData;
- }
- }
-
- public void onReceive(Context context, Intent data) {
- if (!ACTION_UNINSTALL_SHORTCUT.equals(data.getAction())) {
- return;
- }
-
- PendingUninstallShortcutInfo info = new PendingUninstallShortcutInfo(data);
- if (mUseUninstallQueue) {
- mUninstallQueue.add(info);
- } else {
- processUninstallShortcut(context, info);
- }
- }
-
- static void enableUninstallQueue() {
- mUseUninstallQueue = true;
- }
-
- static void disableAndFlushUninstallQueue(Context context) {
- mUseUninstallQueue = false;
- Iterator<PendingUninstallShortcutInfo> iter = mUninstallQueue.iterator();
- while (iter.hasNext()) {
- processUninstallShortcut(context, iter.next());
- iter.remove();
- }
- }
-
- private static void processUninstallShortcut(Context context,
- PendingUninstallShortcutInfo pendingInfo) {
- final Intent data = pendingInfo.data;
-
- LauncherAppState.setApplicationContext(context.getApplicationContext());
- LauncherAppState app = LauncherAppState.getInstance();
- synchronized (app) { // TODO: make removeShortcut internally threadsafe
- removeShortcut(context, data);
- }
- }
-
- private static void removeShortcut(Context context, Intent data) {
- Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
- String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
- boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);
-
- if (intent != null && name != null) {
- final ContentResolver cr = context.getContentResolver();
- Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
- new String[] { LauncherSettings.Favorites._ID, LauncherSettings.Favorites.INTENT },
- LauncherSettings.Favorites.TITLE + "=?", new String[] { name }, null);
-
- final int intentIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT);
- final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
-
- boolean changed = false;
-
- try {
- while (c.moveToNext()) {
- try {
- String intentStr = c.getString(intentIndex);
- if (intentStr != null
- && intent.filterEquals(Intent.parseUri(intentStr, 0))) {
- final long id = c.getLong(idIndex);
- final Uri uri = LauncherSettings.Favorites.getContentUri(id, false);
- cr.delete(uri, null, null);
- changed = true;
- if (!duplicate) {
- break;
- }
- }
- } catch (URISyntaxException e) {
- // Ignore
- }
- }
- } finally {
- c.close();
- }
-
- if (changed) {
- cr.notifyChange(LauncherSettings.Favorites.CONTENT_URI, null);
- Toast.makeText(context, context.getString(R.string.shortcut_uninstalled, name),
- Toast.LENGTH_SHORT).show();
- }
- }
- }
+ @Override
+ public void onReceive(Context context, Intent data) { }
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 497b438..22677c8 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -50,6 +50,8 @@
import android.view.View;
import android.widget.Toast;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
@@ -555,6 +557,25 @@
return defaultWidgetForSearchPackage;
}
+ /**
+ * Compresses the bitmap to a byte array for serialization.
+ */
+ public static byte[] flattenBitmap(Bitmap bitmap) {
+ // Try go guesstimate how much space the icon will take when serialized
+ // to avoid unnecessary allocations/copies during the write.
+ int size = bitmap.getWidth() * bitmap.getHeight() * 4;
+ ByteArrayOutputStream out = new ByteArrayOutputStream(size);
+ try {
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
+ out.flush();
+ out.close();
+ return out.toByteArray();
+ } catch (IOException e) {
+ Log.w(TAG, "Could not write bitmap");
+ return null;
+ }
+ }
+
public static final Comparator<ItemInfo> RANK_COMPARATOR = new Comparator<ItemInfo>() {
@Override
diff --git a/src/com/android/launcher3/WeightWatcher.java b/src/com/android/launcher3/WeightWatcher.java
index 70b8afe..7568479 100644
--- a/src/com/android/launcher3/WeightWatcher.java
+++ b/src/com/android/launcher3/WeightWatcher.java
@@ -34,6 +34,8 @@
import android.widget.LinearLayout;
import android.widget.TextView;
+import com.android.launcher3.util.Thunk;
+
public class WeightWatcher extends LinearLayout {
private static final int RAM_GRAPH_RSS_COLOR = 0xFF990000;
private static final int RAM_GRAPH_PSS_COLOR = 0xFF99CC00;
@@ -81,7 +83,7 @@
}
}
};
- private MemoryTracker mMemoryService;
+ @Thunk MemoryTracker mMemoryService;
public WeightWatcher(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -134,7 +136,7 @@
GraphView mRamGraph;
TextView mText;
int mPid;
- private MemoryTracker.ProcessMemInfo mMemInfo;
+ @Thunk MemoryTracker.ProcessMemInfo mMemInfo;
public ProcessWatcher(Context context) {
this(context, null);
diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java
index d963f2d..1043e2e 100644
--- a/src/com/android/launcher3/WidgetPreviewLoader.java
+++ b/src/com/android/launcher3/WidgetPreviewLoader.java
@@ -1,524 +1,359 @@
package com.android.launcher3;
-import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
-import android.content.SharedPreferences;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.database.Cursor;
-import android.database.sqlite.SQLiteCantOpenDatabaseException;
+import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteDiskIOException;
import android.database.sqlite.SQLiteOpenHelper;
-import android.database.sqlite.SQLiteReadOnlyDatabaseException;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
-import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.Rect;
-import android.graphics.Shader;
+import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
-import android.os.Build;
import android.util.Log;
-import com.android.launcher3.compat.AppWidgetManagerCompat;
+import android.util.LongSparseArray;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.lang.ref.SoftReference;
+import com.android.launcher3.compat.AppWidgetManagerCompat;
+import com.android.launcher3.compat.UserHandleCompat;
+import com.android.launcher3.compat.UserManagerCompat;
+import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.util.Thunk;
+
import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
+import java.util.Set;
+import java.util.WeakHashMap;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
public class WidgetPreviewLoader {
- private static abstract class SoftReferenceThreadLocal<T> {
- private ThreadLocal<SoftReference<T>> mThreadLocal;
- public SoftReferenceThreadLocal() {
- mThreadLocal = new ThreadLocal<SoftReference<T>>();
- }
-
- abstract T initialValue();
-
- public void set(T t) {
- mThreadLocal.set(new SoftReference<T>(t));
- }
-
- public T get() {
- SoftReference<T> reference = mThreadLocal.get();
- T obj;
- if (reference == null) {
- obj = initialValue();
- mThreadLocal.set(new SoftReference<T>(obj));
- return obj;
- } else {
- obj = reference.get();
- if (obj == null) {
- obj = initialValue();
- mThreadLocal.set(new SoftReference<T>(obj));
- }
- return obj;
- }
- }
- }
-
- private static class CanvasCache extends SoftReferenceThreadLocal<Canvas> {
- @Override
- protected Canvas initialValue() {
- return new Canvas();
- }
- }
-
- private static class PaintCache extends SoftReferenceThreadLocal<Paint> {
- @Override
- protected Paint initialValue() {
- return null;
- }
- }
-
- private static class BitmapCache extends SoftReferenceThreadLocal<Bitmap> {
- @Override
- protected Bitmap initialValue() {
- return null;
- }
- }
-
- private static class RectCache extends SoftReferenceThreadLocal<Rect> {
- @Override
- protected Rect initialValue() {
- return new Rect();
- }
- }
-
- private static class BitmapFactoryOptionsCache extends
- SoftReferenceThreadLocal<BitmapFactory.Options> {
- @Override
- protected BitmapFactory.Options initialValue() {
- return new BitmapFactory.Options();
- }
- }
-
private static final String TAG = "WidgetPreviewLoader";
- private static final String ANDROID_INCREMENTAL_VERSION_NAME_KEY = "android.incremental.version";
private static final float WIDGET_PREVIEW_ICON_PADDING_PERCENTAGE = 0.25f;
- private static final HashSet<String> sInvalidPackages = new HashSet<String>();
- // Used for drawing shortcut previews
- private final BitmapCache mCachedShortcutPreviewBitmap = new BitmapCache();
- private final PaintCache mCachedShortcutPreviewPaint = new PaintCache();
- private final CanvasCache mCachedShortcutPreviewCanvas = new CanvasCache();
-
- // Used for drawing widget previews
- private final CanvasCache mCachedAppWidgetPreviewCanvas = new CanvasCache();
- private final RectCache mCachedAppWidgetPreviewSrcRect = new RectCache();
- private final RectCache mCachedAppWidgetPreviewDestRect = new RectCache();
- private final PaintCache mCachedAppWidgetPreviewPaint = new PaintCache();
- private final PaintCache mDefaultAppWidgetPreviewPaint = new PaintCache();
- private final BitmapFactoryOptionsCache mCachedBitmapFactoryOptions = new BitmapFactoryOptionsCache();
-
- private final HashMap<String, WeakReference<Bitmap>> mLoadedPreviews = new HashMap<String, WeakReference<Bitmap>>();
- private final ArrayList<SoftReference<Bitmap>> mUnusedBitmaps = new ArrayList<SoftReference<Bitmap>>();
+ private final HashMap<String, long[]> mPackageVersions = new HashMap<>();
+ private final HashMap<WidgetCacheKey, WeakReference<Bitmap>> mLoadedPreviews = new HashMap<>();
+ private Set<Bitmap> mUnusedBitmaps = Collections.newSetFromMap(new WeakHashMap<Bitmap, Boolean>());
private final Context mContext;
- private final int mAppIconSize;
private final IconCache mIconCache;
+ private final UserManagerCompat mUserManager;
private final AppWidgetManagerCompat mManager;
-
- private int mPreviewBitmapWidth;
- private int mPreviewBitmapHeight;
- private String mSize;
- private PagedViewCellLayout mWidgetSpacingLayout;
-
- private String mCachedSelectQuery;
-
-
- private CacheDb mDb;
+ private final CacheDb mDb;
private final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
- public WidgetPreviewLoader(Context context) {
- LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
-
+ public WidgetPreviewLoader(Context context, IconCache iconCache) {
mContext = context;
- mAppIconSize = grid.iconSizePx;
- mIconCache = app.getIconCache();
+ mIconCache = iconCache;
mManager = AppWidgetManagerCompat.getInstance(context);
-
- mDb = app.getWidgetPreviewCacheDb();
-
- SharedPreferences sp = context.getSharedPreferences(
- LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
- final String lastVersionName = sp.getString(ANDROID_INCREMENTAL_VERSION_NAME_KEY, null);
- final String versionName = android.os.Build.VERSION.INCREMENTAL;
- final boolean isLollipopOrGreater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
- if (!versionName.equals(lastVersionName)) {
- try {
- // clear all the previews whenever the system version changes, to ensure that
- // previews are up-to-date for any apps that might have been updated with the system
- clearDb();
- } catch (SQLiteReadOnlyDatabaseException e) {
- if (isLollipopOrGreater) {
- // Workaround for Bug. 18554839, if we fail to clear the db due to the read-only
- // issue, then ignore this error and leave the old previews
- } else {
- throw e;
- }
- } finally {
- SharedPreferences.Editor editor = sp.edit();
- editor.putString(ANDROID_INCREMENTAL_VERSION_NAME_KEY, versionName);
- editor.commit();
- }
- }
+ mUserManager = UserManagerCompat.getInstance(context);
+ mDb = new CacheDb(context);
}
- public void recreateDb() {
- LauncherAppState app = LauncherAppState.getInstance();
- app.recreateWidgetPreviewDb();
- mDb = app.getWidgetPreviewCacheDb();
- }
+ /**
+ * Generates the widget preview on {@link AsyncTask#THREAD_POOL_EXECUTOR}. Must be
+ * called on UI thread
+ *
+ * @param o either {@link LauncherAppWidgetProviderInfo} or {@link ResolveInfo}
+ * @param immediateResult A bitmap array of size 1. If the result is already cached, it is
+ * set to the final result.
+ * @return a request id which can be used to cancel the request.
+ */
+ public PreviewLoadRequest getPreview(final Object o, int previewWidth, int previewHeight,
+ PagedViewWidget caller, Bitmap[] immediateResult) {
+ String size = previewWidth + "x" + previewHeight;
+ WidgetCacheKey key = getObjectKey(o, size);
- public void setPreviewSize(int previewWidth, int previewHeight,
- PagedViewCellLayout widgetSpacingLayout) {
- mPreviewBitmapWidth = previewWidth;
- mPreviewBitmapHeight = previewHeight;
- mSize = previewWidth + "x" + previewHeight;
- mWidgetSpacingLayout = widgetSpacingLayout;
- }
-
- public Bitmap getPreview(final Object o) {
- final String name = getObjectName(o);
- final String packageName = getObjectPackage(o);
- // check if the package is valid
- synchronized(sInvalidPackages) {
- boolean packageValid = !sInvalidPackages.contains(packageName);
- if (!packageValid) {
- return null;
- }
- }
- synchronized(mLoadedPreviews) {
- // check if it exists in our existing cache
- if (mLoadedPreviews.containsKey(name)) {
- WeakReference<Bitmap> bitmapReference = mLoadedPreviews.get(name);
- Bitmap bitmap = bitmapReference.get();
- if (bitmap != null) {
- return bitmap;
- }
- }
- }
-
- Bitmap unusedBitmap = null;
- synchronized(mUnusedBitmaps) {
- // not in cache; we need to load it from the db
- while (unusedBitmap == null && mUnusedBitmaps.size() > 0) {
- Bitmap candidate = mUnusedBitmaps.remove(0).get();
- if (candidate != null && candidate.isMutable() &&
- candidate.getWidth() == mPreviewBitmapWidth &&
- candidate.getHeight() == mPreviewBitmapHeight) {
- unusedBitmap = candidate;
- }
- }
- if (unusedBitmap != null) {
- final Canvas c = mCachedAppWidgetPreviewCanvas.get();
- c.setBitmap(unusedBitmap);
- c.drawColor(0, PorterDuff.Mode.CLEAR);
- c.setBitmap(null);
- }
- }
-
- if (unusedBitmap == null) {
- unusedBitmap = Bitmap.createBitmap(mPreviewBitmapWidth, mPreviewBitmapHeight,
- Bitmap.Config.ARGB_8888);
- }
- Bitmap preview = readFromDb(name, unusedBitmap);
-
- if (preview != null) {
- synchronized(mLoadedPreviews) {
- mLoadedPreviews.put(name, new WeakReference<Bitmap>(preview));
- }
- return preview;
- } else {
- // it's not in the db... we need to generate it
- final Bitmap generatedPreview = generatePreview(o, unusedBitmap);
- preview = generatedPreview;
- if (preview != unusedBitmap) {
- throw new RuntimeException("generatePreview is not recycling the bitmap " + o);
- }
-
- synchronized(mLoadedPreviews) {
- mLoadedPreviews.put(name, new WeakReference<Bitmap>(preview));
- }
-
- // write to db on a thread pool... this can be done lazily and improves the performance
- // of the first time widget previews are loaded
- new AsyncTask<Void, Void, Void>() {
- public Void doInBackground(Void ... args) {
- writeToDb(o, generatedPreview);
- return null;
- }
- }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
-
- return preview;
- }
- }
-
- public void recycleBitmap(Object o, Bitmap bitmapToRecycle) {
- String name = getObjectName(o);
+ // Check if we have the preview loaded or not.
synchronized (mLoadedPreviews) {
- if (mLoadedPreviews.containsKey(name)) {
- Bitmap b = mLoadedPreviews.get(name).get();
- if (b == bitmapToRecycle) {
- mLoadedPreviews.remove(name);
- if (bitmapToRecycle.isMutable()) {
- synchronized (mUnusedBitmaps) {
- mUnusedBitmaps.add(new SoftReference<Bitmap>(b));
- }
- }
- } else {
- throw new RuntimeException("Bitmap passed in doesn't match up");
- }
+ WeakReference<Bitmap> ref = mLoadedPreviews.get(key);
+ if (ref != null && ref.get() != null) {
+ immediateResult[0] = ref.get();
+ return new PreviewLoadRequest(null, key);
}
}
+
+ PreviewLoadTask task = new PreviewLoadTask(key, o, previewWidth, previewHeight, caller);
+ task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ return new PreviewLoadRequest(task, key);
}
- static class CacheDb extends SQLiteOpenHelper {
- final static int DB_VERSION = 2;
- final static String TABLE_NAME = "shortcut_and_widget_previews";
- final static String COLUMN_NAME = "name";
- final static String COLUMN_SIZE = "size";
- final static String COLUMN_PREVIEW_BITMAP = "preview_bitmap";
- Context mContext;
+ /**
+ * The DB holds the generated previews for various components. Previews can also have different
+ * sizes (landscape vs portrait).
+ */
+ private static class CacheDb extends SQLiteOpenHelper {
+ private static final int DB_VERSION = 3;
+
+ private static final String TABLE_NAME = "shortcut_and_widget_previews";
+ private static final String COLUMN_COMPONENT = "componentName";
+ private static final String COLUMN_USER = "profileId";
+ private static final String COLUMN_SIZE = "size";
+ private static final String COLUMN_PACKAGE = "packageName";
+ private static final String COLUMN_LAST_UPDATED = "lastUpdated";
+ private static final String COLUMN_VERSION = "version";
+ private static final String COLUMN_PREVIEW_BITMAP = "preview_bitmap";
public CacheDb(Context context) {
- super(context, new File(context.getCacheDir(),
- LauncherFiles.WIDGET_PREVIEWS_DB).getPath(), null, DB_VERSION);
- // Store the context for later use
- mContext = context;
+ super(context, LauncherFiles.WIDGET_PREVIEWS_DB, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" +
- COLUMN_NAME + " TEXT NOT NULL, " +
+ COLUMN_COMPONENT + " TEXT NOT NULL, " +
+ COLUMN_USER + " INTEGER NOT NULL, " +
COLUMN_SIZE + " TEXT NOT NULL, " +
- COLUMN_PREVIEW_BITMAP + " BLOB NOT NULL, " +
- "PRIMARY KEY (" + COLUMN_NAME + ", " + COLUMN_SIZE + ") " +
+ COLUMN_PACKAGE + " TEXT NOT NULL, " +
+ COLUMN_LAST_UPDATED + " INTEGER NOT NULL DEFAULT 0, " +
+ COLUMN_VERSION + " INTEGER NOT NULL DEFAULT 0, " +
+ COLUMN_PREVIEW_BITMAP + " BLOB, " +
+ "PRIMARY KEY (" + COLUMN_COMPONENT + ", " + COLUMN_USER + ", " + COLUMN_SIZE + ") " +
");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion != newVersion) {
- // Delete all the records; they'll be repopulated as this is a cache
- db.execSQL("DELETE FROM " + TABLE_NAME);
+ clearDB(db);
}
}
+
+ @Override
+ public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ if (oldVersion != newVersion) {
+ clearDB(db);
+ }
+ }
+
+ private void clearDB(SQLiteDatabase db) {
+ db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
+ onCreate(db);
+ }
}
- private static final String WIDGET_PREFIX = "Widget:";
- private static final String SHORTCUT_PREFIX = "Shortcut:";
-
- private static String getObjectName(Object o) {
+ private WidgetCacheKey getObjectKey(Object o, String size) {
// should cache the string builder
- StringBuilder sb = new StringBuilder();
- String output;
- if (o instanceof AppWidgetProviderInfo) {
- sb.append(WIDGET_PREFIX);
- sb.append(((AppWidgetProviderInfo) o).toString());
- output = sb.toString();
- sb.setLength(0);
- } else {
- sb.append(SHORTCUT_PREFIX);
- ResolveInfo info = (ResolveInfo) o;
- sb.append(new ComponentName(info.activityInfo.packageName,
- info.activityInfo.name).flattenToString());
- output = sb.toString();
- sb.setLength(0);
- }
- return output;
- }
-
- private String getObjectPackage(Object o) {
- if (o instanceof AppWidgetProviderInfo) {
- return ((AppWidgetProviderInfo) o).provider.getPackageName();
+ if (o instanceof LauncherAppWidgetProviderInfo) {
+ LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) o;
+ return new WidgetCacheKey(info.provider, mManager.getUser(info), size);
} else {
ResolveInfo info = (ResolveInfo) o;
- return info.activityInfo.packageName;
+ return new WidgetCacheKey(
+ new ComponentName(info.activityInfo.packageName, info.activityInfo.name),
+ UserHandleCompat.myUserHandle(), size);
}
}
- private void writeToDb(Object o, Bitmap preview) {
- String name = getObjectName(o);
- SQLiteDatabase db = mDb.getWritableDatabase();
+ @Thunk void writeToDb(WidgetCacheKey key, long[] versions, Bitmap preview) {
ContentValues values = new ContentValues();
+ values.put(CacheDb.COLUMN_COMPONENT, key.componentName.flattenToShortString());
+ values.put(CacheDb.COLUMN_USER, mUserManager.getSerialNumberForUser(key.user));
+ values.put(CacheDb.COLUMN_SIZE, key.size);
+ values.put(CacheDb.COLUMN_PACKAGE, key.componentName.getPackageName());
+ values.put(CacheDb.COLUMN_VERSION, versions[0]);
+ values.put(CacheDb.COLUMN_LAST_UPDATED, versions[1]);
+ values.put(CacheDb.COLUMN_PREVIEW_BITMAP, Utilities.flattenBitmap(preview));
- values.put(CacheDb.COLUMN_NAME, name);
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- preview.compress(Bitmap.CompressFormat.PNG, 100, stream);
- values.put(CacheDb.COLUMN_PREVIEW_BITMAP, stream.toByteArray());
- values.put(CacheDb.COLUMN_SIZE, mSize);
try {
- db.insert(CacheDb.TABLE_NAME, null, values);
- } catch (SQLiteDiskIOException e) {
- recreateDb();
- } catch (SQLiteCantOpenDatabaseException e) {
- dumpOpenFiles();
- throw e;
+ mDb.getWritableDatabase().insertWithOnConflict(CacheDb.TABLE_NAME, null, values,
+ SQLiteDatabase.CONFLICT_REPLACE);
+ } catch (SQLException e) {
+ Log.e(TAG, "Error saving image to DB", e);
}
}
- private void clearDb() {
- SQLiteDatabase db = mDb.getWritableDatabase();
- // Delete everything
+ public void removePackage(String packageName, UserHandleCompat user) {
+ removePackage(packageName, user, mUserManager.getSerialNumberForUser(user));
+ }
+
+ private void removePackage(String packageName, UserHandleCompat user, long userSerial) {
+ synchronized(mPackageVersions) {
+ mPackageVersions.remove(packageName);
+ }
+
+ synchronized (mLoadedPreviews) {
+ Set<WidgetCacheKey> keysToRemove = new HashSet<>();
+ for (WidgetCacheKey key : mLoadedPreviews.keySet()) {
+ if (key.componentName.getPackageName().equals(packageName) && key.user.equals(user)) {
+ keysToRemove.add(key);
+ }
+ }
+
+ for (WidgetCacheKey key : keysToRemove) {
+ WeakReference<Bitmap> req = mLoadedPreviews.remove(key);
+ if (req != null && req.get() != null) {
+ mUnusedBitmaps.add(req.get());
+ }
+ }
+ }
+
try {
- db.delete(CacheDb.TABLE_NAME, null, null);
- } catch (SQLiteDiskIOException e) {
- } catch (SQLiteCantOpenDatabaseException e) {
- dumpOpenFiles();
- throw e;
+ mDb.getWritableDatabase().delete(CacheDb.TABLE_NAME,
+ CacheDb.COLUMN_PACKAGE + " = ? AND " + CacheDb.COLUMN_USER + " = ?",
+ new String[] {packageName, Long.toString(userSerial)});
+ } catch (SQLException e) {
+ Log.e(TAG, "Unable to delete items from DB", e);
}
}
- public static void removePackageFromDb(final CacheDb cacheDb, final String packageName) {
- synchronized(sInvalidPackages) {
- sInvalidPackages.add(packageName);
+ /**
+ * Updates the persistent DB:
+ * 1. Any preview generated for an old package version is removed
+ * 2. Any preview for an absent package is removed
+ * This ensures that we remove entries for packages which changed while the launcher was dead.
+ */
+ public void removeObsoletePreviews() {
+ LongSparseArray<UserHandleCompat> userIdCache = new LongSparseArray<>();
+ LongSparseArray<HashSet<String>> validPackages = new LongSparseArray<>();
+
+ for (Object obj : LauncherModel.getSortedWidgetsAndShortcuts(mContext, false)) {
+ final UserHandleCompat user;
+ final String pkg;
+ if (obj instanceof ResolveInfo) {
+ user = UserHandleCompat.myUserHandle();
+ pkg = ((ResolveInfo) obj).activityInfo.packageName;
+ } else {
+ LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) obj;
+ user = mManager.getUser(info);
+ pkg = info.provider.getPackageName();
+ }
+
+ int userIdIndex = userIdCache.indexOfValue(user);
+ final long userId;
+ if (userIdIndex < 0) {
+ userId = mUserManager.getSerialNumberForUser(user);
+ userIdCache.put(userId, user);
+ } else {
+ userId = userIdCache.keyAt(userIdIndex);
+ }
+
+ HashSet<String> packages = validPackages.get(userId);
+ if (packages == null) {
+ packages = new HashSet<>();
+ validPackages.put(userId, packages);
+ }
+ packages.add(pkg);
}
- new AsyncTask<Void, Void, Void>() {
- public Void doInBackground(Void ... args) {
- SQLiteDatabase db = cacheDb.getWritableDatabase();
+
+ LongSparseArray<HashSet<String>> packagesToDelete = new LongSparseArray<>();
+ Cursor c = null;
+ try {
+ c = mDb.getReadableDatabase().query(CacheDb.TABLE_NAME,
+ new String[] {CacheDb.COLUMN_USER, CacheDb.COLUMN_PACKAGE,
+ CacheDb.COLUMN_LAST_UPDATED, CacheDb.COLUMN_VERSION},
+ null, null, null, null, null);
+ while (c.moveToNext()) {
+ long userId = c.getLong(0);
+ String pkg = c.getString(1);
+ long lastUpdated = c.getLong(2);
+ long version = c.getLong(3);
+
+ HashSet<String> packages = validPackages.get(userId);
+ if (packages != null && packages.contains(pkg)) {
+ long[] versions = getPackageVersion(pkg);
+ if (versions[0] == version && versions[1] == lastUpdated) {
+ // Every thing checks out
+ continue;
+ }
+ }
+
+ // We need to delete this package.
+ packages = packagesToDelete.get(userId);
+ if (packages == null) {
+ packages = new HashSet<>();
+ packagesToDelete.put(userId, packages);
+ }
+ packages.add(pkg);
+ }
+
+ for (int i = 0; i < packagesToDelete.size(); i++) {
+ long userId = packagesToDelete.keyAt(i);
+ UserHandleCompat user = mUserManager.getUserForSerialNumber(userId);
+ for (String pkg : packagesToDelete.valueAt(i)) {
+ removePackage(pkg, user, userId);
+ }
+ }
+ } catch (SQLException e) {
+ Log.e(TAG, "Error updatating widget previews", e);
+ } finally {
+ if (c != null) {
+ c.close();
+ }
+ }
+ }
+
+ private Bitmap readFromDb(WidgetCacheKey key, Bitmap recycle) {
+ Cursor cursor = null;
+ try {
+ cursor = mDb.getReadableDatabase().query(
+ CacheDb.TABLE_NAME,
+ new String[] { CacheDb.COLUMN_PREVIEW_BITMAP },
+ CacheDb.COLUMN_COMPONENT + " = ? AND " + CacheDb.COLUMN_USER + " = ? AND " + CacheDb.COLUMN_SIZE + " = ?",
+ new String[] {
+ key.componentName.flattenToString(),
+ Long.toString(mUserManager.getSerialNumberForUser(key.user)),
+ key.size
+ },
+ null, null, null);
+ if (cursor.moveToNext()) {
+ byte[] blob = cursor.getBlob(0);
+ BitmapFactory.Options opts = new BitmapFactory.Options();
+ opts.inBitmap = recycle;
try {
- db.delete(CacheDb.TABLE_NAME,
- CacheDb.COLUMN_NAME + " LIKE ? OR " +
- CacheDb.COLUMN_NAME + " LIKE ?", // SELECT query
- new String[] {
- WIDGET_PREFIX + packageName + "/%",
- SHORTCUT_PREFIX + packageName + "/%"
- } // args to SELECT query
- );
- } catch (SQLiteDiskIOException e) {
- } catch (SQLiteCantOpenDatabaseException e) {
- dumpOpenFiles();
- throw e;
+ return BitmapFactory.decodeByteArray(blob, 0, blob.length, opts);
+ } catch (Exception e) {
+ return null;
}
- synchronized(sInvalidPackages) {
- sInvalidPackages.remove(packageName);
- }
- return null;
}
- }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
+ } catch (SQLException e) {
+ Log.w(TAG, "Error loading preview from DB", e);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ }
+ return null;
}
- private static void removeItemFromDb(final CacheDb cacheDb, final String objectName) {
- new AsyncTask<Void, Void, Void>() {
- public Void doInBackground(Void ... args) {
- SQLiteDatabase db = cacheDb.getWritableDatabase();
- try {
- db.delete(CacheDb.TABLE_NAME,
- CacheDb.COLUMN_NAME + " = ? ", // SELECT query
- new String[] { objectName }); // args to SELECT query
- } catch (SQLiteDiskIOException e) {
- } catch (SQLiteCantOpenDatabaseException e) {
- dumpOpenFiles();
- throw e;
- }
- return null;
- }
- }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
- }
-
- private Bitmap readFromDb(String name, Bitmap b) {
- if (mCachedSelectQuery == null) {
- mCachedSelectQuery = CacheDb.COLUMN_NAME + " = ? AND " +
- CacheDb.COLUMN_SIZE + " = ?";
- }
- SQLiteDatabase db = mDb.getReadableDatabase();
- Cursor result;
- try {
- result = db.query(CacheDb.TABLE_NAME,
- new String[] { CacheDb.COLUMN_PREVIEW_BITMAP }, // cols to return
- mCachedSelectQuery, // select query
- new String[] { name, mSize }, // args to select query
- null,
- null,
- null,
- null);
- } catch (SQLiteDiskIOException e) {
- recreateDb();
- return null;
- } catch (SQLiteCantOpenDatabaseException e) {
- dumpOpenFiles();
- throw e;
- }
- if (result.getCount() > 0) {
- result.moveToFirst();
- byte[] blob = result.getBlob(0);
- result.close();
- final BitmapFactory.Options opts = mCachedBitmapFactoryOptions.get();
- opts.inBitmap = b;
- opts.inSampleSize = 1;
- try {
- return BitmapFactory.decodeByteArray(blob, 0, blob.length, opts);
- } catch (IllegalArgumentException e) {
- removeItemFromDb(mDb, name);
- return null;
- }
- } else {
- result.close();
- return null;
- }
- }
-
- private Bitmap generatePreview(Object info, Bitmap preview) {
- if (preview != null &&
- (preview.getWidth() != mPreviewBitmapWidth ||
- preview.getHeight() != mPreviewBitmapHeight)) {
- throw new RuntimeException("Improperly sized bitmap passed as argument");
- }
+ private Bitmap generatePreview(Object info, Bitmap recycle, int previewWidth, int previewHeight) {
if (info instanceof LauncherAppWidgetProviderInfo) {
- return generateWidgetPreview((LauncherAppWidgetProviderInfo) info, preview);
+ return generateWidgetPreview((LauncherAppWidgetProviderInfo) info, previewWidth, recycle);
} else {
return generateShortcutPreview(
- (ResolveInfo) info, mPreviewBitmapWidth, mPreviewBitmapHeight, preview);
+ (ResolveInfo) info, previewWidth, previewHeight, recycle);
}
}
- public Bitmap generateWidgetPreview(LauncherAppWidgetProviderInfo info, Bitmap preview) {
- int maxWidth = maxWidthForWidgetPreview(info.spanX);
- int maxHeight = maxHeightForWidgetPreview(info.spanY);
- return generateWidgetPreview(info, info.spanX, info.spanY, maxWidth,
- maxHeight, preview, null);
+ public Bitmap generateWidgetPreview(LauncherAppWidgetProviderInfo info,
+ int previewWidth, Bitmap preview) {
+ int maxWidth = Math.min(previewWidth, info.spanX
+ * LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile().cellWidthPx);
+ return generateWidgetPreview(info, maxWidth, preview, null);
}
- public int maxWidthForWidgetPreview(int spanX) {
- return Math.min(mPreviewBitmapWidth,
- mWidgetSpacingLayout.estimateCellWidth(spanX));
- }
-
- public int maxHeightForWidgetPreview(int spanY) {
- return Math.min(mPreviewBitmapHeight,
- mWidgetSpacingLayout.estimateCellHeight(spanY));
- }
-
- public Bitmap generateWidgetPreview(LauncherAppWidgetProviderInfo info, int cellHSpan, int cellVSpan,
- int maxPreviewWidth, int maxPreviewHeight, Bitmap preview, int[] preScaledWidthOut) {
+ public Bitmap generateWidgetPreview(LauncherAppWidgetProviderInfo info,
+ int maxPreviewWidth, Bitmap preview, int[] preScaledWidthOut) {
// Load the preview image if possible
if (maxPreviewWidth < 0) maxPreviewWidth = Integer.MAX_VALUE;
- if (maxPreviewHeight < 0) maxPreviewHeight = Integer.MAX_VALUE;
Drawable drawable = null;
if (info.previewImage != 0) {
@@ -531,61 +366,23 @@
}
}
+ final boolean widgetPreviewExists = (drawable != null);
+ final int spanX = info.spanX < 1 ? 1 : info.spanX;
+ final int spanY = info.spanY < 1 ? 1 : info.spanY;
+
int previewWidth;
int previewHeight;
- Bitmap defaultPreview = null;
- boolean widgetPreviewExists = (drawable != null);
+ Bitmap tileBitmap = null;
+
if (widgetPreviewExists) {
previewWidth = drawable.getIntrinsicWidth();
previewHeight = drawable.getIntrinsicHeight();
} else {
// Generate a preview image if we couldn't load one
- if (cellHSpan < 1) cellHSpan = 1;
- if (cellVSpan < 1) cellVSpan = 1;
-
- // This Drawable is not directly drawn, so there's no need to mutate it.
- BitmapDrawable previewDrawable = (BitmapDrawable) mContext.getResources()
- .getDrawable(R.drawable.widget_tile);
- final int previewDrawableWidth = previewDrawable
- .getIntrinsicWidth();
- final int previewDrawableHeight = previewDrawable
- .getIntrinsicHeight();
- previewWidth = previewDrawableWidth * cellHSpan;
- previewHeight = previewDrawableHeight * cellVSpan;
-
- defaultPreview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888);
- final Canvas c = mCachedAppWidgetPreviewCanvas.get();
- c.setBitmap(defaultPreview);
- Paint p = mDefaultAppWidgetPreviewPaint.get();
- if (p == null) {
- p = new Paint();
- p.setShader(new BitmapShader(previewDrawable.getBitmap(),
- Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
- mDefaultAppWidgetPreviewPaint.set(p);
- }
- final Rect dest = mCachedAppWidgetPreviewDestRect.get();
- dest.set(0, 0, previewWidth, previewHeight);
- c.drawRect(dest, p);
- c.setBitmap(null);
-
- // Draw the icon in the top left corner
- int minOffset = (int) (mAppIconSize * WIDGET_PREVIEW_ICON_PADDING_PERCENTAGE);
- int smallestSide = Math.min(previewWidth, previewHeight);
- float iconScale = Math.min((float) smallestSide
- / (mAppIconSize + 2 * minOffset), 1f);
-
- try {
- Drawable icon = mManager.loadIcon(info, mIconCache);
- if (icon != null) {
- int hoffset = (int) ((previewDrawableWidth - mAppIconSize * iconScale) / 2);
- int yoffset = (int) ((previewDrawableHeight - mAppIconSize * iconScale) / 2);
- icon = mutateOnMainThread(icon);
- renderDrawableToBitmap(icon, defaultPreview, hoffset,
- yoffset, (int) (mAppIconSize * iconScale),
- (int) (mAppIconSize * iconScale));
- }
- } catch (Resources.NotFoundException e) {
- }
+ tileBitmap = ((BitmapDrawable) mContext.getResources().getDrawable(
+ R.drawable.widget_tile)).getBitmap();
+ previewWidth = tileBitmap.getWidth() * spanX;
+ previewHeight = tileBitmap.getHeight() * spanY;
}
// Scale to fit width only - let the widget preview be clipped in the
@@ -603,30 +400,60 @@
}
// If a bitmap is passed in, we use it; otherwise, we create a bitmap of the right size
+ final Canvas c = new Canvas();
if (preview == null) {
preview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888);
+ c.setBitmap(preview);
+ } else {
+ // Reusing bitmap. Clear it.
+ c.setBitmap(preview);
+ c.drawColor(0, PorterDuff.Mode.CLEAR);
}
// Draw the scaled preview into the final bitmap
int x = (preview.getWidth() - previewWidth) / 2;
if (widgetPreviewExists) {
- renderDrawableToBitmap(drawable, preview, x, 0, previewWidth,
- previewHeight);
+ drawable.setBounds(x, 0, x + previewWidth, previewHeight);
+ drawable.draw(c);
} else {
- final Canvas c = mCachedAppWidgetPreviewCanvas.get();
- final Rect src = mCachedAppWidgetPreviewSrcRect.get();
- final Rect dest = mCachedAppWidgetPreviewDestRect.get();
- c.setBitmap(preview);
- src.set(0, 0, defaultPreview.getWidth(), defaultPreview.getHeight());
- dest.set(x, 0, x + previewWidth, previewHeight);
+ final Paint p = new Paint();
+ p.setFilterBitmap(true);
+ int appIconSize = LauncherAppState.getInstance().getDynamicGrid()
+ .getDeviceProfile().iconSizePx;
- Paint p = mCachedAppWidgetPreviewPaint.get();
- if (p == null) {
- p = new Paint();
- p.setFilterBitmap(true);
- mCachedAppWidgetPreviewPaint.set(p);
+ // draw the spanX x spanY tiles
+ final Rect src = new Rect(0, 0, tileBitmap.getWidth(), tileBitmap.getHeight());
+
+ float tileW = scale * tileBitmap.getWidth();
+ float tileH = scale * tileBitmap.getHeight();
+ final RectF dst = new RectF(0, 0, tileW, tileH);
+
+ float tx = x;
+ for (int i = 0; i < spanX; i++, tx += tileW) {
+ float ty = 0;
+ for (int j = 0; j < spanY; j++, ty += tileH) {
+ dst.offsetTo(tx, ty);
+ c.drawBitmap(tileBitmap, src, dst, p);
+ }
}
- c.drawBitmap(defaultPreview, src, dest, p);
+
+ // Draw the icon in the top left corner
+ // TODO: use top right for RTL
+ int minOffset = (int) (appIconSize * WIDGET_PREVIEW_ICON_PADDING_PERCENTAGE);
+ int smallestSide = Math.min(previewWidth, previewHeight);
+ float iconScale = Math.min((float) smallestSide / (appIconSize + 2 * minOffset), scale);
+
+ try {
+ Drawable icon = mutateOnMainThread(mManager.loadIcon(info, mIconCache));
+ if (icon != null) {
+ int hoffset = (int) ((tileW - appIconSize * iconScale) / 2) + x;
+ int yoffset = (int) ((tileH - appIconSize * iconScale) / 2);
+ icon.setBounds(hoffset, yoffset,
+ hoffset + (int) (appIconSize * iconScale),
+ yoffset + (int) (appIconSize * iconScale));
+ icon.draw(c);
+ }
+ } catch (Resources.NotFoundException e) { }
c.setBitmap(null);
}
return mManager.getBadgeBitmap(info, preview);
@@ -634,71 +461,49 @@
private Bitmap generateShortcutPreview(
ResolveInfo info, int maxWidth, int maxHeight, Bitmap preview) {
- Bitmap tempBitmap = mCachedShortcutPreviewBitmap.get();
- final Canvas c = mCachedShortcutPreviewCanvas.get();
- if (tempBitmap == null ||
- tempBitmap.getWidth() != maxWidth ||
- tempBitmap.getHeight() != maxHeight) {
- tempBitmap = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
- mCachedShortcutPreviewBitmap.set(tempBitmap);
- } else {
- c.setBitmap(tempBitmap);
- c.drawColor(0, PorterDuff.Mode.CLEAR);
- c.setBitmap(null);
- }
- // Render the icon
- Drawable icon = mutateOnMainThread(mIconCache.getFullResIcon(info.activityInfo));
-
- int paddingTop = mContext.
- getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top);
- int paddingLeft = mContext.
- getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left);
- int paddingRight = mContext.
- getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
-
- int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
-
- renderDrawableToBitmap(
- icon, tempBitmap, paddingLeft, paddingTop, scaledIconWidth, scaledIconWidth);
-
- if (preview != null &&
- (preview.getWidth() != maxWidth || preview.getHeight() != maxHeight)) {
- throw new RuntimeException("Improperly sized bitmap passed as argument");
- } else if (preview == null) {
+ final Canvas c = new Canvas();
+ if (preview == null) {
preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
+ c.setBitmap(preview);
+ } else if (preview.getWidth() != maxWidth || preview.getHeight() != maxHeight) {
+ throw new RuntimeException("Improperly sized bitmap passed as argument");
+ } else {
+ // Reusing bitmap. Clear it.
+ c.setBitmap(preview);
+ c.drawColor(0, PorterDuff.Mode.CLEAR);
}
- c.setBitmap(preview);
+ Drawable icon = mutateOnMainThread(mIconCache.getFullResIcon(info.activityInfo));
+ icon.setFilterBitmap(true);
+
// Draw a desaturated/scaled version of the icon in the background as a watermark
- Paint p = mCachedShortcutPreviewPaint.get();
- if (p == null) {
- p = new Paint();
- ColorMatrix colorMatrix = new ColorMatrix();
- colorMatrix.setSaturation(0);
- p.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
- p.setAlpha((int) (255 * 0.06f));
- mCachedShortcutPreviewPaint.set(p);
- }
- c.drawBitmap(tempBitmap, 0, 0, p);
+ ColorMatrix colorMatrix = new ColorMatrix();
+ colorMatrix.setSaturation(0);
+ icon.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
+ icon.setAlpha((int) (255 * 0.06f));
+
+ Resources res = mContext.getResources();
+ int paddingTop = res.getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top);
+ int paddingLeft = res.getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left);
+ int paddingRight = res.getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
+ int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
+ icon.setBounds(paddingLeft, paddingTop,
+ paddingLeft + scaledIconWidth, paddingTop + scaledIconWidth);
+ icon.draw(c);
+
+ // Draw the final icon at top left corner.
+ // TODO: use top right for RTL
+ int appIconSize = LauncherAppState.getInstance().getDynamicGrid()
+ .getDeviceProfile().iconSizePx;
+ icon.setAlpha(255);
+ icon.setColorFilter(null);
+ icon.setBounds(0, 0, appIconSize, appIconSize);
+ icon.draw(c);
+
c.setBitmap(null);
-
- renderDrawableToBitmap(icon, preview, 0, 0, mAppIconSize, mAppIconSize);
-
return preview;
}
- private static void renderDrawableToBitmap(
- Drawable d, Bitmap bitmap, int x, int y, int w, int h) {
- if (bitmap != null) {
- Canvas c = new Canvas(bitmap);
- Rect oldBounds = d.copyBounds();
- d.setBounds(x, y, x + w, y + h);
- d.draw(c);
- d.setBounds(oldBounds); // Restore the bounds
- c.setBitmap(null);
- }
- }
-
private Drawable mutateOnMainThread(final Drawable drawable) {
try {
return mMainThreadExecutor.submit(new Callable<Drawable>() {
@@ -715,82 +520,144 @@
}
}
- private static final int MAX_OPEN_FILES = 1024;
- private static final int SAMPLE_RATE = 23;
/**
- * Dumps all files that are open in this process without allocating a file descriptor.
+ * @return an array of containing versionCode and lastUpdatedTime for the package.
*/
- private static void dumpOpenFiles() {
- try {
- Log.i(TAG, "DUMP OF OPEN FILES (sample rate: 1 every " + SAMPLE_RATE + "):");
- final String TYPE_APK = "apk";
- final String TYPE_JAR = "jar";
- final String TYPE_PIPE = "pipe";
- final String TYPE_SOCKET = "socket";
- final String TYPE_DB = "db";
- final String TYPE_ANON_INODE = "anon_inode";
- final String TYPE_DEV = "dev";
- final String TYPE_NON_FS = "non-fs";
- final String TYPE_OTHER = "other";
- List<String> types = Arrays.asList(TYPE_APK, TYPE_JAR, TYPE_PIPE, TYPE_SOCKET, TYPE_DB,
- TYPE_ANON_INODE, TYPE_DEV, TYPE_NON_FS, TYPE_OTHER);
- int[] count = new int[types.size()];
- int[] duplicates = new int[types.size()];
- HashSet<String> files = new HashSet<String>();
- int total = 0;
- for (int i = 0; i < MAX_OPEN_FILES; i++) {
- // This is a gigantic hack but unfortunately the only way to resolve an fd
- // to a file name. Note that we have to loop over all possible fds because
- // reading the directory would require allocating a new fd. The kernel is
- // currently implemented such that no fd is larger then the current rlimit,
- // which is why it's safe to loop over them in such a way.
- String fd = "/proc/self/fd/" + i;
+ private long[] getPackageVersion(String packageName) {
+ synchronized (mPackageVersions) {
+ long[] versions = mPackageVersions.get(packageName);
+ if (versions == null) {
+ versions = new long[2];
try {
- // getCanonicalPath() uses readlink behind the scene which doesn't require
- // a file descriptor.
- String resolved = new File(fd).getCanonicalPath();
- int type = types.indexOf(TYPE_OTHER);
- if (resolved.startsWith("/dev/")) {
- type = types.indexOf(TYPE_DEV);
- } else if (resolved.endsWith(".apk")) {
- type = types.indexOf(TYPE_APK);
- } else if (resolved.endsWith(".jar")) {
- type = types.indexOf(TYPE_JAR);
- } else if (resolved.contains("/fd/pipe:")) {
- type = types.indexOf(TYPE_PIPE);
- } else if (resolved.contains("/fd/socket:")) {
- type = types.indexOf(TYPE_SOCKET);
- } else if (resolved.contains("/fd/anon_inode:")) {
- type = types.indexOf(TYPE_ANON_INODE);
- } else if (resolved.endsWith(".db") || resolved.contains("/databases/")) {
- type = types.indexOf(TYPE_DB);
- } else if (resolved.startsWith("/proc/") && resolved.contains("/fd/")) {
- // Those are the files that don't point anywhere on the file system.
- // getCanonicalPath() wrongly interprets these as relative symlinks and
- // resolves them within /proc/<pid>/fd/.
- type = types.indexOf(TYPE_NON_FS);
+ PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, 0);
+ versions[0] = info.versionCode;
+ versions[1] = info.lastUpdateTime;
+ } catch (NameNotFoundException e) {
+ Log.e(TAG, "PackageInfo not found", e);
+ }
+ mPackageVersions.put(packageName, versions);
+ }
+ return versions;
+ }
+ }
+
+ /**
+ * A request Id which can be used by the client to cancel any request.
+ */
+ public class PreviewLoadRequest {
+
+ private final PreviewLoadTask mTask;
+ private final WidgetCacheKey mKey;
+
+ public PreviewLoadRequest(PreviewLoadTask task, WidgetCacheKey key) {
+ mTask = task;
+ mKey = key;
+ }
+
+ public void cancel(boolean recycleImage) {
+ if (mTask != null) {
+ mTask.cancel(true);
+ }
+
+ if (recycleImage) {
+ synchronized(mLoadedPreviews) {
+ WeakReference<Bitmap> result = mLoadedPreviews.remove(mKey);
+ if (result != null && result.get() != null) {
+ mUnusedBitmaps.add(result.get());
}
- count[type]++;
- total++;
- if (files.contains(resolved)) {
- duplicates[type]++;
- }
- files.add(resolved);
- if (total % SAMPLE_RATE == 0) {
- Log.i(TAG, " fd " + i + ": " + resolved
- + " (" + types.get(type) + ")");
- }
- } catch (IOException e) {
- // Ignoring exceptions for non-existing file descriptors.
}
}
- for (int i = 0; i < types.size(); i++) {
- Log.i(TAG, String.format("Open %10s files: %4d total, %4d duplicates",
- types.get(i), count[i], duplicates[i]));
+ }
+ }
+
+ public class PreviewLoadTask extends AsyncTask<Void, Void, Bitmap> {
+
+ private final WidgetCacheKey mKey;
+ private final Object mInfo;
+ private final int mPreviewHeight;
+ private final int mPreviewWidth;
+ private final PagedViewWidget mCaller;
+
+ PreviewLoadTask(WidgetCacheKey key, Object info, int previewWidth,
+ int previewHeight, PagedViewWidget caller) {
+ mKey = key;
+ mInfo = info;
+ mPreviewHeight = previewHeight;
+ mPreviewWidth = previewWidth;
+ mCaller = caller;
+ }
+
+
+ @Override
+ protected Bitmap doInBackground(Void... params) {
+ Bitmap unusedBitmap = null;
+ synchronized (mUnusedBitmaps) {
+ // Check if we can use a bitmap
+ for (Bitmap candidate : mUnusedBitmaps) {
+ if (candidate != null && candidate.isMutable() &&
+ candidate.getWidth() == mPreviewWidth &&
+ candidate.getHeight() == mPreviewHeight) {
+ unusedBitmap = candidate;
+ break;
+ }
+ }
+
+ if (unusedBitmap == null) {
+ unusedBitmap = Bitmap.createBitmap(mPreviewWidth, mPreviewHeight, Config.ARGB_8888);
+ } else {
+ mUnusedBitmaps.remove(unusedBitmap);
+ }
}
- } catch (Throwable t) {
- // Catch everything. This is called from an exception handler that we shouldn't upset.
- Log.e(TAG, "Unable to log open files.", t);
+
+ if (isCancelled()) {
+ return null;
+ }
+ Bitmap preview = readFromDb(mKey, unusedBitmap);
+ if (!isCancelled() && preview == null) {
+ // Fetch the version info before we generate the preview, so that, in-case the
+ // app was updated while we are generating the preview, we use the old version info,
+ // which would gets re-written next time.
+ long[] versions = getPackageVersion(mKey.componentName.getPackageName());
+
+ // it's not in the db... we need to generate it
+ preview = generatePreview(mInfo, unusedBitmap, mPreviewWidth, mPreviewHeight);
+
+ if (!isCancelled()) {
+ writeToDb(mKey, versions, preview);
+ }
+ }
+
+ return preview;
+ }
+
+ @Override
+ protected void onPostExecute(Bitmap result) {
+ synchronized(mLoadedPreviews) {
+ mLoadedPreviews.put(mKey, new WeakReference<Bitmap>(result));
+ }
+
+ mCaller.applyPreview(result);
+ }
+ }
+
+ private static final class WidgetCacheKey extends ComponentKey {
+
+ // TODO: remove dependency on size
+ private final String size;
+
+ public WidgetCacheKey(ComponentName componentName, UserHandleCompat user, String size) {
+ super(componentName, user);
+ this.size = size;
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode() ^ size.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return super.equals(o) && ((WidgetCacheKey) o).size.equals(size);
}
}
}
diff --git a/src/com/android/launcher3/WidgetsContainerView.java b/src/com/android/launcher3/WidgetsContainerView.java
new file mode 100644
index 0000000..7004d8b
--- /dev/null
+++ b/src/com/android/launcher3/WidgetsContainerView.java
@@ -0,0 +1,84 @@
+package com.android.launcher3;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.FrameLayout;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+
+class SectionedWidgetsRow {
+ String section;
+ List<List<Object>> widgets;
+
+ public SectionedWidgetsRow(String sc) {
+ section = sc;
+ }
+}
+
+class SectionedWidgetsAlgorithm {
+ public List<SectionedWidgetsRow> computeSectionedWidgetRows(List<Object> sortedWidgets,
+ int widgetsPerRow) {
+ List<SectionedWidgetsRow> rows = new ArrayList<>();
+ LinkedHashMap<String, List<Object>> sections = computeSectionedApps(sortedWidgets);
+ for (Map.Entry<String, List<Object>> sectionEntry : sections.entrySet()) {
+ String section = sectionEntry.getKey();
+ SectionedWidgetsRow row = new SectionedWidgetsRow(section);
+ List<Object> widgets = sectionEntry.getValue();
+ int numRows = (int) Math.ceil((float) widgets.size() / widgetsPerRow);
+ for (int i = 0; i < numRows; i++) {
+ List<Object> widgetsInRow = new ArrayList<>();
+ int offset = i * widgetsPerRow;
+ for (int j = 0; j < widgetsPerRow; j++) {
+ widgetsInRow.add(widgets.get(offset + j));
+ }
+ row.widgets.add(widgetsInRow);
+ }
+ }
+ return rows;
+ }
+
+ private LinkedHashMap<String, List<Object>> computeSectionedApps(List<Object> sortedWidgets) {
+ LinkedHashMap<String, List<Object>> sections = new LinkedHashMap<>();
+ for (Object info : sortedWidgets) {
+ String section = getSection(info);
+ List<Object> sectionedWidgets = sections.get(section);
+ if (sectionedWidgets == null) {
+ sectionedWidgets = new ArrayList<>();
+ sections.put(section, sectionedWidgets);
+ }
+ sectionedWidgets.add(info);
+ }
+ return sections;
+ }
+
+ private String getSection(Object widgetOrShortcut) {
+ return "UNKNOWN";
+ }
+}
+
+/**
+ * The widgets list view container.
+ */
+public class WidgetsContainerView extends FrameLayout {
+
+
+ public WidgetsContainerView(Context context) {
+ this(context, null);
+ }
+
+ public WidgetsContainerView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public WidgetsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ }
+}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 3d29b6f..a79add0 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -26,6 +26,7 @@
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
+import android.annotation.TargetApi;
import android.app.WallpaperManager;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetProviderInfo;
@@ -44,6 +45,7 @@
import android.graphics.Region.Op;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
+import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Parcelable;
@@ -67,6 +69,8 @@
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
import com.android.launcher3.compat.UserHandleCompat;
+import com.android.launcher3.util.Thunk;
+import com.android.launcher3.util.WallpaperUtils;
import java.util.ArrayList;
import java.util.HashMap;
@@ -115,24 +119,24 @@
private long mCustomContentShowTime = -1;
private LayoutTransition mLayoutTransition;
- private final WallpaperManager mWallpaperManager;
- private IBinder mWindowToken;
+ @Thunk final WallpaperManager mWallpaperManager;
+ @Thunk IBinder mWindowToken;
private int mOriginalDefaultPage;
private int mDefaultPage;
private ShortcutAndWidgetContainer mDragSourceInternal;
- private static boolean sAccessibilityEnabled;
+ @Thunk static boolean sAccessibilityEnabled;
// The screen id used for the empty screen always present to the right.
final static long EXTRA_EMPTY_SCREEN_ID = -201;
private final static long CUSTOM_CONTENT_SCREEN_ID = -301;
- private HashMap<Long, CellLayout> mWorkspaceScreens = new HashMap<Long, CellLayout>();
- private ArrayList<Long> mScreenOrder = new ArrayList<Long>();
+ @Thunk HashMap<Long, CellLayout> mWorkspaceScreens = new HashMap<Long, CellLayout>();
+ @Thunk ArrayList<Long> mScreenOrder = new ArrayList<Long>();
- private Runnable mRemoveEmptyScreenRunnable;
- private boolean mDeferRemoveExtraEmptyScreen = false;
+ @Thunk Runnable mRemoveEmptyScreenRunnable;
+ @Thunk boolean mDeferRemoveExtraEmptyScreen = false;
/**
* CellInfo for the cell that is currently being dragged
@@ -142,7 +146,7 @@
/**
* Target drop area calculated during last acceptDrop call.
*/
- private int[] mTargetCell = new int[2];
+ @Thunk int[] mTargetCell = new int[2];
private int mDragOverX = -1;
private int mDragOverY = -1;
@@ -157,7 +161,7 @@
/**
* The CellLayout that is currently being dragged over
*/
- private CellLayout mDragTargetLayout = null;
+ @Thunk CellLayout mDragTargetLayout = null;
/**
* The CellLayout that we will show as glowing
*/
@@ -168,16 +172,16 @@
*/
private CellLayout mDropToLayout = null;
- private Launcher mLauncher;
- private IconCache mIconCache;
- private DragController mDragController;
+ @Thunk Launcher mLauncher;
+ @Thunk IconCache mIconCache;
+ @Thunk DragController mDragController;
// These are temporary variables to prevent having to allocate a new object just to
// return an (x, y) value from helper functions. Do NOT use them to maintain other state.
private int[] mTempCell = new int[2];
private int[] mTempPt = new int[2];
private int[] mTempEstimate = new int[2];
- private float[] mDragViewVisualCenter = new float[2];
+ @Thunk float[] mDragViewVisualCenter = new float[2];
private float[] mTempCellLayoutCenterCoordinates = new float[2];
private Matrix mTempInverseMatrix = new Matrix();
@@ -202,7 +206,7 @@
private boolean mInScrollArea = false;
private HolographicOutlineHelper mOutlineHelper;
- private Bitmap mDragOutline = null;
+ @Thunk Bitmap mDragOutline = null;
private static final Rect sTempRect = new Rect();
private final int[] mTempXY = new int[2];
private int[] mTempVisiblePagesRange = new int[2];
@@ -211,11 +215,11 @@
private boolean mWorkspaceFadeInAdjacentScreens;
WallpaperOffsetInterpolator mWallpaperOffset;
- private boolean mWallpaperIsLiveWallpaper;
- private int mNumPagesForWallpaperParallax;
- private float mLastSetWallpaperOffsetSteps = 0;
+ @Thunk boolean mWallpaperIsLiveWallpaper;
+ @Thunk int mNumPagesForWallpaperParallax;
+ @Thunk float mLastSetWallpaperOffsetSteps = 0;
- private Runnable mDelayedResizeRunnable;
+ @Thunk Runnable mDelayedResizeRunnable;
private Runnable mDelayedSnapToPageRunnable;
private Point mDisplaySize = new Point();
@@ -224,7 +228,7 @@
public static final int REORDER_TIMEOUT = 350;
private final Alarm mFolderCreationAlarm = new Alarm();
private final Alarm mReorderAlarm = new Alarm();
- private FolderRingAnimator mDragFolderRingAnimator = null;
+ @Thunk FolderRingAnimator mDragFolderRingAnimator = null;
private FolderIcon mDragOverFolderIcon = null;
private boolean mCreateUserFolderOnDrop = false;
private boolean mAddToExistingFolderOnDrop = false;
@@ -253,8 +257,8 @@
private static final int DRAG_MODE_ADD_TO_FOLDER = 2;
private static final int DRAG_MODE_REORDER = 3;
private int mDragMode = DRAG_MODE_NONE;
- private int mLastReorderX = -1;
- private int mLastReorderY = -1;
+ @Thunk int mLastReorderX = -1;
+ @Thunk int mLastReorderY = -1;
private SparseArray<Parcelable> mSavedStates;
private final ArrayList<Integer> mRestoredPages = new ArrayList<Integer>();
@@ -266,17 +270,17 @@
private float mCurrentScale;
private float mNewScale;
- private float[] mOldBackgroundAlphas;
+ @Thunk float[] mOldBackgroundAlphas;
private float[] mOldAlphas;
- private float[] mNewBackgroundAlphas;
+ @Thunk float[] mNewBackgroundAlphas;
private float[] mNewAlphas;
private int mLastChildCount = -1;
private float mTransitionProgress;
- private Animator mStateAnimator = null;
+ @Thunk Animator mStateAnimator = null;
float mOverScrollEffect = 0f;
- private Runnable mDeferredAction;
+ @Thunk Runnable mDeferredAction;
private boolean mDeferDropAfterUninstall;
private boolean mUninstallSuccessful;
@@ -363,13 +367,12 @@
// estimate the size of a widget with spans hSpan, vSpan. return MAX_VALUE for each
// dimension if unsuccessful
- public int[] estimateItemSize(int hSpan, int vSpan,
- ItemInfo itemInfo, boolean springLoaded) {
+ public int[] estimateItemSize(ItemInfo itemInfo, boolean springLoaded) {
int[] size = new int[2];
if (getChildCount() > 0) {
// Use the first non-custom page to estimate the child position
CellLayout cl = (CellLayout) getChildAt(numCustomPages());
- Rect r = estimateItemPosition(cl, itemInfo, 0, 0, hSpan, vSpan);
+ Rect r = estimateItemPosition(cl, itemInfo, 0, 0, itemInfo.spanX, itemInfo.spanY);
size[0] = r.width();
size[1] = r.height();
if (springLoaded) {
@@ -399,7 +402,6 @@
setChildrenBackgroundAlphaMultipliers(1f);
// Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging
InstallShortcutReceiver.enableInstallQueue();
- UninstallShortcutReceiver.enableUninstallQueue();
post(new Runnable() {
@Override
public void run() {
@@ -427,7 +429,6 @@
// Re-enable any Un/InstallShortcutReceiver and now process any queued items
InstallShortcutReceiver.disableAndFlushInstallQueue(getContext());
- UninstallShortcutReceiver.disableAndFlushUninstallQueue(getContext());
mDragSourceInternal = null;
mLauncher.onInteractionEnd();
@@ -572,6 +573,12 @@
mWorkspaceScreens.put(screenId, newScreen);
mScreenOrder.add(insertIndex, screenId);
addView(newScreen, insertIndex);
+
+ LauncherAccessibilityDelegate delegate =
+ LauncherAppState.getInstance().getAccessibilityDelegate();
+ if (delegate != null && delegate.isInAccessibleDrag()) {
+ newScreen.enableAccessibleDrag(true);
+ }
return screenId;
}
@@ -1308,10 +1315,10 @@
protected void setWallpaperDimension() {
new AsyncTask<Void, Void, Void>() {
public Void doInBackground(Void ... args) {
- String spKey = WallpaperCropActivity.getSharedPreferencesKey();
+ String spKey = LauncherFiles.WALLPAPER_CROP_PREFERENCES_KEY;
SharedPreferences sp =
mLauncher.getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
- LauncherWallpaperPickerActivity.suggestWallpaperDimension(mLauncher.getResources(),
+ WallpaperUtils.suggestWallpaperDimension(mLauncher.getResources(),
sp, mLauncher.getWindowManager(), mWallpaperManager,
mLauncher.overrideWallpaperDimensions());
return null;
@@ -1522,7 +1529,7 @@
@Override
public void announceForAccessibility(CharSequence text) {
// Don't announce if apps is on top of us.
- if (!mLauncher.isAllAppsVisible()) {
+ if (!mLauncher.isAppsViewVisible()) {
super.announceForAccessibility(text);
}
}
@@ -1621,7 +1628,6 @@
float scrollProgress = getScrollProgress(screenCenter, child, i);
float alpha = 1 - Math.abs(scrollProgress);
child.getShortcutsAndWidgets().setAlpha(alpha);
- //child.setBackgroundAlphaMultiplier(1 - alpha);
}
}
}
@@ -1634,6 +1640,23 @@
}
}
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public void enableAccessibleDrag(boolean enable) {
+ for (int i = 0; i < getChildCount(); i++) {
+ CellLayout child = (CellLayout) getChildAt(i);
+ child.enableAccessibleDrag(enable);
+ }
+
+ if (enable) {
+ // We need to allow our individual children to become click handlers in this case
+ setOnClickListener(null);
+ } else {
+ // Reset our click listener
+ setOnClickListener(mLauncher);
+ }
+ mLauncher.getHotseat().getLayout().enableAccessibleDrag(enable);
+ }
+
public boolean hasCustomContent() {
return (mScreenOrder.size() > 0 && mScreenOrder.get(0) == CUSTOM_CONTENT_SCREEN_ID);
}
@@ -1794,7 +1817,7 @@
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
- if (!mLauncher.isAllAppsVisible()) {
+ if (!mLauncher.isAppsViewVisible()) {
final Folder openFolder = getOpenFolder();
if (openFolder != null) {
return openFolder.requestFocus(direction, previouslyFocusedRect);
@@ -1815,7 +1838,7 @@
@Override
public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
- if (!mLauncher.isAllAppsVisible()) {
+ if (!mLauncher.isAppsViewVisible()) {
final Folder openFolder = getOpenFolder();
if (openFolder != null) {
openFolder.addFocusables(views, direction);
@@ -1860,7 +1883,7 @@
}
}
- private void updateChildrenLayersEnabled(boolean force) {
+ @Thunk void updateChildrenLayersEnabled(boolean force) {
boolean small = mState == State.OVERVIEW || mIsSwitchingState;
boolean enableChildrenLayers = force || small || mAnimatingViewIntoPlace || isPageMoving();
@@ -2024,8 +2047,7 @@
// If this is a text view, use its drawable instead
if (v instanceof TextView) {
- TextView tv = (TextView) v;
- Drawable d = tv.getCompoundDrawables()[1];
+ Drawable d = getTextViewIcon((TextView) v);
Rect bounds = getDrawableBounds(d);
bmpWidth = bounds.width();
bmpHeight = bounds.height();
@@ -2043,7 +2065,7 @@
}
public void onDragStartedWithItem(PendingAddItemInfo info, Bitmap b, boolean clipAlpha) {
- int[] size = estimateItemSize(info.spanX, info.spanY, info, false);
+ int[] size = estimateItemSize(info, false);
// The outline is used to visualize where the item will land if dropped
mDragOutline = createDragOutline(b, DRAG_BITMAP_PADDING, size[0], size[1], clipAlpha);
@@ -2184,7 +2206,7 @@
private void updateAccessibilityFlags() {
int accessible = mState == State.NORMAL ?
- IMPORTANT_FOR_ACCESSIBILITY_YES :
+ IMPORTANT_FOR_ACCESSIBILITY_NO :
IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
setImportantForAccessibility(accessible);
}
@@ -2305,7 +2327,7 @@
}
}
- final View searchBar = mLauncher.getQsbBar();
+ final View searchBar = mLauncher.getOrCreateQsbBar();
final View overviewPanel = mLauncher.getOverviewPanel();
final View hotseat = mLauncher.getHotseat();
final View pageIndicator = getPageIndicator();
@@ -2326,7 +2348,7 @@
cl.setShortcutAndWidgetAlpha(mNewAlphas[i]);
} else {
if (layerViews != null) {
- layerViews.put(cl, Launcher.BUILD_LAYER);
+ layerViews.put(cl, LauncherStateTransitionAnimation.BUILD_LAYER);
}
if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) {
LauncherViewPropertyAnimator alphaAnim =
@@ -2378,8 +2400,8 @@
if (layerViews != null) {
// If layerViews is not null, we add these views, and indicate that
// the caller can manage layer state.
- layerViews.put(hotseat, Launcher.BUILD_AND_SET_LAYER);
- layerViews.put(overviewPanel, Launcher.BUILD_AND_SET_LAYER);
+ layerViews.put(hotseat, LauncherStateTransitionAnimation.BUILD_AND_SET_LAYER);
+ layerViews.put(overviewPanel, LauncherStateTransitionAnimation.BUILD_AND_SET_LAYER);
} else {
// Otherwise let the animator handle layer management.
hotseatAlpha.withLayer();
@@ -2408,7 +2430,7 @@
if (layerViews != null) {
// If layerViews is not null, we add these views, and indicate that
// the caller can manage layer state.
- layerViews.put(searchBar, Launcher.BUILD_AND_SET_LAYER);
+ layerViews.put(searchBar, LauncherStateTransitionAnimation.BUILD_AND_SET_LAYER);
} else {
// Otherwise let the animator handle layer management.
searchBarAlpha.withLayer();
@@ -2550,7 +2572,7 @@
}
}
- private void onTransitionEnd() {
+ @Thunk void onTransitionEnd() {
mIsSwitchingState = false;
updateChildrenLayersEnabled(false);
showCustomContentIfNecessary();
@@ -2562,6 +2584,19 @@
}
/**
+ * Returns the drawable for the given text view.
+ */
+ public static Drawable getTextViewIcon(TextView tv) {
+ final Drawable[] drawables = tv.getCompoundDrawables();
+ for (int i = 0; i < drawables.length; i++) {
+ if (drawables[i] != null) {
+ return drawables[i];
+ }
+ }
+ return null;
+ }
+
+ /**
* Draw the View v into the given Canvas.
*
* @param v the view to draw
@@ -2576,7 +2611,7 @@
destCanvas.save();
if (v instanceof TextView) {
- Drawable d = ((TextView) v).getCompoundDrawables()[1];
+ Drawable d = getTextViewIcon((TextView) v);
Rect bounds = getDrawableBounds(d);
clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding);
destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top);
@@ -2613,7 +2648,7 @@
int padding = expectedPadding.get();
if (v instanceof TextView) {
- Drawable d = ((TextView) v).getCompoundDrawables()[1];
+ Drawable d = getTextViewIcon((TextView) v);
Rect bounds = getDrawableBounds(d);
b = Bitmap.createBitmap(bounds.width() + padding,
bounds.height() + padding, Bitmap.Config.ARGB_8888);
@@ -2674,7 +2709,11 @@
return b;
}
- void startDrag(CellLayout.CellInfo cellInfo) {
+ public void startDrag(CellLayout.CellInfo cellInfo) {
+ startDrag(cellInfo, false);
+ }
+
+ public void startDrag(CellLayout.CellInfo cellInfo, boolean accessible) {
View child = cellInfo.cell;
// Make sure the drag was started by a long press as opposed to a long click.
@@ -2687,10 +2726,15 @@
CellLayout layout = (CellLayout) child.getParent().getParent();
layout.prepareChildForDrag(child);
- beginDragShared(child, this);
+ beginDragShared(child, this, accessible);
}
- public void beginDragShared(View child, DragSource source) {
+ public void beginDragShared(View child, DragSource source, boolean accessible) {
+ beginDragShared(child, new Point(), source, accessible);
+ }
+
+ public void beginDragShared(View child, Point relativeTouchPos, DragSource source,
+ boolean accessible) {
child.clearFocus();
child.setPressed(false);
@@ -2715,11 +2759,23 @@
Point dragVisualizeOffset = null;
Rect dragRect = null;
if (child instanceof BubbleTextView) {
+ BubbleTextView icon = (BubbleTextView) child;
int iconSize = grid.iconSizePx;
int top = child.getPaddingTop();
int left = (bmpWidth - iconSize) / 2;
int right = left + iconSize;
int bottom = top + iconSize;
+ if (icon.isLayoutHorizontal()) {
+ // If the layout is horizontal, then if we are just picking up the icon, then just
+ // use the child position since the icon is top-left aligned. Otherwise, offset
+ // the drag layer position horizontally so that the icon is under the current
+ // touch position.
+ if (icon.getIcon().getBounds().contains(relativeTouchPos.x, relativeTouchPos.y)) {
+ dragLayerX = Math.round(mTempXY[0]);
+ } else {
+ dragLayerX = Math.round(mTempXY[0] + relativeTouchPos.x - (bmpWidth / 2));
+ }
+ }
dragLayerY += top;
// Note: The drag region is used to calculate drag layer offsets, but the
// dragVisualizeOffset in addition to the dragRect (the size) to position the outline.
@@ -2744,7 +2800,7 @@
}
DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(),
- DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale);
+ DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale, accessible);
dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor());
if (child.getParent() instanceof ShortcutAndWidgetContainer) {
@@ -2794,25 +2850,13 @@
// Start the drag
DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(),
- DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale);
+ DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale, false);
dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor());
// Recycle temporary bitmaps
tmpB.recycle();
}
- void addApplicationShortcut(ShortcutInfo info, CellLayout target, long container, long screenId,
- int cellX, int cellY, boolean insertAtFirst, int intersectX, int intersectY) {
- View view = mLauncher.createShortcut(R.layout.application, target, (ShortcutInfo) info);
-
- final int[] cellXY = new int[2];
- target.findCellForSpanThatIntersects(cellXY, 1, 1, intersectX, intersectY);
- addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1, insertAtFirst);
-
- LauncherModel.addOrMoveItemInDatabase(mLauncher, info, container, screenId, cellXY[0],
- cellXY[1]);
- }
-
public boolean transitionStateShouldAllowDrop() {
return ((!isSwitchingState() || mTransitionProgress > 0.5f) &&
(mState == State.NORMAL || mState == State.SPRING_LOADED));
@@ -3149,7 +3193,8 @@
final LauncherAppWidgetHostView hostView = (LauncherAppWidgetHostView) cell;
AppWidgetProviderInfo pInfo = hostView.getAppWidgetInfo();
- if (pInfo != null && pInfo.resizeMode != AppWidgetProviderInfo.RESIZE_NONE) {
+ if (pInfo != null && pInfo.resizeMode != AppWidgetProviderInfo.RESIZE_NONE
+ && !d.accessibleDrag) {
final Runnable addResizeFrame = new Runnable() {
public void run() {
DragLayer dragLayer = mLauncher.getDragLayer();
@@ -3638,7 +3683,7 @@
mTargetCell[1]);
manageFolderFeedback(info, mDragTargetLayout, mTargetCell,
- targetCellDistance, dragOverView);
+ targetCellDistance, dragOverView, d.accessibleDrag);
boolean nearestDropOccupied = mDragTargetLayout.isNearestDropLocationOccupied((int)
mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], item.spanX,
@@ -3676,15 +3721,21 @@
}
private void manageFolderFeedback(ItemInfo info, CellLayout targetLayout,
- int[] targetCell, float distance, View dragOverView) {
+ int[] targetCell, float distance, View dragOverView, boolean accessibleDrag) {
boolean userFolderPending = willCreateUserFolder(info, targetLayout, targetCell, distance,
false);
-
if (mDragMode == DRAG_MODE_NONE && userFolderPending &&
!mFolderCreationAlarm.alarmPending()) {
- mFolderCreationAlarm.setOnAlarmListener(new
- FolderCreationAlarmListener(targetLayout, targetCell[0], targetCell[1]));
- mFolderCreationAlarm.setAlarm(FOLDER_CREATION_TIMEOUT);
+
+ FolderCreationAlarmListener listener = new
+ FolderCreationAlarmListener(targetLayout, targetCell[0], targetCell[1]);
+
+ if (!accessibleDrag) {
+ mFolderCreationAlarm.setOnAlarmListener(listener);
+ mFolderCreationAlarm.setAlarm(FOLDER_CREATION_TIMEOUT);
+ } else {
+ listener.onAlarm(mFolderCreationAlarm);
+ }
return;
}
@@ -3981,8 +4032,7 @@
}
public Bitmap createWidgetBitmap(ItemInfo widgetInfo, View layout) {
- int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(widgetInfo.spanX,
- widgetInfo.spanY, widgetInfo, false);
+ int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(widgetInfo, false);
int visibility = layout.getVisibility();
layout.setVisibility(VISIBLE);
@@ -4136,7 +4186,7 @@
*
* pixelX and pixelY should be in the coordinate system of layout
*/
- private int[] findNearestArea(int pixelX, int pixelY,
+ @Thunk int[] findNearestArea(int pixelX, int pixelY,
int spanX, int spanY, CellLayout layout, int[] recycle) {
return layout.findNearestArea(
pixelX, pixelY, spanX, spanY, recycle);
@@ -4273,8 +4323,7 @@
cellX = hotseat.getCellXFromOrder((int) info.screenId);
cellY = hotseat.getCellYFromOrder((int) info.screenId);
}
- LauncherModel.addItemToDatabase(mLauncher, info, container, screenId, cellX,
- cellY, false);
+ LauncherModel.addItemToDatabase(mLauncher, info, container, screenId, cellX, cellY);
}
if (v instanceof FolderIcon) {
FolderIcon fi = (FolderIcon) v;
@@ -4732,7 +4781,7 @@
updates.contains(info)) {
ShortcutInfo si = (ShortcutInfo) info;
BubbleTextView shortcut = (BubbleTextView) v;
- boolean oldPromiseState = shortcut.getCompoundDrawables()[1]
+ boolean oldPromiseState = getTextViewIcon(shortcut)
instanceof PreloadIconDrawable;
shortcut.applyFromShortcutInfo(si, mIconCache, true,
si.isPromise() != oldPromiseState);
@@ -4767,7 +4816,8 @@
if (shortcutInfo.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) {
// For auto install apps update the icon as well as label.
mIconCache.getTitleAndIcon(shortcutInfo,
- shortcutInfo.promisedIntent, user);
+ shortcutInfo.promisedIntent, user,
+ shortcutInfo.shouldUseLowResIcon());
} else {
// Only update the icon for restored apps.
shortcutInfo.updateIcon(mIconCache);
@@ -4827,7 +4877,8 @@
DeferredWidgetRefresh widgetRefresh = new DeferredWidgetRefresh(changedInfo,
mLauncher.getAppWidgetHost());
if (LauncherModel.getProviderInfo(getContext(),
- changedInfo.get(0).providerName) != null) {
+ changedInfo.get(0).providerName,
+ changedInfo.get(0).user) != null) {
// Re-inflate the widgets which have changed status
widgetRefresh.run();
} else {
diff --git a/src/com/android/launcher3/compat/AlphabeticIndexCompat.java b/src/com/android/launcher3/compat/AlphabeticIndexCompat.java
new file mode 100644
index 0000000..f890706
--- /dev/null
+++ b/src/com/android/launcher3/compat/AlphabeticIndexCompat.java
@@ -0,0 +1,149 @@
+package com.android.launcher3.compat;
+
+import android.content.Context;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Locale;
+
+/**
+ * Fallback class to support Alphabetic indexing if not supported by the framework.
+ * TODO(winsonc): disable for non-english locales
+ */
+class BaseAlphabeticIndex {
+
+ private static final String BUCKETS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-";
+ private static final int UNKNOWN_BUCKET_INDEX = BUCKETS.length() - 1;
+
+ public BaseAlphabeticIndex() {}
+
+ /**
+ * Sets the max number of the label buckets in this index.
+ */
+ public void setMaxLabelCount(int count) {
+ // Not currently supported
+ }
+
+ /**
+ * Returns the index of the bucket in which the given string should appear.
+ */
+ protected int getBucketIndex(String s) {
+ if (s.isEmpty()) {
+ return UNKNOWN_BUCKET_INDEX;
+ }
+ int index = BUCKETS.indexOf(s.substring(0, 1).toUpperCase());
+ if (index != -1) {
+ return index;
+ }
+ return UNKNOWN_BUCKET_INDEX;
+ }
+
+ /**
+ * Returns the label for the bucket at the given index (as returned by getBucketIndex).
+ */
+ protected String getBucketLabel(int index) {
+ return BUCKETS.substring(index, index + 1);
+ }
+}
+
+/**
+ * Reflected libcore.icu.AlphabeticIndex implementation, falls back to the base alphabetic index.
+ */
+public class AlphabeticIndexCompat extends BaseAlphabeticIndex {
+
+ private Object mAlphabeticIndex;
+ private Method mAddLabelsMethod;
+ private Method mSetMaxLabelCountMethod;
+ private Method mGetBucketIndexMethod;
+ private Method mGetBucketLabelMethod;
+ private boolean mHasValidAlphabeticIndex;
+
+ public AlphabeticIndexCompat(Context context) {
+ super();
+ try {
+ Locale curLocale = context.getResources().getConfiguration().locale;
+ Class clazz = Class.forName("libcore.icu.AlphabeticIndex");
+ Constructor ctor = clazz.getConstructor(Locale.class);
+ mAddLabelsMethod = clazz.getDeclaredMethod("addLabels", Locale.class);
+ mSetMaxLabelCountMethod = clazz.getDeclaredMethod("setMaxLabelCount", int.class);
+ mGetBucketIndexMethod = clazz.getDeclaredMethod("getBucketIndex", String.class);
+ mGetBucketLabelMethod = clazz.getDeclaredMethod("getBucketLabel", int.class);
+ mAlphabeticIndex = ctor.newInstance(curLocale);
+ try {
+ // Ensure we always have some base English locale buckets
+ if (!curLocale.getLanguage().equals(new Locale("en").getLanguage())) {
+ mAddLabelsMethod.invoke(mAlphabeticIndex, Locale.ENGLISH);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ mHasValidAlphabeticIndex = true;
+ } catch (Exception e) {
+ mHasValidAlphabeticIndex = false;
+ }
+ }
+
+ /**
+ * Sets the max number of the label buckets in this index.
+ * (ICU 51 default is 99)
+ */
+ public void setMaxLabelCount(int count) {
+ if (mHasValidAlphabeticIndex) {
+ try {
+ mSetMaxLabelCountMethod.invoke(mAlphabeticIndex, count);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else {
+ super.setMaxLabelCount(count);
+ }
+ }
+
+ /**
+ * Computes the section name for an given string {@param s}.
+ */
+ public String computeSectionName(String s) {
+ String sectionName = getBucketLabel(getBucketIndex(s));
+ if (sectionName.trim().isEmpty() && s.length() > 0) {
+ boolean startsWithDigit = Character.isDigit(Character.codePointAt(s.trim(), 0));
+ if (startsWithDigit) {
+ // Digit section
+ return "#";
+ } else {
+ // Unknown section
+ return "\u2022";
+ }
+ }
+ return sectionName;
+ }
+
+ /**
+ * Returns the index of the bucket in which {@param s} should appear.
+ * Function is synchronized because underlying routine walks an iterator
+ * whose state is maintained inside the index object.
+ */
+ protected int getBucketIndex(String s) {
+ if (mHasValidAlphabeticIndex) {
+ try {
+ return (Integer) mGetBucketIndexMethod.invoke(mAlphabeticIndex, s);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return super.getBucketIndex(s);
+ }
+
+ /**
+ * Returns the label for the bucket at the given index (as returned by getBucketIndex).
+ */
+ protected String getBucketLabel(int index) {
+ if (mHasValidAlphabeticIndex) {
+ try {
+ return (String) mGetBucketLabelMethod.invoke(mAlphabeticIndex, index);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return super.getBucketLabel(index);
+ }
+}
diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatV16.java b/src/com/android/launcher3/compat/LauncherAppsCompatV16.java
index e47b9a5..ac3d252 100644
--- a/src/com/android/launcher3/compat/LauncherAppsCompatV16.java
+++ b/src/com/android/launcher3/compat/LauncherAppsCompatV16.java
@@ -31,6 +31,8 @@
import android.os.Bundle;
import android.provider.Settings;
+import com.android.launcher3.util.Thunk;
+
import java.util.ArrayList;
import java.util.List;
@@ -139,11 +141,11 @@
mContext.registerReceiver(mPackageMonitor, filter);
}
- private synchronized List<OnAppsChangedCallbackCompat> getCallbacks() {
+ @Thunk synchronized List<OnAppsChangedCallbackCompat> getCallbacks() {
return new ArrayList<OnAppsChangedCallbackCompat>(mCallbacks);
}
- private class PackageMonitor extends BroadcastReceiver {
+ @Thunk class PackageMonitor extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
final UserHandleCompat user = UserHandleCompat.myUserHandle();
diff --git a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
index 601f04c..d6d4b82 100644
--- a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
+++ b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
@@ -26,6 +26,7 @@
import com.android.launcher3.IconCache;
import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.util.Thunk;
import java.util.ArrayList;
import java.util.HashSet;
@@ -36,10 +37,10 @@
private static final boolean DEBUG = false;
// All updates to these sets must happen on the {@link #mWorker} thread.
- private final SparseArray<SessionInfo> mPendingReplays = new SparseArray<SessionInfo>();
- private final HashSet<String> mPendingBadgeUpdates = new HashSet<String>();
+ @Thunk final SparseArray<SessionInfo> mPendingReplays = new SparseArray<SessionInfo>();
+ @Thunk final HashSet<String> mPendingBadgeUpdates = new HashSet<String>();
- private final PackageInstaller mInstaller;
+ @Thunk final PackageInstaller mInstaller;
private final IconCache mCache;
private final Handler mWorker;
@@ -82,7 +83,7 @@
return activePackages;
}
- private void addSessionInfoToCahce(SessionInfo info, UserHandleCompat user) {
+ @Thunk void addSessionInfoToCahce(SessionInfo info, UserHandleCompat user) {
String packageName = info.getAppPackageName();
if (packageName != null) {
mCache.cachePackageInstallInfo(packageName, user, info.getAppIcon(),
@@ -123,7 +124,7 @@
replayUpdates(null);
}
- private void replayUpdates(PackageInstallInfo newInfo) {
+ @Thunk void replayUpdates(PackageInstallInfo newInfo) {
if (DEBUG) Log.d(TAG, "updates resumed");
if (!mResumed || !mBound) {
// Not yet ready
diff --git a/src/com/android/launcher3/util/ComponentKey.java b/src/com/android/launcher3/util/ComponentKey.java
new file mode 100644
index 0000000..0f17f00
--- /dev/null
+++ b/src/com/android/launcher3/util/ComponentKey.java
@@ -0,0 +1,51 @@
+package com.android.launcher3.util;
+
+/**
+ * Copyright (C) 2015 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.
+ */
+
+import android.content.ComponentName;
+
+import com.android.launcher3.compat.UserHandleCompat;
+
+import java.util.Arrays;
+
+public class ComponentKey {
+
+ public final ComponentName componentName;
+ public final UserHandleCompat user;
+
+ private final int mHashCode;
+
+ public ComponentKey(ComponentName componentName, UserHandleCompat user) {
+ assert (componentName != null);
+ assert (user != null);
+ this.componentName = componentName;
+ this.user = user;
+ mHashCode = Arrays.hashCode(new Object[] {componentName, user});
+
+ }
+
+ @Override
+ public int hashCode() {
+ return mHashCode;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ ComponentKey other = (ComponentKey) o;
+ return other.componentName.equals(componentName) && other.user.equals(user);
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/launcher3/util/FocusLogic.java b/src/com/android/launcher3/util/FocusLogic.java
index 0c6bfbf..6e80c2f 100644
--- a/src/com/android/launcher3/util/FocusLogic.java
+++ b/src/com/android/launcher3/util/FocusLogic.java
@@ -184,21 +184,18 @@
*/
// TODO: get rid of the dynamic matrix creation
public static int[][] createSparseMatrix(CellLayout iconLayout, CellLayout hotseatLayout,
- int orientation, int allappsiconRank, boolean includeAllappsicon) {
+ boolean isHorizontal, int allappsiconRank, boolean includeAllappsicon) {
ViewGroup iconParent = iconLayout.getShortcutsAndWidgets();
ViewGroup hotseatParent = hotseatLayout.getShortcutsAndWidgets();
int m, n;
- if (orientation == Configuration.ORIENTATION_PORTRAIT) {
+ if (isHorizontal) {
m = iconLayout.getCountX();
n = iconLayout.getCountY() + hotseatLayout.getCountY();
- } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ } else {
m = iconLayout.getCountX() + hotseatLayout.getCountX();
n = iconLayout.getCountY();
- } else {
- throw new IllegalStateException(String.format(
- "orientation type=%d is not supported for key board events.", orientation));
}
int[][] matrix = createFullMatrix(m, n, false /* set all cell to empty */);
@@ -215,7 +212,7 @@
// is truncated. If it is negative, then all apps icon index is not inserted.
for(int i = hotseatParent.getChildCount() - 1; i >= (includeAllappsicon ? 0 : 1); i--) {
int delta = 0;
- if (orientation == Configuration.ORIENTATION_PORTRAIT) {
+ if (isHorizontal) {
int cx = ((CellLayout.LayoutParams)
hotseatParent.getChildAt(i).getLayoutParams()).cellX;
if ((includeAllappsicon && cx >= allappsiconRank) ||
@@ -223,7 +220,7 @@
delta = -1;
}
matrix[cx + delta][iconLayout.getCountY()] = iconParent.getChildCount() + i;
- } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ } else {
int cy = ((CellLayout.LayoutParams)
hotseatParent.getChildAt(i).getLayoutParams()).cellY;
if ((includeAllappsicon && cy >= allappsiconRank) ||
diff --git a/src/com/android/launcher3/util/Thunk.java b/src/com/android/launcher3/util/Thunk.java
new file mode 100644
index 0000000..de350b0
--- /dev/null
+++ b/src/com/android/launcher3/util/Thunk.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2015 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.launcher3.util;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Indicates that the given field or method has package visibility solely to prevent the creation
+ * of a synthetic method. In practice, you should treat this field/method as if it were private.
+ * <p>
+ *
+ * When a private method is called from an inner class, the Java compiler generates a simple
+ * package private shim method that the class generated from the inner class can call. This results
+ * in unnecessary bloat and runtime method call overhead. It also gets us closer to the dex method
+ * count limit.
+ * <p>
+ *
+ * If you'd like to see warnings for these synthetic methods in eclipse, turn on:
+ * Window > Preferences > Java > Compiler > Errors/Warnings > "Access to a non-accessible member
+ * of an enclosing type".
+ * <p>
+ *
+ */
+@Retention(RetentionPolicy.SOURCE)
+@Target({ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.TYPE})
+public @interface Thunk { }
\ No newline at end of file
diff --git a/src/com/android/launcher3/util/WallpaperUtils.java b/src/com/android/launcher3/util/WallpaperUtils.java
new file mode 100644
index 0000000..53b2acd
--- /dev/null
+++ b/src/com/android/launcher3/util/WallpaperUtils.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2015 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.launcher3.util;
+
+import android.annotation.TargetApi;
+import android.app.WallpaperManager;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
+import android.graphics.Point;
+import android.os.Build;
+import android.view.WindowManager;
+
+/**
+ * Utility methods for wallpaper management.
+ */
+public final class WallpaperUtils {
+
+ public static final String WALLPAPER_WIDTH_KEY = "wallpaper.width";
+ public static final String WALLPAPER_HEIGHT_KEY = "wallpaper.height";
+ public static final float WALLPAPER_SCREENS_SPAN = 2f;
+
+ public static void suggestWallpaperDimension(Resources res,
+ final SharedPreferences sharedPrefs,
+ WindowManager windowManager,
+ final WallpaperManager wallpaperManager, boolean fallBackToDefaults) {
+ final Point defaultWallpaperSize = WallpaperUtils.getDefaultWallpaperSize(res, windowManager);
+ // If we have saved a wallpaper width/height, use that instead
+
+ int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, -1);
+ int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, -1);
+
+ if (savedWidth == -1 || savedHeight == -1) {
+ if (!fallBackToDefaults) {
+ return;
+ } else {
+ savedWidth = defaultWallpaperSize.x;
+ savedHeight = defaultWallpaperSize.y;
+ }
+ }
+
+ if (savedWidth != wallpaperManager.getDesiredMinimumWidth() ||
+ savedHeight != wallpaperManager.getDesiredMinimumHeight()) {
+ wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight);
+ }
+ }
+
+ /**
+ * As a ratio of screen height, the total distance we want the parallax effect to span
+ * horizontally
+ */
+ public static float wallpaperTravelToScreenWidthRatio(int width, int height) {
+ float aspectRatio = width / (float) height;
+
+ // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
+ // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
+ // We will use these two data points to extrapolate how much the wallpaper parallax effect
+ // to span (ie travel) at any aspect ratio:
+
+ final float ASPECT_RATIO_LANDSCAPE = 16/10f;
+ final float ASPECT_RATIO_PORTRAIT = 10/16f;
+ final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
+ final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
+
+ // To find out the desired width at different aspect ratios, we use the following two
+ // formulas, where the coefficient on x is the aspect ratio (width/height):
+ // (16/10)x + y = 1.5
+ // (10/16)x + y = 1.2
+ // We solve for x and y and end up with a final formula:
+ final float x =
+ (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
+ (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
+ final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
+ return x * aspectRatio + y;
+ }
+
+ private static Point sDefaultWallpaperSize;
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
+ public static Point getDefaultWallpaperSize(Resources res, WindowManager windowManager) {
+ if (sDefaultWallpaperSize == null) {
+ Point minDims = new Point();
+ Point maxDims = new Point();
+ windowManager.getDefaultDisplay().getCurrentSizeRange(minDims, maxDims);
+
+ int maxDim = Math.max(maxDims.x, maxDims.y);
+ int minDim = Math.max(minDims.x, minDims.y);
+
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ Point realSize = new Point();
+ windowManager.getDefaultDisplay().getRealSize(realSize);
+ maxDim = Math.max(realSize.x, realSize.y);
+ minDim = Math.min(realSize.x, realSize.y);
+ }
+
+ // We need to ensure that there is enough extra space in the wallpaper
+ // for the intended parallax effects
+ final int defaultWidth, defaultHeight;
+ if (res.getConfiguration().smallestScreenWidthDp >= 720) {
+ defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
+ defaultHeight = maxDim;
+ } else {
+ defaultWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);
+ defaultHeight = maxDim;
+ }
+ sDefaultWallpaperSize = new Point(defaultWidth, defaultHeight);
+ }
+ return sDefaultWallpaperSize;
+ }
+}
diff --git a/res/anim/no_anim.xml b/tests/res/values/string.xml
similarity index 69%
copy from res/anim/no_anim.xml
copy to tests/res/values/string.xml
index 02b1625..3c1ec5c 100644
--- a/res/anim/no_anim.xml
+++ b/tests/res/values/string.xml
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<!-- Copyright (C) 2015 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.
@@ -14,5 +13,9 @@
limitations under the License.
-->
-<alpha xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="417" />
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+
+ <!-- Dummy string for tests. [DO NOT TRANSLATE] -->
+ <string name="dummy" >Dummy string for tests.</string>
+
+</resources>