List of usage examples for android.database Cursor moveToFirst
boolean moveToFirst();
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static Set<String> getUserNodePaths() { Set<String> userNodePaths = new TreeSet<String>(); final String[] projection = new String[] { Nodes._ID, Nodes.NODE_RESOURCE_PATH }; final String selection = Nodes.NODE_PARENT_PATH + " IS NULL"; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, null, null); try {// w w w. j av a2 s .co m if (c.moveToFirst()) { String resourcePath; do { resourcePath = c.getString(c.getColumnIndex(Nodes.NODE_RESOURCE_PATH)); userNodePaths.add(resourcePath); } while (c.moveToNext()); } } finally { c.close(); } return userNodePaths; }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java
public static String getRealPathFromURI(Uri contentUri, Context ctx) { String[] proj = { MediaStore.Video.Media.DATA }; Cursor cursor = ((Activity) ctx).managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); cursor.moveToFirst(); String ret = cursor.getString(columnIndex); return ret; } else {//from ww w.ja v a 2 s. c o m return contentUri.getPath(); } }
From source file:com.zzl.zl_app.cache.Utility.java
public static HttpClient getNewHttpClient(Context context) { try {//from w ww .j av 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(); 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); 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.ubuntuone.android.files.provider.MetaUtilities.java
public static String getStringField(String resourcePath, String columnName) { String result = null;// w ww. jav a 2 s .c o m final String[] projection = new String[] { columnName }; final String[] selectionArgs = new String[] { resourcePath }; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, sSelection, selectionArgs, null); try { if (c.moveToFirst()) { result = c.getString(c.getColumnIndex(columnName)); } } finally { c.close(); } return result; }
From source file:curso.android.DAO.PerguntaDAO.java
public static List<Pergunta> readAll() { Cursor cursor = null; try {//from w ww . j a v a 2 s .c om List<Pergunta> all = new ArrayList<Pergunta>(); cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE user_id <> " + Const.config.idUser, 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_name"); int statusIndex = cursor.getColumnIndex("status"); 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); String status = cursor.getString(statusIndex); Pergunta ask = new Pergunta(); ask.setAsk_id(id); ask.setUser_id(user); ask.setAsk_pergunta(pergunta); ask.setUser_name(user_name); ask.setStatus(Integer.valueOf(status) == 1); all.add(ask); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return all; } finally { if (cursor != null) { cursor.close(); } } }
From source file:curso.android.DAO.PerguntaDAO.java
public static List<Pergunta> getPerguntasUsuario() { Cursor cursor = null; try {//from w ww .ja va 2s.c o m List<Pergunta> questions = new ArrayList<Pergunta>(); cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE user_id =" + Const.config.idUser, null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int perguntaIndex = cursor.getColumnIndex("ask_pergunta"); int nameIndex = cursor.getColumnIndex("user_name"); int statusIndex = cursor.getColumnIndex("status"); 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(nameIndex); String status = cursor.getString(statusIndex); Pergunta ask = new Pergunta(); ask.setAsk_id(id); ask.setUser_id(user); ask.setAsk_pergunta(pergunta); ask.setUser_name(user_name); ask.setStatus(Integer.valueOf(status) == 1); questions.add(ask); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return questions; } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
/** * Try to get the exif orientation of the passed image uri * //ww w.j av a 2s . co m * @param context * @param uri * @return */ public static int getExifOrientation(Context context, Uri uri) { final String scheme = uri.getScheme(); ContentProviderClient provider = null; if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) { return getExifOrientation(uri.getPath()); } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) { try { provider = context.getContentResolver().acquireContentProviderClient(uri); } catch (SecurityException e) { return 0; } if (provider != null) { Cursor result; try { result = provider.query(uri, new String[] { Images.ImageColumns.ORIENTATION, Images.ImageColumns.DATA }, null, null, null); } catch (Exception e) { e.printStackTrace(); return 0; } if (result == null) { return 0; } int orientationColumnIndex = result.getColumnIndex(Images.ImageColumns.ORIENTATION); int dataColumnIndex = result.getColumnIndex(Images.ImageColumns.DATA); try { if (result.getCount() > 0) { result.moveToFirst(); int rotation = 0; if (orientationColumnIndex > -1) { rotation = result.getInt(orientationColumnIndex); } if (dataColumnIndex > -1) { String path = result.getString(dataColumnIndex); rotation |= getExifOrientation(path); } return rotation; } } finally { result.close(); } } } return 0; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static Set<Integer> getChildrenIds(String resourcePath) { Set<Integer> ids = new TreeSet<Integer>(); final String[] projection = new String[] { Nodes._ID, Nodes.NODE_RESOURCE_STATE }; final String selection = Nodes.NODE_PARENT_PATH + "=?"; //+ " AND " + Nodes.NODE_RESOURCE_STATE + " IS NULL"; // FIXME final String[] selectionArgs = new String[] { resourcePath }; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); try {/* w w w .j av a2 s . c o m*/ if (c.moveToFirst()) { int id; do { id = c.getInt(c.getColumnIndex(Nodes._ID)); // We check the state, above SQL is failing to filter out // nodes which are in non-null state. No idea why. String s = c.getString(c.getColumnIndex(Nodes.NODE_RESOURCE_STATE)); if (s == null) { ids.add(id); } else { Log.d("MetaUtilities", "child state != null, ignoring"); } } while (c.moveToNext()); } } finally { c.close(); } return ids; }
From source file:Main.java
/** * Retourner le nom de calendrier/* ww w. j av a 2s . com*/ * * @param id * @return */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static String getCalendarName(ContentResolver contentResolver, String id) { String name = null; Cursor cursor; String[] projection; Uri calendarUri; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { calendarUri = CalendarContract.Calendars.CONTENT_URI; projection = new String[] { CalendarContract.Calendars._ID, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME }; } else if (Integer.parseInt(Build.VERSION.SDK) >= 8) { calendarUri = Uri.parse("content://com.android.calendar/calendars"); projection = new String[] { "_id", "displayname" }; } else { calendarUri = Uri.parse("content://calendar/calendars"); projection = new String[] { "_id", "displayname" }; } cursor = contentResolver.query(calendarUri, projection, "_id = ?", new String[] { id }, null); if (cursor.moveToFirst()) { name = cursor.getString(1); } cursor.close(); return name; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static long getSize(final String resourcePath) { final String[] projection = new String[] { Nodes.NODE_SIZE }; final String selection = Nodes.NODE_RESOURCE_PATH + "=?"; final String[] selectionArgs = new String[] { resourcePath }; Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); long size = 0L; try {//from ww w. j a v a2 s.c om if (c.moveToFirst()) { size = c.getLong(c.getColumnIndex(Nodes.NODE_SIZE)); } } finally { c.close(); } return size; }