Search in sources :

Example 16 with AbsListView

use of android.widget.AbsListView 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 17 with AbsListView

use of android.widget.AbsListView 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 18 with AbsListView

use of android.widget.AbsListView in project android_frameworks_base by DirtyUnicorns.

the class ResolverActivity method onPrepareAdapterView.

public void onPrepareAdapterView(AbsListView adapterView, ResolveListAdapter adapter, boolean alwaysUseOption) {
    final boolean useHeader = adapter.hasFilteredItem();
    final ListView listView = adapterView instanceof ListView ? (ListView) adapterView : null;
    adapterView.setAdapter(mAdapter);
    final ItemClickListener listener = new ItemClickListener();
    adapterView.setOnItemClickListener(listener);
    adapterView.setOnItemLongClickListener(listener);
    if (alwaysUseOption) {
        listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    }
    if (useHeader && listView != null) {
        listView.addHeaderView(LayoutInflater.from(this).inflate(R.layout.resolver_different_item_header, listView, false));
    }
}
Also used : ListView(android.widget.ListView) AbsListView(android.widget.AbsListView)

Example 19 with AbsListView

use of android.widget.AbsListView in project android_frameworks_base by DirtyUnicorns.

the class ResolverDrawerLayout method findListChildUnder.

private View findListChildUnder(float x, float y) {
    View v = findChildUnder(x, y);
    while (v != null) {
        x -= v.getX();
        y -= v.getY();
        if (v instanceof AbsListView) {
            // One more after this.
            return findChildUnder((ViewGroup) v, x, y);
        }
        v = v instanceof ViewGroup ? findChildUnder((ViewGroup) v, x, y) : null;
    }
    return v;
}
Also used : ViewGroup(android.view.ViewGroup) AbsListView(android.widget.AbsListView) View(android.view.View) AbsListView(android.widget.AbsListView)

Example 20 with AbsListView

use of android.widget.AbsListView in project android_frameworks_base by DirtyUnicorns.

the class ResolverDrawerLayout method getHeightUsed.

private int getHeightUsed(View child) {
    // This method exists because we're taking a fast path at measuring ListViews that
    // lets us get away with not doing the more expensive wrap_content measurement which
    // imposes double child view measurement costs. If we're looking at a ListView, we can
    // check against the lowest child view plus padding and margin instead of the actual
    // measured height of the ListView. This lets the ListView hang off the edge when
    // all of the content would fit on-screen.
    int heightUsed = child.getMeasuredHeight();
    if (child instanceof AbsListView) {
        final AbsListView lv = (AbsListView) child;
        final int lvPaddingBottom = lv.getPaddingBottom();
        int lowest = 0;
        for (int i = 0, N = lv.getChildCount(); i < N; i++) {
            final int bottom = lv.getChildAt(i).getBottom() + lvPaddingBottom;
            if (bottom > lowest) {
                lowest = bottom;
            }
        }
        if (lowest < heightUsed) {
            heightUsed = lowest;
        }
    }
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    return lp.topMargin + heightUsed + lp.bottomMargin;
}
Also used : AbsListView(android.widget.AbsListView)

Aggregations

AbsListView (android.widget.AbsListView)218 View (android.view.View)126 ListView (android.widget.ListView)80 AdapterView (android.widget.AdapterView)54 TextView (android.widget.TextView)46 ViewGroup (android.view.ViewGroup)33 ImageView (android.widget.ImageView)29 RecyclerView (android.support.v7.widget.RecyclerView)21 GridView (android.widget.GridView)21 SuppressLint (android.annotation.SuppressLint)20 ScrollView (android.widget.ScrollView)20 OnScrollListener (android.widget.AbsListView.OnScrollListener)19 Intent (android.content.Intent)17 ArrayList (java.util.ArrayList)16 Context (android.content.Context)12 Point (android.graphics.Point)12 Handler (android.os.Handler)12 ExpandableListView (android.widget.ExpandableListView)12 ArrayListLoader (com.klinker.android.twitter.adapters.ArrayListLoader)10 ItemManager (org.lucasr.smoothie.ItemManager)10