List of usage examples for android.support.v4.content Loader getId
public int getId()
From source file:com.nextgis.maplibui.fragment.NGWLoginFragment.java
@Override public void onLoadFinished(Loader<String> loader, String token) { mSignInButton.setEnabled(true);/*from ww w . ja va 2 s . c o m*/ if (null != mGuestButton) { // needed for overrides mGuestButton.setEnabled(true); } String accountName = ""; try { String url = mUrlText; if (!url.startsWith("http")) { url = "http://" + url; } URI uri = new URI(url); if (uri.getHost() != null && uri.getHost().length() > 0) { accountName += uri.getHost(); } if (uri.getPort() != 80 && uri.getPort() > 0) { accountName += ":" + uri.getPort(); } if (uri.getPath() != null && uri.getPath().length() > 0) { accountName += uri.getPath(); } } catch (URISyntaxException e) { accountName = mUrlText; } if (loader.getId() == R.id.auth_token_loader) { if (token != null && token.length() > 0) onTokenReceived(accountName, token); else Toast.makeText(getActivity(), R.string.error_login, Toast.LENGTH_SHORT).show(); } else if (loader.getId() == R.id.non_auth_token_loader) onTokenReceived(accountName, Constants.NGW_ACCOUNT_GUEST); }
From source file:cz.maresmar.sfm.view.MainActivity.java
@Override public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor cursor) { switch (loader.getId()) { case USER_LOADER_ID: { Timber.d("User data loaded"); // Removes old profiles mProfiles.clear();/*from www. j av a2s . c o m*/ // Insert new profiles if (cursor.moveToFirst()) { do { Long userId = cursor.getLong(0); String userName = cursor.getString(1); Uri iconUri = Uri.parse(cursor.getString(2)); ProfileDrawerItem profile = new ProfileDrawerItem().withIdentifier(userId).withName(userName) .withIcon(iconUri); mProfiles.addProfiles(profile); } while (cursor.moveToNext()); } // Select default user if (mSelectedUserId == SettingsContract.LAST_USER_UNKNOWN && mProfiles.getActiveProfile() != null) { mSelectedUserId = mProfiles.getActiveProfile().getIdentifier(); } // Set last user in UI if (mSelectedUserId != SettingsContract.LAST_USER_UNKNOWN) { mProfiles.setActiveProfile(mSelectedUserId); } // Insert control entries mProfiles.addProfiles(ADD_USER_DRAWER_ITEM, MANAGE_USER_DRAWER_ITEM); // Load correct user info for selected user (could be from backup) Loader portalLoader = getSupportLoaderManager().getLoader(PORTAL_LOADER_ID); if (portalLoader == null || !portalLoader.isStarted()) { getSupportLoaderManager().initLoader(PORTAL_LOADER_ID, null, this); getSupportLoaderManager().initLoader(EDIT_ACTIONS_COUNT_LOADER_ID, null, this); } // Should be always reused because of users recreation getSupportLoaderManager().initLoader(CREDENTIAL_LOADER_ID, null, this); break; } case PORTAL_LOADER_ID: { Timber.d("Portal data loaded"); // Clear old portals int oldPortalCount = mPortalDrawerItem.getSubItems().size(); mPortalDrawerItem.getSubItems().clear(); // Insert new portals boolean selectedFound = false; if (cursor.moveToFirst()) { do { Long portalId = cursor.getLong(0); String portalName = cursor.getString(1); int credit = cursor.getInt(2); SecondaryDrawerItem portalItem = new SecondaryDrawerItem().withIdentifier(portalId) .withName(portalName).withDescription(MenuUtils.getPriceStr(this, credit)) .withTag(PORTAL_ITEM_DRAWER_TAG); // Updates selected fragment if new user hasn't the old one if (portalId == mSelectedFragmentId) { portalItem.withSetSelected(true); setTitle(portalName); selectedFound = true; } else if (cursor.isLast() && !selectedFound && mSelectedFragmentId >= 0) { mSelectedFragmentId = portalId; portalItem.withSetSelected(true); setTitle(portalName); showToolbar(); } mPortalDrawerItem.withSubItems(portalItem); } while (cursor.moveToNext()); } // Insert control entries mPortalDrawerItem.withSubItems(ADD_PORTAL_DRAWER_ITEM, MANAGE_PORTAL_DRAWER_ITEM); // Notify about changes if (mPortalDrawerItem.isExpanded()) { mDrawer.getExpandableExtension() .notifyAdapterSubItemsChanged(mDrawer.getPosition(mPortalDrawerItem), oldPortalCount); } // Set default title as title on empty cursor if (cursor.getCount() == 0) { setTitle(R.string.drawer_portal); showToolbar(); } // Show saved fragment in UI showOrResetFragment(mSelectedFragmentId); break; } case CREDENTIAL_LOADER_ID: { Timber.d("Credential data loaded"); if (mProfiles.getActiveProfile() == null) return; // Prepare result StringBuilder builder = new StringBuilder(); if (cursor.moveToFirst()) { do { if (builder.length() > 0) { builder.append("; "); } int rawCredit = cursor.getInt(1); builder.append(MenuUtils.getPriceStr(this, rawCredit)); } while (cursor.moveToNext()); } // Show result ((ProfileDrawerItem) mProfiles.getActiveProfile()).withEmail(builder.toString()).withNameShown(true); mProfiles.updateProfile(mProfiles.getActiveProfile()); break; } case EDIT_ACTIONS_COUNT_LOADER_ID: Timber.i("Edit actions count loaded"); if (cursor.moveToFirst()) { if (cursor.getInt(0) > 0) { setMenuEditUiShown(true); } else { setMenuEditUiShown(false); } } if (BuildConfig.DEBUG) { Assert.isOne(cursor.getCount()); } break; default: throw new UnsupportedOperationException("Unknown loader id: " + loader.getId()); } }
From source file:edu.umbc.cs.ebiquity.mithril.parserapp.contentparsers.contacts.ContactDetailFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // If this fragment was cleared while the query was running // eg. from from a call like setContact(uri) then don't do // anything./*w ww . j av a 2s.c o m*/ if (mContactUri == null) { return; } switch (loader.getId()) { case ContactDetailQuery.QUERY_ID: // Moves to the first row in the Cursor if (data.moveToFirst()) { // For the contact details query, fetches the contact display name. // ContactDetailQuery.DISPLAY_NAME maps to the appropriate display // name field based on OS version. final String contactName = data.getString(ContactDetailQuery.DISPLAY_NAME); if (mIsTwoPaneLayout && mContactName != null) { // In the two pane layout, there is a dedicated TextView // that holds the contact name. mContactName.setText(contactName); } else { // In the single pane layout, sets the activity title // to the contact name. On HC+ this will be set as // the ActionBar title text. getActivity().setTitle(contactName); } } break; case ContactAddressQuery.QUERY_ID: // This query loads the contact address details. More than // one contact address is possible, so move each one to a // LinearLayout in a Scrollview so multiple addresses can // be scrolled by the user. // Each LinearLayout has the same LayoutParams so this can // be created once and used for each address. final LinearLayout.LayoutParams addressLayoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); // Clears out the details layout first in case the details // layout has addresses from a previous data load still // added as children. mDetailsLayout.removeAllViews(); // Loops through all the rows in the Cursor if (data.moveToFirst()) { do { // Builds the address layout final LinearLayout layout = buildAddressLayout(data.getInt(ContactAddressQuery.TYPE), data.getString(ContactAddressQuery.LABEL), data.getString(ContactAddressQuery.ADDRESS)); // Adds the new address layout to the details layout mDetailsLayout.addView(layout, addressLayoutParams); } while (data.moveToNext()); } else { // If nothing found, adds an empty address layout mDetailsLayout.addView(buildEmptyAddressLayout(), addressLayoutParams); } break; case ContactPhoneQuery.QUERY_ID: // This query loads the contact phone details. More than // one contact phone number is possible, so move each one to a // LinearLayout in a Scrollview so multiple phone numbers can // be scrolled by the user. // Each LinearLayout has the same LayoutParams so this can // be created once and used for each address. final LinearLayout.LayoutParams phoneLayoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); // Clears out the details layout first in case the details // layout has addresses from a previous data load still // added as children. mPhoneLayout.removeAllViews(); // Loops through all the rows in the Cursor if (data.moveToFirst()) { do { // Builds the address layout final LinearLayout layout = buildPhoneLayout(data.getString(ContactPhoneQuery.PHONE_NUMBER), data.getInt(ContactPhoneQuery.PHONE_NUMBER_TYPE)); // Adds the new address layout to the details layout mPhoneLayout.addView(layout, phoneLayoutParams); } while (data.moveToNext()); } else { // If nothing found, adds an empty address layout mPhoneLayout.addView(buildEmptyPhoneLayout(), phoneLayoutParams); } break; } }
From source file:edu.umbc.cs.ebiquity.mithril.parserapp.contentparsers.contacts.ContactsListFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { /**/*from w ww. j a va2 s . c om*/ * This swaps the new cursor into the adapter. This is the point when the cursor data is passed on to the adapter. */ if (loader.getId() == ContactsQuery.QUERY_ID) { mAdapter.swapCursor(data); // If this is a two-pane layout and there is a search query then // there is some additional work to do around default selected // search item. if (mIsTwoPaneLayout && !TextUtils.isEmpty(mSearchTerm) && mSearchQueryChanged) { // Selects the first item in results, unless this fragment has // been restored from a saved state (like orientation change) // in which case it selects the previously selected search item. if (data != null && data.moveToPosition(mPreviouslySelectedSearchItem)) { // Creates the content Uri for the previously selected contact by appending the // contact's ID to the Contacts table content Uri final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(data.getLong(ContactsQuery.ID))); mOnContactSelectedListener.onContactSelected(uri); getListView().setItemChecked(mPreviouslySelectedSearchItem, true); } else { // No results, clear selection. onSelectionCleared(); } // Only restore from saved state one time. Next time fall back // to selecting first item. If the fragment state is saved again // then the currently selected item will once again be saved. mPreviouslySelectedSearchItem = 0; mSearchQueryChanged = false; } } }
From source file:cz.maresmar.sfm.view.portal.PortalDetailFragment.java
@Override public void onStart() { super.onStart(); // Loads plugins getLoaderManager().initLoader(PLUGIN_LOADER_ID, null, new LoaderManager.LoaderCallbacks<List<PluginInfo>>() { @NonNull// w ww .j a v a 2s . com @Override public Loader<List<PluginInfo>> onCreateLoader(int id, Bundle args) { switch (id) { case PLUGIN_LOADER_ID: return new PluginListLoader(getContext()); default: throw new UnsupportedOperationException("Unknown loader id: " + id); } } @Override public void onLoadFinished(@NonNull Loader<List<PluginInfo>> loader, List<PluginInfo> data) { //noinspection ConstantConditions mPluginAdapter = new PluginAdapter(getContext(), data); mPluginSpinner.setAdapter(mPluginAdapter); blockingLoaders.countDown(); } @Override public void onLoaderReset(@NonNull Loader<List<PluginInfo>> loader) { switch (loader.getId()) { case PLUGIN_LOADER_ID: Timber.d("Action loader reset"); return; default: throw new UnsupportedOperationException("Unknown loader id: " + loader.getId()); } } }); // Loads portal data from DB if (mPortalUri != null && mLoadDataFromDb) { getLoaderManager().initLoader(PORTAL_LOADER_ID, null, this); } else { mPluginSpinner.setOnItemSelectedListener(mPluginChangeListen); } }
From source file:org.totschnig.myexpenses.fragment.CategoryList.java
@Override public void onLoaderReset(Loader<Cursor> loader) { int id = loader.getId(); if (id == SORTABLE_CURSOR) { mGroupCursor = null;//from w w w . ja v a 2 s . c om mAdapter.setGroupCursor(null); } else if (id > 0) { // child cursor try { mAdapter.setChildrenCursor(id, null); } catch (NullPointerException e) { Log.w("TAG", "Adapter expired, try again on the next query: " + e.getMessage()); } } }
From source file:com.example.linhdq.test.documents.viewing.grid.DocumentGridActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (cursor.moveToFirst()) { final int titleIndex = cursor.getColumnIndex(DocumentContentProvider.Columns.TITLE); final String oldTitle = cursor.getString(titleIndex); final int idIndex = cursor.getColumnIndex(DocumentContentProvider.Columns.ID); final String documentId = String.valueOf(cursor.getInt(idIndex)); final Uri documentUri = Uri.withAppendedPath(DocumentContentProvider.CONTENT_URI, documentId); askUserForNewTitle(oldTitle, documentUri); }//from w w w.ja va2 s .c om getSupportLoaderManager().destroyLoader(loader.getId()); }
From source file:com.dsdar.thosearoundme.util.ContactsListFragment.java
@Override public void onLoaderReset(Loader<Cursor> loader) { if (loader.getId() == ContactsQuery.QUERY_ID) { // When the loader is being reset, clear the cursor from the // adapter. This allows the // cursor resources to be freed. mAdapter.swapCursor(null);/*from w w w.ja va2s. c om*/ } }
From source file:net.smartpager.android.activity.MainActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { switch (LoaderID.values()[loader.getId()]) { case CONTACT_EXISTS_LOADER: boolean contactExist = cursor.moveToFirst(); if (contactExist) { mHandler.sendEmptyMessage(MSG_SHOW_DIALOG_CONTACT_EXISTS); } else {/*from w w w .j a v a 2 s. c o m*/ mHandler.sendEmptyMessage(MSG_SEND_REQUEST_CONTACT_COMMAND); } break; default: break; } }
From source file:org.totschnig.myexpenses.activity.MyExpenses.java
@Override public void onLoaderReset(Loader<Cursor> arg0) { if (arg0.getId() == ACCOUNTS_CURSOR) { mViewPagerAdapter.swapCursor(null); ((SimpleCursorAdapter) mDrawerListAdapter).swapCursor(null); mCurrentPosition = -1;//from www .jav a 2 s . c o m mAccountsCursor = null; } }