Skip to content

Commit a57aae3

Browse files
committed
address lint warnings
1 parent f021762 commit a57aae3

18 files changed

Lines changed: 105 additions & 87 deletions

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapAlert.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.beardedhen.androidbootstrap.api.attributes.BootstrapBrand;
2121
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand;
2222
import com.beardedhen.androidbootstrap.utils.DimenUtils;
23+
import com.beardedhen.androidbootstrap.utils.ViewUtils;
2324

2425
import java.util.concurrent.atomic.AtomicInteger;
2526

@@ -29,7 +30,6 @@
2930
public class BootstrapAlert extends RelativeLayout {
3031

3132
private ImageView closeButton;
32-
private TextView alertText;
3333

3434
private BootstrapBrand bootstrapBrand;
3535

@@ -95,7 +95,7 @@ private void initialise(AttributeSet attrs) {
9595
}
9696

9797
private void updateBootstrapState() {
98-
alertText = new TextView(getContext());
98+
TextView alertText = new TextView(getContext());
9999
closeButton = new ImageView(getContext());
100100
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
101101
alertText.setId(generateViewUniqueId());
@@ -146,7 +146,7 @@ public void onAnimationRepeat(Animation animation) {}
146146

147147
alertText.setLayoutParams(textParams);
148148
alertText.setTextSize(baselineFontSize);
149-
alertText.setGravity(Gravity.LEFT);
149+
alertText.setGravity(Gravity.START);
150150
alertText.setTextColor(
151151
BootstrapDrawableFactory.bootstrapButtonText(getContext(), true, bootstrapBrand));
152152
alertText.setText(Html.fromHtml(String.format("<b>%s</b>%s", strongText,
@@ -155,20 +155,15 @@ public void onAnimationRepeat(Animation animation) {}
155155
messageText))));
156156

157157
closeButton.setLayoutParams(closeParams);
158-
closeButton.setBackgroundDrawable(
159-
BootstrapDrawableFactory.bootstrapAlertCloseIcon(getContext(),
160-
(int) baselineFontSize,
161-
(int) baselineFontSize,
162-
DimenUtils.dpToPixels(6)));
158+
Drawable buttonBg = BootstrapDrawableFactory.bootstrapAlertCloseIcon(
159+
getContext(), (int) baselineFontSize, (int) baselineFontSize,
160+
DimenUtils.dpToPixels(6));
161+
162+
ViewUtils.setBackgroundDrawable(closeButton, buttonBg);
163163

164164
Drawable bg = BootstrapDrawableFactory.bootstrapAlert(getContext(), bootstrapBrand);
165+
ViewUtils.setBackgroundDrawable(this, bg);
165166

166-
if (Build.VERSION.SDK_INT >= 16) {
167-
setBackground(bg);
168-
}
169-
else {
170-
setBackgroundDrawable(bg);
171-
}
172167
addView(alertText);
173168
if (dismissible) {
174169
addView(closeButton);

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapBadge.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.content.Context;
44
import android.content.res.TypedArray;
55
import android.graphics.drawable.Drawable;
6-
import android.os.Build;
76
import android.support.annotation.NonNull;
87
import android.util.AttributeSet;
98
import android.widget.ImageView;
@@ -14,6 +13,7 @@
1413
import com.beardedhen.androidbootstrap.api.view.BootstrapBrandView;
1514
import com.beardedhen.androidbootstrap.api.view.BootstrapSizeView;
1615
import com.beardedhen.androidbootstrap.utils.DimenUtils;
16+
import com.beardedhen.androidbootstrap.utils.ViewUtils;
1717

1818
/**
1919
* See <a href="http://getbootstrap.com/components/#badges>http://getbootstrap.com/components/#badges</a>
@@ -69,12 +69,7 @@ private void updateBootstrapState() {
6969
badgeCount, allowZeroValue,
7070
insideContainer);
7171

72-
if (Build.VERSION.SDK_INT >= 16) {
73-
setBackground(badgeDrawable);
74-
}
75-
else {
76-
setBackgroundDrawable(badgeDrawable);
77-
}
72+
ViewUtils.setBackgroundDrawable(this, badgeDrawable);
7873
}
7974

8075
public void setBadgeCount(int badgeCount) {

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapButton.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.content.Context;
44
import android.content.res.TypedArray;
55
import android.graphics.drawable.Drawable;
6-
import android.os.Build;
76
import android.os.Bundle;
87
import android.os.Parcelable;
98
import android.support.annotation.NonNull;
@@ -21,6 +20,7 @@
2120
import com.beardedhen.androidbootstrap.api.view.OutlineableView;
2221
import com.beardedhen.androidbootstrap.api.view.RoundableView;
2322
import com.beardedhen.androidbootstrap.utils.DimenUtils;
23+
import com.beardedhen.androidbootstrap.utils.ViewUtils;
2424

2525
import java.io.Serializable;
2626

@@ -158,12 +158,7 @@ private void initialise(AttributeSet attrs) {
158158
showOutline,
159159
roundedCorners);
160160

161-
if (Build.VERSION.SDK_INT >= 16) {
162-
setBackground(bg);
163-
}
164-
else {
165-
setBackgroundDrawable(bg);
166-
}
161+
ViewUtils.setBackgroundDrawable(this, bg);
167162

168163
int vert = (int) (baselineVertPadding * bootstrapSize);
169164
int hori = (int) (baselineHoriPadding * bootstrapSize);

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapCircleThumbnail.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
import android.graphics.RectF;
1010
import android.graphics.Shader;
1111
import android.graphics.drawable.Drawable;
12-
import android.os.Build;
1312
import android.support.annotation.NonNull;
1413
import android.util.AttributeSet;
1514

1615
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand;
1716
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapSize;
1817
import com.beardedhen.androidbootstrap.utils.ColorUtils;
1918
import com.beardedhen.androidbootstrap.utils.DimenUtils;
19+
import com.beardedhen.androidbootstrap.utils.ViewUtils;
2020

2121
/**
2222
* BootstrapCircleThumbnails display a circular image with an optional border, that can be themed
@@ -176,12 +176,7 @@ private void updateBackground() {
176176
(int) (baselineOuterBorderWidth * bootstrapSize),
177177
ColorUtils.resolveColor(R.color.bootstrap_thumbnail_background, getContext()));
178178
}
179-
if (Build.VERSION.SDK_INT >= 16) {
180-
setBackground(bg);
181-
}
182-
else {
183-
setBackgroundDrawable(bg);
184-
}
179+
ViewUtils.setBackgroundDrawable(this, bg);
185180
}
186181

187182
}

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDrawableFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,9 @@ public static Drawable createBadgeDrawable(Context context, BootstrapBrand brand
484484

485485
static ColorStateList bootstrapDropDownViewText(Context context) {
486486

487-
int defaultColor = context.getResources().getColor(R.color.bootstrap_gray_dark);
488-
int activeColor = context.getResources().getColor(android.R.color.black);
489-
int disabledColor = context.getResources().getColor(R.color.bootstrap_gray_light);
487+
int defaultColor = ColorUtils.resolveColor(R.color.bootstrap_gray_dark, context);
488+
int activeColor = ColorUtils.resolveColor(android.R.color.black, context);
489+
int disabledColor = ColorUtils.resolveColor(R.color.bootstrap_gray_light, context);
490490

491491
return new ColorStateList(getStateList(), getColorList(defaultColor, activeColor, disabledColor));
492492
}

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDropDown.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import android.graphics.Canvas;
66
import android.graphics.Paint;
77
import android.graphics.drawable.Drawable;
8-
import android.os.Build;
98
import android.os.Bundle;
109
import android.os.Parcelable;
1110
import android.support.v4.widget.PopupWindowCompat;
@@ -28,7 +27,9 @@
2827
import com.beardedhen.androidbootstrap.api.view.BootstrapSizeView;
2928
import com.beardedhen.androidbootstrap.api.view.OutlineableView;
3029
import com.beardedhen.androidbootstrap.api.view.RoundableView;
30+
import com.beardedhen.androidbootstrap.utils.ColorUtils;
3131
import com.beardedhen.androidbootstrap.utils.DimenUtils;
32+
import com.beardedhen.androidbootstrap.utils.ViewUtils;
3233

3334
import java.io.Serializable;
3435
import java.util.regex.Pattern;
@@ -160,10 +161,13 @@ private ScrollView createDropDownView() {
160161
childView.setPadding(DimenUtils.dpToPixels(baselineItemLeftPadding * bootstrapSize), 0,
161162
DimenUtils.dpToPixels(baselineItemRightPadding * bootstrapSize), 0);
162163
childView.setTextSize(baselineDropDownViewFontSize * bootstrapSize);
163-
childView.setTextColor(getResources().getColor(android.R.color.black));
164-
childView.setBackgroundDrawable(getContext()
165-
.obtainStyledAttributes(null, new int[]{android.R.attr.selectableItemBackground}, 0, 0)
166-
.getDrawable(0));
164+
childView.setTextColor(ColorUtils.resolveColor(android.R.color.black, getContext()));
165+
166+
Drawable background = getContext().obtainStyledAttributes(null, new int[]{
167+
android.R.attr.selectableItemBackground}, 0, 0)
168+
.getDrawable(0);
169+
ViewUtils.setBackgroundDrawable(childView, background);
170+
167171
childView.setTextColor(BootstrapDrawableFactory.bootstrapDropDownViewText(getContext()));
168172
childView.setOnClickListener(new OnClickListener() {
169173
@Override
@@ -179,7 +183,8 @@ public void onClick(View v) {
179183
childView.setText(text.replaceFirst(REPLACE_REGEX_HEADER, ""));
180184
childView.setTextSize((baselineDropDownViewFontSize - 2F) * bootstrapSize);
181185
childView.setClickable(false);
182-
childView.setTextColor(getResources().getColor(R.color.bootstrap_gray_light));
186+
childView.setTextColor(ColorUtils.resolveColor(R.color.bootstrap_gray_light,
187+
getContext()));
183188
}
184189
else if (Pattern.matches(SEARCH_REGEX_SEPARATOR, text)) {
185190
childView = new DividerView(getContext());
@@ -248,12 +253,7 @@ private void updateDropDownState() {
248253
showOutline,
249254
roundedCorners);
250255

251-
if (Build.VERSION.SDK_INT >= 16) {
252-
setBackground(bg);
253-
}
254-
else {
255-
setBackgroundDrawable(bg);
256-
}
256+
ViewUtils.setBackgroundDrawable(this, bg);
257257

258258
int vert = (int) (baselineVertPadding * bootstrapSize);
259259
int hori = (int) (baselineHoriPadding * bootstrapSize);
@@ -462,7 +462,7 @@ private static class DividerView extends TextView {
462462
public DividerView(Context context) {
463463
super(context);
464464
paint = new Paint();
465-
paint.setColor(getResources().getColor(R.color.bootstrap_dropdown_divider));
465+
paint.setColor(ColorUtils.resolveColor(R.color.bootstrap_dropdown_divider, context));
466466
}
467467

468468
@Override protected void onDraw(Canvas canvas) {

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapEditText.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.content.Context;
44
import android.content.res.TypedArray;
55
import android.graphics.drawable.Drawable;
6-
import android.os.Build;
76
import android.os.Bundle;
87
import android.os.Parcelable;
98
import android.support.annotation.NonNull;
@@ -18,6 +17,7 @@
1817
import com.beardedhen.androidbootstrap.api.view.BootstrapSizeView;
1918
import com.beardedhen.androidbootstrap.api.view.RoundableView;
2019
import com.beardedhen.androidbootstrap.utils.DimenUtils;
20+
import com.beardedhen.androidbootstrap.utils.ViewUtils;
2121

2222
import java.io.Serializable;
2323

@@ -131,12 +131,7 @@ private void updateBootstrapState() {
131131
cornerRadius,
132132
rounded);
133133

134-
if (Build.VERSION.SDK_INT >= 16) {
135-
setBackground(bg);
136-
}
137-
else {
138-
setBackgroundDrawable(bg);
139-
}
134+
ViewUtils.setBackgroundDrawable(this, bg);
140135
}
141136

142137
/*

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapLabel.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import android.content.res.TypedArray;
55
import android.graphics.Typeface;
66
import android.graphics.drawable.Drawable;
7-
import android.os.Build;
87
import android.os.Bundle;
98
import android.os.Parcelable;
109
import android.support.annotation.NonNull;
@@ -14,6 +13,7 @@
1413
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapHeading;
1514
import com.beardedhen.androidbootstrap.api.view.BootstrapHeadingView;
1615
import com.beardedhen.androidbootstrap.api.view.RoundableView;
16+
import com.beardedhen.androidbootstrap.utils.ViewUtils;
1717

1818
import java.io.Serializable;
1919

@@ -105,12 +105,7 @@ private void initialise(AttributeSet attrs) {
105105
roundable,
106106
getHeight());
107107

108-
if (Build.VERSION.SDK_INT >= 16) {
109-
setBackground(bg);
110-
}
111-
else {
112-
setBackgroundDrawable(bg);
113-
}
108+
ViewUtils.setBackgroundDrawable(this, bg);
114109
}
115110

116111
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapThumbnail.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapSize;
1616
import com.beardedhen.androidbootstrap.api.view.RoundableView;
1717
import com.beardedhen.androidbootstrap.utils.ColorUtils;
18+
import com.beardedhen.androidbootstrap.utils.ViewUtils;
1819

1920
/**
2021
* BootstrapThumbnail displays a rectangular image with an optional border, that can be
@@ -112,12 +113,7 @@ private void updateBackground() {
112113
ColorUtils.resolveColor(R.color.bootstrap_thumbnail_background, getContext()),
113114
roundedCorners);
114115
}
115-
if (Build.VERSION.SDK_INT >= 16) {
116-
setBackground(bg);
117-
}
118-
else {
119-
setBackgroundDrawable(bg);
120-
}
116+
ViewUtils.setBackgroundDrawable(this, bg);
121117
}
122118

123119
private void updatePadding() {

AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapWell.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import android.content.Context;
44
import android.content.res.TypedArray;
55
import android.graphics.drawable.Drawable;
6-
import android.os.Build;
76
import android.util.AttributeSet;
87
import android.widget.FrameLayout;
98

109
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapSize;
1110
import com.beardedhen.androidbootstrap.utils.ColorUtils;
1211
import com.beardedhen.androidbootstrap.utils.DimenUtils;
12+
import com.beardedhen.androidbootstrap.utils.ViewUtils;
1313

1414
/**
1515
* BootstrapWells are used as a container layout for other views, typically text.
@@ -52,12 +52,7 @@ private void updateBootstrapState() {
5252
(int) DimenUtils.pixelsFromDpResource(getContext(), R.dimen.bootstrap_well_stroke_width),
5353
ColorUtils.resolveColor(R.color.bootstrap_well_border_color, getContext()));
5454

55-
if (Build.VERSION.SDK_INT >= 16) {
56-
setBackground(bg);
57-
}
58-
else {
59-
setBackgroundDrawable(bg);
60-
}
55+
ViewUtils.setBackgroundDrawable(this, bg);
6156

6257
int padding = (int) (DimenUtils.pixelsFromDpResource(getContext(), R.dimen.bootstrap_well_default_padding) * bootstrapSize * 2.5);
6358
setPadding(padding, padding, padding, padding);

0 commit comments

Comments
 (0)