Bug 1084529 - Move hardcoded colors to resources on Android. r=mcomella

--HG--
extra : rebase_source : 8e3d8eb16d6b03066b699d5d344c8d4a828e44b5
This commit is contained in:
Erik Edrosa 2014-10-23 14:24:38 -07:00
Родитель 70726fa7b1
Коммит 182d89c3a4
6 изменённых файлов: 41 добавлений и 27 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -144,4 +144,11 @@
<!-- Colour used for Find-In-Page dialog -->
<color name="find_status_default">#AFB1B3</color>
<!-- Canvas delegate paint color -->
<color name="canvas_delegate_paint">#FFFF0000</color>
<!-- Top sites thumbnail colors -->
<color name="top_site_default">#FFECF0F3</color>
<color name="top_site_border">#FFCFD9E1</color>
</resources>

Просмотреть файл

@ -26,4 +26,7 @@
<color name="facet_button_text_color_selected">#383E42</color>
<color name="network_error_link">#0092DB</color>
<!-- Suggestion highlight color -->
<color name="suggestion_highlight">#FF999999</color>
</resources>

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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<Suggestion> 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<Suggestion> result = new ArrayList<Suggestion>(values.size());
for (String value : values) {
result.add(new Suggestion(value, searchTerm));
result.add(new Suggestion(value, searchTerm, suggestionHighlightColor));
}
return result;