Merge "Fix longpress crash." into jb-ub-now-kermit
diff --git a/WallpaperPicker/res/values/config.xml b/WallpaperPicker/res/values/config.xml
index 1b24190..71580b5 100644
--- a/WallpaperPicker/res/values/config.xml
+++ b/WallpaperPicker/res/values/config.xml
@@ -15,4 +15,7 @@
-->
<resources>
<bool name="allow_rotation">false</bool>
+ <!-- Specifies whether to expand the cropped area on both sides (rather
+ than just to one side) -->
+ <bool name="center_crop">false</bool>
</resources>
diff --git a/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java b/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java
index 58add70..44bfdf1 100644
--- a/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java
+++ b/WallpaperPicker/src/com/android/launcher3/SavedWallpaperImages.java
@@ -85,6 +85,9 @@
}
public SavedWallpaperImages(Activity 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();
@@ -215,11 +218,20 @@
Context mContext;
public ImageDb(Context context) {
- super(context, new File(context.getCacheDir(), DB_NAME).getPath(), null, DB_VERSION);
+ super(context, context.getDatabasePath(DB_NAME).getPath(), null, DB_VERSION);
// Store the context for later use
mContext = context;
}
+ public static void moveFromCacheDirectoryIfNecessary(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
+ File oldSavedImagesFile = new File(context.getCacheDir(), ImageDb.DB_NAME);
+ File savedImagesFile = context.getDatabasePath(ImageDb.DB_NAME);
+ if (oldSavedImagesFile.exists()) {
+ oldSavedImagesFile.renameTo(savedImagesFile);
+ }
+ }
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" +
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
index b3ef073..ee7b819 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
@@ -330,10 +330,10 @@
protected void cropImageAndSetWallpaper(Uri uri,
OnBitmapCroppedHandler onBitmapCroppedHandler, final boolean finishActivityWhenDone) {
+ boolean centerCrop = getResources().getBoolean(R.bool.center_crop);
// Get the crop
boolean ltr = mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
-
Display d = getWindowManager().getDefaultDisplay();
Point displaySize = new Point();
@@ -358,15 +358,25 @@
// ADJUST CROP WIDTH
// Extend the crop all the way to the right, for parallax
// (or all the way to the left, in RTL)
- float extraSpace = ltr ? rotatedInSize[0] - cropRect.right : cropRect.left;
+ float extraSpace;
+ if (centerCrop) {
+ extraSpace = 2f * Math.min(rotatedInSize[0] - cropRect.right, cropRect.left);
+ } else {
+ extraSpace = ltr ? rotatedInSize[0] - cropRect.right : cropRect.left;
+ }
// Cap the amount of extra width
float maxExtraSpace = defaultWallpaperSize.x / cropScale - cropRect.width();
extraSpace = Math.min(extraSpace, maxExtraSpace);
- if (ltr) {
- cropRect.right += extraSpace;
+ if (centerCrop) {
+ cropRect.left -= extraSpace / 2f;
+ cropRect.right += extraSpace / 2f;
} else {
- cropRect.left -= extraSpace;
+ if (ltr) {
+ cropRect.right += extraSpace;
+ } else {
+ cropRect.left -= extraSpace;
+ }
}
// ADJUST CROP HEIGHT
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index 5e41fca..156befb 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -84,7 +84,7 @@
mIsScreenLarge = isScreenLarge(sContext.getResources());
mScreenDensity = sContext.getResources().getDisplayMetrics().density;
- mWidgetPreviewCacheDb = new WidgetPreviewLoader.CacheDb(sContext);
+ recreateWidgetPreviewDb();
mIconCache = new IconCache(sContext);
mAppFilter = AppFilter.loadByName(sContext.getString(R.string.app_filter_class));
@@ -115,6 +115,13 @@
resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true,
mFavoritesObserver);
}
+
+ public void recreateWidgetPreviewDb() {
+ if (mWidgetPreviewCacheDb != null) {
+ mWidgetPreviewCacheDb.close();
+ }
+ mWidgetPreviewCacheDb = new WidgetPreviewLoader.CacheDb(sContext);
+ }
/**
* Call from Application.onTerminate(), which is not guaranteed to ever be called.
diff --git a/src/com/android/launcher3/LauncherBackupAgentHelper.java b/src/com/android/launcher3/LauncherBackupAgentHelper.java
index 83e4a60..876cf08 100644
--- a/src/com/android/launcher3/LauncherBackupAgentHelper.java
+++ b/src/com/android/launcher3/LauncherBackupAgentHelper.java
@@ -21,6 +21,7 @@
import android.app.backup.SharedPreferencesBackupHelper;
import android.content.Context;
import android.content.SharedPreferences;
+import android.provider.Settings;
public class LauncherBackupAgentHelper extends BackupAgentHelper {
@@ -28,6 +29,8 @@
private static BackupManager sBackupManager;
+ protected static final String SETTING_RESTORE_ENABLED = "launcher_restore_enabled";
+
/**
* Notify the backup manager that out database is dirty.
*
@@ -54,9 +57,15 @@
@Override
public void onCreate() {
+
+ boolean restoreEnabled = 0 != Settings.Secure.getInt(
+ getContentResolver(), SETTING_RESTORE_ENABLED, 0);
+
addHelper(LauncherBackupHelper.LAUNCHER_PREFS_PREFIX,
- new SharedPreferencesBackupHelper(this,
- LauncherAppState.getSharedPreferencesKey()));
- addHelper(LauncherBackupHelper.LAUNCHER_PREFIX, new LauncherBackupHelper(this));
+ new LauncherPreferencesBackupHelper(this,
+ LauncherAppState.getSharedPreferencesKey(),
+ restoreEnabled));
+ addHelper(LauncherBackupHelper.LAUNCHER_PREFIX,
+ new LauncherBackupHelper(this, restoreEnabled));
}
}
diff --git a/src/com/android/launcher3/LauncherBackupHelper.java b/src/com/android/launcher3/LauncherBackupHelper.java
index a081c21..556d4af 100644
--- a/src/com/android/launcher3/LauncherBackupHelper.java
+++ b/src/com/android/launcher3/LauncherBackupHelper.java
@@ -137,12 +137,15 @@
private final Context mContext;
+ private final boolean mRestoreEnabled;
+
private HashMap<ComponentName, AppWidgetProviderInfo> mWidgetMap;
private ArrayList<Key> mKeys;
- public LauncherBackupHelper(Context context) {
+ public LauncherBackupHelper(Context context, boolean restoreEnabled) {
mContext = context;
+ mRestoreEnabled = restoreEnabled;
}
private void dataChanged() {
@@ -296,8 +299,9 @@
final long updateTime = cursor.getLong(ID_MODIFIED);
Key key = getKey(Key.FAVORITE, id);
keys.add(key);
- currentIds.add(keyToBackupKey(key));
- if (updateTime >= in.t) {
+ final String backupKey = keyToBackupKey(key);
+ currentIds.add(backupKey);
+ if (!savedIds.contains(backupKey) || updateTime >= in.t) {
byte[] blob = packFavorite(cursor);
writeRowToBackup(key, blob, out, data);
}
@@ -364,8 +368,9 @@
final long updateTime = cursor.getLong(ID_MODIFIED);
Key key = getKey(Key.SCREEN, id);
keys.add(key);
- currentIds.add(keyToBackupKey(key));
- if (updateTime >= in.t) {
+ final String backupKey = keyToBackupKey(key);
+ currentIds.add(backupKey);
+ if (!savedIds.contains(backupKey) || updateTime >= in.t) {
byte[] blob = packScreen(cursor);
writeRowToBackup(key, blob, out, data);
}
diff --git a/src/com/android/launcher3/LauncherClings.java b/src/com/android/launcher3/LauncherClings.java
index 541eadd..85937aa 100644
--- a/src/com/android/launcher3/LauncherClings.java
+++ b/src/com/android/launcher3/LauncherClings.java
@@ -373,14 +373,14 @@
showMigrationWorkspaceCling();
}
};
- dismissCling(cling, cb, WORKSPACE_CLING_DISMISSED_KEY,
+ dismissCling(cling, cb, MIGRATION_CLING_DISMISSED_KEY,
DISMISS_CLING_DURATION, true);
}
};
mLauncher.getWorkspace().post(dismissCb);
}
- private void dismissAnyWorkspaceCling(Cling cling, View v) {
+ private void dismissAnyWorkspaceCling(Cling cling, String key, View v) {
Runnable cb = null;
if (v == null) {
cb = new Runnable() {
@@ -389,8 +389,7 @@
}
};
}
- dismissCling(cling, cb, WORKSPACE_CLING_DISMISSED_KEY,
- DISMISS_CLING_DURATION, true);
+ dismissCling(cling, cb, key, DISMISS_CLING_DURATION, true);
// Fade in the search bar
mLauncher.getSearchBar().showSearchBar(true);
@@ -428,12 +427,12 @@
public void dismissMigrationWorkspaceCling(View v) {
Cling cling = (Cling) mLauncher.findViewById(R.id.migration_workspace_cling);
- dismissAnyWorkspaceCling(cling, v);
+ dismissAnyWorkspaceCling(cling, MIGRATION_WORKSPACE_CLING_DISMISSED_KEY, v);
}
public void dismissWorkspaceCling(View v) {
Cling cling = (Cling) mLauncher.findViewById(R.id.workspace_cling);
- dismissAnyWorkspaceCling(cling, v);
+ dismissAnyWorkspaceCling(cling, WORKSPACE_CLING_DISMISSED_KEY, v);
}
public void dismissFolderCling(View v) {
diff --git a/src/com/android/launcher3/LauncherPreferencesBackupHelper.java b/src/com/android/launcher3/LauncherPreferencesBackupHelper.java
new file mode 100644
index 0000000..1ac6ff9
--- /dev/null
+++ b/src/com/android/launcher3/LauncherPreferencesBackupHelper.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2014 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.app.backup.BackupDataInputStream;
+import android.app.backup.SharedPreferencesBackupHelper;
+import android.content.Context;
+
+public class LauncherPreferencesBackupHelper extends SharedPreferencesBackupHelper {
+
+ private final boolean mRestoreEnabled;
+
+ public LauncherPreferencesBackupHelper(Context context, String sharedPreferencesKey,
+ boolean restoreEnabled) {
+ super(context, sharedPreferencesKey);
+ mRestoreEnabled = restoreEnabled;
+ }
+
+ @Override
+ public void restoreEntity(BackupDataInputStream data) {
+ if (mRestoreEnabled) {
+ super.restoreEntity(data);
+ }
+ }
+}
diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java
index 7e1ad6d..3db0b51 100644
--- a/src/com/android/launcher3/WidgetPreviewLoader.java
+++ b/src/com/android/launcher3/WidgetPreviewLoader.java
@@ -10,6 +10,7 @@
import android.content.res.Resources;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteDiskIOException;
import android.database.sqlite.SQLiteOpenHelper;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
@@ -164,6 +165,12 @@
editor.commit();
}
}
+
+ public void recreateDb() {
+ LauncherAppState app = LauncherAppState.getInstance();
+ app.recreateWidgetPreviewDb();
+ mDb = app.getWidgetPreviewCacheDb();
+ }
public void setPreviewSize(int previewWidth, int previewHeight,
PagedViewCellLayout widgetSpacingLayout) {
@@ -347,13 +354,20 @@
preview.compress(Bitmap.CompressFormat.PNG, 100, stream);
values.put(CacheDb.COLUMN_PREVIEW_BITMAP, stream.toByteArray());
values.put(CacheDb.COLUMN_SIZE, mSize);
- db.insert(CacheDb.TABLE_NAME, null, values);
+ try {
+ db.insert(CacheDb.TABLE_NAME, null, values);
+ } catch (SQLiteDiskIOException e) {
+ recreateDb();
+ }
}
private void clearDb() {
SQLiteDatabase db = mDb.getWritableDatabase();
// Delete everything
- db.delete(CacheDb.TABLE_NAME, null, null);
+ try {
+ db.delete(CacheDb.TABLE_NAME, null, null);
+ } catch (SQLiteDiskIOException e) {
+ }
}
public static void removePackageFromDb(final CacheDb cacheDb, final String packageName) {
@@ -363,13 +377,17 @@
new AsyncTask<Void, Void, Void>() {
public Void doInBackground(Void ... args) {
SQLiteDatabase db = cacheDb.getWritableDatabase();
- 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
- );
+ 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) {
+ }
synchronized(sInvalidPackages) {
sInvalidPackages.remove(packageName);
}
@@ -382,9 +400,12 @@
new AsyncTask<Void, Void, Void>() {
public Void doInBackground(Void ... args) {
SQLiteDatabase db = cacheDb.getWritableDatabase();
- db.delete(CacheDb.TABLE_NAME,
- CacheDb.COLUMN_NAME + " = ? ", // SELECT query
- new String[] { objectName }); // args to SELECT query
+ try {
+ db.delete(CacheDb.TABLE_NAME,
+ CacheDb.COLUMN_NAME + " = ? ", // SELECT query
+ new String[] { objectName }); // args to SELECT query
+ } catch (SQLiteDiskIOException e) {
+ }
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
@@ -396,14 +417,20 @@
CacheDb.COLUMN_SIZE + " = ?";
}
SQLiteDatabase db = mDb.getReadableDatabase();
- Cursor 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);
+ 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;
+ }
if (result.getCount() > 0) {
result.moveToFirst();
byte[] blob = result.getBlob(0);