List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:edu.cens.loci.ui.VisitDetailActivity.java
private void updateData(Uri visitUri) { ContentResolver resolver = getContentResolver(); Cursor visitCursor = resolver.query(visitUri, VISIT_LOG_PROJECTION, null, null, null); try {// w ww . j a va2 s .c om if (visitCursor != null && visitCursor.moveToFirst()) { long placeId = visitCursor.getLong(PLACE_ID_INDEX); long enter = visitCursor.getLong(ENTER_INDEX); long exit = visitCursor.getLong(EXIT_INDEX); int type = visitCursor.getInt(TYPE); String extra1 = visitCursor.getString(EXTRA1_INDEX); String extra2 = visitCursor.getString(EXTRA2_INDEX); MyLog.d(LociConfig.D.UI.DEBUG, TAG, String.format("[updateData] placeId=%d enter=%s exit=%s type=%d extra1=%s extra2=%s", placeId, MyDateUtils.getTimeFormatLong(enter), MyDateUtils.getTimeFormatLong(exit), type, extra1, extra2)); // Place name String place_name = ""; int place_state = 0; if (placeId > 0) { String placeSelection = Places._ID + "=" + placeId; Uri placeUri = ContentUris.withAppendedId(Places.CONTENT_URI, placeId); Cursor placeCursor = resolver.query(placeUri, PLACE_PROJECTION, placeSelection, null, null); if (placeCursor != null && placeCursor.moveToFirst()) { place_name = placeCursor.getString(PLACE_NAME_INDEX); place_state = placeCursor.getInt(PLACE_STATE_INDEX); placeCursor.close(); } else { place_name = "Unknown"; } } else { place_name = "Unknown"; } mPlaceName.setText(place_name); // Pull out string in format [relative], [date] CharSequence dateClause = DateUtils.formatDateRange(this, enter, enter, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); mVisitTime.setText(dateClause); // Set the duration mVisitDuration.setText(formatDuration((exit - enter) / 1000)); switch (type) { case Visits.TYPE_GPS: mPlaceTypeIcon.setImageResource(R.drawable.icon_satellite); break; case Visits.TYPE_WIFI: mPlaceTypeIcon.setImageResource(R.drawable.icon_wifi); break; } List<ViewEntry> actions = new ArrayList<ViewEntry>(); // View place Intent viewPlaceIntent = new Intent(Intent.ACTION_VIEW, ContentUris.withAppendedId(Places.CONTENT_URI, placeId)); String placeViewLabel = ""; MyLog.d(LociConfig.D.UI.DEBUG, TAG, String.format("[updateData] placename=%s placestate=%d", place_name, place_state)); switch (place_state) { case Places.STATE_SUGGESTED: placeViewLabel = "Handle Suggested Place"; break; case Places.STATE_REGISTERED: placeViewLabel = "View " + place_name; break; default: placeViewLabel = null;//place_name + " state " + place_state; } if (placeViewLabel != null) { ViewEntry entry = new ViewEntry(LIST_ACTION_VIEW_PLACE, R.drawable.sym_action_map, placeViewLabel, null, null); entry.intent = viewPlaceIntent; actions.add(entry); } // View Wifi APs if (type == Visits.TYPE_WIFI && extra1 != null) { LociWifiFingerprint wifi; String apsAbstract = "Not available"; try { wifi = new LociWifiFingerprint(extra1); apsAbstract = wifi.getWifiInfoSubstring(5); ViewEntry wifiEntry = new ViewEntry(LIST_ACTION_VIEW_WIFIS, R.drawable.ic_settings_wireless, "View Wi-Fi APs", apsAbstract, null); wifiEntry.extra_string = extra1; actions.add(wifiEntry); } catch (JSONException e) { MyLog.e(LociConfig.D.JSON, TAG, "wifi json failed : " + extra1); e.printStackTrace(); } } // Additional Actions if (placeId > 0) { if (place_state == Places.STATE_REGISTERED || place_state == Places.STATE_BLOCKED) { if (type == Visits.TYPE_WIFI && extra1 != null) { ViewEntry entry = new ViewEntry(LIST_ACTION_CHANGE_PLACE, android.R.drawable.ic_menu_edit, "Change Place", null, null); entry.intent = new Intent(Intents.UI.ACTION_INSERT); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_KEY, PlacesList.LIST_ORDER_TYPE_WIFI_SIMILARITY); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_KEY, extra1); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_TIME_KEY, String.valueOf(enter)); entry.intent.putExtra(Intents.UI.PLACE_ENTRY_TYPE_EXTRA_KEY, Places.ENTRY_WIFI_OVERWRITE_WRONG_RECOGNITION); actions.add(entry); } } } else { ViewEntry entry = new ViewEntry(LIST_ACTION_ADD_PLACE, R.drawable.sym_action_add, "Add Place", null, null); entry.intent = new Intent(Intents.UI.ACTION_INSERT); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_KEY, PlacesList.LIST_ORDER_TYPE_WIFI_SIMILARITY); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_KEY, extra1); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_TIME_KEY, String.valueOf(enter)); entry.intent.putExtra(Intents.UI.PLACE_ENTRY_TYPE_EXTRA_KEY, Places.ENTRY_WIFI_USE_SHORT_VISIT); actions.add(entry); } // View Recognition Results //Log.d(TAG, "recog: " + extra2); if (extra2 != null && !TextUtils.isEmpty(extra2)) { ViewEntry recogEntry = new ViewEntry(LIST_ACTION_VIEW_RECOGNITION, R.drawable.ic_clock_strip_desk_clock, "View Recogntion Results", "", null); recogEntry.extra_string = extra2; actions.add(recogEntry); } ViewAdapter adapter = new ViewAdapter(this, actions); setListAdapter(adapter); //Log.d(TAG, String.format("placeId=%d enter=%s exit=%s", placeId, MyDateUtils.getDateFormatLong(enter), MyDateUtils.getDateFormatLong(exit))); //Log.d(TAG, String.format("extra1=%s", extra1)); //Log.d(TAG, String.format("extra2=%s", extra2)); } } finally { if (visitCursor != null) { visitCursor.close(); } } }
From source file:eu.operando.operandoapp.database.DatabaseHelper.java
public List<DomainFilter> getAllDomainFilters() { List<DomainFilter> domainFilters = new ArrayList<>(); String selectQuery = "SELECT * FROM " + TABLE_DOMAIN_FILTERS; SQLiteDatabase db = this.getReadableDatabase(); Cursor c = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (c.moveToFirst()) { do {// ww w . j a v a 2s. c o m DomainFilter domainFilter = new DomainFilter(); domainFilter.setId(c.getInt(c.getColumnIndex(KEY_ID))); domainFilter.setContent((c.getString(c.getColumnIndex(KEY_CONTENT)))); domainFilter.setSource((c.getString(c.getColumnIndex(KEY_SOURCE)))); domainFilter.setModified(c.getString(c.getColumnIndex(KEY_MODIFIED))); domainFilter.setWildcard((c.getInt(c.getColumnIndex(KEY_WILDCARD)))); domainFilters.add(domainFilter); } while (c.moveToNext()); } return domainFilters; }
From source file:eu.operando.operandoapp.database.DatabaseHelper.java
public List<DomainFilter> getAllUserDomainFilters() { List<DomainFilter> domainFilters = new ArrayList<DomainFilter>(); String selectQuery = "SELECT * FROM " + TABLE_DOMAIN_FILTERS + " WHERE " + KEY_SOURCE + " IS NULL "; SQLiteDatabase db = this.getReadableDatabase(); Cursor c = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (c.moveToFirst()) { do {/* w ww .j a va2s . com*/ DomainFilter domainFilter = new DomainFilter(); domainFilter.setId(c.getInt(c.getColumnIndex(KEY_ID))); domainFilter.setContent((c.getString(c.getColumnIndex(KEY_CONTENT)))); domainFilter.setSource((c.getString(c.getColumnIndex(KEY_SOURCE)))); domainFilter.setModified(c.getString(c.getColumnIndex(KEY_MODIFIED))); domainFilter.setWildcard((c.getInt(c.getColumnIndex(KEY_WILDCARD)))); domainFilters.add(domainFilter); } while (c.moveToNext()); } return domainFilters; }
From source file:com.piusvelte.wapdroid.MapData.java
public void mapData() { mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setTitle(R.string.loading); mLoadingDialog.setMessage((mPair == 0 ? Wapdroid.Ranges.NETWORK : Wapdroid.Ranges.CELL)); mLoadingDialog.setCancelable(true);/* w ww.j av a 2 s . c o m*/ mLoadingDialog.setOnCancelListener(this); mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this); mLoadingDialog.show(); mThread = new Thread() { public void run() { String ssid = "", bssid = "", towers = ""; int ctr = 0; List<Overlay> mapOverlays = mMView.getOverlays(); GeoPoint point = new GeoPoint(0, 0); Cursor pairs = MapData.this.getContentResolver().query(Wapdroid.Ranges.CONTENT_URI, new String[] { Wapdroid.Ranges._ID, Wapdroid.Ranges.SSID, Wapdroid.Ranges.BSSID, Wapdroid.Ranges.CID, Wapdroid.Ranges.LAC, Wapdroid.Ranges.RSSI_MIN, Wapdroid.Ranges.RSSI_MAX }, mPair == 0 ? Wapdroid.Ranges.NETWORK + "=" + mNetwork : Wapdroid.Ranges._ID + "=" + mPair, null, null); int ct = pairs.getCount(); if (pairs.moveToFirst()) { WapdroidItemizedOverlay pinOverlays = new WapdroidItemizedOverlay((MapData) mContext, ct); while (!interrupted() && !pairs.isAfterLast()) { ctr++; int cid = pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges.CID)), lac = pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges.LAC)), rssi_min = pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges.RSSI_MIN)), rssi_max = pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges.RSSI_MAX)), rssi_avg = Math.round((rssi_min + rssi_max) / 2), rssi_range = Math.abs(rssi_min) - Math.abs(rssi_max); mMsg = string_cellWarning + Wapdroid.Ranges.CELL + " " + Integer.toString(ctr) + " of " + Integer.toString(ct); mHandler.post(mUpdtDialog); String tower = "{" + String.format(SAddInt, cell_id, cid) + "," + String.format(SAddInt, location_area_code, lac) + "," + String.format(SAddInt, mcc, mMCC) + "," + String.format(SAddInt, mnc, mMNC); if (rssi_avg != Wapdroid.UNKNOWN_RSSI) tower += "," + String.format(SAddInt, signal_strength, rssi_avg); tower += "}"; if (ssid == "") ssid = pairs.getString(pairs.getColumnIndex(Wapdroid.Ranges.SSID)); if (bssid == "") bssid = pairs.getString(pairs.getColumnIndex(Wapdroid.Ranges.BSSID)); if (towers != "") towers += ","; towers += tower; point = getGeoPoint(bldRequest(tower, bssid)); pinOverlays.addOverlay(new WapdroidOverlayItem(point, Wapdroid.Ranges.CELL, string_cid + Integer.toString(cid) + string_linefeed + string_lac + Integer.toString(lac) + string_linefeed + string_range + Integer.toString(rssi_min) + string_colon + Integer.toString(rssi_max), mNetwork, pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges._ID)), rssi_avg, rssi_range)); pairs.moveToNext(); } if (mPair == 0) { mMsg = Wapdroid.Ranges.NETWORK + ": " + ssid; mHandler.post(mUpdtDialog); point = getGeoPoint(bldRequest(towers, bssid)); Location location = new Location(""); location.setLatitude(point.getLatitudeE6() / 1e6); location.setLongitude(point.getLongitudeE6() / 1e6); pinOverlays.addOverlay( new WapdroidOverlayItem(point, Wapdroid.Ranges.NETWORK, ssid, mNetwork), drawable_network); pinOverlays.setDistances(location); } mapOverlays.add(pinOverlays); mMController.setCenter(point); } pairs.close(); mLoadingDialog.dismiss(); interrupt(); } }; mThread.start(); }
From source file:cn.code.notes.gtask.data.Task.java
public int getSyncAction(Cursor c) { try {/*from w w w. j a va 2s . c o m*/ JSONObject noteInfo = null; if (mMetaInfo != null && mMetaInfo.has(GTaskStringUtils.META_HEAD_NOTE)) { noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); } if (noteInfo == null) { Log.w(TAG, "it seems that note meta has been deleted"); return SYNC_ACTION_UPDATE_REMOTE; } if (!noteInfo.has(NoteColumns.ID)) { Log.w(TAG, "remote note id seems to be deleted"); return SYNC_ACTION_UPDATE_LOCAL; } // validate the note id now if (c.getLong(SqlNote.ID_COLUMN) != noteInfo.getLong(NoteColumns.ID)) { Log.w(TAG, "note id doesn't match"); return SYNC_ACTION_UPDATE_LOCAL; } if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) { // there is no local update if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) { // no update both side return SYNC_ACTION_NONE; } else { // apply remote to local return SYNC_ACTION_UPDATE_LOCAL; } } else { // validate gtask id if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) { Log.e(TAG, "gtask id doesn't match"); return SYNC_ACTION_ERROR; } if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) { // local modification only return SYNC_ACTION_UPDATE_REMOTE; } else { return SYNC_ACTION_UPDATE_CONFLICT; } } } catch (Exception e) { Log.e(TAG, e.toString()); e.printStackTrace(); } return SYNC_ACTION_ERROR; }
From source file:eu.operando.operandoapp.database.DatabaseHelper.java
public List<ResponseFilter> getAllResponseFilters() { List<ResponseFilter> responseFilters = new ArrayList<ResponseFilter>(); String selectQuery = "SELECT * FROM " + TABLE_RESPONSE_FILTERS; SQLiteDatabase db = this.getReadableDatabase(); Cursor c = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (c.moveToFirst()) { do {//from w ww. j ava2 s. co m ResponseFilter responseFilter = new ResponseFilter(); responseFilter.setId(c.getInt(c.getColumnIndex(KEY_ID))); responseFilter.setContent((c.getString(c.getColumnIndex(KEY_CONTENT)))); responseFilter.setSource((c.getString(c.getColumnIndex(KEY_SOURCE)))); responseFilter.setModified(c.getString(c.getColumnIndex(KEY_MODIFIED))); responseFilters.add(responseFilter); } while (c.moveToNext()); } return responseFilters; }
From source file:eu.operando.operandoapp.database.DatabaseHelper.java
public List<ResponseFilter> getAllUserResponseFilters() { List<ResponseFilter> responseFilters = new ArrayList<ResponseFilter>(); String selectQuery = "SELECT * FROM " + TABLE_RESPONSE_FILTERS + " WHERE " + KEY_SOURCE + " IS NULL "; SQLiteDatabase db = this.getReadableDatabase(); Cursor c = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (c.moveToFirst()) { do {/*from w ww . ja v a2s .c o m*/ ResponseFilter responseFilter = new ResponseFilter(); responseFilter.setId(c.getInt(c.getColumnIndex(KEY_ID))); responseFilter.setContent((c.getString(c.getColumnIndex(KEY_CONTENT)))); responseFilter.setSource((c.getString(c.getColumnIndex(KEY_SOURCE)))); responseFilter.setModified(c.getString(c.getColumnIndex(KEY_MODIFIED))); responseFilters.add(responseFilter); } while (c.moveToNext()); } return responseFilters; }
From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java
@SuppressWarnings("ConstantConditions") @Override/* www .jav a2 s. c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initActivityTransitions(); setContentView(R.layout.activity_detail); String[] projection = { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DISPLAY_NAME }; String selection = MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " = ?"; String[] selectionArgs = new String[] { TEMP_WALLPAPER_DIR }; Cursor mImageCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, null); mImageCursor.moveToFirst(); if (mImageCursor.getCount() == 1) { imageId = mImageCursor.getInt((mImageCursor.getColumnIndex(MediaStore.Images.Media._ID))); Log.e("CROP", "" + imageId); mImageCursor.close(); } checkDir(); timerTasks = new TimerTasks(context); ViewCompat.setTransitionName(findViewById(R.id.app_bar_layout), EXTRA_IMAGE_SMALL); supportPostponeEnterTransition(); superCategory = getIntent().getExtras().getInt(EXTRA_SUPER_CATEGORY); floatingActionButton = (FloatingActionButton) findViewById(R.id.fab_set_as_wallpaper); floatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setAsWallpaper(imageId); } }); toolbar = ((Toolbar) findViewById(R.id.toolbar)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setVisibility(View.GONE); String itemTitle = getIntent().getStringExtra(EXTRA_TITLE); progressBar = (ProgressBar) findViewById(R.id.progressBarImage); collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbarLayout.setTitle(itemTitle); collapsingToolbarLayout.setExpandedTitleColor(getResources().getColor(android.R.color.transparent)); imageView = (ImageView) findViewById(R.id.image); Picasso.with(this).load(getIntent().getStringExtra(EXTRA_IMAGE_SMALL)).into(imageView, new Callback() { @SuppressWarnings("NewApi") @Override public void onSuccess() { Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); float ImageHieghtTemp = bitmap.getHeight(); float ImageWidthTemp = bitmap.getWidth(); Point size = new Point(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getRealSize(size); float widthMain = size.x; float heightMain = size.y; imageView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); int addWidth = imageView.getMeasuredWidth(); // Display display = getWindowManager().getDefaultDisplay(); // float widthMain = display.getWidth(); // float heightMain = display.getHeight(); Log.e(LOG_TAG, "IMAGE_MAIN : " + ImageWidthTemp + " : " + ImageHieghtTemp); float imageHeight = widthMain * ((float) (bitmap.getHeight()) / (float) (bitmap.getWidth())); float scaleXY = heightMain / imageHeight; if (scaleXY > 1.0007f) { Log.e(LOG_TAG, "SCALE FACTORE : " + scaleXY + " : " + 1.10454545f * scaleXY); scaleXY = 1.8f * scaleXY; } PhotoViewAttacher mAttacherTest = new PhotoViewAttacher(imageView, true, false); mAttacherTest.setZoomScale(scaleXY); mAttacherTest.setScale(scaleXY, (widthMain) / 2, heightMain / 2, true); Log.e(LOG_TAG, "DETAILS : " + widthMain + " : " + heightMain + " : " + scaleXY + " : " + bitmap.getWidth() + " : " + bitmap.getHeight()); Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() { public void onGenerated(Palette palette) { applyPalette(palette); } }); } @Override public void onError() { } }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = getWindow(); w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } // clearApplicationData(); new ImageLoadTask().execute(""); initDownloadComponents(); mAdView = (AdView) findViewById(R.id.adViewFullImage); mAdView.setVisibility(View.GONE); AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build(); // Start loading the ad in sthe background. mAdView.loadAd(adRequest); mAdView.setAdListener(new AdListener() { @Override public void onAdLoaded() { super.onAdLoaded(); mAdView.setVisibility(View.VISIBLE); } }); }
From source file:com.ubuntuone.android.files.service.MetaService.java
/** * Given parents resource path and {@link ArrayList} of {@link NodeInfo}s of * its children, syncs cached info of these children. Updating children in * one method enables us to make use of database transaction.<br /> * <ul>/*w w w. j av a 2 s . c o m*/ * <li>- inserts if child is new</li> * <li>- updates if child has changed [thus marks is_cached = false]</li> * <li>- deletes if child is missing [dead node]</li> * </ul> * * @param parentResourcePath * the resource path of childrens parent * @param children * {@link NodeInfo}s of the parents children * @throws OperationApplicationException * @throws RemoteException */ public void getDirectoryNode(final String resourcePath, final ResultReceiver receiver) { Log.i(TAG, "getDirectoryNode()"); final String[] projection = new String[] { Nodes._ID, Nodes.NODE_RESOURCE_PATH, Nodes.NODE_GENERATION, Nodes.NODE_DATA }; final String selection = Nodes.NODE_RESOURCE_PATH + "=?"; final Set<Integer> childrenIds = MetaUtilities.getChildrenIds(resourcePath); final ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(); final Bundle data = new Bundle(); data.putString(EXTRA_RESOURCE_PATH, resourcePath); api.listDirectory(resourcePath, new U1NodeListener() { @Override public void onStart() { if (receiver != null) receiver.send(Status.RUNNING, data); } @Override public void onSuccess(U1Node node) { if (node.getKind() == U1NodeKind.FILE && ((U1File) node).getSize() == null) { // Ignore files with null size. return; } final String[] selectionArgs = new String[] { node.getResourcePath() }; final Cursor c = contentResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); try { ContentValues values = Nodes.valuesFromRepr(node); if (c.moveToFirst()) { final int id = c.getInt(c.getColumnIndex(Nodes._ID)); // Node is live. childrenIds.remove(id); // Update node. final long generation = c.getLong(c.getColumnIndex(Nodes.NODE_GENERATION)); final long newGeneration = node.getGeneration(); if (generation < newGeneration) { Log.v(TAG, "updating child node, new generation"); values.put(Nodes.NODE_IS_CACHED, false); values.put(Nodes.NODE_DATA, ""); String data = c.getString(c.getColumnIndex(Nodes.NODE_DATA)); FileUtilities.removeSilently(data); Uri uri = MetaUtilities.buildNodeUri(id); ContentProviderOperation op = ContentProviderOperation.newUpdate(uri).withValues(values) .build(); operations.add(op); if (operations.size() > 10) { try { contentResolver.applyBatch(MetaContract.CONTENT_AUTHORITY, operations); operations.clear(); } catch (RemoteException e) { Log.e(TAG, "Remote exception", e); } catch (OperationApplicationException e) { MetaUtilities.setIsCached(resourcePath, false); return; } Thread.yield(); } } else { Log.v(TAG, "child up to date"); } } else { // Insert node. Log.v(TAG, "inserting child"); ContentProviderOperation op = ContentProviderOperation.newInsert(Nodes.CONTENT_URI) .withValues(values).build(); operations.add(op); if (operations.size() > 10) { try { contentResolver.applyBatch(MetaContract.CONTENT_AUTHORITY, operations); operations.clear(); } catch (RemoteException e) { Log.e(TAG, "Remote exception", e); } catch (OperationApplicationException e) { MetaUtilities.setIsCached(resourcePath, false); return; } Thread.yield(); } } } finally { c.close(); } } @Override public void onUbuntuOneFailure(U1Failure failure) { MetaService.this.onUbuntuOneFailure(failure, receiver); } @Override public void onFailure(U1Failure failure) { MetaService.this.onFailure(failure, receiver); } @Override public void onFinish() { if (receiver != null) receiver.send(Status.FINISHED, data); } }); // Remove nodes, which ids are left in childrenIds set. if (!childrenIds.isEmpty()) { Log.v(TAG, "childrenIDs not empty: " + childrenIds.size()); final Iterator<Integer> it = childrenIds.iterator(); while (it.hasNext()) { int id = it.next(); Uri uri = MetaUtilities.buildNodeUri(id); ContentProviderOperation op = ContentProviderOperation.newDelete(uri).build(); operations.add(op); } } else { Log.v(TAG, "childrenIDs empty"); } try { long then = System.currentTimeMillis(); contentResolver.applyBatch(MetaContract.CONTENT_AUTHORITY, operations); MetaUtilities.setIsCached(resourcePath, true); long now = System.currentTimeMillis(); Log.d(TAG, "time to update children: " + (now - then)); contentResolver.notifyChange(Nodes.CONTENT_URI, null); } catch (RemoteException e) { Log.e(TAG, "", e); } catch (OperationApplicationException e) { MetaUtilities.setIsCached(resourcePath, false); return; } }
From source file:eu.operando.operandoapp.database.DatabaseHelper.java
public List<String> getStatistics() { SQLiteDatabase db = DatabaseHelper.this.getWritableDatabase(); List<String> result = new ArrayList(); Cursor c = db.rawQuery("SELECT * FROM " + TABLE_STATISTICS + " WHERE " + KEY_ID + " = 1", null); if (c.moveToFirst()) { for (int i = 1; i < c.getColumnCount(); i++) { //omit column 0 result.add(filterName(c.getColumnName(i)) + ": " + c.getInt(i) + (c.getInt(i) == 1 ? " time." : " times.")); }//w w w . j av a2 s . c om } return result; }