Bug 1369650 - Fix lint: NewApi issues in WebAppActivity.java; r?maliu
MozReview-Commit-ID: ERmh2IMTh0X
--- a/mobile/android/app/lint.xml
+++ b/mobile/android/app/lint.xml
@@ -52,17 +52,16 @@
<ignore path="**/mobile/android/base/java/org/mozilla/gecko/PrintHelper.java"/>
<ignore path="**/mobile/android/base/java/org/mozilla/gecko/animation/PropertyAnimator.java"/>
<ignore path="**/mobile/android/base/java/org/mozilla/gecko/RemotePresentationService.java"/>
<ignore path="**/mobile/android/base/java/org/mozilla/gecko/db/SharedBrowserDatabaseProvider.java"/>
<ignore path="**/mobile/android/base/java/org/mozilla/gecko/toolbar/TabCounter.java"/>
<ignore path="**/mobile/android/base/java/org/mozilla/gecko/tabs/TabPanelBackButton.java"/>
<ignore path="**/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarEditText.java"/>
<ignore path="**/mobile/android/base/java/org/mozilla/gecko/util/ViewUtil.java"/>
- <ignore path="**/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java"/>
<ignore path="**/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java"/>
<ignore path="**/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioEffects.java"/>
<ignore path="**/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/WebRtcAudioRecord.java"/>
<ignore path="src/main/res/values/styles.xml"/>
<ignore path="src/main/res/values/themes.xml"/>
</issue>
<!-- We fixed all "Registered" lint errors. However the current gradle plugin has a bug where
--- a/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/webapps/WebAppActivity.java
@@ -4,20 +4,22 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.webapps;
import java.io.File;
import java.io.IOException;
import java.util.List;
+import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -113,46 +115,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;
}
- // The customisations defined in the manifest only work on Android API 21+
- if (AppConstants.Versions.preLollipop) {
- 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);
- updateStatusBarColor(color);
+ updateStatusBarColorV21(color);
setTaskDescription(taskDescription);
} catch (IOException | JSONException e) {
Log.e(LOGTAG, "Failed to read manifest", e);
}
}
- private void updateStatusBarColor(final Integer themeColor) {
+ @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));
}
}
private Integer readColorFromManifest(JSONObject manifest) {