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:hashengineering.digitalcoin.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();

    if (exchangeRates == null || now - lastUpdated > UPDATE_FREQ_MS) {
        Map<String, ExchangeRate> newExchangeRates = getBitcoinCharts();
        if (exchangeRates == null && newExchangeRates == null)
            newExchangeRates = getBlockchainInfo();

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;//  w w w .j a  v  a  2 s.  c o  m
        }
    }

    if (exchangeRates == null)
        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 String selectedCode = selectionArgs[0];
        ExchangeRate rate = selectedCode != null ? exchangeRates.get(selectedCode) : null;

        if (rate == null) {
            final String defaultCode = defaultCurrencyCode();
            rate = defaultCode != null ? exchangeRates.get(defaultCode) : null;

            if (rate == null) {
                rate = exchangeRates.get(Constants.DEFAULT_EXCHANGE_CURRENCY);

                if (rate == null)
                    return null;
            }
        }

        cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                .add(rate.source);
    }

    return cursor;
}

From source file:de.schildbach.wallet.goldcoin.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();

    if (exchangeRates == null || now - lastUpdated > UPDATE_FREQ_MS) {
        Map<String, ExchangeRate> newExchangeRates = getBitcoinCharts();//getLitecoinCharts();

        if (exchangeRates == null && newExchangeRates == null)
            newExchangeRates = getBlockchainInfo();

        if (newExchangeRates == null)
            newExchangeRates = getLitecoinCharts();

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;/*from  www.  j  av a 2s.  com*/
        }
    }

    if (exchangeRates == null)
        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(entry.getKey().hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String code = selectionArgs[0];
        final ExchangeRate rate = exchangeRates.get(code);
        try {
            cursor.newRow().add(code.hashCode()).add(rate.currencyCode).add(rate.rate.longValue())
                    .add(rate.source);
        } catch (NullPointerException e) {
            Log.e("GoldCoin", "Unable to add an exchange rate.  NullPointerException.");
        }
    }

    return cursor;
}

From source file:com.google.android.apps.muzei.SourceSubscriberService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null || intent.getAction() == null) {
        return;//from  ww  w .j  a  va2s.  co  m
    }

    String action = intent.getAction();
    if (!ACTION_PUBLISH_STATE.equals(action)) {
        return;
    }
    // Handle API call from source
    String token = intent.getStringExtra(EXTRA_TOKEN);
    ComponentName selectedSource = SourceManager.getSelectedSource(this);
    if (selectedSource == null || !TextUtils.equals(token, selectedSource.flattenToShortString())) {
        Log.w(TAG, "Dropping update from non-selected source, token=" + token + " does not match token for "
                + selectedSource);
        return;
    }

    SourceState state = null;
    if (intent.hasExtra(EXTRA_STATE)) {
        Bundle bundle = intent.getBundleExtra(EXTRA_STATE);
        if (bundle != null) {
            state = SourceState.fromBundle(bundle);
        }
    }

    if (state == null) {
        // If there is no state, there is nothing to change
        return;
    }

    ContentValues values = new ContentValues();
    values.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, selectedSource.flattenToShortString());
    values.put(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED, true);
    values.put(MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION, state.getDescription());
    values.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, state.getWantsNetworkAvailable());
    JSONArray commandsSerialized = new JSONArray();
    int numSourceActions = state.getNumUserCommands();
    boolean supportsNextArtwork = false;
    for (int i = 0; i < numSourceActions; i++) {
        UserCommand command = state.getUserCommandAt(i);
        if (command.getId() == MuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK) {
            supportsNextArtwork = true;
        } else {
            commandsSerialized.put(command.serialize());
        }
    }
    values.put(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND, supportsNextArtwork);
    values.put(MuzeiContract.Sources.COLUMN_NAME_COMMANDS, commandsSerialized.toString());
    ContentResolver contentResolver = getContentResolver();
    Cursor existingSource = contentResolver.query(MuzeiContract.Sources.CONTENT_URI,
            new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?",
            new String[] { selectedSource.flattenToShortString() }, null, null);
    if (existingSource != null && existingSource.moveToFirst()) {
        Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI,
                existingSource.getLong(0));
        contentResolver.update(sourceUri, values, null, null);
    } else {
        contentResolver.insert(MuzeiContract.Sources.CONTENT_URI, values);
    }
    if (existingSource != null) {
        existingSource.close();
    }

    Artwork artwork = state.getCurrentArtwork();
    if (artwork != null) {
        artwork.setComponentName(selectedSource);
        contentResolver.insert(MuzeiContract.Artwork.CONTENT_URI, artwork.toContentValues());

        // Download the artwork contained from the newly published SourceState
        startService(TaskQueueService.getDownloadCurrentArtworkIntent(this));
    }
}

From source file:com.cyanogenmod.filemanager.util.MediaHelper.java

/**
 * Method that converts a file reference to a content uri reference
 *
 * @param cr A content resolver/*from w  ww .  jav a2s.  c  om*/
 * @param path The path to search
 * @param volume The volume
 * @return Uri The content uri or null if file not exists in the media database
 */
private static Uri fileToContentUri(ContentResolver cr, String path, String volume) {
    final String[] projection = { BaseColumns._ID, MediaStore.Files.FileColumns.MEDIA_TYPE };
    final String where = MediaColumns.DATA + " = ?";
    Uri baseUri = MediaStore.Files.getContentUri(volume);
    Cursor c = cr.query(baseUri, projection, where, new String[] { path }, null);
    try {
        if (c != null && c.moveToNext()) {
            int type = c.getInt(c.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE));
            if (type != 0) {
                // Do not force to use content uri for no media files
                long id = c.getLong(c.getColumnIndexOrThrow(BaseColumns._ID));
                return Uri.withAppendedPath(baseUri, String.valueOf(id));
            }
        }
    } finally {
        IOUtils.closeQuietly(c);
    }
    return null;
}

From source file:com.frostwire.android.gui.Librarian.java

public FileDescriptor getFileDescriptor(final Context context, byte fileType, int fileId) {
    List<FileDescriptor> fds = getFiles(context, 0, 1, TableFetchers.getFetcher(fileType),
            BaseColumns._ID + "=?", new String[] { String.valueOf(fileId) });
    if (fds.size() > 0) {
        return fds.get(0);
    } else {//from w  w  w. ja v a2 s  .c om
        return null;
    }
}

From source file:org.catnut.metadata.Status.java

@Override
public String ddl() {
    Log.i(TAG, "create table [statuses]...");

    StringBuilder ddl = new StringBuilder("CREATE TABLE ");
    ddl.append(TABLE).append("(").append(BaseColumns._ID).append(" int primary key,").append(TYPE)
            .append(" int,") // ?
            .append(TO_WHICH_TWEET).append(" int,") // ??id
            .append(created_at).append(" text,").append(columnText).append(" text,").append(source)
            .append(" text,").append(favorited).append(" int,").append(truncated).append(" int,")
            .append(pic_urls).append(" text,").append(thumbnail_pic).append(" text,").append(bmiddle_pic)
            .append(" text,").append(original_pic).append(" text,").append(retweeted_status).append(" text,")
            .append(uid).append(" int,").append(reposts_count).append(" int,").append(comments_count)
            .append(" int,").append(attitudes_count).append(" int");
    return ddl.append(")").toString();
}

From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java

/**
 * Creates and initializes a column project for all columns for Artwork
 *
 * @return The all column projection map for Artwork
 *///from  w w  w . j  ava2  s. c o  m
private static HashMap<String, String> buildAllArtworkColumnProjectionMap() {
    final HashMap<String, String> allColumnProjectionMap = new HashMap<>();
    allColumnProjectionMap.put(BaseColumns._ID, MuzeiContract.Artwork.TABLE_NAME + "." + BaseColumns._ID);
    allColumnProjectionMap.put(MuzeiContract.Artwork.TABLE_NAME + "." + BaseColumns._ID,
            MuzeiContract.Artwork.TABLE_NAME + "." + BaseColumns._ID);
    allColumnProjectionMap.put(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME,
            MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME);
    allColumnProjectionMap.put(MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI,
            MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI);
    allColumnProjectionMap.put(MuzeiContract.Artwork.COLUMN_NAME_TITLE,
            MuzeiContract.Artwork.COLUMN_NAME_TITLE);
    allColumnProjectionMap.put(MuzeiContract.Artwork.COLUMN_NAME_BYLINE,
            MuzeiContract.Artwork.COLUMN_NAME_BYLINE);
    allColumnProjectionMap.put(MuzeiContract.Artwork.COLUMN_NAME_ATTRIBUTION,
            MuzeiContract.Artwork.COLUMN_NAME_ATTRIBUTION);
    allColumnProjectionMap.put(MuzeiContract.Artwork.COLUMN_NAME_TOKEN,
            MuzeiContract.Artwork.COLUMN_NAME_TOKEN);
    allColumnProjectionMap.put(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT,
            MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT);
    allColumnProjectionMap.put(MuzeiContract.Artwork.COLUMN_NAME_META_FONT,
            MuzeiContract.Artwork.COLUMN_NAME_META_FONT);
    allColumnProjectionMap.put(MuzeiContract.Artwork.COLUMN_NAME_DATE_ADDED,
            MuzeiContract.Artwork.COLUMN_NAME_DATE_ADDED);
    allColumnProjectionMap.put(MuzeiContract.Sources.TABLE_NAME + "." + BaseColumns._ID,
            MuzeiContract.Sources.TABLE_NAME + "." + BaseColumns._ID);
    allColumnProjectionMap.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME,
            MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME);
    allColumnProjectionMap.put(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED,
            MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED);
    allColumnProjectionMap.put(MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION,
            MuzeiContract.Sources.COLUMN_NAME_DESCRIPTION);
    allColumnProjectionMap.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE,
            MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE);
    allColumnProjectionMap.put(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND,
            MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND);
    allColumnProjectionMap.put(MuzeiContract.Sources.COLUMN_NAME_COMMANDS,
            MuzeiContract.Sources.COLUMN_NAME_COMMANDS);
    return allColumnProjectionMap;
}

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

@Override
protected void refresh() {
    // ???/* w  w w.  java2 s  .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 }, null, Comment.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.to_me(since_id, 0, getFetchSize(), 0, 0, 0);
            // refresh...
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    mRequestQueue.add(new CatnutRequest(getActivity(), api,
                            new StatusProcessor.Comments2MeProcessor(), new Response.Listener<JSONObject>() {
                                @Override
                                public void onResponse(JSONObject response) {
                                    Log.d(TAG, "refresh done...");
                                    mTotal = response.optInt(TOTAL_NUMBER);
                                    // ???
                                    JSONArray jsonArray = response.optJSONArray(Comment.MULTIPLE);
                                    int newSize = jsonArray.length(); // ...
                                    Bundle args = new Bundle();
                                    args.putInt(TAG, newSize);
                                    getLoaderManager().restartLoader(0, args, ConversationFragment.this);
                                }
                            }, errorListener)).setTag(TAG);
                }
            });
        }
    })).start();
}

From source file:ru.glesik.nostrangersms.SMSReceiver.java

public String getContactDisplayNameByNumber(Context context, String number) {
    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    String name = "";
    ContentResolver contentResolver = context.getContentResolver();
    Cursor contactLookup = contentResolver.query(uri,
            new String[] { BaseColumns._ID, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null);
    try {//from  w  w w  .  j  av  a 2 s  . c  o  m
        if (contactLookup != null && contactLookup.getCount() > 0) {
            contactLookup.moveToNext();
            name = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
        }
    } finally {
        if (contactLookup != null) {
            contactLookup.close();
        }
    }
    return name;
}

From source file:ollie.Ollie.java

/**
 * Iterate over a cursor and load entities.
 *
 * @param cls    The model class.//ww w  .  j  av a  2s  . c  o m
 * @param cursor The result cursor.
 * @return The list of entities.
 */
public static <T extends Model> List<T> processCursor(Class<T> cls, Cursor cursor) {
    final List<T> entities = new ArrayList<T>();
    try {
        Constructor<T> entityConstructor = cls.getConstructor();
        if (cursor.moveToFirst()) {
            do {
                T entity = getEntity(cls, cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)));
                if (entity == null) {
                    entity = entityConstructor.newInstance();
                }

                entity.load(cursor);
                entities.add(entity);
            } while (cursor.moveToNext());
        }
    } catch (Exception e) {
        Log.e(TAG, "Failed to process cursor.", e);
    }

    return entities;
}