am 235a50e0: Merge "Fix ConcurrentModificationException in InstallShortcutReceiver" into jb-ub-now-indigo-rose
* commit '235a50e0d1a303e586c36bc5e70d560b8b924d58':
Fix ConcurrentModificationException in InstallShortcutReceiver
diff --git a/res/layout/wallpaper_picker.xml b/res/layout/wallpaper_picker.xml
index c91cc7e..0492b7b 100644
--- a/res/layout/wallpaper_picker.xml
+++ b/res/layout/wallpaper_picker.xml
@@ -27,6 +27,11 @@
android:id="@+id/cropView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
+ <ImageView
+ android:id="@+id/defaultWallpaperView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="invisible" />
<ProgressBar
android:id="@+id/loading"
style="@android:style/Widget.Holo.ProgressBar.Large"
diff --git a/src/com/android/launcher3/DragLayer.java b/src/com/android/launcher3/DragLayer.java
index 89f8275..159d7d9 100644
--- a/src/com/android/launcher3/DragLayer.java
+++ b/src/com/android/launcher3/DragLayer.java
@@ -480,7 +480,7 @@
}
public void animateViewIntoPosition(DragView dragView, final View child) {
- animateViewIntoPosition(dragView, child, null);
+ animateViewIntoPosition(dragView, child, null, null);
}
public void animateViewIntoPosition(DragView dragView, final int[] pos, float alpha,
@@ -496,8 +496,8 @@
}
public void animateViewIntoPosition(DragView dragView, final View child,
- final Runnable onFinishAnimationRunnable) {
- animateViewIntoPosition(dragView, child, -1, onFinishAnimationRunnable, null);
+ final Runnable onFinishAnimationRunnable, View anchorView) {
+ animateViewIntoPosition(dragView, child, -1, onFinishAnimationRunnable, anchorView);
}
public void animateViewIntoPosition(DragView dragView, final View child, int duration,
@@ -645,8 +645,10 @@
int x = (int) (fromLeft + Math.round(((to.left - fromLeft) * motionPercent)));
int y = (int) (fromTop + Math.round(((to.top - fromTop) * motionPercent)));
- int xPos = x - mDropView.getScrollX() + (mAnchorView != null
- ? (mAnchorViewInitialScrollX - mAnchorView.getScrollX()) : 0);
+ int anchorAdjust = mAnchorView == null ? 0 : (int) (mAnchorView.getScaleX() *
+ (mAnchorViewInitialScrollX - mAnchorView.getScrollX()));
+
+ int xPos = x - mDropView.getScrollX() + anchorAdjust;
int yPos = y - mDropView.getScrollY();
mDropView.setTranslationX(xPos);
diff --git a/src/com/android/launcher3/LauncherAppWidgetHostView.java b/src/com/android/launcher3/LauncherAppWidgetHostView.java
index 83aef1a..51a649a 100644
--- a/src/com/android/launcher3/LauncherAppWidgetHostView.java
+++ b/src/com/android/launcher3/LauncherAppWidgetHostView.java
@@ -65,6 +65,12 @@
}
public boolean onInterceptTouchEvent(MotionEvent ev) {
+ // Just in case the previous long press hasn't been cleared, we make sure to start fresh
+ // on touch down.
+ if (ev.getAction() == MotionEvent.ACTION_DOWN) {
+ mLongPressHelper.cancelLongPress();
+ }
+
// Consume any touch events for ourselves after longpress is triggered
if (mLongPressHelper.hasPerformedLongPress()) {
mLongPressHelper.cancelLongPress();
@@ -110,13 +116,15 @@
@Override
public void onTouchComplete() {
- mLongPressHelper.cancelLongPress();
+ if (!mLongPressHelper.hasPerformedLongPress()) {
+ // If a long press has been performed, we don't want to clear the record of that since
+ // we still may be receiving a touch up which we want to intercept
+ mLongPressHelper.cancelLongPress();
+ }
}
@Override
public int getDescendantFocusability() {
return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
}
-
-
}
diff --git a/src/com/android/launcher3/LauncherBackupHelper.java b/src/com/android/launcher3/LauncherBackupHelper.java
index 9b901ee..8023fcd 100644
--- a/src/com/android/launcher3/LauncherBackupHelper.java
+++ b/src/com/android/launcher3/LauncherBackupHelper.java
@@ -31,9 +31,8 @@
import com.android.launcher3.backup.BackupProtos.Widget;
import android.app.backup.BackupDataInputStream;
-import android.app.backup.BackupHelper;
-import android.app.backup.BackupDataInput;
import android.app.backup.BackupDataOutput;
+import android.app.backup.BackupHelper;
import android.app.backup.BackupManager;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 7e1442d..aad768d 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -186,9 +186,6 @@
mBgAllAppsList = new AllAppsList(iconCache, appFilter);
mIconCache = iconCache;
- mDefaultIcon = Utilities.createIconBitmap(
- mIconCache.getFullResDefaultActivityIcon(), context);
-
final Resources res = context.getResources();
Configuration config = res.getConfiguration();
mPreviousConfigMcc = config.mcc;
@@ -400,6 +397,11 @@
}
public Bitmap getFallbackIcon() {
+ if (mDefaultIcon == null) {
+ final Context context = LauncherAppState.getInstance().getContext();
+ mDefaultIcon = Utilities.createIconBitmap(
+ mIconCache.getFullResDefaultActivityIcon(), context);
+ }
return Bitmap.createBitmap(mDefaultIcon);
}
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index e982985..e724063 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -268,8 +268,6 @@
protected final Rect mInsets = new Rect();
- protected int mFirstChildLeft;
-
public interface PageSwitchListener {
void onPageSwitch(View newPage, int newPageIndex);
}
@@ -899,10 +897,6 @@
requestLayout();
}
- protected int getFirstChildLeft() {
- return mFirstChildLeft;
- }
-
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
if (!mIsDataReady || getChildCount() == 0) {
@@ -928,7 +922,7 @@
int verticalPadding = getPaddingTop() + getPaddingBottom();
- int childLeft = mFirstChildLeft = offsetX + (screenWidth - getChildWidth(startIndex)) / 2;
+ int childLeft = offsetX + (screenWidth - getChildWidth(startIndex)) / 2;
if (mPageScrolls == null || getChildCount() != mChildCountOnLastLayout) {
mPageScrolls = new int[getChildCount()];
}
diff --git a/src/com/android/launcher3/SavedWallpaperImages.java b/src/com/android/launcher3/SavedWallpaperImages.java
index 8d5b005..c19692b 100644
--- a/src/com/android/launcher3/SavedWallpaperImages.java
+++ b/src/com/android/launcher3/SavedWallpaperImages.java
@@ -62,6 +62,7 @@
File file = new File(a.getFilesDir(), imageFilename);
CropView v = a.getCropView();
int rotation = WallpaperCropActivity.getRotationFromExif(file.getAbsolutePath());
+ a.getDefaultWallpaperView().setVisibility(View.INVISIBLE);
v.setTileSource(
new BitmapRegionTileSource(a, file.getAbsolutePath(), 1024, rotation), null);
v.moveToLeft();
diff --git a/src/com/android/launcher3/WallpaperPickerActivity.java b/src/com/android/launcher3/WallpaperPickerActivity.java
index e71a26b..2ad9218 100644
--- a/src/com/android/launcher3/WallpaperPickerActivity.java
+++ b/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -31,7 +31,9 @@
import android.database.DataSetObserver;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
import android.graphics.Matrix;
+import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.Rect;
@@ -40,6 +42,7 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LevelListDrawable;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
@@ -51,10 +54,10 @@
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
+import android.view.View.OnLayoutChangeListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
-import android.view.accessibility.AccessibilityEvent;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.BaseAdapter;
@@ -64,14 +67,11 @@
import android.widget.LinearLayout;
import android.widget.ListAdapter;
-import com.android.gallery3d.exif.ExifInterface;
import com.android.photos.BitmapRegionTileSource;
-import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.util.ArrayList;
public class WallpaperPickerActivity extends WallpaperCropActivity {
@@ -81,6 +81,7 @@
public static final int PICK_WALLPAPER_THIRD_PARTY_ACTIVITY = 6;
public static final int PICK_LIVE_WALLPAPER = 7;
private static final String TEMP_WALLPAPER_TILES = "TEMP_WALLPAPER_TILES";
+ private static final String DEFAULT_WALLPAPER_THUMBNAIL_FILENAME = "default_thumb.jpg";
private View mSelectedThumb;
private boolean mIgnoreNextTap;
@@ -88,6 +89,7 @@
private LinearLayout mWallpapersView;
private View mWallpaperStrip;
+ private ImageView mDefaultWallpaperView;
private ActionMode.Callback mActionModeCallback;
private ActionMode mActionMode;
@@ -133,6 +135,7 @@
public void onClick(WallpaperPickerActivity a) {
CropView v = a.getCropView();
int rotation = WallpaperCropActivity.getRotationFromExif(a, mUri);
+ a.getDefaultWallpaperView().setVisibility(View.INVISIBLE);
v.setTileSource(new BitmapRegionTileSource(a, mUri, 1024, rotation), null);
v.setTouchEnabled(true);
}
@@ -176,6 +179,7 @@
BitmapRegionTileSource source = new BitmapRegionTileSource(
mResources, a, mResId, 1024, rotation);
CropView v = a.getCropView();
+ a.getDefaultWallpaperView().setVisibility(View.INVISIBLE);
v.setTileSource(source, null);
Point wallpaperSize = WallpaperCropActivity.getDefaultWallpaperSize(
a.getResources(), a.getWindowManager());
@@ -200,6 +204,42 @@
}
}
+ public static class DefaultWallpaperInfo extends WallpaperTileInfo {
+ public Drawable mThumb;
+ public DefaultWallpaperInfo(Drawable thumb) {
+ mThumb = thumb;
+ }
+ @Override
+ public void onClick(WallpaperPickerActivity a) {
+ a.getCropView().setTouchEnabled(false);
+ ImageView defaultWallpaperView = a.getDefaultWallpaperView();
+ defaultWallpaperView.setVisibility(View.VISIBLE);
+ Drawable defaultWallpaper = WallpaperManager.getInstance(a).getBuiltInDrawable(
+ defaultWallpaperView.getWidth(), defaultWallpaperView.getHeight(),
+ false, 0.5f, 0.5f);
+ if (defaultWallpaper != null) {
+ defaultWallpaperView.setBackgroundDrawable(defaultWallpaper);
+ }
+ }
+ @Override
+ public void onSave(WallpaperPickerActivity a) {
+ try {
+ WallpaperManager.getInstance(a).clear();
+ } catch (IOException e) {
+ Log.w("Setting wallpaper to default threw exception", e);
+ }
+ a.finish();
+ }
+ @Override
+ public boolean isSelectable() {
+ return true;
+ }
+ @Override
+ public boolean isNamelessWallpaper() {
+ return true;
+ }
+ }
+
public void setWallpaperStripYOffset(float offset) {
mWallpaperStrip.setPadding(0, 0, 0, (int) offset);
}
@@ -209,6 +249,7 @@
setContentView(R.layout.wallpaper_picker);
mCropView = (CropView) findViewById(R.id.cropView);
+ mDefaultWallpaperView = (ImageView) findViewById(R.id.defaultWallpaperView);
mWallpaperStrip = findViewById(R.id.wallpaper_strip);
mCropView.setTouchCallback(new CropView.TouchCallback() {
LauncherViewPropertyAnimator mAnim;
@@ -305,12 +346,12 @@
ArrayList<ResourceWallpaperInfo> wallpapers = findBundledWallpapers();
mWallpapersView = (LinearLayout) findViewById(R.id.wallpaper_list);
BuiltInWallpapersAdapter ia = new BuiltInWallpapersAdapter(this, wallpapers);
- populateWallpapersFromAdapter(mWallpapersView, ia, false, true);
+ populateWallpapersFromAdapter(mWallpapersView, ia, false);
// Populate the saved wallpapers
mSavedImages = new SavedWallpaperImages(this);
mSavedImages.loadThumbnailsAndImageIdList();
- populateWallpapersFromAdapter(mWallpapersView, mSavedImages, true, true);
+ populateWallpapersFromAdapter(mWallpapersView, mSavedImages, true);
// Populate the live wallpapers
final LinearLayout liveWallpapersView =
@@ -319,7 +360,7 @@
a.registerDataSetObserver(new DataSetObserver() {
public void onChanged() {
liveWallpapersView.removeAllViews();
- populateWallpapersFromAdapter(liveWallpapersView, a, false, false);
+ populateWallpapersFromAdapter(liveWallpapersView, a, false);
initializeScrollForRtl();
updateTileIndices();
}
@@ -330,7 +371,7 @@
(LinearLayout) findViewById(R.id.third_party_wallpaper_list);
final ThirdPartyWallpaperPickerListAdapter ta =
new ThirdPartyWallpaperPickerListAdapter(this);
- populateWallpapersFromAdapter(thirdPartyWallpapersView, ta, false, false);
+ populateWallpapersFromAdapter(thirdPartyWallpapersView, ta, false);
// Add a tile for the Gallery
LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list);
@@ -354,7 +395,33 @@
pickImageTile.setTag(pickImageInfo);
pickImageInfo.setView(pickImageTile);
pickImageTile.setOnClickListener(mThumbnailOnClickListener);
- pickImageInfo.setView(pickImageTile);
+
+ // Add a tile for the default wallpaper
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ DefaultWallpaperInfo defaultWallpaperInfo = getDefaultWallpaper();
+ FrameLayout defaultWallpaperTile = (FrameLayout) createImageTileView(
+ getLayoutInflater(), 0, null, mWallpapersView, defaultWallpaperInfo.mThumb);
+ setWallpaperItemPaddingToZero(defaultWallpaperTile);
+ defaultWallpaperTile.setTag(defaultWallpaperInfo);
+ mWallpapersView.addView(defaultWallpaperTile, 0);
+ defaultWallpaperTile.setOnClickListener(mThumbnailOnClickListener);
+ defaultWallpaperInfo.setView(defaultWallpaperTile);
+ }
+
+ // Select the first item; wait for a layout pass so that we initialize the dimensions of
+ // cropView or the defaultWallpaperView first
+ mDefaultWallpaperView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
+ @Override
+ public void onLayoutChange(View v, int left, int top, int right, int bottom,
+ int oldLeft, int oldTop, int oldRight, int oldBottom) {
+ if ((right - left) > 0 && (bottom - top) > 0) {
+ if (mWallpapersView.getChildCount() > 0) {
+ mThumbnailOnClickListener.onClick(mWallpapersView.getChildAt(0));
+ }
+ v.removeOnLayoutChangeListener(this);
+ }
+ }
+ });
updateTileIndices();
@@ -520,7 +587,7 @@
}
private void populateWallpapersFromAdapter(ViewGroup parent, BaseAdapter adapter,
- boolean addLongPressHandler, boolean selectFirstTile) {
+ boolean addLongPressHandler) {
for (int i = 0; i < adapter.getCount(); i++) {
FrameLayout thumbnail = (FrameLayout) adapter.getView(i, null, parent);
parent.addView(thumbnail, i);
@@ -531,9 +598,6 @@
addLongPressHandler(thumbnail);
}
thumbnail.setOnClickListener(mThumbnailOnClickListener);
- if (i == 0 && selectFirstTile) {
- mThumbnailOnClickListener.onClick(thumbnail);
- }
}
}
@@ -700,18 +764,35 @@
}
// Add an entry for the default wallpaper (stored in system resources)
- ResourceWallpaperInfo defaultWallpaperInfo = getDefaultWallpaperInfo();
- if (defaultWallpaperInfo != null) {
- bundledWallpapers.add(0, defaultWallpaperInfo);
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+ ResourceWallpaperInfo defaultWallpaperInfo = getPreKKDefaultWallpaperInfo();
+ if (defaultWallpaperInfo != null) {
+ bundledWallpapers.add(0, defaultWallpaperInfo);
+ }
}
return bundledWallpapers;
}
- private ResourceWallpaperInfo getDefaultWallpaperInfo() {
+ private boolean writeImageToFileAsJpeg(File f, Bitmap b) {
+ try {
+ f.createNewFile();
+ FileOutputStream thumbFileStream =
+ openFileOutput(f.getName(), Context.MODE_PRIVATE);
+ b.compress(Bitmap.CompressFormat.JPEG, 95, thumbFileStream);
+ thumbFileStream.close();
+ return true;
+ } catch (IOException e) {
+ Log.e(TAG, "Error while writing bitmap to file " + e);
+ f.delete();
+ }
+ return false;
+ }
+
+ private ResourceWallpaperInfo getPreKKDefaultWallpaperInfo() {
Resources sysRes = Resources.getSystem();
int resId = sysRes.getIdentifier("default_wallpaper", "drawable", "android");
- File defaultThumbFile = new File(getFilesDir(), "default_thumb.jpg");
+ File defaultThumbFile = new File(getFilesDir(), DEFAULT_WALLPAPER_THUMBNAIL_FILENAME);
Bitmap thumb = null;
boolean defaultWallpaperExists = false;
if (defaultThumbFile.exists()) {
@@ -724,17 +805,7 @@
thumb = createThumbnail(
defaultThumbSize, this, null, null, sysRes, resId, rotation, false);
if (thumb != null) {
- try {
- defaultThumbFile.createNewFile();
- FileOutputStream thumbFileStream =
- openFileOutput(defaultThumbFile.getName(), Context.MODE_PRIVATE);
- thumb.compress(Bitmap.CompressFormat.JPEG, 95, thumbFileStream);
- thumbFileStream.close();
- defaultWallpaperExists = true;
- } catch (IOException e) {
- Log.e(TAG, "Error while writing default wallpaper thumbnail to file " + e);
- defaultThumbFile.delete();
- }
+ defaultWallpaperExists = writeImageToFileAsJpeg(defaultThumbFile, thumb);
}
}
if (defaultWallpaperExists) {
@@ -743,6 +814,37 @@
return null;
}
+ private DefaultWallpaperInfo getDefaultWallpaper() {
+ File defaultThumbFile = new File(getFilesDir(), DEFAULT_WALLPAPER_THUMBNAIL_FILENAME);
+ Bitmap thumb = null;
+ boolean defaultWallpaperExists = false;
+ if (defaultThumbFile.exists()) {
+ thumb = BitmapFactory.decodeFile(defaultThumbFile.getAbsolutePath());
+ defaultWallpaperExists = true;
+ } else {
+ Resources res = getResources();
+ Point defaultThumbSize = getDefaultThumbnailSize(res);
+ Paint p = new Paint();
+ p.setFilterBitmap(true);
+ Drawable wallpaperDrawable = WallpaperManager.getInstance(this).getBuiltInDrawable(
+ defaultThumbSize.x, defaultThumbSize.y, true, 0.5f, 0.5f);
+ if (wallpaperDrawable != null) {
+ thumb = Bitmap.createBitmap(
+ defaultThumbSize.x, defaultThumbSize.y, Bitmap.Config.ARGB_8888);
+ Canvas c = new Canvas(thumb);
+ wallpaperDrawable.draw(c);
+ c.setBitmap(null);
+ }
+ if (thumb != null) {
+ defaultWallpaperExists = writeImageToFileAsJpeg(defaultThumbFile, thumb);
+ }
+ }
+ if (defaultWallpaperExists) {
+ return new DefaultWallpaperInfo(new BitmapDrawable(thumb));
+ }
+ return null;
+ }
+
public Pair<ApplicationInfo, Integer> getWallpaperArrayResourceId() {
// Context.getPackageName() may return the "original" package name,
// com.android.launcher3; Resources needs the real package name,
@@ -784,6 +886,10 @@
return mCropView;
}
+ public ImageView getDefaultWallpaperView() {
+ return mDefaultWallpaperView;
+ }
+
public SavedWallpaperImages getSavedImages() {
return mSavedImages;
}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 908a61e..2fdcb43 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1199,10 +1199,8 @@
// TODO: do different behavior if it's a live wallpaper?
// Sometimes the left parameter of the pages is animated during a layout transition;
// this parameter offsets it to keep the wallpaper from animating as well
- int offsetForLayoutTransitionAnimation = isLayoutRtl() ?
- getPageAt(getChildCount() - 1).getLeft() - getFirstChildLeft() : 0;
int adjustedScroll =
- getScrollX() - firstPageScrollX - offsetForLayoutTransitionAnimation;
+ getScrollX() - firstPageScrollX - getLayoutTransitionOffsetForPage(0);
float offset = Math.min(1, adjustedScroll / (float) scrollRange);
offset = Math.max(0, offset);
// Don't use up all the wallpaper parallax until you have at least
@@ -3654,7 +3652,7 @@
// the correct final location.
setFinalTransitionTransform(cellLayout);
mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, view,
- exitSpringLoadedRunnable);
+ exitSpringLoadedRunnable, this);
resetTransitionTransform(cellLayout);
}
}