List of usage examples for android.app Activity getContentResolver
@Override
public ContentResolver getContentResolver()
From source file:com.rjfun.cordova.sms.SMSPlugin.java
private PluginResult listSMS(JSONObject filter, CallbackContext callbackContext) { Log.i(LOGTAG, ACTION_LIST_SMS);// www . j av a 2s .co m String uri_filter = filter.has(BOX) ? filter.optString(BOX) : "inbox"; int fread = filter.has(READ) ? filter.optInt(READ) : -1; int fid = filter.has("_id") ? filter.optInt("_id") : -1; String faddress = filter.optString(ADDRESS); String fcontent = filter.optString(BODY); int indexFrom = filter.has("indexFrom") ? filter.optInt("indexFrom") : 0; int maxCount = filter.has("maxCount") ? filter.optInt("maxCount") : 10; JSONArray jsons = new JSONArray(); Activity ctx = this.cordova.getActivity(); Uri uri = Uri.parse((SMS_URI_ALL + uri_filter)); Cursor cur = ctx.getContentResolver().query(uri, (String[]) null, "", (String[]) null, null); int i = 0; while (cur.moveToNext()) { JSONObject json; boolean matchFilter = false; if (fid > -1) { matchFilter = (fid == cur.getInt(cur.getColumnIndex("_id"))); } else if (fread > -1) { matchFilter = (fread == cur.getInt(cur.getColumnIndex(READ))); } else if (faddress.length() > 0) { matchFilter = faddress.equals(cur.getString(cur.getColumnIndex(ADDRESS)).trim()); } else if (fcontent.length() > 0) { matchFilter = fcontent.equals(cur.getString(cur.getColumnIndex(BODY)).trim()); } else { matchFilter = true; } if (!matchFilter) continue; if (i < indexFrom) continue; if (i >= indexFrom + maxCount) break; ++i; if ((json = this.getJsonFromCursor(cur)) == null) { callbackContext.error("failed to get json from cursor"); cur.close(); return null; } jsons.put((Object) json); } cur.close(); callbackContext.success(jsons); return null; }
From source file:ca.rmen.android.palidamuerte.app.poem.detail.PoemDetailFragment.java
private void updateView(final Activity activity, final View rootView) { Log.v(TAG, "updateView"); new AsyncTask<Void, Void, PoemCursor>() { @Override/*from w ww .j av a 2s . c o m*/ protected PoemCursor doInBackground(Void... params) { if (getArguments().containsKey(ARG_ITEM_ID)) { long poemId = getArguments().getLong(ARG_ITEM_ID); PoemCursor poemCursor = new PoemSelection().id(poemId).query(activity.getContentResolver()); if (poemCursor.moveToFirst()) return poemCursor; poemCursor.close(); } return null; } @Override protected void onPostExecute(PoemCursor poemCursor) { boolean favorite = poemCursor.getIsFavorite(); if (favorite != mIsFavorite) { mIsFavorite = favorite; activity.invalidateOptionsMenu(); } TextView tvTitleView = (TextView) rootView.findViewById(R.id.title); tvTitleView.setText(poemCursor.getTitle()); String preContent = poemCursor.getPreContent(); TextView preContentView = (TextView) rootView.findViewById(R.id.pre_content); preContentView.setVisibility(TextUtils.isEmpty(preContent) ? View.GONE : View.VISIBLE); preContentView.setText(preContent); ((TextView) rootView.findViewById(R.id.content)).setText(poemCursor.getContent()); String poemTypeAndNumber = Poems.getPoemNumberString(activity, poemCursor); TextView tvPoemTypeAndNumber = (TextView) rootView.findViewById(R.id.poem_type_and_number); tvPoemTypeAndNumber.setVisibility(TextUtils.isEmpty(poemTypeAndNumber) ? View.GONE : View.VISIBLE); tvPoemTypeAndNumber.setText(poemTypeAndNumber); String locationDateString = Poems.getLocationDateString(activity, poemCursor); ((TextView) rootView.findViewById(R.id.author)).setText(R.string.author); ((TextView) rootView.findViewById(R.id.location_and_date)).setText(locationDateString); poemCursor.close(); } }.execute(); }
From source file:com.kyakujin.android.tagnotepad.ui.NoteEditFragment.java
/** * ?<br>//ww w.j a va 2s. c o m * {@link NoteListFragment}}????????<br> * {@link NoteEditFragment}???? */ private void extractNoteData() { Activity context = getActivity(); if (context != null) { if (mNoteUri != null) { Cursor c = null; try { c = context.getContentResolver().query(mNoteUri, NotesQuery.PROJECTION, null, null, null); if (c.moveToFirst()) { mTitleText.setText(c.getString(NotesQuery.TITLE)); mBodyText.setText(c.getString(NotesQuery.BODY)); } } finally { if (c != null) { c.close(); } } } } mBodyTextViewMode.setText(mBodyText.getText()); }
From source file:com.conferenceengineer.android.iosched.ui.ScheduleFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); activity.getContentResolver().registerContentObserver(ScheduleContract.Sessions.CONTENT_URI, true, mObserver);/* w w w.j a v a 2s . co m*/ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity); sp.registerOnSharedPreferenceChangeListener(mPrefChangeListener); }
From source file:com.rjfun.cordova.sms.SMSPlugin.java
private PluginResult deleteSMS(JSONObject filter, CallbackContext callbackContext) { Log.d(LOGTAG, ACTION_DELETE_SMS);/*from w w w .j a v a 2 s . com*/ String uri_filter = filter.has(BOX) ? filter.optString(BOX) : "inbox"; int fread = filter.has(READ) ? filter.optInt(READ) : -1; int fid = filter.has("_id") ? filter.optInt("_id") : -1; String faddress = filter.optString(ADDRESS); String fcontent = filter.optString(BODY); Activity ctx = this.cordova.getActivity(); int n = 0; try { Uri uri = Uri.parse((SMS_URI_ALL + uri_filter)); Cursor cur = ctx.getContentResolver().query(uri, (String[]) null, "", (String[]) null, null); while (cur.moveToNext()) { int id = cur.getInt(cur.getColumnIndex("_id")); boolean matchId = fid > -1 && fid == id; int read = cur.getInt(cur.getColumnIndex(READ)); boolean matchRead = fread > -1 && fread == read; String address = cur.getString(cur.getColumnIndex(ADDRESS)).trim(); boolean matchAddr = faddress.length() > 0 && address.equals(faddress); String body = cur.getString(cur.getColumnIndex(BODY)).trim(); boolean matchContent = fcontent.length() > 0 && body.equals(fcontent); if (!matchId && !matchRead && !matchAddr && !matchContent) continue; ctx.getContentResolver().delete(uri, "_id=" + id, (String[]) null); ++n; } callbackContext.success(n); } catch (Exception e) { callbackContext.error(e.toString()); } return null; }
From source file:com.matthewmitchell.peercoin_android_wallet.ui.TransactionsListFragment.java
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AbstractWalletActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.resolver = activity.getContentResolver(); this.loaderManager = getLoaderManager(); }
From source file:com.redoceanred.unity.android.RORAudioPlayer.java
public void pickAudioDialog() { String[] proj = { MediaStore.Audio.AudioColumns.TITLE }; Activity activity = null; if (mFragment != null) { activity = mFragment.get().getActivity(); } else if (mFragmentActivity != null) { activity = mFragmentActivity.get(); } else {/* w w w . ja v a2 s .c o m*/ activity = mActivity.get(); } Cursor cursor = activity.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, null, null, null); int audioCount = cursor.getCount(); String[] audioTitleArray = new String[0]; if (audioCount == 0) { // Audio?????. } else { audioTitleArray = new String[audioCount]; int count = 0; while (cursor.moveToNext()) { String audioTitle = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.AudioColumns.TITLE)); audioTitleArray[count] = audioTitle; count++; } } RORDialogFragment.Builder builder = null; if (mFragment != null) { builder = new RORDialogFragment.Builder(mFragment.get().getActivity()); } else if (mFragmentActivity != null) { builder = new RORDialogFragment.Builder(mFragmentActivity.get()); } else { builder = new RORDialogFragment.Builder(mActivity.get()); } builder.setTitle("?????"); final String[] finalTitleArray = audioTitleArray; builder.setItems(audioTitleArray, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String selectTitle = finalTitleArray[which]; String[] proj = { MediaStore.Audio.AudioColumns.DATA }; Activity activity = null; if (mFragment != null) { activity = mFragment.get().getActivity(); } else if (mFragmentActivity != null) { activity = mFragmentActivity.get(); } else { activity = mActivity.get(); } String[] selection = { selectTitle }; Cursor cursor = activity.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, MediaStore.Audio.AudioColumns.TITLE + "=?", selection, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.DATA); cursor.moveToFirst(); mAudioFilePath = cursor.getString(column_index); setDataSource(); if (mPickListener != null) { mPickListener.onPickAudio(true); } } }); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (mPickListener != null) { mPickListener.onPickAudio(false); } } }); if (mFragment != null) { RORDialogFragment dialog = RORDialogFragment.getInstanse(builder); dialog.show(mFragment.get().getFragmentManager(), "test"); } else if (mFragmentActivity != null) { RORDialogFragment dialog = RORDialogFragment.getInstanse(builder); dialog.show(mFragmentActivity.get().getSupportFragmentManager(), "test"); } else { // Activity?????????????.Leak????. final RORDialogFragment.Builder finalBuilder = builder; mActivity.get().runOnUiThread(new Runnable() { @Override public void run() { finalBuilder.create().show(); } }); } }
From source file:com.feathercoin.wallet.feathercoin.ui.TransactionsListFragment.java
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AbstractWalletActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.wallet = application.getWallet(); this.prefs = PreferenceManager.getDefaultSharedPreferences(activity); this.resolver = activity.getContentResolver(); this.loaderManager = getLoaderManager(); }
From source file:org.level28.android.moca.ui.schedule.SessionListFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); // This is where the observer magic happens: register our little voyeur // with the activity's content resolver activity.getContentResolver().registerContentObserver(Sessions.CONTENT_URI, true, mObserver); }
From source file:ca.rmen.android.palidamuerte.app.poem.detail.PoemDetailFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Log.v(TAG, "onOptionsItemSelected"); if (item.getItemId() == R.id.action_favorite) { final Activity activity = getActivity(); final View rootView = getView(); new AsyncTask<Void, Void, Void>() { @Override// ww w . j a v a 2 s . c o m protected Void doInBackground(Void... params) { // Write the poem favorite field. long poemId = getArguments().getLong(ARG_ITEM_ID); PoemSelection poemSelection = new PoemSelection().id(poemId); PoemCursor cursor = poemSelection.query(activity.getContentResolver()); try { if (cursor.moveToFirst()) { boolean wasFavorite = cursor.getIsFavorite(); boolean isFavorite = !wasFavorite; new PoemContentValues().putIsFavorite(isFavorite).update(activity.getContentResolver(), poemSelection); } } finally { cursor.close(); } return null; } @Override protected void onPostExecute(Void params) { // Reread the poem updateView(activity, rootView); } }.execute(); } else if (item.getItemId() == R.id.action_music) { MusicPlayer.getInstance(getActivity()).toggle(); final Activity activity = getActivity(); mHandler.postDelayed(new Runnable() { @Override public void run() { activity.invalidateOptionsMenu(); } }, 200); } return super.onOptionsItemSelected(item); }