List of usage examples for android.support.v4.app LoaderManager initLoader
public abstract <D> Loader<D> initLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> callback);
From source file:org.dmfs.webcal.fragments.CalendarItemFragment.java
public void loadCalendar() { // the the adapter has no cursor yet LoaderManager loaderManager = getLoaderManager(); if (loaderManager != null) { if (loaderManager.getLoader(LOADER_PREVIEW) == null) { Loader<Cursor> initLoader = loaderManager.initLoader(LOADER_PREVIEW, null, CalendarItemFragment.this); if (initLoader != null) { initLoader.forceLoad();/*ww w. j av a 2 s .c om*/ } else { Log.e(TAG, "Newly created Loader is null"); } } else { loaderManager.restartLoader(LOADER_PREVIEW, null, CalendarItemFragment.this); } } else { Log.e(TAG, "Loader Manager is null"); } }
From source file:de.vanita5.twittnuker.fragment.support.DirectMessagesConversationFragment.java
public void showConversation(final long accountId, final long recipientId) { mAccountId = accountId;// w w w . ja v a 2 s . co m mRecipientId = recipientId; final LoaderManager lm = getLoaderManager(); final Bundle args = new Bundle(); args.putLong(EXTRA_ACCOUNT_ID, accountId); args.putLong(EXTRA_RECIPIENT_ID, recipientId); if (mLoaderInitialized) { lm.restartLoader(0, args, this); } else { mLoaderInitialized = true; lm.initLoader(0, args, this); } }
From source file:com.wit.android.support.fragment.BaseFragment.java
/** * 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>. * <p>/*from w w w . jav a 2s .c o m*/ * See {@link android.support.v4.app.LoaderManager#restartLoader(int, Bundle, android.support.v4.app.LoaderManager.LoaderCallbacks)} and * {@link android.support.v4.app.LoaderManager#initLoader(int, Bundle, android.support.v4.app.LoaderManager.LoaderCallbacks)} for more info. * * @param id Id of the desired loader to start. * @param params Params for loader. * @param callbacks Callbacks for loader. * @return {@code True} if loader with the specified id was <b>initialized</b> or <b>re-started</b>, * {@code false} if the current activity is already invalid or {@link android.support.v4.app.LoaderManager} is not available. */ protected boolean startLoader(int id, @Nullable Bundle params, @NonNull LoaderManager.LoaderCallbacks callbacks) { if (mActivity != null) { final LoaderManager loaderManager = ((FragmentActivity) mActivity).getSupportLoaderManager(); if (loaderManager != null) { if (loaderManager.getLoader(id) != null) { loaderManager.restartLoader(id, params, callbacks); } else { loaderManager.initLoader(id, params, callbacks); } return true; } } return false; }
From source file:org.bwgz.quotation.activity.QuotationActivity.java
private <T> void initLoader(LoaderManager loaderManager, int loaderId, Bundle args, LoaderCallbacks<T> callbacks) { final Loader<T> loader = loaderManager.getLoader(loaderId); if (loader == null || loader.isReset()) { Log.d(TAG, String.format("initLoader - initLoader: %d", loaderId)); loaderManager.initLoader(loaderId, args, callbacks); } else {//from ww w .j av a 2 s . c o m Log.d(TAG, String.format("initLoader - restartLoader: %d", loaderId)); loaderManager.restartLoader(loaderId, args, callbacks); } }
From source file:de.ub0r.android.callmeter.ui.PlansFragment.java
/** * Re-query database.//from w ww . j a v a2 s .co m * * @param forceUpdate force update */ public void requery(final boolean forceUpdate) { Log.d(TAG, "requery(", forceUpdate, ")"); if (!this.ignoreQuery) { LoaderManager lm = getLoaderManager(); if (forceUpdate && lm.getLoader(uid) != null) { lm.restartLoader(uid, null, this); } else { lm.initLoader(uid, null, this); } } else { Log.d(TAG, "requery(", forceUpdate, "): ignore"); } }
From source file:com.joulespersecond.seattlebusbot.ArrivalsListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Set and add the view that is shown if no arrival information is returned by the REST API getListView().setEmptyView(mEmptyList); ((ViewGroup) getListView().getParent()).addView(mEmptyList); // We have a menu item to show in action bar. setHasOptionsMenu(true);//from w w w .j a v a2 s . c o m mAlertList = new AlertList(getActivity()); mAlertList.initView(getView().findViewById(R.id.arrivals_alert_list)); mHeader = new ArrivalsListHeader(getActivity(), this); View header = getView().findViewById(R.id.arrivals_list_header); mHeader.initView(header); mHeader.refresh(); // Setup list footer button to load more arrivals (when arrivals are shown) Button loadMoreArrivals = (Button) mFooter.findViewById(R.id.load_more_arrivals); loadMoreArrivals.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadMoreArrivals(); } }); getListView().addFooterView(mFooter); // Repeat for the load more arrivals button in the empty list view Button loadMoreArrivalsEmptyList = (Button) mEmptyList.findViewById(R.id.load_more_arrivals); loadMoreArrivalsEmptyList.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadMoreArrivals(); } }); // This sets the stopId and uri setStopId(); setUserInfo(); // Create an empty adapter we will use to display the loaded data. mAdapter = new ArrivalsListAdapter(getActivity()); setListAdapter(mAdapter); // Start out with a progress indicator. setListShown(false); mRoutesFilter = ObaContract.StopRouteFilters.get(getActivity(), mStopId); mTripsForStopCallback = new TripsForStopCallback(); //LoaderManager.enableDebugLogging(true); LoaderManager mgr = getLoaderManager(); mgr.initLoader(TRIPS_FOR_STOP_LOADER, null, mTripsForStopCallback); mgr.initLoader(ARRIVALS_LIST_LOADER, getArguments(), this); // Set initial minutesAfter value in the empty list view setEmptyText(UIHelp.getNoArrivalsMessage(getActivity(), getArrivalsLoader().getMinutesAfter(), false)); }
From source file:bikebadger.RideFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(Constants.APP.TAG, "RideFragment.onCreate()"); //setRetainInstance(true); mRideManager = RideManager.get(getActivity()); Log.d(Constants.APP.TAG, "mRideManager set = RideManager.get(" + getActivity() + ")"); setHasOptionsMenu(true);// w ww . j a va2 s.c o m // check for a Ride ID as an argument, and find the run Bundle args = getArguments(); if (args != null) { long runId = args.getLong(ARG_RUN_ID, -1); Log.d(Constants.APP.TAG, "RideFragment.onCreate() runId=" + runId); if (runId != -1) { LoaderManager lm = getLoaderManager(); lm.initLoader(LOAD_RUN, args, new RunLoaderCallbacks()); lm.initLoader(LOAD_LOCATION, args, new LocationLoaderCallbacks()); } } // Initialize the TextToSpeech Engine... // TODO this engine may not exist. Provide the ability to run without it. Intent checkTTSIntent = new Intent(); checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); if (checkTTSIntent.resolveActivity(mRideManager.mAppContext.getPackageManager()) != null) { startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE_REQUEST); } else { Log.d(Constants.APP.TAG, "Could not find TTS Intent"); MyToast.Show(getActivity(), "Could not find Text To Speech Service", Color.RED); AlertDialog ad1 = new AlertDialog.Builder(getActivity()).create(); ad1.setCancelable(false); ad1.setTitle("Text To Speech Engine Not Found"); ad1.setMessage( "There was a problem finding the Text To Speech Engine. Make sure it's install properly under Language and Input Settings."); ad1.setButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); ad1.show(); } if (mRideManager.mLoadLastGPXFile) { Log.d(Constants.APP.TAG, "mLoadLastGPXFile=" + mRideManager.mLoadLastGPXFile); Log.d(Constants.APP.TAG, "mCurrentGPXPath=" + mRideManager.mCurrentGPXPath); OpenGPXFileOnNewThreadWithDialog(mRideManager.mCurrentGPXPath); } if (!mRideManager.IsGPSEnabled()) { ShowAlertMessageNoGps(); } // keep the screen on so it doesn't time out and turn dark getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); }
From source file:com.jefftharris.passwdsafe.sync.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.i(TAG, "onCreate"); OnItemSelectedListener freqSelListener = new OnItemSelectedListener() { @Override//from ww w. j a v a2 s. c o m public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { switch (parent.getId()) { case R.id.gdrive_interval: { onGdriveFreqChanged(position); break; } case R.id.dropbox_interval: { onDropboxFreqChanged(position); break; } case R.id.box_interval: { onBoxFreqChanged(position); break; } case R.id.onedrive_interval: { onOnedriveFreqChanged(position); break; } } } @Override public void onNothingSelected(AdapterView<?> parent) { } }; for (int id : new int[] { R.id.box_interval, R.id.dropbox_interval, R.id.gdrive_interval, R.id.onedrive_interval }) { Spinner freqSpin = (Spinner) findViewById(id); assert freqSpin != null; freqSpin.setOnItemSelectedListener(freqSelListener); } itsPermissionMgr = new DynamicPermissionMgr(Manifest.permission.GET_ACCOUNTS, this, PERMISSIONS_RC, APP_SETTINGS_RC, "com.jefftharris.passwdsafe.sync", R.id.reload, R.id.app_settings); View noPermGroup = findViewById(R.id.no_permission_group); GuiUtils.setVisible(noPermGroup, !itsPermissionMgr.checkPerms()); // Check the state of Google Play services GoogleApiAvailability googleApi = GoogleApiAvailability.getInstance(); int rc = googleApi.isGooglePlayServicesAvailable(this); if (rc != ConnectionResult.SUCCESS) { googleApi.showErrorDialogFragment(this, rc, GDRIVE_PLAY_SERVICES_ERROR_RC); } updateGdriveAccount(null); updateDropboxAccount(null); updateBoxAccount(null); updateOnedriveAccount(null); updateOwncloudAccount(null); LoaderManager lm = getSupportLoaderManager(); lm.initLoader(LOADER_PROVIDERS, null, this); }
From source file:can.yrt.onebusaway.ArrivalsListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Set and add the view that is shown if no arrival information is returned by the REST API getListView().setEmptyView(mEmptyList); ((ViewGroup) getListView().getParent()).addView(mEmptyList); // We have a menu item to show in action bar. setHasOptionsMenu(true);/* www. java2 s.com*/ mAlertList = new AlertList(getActivity()); mAlertList.initView(getView().findViewById(R.id.arrivals_alert_list)); mHeader = new ArrivalsListHeader(getActivity(), this); View header = getView().findViewById(R.id.arrivals_list_header); mHeader.initView(header); mHeader.refresh(); // Setup list footer button to load more arrivals (when arrivals are shown) Button loadMoreArrivals = (Button) mFooter.findViewById(R.id.load_more_arrivals); loadMoreArrivals.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadMoreArrivals(); } }); getListView().addFooterView(mFooter); // Repeat for the load more arrivals button in the empty list view Button loadMoreArrivalsEmptyList = (Button) mEmptyList.findViewById(R.id.load_more_arrivals); loadMoreArrivalsEmptyList.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadMoreArrivals(); } }); // This sets the stopId and uri setStopId(); setUserInfo(); // Create an empty adapter we will use to display the loaded data. mAdapter = new ArrivalsListAdapter(this, getActivity()); setListAdapter(mAdapter); // Start out with a progress indicator. setListShown(false); mRoutesFilter = ObaContract.StopRouteFilters.get(getActivity(), mStopId); mTripsForStopCallback = new TripsForStopCallback(); //LoaderManager.enableDebugLogging(true); LoaderManager mgr = getLoaderManager(); mgr.initLoader(TRIPS_FOR_STOP_LOADER, null, mTripsForStopCallback); mgr.initLoader(ARRIVALS_LIST_LOADER, getArguments(), this); // Set initial minutesAfter value in the empty list view setEmptyText(UIHelp.getNoArrivalsMessage(getActivity(), getArrivalsLoader().getMinutesAfter(), false)); }
From source file:hku.fyp14017.blencode.ui.fragment.LookFragment.java
public void initOrRestartLoader(Bundle arguments) { LoaderManager loaderManager = getLoaderManager(); if (loaderManager.getLoader(LookController.ID_LOADER_MEDIA_IMAGE) == null) { loaderManager.initLoader(LookController.ID_LOADER_MEDIA_IMAGE, arguments, this); } else {// w w w. j a v a 2 s .c o m loaderManager.restartLoader(LookController.ID_LOADER_MEDIA_IMAGE, arguments, this); } }