當前位置: 首頁>>代碼示例>>Java>>正文


Java LoaderManager.LoaderCallbacks方法代碼示例

本文整理匯總了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);
}
 
開發者ID:universum-studios,項目名稱:android_fragments,代碼行數:19,代碼來源:BaseFragmentTest.java

示例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);
}
 
開發者ID:rmceoin,項目名稱:cominghome,代碼行數:17,代碼來源:StructuresListFragment.java

示例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);
}
 
開發者ID:rmceoin,項目名稱:cominghome,代碼行數:17,代碼來源:HistoryListFragment.java

示例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);
}
 
開發者ID:universum-studios,項目名稱:android_fragments,代碼行數:16,代碼來源:BaseFragmentTest.java

示例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);
}
 
開發者ID:universum-studios,項目名稱:android_fragments,代碼行數:16,代碼來源:BaseFragmentTest.java

示例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);
}
 
開發者ID:universum-studios,項目名稱:android_fragments,代碼行數:16,代碼來源:BaseFragmentTest.java

示例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()));
}
 
開發者ID:universum-studios,項目名稱:android_fragments,代碼行數:15,代碼來源:BaseFragmentTest.java

示例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);
}
 
開發者ID:plusCubed,項目名稱:china-missed-calls,代碼行數:13,代碼來源:MainFragment.java

示例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);
}
 
開發者ID:rmceoin,項目名稱:cidrcalculator,代碼行數:29,代碼來源:HistoryList.java

示例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);
    }

}
 
開發者ID:AAverin,項目名稱:android-skeleton-project,代碼行數:10,代碼來源:Utils.java

示例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);
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:49,代碼來源:HomeFragment.java

示例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);

}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:49,代碼來源:ConnectionsFragment.java

示例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);
}
 
開發者ID:universum-studios,項目名稱:android_fragments,代碼行數:21,代碼來源:BaseFragment.java

示例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);
}
 
開發者ID:universum-studios,項目名稱:android_fragments,代碼行數:18,代碼來源:BaseFragment.java

示例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);
}
 
開發者ID:universum-studios,項目名稱:android_fragments,代碼行數:18,代碼來源:BaseFragment.java


注:本文中的android.app.LoaderManager.LoaderCallbacks方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。