Search in sources :

Example 16 with OnScrollListener

use of android.widget.AbsListView.OnScrollListener in project Rashr by DsLNeXuS.

the class CardUI method setHeader.

public void setHeader(View header) {
    mPlaceholderView.setVisibility(View.VISIBLE);
    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();
            }
            int rawY = mPlaceholderView.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) {
                        mState = STATE_OFFSCREEN;
                        mMinRawY = rawY;
                    }
                    translationY = rawY;
                    break;
                case STATE_RETURNING:
                    translationY = (rawY - mMinRawY) - mQuickReturnHeight;
                    if (translationY > 0) {
                        translationY = 0;
                        mMinRawY = rawY - mQuickReturnHeight;
                    }
                    if (rawY > 0) {
                        mState = STATE_ONSCREEN;
                        translationY = rawY;
                    }
                    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) {
                TranslateAnimation 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) {
        }
    });
    if (header != null) {
        try {
            mQuickReturnView.removeAllViews();
        } catch (Exception e) {
            e.printStackTrace();
        }
        mQuickReturnView.addView(header);
    }
}
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 17 with OnScrollListener

use of android.widget.AbsListView.OnScrollListener in project little-bear-dictionary by daimajia.

the class CalendarView method setUpListView.

@SuppressLint("NewApi")
private void setUpListView() {
    mListView.setDivider(null);
    mListView.setItemsCanFocus(true);
    mListView.setVerticalScrollBarEnabled(false);
    mListView.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            CalendarView.this.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            CalendarView.this.onScrollStateChanged(view, scrollState);
        }
    });
    if (VERSION.SDK_INT >= 11) {
        mListView.setFriction(mFriction);
        mListView.setVelocityScale(mVelocityScale);
    }
}
Also used : OnScrollListener(android.widget.AbsListView.OnScrollListener) AbsListView(android.widget.AbsListView) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 18 with OnScrollListener

use of android.widget.AbsListView.OnScrollListener in project MultiImageChooser by derosa.

the class MultiImageChooserActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    int theme = getIntent().getIntExtra("THEME", R.style.CollageTheme);
    setTheme(theme);
    setContentView(R.layout.multiselectorgrid);
    fileNames.clear();
    maxImages = getIntent().getIntExtra(MAX_IMAGES_KEY, NOLIMIT);
    unlimitedImages = maxImages == NOLIMIT;
    if (!unlimitedImages) {
        freeLabel = (TextView) findViewById(R.id.label_images_left);
        freeLabel.setVisibility(View.VISIBLE);
        updateLabel();
    }
    colWidth = getIntent().getIntExtra(COL_WIDTH_KEY, DEFAULT_COLUMN_WIDTH);
    Display display = getWindowManager().getDefaultDisplay();
    int width = 0;
    if (Build.VERSION.SDK_INT >= 13) {
        Point p = new Point();
        display.getSize(p);
        width = p.x;
    } else {
        width = display.getWidth();
    }
    gridView = (GridView) findViewById(R.id.gridview);
    gridView.setColumnWidth(width / 3);
    gridView.setNumColumns(3);
    gridView.setOnItemClickListener(this);
    gridView.setOnScrollListener(new OnScrollListener() {

        private int lastFirstItem = 0;

        private long timestamp = System.currentTimeMillis();

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (scrollState == SCROLL_STATE_IDLE) {
                Log.d(TAG, "IDLE - Reload!");
                shouldRequestThumb = true;
                ia.notifyDataSetChanged();
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            float dt = System.currentTimeMillis() - timestamp;
            if (firstVisibleItem != lastFirstItem) {
                double speed = 1 / dt * 1000;
                lastFirstItem = firstVisibleItem;
                timestamp = System.currentTimeMillis();
                Log.d(TAG, "Speed: " + speed + " elements/second");
                // Limitarlo si vamos a más de una página por segundo...
                shouldRequestThumb = speed < visibleItemCount;
            }
        }
    });
    selectedColor = 0xff32b2e1;
    // selectedColor = Color.RED;
    // gridView.setBackgroundColor(bgColor);
    // gridView.setBackgroundResource(R.drawable.grid_background);
    ia = new ImageAdapter(this);
    gridView.setAdapter(ia);
    LoaderManager.enableDebugLogging(false);
    getSupportLoaderManager().initLoader(CURSORLOADER_THUMBS, null, this);
    getSupportLoaderManager().initLoader(CURSORLOADER_REAL, null, this);
    setupHeader();
    updateAcceptButton();
}
Also used : OnScrollListener(android.widget.AbsListView.OnScrollListener) AbsListView(android.widget.AbsListView) Point(android.graphics.Point) Point(android.graphics.Point) Display(android.view.Display)

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