Skip to content

Commit

Permalink
Clean-up mcxiaoke's Pull Request a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Banes committed Feb 9, 2012
1 parent 0f7501f commit 5102695
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,14 @@ public void stop() {
// ===========================================================

public PullToRefreshBase(Context context) {
// this(context, null);
super(context);
init(context);
init(context, null);
}

public PullToRefreshBase(Context context, int mode) {
// this(context);
// this.mode = mode;
super(context);
this.mode = mode;
init(context);
init(context, null);
}

public PullToRefreshBase(Context context, AttributeSet attrs) {
Expand Down Expand Up @@ -531,60 +528,6 @@ protected final void smoothScrollTo(int y) {
handler.post(currentSmoothScrollRunnable);
}
}

private void init(Context context) {

setOrientation(LinearLayout.VERTICAL);

touchSlop = ViewConfiguration.getTouchSlop();

// Refreshable View
// By passing the attrs, we can add ListView/GridView params via XML
refreshableView = this.createRefreshableView(context, null);
this.addRefreshableView(context, refreshableView);

// Loading View Strings
String pullLabel = context.getString(R.string.pull_to_refresh_pull_label);
String refreshingLabel = context.getString(R.string.pull_to_refresh_refreshing_label);
String releaseLabel = context.getString(R.string.pull_to_refresh_release_label);

// Add Loading Views
if (mode == MODE_PULL_DOWN_TO_REFRESH || mode == MODE_BOTH) {
headerLayout = new LoadingLayout(context, MODE_PULL_DOWN_TO_REFRESH, releaseLabel, pullLabel,
refreshingLabel);
addView(headerLayout, 0, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
measureView(headerLayout);
headerHeight = headerLayout.getMeasuredHeight();
}
if (mode == MODE_PULL_UP_TO_REFRESH || mode == MODE_BOTH) {
footerLayout = new LoadingLayout(context, MODE_PULL_UP_TO_REFRESH, releaseLabel, pullLabel, refreshingLabel);
addView(footerLayout, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
measureView(footerLayout);
headerHeight = footerLayout.getMeasuredHeight();
}

// Hide Loading Views
switch (mode) {
case MODE_BOTH:
setPadding(0, -headerHeight, 0, -headerHeight);
break;
case MODE_PULL_UP_TO_REFRESH:
setPadding(0, 0, 0, -headerHeight);
break;
case MODE_PULL_DOWN_TO_REFRESH:
default:
setPadding(0, -headerHeight, 0, 0);
break;
}

// If we're not using MODE_BOTH, then just set currentMode to current
// mode
if (mode != MODE_BOTH) {
currentMode = mode;
}
}

private void init(Context context, AttributeSet attrs) {

Expand All @@ -593,8 +536,10 @@ private void init(Context context, AttributeSet attrs) {
touchSlop = ViewConfiguration.getTouchSlop();

// Styleables from XML
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PullToRefresh);
mode = a.getInteger(R.styleable.PullToRefresh_mode, MODE_PULL_DOWN_TO_REFRESH);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PullToRefresh);
if (a.hasValue(R.styleable.PullToRefresh_mode)) {
mode = a.getInteger(R.styleable.PullToRefresh_mode, MODE_PULL_DOWN_TO_REFRESH);
}

// Refreshable View
// By passing the attrs, we can add ListView/GridView params via XML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public PullToRefreshExpandableListView(Context context) {
super(context);
}

public PullToRefreshExpandableListView(Context context, int mode) {
super(context, mode);
}

public PullToRefreshExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
Expand All @@ -50,6 +54,6 @@ protected final ExpandableListView createRefreshableView(Context context, Attrib

@Override
public ContextMenuInfo getContextMenuInfo() {
return ((InternalExpandableListView)getRefreshableView()).getContextMenuInfo();
return ((InternalExpandableListView) getRefreshableView()).getContextMenuInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public PullToRefreshGridView(Context context) {
super(context);
}

public PullToRefreshGridView(Context context, int mode) {
super(context, mode);
}

public PullToRefreshGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
Expand All @@ -51,6 +55,6 @@ protected final GridView createRefreshableView(Context context, AttributeSet att

@Override
public ContextMenuInfo getContextMenuInfo() {
return ((InternalGridView)getRefreshableView()).getContextMenuInfo();
return ((InternalGridView) getRefreshableView()).getContextMenuInfo();
}
}

0 comments on commit 5102695

Please sign in to comment.