Bug 1369817 - Clean up webapp manifest handling r=daleharvey
MozReview-Commit-ID: 4ImLBrlGzBc
--- a/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
@@ -120,50 +120,51 @@ public class WebAppActivity extends AppC
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(SAVED_INTENT, getIntent());
}
private void loadManifest(String manifestPath) {
- if (AppConstants.Versions.feature21Plus) {
- loadManifestV21(manifestPath);
- }
- }
-
- // The customisations defined in the manifest only work on Android API 21+
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)
- private void loadManifestV21(String manifestPath) {
if (TextUtils.isEmpty(manifestPath)) {
Log.e(LOGTAG, "Missing manifest");
return;
}
try {
final File manifestFile = new File(manifestPath);
final JSONObject manifest = FileUtils.readJSONObjectFromFile(manifestFile);
final JSONObject manifestField = manifest.getJSONObject("manifest");
- final Integer color = readColorFromManifest(manifestField);
- final String name = readNameFromManifest(manifestField);
- final Bitmap icon = readIconFromManifest(manifest);
- mScope = readScopeFromManifest(manifest, manifestPath);
- final ActivityManager.TaskDescription taskDescription = (color == null)
- ? new ActivityManager.TaskDescription(name, icon)
- : new ActivityManager.TaskDescription(name, icon, color);
- updateStatusBarColorV21(color);
- setTaskDescription(taskDescription);
+ if (AppConstants.Versions.feature21Plus) {
+ loadManifestV21(manifest, manifestField);
+ }
updateScreenOrientation(manifestField);
} catch (IOException | JSONException e) {
Log.e(LOGTAG, "Failed to read manifest", e);
}
}
+ // The customisations defined in the manifest only work on Android API 21+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ private void loadManifestV21(JSONObject manifest, JSONObject manifestField) {
+ final Integer color = readColorFromManifest(manifestField);
+ final String name = readNameFromManifest(manifestField);
+ final Bitmap icon = readIconFromManifest(manifest);
+ mScope = readScopeFromManifest(manifest);
+ final ActivityManager.TaskDescription taskDescription = (color == null)
+ ? new ActivityManager.TaskDescription(name, icon)
+ : new ActivityManager.TaskDescription(name, icon, color);
+
+ updateStatusBarColorV21(color);
+ setTaskDescription(taskDescription);
+ }
+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void updateStatusBarColorV21(final Integer themeColor) {
if (themeColor != null) {
final Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ColorUtil.darken(themeColor, 0.25));
}
}
@@ -208,17 +209,17 @@ public class WebAppActivity extends AppC
final LoadFaviconResult loadIconResult = FaviconDecoder
.decodeDataURI(this, iconStr);
if (loadIconResult == null) {
return null;
}
return loadIconResult.getBestBitmap(GeckoAppShell.getPreferredIconSize());
}
- private Uri readScopeFromManifest(JSONObject manifest, String manifestPath) {
+ private Uri readScopeFromManifest(JSONObject manifest) {
final String scopeStr = manifest.optString("scope", null);
if (scopeStr == null) {
return null;
}
Uri res = Uri.parse(scopeStr);
if (res.isRelative()) {
// TODO: Handle this more correctly.