List of usage examples for android.database Cursor getColumnIndexOrThrow
int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;
From source file:com.example.linhdq.test.documents.creation.NewDocumentActivity.java
private void onTakePhotoActivityResult(CameraResult cameraResult) { if (cameraResult.mResultCode == RESULT_OK) { if (cameraResult.mRequestCode == REQUEST_CODE_MAKE_PHOTO) { Cursor myCursor = null; Date dateOfPicture;/*from w w w . j a v a2 s. c o m*/ //check if there is a file at the uri we specified if (cameraPicUri != null) { File f = new File(cameraPicUri.getPath()); if (f.isFile() && f.exists() && f.canRead()) { //all is well Log.i(LOG_TAG, "onTakePhotoActivityResult"); loadBitmapFromContentUri(cameraPicUri, ImageSource.CAMERA); return; } } //try to look up the image by querying the media content provider try { // Create a Cursor to obtain the file Path for the large // image String[] largeFileProjection = { MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA, MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.Images.ImageColumns.DATE_TAKEN }; String largeFileSort = MediaStore.Images.ImageColumns._ID + " DESC"; myCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, largeFileProjection, null, null, largeFileSort); if (myCursor != null) { myCursor.moveToFirst(); // This will actually give you the file path location of the // image. String largeImagePath = myCursor .getString(myCursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATA)); Uri tempCameraPicUri = Uri.fromFile(new File(largeImagePath)); dateOfPicture = new Date(myCursor.getLong( myCursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATE_TAKEN))); if (dateOfPicture.getTime() == 0 || (dateOfPicture.after(dateCameraIntentStarted))) { cameraPicUri = tempCameraPicUri; } } } catch (Exception ignored) { } finally { if (myCursor != null) { myCursor.close(); } } } if (cameraPicUri == null) { try { cameraPicUri = mCameraResult.mData.getData(); } catch (Exception e) { showFileError(PixLoadStatus.CAMERA_APP_ERROR); } } if (cameraPicUri != null) { loadBitmapFromContentUri(cameraPicUri, mCameraResult.mSource); } else { showFileError(PixLoadStatus.CAMERA_NO_IMAGE_RETURNED); } } }
From source file:com.dwdesign.tweetings.util.Utils.java
public static long getAccountId(final Context context, final String username) { if (context == null) return -1; long user_id = -1; final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, new String[] { Accounts.USER_ID }, Accounts.USERNAME + " = ?", new String[] { username }, null); if (cur == null) return user_id; if (cur.getCount() > 0) { cur.moveToFirst();//from ww w. ja va 2 s .c o m user_id = cur.getLong(cur.getColumnIndexOrThrow(Accounts.USER_ID)); } cur.close(); return user_id; }
From source file:com.ezac.gliderlogs.FlightOverviewActivity.java
public void addItemSpinner_2() { Uri uri = FlightsContentProvider.CONTENT_URI_GLIDER; String[] projection = { GliderLogTables.G_REGISTRATION }; Cursor cur_sp = getContentResolver().query(uri, projection, null, null, GliderLogTables.G_REGISTRATION + " ASC"); if (cur_sp != null) { try {/*from w ww .j a v a 2s . co m*/ cur_sp.moveToFirst(); // insert dummy item with no data as to avoid pre-selection GliderList.add(""); for (int i = 0; i < cur_sp.getCount(); i++) { GliderList.add(cur_sp.getString(cur_sp.getColumnIndexOrThrow(GliderLogTables.G_REGISTRATION))); cur_sp.moveToNext(); } } finally { if (!cur_sp.isClosed()) { cur_sp.close(); } } } }
From source file:com.dwdesign.tweetings.util.Utils.java
public static int getAccountColor(final Context context, final long account_id) { if (context == null) return Color.TRANSPARENT; Integer color = sAccountColors.get(account_id); if (color == null) { final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, new String[] { Accounts.USER_COLOR }, Accounts.USER_ID + "=" + account_id, null, null); if (cur == null) return Color.TRANSPARENT; if (cur.getCount() <= 0) { cur.close();//from w w w. jav a 2 s. c o m return Color.TRANSPARENT; } cur.moveToFirst(); sAccountColors.put(account_id, color = cur.getInt(cur.getColumnIndexOrThrow(Accounts.USER_COLOR))); cur.close(); } return color; }
From source file:com.ezac.gliderlogs.FlightOverviewActivity.java
public void addItemSpinner_1() { Uri uri = FlightsContentProvider.CONTENT_URI_MEMBER; String[] projection = { GliderLogTables.M_ID, GliderLogTables.M_2_NAME, GliderLogTables.M_3_NAME, GliderLogTables.M_1_NAME, GliderLogTables.M_INSTRUCTION }; Cursor cur_sp = getContentResolver().query(uri, projection, null, null, GliderLogTables.M_1_NAME + " ASC"); if (cur_sp != null) { try {//from w ww . j a v a 2 s. c o m cur_sp.moveToFirst(); // insert dummy item with no data as to avoid pre-selection MemberList.add(""); MemberIndexList.add(""); for (int i = 0; i < cur_sp.getCount(); i++) { String tmp = cur_sp.getString(cur_sp.getColumnIndexOrThrow(GliderLogTables.M_1_NAME)) + " " + cur_sp.getString(cur_sp.getColumnIndexOrThrow(GliderLogTables.M_2_NAME)) + " " + cur_sp.getString(cur_sp.getColumnIndexOrThrow(GliderLogTables.M_3_NAME)); MemberList.add(tmp.replaceAll("\\s+", " ")); MemberIndexList.add(cur_sp.getString(cur_sp.getColumnIndexOrThrow(GliderLogTables.M_ID))); cur_sp.moveToNext(); } } finally { if (!cur_sp.isClosed()) { cur_sp.close(); } } } }
From source file:com.ezac.gliderlogs.FlightOverviewActivity.java
@SuppressLint("SimpleDateFormat") public void GliderLogToCSV(String DB, String device_id) { // format date's SimpleDateFormat CSV = new SimpleDateFormat("yyyyMMdd_kkss"); SimpleDateFormat DIR = new SimpleDateFormat("yyyy/MM_dd"); Date myDate = new Date(); String TS_DB = CSV.format(myDate); String TS_DIR = DIR.format(myDate); // to internal sdcard File dir = new File(Environment.getExternalStorageDirectory() + "/Download/" + TS_DIR); if (!dir.exists() || !dir.isDirectory()) { dir.mkdir();/*from w w w .ja v a2 s.c o m*/ } File myFile = new File(Environment.getExternalStorageDirectory() + "/Download/" + TS_DIR + "/" + device_id.toUpperCase(Locale.US) + "_" + TS_DB + ".csv"); try { myFile.createNewFile(); FileOutputStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); myOutWriter.append( "datum;start;landing;duur;soort;registratie;piloot;piloot_id;tweede;tweede_id;instructie;opmerking;methode"); myOutWriter.append("\n"); Uri uri = FlightsContentProvider.CONTENT_URI_FLIGHT; String[] projection = { GliderLogTables.F_DATE, GliderLogTables.F_STARTED, GliderLogTables.F_LANDED, GliderLogTables.F_DURATION, GliderLogTables.F_TYPE, GliderLogTables.F_REGISTRATION, GliderLogTables.F_PILOT, GliderLogTables.F_PILOT_ID, GliderLogTables.F_COPILOT, GliderLogTables.F_COPILOT_ID, GliderLogTables.F_INSTRUCTION, GliderLogTables.F_NOTES, GliderLogTables.F_LAUNCH }; Cursor cur_go = getContentResolver().query(uri, projection, null, null, null); if (cur_go != null) { //Log.d(TAG,"cnt " + cursor.getCount()); try { if ((cur_go.getCount()) > 0) { cur_go.moveToFirst(); do { myOutWriter.append(cur_go .getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_DATE)) + ";" + cur_go.getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_STARTED)) + ";" + cur_go.getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_LANDED)) + ";" + cur_go.getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_DURATION)) + ";" + cur_go.getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_TYPE)) + ";" + cur_go.getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_REGISTRATION)) + ";" + cur_go.getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_PILOT)) + ";" + cur_go.getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_PILOT_ID)) + ";" + cur_go.getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_COPILOT)) + ";" + cur_go.getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_COPILOT_ID)) + ";" + cur_go.getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_INSTRUCTION)) + ";" + cur_go.getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_NOTES)) + ";" + cur_go.getString(cur_go.getColumnIndexOrThrow(GliderLogTables.F_LAUNCH))); myOutWriter.append("\n"); // Log.d(TAG,"gld " + cursor // .getColumnIndexOrThrow(GliderLogTables.F_REGISTRATION)); } while (cur_go.moveToNext()); } } finally { if (!cur_go.isClosed()) { cur_go.close(); } } } myOutWriter.close(); fOut.close(); } catch (IOException ioe) { Log.e(TAG, "Could not open/write the csv file, error: " + ioe.getMessage()); } catch (SQLiteException e) { Log.e(TAG, "SQLiteException:" + e.getMessage()); } catch (Exception e) { Log.e(TAG, "Could not open/read the DB, error: " + e.getMessage()); } }
From source file:com.ezac.gliderlogs.FlightOverviewActivity.java
public String getDetailInfo(Uri uri, String param, int mde) { Cursor cur_di = null; String tmp = ""; switch (mde) { case 0:/*from w ww .ja v a 2s .c o m*/ String[] projection_1 = { GliderLogTables.G_REGISTRATION, GliderLogTables.G_CALLSIGN, GliderLogTables.G_TYPE, GliderLogTables.G_BUILD, GliderLogTables.G_SEATS, GliderLogTables.G_OWNER, GliderLogTables.G_PRIVATE }; selection = GliderLogTables.G_REGISTRATION + " like '" + param + "'"; cur_di = getContentResolver().query(uri, projection_1, selection, null, null); if (cur_di != null) { try { cur_di.moveToFirst(); tmp = cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_REGISTRATION)); tmp = tmp + ";" + (cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_CALLSIGN)) .equals("null") ? "-" : cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_CALLSIGN))); tmp = tmp + ";" + (cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_TYPE)).equals("null") ? "-" : cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_TYPE))); tmp = tmp + ";" + (cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_BUILD)) .equals("null") ? "-" : cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_BUILD))); tmp = tmp + ";\nTweezitter: " + (cur_di .getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_SEATS)).equals("null") ? "?" : (cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_SEATS))) .equals("1") ? "Nee" : "Ja"); tmp = tmp + ";\nEigenaar: " + (cur_di .getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_OWNER)).equals("null") ? "" : cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_OWNER))); tmp = tmp + ";Prive: " + (cur_di .getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_PRIVATE)).equals("null") ? "?" : (cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.G_PRIVATE))) .equals("0") ? "Nee" : "Ja"); } finally { if (!cur_di.isClosed()) { cur_di.close(); } } } break; case 1: String[] projection_2 = { GliderLogTables.M_1_NAME, GliderLogTables.M_2_NAME, GliderLogTables.M_3_NAME, GliderLogTables.M_PHONE, GliderLogTables.M_MOBILE, GliderLogTables.M_INSTRUCTION, GliderLogTables.M_ID }; selection = GliderLogTables.M_ID + " like '" + param + "'"; cur_di = getContentResolver().query(uri, projection_2, selection, null, null); if (cur_di != null) { try { cur_di.moveToFirst(); tmp = cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.M_1_NAME)) + " " + cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.M_2_NAME)) + " " + cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.M_3_NAME)); tmp = tmp.replaceAll("\\s+", " "); tmp = tmp + ";\n" + (cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.M_PHONE)) .equals("null") ? "-" : cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.M_PHONE))); tmp = tmp + ";" + (cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.M_MOBILE)) .equals("null") ? "-" : cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.M_MOBILE))); tmp = tmp + ";\nInstructeur: " + (cur_di.getString(cur_di.getColumnIndexOrThrow(GliderLogTables.M_INSTRUCTION)) .equals("0") ? "Nee" : "Ja"); } finally { if (!cur_di.isClosed()) { cur_di.close(); } } } break; } return tmp; }
From source file:de.vanita5.twittnuker.util.Utils.java
public static ArrayList<Long> getStatusIdsInDatabase(final Context context, final Uri uri, final long account_id) { final ArrayList<Long> list = new ArrayList<Long>(); if (context == null) return list; final ContentResolver resolver = context.getContentResolver(); final String where = Statuses.ACCOUNT_ID + " = " + account_id; final String[] projection = new String[] { Statuses.STATUS_ID }; final Cursor cur = ContentResolverUtils.query(resolver, uri, projection, where, null, null); if (cur != null) { final int idx = cur.getColumnIndexOrThrow(Statuses.STATUS_ID); cur.moveToFirst();/*from w w w . j a v a2 s.com*/ while (!cur.isAfterLast()) { list.add(cur.getLong(idx)); cur.moveToNext(); } cur.close(); } return list; }
From source file:com.devalladolid.musictoday.MusicService.java
private void addXTrackSelector(Notification n) { if (NotificationHelper.isSupported(n)) { StringBuilder selection = new StringBuilder(); StringBuilder order = new StringBuilder().append("CASE _id \n"); for (int i = 0; i < mPlaylist.size(); i++) { selection.append("_id=").append(mPlaylist.get(i).mId).append(" OR "); order.append("WHEN ").append(mPlaylist.get(i).mId).append(" THEN ").append(i).append("\n"); }//from w w w.j a v a 2 s .c om order.append("END"); Cursor c = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, NOTIFICATION_PROJECTION, selection.substring(0, selection.length() - 3), null, order.toString()); if (c != null && c.getCount() != 0) { c.moveToFirst(); ArrayList<Bundle> list = new ArrayList<>(); do { TrackItem t = new TrackItem() .setArt(ImageLoader.getInstance() .loadImageSync(TimberUtils .getAlbumArtUri( c.getLong(c.getColumnIndexOrThrow(AudioColumns.ALBUM_ID))) .toString())) .setTitle(c.getString(c.getColumnIndexOrThrow(AudioColumns.TITLE))) .setArtist(c.getString(c.getColumnIndexOrThrow(AudioColumns.ARTIST))) .setDuration(TimberUtils.makeShortTimeString(this, c.getInt(c.getColumnIndexOrThrow(AudioColumns.DURATION)) / 1000)); list.add(t.get()); } while (c.moveToNext()); try { NotificationHelper.insertToNotification(n, list, this, getQueuePosition()); } catch (ModNotInstalledException e) { e.printStackTrace(); } c.close(); } } }