List of usage examples for android.database Cursor getCount
int getCount();
From source file:com.photowall.oauth.util.BaseHttpClient.java
/** * //from w ww . j ava2s . c o m * @param mContext */ private void setProxy(Context mContext) { try { ContentValues values = new ContentValues(); Cursor cur = mContext.getContentResolver().query(Uri.parse("content://telephony/carriers/preferapn"), null, null, null, null); if (cur != null && cur.getCount() > 0) { if (cur.moveToFirst()) { int colCount = cur.getColumnCount(); for (int i = 0; i < colCount; i++) { values.put(cur.getColumnName(i), cur.getString(i)); } } cur.close(); } String proxyHost = (String) values.get("proxy"); if (!TextUtils.isEmpty(proxyHost) && !isWiFiConnected(mContext)) { int prot = Integer.parseInt(String.valueOf(values.get("port"))); delegate.getCredentialsProvider().setCredentials(new AuthScope(proxyHost, prot), new UsernamePasswordCredentials((String) values.get("user"), (String) values.get("password"))); HttpHost proxy = new HttpHost(proxyHost, prot); delegate.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } } catch (Exception e) { e.printStackTrace(); Log.w(TAG, "set proxy error+++++++++++++++++"); } }
From source file:org.odk.collect.android.tasks.DownloadFormsTask.java
/** * Takes the formName and the URL and attempts to download the specified file. Returns a file * object representing the downloaded file. * //from w ww . j av a2s .c om * @param formName * @param url * @return * @throws Exception */ private File downloadXform(String formName, String url) throws Exception { File f = null; // clean up friendly form name... String rootName = formName.replaceAll("[^\\p{L}\\p{Digit}]", " "); rootName = rootName.replaceAll("\\p{javaWhitespace}+", " "); rootName = rootName.trim(); // proposed name of xml file... String path = Collect.FORMS_PATH + "/" + rootName + ".xml"; int i = 2; f = new File(path); while (f.exists()) { path = Collect.FORMS_PATH + "/" + rootName + "_" + i + ".xml"; f = new File(path); i++; } downloadFile(f, url); // we've downloaded the file, and we may have renamed it // make sure it's not the same as a file we already have String[] projection = { FormsColumns.FORM_FILE_PATH }; String[] selectionArgs = { FileUtils.getMd5Hash(f) }; String selection = FormsColumns.MD5_HASH + "=?"; Cursor c = Collect.getInstance().getContentResolver().query(FormsColumns.CONTENT_URI, projection, selection, selectionArgs, null); if (c.getCount() > 0) { // Should be at most, 1 c.moveToFirst(); // delete the file we just downloaded, because it's a duplicate f.delete(); // set the file returned to the file we already had f = new File(c.getString(c.getColumnIndex(FormsColumns.FORM_FILE_PATH))); } c.close(); return f; }
From source file:com.blandware.android.atleap.test.RobospiceTestCase.java
public void test_book_by_id_with_args() throws Exception { Book.BooksResult result = makeRobospiceRequest(BOOKS_FILENAME, new BooksAuthorsRobospiceRequest()); Cursor cursor = getContext().getContentResolver().query( TestContract.Book.CONTENT_URI.buildUpon().appendPath("1382763").build(), //uri null, //projection TestContract.Book.PUBLISHER_TITLE + "=?", //selection new String[] { "Wow publisher" }, //selectionArgs null //sort order );//from ww w . j a va 2 s .co m assertTrue(cursor != null); assertTrue(cursor.getCount() == 1); cursor.moveToFirst(); assertTrue(cursor.getString(cursor.getColumnIndex(TestContract.Book.TITLE)) != null); assertTrue(cursor.getString(cursor.getColumnIndex(TestContract.Book.TITLE)).equals("Super book")); }
From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java
private void syncCheckins(ContentProviderClient provider, String cookie) { Cursor cursor = null; try {/*from www . j av a 2 s . co m*/ cursor = provider.query(Table.ATTENDEE.getBaseUri(), new String[] { Table.Attendee.ID, Table.Attendee.CHECKIN, Table.Attendee.EVENT_ID, }, Table.Attendee.CHECKIN_MODIFIED, null, null); if (0 == cursor.getCount()) { Log.d(TAG, "No checkin to sync."); return; } int syncCount = 0; while (cursor.moveToNext()) { String attendeeId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.ID)); String eventId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.EVENT_ID)); long checkin = cursor.getLong(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN)); long serverCheckin = postCheckIn(attendeeId, eventId, checkin == 0, cookie); if (serverCheckin >= 0) { ContentValues values = new ContentValues(); values.put(Table.Attendee.CHECKIN_MODIFIED, false); if (0 == serverCheckin) { values.putNull(Table.Attendee.CHECKIN); } else { values.put(Table.Attendee.CHECKIN, serverCheckin); } provider.update(Table.ATTENDEE.getItemUri(eventId, attendeeId), values, null, null); ++syncCount; } } Log.d(TAG, syncCount + " checkin(s) synced."); } catch (RemoteException e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.andrew.apollo.utils.MusicUtils.java
/** * @param cursor The {@link Cursor} used to perform our query. * @return The song list for a MIME type. *///from w w w . j a v a2s . com public static long[] getSongListForCursor(Cursor cursor) { if (cursor == null) { return sEmptyList; } final int len = cursor.getCount(); final long[] list = new long[len]; cursor.moveToFirst(); int columnIndex; try { columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.AUDIO_ID); } catch (final IllegalArgumentException notaplaylist) { columnIndex = cursor.getColumnIndexOrThrow(BaseColumns._ID); } for (int i = 0; i < len; i++) { list[i] = cursor.getLong(columnIndex); cursor.moveToNext(); } cursor.close(); return list; }
From source file:com.mpower.mintel.android.tasks.DownloadFormsTask.java
/** * Takes the formName and the URL and attempts to download the specified file. Returns a file * object representing the downloaded file. * //from w ww . ja v a2s. c o m * @param formName * @param url * @return * @throws Exception */ private File downloadXform(String formName, String url) throws Exception { File f = null; // clean up friendly form name... String rootName = formName.replaceAll("[^\\p{L}\\p{Digit}]", " "); rootName = rootName.replaceAll("\\p{javaWhitespace}+", " "); rootName = rootName.trim(); // proposed name of xml file... String path = MIntel.FORMS_PATH + "/" + rootName + ".xml"; int i = 2; f = new File(path); while (f.exists()) { path = MIntel.FORMS_PATH + "/" + rootName + "_" + i + ".xml"; f = new File(path); i++; } downloadFile(f, url); // we've downloaded the file, and we may have renamed it // make sure it's not the same as a file we already have String[] projection = { FormsColumns.FORM_FILE_PATH }; String[] selectionArgs = { FileUtils.getMd5Hash(f) }; String selection = FormsColumns.MD5_HASH + "=?"; Cursor c = MIntel.getInstance().getContentResolver().query(FormsColumns.CONTENT_URI, projection, selection, selectionArgs, null); if (c.getCount() > 0) { // Should be at most, 1 c.moveToFirst(); // delete the file we just downloaded, because it's a duplicate f.delete(); // set the file returned to the file we already had f = new File(c.getString(c.getColumnIndex(FormsColumns.FORM_FILE_PATH))); } c.close(); return f; }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Utility method to load the list of browser bookmarks. *//*w ww. jav a 2s. com*/ private static ArrayList<BookmarkInfo> loadBookmarks(Launcher context) { ArrayList<BookmarkInfo> bookmarks = new ArrayList<BookmarkInfo>(); Cursor cursor = context.managedQuery(Browser.BOOKMARKS_URI, Browser.HISTORY_PROJECTION, null, null, null); if (cursor != null) { cursor.moveToFirst(); if (cursor.moveToFirst() && cursor.getCount() > 0) { while (cursor.isAfterLast() == false) { String bookmarkIndex = cursor.getString(Browser.HISTORY_PROJECTION_BOOKMARK_INDEX); if (bookmarkIndex != null && bookmarkIndex.equals("1")) { BookmarkInfo bookmark = new BookmarkInfo(); String title = cursor.getString(Browser.HISTORY_PROJECTION_TITLE_INDEX); bookmark.setTitle(title); String url = cursor.getString(Browser.HISTORY_PROJECTION_URL_INDEX); bookmark.setUrl(url); // for some reason the favicons aren't good looking // images // byte[] data = // cursor.getBlob(Browser.HISTORY_PROJECTION_FAVICON_INDEX); // if (data != null) { // try { // Bitmap bitmap = BitmapFactory.decodeByteArray(data, // 0, data.length); // bookmark.setDrawable(new FastBitmapDrawable(bitmap)); // } catch (Exception e) { // Log.e(LOG_TAG, "bookmark icon", e); // } // } bookmarks.add(bookmark); } cursor.moveToNext(); } } } return bookmarks; }
From source file:com.murrayc.galaxyzoo.app.syncadapter.SyncAdapter.java
/** * Upload any outstanding classifications. * * @return Return true if we know for sure that no further uploading is currently necessary. *///from www .j a v a2 s . co m private boolean uploadOutstandingClassifications() { //To keep things simple, don't do this while it is already happening. //This only ever happens on this thread so there should be no need for a lock here. if (mUploadsInProgress > 0) return false; // TODO: Request re-authentication when the server says we have used the wrong name + api_key. // What does the server reply in that case? // See https://github.com/zooniverse/Galaxy-Zoo/issues/184 final LoginUtils.LoginDetails loginDetails = LoginUtils.getAccountLoginDetails(getContext()); // query the database for any item whose classification is not yet uploaded. final ContentResolver resolver = getContentResolver(); final String[] projection = { Item.Columns._ID, Item.Columns.SUBJECT_ID }; final String whereClause = "(" + Item.Columns.DONE + " == 1) AND " + "(" + Item.Columns.UPLOADED + " != 1)"; final Cursor c = resolver.query(Item.ITEMS_URI, projection, whereClause, new String[] {}, null); //TODO: Order by? if (c.getCount() == 0) { c.close(); return true; //Tell the caller that no action was necessary. } while (c.moveToNext()) { final String itemId = c.getString(0); final String subjectId = c.getString(1); mUploadsInProgress++; final UploadTask task = new UploadTask(itemId, subjectId, loginDetails.name, loginDetails.authApiKey); final Thread thread = new Thread(task); thread.start(); } c.close(); return false; }
From source file:com.karura.framework.plugins.Capture.java
/** * Used to find out if we are in a situation where the Camera Intent adds to images to the content store. *//*from www . j a va2 s .com*/ private void checkForDuplicateImage() { Uri contentStore = whichContentStore(); Cursor cursor = queryImgDB(contentStore); int currentNumOfImages = cursor.getCount(); // delete the duplicate file if the difference is 2 if ((currentNumOfImages - numPics) == 2) { cursor.moveToLast(); int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID))) - 1; Uri uri = Uri.parse(contentStore + "/" + id); getContext().getContentResolver().delete(uri, null, null); } }
From source file:org.noorganization.instalistsynch.controller.local.dba.impl.SqliteGroupAccessDbControllerTest.java
License:asdf
public void testInsert() throws Exception { Date currentDate = new Date(); GroupAccess groupAccess = new GroupAccess(1, "fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds."); groupAccess.setLastTokenRequest(currentDate); groupAccess.setLastUpdateFromServer(currentDate); groupAccess.setSynchronize(true);/*from w w w. j av a 2s.com*/ groupAccess.setInterrupted(false); assertEquals(IGroupAuthAccessDbController.INSERTION_CODE.CORRECT, mGroupAuthAccessDbController.insert(groupAccess)); SQLiteDatabase db = mDbHelper.getReadableDatabase(); Cursor cursor = db.query(GroupAccess.TABLE_NAME, GroupAccess.COLUMN.ALL_COLUMNS, GroupAccess.COLUMN.GROUP_ID + " = ? ", new String[] { String.valueOf(1) }, null, null, null); int count = cursor.getCount(); if (count == 0) cursor.close(); assertTrue(cursor.moveToFirst()); int groupId = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.GROUP_ID)); boolean synchronize = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.SYNCHRONIZE)) == 1; boolean interrupted = cursor.getInt(cursor.getColumnIndex(GroupAccess.COLUMN.INTERRUPTED)) == 1; Date lastTokenRequestDate = ISO8601Utils.parse( cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.LAST_TOKEN_REQUEST)), new ParsePosition(0)); Date lastUpdateDate = ISO8601Utils.parse( cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER)), new ParsePosition(0)); String token = cursor.getString(cursor.getColumnIndex(GroupAccess.COLUMN.TOKEN)); cursor.close(); assertEquals(1, groupId); assertEquals(true, synchronize); assertEquals(false, interrupted); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastTokenRequestDate)); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(lastUpdateDate)); assertEquals("fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds.", token); }