本文整理汇总了Java中android.app.LoaderManager.LoaderCallbacks方法的典型用法代码示例。如果您正苦于以下问题:Java LoaderManager.LoaderCallbacks方法的具体用法?Java LoaderManager.LoaderCallbacks怎么用?Java LoaderManager.LoaderCallbacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.LoaderManager
的用法示例。
在下文中一共展示了LoaderManager.LoaderCallbacks方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStartLoaderThatIsAlreadyInitialized
import android.app.LoaderManager; //导入方法依赖的package包/类
@Test
public void testStartLoaderThatIsAlreadyInitialized() {
final Activity activity = Robolectric.buildActivity(TestActivity.class).create().start().resume().get();
final FragmentManager fragmentManager = activity.getFragmentManager();
final BaseFragment fragment = new TestFragment();
fragmentManager.beginTransaction().add(fragment, null).commit();
fragmentManager.executePendingTransactions();
final LoaderManager loaderManager = fragment.getLoaderManager();
final LoaderManager.LoaderCallbacks mockLoaderCallbacks = mock(LoaderManager.LoaderCallbacks.class);
final Loader firstLoader = new CursorLoader(mApplication, Uri.EMPTY, null, null, null, null);
final Loader secondLoader = new CursorLoader(mApplication, Uri.EMPTY, null, null, null, null);
when(mockLoaderCallbacks.onCreateLoader(1, null)).thenReturn(firstLoader);
loaderManager.initLoader(1, null, mockLoaderCallbacks);
when(mockLoaderCallbacks.onCreateLoader(1, null)).thenReturn(secondLoader);
assertThat(fragment.startLoader(1, null, mockLoaderCallbacks), is(secondLoader));
assertThat(loaderManager.getLoader(1), is(secondLoader));
loaderManager.destroyLoader(1);
}
示例2: onCreate
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new SimpleCursorAdapter(getActivity(),
R.layout.structureslist_item, null,
new String[]{StructuresValues.Structures.NAME, StructuresValues.Structures.AWAY},
new int[]{R.id.structure_name, R.id.structure_away}, 0);
setListAdapter(mAdapter);
LoaderManager.LoaderCallbacks<Cursor> mCallbacks = this;
LoaderManager lm = getLoaderManager();
lm.initLoader(LOADER_ID, null, mCallbacks);
}
示例3: onCreate
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new SimpleCursorAdapter(getActivity(),
R.layout.historylist_item, null,
new String[]{HistoryValues.History.ENTRY, HistoryValues.History.CREATED_DATE_STR},
new int[]{R.id.history_entry, R.id.history_date}, 0);
setListAdapter(mAdapter);
LoaderManager.LoaderCallbacks<Cursor> mCallbacks = this;
LoaderManager lm = getLoaderManager();
lm.initLoader(LOADER_ID, null, mCallbacks);
}
示例4: testStartLoader
import android.app.LoaderManager; //导入方法依赖的package包/类
@Test
public void testStartLoader() {
final Activity activity = Robolectric.buildActivity(TestActivity.class).create().start().resume().get();
final FragmentManager fragmentManager = activity.getFragmentManager();
final BaseFragment fragment = new TestFragment();
fragmentManager.beginTransaction().add(fragment, null).commit();
fragmentManager.executePendingTransactions();
final LoaderManager loaderManager = fragment.getLoaderManager();
final LoaderManager.LoaderCallbacks mockLoaderCallbacks = mock(LoaderManager.LoaderCallbacks.class);
final Loader<Cursor> loader = new CursorLoader(mApplication, Uri.EMPTY, null, null, null, null);
when(mockLoaderCallbacks.onCreateLoader(1, null)).thenReturn(loader);
assertThat(fragment.startLoader(1, null, mockLoaderCallbacks), Is.<Loader>is(loader));
assertThat(loaderManager.getLoader(1), is(not(nullValue())));
loaderManager.destroyLoader(1);
}
示例5: testInitLoader
import android.app.LoaderManager; //导入方法依赖的package包/类
@Test
public void testInitLoader() {
final Activity activity = Robolectric.buildActivity(TestActivity.class).create().start().resume().get();
final FragmentManager fragmentManager = activity.getFragmentManager();
final BaseFragment fragment = new TestFragment();
fragmentManager.beginTransaction().add(fragment, null).commit();
fragmentManager.executePendingTransactions();
final LoaderManager loaderManager = fragment.getLoaderManager();
final LoaderManager.LoaderCallbacks mockLoaderCallbacks = mock(LoaderManager.LoaderCallbacks.class);
final Loader loader = new CursorLoader(mApplication, Uri.EMPTY, null, null, null, null);
when(mockLoaderCallbacks.onCreateLoader(1, null)).thenReturn(loader);
assertThat(fragment.initLoader(1, null, mockLoaderCallbacks), is(loader));
assertThat(loaderManager.getLoader(1), is(loader));
loaderManager.destroyLoader(1);
}
示例6: testRestartLoader
import android.app.LoaderManager; //导入方法依赖的package包/类
@Test
public void testRestartLoader() {
final Activity activity = Robolectric.buildActivity(TestActivity.class).create().start().resume().get();
final FragmentManager fragmentManager = activity.getFragmentManager();
final BaseFragment fragment = new TestFragment();
fragmentManager.beginTransaction().add(fragment, null).commit();
fragmentManager.executePendingTransactions();
final LoaderManager loaderManager = fragment.getLoaderManager();
final LoaderManager.LoaderCallbacks mockLoaderCallbacks = mock(LoaderManager.LoaderCallbacks.class);
final Loader loader = new CursorLoader(mApplication, Uri.EMPTY, null, null, null, null);
when(mockLoaderCallbacks.onCreateLoader(1, null)).thenReturn(loader);
assertThat(fragment.restartLoader(1, null, mockLoaderCallbacks), is(loader));
assertThat(loaderManager.getLoader(1), is(loader));
loaderManager.destroyLoader(1);
}
示例7: testDestroyLoader
import android.app.LoaderManager; //导入方法依赖的package包/类
@Test
public void testDestroyLoader() {
final Activity activity = Robolectric.buildActivity(TestActivity.class).create().start().resume().get();
final FragmentManager fragmentManager = activity.getFragmentManager();
final BaseFragment fragment = new TestFragment();
fragmentManager.beginTransaction().add(fragment, null).commit();
fragmentManager.executePendingTransactions();
final LoaderManager loaderManager = fragment.getLoaderManager();
final LoaderManager.LoaderCallbacks mockLoaderCallbacks = mock(LoaderManager.LoaderCallbacks.class);
when(mockLoaderCallbacks.onCreateLoader(1, null)).thenReturn(new CursorLoader(mApplication, Uri.EMPTY, null, null, null, null));
loaderManager.initLoader(1, null, mockLoaderCallbacks);
fragment.destroyLoader(1);
assertThat(loaderManager.getLoader(1), is(nullValue()));
}
示例8: onCreate
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mMissedCalls = new ArrayList<>();
mContactQueryHandler = new ContactQueryHandler(getActivity().getContentResolver(), this);
final LoaderManager.LoaderCallbacks<Cursor> loaderCallbacks = new SmsLoaderCallbacks();
getLoaderManager().initLoader(Utils.CHINA_UNICOM, null, loaderCallbacks);
setListAdapter(new ContactsMissedCallAdapter());
//TODO: get rid of this atrocity
setRetainInstance(true);
}
示例9: onCreate
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);
// If no data was given in the intent (because we were started
// as a MAIN activity), then use our default content provider.
Intent intent = getIntent();
if (intent.getData() == null) {
intent.setData(History.CONTENT_URI);
}
// Inform the list we provide context menus for items
getListView().setOnCreateContextMenuListener(this);
mAdapter = new SimpleCursorAdapter(this,
R.layout.historylist_item, null,
new String[]{History.IP, History.BITS},
new int[]{R.id.history_ip, R.id.history_bits}, 0);
setListAdapter(mAdapter);
LoaderManager.LoaderCallbacks<Cursor> mCallbacks = this;
LoaderManager lm = getLoaderManager();
lm.initLoader(LOADER_ID, null, mCallbacks);
}
示例10: initOrRestartLoader
import android.app.LoaderManager; //导入方法依赖的package包/类
public static void initOrRestartLoader(LoaderManager loaderManager, int id, Bundle bundle, LoaderManager.LoaderCallbacks callbacks) {
Loader loader = loaderManager.getLoader(id);
if (loader == null) {
loaderManager.initLoader(id, bundle, callbacks);
} else {
loaderManager.restartLoader(id, bundle, callbacks);
}
}
示例11: showRecents
import android.app.LoaderManager; //导入方法依赖的package包/类
private void showRecents() {
final RootInfo root = roots.getRecentsRoot();
recents.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openRoot(root);
}
});
mRecentsAdapter = new RecentsAdapter(getActivity(), null);
mRecentsAdapter.setOnItemClickListener(new RecentsAdapter.OnItemClickListener() {
@Override
public void onItemClick(RecentsAdapter.ViewHolder item, int position) {
openDocument(item.mDocumentInfo);
}
});
mRecentsRecycler.setAdapter(mRecentsAdapter);
LinearSnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(mRecentsRecycler);
final BaseActivity.State state = getDisplayState(this);
mCallbacks = new LoaderManager.LoaderCallbacks<DirectoryResult>() {
@Override
public Loader<DirectoryResult> onCreateLoader(int id, Bundle args) {
final RootsCache roots = DocumentsApplication.getRootsCache(getActivity());
return new RecentLoader(getActivity(), roots, state);
}
@Override
public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
if (!isAdded())
return;
if(null == result.cursor || (null != result.cursor && result.cursor.getCount() == 0)) {
recents_container.setVisibility(View.GONE);
} else {
//recents_container.setVisibility(View.VISIBLE);
mRecentsAdapter.swapCursor(new LimitCursorWrapper(result.cursor, MAX_RECENT_COUNT));
}
}
@Override
public void onLoaderReset(Loader<DirectoryResult> loader) {
mRecentsAdapter.swapCursor(null);
}
};
getLoaderManager().restartLoader(mLoaderId, null, mCallbacks);
}
示例12: onActivityCreated
import android.app.LoaderManager; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Context context = getActivity();
mAdapter = new ConnectionsAdapter(this);
mCallbacks = new LoaderManager.LoaderCallbacks<Cursor>() {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Uri contentsUri = ExplorerProvider.buildConnection();
String selection = null;
String[] selectionArgs = null;
if(!Utils.hasWiFi(getActivity())){
selection = ExplorerProvider.ConnectionColumns.TYPE + "!=? " ;
selectionArgs = new String[]{SERVER};
}
return new CursorLoader(context, contentsUri, null, selection, selectionArgs, null);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor result) {
if (!isAdded())
return;
mAdapter.swapResult(result);
mEmptyView.setVisibility(mAdapter.isEmpty() ? View.VISIBLE : View.GONE);
if (isResumed()) {
setListShown(true);
} else {
setListShownNoAnimation(true);
}
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
mAdapter.swapResult(null);
}
};
setListAdapter(mAdapter);
setListShown(false);
// Kick off loader at least once
getLoaderManager().restartLoader(mLoaderId, null, mCallbacks);
}
示例13: startLoader
import android.app.LoaderManager; //导入方法依赖的package包/类
/**
* Starts a loader with the specified <var>id</var>. If there was already started loader with the
* same id before, such a loader will be <b>re-started</b>, otherwise new loader will be <b>initialized</b>.
*
* @param id Id of the desired loader to start.
* @param params Params for loader.
* @param callbacks Callbacks for loader.
* @return Initialized or re-started loader instance or {@code null} if the specified <var>callbacks</var>
* do not create loader for the specified <var>id</var>.
* @see #initLoader(int, Bundle, LoaderManager.LoaderCallbacks)
* @see #restartLoader(int, Bundle, LoaderManager.LoaderCallbacks)
* @see #destroyLoader(int)
*/
@Nullable
public <D> Loader<D> startLoader(@IntRange(from = 0) final int id, @Nullable final Bundle params, @NonNull final LoaderManager.LoaderCallbacks<D> callbacks) {
final LoaderManager manager = getLoaderManager();
return manager.getLoader(id) == null ?
initLoader(id, params, callbacks) :
restartLoader(id, params, callbacks);
}
示例14: initLoader
import android.app.LoaderManager; //导入方法依赖的package包/类
/**
* Initializes a loader with the specified <var>id</var> for the given <var>callbacks</var>.
*
* @param id Id of the desired loader to init.
* @param params Params for loader.
* @param callbacks Callbacks for loader.
* @return Initialized loader instance or {@code null} if the specified <var>callbacks</var> do
* not create loader for the specified <var>id</var>.
* @see #startLoader(int, Bundle, LoaderManager.LoaderCallbacks)
* @see #restartLoader(int, Bundle, LoaderManager.LoaderCallbacks)
* @see #destroyLoader(int)
* @see LoaderManager#initLoader(int, Bundle, LoaderManager.LoaderCallbacks)
*/
@Nullable
public <D> Loader<D> initLoader(@IntRange(from = 0) final int id, @Nullable final Bundle params, @NonNull final LoaderManager.LoaderCallbacks<D> callbacks) {
return getLoaderManager().initLoader(id, params, callbacks);
}
示例15: restartLoader
import android.app.LoaderManager; //导入方法依赖的package包/类
/**
* Re-starts a loader with the specified <var>id</var> for the given <var>callbacks</var>.
*
* @param id Id of the desired loader to re-start.
* @param params Params for loader.
* @param callbacks Callbacks for loader.
* @return Re-started loader instance or {@code null} if the specified <var>callbacks</var> do
* not create loader for the specified <var>id</var>.
* @see #startLoader(int, Bundle, LoaderManager.LoaderCallbacks)
* @see #initLoader(int, Bundle, LoaderManager.LoaderCallbacks)
* @see #destroyLoader(int)
* @see LoaderManager#restartLoader(int, Bundle, LoaderManager.LoaderCallbacks)
*/
@Nullable
public <D> Loader<D> restartLoader(@IntRange(from = 0) final int id, @Nullable final Bundle params, @NonNull final LoaderManager.LoaderCallbacks<D> callbacks) {
return getLoaderManager().restartLoader(id, params, callbacks);
}