Search in sources :

Example 6 with OnScrollListener

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) {
        }
    });
}
Also used : AbsListView(android.widget.AbsListView) TranslateAnimation(android.view.animation.TranslateAnimation) SuppressLint(android.annotation.SuppressLint) OnScrollListener(android.widget.AbsListView.OnScrollListener) SuppressLint(android.annotation.SuppressLint) TranslateAnimation(android.view.animation.TranslateAnimation) Animation(android.view.animation.Animation) AnimationListener(android.view.animation.Animation.AnimationListener) ViewTreeObserver(android.view.ViewTreeObserver)

Example 7 with OnScrollListener

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) {
        }
    });
}
Also used : OnScrollListener(android.widget.AbsListView.OnScrollListener) SuppressLint(android.annotation.SuppressLint) AbsListView(android.widget.AbsListView) TranslateAnimation(android.view.animation.TranslateAnimation) ViewTreeObserver(android.view.ViewTreeObserver) SuppressLint(android.annotation.SuppressLint)

Example 8 with OnScrollListener

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();
            }
        }
    });
}
Also used : AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) OnScrollListener(android.widget.AbsListView.OnScrollListener) AbsListView(android.widget.AbsListView)

Example 9 with OnScrollListener

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;
}
Also used : OnScrollListener(android.widget.AbsListView.OnScrollListener) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView)

Example 10 with OnScrollListener

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;
}
Also used : OnScrollListener(android.widget.AbsListView.OnScrollListener) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView)

Aggregations

OnScrollListener (android.widget.AbsListView.OnScrollListener)18 AbsListView (android.widget.AbsListView)14 SuppressLint (android.annotation.SuppressLint)8 View (android.view.View)6 ListView (android.widget.ListView)5 MotionEvent (android.view.MotionEvent)4 ViewTreeObserver (android.view.ViewTreeObserver)4 TranslateAnimation (android.view.animation.TranslateAnimation)4 Paint (android.graphics.Paint)3 Animation (android.view.animation.Animation)3 AnimationListener (android.view.animation.Animation.AnimationListener)3 OnTouchListener (android.view.View.OnTouchListener)2 ViewGroup (android.view.ViewGroup)2 LayoutParams (android.view.ViewGroup.LayoutParams)2 AlphaAnimation (android.view.animation.AlphaAnimation)2 CompoundButton (android.widget.CompoundButton)2 ExpandableListView (android.widget.ExpandableListView)2 ImageView (android.widget.ImageView)2 File (java.io.File)2 Builder (android.app.AlertDialog.Builder)1