Example usage for android.support.v4.content CursorLoader loadInBackground

List of usage examples for android.support.v4.content CursorLoader loadInBackground

Introduction

In this page you can find the example usage for android.support.v4.content CursorLoader loadInBackground.

Prototype

@Override
    public Cursor loadInBackground() 

Source Link

Usage

From source file:com.arcusapp.soundbox.data.MediaProvider.java

/**
 * Returns a list of SongEntries for the Songs in the specified directory.
 * // w w w . j ava 2s .c  o  m
 * @param directory the directory in which to search
 * @param projection one key from {@linkplain MediaStore.Audio.Media} to associate on the SongEntry's value
 * @return a list of SongEntries
 */
public List<SongEntry> getSongsInAFolder(File directory, String projection) {
    List<SongEntry> songs = new ArrayList<SongEntry>();
    String folder = directory.getPath();

    String[] cursorProjection = new String[] { MediaStore.Audio.Media._ID, projection };
    String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0 AND " + "SUBSTR(" + MediaStore.Audio.Media.DATA
            + ",0 , LENGTH('" + folder + "')+1) = '" + folder + "' AND " + "SUBSTR("
            + MediaStore.Audio.Media.DATA + ",LENGTH('" + folder + "')+1, 200) LIKE '/%.mp3' AND " + "SUBSTR("
            + MediaStore.Audio.Media.DATA + ",LENGTH('" + folder + "')+1, 200) NOT LIKE '/%/%.mp3'";

    String sortOrder = MediaStore.Audio.Media.TITLE;

    CursorLoader cl = new CursorLoader(SoundBoxApplication.getContext(),
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, cursorProjection, selection, null, sortOrder);
    myCursor = cl.loadInBackground();

    while (myCursor.moveToNext()) {
        songs.add(new SongEntry(myCursor.getString(0), myCursor.getString(1)));
    }

    CursorLoader cl2 = new CursorLoader(SoundBoxApplication.getContext(),
            MediaStore.Audio.Media.INTERNAL_CONTENT_URI, cursorProjection, selection, null, sortOrder);
    myCursor = cl2.loadInBackground();

    while (myCursor.moveToNext()) {
        songs.add(new SongEntry(myCursor.getString(0), myCursor.getString(1)));
    }

    myCursor.close();
    return songs;
}

From source file:com.laer.easycast.ImagePane.java

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };

    //This method was deprecated in API level 11
    //Cursor cursor = managedQuery(contentUri, proj, null, null, null);

    CursorLoader cursorLoader = new CursorLoader(getActivity(), contentUri, proj, null, null, null);
    Cursor cursor = cursorLoader.loadInBackground();

    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();//from w  w  w  .ja va 2  s .c  o  m
    return cursor.getString(column_index);
}

From source file:com.handpoint.headstart.client.ui.ReceiptActivity.java

private String getFilePathFromContentUrl(String url) {
    String[] proj = { MediaStore.Images.Media.DATA };
    CursorLoader loader = new CursorLoader(this, Uri.parse(url), proj, null, null, null);
    Cursor cursor = loader.loadInBackground();
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();/*ww w .j av  a 2s.  c om*/
    return cursor.getString(column_index);
}

From source file:ca.ualberta.app.activity.CreateAnswerActivity.java

/**
 * function that user to get the image path
 * //w  ww  . j  av a  2 s.c o m
 * @param context
 *            the context
 * @param imageFileUri
 *            the imageFileUri that contains the URL of the image
 * @return return the imagePath of the image
 */
private String getPath(Context context, Uri imageFileUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    String result = null;

    CursorLoader cursorLoader = new CursorLoader(context, imageFileUri, proj, null, null, null);
    Cursor cursor = cursorLoader.loadInBackground();

    if (cursor != null) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        result = cursor.getString(column_index);
    }
    return result;
}

From source file:com.game.simple.Game3.java

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    CursorLoader loader = new CursorLoader(self, contentUri, proj, null, null, null);
    Cursor cursor = loader.loadInBackground();
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();//w w  w  . ja v  a  2  s.c om
    return cursor.getString(column_index);
}

From source file:de.elanev.studip.android.app.widget.UserListFragment.java

/**
 * Creating floating context menu//  w w w . j  a va 2s. c  om
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getActivity().getMenuInflater();
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    Cursor listItemCursor = (Cursor) mListView.getAdapter().getItem(info.position);

    final String[] projection = new String[] {
            ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_GROUP_NAME,
            ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_GROUP_ID,
            ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_ID };
    final String contactId = listItemCursor
            .getString(listItemCursor.getColumnIndex(UsersContract.Columns.USER_ID));

    CursorLoader loader = new CursorLoader(getActivity(),
            ContactsContract.CONTENT_URI_CONTACTS.buildUpon().appendPath(contactId).build(), projection, null,
            null, ContactsContract.Columns.ContactGroups.GROUP_NAME + " ASC");

    final Cursor c = loader.loadInBackground();

    if (c.getCount() <= 0) {
        inflater.inflate(R.menu.user_add_context_menu, menu);
    } else {
        inflater.inflate(R.menu.user_context_menu, menu);
        c.moveToFirst();
        while (!c.isAfterLast()) {
            String currGroupName = c
                    .getString(c.getColumnIndex(ContactsContract.Columns.ContactGroups.GROUP_NAME));
            if (TextUtils.equals(currGroupName, getString(R.string.studip_app_contacts_favorites))) {
                menu.removeItem(R.id.add_to_favorites);
                menu.findItem(R.id.remove_from_favorites).setVisible(true);
            }

            c.moveToNext();
        }

    }
    c.close();
}

From source file:org.xingjitong.ChatFragment.java

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    CursorLoader loader = new CursorLoader(getActivity(), contentUri, proj, null, null, null);
    Cursor cursor = loader.loadInBackground();
    if (cursor != null && cursor.moveToFirst()) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        String result = cursor.getString(column_index);
        cursor.close();/*from www .ja  v  a  2s . c  o m*/
        return result;
    }
    cursor.close();
    return null;
}

From source file:com.markupartist.sthlmtraveling.PlannerFragment.java

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

    // If the activity was started with the "create shortcut" action, we
    // remember this to change the behavior upon a search.
    if (Intent.ACTION_CREATE_SHORTCUT.equals(getActivity().getIntent().getAction())) {
        mCreateShortcut = true;/*w w w . j  a va  2  s  .c  om*/
    }

    if (savedInstanceState != null) {
        mStackLevel = savedInstanceState.getInt("level");
    }

    CursorLoader cursorLoader = new CursorLoader(getActivity(), Journeys.CONTENT_URI, PROJECTION, null, //selection,
            null, //selectionArgs,
            Journeys.HISTORY_SORT_ORDER);
    Cursor cursor = cursorLoader.loadInBackground();
    mAdapter = new JourneyAdapter(getActivity(), cursor);
}

From source file:com.lewa.crazychapter11.MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    switch (requestCode) {
    case PICK_CONTACT:
        if (resultCode == Activity.RESULT_OK) {
            Uri contactData = intent.getData();
            CursorLoader cursorLoader = new CursorLoader(this, contactData, null, null, null, null);

            Cursor cursor = cursorLoader.loadInBackground();
            if (cursor != null && cursor.moveToFirst()) {
                Log.i("algerheContact", " comhere 111");
                String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                String name = cursor
                        .getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
                String phoneNumber = "????";

                Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                        null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId, null, null);
                if (phones == null) {
                    return;
                }// www . java2 s.c  o m
                // Log.i("algerheContact"," comhere 222 phones.moveToFirst()="+phones.moveToFirst());
                if (phones.moveToFirst()) {
                    phoneNumber = phones
                            .getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                }

                phones.close();
                EditText show = (EditText) findViewById(R.id.show);

                show.setText(name);
                EditText phone = (EditText) findViewById(R.id.phone);
                phone.setText(phoneNumber);

                show.setVisibility(View.GONE);
                phone.setVisibility(View.GONE);
            }
            cursor.close();
        }
        break;
    }

    if (requestCode == 0 && resultCode == 0 && intent != null) {
        Bundle data = intent.getExtras();
        if (data == null) {
            return;
        }
        String resultArms = data.getString("armType");
        String showArms = "?" + resultArms;
        show_txt = (EditText) findViewById(R.id.show_txt);
        if (resultArms != null && show_txt != null) {
            show_txt.setText(showArms);
        }
    }
}

From source file:co.taqat.call.ChatFragment.java

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    CursorLoader loader = new CursorLoader(getActivity(), contentUri, proj, null, null, null);
    Cursor cursor = loader.loadInBackground();
    if (cursor != null && cursor.moveToFirst()) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        String result = cursor.getString(column_index);
        cursor.close();//  w  w w.j  a v  a 2  s  . c o m
        return result;
    }
    return null;
}