Search in sources :

Example 1 with OnScrollListener

use of android.widget.AbsListView.OnScrollListener in project BlurEffectForAndroidDesign by PomepuyN.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_main);
    // Get the screen width
    final int screenWidth = ImageUtils.getScreenWidth(this);
    // Find the view
    mBlurredImage = (ImageView) findViewById(R.id.blurred_image);
    mNormalImage = (ImageView) findViewById(R.id.normal_image);
    mBlurredImageHeader = (ScrollableImageView) findViewById(R.id.blurred_image_header);
    mSwitch = (Switch) findViewById(R.id.background_switch);
    mList = (ListView) findViewById(R.id.list);
    // prepare the header ScrollableImageView
    mBlurredImageHeader.setScreenWidth(screenWidth);
    // Action for the switch
    mSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mBlurredImage.setAlpha(alpha);
            } else {
                mBlurredImage.setAlpha(0f);
            }
        }
    });
    // Try to find the blurred image
    final File blurredImage = new File(getFilesDir() + BLURRED_IMG_PATH);
    if (!blurredImage.exists()) {
        // launch the progressbar in ActionBar
        setProgressBarIndeterminateVisibility(true);
        new Thread(new Runnable() {

            @Override
            public void run() {
                // No image found => let's generate it!
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 2;
                Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.image, options);
                Bitmap newImg = Blur.fastblur(MainActivity.this, image, 12);
                ImageUtils.storeImage(newImg, blurredImage);
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        updateView(screenWidth);
                        // And finally stop the progressbar
                        setProgressBarIndeterminateVisibility(false);
                    }
                });
            }
        }).start();
    } else {
        // The image has been found. Let's update the view
        updateView(screenWidth);
    }
    String[] strings = getResources().getStringArray(R.array.list_content);
    // Prepare the header view for our list
    headerView = new View(this);
    headerView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, TOP_HEIGHT));
    mList.addHeaderView(headerView);
    mList.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, strings));
    mList.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        /**
			 * Listen to the list scroll. This is where magic happens ;)
			 */
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            // Calculate the ratio between the scroll amount and the list
            // header weight to determinate the top picture alpha
            alpha = (float) -headerView.getTop() / (float) TOP_HEIGHT;
            // Apply a ceil
            if (alpha > 1) {
                alpha = 1;
            }
            // Apply on the ImageView if needed
            if (mSwitch.isChecked()) {
                mBlurredImage.setAlpha(alpha);
            }
            // Parallax effect : we apply half the scroll amount to our
            // three views
            mBlurredImage.setTop(headerView.getTop() / 2);
            mNormalImage.setTop(headerView.getTop() / 2);
            mBlurredImageHeader.handleScroll(headerView.getTop() / 2);
        }
    });
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) LayoutParams(android.widget.AbsListView.LayoutParams) AbsListView(android.widget.AbsListView) ImageView(android.widget.ImageView) AbsListView(android.widget.AbsListView) View(android.view.View) ListView(android.widget.ListView) Bitmap(android.graphics.Bitmap) OnScrollListener(android.widget.AbsListView.OnScrollListener) BitmapFactory(android.graphics.BitmapFactory) File(java.io.File) CompoundButton(android.widget.CompoundButton)

Example 2 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 3 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 4 with OnScrollListener

use of android.widget.AbsListView.OnScrollListener in project android_frameworks_base by ParanoidAndroid.

the class CalendarView method setUpListView.

/**
     * Sets all the required fields for the list view.
     */
private void setUpListView() {
    // Configure the listview
    mListView.setDivider(null);
    mListView.setItemsCanFocus(true);
    mListView.setVerticalScrollBarEnabled(false);
    mListView.setOnScrollListener(new OnScrollListener() {

        public void onScrollStateChanged(AbsListView view, int scrollState) {
            CalendarView.this.onScrollStateChanged(view, scrollState);
        }

        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            CalendarView.this.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
        }
    });
    // Make the scrolling behavior nicer
    mListView.setFriction(mFriction);
    mListView.setVelocityScale(mVelocityScale);
}
Also used : OnScrollListener(android.widget.AbsListView.OnScrollListener) Paint(android.graphics.Paint)

Example 5 with OnScrollListener

use of android.widget.AbsListView.OnScrollListener in project androidquery by androidquery.

the class ImageLoadingList4Activity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    aq.id(R.id.list).scrolled(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            AQUtility.debug("forward", "onScrollStateChanged");
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            AQUtility.debug("forward", "onScroll");
        }
    });
}
Also used : OnScrollListener(android.widget.AbsListView.OnScrollListener) AbsListView(android.widget.AbsListView)

Aggregations

OnScrollListener (android.widget.AbsListView.OnScrollListener)23 AbsListView (android.widget.AbsListView)19 ListView (android.widget.ListView)10 SuppressLint (android.annotation.SuppressLint)9 View (android.view.View)9 MotionEvent (android.view.MotionEvent)4 ViewGroup (android.view.ViewGroup)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 AdapterView (android.widget.AdapterView)3 ImageView (android.widget.ImageView)3 File (java.io.File)3 Resources (android.content.res.Resources)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 KeyEvent (android.view.KeyEvent)2 LayoutInflater (android.view.LayoutInflater)2 OnClickListener (android.view.View.OnClickListener)2