OSDN Git Service

Add content description for wallpaper thumbs
authorMichael Jurka <mikejurka@google.com>
Fri, 4 Oct 2013 19:26:48 +0000 (12:26 -0700)
committerMichael Jurka <mikejurka@google.com>
Mon, 7 Oct 2013 22:39:42 +0000 (15:39 -0700)
Bug: 11012903

res/values/strings.xml
src/com/android/launcher3/LiveWallpaperListAdapter.java
src/com/android/launcher3/SavedWallpaperImages.java
src/com/android/launcher3/WallpaperPickerActivity.java

index dfccd98..9f4f20b 100644 (file)
@@ -38,6 +38,9 @@
         <item quantity="one">%1$d selected</item>
         <item quantity="other">%1$d selected</item>
     </plurals>
+    <!-- Accessibility string used as a label for a particular wallpaper in the Wallpaper Picker list.
+         e.g. "Wallpaper 3 of 10" -->
+    <string name="wallpaper_accessibility_name">Wallpaper %1$d of %2$d</string>
 
     <!-- Label on button to delete wallpaper(s) -->
     <string name="wallpaper_delete">Delete</string>
index 4b59794..54e0af7 100644 (file)
@@ -93,6 +93,7 @@ public class LiveWallpaperListAdapter extends BaseAdapter implements ListAdapter
         WallpaperPickerActivity.setWallpaperItemPaddingToZero((FrameLayout) view);
 
         LiveWallpaperTile wallpaperInfo = mWallpapers.get(position);
+        wallpaperInfo.setView(view);
         ImageView image = (ImageView) view.findViewById(R.id.wallpaper_image);
         ImageView icon = (ImageView) view.findViewById(R.id.wallpaper_icon);
         if (wallpaperInfo.mThumbnail != null) {
@@ -174,46 +175,10 @@ public class LiveWallpaperListAdapter extends BaseAdapter implements ListAdapter
                 Intent launchIntent = new Intent(WallpaperService.SERVICE_INTERFACE);
                 launchIntent.setClassName(info.getPackageName(), info.getServiceName());
                 LiveWallpaperTile wallpaper = new LiveWallpaperTile(thumb, info, launchIntent);
-
-                // 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);
-                }*/
                 publishProgress(wallpaper);
             }
+            // Send a null object to show loading is finished
+            publishProgress((LiveWallpaperTile) null);
 
             return null;
         }
@@ -221,6 +186,10 @@ public class LiveWallpaperListAdapter extends BaseAdapter implements ListAdapter
         @Override
         protected void onProgressUpdate(LiveWallpaperTile...infos) {
             for (LiveWallpaperTile info : infos) {
+                if (info == null) {
+                    LiveWallpaperListAdapter.this.notifyDataSetChanged();
+                    break;
+                }
                 info.mThumbnail.setDither(true);
                 if (mWallpaperPosition < mWallpapers.size()) {
                     mWallpapers.set(mWallpaperPosition, info);
@@ -228,9 +197,6 @@ public class LiveWallpaperListAdapter extends BaseAdapter implements ListAdapter
                     mWallpapers.add(info);
                 }
                 mWallpaperPosition++;
-                if (mWallpaperPosition == getCount()) {
-                    LiveWallpaperListAdapter.this.notifyDataSetChanged();
-                }
             }
         }
     }
index 531672a..ee4888d 100644 (file)
@@ -79,6 +79,10 @@ public class SavedWallpaperImages extends BaseAdapter implements ListAdapter {
         public boolean isSelectable() {
             return true;
         }
+        @Override
+        public boolean isNamelessWallpaper() {
+            return true;
+        }
     }
 
     public SavedWallpaperImages(Activity context) {
index 82c9977..26d858b 100644 (file)
@@ -92,10 +92,20 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
     private WallpaperInfo mLiveWallpaperInfoOnPickerLaunch;
 
     public static abstract class WallpaperTileInfo {
+        protected View mView;
+        public void setView(View v) {
+            mView = v;
+        }
         public void onClick(WallpaperPickerActivity a) {}
         public void onSave(WallpaperPickerActivity a) {}
         public void onDelete(WallpaperPickerActivity a) {}
         public boolean isSelectable() { return false; }
+        public boolean isNamelessWallpaper() { return false; }
+        public void onIndexUpdated(CharSequence label) {
+            if (isNamelessWallpaper()) {
+                mView.setContentDescription(label);
+            }
+        }
     }
 
     public static class PickImageInfo extends WallpaperTileInfo {
@@ -136,6 +146,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
         public boolean isSelectable() {
             return true;
         }
+        @Override
+        public boolean isNamelessWallpaper() {
+            return true;
+        }
     }
 
     public static class ResourceWallpaperInfo extends WallpaperTileInfo {
@@ -171,6 +185,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
         public boolean isSelectable() {
             return true;
         }
+        @Override
+        public boolean isNamelessWallpaper() {
+            return true;
+        }
     }
 
     public void setWallpaperStripYOffset(float offset) {
@@ -282,6 +300,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
                 liveWallpapersView.removeAllViews();
                 populateWallpapersFromAdapter(liveWallpapersView, a, false, false);
                 initializeScrollForRtl();
+                updateTileIndices();
             }
         });
 
@@ -294,16 +313,16 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
 
         // Add a tile for the Gallery
         LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list);
-        FrameLayout galleryThumbnail = (FrameLayout) getLayoutInflater().
+        FrameLayout pickImageTile = (FrameLayout) getLayoutInflater().
                 inflate(R.layout.wallpaper_picker_image_picker_item, masterWallpaperList, false);
-        setWallpaperItemPaddingToZero(galleryThumbnail);
-        masterWallpaperList.addView(galleryThumbnail, 0);
+        setWallpaperItemPaddingToZero(pickImageTile);
+        masterWallpaperList.addView(pickImageTile, 0);
 
         // Make its background the last photo taken on external storage
         Bitmap lastPhoto = getThumbnailOfLastPhoto();
         if (lastPhoto != null) {
             ImageView galleryThumbnailBg =
-                    (ImageView) galleryThumbnail.findViewById(R.id.wallpaper_image);
+                    (ImageView) pickImageTile.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);
@@ -311,8 +330,12 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
         }
 
         PickImageInfo pickImageInfo = new PickImageInfo();
-        galleryThumbnail.setTag(pickImageInfo);
-        galleryThumbnail.setOnClickListener(mThumbnailOnClickListener);
+        pickImageTile.setTag(pickImageInfo);
+        pickImageInfo.setView(pickImageTile);
+        pickImageTile.setOnClickListener(mThumbnailOnClickListener);
+        pickImageInfo.setView(pickImageTile);
+
+        updateTileIndices();
 
         // Update the scroll for RTL
         initializeScrollForRtl();
@@ -396,6 +419,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
                     for (View v : viewsToRemove) {
                         mWallpapersView.removeView(v);
                     }
+                    updateTileIndices();
                     mode.finish(); // Action picked, so close the CAB
                     return true;
                 } else {
@@ -479,7 +503,9 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
         for (int i = 0; i < adapter.getCount(); i++) {
             FrameLayout thumbnail = (FrameLayout) adapter.getView(i, null, parent);
             parent.addView(thumbnail, i);
-            thumbnail.setTag(adapter.getItem(i));
+            WallpaperTileInfo info = (WallpaperTileInfo) adapter.getItem(i);
+            thumbnail.setTag(info);
+            info.setView(thumbnail);
             if (addLongPressHandler) {
                 addLongPressHandler(thumbnail);
             }
@@ -490,6 +516,48 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
         }
     }
 
+    private void updateTileIndices() {
+        LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list);
+        final int childCount = masterWallpaperList.getChildCount();
+        ArrayList<WallpaperTileInfo> tiles = new ArrayList<WallpaperTileInfo>();
+        final Resources res = getResources();
+
+        // Do two passes; the first pass gets the total number of tiles
+        int numTiles = 0;
+        for (int passNum = 0; passNum < 2; passNum++) {
+            int tileIndex = 0;
+            for (int i = 0; i < childCount; i++) {
+                View child = masterWallpaperList.getChildAt(i);
+                LinearLayout subList;
+
+                int subListStart;
+                int subListEnd;
+                if (child.getTag() instanceof WallpaperTileInfo) {
+                    subList = masterWallpaperList;
+                    subListStart = i;
+                    subListEnd = i + 1;
+                } else { // if (child instanceof LinearLayout) {
+                    subList = (LinearLayout) child;
+                    subListStart = 0;
+                    subListEnd = subList.getChildCount();
+                }
+
+                for (int j = subListStart; j < subListEnd; j++) {
+                    WallpaperTileInfo info = (WallpaperTileInfo) subList.getChildAt(j).getTag();
+                    if (info.isNamelessWallpaper()) {
+                        if (passNum == 0) {
+                            numTiles++;
+                        } else {
+                            CharSequence label = res.getString(
+                                    R.string.wallpaper_accessibility_name, ++tileIndex, numTiles);
+                            info.onIndexUpdated(label);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
     private static Point getDefaultThumbnailSize(Resources res) {
         return new Point(res.getDimensionPixelSize(R.dimen.wallpaperThumbnailWidth),
                 res.getDimensionPixelSize(R.dimen.wallpaperThumbnailHeight));
@@ -545,9 +613,11 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
             Log.e(TAG, "Error loading thumbnail for uri=" + uri);
         }
         mWallpapersView.addView(pickedImageThumbnail, 0);
+        updateTileIndices();
 
         UriWallpaperInfo info = new UriWallpaperInfo(uri);
         pickedImageThumbnail.setTag(info);
+        info.setView(pickedImageThumbnail);
         pickedImageThumbnail.setOnClickListener(mThumbnailOnClickListener);
         mThumbnailOnClickListener.onClick(pickedImageThumbnail);
     }