Skip to content
This repository has been archived by the owner on May 15, 2021. It is now read-only.

Commit

Permalink
Added scrollBarPanel attribute to ExtendedListView.
Browse files Browse the repository at this point in the history
  • Loading branch information
rno committed Mar 19, 2012
1 parent 8741a61 commit 254f9bb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
5 changes: 5 additions & 0 deletions library/res/values/attrs.xml
@@ -0,0 +1,5 @@
<resources>
<declare-styleable name="ExtendedListView">
<attr name="scrollBarPanel" format="reference" />
</declare-styleable>
</resources>
Expand Up @@ -3,6 +3,7 @@
import com.dafruits.android.library.R; import com.dafruits.android.library.R;


import android.content.Context; import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.os.Handler; import android.os.Handler;
import android.util.AttributeSet; import android.util.AttributeSet;
Expand Down Expand Up @@ -63,20 +64,51 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun




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




public ExtendedListView(Context context, AttributeSet attrs) { public ExtendedListView(Context context, AttributeSet attrs) {
super(context, attrs); this(context, attrs, android.R.attr.listViewStyle);
init();
} }




public ExtendedListView(Context context, AttributeSet attrs, int defStyle) { public ExtendedListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, 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);
}
}
});
} }




Expand Down Expand Up @@ -179,32 +211,4 @@ private void updateScrollerView() {


mHandler.postDelayed(mScrollBarPanelFadeRunnable, mScrollBarPanelFadeDuration); 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);
}
}
});
}
} }
4 changes: 3 additions & 1 deletion sample/res/layout/main.xml
Expand Up @@ -5,9 +5,11 @@
android:orientation="vertical" > android:orientation="vertical" >


<com.dafruits.android.library.widgets.ExtendedListView <com.dafruits.android.library.widgets.ExtendedListView
xmlns:dafruits="http://schemas.android.com/apk/res/com.dafruits.android.samples"
android:id="@android:id/list" android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:choiceMode="singleChoice" /> android:choiceMode="singleChoice"
dafruits:scrollBarPanel="@layout/scrollbarpanel" />


</LinearLayout> </LinearLayout>
Expand Up @@ -17,17 +17,15 @@
public class DemoScrollBarPanelActivity extends Activity { public class DemoScrollBarPanelActivity extends Activity {


private ExtendedListView mListView; private ExtendedListView mListView;
private TextView mScrollBarPanel;



@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);


setContentView(R.layout.main); setContentView(R.layout.main);


mListView = (ExtendedListView) findViewById(android.R.id.list); 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.setAdapter(new DummyAdapter());
mListView.setCacheColorHint(Color.TRANSPARENT); mListView.setCacheColorHint(Color.TRANSPARENT);
mListView.setOnScrollListener(new OnScrollListener() { mListView.setOnScrollListener(new OnScrollListener() {
Expand All @@ -37,7 +35,8 @@ public void onScrollStateChanged(AbsListView view, int scrollState) {


@Override @Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 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);
} }
}); });
} }
Expand Down

0 comments on commit 254f9bb

Please sign in to comment.