List of usage examples for android.app Activity getContentResolver
@Override
public ContentResolver getContentResolver()
From source file:com.conferenceengineer.android.iosched.ui.SessionsFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); if (!(activity instanceof Callbacks)) { throw new ClassCastException("Activity must implement fragment's callbacks."); }//from w w w . j a v a 2s . c o m mCallbacks = (Callbacks) activity; activity.getContentResolver().registerContentObserver(ScheduleContract.Sessions.CONTENT_URI, true, mObserver); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity); sp.registerOnSharedPreferenceChangeListener(mPrefChangeListener); }
From source file:com.google.android.apps.mytracks.fragments.AddEmailsDialogFragment.java
/** * Gets the cursor/*w w w.jav a 2s.c om*/ * * @param activity the activity * @param constraint the constraint */ private Cursor getCursor(Activity activity, CharSequence constraint) { String order = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"; String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'"; if (constraint != null) { selection += " AND (" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE '%" + constraint + "%' OR " + ContactsContract.CommonDataKinds.Email.DATA + " LIKE '%" + constraint + "%' )"; } String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA }; Uri uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI; return activity.getContentResolver().query(uri, projection, selection, null, order); }
From source file:com.ecml.FileUri.java
/** Return the file contents as a byte array. * If any IO error occurs, return null. *//*w ww . j ava 2s.c om*/ public byte[] getData(Activity activity) { try { byte[] data; int totallen, len, offset; // First, determine the file length data = new byte[4096]; InputStream file; String uriString = uri.toString(); if (uriString.startsWith("file:///android_asset/")) { AssetManager asset = activity.getResources().getAssets(); String filepath = uriString.replace("file:///android_asset/", ""); file = asset.open(filepath); } else if (uriString.startsWith("content://")) { ContentResolver resolver = activity.getContentResolver(); file = resolver.openInputStream(uri); } else { file = new FileInputStream(uri.getPath()); } totallen = 0; len = file.read(data, 0, 4096); while (len > 0) { totallen += len; len = file.read(data, 0, 4096); } file.close(); // Now read in the data offset = 0; data = new byte[totallen]; if (uriString.startsWith("file:///android_asset/")) { AssetManager asset = activity.getResources().getAssets(); String filepath = uriString.replace("file:///android_asset/", ""); file = asset.open(filepath); } else if (uriString.startsWith("content://")) { ContentResolver resolver = activity.getContentResolver(); file = resolver.openInputStream(uri); } else { file = new FileInputStream(uri.getPath()); } while (offset < totallen) { len = file.read(data, offset, totallen - offset); if (len <= 0) { throw new MidiFileException("Error reading midi file", offset); } offset += len; } return data; } catch (Exception e) { return null; } }
From source file:com.kncwallet.wallet.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.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE); this.resolver = activity.getContentResolver(); this.loaderManager = getLoaderManager(); }
From source file:org.catrobat.catroid.ui.controller.LookController.java
public void loadImageIntoCatroid(Intent intent, Activity activity, ArrayList<LookData> lookDataList, LookFragment fragment) {/*from w w w.j a v a 2 s. co m*/ String originalImagePath = ""; //get path of image - will work for most applications Bundle bundle = intent.getExtras(); if (bundle != null) { originalImagePath = bundle.getString(Constants.EXTRA_PICTURE_PATH_POCKET_PAINT); } Uri imageUri = intent.getData(); if (imageUri != null) { Cursor cursor = activity.getContentResolver().query(imageUri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null); if (cursor != null) { cursor.moveToFirst(); originalImagePath = cursor.getString(0); cursor.close(); } } if (originalImagePath == null || originalImagePath.equals("")) { Bundle arguments = new Bundle(); arguments.putParcelable(LOADER_ARGUMENTS_IMAGE_URI, intent.getData()); fragment.initOrRestartLoader(arguments); } else { copyImageToCatroid(originalImagePath, activity, lookDataList, fragment); } }
From source file:com.google.samples.apps.iosched.map.MapFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); if (!(activity instanceof Callbacks)) { throw new ClassCastException("Activity must implement fragment's callbacks."); }/* w w w. j ava2 s . com*/ mCallbacks = (Callbacks) activity; activity.getContentResolver().registerContentObserver(ScheduleContract.MapMarkers.CONTENT_URI, true, mObserver); activity.getContentResolver().registerContentObserver(ScheduleContract.MapTiles.CONTENT_URI, true, mObserver); }
From source file:com.xandy.calendar.event.EditEventFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mActivity = activity;/*from www. j a v a 2 s. c om*/ mHelper = new EditEventHelper(activity, null); mHandler = new QueryHandler(activity.getContentResolver()); mModel = new CalendarEventModel(activity, mIntent); mInputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); mUseCustomActionBar = !Utils.getConfigBool(mActivity, R.bool.multiple_pane_config); }
From source file:com.android.calendar.event.EditEventFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mContext = (AppCompatActivity) activity; mHelper = new EditEventHelper(activity, null); mHandler = new QueryHandler(activity.getContentResolver()); mModel = new CalendarEventModel(activity, mIntent); mInputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); mUseCustomActionBar = !Utils.getConfigBool(mContext, R.bool.multiple_pane_config); }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.MapFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); if (!(activity instanceof Callbacks)) { throw new ClassCastException("Activity must implement fragment's callbacks."); }/*from w ww . j a v a 2 s . c om*/ mCallbacks = (Callbacks) activity; activity.getContentResolver().registerContentObserver(ScheduleContract.MapMarkers.CONTENT_URI, true, mObserver); activity.getContentResolver().registerContentObserver(ScheduleContract.MapTiles.CONTENT_URI, true, mObserver); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity); sp.registerOnSharedPreferenceChangeListener(mPrefChangeListener); }
From source file:de.schildbach.litecoinwallet.ui.SendCoinsFragment.java
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AbstractBindServiceActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.prefs = PreferenceManager.getDefaultSharedPreferences(activity); this.wallet = application.getWallet(); this.contentResolver = activity.getContentResolver(); this.loaderManager = getLoaderManager(); }