Skip to content

Commit

Permalink
Adding sub header functionality for displaying last updated time. Kee…
Browse files Browse the repository at this point in the history
…p it generic and pass a string so the app can easily format the date however it wants to.
  • Loading branch information
Peter Elliott committed Apr 20, 2012
1 parent 33a47ed commit 1dbe652
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
33 changes: 24 additions & 9 deletions library/res/layout/pull_to_refresh_header.xml
Expand Up @@ -5,15 +5,32 @@
android:paddingTop="10dp"
android:paddingBottom="10dip">

<TextView
android:id="@+id/pull_to_refresh_text"
android:text="@string/pull_to_refresh_pull_label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />

android:layout_centerInParent="true"
android:orientation="vertical"
android:gravity="center">

<TextView
android:id="@+id/pull_to_refresh_text"
android:text="@string/pull_to_refresh_pull_label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />

<TextView
android:id="@+id/pull_to_refresh_sub_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="11sp"
android:visibility="gone" />

</LinearLayout>

<ProgressBar
android:id="@+id/pull_to_refresh_progress"
android:indeterminate="true"
Expand All @@ -33,6 +50,4 @@
android:layout_marginRight="20dip"
android:layout_centerVertical="true" />



</RelativeLayout>
Expand Up @@ -855,4 +855,8 @@ public static interface OnLastItemVisibleListener {
public void setLongClickable(boolean longClickable) {
getRefreshableView().setLongClickable(longClickable);
}

public void setSubHeaderText(CharSequence text) {
mHeaderLayout.setSubHeaderText(text);
}
}
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -25,6 +26,7 @@ public class LoadingLayout extends FrameLayout {
private final ImageView mHeaderImage;
private final ProgressBar mHeaderProgress;
private final TextView mHeaderText;
private final TextView mSubHeaderText;

private String mPullLabel;
private String mRefreshingLabel;
Expand All @@ -37,6 +39,7 @@ public LoadingLayout(Context context, final int mode, String releaseLabel, Strin
super(context);
ViewGroup header = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.pull_to_refresh_header, this);
mHeaderText = (TextView) header.findViewById(R.id.pull_to_refresh_text);
mSubHeaderText = (TextView) header.findViewById(R.id.pull_to_refresh_sub_text);
mHeaderImage = (ImageView) header.findViewById(R.id.pull_to_refresh_image);
mHeaderProgress = (ProgressBar) header.findViewById(R.id.pull_to_refresh_progress);

Expand Down Expand Up @@ -77,6 +80,11 @@ public void reset() {
mHeaderText.setText(mPullLabel);
mHeaderImage.setVisibility(View.VISIBLE);
mHeaderProgress.setVisibility(View.GONE);
if (TextUtils.isEmpty(mSubHeaderText.getText())) {
mSubHeaderText.setVisibility(View.GONE);
} else {
mSubHeaderText.setVisibility(View.VISIBLE);
}
}

public void releaseToRefresh() {
Expand All @@ -94,6 +102,7 @@ public void refreshing() {
mHeaderImage.clearAnimation();
mHeaderImage.setVisibility(View.INVISIBLE);
mHeaderProgress.setVisibility(View.VISIBLE);
mSubHeaderText.setVisibility(View.GONE);
}

public void setRefreshingLabel(String refreshingLabel) {
Expand All @@ -112,6 +121,15 @@ public void pullToRefresh() {

public void setTextColor(int color) {
mHeaderText.setTextColor(color);
mSubHeaderText.setTextColor(color);
}

public void setSubHeaderText(CharSequence text) {
mSubHeaderText.setText(text);
if (TextUtils.isEmpty(text)) {
mSubHeaderText.setVisibility(View.GONE);
} else {
mSubHeaderText.setVisibility(View.VISIBLE);
}
}

}

0 comments on commit 1dbe652

Please sign in to comment.