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:org.chromium.chrome.browser.util.CompatibilityFileProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Cursor source = super.query(uri, projection, selection, selectionArgs, sortOrder);

    String[] columnNames = source.getColumnNames();
    String[] newColumnNames = columnNamesWithData(columnNames);
    if (columnNames == newColumnNames)
        return source;

    MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount());

    source.moveToPosition(-1);
    while (source.moveToNext()) {
        MatrixCursor.RowBuilder row = cursor.newRow();
        for (int i = 0; i < columnNames.length; i++) {
            switch (source.getType(i)) {
            case Cursor.FIELD_TYPE_INTEGER:
                row.add(source.getInt(i));
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                row.add(source.getFloat(i));
                break;
            case Cursor.FIELD_TYPE_STRING:
                row.add(source.getString(i));
                break;
            case Cursor.FIELD_TYPE_BLOB:
                row.add(source.getBlob(i));
                break;
            case Cursor.FIELD_TYPE_NULL:
            default:
                row.add(null);/*w  ww  . j a v a  2s. c o  m*/
                break;
            }
        }
    }

    source.close();
    return cursor;
}

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

/**
 * Returns all forms available through the cursor and closes the cursor.
 *//*from  w  ww .  j av  a2  s.  c om*/
public List<Form> getFormsFromCursor(Cursor cursor) {
    List<Form> forms = new ArrayList<>();
    if (cursor != null) {
        try {
            cursor.moveToPosition(-1);
            while (cursor.moveToNext()) {
                int idColumnIndex = cursor.getColumnIndex(BaseColumns._ID);
                int displayNameColumnIndex = cursor.getColumnIndex(FormsProviderAPI.FormsColumns.DISPLAY_NAME);
                int descriptionColumnIndex = cursor.getColumnIndex(FormsProviderAPI.FormsColumns.DESCRIPTION);
                int jrFormIdColumnIndex = cursor.getColumnIndex(FormsProviderAPI.FormsColumns.JR_FORM_ID);
                int jrVersionColumnIndex = cursor.getColumnIndex(FormsProviderAPI.FormsColumns.JR_VERSION);
                int formFilePathColumnIndex = cursor
                        .getColumnIndex(FormsProviderAPI.FormsColumns.FORM_FILE_PATH);
                int submissionUriColumnIndex = cursor
                        .getColumnIndex(FormsProviderAPI.FormsColumns.SUBMISSION_URI);
                int base64RSAPublicKeyColumnIndex = cursor
                        .getColumnIndex(FormsProviderAPI.FormsColumns.BASE64_RSA_PUBLIC_KEY);
                int displaySubtextColumnIndex = cursor
                        .getColumnIndex(FormsProviderAPI.FormsColumns.DISPLAY_SUBTEXT);
                int md5HashColumnIndex = cursor.getColumnIndex(FormsProviderAPI.FormsColumns.MD5_HASH);
                int dateColumnIndex = cursor.getColumnIndex(FormsProviderAPI.FormsColumns.DATE);
                int jrCacheFilePathColumnIndex = cursor
                        .getColumnIndex(FormsProviderAPI.FormsColumns.JRCACHE_FILE_PATH);
                int formMediaPathColumnIndex = cursor
                        .getColumnIndex(FormsProviderAPI.FormsColumns.FORM_MEDIA_PATH);
                int languageColumnIndex = cursor.getColumnIndex(FormsProviderAPI.FormsColumns.LANGUAGE);
                int autoSendColumnIndex = cursor.getColumnIndex(FormsProviderAPI.FormsColumns.AUTO_SEND);
                int autoDeleteColumnIndex = cursor.getColumnIndex(FormsProviderAPI.FormsColumns.AUTO_DELETE);
                int lastDetectedFormVersionHashColumnIndex = cursor
                        .getColumnIndex(FormsProviderAPI.FormsColumns.LAST_DETECTED_FORM_VERSION_HASH);

                Form form = new Form.Builder().id(cursor.getInt(idColumnIndex))
                        .displayName(cursor.getString(displayNameColumnIndex))
                        .description(cursor.getString(descriptionColumnIndex))
                        .jrFormId(cursor.getString(jrFormIdColumnIndex))
                        .jrVersion(cursor.getString(jrVersionColumnIndex))
                        .formFilePath(cursor.getString(formFilePathColumnIndex))
                        .submissionUri(cursor.getString(submissionUriColumnIndex))
                        .base64RSAPublicKey(cursor.getString(base64RSAPublicKeyColumnIndex))
                        .displaySubtext(cursor.getString(displaySubtextColumnIndex))
                        .md5Hash(cursor.getString(md5HashColumnIndex)).date(cursor.getLong(dateColumnIndex))
                        .jrCacheFilePath(cursor.getString(jrCacheFilePathColumnIndex))
                        .formMediaPath(cursor.getString(formMediaPathColumnIndex))
                        .language(cursor.getString(languageColumnIndex))
                        .autoSend(cursor.getString(autoSendColumnIndex))
                        .autoDelete(cursor.getString(autoDeleteColumnIndex))
                        .lastDetectedFormVersionHash(cursor.getString(lastDetectedFormVersionHashColumnIndex))
                        .build();

                forms.add(form);
            }
        } finally {
            cursor.close();
        }
    }
    return forms;
}

From source file:ru.besttuts.stockwidget.ui.SearchableQuoteActivity.java

@Override
public void onCreate(Bundle savedInstanceState) { // TODO Closing after rotate!
    super.onCreate(savedInstanceState);

    //        if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
    //            finish();
    //            return;
    //        }/* ww  w .  j a  v  a 2  s.c  om*/

    setContentView(R.layout.activity_search);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar3);
    setSupportActionBar(toolbar);

    Utils.onActivityCreateSetActionBarColor(getSupportActionBar());

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    if (null == savedInstanceState) {
        Bundle b = getIntent().getExtras();
        mAppWidgetId = b.getInt(EconomicWidgetConfigureActivity.ARG_WIDGET_ID);
        mQuoteTypeValue = b.getInt(EconomicWidgetConfigureActivity.ARG_QUOTE_TYPE_VALUE);
    } else {
        mAppWidgetId = savedInstanceState.getInt(EconomicWidgetConfigureActivity.ARG_WIDGET_ID);
        mQuoteTypeValue = savedInstanceState.getInt(EconomicWidgetConfigureActivity.ARG_QUOTE_TYPE_VALUE);
    }

    String[] from = new String[] { QuoteContract.QuoteColumns.QUOTE_NAME,
            QuoteContract.QuoteColumns.QUOTE_SYMBOL };

    int[] to = new int[] { android.R.id.text1, android.R.id.text2 };

    mSimpleCursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, null, from, to,
            0);

    ListView listView = (ListView) findViewById(R.id.listView);
    listView.setAdapter(mSimpleCursorAdapter);
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            LOGD(TAG, "onItemClick: " + mSimpleCursorAdapter.getItem(position));
            Cursor cursor = mSimpleCursorAdapter.getCursor();
            cursor.moveToPosition(position);
            String symbol = cursor
                    .getString(cursor.getColumnIndexOrThrow(QuoteContract.QuoteColumns.QUOTE_SYMBOL));
            Result result = SymbolProvider.tempMap.get(symbol);
            if (null != mDataSource) {
                try {
                    mDataSource.addQuoteRec(result);
                    finish();
                } catch (IllegalArgumentException e) {
                    LOGE(TAG, e.getMessage());
                    Toast.makeText(SearchableQuoteActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            }
        }
    });

    mDataSource = new QuoteDataSource(this);
    mDataSource.open();

    // ?  ? ? 
    Loader loader = getSupportLoaderManager().getLoader(URL_LOADER);
    if (null == loader) {
        LOGD(TAG, "Loader is null");
        getSupportLoaderManager().initLoader(URL_LOADER, null, this);
    } else {
        LOGD(TAG, "Loader is " + loader);
        loader.forceLoad();
    }

    LOGD(TAG, "onCreate: intent: " + getIntent());

    //        LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayoutSearch);
    //        linearLayout.setOnKeyListener(new View.OnKeyListener() {
    //            @Override
    //            public boolean onKey(View v, int keyCode, KeyEvent event) {
    //                LOGD(TAG, "onKey: searchView: " + searchView + ", mMenu: " + mMenu);
    //
    //                return false;
    //            }
    //        });

    handleIntent(getIntent());
}

From source file:tw.idv.palatis.danboorugallery.siteapi.DanbooruLegacyAPI.java

@Override
public Post getPostFromCursor(Host host, Cursor post_cursor, Cursor tags_cursor) {
    String[] tags;//from  w  w  w .j  av a 2s  .c  o m
    if (tags_cursor != null) {
        tags_cursor.moveToPosition(-1);
        tags = new String[tags_cursor.getCount()];
        while (tags_cursor.moveToNext())
            tags[tags_cursor.getPosition()] = tags_cursor.getString(PostTagsView.INDEX_KEY_POST_TAG_TAG_NAME);
    } else
        tags = new String[0];
    return new DanbooruLegacyPost(host, post_cursor.getInt(PostsTable.INDEX_POST_POST_ID),
            post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_WIDTH),
            post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_HEIGHT),
            new Date(post_cursor.getLong(PostsTable.INDEX_POST_CREATED_AT)),
            new Date(post_cursor.getLong(PostsTable.INDEX_POST_UPDATED_AT)),
            post_cursor.getInt(PostsTable.INDEX_POST_FILE_SIZE),
            post_cursor.getString(PostsTable.INDEX_POST_FILE_URL),
            post_cursor.getString(PostsTable.INDEX_POST_LARGE_FILE_URL),
            post_cursor.getString(PostsTable.INDEX_POST_PREVIEW_FILE_URL), tags,
            post_cursor.getString(PostsTable.INDEX_POST_RATING),
            post_cursor.getString(PostsTable.INDEX_POST_EXTRA_INFO));
}

From source file:com.baqsoft.listas.ui.edit.EditItemFragment.java

/**
 * Called when a previously created loader has finished its load.
 *
 * @param loader The Loader that has finished.
 * @param data   The data generated by the Loader.
 *///w  ww  .  j a  v a  2  s . co m
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    // Find position of selected category - checklist.
    data.moveToFirst();
    int numRows = data.getCount();
    int position = 0;
    int idIndex = data.getColumnIndex(ListasContract.CatCheckContract.COLUMN_ID);
    for (int count = 0; count < numRows; count++) {
        data.moveToPosition(count);
        if (checklistId == data.getLong(idIndex)) {
            position = count;
            break;
        }
    }

    // Change cursor
    checklistSpinnerAdapter.changeCursor(data);

    // Move to position
    mSpinner.setSelection(position);
}

From source file:com.udacity.sunshine.fragment.ForecastFragment.java

private void openPreferredLocationInMap() {
    // Using the URI scheme for showing a location found on a map. This super-handy
    // intent can is detailed in the "Common Intents" page of Android's developer site:
    // http://developer.android.com/guide/components/intents-common.html#Maps
    if (null != mForecastAdapter) {
        Cursor cursor = mForecastAdapter.getCursor();
        if (null != cursor) {

            if (!cursor.moveToFirst())
                return;

            cursor.moveToPosition(0);
            String posLat = cursor.getString(COL_COORD_LAT);
            String posLong = cursor.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   www.  ja v a  2  s . c  o  m
            } else {
                Log.d(TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
            }
        }
    }
}

From source file:fr.julienvermet.bugdroid.service.ProductsIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Context context = getApplicationContext();

    Bundle bundle = intent.getExtras();//from w  w w  .ja  v  a 2  s .c  om
    String query = bundle.getString(QUERY);
    int instances_id = bundle.getInt(INSTANCES_ID);
    int accounts_id = bundle.getInt(ACCOUNTS_ID, -1);
    boolean forceReload = bundle.getBoolean(FORCE_RELOAD);

    ArrayList<Product> products = null;
    if (!forceReload) {
        String selection = Products.Columns.INSTANCES_ID.getName() + "=" + instances_id + " AND "
                + Products.Columns.ACCOUNTS_ID.getName() + "=" + accounts_id;
        String sortOrder = Products.Columns.NAME.getName();
        Cursor cursor = context.getContentResolver().query(Products.CONTENT_URI, Products.PROJECTION, selection,
                null, sortOrder);
        if (cursor.getCount() > 0) {
            products = new ArrayList<Product>();
            for (int i = 0; i < cursor.getCount(); i++) {
                cursor.moveToPosition(i);
                Product product = Product.toProduct(cursor);
                products.add(product);
            }
            sendResult(intent, products);
            return;
        }
        cursor.close();
    }
    String jsonString = NetworkUtils.readJson(query).result;
    products = parse(jsonString);
    sendResult(intent, products);

    // Delete old products for instance
    String selection = Products.Columns.INSTANCES_ID + "=" + instances_id + " AND "
            + Products.Columns.ACCOUNTS_ID.getName() + "=" + accounts_id;
    context.getContentResolver().delete(Products.CONTENT_URI, selection, null);
    context.getContentResolver().bulkInsert(Products.CONTENT_URI,
            Product.toContentValues(products, instances_id, accounts_id));
}

From source file:net.simonvt.cathode.ui.fragment.MovieFragment.java

private void updateActors(Cursor c) {
    actorsParent.setVisibility(c.getCount() > 0 ? View.VISIBLE : View.GONE);
    actors.removeAllViews();/*  w w w .  ja  v  a 2s  . co  m*/

    c.moveToPosition(-1);

    while (c.moveToNext()) {
        View v = LayoutInflater.from(getActivity()).inflate(R.layout.person, actors, false);

        RemoteImageView headshot = (RemoteImageView) v.findViewById(R.id.headshot);
        headshot.setImage(c.getString(c.getColumnIndex(PersonColumns.HEADSHOT)));
        TextView name = (TextView) v.findViewById(R.id.name);
        name.setText(c.getString(c.getColumnIndex(PersonColumns.NAME)));
        TextView character = (TextView) v.findViewById(R.id.job);
        character.setText(c.getString(c.getColumnIndex(MovieCastColumns.CHARACTER)));

        actors.addView(v);
    }
}

From source file:cm.confide.ex.chips.RecipientAlternatesAdapter.java

public RecipientEntry getRecipientEntry(int position) {
    Cursor c = getCursor();
    c.moveToPosition(position);
    return RecipientEntry.constructTopLevelEntry(c.getString(Queries.Query.NAME),
            c.getInt(Queries.Query.DISPLAY_NAME_SOURCE), c.getString(Queries.Query.DESTINATION),
            c.getInt(Queries.Query.DESTINATION_TYPE), c.getString(Queries.Query.DESTINATION_LABEL),
            c.getLong(Queries.Query.CONTACT_ID), c.getLong(Queries.Query.DATA_ID),
            c.getString(Queries.Query.PHOTO_THUMBNAIL_URI), true,
            false /* isGalContact TODO(skennedy) We should look these up eventually */);
}

From source file:cm.confide.ex.chips.RecipientAlternatesAdapter.java

@Override
public long getItemId(int position) {
    Cursor c = getCursor();
    if (c.moveToPosition(position)) {
        c.getLong(Queries.Query.DATA_ID);
    }//from   w  w w .ja va 2 s.  c o  m
    return -1;
}