Skip to content

Commit 7543910

Browse files
authored
Merge pull request #4304 from wordpress-mobile/issue/4303-vector-drawable-pref-api-19
Fixes #4303: vector drawable usaeg in site settings on API <= 19
2 parents 34b1771 + 92cf15c commit 7543910

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

WordPress/src/main/java/org/wordpress/android/ui/prefs/WPStartOverPreference.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import android.content.Context;
44
import android.content.res.TypedArray;
5+
import android.graphics.drawable.Drawable;
56
import android.support.annotation.NonNull;
7+
import android.support.graphics.drawable.VectorDrawableCompat;
68
import android.support.v4.content.ContextCompat;
79
import android.util.AttributeSet;
810
import android.view.View;
911
import android.widget.Button;
12+
import android.widget.ImageView;
1013
import android.widget.TextView;
1114

1215
import org.wordpress.android.R;
@@ -23,22 +26,23 @@ public class WPStartOverPreference extends WPPreference {
2326
private String mButtonText;
2427
private int mButtonTextColor;
2528
private boolean mButtonTextAllCaps;
29+
private Drawable mPrefIcon;
2630

2731
public WPStartOverPreference(Context context, AttributeSet attrs) {
2832
super(context, attrs);
2933

30-
mButtonTextColor = ContextCompat.getColor(context, R.color.black);
31-
3234
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.WPStartOverPreference);
3335

3436
for (int i = 0; i < array.getIndexCount(); ++i) {
3537
int index = array.getIndex(i);
3638
if (index == R.styleable.WPStartOverPreference_buttonText) {
3739
mButtonText = array.getString(index);
3840
} else if (index == R.styleable.WPStartOverPreference_buttonTextColor) {
39-
mButtonTextColor = array.getColor(index, ContextCompat.getColor(context, R.color.grey_dark));
41+
mButtonTextColor = array.getColor(index, ContextCompat.getColor(context, R.color.black));
4042
} else if (index == R.styleable.WPStartOverPreference_buttonTextAllCaps) {
4143
mButtonTextAllCaps = array.getBoolean(index, false);
44+
} else if (index == R.styleable.WPStartOverPreference_preficon) {
45+
mPrefIcon = VectorDrawableCompat.create(context.getResources(), array.getResourceId(index, 0), null);
4246
}
4347
}
4448

@@ -49,6 +53,11 @@ public WPStartOverPreference(Context context, AttributeSet attrs) {
4953
protected void onBindView(@NonNull View view) {
5054
super.onBindView(view);
5155

56+
if (view.findViewById(R.id.pref_icon) != null) {
57+
ImageView imageView = (ImageView) view.findViewById(R.id.pref_icon);
58+
imageView.setImageDrawable(mPrefIcon);
59+
}
60+
5261
if (view.findViewById(R.id.button) != null) {
5362
final WPStartOverPreference wpStartOverPreference = this;
5463

WordPress/src/main/res/layout/start_over_preference.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
android:orientation="horizontal">
1919

2020
<ImageView
21-
android:id="@+android:id/icon"
21+
android:id="@+id/pref_icon"
2222
android:layout_width="@dimen/start_over_icon_size"
2323
android:layout_height="@dimen/start_over_icon_size"
2424
android:layout_marginRight="@dimen/start_over_icon_margin_right"

WordPress/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</declare-styleable>
2020

2121
<declare-styleable name="WPStartOverPreference">
22+
<attr name="preficon" format="reference" />
2223
<attr name="buttonText" format="string" />
2324
<attr name="buttonTextColor" format="reference|color" />
2425
<attr name="buttonTextAllCaps" format="boolean" />

WordPress/src/main/res/xml/site_settings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,14 @@
293293
<org.wordpress.android.ui.prefs.WPStartOverPreference
294294
android:id="@+id/pref_start_over"
295295
android:key="@string/pref_key_site_start_over"
296-
android:icon="@drawable/gridicons_history"
297296
android:title="@string/let_us_help"
298297
android:summary="@string/start_over_text"
299298
android:widgetLayout="@layout/start_over_preference_button"
300299
android:layout="@layout/start_over_preference"
300+
app:preficon="@drawable/gridicons_history"
301301
app:longClickHint="@string/site_settings_start_over_hint"
302302
app:buttonText="@string/contact_support"
303+
app:buttonTextColor="@color/grey_dark"
303304
app:buttonTextAllCaps="true" />
304305

305306
</PreferenceScreen>

0 commit comments

Comments
 (0)