OSDN Git Service

Merge "Fixing issue with numerous empty screens showing when adding a shortcut to...
authorWinson Chung <winsonc@google.com>
Fri, 4 Oct 2013 20:58:25 +0000 (20:58 +0000)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Fri, 4 Oct 2013 20:58:25 +0000 (20:58 +0000)
res/layout/wallpaper_picker.xml
res/layout/wallpaper_picker_image_picker_item.xml [moved from res/layout/wallpaper_picker_gallery_item.xml with 96% similarity]
res/layout/wallpaper_picker_live_wallpaper_item.xml [moved from res/layout/live_wallpaper_picker_item.xml with 90% similarity]
res/layout/wallpaper_picker_third_party_item.xml [moved from res/layout/third_party_wallpaper_picker_item.xml with 95% similarity]
res/values/dimens.xml
src/com/android/launcher3/LauncherAppState.java
src/com/android/launcher3/LauncherBackupAgent.java
src/com/android/launcher3/LiveWallpaperListAdapter.java
src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java
src/com/android/launcher3/WallpaperPickerActivity.java
util/com/android/launcher3/DecoderRing.java

index fd66a57..c91cc7e 100644 (file)
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:orientation="horizontal" >
-                <LinearLayout android:id="@+id/third_party_wallpaper_list"
+                <LinearLayout android:id="@+id/wallpaper_list"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:orientation="horizontal" />
-                <LinearLayout android:id="@+id/wallpaper_list"
+                <LinearLayout android:id="@+id/live_wallpaper_list"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:orientation="horizontal" />
-                <LinearLayout android:id="@+id/live_wallpaper_list"
+                <LinearLayout android:id="@+id/third_party_wallpaper_list"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:orientation="horizontal" />
@@ -32,6 +32,8 @@
         android:id="@+id/wallpaper_item_label"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:ellipsize="marquee"
+        android:gravity="center"
         android:layout_gravity="center"
         android:text="@string/pick_image"
         android:drawableTop="@drawable/ic_images"
         android:scaleType="centerCrop" />
     <ImageView
         android:id="@+id/wallpaper_icon"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
+        android:layout_width="@dimen/wallpaperItemIconSize"
+        android:layout_height="@dimen/wallpaperItemIconSize"
         android:layout_gravity="center"
         android:visibility="gone" />
     <TextView
         android:id="@+id/wallpaper_item_label"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:singleLine="true"
+        android:ellipsize="marquee"
         android:gravity="center"
         android:padding="4dp"
         android:layout_gravity="bottom"
@@ -32,6 +32,8 @@
         android:id="@+id/wallpaper_item_label"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:ellipsize="marquee"
+        android:gravity="center"
         android:layout_gravity="center"
         android:drawablePadding="4dp"
         android:textColor="@android:color/white"/>
index 2910b7c..b4b2367 100644 (file)
@@ -24,6 +24,7 @@
 <!-- Wallpaper picker -->
     <dimen name="wallpaperThumbnailWidth">106.5dp</dimen>
     <dimen name="wallpaperThumbnailHeight">94.5dp</dimen>
+    <dimen name="wallpaperItemIconSize">32dp</dimen>
 
 <!-- Cling -->
     <dimen name="clingPunchThroughGraphicCenterRadius">94dp</dimen>
index 7da1c2a..8b34ffb 100644 (file)
@@ -54,6 +54,10 @@ public class LauncherAppState {
         return INSTANCE;
     }
 
+    public static LauncherAppState getInstanceNoCreate() {
+        return INSTANCE;
+    }
+
     public Context getContext() {
         return sContext;
     }
index 7cffe7b..f40238c 100644 (file)
@@ -61,8 +61,6 @@ import java.util.List;
 import java.util.Set;
 import java.util.zip.CRC32;
 
-import static android.graphics.Bitmap.CompressFormat.WEBP;
-
 /**
  * Persist the launcher home state across calamities.
  */
@@ -81,6 +79,9 @@ public class LauncherBackupAgent extends BackupAgent {
 
     public static final int IMAGE_COMPRESSION_QUALITY = 75;
 
+    private static final Bitmap.CompressFormat IMAGE_FORMAT =
+            android.graphics.Bitmap.CompressFormat.PNG;
+
     private static BackupManager sBackupManager;
 
     private static final String[] FAVORITE_PROJECTION = {
@@ -407,8 +408,13 @@ public class LauncherBackupAgent extends BackupAgent {
     private void backupIcons(Journal in, BackupDataOutput data, Journal out,
             ArrayList<Key> keys) throws IOException {
         // persist icons that haven't been persisted yet
+        final LauncherAppState app = LauncherAppState.getInstanceNoCreate();
+        if (app == null) {
+            dataChanged(this); // try again later
+            if (DEBUG) Log.d(TAG, "Launcher is not initialized, delaying icon backup");
+            return;
+        }
         final ContentResolver cr = getContentResolver();
-        final LauncherAppState app = LauncherAppState.getInstance();
         final IconCache iconCache = app.getIconCache();
         final int dpi = getResources().getDisplayMetrics().densityDpi;
 
@@ -519,10 +525,15 @@ public class LauncherBackupAgent extends BackupAgent {
     private void backupWidgets(Journal in, BackupDataOutput data, Journal out,
             ArrayList<Key> keys) throws IOException {
         // persist static widget info that hasn't been persisted yet
+        final LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
+        if (appState == null) {
+            dataChanged(this); // try again later
+            if (DEBUG) Log.d(TAG, "Launcher is not initialized, delaying widget backup");
+            return;
+        }
         final ContentResolver cr = getContentResolver();
-        final PagedViewCellLayout widgetSpacingLayout = new PagedViewCellLayout(this);
         final WidgetPreviewLoader previewLoader = new WidgetPreviewLoader(this);
-        final LauncherAppState appState = LauncherAppState.getInstance();
+        final PagedViewCellLayout widgetSpacingLayout = new PagedViewCellLayout(this);
         final IconCache iconCache = appState.getIconCache();
         final int dpi = getResources().getDisplayMetrics().densityDpi;
         final DeviceProfile profile = appState.getDynamicGrid().getDeviceProfile();
@@ -567,6 +578,7 @@ public class LauncherBackupAgent extends BackupAgent {
                         previewLoader.setPreviewSize(spanX * profile.cellWidthPx,
                                 spanY * profile.cellHeightPx, widgetSpacingLayout);
                         byte[] blob = packWidget(dpi, previewLoader, iconCache, provider);
+                        keys.add(key);
                         writeRowToBackup(key, blob, out, data);
 
                     } else {
@@ -643,7 +655,7 @@ public class LauncherBackupAgent extends BackupAgent {
 
     /** keys need to be strings, serialize and encode. */
     private String keyToBackupKey(Key key) {
-        return Base64.encodeToString(Key.toByteArray(key), Base64.NO_WRAP | Base64.NO_PADDING);
+        return Base64.encodeToString(Key.toByteArray(key), Base64.NO_WRAP);
     }
 
     /** keys need to be strings, decode and parse. */
@@ -775,7 +787,7 @@ public class LauncherBackupAgent extends BackupAgent {
         Resource res = new Resource();
         res.dpi = dpi;
         ByteArrayOutputStream os = new ByteArrayOutputStream();
-        if (icon.compress(WEBP, IMAGE_COMPRESSION_QUALITY, os)) {
+        if (icon.compress(IMAGE_FORMAT, IMAGE_COMPRESSION_QUALITY, os)) {
             res.data = os.toByteArray();
         }
         return writeCheckedBytes(res);
@@ -802,7 +814,7 @@ public class LauncherBackupAgent extends BackupAgent {
             Drawable fullResIcon = iconCache.getFullResIcon(provider.getPackageName(), info.icon);
             Bitmap icon = Utilities.createIconBitmap(fullResIcon, this);
             ByteArrayOutputStream os = new ByteArrayOutputStream();
-            if (icon.compress(WEBP, IMAGE_COMPRESSION_QUALITY, os)) {
+            if (icon.compress(IMAGE_FORMAT, IMAGE_COMPRESSION_QUALITY, os)) {
                 widget.icon.data = os.toByteArray();
                 widget.icon.dpi = dpi;
             }
@@ -811,7 +823,7 @@ public class LauncherBackupAgent extends BackupAgent {
             widget.preview = new Resource();
             Bitmap preview = previewLoader.generateWidgetPreview(info, null);
             ByteArrayOutputStream os = new ByteArrayOutputStream();
-            if (preview.compress(WEBP, IMAGE_COMPRESSION_QUALITY, os)) {
+            if (preview.compress(IMAGE_FORMAT, IMAGE_COMPRESSION_QUALITY, os)) {
                 widget.preview.data = os.toByteArray();
                 widget.preview.dpi = dpi;
             }
index e9e5e79..4b59794 100644 (file)
@@ -85,7 +85,7 @@ public class LiveWallpaperListAdapter extends BaseAdapter implements ListAdapter
         View view;
 
         if (convertView == null) {
-            view = mInflater.inflate(R.layout.live_wallpaper_picker_item, parent, false);
+            view = mInflater.inflate(R.layout.wallpaper_picker_live_wallpaper_item, parent, false);
         } else {
             view = convertView;
         }
index 70ef7c3..494694c 100644 (file)
@@ -22,6 +22,8 @@ import android.content.Intent;
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -38,6 +40,7 @@ public class ThirdPartyWallpaperPickerListAdapter extends BaseAdapter implements
 
     private final LayoutInflater mInflater;
     private final PackageManager mPackageManager;
+    private final int mIconSize;
 
     private List<ThirdPartyWallpaperTile> mThirdPartyWallpaperPickers =
             new ArrayList<ThirdPartyWallpaperTile>();
@@ -61,6 +64,7 @@ public class ThirdPartyWallpaperPickerListAdapter extends BaseAdapter implements
     public ThirdPartyWallpaperPickerListAdapter(Context context) {
         mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         mPackageManager = context.getPackageManager();
+        mIconSize = context.getResources().getDimensionPixelSize(R.dimen.wallpaperItemIconSize);
         final PackageManager pm = mPackageManager;
 
         final Intent pickWallpaperIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
@@ -117,7 +121,7 @@ public class ThirdPartyWallpaperPickerListAdapter extends BaseAdapter implements
         View view;
 
         if (convertView == null) {
-            view = mInflater.inflate(R.layout.third_party_wallpaper_picker_item, parent, false);
+            view = mInflater.inflate(R.layout.wallpaper_picker_third_party_item, parent, false);
         } else {
             view = convertView;
         }
@@ -127,8 +131,9 @@ public class ThirdPartyWallpaperPickerListAdapter extends BaseAdapter implements
         ResolveInfo info = mThirdPartyWallpaperPickers.get(position).mResolveInfo;
         TextView label = (TextView) view.findViewById(R.id.wallpaper_item_label);
         label.setText(info.loadLabel(mPackageManager));
-        label.setCompoundDrawablesWithIntrinsicBounds(
-                null, info.loadIcon(mPackageManager), null, null);
+        Drawable icon = info.loadIcon(mPackageManager);
+        icon.setBounds(new Rect(0, 0, mIconSize, mIconSize));
+        label.setCompoundDrawables(null, icon, null, null);
         return view;
     }
 }
index 12e69d3..9702a3a 100644 (file)
@@ -295,7 +295,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
         // 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, masterWallpaperList, false);
+                inflate(R.layout.wallpaper_picker_image_picker_item, masterWallpaperList, false);
         setWallpaperItemPaddingToZero(galleryThumbnail);
         masterWallpaperList.addView(galleryThumbnail, 0);
 
@@ -554,8 +554,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
 
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         if (requestCode == IMAGE_PICK && resultCode == RESULT_OK) {
-            Uri uri = data.getData();
-            addTemporaryWallpaperTile(uri);
+            if (data != null && data.getData() != null) {
+                Uri uri = data.getData();
+                addTemporaryWallpaperTile(uri);
+            }
         } else if (requestCode == PICK_WALLPAPER_THIRD_PARTY_ACTIVITY) {
             setResult(RESULT_OK);
             finish();
index cde845e..b7349fe 100644 (file)
@@ -100,7 +100,7 @@ class DecoderRing {
         if (type == Key.class) {
             Key key = new Key();
             try {
-                MessageNano.mergeFrom(key, byteStream.toByteArray());
+                key = Key.parseFrom(byteStream.toByteArray());
             } catch (InvalidProtocolBufferNanoException e) {
                 System.err.println("failed to parse proto: " + e);
                 System.exit(1);