List of usage examples for android.database Cursor getColumnIndex
int getColumnIndex(String columnName);
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
/** * Calculates directory content size, recursively if necessary. * //from w w w . j av a 2 s .com * @param resourcePath * the directory resource path to calculate size of * @param recursive * the flag indicating recursive calculation * @return the resorucePath defined directory size */ public static long getDirectorySize(final String resourcePath, final boolean recursive) { final String[] projection = new String[] { Nodes.NODE_RESOURCE_PATH, Nodes.NODE_KIND, Nodes.NODE_SIZE }; final String selection = Nodes.NODE_PARENT_PATH + "=?"; final String[] selectionArgs = new String[] { resourcePath }; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); U1NodeKind kind; long size = 0L; try { if (c.moveToFirst()) { do { kind = U1NodeKind .valueOf(c.getString(c.getColumnIndex(Nodes.NODE_KIND)).toUpperCase(Locale.US)); if (U1NodeKind.FILE == kind) { size += c.getLong(c.getColumnIndex(Nodes.NODE_SIZE)); } else if (U1NodeKind.DIRECTORY == kind && recursive) { final String subDirResourcePath = c.getString(c.getColumnIndex(Nodes.NODE_RESOURCE_PATH)); size += getDirectorySize(subDirResourcePath, true); } } while (c.moveToNext()); } } finally { c.close(); } return size; }
From source file:edu.mit.mobile.android.locast.data.JsonSyncableItem.java
/** * Given a public Uri fragment, finds the local item representing it. If there isn't any such item, null is returned. * * @param context/* w ww . ja v a 2 s.c om*/ * @param dirUri the base local URI to search. * @param pubUri A public URI fragment that represents the given item. This must match the result from the API. * @return a local URI matching the item or null if none were found. */ public static Uri getItemByPubIUri(Context context, Uri dirUri, String pubUri) { Uri uri = null; final ContentResolver cr = context.getContentResolver(); final String[] selectionArgs = { pubUri }; final Cursor c = cr.query(dirUri, PUB_URI_PROJECTION, _PUBLIC_URI + "=?", selectionArgs, null); if (c.moveToFirst()) { uri = ContentUris.withAppendedId(dirUri, c.getLong(c.getColumnIndex(_ID))); } c.close(); return uri; }
From source file:com.external.activeandroid.DataBaseModel.java
@Override public void loadFromCursor(Class<? extends Model> type, Cursor cursor) { final int columnIndex = cursor.getColumnIndex("jsonString"); if (columnIndex < 0) { super.loadFromCursor(type, cursor); return;/* www .j av a2 s .co m*/ } boolean columnIsNull = cursor.isNull(columnIndex); if (!columnIsNull) { jsonString = cursor.getString(columnIndex); try { JSONObject jsonObject = new JSONObject(jsonString); fromJson(jsonObject); } catch (JSONException e) { e.printStackTrace(); } } }
From source file:com.jpa.JPAApplication.java
public ArrayList<String> getDbAuth() { DbModel db = new DbModel(getApplicationContext()); ArrayList<String> s = new ArrayList<String>(); db.open();/*from w ww. j a va 2 s. c o m*/ Cursor c = db.getDbAuth(); int urlCol = c.getColumnIndex(DbModel.MetaData.JPA_URL_KEY); int passwordCol = c.getColumnIndex(DbModel.MetaData.JPA_PASSWORD_KEY); c.moveToFirst(); s.add(c.getString(urlCol)); s.add(c.getString(passwordCol)); db.close(); return s; }
From source file:com.liferay.alerts.model.User.java
public User(Cursor cursor) { _id = cursor.getLong(cursor.getColumnIndex(ID)); _uuid = cursor.getString(cursor.getColumnIndex(UUID)); _fullName = cursor.getString(cursor.getColumnIndex(FULL_NAME)); _portraitId = cursor.getLong(cursor.getColumnIndex(PORTRAIT_ID)); }
From source file:net.naonedbus.manager.impl.CommentaireManager.java
@Override public void onIndexCursor(final Cursor c) { mColId = c.getColumnIndex(CommentaireTable._ID); mColCodeLigne = c.getColumnIndex(CommentaireTable.CODE_LIGNE); mColCodeSens = c.getColumnIndex(CommentaireTable.CODE_SENS); mColCodeArret = c.getColumnIndex(CommentaireTable.CODE_ARRET); mColMessage = c.getColumnIndex(CommentaireTable.MESSAGE); mColSource = c.getColumnIndex(CommentaireTable.SOURCE); mColTimestamp = c.getColumnIndex(CommentaireTable.TIMESTAMP); }
From source file:com.haoqee.chatsdk.net.Utility.java
/** * Get a HttpClient object which is setting correctly . * // w w w. j a v a2 s . co m * @param context * : context of activity * @return HttpClient: HttpClient object */ public static DefaultHttpClient getHttpClient(Context context) { BasicHttpParams httpParameters = new BasicHttpParams(); // Set the default socket timeout (SO_TIMEOUT) // in // milliseconds which is the timeout for waiting for data. HttpConnectionParams.setConnectionTimeout(httpParameters, Utility.SET_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParameters, Utility.SET_SOCKET_TIMEOUT); DefaultHttpClient client = new DefaultHttpClient(httpParameters); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (!wifiManager.isWifiEnabled()) { // ??PN???? 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")); if (proxyStr != null && proxyStr.trim().length() > 0) { HttpHost proxy = new HttpHost(proxyStr, 80); client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy); } mCursor.close(); } } return client; }
From source file:android.database.DatabaseUtils.java
/** * Reads a Integer out of a field in a Cursor and writes it to a Map. * * @param cursor The cursor to read from * @param field The INTEGER field to read * @param values The {@link ContentValues} to put the value into, with the field as the key * @param key The key to store the value with in the map *//* w w w.j a va 2 s . c o m*/ public static void cursorIntToContentValues(Cursor cursor, String field, ContentValues values, String key) { int colIndex = cursor.getColumnIndex(field); if (!cursor.isNull(colIndex)) { values.put(key, cursor.getInt(colIndex)); } else { values.put(key, (Integer) null); } }
From source file:android.database.DatabaseUtils.java
/** * Reads a Double out of a field in a Cursor and writes it to a Map. * * @param cursor The cursor to read from * @param field The REAL field to read/*from ww w . jav a 2s . c om*/ * @param values The {@link ContentValues} to put the value into * @param key The key to store the value with in the map */ public static void cursorDoubleToContentValues(Cursor cursor, String field, ContentValues values, String key) { int colIndex = cursor.getColumnIndex(field); if (!cursor.isNull(colIndex)) { values.put(key, cursor.getDouble(colIndex)); } else { values.put(key, (Double) null); } }
From source file:android.database.DatabaseUtils.java
/** * Reads a Long out of a field in a Cursor and writes it to a Map. * * @param cursor The cursor to read from * @param field The INTEGER field to read * @param values The {@link ContentValues} to put the value into * @param key The key to store the value with in the map */// w ww. j av a 2 s. co m public static void cursorLongToContentValues(Cursor cursor, String field, ContentValues values, String key) { int colIndex = cursor.getColumnIndex(field); if (!cursor.isNull(colIndex)) { Long value = Long.valueOf(cursor.getLong(colIndex)); values.put(key, value); } else { values.put(key, (Long) null); } }