List of usage examples for android.support.v4.app FragmentActivity getSupportLoaderManager
public LoaderManager getSupportLoaderManager()
From source file:co.nerdart.ourss.adapter.CursorLoaderExpandableListAdapter.java
/** * Constructor.//from w w w .j a v a2s. co m * * @param collapsedGroupLayout resource identifier of a layout file that defines the views for collapsed groups. * @param expandedGroupLayout resource identifier of a layout file that defines the views for expanded groups. * @param childLayout resource identifier of a layout file that defines the views for all children but the last.. */ public CursorLoaderExpandableListAdapter(FragmentActivity activity, Uri groupUri, int collapsedGroupLayout, int expandedGroupLayout, int childLayout) { mActivity = activity; mLoaderMgr = activity.getSupportLoaderManager(); mGroupUri = groupUri; mCollapsedGroupLayout = collapsedGroupLayout; mExpandedGroupLayout = expandedGroupLayout; mChildLayout = childLayout; mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mLoaderMgr.restartLoader(0, null, mGroupLoaderCallback); }
From source file:com.github.jobs.ui.fragment.JobListFragment.java
private void queryList() { try {/*from w ww.ja v a 2 s . co m*/ FragmentActivity activity = getActivity(); if (activity == null || !isAdded()) { return; } LoaderManager loaderManager = activity.getSupportLoaderManager(); Loader<Object> loader = loaderManager.getLoader(mCurrentSearch.hashCode()); if (loader == null) { loaderManager.initLoader(mCurrentSearch.hashCode(), null, this); } else { loaderManager.restartLoader(mCurrentSearch.hashCode(), null, this); } } catch (IllegalStateException e) { // happens when activity is closed. We can't use isResumed since it will be false when the activity is // not being shown, thus it will cause problems if user loads another screen while this is still loading } }
From source file:de.grobox.liberario.ui.LocationView.java
public void initialize(FragmentActivity a) { loaderManager = a.getSupportLoaderManager(); loaderManager.initLoader(getId(), null, this); activity = a;//from ww w. j a v a 2 s. c o m }
From source file:org.dmfs.webcal.fragments.GenericListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View result = inflater.inflate(R.layout.generic_list, container, false); mListView = (ListView) result.findViewById(android.R.id.list); mMessageView = (TextView) result.findViewById(android.R.id.message); mAdapter = new MixedNavigationAdapter(getActivity(), null, 0, mShowStars); mAdapter.setShowMissingIcons(true);//from ww w . j a va 2s .co m mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(this); FragmentActivity activity = getActivity(); /* * FIXME: Using a random loader id is a hack. We just need to ensure that the loader id doesn't collide with another load id that might be visible. */ if (getParentFragment() != null) { getParentFragment().getLoaderManager().initLoader((int) (Math.random() * Integer.MAX_VALUE), null, this); } else { activity.getSupportLoaderManager().initLoader((int) (Math.random() * Integer.MAX_VALUE), null, this); } return result; }
From source file:com.gh.bmd.jrt.android.v4.core.LoaderInvocation.java
@Override @SuppressWarnings("unchecked") @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "class comparison with == is done") public void onCall(@Nonnull final List<? extends INPUT> inputs, @Nonnull final ResultChannel<OUTPUT> result) { final Logger logger = mLogger; final Object context = mContext.get(); if (context == null) { logger.dbg("avoiding running invocation since context is null"); return;// ww w . j a va 2 s. c o m } final Context loaderContext; final LoaderManager loaderManager; if (context instanceof FragmentActivity) { final FragmentActivity activity = (FragmentActivity) context; loaderContext = activity.getApplicationContext(); loaderManager = activity.getSupportLoaderManager(); logger.dbg("running invocation bound to activity: %s", activity); } else if (context instanceof Fragment) { final Fragment fragment = (Fragment) context; loaderContext = fragment.getActivity().getApplicationContext(); loaderManager = fragment.getLoaderManager(); logger.dbg("running invocation bound to fragment: %s", fragment); } else { throw new IllegalArgumentException("invalid context type: " + context.getClass().getCanonicalName()); } int loaderId = mLoaderId; if (loaderId == ContextRoutineBuilder.AUTO) { loaderId = mConstructor.getDeclaringClass().hashCode(); for (final Object arg : mArgs) { loaderId = 31 * loaderId + recursiveHashCode(arg); } loaderId = 31 * loaderId + inputs.hashCode(); logger.dbg("generating invocation ID: %d", loaderId); } final Loader<InvocationResult<OUTPUT>> loader = loaderManager.getLoader(loaderId); final boolean isClash = isClash(loader, loaderId, inputs); final WeakIdentityHashMap<Object, SparseArray<WeakReference<RoutineLoaderCallbacks<?>>>> callbackMap = sCallbackMap; SparseArray<WeakReference<RoutineLoaderCallbacks<?>>> callbackArray = callbackMap.get(context); if (callbackArray == null) { callbackArray = new SparseArray<WeakReference<RoutineLoaderCallbacks<?>>>(); callbackMap.put(context, callbackArray); } final WeakReference<RoutineLoaderCallbacks<?>> callbackReference = callbackArray.get(loaderId); RoutineLoaderCallbacks<OUTPUT> callbacks = (callbackReference != null) ? (RoutineLoaderCallbacks<OUTPUT>) callbackReference.get() : null; if ((callbacks == null) || (loader == null) || isClash) { final RoutineLoader<INPUT, OUTPUT> routineLoader; if (!isClash && (loader != null) && (loader.getClass() == RoutineLoader.class)) { routineLoader = (RoutineLoader<INPUT, OUTPUT>) loader; } else { routineLoader = null; } final RoutineLoaderCallbacks<OUTPUT> newCallbacks = createCallbacks(loaderContext, loaderManager, routineLoader, inputs, loaderId); if (callbacks != null) { logger.dbg("resetting existing callbacks [%d]", loaderId); callbacks.reset(); } callbackArray.put(loaderId, new WeakReference<RoutineLoaderCallbacks<?>>(newCallbacks)); callbacks = newCallbacks; } logger.dbg("setting result cache type [%d]: %s", loaderId, mCacheStrategyType); callbacks.setCacheStrategy(mCacheStrategyType); final OutputChannel<OUTPUT> outputChannel = callbacks.newChannel(); if (isClash) { logger.dbg("restarting loader [%d]", loaderId); loaderManager.restartLoader(loaderId, Bundle.EMPTY, callbacks); } else { logger.dbg("initializing loader [%d]", loaderId); loaderManager.initLoader(loaderId, Bundle.EMPTY, callbacks); } result.pass(outputChannel); }