mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1102339 - Don't generate widget/Themed*.java. r=rnewman
This lands the widget/Themed*.java sources into the tree and provides a simple script for regenerating them in the source tree. Use it like: <edit mobile/android/base/widget/ThemedView.java.frag> $ ./mach python mobile/android/base/widget/generate_themed_views.py $ hg diff ... changes to Themed*java --HG-- extra : rebase_source : c32966b91ac0c1c5719532e3b558c123c3d02c7e extra : source : 4bcc69eb4a27db09b2423c52c22a0c07baffd7d0
This commit is contained in:
parent
c17cd63da0
commit
4d3964dda8
@ -480,6 +480,19 @@ gbjar.sources += [
|
|||||||
'widget/TwoWayView.java',
|
'widget/TwoWayView.java',
|
||||||
'ZoomConstraints.java',
|
'ZoomConstraints.java',
|
||||||
]
|
]
|
||||||
|
# The following sources are checked in to version control but
|
||||||
|
# generated by a script (widget/generate_themed_views.py). If you're
|
||||||
|
# editing this list, make sure to edit that script.
|
||||||
|
gbjar.sources += [
|
||||||
|
'widget/ThemedEditText.java',
|
||||||
|
'widget/ThemedImageButton.java',
|
||||||
|
'widget/ThemedImageView.java',
|
||||||
|
'widget/ThemedLinearLayout.java',
|
||||||
|
'widget/ThemedRelativeLayout.java',
|
||||||
|
'widget/ThemedTextSwitcher.java',
|
||||||
|
'widget/ThemedTextView.java',
|
||||||
|
'widget/ThemedView.java',
|
||||||
|
]
|
||||||
gbjar.sources += [ thirdparty_source_dir + f for f in [
|
gbjar.sources += [ thirdparty_source_dir + f for f in [
|
||||||
'com/googlecode/eyesfree/braille/selfbraille/ISelfBrailleService.java',
|
'com/googlecode/eyesfree/braille/selfbraille/ISelfBrailleService.java',
|
||||||
'com/googlecode/eyesfree/braille/selfbraille/SelfBrailleClient.java',
|
'com/googlecode/eyesfree/braille/selfbraille/SelfBrailleClient.java',
|
||||||
@ -488,14 +501,6 @@ gbjar.sources += [ thirdparty_source_dir + f for f in [
|
|||||||
android_package_dir = CONFIG['ANDROID_PACKAGE_NAME'].replace('.', '/')
|
android_package_dir = CONFIG['ANDROID_PACKAGE_NAME'].replace('.', '/')
|
||||||
gbjar.generated_sources += [
|
gbjar.generated_sources += [
|
||||||
'org/mozilla/gecko/SysInfo.java',
|
'org/mozilla/gecko/SysInfo.java',
|
||||||
'org/mozilla/gecko/widget/ThemedEditText.java',
|
|
||||||
'org/mozilla/gecko/widget/ThemedImageButton.java',
|
|
||||||
'org/mozilla/gecko/widget/ThemedImageView.java',
|
|
||||||
'org/mozilla/gecko/widget/ThemedLinearLayout.java',
|
|
||||||
'org/mozilla/gecko/widget/ThemedRelativeLayout.java',
|
|
||||||
'org/mozilla/gecko/widget/ThemedTextSwitcher.java',
|
|
||||||
'org/mozilla/gecko/widget/ThemedTextView.java',
|
|
||||||
'org/mozilla/gecko/widget/ThemedView.java',
|
|
||||||
]
|
]
|
||||||
if CONFIG['MOZ_CRASHREPORTER']:
|
if CONFIG['MOZ_CRASHREPORTER']:
|
||||||
gbjar.sources += [ 'CrashReporter.java' ]
|
gbjar.sources += [ 'CrashReporter.java' ]
|
||||||
|
155
mobile/android/base/widget/ThemedEditText.java
Normal file
155
mobile/android/base/widget/ThemedEditText.java
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
// This file is generated by generate_themed_views.py; do not edit.
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.gecko.widget;
|
||||||
|
|
||||||
|
import org.mozilla.gecko.GeckoApplication;
|
||||||
|
import org.mozilla.gecko.LightweightTheme;
|
||||||
|
import org.mozilla.gecko.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
public class ThemedEditText extends android.widget.EditText
|
||||||
|
implements LightweightTheme.OnChangeListener {
|
||||||
|
private LightweightTheme mTheme;
|
||||||
|
|
||||||
|
private static final int[] STATE_PRIVATE_MODE = { R.attr.state_private };
|
||||||
|
private static final int[] STATE_LIGHT = { R.attr.state_light };
|
||||||
|
private static final int[] STATE_DARK = { R.attr.state_dark };
|
||||||
|
|
||||||
|
protected static final int[] PRIVATE_PRESSED_STATE_SET = { R.attr.state_private, android.R.attr.state_pressed };
|
||||||
|
protected static final int[] PRIVATE_FOCUSED_STATE_SET = { R.attr.state_private, android.R.attr.state_focused };
|
||||||
|
protected static final int[] PRIVATE_STATE_SET = { R.attr.state_private };
|
||||||
|
|
||||||
|
private boolean mIsPrivate;
|
||||||
|
private boolean mIsLight;
|
||||||
|
private boolean mIsDark;
|
||||||
|
private boolean mAutoUpdateTheme; // always false if there's no theme.
|
||||||
|
|
||||||
|
public ThemedEditText(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
initialize(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] onCreateDrawableState(int extraSpace) {
|
||||||
|
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
|
||||||
|
|
||||||
|
if (mIsPrivate)
|
||||||
|
mergeDrawableStates(drawableState, STATE_PRIVATE_MODE);
|
||||||
|
else if (mIsLight)
|
||||||
|
mergeDrawableStates(drawableState, STATE_LIGHT);
|
||||||
|
else if (mIsDark)
|
||||||
|
mergeDrawableStates(drawableState, STATE_DARK);
|
||||||
|
|
||||||
|
return drawableState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeChanged() {
|
||||||
|
if (mAutoUpdateTheme && mTheme.isEnabled())
|
||||||
|
setTheme(mTheme.isLightTheme());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeReset() {
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
resetTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom);
|
||||||
|
onLightweightThemeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrivateMode() {
|
||||||
|
return mIsPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivateMode(boolean isPrivate) {
|
||||||
|
if (mIsPrivate != isPrivate) {
|
||||||
|
mIsPrivate = isPrivate;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTheme(boolean isLight) {
|
||||||
|
// Set the theme only if it is different from existing theme.
|
||||||
|
if ((isLight && mIsLight != isLight) ||
|
||||||
|
(!isLight && mIsDark == isLight)) {
|
||||||
|
if (isLight) {
|
||||||
|
mIsLight = true;
|
||||||
|
mIsDark = false;
|
||||||
|
} else {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetTheme() {
|
||||||
|
if (mIsLight || mIsDark) {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = false;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoUpdateTheme(boolean autoUpdateTheme) {
|
||||||
|
if (mTheme == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme != autoUpdateTheme) {
|
||||||
|
mAutoUpdateTheme = autoUpdateTheme;
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
else
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorDrawable getColorDrawable(int id) {
|
||||||
|
return new ColorDrawable(getResources().getColor(id));
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
//#filter substitution
|
|
||||||
//#define VIEW_NAME_SUFFIX EditText
|
|
||||||
//#define BASE_TYPE android.widget.EditText
|
|
||||||
//#define STYLE_CONSTRUCTOR 1
|
|
||||||
//#include ThemedView.java.frag
|
|
155
mobile/android/base/widget/ThemedImageButton.java
Normal file
155
mobile/android/base/widget/ThemedImageButton.java
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
// This file is generated by generate_themed_views.py; do not edit.
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.gecko.widget;
|
||||||
|
|
||||||
|
import org.mozilla.gecko.GeckoApplication;
|
||||||
|
import org.mozilla.gecko.LightweightTheme;
|
||||||
|
import org.mozilla.gecko.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
public class ThemedImageButton extends android.widget.ImageButton
|
||||||
|
implements LightweightTheme.OnChangeListener {
|
||||||
|
private LightweightTheme mTheme;
|
||||||
|
|
||||||
|
private static final int[] STATE_PRIVATE_MODE = { R.attr.state_private };
|
||||||
|
private static final int[] STATE_LIGHT = { R.attr.state_light };
|
||||||
|
private static final int[] STATE_DARK = { R.attr.state_dark };
|
||||||
|
|
||||||
|
protected static final int[] PRIVATE_PRESSED_STATE_SET = { R.attr.state_private, android.R.attr.state_pressed };
|
||||||
|
protected static final int[] PRIVATE_FOCUSED_STATE_SET = { R.attr.state_private, android.R.attr.state_focused };
|
||||||
|
protected static final int[] PRIVATE_STATE_SET = { R.attr.state_private };
|
||||||
|
|
||||||
|
private boolean mIsPrivate;
|
||||||
|
private boolean mIsLight;
|
||||||
|
private boolean mIsDark;
|
||||||
|
private boolean mAutoUpdateTheme; // always false if there's no theme.
|
||||||
|
|
||||||
|
public ThemedImageButton(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
initialize(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] onCreateDrawableState(int extraSpace) {
|
||||||
|
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
|
||||||
|
|
||||||
|
if (mIsPrivate)
|
||||||
|
mergeDrawableStates(drawableState, STATE_PRIVATE_MODE);
|
||||||
|
else if (mIsLight)
|
||||||
|
mergeDrawableStates(drawableState, STATE_LIGHT);
|
||||||
|
else if (mIsDark)
|
||||||
|
mergeDrawableStates(drawableState, STATE_DARK);
|
||||||
|
|
||||||
|
return drawableState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeChanged() {
|
||||||
|
if (mAutoUpdateTheme && mTheme.isEnabled())
|
||||||
|
setTheme(mTheme.isLightTheme());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeReset() {
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
resetTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom);
|
||||||
|
onLightweightThemeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrivateMode() {
|
||||||
|
return mIsPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivateMode(boolean isPrivate) {
|
||||||
|
if (mIsPrivate != isPrivate) {
|
||||||
|
mIsPrivate = isPrivate;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTheme(boolean isLight) {
|
||||||
|
// Set the theme only if it is different from existing theme.
|
||||||
|
if ((isLight && mIsLight != isLight) ||
|
||||||
|
(!isLight && mIsDark == isLight)) {
|
||||||
|
if (isLight) {
|
||||||
|
mIsLight = true;
|
||||||
|
mIsDark = false;
|
||||||
|
} else {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetTheme() {
|
||||||
|
if (mIsLight || mIsDark) {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = false;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoUpdateTheme(boolean autoUpdateTheme) {
|
||||||
|
if (mTheme == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme != autoUpdateTheme) {
|
||||||
|
mAutoUpdateTheme = autoUpdateTheme;
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
else
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorDrawable getColorDrawable(int id) {
|
||||||
|
return new ColorDrawable(getResources().getColor(id));
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
//#filter substitution
|
|
||||||
//#define VIEW_NAME_SUFFIX ImageButton
|
|
||||||
//#define BASE_TYPE android.widget.ImageButton
|
|
||||||
//#define STYLE_CONSTRUCTOR 1
|
|
||||||
//#include ThemedView.java.frag
|
|
155
mobile/android/base/widget/ThemedImageView.java
Normal file
155
mobile/android/base/widget/ThemedImageView.java
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
// This file is generated by generate_themed_views.py; do not edit.
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.gecko.widget;
|
||||||
|
|
||||||
|
import org.mozilla.gecko.GeckoApplication;
|
||||||
|
import org.mozilla.gecko.LightweightTheme;
|
||||||
|
import org.mozilla.gecko.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
public class ThemedImageView extends android.widget.ImageView
|
||||||
|
implements LightweightTheme.OnChangeListener {
|
||||||
|
private LightweightTheme mTheme;
|
||||||
|
|
||||||
|
private static final int[] STATE_PRIVATE_MODE = { R.attr.state_private };
|
||||||
|
private static final int[] STATE_LIGHT = { R.attr.state_light };
|
||||||
|
private static final int[] STATE_DARK = { R.attr.state_dark };
|
||||||
|
|
||||||
|
protected static final int[] PRIVATE_PRESSED_STATE_SET = { R.attr.state_private, android.R.attr.state_pressed };
|
||||||
|
protected static final int[] PRIVATE_FOCUSED_STATE_SET = { R.attr.state_private, android.R.attr.state_focused };
|
||||||
|
protected static final int[] PRIVATE_STATE_SET = { R.attr.state_private };
|
||||||
|
|
||||||
|
private boolean mIsPrivate;
|
||||||
|
private boolean mIsLight;
|
||||||
|
private boolean mIsDark;
|
||||||
|
private boolean mAutoUpdateTheme; // always false if there's no theme.
|
||||||
|
|
||||||
|
public ThemedImageView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
initialize(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] onCreateDrawableState(int extraSpace) {
|
||||||
|
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
|
||||||
|
|
||||||
|
if (mIsPrivate)
|
||||||
|
mergeDrawableStates(drawableState, STATE_PRIVATE_MODE);
|
||||||
|
else if (mIsLight)
|
||||||
|
mergeDrawableStates(drawableState, STATE_LIGHT);
|
||||||
|
else if (mIsDark)
|
||||||
|
mergeDrawableStates(drawableState, STATE_DARK);
|
||||||
|
|
||||||
|
return drawableState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeChanged() {
|
||||||
|
if (mAutoUpdateTheme && mTheme.isEnabled())
|
||||||
|
setTheme(mTheme.isLightTheme());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeReset() {
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
resetTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom);
|
||||||
|
onLightweightThemeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrivateMode() {
|
||||||
|
return mIsPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivateMode(boolean isPrivate) {
|
||||||
|
if (mIsPrivate != isPrivate) {
|
||||||
|
mIsPrivate = isPrivate;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTheme(boolean isLight) {
|
||||||
|
// Set the theme only if it is different from existing theme.
|
||||||
|
if ((isLight && mIsLight != isLight) ||
|
||||||
|
(!isLight && mIsDark == isLight)) {
|
||||||
|
if (isLight) {
|
||||||
|
mIsLight = true;
|
||||||
|
mIsDark = false;
|
||||||
|
} else {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetTheme() {
|
||||||
|
if (mIsLight || mIsDark) {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = false;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoUpdateTheme(boolean autoUpdateTheme) {
|
||||||
|
if (mTheme == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme != autoUpdateTheme) {
|
||||||
|
mAutoUpdateTheme = autoUpdateTheme;
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
else
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorDrawable getColorDrawable(int id) {
|
||||||
|
return new ColorDrawable(getResources().getColor(id));
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
//#filter substitution
|
|
||||||
//#define VIEW_NAME_SUFFIX ImageView
|
|
||||||
//#define BASE_TYPE android.widget.ImageView
|
|
||||||
//#define STYLE_CONSTRUCTOR 1
|
|
||||||
//#include ThemedView.java.frag
|
|
150
mobile/android/base/widget/ThemedLinearLayout.java
Normal file
150
mobile/android/base/widget/ThemedLinearLayout.java
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
// This file is generated by generate_themed_views.py; do not edit.
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.gecko.widget;
|
||||||
|
|
||||||
|
import org.mozilla.gecko.GeckoApplication;
|
||||||
|
import org.mozilla.gecko.LightweightTheme;
|
||||||
|
import org.mozilla.gecko.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
public class ThemedLinearLayout extends android.widget.LinearLayout
|
||||||
|
implements LightweightTheme.OnChangeListener {
|
||||||
|
private LightweightTheme mTheme;
|
||||||
|
|
||||||
|
private static final int[] STATE_PRIVATE_MODE = { R.attr.state_private };
|
||||||
|
private static final int[] STATE_LIGHT = { R.attr.state_light };
|
||||||
|
private static final int[] STATE_DARK = { R.attr.state_dark };
|
||||||
|
|
||||||
|
protected static final int[] PRIVATE_PRESSED_STATE_SET = { R.attr.state_private, android.R.attr.state_pressed };
|
||||||
|
protected static final int[] PRIVATE_FOCUSED_STATE_SET = { R.attr.state_private, android.R.attr.state_focused };
|
||||||
|
protected static final int[] PRIVATE_STATE_SET = { R.attr.state_private };
|
||||||
|
|
||||||
|
private boolean mIsPrivate;
|
||||||
|
private boolean mIsLight;
|
||||||
|
private boolean mIsDark;
|
||||||
|
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();
|
||||||
|
|
||||||
|
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() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] onCreateDrawableState(int extraSpace) {
|
||||||
|
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
|
||||||
|
|
||||||
|
if (mIsPrivate)
|
||||||
|
mergeDrawableStates(drawableState, STATE_PRIVATE_MODE);
|
||||||
|
else if (mIsLight)
|
||||||
|
mergeDrawableStates(drawableState, STATE_LIGHT);
|
||||||
|
else if (mIsDark)
|
||||||
|
mergeDrawableStates(drawableState, STATE_DARK);
|
||||||
|
|
||||||
|
return drawableState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeChanged() {
|
||||||
|
if (mAutoUpdateTheme && mTheme.isEnabled())
|
||||||
|
setTheme(mTheme.isLightTheme());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeReset() {
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
resetTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom);
|
||||||
|
onLightweightThemeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrivateMode() {
|
||||||
|
return mIsPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivateMode(boolean isPrivate) {
|
||||||
|
if (mIsPrivate != isPrivate) {
|
||||||
|
mIsPrivate = isPrivate;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTheme(boolean isLight) {
|
||||||
|
// Set the theme only if it is different from existing theme.
|
||||||
|
if ((isLight && mIsLight != isLight) ||
|
||||||
|
(!isLight && mIsDark == isLight)) {
|
||||||
|
if (isLight) {
|
||||||
|
mIsLight = true;
|
||||||
|
mIsDark = false;
|
||||||
|
} else {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetTheme() {
|
||||||
|
if (mIsLight || mIsDark) {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = false;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoUpdateTheme(boolean autoUpdateTheme) {
|
||||||
|
if (mTheme == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme != autoUpdateTheme) {
|
||||||
|
mAutoUpdateTheme = autoUpdateTheme;
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
else
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorDrawable getColorDrawable(int id) {
|
||||||
|
return new ColorDrawable(getResources().getColor(id));
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +0,0 @@
|
|||||||
//#filter substitution
|
|
||||||
//#define VIEW_NAME_SUFFIX LinearLayout
|
|
||||||
//#define BASE_TYPE android.widget.LinearLayout
|
|
||||||
//#include ThemedView.java.frag
|
|
155
mobile/android/base/widget/ThemedRelativeLayout.java
Normal file
155
mobile/android/base/widget/ThemedRelativeLayout.java
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
// This file is generated by generate_themed_views.py; do not edit.
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.gecko.widget;
|
||||||
|
|
||||||
|
import org.mozilla.gecko.GeckoApplication;
|
||||||
|
import org.mozilla.gecko.LightweightTheme;
|
||||||
|
import org.mozilla.gecko.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
public class ThemedRelativeLayout extends android.widget.RelativeLayout
|
||||||
|
implements LightweightTheme.OnChangeListener {
|
||||||
|
private LightweightTheme mTheme;
|
||||||
|
|
||||||
|
private static final int[] STATE_PRIVATE_MODE = { R.attr.state_private };
|
||||||
|
private static final int[] STATE_LIGHT = { R.attr.state_light };
|
||||||
|
private static final int[] STATE_DARK = { R.attr.state_dark };
|
||||||
|
|
||||||
|
protected static final int[] PRIVATE_PRESSED_STATE_SET = { R.attr.state_private, android.R.attr.state_pressed };
|
||||||
|
protected static final int[] PRIVATE_FOCUSED_STATE_SET = { R.attr.state_private, android.R.attr.state_focused };
|
||||||
|
protected static final int[] PRIVATE_STATE_SET = { R.attr.state_private };
|
||||||
|
|
||||||
|
private boolean mIsPrivate;
|
||||||
|
private boolean mIsLight;
|
||||||
|
private boolean mIsDark;
|
||||||
|
private boolean mAutoUpdateTheme; // always false if there's no theme.
|
||||||
|
|
||||||
|
public ThemedRelativeLayout(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
initialize(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] onCreateDrawableState(int extraSpace) {
|
||||||
|
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
|
||||||
|
|
||||||
|
if (mIsPrivate)
|
||||||
|
mergeDrawableStates(drawableState, STATE_PRIVATE_MODE);
|
||||||
|
else if (mIsLight)
|
||||||
|
mergeDrawableStates(drawableState, STATE_LIGHT);
|
||||||
|
else if (mIsDark)
|
||||||
|
mergeDrawableStates(drawableState, STATE_DARK);
|
||||||
|
|
||||||
|
return drawableState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeChanged() {
|
||||||
|
if (mAutoUpdateTheme && mTheme.isEnabled())
|
||||||
|
setTheme(mTheme.isLightTheme());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeReset() {
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
resetTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom);
|
||||||
|
onLightweightThemeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrivateMode() {
|
||||||
|
return mIsPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivateMode(boolean isPrivate) {
|
||||||
|
if (mIsPrivate != isPrivate) {
|
||||||
|
mIsPrivate = isPrivate;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTheme(boolean isLight) {
|
||||||
|
// Set the theme only if it is different from existing theme.
|
||||||
|
if ((isLight && mIsLight != isLight) ||
|
||||||
|
(!isLight && mIsDark == isLight)) {
|
||||||
|
if (isLight) {
|
||||||
|
mIsLight = true;
|
||||||
|
mIsDark = false;
|
||||||
|
} else {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetTheme() {
|
||||||
|
if (mIsLight || mIsDark) {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = false;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoUpdateTheme(boolean autoUpdateTheme) {
|
||||||
|
if (mTheme == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme != autoUpdateTheme) {
|
||||||
|
mAutoUpdateTheme = autoUpdateTheme;
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
else
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorDrawable getColorDrawable(int id) {
|
||||||
|
return new ColorDrawable(getResources().getColor(id));
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
//#filter substitution
|
|
||||||
//#define VIEW_NAME_SUFFIX RelativeLayout
|
|
||||||
//#define BASE_TYPE android.widget.RelativeLayout
|
|
||||||
//#define STYLE_CONSTRUCTOR 1
|
|
||||||
//#include ThemedView.java.frag
|
|
150
mobile/android/base/widget/ThemedTextSwitcher.java
Normal file
150
mobile/android/base/widget/ThemedTextSwitcher.java
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
// This file is generated by generate_themed_views.py; do not edit.
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.gecko.widget;
|
||||||
|
|
||||||
|
import org.mozilla.gecko.GeckoApplication;
|
||||||
|
import org.mozilla.gecko.LightweightTheme;
|
||||||
|
import org.mozilla.gecko.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
public class ThemedTextSwitcher extends android.widget.TextSwitcher
|
||||||
|
implements LightweightTheme.OnChangeListener {
|
||||||
|
private LightweightTheme mTheme;
|
||||||
|
|
||||||
|
private static final int[] STATE_PRIVATE_MODE = { R.attr.state_private };
|
||||||
|
private static final int[] STATE_LIGHT = { R.attr.state_light };
|
||||||
|
private static final int[] STATE_DARK = { R.attr.state_dark };
|
||||||
|
|
||||||
|
protected static final int[] PRIVATE_PRESSED_STATE_SET = { R.attr.state_private, android.R.attr.state_pressed };
|
||||||
|
protected static final int[] PRIVATE_FOCUSED_STATE_SET = { R.attr.state_private, android.R.attr.state_focused };
|
||||||
|
protected static final int[] PRIVATE_STATE_SET = { R.attr.state_private };
|
||||||
|
|
||||||
|
private boolean mIsPrivate;
|
||||||
|
private boolean mIsLight;
|
||||||
|
private boolean mIsDark;
|
||||||
|
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();
|
||||||
|
|
||||||
|
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() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] onCreateDrawableState(int extraSpace) {
|
||||||
|
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
|
||||||
|
|
||||||
|
if (mIsPrivate)
|
||||||
|
mergeDrawableStates(drawableState, STATE_PRIVATE_MODE);
|
||||||
|
else if (mIsLight)
|
||||||
|
mergeDrawableStates(drawableState, STATE_LIGHT);
|
||||||
|
else if (mIsDark)
|
||||||
|
mergeDrawableStates(drawableState, STATE_DARK);
|
||||||
|
|
||||||
|
return drawableState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeChanged() {
|
||||||
|
if (mAutoUpdateTheme && mTheme.isEnabled())
|
||||||
|
setTheme(mTheme.isLightTheme());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeReset() {
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
resetTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom);
|
||||||
|
onLightweightThemeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrivateMode() {
|
||||||
|
return mIsPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivateMode(boolean isPrivate) {
|
||||||
|
if (mIsPrivate != isPrivate) {
|
||||||
|
mIsPrivate = isPrivate;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTheme(boolean isLight) {
|
||||||
|
// Set the theme only if it is different from existing theme.
|
||||||
|
if ((isLight && mIsLight != isLight) ||
|
||||||
|
(!isLight && mIsDark == isLight)) {
|
||||||
|
if (isLight) {
|
||||||
|
mIsLight = true;
|
||||||
|
mIsDark = false;
|
||||||
|
} else {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetTheme() {
|
||||||
|
if (mIsLight || mIsDark) {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = false;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoUpdateTheme(boolean autoUpdateTheme) {
|
||||||
|
if (mTheme == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme != autoUpdateTheme) {
|
||||||
|
mAutoUpdateTheme = autoUpdateTheme;
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
else
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorDrawable getColorDrawable(int id) {
|
||||||
|
return new ColorDrawable(getResources().getColor(id));
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +0,0 @@
|
|||||||
//#filter substitution
|
|
||||||
//#define VIEW_NAME_SUFFIX TextSwitcher
|
|
||||||
//#define BASE_TYPE android.widget.TextSwitcher
|
|
||||||
//#include ThemedView.java.frag
|
|
155
mobile/android/base/widget/ThemedTextView.java
Normal file
155
mobile/android/base/widget/ThemedTextView.java
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
// This file is generated by generate_themed_views.py; do not edit.
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.gecko.widget;
|
||||||
|
|
||||||
|
import org.mozilla.gecko.GeckoApplication;
|
||||||
|
import org.mozilla.gecko.LightweightTheme;
|
||||||
|
import org.mozilla.gecko.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
public class ThemedTextView extends android.widget.TextView
|
||||||
|
implements LightweightTheme.OnChangeListener {
|
||||||
|
private LightweightTheme mTheme;
|
||||||
|
|
||||||
|
private static final int[] STATE_PRIVATE_MODE = { R.attr.state_private };
|
||||||
|
private static final int[] STATE_LIGHT = { R.attr.state_light };
|
||||||
|
private static final int[] STATE_DARK = { R.attr.state_dark };
|
||||||
|
|
||||||
|
protected static final int[] PRIVATE_PRESSED_STATE_SET = { R.attr.state_private, android.R.attr.state_pressed };
|
||||||
|
protected static final int[] PRIVATE_FOCUSED_STATE_SET = { R.attr.state_private, android.R.attr.state_focused };
|
||||||
|
protected static final int[] PRIVATE_STATE_SET = { R.attr.state_private };
|
||||||
|
|
||||||
|
private boolean mIsPrivate;
|
||||||
|
private boolean mIsLight;
|
||||||
|
private boolean mIsDark;
|
||||||
|
private boolean mAutoUpdateTheme; // always false if there's no theme.
|
||||||
|
|
||||||
|
public ThemedTextView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
initialize(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] onCreateDrawableState(int extraSpace) {
|
||||||
|
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
|
||||||
|
|
||||||
|
if (mIsPrivate)
|
||||||
|
mergeDrawableStates(drawableState, STATE_PRIVATE_MODE);
|
||||||
|
else if (mIsLight)
|
||||||
|
mergeDrawableStates(drawableState, STATE_LIGHT);
|
||||||
|
else if (mIsDark)
|
||||||
|
mergeDrawableStates(drawableState, STATE_DARK);
|
||||||
|
|
||||||
|
return drawableState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeChanged() {
|
||||||
|
if (mAutoUpdateTheme && mTheme.isEnabled())
|
||||||
|
setTheme(mTheme.isLightTheme());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeReset() {
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
resetTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom);
|
||||||
|
onLightweightThemeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrivateMode() {
|
||||||
|
return mIsPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivateMode(boolean isPrivate) {
|
||||||
|
if (mIsPrivate != isPrivate) {
|
||||||
|
mIsPrivate = isPrivate;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTheme(boolean isLight) {
|
||||||
|
// Set the theme only if it is different from existing theme.
|
||||||
|
if ((isLight && mIsLight != isLight) ||
|
||||||
|
(!isLight && mIsDark == isLight)) {
|
||||||
|
if (isLight) {
|
||||||
|
mIsLight = true;
|
||||||
|
mIsDark = false;
|
||||||
|
} else {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetTheme() {
|
||||||
|
if (mIsLight || mIsDark) {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = false;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoUpdateTheme(boolean autoUpdateTheme) {
|
||||||
|
if (mTheme == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme != autoUpdateTheme) {
|
||||||
|
mAutoUpdateTheme = autoUpdateTheme;
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
else
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorDrawable getColorDrawable(int id) {
|
||||||
|
return new ColorDrawable(getResources().getColor(id));
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
//#filter substitution
|
|
||||||
//#define VIEW_NAME_SUFFIX TextView
|
|
||||||
//#define BASE_TYPE android.widget.TextView
|
|
||||||
//#define STYLE_CONSTRUCTOR 1
|
|
||||||
//#include ThemedView.java.frag
|
|
155
mobile/android/base/widget/ThemedView.java
Normal file
155
mobile/android/base/widget/ThemedView.java
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
// This file is generated by generate_themed_views.py; do not edit.
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.gecko.widget;
|
||||||
|
|
||||||
|
import org.mozilla.gecko.GeckoApplication;
|
||||||
|
import org.mozilla.gecko.LightweightTheme;
|
||||||
|
import org.mozilla.gecko.R;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
public class ThemedView extends android.view.View
|
||||||
|
implements LightweightTheme.OnChangeListener {
|
||||||
|
private LightweightTheme mTheme;
|
||||||
|
|
||||||
|
private static final int[] STATE_PRIVATE_MODE = { R.attr.state_private };
|
||||||
|
private static final int[] STATE_LIGHT = { R.attr.state_light };
|
||||||
|
private static final int[] STATE_DARK = { R.attr.state_dark };
|
||||||
|
|
||||||
|
protected static final int[] PRIVATE_PRESSED_STATE_SET = { R.attr.state_private, android.R.attr.state_pressed };
|
||||||
|
protected static final int[] PRIVATE_FOCUSED_STATE_SET = { R.attr.state_private, android.R.attr.state_focused };
|
||||||
|
protected static final int[] PRIVATE_STATE_SET = { R.attr.state_private };
|
||||||
|
|
||||||
|
private boolean mIsPrivate;
|
||||||
|
private boolean mIsLight;
|
||||||
|
private boolean mIsDark;
|
||||||
|
private boolean mAutoUpdateTheme; // always false if there's no theme.
|
||||||
|
|
||||||
|
public ThemedView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
initialize(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetachedFromWindow() {
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] onCreateDrawableState(int extraSpace) {
|
||||||
|
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
|
||||||
|
|
||||||
|
if (mIsPrivate)
|
||||||
|
mergeDrawableStates(drawableState, STATE_PRIVATE_MODE);
|
||||||
|
else if (mIsLight)
|
||||||
|
mergeDrawableStates(drawableState, STATE_LIGHT);
|
||||||
|
else if (mIsDark)
|
||||||
|
mergeDrawableStates(drawableState, STATE_DARK);
|
||||||
|
|
||||||
|
return drawableState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeChanged() {
|
||||||
|
if (mAutoUpdateTheme && mTheme.isEnabled())
|
||||||
|
setTheme(mTheme.isLightTheme());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLightweightThemeReset() {
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
resetTheme();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||||
|
super.onLayout(changed, left, top, right, bottom);
|
||||||
|
onLightweightThemeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrivateMode() {
|
||||||
|
return mIsPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrivateMode(boolean isPrivate) {
|
||||||
|
if (mIsPrivate != isPrivate) {
|
||||||
|
mIsPrivate = isPrivate;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTheme(boolean isLight) {
|
||||||
|
// Set the theme only if it is different from existing theme.
|
||||||
|
if ((isLight && mIsLight != isLight) ||
|
||||||
|
(!isLight && mIsDark == isLight)) {
|
||||||
|
if (isLight) {
|
||||||
|
mIsLight = true;
|
||||||
|
mIsDark = false;
|
||||||
|
} else {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetTheme() {
|
||||||
|
if (mIsLight || mIsDark) {
|
||||||
|
mIsLight = false;
|
||||||
|
mIsDark = false;
|
||||||
|
refreshDrawableState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoUpdateTheme(boolean autoUpdateTheme) {
|
||||||
|
if (mTheme == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme != autoUpdateTheme) {
|
||||||
|
mAutoUpdateTheme = autoUpdateTheme;
|
||||||
|
|
||||||
|
if (mAutoUpdateTheme)
|
||||||
|
mTheme.addListener(this);
|
||||||
|
else
|
||||||
|
mTheme.removeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColorDrawable getColorDrawable(int id) {
|
||||||
|
return new ColorDrawable(getResources().getColor(id));
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,6 @@
|
|||||||
|
//#filter substitution
|
||||||
|
// This file is generated by generate_themed_views.py; do not edit.
|
||||||
|
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
//#filter substitution
|
|
||||||
//#define VIEW_NAME_SUFFIX View
|
|
||||||
//#define BASE_TYPE android.view.View
|
|
||||||
//#define STYLE_CONSTRUCTOR 1
|
|
||||||
//#include ThemedView.java.frag
|
|
66
mobile/android/base/widget/generate_themed_views.py
Normal file
66
mobile/android/base/widget/generate_themed_views.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#!/bin/python
|
||||||
|
|
||||||
|
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
'''
|
||||||
|
Script to generate Themed*.java source files for Fennec.
|
||||||
|
|
||||||
|
This script runs the preprocessor on a input template and writes
|
||||||
|
updated files into the source directory.
|
||||||
|
|
||||||
|
To update the themed views, update the input template
|
||||||
|
(ThemedView.java.frag) and run the script. Use version control to
|
||||||
|
examine the differences, and don't forget to commit the changes to the
|
||||||
|
template and the outputs.
|
||||||
|
'''
|
||||||
|
|
||||||
|
from __future__ import (
|
||||||
|
print_function,
|
||||||
|
unicode_literals,
|
||||||
|
)
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from mozbuild.preprocessor import Preprocessor
|
||||||
|
|
||||||
|
__DIR__ = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
template = os.path.join(__DIR__, 'ThemedView.java.frag')
|
||||||
|
dest_format_string = 'Themed%(VIEW_NAME_SUFFIX)s.java'
|
||||||
|
|
||||||
|
views = [
|
||||||
|
dict(VIEW_NAME_SUFFIX='EditText',
|
||||||
|
BASE_TYPE='android.widget.EditText',
|
||||||
|
STYLE_CONSTRUCTOR=1),
|
||||||
|
dict(VIEW_NAME_SUFFIX='ImageButton',
|
||||||
|
BASE_TYPE='android.widget.ImageButton',
|
||||||
|
STYLE_CONSTRUCTOR=1),
|
||||||
|
dict(VIEW_NAME_SUFFIX='ImageView',
|
||||||
|
BASE_TYPE='android.widget.ImageView',
|
||||||
|
STYLE_CONSTRUCTOR=1),
|
||||||
|
dict(VIEW_NAME_SUFFIX='LinearLayout',
|
||||||
|
BASE_TYPE='android.widget.LinearLayout'),
|
||||||
|
dict(VIEW_NAME_SUFFIX='RelativeLayout',
|
||||||
|
BASE_TYPE='android.widget.RelativeLayout',
|
||||||
|
STYLE_CONSTRUCTOR=1),
|
||||||
|
dict(VIEW_NAME_SUFFIX='TextSwitcher',
|
||||||
|
BASE_TYPE='android.widget.TextSwitcher'),
|
||||||
|
dict(VIEW_NAME_SUFFIX='TextView',
|
||||||
|
BASE_TYPE='android.widget.TextView',
|
||||||
|
STYLE_CONSTRUCTOR=1),
|
||||||
|
dict(VIEW_NAME_SUFFIX='View',
|
||||||
|
BASE_TYPE='android.view.View',
|
||||||
|
STYLE_CONSTRUCTOR=1),
|
||||||
|
]
|
||||||
|
|
||||||
|
for view in views:
|
||||||
|
pp = Preprocessor(defines=view, marker='//#')
|
||||||
|
|
||||||
|
dest = os.path.join(__DIR__, dest_format_string % view)
|
||||||
|
with open(template, 'rU') as input:
|
||||||
|
with open(dest, 'wt') as output:
|
||||||
|
pp.processFile(input=input, output=output)
|
||||||
|
print('%s' % dest)
|
Loading…
Reference in New Issue
Block a user