List of usage examples for android.database Cursor moveToFirst
boolean moveToFirst();
From source file:fr.mixit.android.io.JsonHandlerApplyMembers.java
private static boolean isSharedLinkUpdated(Uri uri, String itemId, JSONObject sharedLink, ContentResolver resolver) throws JSONException { final String[] selectionArgs = { itemId }; final Cursor cursor = resolver.query(uri, MixItContract.SharedLinks.PROJ.PROJECTION, MixItContract.SharedLinks.MEMBER_ID + " = ?", selectionArgs, null); try {/* w ww .j ava 2 s. com*/ if (!cursor.moveToFirst()) { return false; } final int curOrderNum = cursor.getInt(MixItContract.SharedLinks.PROJ.ORDER_NUM); final String curName = cursor.getString(MixItContract.SharedLinks.PROJ.NAME) .toLowerCase(Locale.getDefault()).trim(); final String curUrl = cursor.getString(MixItContract.SharedLinks.PROJ.URL) .toLowerCase(Locale.getDefault()).trim(); final int newOrderNum = sharedLink.has(TAG_ORDER_NUM) ? sharedLink.getInt(TAG_ORDER_NUM) : curOrderNum; final String newName = sharedLink.has(TAG_NAME) ? sharedLink.getString(TAG_NAME).toLowerCase(Locale.getDefault()).trim() : curName; final String newUrl = sharedLink.has(TAG_URL) ? sharedLink.getString(TAG_URL).toLowerCase(Locale.getDefault()).trim() : curUrl; return !curName.equals(newName) || // !curUrl.equals(newUrl) || // curOrderNum != newOrderNum; } finally { if (cursor != null) { cursor.close(); } } }
From source file:curso.android.DAO.PerguntaDAO.java
public static Pergunta getPerguntaById(Pergunta p) { Cursor cursor = null; try {/*w ww. ja v a 2 s .co 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:com.eastedge.readnovel.weibo.net.Utility.java
/** * Get a HttpClient object which is setting correctly . * /*from w w w .j a v a 2 s. c om*/ * @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:edu.mit.mobile.android.locast.data.TaggableItem.java
/** * @param cr/*from w w w .ja v a 2s . com*/ * @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; }
From source file:foam.zizim.android.BoskoiService.java
public static CategoriesData[] getParentCategories() { Cursor cursor = BoskoiApplication.mDb.fetchParentCategories(); CategoriesData result[] = new CategoriesData[cursor.getCount()]; int i = 0;/* ww w . java 2 s . c om*/ if (cursor.moveToFirst()) { int titleIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE); int titleNL = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE_NL); int titleLA = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE_LA); int idIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_ID); int parentId = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_PARENT_ID); int color = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_COLOR); int desc = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_DESC); do { CategoriesData cat = new CategoriesData(); cat.setCategoryId(cursor.getInt(idIndex)); cat.setCategoryTitle(cursor.getString(titleIndex)); cat.setCategoryTitleNL(cursor.getString(titleNL)); cat.setCategoryTitleLA(cursor.getString(titleLA)); cat.setCategoryParentId(cursor.getInt(parentId)); cat.setCategoryColor(cursor.getString(color)); cat.setCategoryDescription(cursor.getString(desc)); result[i] = cat; i++; } while (cursor.moveToNext()); } cursor.close(); return result; }
From source file:Main.java
/** * Convert image uri to file/*from w w w. j a v a 2s.c om*/ */ public static String/*File*/ convertImageUriToFile(Context context, Uri imageUri) { Cursor cursor = null; try { String[] projection = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID /*, MediaStore.Images.ImageColumns.ORIENTATION*/ }; cursor = context.getContentResolver().query(imageUri, projection, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) int file_ColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); //int orientation_ColumnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.ORIENTATION); if (cursor.moveToFirst()) { //String orientation = cursor.getString(orientation_ColumnIndex); return cursor.getString(file_ColumnIndex)/*new File(cursor.getString(file_ColumnIndex))*/; } return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.smarthome.deskclock.Alarms.java
/** * Return an Alarm object representing the alarm id in the database. * Returns null if no alarm exists./*from ww w.j a va2s.c o m*/ */ public static Alarm getAlarm(ContentResolver contentResolver, int alarmId) { Cursor cursor = contentResolver.query(ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarmId), Alarm.Columns.ALARM_QUERY_COLUMNS, null, null, null); Alarm alarm = null; if (cursor != null) { if (cursor.moveToFirst()) { alarm = new Alarm(cursor); } cursor.close(); } return alarm; }
From source file:com.fada.sellsteward.myweibo.sina.net.Utility.java
/** * Get a HttpClient object which is setting correctly . * /*from w ww. java 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; }
From source file:foam.zizim.android.BoskoiService.java
public static CategoriesData[] getCategoriesFromParent(int categoryId) { Cursor cursor = BoskoiApplication.mDb.fetchCategoriesFromParent(categoryId); CategoriesData result[] = new CategoriesData[cursor.getCount()]; int i = 0;//from w w w .j a v a2 s . c o m if (cursor.moveToFirst()) { int titleIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE); int titleNL = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE_NL); int titleLA = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_TITLE_LA); int idIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_ID); int parentId = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_PARENT_ID); int color = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_COLOR); int desc = cursor.getColumnIndexOrThrow(BoskoiDatabase.CATEGORY_DESC); do { CategoriesData cat = new CategoriesData(); cat.setCategoryId(cursor.getInt(idIndex)); cat.setCategoryTitle(cursor.getString(titleIndex)); cat.setCategoryTitleNL(cursor.getString(titleNL)); cat.setCategoryTitleLA(cursor.getString(titleLA)); cat.setCategoryParentId(cursor.getInt(parentId)); cat.setCategoryColor(cursor.getString(color)); cat.setCategoryDescription(cursor.getString(desc)); result[i] = cat; i++; } while (cursor.moveToNext()); } cursor.close(); return result; }
From source file:com.eastedge.readnovel.weibo.net.Utility.java
public static HttpClient getNewHttpClient(Context context) { try {/*w w w . ja va 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(); } }