List of usage examples for android.database Cursor getString
String getString(int columnIndex);
From source file:edu.stanford.mobisocial.dungbeetle.DungBeetleContentProvider.java
static void notifyDependencies(DBHelper helper, ContentResolver resolver, String feedName) { Uri feedUri = Feed.uriForName(feedName); if (DBG)/*from ww w .j ava 2 s. co m*/ Log.d(TAG, "notifying dependencies of " + feedUri); resolver.notifyChange(feedUri, null); resolver.notifyChange(Feed.uriForName(Feed.FEED_NAME_GLOBAL), null); if (feedName.contains(":")) { feedName = feedName.split(":")[0]; resolver.notifyChange(Feed.uriForName(feedName), null); } Cursor c = helper.getFeedDependencies(feedName); try { while (c.moveToNext()) { Uri uri = Feed.uriForName(c.getString(0)); resolver.notifyChange(uri, null); } } finally { 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.zrlh.llkc.funciton.Http_Utility.java
public static HttpClient getNewHttpClient(Context context) { try {/* w w w. j a v a2 s.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(); 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.eTilbudsavis.etasdk.DbHelper.java
/** * Method does not close the Cursor./* ww w . ja va2s. com*/ * @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.eastedge.readnovel.weibo.net.Utility.java
/** * Get a HttpClient object which is setting correctly . * // ww w. ja v a 2s .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.github.chenxiaolong.dualbootpatcher.FileUtils.java
public static UriMetadata[] queryUriMetadata(ContentResolver cr, Uri... uris) { ThreadUtils.enforceExecutionOnNonMainThread(); UriMetadata[] metadatas = new UriMetadata[uris.length]; for (int i = 0; i < metadatas.length; i++) { UriMetadata metadata = new UriMetadata(); metadatas[i] = metadata;/*from ww w .ja v a 2s. c o m*/ metadata.uri = uris[i]; metadata.mimeType = cr.getType(metadata.uri); if (SAF_SCHEME.equals(metadata.uri.getScheme())) { Cursor cursor = cr.query(metadata.uri, null, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE); metadata.displayName = cursor.getString(nameIndex); if (cursor.isNull(sizeIndex)) { metadata.size = -1; } else { metadata.size = cursor.getLong(sizeIndex); } } } finally { IOUtils.closeQuietly(cursor); } } else if (FILE_SCHEME.equals(metadata.uri.getScheme())) { metadata.displayName = metadata.uri.getLastPathSegment(); metadata.size = new File(metadata.uri.getPath()).length(); } else { throw new IllegalArgumentException("Cannot handle URI: " + metadata.uri); } } return metadatas; }
From source file:fr.mixit.android.io.JsonHandlerApplyMembers.java
private static boolean isItemUpdated(Uri uri, JSONObject item, ContentResolver resolver, int newMemberType) throws JSONException { final Cursor cursor = resolver.query(uri, MixItContract.Members.PROJ_DETAIL.PROJECTION, null, null, null); try {/*from www . j av a 2s . c o m*/ if (!cursor.moveToFirst()) { return false; } String curFirstName = cursor.getString(MixItContract.Members.PROJ_DETAIL.FIRSTNAME); if (TextUtils.isEmpty(curFirstName)) { curFirstName = EMPTY; } String curLastName = cursor.getString(MixItContract.Members.PROJ_DETAIL.LASTNAME); if (TextUtils.isEmpty(curLastName)) { curLastName = EMPTY; } String curLogin = cursor.getString(MixItContract.Members.PROJ_DETAIL.LOGIN); if (TextUtils.isEmpty(curLogin)) { curLogin = EMPTY; } String curCompany = cursor.getString(MixItContract.Members.PROJ_DETAIL.COMPANY); if (TextUtils.isEmpty(curCompany)) { curCompany = EMPTY; } String curShortDesc = cursor.getString(MixItContract.Members.PROJ_DETAIL.SHORT_DESC); if (TextUtils.isEmpty(curShortDesc)) { curShortDesc = EMPTY; } String curLongDesc = cursor.getString(MixItContract.Members.PROJ_DETAIL.LONG_DESC); if (TextUtils.isEmpty(curLongDesc)) { curLongDesc = EMPTY; } String curImageUrl = cursor.getString(MixItContract.Members.PROJ_DETAIL.IMAGE_URL); if (TextUtils.isEmpty(curImageUrl)) { curImageUrl = EMPTY; } final int curNbConsults = cursor.getInt(MixItContract.Members.PROJ_DETAIL.NB_CONSULT); String curLevel = cursor.getString(MixItContract.Members.PROJ_DETAIL.LEVEL); if (TextUtils.isEmpty(curLevel)) { curLevel = EMPTY; } // final int curMemberType = cursor.getInt(MixItContract.Members.PROJ_DETAIL.TYPE); final String newFirstName = item.has(TAG_FIRSTNAME) ? item.getString(TAG_FIRSTNAME).trim() : curFirstName; final String newLastName = item.has(TAG_LASTNAME) ? item.getString(TAG_LASTNAME).trim() : curLastName; final String newLogin = item.has(TAG_LOGIN) ? item.getString(TAG_LOGIN).trim() : curLogin; final String newCompany = item.has(TAG_COMPANY) ? item.getString(TAG_COMPANY).trim() : curCompany; final String newShortDesc = item.has(TAG_SHORT_DESC) ? item.getString(TAG_SHORT_DESC).trim() : curShortDesc; final String newLongDesc = item.has(TAG_LONG_DESC) ? item.getString(TAG_LONG_DESC).trim() : curLongDesc; final String newImageUrl = item.has(TAG_LOGO) ? item.getString(TAG_LOGO).trim() : item.has(TAG_IMAGE_URL) ? item.getString(TAG_IMAGE_URL).trim() : curImageUrl; final int newNbConsults = item.has(TAG_NB_CONSULTS) ? item.getInt(TAG_NB_CONSULTS) : curNbConsults; final String newLevel = item.has(TAG_LEVEL) ? item.getString(TAG_LEVEL).trim() : curLevel; return !curFirstName.equalsIgnoreCase(newFirstName) || // !curLastName.equalsIgnoreCase(newLastName) || // !curLogin.equals(newLogin) || // !curCompany.equals(newCompany) || // !curShortDesc.equals(newShortDesc) || // !curLongDesc.equals(newLongDesc) || // !curImageUrl.equals(newImageUrl) || // curNbConsults != newNbConsults || // !curLevel.equals(newLevel) /* || // curMemberType != newMemberType && newMemberType != MixItContract.Members.TYPE_MEMBER */; } finally { if (cursor != null) { cursor.close(); } } }
From source file:me.myatminsoe.myansms.Message.java
/** * Get a {@link Message} from cache or {@link Cursor}. * * @param context {@link Context}//from w w w .j a va 2s. co m * @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); while (CACHE.size() > CAHCESIZE) { Integer i = CACHE.keySet().iterator().next(); Message cc = CACHE.remove(i); if (cc == null) { break; } } } else { ret.update(cursor); } return ret; } }
From source file:com.eastedge.readnovel.weibo.net.Utility.java
public static HttpClient getNewHttpClient(Context context) { try {/* w w w.ja v a 2 s . 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:edu.mit.mobile.android.locast.data.TaggableItem.java
/** * @param cr/*from w ww. ja va2 s. c o m*/ * @param item * @param prefix * @return a list of all the tags attached to a given item */ public static Set<String> getTags(ContentResolver cr, Uri item, String prefix) { final Cursor tags = cr.query(Uri.withAppendedPath(item, Tag.PATH), Tag.DEFAULT_PROJECTION, null, null, null); final Set<String> tagSet = new HashSet<String>(tags.getCount()); final int tagColumn = tags.getColumnIndex(Tag._NAME); final Predicate<String> predicate = getPrefixPredicate(prefix); for (tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) { final String tag = tags.getString(tagColumn); if (predicate.apply(tag)) { final int separatorIndex = tag.indexOf(PREFIX_SEPARATOR); if (separatorIndex == -1) { tagSet.add(tag); } else { tagSet.add(tag.substring(separatorIndex + 1)); } } } tags.close(); return tagSet; }