Example usage for android.widget AbsListView.OnScrollListener AbsListView.OnScrollListener

List of usage examples for android.widget AbsListView.OnScrollListener AbsListView.OnScrollListener

Introduction

In this page you can find the example usage for android.widget AbsListView.OnScrollListener AbsListView.OnScrollListener.

Prototype

AbsListView.OnScrollListener

Source Link

Usage

From source file:com.google.samples.apps.iosched.ui.HashtagsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (loader.getId() == HashtagsQuery.TOKEN) {
        final HashtagsAdapter adapter = new HashtagsAdapter(getActivity(), cursor);
        mCollectionView.setCollectionAdapter(adapter);
        mCollectionView.updateInventory(adapter.getInventory());
        mCollectionView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override/*from   w ww  . ja  v  a2  s  .  com*/
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                adapter.hideDescriptionToast();
            }

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

From source file:net.wespot.pim.view.InqImageGridFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View v = inflater.inflate(R.layout.fragment_data_collect_grid, container, false);
    final GridView mGridView = (GridView) v.findViewById(R.id.gridView);
    mGridView.setAdapter(mAdapter);/* ww  w. j ava 2 s. com*/
    mGridView.setOnItemClickListener(this);
    mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            // Pause fetcher to ensure smoother scrolling when flinging
            if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
                // Before Honeycomb pause image loading on scroll to help with performance
                if (!Utils.hasHoneycomb()) {
                    mImageFetcher.setPauseWork(true);
                }
            } else {
                mImageFetcher.setPauseWork(false);
            }
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
        }
    });

    // This listener is used to get the final width of the GridView and then calculate the
    // number of columns and the width of each column. The width of each column is variable
    // as the GridView has stretchMode=columnWidth. The column width is used to set the height
    // of each view so we get nice square thumbnails.
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @TargetApi(VERSION_CODES.JELLY_BEAN)
        @Override
        public void onGlobalLayout() {
            if (mAdapter.getNumColumns() == 0) {
                final int numColumns = (int) Math
                        .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
                if (numColumns > 0) {
                    final int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing;
                    mAdapter.setNumColumns(numColumns);
                    mAdapter.setItemHeight(columnWidth);
                    if (BuildConfig.DEBUG) {
                        Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
                    }
                    if (Utils.hasJellyBean()) {
                        mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }
            }
        }
    });

    return v;
}

From source file:com.mklodoss.SexyGirl.displayingbitmaps.ui.ImageGridFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View v = inflater.inflate(R.layout.image_grid_fragment, container, false);
    mGridView = (GridView) v.findViewById(R.id.gridView);
    mGridView.setAdapter(mAdapter);//from  w ww  .j ava  2s .  c  o m
    mGridView.setBackgroundColor(Color.GRAY);
    mGridView.setOnItemClickListener(this);
    mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            // Pause fetcher to ensure smoother scrolling when flinging
            if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
                // Before Honeycomb pause image loading on scroll to help with performance
                if (!Utils.hasHoneycomb()) {
                    //mImageFetcher.setPauseWork(true);
                }
            } else {
                //mImageFetcher.setPauseWork(false);
            }
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
        }
    });

    // This listener is used to get the final width of the GridView and then calculate the
    // number of columns and the width of each column. The width of each column is variable
    // as the GridView has stretchMode=columnWidth. The column width is used to set the height
    // of each view so we get nice square thumbnails.
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @TargetApi(VERSION_CODES.JELLY_BEAN)
        @Override
        public void onGlobalLayout() {
            if (mAdapter.getNumColumns() == 0) {
                final int numColumns = (int) Math
                        .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
                if (numColumns > 0) {
                    final int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing;
                    mAdapter.setNumColumns(numColumns);
                    mAdapter.setItemHeight((int) (columnWidth * 1.46));
                    if (BuildConfig.DEBUG) {
                        Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
                    }
                    if (Utils.hasJellyBean()) {
                        mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }
            }
        }
    });

    return v;
}

From source file:org.tanrabad.team.ChatFragment.java

private void initUiComponents(View rootView) {
    mListView = (ListView) rootView.findViewById(R.id.list);
    turnOffListViewDecoration(mListView);
    mListView.setAdapter(mAdapter);//ww w . j ava 2s  .  co  m

    mBtnChannel = (ImageButton) rootView.findViewById(R.id.btn_channel);
    mBtnSend = (Button) rootView.findViewById(R.id.btn_send);
    mBtnUpload = (ImageButton) rootView.findViewById(R.id.btn_upload);
    mProgressBtnUpload = (ProgressBar) rootView.findViewById(R.id.progress_btn_upload);
    mEtxtMessage = (EditText) rootView.findViewById(R.id.etxt_message);

    mBtnSend.setEnabled(false);
    mBtnSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            send();
        }
    });

    mBtnChannel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mHandler != null) {
                mHandler.onChannelListClicked();
            }
        }
    });

    mBtnUpload.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_PICK_IMAGE);
        }
    });

    mEtxtMessage.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    send();
                }
                return true; // Do not hide keyboard.
            }
            return false;
        }
    });
    mEtxtMessage.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    mEtxtMessage.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            mBtnSend.setEnabled(s.length() > 0);
        }
    });
    mListView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            SoftKeyboard.hide(getActivity());
            return false;
        }
    });
    mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (scrollState == SCROLL_STATE_IDLE) {
                if (view.getFirstVisiblePosition() == 0 && view.getChildCount() > 0
                        && view.getChildAt(0).getTop() == 0) {
                    resultHandler = new MessageListQuery.MessageListQueryResult() {
                        @Override
                        public void onResult(List<MessageModel> messageModels) {
                            for (MessageModel model : messageModels) {
                                mAdapter.addMessageModel(model);
                            }

                            mAdapter.notifyDataSetChanged();
                            mListView.setSelection(messageModels.size());
                        }

                        @Override
                        public void onError(Exception e) {
                        }
                    };
                    SendBird.queryMessageList(SendBird.getChannelUrl()).prev(mAdapter.getMinMessageTimestamp(),
                            30, resultHandler);
                }
            }
        }

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

From source file:com.downrighttech.dmxdip.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    mThemeManager = new ThemeManager(VERSION.SDK_INT);

    super.onCreate(savedInstanceState);
    // load preferences
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // Load Theme from preferences
    mThemeManager.setTheme(Integer.parseInt(mSharedPreferences.getString("pref_theme", "0")));
    setTheme(mThemeManager.getTheme());//from  w ww  .  java2  s . c om

    setContentView(R.layout.activity_main);

    //Load Resources
    button_on = getResources().getDrawable(R.drawable.button_on);
    button_off = getResources().getDrawable(R.drawable.button_off);

    // Load Interface Items
    editText_Start = (EditText) findViewById(R.id.editText_Start);
    editText_Span = (EditText) findViewById(R.id.EditText_Span);
    clearButton = (ImageButton) findViewById(R.id.imageButton);
    toggleButton = new ToggleButton[9];
    toggleButton[0] = (ToggleButton) findViewById(R.id.ToggleButton01);
    toggleButton[1] = (ToggleButton) findViewById(R.id.ToggleButton02);
    toggleButton[2] = (ToggleButton) findViewById(R.id.ToggleButton03);
    toggleButton[3] = (ToggleButton) findViewById(R.id.ToggleButton04);
    toggleButton[4] = (ToggleButton) findViewById(R.id.ToggleButton05);
    toggleButton[5] = (ToggleButton) findViewById(R.id.ToggleButton06);
    toggleButton[6] = (ToggleButton) findViewById(R.id.ToggleButton07);
    toggleButton[7] = (ToggleButton) findViewById(R.id.ToggleButton08);
    toggleButton[8] = (ToggleButton) findViewById(R.id.ToggleButton09);
    listView = (ListView) findViewById(R.id.listView1);

    // Load ArrayList
    mAddressArray = new ArrayList<Integer>();
    mBitArray = new ArrayList<String>();
    mAddressArray.ensureCapacity(512);
    mBitArray.ensureCapacity(512);

    // Load Fonts
    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/RobotoSlab-Regular.ttf");

    // Setup Fonts
    editText_Start.setTypeface(tf);
    editText_Span.setTypeface(tf);
    for (int i = 0; i < ADDRESS_BUTTONS; i++)
        toggleButton[i].setTypeface(tf);

    //Setup setHapticFeedbackEnabled
    vib = (Vibrator) this.getSystemService(Service.VIBRATOR_SERVICE);

    // Events
    editText_Start.addTextChangedListener(this);
    editText_Span.addTextChangedListener(this);
    clearButton.setOnClickListener(this);

    // What's New Count
    int dialogCount = mSharedPreferences.getInt("pref_startup_dialog", 0);

    // If this is a new version, show the Dialog again
    String lastRunVersion = mSharedPreferences.getString("pref_version", "");
    String savedString = getString(R.string.version);
    if (!lastRunVersion.equals(savedString)) {
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putString("pref_version", getString(R.string.version));
        editor.commit();
        dialogCount = 0;
    }

    // If the dialog is due to be shown
    Log.v(TAG, "onCreate dialogCount:" + dialogCount);
    if (dialogCount == 0) {
        mDialogManager = new DialogManager(this);
        mDialogManager.setmIcon(R.drawable.ic_launcher);
        mDialogManager.setTitle(getText(R.string.app_name) + " - " + getText(R.string.version));
        mDialogManager.setMessage(R.string.dialog_about_message);
        mDialogManager.setPositiveButton(R.string.dialog_yes);
        mDialogManager.setNeutralButton(R.string.dialog_maybe);
        mDialogManager.show(getSupportFragmentManager(), "What's New");
    } else if (dialogCount > 0) {
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putInt("pref_startup_dialog", --dialogCount);
        editor.commit();
    }

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(listView.getWindowToken(), 0);
        }
    });

    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScroll(AbsListView absListView, int i, int i2, int i3) {
        }

        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {
            if (i != SCROLL_STATE_IDLE) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(listView.getWindowToken(), 0);
            }
        }
    });
}

From source file:io.jari.geenstijl.Blog.java

void initUI(final Artikel[] artikelen, final boolean doSwitchState) {
    final PullToRefreshLayout mPullToRefreshLayout = (PullToRefreshLayout) findViewById(R.id.ptr_layout);
    runOnUiThread(new Runnable() {
        public void run() {
            ListView siteSwitch = (ListView) findViewById(R.id.site_switcher);
            String domain = getSharedPreferences("geenstijl", 0).getString("gsdomain", "www.geenstijl.nl");
            if (domain.equals("www.geenstijl.nl")) {
                actionBar.setTitle("GeenStijl");
                siteSwitch.setItemChecked(0, true);
            } else {
                actionBar.setTitle("GeenStijl.TV");
                siteSwitch.setItemChecked(1, true);
            }/*w  w w. ja  v  a  2s  . com*/

            final ListView show = (ListView) findViewById(R.id.show);
            if (showTopPadding == 0)
                showTopPadding = show.getPaddingTop();
            show.setScrollingCacheEnabled(false);
            show.setAdapter(new ArtikelAdapter(Blog.this, 0, artikelen));

            //#HOLOYOLO
            if (Build.VERSION.SDK_INT >= 19) {
                SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
                show.setPadding(0, showTopPadding + config.getPixelInsetTop(true), 0, 0);
            }

            //hiding the actionbar when scrolling
            show.setOnScrollListener(new AbsListView.OnScrollListener() {
                int mLastFirstVisibleItem = 0;

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

                public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                        int totalItemCount) {
                    if (view.getId() == show.getId()) {
                        final int currentFirstVisibleItem = show.getFirstVisiblePosition();

                        if (currentFirstVisibleItem > mLastFirstVisibleItem && actionBar.isShowing()) {
                            enableImmersive(true, show);
                        } else if (currentFirstVisibleItem < mLastFirstVisibleItem && !actionBar.isShowing()) {
                            enableImmersive(false, show);
                        }

                        mLastFirstVisibleItem = currentFirstVisibleItem;
                    }
                }
            });

            //footer
            if (show.getAdapter().getClass() != HeaderViewListAdapter.class) { //check if footer is present, if not, add it
                View footer = getLayoutInflater().inflate(R.layout.meerrr, null);
                final View button = footer.findViewById(R.id.more);
                if (Build.VERSION.SDK_INT >= 19) {
                    ViewGroup.LayoutParams params = button.getLayoutParams();
                    SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
                    ((ViewGroup.MarginLayoutParams) params).bottomMargin = config.getPixelInsetBottom();
                }
                button.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        button.setEnabled(false);
                        mPullToRefreshLayout.setRefreshing(true);
                        enableImmersive(false, show);
                        forceNoImmersive = true;
                        new Thread(new Runnable() {
                            public void run() {
                                try {
                                    final Artikel[] artikelen2 = API.getArticles(true, true,
                                            getApplicationContext());
                                    runOnUiThread(new Runnable() {
                                        public void run() {
                                            ListView show = (ListView) findViewById(R.id.show);
                                            //java is such a beautiful language *cough*
                                            ArtikelAdapter artikelAdapter = (ArtikelAdapter) ((HeaderViewListAdapter) show
                                                    .getAdapter()).getWrappedAdapter();
                                            artikelAdapter.update(artikelen2);
                                            mPullToRefreshLayout.setRefreshComplete();
                                            button.setVisibility(View.GONE);
                                            forceNoImmersive = false;
                                        }
                                    });
                                } catch (final Exception e) {
                                    e.printStackTrace();
                                    runOnUiThread(new Runnable() {
                                        public void run() {
                                            button.setEnabled(true);
                                            mPullToRefreshLayout.setRefreshComplete();
                                            forceNoImmersive = false;
                                            Crouton.makeText(Blog.this,
                                                    e.getLocalizedMessage() == null ? "Onbekende fout"
                                                            : e.getLocalizedMessage(),
                                                    Style.ALERT).show();
                                        }
                                    });
                                }
                            }
                        }).start();

                    }
                });
                show.addFooterView(footer);
            }

            //grreat success!
            if (doSwitchState)
                switchState(STATE_SHOW);
            else
                mPullToRefreshLayout.setRefreshComplete();
        }
    });
}

From source file:fr.paug.droidcon.ui.BaseActivity.java

protected void enableActionBarAutoHide(final ListView listView) {
    initActionBarAutoHide();//  w  w w. j  ava2  s . c o  m
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        final static int ITEMS_THRESHOLD = 3;
        int lastFvi = 0;

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

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            onMainContentScrolled(firstVisibleItem <= ITEMS_THRESHOLD ? 0 : Integer.MAX_VALUE,
                    lastFvi - firstVisibleItem > 0 ? Integer.MIN_VALUE
                            : lastFvi == firstVisibleItem ? 0 : Integer.MAX_VALUE);
            lastFvi = firstVisibleItem;
        }
    });
}