Bug 914740 - Reland drawable and -moz-icon changes. r=mfinkle DONTBUILD
This commit is contained in:
@@ -27,6 +27,7 @@ import org.mozilla.gecko.R;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.NoSuchFieldException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
@@ -81,6 +82,19 @@ public final class BitmapUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
if(data.startsWith("-moz-icon://")) {
|
||||
Uri imageUri = Uri.parse(data);
|
||||
String resource = imageUri.getSchemeSpecificPart();
|
||||
resource = resource.substring(resource.lastIndexOf('/') + 1);
|
||||
|
||||
try {
|
||||
Drawable d = context.getPackageManager().getApplicationIcon(resource);
|
||||
loader.onBitmapFound(d);
|
||||
} catch(Exception ex) { }
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(data.startsWith("drawable://")) {
|
||||
Uri imageUri = Uri.parse(data);
|
||||
int id = getResource(imageUri, R.drawable.ic_status_logo);
|
||||
@@ -282,11 +296,34 @@ public final class BitmapUtils {
|
||||
if ("drawable".equals(scheme)) {
|
||||
String resource = resourceUrl.getSchemeSpecificPart();
|
||||
resource = resource.substring(resource.lastIndexOf('/') + 1);
|
||||
|
||||
try {
|
||||
return Integer.parseInt(resource);
|
||||
} catch(NumberFormatException ex) {
|
||||
// This isn't a resource id, try looking for a string
|
||||
}
|
||||
|
||||
try {
|
||||
final Class<R.drawable> drawableClass = R.drawable.class;
|
||||
final Field f = drawableClass.getField(resource);
|
||||
icon = f.getInt(null);
|
||||
} catch (final Exception e) {} // just means the resource doesn't exist
|
||||
} catch (final NoSuchFieldException e1) {
|
||||
|
||||
// just means the resource doesn't exist for fennec. Check in Android resources
|
||||
try {
|
||||
final Class<android.R.drawable> drawableClass = android.R.drawable.class;
|
||||
final Field f = drawableClass.getField(resource);
|
||||
icon = f.getInt(null);
|
||||
} catch (final NoSuchFieldException e2) {
|
||||
// This drawable doesn't seem to exist...
|
||||
} catch(Exception e3) {
|
||||
Log.i(LOGTAG, "Exception getting drawable", e3);
|
||||
}
|
||||
|
||||
} catch (Exception e4) {
|
||||
Log.i(LOGTAG, "Exception getting drawable", e4);
|
||||
}
|
||||
|
||||
resourceUrl = null;
|
||||
}
|
||||
return icon;
|
||||
|
||||
Reference in New Issue
Block a user