List of usage examples for android.database Cursor requery
@Deprecated
boolean requery();
From source file:com.todoroo.astrid.activity.TaskListFragment.java
/** * Load or re-load action items and update views * * @param requery/*www.j av a 2s.c o m*/ */ public void loadTaskListContent(boolean requery) { if (taskAdapter == null) { setUpTaskList(); return; } Cursor taskCursor = taskAdapter.getCursor(); if (requery) { taskCursor.requery(); taskAdapter.flushCaches(); taskAdapter.notifyDataSetChanged(); } if (getView() != null) { // This was happening sometimes int oldListItemSelected = getListView().getSelectedItemPosition(); if (oldListItemSelected != ListView.INVALID_POSITION && oldListItemSelected < taskCursor.getCount()) getListView().setSelection(oldListItemSelected); } // also load sync actions syncActionHelper.request(); }
From source file:com.android.unit_tests.CheckinProviderTest.java
@MediumTest public void testCrashReport() throws Exception { long start = System.currentTimeMillis(); ContentResolver r = getContext().getContentResolver(); // Log a test (fake) crash report. Checkin.reportCrash(r, new CrashData("Test", "Test Activity", new BuildData("Test Build", "123", start), new ThrowableData(new RuntimeException("Test Exception")))); // Crashes aren't indexed; go through them all to find the one we added. Cursor c = r.query(Checkin.Crashes.CONTENT_URI, null, null, null, null); Uri uri = null;/*w w w.j av a2s . c om*/ while (c.moveToNext()) { String coded = c.getString(c.getColumnIndex(Checkin.Crashes.DATA)); byte[] bytes = Base64.decodeBase64(coded.getBytes()); CrashData crash = new CrashData(new DataInputStream(new ByteArrayInputStream(bytes))); // Should be exactly one recently added "Test" crash. if (crash.getId().equals("Test") && crash.getTime() > start) { assertEquals("Test Activity", crash.getActivity()); assertEquals("Test Build", crash.getBuildData().getFingerprint()); assertEquals("Test Exception", crash.getThrowableData().getMessage()); assertNull(uri); uri = ContentUris.withAppendedId(Checkin.Crashes.CONTENT_URI, c.getInt(c.getColumnIndex(Checkin.Crashes._ID))); } } assertNotNull(uri); c.close(); // Update the "logs" column. ContentValues values = new ContentValues(); values.put(Checkin.Crashes.LOGS, "Test Logs"); assertEquals(1, r.update(uri, values, null, null)); c = r.query(uri, null, null, null, null); assertTrue(c.moveToNext()); String logs = c.getString(c.getColumnIndex(Checkin.Crashes.LOGS)); assertEquals("Test Logs", logs); c.deleteRow(); c.close(); c.requery(); assertFalse(c.moveToNext()); c.close(); }
From source file:jp.co.conit.sss.sp.ex1.fragment.MybooksListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mSelfActibity = getActivity();/* w ww .java 2s.c om*/ if (savedInstanceState != null) { mIsRemoveMode = savedInstanceState.getBoolean("remove_mode"); } setEmptyText(getString(R.string.empty_purchase_book_data)); mMyBookAdapter = new MyBookAdapter(mSelfActibity, null, true); setListAdapter(mMyBookAdapter); getListView().setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Cursor c = (Cursor) parent.getItemAtPosition(position); String productId = c.getString(1); boolean isFree = (c.getInt(5) == 0) ? true : false; Builder builder = new Book.Builder(productId); Book book = builder.build(); if (mIsRemoveMode) { PurchasedBookDao purchasedBookDao = new PurchasedBookDao(mSelfActibity); boolean isSuccessDeleteBookData = purchasedBookDao.deleteData(productId); boolean isSuccessDeleteBookReceipt = false; if (isFree) { // ?????????? isSuccessDeleteBookReceipt = true; } else { PurchaseDatabase purchaseDatabase = new PurchaseDatabase(mSelfActibity); isSuccessDeleteBookReceipt = purchaseDatabase.delete(productId); } File file = new File(FileUtil.generateBookFilePath(mSelfActibity, book)); if (file.exists()) { file.delete(); } if (isSuccessDeleteBookData && isSuccessDeleteBookReceipt) { Toast.makeText(mSelfActibity, getString(R.string.delete_purchase_book_data), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(mSelfActibity, getString(R.string.delete_purchase_book_data_fail), Toast.LENGTH_SHORT).show(); } c.requery(); } else { mOnMypageItemSelectedListener.onMypageItemSelected(book); } } }); mPurchasedBookDao = new PurchasedBookDao(mSelfActibity); getMybooksListAsync(); }
From source file:com.radioactiveyak.location_best_practices.services.PlaceCheckinService.java
/** * {@inheritDoc}//www.ja va 2s .co m * Perform a checkin the specified venue. If the checkin fails, add it to the queue and * set an alarm to retry. * * Query the checkin queue to see if there are pending checkins to be retried. */ @Override protected void onHandleIntent(Intent intent) { // Retrieve the details for the checkin to perform. String reference = intent.getStringExtra(PlacesConstants.EXTRA_KEY_REFERENCE); String id = intent.getStringExtra(PlacesConstants.EXTRA_KEY_ID); long timeStamp = intent.getLongExtra(PlacesConstants.EXTRA_KEY_TIME_STAMP, 0); // Check if we're running in the foreground, if not, check if // we have permission to do background updates. boolean backgroundAllowed = cm.getBackgroundDataSetting(); boolean inBackground = sharedPreferences.getBoolean(PlacesConstants.EXTRA_KEY_IN_BACKGROUND, true); if (reference != null && !backgroundAllowed && inBackground) { addToQueue(timeStamp, reference, id); return; } // Check to see if we are connected to a data network. NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); // If we're not connected then disable the retry Alarm, enable the Connectivity Changed Receiver // and add the new checkin directly to the queue. The Connectivity Changed Receiver will listen // for when we connect to a network and start this service to retry the checkins. if (!isConnected) { // No connection so no point triggering an alarm to retry until we're connected. alarmManager.cancel(retryQueuedCheckinsPendingIntent); // Enable the Connectivity Changed Receiver to listen for connection to a network // so we can commit the pending checkins. PackageManager pm = getPackageManager(); ComponentName connectivityReceiver = new ComponentName(this, ConnectivityChangedReceiver.class); pm.setComponentEnabledSetting(connectivityReceiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); // Add this checkin to the queue. addToQueue(timeStamp, reference, id); } else { // Execute the checkin. If it fails, add it to the retry queue. if (reference != null) { if (!checkin(timeStamp, reference, id)) addToQueue(timeStamp, reference, id); } // Retry the queued checkins. ArrayList<String> successfulCheckins = new ArrayList<String>(); Cursor queuedCheckins = contentResolver.query(QueuedCheckinsContentProvider.CONTENT_URI, null, null, null, null); try { // Retry each checkin. while (queuedCheckins.moveToNext()) { long queuedTimeStamp = queuedCheckins .getLong(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_TIME_STAMP)); String queuedReference = queuedCheckins .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_REFERENCE)); String queuedId = queuedCheckins .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_ID)); if (queuedReference == null || checkin(queuedTimeStamp, queuedReference, queuedId)) successfulCheckins.add(queuedReference); } // Delete the queued checkins that were successful. if (successfulCheckins.size() > 0) { StringBuilder sb = new StringBuilder("(" + QueuedCheckinsContentProvider.KEY_REFERENCE + "='" + successfulCheckins.get(0) + "'"); for (int i = 1; i < successfulCheckins.size(); i++) sb.append(" OR " + QueuedCheckinsContentProvider.KEY_REFERENCE + " = '" + successfulCheckins.get(i) + "'"); sb.append(")"); int deleteCount = contentResolver.delete(QueuedCheckinsContentProvider.CONTENT_URI, sb.toString(), null); Log.d(TAG, "Deleted: " + deleteCount); } // If there are still queued checkins then set a non-waking alarm to retry them. queuedCheckins.requery(); if (queuedCheckins.getCount() > 0) { long triggerAtTime = System.currentTimeMillis() + PlacesConstants.CHECKIN_RETRY_INTERVAL; alarmManager.set(AlarmManager.ELAPSED_REALTIME, triggerAtTime, retryQueuedCheckinsPendingIntent); } else alarmManager.cancel(retryQueuedCheckinsPendingIntent); } finally { queuedCheckins.close(); } } }
From source file:com.android.transmart.services.PlaceCheckinService.java
/** * {@inheritDoc}//from w w w. j a v a 2s. co m * Perform a checkin the specified venue. If the checkin fails, add it to the queue and * set an alarm to retry. * * Query the checkin queue to see if there are pending checkins to be retried. */ @Override protected void onHandleIntent(Intent intent) { // Retrieve the details for the checkin to perform. String reference = intent.getStringExtra(LocationConstants.EXTRA_KEY_REFERENCE); String id = intent.getStringExtra(LocationConstants.EXTRA_KEY_ID); long timeStamp = intent.getLongExtra(LocationConstants.EXTRA_KEY_TIME_STAMP, 0); // Check if we're running in the foreground, if not, check if // we have permission to do background updates. boolean backgroundAllowed = cm.getBackgroundDataSetting(); boolean inBackground = sharedPreferences.getBoolean(LocationConstants.EXTRA_KEY_IN_BACKGROUND, true); if (reference != null && !backgroundAllowed && inBackground) { addToQueue(timeStamp, reference, id); return; } // Check to see if we are connected to a data network. NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); // If we're not connected then disable the retry Alarm, enable the Connectivity Changed Receiver // and add the new checkin directly to the queue. The Connectivity Changed Receiver will listen // for when we connect to a network and start this service to retry the checkins. if (!isConnected) { // No connection so no point triggering an alarm to retry until we're connected. alarmManager.cancel(retryQueuedCheckinsPendingIntent); // Enable the Connectivity Changed Receiver to listen for connection to a network // so we can commit the pending checkins. PackageManager pm = getPackageManager(); ComponentName connectivityReceiver = new ComponentName(this, ConnectivityChangedReceiver.class); pm.setComponentEnabledSetting(connectivityReceiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); // Add this checkin to the queue. addToQueue(timeStamp, reference, id); } else { // Execute the checkin. If it fails, add it to the retry queue. if (reference != null) { if (!checkin(timeStamp, reference, id)) addToQueue(timeStamp, reference, id); } // Retry the queued checkins. ArrayList<String> successfulCheckins = new ArrayList<String>(); Cursor queuedCheckins = contentResolver.query(QueuedCheckinsContentProvider.CONTENT_URI, null, null, null, null); try { // Retry each checkin. while (queuedCheckins.moveToNext()) { long queuedTimeStamp = queuedCheckins .getLong(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_TIME_STAMP)); String queuedReference = queuedCheckins .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_REFERENCE)); String queuedId = queuedCheckins .getString(queuedCheckins.getColumnIndex(QueuedCheckinsContentProvider.KEY_ID)); if (queuedReference == null || checkin(queuedTimeStamp, queuedReference, queuedId)) successfulCheckins.add(queuedReference); } // Delete the queued checkins that were successful. if (successfulCheckins.size() > 0) { StringBuilder sb = new StringBuilder("(" + QueuedCheckinsContentProvider.KEY_REFERENCE + "='" + successfulCheckins.get(0) + "'"); for (int i = 1; i < successfulCheckins.size(); i++) sb.append(" OR " + QueuedCheckinsContentProvider.KEY_REFERENCE + " = '" + successfulCheckins.get(i) + "'"); sb.append(")"); int deleteCount = contentResolver.delete(QueuedCheckinsContentProvider.CONTENT_URI, sb.toString(), null); Log.d(TAG, "Deleted: " + deleteCount); } // If there are still queued checkins then set a non-waking alarm to retry them. queuedCheckins.requery(); if (queuedCheckins.getCount() > 0) { long triggerAtTime = System.currentTimeMillis() + LocationConstants.CHECKIN_RETRY_INTERVAL; alarmManager.set(AlarmManager.ELAPSED_REALTIME, triggerAtTime, retryQueuedCheckinsPendingIntent); } else alarmManager.cancel(retryQueuedCheckinsPendingIntent); } finally { queuedCheckins.close(); } } }
From source file:info.guardianproject.otr.app.im.app.ChatView.java
void requeryCursor() { if (mMessageAdapter.isScrolling()) { mMessageAdapter.setNeedRequeryCursor(true); return;/* www. j av a 2s. c o m*/ } // This is redundant if there are messages in view, because the cursor requery will update everything. // However, if there are no messages, no update will trigger below, and we still want this to update. updateWarningView(); // TODO: async query? Cursor cursor = getMessageCursor(); if (cursor != null) { cursor.requery(); } }