summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2/WallpaperChooserDialogFragment.java
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2011-06-21 13:03:34 -0700
committerAmith Yamasani <yamasani@google.com>2011-06-22 11:29:38 -0700
commit6be594922fac988f3b350718df8e9df3ef25b97e (patch)
tree7352b5679222d26d849eb15bb5694defc81baa79 /src/com/android/launcher2/WallpaperChooserDialogFragment.java
parent2a451abcc0d81d249840ca755d54ae829002d27e (diff)
downloadandroid_packages_apps_Trebuchet-6be594922fac988f3b350718df8e9df3ef25b97e.tar.gz
android_packages_apps_Trebuchet-6be594922fac988f3b350718df8e9df3ef25b97e.tar.bz2
android_packages_apps_Trebuchet-6be594922fac988f3b350718df8e9df3ef25b97e.zip
A fullscreen wallpaper chooser for all screen sizes.
The wallpaper preview covers the whole screen, with background protection for the gallery items and button. Change-Id: Ice31c4fea6503d1a59b59d6fbffb5e4a28eb2143
Diffstat (limited to 'src/com/android/launcher2/WallpaperChooserDialogFragment.java')
-rw-r--r--src/com/android/launcher2/WallpaperChooserDialogFragment.java84
1 files changed, 62 insertions, 22 deletions
diff --git a/src/com/android/launcher2/WallpaperChooserDialogFragment.java b/src/com/android/launcher2/WallpaperChooserDialogFragment.java
index 4f133324c..c9e21f2da 100644
--- a/src/com/android/launcher2/WallpaperChooserDialogFragment.java
+++ b/src/com/android/launcher2/WallpaperChooserDialogFragment.java
@@ -15,8 +15,6 @@
*/
package com.android.launcher2;
-import com.android.launcher.R;
-
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -27,14 +25,17 @@ import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.View.OnClickListener;
import android.view.ViewGroup;
+import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
@@ -44,6 +45,8 @@ import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.SpinnerAdapter;
+import com.android.launcher.R;
+
import java.io.IOException;
import java.util.ArrayList;
@@ -55,12 +58,12 @@ public class WallpaperChooserDialogFragment extends DialogFragment implements
+ "WallpaperChooserDialogFragment.EMBEDDED_KEY";
private boolean mEmbedded;
- private ImageView mImageView = null;
private Bitmap mBitmap = null;
private ArrayList<Integer> mThumbs;
private ArrayList<Integer> mImages;
private WallpaperLoader mLoader;
+ private WallpaperDrawable mWallpaperDrawable = new WallpaperDrawable();
public static WallpaperChooserDialogFragment newInstance() {
WallpaperChooserDialogFragment fragment = new WallpaperChooserDialogFragment();
@@ -113,6 +116,9 @@ public class WallpaperChooserDialogFragment extends DialogFragment implements
public Dialog onCreateDialog(Bundle savedInstanceState) {
findWallpapers();
+ // TODO: The following code is not exercised right now and may be removed
+ // if the dialog version is not needed.
+ /*
final View v = getActivity().getLayoutInflater().inflate(
R.layout.wallpaper_chooser, null, false);
@@ -122,13 +128,15 @@ public class WallpaperChooserDialogFragment extends DialogFragment implements
final int viewInset =
getResources().getDimensionPixelSize(R.dimen.alert_dialog_content_inset);
-
+
FrameLayout wallPaperList = (FrameLayout) v.findViewById(R.id.wallpaper_list);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setNegativeButton(R.string.wallpaper_cancel, null);
builder.setTitle(R.string.wallpaper_dialog_title);
- builder.setView(wallPaperList, viewInset, viewInset, viewInset, viewInset);
- return builder.create();
+ builder.setView(wallPaperList,
+ viewInset, viewInset, viewInset, viewInset); return builder.create();
+ */
+ return null;
}
@Override
@@ -142,6 +150,7 @@ public class WallpaperChooserDialogFragment extends DialogFragment implements
*/
if (mEmbedded) {
View view = inflater.inflate(R.layout.wallpaper_chooser, container, false);
+ view.setBackgroundDrawable(mWallpaperDrawable);
final Gallery gallery = (Gallery) view.findViewById(R.id.gallery);
gallery.setCallbackDuringFling(false);
@@ -155,7 +164,6 @@ public class WallpaperChooserDialogFragment extends DialogFragment implements
selectWallpaper(gallery.getSelectedItemPosition());
}
});
- mImageView = (ImageView) view.findViewById(R.id.wallpaper);
return view;
}
return null;
@@ -299,20 +307,9 @@ public class WallpaperChooserDialogFragment extends DialogFragment implements
mBitmap.recycle();
}
- // This should always be the case, but check anyways
- final ImageView view = mImageView;
- if (view != null) {
- view.setImageBitmap(b);
-
- mBitmap = b;
-
- final Drawable drawable = view.getDrawable();
- drawable.setFilterBitmap(true);
- drawable.setDither(true);
-
- view.postInvalidate();
- }
-
+ mBitmap = b;
+ mWallpaperDrawable.setBitmap(b);
+ getView().postInvalidate();
mLoader = null;
} else {
b.recycle();
@@ -324,4 +321,47 @@ public class WallpaperChooserDialogFragment extends DialogFragment implements
super.cancel(true);
}
}
+
+ /**
+ * Custom drawable that centers the bitmap fed to it.
+ */
+ static class WallpaperDrawable extends Drawable {
+
+ Bitmap mBitmap;
+ int mIntrinsicWidth;
+ int mIntrinsicHeight;
+
+ /* package */void setBitmap(Bitmap bitmap) {
+ mBitmap = bitmap;
+ if (mBitmap == null)
+ return;
+ mIntrinsicWidth = mBitmap.getWidth();
+ mIntrinsicHeight = mBitmap.getHeight();
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ if (mBitmap == null) return;
+ int width = canvas.getWidth();
+ int height = canvas.getHeight();
+ int x = (width - mIntrinsicWidth) / 2;
+ int y = (height - mIntrinsicHeight) / 2;
+ canvas.drawBitmap(mBitmap, x, y, null);
+ }
+
+ @Override
+ public int getOpacity() {
+ return android.graphics.PixelFormat.OPAQUE;
+ }
+
+ @Override
+ public void setAlpha(int alpha) {
+ // Ignore
+ }
+
+ @Override
+ public void setColorFilter(ColorFilter cf) {
+ // Ignore
+ }
+ }
} \ No newline at end of file