Permalink
Browse files

Added scrollBarPanel attribute to ExtendedListView.

  • Loading branch information...
rno committed Mar 19, 2012
1 parent 8741a61 commit 254f9bb8124071e76d0a67cc3a3b4d511097ea18
@@ -0,0 +1,5 @@
+<resources>
+ <declare-styleable name="ExtendedListView">
+ <attr name="scrollBarPanel" format="reference" />
+ </declare-styleable>
+</resources>
@@ -3,6 +3,7 @@
import com.dafruits.android.library.R;
import android.content.Context;
+import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.os.Handler;
import android.util.AttributeSet;
@@ -63,20 +64,51 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
public ExtendedListView(Context context) {
- super(context);
- init();
+ this(context, null);
}
public ExtendedListView(Context context, AttributeSet attrs) {
- super(context, attrs);
- init();
+ this(context, attrs, android.R.attr.listViewStyle);
}
public ExtendedListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- init();
+
+ super.setOnScrollListener(mScrollListener);
+
+ final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ExtendedListView);
+ final int scrollBarPanelLayoutId = a.getResourceId(R.styleable.ExtendedListView_scrollBarPanel, -1);
+ a.recycle();
+
+ if (scrollBarPanelLayoutId != -1) {
+ setScrollBarPanel(scrollBarPanelLayoutId);
+ }
+
+ mScrollBarPanelFadeDuration = ViewConfiguration.getScrollBarFadeDuration() * 2;
+
+ mInAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.in_animation);
+ mOutAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.out_animation);
+
+ mOutAnimation.setAnimationListener(new AnimationListener() {
+
+ @Override
+ public void onAnimationStart(Animation animation) {
+ }
+
+ @Override
+ public void onAnimationRepeat(Animation animation) {
+
+ }
+
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ if (mScrollBarPanel != null) {
+ mScrollBarPanel.setVisibility(View.GONE);
+ }
+ }
+ });
}
@@ -179,32 +211,4 @@ private void updateScrollerView() {
mHandler.postDelayed(mScrollBarPanelFadeRunnable, mScrollBarPanelFadeDuration);
}
-
-
- private void init() {
- super.setOnScrollListener(mScrollListener);
- mScrollBarPanelFadeDuration = ViewConfiguration.getScrollBarFadeDuration() * 2;
-
- mInAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.in_animation);
- mOutAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.out_animation);
-
- mOutAnimation.setAnimationListener(new AnimationListener() {
-
- @Override
- public void onAnimationStart(Animation animation) {
- }
-
- @Override
- public void onAnimationRepeat(Animation animation) {
-
- }
-
- @Override
- public void onAnimationEnd(Animation animation) {
- if (mScrollBarPanel != null) {
- mScrollBarPanel.setVisibility(View.GONE);
- }
- }
- });
- }
}
@@ -5,9 +5,11 @@
android:orientation="vertical" >
<com.dafruits.android.library.widgets.ExtendedListView
+ xmlns:dafruits="http://schemas.android.com/apk/res/com.dafruits.android.samples"
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:choiceMode="singleChoice" />
+ android:choiceMode="singleChoice"
+ dafruits:scrollBarPanel="@layout/scrollbarpanel" />
</LinearLayout>
@@ -17,17 +17,15 @@
public class DemoScrollBarPanelActivity extends Activity {
private ExtendedListView mListView;
- private TextView mScrollBarPanel;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mListView = (ExtendedListView) findViewById(android.R.id.list);
- mScrollBarPanel = (TextView) LayoutInflater.from(this).inflate(R.layout.scrollbarpanel, mListView, false);
- mListView.setScrollBarPanel(mScrollBarPanel);
mListView.setAdapter(new DummyAdapter());
mListView.setCacheColorHint(Color.TRANSPARENT);
mListView.setOnScrollListener(new OnScrollListener() {
@@ -37,7 +35,8 @@ public void onScrollStateChanged(AbsListView view, int scrollState) {
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
- mScrollBarPanel.setText("Position " + firstVisibleItem);
+ final TextView scrollBarPanel = (TextView) mListView.getScrollBarPanel();
+ scrollBarPanel.setText("Position " + firstVisibleItem);
}
});
}

0 comments on commit 254f9bb

Please sign in to comment.