List of usage examples for android.support.v4.content Loader getId
public int getId()
From source file:com.battlelancer.seriesguide.ui.OverviewFragment.java
@SuppressLint("NewApi") @Override//from w w w . ja va 2 s .c o m public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (isAdded()) { switch (loader.getId()) { case OverviewActivity.OVERVIEW_EPISODE_LOADER_ID: getActivity().invalidateOptionsMenu(); onPopulateEpisodeData(data); break; case OverviewActivity.OVERVIEW_SHOW_LOADER_ID: onPopulateShowData(data); break; } } }
From source file:com.haedrian.curo.HomeScreen.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.//from w w w . ja 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); 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 ContactEmailQuery.QUERY_ID: final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); mDetailsLayout.removeAllViews(); // Loops through all the rows in the Cursor if (data.moveToFirst()) { do { Log.v("TEST", data.getString(ContactEmailQuery.ADDRESS)); // Builds the address layout final LinearLayout layout = buildAddressLayout(data.getInt(ContactEmailQuery.TYPE), data.getString(ContactEmailQuery.LABEL), data.getString(ContactEmailQuery.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; } }
From source file:android.com.example.contactslist.ui.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 ww . j a va 2 s. com*/ } }
From source file:me.philio.ghost.ui.NavigationDrawerFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { switch (loader.getId()) { case LOADER_BLOG_NAME: // Validity check if (cursor == null || cursor.getCount() == 0) { Log.e(TAG, "Failed to load setting"); // Make sure a sync is scheduled to fix the problem SyncHelper.requestSync(mSelectedAccount, getString(R.string.content_authority)); return; }/* ww w .j a va 2 s . co m*/ // Create a model from the cursor as it's easier than lots of string manipulation cursor.moveToFirst(); Setting setting = new Setting(); setting.loadFromCursor(cursor); // Set the title/url mBlogName.setText(setting.value); mBlogUrl.setText(setting.blog.url); break; case LOADER_USER: // Validity check if (cursor == null || cursor.getCount() == 0) { Log.e(TAG, "Failed to load user"); // Make sure a sync is scheduled to fix the problem SyncHelper.requestSync(mSelectedAccount, getString(R.string.content_authority)); return; } // Create a model from the cursor as it's easier than lots of string manipulation cursor.moveToFirst(); User user = new User(); user.loadFromCursor(cursor); // Show cover image if (user.cover != null) { try { String path = ImageUtils.getUrl(user.blog, user.cover); String filename = ImageUtils.getFilename(getActivity(), user.blog, path); File cover = new File(filename); if (cover.exists()) { Picasso.with(getActivity()).load(cover).fit().centerCrop().into(mCover); } } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { Log.e(TAG, "Error loading image"); } } else { mCover.setImageDrawable(null); } // Show avatar if (user.image != null) { try { String path = ImageUtils.getUrl(user.blog, user.image); String filename = ImageUtils.getFilename(getActivity(), user.blog, path); File avatar = new File(filename); if (avatar.exists()) { Picasso.with(getActivity()).load(avatar).fit().into(mAvatar); } } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { Log.e(TAG, "Error loading image"); } } else { mAvatar.setImageResource(R.drawable.ic_action_social_person); } // Set text values mName.setText(user.name); mEmail.setText(user.email); break; } }
From source file:com.visva.voicerecorder.view.fragments.FragmentContact.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 ww w . j a v a 2 s.c o 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); mListContact.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:fr.jbteam.jabboid.core.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 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); 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.getString(ContactAddressQuery.CONTACT), data.getInt(ContactAddressQuery.PRESENCE), data.getInt(ContactAddressQuery.PROTOCOL), data.getString(ContactAddressQuery.LABEL)); // 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; } }
From source file:com.money.manager.ex.home.HomeFragment.java
@Override public void onLoaderReset(Loader<Cursor> loader) { switch (loader.getId()) { case LOADER_ACCOUNT_BILLS: txtTotalAccounts.setText(mCurrencyService.getBaseCurrencyFormatted(MoneyFactory.fromString("0"))); setListViewAccountBillsVisible(false); mAccountsByType.clear();/* w ww .j av a 2 s . co m*/ mTotalsByType.clear(); mAccountTypes.clear(); break; } }
From source file:android.com.example.contactslist.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 w w.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); 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; } }
From source file:net.reichholf.dreamdroid.fragment.MediaPlayerFragment.java
public void onLoadFinished(Loader<LoaderResult<ArrayList<ExtendedHashMap>>> loader, LoaderResult<ArrayList<ExtendedHashMap>> result) { getActionBarActivity().setSupportProgressBarIndeterminateVisibility(false); if (loader.getId() == LOADER_PLAYLIST_ID) { setCurrentTitle(getLoadFinishedTitle()); mPlaylist.clear();/* www .ja v a 2s. c o m*/ if (result.isError()) { showToast(result.getErrorText()); return; } mPlaylist.addAll(result.getResult()); mPlaylistAdapter.notifyDataSetChanged(); return; } mMapList.clear(); if (result.isError()) { setEmptyText(result.getErrorText()); return; } ArrayList<ExtendedHashMap> list = result.getResult(); if (list.size() == 0) setEmptyText(getText(R.string.no_list_item)); else { // get first media item ExtendedHashMap media = list.get(0); // save current media object mMedia = media; if (mMode == PLAY_MODE) { // add media info to detail view setMediaInfo(mMediaInfo); // add image to detail view ImageView imageView = (ImageView) getView().findViewById(R.id.cover); ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("file", "/tmp/.id3coverart")); String imageUrl = getHttpClient().buildUrl("/file?", params); // String imageUrl = // "http://192.168.2.100/file?file=/tmp/.id3coverart"; mImageLoader.displayImage(imageUrl, imageView); } // check for changes in options menu getActionBarActivity().supportInvalidateOptionsMenu(); String root = media.getString(Mediaplayer.KEY_ROOT); String path = ""; // create current title and remove first item from result list if // not a root item if (!Python.NONE.equals(root)) { path = " - " + root; list.remove(0); } setCurrentTitle(getLoadFinishedTitle() + path); mMapList.addAll(list); } getActionBarActivity().setTitle(getCurrentTitle()); mAdapter.notifyDataSetChanged(); }
From source file:net.reichholf.dreamdroid.fragment.ServiceListFragment.java
@Override public void onLoadFinished(Loader<LoaderResult<ArrayList<ExtendedHashMap>>> loader, LoaderResult<ArrayList<ExtendedHashMap>> result) { getActionBarActivity().supportInvalidateOptionsMenu(); if (loader.getId() == LOADER_BOUQUETLIST_ID) { mNavItems.clear();//from w w w .j ava 2 s. c o m ((BaseAdapter) mNavList.getAdapter()).notifyDataSetChanged(); } else { mDetailItems.clear(); ((BaseAdapter) mDetailList.getAdapter()).notifyDataSetChanged(); } String title = mNavName; if (isDetailAvail()) title = mDetailName; mHttpHelper.finishProgress(title); if (result.isError()) { setEmptyText(result.getErrorText()); return; } ArrayList<ExtendedHashMap> list = result.getResult(); if (list == null) { showToast(getString(R.string.error)); return; } if (loader.getId() == LOADER_BOUQUETLIST_ID) { mNavItems.addAll(list); ((BaseAdapter) mNavList.getAdapter()).notifyDataSetChanged(); } else { mEmpty.setVisibility(View.GONE); mDetailList.setVisibility(View.VISIBLE); mDetailItems.addAll(list); ((BaseAdapter) mDetailList.getAdapter()).notifyDataSetChanged(); } }