mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-11 14:28:42 +00:00
Bug 813346 - Add getBitmapFromDataURI() to BitmapUtils. r=wesj
This commit is contained in:
parent
b72ec6d7d5
commit
9c46e81858
@ -7,6 +7,7 @@ package org.mozilla.gecko;
|
||||
|
||||
import org.mozilla.gecko.db.BrowserContract.Combined;
|
||||
import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.gfx.BitmapUtils;
|
||||
import org.mozilla.gecko.util.GeckoAsyncTask;
|
||||
import org.mozilla.gecko.util.GeckoBackgroundThread;
|
||||
|
||||
@ -21,7 +22,6 @@ import android.content.SharedPreferences;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.Rect;
|
||||
@ -757,9 +757,7 @@ abstract public class BrowserApp extends GeckoApp
|
||||
|
||||
if (icon != null) {
|
||||
if (icon.startsWith("data")) {
|
||||
byte[] raw = GeckoAppShell.decodeBase64(icon.substring(22), GeckoAppShell.BASE64_DEFAULT);
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(raw, 0, raw.length);
|
||||
BitmapDrawable drawable = new BitmapDrawable(bitmap);
|
||||
BitmapDrawable drawable = new BitmapDrawable(BitmapUtils.getBitmapFromDataURI(icon));
|
||||
item.setIcon(drawable);
|
||||
}
|
||||
else if (icon.startsWith("jar:") || icon.startsWith("file://")) {
|
||||
|
@ -852,9 +852,7 @@ public class GeckoAppShell
|
||||
|
||||
// internal, for webapps
|
||||
static void createShortcut(String aTitle, String aURI, String aUniqueURI, String aIconData, String aType) {
|
||||
byte[] raw = Base64.decode(aIconData.substring(22), Base64.DEFAULT);
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(raw, 0, raw.length);
|
||||
createShortcut(aTitle, aURI, aUniqueURI, bitmap, aType);
|
||||
createShortcut(aTitle, aURI, aUniqueURI, BitmapUtils.getBitmapFromDataURI(aIconData), aType);
|
||||
}
|
||||
|
||||
public static void createShortcut(final String aTitle, final String aURI, final String aUniqueURI,
|
||||
|
@ -8,8 +8,6 @@ package org.mozilla.gecko;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
@ -63,9 +61,7 @@ public class WebAppAllocator {
|
||||
}
|
||||
|
||||
public synchronized int findAndAllocateIndex(String app, String name, String aIconData) {
|
||||
byte[] raw = Base64.decode(aIconData.substring(22), Base64.DEFAULT);
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(raw, 0, raw.length);
|
||||
return findAndAllocateIndex(app, name, bitmap);
|
||||
return findAndAllocateIndex(app, name, BitmapUtils.getBitmapFromDataURI(aIconData));
|
||||
}
|
||||
|
||||
public synchronized int findAndAllocateIndex(final String app, final String name, final Bitmap aIcon) {
|
||||
|
@ -9,6 +9,7 @@ import org.mozilla.gecko.AwesomeBar.ContextMenuSubject;
|
||||
import org.mozilla.gecko.db.BrowserContract.Combined;
|
||||
import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.db.BrowserDB.URLColumns;
|
||||
import org.mozilla.gecko.gfx.BitmapUtils;
|
||||
import org.mozilla.gecko.util.GeckoAsyncTask;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
|
||||
@ -27,7 +28,6 @@ import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.SystemClock;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
@ -553,7 +553,7 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
|
||||
JSONObject engineJSON = engines.getJSONObject(i);
|
||||
String name = engineJSON.getString("name");
|
||||
String iconURI = engineJSON.getString("iconURI");
|
||||
Bitmap icon = getBitmapFromDataURI(iconURI);
|
||||
Bitmap icon = BitmapUtils.getBitmapFromDataURI(iconURI);
|
||||
if (name.equals(suggestEngine) && suggestTemplate != null) {
|
||||
// suggest engine should be at the front of the list
|
||||
mSearchEngines.add(0, new SearchEngine(name, icon));
|
||||
@ -575,16 +575,6 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
|
||||
filterSuggestions(mSearchTerm);
|
||||
}
|
||||
|
||||
private Bitmap getBitmapFromDataURI(String dataURI) {
|
||||
try {
|
||||
byte[] raw = Base64.decode(dataURI.substring(22), Base64.DEFAULT);
|
||||
return BitmapFactory.decodeByteArray(raw, 0, raw.length);
|
||||
} catch(Exception ex) {
|
||||
Log.i(LOGTAG, "exception while decoding bitmap: " + dataURI, ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void showSuggestionsOptIn() {
|
||||
mSuggestionsOptInPrompt = LayoutInflater.from(mContext).inflate(R.layout.awesomebar_suggestion_prompt, (LinearLayout)getView(), false);
|
||||
((TextView) mSuggestionsOptInPrompt.findViewById(R.id.suggestions_prompt_title))
|
||||
|
@ -6,9 +6,14 @@
|
||||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
public final class BitmapUtils {
|
||||
private static final String LOGTAG = "GeckoBitmapUtils";
|
||||
|
||||
public static int getDominantColor(Bitmap source) {
|
||||
return getDominantColor(source, true);
|
||||
}
|
||||
@ -58,5 +63,22 @@ public final class BitmapUtils {
|
||||
hsv[2] = (float)maxV/10.0f;
|
||||
return Color.HSVToColor(hsv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a bitmap from a Base64 data URI.
|
||||
*
|
||||
* @param dataURI a Base64-encoded data URI string
|
||||
* @return the decoded bitmap, or null if the data URI is invalid
|
||||
*/
|
||||
public static Bitmap getBitmapFromDataURI(String dataURI) {
|
||||
String base64 = dataURI.substring(dataURI.indexOf(',') + 1);
|
||||
try {
|
||||
byte[] raw = Base64.decode(base64, Base64.DEFAULT);
|
||||
return BitmapFactory.decodeByteArray(raw, 0, raw.length);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "exception decoding bitmap from data URI: " + dataURI, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user