Example usage for android.provider BaseColumns _ID

List of usage examples for android.provider BaseColumns _ID

Introduction

In this page you can find the example usage for android.provider BaseColumns _ID.

Prototype

String _ID

To view the source code for android.provider BaseColumns _ID.

Click Source Link

Document

The unique ID for a row.

Usage

From source file:com.dopecoin.wallet.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
    int provider = Integer.parseInt(sp.getString(Constants.PREFS_KEY_EXCHANGE_PROVIDER, "0"));
    boolean forceRefresh = sp.getBoolean(Constants.PREFS_KEY_EXCHANGE_FORCE_REFRESH, false);
    if (forceRefresh)
        sp.edit().putBoolean(Constants.PREFS_KEY_EXCHANGE_FORCE_REFRESH, false).commit();

    if (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) {
        float newDogeBtcConversion = -1;
        if ((leafBtcConversion == -1 && newDogeBtcConversion == -1) || forceRefresh)
            newDogeBtcConversion = requestDogeBtcConversion(provider);

        if (newDogeBtcConversion != -1)
            leafBtcConversion = newDogeBtcConversion;

        if (leafBtcConversion == -1)
            return null;

        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, leafBtcConversion, userAgent,
                    BITCOINAVERAGE_FIELDS);
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, leafBtcConversion, userAgent,
                    BLOCKCHAININFO_FIELDS);

        if (newExchangeRates != null) {
            String providerUrl;/*from   w  ww.j a  v  a2s. c o m*/
            switch (provider) {
            case 0:
                providerUrl = "http://www.cryptsy.com";
                break;
            case 1:
                providerUrl = "http://www.vircurex.com";
                break;
            default:
                providerUrl = "";
                break;
            }
            float mBTCRate = leafBtcConversion * 1000;
            String strmBTCRate = String.format("%.5f", mBTCRate).replace(',', '.');
            newExchangeRates.put("mBTC", new ExchangeRate("mBTC",
                    new BigDecimal(GenericUtils.toNanoCoins(strmBTCRate, 0)).toBigInteger(), providerUrl));
            exchangeRates = newExchangeRates;
            lastUpdated = now;

            final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode());
            if (exchangeRateToCache != null)
                config.setCachedExchangeRate(exchangeRateToCache);
        }
    }

    if (exchangeRates == null || leafBtcConversion == -1)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate rate = entry.getValue();
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final ExchangeRate rate = bestExchangeRate(selectionArgs[0]);
        if (rate != null)
            cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
    }

    return cursor;
}

From source file:de.langerhans.wallet.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();
    int provider = config.getExchangeProvider();
    boolean forceRefresh = config.getExchangeForceRefresh();
    if (forceRefresh) {
        config.setExchangeForceRefresh(false);
    }/*w w  w.  j  a va  2 s. com*/

    final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null;

    if (!offline && (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) || forceRefresh) {
        double newDogeBtcConversion = -1;
        if ((dogeBtcConversion == -1 && newDogeBtcConversion == -1) || forceRefresh)
            newDogeBtcConversion = requestDogeBtcConversion(provider);

        if (newDogeBtcConversion != -1)
            dogeBtcConversion = newDogeBtcConversion;

        if (dogeBtcConversion == -1)
            return null;

        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, dogeBtcConversion, userAgent,
                    BITCOINAVERAGE_SOURCE, BITCOINAVERAGE_FIELDS);
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, dogeBtcConversion, userAgent,
                    BLOCKCHAININFO_SOURCE, BLOCKCHAININFO_FIELDS);

        if (newExchangeRates != null) {
            String providerUrl;
            switch (provider) {
            case 0:
                providerUrl = "http://www.cryptsy.com";
                break;
            case 1:
                providerUrl = "http://www.bter.com";
                break;
            default:
                providerUrl = "";
                break;
            }
            double mBTCRate = dogeBtcConversion * 1000;
            String strmBTCRate = String.format(Locale.US, "%.4f", mBTCRate).replace(',', '.');
            newExchangeRates.put("mBTC",
                    new ExchangeRate(
                            new com.dogecoin.dogecoinj.utils.ExchangeRate(Fiat.parseFiat("mBTC", strmBTCRate)),
                            providerUrl));
            newExchangeRates.put("DOGE",
                    new ExchangeRate(new com.dogecoin.dogecoinj.utils.ExchangeRate(Fiat.parseFiat("DOGE", "1")),
                            "priceofdoge.com"));
            exchangeRates = newExchangeRates;
            lastUpdated = now;

            final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode());
            if (exchangeRateToCache != null)
                config.setCachedExchangeRate(exchangeRateToCache);
        }
    }

    if (exchangeRates == null || dogeBtcConversion == -1)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE_COIN, KEY_RATE_FIAT, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final com.dogecoin.dogecoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(QUERY_PARAM_Q)) {
        final String selectionArg = selectionArgs[0].toLowerCase(Locale.US);
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final com.dogecoin.dogecoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            final String currencySymbol = GenericUtils.currencySymbol(currencyCode);
            if (currencyCode.toLowerCase(Locale.US).contains(selectionArg)
                    || currencySymbol.toLowerCase(Locale.US).contains(selectionArg))
                cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                        .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String selectionArg = selectionArgs[0];
        final ExchangeRate exchangeRate = bestExchangeRate(selectionArg);
        if (exchangeRate != null) {
            final com.dogecoin.dogecoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    }

    return cursor;
}

From source file:org.catnut.util.CatnutUtils.java

/**
 * ???_id=??//w w  w . ja  va 2 s  .  co m
 *
 * @param increment
 * @param table
 * @param column
 * @param _id
 * @return update sql
 */
public static String increment(boolean increment, String table, String column, long _id) {
    return new StringBuilder("UPDATE ").append(table).append(" ").append(" SET ").append(column).append("=")
            .append(column).append(increment ? "+1" : "-1").append(" WHERE ").append(BaseColumns._ID)
            .append("=").append(_id).toString();
}

From source file:com.andrew.apollo.ui.activities.SearchActivity.java

/**
 * {@inheritDoc}/*  w  ww.j a v  a2s .  c om*/
 */
@Override
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
    final Uri uri = Uri.parse("content://media/external/audio/search/fancy/" + Uri.encode(mFilterString));
    final String[] projection = new String[] { BaseColumns._ID, MediaStore.Audio.Media.MIME_TYPE,
            MediaStore.Audio.Artists.ARTIST, MediaStore.Audio.Albums.ALBUM, MediaStore.Audio.Media.TITLE,
            "data1", "data2" };
    return new CursorLoader(this, uri, projection, null, null, null);
}

From source file:org.catnut.fragment.TweetFragment.java

protected void refresh() {
    // ???//  w  w  w  .j  a  v a 2s.c  o  m
    if (!isNetworkAvailable()) {
        Toast.makeText(getActivity(), getString(R.string.network_unavailable), Toast.LENGTH_SHORT).show();
        initFromLocal();
        return;
    }
    // refresh!
    final int size = getFetchSize();
    (new Thread(new Runnable() {
        @Override
        public void run() {
            // ??????(?-)???Orz...
            String query = CatnutUtils.buildQuery(new String[] { BaseColumns._ID }, mSelection, Status.TABLE,
                    null, BaseColumns._ID + " desc", size + ", 1" // limit x, y
            );
            Cursor cursor = getActivity().getContentResolver().query(CatnutProvider.parse(Status.MULTIPLE),
                    null, query, null, null);
            // the cursor never null?
            final long since_id;
            if (cursor.moveToNext()) {
                since_id = cursor.getLong(0);
            } else {
                since_id = 0;
            }
            cursor.close();
            final CatnutAPI api = CommentsAPI.show(mId, since_id, 0, size, 0, 0);
            // refresh...
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mRequestQueue.add(new CatnutRequest(getActivity(), api,
                            new StatusProcessor.CommentTweetsProcessor(mId),
                            new Response.Listener<JSONObject>() {
                                @Override
                                public void onResponse(JSONObject response) {
                                    Log.d(TAG, "refresh done...");
                                    mTotal = response.optInt(Status.total_number);
                                    // ???
                                    mLastTotalCount = 0;
                                    mShowToastTimes = 0;
                                    JSONArray jsonArray = response.optJSONArray(Status.COMMENTS);
                                    int newSize = jsonArray.length(); // ...
                                    Bundle args = new Bundle();
                                    args.putInt(TAG, newSize);
                                    getLoaderManager().restartLoader(0, args, TweetFragment.this);
                                }
                            }, errorListener)).setTag(TAG);
                }
            });
        }
    })).start();
}

From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java

/**
 * ????//  w  w w  .j a va  2s  . com
 */
private int getRecordCount(Uri queryUri, String selection, String[] selectionArgs)
        throws InvalidParameterException {
    ContentResolver resolver = mContext.getContentResolver();
    Cursor cursor = resolver.query(queryUri, new String[] { BaseColumns._ID }, selection, selectionArgs, null);
    if (null == cursor) {
        throw new InvalidParameterException();
    }
    final int count = cursor.getCount();
    cursor.close();
    return count;
}

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

/**
 * Returns all forms available through the cursor and closes the cursor.
 *//*from ww w .  j a v a  2s  .co m*/
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:com.polyvi.xface.extension.XMessagingExt.java

/**
 * ????/*from   w ww  . ja v  a  2 s.c o  m*/
 */
private int getRecordCount(Uri queryUri, String selection, String[] selectionArgs)
        throws InvalidParameterException {
    ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = resolver.query(queryUri, new String[] { BaseColumns._ID }, selection, selectionArgs, null);
    if (null == cursor) {
        throw new InvalidParameterException();
    }
    final int count = cursor.getCount();
    cursor.close();
    return count;
}

From source file:com.teocci.utubinbg.MainActivity.java

/**
 * Options menu in action bar/* ww  w  . j a  va  2 s .  c  o m*/
 *
 * @param menu
 * @return
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    if (searchView != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    }

    //suggestions
    final CursorAdapter suggestionAdapter = new SimpleCursorAdapter(this, R.layout.dropdown_menu, null,
            new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1 }, new int[] { android.R.id.text1 }, 0);
    final List<String> suggestions = new ArrayList<>();

    searchView.setSuggestionsAdapter(suggestionAdapter);

    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override
        public boolean onSuggestionSelect(int position) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int position) {
            searchView.setQuery(suggestions.get(position), false);
            searchView.clearFocus();

            Intent suggestionIntent = new Intent(Intent.ACTION_SEARCH);
            suggestionIntent.putExtra(SearchManager.QUERY, suggestions.get(position));
            handleIntent(suggestionIntent);

            return true;
        }
    });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String s) {
            return false; //if true, no new intent is started
        }

        @Override
        public boolean onQueryTextChange(String suggestion) {
            // check network connection. If not available, do not query.
            // this also disables onSuggestionClick triggering
            if (suggestion.length() > 2) { //make suggestions after 3rd letter

                if (networkConf.isNetworkAvailable()) {

                    new JsonAsyncTask(new JsonAsyncTask.AsyncResponse() {
                        @Override
                        public void processFinish(ArrayList<String> result) {
                            suggestions.clear();
                            suggestions.addAll(result);
                            String[] columns = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1 };
                            MatrixCursor cursor = new MatrixCursor(columns);

                            for (int i = 0; i < result.size(); i++) {
                                String[] tmp = { Integer.toString(i), result.get(i) };
                                cursor.addRow(tmp);
                            }
                            suggestionAdapter.swapCursor(cursor);

                        }
                    }).execute(suggestion);
                    return true;
                }
            }
            return false;
        }
    });

    return true;
}

From source file:org.catnut.fragment.MyRelationshipFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String selection = mSelection;
    boolean search = args.getBoolean(SEARCH_TWEET);
    if (search) {
        if (!TextUtils.isEmpty(mCurFilter)) {
            selection = new StringBuilder(mSelection).append(" and (").append(User.remark).append(" like ")
                    .append(CatnutUtils.like(mCurFilter)).append(" or ").append(User.screen_name)
                    .append(" like ").append(CatnutUtils.like(mCurFilter)).append(")").toString();
        } else {// www. j a  va 2s.c  o m
            search = false;
        }
    }
    int limit = args.getInt(TAG, getFetchSize());
    return CatnutUtils.getCursorLoader(getActivity(), CatnutProvider.parse(User.MULTIPLE), PROJECTION,
            selection, null, User.TABLE, null, BaseColumns._ID + " desc",
            search ? null : String.valueOf(limit));
}