List of usage examples for android.support.v4.content Loader getId
public int getId()
From source file:de.electricdynamite.pasty.ClipboardFragment.java
@Override public void onLoadFinished(Loader<PastyLoader.PastyResponse> loader, PastyLoader.PastyResponse response) { ProgressBar pbLoading = (ProgressBar) getSherlockActivity().findViewById(R.id.progressbar_downloading); pbLoading.setVisibility(View.GONE); pbLoading = null;// w ww . j a v a 2s. c om mHelpTextBig.setTextColor(getResources().getColor(R.color.abs__primary_text_holo_light)); mHelpTextBig.setBackgroundDrawable(mBackground); if (response.isFinal) { getSherlockActivity().setSupportProgressBarIndeterminateVisibility(Boolean.FALSE); if (response.getResultSource() == PastyResponse.SOURCE_CACHE) { Toast.makeText(getSherlockActivity().getApplicationContext(), getString(R.string.warning_no_network_short), Toast.LENGTH_SHORT).show(); } } if (response.hasException) { if (LOCAL_LOG) Log.v(TAG, "onLoadFinished(): Loader delivered exception; calling handleException()"); // an error occured getSherlockActivity().setSupportProgressBarIndeterminateVisibility(Boolean.FALSE); PastyException mException = response.getException(); handleException(mException); } else { switch (loader.getId()) { case PastyLoader.TASK_CLIPBOARD_FETCH: JSONArray Clipboard = response.getClipboard(); mItems.clear(); mAdapter.notifyDataSetChanged(); getListView().invalidateViews(); try { if (Clipboard.length() == 0) { //Clipboard is empty mHelpTextBig.setText(R.string.helptext_PastyActivity_clipboard_empty); mHelpTextSmall.setText(R.string.helptext_PastyActivity_how_to_add); } else { for (int i = 0; i < Clipboard.length(); i++) { JSONObject Item = Clipboard.getJSONObject(i); ClipboardItem cbItem = new ClipboardItem(Item.getString("_id"), Item.getString("item")); this.mItems.add(cbItem); } mHelpTextBig.setText(R.string.helptext_PastyActivity_copy); mHelpTextSmall.setText(R.string.helptext_PastyActivity_options); //Assign adapter to ListView ListView listView = (ListView) getSherlockActivity().findViewById(R.id.listItems); listView.setAdapter(mAdapter); listView.setItemsCanFocus(false); listView.setOnItemClickListener(new OnItemClickListener() { @SuppressLint("NewApi") @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ClipboardItem Item = mItems.get(position); // get a ClipboardItem from the clicked position if (Item.isLinkified() && prefs.getClickableLinks()) { /* If the clicked item was originally linkified and prefs.getClickableLinks() is true, we manually * fire an ACTION_VIEW intent to simulate Linkify() behavior */ String url = Item.getText(); if (!URLUtil.isValidUrl(url)) url = "http://" + url; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } else { /* Else we copy the item to the systems clipboard, * show a Toast and finish() the activity */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { android.content.ClipboardManager sysClipboard = (android.content.ClipboardManager) getSherlockActivity() .getSystemService(Context.CLIPBOARD_SERVICE); Item.copyToClipboard(sysClipboard); sysClipboard = null; } else { ClipboardManager sysClipboard = (ClipboardManager) getSherlockActivity() .getSystemService(Context.CLIPBOARD_SERVICE); Item.copyToClipboard(sysClipboard); sysClipboard = null; } Toast.makeText(getSherlockActivity().getApplicationContext(), getString(R.string.item_copied), Toast.LENGTH_LONG).show(); getSherlockActivity().finish(); } } }); registerForContextMenu(listView); } } catch (Exception e) { e.printStackTrace(); } break; default: break; } } }
From source file:net.ddns.mlsoftlaberge.contactslist.ui.ContactAdminFragment.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 . ja v a 2s.com*/ if (mContactUri == null) { return; } // Each LinearLayout has the same LayoutParams so this can // be created once and used for each cumulative layouts of data final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); switch (loader.getId()) { case ContactDetailQuery.QUERY_ID: // Moves to the first row in the Cursor if (data.moveToFirst()) { // For the contact admins 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); mContactId = data.getString(ContactDetailQuery.ID); mRawContactId = data.getString(ContactDetailQuery.RAWID); if (mContactName != null) { mContactName.setText(contactName); } // 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: // Clears out the details layout first in case the details // layout has addresses from a previous data load still // added as children. mAddressLayout.removeAllViews(); // This query loads the contact address . // Loops through all the rows in the Cursor if (data.moveToFirst()) { // loop thru all addresses for the bottom layout do { // Builds the address layout final LinearLayout alayout = buildAddressLayout(data.getInt(ContactAddressQuery.TYPE), data.getString(ContactAddressQuery.LABEL), data.getString(ContactAddressQuery.ADDRESS)); // Adds the new address layout to the addresses layout mAddressLayout.addView(alayout, layoutParams); } while (data.moveToNext()); } break; case ContactPhoneQuery.QUERY_ID: // Clears out the details layout first in case the details // layout has data from a previous data load still // added as children. mPhoneLayout.removeAllViews(); // This query loads the contact phone // Loops through all the rows in the Cursor if (data.moveToFirst()) { // loop thru all phones for the bottom layout do { final LinearLayout playout = buildPhoneLayout(data.getInt(ContactPhoneQuery.TYPE), data.getString(ContactPhoneQuery.LABEL), data.getString(ContactPhoneQuery.PHONE)); // Adds the new phone layout to the phones layout mPhoneLayout.addView(playout, layoutParams); } while (data.moveToNext()); } break; case ContactEmailQuery.QUERY_ID: // Clears out the details layout first in case the details // layout has data from a previous data load still // added as children. mEmailLayout.removeAllViews(); // This query loads the contact email // Loops through all the rows in the Cursor if (data.moveToFirst()) { // loop thru all emails for the bottom layout do { final LinearLayout elayout = buildEmailLayout(data.getInt(ContactEmailQuery.TYPE), data.getString(ContactEmailQuery.LABEL), data.getString(ContactEmailQuery.EMAIL)); // Adds the new address layout to the details layout mEmailLayout.addView(elayout, layoutParams); // store full note, and process it } while (data.moveToNext()); } break; case ContactNotesQuery.QUERY_ID: // This query loads the contact notes // Get the first row of the cursor (table contains only one row) if (data.moveToFirst()) { // store full note, and process it mNotesData = data.getString(ContactNotesQuery.NOTE); mNotesRawId = data.getString(ContactNotesQuery.RAWID); mNotesId = data.getString(ContactNotesQuery.ID); expandnote(); compactnote(); } else { // If nothing found, clear the data mNotesData = ""; mNotesRawId = ""; mNotesId = ""; clearnote(); } // display the memo part of the note in the memo field (decoded note) mMemoItem.setText(notememo); // fill the layout of editables transactions filltransactionlayout(); break; } }
From source file:net.ddns.mlsoftlaberge.mlsoft.contacts.ContactAdminFragment.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 a v a2 s. c o m if (mContactUri == null) { return; } // Each LinearLayout has the same LayoutParams so this can // be created once and used for each cumulative layouts of data final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); switch (loader.getId()) { case ContactDetailQuery.QUERY_ID: // Moves to the first row in the Cursor if (data.moveToFirst()) { // For the contact admins 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); mContactId = data.getString(ContactDetailQuery.ID); mRawContactId = data.getString(ContactDetailQuery.RAWID); if (mContactName != null) { mContactName.setText(contactName); } // 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: // Clears out the details layout first in case the details // layout has addresses from a previous data load still // added as children. mAddressLayout.removeAllViews(); // This query loads the contact address . // Loops through all the rows in the Cursor if (data.moveToFirst()) { // loop thru all addresses for the bottom layout do { // Builds the address layout final LinearLayout alayout = buildAddressLayout(data.getInt(ContactAddressQuery.TYPE), data.getString(ContactAddressQuery.LABEL), data.getString(ContactAddressQuery.ADDRESS)); // Adds the new address layout to the addresses layout mAddressLayout.addView(alayout, layoutParams); } while (data.moveToNext()); } break; case ContactPhoneQuery.QUERY_ID: // Clears out the details layout first in case the details // layout has data from a previous data load still // added as children. mPhoneLayout.removeAllViews(); // This query loads the contact phone // Loops through all the rows in the Cursor if (data.moveToFirst()) { // loop thru all phones for the bottom layout do { final LinearLayout playout = buildPhoneLayout(data.getInt(ContactPhoneQuery.TYPE), data.getString(ContactPhoneQuery.LABEL), data.getString(ContactPhoneQuery.PHONE)); // Adds the new phone layout to the phones layout mPhoneLayout.addView(playout, layoutParams); } while (data.moveToNext()); } break; case ContactEmailQuery.QUERY_ID: // Clears out the details layout first in case the details // layout has data from a previous data load still // added as children. mEmailLayout.removeAllViews(); // This query loads the contact email // Loops through all the rows in the Cursor if (data.moveToFirst()) { // loop thru all emails for the bottom layout do { final LinearLayout elayout = buildEmailLayout(data.getInt(ContactEmailQuery.TYPE), data.getString(ContactEmailQuery.LABEL), data.getString(ContactEmailQuery.EMAIL)); // Adds the new address layout to the details layout mEmailLayout.addView(elayout, layoutParams); // store full note, and process it } while (data.moveToNext()); } break; case ContactNotesQuery.QUERY_ID: // This query loads the contact notes // Get the first row of the cursor (table contains only one row) if (data.moveToFirst()) { // store full note, and process it mNotesData = data.getString(ContactNotesQuery.NOTE); mNotesRawId = data.getString(ContactNotesQuery.RAWID); mNotesId = data.getString(ContactNotesQuery.ID); expandnote(); compactnote(); } else { // If nothing found, clear the data mNotesData = ""; mNotesRawId = ""; mNotesId = ""; clearnote(); } // display the memo part of the note in the memo field (decoded note) mMemoItem.setText(notememo); // fill the layout of editables transactions filltransactionlayout(); break; } }
From source file:com.vegnab.vegnab.MainVNActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor finishedCursor) { mRowCt = finishedCursor.getCount();//from w ww. jav a 2 s . com // there will be various loaders, switch them out here switch (loader.getId()) { case VNContract.Loaders.EXISTING_PH_CODES: mExistingPhCodes.clear(); while (finishedCursor.moveToNext()) { mExistingPhCodes.put( finishedCursor.getString(finishedCursor.getColumnIndexOrThrow("PlaceHolderCode")), finishedCursor.getLong(finishedCursor.getColumnIndexOrThrow("_id"))); } break; case VNContract.Loaders.EXISTING_SPP: // if there are species in the master list, record this is Preferences boolean hasSpp = false; while (finishedCursor.moveToNext()) { // should be just one record if (finishedCursor.getLong(finishedCursor.getColumnIndexOrThrow("Ct")) > 0) { hasSpp = true; } } SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor prefEditor; prefEditor = sharedPref.edit(); prefEditor.putBoolean(Prefs.SPECIES_LIST_DOWNLOADED, hasSpp); prefEditor.commit(); break; } }
From source file:com.vegnab.vegnab.MainVNActivity.java
@Override public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // is about to be closed. Need to make sure it is no longer is use. switch (loader.getId()) { case VNContract.Loaders.EXISTING_PH_CODES: break; // nothing to do with this one case VNContract.Loaders.EXISTING_SPP: break; // nothing to do with this one }/*ww w.j a v a 2s. co m*/ }
From source file:org.totschnig.myexpenses.activity.ExpenseEdit.java
@Override public void onLoaderReset(Loader<Cursor> loader) { //should not be necessary to empty the autocompletetextview int id = loader.getId(); switch (id) { case METHODS_CURSOR: mMethodsCursor = null;/*from ww w . java2 s. c om*/ if (mMethodsAdapter != null) { mMethodsAdapter.swapCursor(null); } break; case ACCOUNTS_CURSOR: if (mAccountsAdapter != null) { mAccountsAdapter.swapCursor(null); } break; } }
From source file:org.totschnig.myexpenses.activity.ExpenseEdit.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data == null) { return;/* www.j a va 2s . c o m*/ } int id = loader.getId(); switch (id) { case METHODS_CURSOR: mMethodsCursor = data; View methodContainer = findViewById(R.id.MethodRow); if (mMethodsAdapter == null || !data.moveToFirst()) { methodContainer.setVisibility(View.GONE); } else { methodContainer.setVisibility(View.VISIBLE); MatrixCursor extras = new MatrixCursor(new String[] { KEY_ROWID, KEY_LABEL, KEY_IS_NUMBERED }); extras.addRow(new String[] { "0", "- - - -", "0" }); mMethodsAdapter.swapCursor(new MergeCursor(new Cursor[] { extras, data })); if (mSavedInstance) { mTransaction.methodId = mMethodId; } if (mTransaction.methodId != null) { while (data.isAfterLast() == false) { if (data.getLong(data.getColumnIndex(KEY_ROWID)) == mTransaction.methodId) { mMethodSpinner.setSelection(data.getPosition() + 1); break; } data.moveToNext(); } } else { mMethodSpinner.setSelection(0); } } break; case ACCOUNTS_CURSOR: mAccountsAdapter.swapCursor(data); mAccounts = new Account[data.getCount()]; if (mSavedInstance) { mTransaction.accountId = mAccountId; mTransaction.transfer_account = mTransferAccountId; } data.moveToFirst(); boolean selectionSet = false; String currencyExtra = getIntent().getStringExtra(KEY_CURRENCY); while (data.isAfterLast() == false) { int position = data.getPosition(); Account a = Account.fromCacheOrFromCursor(data); mAccounts[position] = a; if (!selectionSet && (a.currency.getCurrencyCode().equals(currencyExtra) || (currencyExtra == null && a.getId().equals(mTransaction.accountId)))) { mAccountSpinner.setSelection(position); setAccountLabel(a); selectionSet = true; } data.moveToNext(); } //if the accountId we have been passed does not exist, we select the first entry if (mAccountSpinner.getSelectedItemPosition() == android.widget.AdapterView.INVALID_POSITION) { mAccountSpinner.setSelection(0); mTransaction.accountId = mAccounts[0].getId(); setAccountLabel(mAccounts[0]); } if (mOperationType == MyExpenses.TYPE_TRANSFER) { mTransferAccountCursor = new FilterCursorWrapper(data); int selectedPosition = setTransferAccountFilterMap(); mTransferAccountsAdapter.swapCursor(mTransferAccountCursor); mTransferAccountSpinner.setSelection(selectedPosition); mTransaction.transfer_account = mTransferAccountSpinner.getSelectedItemId(); configureTransferInput(); if (!mNewInstance && !(mTransaction instanceof Template)) { isProcessingLinkedAmountInputs = true; mTransferAmountText.setAmount(mTransaction.getTransferAmount().getAmountMajor().abs()); updateExchangeRates(); isProcessingLinkedAmountInputs = false; } } else { //the methods cursor is based on the current account, //hence it is loaded only after the accounts cursor is loaded if (!(mTransaction instanceof SplitPartCategory)) { mManager.initLoader(METHODS_CURSOR, null, this); } } mTypeButton.setEnabled(true); configureType(); configureStatusSpinner(); if (mIsResumed) setupListeners(); break; case LAST_EXCHANGE_CURSOR: if (data.moveToFirst()) { final Currency currency1 = getCurrentAccount().currency; final Currency currency2 = Account .getInstanceFromDb(mTransferAccountSpinner.getSelectedItemId()).currency; if (currency1.getCurrencyCode().equals(data.getString(0)) && currency2.getCurrencyCode().equals(data.getString(1))) { BigDecimal amount = new Money(currency1, data.getLong(2)).getAmountMajor(); BigDecimal transferAmount = new Money(currency2, data.getLong(3)).getAmountMajor(); BigDecimal exchangeRate = amount.compareTo(nullValue) != 0 ? transferAmount.divide(amount, EXCHANGE_RATE_FRACTION_DIGITS, RoundingMode.DOWN) : nullValue; if (exchangeRate.compareTo(nullValue) != 0) { mExchangeRate1Text.setAmount(exchangeRate); } } } } }
From source file:cm.aptoide.pt.MainActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { switch (loader.getId()) { case AVAILABLE_LOADER: availableAdapter.swapCursor(data); if (scrollMemory.get(depth) != null) { ListViewPosition lvp = scrollMemory.get(depth); availableListView.setSelectionFromTop(lvp.index, lvp.top); }/* ww w . j a v a 2s .c o m*/ break; case INSTALLED_LOADER: installedAdapter.swapCursor(data); break; case UPDATES_LOADER: updatesAdapter.swapCursor(data); if (data.getCount() == 1) { updateView.findViewById(R.id.all_apps_up_to_date).setVisibility(View.GONE); updateView.findViewById(R.id.update_all_view_layout).setVisibility(View.GONE); } else if (data.getCount() > 1) { updateView.findViewById(R.id.update_all_view_layout).setVisibility(View.VISIBLE); // updateView.findViewById(R.id.update_all_view_layout).startAnimation(AnimationUtils.loadAnimation(mContext, // android.R.anim.fade_in)); updateView.findViewById(R.id.all_apps_up_to_date).setVisibility(View.GONE); } else { updateView.findViewById(R.id.update_all_view_layout).setVisibility(View.GONE); updateView.findViewById(R.id.all_apps_up_to_date).setVisibility(View.VISIBLE); ((TextView) updateView.findViewById(R.id.all_apps_up_to_date)).setText(R.string.all_updated); } break; default: break; } pb.setVisibility(View.GONE); if (availableListView.getAdapter().getCount() > 2 || joinStores_boolean) { joinStores.setVisibility(View.VISIBLE); } else { joinStores.setVisibility(View.INVISIBLE); } if (availableListView.getAdapter().getCount() > 1) { pb.setVisibility(View.GONE); } else if (depth == ListDepth.STORES) { pb.setVisibility(View.VISIBLE); pb.setText(R.string.add_store_button_below); } }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
@Override public void onLoadFinished(Loader<Cursor> l, Cursor c) { if (c == null) return;//from ww w .j a v a 2 s .c o m int flag = (int) Math.pow(2, l.getId() + 1); if ((OpenCursor.LoadedCursors & flag) == flag) { c.close(); return; } OpenCursor.LoadedCursors |= flag; Logger.LogVerbose("LoadedCursors: " + OpenCursor.LoadedCursors); OpenCursor mParent = mVideoParent; if (l.getId() == 1) mParent = mPhotoParent; else if (l.getId() == 2) mParent = mMusicParent; else if (l.getId() == 3) mParent = mApkParent; mParent.setCursor(c); mBookmarks.refresh(); OpenFragment f = getSelectedFragment(); if (f instanceof ContentFragment && ((ContentFragment) f).getPath().equals(mParent)) ((ContentFragment) f).refreshData(null, false); }