List of usage examples for android.database Cursor getColumnIndex
int getColumnIndex(String columnName);
From source file:li.barter.fragments.ChatsFragment.java
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final Cursor cursor = (Cursor) mChatsAdapter.getItem(position); mDeleteChatId = cursor.getString(cursor.getColumnIndex(DatabaseColumns.CHAT_ID)); mBlockUserId = cursor.getString(cursor.getColumnIndex(DatabaseColumns.USER_ID)); showChatOptions();/* w w w. jav a2 s .com*/ return true; }
From source file:alberthsu.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*from ww w .jav a 2s . c om*/ * @param lon the longitude of the city * @return the row ID of the added location. */ private long addLocation(String locationSetting, String cityName, double lat, double lon) { // First, check if the location with this city name exists in the db Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID); return cursor.getLong(locationIdIndex); } else { ContentValues locationValues = new ContentValues(); locationValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(LocationEntry.COLUMN_COORD_LONG, lon); Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues); return ContentUris.parseId(locationInsertUri); } }
From source file:com.autoparts.buyers.activity.UserInfoActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) {//?? switch (requestCode) { case CommonData.PHOTO_REQUEST_TAKEPHOTO: setPicToView(cameraUtils.getTempFile().getPath()); break; case CommonData.PHOTO_REQUEST_GALLERY: if (data != null) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst();/*from w w w . jav a 2 s . c om*/ int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); setPicToView(picturePath); } break; case CommonData.REQUEST_USER_TEL: String strTel = data.getStringExtra("content"); tel.setText(strTel); break; case CommonData.REQUEST_USER_ADDRESS: String content = data.getStringExtra("content"); address.setText(content); getData(Constants.USER_INFO); break; case CommonData.REQUEST_USER_NAME: String title = data.getStringExtra("content"); user_title.setText(title); getData(Constants.USER_INFO); break; } } }
From source file:com.example.danstormont.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city/*from w w w .j ava 2 s . c o m*/ * @param lon the longitude of the city * @return the row ID of the added location. */ private long addLocation(String locationSetting, String cityName, double lat, double lon) { Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon); // First, check if the location with this city name exists in the db Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID); return cursor.getLong(locationIdIndex); } else { ContentValues locationValues = new ContentValues(); locationValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(LocationEntry.COLUMN_COORD_LAT, lat); locationValues.put(LocationEntry.COLUMN_COORD_LONG, lon); Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues); return ContentUris.parseId(locationInsertUri); } }
From source file:com.navjagpal.fileshare.StreamingZipEntity.java
public void writeTo(OutputStream out) throws IOException { Cursor c = mContentResolver.query(FileSharingProvider.Files.CONTENT_URI, new String[] { FileSharingProvider.Files.Columns.DISPLAY_NAME, FileSharingProvider.Files.Columns._DATA }, FileSharingProvider.Files.Columns.FOLDER_ID + "=?", new String[] { mFolderId }, null); ZipOutputStream zipOut = new ZipOutputStream(out); byte[] buf = new byte[BUFFER_SIZE]; while (c.moveToNext()) { String filename = c.getString(c.getColumnIndex(FileSharingProvider.Files.Columns.DISPLAY_NAME)); String data = c.getString(c.getColumnIndex(FileSharingProvider.Files.Columns._DATA)); zipOut.putNextEntry(new ZipEntry(filename)); InputStream input = mContentResolver.openInputStream(Uri.parse(data)); int len;//from ww w.ja v a 2s . c om while ((len = input.read(buf)) > 0) { zipOut.write(buf, 0, len); } zipOut.closeEntry(); input.close(); } zipOut.finish(); mFinished = true; }
From source file:name.zurell.kirk.apps.android.rhetolog.RhetologApplication.java
/** Data management support routines */ public Uri insertContactIntoParticipants(Uri contact, Uri session) { String[] contactProjection = { ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.PHOTO_THUMBNAIL_URI }; Cursor contactQuery = getContentResolver().query(contact, contactProjection, null, null, null); if ((contactQuery == null) || (!contactQuery.moveToFirst())) { return null; }//w w w .j ava2s . c om int nameCol = contactQuery.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); int photoCol = contactQuery.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI); String participantName = null; String participantPhoto = null; if (contactQuery.getType(nameCol) == Cursor.FIELD_TYPE_STRING) participantName = contactQuery.getString(nameCol); else participantName = getResources().getString(R.string.defaultParticipantCaption); if (contactQuery.getType(photoCol) == Cursor.FIELD_TYPE_STRING) { participantPhoto = contactQuery.getString(photoCol); } else { participantPhoto = "android.resource://" + this.getPackageName() + "/" + Integer.toString(R.drawable.rhetolog_participant); } contactQuery.close(); ContentValues values = new ContentValues(); values.put(RhetologContract.ParticipantsColumns.NAME, participantName); values.put(RhetologContract.ParticipantsColumns.PHOTO, participantPhoto); values.put(RhetologContract.ParticipantsColumns.LOOKUP, contact.toString()); // Learn session id, use in participants/session/id // String sessionId = session.getLastPathSegment(); // long currentSessionId; // if (sessionId.contentEquals("currentsession")) { // Bundle currentSessionBundle = getContentResolver().call(RhetologContract.PROVIDER_URI, "getCurrentSession", null, null); // currentSessionId = currentSessionBundle.getLong(RhetologContentProvider.CURRENTSESSIONEXTRA); // } else { // currentSessionId = Long.valueOf(sessionId); // } // // // Ugly, not sure how to make less so. // values.put(RhetologContract.ParticipantsColumns.SESSION, currentSessionId); Uri newParticipant = getContentResolver().insert(session, values); return newParticipant; }
From source file:com.tcm.sunshine.app.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city//from www. ja v a 2s . co m * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { // Students: First, check if the location with this city name exists in the db // If it exists, return the current ID // Otherwise, insert it using the content resolver and the base URI ContentResolver contentResolver = mContext.getContentResolver(); Cursor cursor = contentResolver.query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID }, LocationEntry.COLUMN_CITY_NAME + " = ?", new String[] { cityName }, null); try { if (cursor.moveToFirst()) { return cursor.getInt(cursor.getColumnIndex(LocationEntry._ID)); } } finally { cursor.close(); } ContentValues contentValues = new ContentValues(); contentValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); contentValues.put(LocationEntry.COLUMN_CITY_NAME, cityName); contentValues.put(LocationEntry.COLUMN_COORD_LAT, lat); contentValues.put(LocationEntry.COLUMN_COORD_LONG, lon); Uri insertUri = contentResolver.insert(LocationEntry.CONTENT_URI, contentValues); return ContentUris.parseId(insertUri); }
From source file:com.example.spatidar.sunshine.FetchWeatherTask.java
/** * Helper method to handle insertion of a new location in the weather database. * * @param locationSetting The location string used to request updates from the server. * @param cityName A human-readable city name, e.g "Mountain View" * @param lat the latitude of the city//from w w w . jav a 2s . c om * @param lon the longitude of the city * @return the row ID of the added location. */ long addLocation(String locationSetting, String cityName, double lat, double lon) { long locationId = -1; // Query if locationSetting entry exists in the table Cursor cur = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, null, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + "= ?", new String[] { locationSetting }, null); if (cur.moveToFirst()) { int idx = cur.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = cur.getLong(idx); } else { // Insert ContentValues values = new ContentValues(); values.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); values.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri uri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, values); locationId = ContentUris.parseId(uri); } cur.close(); return locationId; }
From source file:edu.cloud.iot.reception.ocr.FaceRecognitionActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 0) { Bitmap img = (Bitmap) data.getExtras().get("data"); imageResult.setImageBitmap(img); }// www. j av a 2 s.co m if (requestCode == SET_COMPARE_IMAGE && resultCode == RESULT_OK && null != data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); Bitmap compImg = BitmapFactory.decodeFile(picturePath); ByteArrayOutputStream bos = new ByteArrayOutputStream(); compImg.compress(Bitmap.CompressFormat.JPEG, 100, bos); compareImageBytes = bos.toByteArray(); // ImageView imageView = (ImageView) findViewById(R.id.imgView); // imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); } }
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
public static int getUnNotifyUnreadCount() { String sql = "SELECT sum(" + IThreadColumn.UNREAD_COUNT + ") FROM im_thread \n" + " inner JOIN groups2 ON im_thread.sessionId = groups2.groupid and isnotice == 2"; int count = 0; Cursor cursor = null; try {/*from w w w . j a v a 2 s. c o m*/ cursor = getInstance().sqliteDB().rawQuery(sql, null); if (cursor != null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { count = cursor.getInt(cursor.getColumnIndex("sum(" + IThreadColumn.UNREAD_COUNT + ")")); } } } catch (Exception e) { LogUtil.e(TAG + " " + e.toString()); } finally { if (cursor != null) { cursor.close(); } } return count; }