List of usage examples for android.database Cursor getColumnIndex
int getColumnIndex(String columnName);
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static boolean isDirectory(Cursor c) { final String type = c.getString(c.getColumnIndex(Nodes.NODE_KIND)); return U1NodeKind.DIRECTORY == U1NodeKind.valueOf(type.toUpperCase(Locale.US)); }
From source file:com.zrlh.llkc.funciton.Http_Utility.java
/** * Get a HttpClient object which is setting correctly . * //www . j av a 2 s. com * @param context * : context of activity * @return HttpClient: HttpClient object */ public static HttpClient 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, Http_Utility.SET_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParameters, Http_Utility.SET_SOCKET_TIMEOUT); HttpClient client = new DefaultHttpClient(httpParameters); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifiManager.getConnectionInfo(); if (!wifiManager.isWifiEnabled() || -1 == info.getNetworkId()) { // ??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")); 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:com.eTilbudsavis.etasdk.DbHelper.java
/** * Method does not close the Cursor./*from w w w . jav a 2 s . c o m*/ * @param c with data * @return A shoppinglistitem */ public static ShoppinglistItem cursorToSli(Cursor c) { ShoppinglistItem sli = new ShoppinglistItem(); sli.setId(c.getString(c.getColumnIndex(ID))); sli.setErn(c.getString(c.getColumnIndex(ERN))); sli.setModified(Utils.stringToDate(c.getString(c.getColumnIndex(MODIFIED)))); sli.setDescription(c.getString(c.getColumnIndex(DESCRIPTION))); sli.setCount(c.getInt(c.getColumnIndex(COUNT))); sli.setTick(0 < c.getInt(c.getColumnIndex(TICK))); sli.setOfferId(c.getString(c.getColumnIndex(OFFER_ID))); sli.setCreator(c.getString(c.getColumnIndex(CREATOR))); sli.setShoppinglistId(c.getString(c.getColumnIndex(SHOPPINGLIST_ID))); sli.setState(c.getInt(c.getColumnIndex(STATE))); sli.setPreviousId(c.getString(c.getColumnIndex(PREVIOUS_ID))); String meta = c.getString(c.getColumnIndex(META)); try { sli.setMeta(meta == null ? null : new JSONObject(meta)); } catch (JSONException e) { EtaLog.e(TAG, null, e); } sli.setUserId(c.getInt(c.getColumnIndex(USER))); return sli; }
From source file:com.zrlh.llkc.funciton.Http_Utility.java
public static HttpClient getNewHttpClient(Context context) { try {//from w w w .j a v a2 s . com KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); // Set the default socket timeout (SO_TIMEOUT) // in // milliseconds which is the timeout for waiting for data. HttpConnectionParams.setConnectionTimeout(params, Http_Utility.SET_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, Http_Utility.SET_SOCKET_TIMEOUT); HttpClient client = new DefaultHttpClient(ccm, params); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifiManager.getConnectionInfo(); if (!wifiManager.isWifiEnabled() || -1 == info.getNetworkId()) { // ??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")); if (proxyStr != null && proxyStr.trim().length() > 0) { HttpHost proxy = new HttpHost(proxyStr, 80); client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy); } mCursor.close(); } } return client; } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:com.eastedge.readnovel.weibo.net.Utility.java
/** * Get a HttpClient object which is setting correctly . * //ww w . j a v a 2 s . c o m * @param context * : context of activity * @return HttpClient: HttpClient object */ public static HttpClient 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); HttpClient client = new DefaultHttpClient(httpParameters); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (!wifiManager.isWifiEnabled()) { 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:com.bourke.kitchentimer.utils.Utils.java
public static boolean exportCSV(Context context, Cursor cursor) { if (cursor.getCount() == 0) return true; // An array to hold the rows that will be written to the CSV file. final int rowLenght = FoodMetaData.COLUMNS.length - 1; String[] row = new String[rowLenght]; System.arraycopy(FoodMetaData.COLUMNS, 1, row, 0, rowLenght); CSVWriter writer = null;//www. j a va 2 s . c o m boolean success = false; try { writer = new CSVWriter(new FileWriter(Constants.CSV_FILE)); // Write descriptive headers. writer.writeNext(row); int nameIndex = cursor.getColumnIndex(FoodMetaData.NAME); int hoursIndex = cursor.getColumnIndex(FoodMetaData.HOURS); int minutesIndex = cursor.getColumnIndex(FoodMetaData.MINUTES); int secondsIndex = cursor.getColumnIndex(FoodMetaData.SECONDS); if (cursor.requery()) { while (cursor.moveToNext()) { row[0] = cursor.getString(nameIndex); row[1] = cursor.getInt(hoursIndex) + ""; row[2] = cursor.getInt(minutesIndex) + ""; row[3] = cursor.getInt(secondsIndex) + ""; // NOTE: writeNext() handles nulls in row[] gracefully. writer.writeNext(row); } } success = true; } catch (Exception ex) { Log.e("Utils", "exportCSV", ex); } finally { try { if (null != writer) writer.close(); } catch (IOException ex) { } } return success; }
From source file:com.eastedge.readnovel.weibo.net.Utility.java
public static HttpClient getNewHttpClient(Context context) { try {/*from ww w.j a v a 2s. c o m*/ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 10000); HttpConnectionParams.setSoTimeout(params, 10000); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); // Set the default socket timeout (SO_TIMEOUT) // in // milliseconds which is the timeout for waiting for data. HttpConnectionParams.setConnectionTimeout(params, Utility.SET_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, Utility.SET_SOCKET_TIMEOUT); HttpClient client = new DefaultHttpClient(ccm, params); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (!wifiManager.isWifiEnabled()) { 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; } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:com.rsegismont.androlife.core.utils.AndrolifeUtils.java
public static long getTonightIndex(Cursor mCursor) { if (mCursor == null) return -1; if (mCursor.getCount() <= 0) return -1; long dateUtc = -1; final int initialPosition = mCursor.getPosition(); mCursor.moveToPosition(0);// w w w . j av a 2s . c o m final long initialValue = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue)); final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(initialValue); calendar.set(Calendar.HOUR_OF_DAY, 19); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); for (int i = 0; i < mCursor.getCount(); i++) { mCursor.moveToPosition(i); final long value = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue)); if (calendar.getTime().getTime() - value < 0) { mCursor.moveToPosition(Math.max(0, i - 1)); dateUtc = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue)); break; } if ((i == 0) && (calendar.getTime().getTime() - value < 0)) { mCursor.moveToPosition(0); dateUtc = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue)); break; } if (i == (mCursor.getCount() - 1)) { mCursor.moveToPosition(Math.max(0, mCursor.getCount() - 1)); dateUtc = mCursor.getLong(mCursor.getColumnIndex(DatabaseColumn.DATE_UTC.stringValue)); break; } } if (initialPosition >= 0) mCursor.moveToPosition(initialPosition); return dateUtc; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static String getStringField(Uri uri, String columnName) { String result = null;// ww w. java 2 s . c o m final String[] projection = new String[] { columnName }; final Cursor c = sResolver.query(uri, projection, null, null, null); try { if (c.moveToFirst()) { result = c.getString(c.getColumnIndex(columnName)); } } finally { c.close(); } return result; }
From source file:com.fada.sellsteward.myweibo.sina.net.Utility.java
/** * Get a HttpClient object which is setting correctly . * //from w w w . j ava 2 s . c o m * @param context * : context of activity * @return HttpClient: HttpClient object */ public static HttpClient 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); HttpClient client = new DefaultHttpClient(httpParameters); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (!wifiManager.isWifiEnabled()) { // ??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")); if (proxyStr != null && proxyStr.trim().length() > 0) { HttpHost proxy = new HttpHost(proxyStr, 80); client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy); } mCursor.close(); } } return client; }