summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2016-04-05 21:15:43 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-04-05 21:15:43 +0000
commit5105849a127fbe91f5226b02360951e8541808aa (patch)
tree7f05a3c24894c9d6541388e89f50e33326fe80f9
parent140ea8aed151504114c40fe26d3ef3e1a5eaeb32 (diff)
parent5d7bea799d0a1231f16b9e975718035c786da5f3 (diff)
downloadsetupwizard-5105849a127fbe91f5226b02360951e8541808aa.tar.gz
Merge "[SuwLib] Use framework selectableItemBackground" into ub-setupwizard-belgarath
-rw-r--r--library/full-support/res/values/attrs.xml7
-rw-r--r--library/full-support/src/com/android/setupwizardlib/items/RecyclerItemAdapter.java34
2 files changed, 28 insertions, 13 deletions
diff --git a/library/full-support/res/values/attrs.xml b/library/full-support/res/values/attrs.xml
index c8ea49a..86b2a56 100644
--- a/library/full-support/res/values/attrs.xml
+++ b/library/full-support/res/values/attrs.xml
@@ -30,4 +30,11 @@
<attr name="suwDividerInset" />
<attr name="suwHasStableIds" />
</declare-styleable>
+
+ <declare-styleable name="SuwRecyclerItemAdapter">
+ <attr name="android:colorBackground" />
+ <attr name="android:selectableItemBackground" />
+ <attr name="selectableItemBackground" />
+ </declare-styleable>
+
</resources>
diff --git a/library/full-support/src/com/android/setupwizardlib/items/RecyclerItemAdapter.java b/library/full-support/src/com/android/setupwizardlib/items/RecyclerItemAdapter.java
index 5fe46d5..632fee2 100644
--- a/library/full-support/src/com/android/setupwizardlib/items/RecyclerItemAdapter.java
+++ b/library/full-support/src/com/android/setupwizardlib/items/RecyclerItemAdapter.java
@@ -17,12 +17,14 @@
package com.android.setupwizardlib.items;
import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.LayerDrawable;
import android.support.v7.widget.RecyclerView;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.graphics.drawable.LayerDrawable;
-import android.graphics.drawable.Drawable;
+
import com.android.setupwizardlib.R;
/**
@@ -33,10 +35,7 @@ import com.android.setupwizardlib.R;
public class RecyclerItemAdapter extends RecyclerView.Adapter<ItemViewHolder>
implements ItemHierarchy.Observer {
- private static final int[] SELECTABLE_ITEM_BACKGROUND = new int[] {
- R.attr.selectableItemBackground,
- android.R.attr.colorBackground
- };
+ private static final String TAG = "RecyclerItemAdapter";
public interface OnItemSelectedListener {
void onItemSelected(IItem item);
@@ -77,15 +76,24 @@ public class RecyclerItemAdapter extends RecyclerView.Adapter<ItemViewHolder>
final ItemViewHolder viewHolder = new ItemViewHolder(view);
final TypedArray typedArray = parent.getContext()
- .obtainStyledAttributes(SELECTABLE_ITEM_BACKGROUND);
- Drawable firstLayer = typedArray.getDrawable(0);
- Drawable secondLayer = typedArray.getDrawable(1);
+ .obtainStyledAttributes(R.styleable.SuwRecyclerItemAdapter);
+ Drawable selectableItemBackground = typedArray.getDrawable(
+ R.styleable.SuwRecyclerItemAdapter_android_selectableItemBackground);
+ if (selectableItemBackground == null) {
+ selectableItemBackground = typedArray.getDrawable(
+ R.styleable.SuwRecyclerItemAdapter_selectableItemBackground);
+ }
- if (firstLayer != null && secondLayer != null) {
- Drawable [] layers = new Drawable[] {secondLayer, firstLayer};
- view.setBackgroundDrawable(new LayerDrawable(layers));
+ final Drawable background = typedArray.getDrawable(
+ R.styleable.SuwRecyclerItemAdapter_android_colorBackground);
+
+ if (selectableItemBackground == null || background == null) {
+ Log.e(TAG, "Cannot resolve required attributes."
+ + " selectableItemBackground=" + selectableItemBackground
+ + " background=" + background);
} else {
- view.setBackgroundDrawable(firstLayer);
+ final Drawable[] layers = { background, selectableItemBackground };
+ view.setBackgroundDrawable(new LayerDrawable(layers));
}
typedArray.recycle();