List of usage examples for android.provider BaseColumns _ID
String _ID
To view the source code for android.provider BaseColumns _ID.
Click Source Link
From source file:de.kollode.redminebrowser.sync.SyncHelper.java
void performSync(SyncResult syncResult, Account account) throws IOException { NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext); mBuilder.setContentTitle("Projects").setContentText("Syncing in progress") .setSmallIcon(R.drawable.ic_launcher); final ContentResolver resolver = mContext.getContentResolver(); ArrayList<ContentProviderOperation> batch = new ArrayList<ContentProviderOperation>(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); AccountManager accMgr = AccountManager.get(this.mContext); String serverUrl = accMgr.getUserData(account, "serverUrl"); if (isOnline()) { final long startRemote = System.currentTimeMillis(); int syncedProjects = 0; Log.i(sTag, "Remote syncing speakers"); Log.i(sTag, serverUrl);/*from w w w. j av a2 s .c o m*/ try { int offset = 0; int numberOfProjects; int limit = 100; boolean loadMore = true; do { String restQuery = "sort=updated_on:desc&limit=" + limit + "&offset=" + offset + "&key=" + accMgr.getPassword(account); Log.d(sTag, "REST URL: " + serverUrl + "/projects.json?" + restQuery); JSONObject projectsJson = getJsonFromUrl(serverUrl + "/projects.json?" + restQuery); numberOfProjects = projectsJson.getInt("total_count"); mBuilder.setProgress(numberOfProjects, syncedProjects, false); mNotificationManager.notify(0, mBuilder.build()); if (numberOfProjects < limit + offset) { Log.d(sTag, "Enough Projects"); loadMore = false; } else { Log.d(sTag, "More Projects"); offset += limit; } JSONArray projects = projectsJson.getJSONArray("projects"); for (int i = 0; i < projects.length(); i++) { JSONObject project = projects.getJSONObject(i); Builder projectBuilder = ContentProviderOperation .newInsert(Project.buildProjectsUri(account.name)); Log.d(sTag, project.toString()); try { projectBuilder.withValue(Project.PARENT, project.getJSONObject("parent").getInt("id")); } catch (Exception e) { } batch.add(projectBuilder.withValue(BaseColumns._ID, project.getInt("id")) .withValue(Project.NAME, project.getString("name")) .withValue(Project.IDENTIFIER, project.getString("identifier")) .withValue(Project.UPDATED, System.currentTimeMillis()) .withValue(Project.CREATED, System.currentTimeMillis()) .withValue(Project.CREATED_ON, project.getString("created_on")) .withValue(Project.UPDATED_ON, project.getString("updated_on")).build()); mBuilder.setProgress(numberOfProjects, syncedProjects++, false); mNotificationManager.notify(0, mBuilder.build()); } } while (loadMore && !this.isCanceled()); try { // Apply all queued up batch operations for local data. resolver.applyBatch(RedmineTables.CONTENT_AUTHORITY, batch); } catch (RemoteException e) { throw new RuntimeException("Problem applying batch operation", e); } catch (OperationApplicationException e) { throw new RuntimeException("Problem applying batch operation", e); } } catch (Exception e) { e.printStackTrace(); } if (this.isCanceled()) { mBuilder.setContentText("Sync was canceled").setProgress(0, 0, false); } else { mBuilder.setContentText("Sync complete").setProgress(0, 0, false); } mNotificationManager.notify(0, mBuilder.build()); syncResult.delayUntil = ((long) 60 * 60); Log.d(sTag, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms"); Log.d(sTag, "Number of projects: " + syncedProjects); } }
From source file:org.catnut.metadata.Status.java
@Override public ContentValues convert(JSONObject json) { ContentValues tweet = new ContentValues(); tweet.put(BaseColumns._ID, json.optLong(Constants.ID)); tweet.put(created_at, json.optString(created_at)); // ?jsonsql??? tweet.put(columnText, json.optString(text)); tweet.put(source, json.optString(source)); tweet.put(favorited, json.optBoolean(favorited)); tweet.put(truncated, json.optBoolean(truncated)); // ??????/* w ww. j a v a 2s.c om*/ JSONArray thumbs = json.optJSONArray(pic_urls); if (thumbs != null) { // json tweet.put(pic_urls, thumbs.toString()); } tweet.put(thumbnail_pic, json.optString(thumbnail_pic)); tweet.put(bmiddle_pic, json.optString(bmiddle_pic)); tweet.put(original_pic, json.optString(original_pic)); // ??? if (json.has(retweeted_status)) { tweet.put(retweeted_status, json.optJSONObject(retweeted_status).toString()); } // if (json.has(User.SINGLE)) { tweet.put(uid, json.optJSONObject(User.SINGLE).optLong(Constants.ID)); } else if (json.has(uid)) { tweet.put(uid, json.optLong(uid)); } tweet.put(reposts_count, json.optInt(reposts_count)); tweet.put(comments_count, json.optInt(comments_count)); tweet.put(attitudes_count, json.optInt(attitudes_count)); return tweet; }
From source file:com.frostwire.android.gui.Librarian.java
public String renameFile(final Context context, FileDescriptor fd, String newFileName) { try {// w w w .ja v a2 s . c o m String filePath = fd.filePath; File oldFile = new File(filePath); String ext = FilenameUtils.getExtension(filePath); File newFile = new File(oldFile.getParentFile(), newFileName + '.' + ext); ContentResolver cr = context.getContentResolver(); ContentValues values = new ContentValues(); values.put(MediaColumns.DATA, newFile.getAbsolutePath()); values.put(MediaColumns.DISPLAY_NAME, FilenameUtils.getBaseName(newFileName)); values.put(MediaColumns.TITLE, FilenameUtils.getBaseName(newFileName)); TableFetcher fetcher = TableFetchers.getFetcher(fd.fileType); cr.update(fetcher.getContentUri(), values, BaseColumns._ID + "=?", new String[] { String.valueOf(fd.id) }); oldFile.renameTo(newFile); return newFile.getAbsolutePath(); } catch (Throwable e) { Log.e(TAG, "Failed to rename file: " + fd, e); } return null; }
From source file:com.csipsimple.ui.favorites.FavLoader.java
/** * Creates a cursor that contains a single row and maps the section to the * given value./*from w w w. j a va2 s .c o m*/ */ private Cursor createHeaderCursorFor(SipProfile account) { MatrixCursor matrixCursor = new MatrixCursor( new String[] { BaseColumns._ID, ContactsWrapper.FIELD_TYPE, SipProfile.FIELD_DISPLAY_NAME, SipProfile.FIELD_WIZARD, SipProfile.FIELD_ANDROID_GROUP, SipProfile.FIELD_PUBLISH_ENABLED, SipProfile.FIELD_REG_URI, SipProfile.FIELD_PROXY, SipProfile.FIELD_ACC_ID }); String proxies = ""; if (account.proxies != null) { proxies = TextUtils.join(SipProfile.PROXIES_SEPARATOR, account.proxies); } matrixCursor .addRow(new Object[] { account.id, ContactsWrapper.TYPE_GROUP, account.display_name, account.wizard, account.android_group, account.publish_enabled, account.reg_uri, proxies, account.acc_id }); return matrixCursor; }
From source file:com.bushstar.htmlcoin_android_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 (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) { Map<String, ExchangeRate> newExchangeRates = null; if (newExchangeRates == null) newExchangeRates = requestExchangeRates(userAgent); if (newExchangeRates != null) { exchangeRates = newExchangeRates; lastUpdated = now;//w w w. ja v a 2s.c o m final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode()); if (exchangeRateToCache != null) config.setCachedExchangeRate(exchangeRateToCache); } } 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(QUERY_PARAM_Q)) { final String selectionArg = selectionArgs[0].toLowerCase(Locale.US); for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) { final ExchangeRate rate = entry.getValue(); final String currencyCode = rate.currencyCode; 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.rate.longValue()) .add(rate.source); } } else if (selection.equals(KEY_CURRENCY_CODE)) { final String selectionArg = selectionArgs[0]; final ExchangeRate rate = bestExchangeRate(selectionArg); if (rate != null) cursor.newRow().add(rate.currencyCode.hashCode()).add(rate.currencyCode).add(rate.rate.longValue()) .add(rate.source); } return cursor; }
From source file:com.roamprocess1.roaming4world.ui.favorites.FavLoader.java
/** * Creates a cursor that contains a single row and maps the section to the * given value.//from ww w . j ava2s. c o m */ private Cursor createHeaderCursorFor(SipProfile account) { MatrixCursor matrixCursor = new MatrixCursor( new String[] { BaseColumns._ID, ContactsWrapper.FIELD_TYPE, SipProfile.FIELD_DISPLAY_NAME, SipProfile.FIELD_WIZARD, SipProfile.FIELD_ANDROID_GROUP, SipProfile.FIELD_PUBLISH_ENABLED, SipProfile.FIELD_REG_URI, SipProfile.FIELD_PROXY, SipProfile.FIELD_ACC_ID }); String proxies = ""; if (account.proxies != null) { proxies = TextUtils.join(SipProfile.PROXIES_SEPARATOR, account.proxies); } matrixCursor .addRow(new Object[] { account.id, ContactsWrapper.TYPE_GROUP, account.display_name, account.wizard, account.android_group, account.publish_enabled, account.reg_uri, proxies, account.acc_id }); return matrixCursor; }
From source file:com.nonninz.robomodel.RoboManager.java
private long getLastId() throws InstanceNotFoundException { final SQLiteDatabase db = mDatabaseManager.openOrCreateDatabase(getDatabaseName()); final String columns[] = new String[] { BaseColumns._ID }; Cursor query;//from ww w . ja va2 s . c om /* * Try the query. If the Table doesn't exist, fix the DB and re-run the query. */ try { query = db.query(getTableName(), columns, null, null, null, null, null); } catch (final SQLiteException e) { prepareTable(db); query = db.query(getTableName(), columns, null, null, null, null, null); } if (query.moveToLast()) { final int columnIndex = query.getColumnIndex(BaseColumns._ID); return query.getLong(columnIndex); } else { throw new InstanceNotFoundException("table " + getTableName() + " is empty"); } }
From source file:com.nineash.hutsync.client.NetworkUtilities.java
private static long getCalendar(Account account) { // Find the Last.fm calendar if we've got one Uri calenderUri = Calendars.CONTENT_URI.buildUpon() .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name) .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type).build(); Cursor c1 = mContentResolver.query(calenderUri, new String[] { BaseColumns._ID }, null, null, null); if (c1.moveToNext()) { long ret = c1.getLong(0); c1.close();/* www. j av a 2 s . co m*/ return ret; } else { ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(Calendars.CONTENT_URI .buildUpon().appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true") .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name) .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type).build()); builder.withValue(Calendars.ACCOUNT_NAME, account.name); builder.withValue(Calendars.ACCOUNT_TYPE, account.type); builder.withValue(Calendars.NAME, "Pizza Hut Shifts"); builder.withValue(Calendars.CALENDAR_DISPLAY_NAME, "Pizza Hut Shifts"); builder.withValue(Calendars.CALENDAR_COLOR, 0xD51007); builder.withValue(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ); builder.withValue(Calendars.OWNER_ACCOUNT, account.name); builder.withValue(Calendars.SYNC_EVENTS, 1); operationList.add(builder.build()); try { mContentResolver.applyBatch(CalendarContract.AUTHORITY, operationList); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return -1; } c1.close(); return getCalendar(account); } }
From source file:com.pindroid.platform.NoteManager.java
public static Note CursorToNote(Cursor c) { Note n = new Note(); n.setId(c.getInt(c.getColumnIndex(BaseColumns._ID))); n.setTitle(c.getString(c.getColumnIndex(Note.Title))); n.setText(c.getString(c.getColumnIndex(Note.Text))); if (c.getColumnIndex(Note.Account) != -1) n.setAccount(c.getString(c.getColumnIndex(Note.Account))); return n;/* w w w . j av a 2s. c om*/ }
From source file:fr.openbike.android.database.OpenBikeDBAdapter.java
public void insertStations(JSONArray jsonArray) throws JSONException, SQLiteException { InsertHelper stationsInsertHelper = new InsertHelper(mDb, STATIONS_TABLE); InsertHelper virtualInsertHelper = new InsertHelper(mDb, STATIONS_VIRTUAL_TABLE); final int idColumn = stationsInsertHelper.getColumnIndex(BaseColumns._ID); final int nameColumn = stationsInsertHelper.getColumnIndex(KEY_NAME); final int openColumn = stationsInsertHelper.getColumnIndex(KEY_OPEN); final int bikesColumn = stationsInsertHelper.getColumnIndex(KEY_BIKES); final int slotsColumn = stationsInsertHelper.getColumnIndex(KEY_SLOTS); final int addressColumn = stationsInsertHelper.getColumnIndex(KEY_ADDRESS); final int latitudeColumn = stationsInsertHelper.getColumnIndex(KEY_LATITUDE); final int longitudeColumn = stationsInsertHelper.getColumnIndex(KEY_LONGITUDE); final int paymentColumn = stationsInsertHelper.getColumnIndex(KEY_PAYMENT); final int specialColumn = stationsInsertHelper.getColumnIndex(KEY_SPECIAL); final int networkColumn = stationsInsertHelper.getColumnIndex(KEY_NETWORK); final int favoriteColumn = stationsInsertHelper.getColumnIndex(KEY_FAVORITE); final int virtualIdColumn = virtualInsertHelper.getColumnIndex(BaseColumns._ID); final int virtualNameColumn = virtualInsertHelper.getColumnIndex(KEY_NAME); final int virtualNetworkColumn = virtualInsertHelper.getColumnIndex(KEY_NETWORK); final int networkId = jsonArray.getJSONObject(0).getInt(Station.NETWORK); final int size = jsonArray.length(); final String sql = "INSERT INTO " + STATIONS_TABLE + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?);"; final String sql_virtual = "INSERT INTO " + STATIONS_VIRTUAL_TABLE + " VALUES (?,?,?);"; virtualInsertHelper.close();//from w w w . ja v a 2s .com stationsInsertHelper.close(); try { mDb.beginTransaction(); SQLiteStatement insert = mDb.compileStatement(sql); SQLiteStatement insert_virtual = mDb.compileStatement(sql_virtual); int id; String name; for (int i = 0; i < size; i++) { JSONObject jsonStation = jsonArray.getJSONObject(i); id = jsonStation.getInt(Station.ID); name = jsonStation.getString(Station.NAME); insert.bindLong(idColumn, id); insert.bindString(nameColumn, name); insert.bindLong(openColumn, jsonStation.getBoolean(Station.OPEN) ? 1 : 0); insert.bindLong(bikesColumn, jsonStation.getInt(Station.BIKES)); insert.bindLong(slotsColumn, jsonStation.getInt(Station.SLOTS)); insert.bindString(addressColumn, jsonStation.getString(Station.ADDRESS)); insert.bindLong(latitudeColumn, (int) (jsonStation.getDouble(Station.LATITUDE) * 1E6)); insert.bindLong(longitudeColumn, (int) (jsonStation.getDouble(Station.LONGITUDE) * 1E6)); insert.bindLong(paymentColumn, jsonStation.getBoolean(Station.PAYMENT) ? 1 : 0); insert.bindLong(specialColumn, jsonStation.getBoolean(Station.SPECIAL) ? 1 : 0); insert.bindLong(networkColumn, networkId); insert.bindLong(favoriteColumn, 0); // Favorite insert.executeInsert(); insert_virtual.bindLong(virtualNetworkColumn, networkId); insert_virtual.bindLong(virtualIdColumn, id); insert_virtual.bindString(virtualNameColumn, name); insert_virtual.executeInsert(); } mDb.setTransactionSuccessful(); } catch (JSONException e) { throw e; } catch (SQLException e) { throw e; } finally { mDb.endTransaction(); } }