Skip to content

Commit

Permalink
Make init reuse context
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Marchesin committed Aug 8, 2015
1 parent 0f1377d commit b491579
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/main/java/org/angmarch/views/NiceSpinner.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ public class NiceSpinner extends TextView {
@SuppressWarnings("ConstantConditions")
public NiceSpinner(Context context) {
super(context);
init(null);
init(context, null);
}

public NiceSpinner(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
init(context, attrs);
}

public NiceSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
init(context, attrs);
}

@Override
Expand Down Expand Up @@ -106,9 +106,9 @@ public void run() {
super.onRestoreInstanceState(savedState);
}

private void init(AttributeSet attrs) {
private void init(Context context, AttributeSet attrs) {
Resources resources = getResources();
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.NiceSpinner);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NiceSpinner);
int defaultPadding = resources.getDimensionPixelSize(R.dimen.one_and_a_half_grid_unit);

setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
Expand All @@ -117,7 +117,7 @@ private void init(AttributeSet attrs) {
setClickable(true);
setBackgroundResource(R.drawable.selector);

mListView = new ListView(getContext());
mListView = new ListView(context);
mListView.setDivider(null);
mListView.setItemsCanFocus(true);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
Expand All @@ -142,17 +142,17 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
}
});

mPopup = new PopupWindow(getContext());
mPopup = new PopupWindow(context);
mPopup.setContentView(mListView);
mPopup.setOutsideTouchable(true);
mPopup.setFocusable(true);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mPopup.setElevation(DEFAULT_ELEVATION);
mPopup.setBackgroundDrawable(
ContextCompat.getDrawable(getContext(), R.drawable.spinner_drawable));
ContextCompat.getDrawable(context, R.drawable.spinner_drawable));
} else {
mPopup.setBackgroundDrawable(ContextCompat.getDrawable(getContext(),
mPopup.setBackgroundDrawable(ContextCompat.getDrawable(context,
R.drawable.drop_down_shadow));
}

Expand All @@ -163,7 +163,7 @@ public void onDismiss() {
}
});

Drawable basicDrawable = ContextCompat.getDrawable(getContext(), R.drawable.arrow);
Drawable basicDrawable = ContextCompat.getDrawable(context, R.drawable.arrow);
int resId = typedArray.getColor(R.styleable.NiceSpinner_arrowTint, -1);

if (basicDrawable != null) {
Expand Down

0 comments on commit b491579

Please sign in to comment.