Example usage for android.database Cursor moveToPosition

List of usage examples for android.database Cursor moveToPosition

Introduction

In this page you can find the example usage for android.database Cursor moveToPosition.

Prototype

boolean moveToPosition(int position);

Source Link

Document

Move the cursor to an absolute position.

Usage

From source file:inc.bait.jubilee.ui.fragments.ContactsListFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    final Cursor cursor = adapter.getCursor();
    cursor.moveToPosition(position);
    final Uri uri = Contacts.getLookupUri(cursor.getLong(ContactsQuery.ID),
            cursor.getString(ContactsQuery.LOOKUP_KEY));
    contactsInteractionListener.onContactSelected(uri);
}

From source file:mobisocial.musubi.ui.widget.DbObjCursorAdapter.java

boolean moveCursorToPosition(Cursor cursor, int position) {
    return cursor.moveToPosition(cursor.getCount() - position - 1);
}

From source file:com.ogunwale.android.app.yaps.ui.PhotosActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    mSourceSelection = SettingsManager.getInstance(getApplicationContext()).getAlbumSelection();

    setContentView(R.layout.activity_photos);

    // Set-up cursor adapter
    mAdapter = new PhotosSimpleCursorAdapter(this);

    // Set-up thumbnail grid
    mGridView = (TwoWayGridView) findViewById(R.id.photo_gridview);
    mGridView.setAdapter(mAdapter);/*from w  w  w  .  ja  v a 2  s.  com*/
    mGridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(TwoWayAdapterView<?> parent, View view, int position, long id) {
            Cursor cursor = mAdapter.getCursor();
            if (cursor.moveToPosition(position)) {
                DialogFragment df = TransferDialogFragment.newInstance(cursor, id);
                df.show(getFragmentManager(), "transfer_dialog");
            } else {
                Log.e(sTAG, "Can not move cursor to: " + position);
            }
        }
    });

    // Prepare the database loader.
    getLoaderManager().initLoader(0, null, this);

    // Register for local broadcasts
    IntentFilter iFilter = new IntentFilter();
    iFilter.addAction(Extras.ACTION_SET_PHOTO_SOURCE_FACEBOOK);
    iFilter.addAction(Extras.ACTION_SET_PHOTO_SOURCE_PICASA);
    iFilter.addAction(Extras.ACTION_REMOTE_ALBUM_REQUEST_COMPLETE);
    LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(mLocalBroadcastReceiver,
            iFilter);
}

From source file:com.supremainc.biostar2.base.BaseListCursorAdapter.java

@Override
public Object getItem(int position) {
    Cursor cursor = getCursor();
    PushNotification item = null;/*from   w ww . ja  v a2 s. c om*/
    if (cursor.moveToPosition(position)) {
        item = mDBProvider.get(cursor);
    }

    return item;
}

From source file:csms19.inapp.msg.customgallery.ImageFragment.java

private void setAdapter(Cursor imagecursor) {

    if (imagecursor.getCount() > 0) {

        mGalleryModelList = new ArrayList<MediaModel>();

        for (int i = 0; i < imagecursor.getCount(); i++) {
            imagecursor.moveToPosition(i);
            int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
            MediaModel galleryModel = new MediaModel(imagecursor.getString(dataColumnIndex).toString(), false);
            mGalleryModelList.add(galleryModel);
        }/*from w ww  .  j  av a 2 s  . com*/

        mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false);
        mImageGridView.setAdapter(mImageAdapter);
    } else {
        Toast.makeText(getActivity(), "no media file available", Toast.LENGTH_SHORT).show();
    }

    mImageGridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = adapter.getItem(position);
            File file = new File(galleryModel.url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "image/*");
            startActivity(intent);
            return true;
        }
    });

    mImageGridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // update the mStatus of each category in the adapter
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = adapter.getItem(position);

            if (!galleryModel.status) {
                long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()),
                        false);
                if (size != 0) {
                    Toast.makeText(
                            getActivity(), "File size greater then" + "  "
                                    + MediaChooserConstants.SELECTED_IMAGE_SIZE_IN_MB + " " + "mb",
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) {
                    if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) {
                        Toast.makeText(
                                getActivity(), "Max selected file " + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + "file",
                                Toast.LENGTH_SHORT).show();
                        return;
                    } else {
                        Toast.makeText(
                                getActivity(), "Max selected file " + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + "file",
                                Toast.LENGTH_SHORT).show();
                        return;
                    }

                }
            }

            // inverse the status
            galleryModel.status = !galleryModel.status;

            adapter.notifyDataSetChanged();

            if (galleryModel.status) {
                mSelectedItems.add(galleryModel.url.toString());
                MediaChooserConstants.SELECTED_MEDIA_COUNT++;

            } else {
                mSelectedItems.remove(galleryModel.url.toString().trim());
                MediaChooserConstants.SELECTED_MEDIA_COUNT--;
            }

            if (mCallback != null) {
                mCallback.onImageSelected(mSelectedItems.size());
                Intent intent = new Intent();
                intent.putStringArrayListExtra("list", mSelectedItems);
                getActivity().setResult(Activity.RESULT_OK, intent);
            }

        }
    });
}

From source file:org.odk.collect.android.dao.InstancesDao.java

/**
 * Returns all instances available through the cursor and closes the cursor.
 *///from  w  w w .j  av  a2s  . c  om
public List<Instance> getInstancesFromCursor(Cursor cursor) {
    List<Instance> instances = new ArrayList<>();
    if (cursor != null) {
        try {
            cursor.moveToPosition(-1);
            while (cursor.moveToNext()) {
                int displayNameColumnIndex = cursor
                        .getColumnIndex(InstanceProviderAPI.InstanceColumns.DISPLAY_NAME);
                int submissionUriColumnIndex = cursor
                        .getColumnIndex(InstanceProviderAPI.InstanceColumns.SUBMISSION_URI);
                int canEditWhenCompleteIndex = cursor
                        .getColumnIndex(InstanceProviderAPI.InstanceColumns.CAN_EDIT_WHEN_COMPLETE);
                int instanceFilePathIndex = cursor
                        .getColumnIndex(InstanceProviderAPI.InstanceColumns.INSTANCE_FILE_PATH);
                int jrFormIdColumnIndex = cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.JR_FORM_ID);
                int jrVersionColumnIndex = cursor
                        .getColumnIndex(InstanceProviderAPI.InstanceColumns.JR_VERSION);
                int statusColumnIndex = cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.STATUS);
                int lastStatusChangeDateColumnIndex = cursor
                        .getColumnIndex(InstanceProviderAPI.InstanceColumns.LAST_STATUS_CHANGE_DATE);
                int displaySubtextColumnIndex = cursor
                        .getColumnIndex(InstanceProviderAPI.InstanceColumns.DISPLAY_SUBTEXT);
                int deletedDateColumnIndex = cursor
                        .getColumnIndex(InstanceProviderAPI.InstanceColumns.DELETED_DATE);

                int databaseIdIndex = cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns._ID);

                Instance instance = new Instance.Builder().displayName(cursor.getString(displayNameColumnIndex))
                        .submissionUri(cursor.getString(submissionUriColumnIndex))
                        .canEditWhenComplete(cursor.getString(canEditWhenCompleteIndex))
                        .instanceFilePath(cursor.getString(instanceFilePathIndex))
                        .jrFormId(cursor.getString(jrFormIdColumnIndex))
                        .jrVersion(cursor.getString(jrVersionColumnIndex))
                        .status(cursor.getString(statusColumnIndex))
                        .lastStatusChangeDate(cursor.getLong(lastStatusChangeDateColumnIndex))
                        .displaySubtext(cursor.getString(displaySubtextColumnIndex))
                        .deletedDate(cursor.getLong(deletedDateColumnIndex))
                        .databaseId(cursor.getLong(databaseIdIndex)).build();

                instances.add(instance);
            }
        } finally {
            cursor.close();
        }
    }
    return instances;
}

From source file:com.media.LuYinFragment.java

private void setAdapter(Cursor imagecursor) {
    if (imagecursor.getCount() > 0) {

        mGalleryModelList = new ArrayList<MediaModel>();

        for (int i = 0; i < imagecursor.getCount(); i++) {
            imagecursor.moveToPosition(i);
            int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Audio.Media.DATA);
            MediaModel galleryModel = new MediaModel(imagecursor.getString(dataColumnIndex).toString(), false);
            mGalleryModelList.add(galleryModel);
        }/*from w  w w.j  a v  a  2  s. c o  m*/

        mImageAdapter = new AudioListViewAdapter(getActivity(), 0, mGalleryModelList, false);
        audioListView.setAdapter(mImageAdapter);
    } else {
        Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                Toast.LENGTH_SHORT).show();
    }

    audioListView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            AudioListViewAdapter adapter = (AudioListViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);
            File file = new File(galleryModel.url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "audio/*");
            startActivity(intent);
            return true;
        }
    });

    audioListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // update the mStatus of each category in the adapter
            AudioListViewAdapter adapter = (AudioListViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);

            if (!galleryModel.status) {
                long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()),
                        false);
                if (size != 0) {
                    Toast.makeText(getActivity(),
                            getActivity().getResources().getString(R.string.file_size_exeeded) + "  "
                                    + MediaChooserConstants.SELECTED_IMAGE_SIZE_IN_MB + " "
                                    + getActivity().getResources().getString(R.string.mb),
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) {
                    if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.file),
                                Toast.LENGTH_SHORT).show();
                        return;
                    } else {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.files),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }

                }
            }

            // inverse the status
            galleryModel.status = !galleryModel.status;

            adapter.notifyDataSetChanged();

            if (galleryModel.status) {
                mSelectedItems.add(galleryModel.url.toString());
                MediaChooserConstants.SELECTED_MEDIA_COUNT++;

            } else {
                mSelectedItems.remove(galleryModel.url.toString().trim());
                MediaChooserConstants.SELECTED_MEDIA_COUNT--;
            }

            if (mCallback != null) {
                mCallback.onLuYinSelected(mSelectedItems.size());
                Intent intent = new Intent();
                intent.putStringArrayListExtra("list", mSelectedItems);
                getActivity().setResult(Activity.RESULT_OK, intent);
            }

        }
    });
}

From source file:com.money.manager.ex.account.AccountListFragment.java

@Override
protected void setResult() {
    Intent result;/* w  w w  .j  a  v  a  2  s . com*/
    if (Intent.ACTION_PICK.equals(mAction)) {
        // take cursor
        Cursor cursor = ((SimpleCursorAdapter) getListAdapter()).getCursor();

        for (int i = 0; i < getListView().getCount(); i++) {
            if (getListView().isItemChecked(i)) {
                cursor.moveToPosition(i);
                result = new Intent();
                result.putExtra(AccountListActivity.INTENT_RESULT_ACCOUNTID,
                        cursor.getInt(cursor.getColumnIndex(Account.ACCOUNTID)));
                result.putExtra(AccountListActivity.INTENT_RESULT_ACCOUNTNAME,
                        cursor.getString(cursor.getColumnIndex(Account.ACCOUNTNAME)));
                getActivity().setResult(Activity.RESULT_OK, result);
                return;
            }
        }
    }
    // return cancel
    getActivity().setResult(AccountListActivity.RESULT_CANCELED);
}

From source file:com.alley.android.ppi.app.OverviewFragment.java

private void openPreferredLocationInMap() {
    if (null != mOverviewAdapter) {
        Cursor c = mOverviewAdapter.getCursor();
        if (null != c) {
            c.moveToPosition(0);
            String posLat = c.getString(COL_COORD_LAT);
            String posLong = c.getString(COL_COORD_LONG);
            Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong);

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(geoLocation);

            if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
                startActivity(intent);//from w ww .ja  v a  2  s .c o m
            } else {
                Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
            }
        }

    }
}