List of usage examples for android.support.v4.content Loader getId
public int getId()
From source file:com.tavant.droid.womensecurity.fragments.ContactsListFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // This swaps the new cursor into the adapter. if (loader.getId() == ContactsQuery.QUERY_ID) { mAdapter.swapCursor(data);//from www . j av a2s . c om if (!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:com.example.android.contactslist.ui.groupsEditor.GroupsEditorFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // This swaps the new cursor into the adapter. switch (loader.getId()) { case GroupsListQuery.QUERY_ID: String acc_name;/*from w ww. jav a 2 s.c o m*/ String acc_type; if (data != null && data.moveToFirst()) { final ArrayList<ContactInfo> list = new ArrayList<ContactInfo>(); ContactInfo group; do { group = new ContactInfo(data.getString(GroupsListQuery.TITLE), ContactInfo.group_lookup_key, data.getLong(GroupsListQuery.ID)); group.setMemberCount(data.getInt(GroupsListQuery.MEMBER_COUNT)); group = GroupBehavior.setGroupBehaviorFromName(group, // choose the default behavior based on if the group was just added // the new group should at least be included/ checked group.getName().equals(name_of_new_group) ? ContactInfo.PASSIVE_BEHAVIOR : ContactInfo.IGNORED, getActivity()); acc_name = data.getString(GroupsListQuery.ACCOUNT_NAME); acc_type = data.getString(GroupsListQuery.ACCOUNT_TYPE); list.add(group); } while (data.moveToNext()); // reset the record for which was the recently added group name_of_new_group = ""; new Thread(new Runnable() { @Override public void run() { final ContactStatsContract statsDb = new ContactStatsContract(getActivity()); final GroupStatsHelper groupStatsHelper = new GroupStatsHelper(getActivity()); // adds each group to the database,if they aren't already there // any new group that has a prescribed behavior is opted in // That is, it's checked by default groupStatsHelper.updateGroupListInDB(list, statsDb); statsDb.close(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // in the UI thread update the group list from the database getGroupStats(); } }); } }).start(); } break; case GroupsListStatsQuery.QUERY_ID: mAdapter.swapCursor(data); break; default: } }
From source file:info.staticfree.android.units.Units.java
public void onLoadFinished(Loader<Cursor> loader, Cursor c) { switch (loader.getId()) { case LOADER_HISTORY: mHistoryAdapter.swapCursor(c);/*from ww w . j a v a 2 s.com*/ break; case LOADER_USAGE: mHaveUsageAdapter.swapCursor(c); mWantUsageAdapter.swapCursor(c); } }
From source file:com.gsma.rcs.ri.messaging.GroupTalkView.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (LOADER_ID != loader.getId()) { return;/* w w w .j a v a2s . com*/ } /* * The asynchronous load is complete and the data is now available for use. Only now can we * associate the queried Cursor with the CursorAdapter. */ mAdapter.swapCursor(cursor); /** * Registering content observer for chat message and file transfer content URIs. When these * content URIs will change, this will notify the loader to reload its data. */ if (mObserver != null && !mObserver.getLoader().equals(loader)) { ContentResolver resolver = getContentResolver(); resolver.unregisterContentObserver(mObserver); resolver.unregisterContentObserver(mObserver); mObserver = null; } if (mObserver == null) { if (LogUtils.isActive) { Log.d(LOGTAG, "onLoadFinished: register content observer"); } mObserver = new ChatCursorObserver(new Handler(), loader); ContentResolver resolver = getContentResolver(); resolver.registerContentObserver(ChatLog.Message.CONTENT_URI, true, mObserver); resolver.registerContentObserver(FileTransferLog.CONTENT_URI, true, mObserver); } }
From source file:br.com.mybaby.contatos.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./*from ww w . j a v a 2s . c om*/ 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); contatoParaSalvar.setId(data.getInt(ContactDetailQuery.ID)); contatoParaSalvar.setNome(contactName); contatoParaSalvar.setTipo(tipoContato); 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 layoutParams = // 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, layoutParams); // } while (data.moveToNext()); // } else { // // If nothing found, adds an empty address layout // mDetailsLayout.addView(buildEmptyAddressLayout(), layoutParams); // } // break; case ContactPhoneQuery.QUERY_ID: final LinearLayout.LayoutParams layoutPhoneParams = 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(); if (data.moveToFirst()) { do { boolean checked = false; Telefone telefone = new Telefone(); telefone.setId(data.getInt(ContactPhoneQuery.ID)); telefone.setNumero(data.getString(ContactPhoneQuery.NUMBER)); telefonesContatoAtual.add(telefone); if (telefonesBase.contains(telefone)) { contatoParaSalvar.getTelefones().add(telefone); checked = true; } // Builds the phone layout final LinearLayout layout = buildPhoneLayout(data.getInt(ContactPhoneQuery.ID), data.getString(ContactPhoneQuery.NUMBER), checked); // Adds the new address layout to the details layout mDetailsLayout.addView(layout, layoutPhoneParams); } while (data.moveToNext()); } else { // If nothing found, adds an empty address layout mDetailsLayout.addView(buildEmptyAddressLayout(), layoutPhoneParams); } } }
From source file:com.nononsenseapps.feeder.ui.FeedFragment.java
@Override public void onLoadFinished(final Loader cursorLoader, final Object result) { if (FEEDITEMS_LOADER == cursorLoader.getId()) { HashMap<FeedItemSQL, Integer> map = (HashMap<FeedItemSQL, Integer>) result; mAdapter.updateData(map);// ww w . j a va 2 s. c om boolean empty = mAdapter.getItemCount() <= 2; mEmptyView.setVisibility(empty ? View.VISIBLE : View.GONE); mSwipeRefreshLayout.setVisibility(empty ? View.GONE : View.VISIBLE); } else if (FEED_LOADER == cursorLoader.getId()) { Cursor cursor = (Cursor) result; if (cursor.moveToFirst()) { FeedSQL feed = new FeedSQL(cursor); this.title = feed.title; this.customTitle = feed.customTitle; this.url = feed.url; this.notify = feed.notify; ((BaseActivity) getActivity()).getSupportActionBar().setTitle(title); mNotifyCheck.setChecked(this.notify == 1); } // Reset loader getLoaderManager().destroyLoader(cursorLoader.getId()); } else if (FEED_SETTINGS_LOADER == cursorLoader.getId()) { Cursor cursor = (Cursor) result; if (cursor.getCount() == 1 && cursor.moveToFirst()) { // Conclusive results this.notify = cursor.getInt(0); } else { this.notify = 0; } mNotifyCheck.setChecked(this.notify == 1); // Reset loader getLoaderManager().destroyLoader(cursorLoader.getId()); } }
From source file:es.example.contacts.ui.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.//from w ww . j a v a 2 s .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); displayName = contactName; id = data.getString(ContactDetailQuery.ID); 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 layoutParams = 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 { final Uri uri = Uri.withAppendedPath(mContactUri, ContactsContract.RawContacts.Data.CONTENT_DIRECTORY); ContentResolver cr = getActivity().getContentResolver(); Cursor cur = cr.query(uri, ContactPhoneQuery.PROJECTION, ContactPhoneQuery.SELECTION, null, null); try { if (cur.moveToFirst()) { // Builds the address layout final Uri uriData = Uri.parse("content://com.android.contacts/data"); Cursor curData = cr.query(Data.CONTENT_URI, ContactData1Query.PROJECTION, ContactData1Query.SELECTION, null, null); try { if (curData.getCount() == 0) { final LinearLayout layout = buildAddressLayout( data.getInt(ContactAddressQuery.TYPE), data.getString(ContactAddressQuery.LABEL), data.getString(ContactAddressQuery.ADDRESS), cur.getString(ContactPhoneQuery.PHONE), null, data.getString(ContactAddressQuery.CONTACT_ID), displayName); // Adds the new address layout to the details layout mDetailsLayout.addView(layout, layoutParams); } else { if (curData.moveToFirst()) { final LinearLayout layout = buildAddressLayout( curData.getInt(ContactAddressQuery.ID), data.getString(ContactAddressQuery.LABEL), data.getString(ContactAddressQuery.ADDRESS), cur.getString(ContactPhoneQuery.PHONE), curData.getString(ContactData1Query.DATA1), data.getString(ContactAddressQuery.CONTACT_ID), displayName); // Adds the new address layout to the details layout mDetailsLayout.addView(layout, layoutParams); } } } finally { if (curData != null) curData.close(); } } } finally { if (cur != null) cur.close(); } } while (data.moveToNext()); data.close(); } else { // If nothing found, adds an empty address layout mDetailsLayout.addView(buildEmptyAddressLayout(), layoutParams); } break; } }
From source file:net.abcdroid.devfest12.ui.SessionLivestreamActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { switch (loader.getId()) { case SessionSummaryQuery._TOKEN: loadSession(data);//from w w w.j ava 2 s . c o m break; case SessionsQuery._TOKEN: mLivestreamAdapter.swapCursor(data); if (data != null && data.getCount() > 0) { mSessionsFound = true; final int selected = locateSelectedItem(data); getSupportActionBar().setSelectedNavigationItem(selected); } else if (mSessionsFound) { mSessionsFound = false; final Bundle bundle = new Bundle(); bundle.putBoolean(LOADER_SESSIONS_ARG, true); getSupportLoaderManager().restartLoader(SessionsQuery._TOKEN, bundle, this); } else { navigateUpOrFinish(); } break; } }
From source file:miguelmaciel.play.anonymouscall.ui.ContactsListFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // This swaps the new cursor into the adapter. if (loader.getId() == ContactsQuery.QUERY_ID) { mAdapter.swapCursor(data);/*from w w w . java2s. co m*/ // 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; } //This method will get all Names and respective phone numbers to an array [arrID/arrPhones] if (data.getCount() > 0) { //Clear the arrays arrID.clear(); arrPhones.clear(); //Go to first position of the array and start getting the data data.moveToFirst(); do { String contactId = data.getString(data.getColumnIndex(Contacts._ID)); // // Get all phone numbers. // Cursor phones = null; try { phones = getActivity().getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null); if (phones.getCount() > 0) { phones.moveToFirst(); do { String number = phones.getString( phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); int type = phones .getInt(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)); switch (type) { case ContactsContract.CommonDataKinds.Phone.TYPE_HOME: // do something with the Home number here... arrID.add(contactId); arrPhones.add(number); break; case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE: // do something with the Mobile number here... arrID.add(contactId); arrPhones.add(number); break; case ContactsContract.CommonDataKinds.Phone.TYPE_WORK: // do something with the Work number here... arrID.add(contactId); arrPhones.add(number); break; } } while (phones.moveToNext()); // phones.close(); } } catch (Throwable e) { phones.close(); } finally { phones.close(); } } while (data.moveToNext()); } } }
From source file:com.money.manager.ex.common.AllDataListFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { LoaderManager.LoaderCallbacks<Cursor> parent = getSearchResultFragmentLoaderCallbacks(); if (parent != null) parent.onLoadFinished(loader, data); switch (loader.getId()) { case ID_LOADER_ALL_DATA_DETAIL: // Transactions list loaded. AllDataAdapter adapter = (AllDataAdapter) getListAdapter(); // adapter.swapCursor(data); adapter.changeCursor(data);//from w ww . j av a2s . co m if (isResumed()) { setListShown(true); if (data != null && data.getCount() <= 0 && getFloatingActionButton() != null) getFloatingActionButton().show(true); } else { setListShownNoAnimation(true); } // reset the transaction groups (account name collection) adapter.resetAccountHeaderIndexes(); // Show totals if (this.mShowFooter) { try { this.updateFooter(data); } catch (Exception e) { Timber.e(e, "displaying footer"); } } } }