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:org.ohmage.sync.ResponseSyncAdapter.java
@Override public synchronized void onPerformSync(Account account, Bundle extras, String authority, final ContentProviderClient provider, final SyncResult syncResult) { Log.d(TAG, "Start onPerformSync()"); // Check for authtoken String token = null;/*from w w w.j a va 2 s. c om*/ try { token = am.blockingGetAuthToken(account, AuthUtil.AUTHTOKEN_TYPE, true); } catch (OperationCanceledException e) { syncResult.stats.numSkippedEntries++; } catch (IOException e) { syncResult.stats.numIoExceptions++; } catch (AuthenticatorException e) { syncResult.stats.numAuthExceptions++; } // If the token wasn't found or there was a problem, we can stop now if (token == null || syncResult.stats.numSkippedEntries > 0 || syncResult.stats.numIoExceptions > 0 || syncResult.stats.numAuthExceptions > 0) { Log.d(TAG, "No token found or there was a problem."); return; } // Upload responses Observable<Long> toDelete = null; Observable<ResponseFiles> filesToDelete = null; Cursor cursor = null; try { cursor = provider.query(Responses.CONTENT_URI, new String[] { BaseColumns._ID, Responses.SURVEY_ID, Responses.SURVEY_VERSION, Responses.RESPONSE_DATA, Responses.RESPONSE_METADATA, Responses.RESPONSE_EXTRAS }, null, null, null); AppLogManager.getInstance().logInfo(mContext, "ResponsesSyncStarted", cursor.getCount() + " surveys to upload."); while (cursor.moveToNext()) { final ResponseFiles files = gson.fromJson(cursor.getString(5), ResponseFiles.class); try { // Make the call to upload responses Observable<Response> uploadResponse = null; if (Ohmage.USE_DSU_DATAPOINTS_API) { uploadResponse = uploadDatapoint(cursor, files); } else { uploadOhmagePoint(cursor, files); } // Map the data for the upload response to the local id in the db final long localResponseId = cursor.getLong(0); Observable<Long> responseId = uploadResponse.map(new Func1<Response, Long>() { @Override public Long call(Response response) { return localResponseId; } }); if (toDelete == null) { toDelete = responseId; } else { toDelete = Observable.mergeDelayError(responseId, toDelete); } // Map the data for the upload response to the files in the db Observable<ResponseFiles> responseFiles = uploadResponse .map(new Func1<Response, ResponseFiles>() { @Override public ResponseFiles call(Response response) { return files; } }); if (filesToDelete == null) { filesToDelete = responseFiles; } else { filesToDelete = Observable.mergeDelayError(responseFiles, filesToDelete); } } catch (AuthenticationException e) { Crashlytics.logException(e); Log.e(TAG, "Auth", e); syncResult.stats.numAuthExceptions++; } catch (Exception e) { Log.e(TAG, "Other uploading error", e); Crashlytics.logException(e); } } cursor.close(); } catch (RemoteException e) { Log.e(TAG, "Remote", e); Crashlytics.logException(e); syncResult.stats.numIoExceptions++; } finally { if (cursor != null) cursor.close(); } if (toDelete != null) { Log.d(TAG, "Start deleting responses."); toDelete.flatMap(new Func1<Long, Observable<ContentProviderOperation>>() { @Override public Observable<ContentProviderOperation> call(Long aLong) { return Observable.from(ContentProviderOperation.newDelete( appendSyncAdapterParam(ContentUris.withAppendedId(Responses.CONTENT_URI, aLong))) .build()); } }).subscribe(new Subscriber<ContentProviderOperation>() { ArrayList<ContentProviderOperation> toDelete = new ArrayList<ContentProviderOperation>(); @Override public void onCompleted() { try { getContext().getContentResolver().applyBatch(ResponseContract.CONTENT_AUTHORITY, toDelete); } catch (RemoteException e) { syncResult.stats.numIoExceptions++; } catch (OperationApplicationException e) { syncResult.stats.numIoExceptions++; } unsubscribe(); } @Override public void onError(Throwable e) { // Send error report Log.e(TAG, "Upload failed", e); Crashlytics.logException(e); onCompleted(); } @Override public void onNext(ContentProviderOperation args) { toDelete.add(args); } }); } if (filesToDelete != null) { filesToDelete.doOnNext(new Action1<ResponseFiles>() { @Override public void call(ResponseFiles responseFiles) { for (String s : responseFiles.getIds()) { responseFiles.getFile(s).delete(); } } }).subscribe(new Subscriber<ResponseFiles>() { @Override public void onCompleted() { unsubscribe(); } @Override public void onError(Throwable e) { Crashlytics.logException(e); } @Override public void onNext(ResponseFiles responseFiles) { } }); } }
From source file:org.catnut.fragment.MentionTimelineFragment.java
@Override protected void refresh() { // ???/*from w w w . ja 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 = TweetAPI.mentions(since_id, 0, getFetchSize(), 0, 0, 0, 0); // refresh... mHandler.post(new Runnable() { @Override public void run() { mRequestQueue.add(new CatnutRequest(getActivity(), api, new StatusProcessor.TimelineProcessor(Status.MENTION, true), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.d(TAG, "refresh done..."); mTotal = response.optInt(TOTAL_NUMBER); // ??? JSONArray jsonArray = response.optJSONArray(Status.MULTIPLE); int newSize = jsonArray.length(); // ... Bundle args = new Bundle(); args.putInt(TAG, newSize); getLoaderManager().restartLoader(0, args, MentionTimelineFragment.this); } }, errorListener)).setTag(TAG); } }); } })).start(); }
From source file:ru.valle.safetrade.BuyActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.buy);//from w ww .jav a 2 s . c o m intermediateCodeView = (TextView) findViewById(R.id.intermediate_code); confirmationCodeView = (TextView) findViewById(R.id.confirmation_code); addressView = (TextView) findViewById(R.id.address); encryptedPrivateKeyView = (TextView) findViewById(R.id.encrypted_private_key); balanceView = (TextView) findViewById(R.id.balance); findViewById(R.id.send_confirmation_code_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sendConfirmationCode(); } }); findViewById(R.id.send_encrypted_private_key_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sendEncryptedPrivateKey(); } }); findViewById(R.id.deposit_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (tradeInfo == null || TextUtils.isEmpty(tradeInfo.address)) { new AlertDialog.Builder(BuyActivity.this) .setMessage(getString(R.string.buy_state_still_loading)) .setPositiveButton(android.R.string.ok, null).show(); } else { depositFunds(tradeInfo.address); } } }); findViewById(R.id.show_qr_code_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (tradeInfo == null || TextUtils.isEmpty(tradeInfo.address)) { new AlertDialog.Builder(BuyActivity.this) .setMessage(getString(R.string.buy_state_still_loading)) .setPositiveButton(android.R.string.ok, null).show(); } else { showQrCode(tradeInfo.address); } } }); rowId = getIntent().getLongExtra(BaseColumns._ID, -1); }
From source file:com.abcvoipsip.ui.favorites.FavLoader.java
/** * Creates a cursor that contains a single row and maps the section to the * given value.//from w w w. ja v a 2 s . com */ private Cursor createHeaderCursorFor(SipProfile account) { MatrixCursor matrixCursor = new MatrixCursor(new String[] { BaseColumns._ID, ContactsWrapper.FIELD_TYPE, SipProfile.FIELD_DISPLAY_NAME, SipProfile.FIELD_WIZARD }); matrixCursor.addRow( new Object[] { account.id, ContactsWrapper.TYPE_GROUP, account.display_name, account.wizard }); return matrixCursor; }
From source file:de.schildbach.wallet.data.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(); final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null; if (!offline && (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS)) { Map<String, ExchangeRate> newExchangeRates = null; if (newExchangeRates == null) newExchangeRates = requestExchangeRates(); if (newExchangeRates != null) { exchangeRates = newExchangeRates; lastUpdated = now;/* w ww . ja va 2 s . 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_COIN, KEY_RATE_FIAT, KEY_SOURCE }); if (selection == null) { for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) { final ExchangeRate exchangeRate = entry.getValue(); final org.bitcoinj.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 org.bitcoinj.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 org.bitcoinj.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.glom.app.SqlUtils.java
private static SelectFinalStep buildSqlSelectStepWithWhereClause(final Document document, final String tableName, final List<LayoutItemField> fieldsToGet, final Condition whereClause, final SortClause sortClause, final SQLDialect sqlDialect) { SelectSelectStep<Record> selectStep = createSelect(sqlDialect); // Add the fields, and any necessary joins: final List<UsesRelationship> listRelationships = buildSqlSelectAddFieldsToGet(selectStep, tableName, fieldsToGet, sortClause, false /* extraJoin */); // Android's CursorAdapter and SimpleCursorAdapter need the primary key to be called "_id" // so we add an extra "theid as _id" alias: Field pk = document.getTablePrimaryKeyField(tableName); if (pk != null) { final org.jooq.Field<?> fieldPk = createField(tableName, pk.getName()); selectStep = selectStep.select(fieldPk.as(BaseColumns._ID)); }//from w w w . j ava 2 s . c o m final Table<Record> table = DSL.tableByName(tableName); final SelectJoinStep<Record> joinStep = selectStep.from(table); // LEFT OUTER JOIN will get the field values from the other tables, // and give us our fields for this table even if there is no corresponding value in the other table. for (final UsesRelationship usesRelationship : listRelationships) { builderAddJoin(joinStep, usesRelationship); } SelectFinalStep finalStep = joinStep; if (whereClause != null) { finalStep = joinStep.where(whereClause); } return finalStep; }
From source file:com.bamalearn.bamalearnburmese.DrawerMainActivity.java
private void populateAdapter(String query) { final MatrixCursor c = new MatrixCursor(new String[] { BaseColumns._ID, "cityName" }); for (int i = 0; i < SUGGESTIONS.length; i++) { if (SUGGESTIONS[i].toLowerCase().startsWith(query.toLowerCase())) c.addRow(new Object[] { i, SUGGESTIONS[i] }); }/*ww w . j a v a 2 s . co m*/ mAdapter.changeCursor(c); }
From source file:com.pawnua.android.app.gpstrips.activities.TripDetailActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_trip_detail); context = this; // restore photoFile after Camera shooting in portrait mode if (savedInstanceState != null) { photoFileString = savedInstanceState.getString("photoFile", ""); if (photoFileString != "") { photoFile = new File(photoFileString); }/*from ww w .j a va2 s .c om*/ } Typeface custom_font = Typeface.createFromAsset(getAssets(), "font/WLM.ttf"); tvSpeed = (TextView) findViewById(R.id.currentSpeed); tvSpeed.setTypeface(custom_font); // tvMaxSpeed.setTypeface(custom_font); trip = Trip.getTripByID(getIntent().getLongExtra(BaseColumns._ID, -1)); tripCharacteristics = TripCharacteristics.getTripCharacteristics(trip); if (tripCharacteristics == null) initTripCharacteristics(trip); // initRecyclerView LinearLayoutManager layoutManager = new GridLayoutManager(this, 2); RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator(); adapter = new TripInfoAdapter(TripInfo.initTripInfo(this, tripCharacteristics)); recyclerView = (RecyclerView) findViewById(R.id.trip_infoRecyclerView); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(layoutManager); recyclerView.setItemAnimator(itemAnimator); // ... initRecyclerView mFragmentManager = getSupportFragmentManager(); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); //Initializing NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view); //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu navigationView.setNavigationItemSelectedListener(this); // Initializing Drawer Layout and ActionBarToggle drawerLayout = (DrawerLayout) findViewById(R.id.drawer); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerClosed(View drawerView) { // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank super.onDrawerClosed(drawerView); } @Override public void onDrawerOpened(View drawerView) { // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank super.onDrawerOpened(drawerView); } }; //Setting the actionbarToggle to drawer layout drawerLayout.setDrawerListener(actionBarDrawerToggle); //calling sync state is necessay or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setTitle(getTripTitle(trip)); // CollapsingToolbarLayout collapsingToolbar = // (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); // collapsingToolbar.setTitle(tripName); mGalleryFolder = GalleryDataManager.createImageGallery(trip); }
From source file:org.catnut.fragment.HomeTimelineFragment.java
@Override protected void refresh() { // ???/*w ww .j a va 2s. co 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 = TweetAPI.homeTimeline(since_id, 0, size, 0, 0, 0, 0); // refresh... mHandler.post(new Runnable() { @Override public void run() { mRequestQueue.add(new CatnutRequest(getActivity(), api, new StatusProcessor.TimelineProcessor(Status.HOME, true), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.d(TAG, "refresh done..."); mTotal = response.optInt(TOTAL_NUMBER); // ??? JSONArray jsonArray = response.optJSONArray(Status.MULTIPLE); int newSize = jsonArray.length(); // ... Bundle args = new Bundle(); args.putInt(TAG, newSize); getLoaderManager().restartLoader(0, args, HomeTimelineFragment.this); } }, errorListener)).setTag(TAG); } }); } })).start(); }
From source file:org.rapidandroid.ModelBootstrap.java
private static void insertFieldTypesIntoDBIfNecessary() { Iterator<Map.Entry<Integer, SimpleFieldType>> it = fieldTypeHash.entrySet().iterator(); // for(int i = 0; i < forms.size(); i++) { while (it.hasNext()) { Map.Entry<Integer, SimpleFieldType> pairs = it.next(); SimpleFieldType thetype = pairs.getValue(); // make the URI and insert for the Fieldtype Uri fieldtypeUri = Uri.parse(RapidSmsDBConstants.FieldType.CONTENT_URI_STRING + thetype.getId()); Cursor typeCursor = mContext.getContentResolver().query(fieldtypeUri, null, null, null, null); if (typeCursor.getCount() == 0) { ContentValues typecv = new ContentValues(); typecv.put(BaseColumns._ID, thetype.getId()); typecv.put(RapidSmsDBConstants.FieldType.DATATYPE, thetype.getDataType()); typecv.put(RapidSmsDBConstants.FieldType.NAME, thetype.getReadableName()); typecv.put(RapidSmsDBConstants.FieldType.REGEX, thetype.getRegex()); Log.d("dimagi", "InsertFieldType: " + thetype.getId()); Log.d("dimagi", "InsertFieldType: " + thetype.getDataType()); Log.d("dimagi", "InsertFieldType: " + thetype.getReadableName()); Log.d("dimagi", "InsertFieldType: " + thetype.getRegex()); Uri insertedTypeUri = mContext.getContentResolver() .insert(RapidSmsDBConstants.FieldType.CONTENT_URI, typecv); Log.d("dimagi", "********** Inserted SimpleFieldType into db: " + insertedTypeUri); } else if (typeCursor.getCount() == 1 && typeCursor.moveToFirst()) { // SAGES: update the fieldtype in the database -- the Name and/or Regex has changed int nameColIndx = typeCursor.getColumnIndex(FieldType.NAME); int regexColIndx = typeCursor.getColumnIndex(FieldType.REGEX); boolean isUpdatedFieldType = (!typeCursor.getString(nameColIndx).equals(thetype.getReadableName())); boolean isUpdatedRegex = (!typeCursor.getString(regexColIndx).equals(thetype.getRegex())); if (isUpdatedFieldType || isUpdatedRegex) { ContentValues typecv = new ContentValues(); //typecv.put(BaseColumns._ID, thetype.getId()); typecv.put(RapidSmsDBConstants.FieldType.DATATYPE, thetype.getDataType()); typecv.put(RapidSmsDBConstants.FieldType.NAME, thetype.getReadableName()); typecv.put(RapidSmsDBConstants.FieldType.REGEX, thetype.getRegex()); Log.d("sages", "UpdateFieldType: " + thetype.getId()); Log.d("sages", "UpdateFieldType: " + thetype.getDataType()); Log.d("sages", "UpdateFieldType: " + thetype.getReadableName()); Log.d("sages", "UpdateFieldType: " + thetype.getRegex()); String whereClause = BaseColumns._ID + "= ?"; String[] whereClauseArgs = { String.valueOf(thetype.getId()) }; int numUpdatedType = mContext.getContentResolver().update( RapidSmsDBConstants.FieldType.CONTENT_URI, typecv, whereClause, whereClauseArgs); Log.d("sages", "********** Updated SimpleFieldType into db: " + numUpdatedType); }// w w w . j a v a 2 s. c om } typeCursor.close(); } }