summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/WallpaperHandler.java
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2011-10-07 15:57:53 -0700
committerGeorge Mount <mount@google.com>2011-10-10 13:11:56 -0700
commit387d45d2284c7fd7f12cbadc96161f946ae29cad (patch)
tree04bc0d8cdcca96dc2d5730f26309885f55d99d95 /src/com/android/browser/WallpaperHandler.java
parent07af26d9ae4239bad876e8fd7ac69984a1d66996 (diff)
downloadandroid_packages_apps_Gello-387d45d2284c7fd7f12cbadc96161f946ae29cad.tar.gz
android_packages_apps_Gello-387d45d2284c7fd7f12cbadc96161f946ae29cad.tar.bz2
android_packages_apps_Gello-387d45d2284c7fd7f12cbadc96161f946ae29cad.zip
Data URL fixes - bookmarks, save, and wallpaper
Bug 5383517 Images kept in data URLs can now be selected and this fixes the Save and Set Wallpaper options. It also removes the bookmarking capability. Change-Id: I461bdcb4c950f6fcd8db8b38f4c599212106b027
Diffstat (limited to 'src/com/android/browser/WallpaperHandler.java')
-rw-r--r--src/com/android/browser/WallpaperHandler.java37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/com/android/browser/WallpaperHandler.java b/src/com/android/browser/WallpaperHandler.java
index 6437b1a2..b76861cc 100644
--- a/src/com/android/browser/WallpaperHandler.java
+++ b/src/com/android/browser/WallpaperHandler.java
@@ -27,8 +27,8 @@ import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
-
import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@@ -41,24 +41,19 @@ import java.net.URL;
public class WallpaperHandler extends Thread
implements OnMenuItemClickListener, DialogInterface.OnCancelListener {
-
private static final String LOGTAG = "WallpaperHandler";
// This should be large enough for BitmapFactory to decode the header so
// that we can mark and reset the input stream to avoid duplicate network i/o
private static final int BUFFER_SIZE = 128 * 1024;
private Context mContext;
- private URL mUrl;
+ private String mUrl;
private ProgressDialog mWallpaperProgress;
private boolean mCanceled = false;
public WallpaperHandler(Context context, String url) {
mContext = context;
- try {
- mUrl = new URL(url);
- } catch (MalformedURLException e) {
- mUrl = null;
- }
+ mUrl = url;
}
@Override
@@ -97,7 +92,7 @@ public class WallpaperHandler extends Thread
// version and instead open an input stream on that. This pattern
// could also be used in the download manager where the same problem
// exists.
- inputstream = mUrl.openStream();
+ inputstream = openStream();
if (inputstream != null) {
if (!inputstream.markSupported()) {
inputstream = new BufferedInputStream(inputstream, BUFFER_SIZE);
@@ -118,7 +113,7 @@ public class WallpaperHandler extends Thread
int bmHeight = options.outHeight;
int scale = 1;
- while (bmWidth > maxWidth || bmHeight > maxWidth) {
+ while (bmWidth > maxWidth || bmHeight > maxHeight) {
scale <<= 1;
bmWidth >>= 1;
bmHeight >>= 1;
@@ -131,7 +126,7 @@ public class WallpaperHandler extends Thread
// BitmapFactory read more than we could buffer
// Re-open the stream
inputstream.close();
- inputstream = mUrl.openStream();
+ inputstream = openStream();
}
Bitmap scaledWallpaper = BitmapFactory.decodeStream(inputstream,
null, options);
@@ -175,4 +170,24 @@ public class WallpaperHandler extends Thread
mWallpaperProgress.dismiss();
}
}
+
+ /**
+ * Opens the input stream for the URL that the class should
+ * use to set the wallpaper. Abstracts the difference between
+ * standard URLs and data URLs.
+ * @return An open InputStream for the data at the URL
+ * @throws IOException if there is an error opening the URL stream
+ * @throws MalformedURLException if the URL is malformed
+ */
+ private InputStream openStream() throws IOException, MalformedURLException {
+ InputStream inputStream = null;
+ if (DataUri.isDataUri(mUrl)) {
+ DataUri dataUri = new DataUri(mUrl);
+ inputStream = new ByteArrayInputStream(dataUri.getData());
+ } else {
+ URL url = new URL(mUrl);
+ inputStream = url.openStream();
+ }
+ return inputStream;
+ }
}