Example usage for android.app Activity getContentResolver

List of usage examples for android.app Activity getContentResolver

Introduction

In this page you can find the example usage for android.app Activity getContentResolver.

Prototype

@Override
    public ContentResolver getContentResolver() 

Source Link

Usage

From source file:de.elanev.studip.android.app.frontend.courses.CourseOverviewFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    final ContentResolver contentResolver = activity.getContentResolver();

    contentResolver.registerContentObserver(CoursesContract.CONTENT_URI, true, mObserverCourse);

    contentResolver.registerContentObserver(EventsContract.CONTENT_URI, true, mObserverEvents);

    contentResolver.registerContentObserver(NewsContract.CONTENT_URI, true, mObserverNews);
}

From source file:nl.atcomputing.spacetravelagency.fragments.PlaceOrderFragment.java

private Order createOrder() {
    Activity activity = getActivity();

    Order order = new Order();

    String android_id = Secure.getString(activity.getContentResolver(), Secure.ANDROID_ID);
    order.setOrderId(android_id);//from  w  ww.j a  v a2 s . c  o m
    order.fillFromDatabase(activity);
    return order;
}

From source file:com.digiplex.extra.grantpermissiondemo.ContactDetailsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    long personId = getArguments().getLong(ContactActivity.SELECTED_CONTACT_ID);// getIntent().getLongExtra("id", 0);
    Activity activity = getActivity();

    Uri phonesUri = Phone.CONTENT_URI;
    String[] projection = new String[] { Phone._ID, Phone.DISPLAY_NAME, Phone.TYPE, Phone.NUMBER, Phone.LABEL };
    String selection = Phone.CONTACT_ID + " = ?";
    String[] selectionArgs = new String[] { Long.toString(personId) };

    mCursor = activity.getContentResolver().query(phonesUri, projection, selection, selectionArgs, null);

    mDisplayName = (TextView) activity.findViewById(R.id.display_name);
    if (mCursor.moveToFirst()) {
        mDisplayName.setText(mCursor.getString(mCursor.getColumnIndex(Phone.DISPLAY_NAME)));
    }//w w  w. j  a v  a  2s  . co m

    ListAdapter adapter = new PhoneNumbersAdapter(this.getActivity(), R.layout.list_item_phone_number, mCursor,
            new String[] { Phone.TYPE, Phone.NUMBER }, new int[] { R.id.label, R.id.phone_number });
    setListAdapter(adapter);
}

From source file:de.vanita5.twittnuker.fragment.support.BaseSupportListFragment.java

public final ContentResolver getContentResolver() {
    final Activity activity = getActivity();
    if (activity != null)
        return activity.getContentResolver();
    return null;/* www. ja  va 2  s  .c  o m*/
}

From source file:de.langerhans.wallet.ui.ImportKeysQrFragment.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.contentResolver = activity.getContentResolver();
    this.loaderManager = getLoaderManager();
}

From source file:it.imwatch.nfclottery.dialogs.WinnersListDialog.java

/**
 * Queries the ContentProvider for winners and returns the
 * newly created Cursor./*from w w  w .j  a  va  2 s  .c  o m*/
 *
 * @return Returns the winners cursor, or null if there was any error
 */
private Cursor updateWinnersCursors() {
    // Load the winners from the ContentProvider
    final Activity activity = getActivity();
    if (activity == null) {
        Log.e(TAG, "Not attached to Activity: cannot update winners cursor");
        return null;
    }

    ContentResolver cr = activity.getContentResolver();

    String[] projection = new String[] { NFCMLContent.Geeks.Columns.ID.getName(),
            NFCMLContent.Geeks.Columns.NAME.getName(), NFCMLContent.Geeks.Columns.EMAIL.getName() };

    return cr.query(NFCMLContent.Geeks.CONTENT_URI, projection,
            NFCMLContent.Geeks.Columns.TIMEWINNER.getName() + "!=0", null,
            NFCMLContent.Geeks.Columns.TIMEWINNER.getName() + " ASC");
}

From source file:org.flerda.android.honeypad.NoteListFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.checkbox:
        Integer position = (Integer) v.getTag(R.id.list);
        if (null != position) {
            ListView lv = getListView();
            int pos = position;
            boolean isChecked = !lv.isItemChecked(pos);
            lv.setItemChecked(pos, isChecked);
            if (!mIsV11) {
                showMultiPanel();//from w  w  w.  ja  v  a2s  . c  o m
            }
        }
        break;
    case R.id.btn_multi_delete: {
        Activity a = getActivity();
        ContentResolver cr = a.getContentResolver();
        ListView lv = mLV;
        int deletedCount = 0;
        /** Badness. Don't loop a delete operation on the UI thread **/
        /** We also assume that the ID's and positions are constant **/
        for (long id : lv.getCheckItemIds()) {
            deletedCount += cr.delete(ContentUris.withAppendedId(NotesProvider.CONTENT_URI, id), null, null);
        }
        // clear any selections
        lv.clearChoices();

        // update container
        mContainerCallback.onNoteDeleted();

        // show a toast to confirm delete
        Toast.makeText(a,
                String.format(getString(R.string.num_deleted), deletedCount, (deletedCount == 1 ? "" : "s")),
                Toast.LENGTH_SHORT).show();
        showMultiPanel();
        break;
    }
    }
}

From source file:com.codinguser.android.contactpicker.ContactDetailsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    long personId = getArguments().getLong(ContactsPickerActivity.SELECTED_CONTACT_ID);// getIntent().getLongExtra("id", 0);
    Activity activity = getActivity();

    Uri phonesUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String[] projection = new String[] { Phone._ID, Phone.DISPLAY_NAME, Phone.TYPE, Phone.NUMBER, Phone.LABEL };
    String selection = ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?";
    String[] selectionArgs = new String[] { Long.toString(personId) };

    mCursor = activity.getContentResolver().query(phonesUri, projection, selection, selectionArgs, null);

    mDisplayName = (TextView) activity.findViewById(R.id.display_name);
    if (mCursor.moveToFirst()) {
        mDisplayName.setText(mCursor.getString(mCursor.getColumnIndex(Phone.DISPLAY_NAME)));
    }//from   w w w. j a v  a  2s . co m

    ListAdapter adapter = new PhoneNumbersAdapter(this.getActivity(), R.layout.list_item_phone_number, mCursor,
            new String[] { Phone.TYPE, Phone.NUMBER }, new int[] { R.id.label, R.id.phone_number });
    setListAdapter(adapter);
}

From source file:com.z299studio.pb.ActionDialog.java

private String getDataColumn(Activity context, Uri uri, String selection, String[] selectionArgs) {

    Cursor cursor = null;/*from w w w  .  j a  v  a 2  s.co m*/
    final String[] projection = { MediaStore.Images.Media.DATA };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndexOrThrow(projection[0]);
            return cursor.getString(columnIndex);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}

From source file:com.redoceanred.unity.android.RORAudioPlayer.java

private String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Audio.AudioColumns.DATA };
    Activity activity = null;
    if (mFragment != null) {
        activity = mFragment.get().getActivity();
    } else if (mFragmentActivity != null) {
        activity = mFragmentActivity.get();
    } else {//www . ja v a2 s. co  m
        activity = mActivity.get();
    }
    Cursor cursor = activity.getContentResolver().query(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}