List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:com.winsuk.pebbletype.WatchCommunication.java
private void sendThreadList(Context context) { Cursor msgCursor = context.getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);// w w w. j a v a 2 s. com Activity act = new Activity(); act.startManagingCursor(msgCursor); ArrayList<SMSThread> threads = new ArrayList<SMSThread>(); if (msgCursor.moveToFirst()) { for (int i = 0; i < msgCursor.getCount(); i++) { int thread_id = msgCursor.getInt(msgCursor.getColumnIndexOrThrow("thread_id")); SMSThread th = null; for (int t = 0; t < threads.size(); t++) { SMSThread existingTh = threads.get(t); if (existingTh.thread_id == thread_id) { th = existingTh; } } if (th == null) { String address = msgCursor.getString(msgCursor.getColumnIndexOrThrow("address")).toString(); String name = ""; Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, address); Cursor contactCursor = context.getContentResolver().query(uri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); if (contactCursor.moveToFirst()) { name = contactCursor.getString(contactCursor.getColumnIndex(PhoneLookup.DISPLAY_NAME)); contactCursor.close(); } th = new SMSThread(); th.thread_id = thread_id; th.address = address; th.name = name; //th.messages = new ArrayList<String>(); threads.add(th); } /* TODO: this line is causing crashes on select few devices String body = msgCursor.getString(msgCursor.getColumnIndexOrThrow("body")).toString(); if (th.messages.size() < 5) { th.messages.add(body); } */ msgCursor.moveToNext(); } } msgCursor.close(); int limit = (threads.size() <= THREAD_LIMIT ? threads.size() : THREAD_LIMIT); String output = ""; if (limit > 0) { // Calculate how many characters names can take up int availibleCharacters = 120; for (int i = 0; i < limit; i++) { availibleCharacters -= threads.get(i).address.length(); availibleCharacters -= 2; //for ; and \n } int maxNameLength = availibleCharacters / limit - 3; for (int i = 0; i < limit; i++) { SMSThread thread = threads.get(i); String name = ""; if (thread.name.length() < maxNameLength) { name = thread.name; } else { name = thread.name.substring(0, maxNameLength - 1); name += ""; } output = output + thread.address + ";" + name + "\n"; /* List messages for (int ii = 0; ii < thread.messages.size(); ii++) { output = output + thread.messages.get(ii) + "\n"; }*/ } } PebbleDictionary data = new PebbleDictionary(); data.addString(KEY_THREAD_LIST, output); PebbleKit.sendDataToPebble(context, PEBBLE_APP_UUID, data); }
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
/** * ????/* w ww. j a v a2 s. c o m*/ * * @return */ public static int qureyIMCountForSession(long threadId) { int count = 0; String[] columnsList = { "count(*)" }; String where = IMessageColumn.OWN_THREAD_ID + " = " + threadId + " and " + IMessageColumn.BOX_TYPE + " != 3"; Cursor cursor = null; try { cursor = getInstance().sqliteDB().query(DatabaseHelper.TABLES_NAME_IM_MESSAGE, columnsList, where, null, null, null, null); if (cursor != null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { count = cursor.getInt(cursor.getColumnIndex("count(*)")); } } } catch (Exception e) { LogUtil.e(TAG + " " + e.toString()); } finally { if (cursor != null) { cursor.close(); cursor = null; } } return count; }
From source file:com.nnm.smsviet.Message.java
/** * Update {@link Message}./* w ww. ja v a 2s. c o m*/ * * @param cursor * {@link Cursor} to read from */ public void update(final Cursor cursor) { this.read = cursor.getInt(INDEX_READ); this.type = cursor.getInt(INDEX_TYPE); try { if (cursor.getColumnCount() > INDEX_MTYPE) { final int t = cursor.getInt(INDEX_MTYPE); if (t != 0) { this.type = t; } } } catch (IllegalStateException e) { Log.e(TAG, "wrong projection?", e); } }
From source file:com.google.android.apps.iosched.ui.VendorDetailActivity.java
/** {@inheritDoc} */ public void onQueryComplete(int token, Object cookie, Cursor cursor) { try {/* w w w. j av a 2 s.c o m*/ if (!cursor.moveToFirst()) return; mName.setText(cursor.getString(VendorsQuery.NAME)); mLocation.setText(cursor.getString(VendorsQuery.LOCATION)); // Unregister around setting checked state to avoid triggering // listener since change isn't user generated. mStarred.setOnCheckedChangeListener(null); mStarred.setChecked(cursor.getInt(VendorsQuery.STARRED) != 0); mStarred.setOnCheckedChangeListener(this); // Start background fetch to load vendor logo final String logoUrl = cursor.getString(VendorsQuery.LOGO_URL); new VendorLogoTask().execute(logoUrl); mUrl.setText(cursor.getString(VendorsQuery.URL)); mDesc.setText(cursor.getString(VendorsQuery.DESC)); mProductDesc.setText(cursor.getString(VendorsQuery.PRODUCT_DESC)); mTrackId = cursor.getString(VendorsQuery.TRACK_ID); // Assign track details when found // TODO: handle vendors not attached to track ((TextView) findViewById(R.id.title_text)).setText(cursor.getString(VendorsQuery.TRACK_NAME)); UIUtils.setTitleBarColor(findViewById(R.id.title_container), cursor.getInt(VendorsQuery.TRACK_COLOR)); } finally { cursor.close(); } }
From source file:com.digipom.manteresting.android.processor.json.NailsJsonProcessor.java
@Override public ArrayList<ContentProviderOperation> parse(JSONObject response, Meta meta) throws JSONException { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); final TreeSet<Integer> nailIds = new TreeSet<Integer>(); final Cursor nails = resolver.query(ManterestingContract.Nails.CONTENT_URI, new String[] { Nails.NAIL_ID }, null, null, Nails.NAIL_ID + " DESC"); int greatestOfExisting = Integer.MIN_VALUE; if (nails != null && !nails.isClosed()) { try {/* www.ja v a2 s. c om*/ nails.moveToFirst(); final int idColumn = nails.getColumnIndex(Nails.NAIL_ID); while (!nails.isAfterLast()) { final int nailId = nails.getInt(idColumn); nailIds.add(nailId); greatestOfExisting = nailId > greatestOfExisting ? nailId : greatestOfExisting; nails.moveToNext(); } } finally { if (nails != null) { nails.close(); } } } final JSONArray objects = response.getJSONArray("objects"); int smallestOfNew = Integer.MAX_VALUE; for (int i = 0; i < objects.length(); i++) { final JSONObject nailObject = objects.getJSONObject(i); final boolean isPrivate = nailObject.getJSONObject("workbench").getBoolean("private"); if (!isPrivate) { final ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(Nails.CONTENT_URI); final int nailId = nailObject.getInt("id"); smallestOfNew = nailId < smallestOfNew ? nailId : smallestOfNew; builder.withValue(Nails.NAIL_ID, nailId); builder.withValue(Nails.NAIL_JSON, nailObject.toString()); batch.add(builder.build()); nailIds.add(nailId); } } // If more than LIMIT were fetched, and this was the initial fetch, then // we flush everything in the DB before adding the new nails (as // otherwise we would introduce a gap). if (meta.nextOffset == meta.nextLimit // For initial fetch && smallestOfNew > greatestOfExisting) { if (LoggerConfig.canLog(Log.DEBUG)) { Log.d(TAG, "Flushing all existing nails on initial fetch, so as to avoid a gap."); } resolver.delete(Nails.CONTENT_URI, null, null); } else { // If more than 500 nails, find the 500th biggest and delete those // after it. if (nailIds.size() > MAX_COUNT) { Iterator<Integer> it = nailIds.descendingIterator(); for (int i = 0; i < MAX_COUNT; i++) { it.next(); } final Integer toDelete = it.next(); if (LoggerConfig.canLog(Log.DEBUG)) { Log.d(TAG, "deleting from nails where NAIL_ID is less than or equal to " + toDelete); } SelectionBuilder selectionBuilder = new SelectionBuilder(); selectionBuilder.where(ManterestingContract.Nails.NAIL_ID + " <= ?", new String[] { String.valueOf(toDelete) }); resolver.delete(ManterestingContract.Nails.CONTENT_URI, selectionBuilder.getSelection(), selectionBuilder.getSelectionArgs()); } } return batch; }
From source file:com.cryart.sabbathschool.util.SSCore.java
public ArrayList<SSDay> ssGetDaysByLessonSerial(int ssLessonSerial) { SQLiteDatabase db = this.getReadableDatabase(); Cursor c = db.rawQuery( "SELECT ss_days.* " + "FROM ss_days WHERE day_lesson_serial = ? " + "ORDER BY serial ASC", new String[] { String.valueOf(ssLessonSerial) }); ArrayList<SSDay> ret = new ArrayList<SSDay>(); if (c.moveToFirst()) { do {/*from w ww . j av a 2s.co m*/ ret.add(new SSDay(c.getInt(0), c.getString(2), c.getString(3), c.getString(7))); } while (c.moveToNext()); } return ret; }
From source file:com.android.browser.BookmarksPageCallbacks.java
private void openInNewWindow(BrowserBookmarksAdapter adapter, int position) { if (mCallbacks != null) { Cursor c = adapter.getItem(position); boolean isFolder = c.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) == 1; if (isFolder) { long id = c.getLong(BookmarksLoader.COLUMN_INDEX_ID); new OpenAllInTabsTask(id).execute(); } else {//w w w .j a va2 s .c o m mCallbacks.onOpenInNewWindow(BrowserBookmarksPage.getUrl(c)); } } }
From source file:edu.htl3r.schoolplanner.backend.database.AutoSelectDatabase.java
@Override public AutoSelectSet getAutoSelect() { AutoSelectSet autoSelectSet = new AutoSelectSet(); SQLiteDatabase database = this.database.openDatabase(false); Cursor query = this.database.queryWithLoginSetKey(database, DatabaseAutoSelectConstants.TABLE_AUTO_SELECT_NAME); Assert.isTrue(query.getCount() <= 1, "More than one auto-select entry for " + this.database.getLoginSetKeyForTable() + "."); int indexEnabled = query.getColumnIndex(DatabaseAutoSelectConstants.ENABLED); int indexType = query.getColumnIndex(DatabaseAutoSelectConstants.TYPE); int indexValue = query.getColumnIndex(DatabaseAutoSelectConstants.VALUE); while (query.moveToNext()) { boolean enabled = query.getInt(indexEnabled) > 0; String type = query.getString(indexType); int value = query.getInt(indexValue); autoSelectSet.setEnabled(enabled); autoSelectSet.setAutoSelectType(type); autoSelectSet.setAutoSelectValue(value); }/* w w w. j a v a 2s . c om*/ query.close(); this.database.closeDatabase(database); return autoSelectSet; }
From source file:com.seneca.android.senfitbeta.DbHelper.java
public ArrayList<Exercise> getExercises() { Log.d("SELECT EXDB", "Getinging exercise"); String fetchdata = "select * from " + EXERCISE_TABLE + " ORDER BY " + NAMETYPE + " ASC"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(fetchdata, null); cursor.moveToFirst();/*from w w w . j av a 2s. co m*/ if (cursor == null) { Log.d("exiting", "NOTHING"); } ArrayList<Exercise> temp = new ArrayList<Exercise>(); cursor.moveToFirst(); do { Exercise ex = new Exercise(); ex.setId(cursor.getInt(cursor.getColumnIndex(EXERCISE_ID))); ex.setLicense_author(cursor.getString(cursor.getColumnIndex(AUTHOR))); ex.setDescription(cursor.getString(cursor.getColumnIndex(DESCRIPTION))); ex.setName(cursor.getString(cursor.getColumnIndex(NAMETYPE))); ex.setName_original(cursor.getString(cursor.getColumnIndex(ORIGNALNAME))); ex.setCreation_date(cursor.getString(cursor.getColumnIndex(CREATIONDATE))); ex.setCategory(cursor.getString(cursor.getColumnIndex(CATEGORY))); temp.add(ex); } while (cursor.moveToNext()); cursor.close(); getReadableDatabase().close(); return temp; }
From source file:com.android.browser.BookmarksPageCallbacks.java
@Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { BrowserBookmarksAdapter adapter = getChildAdapter(groupPosition); Cursor cursor = adapter.getItem(childPosition); boolean isFolder = cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0; if (mCallbacks != null && mCallbacks.onBookmarkSelected(cursor, isFolder)) { return true; }//from www .jav a 2s .com if (isFolder) { String title = cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE); Uri uri = ContentUris.withAppendedId(BrowserContract.Bookmarks.CONTENT_URI_DEFAULT_FOLDER, id); BreadCrumbView crumbs = getBreadCrumbs(groupPosition); if (crumbs != null) { // update crumbs crumbs.pushView(title, uri); crumbs.setVisibility(View.VISIBLE); } loadFolder(groupPosition, uri); } return true; }