Bug 1084098 - Pre: Don't require GeckoApplication in Themed*widgets. r=mcomella
authorNick Alexander <nalexander@mozilla.com>
Mon, 08 Dec 2014 18:58:37 -0800
changeset 218745 fb4c144263b2078ded281217482930e23d7f3053
parent 218744 eb203c9db11de72c79bb452144d3dfc31bd22168
child 218746 ddb6ffa2c017b2f5727ae31b1851f87a6c8b0a39
push id10301
push usernalexander@mozilla.com
push dateTue, 09 Dec 2014 03:32:57 +0000
treeherderfx-team@24f1cc4e2e32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1084098
milestone37.0a1
Bug 1084098 - Pre: Don't require GeckoApplication in Themed*widgets. r=mcomella In editors (Eclipse and IntelliJ), Android View sub-classes are created in a "Bridging" mock context. There is no ambient GeckoApplication in this case. It's already okay for the LWT to be null; let's loosen the requirement that there be an ambient GeckoApplication to let these View sub-classes render in editors.
mobile/android/base/widget/ThemedEditText.java
mobile/android/base/widget/ThemedImageButton.java
mobile/android/base/widget/ThemedImageView.java
mobile/android/base/widget/ThemedLinearLayout.java
mobile/android/base/widget/ThemedRelativeLayout.java
mobile/android/base/widget/ThemedTextSwitcher.java
mobile/android/base/widget/ThemedTextView.java
mobile/android/base/widget/ThemedView.java
mobile/android/base/widget/ThemedView.java.frag
--- a/mobile/android/base/widget/ThemedEditText.java
+++ b/mobile/android/base/widget/ThemedEditText.java
@@ -38,18 +38,22 @@ public class ThemedEditText extends andr
     }
 
     public ThemedEditText(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         initialize(context, attrs);
     }
 
     private void initialize(final Context context, final AttributeSet attrs) {
-        // The theme can be null, particularly for webapps: Bug 1089266.
-        mTheme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme();
+        // The theme can be null, particularly for webapps: Bug 1089266.  Or we
+        // might be instantiating this View in an IDE, with no ambient GeckoApplication.
+        final Context applicationContext = context.getApplicationContext();
+        if (applicationContext instanceof GeckoApplication) {
+            mTheme = ((GeckoApplication) applicationContext).getLightweightTheme();
+        }
 
         final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LightweightTheme);
         mAutoUpdateTheme = mTheme != null && a.getBoolean(R.styleable.LightweightTheme_autoUpdateTheme, true);
         a.recycle();
     }
 
     @Override
     public void onAttachedToWindow() {
--- a/mobile/android/base/widget/ThemedImageButton.java
+++ b/mobile/android/base/widget/ThemedImageButton.java
@@ -38,18 +38,22 @@ public class ThemedImageButton extends a
     }
 
     public ThemedImageButton(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         initialize(context, attrs);
     }
 
     private void initialize(final Context context, final AttributeSet attrs) {
-        // The theme can be null, particularly for webapps: Bug 1089266.
-        mTheme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme();
+        // The theme can be null, particularly for webapps: Bug 1089266.  Or we
+        // might be instantiating this View in an IDE, with no ambient GeckoApplication.
+        final Context applicationContext = context.getApplicationContext();
+        if (applicationContext instanceof GeckoApplication) {
+            mTheme = ((GeckoApplication) applicationContext).getLightweightTheme();
+        }
 
         final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LightweightTheme);
         mAutoUpdateTheme = mTheme != null && a.getBoolean(R.styleable.LightweightTheme_autoUpdateTheme, true);
         a.recycle();
     }
 
     @Override
     public void onAttachedToWindow() {
--- a/mobile/android/base/widget/ThemedImageView.java
+++ b/mobile/android/base/widget/ThemedImageView.java
@@ -38,18 +38,22 @@ public class ThemedImageView extends and
     }
 
     public ThemedImageView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         initialize(context, attrs);
     }
 
     private void initialize(final Context context, final AttributeSet attrs) {
-        // The theme can be null, particularly for webapps: Bug 1089266.
-        mTheme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme();
+        // The theme can be null, particularly for webapps: Bug 1089266.  Or we
+        // might be instantiating this View in an IDE, with no ambient GeckoApplication.
+        final Context applicationContext = context.getApplicationContext();
+        if (applicationContext instanceof GeckoApplication) {
+            mTheme = ((GeckoApplication) applicationContext).getLightweightTheme();
+        }
 
         final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LightweightTheme);
         mAutoUpdateTheme = mTheme != null && a.getBoolean(R.styleable.LightweightTheme_autoUpdateTheme, true);
         a.recycle();
     }
 
     @Override
     public void onAttachedToWindow() {
--- a/mobile/android/base/widget/ThemedLinearLayout.java
+++ b/mobile/android/base/widget/ThemedLinearLayout.java
@@ -33,18 +33,22 @@ public class ThemedLinearLayout extends 
     private boolean mAutoUpdateTheme;        // always false if there's no theme.
 
     public ThemedLinearLayout(Context context, AttributeSet attrs) {
         super(context, attrs);
         initialize(context, attrs);
     }
 
     private void initialize(final Context context, final AttributeSet attrs) {
-        // The theme can be null, particularly for webapps: Bug 1089266.
-        mTheme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme();
+        // The theme can be null, particularly for webapps: Bug 1089266.  Or we
+        // might be instantiating this View in an IDE, with no ambient GeckoApplication.
+        final Context applicationContext = context.getApplicationContext();
+        if (applicationContext instanceof GeckoApplication) {
+            mTheme = ((GeckoApplication) applicationContext).getLightweightTheme();
+        }
 
         final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LightweightTheme);
         mAutoUpdateTheme = mTheme != null && a.getBoolean(R.styleable.LightweightTheme_autoUpdateTheme, true);
         a.recycle();
     }
 
     @Override
     public void onAttachedToWindow() {
--- a/mobile/android/base/widget/ThemedRelativeLayout.java
+++ b/mobile/android/base/widget/ThemedRelativeLayout.java
@@ -38,18 +38,22 @@ public class ThemedRelativeLayout extend
     }
 
     public ThemedRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         initialize(context, attrs);
     }
 
     private void initialize(final Context context, final AttributeSet attrs) {
-        // The theme can be null, particularly for webapps: Bug 1089266.
-        mTheme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme();
+        // The theme can be null, particularly for webapps: Bug 1089266.  Or we
+        // might be instantiating this View in an IDE, with no ambient GeckoApplication.
+        final Context applicationContext = context.getApplicationContext();
+        if (applicationContext instanceof GeckoApplication) {
+            mTheme = ((GeckoApplication) applicationContext).getLightweightTheme();
+        }
 
         final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LightweightTheme);
         mAutoUpdateTheme = mTheme != null && a.getBoolean(R.styleable.LightweightTheme_autoUpdateTheme, true);
         a.recycle();
     }
 
     @Override
     public void onAttachedToWindow() {
--- a/mobile/android/base/widget/ThemedTextSwitcher.java
+++ b/mobile/android/base/widget/ThemedTextSwitcher.java
@@ -33,18 +33,22 @@ public class ThemedTextSwitcher extends 
     private boolean mAutoUpdateTheme;        // always false if there's no theme.
 
     public ThemedTextSwitcher(Context context, AttributeSet attrs) {
         super(context, attrs);
         initialize(context, attrs);
     }
 
     private void initialize(final Context context, final AttributeSet attrs) {
-        // The theme can be null, particularly for webapps: Bug 1089266.
-        mTheme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme();
+        // The theme can be null, particularly for webapps: Bug 1089266.  Or we
+        // might be instantiating this View in an IDE, with no ambient GeckoApplication.
+        final Context applicationContext = context.getApplicationContext();
+        if (applicationContext instanceof GeckoApplication) {
+            mTheme = ((GeckoApplication) applicationContext).getLightweightTheme();
+        }
 
         final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LightweightTheme);
         mAutoUpdateTheme = mTheme != null && a.getBoolean(R.styleable.LightweightTheme_autoUpdateTheme, true);
         a.recycle();
     }
 
     @Override
     public void onAttachedToWindow() {
--- a/mobile/android/base/widget/ThemedTextView.java
+++ b/mobile/android/base/widget/ThemedTextView.java
@@ -38,18 +38,22 @@ public class ThemedTextView extends andr
     }
 
     public ThemedTextView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         initialize(context, attrs);
     }
 
     private void initialize(final Context context, final AttributeSet attrs) {
-        // The theme can be null, particularly for webapps: Bug 1089266.
-        mTheme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme();
+        // The theme can be null, particularly for webapps: Bug 1089266.  Or we
+        // might be instantiating this View in an IDE, with no ambient GeckoApplication.
+        final Context applicationContext = context.getApplicationContext();
+        if (applicationContext instanceof GeckoApplication) {
+            mTheme = ((GeckoApplication) applicationContext).getLightweightTheme();
+        }
 
         final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LightweightTheme);
         mAutoUpdateTheme = mTheme != null && a.getBoolean(R.styleable.LightweightTheme_autoUpdateTheme, true);
         a.recycle();
     }
 
     @Override
     public void onAttachedToWindow() {
--- a/mobile/android/base/widget/ThemedView.java
+++ b/mobile/android/base/widget/ThemedView.java
@@ -38,18 +38,22 @@ public class ThemedView extends android.
     }
 
     public ThemedView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         initialize(context, attrs);
     }
 
     private void initialize(final Context context, final AttributeSet attrs) {
-        // The theme can be null, particularly for webapps: Bug 1089266.
-        mTheme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme();
+        // The theme can be null, particularly for webapps: Bug 1089266.  Or we
+        // might be instantiating this View in an IDE, with no ambient GeckoApplication.
+        final Context applicationContext = context.getApplicationContext();
+        if (applicationContext instanceof GeckoApplication) {
+            mTheme = ((GeckoApplication) applicationContext).getLightweightTheme();
+        }
 
         final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LightweightTheme);
         mAutoUpdateTheme = mTheme != null && a.getBoolean(R.styleable.LightweightTheme_autoUpdateTheme, true);
         a.recycle();
     }
 
     @Override
     public void onAttachedToWindow() {
--- a/mobile/android/base/widget/ThemedView.java.frag
+++ b/mobile/android/base/widget/ThemedView.java.frag
@@ -41,18 +41,22 @@ public class Themed@VIEW_NAME_SUFFIX@ ex
 //#ifdef STYLE_CONSTRUCTOR
     public Themed@VIEW_NAME_SUFFIX@(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         initialize(context, attrs);
     }
 
 //#endif
     private void initialize(final Context context, final AttributeSet attrs) {
-        // The theme can be null, particularly for webapps: Bug 1089266.
-        mTheme = ((GeckoApplication) context.getApplicationContext()).getLightweightTheme();
+        // The theme can be null, particularly for webapps: Bug 1089266.  Or we
+        // might be instantiating this View in an IDE, with no ambient GeckoApplication.
+        final Context applicationContext = context.getApplicationContext();
+        if (applicationContext instanceof GeckoApplication) {
+            mTheme = ((GeckoApplication) applicationContext).getLightweightTheme();
+        }
 
         final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LightweightTheme);
         mAutoUpdateTheme = mTheme != null && a.getBoolean(R.styleable.LightweightTheme_autoUpdateTheme, true);
         a.recycle();
     }
 
     @Override
     public void onAttachedToWindow() {