Search in sources :

Example 1 with SoundPullEventListener

use of com.handmark.pulltorefresh.library.extras.SoundPullEventListener in project Android-PullToRefresh by chrisbanes.

the class PullToRefreshListActivity method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ptr_list);
    mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);
    // Set a listener to be invoked when the list should be refreshed.
    mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {

        @Override
        public void onRefresh(PullToRefreshBase<ListView> refreshView) {
            String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
            // Update the LastUpdatedLabel
            refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
            // Do work to refresh the list here.
            new GetDataTask().execute();
        }
    });
    // Add an end-of-list listener
    mPullRefreshListView.setOnLastItemVisibleListener(new OnLastItemVisibleListener() {

        @Override
        public void onLastItemVisible() {
            Toast.makeText(PullToRefreshListActivity.this, "End of List!", Toast.LENGTH_SHORT).show();
        }
    });
    ListView actualListView = mPullRefreshListView.getRefreshableView();
    // Need to use the Actual ListView when registering for Context Menu
    registerForContextMenu(actualListView);
    mListItems = new LinkedList<String>();
    mListItems.addAll(Arrays.asList(mStrings));
    mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems);
    /**
		 * Add Sound Event Listener
		 */
    SoundPullEventListener<ListView> soundListener = new SoundPullEventListener<ListView>(this);
    soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event);
    soundListener.addSoundEvent(State.RESET, R.raw.reset_sound);
    soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound);
    mPullRefreshListView.setOnPullEventListener(soundListener);
    // You can also just use setListAdapter(mAdapter) or
    // mPullRefreshListView.setAdapter(mAdapter)
    actualListView.setAdapter(mAdapter);
}
Also used : PullToRefreshListView(com.handmark.pulltorefresh.library.PullToRefreshListView) ListView(android.widget.ListView) SoundPullEventListener(com.handmark.pulltorefresh.library.extras.SoundPullEventListener) OnLastItemVisibleListener(com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener)

Aggregations

ListView (android.widget.ListView)1 OnLastItemVisibleListener (com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener)1 PullToRefreshListView (com.handmark.pulltorefresh.library.PullToRefreshListView)1 SoundPullEventListener (com.handmark.pulltorefresh.library.extras.SoundPullEventListener)1