List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:Main.java
private static String makeTitle(Cursor result, String packageName, String extNumber) { String title = ""; String prefValue = mPreferences.getString("ext_title_preference" + extNumber, "app_count"); // App name, no count if (prefValue.equals(mPrefValues[0])) { try {/*from w w w. j av a2s . com*/ title = mPm.getApplicationLabel(mPm.getApplicationInfo(packageName, 0)).toString(); } catch (NameNotFoundException e) { e.printStackTrace(); } } // App name with count else if (prefValue.equals(mPrefValues[1])) { int count = result.getCount() == 0 ? 0 : result.getInt(10); try { title = mPm.getApplicationLabel(mPm.getApplicationInfo(packageName, 0)).toString() + " (" + Integer.toString(count) + ")"; } catch (NameNotFoundException e) { e.printStackTrace(); } } // Custom, no count else if (prefValue.equals(mPrefValues[2])) { try { String temp = mPreferences.getString("text_preference" + extNumber, ""); if (TextUtils.isEmpty(temp)) title = mPm.getApplicationLabel(mPm.getApplicationInfo(packageName, 0)).toString(); else title = temp; } catch (NameNotFoundException e) { e.printStackTrace(); } } // Custom with count else if (prefValue.equals(mPrefValues[3])) { int count = result.getCount() == 0 ? 0 : result.getInt(10); try { String temp = mPreferences.getString("text_preference" + extNumber, ""); if (TextUtils.isEmpty(temp)) title = mPm.getApplicationLabel(mPm.getApplicationInfo(packageName, 0)).toString() + " (" + Integer.toString(count) + ")"; else title = temp + " (" + Integer.toString(count) + ")"; } catch (NameNotFoundException e) { e.printStackTrace(); } } // Notification title, no count else if (prefValue.equals(mPrefValues[4])) { try { title = result.getString(3); } catch (CursorIndexOutOfBoundsException e) { try { title = mPm.getApplicationLabel(mPm.getApplicationInfo(packageName, 0)).toString(); } catch (NameNotFoundException e1) { e1.printStackTrace(); } } } // Notification title with count else if (prefValue.equals(mPrefValues[5])) { int count = result.getCount() == 0 ? 0 : result.getInt(10); try { title = result.getString(3) + " (" + Integer.toString(count) + ")"; } catch (CursorIndexOutOfBoundsException e) { try { title = mPm.getApplicationLabel(mPm.getApplicationInfo(packageName, 0)).toString() + " (" + Integer.toString(count) + ")"; } catch (NameNotFoundException e1) { e1.printStackTrace(); } } } result.moveToFirst(); return title; }
From source file:org.zywx.wbpalmstar.engine.EUtil.java
public static java.net.Proxy checkJavaProxy(Context context) { java.net.Proxy proxy = null;/*from w w w . ja va 2 s . c o m*/ if (!wifiEnable(context)) {// ??APN Uri uri = Uri.parse("content://telephony/carriers/preferapn"); Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null); if (mCursor != null && mCursor.moveToFirst()) { String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy")); int proxyPort = mCursor.getInt(mCursor.getColumnIndex("port")); if (proxyStr != null && proxyStr.trim().length() > 0) { if (0 == proxyPort) { proxyPort = 80; } proxy = new java.net.Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyStr, proxyPort)); } mCursor.close(); } } return proxy; }
From source file:org.zywx.wbpalmstar.engine.EUtil.java
public static HttpHost checkAndroidProxy(Context context) { HttpHost proxy = null;/*from w w w.j a v a 2 s . co m*/ if (!wifiEnable(context)) {// ??APN Uri uri = Uri.parse("content://telephony/carriers/preferapn"); Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null); if (mCursor != null && mCursor.moveToFirst()) { String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy")); int proxyPort = mCursor.getInt(mCursor.getColumnIndex("port")); if (proxyStr != null && proxyStr.trim().length() > 0) { if (0 == proxyPort) { proxyPort = 80; } proxy = new HttpHost(proxyStr, proxyPort); } mCursor.close(); } } return proxy; }
From source file:com.nnm.smsviet.Message.java
/** * Get a {@link Message} from cache or {@link Cursor}. * //from w ww. j a v a 2s . c o m * @param context * {@link Context} * @param cursor * {@link Cursor} * @return {@link Message} */ public static Message getMessage(final Context context, final Cursor cursor) { synchronized (CACHE) { String body = cursor.getString(INDEX_BODY); int id = cursor.getInt(INDEX_ID); if (body == null) { // MMS id *= -1; } Message ret = CACHE.get(id); if (ret == null) { ret = new Message(context, cursor); CACHE.put(id, ret); Log.d(TAG, "cachesize: " + CACHE.size()); while (CACHE.size() > CAHCESIZE) { Integer i = CACHE.keySet().iterator().next(); Log.d(TAG, "rm msg. from cache: " + i); Message cc = CACHE.remove(i); if (cc == null) { Log.w(TAG, "CACHE might be inconsistent!"); break; } } } else { ret.update(cursor); } return ret; } }
From source file:info.staticfree.android.units.UnitUsageDBHelper.java
/** * Increments the usage counter for the given unit. * @param unit name of the unit//from w w w . jav a 2s . c o m * @param db the unit usage database */ public static void logUnitUsed(String unit, ContentResolver cr) { final String[] selectionArgs = { unit }; final Cursor c = cr.query(UsageEntry.CONTENT_URI, INCREMENT_QUERY_PROJECTION, UsageEntry._UNIT + "=?", selectionArgs, null); if (c.getCount() > 0) { c.moveToFirst(); final int useCount = c.getInt(c.getColumnIndex(UsageEntry._USE_COUNT)); final int id = c.getInt(c.getColumnIndex(UsageEntry._ID)); final ContentValues cv = new ContentValues(); cv.put(UsageEntry._USE_COUNT, useCount + 1); cr.update(ContentUris.withAppendedId(UsageEntry.CONTENT_URI, id), cv, null, null); } else { final ContentValues cv = new ContentValues(); cv.put(UsageEntry._UNIT, unit); cv.put(UsageEntry._USE_COUNT, 1); cv.put(UsageEntry._FACTOR_FPRINT, getFingerprint(unit)); cr.insert(UsageEntry.CONTENT_URI, cv); } c.close(); }
From source file:at.bitfire.davdroid.resource.LocalTaskList.java
public static LocalTaskList[] findAll(Account account, ContentProviderClient providerClient) throws RemoteException { @Cleanup Cursor cursor = providerClient.query(taskListsURI(account), new String[] { TaskContract.TaskLists._ID, TaskContract.TaskLists._SYNC_ID }, null, null, null); LinkedList<LocalTaskList> taskList = new LinkedList<>(); while (cursor != null && cursor.moveToNext()) taskList.add(new LocalTaskList(account, providerClient, cursor.getInt(0), cursor.getString(1))); return taskList.toArray(new LocalTaskList[taskList.size()]); }
From source file:com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper.java
/** * Creates a quiz corresponding to the projection provided from a cursor row. * Currently only {@link QuizTable#PROJECTION} is supported. * * @param cursor The Cursor containing the data. * @return The created quiz.//from www. jav a2s.c om */ private static Quiz createQuizDueToType(Cursor cursor) { // "magic numbers" based on QuizTable#PROJECTION final String type = cursor.getString(2); final String question = cursor.getString(3); final String answer = cursor.getString(4); final String options = cursor.getString(5); final int min = cursor.getInt(6); final int max = cursor.getInt(7); final int step = cursor.getInt(8); final boolean solved = getBooleanFromDatabase(cursor.getString(11)); switch (type) { case JsonAttributes.QuizType.ALPHA_PICKER: { return new AlphaPickerQuiz(question, answer, solved); } case JsonAttributes.QuizType.FILL_BLANK: { return createFillBlankQuiz(cursor, question, answer, solved); } case JsonAttributes.QuizType.FILL_TWO_BLANKS: { return createFillTwoBlanksQuiz(question, answer, solved); } case JsonAttributes.QuizType.FOUR_QUARTER: { return createFourQuarterQuiz(question, answer, options, solved); } case JsonAttributes.QuizType.MULTI_SELECT: { return createMultiSelectQuiz(question, answer, options, solved); } case JsonAttributes.QuizType.PICKER: { return new PickerQuiz(question, Integer.valueOf(answer), min, max, step, solved); } case JsonAttributes.QuizType.SINGLE_SELECT: //fall-through intended case JsonAttributes.QuizType.SINGLE_SELECT_ITEM: { return createSelectItemQuiz(question, answer, options, solved); } case JsonAttributes.QuizType.TOGGLE_TRANSLATE: { return createToggleTranslateQuiz(question, answer, options, solved); } case JsonAttributes.QuizType.TRUE_FALSE: { return createTrueFalseQuiz(question, answer, solved); } default: { throw new IllegalArgumentException("Quiz type " + type + " is not supported"); } } }
From source file:net.smart_json_database.JSONEntity.java
public static JSONEntity loadFromCursor(Cursor c) throws JSONException { int col_id = c.getColumnIndex("json_uid"); int col_createDate = c.getColumnIndex("createDate"); int col_updateDate = c.getColumnIndex("updateDate"); int col_data = c.getColumnIndex("data"); int col_type = c.getColumnIndex("type"); JSONEntity entity = new JSONEntity(); entity.setUid(c.getInt(col_id)); entity.setCreationDate(Util.ParseDateFromString(c.getString(col_createDate))); entity.setUpdateDate(Util.ParseDateFromString(c.getString(col_updateDate))); entity.setData(new JSONObject(c.getString(col_data))); entity.setType(c.getString(col_type)); return entity; }
From source file:curso.android.DAO.PerguntaDAO.java
public static Pergunta getPerguntaById(Pergunta p) { Cursor cursor = null; try {/*from www .j a v a 2 s .c o m*/ cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE ask_id = " + p.getAsk_id(), null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int perguntaIndex = cursor.getColumnIndex("ask_pergunta"); int nomeIndex = cursor.getColumnIndex("user_nome"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String pergunta = cursor.getString(perguntaIndex); String user_name = cursor.getString(nomeIndex); Pergunta ask = new Pergunta(); ask.setAsk_id(id); ask.setUser_id(user); ask.setAsk_pergunta(pergunta); ask.setUser_name(user_name); return ask; } while (!cursor.isAfterLast()); } return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:za.co.neilson.alarm.database.Database.java
public static List<Alarm> getAll() { List<Alarm> alarms = new ArrayList<Alarm>(); Cursor cursor = Database.getCursor(); if (cursor.moveToFirst()) { do {/*w ww . j av a2s . c o m*/ // COLUMN_ALARM_ID, // COLUMN_ALARM_ACTIVE, // COLUMN_ALARM_TIME, // COLUMN_ALARM_DAYS, // COLUMN_ALARM_DIFFICULTY, // COLUMN_ALARM_TONE, // COLUMN_ALARM_VIBRATE, // COLUMN_ALARM_NAME Alarm alarm = new Alarm(); alarm.setId(cursor.getInt(0)); alarm.setAlarmActive(cursor.getInt(1) == 1); alarm.setAlarmTime(cursor.getString(2)); byte[] repeatDaysBytes = cursor.getBlob(3); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(repeatDaysBytes); try { ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); Alarm.Day[] repeatDays; Object object = objectInputStream.readObject(); if (object instanceof Alarm.Day[]) { repeatDays = (Alarm.Day[]) object; alarm.setDays(repeatDays); } } catch (StreamCorruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } alarm.setDifficulty(Difficulty.values()[cursor.getInt(4)]); alarm.setAlarmTonePath(cursor.getString(5)); alarm.setVibrate(cursor.getInt(6) == 1); alarm.setAlarmName(cursor.getString(7)); alarms.add(alarm); } while (cursor.moveToNext()); } cursor.close(); return alarms; }