use of android.widget.AbsListView.OnScrollListener in project UltimateAndroid by cymcsg.
the class AnimationFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mListView = (QuickReturnListView) getListView();
mQuickReturnView.setText("Animation");
mListView.addHeaderView(mHeader);
String[] array = new String[] { "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android" };
setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.quick_return_listview_list_item, R.id.text1, array));
mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mQuickReturnHeight = mQuickReturnView.getHeight();
mListView.computeScrollY();
mCachedVerticalScrollRange = mListView.getListHeight();
}
});
mListView.setOnScrollListener(new OnScrollListener() {
@SuppressLint("NewApi")
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
mScrollY = 0;
int translationY = 0;
if (mListView.scrollYIsComputed()) {
mScrollY = mListView.getComputedScrollY();
}
rawY = mPlaceHolder.getTop() - Math.min(mCachedVerticalScrollRange - mListView.getHeight(), mScrollY);
switch(mState) {
case STATE_OFFSCREEN:
if (rawY <= mMinRawY) {
mMinRawY = rawY;
} else {
mState = STATE_RETURNING;
}
translationY = rawY;
break;
case STATE_ONSCREEN:
if (rawY < -mQuickReturnHeight) {
System.out.println("test3");
mState = STATE_OFFSCREEN;
mMinRawY = rawY;
}
translationY = rawY;
break;
case STATE_RETURNING:
if (translationY > 0) {
translationY = 0;
mMinRawY = rawY - mQuickReturnHeight;
} else if (rawY > 0) {
mState = STATE_ONSCREEN;
translationY = rawY;
} else if (translationY < -mQuickReturnHeight) {
mState = STATE_OFFSCREEN;
mMinRawY = rawY;
} else if (mQuickReturnView.getTranslationY() != 0 && !noAnimation) {
noAnimation = true;
anim = new TranslateAnimation(0, 0, -mQuickReturnHeight, 0);
anim.setFillAfter(true);
anim.setDuration(250);
mQuickReturnView.startAnimation(anim);
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
noAnimation = false;
mMinRawY = rawY;
mState = STATE_EXPANDED;
}
});
}
break;
case STATE_EXPANDED:
if (rawY < mMinRawY - 2 && !noAnimation) {
noAnimation = true;
anim = new TranslateAnimation(0, 0, 0, -mQuickReturnHeight);
anim.setFillAfter(true);
anim.setDuration(250);
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
noAnimation = false;
mState = STATE_OFFSCREEN;
}
});
mQuickReturnView.startAnimation(anim);
} else if (translationY > 0) {
translationY = 0;
mMinRawY = rawY - mQuickReturnHeight;
} else if (rawY > 0) {
mState = STATE_ONSCREEN;
translationY = rawY;
} else if (translationY < -mQuickReturnHeight) {
mState = STATE_OFFSCREEN;
mMinRawY = rawY;
} else {
mMinRawY = rawY;
}
}
/** this can be used if the build is below honeycomb **/
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
anim = new TranslateAnimation(0, 0, translationY, translationY);
anim.setFillAfter(true);
anim.setDuration(0);
mQuickReturnView.startAnimation(anim);
} else {
mQuickReturnView.setTranslationY(translationY);
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
});
}
use of android.widget.AbsListView.OnScrollListener in project UltimateAndroid by cymcsg.
the class BottomFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mListView = (QuickReturnListView) getListView();
String[] array = new String[] { "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android" };
setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.quick_return_listview_list_item, R.id.text1, array));
mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mQuickReturnHeight = mQuickReturnView.getHeight();
mListView.computeScrollY();
}
});
mListView.setOnScrollListener(new OnScrollListener() {
@SuppressLint("NewApi")
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
mScrollY = 0;
int translationY = 0;
if (mListView.scrollYIsComputed()) {
mScrollY = mListView.getComputedScrollY();
}
int rawY = mScrollY;
switch(mState) {
case STATE_OFFSCREEN:
if (rawY >= mMinRawY) {
mMinRawY = rawY;
} else {
mState = STATE_RETURNING;
}
translationY = rawY;
break;
case STATE_ONSCREEN:
if (rawY > mQuickReturnHeight) {
mState = STATE_OFFSCREEN;
mMinRawY = rawY;
}
translationY = rawY;
break;
case STATE_RETURNING:
translationY = (rawY - mMinRawY) + mQuickReturnHeight;
System.out.println(translationY);
if (translationY < 0) {
translationY = 0;
mMinRawY = rawY + mQuickReturnHeight;
}
if (rawY == 0) {
mState = STATE_ONSCREEN;
translationY = 0;
}
if (translationY > mQuickReturnHeight) {
mState = STATE_OFFSCREEN;
mMinRawY = rawY;
}
break;
}
/** this can be used if the build is below honeycomb **/
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
anim = new TranslateAnimation(0, 0, translationY, translationY);
anim.setFillAfter(true);
anim.setDuration(0);
mQuickReturnView.startAnimation(anim);
} else {
mQuickReturnView.setTranslationY(translationY);
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
});
}
use of android.widget.AbsListView.OnScrollListener in project AndroidSDK-RecipeBook by gabu.
the class Recipe045 method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 文字列のみのシンプルなAdapterを作成
ArrayAdapter<String> adapter;
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
// 0から19までのリストアイテムを追加
for (int i = 0; i < 20; i++) {
adapter.add("item_" + i);
}
ListView listView = (ListView) findViewById(R.id.ListView01);
listView.setAdapter(adapter);
listView.setOnScrollListener(new OnScrollListener() {
public void onScrollStateChanged(AbsListView view, int scrollState) {
// 実装が必須なので定義するが今回は使わない
}
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Log.d(TAG, "++++++++++++++++");
Log.d(TAG, "firstVisibleItem=" + firstVisibleItem);
Log.d(TAG, "visibleItemCount=" + visibleItemCount);
Log.d(TAG, "totalItemCount=" + totalItemCount);
if ((totalItemCount - visibleItemCount) == firstVisibleItem) {
Toast.makeText(view.getContext(), "ここが最後です><", Toast.LENGTH_LONG).show();
}
}
});
}
use of android.widget.AbsListView.OnScrollListener in project SmartAndroidSource by jaychou2012.
the class Common method shouldDelay.
public static boolean shouldDelay(int groupPosition, int childPosition, View convertView, ViewGroup parent, String url) {
if (url == null || BitmapAjaxCallback.isMemoryCached(url)) {
return false;
}
AbsListView lv = (AbsListView) parent;
OnScrollListener sl = (OnScrollListener) parent.getTag(AQuery.TAG_SCROLL_LISTENER);
if (sl == null) {
sl = new Common();
lv.setOnScrollListener(sl);
parent.setTag(AQuery.TAG_SCROLL_LISTENER, sl);
}
Integer scrollState = (Integer) lv.getTag(AQuery.TAG_NUM);
if (scrollState == null || scrollState == OnScrollListener.SCROLL_STATE_IDLE || scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
return false;
}
long packed = childPosition;
if (parent instanceof ExpandableListView) {
packed = ExpandableListView.getPackedPositionForChild(groupPosition, childPosition);
}
convertView.setTag(AQuery.TAG_NUM, packed);
return true;
}
use of android.widget.AbsListView.OnScrollListener in project androidquery by androidquery.
the class Common method shouldDelay.
public static boolean shouldDelay(int groupPosition, int childPosition, View convertView, ViewGroup parent, String url) {
if (url == null || BitmapAjaxCallback.isMemoryCached(url)) {
return false;
}
AbsListView lv = (AbsListView) parent;
OnScrollListener sl = (OnScrollListener) parent.getTag(AQuery.TAG_SCROLL_LISTENER);
if (sl == null) {
sl = new Common();
lv.setOnScrollListener(sl);
parent.setTag(AQuery.TAG_SCROLL_LISTENER, sl);
}
Integer scrollState = (Integer) lv.getTag(AQuery.TAG_NUM);
if (scrollState == null || scrollState == OnScrollListener.SCROLL_STATE_IDLE || scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
return false;
}
long packed = childPosition;
if (parent instanceof ExpandableListView) {
packed = ExpandableListView.getPackedPositionForChild(groupPosition, childPosition);
}
convertView.setTag(AQuery.TAG_NUM, packed);
return true;
}
Aggregations