diff options
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/launcher3/BubbleTextView.java | 3 | ||||
-rw-r--r-- | src/com/android/launcher3/CropView.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/DragController.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher3/DynamicGrid.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 170 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherModel.java | 116 | ||||
-rw-r--r-- | src/com/android/launcher3/LiveWallpaperListAdapter.java | 237 | ||||
-rw-r--r-- | src/com/android/launcher3/ShortcutAndWidgetContainer.java | 3 | ||||
-rw-r--r-- | src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java | 117 | ||||
-rw-r--r-- | src/com/android/launcher3/WallpaperCropActivity.java | 3 | ||||
-rw-r--r-- | src/com/android/launcher3/WallpaperPickerActivity.java | 193 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 76 |
12 files changed, 570 insertions, 356 deletions
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index bb6903d43..7a7a3b61f 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -102,10 +102,13 @@ public class BubbleTextView extends TextView { public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) { Bitmap b = info.getIcon(iconCache); + LauncherAppState app = LauncherAppState.getInstance(); + DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(b), null, null); + setCompoundDrawablePadding((int) ((grid.folderIconSizePx - grid.iconSizePx) / 2f)); setText(info.title); setTag(info); } diff --git a/src/com/android/launcher3/CropView.java b/src/com/android/launcher3/CropView.java index 32c590d91..c4d1475c6 100644 --- a/src/com/android/launcher3/CropView.java +++ b/src/com/android/launcher3/CropView.java @@ -44,6 +44,7 @@ public class CropView extends TiledImageView implements OnScaleGestureListener { public interface TouchCallback { void onTouchDown(); void onTap(); + void onTouchUp(); } public CropView(Context context) { @@ -202,6 +203,7 @@ public class CropView extends TiledImageView implements OnScaleGestureListener { now < mTouchDownTime + ViewConfiguration.getTapTimeout()) { mTouchCallback.onTap(); } + mTouchCallback.onTouchUp(); } if (!mTouchEnabled) { diff --git a/src/com/android/launcher3/DragController.java b/src/com/android/launcher3/DragController.java index f51366f86..4c4f399a9 100644 --- a/src/com/android/launcher3/DragController.java +++ b/src/com/android/launcher3/DragController.java @@ -687,10 +687,6 @@ public class DragController { } } mDragObject.dragSource.onDropCompleted((View) dropTarget, mDragObject, false, accepted); - - // Write all the logs to disk - Launcher.addDumpLog(TAG, "10249126 - DragController.drop() - dumping logs to disk", true); - mLauncher.dumpLogsToLocalData(false); } private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) { diff --git a/src/com/android/launcher3/DynamicGrid.java b/src/com/android/launcher3/DynamicGrid.java index 70f000053..6e101750f 100644 --- a/src/com/android/launcher3/DynamicGrid.java +++ b/src/com/android/launcher3/DynamicGrid.java @@ -207,7 +207,7 @@ class DeviceProfile { // Folder folderCellWidthPx = cellWidthPx + 3 * edgeMarginPx; - folderCellHeightPx = cellHeightPx + edgeMarginPx; + folderCellHeightPx = cellHeightPx + (int) ((3f/2f) * edgeMarginPx); folderBackgroundOffset = -edgeMarginPx; folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset; } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index ad7d238ca..89d4cb379 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -130,6 +130,7 @@ public class Launcher extends Activity static final boolean DEBUG_WIDGETS = false; static final boolean DEBUG_STRICT_MODE = false; static final boolean DEBUG_RESUME_TIME = false; + static final boolean DEBUG_DUMP_LOG = false; private static final int REQUEST_CREATE_SHORTCUT = 1; private static final int REQUEST_CREATE_APPWIDGET = 5; @@ -889,10 +890,6 @@ public class Launcher extends Activity if (DEBUG_RESUME_TIME) { Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime)); } - - // Write all the logs to disk - Launcher.addDumpLog(TAG, "10249126 - onResume() - dumping logs to disk", true); - dumpLogsToLocalData(false); } @Override @@ -909,10 +906,6 @@ public class Launcher extends Activity mPaused = true; mDragController.cancelDrag(); mDragController.resetLastGestureUpTime(); - - // Write all the logs to disk - Launcher.addDumpLog(TAG, "10249126 - onPause() - dumping logs to disk", true); - dumpLogsToLocalData(false); } protected void onFinishBindingItems() { @@ -930,12 +923,14 @@ public class Launcher extends Activity if (mWorkspace.isOnOrMovingToCustomContent()) { mSearchDropTargetBar.setTranslationY(- scrollY); + getQsbBar().setTranslationY(-scrollY); } } }; public void resetQSBScroll() { mSearchDropTargetBar.animate().translationY(0).start(); + getQsbBar().animate().translationY(0).start(); } public interface CustomContentCallbacks { @@ -3586,7 +3581,6 @@ public class Launcher extends Activity public void bindAddScreens(ArrayList<Long> orderedScreenIds) { int count = orderedScreenIds.size(); for (int i = 0; i < count; i++) { - Launcher.addDumpLog(TAG, "10249126 - bindAddScreens(" + orderedScreenIds.get(i) + ")", true); mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i)); } } @@ -3644,8 +3638,6 @@ public class Launcher extends Activity return; } - Launcher.addDumpLog(TAG, "10249126 - bindAppsAdded(" + newScreens.size() + ")", true); - // Add the new screens bindAddScreens(newScreens); @@ -3868,10 +3860,6 @@ public class Launcher extends Activity onFinishBindingItems(); } }); - - // Write all the logs to disk - Launcher.addDumpLog(TAG, "10249126 - finishBindingItems() - dumping logs to disk", true); - dumpLogsToLocalData(false); } private boolean canRunNewAppsAnimation() { @@ -4272,15 +4260,17 @@ public class Launcher extends Activity } public static void dumpDebugLogsToConsole() { - synchronized (sDumpLogs) { - Log.d(TAG, ""); - Log.d(TAG, "*********************"); - Log.d(TAG, "Launcher debug logs: "); - for (int i = 0; i < sDumpLogs.size(); i++) { - Log.d(TAG, " " + sDumpLogs.get(i)); + if (DEBUG_DUMP_LOG) { + synchronized (sDumpLogs) { + Log.d(TAG, ""); + Log.d(TAG, "*********************"); + Log.d(TAG, "Launcher debug logs: "); + for (int i = 0; i < sDumpLogs.size(); i++) { + Log.d(TAG, " " + sDumpLogs.get(i)); + } + Log.d(TAG, "*********************"); + Log.d(TAG, ""); } - Log.d(TAG, "*********************"); - Log.d(TAG, ""); } } @@ -4288,105 +4278,59 @@ public class Launcher extends Activity if (debugLog) { Log.d(tag, log); } - sDateStamp.setTime(System.currentTimeMillis()); - synchronized (sDumpLogs) { - sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log); + if (DEBUG_DUMP_LOG) { + sDateStamp.setTime(System.currentTimeMillis()); + synchronized (sDumpLogs) { + sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log); + } } } - public void dumpLogsToLocalData(final boolean email) { - new Thread("DumpLogsToLocalData") { - @Override - public void run() { - boolean success = false; - sDateStamp.setTime(sRunStart); - String FILENAME = sDateStamp.getMonth() + "-" - + sDateStamp.getDay() + "_" - + sDateStamp.getHours() + "-" - + sDateStamp.getMinutes() + "_" - + sDateStamp.getSeconds() + ".txt"; - - FileOutputStream fos = null; - File outFile = null; - try { - outFile = new File(getFilesDir(), FILENAME); - outFile.createNewFile(); - fos = new FileOutputStream(outFile); - } catch (Exception e) { - e.printStackTrace(); - } - if (fos != null) { - PrintWriter writer = new PrintWriter(fos); - - writer.println(" "); - writer.println("Debug logs: "); - synchronized (sDumpLogs) { - for (int i = 0; i < sDumpLogs.size(); i++) { - writer.println(" " + sDumpLogs.get(i)); - } + public void dumpLogsToLocalData() { + if (DEBUG_DUMP_LOG) { + new Thread("DumpLogsToLocalData") { + @Override + public void run() { + boolean success = false; + sDateStamp.setTime(sRunStart); + String FILENAME = sDateStamp.getMonth() + "-" + + sDateStamp.getDay() + "_" + + sDateStamp.getHours() + "-" + + sDateStamp.getMinutes() + "_" + + sDateStamp.getSeconds() + ".txt"; + + FileOutputStream fos = null; + File outFile = null; + try { + outFile = new File(getFilesDir(), FILENAME); + outFile.createNewFile(); + fos = new FileOutputStream(outFile); + } catch (Exception e) { + e.printStackTrace(); } - writer.close(); - } - try { if (fos != null) { - fos.close(); - success = true; + PrintWriter writer = new PrintWriter(fos); + + writer.println(" "); + writer.println("Debug logs: "); + synchronized (sDumpLogs) { + for (int i = 0; i < sDumpLogs.size(); i++) { + writer.println(" " + sDumpLogs.get(i)); + } + } + writer.close(); } - } catch (IOException e) { - e.printStackTrace(); - } - - if (success && email) { - if (!emailSent()) { - emailFile(outFile); + try { + if (fos != null) { + fos.close(); + success = true; + } + } catch (IOException e) { + e.printStackTrace(); } } - } - }.start(); - } - - private void emailFile(File file) { - File publicCopy = new File(Environment.getExternalStorageDirectory(), file.getName()); - try { - copyFile(file, publicCopy); - } catch (IOException e) { - e.printStackTrace(); - return; - } - - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"adamcohen@google.com, winsonc@google.com," + - "mikejurka@google"}); - intent.putExtra(Intent.EXTRA_SUBJECT, "Data corruption " + file.getName()); - intent.putExtra(Intent.EXTRA_TEXT, "Data corruption has occurred, logs attached"); - - if (!file.exists() || !file.canRead()) { - Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show(); - finish(); - return; - } - - Toast.makeText(this, "Data corruption has occurred, please send e-mail", Toast.LENGTH_LONG); - Uri uri = Uri.fromFile(publicCopy); - intent.putExtra(Intent.EXTRA_STREAM, uri); - startActivity(Intent.createChooser(intent, "Please send logs, consider clearing data")); - - setEmailSent(true); - } - - public void copyFile(File src, File dst) throws IOException { - InputStream in = new FileInputStream(src); - OutputStream out = new FileOutputStream(dst); - - // Transfer bytes from in to out - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); + }.start(); } - in.close(); - out.close(); } } diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index aaa901ac1..bc0d1bcc1 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -170,7 +170,7 @@ public class LauncherModel extends BroadcastReceiver { public void bindPackagesUpdated(ArrayList<Object> widgetsAndShortcuts); public void bindSearchablesChanged(); public void onPageBoundSynchronously(int page); - public void dumpLogsToLocalData(boolean email); + public void dumpLogsToLocalData(); } public interface ItemInfoFilter { @@ -286,7 +286,6 @@ public class LauncherModel extends BroadcastReceiver { } public void addAndBindAddedApps(final Context context, final ArrayList<ItemInfo> added, final Callbacks callbacks, final ArrayList<AppInfo> addedApps) { - Launcher.addDumpLog(TAG, "10249126 - addAndBindAddedApps()", true); if (added.isEmpty()) { return; } @@ -333,7 +332,6 @@ public class LauncherModel extends BroadcastReceiver { workspaceScreens.size()); while (numPagesToAdd > 0) { long screenId = lp.generateNewScreenId(); - Launcher.addDumpLog(TAG, "10249126 - addAndBindAddedApps(" + screenId + ")", true); // Save the screen id for binding in the workspace workspaceScreens.add(screenId); addedWorkspaceScreensFinal.add(screenId); @@ -365,8 +363,6 @@ public class LauncherModel extends BroadcastReceiver { } } - Launcher.addDumpLog(TAG, "10249126 - addAndBindAddedApps - updateWorkspaceScreenOrder(" + workspaceScreens.size() + ")", true); - // Update the workspace screens updateWorkspaceScreenOrder(context, workspaceScreens); @@ -571,7 +567,6 @@ public class LauncherModel extends BroadcastReceiver { String msg = "item: " + item + " container being set to: " + item.container + ", not in the list of folders"; Log.e(TAG, msg); - Launcher.dumpDebugLogsToConsole(); } } @@ -632,11 +627,6 @@ public class LauncherModel extends BroadcastReceiver { */ static void moveItemInDatabase(Context context, final ItemInfo item, final long container, final long screenId, final int cellX, final int cellY) { - String transaction = "DbDebug Modify item (" + item.title + ") in db, id: " + item.id + - " (" + item.container + ", " + item.screenId + ", " + item.cellX + ", " + item.cellY + - ") --> " + "(" + container + ", " + screenId + ", " + cellX + ", " + cellY + ")"; - Launcher.addDumpLog(TAG, transaction, true); - item.container = container; item.cellX = cellX; item.cellY = cellY; @@ -671,11 +661,6 @@ public class LauncherModel extends BroadcastReceiver { for (int i = 0; i < count; i++) { ItemInfo item = items.get(i); - String transaction = "DbDebug Modify item (" + item.title + ") in db, id: " - + item.id + " (" + item.container + ", " + item.screenId + ", " + item.cellX - + ", " + item.cellY + ") --> " + "(" + container + ", " + screen + ", " - + item.cellX + ", " + item.cellY + ")"; - Launcher.addDumpLog(TAG, transaction, true); item.container = container; // We store hotseat items in canonical form which is this orientation invariant position @@ -704,11 +689,6 @@ public class LauncherModel extends BroadcastReceiver { */ static void modifyItemInDatabase(Context context, final ItemInfo item, final long container, final long screenId, final int cellX, final int cellY, final int spanX, final int spanY) { - String transaction = "DbDebug Modify item (" + item.title + ") in db, id: " + item.id + - " (" + item.container + ", " + item.screenId + ", " + item.cellX + ", " + item.cellY + - ") --> " + "(" + container + ", " + screenId + ", " + cellX + ", " + cellY + ")"; - Launcher.addDumpLog(TAG, transaction, true); - item.cellX = cellX; item.cellY = cellY; item.spanX = spanX; @@ -874,11 +854,6 @@ public class LauncherModel extends BroadcastReceiver { Runnable r = new Runnable() { public void run() { - String transaction = "DbDebug Add item (" + item.title + ") to db, id: " - + item.id + " (" + container + ", " + screenId + ", " + cellX + ", " - + cellY + ")"; - Launcher.addDumpLog(TAG, transaction, true); - cr.insert(notify ? LauncherSettings.Favorites.CONTENT_URI : LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values); @@ -901,7 +876,6 @@ public class LauncherModel extends BroadcastReceiver { String msg = "adding item: " + item + " to a folder that " + " doesn't exist"; Log.e(TAG, msg); - Launcher.dumpDebugLogsToConsole(); } } break; @@ -935,11 +909,6 @@ public class LauncherModel extends BroadcastReceiver { Runnable r = new Runnable() { public void run() { - String transaction = "DbDebug Delete item (" + item.title + ") from db, id: " - + item.id + " (" + item.container + ", " + item.screenId + ", " + item.cellX + - ", " + item.cellY + ")"; - Launcher.addDumpLog(TAG, transaction, true); - cr.delete(uriToDelete, null, null); // Lock on mBgLock *after* the db operation @@ -954,7 +923,6 @@ public class LauncherModel extends BroadcastReceiver { String msg = "deleting a folder (" + item + ") which still " + "contains items (" + info + ")"; Log.e(TAG, msg); - Launcher.dumpDebugLogsToConsole(); } } sBgWorkspaceItems.remove(item); @@ -980,7 +948,6 @@ public class LauncherModel extends BroadcastReceiver { * a list of screen ids in the order that they should appear. */ void updateWorkspaceScreenOrder(Context context, final ArrayList<Long> screens) { - Launcher.addDumpLog(TAG, "10249126 - updateWorkspaceScreenOrder()", true); final ArrayList<Long> screensCopy = new ArrayList<Long>(screens); final ContentResolver cr = context.getContentResolver(); final Uri uri = LauncherSettings.WorkspaceScreens.CONTENT_URI; @@ -990,17 +957,10 @@ public class LauncherModel extends BroadcastReceiver { while (iter.hasNext()) { long id = iter.next(); if (id < 0) { - Launcher.addDumpLog(TAG, "10249126 - updateWorkspaceScreenOrder - remove: " + id + ")", true); iter.remove(); } } - // Dump the screens copy - Launcher.addDumpLog(TAG, "10249126 - updateWorkspaceScreenOrder - screensCopy", true); - for (Long l : screensCopy) { - Launcher.addDumpLog(TAG, "10249126\t- " + l, true); - } - Runnable r = new Runnable() { @Override public void run() { @@ -1013,26 +973,13 @@ public class LauncherModel extends BroadcastReceiver { long screenId = screensCopy.get(i); v.put(LauncherSettings.WorkspaceScreens._ID, screenId); v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i); - Launcher.addDumpLog(TAG, "10249126 - updateWorkspaceScreenOrder(" + screenId + ", " + i + ")", true); values[i] = v; } cr.bulkInsert(uri, values); synchronized (sBgLock) { - // Dump the sBgWorkspaceScreens - Launcher.addDumpLog(TAG, "10249126 - updateWorkspaceScreenOrder - sBgWorkspaceScreens - pre clear", true); - for (Long l : sBgWorkspaceScreens) { - Launcher.addDumpLog(TAG, "10249126\t- " + l, true); - } - sBgWorkspaceScreens.clear(); sBgWorkspaceScreens.addAll(screensCopy); - - // Dump the sBgWorkspaceScreens - Launcher.addDumpLog(TAG, "10249126 - updateWorkspaceScreenOrder - sBgWorkspaceScreens - post clear", true); - for (Long l : sBgWorkspaceScreens) { - Launcher.addDumpLog(TAG, "10249126\t- " + l, true); - } } } }; @@ -1273,9 +1220,6 @@ public class LauncherModel extends BroadcastReceiver { try { long screenId = sc.getLong(idIndex); int rank = sc.getInt(rankIndex); - - Launcher.addDumpLog(TAG, "10249126 - loadWorkspaceScreensDb(" + screenId + ", " + rank + ")", true); - orderedScreens.put(rank, screenId); } catch (Exception e) { Launcher.addDumpLog(TAG, "Desktop items loading interrupted - invalid screens: " + e, true); @@ -1343,7 +1287,6 @@ public class LauncherModel extends BroadcastReceiver { isUpgradePath = loadWorkspace(); synchronized (LoaderTask.this) { if (mStopped) { - Launcher.addDumpLog(TAG, "10249126 - loadAndBindWorkspace() stopped", true); return isUpgradePath; } mWorkspaceLoaded = true; @@ -1484,10 +1427,7 @@ public class LauncherModel extends BroadcastReceiver { if (AppsCustomizePagedView.DISABLE_ALL_APPS) { // Ensure that all the applications that are in the system are // represented on the home screen. - Launcher.addDumpLog(TAG, "10249126 - verifyApplications - useMoreApps=" - + UPGRADE_USE_MORE_APPS_FOLDER + " isUpgrade=" + isUpgrade, true); if (!UPGRADE_USE_MORE_APPS_FOLDER || !isUpgrade) { - Launcher.addDumpLog(TAG, "10249126 - verifyApplications(" + isUpgrade + ")", true); verifyApplications(); } } @@ -1507,7 +1447,6 @@ public class LauncherModel extends BroadcastReceiver { public void stopLocked() { synchronized (LoaderTask.this) { - Launcher.addDumpLog(TAG, "10249126 - STOPPED", true); mStopped = true; this.notify(); } @@ -1552,7 +1491,6 @@ public class LauncherModel extends BroadcastReceiver { synchronized (sBgLock) { for (AppInfo app : mBgAllAppsList.data) { tmpInfos = getItemInfoForComponentName(app.componentName); - Launcher.addDumpLog(TAG, "10249126 - \t" + app.componentName.getPackageName() + ", " + tmpInfos.isEmpty(), true); if (tmpInfos.isEmpty()) { // We are missing an application icon, so add this to the workspace added.add(app); @@ -1667,7 +1605,6 @@ public class LauncherModel extends BroadcastReceiver { synchronized (sBgLock) { clearSBgDataStructures(); - Launcher.addDumpLog(TAG, "10249126 - loadWorkspace()", true); final ArrayList<Long> itemsToRemove = new ArrayList<Long>(); final Uri contentUri = LauncherSettings.Favorites.CONTENT_URI; @@ -1720,7 +1657,6 @@ public class LauncherModel extends BroadcastReceiver { long id; Intent intent; - Launcher.addDumpLog(TAG, "10249126 - Num rows: " + c.getCount(), true); while (!mStopped && c.moveToNext()) { try { int itemType = c.getInt(itemTypeIndex); @@ -1739,7 +1675,6 @@ public class LauncherModel extends BroadcastReceiver { Uri uri = LauncherSettings.Favorites.getContentUri(id, false); contentResolver.delete(uri, null, null); - Launcher.addDumpLog(TAG, "Invalid package removed: " + cn, true); } else { // If apps can be on external storage, then we just // leave them for the user to remove (maybe add @@ -1932,7 +1867,6 @@ public class LauncherModel extends BroadcastReceiver { // Break early if we've stopped loading if (mStopped) { - Launcher.addDumpLog(TAG, "10249126 - loadWorkspace() - Stopped", true); clearSBgDataStructures(); return false; } @@ -1956,14 +1890,12 @@ public class LauncherModel extends BroadcastReceiver { } if (loadedOldDb) { - Launcher.addDumpLog(TAG, "10249126 - loadWorkspace - loadedOldDb", true); long maxScreenId = 0; // If we're importing we use the old screen order. for (ItemInfo item: sBgItemsIdMap.values()) { long screenId = item.screenId; if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP && !sBgWorkspaceScreens.contains(screenId)) { - Launcher.addDumpLog(TAG, "10249126 - loadWorkspace-loadedOldDb(" + screenId + ")", true); sBgWorkspaceScreens.add(screenId); if (screenId > maxScreenId) { maxScreenId = screenId; @@ -1972,12 +1904,6 @@ public class LauncherModel extends BroadcastReceiver { } Collections.sort(sBgWorkspaceScreens); - // Dump the sBgWorkspaceScreens - Launcher.addDumpLog(TAG, "10249126 - updateWorkspaceScreenOrder - sBgWorkspaceScreens", true); - for (Long l : sBgWorkspaceScreens) { - Launcher.addDumpLog(TAG, "10249126\t- " + l, true); - } - LauncherAppState.getLauncherProvider().updateMaxScreenId(maxScreenId); updateWorkspaceScreenOrder(context, sBgWorkspaceScreens); @@ -1989,50 +1915,24 @@ public class LauncherModel extends BroadcastReceiver { } LauncherAppState.getLauncherProvider().updateMaxItemId(maxItemId); } else { - Launcher.addDumpLog(TAG, "10249126 - loadWorkspace - !loadedOldDb [" + sWorkerThread.getThreadId() + ", " + Process.myTid() + "]", true); TreeMap<Integer, Long> orderedScreens = loadWorkspaceScreensDb(mContext); for (Integer i : orderedScreens.keySet()) { - Launcher.addDumpLog(TAG, "10249126 - adding to sBgWorkspaceScreens: " + orderedScreens.get(i), true); sBgWorkspaceScreens.add(orderedScreens.get(i)); } // Remove any empty screens ArrayList<Long> unusedScreens = new ArrayList<Long>(sBgWorkspaceScreens); - for (Long l : unusedScreens) { - Launcher.addDumpLog(TAG, "10249126 - unused screens: " + l, true); - } - - Launcher.addDumpLog(TAG, "10249126 - sBgItemsIdMap [" + sWorkerThread.getThreadId() + ", " + Process.myTid() + "]", true); for (ItemInfo item: sBgItemsIdMap.values()) { long screenId = item.screenId; - Launcher.addDumpLog(TAG, "10249126 - \t" + item.container + ", " + screenId + " - " + unusedScreens.contains(screenId) + " | " + item, true); - if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP && unusedScreens.contains(screenId)) { unusedScreens.remove(screenId); - Launcher.addDumpLog(TAG, "10249126 - \t\tRemoving " + screenId, true); - for (Long l : unusedScreens) { - Launcher.addDumpLog(TAG, "10249126 - \t\t\t unused screens: " + l, true); - } } } // If there are any empty screens remove them, and update. if (unusedScreens.size() != 0) { - // Dump the sBgWorkspaceScreens - Launcher.addDumpLog(TAG, "10249126 - updateWorkspaceScreenOrder - sBgWorkspaceScreens - pre removeAll", true); - for (Long l : sBgWorkspaceScreens) { - Launcher.addDumpLog(TAG, "10249126\t- " + l, true); - } - sBgWorkspaceScreens.removeAll(unusedScreens); - - // Dump the sBgWorkspaceScreens - Launcher.addDumpLog(TAG, "10249126 - updateWorkspaceScreenOrder - sBgWorkspaceScreens - post removeAll", true); - for (Long l : sBgWorkspaceScreens) { - Launcher.addDumpLog(TAG, "10249126\t- " + l, true); - } - updateWorkspaceScreenOrder(context, sBgWorkspaceScreens); } } @@ -2185,16 +2085,6 @@ public class LauncherModel extends BroadcastReceiver { private void bindWorkspaceScreens(final Callbacks oldCallbacks, final ArrayList<Long> orderedScreens) { - Launcher.addDumpLog(TAG, "10249126 - bindWorkspaceScreens()", true); - - // Dump the orderedScreens - synchronized (sBgLock) { - Launcher.addDumpLog(TAG, "10249126 - orderedScreens", true); - for (Long l : sBgWorkspaceScreens) { - Launcher.addDumpLog(TAG, "10249126\t- " + l, true); - } - } - final Runnable r = new Runnable() { @Override public void run() { @@ -2278,7 +2168,6 @@ public class LauncherModel extends BroadcastReceiver { * Binds all loaded data to actual views on the main thread. */ private void bindWorkspace(int synchronizeBindPage, final boolean isUpgradePath) { - Launcher.addDumpLog(TAG, "10249126 - bindWorkspace(" + synchronizeBindPage + ", " + isUpgradePath + ")", true); final long t = SystemClock.uptimeMillis(); Runnable r; @@ -2679,12 +2568,11 @@ public class LauncherModel extends BroadcastReceiver { }); // Write all the logs to disk - Launcher.addDumpLog(TAG, "10249126 - PackageUpdatedTask - dumping logs to disk", true); mHandler.post(new Runnable() { public void run() { Callbacks cb = mCallbacks != null ? mCallbacks.get() : null; if (callbacks == cb && cb != null) { - callbacks.dumpLogsToLocalData(false); + callbacks.dumpLogsToLocalData(); } } }); diff --git a/src/com/android/launcher3/LiveWallpaperListAdapter.java b/src/com/android/launcher3/LiveWallpaperListAdapter.java new file mode 100644 index 000000000..a6facaa02 --- /dev/null +++ b/src/com/android/launcher3/LiveWallpaperListAdapter.java @@ -0,0 +1,237 @@ +/* + * 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.app.WallpaperInfo; +import android.content.Context; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; +import android.content.pm.ResolveInfo; +import android.graphics.drawable.Drawable; +import android.os.AsyncTask; +import android.service.wallpaper.WallpaperService; +import android.util.Log; +import android.view.LayoutInflater; +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 org.xmlpull.v1.XmlPullParserException; + +import java.io.IOException; +import java.text.Collator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class LiveWallpaperListAdapter extends BaseAdapter implements ListAdapter { + private static final String LOG_TAG = "LiveWallpaperListAdapter"; + + private final LayoutInflater mInflater; + private final PackageManager mPackageManager; + + private List<LiveWallpaperInfo> mWallpapers; + + @SuppressWarnings("unchecked") + public LiveWallpaperListAdapter(Context context) { + mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mPackageManager = context.getPackageManager(); + + List<ResolveInfo> list = mPackageManager.queryIntentServices( + new Intent(WallpaperService.SERVICE_INTERFACE), + PackageManager.GET_META_DATA); + + mWallpapers = generatePlaceholderViews(list.size()); + + new LiveWallpaperEnumerator(context).execute(list); + } + + private List<LiveWallpaperInfo> generatePlaceholderViews(int amount) { + ArrayList<LiveWallpaperInfo> list = new ArrayList<LiveWallpaperInfo>(amount); + for (int i = 0; i < amount; i++) { + LiveWallpaperInfo info = new LiveWallpaperInfo(); + list.add(info); + } + return list; + } + + public int getCount() { + if (mWallpapers == null) { + return 0; + } + return mWallpapers.size(); + } + + public Object getItem(int position) { + return mWallpapers.get(position); + } + + public long getItemId(int position) { + return position; + } + + public View getView(int position, View convertView, ViewGroup parent) { + View view; + + if (convertView == null) { + view = mInflater.inflate(R.layout.live_wallpaper_picker_item, parent, false); + } else { + view = convertView; + } + + WallpaperPickerActivity.setWallpaperItemPaddingToZero((FrameLayout) view); + + LiveWallpaperInfo wallpaperInfo = mWallpapers.get(position); + ImageView image = (ImageView) view.findViewById(R.id.wallpaper_image); + ImageView icon = (ImageView) view.findViewById(R.id.wallpaper_icon); + if (wallpaperInfo.thumbnail != null) { + image.setImageDrawable(wallpaperInfo.thumbnail); + icon.setVisibility(View.GONE); + } else { + icon.setImageDrawable(wallpaperInfo.info.loadIcon(mPackageManager)); + icon.setVisibility(View.VISIBLE); + } + + TextView label = (TextView) view.findViewById(R.id.wallpaper_item_label); + label.setText(wallpaperInfo.info.loadLabel(mPackageManager)); + + return view; + } + + public class LiveWallpaperInfo { + public Drawable thumbnail; + public WallpaperInfo info; + public Intent intent; + } + + private class LiveWallpaperEnumerator extends + AsyncTask<List<ResolveInfo>, LiveWallpaperInfo, Void> { + private Context mContext; + private int mWallpaperPosition; + + public LiveWallpaperEnumerator(Context context) { + super(); + mContext = context; + mWallpaperPosition = 0; + } + + @Override + protected Void doInBackground(List<ResolveInfo>... params) { + final PackageManager packageManager = mContext.getPackageManager(); + + List<ResolveInfo> list = params[0]; + + Collections.sort(list, new Comparator<ResolveInfo>() { + final Collator mCollator; + + { + mCollator = Collator.getInstance(); + } + + public int compare(ResolveInfo info1, ResolveInfo info2) { + return mCollator.compare(info1.loadLabel(packageManager), + info2.loadLabel(packageManager)); + } + }); + + for (ResolveInfo resolveInfo : list) { + WallpaperInfo info = null; + try { + info = new WallpaperInfo(mContext, resolveInfo); + } catch (XmlPullParserException e) { + Log.w(LOG_TAG, "Skipping wallpaper " + resolveInfo.serviceInfo, e); + continue; + } catch (IOException e) { + Log.w(LOG_TAG, "Skipping wallpaper " + resolveInfo.serviceInfo, e); + continue; + } + + LiveWallpaperInfo wallpaper = new LiveWallpaperInfo(); + wallpaper.intent = new Intent(WallpaperService.SERVICE_INTERFACE); + wallpaper.intent.setClassName(info.getPackageName(), info.getServiceName()); + wallpaper.info = info; + + Drawable thumb = info.loadThumbnail(packageManager); + // TODO: generate a default thumb + /* + final Resources res = mContext.getResources(); + Canvas canvas = new Canvas(); + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG); + paint.setTextAlign(Paint.Align.CENTER); + BitmapDrawable galleryIcon = (BitmapDrawable) res.getDrawable( + R.drawable.livewallpaper_placeholder); + if (thumb == null) { + int thumbWidth = res.getDimensionPixelSize( + R.dimen.live_wallpaper_thumbnail_width); + int thumbHeight = res.getDimensionPixelSize( + R.dimen.live_wallpaper_thumbnail_height); + + Bitmap thumbnail = Bitmap.createBitmap(thumbWidth, thumbHeight, + Bitmap.Config.ARGB_8888); + + paint.setColor(res.getColor(R.color.live_wallpaper_thumbnail_background)); + canvas.setBitmap(thumbnail); + canvas.drawPaint(paint); + + galleryIcon.setBounds(0, 0, thumbWidth, thumbHeight); + galleryIcon.setGravity(Gravity.CENTER); + galleryIcon.draw(canvas); + + String title = info.loadLabel(packageManager).toString(); + + paint.setColor(res.getColor(R.color.live_wallpaper_thumbnail_text_color)); + paint.setTextSize( + res.getDimensionPixelSize(R.dimen.live_wallpaper_thumbnail_text_size)); + + canvas.drawText(title, (int) (thumbWidth * 0.5), + thumbHeight - res.getDimensionPixelSize( + R.dimen.live_wallpaper_thumbnail_text_offset), paint); + + thumb = new BitmapDrawable(res, thumbnail); + }*/ + wallpaper.thumbnail = thumb; + publishProgress(wallpaper); + } + + return null; + } + + @Override + protected void onProgressUpdate(LiveWallpaperInfo...infos) { + for (LiveWallpaperInfo info : infos) { + info.thumbnail.setDither(true); + if (mWallpaperPosition < mWallpapers.size()) { + mWallpapers.set(mWallpaperPosition, info); + } else { + mWallpapers.add(info); + } + mWallpaperPosition++; + if (mWallpaperPosition == getCount()) { + LiveWallpaperListAdapter.this.notifyDataSetChanged(); + } + } + } + } +} diff --git a/src/com/android/launcher3/ShortcutAndWidgetContainer.java b/src/com/android/launcher3/ShortcutAndWidgetContainer.java index 5ce557192..b9511005e 100644 --- a/src/com/android/launcher3/ShortcutAndWidgetContainer.java +++ b/src/com/android/launcher3/ShortcutAndWidgetContainer.java @@ -137,7 +137,8 @@ public class ShortcutAndWidgetContainer extends ViewGroup { // Otherwise, center the icon int cHeight = mIsHotseatLayout ? grid.hotseatCellHeightPx : Math.min(getMeasuredHeight(), grid.cellHeightPx); int cellPaddingY = (int) Math.max(0, ((lp.height - cHeight) / 2f)); - child.setPadding(0, cellPaddingY, 0, 0); + int cellPaddingX = (int) (grid.edgeMarginPx / 2f); + child.setPadding(cellPaddingX, cellPaddingY, cellPaddingX, 0); } } else { lp.x = 0; diff --git a/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java b/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java new file mode 100644 index 000000000..9fd0d0a5f --- /dev/null +++ b/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java @@ -0,0 +1,117 @@ +/* + * 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.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.view.LayoutInflater; +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 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 List<ResolveInfo> mThirdPartyWallpaperPickers = new ArrayList<ResolveInfo>(); + + public ThirdPartyWallpaperPickerListAdapter(Context context) { + mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mPackageManager = context.getPackageManager(); + final PackageManager pm = mPackageManager; + + final Intent pickWallpaperIntent = new Intent(Intent.ACTION_SET_WALLPAPER); + final List<ResolveInfo> apps = + pm.queryIntentActivities(pickWallpaperIntent, 0); + + // Get list of image picker intents + Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT); + pickImageIntent.setType("image/*"); + final List<ResolveInfo> imagePickerActivities = + pm.queryIntentActivities(pickImageIntent, 0); + final ComponentName[] imageActivities = new ComponentName[imagePickerActivities.size()]; + for (int i = 0; i < imagePickerActivities.size(); i++) { + ActivityInfo activityInfo = imagePickerActivities.get(i).activityInfo; + imageActivities[i] = new ComponentName(activityInfo.packageName, activityInfo.name); + } + + outerLoop: + for (ResolveInfo info : apps) { + final ComponentName itemComponentName = + new ComponentName(info.activityInfo.packageName, info.activityInfo.name); + final String itemPackageName = itemComponentName.getPackageName(); + // Exclude anything from our own package, and the old Launcher, + // and live wallpaper picker + if (itemPackageName.equals(context.getPackageName()) || + itemPackageName.equals("com.android.launcher") || + itemPackageName.equals("com.android.wallpaper.livepicker")) { + continue; + } + // Exclude any package that already responds to the image picker intent + for (ResolveInfo imagePickerActivityInfo : imagePickerActivities) { + if (itemPackageName.equals( + imagePickerActivityInfo.activityInfo.packageName)) { + continue outerLoop; + } + } + mThirdPartyWallpaperPickers.add(info); + } + } + + public int getCount() { + return mThirdPartyWallpaperPickers.size(); + } + + public Object getItem(int position) { + return mThirdPartyWallpaperPickers.get(position); + } + + public long getItemId(int position) { + return position; + } + + public View getView(int position, View convertView, ViewGroup parent) { + View view; + + if (convertView == null) { + view = mInflater.inflate(R.layout.third_party_wallpaper_picker_item, parent, false); + } else { + view = convertView; + } + + WallpaperPickerActivity.setWallpaperItemPaddingToZero((FrameLayout) view); + + ResolveInfo info = mThirdPartyWallpaperPickers.get(position); + TextView label = (TextView) view.findViewById(R.id.wallpaper_item_label); + label.setText(info.loadLabel(mPackageManager)); + label.setCompoundDrawablesWithIntrinsicBounds( + null, info.loadIcon(mPackageManager), null, null); + return view; + } +} diff --git a/src/com/android/launcher3/WallpaperCropActivity.java b/src/com/android/launcher3/WallpaperCropActivity.java index f5a6b80b3..f35948058 100644 --- a/src/com/android/launcher3/WallpaperCropActivity.java +++ b/src/com/android/launcher3/WallpaperCropActivity.java @@ -138,12 +138,13 @@ public class WallpaperCropActivity extends Activity { windowManager.getDefaultDisplay().getCurrentSizeRange(minDims, maxDims); int maxDim = Math.max(maxDims.x, maxDims.y); - final int minDim = Math.min(minDims.x, minDims.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 diff --git a/src/com/android/launcher3/WallpaperPickerActivity.java b/src/com/android/launcher3/WallpaperPickerActivity.java index 824dea642..868b1dfb8 100644 --- a/src/com/android/launcher3/WallpaperPickerActivity.java +++ b/src/com/android/launcher3/WallpaperPickerActivity.java @@ -19,6 +19,8 @@ package com.android.launcher3; import android.animation.LayoutTransition; import android.app.ActionBar; import android.app.Activity; +import android.app.WallpaperInfo; +import android.app.WallpaperManager; import android.content.ComponentName; import android.content.Intent; import android.content.pm.ActivityInfo; @@ -27,8 +29,10 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.database.Cursor; +import android.database.DataSetObserver; import android.graphics.Bitmap; import android.graphics.Point; +import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; @@ -66,6 +70,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { private static final int IMAGE_PICK = 5; private static final int PICK_WALLPAPER_THIRD_PARTY_ACTIVITY = 6; + private static final int PICK_LIVE_WALLPAPER = 7; private static final String TEMP_WALLPAPER_TILES = "TEMP_WALLPAPER_TILES"; private ArrayList<Drawable> mBundledWallpaperThumbs; @@ -85,12 +90,15 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { ArrayList<Uri> mTempWallpaperTiles = new ArrayList<Uri>(); private SavedWallpaperImages mSavedImages; + private WallpaperInfo mLiveWallpaperInfoOnPickerLaunch; private static class ThumbnailMetaData { - public boolean mLaunchesGallery; + public TileType mTileType; public Uri mWallpaperUri; public int mSavedWallpaperDbId; public int mWallpaperResId; + public LiveWallpaperListAdapter.LiveWallpaperInfo mLiveWallpaperInfo; + public ResolveInfo mThirdPartyWallpaperPickerInfo; } // called by onCreate; this is subclassed to overwrite WallpaperCropActivity @@ -101,6 +109,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { final View wallpaperStrip = findViewById(R.id.wallpaper_strip); mCropView.setTouchCallback(new CropView.TouchCallback() { LauncherViewPropertyAnimator mAnim; + @Override public void onTouchDown() { if (mAnim != null) { mAnim.cancel(); @@ -113,6 +122,11 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { .setInterpolator(new DecelerateInterpolator(0.75f)); mAnim.start(); } + @Override + public void onTouchUp() { + mIgnoreNextTap = false; + } + @Override public void onTap() { boolean ignoreTap = mIgnoreNextTap; mIgnoreNextTap = false; @@ -142,29 +156,38 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } ThumbnailMetaData meta = (ThumbnailMetaData) v.getTag(); - - if (!meta.mLaunchesGallery) { + if (meta.mTileType == TileType.WALLPAPER_RESOURCE || + meta.mTileType == TileType.SAVED_WALLPAPER || + meta.mTileType == TileType.WALLPAPER_URI) { mSelectedThumb = v; v.setSelected(true); } - - if (meta.mLaunchesGallery) { + if (meta.mTileType == TileType.PICK_IMAGE) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); Utilities.startActivityForResultSafely( WallpaperPickerActivity.this, intent, IMAGE_PICK); - } else if (meta.mWallpaperUri != null) { + } else if (meta.mTileType == TileType.WALLPAPER_URI) { mCropView.setTileSource(new BitmapRegionTileSource(WallpaperPickerActivity.this, meta.mWallpaperUri, 1024, 0), null); mCropView.setTouchEnabled(true); - } else if (meta.mSavedWallpaperDbId != 0) { + } else if (meta.mTileType == TileType.SAVED_WALLPAPER) { String imageFilename = mSavedImages.getImageFilename(meta.mSavedWallpaperDbId); File file = new File(getFilesDir(), imageFilename); mCropView.setTileSource(new BitmapRegionTileSource(WallpaperPickerActivity.this, file.getAbsolutePath(), 1024, 0), null); mCropView.moveToLeft(); mCropView.setTouchEnabled(false); - } else if (meta.mWallpaperResId != 0) { + } else if (meta.mTileType == TileType.LIVE_WALLPAPER) { + Intent preview = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER); + preview.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, + meta.mLiveWallpaperInfo.info.getComponent()); + WallpaperManager wm = + WallpaperManager.getInstance(WallpaperPickerActivity.this); + mLiveWallpaperInfoOnPickerLaunch = wm.getWallpaperInfo(); + Utilities.startActivityForResultSafely(WallpaperPickerActivity.this, + preview, PICK_LIVE_WALLPAPER); + } else if (meta.mTileType == TileType.WALLPAPER_RESOURCE) { BitmapRegionTileSource source = new BitmapRegionTileSource(mWallpaperResources, WallpaperPickerActivity.this, meta.mWallpaperResId, 1024, 0); mCropView.setTileSource(source, null); @@ -175,6 +198,15 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { wallpaperSize.x, wallpaperSize.y, false); mCropView.setScale(wallpaperSize.x / crop.width()); mCropView.setTouchEnabled(false); + } else if (meta.mTileType == TileType.THIRD_PARTY_WALLPAPER_PICKER) { + ResolveInfo info = meta.mThirdPartyWallpaperPickerInfo; + + final ComponentName itemComponentName = new ComponentName( + info.activityInfo.packageName, info.activityInfo.name); + Intent launchIntent = new Intent(Intent.ACTION_SET_WALLPAPER); + launchIntent.setComponent(itemComponentName); + Utilities.startActivityForResultSafely(WallpaperPickerActivity.this, + launchIntent, PICK_WALLPAPER_THIRD_PARTY_ACTIVITY); } } }; @@ -202,7 +234,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { findBundledWallpapers(); mWallpapersView = (LinearLayout) findViewById(R.id.wallpaper_list); ImageAdapter ia = new ImageAdapter(this, mBundledWallpaperThumbs); - populateWallpapersFromAdapter(mWallpapersView, ia, mBundledWallpaperResIds, true, false); + populateWallpapersFromAdapter( + mWallpapersView, ia, mBundledWallpaperResIds, TileType.WALLPAPER_RESOURCE, false, true); // Populate the saved wallpapers mSavedImages = new SavedWallpaperImages(this); @@ -210,13 +243,34 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { ArrayList<Drawable> savedWallpaperThumbs = mSavedImages.getThumbnails(); ArrayList<Integer > savedWallpaperIds = mSavedImages.getImageIds(); ia = new ImageAdapter(this, savedWallpaperThumbs); - populateWallpapersFromAdapter(mWallpapersView, ia, savedWallpaperIds, false, true); + populateWallpapersFromAdapter( + mWallpapersView, ia, savedWallpaperIds, TileType.SAVED_WALLPAPER, true, true); + + // Populate the live wallpapers + final LinearLayout liveWallpapersView = (LinearLayout) findViewById(R.id.live_wallpaper_list); + final LiveWallpaperListAdapter a = new LiveWallpaperListAdapter(this); + a.registerDataSetObserver(new DataSetObserver() { + public void onChanged() { + liveWallpapersView.removeAllViews(); + populateWallpapersFromAdapter( + liveWallpapersView, a, null, TileType.LIVE_WALLPAPER, false, false); + } + }); + + // Populate the third-party wallpaper pickers + final LinearLayout thirdPartyWallpapersView = + (LinearLayout) findViewById(R.id.third_party_wallpaper_list); + final ThirdPartyWallpaperPickerListAdapter ta = + new ThirdPartyWallpaperPickerListAdapter(this); + populateWallpapersFromAdapter(thirdPartyWallpapersView, ta, null, + TileType.THIRD_PARTY_WALLPAPER_PICKER, false, false); // Add a tile for the Gallery + LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list); FrameLayout galleryThumbnail = (FrameLayout) getLayoutInflater(). - inflate(R.layout.wallpaper_picker_gallery_item, mWallpapersView, false); + inflate(R.layout.wallpaper_picker_gallery_item, masterWallpaperList, false); setWallpaperItemPaddingToZero(galleryThumbnail); - mWallpapersView.addView(galleryThumbnail, 0); + masterWallpaperList.addView(galleryThumbnail, 0); // Make its background the last photo taken on external storage Bitmap lastPhoto = getThumbnailOfLastPhoto(); @@ -224,10 +278,12 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { ImageView galleryThumbnailBg = (ImageView) galleryThumbnail.findViewById(R.id.wallpaper_image); galleryThumbnailBg.setImageBitmap(getThumbnailOfLastPhoto()); + int colorOverlay = getResources().getColor(R.color.wallpaper_picker_translucent_gray); + galleryThumbnailBg.setColorFilter(colorOverlay, PorterDuff.Mode.SRC_ATOP); } ThumbnailMetaData meta = new ThumbnailMetaData(); - meta.mLaunchesGallery = true; + meta.mTileType = TileType.PICK_IMAGE; galleryThumbnail.setTag(meta); galleryThumbnail.setOnClickListener(mThumbnailOnClickListener); @@ -247,7 +303,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { @Override public void onClick(View v) { ThumbnailMetaData meta = (ThumbnailMetaData) mSelectedThumb.getTag(); - if (meta.mLaunchesGallery) { + if (meta.mTileType == TileType.PICK_IMAGE) { // shouldn't be selected, but do nothing } else if (meta.mWallpaperUri != null) { boolean finishActivityWhenDone = true; @@ -385,24 +441,39 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } } - private void populateWallpapersFromAdapter(ViewGroup parent, ImageAdapter ia, - ArrayList<Integer> imageIds, boolean imagesAreResources, boolean addLongPressHandler) { - for (int i = 0; i < ia.getCount(); i++) { - FrameLayout thumbnail = (FrameLayout) ia.getView(i, null, parent); + private enum TileType { + PICK_IMAGE, + WALLPAPER_RESOURCE, + WALLPAPER_URI, + SAVED_WALLPAPER, + LIVE_WALLPAPER, + THIRD_PARTY_WALLPAPER_PICKER + }; + + private void populateWallpapersFromAdapter(ViewGroup parent, BaseAdapter adapter, + ArrayList<Integer> imageIds, TileType tileType, boolean addLongPressHandler, boolean selectFirstTile) { + for (int i = 0; i < adapter.getCount(); i++) { + FrameLayout thumbnail = (FrameLayout) adapter.getView(i, null, parent); parent.addView(thumbnail, i); ThumbnailMetaData meta = new ThumbnailMetaData(); - if (imagesAreResources) { + meta.mTileType = tileType; + if (tileType == TileType.WALLPAPER_RESOURCE) { meta.mWallpaperResId = imageIds.get(i); - } else { + } else if (tileType == TileType.SAVED_WALLPAPER) { meta.mSavedWallpaperDbId = imageIds.get(i); + } else if (tileType == TileType.LIVE_WALLPAPER) { + meta.mLiveWallpaperInfo = + (LiveWallpaperListAdapter.LiveWallpaperInfo) adapter.getItem(i); + } else if (tileType == TileType.THIRD_PARTY_WALLPAPER_PICKER) { + meta.mThirdPartyWallpaperPickerInfo = (ResolveInfo) adapter.getItem(i); } thumbnail.setTag(meta); if (addLongPressHandler) { addLongPressHandler(thumbnail); } thumbnail.setOnClickListener(mThumbnailOnClickListener); - if (i == 0) { + if (i == 0 && selectFirstTile) { mThumbnailOnClickListener.onClick(thumbnail); } } @@ -452,9 +523,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } else { Log.e(TAG, "Error loading thumbnail for uri=" + uri); } - mWallpapersView.addView(pickedImageThumbnail, 1); + mWallpapersView.addView(pickedImageThumbnail, 0); ThumbnailMetaData meta = new ThumbnailMetaData(); + meta.mTileType = TileType.WALLPAPER_URI; meta.mWallpaperUri = uri; pickedImageThumbnail.setTag(meta); pickedImageThumbnail.setOnClickListener(mThumbnailOnClickListener); @@ -466,13 +538,24 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { Uri uri = data.getData(); addTemporaryWallpaperTile(uri); } else if (requestCode == PICK_WALLPAPER_THIRD_PARTY_ACTIVITY) { - // No result code is returned; just return setResult(RESULT_OK); finish(); + } else if (requestCode == PICK_LIVE_WALLPAPER) { + WallpaperManager wm = WallpaperManager.getInstance(this); + final WallpaperInfo oldLiveWallpaper = mLiveWallpaperInfoOnPickerLaunch; + WallpaperInfo newLiveWallpaper = wm.getWallpaperInfo(); + // Try to figure out if a live wallpaper was set; + if (newLiveWallpaper != null && + (oldLiveWallpaper == null || + !oldLiveWallpaper.getComponent().equals(newLiveWallpaper.getComponent()))) { + // Return if a live wallpaper was set + setResult(RESULT_OK); + finish(); + } } } - private static void setWallpaperItemPaddingToZero(FrameLayout frameLayout) { + static void setWallpaperItemPaddingToZero(FrameLayout frameLayout) { frameLayout.setPadding(0, 0, 0, 0); frameLayout.setForeground(new ZeroPaddingDrawable(frameLayout.getForeground())); } @@ -481,68 +564,6 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { v.setOnLongClickListener(mLongClickListener); } - - public boolean onMenuItemSelected(int featureId, MenuItem item) { - if (item.getIntent() == null) { - return super.onMenuItemSelected(featureId, item); - } else { - Utilities.startActivityForResultSafely( - this, item.getIntent(), PICK_WALLPAPER_THIRD_PARTY_ACTIVITY); - return true; - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - final Intent pickWallpaperIntent = new Intent(Intent.ACTION_SET_WALLPAPER); - final PackageManager pm = getPackageManager(); - final List<ResolveInfo> apps = - pm.queryIntentActivities(pickWallpaperIntent, 0); - - SubMenu sub = menu.addSubMenu("Other\u2026"); // TODO: what's the better way to do this? - sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - - - // Get list of image picker intents - Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT); - pickImageIntent.setType("image/*"); - final List<ResolveInfo> imagePickerActivities = - pm.queryIntentActivities(pickImageIntent, 0); - final ComponentName[] imageActivities = new ComponentName[imagePickerActivities.size()]; - for (int i = 0; i < imagePickerActivities.size(); i++) { - ActivityInfo activityInfo = imagePickerActivities.get(i).activityInfo; - imageActivities[i] = new ComponentName(activityInfo.packageName, activityInfo.name); - } - - outerLoop: - for (ResolveInfo info : apps) { - final ComponentName itemComponentName = - new ComponentName(info.activityInfo.packageName, info.activityInfo.name); - final String itemPackageName = itemComponentName.getPackageName(); - // Exclude anything from our own package, and the old Launcher - if (itemPackageName.equals(getPackageName()) || - itemPackageName.equals("com.android.launcher")) { - continue; - } - // Exclude any package that already responds to the image picker intent - for (ResolveInfo imagePickerActivityInfo : imagePickerActivities) { - if (itemPackageName.equals( - imagePickerActivityInfo.activityInfo.packageName)) { - continue outerLoop; - } - } - MenuItem mi = sub.add(info.loadLabel(pm)); - Intent launchIntent = new Intent(Intent.ACTION_SET_WALLPAPER); - launchIntent.setComponent(itemComponentName); - mi.setIntent(launchIntent); - Drawable icon = info.loadIcon(pm); - if (icon != null) { - mi.setIcon(icon); - } - } - return super.onCreateOptionsMenu(menu); - } - private void findBundledWallpapers() { mBundledWallpaperThumbs = new ArrayList<Drawable>(24); mBundledWallpaperResIds = new ArrayList<Integer>(24); diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 2f58571d4..eb2b19df0 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -479,7 +479,6 @@ public class Workspace extends SmoothPagedView } public void removeAllWorkspaceScreens() { - Launcher.addDumpLog(TAG, "10249126 - removeAllWorkspaceScreens()", true); // Remove the pages and clear the screen models removeAllViews(); mScreenOrder.clear(); @@ -490,7 +489,6 @@ public class Workspace extends SmoothPagedView // Find the index to insert this view into. If the empty screen exists, then // insert it before that. int insertIndex = mScreenOrder.indexOf(EXTRA_EMPTY_SCREEN_ID); - Launcher.addDumpLog(TAG, "10249126 - insertNewWorkspaceScreenBeforeEmptyScreen(" + insertIndex + ")", true); if (insertIndex < 0) { insertIndex = mScreenOrder.size(); } @@ -502,9 +500,6 @@ public class Workspace extends SmoothPagedView } public long insertNewWorkspaceScreen(long screenId, int insertIndex) { - String log = "10249126 - insertNewWorkspaceScreen(" + screenId + ", " + insertIndex + ")"; - Launcher.addDumpLog(TAG, log, true); - if (mWorkspaceScreens.containsKey(screenId)) { throw new RuntimeException("Screen id " + screenId + " already exists!"); } @@ -522,7 +517,6 @@ public class Workspace extends SmoothPagedView } public void createCustomContentPage() { - Launcher.addDumpLog(TAG, "10249126 - createCustomContentPage()", true); CellLayout customScreen = (CellLayout) mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null); @@ -540,8 +534,6 @@ public class Workspace extends SmoothPagedView } public void removeCustomContentPage() { - Launcher.addDumpLog(TAG, "10249126 - removeCustomContentPage()", true); - CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID); if (customScreen == null) { throw new RuntimeException("Expected custom content screen to exist"); @@ -609,10 +601,7 @@ public class Workspace extends SmoothPagedView } public void removeExtraEmptyScreen() { - int nScreens = getChildCount(); - nScreens = hasCustomContent() ? nScreens - 1 : nScreens; - - if (mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) && nScreens > 1) { + if (hasExtraEmptyScreen()) { CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID); mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID); mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID); @@ -620,13 +609,13 @@ public class Workspace extends SmoothPagedView } } - public long commitExtraEmptyScreen() { - Launcher.addDumpLog(TAG, "10249126 - commitExtraEmptyScreen()", true); - - // Write all the logs to disk - Launcher.addDumpLog(TAG, "10249126 - commitExtraEmptyScreen() - dumping logs to disk", true); - mLauncher.dumpLogsToLocalData(false); + public boolean hasExtraEmptyScreen() { + int nScreens = getChildCount(); + nScreens = hasCustomContent() ? nScreens - 1 : nScreens; + return mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) && nScreens > 1; + } + public long commitExtraEmptyScreen() { CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID); mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID); mScreenOrder.remove(EXTRA_EMPTY_SCREEN_ID); @@ -643,13 +632,11 @@ public class Workspace extends SmoothPagedView public CellLayout getScreenWithId(long screenId) { - Launcher.addDumpLog(TAG, "10249126 - getScreenWithId(" + screenId + ")", true); CellLayout layout = mWorkspaceScreens.get(screenId); return layout; } public long getIdForScreen(CellLayout layout) { - Launcher.addDumpLog(TAG, "10249126 - getIdForScreen()", true); Iterator<Long> iter = mWorkspaceScreens.keySet().iterator(); while (iter.hasNext()) { long id = iter.next(); @@ -661,7 +648,6 @@ public class Workspace extends SmoothPagedView } public int getPageIndexForScreenId(long screenId) { - Launcher.addDumpLog(TAG, "10249126 - getPageIndexForScreenId(" + screenId + ")", true); return indexOfChild(mWorkspaceScreens.get(screenId)); } @@ -682,8 +668,6 @@ public class Workspace extends SmoothPagedView return; } - Launcher.addDumpLog(TAG, "10249126 - stripEmptyScreens()", true); - int currentPage = getNextPage(); ArrayList<Long> removeScreens = new ArrayList<Long>(); for (Long id: mWorkspaceScreens.keySet()) { @@ -699,7 +683,6 @@ public class Workspace extends SmoothPagedView int pageShift = 0; for (Long id: removeScreens) { - Launcher.addDumpLog(TAG, "10249126 - \tremove(" + id + ")", true); CellLayout cl = mWorkspaceScreens.get(id); mWorkspaceScreens.remove(id); mScreenOrder.remove(id); @@ -1058,9 +1041,6 @@ public class Workspace extends SmoothPagedView sp, mLauncher.getWindowManager(), mWallpaperManager); } - - - protected void snapToPage(int whichPage, Runnable r) { if (mDelayedSnapToPageRunnable != null) { mDelayedSnapToPageRunnable.run(); @@ -1083,7 +1063,9 @@ public class Workspace extends SmoothPagedView boolean mAnimating; long mAnimationStartTime; float mAnimationStartOffset; - final int ANIMATION_DURATION = 250; + private final int ANIMATION_DURATION = 250; + // Don't use all the wallpaper for parallax until you have at least this many pages + private final int MIN_PARALLAX_PAGE_SPAN = 4; int mNumScreens; public WallpaperOffsetInterpolator() { @@ -1096,7 +1078,6 @@ public class Workspace extends SmoothPagedView updateOffset(false); } - private void updateOffset(boolean force) { if (mWaitingForUpdate || force) { mWaitingForUpdate = false; @@ -1138,19 +1119,43 @@ public class Workspace extends SmoothPagedView if (getChildCount() <= 1) { return 0; } - final int lastIndex = isLayoutRtl() ? 0 : getChildCount() - 1; + + // Exclude the leftmost page final int firstIndex = isLayoutRtl() ? getChildCount() - 2 : 1; + // Exclude the last extra empty screen (if we have > MIN_PARALLAX_PAGE_SPAN pages) + int extra = numExtraScreensToIgnore(); + final int lastIndex = isLayoutRtl() ? 0 + extra : getChildCount() - 1 - extra; + int firstPageScrollX = getScrollForPage(firstIndex); int scrollRange = getScrollForPage(lastIndex) - firstPageScrollX; if (scrollRange == 0) { return 0; } else { - // do different behavior if it's a live wallpaper? - float offset = (getScrollX() - firstPageScrollX) / (float) scrollRange; - return offset; + // TODO: do different behavior if it's a live wallpaper? + float offset = Math.min(1, (getScrollX() - firstPageScrollX) / (float) scrollRange); + offset = Math.max(0, offset); + // Don't use up all the wallpaper parallax until you have at least + // MIN_PARALLAX_PAGE_SPAN pages + int numScrollingPages = getNumScreensExcludingExtraEmptyScreenAndLeftmost(); + int parallaxPageSpan = Math.max(MIN_PARALLAX_PAGE_SPAN, numScrollingPages) - 1; + return offset * (numScrollingPages - 1) / parallaxPageSpan; + } + } + + private int numExtraScreensToIgnore() { + int numScrollingPages = getChildCount() - 1; + if (numScrollingPages > MIN_PARALLAX_PAGE_SPAN && hasExtraEmptyScreen()) { + return 1; + } else { + return 0; } } + private int getNumScreensExcludingExtraEmptyScreenAndLeftmost() { + int numScrollingPages = getChildCount() - 1 - numExtraScreensToIgnore(); + return numScrollingPages; + } + public void syncWithScroll() { float offset = wallpaperOffsetForCurrentScroll(); mWallpaperOffset.setFinalX(offset); @@ -1179,12 +1184,12 @@ public class Workspace extends SmoothPagedView public void setFinalX(float x) { scheduleUpdate(); mFinalOffset = Math.max(0f, Math.min(x, 1.0f)); - if (getChildCount() != mNumScreens) { + if (getNumScreensExcludingExtraEmptyScreenAndLeftmost() != mNumScreens) { if (mNumScreens > 0) { // Don't animate if we're going from 0 screens animateToFinal(); } - mNumScreens = getChildCount(); + mNumScreens = getNumScreensExcludingExtraEmptyScreenAndLeftmost(); } } @@ -1746,7 +1751,6 @@ public class Workspace extends SmoothPagedView mScreenOrder.add(getIdForScreen(cl)); } - Launcher.addDumpLog(TAG, "10249126 - onEndReordering()", true); mLauncher.getModel().updateWorkspaceScreenOrder(mLauncher, mScreenOrder); // Re-enable auto layout transitions for page deletion. |