Example usage for android.support.v4.content Loader reset

List of usage examples for android.support.v4.content Loader reset

Introduction

In this page you can find the example usage for android.support.v4.content Loader reset.

Prototype

public void reset() 

Source Link

Document

Resets the state of the Loader.

Usage

From source file:com.rks.musicx.ui.fragments.PlayListPicker.java

@Override
public void onLoaderReset(Loader<List<Playlist>> loader) {
    loader.reset();
    playlistListAdapter.notifyDataSetChanged();

}

From source file:com.rks.musicx.ui.fragments.PlaylistListFragment.java

@Override
public void onLoaderReset(Loader<List<Playlist>> loader) {
    loader.reset();
    playlistAdapter.notifyDataSetChanged();

}

From source file:org.akvo.flow.ui.fragment.SurveyListFragment.java

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    loader.reset();
}

From source file:com.twofortyfouram.locale.sdk.host.test.Junit4SupportLoaderTestCase.java

/**
 * Runs a Loader synchronously and returns the result of the load. The loader will
 * be started, stopped, and destroyed by this method so it cannot be reused.
 *
 * @param loader The loader to run synchronously
 * @return The result from the loader/*from  w w  w  .  j a  va2  s.  co  m*/
 */
public <T> T getLoaderResultSynchronously(final Loader<T> loader) {
    // The test thread blocks on this queue until the loader puts it's result in
    final ArrayBlockingQueue<T> queue = new ArrayBlockingQueue<T>(1);

    // This callback runs on the "main" thread and unblocks the test thread
    // when it puts the result into the blocking queue
    final Loader.OnLoadCompleteListener<T> listener = new Loader.OnLoadCompleteListener<T>() {
        @Override
        public void onLoadComplete(Loader<T> completedLoader, T data) {
            // Shut the loader down
            completedLoader.unregisterListener(this);
            completedLoader.stopLoading();
            completedLoader.reset();

            // Store the result, unblocking the test thread
            queue.add(data);
        }
    };

    // This handler runs on the "main" thread of the process since AsyncTask
    // is documented as needing to run on the main thread and many Loaders use
    // AsyncTask
    final Handler mainThreadHandler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            loader.registerListener(0, listener);
            loader.startLoading();
        }
    };

    // Ask the main thread to start the loading process
    mainThreadHandler.sendEmptyMessage(0);

    // Block on the queue waiting for the result of the load to be inserted
    T result;
    while (true) {
        try {
            result = queue.take();
            break;
        } catch (InterruptedException e) {
            throw new RuntimeException("waiting thread interrupted", e);
        }
    }

    return result;
}

From source file:com.scvngr.levelup.core.test.SupportLoaderTestCase.java

/**
 * Runs a Loader synchronously and returns the result of the load. The loader will be started,
 * stopped, and destroyed by this method so it cannot be reused.
 *
 * @param loader The loader to run synchronously
 * @return The result from the loader/*from   w w w . j av a2s.com*/
 */
public <T> T getLoaderResultSynchronously(final Loader<T> loader) {
    // The test thread blocks on this queue until the loader puts its result in
    final ArrayBlockingQueue<T> queue = new ArrayBlockingQueue<T>(1);
    final CountDownLatch latch = new CountDownLatch(1);

    // This callback runs on the "main" thread and unblocks the test thread
    // when it puts the result into the blocking queue
    final OnLoadCompleteListener<T> listener = new OnLoadCompleteListener<T>() {
        @Override
        public void onLoadComplete(final Loader<T> completedLoader, final T data) {
            // Shut the loader down
            completedLoader.unregisterListener(this);
            completedLoader.stopLoading();
            completedLoader.reset();

            // Store the result, unblocking the test thread
            if (null != data) {
                queue.add(data);
            }
            latch.countDown();
        }
    };

    // This handler runs on the "main" thread of the process since AsyncTask
    // is documented as needing to run on the main thread and many Loaders use
    // AsyncTask
    final Handler mainThreadHandler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(final Message msg) {
            loader.registerListener(0, listener);
            loader.startLoading();
        }
    };

    // Ask the main thread to start the loading process
    mainThreadHandler.sendEmptyMessage(0);

    // Block on the queue waiting for the result of the load to be inserted
    T result;
    while (true) {
        try {
            latch.await();
            result = queue.peek();
            break;
        } catch (final InterruptedException e) {
            throw new RuntimeException("waiting thread interrupted", e);
        }
    }

    return result;
}

From source file:org.pixmob.droidlink.ui.EventsFragment.java

@Override
public void onDetach() {
    final Loader<Cursor> loader = getLoaderManager().getLoader(0);
    if (loader != null) {
        loader.reset();
    }/*from w  ww.j a  v a 2s .c o  m*/
    super.onDetach();
}

From source file:org.mozilla.gecko.background.fxa.TestAccountLoader.java

/**
 * Runs a Loader synchronously and returns the result of the load. The loader will
 * be started, stopped, and destroyed by this method so it cannot be reused.
 *
 * @param loader The loader to run synchronously
 * @return The result from the loader//from   w  ww  .  j  a v  a2  s.co m
 */
public <T> T getLoaderResultSynchronously(final Loader<T> loader) {
    // The test thread blocks on this queue until the loader puts it's result in
    final ArrayBlockingQueue<AtomicReference<T>> queue = new ArrayBlockingQueue<AtomicReference<T>>(1);

    // This callback runs on the "main" thread and unblocks the test thread
    // when it puts the result into the blocking queue
    final OnLoadCompleteListener<T> listener = new OnLoadCompleteListener<T>() {
        @Override
        public void onLoadComplete(Loader<T> completedLoader, T data) {
            // Shut the loader down
            completedLoader.unregisterListener(this);
            completedLoader.stopLoading();
            completedLoader.reset();
            // Store the result, unblocking the test thread
            queue.add(new AtomicReference<T>(data));
        }
    };

    // This handler runs on the "main" thread of the process since AsyncTask
    // is documented as needing to run on the main thread and many Loaders use
    // AsyncTask
    final Handler mainThreadHandler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            loader.registerListener(0, listener);
            loader.startLoading();
        }
    };

    // Ask the main thread to start the loading process
    mainThreadHandler.sendEmptyMessage(0);

    // Block on the queue waiting for the result of the load to be inserted
    T result;
    while (true) {
        try {
            result = queue.take().get();
            break;
        } catch (InterruptedException e) {
            throw new RuntimeException("waiting thread interrupted", e);
        }
    }
    return result;
}