From 182d89c3a45d08aa7832374bc7a51561a8733d11 Mon Sep 17 00:00:00 2001 From: Erik Edrosa Date: Thu, 23 Oct 2014 14:24:38 -0700 Subject: [PATCH] Bug 1084529 - Move hardcoded colors to resources on Android. r=mcomella --HG-- extra : rebase_source : 8e3d8eb16d6b03066b699d5d344c8d4a828e44b5 --- .../base/home/TopSitesThumbnailView.java | 24 +++++++++---------- .../android/base/resources/values/colors.xml | 7 ++++++ .../base/resources/values/search_colors.xml | 3 +++ .../android/base/toolbar/CanvasDelegate.java | 7 ++---- mobile/android/base/toolbar/ShapedButton.java | 8 ++++++- .../autocomplete/SuggestionsFragment.java | 19 ++++++++------- 6 files changed, 41 insertions(+), 27 deletions(-) diff --git a/mobile/android/base/home/TopSitesThumbnailView.java b/mobile/android/base/home/TopSitesThumbnailView.java index 7c040efb8ed0..034306ab7248 100644 --- a/mobile/android/base/home/TopSitesThumbnailView.java +++ b/mobile/android/base/home/TopSitesThumbnailView.java @@ -9,6 +9,7 @@ import org.mozilla.gecko.R; import org.mozilla.gecko.ThumbnailHelper; import android.content.Context; +import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuff.Mode; @@ -26,20 +27,13 @@ public class TopSitesThumbnailView extends ImageView { private static final int COLOR_FILTER = 0x46FFFFFF; // Default filter color for "Add a bookmark" views. - private static final int DEFAULT_COLOR = 0xFFECF0F3; + private final int mDefaultColor = getResources().getColor(R.color.top_site_default); // Stroke width for the border. private final float mStrokeWidth = getResources().getDisplayMetrics().density * 2; // Paint for drawing the border. - private static final Paint sBorderPaint; - - // Initializing the static border paint. - static { - sBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - sBorderPaint.setColor(0xFFCFD9E1); - sBorderPaint.setStyle(Paint.Style.STROKE); - } + private final Paint mBorderPaint; public TopSitesThumbnailView(Context context) { this(context, null); @@ -54,6 +48,12 @@ public class TopSitesThumbnailView extends ImageView { public TopSitesThumbnailView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + + // Initialize the border paint. + final Resources res = getResources(); + mBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG); + mBorderPaint.setColor(res.getColor(R.color.top_site_border)); + mBorderPaint.setStyle(Paint.Style.STROKE); } /** @@ -82,8 +82,8 @@ public class TopSitesThumbnailView extends ImageView { super.onDraw(canvas); if (getBackground() == null) { - sBorderPaint.setStrokeWidth(mStrokeWidth); - canvas.drawRect(0, 0, getWidth(), getHeight(), sBorderPaint); + mBorderPaint.setStrokeWidth(mStrokeWidth); + canvas.drawRect(0, 0, getWidth(), getHeight(), mBorderPaint); } } @@ -104,7 +104,7 @@ public class TopSitesThumbnailView extends ImageView { @Override public void setBackgroundColor(int color) { if (color == 0) { - color = DEFAULT_COLOR; + color = mDefaultColor; } Drawable drawable = getResources().getDrawable(R.drawable.top_sites_thumbnail_bg); diff --git a/mobile/android/base/resources/values/colors.xml b/mobile/android/base/resources/values/colors.xml index 380a7ced2a30..b9a969d1bfcf 100644 --- a/mobile/android/base/resources/values/colors.xml +++ b/mobile/android/base/resources/values/colors.xml @@ -144,4 +144,11 @@ #AFB1B3 + + #FFFF0000 + + + #FFECF0F3 + #FFCFD9E1 + diff --git a/mobile/android/base/resources/values/search_colors.xml b/mobile/android/base/resources/values/search_colors.xml index a572181901d0..b71c200b80f7 100644 --- a/mobile/android/base/resources/values/search_colors.xml +++ b/mobile/android/base/resources/values/search_colors.xml @@ -26,4 +26,7 @@ #383E42 #0092DB + + + #FF999999 diff --git a/mobile/android/base/toolbar/CanvasDelegate.java b/mobile/android/base/toolbar/CanvasDelegate.java index d139286040cc..7cc959f17b49 100644 --- a/mobile/android/base/toolbar/CanvasDelegate.java +++ b/mobile/android/base/toolbar/CanvasDelegate.java @@ -24,16 +24,13 @@ class CanvasDelegate { public void defaultDraw(Canvas canvas); } - CanvasDelegate(DrawManager drawManager, Mode mode) { + CanvasDelegate(DrawManager drawManager, Mode mode, Paint paint) { mDrawManager = drawManager; // DST_IN masks, DST_OUT clips. mMode = new PorterDuffXfermode(mode); - mPaint = new Paint(); - mPaint.setAntiAlias(true); - mPaint.setColor(0xFFFF0000); - mPaint.setStrokeWidth(0.0f); + mPaint = paint; } void draw(Canvas canvas, Path path, int width, int height) { diff --git a/mobile/android/base/toolbar/ShapedButton.java b/mobile/android/base/toolbar/ShapedButton.java index 096b52ab5bc8..0f837baf56a5 100644 --- a/mobile/android/base/toolbar/ShapedButton.java +++ b/mobile/android/base/toolbar/ShapedButton.java @@ -14,6 +14,7 @@ import org.mozilla.gecko.widget.ThemedImageButton; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; +import android.graphics.Paint; import android.graphics.Path; import android.graphics.PorterDuff.Mode; import android.graphics.drawable.Drawable; @@ -33,7 +34,12 @@ public class ShapedButton extends ThemedImageButton // Path is clipped. mPath = new Path(); - mCanvasDelegate = new CanvasDelegate(this, Mode.DST_IN); + + final Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(getResources().getColor(R.color.canvas_delegate_paint)); + paint.setStrokeWidth(0.0f); + mCanvasDelegate = new CanvasDelegate(this, Mode.DST_IN, paint); setWillNotDraw(false); } diff --git a/mobile/android/search/java/org/mozilla/search/autocomplete/SuggestionsFragment.java b/mobile/android/search/java/org/mozilla/search/autocomplete/SuggestionsFragment.java index 7706fc31eea1..d3e283ca8e9f 100644 --- a/mobile/android/search/java/org/mozilla/search/autocomplete/SuggestionsFragment.java +++ b/mobile/android/search/java/org/mozilla/search/autocomplete/SuggestionsFragment.java @@ -48,9 +48,6 @@ public class SuggestionsFragment extends Fragment { // Number of search suggestions to show. private static final int SUGGESTION_MAX = 5; - // Color of search term match in search suggestion - private static final int SUGGESTION_HIGHLIGHT_COLOR = 0xFF999999; - public static final String GECKO_SEARCH_TERMS_URL_PARAM = "__searchTerms__"; private AcceptsSearchQuery searchListener; @@ -156,21 +153,21 @@ public class SuggestionsFragment extends Fragment { public static class Suggestion { - private static final ForegroundColorSpan COLOR_SPAN = - new ForegroundColorSpan(SUGGESTION_HIGHLIGHT_COLOR); - public final String value; public final SpannableString display; + public final ForegroundColorSpan colorSpan; - public Suggestion(String value, String searchTerm) { + public Suggestion(String value, String searchTerm, int suggestionHighlightColor) { this.value = value; display = new SpannableString(value); + colorSpan = new ForegroundColorSpan(suggestionHighlightColor); + // Highlight mixed-case matches. final int start = value.toLowerCase().indexOf(searchTerm.toLowerCase()); if (start >= 0) { - display.setSpan(COLOR_SPAN, start, start + searchTerm.length(), 0); + display.setSpan(colorSpan, start, start + searchTerm.length(), 0); } } } @@ -206,12 +203,16 @@ public class SuggestionsFragment extends Fragment { private final SuggestClient suggestClient; private final String searchTerm; private List suggestions; + private final int suggestionHighlightColor; public SuggestionAsyncLoader(Context context, SuggestClient suggestClient, String searchTerm) { super(context); this.suggestClient = suggestClient; this.searchTerm = searchTerm; this.suggestions = null; + + // Color of search term match in search suggestion + suggestionHighlightColor = context.getResources().getColor(R.color.suggestion_highlight); } @Override @@ -220,7 +221,7 @@ public class SuggestionsFragment extends Fragment { final List result = new ArrayList(values.size()); for (String value : values) { - result.add(new Suggestion(value, searchTerm)); + result.add(new Suggestion(value, searchTerm, suggestionHighlightColor)); } return result;