List of usage examples for android.database Cursor getColumnIndexOrThrow
int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException;
From source file:cn.gen.superwechat.activity.ChatActivity.java
/** * ??//w w w.j a va 2 s.c o m * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { String st7 = getResources().getString(cn.gen.superwechat.R.string.File_does_not_exist); Toast.makeText(getApplicationContext(), st7, Toast.LENGTH_SHORT).show(); return; } if (file.length() > 10 * 1024 * 1024) { String st6 = getResources().getString(cn.gen.superwechat.R.string.The_file_is_not_greater_than_10_m); Toast.makeText(getApplicationContext(), st6, Toast.LENGTH_SHORT).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) { message.setChatType(ChatType.GroupChat); } else if (chatType == CHATTYPE_CHATROOM) { message.setChatType(ChatType.ChatRoom); } message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); if (isRobot) { message.setAttribute("em_robot_message", true); } conversation.addMessage(message); listView.setAdapter(adapter); adapter.refreshSelectLast(); setResult(RESULT_OK); }
From source file:cn.hbm.superwechat.activity.ChatActivity.java
/** * ??//from w w w. j av a 2 s . c om * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { String st7 = getResources().getString(R.string.File_does_not_exist); Toast.makeText(getApplicationContext(), st7, Toast.LENGTH_SHORT).show(); return; } if (file.length() > 10 * 1024 * 1024) { String st6 = getResources().getString(R.string.The_file_is_not_greater_than_10_m); Toast.makeText(getApplicationContext(), st6, Toast.LENGTH_SHORT).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) { message.setChatType(ChatType.GroupChat); } else if (chatType == CHATTYPE_CHATROOM) { message.setChatType(ChatType.ChatRoom); } message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); if (isRobot) { message.setAttribute("em_robot_message", true); } conversation.addMessage(message); listView.setAdapter(adapter); adapter.refreshSelectLast(); setResult(RESULT_OK); }
From source file:cn.ucai.chatuidemo.activity.ChatActivity.java
/** * ??/*from w ww. ja v a 2 s . com*/ * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { String st7 = getResources().getString(R.string.File_does_not_exist); Toast.makeText(getApplicationContext(), st7, Toast.LENGTH_LONG).show(); return; } if (file.length() > 10 * 1024 * 1024) { String st6 = getResources().getString(R.string.The_file_is_not_greater_than_10_m); Toast.makeText(getApplicationContext(), st6, Toast.LENGTH_LONG).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) { message.setChatType(ChatType.GroupChat); } else if (chatType == CHATTYPE_CHATROOM) { message.setChatType(ChatType.ChatRoom); } message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); if (isRobot) { message.setAttribute("em_robot_message", true); } conversation.addMessage(message); listView.setAdapter(adapter); adapter.refreshSelectLast(); setResult(RESULT_OK); }
From source file:com.eason.marker.emchat.chatuidemo.activity.ChatActivity.java
/** * ??// ww w. j a va 2 s.co m * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { String st7 = getResources().getString(R.string.File_does_not_exist); GreenToast.makeText(getApplicationContext(), st7, 0).show(); return; } if (file.length() > 10 * 1024 * 1024) { String st6 = getResources().getString(R.string.The_file_is_not_greater_than_10_m); GreenToast.makeText(getApplicationContext(), st6, 0).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) { message.setChatType(ChatType.GroupChat); } else if (chatType == CHATTYPE_CHATROOM) { message.setChatType(ChatType.ChatRoom); } message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); if (isRobot) { message.setAttribute("em_robot_message", true); } conversation.addMessage(message); listView.setAdapter(adapter); adapter.refreshSelectLast(); setResult(RESULT_OK); }
From source file:com.android.calendar.event.EditEventView.java
private int findSelectedCalendarPosition(Cursor calendarsCursor, long calendarId) { if (calendarsCursor.getCount() <= 0) { return -1; }/*w ww .ja v a2 s . com*/ int calendarIdColumn = calendarsCursor.getColumnIndexOrThrow(Calendars._ID); int position = 0; calendarsCursor.moveToPosition(-1); while (calendarsCursor.moveToNext()) { if (calendarsCursor.getLong(calendarIdColumn) == calendarId) { return position; } position++; } return 0; }
From source file:com.fvd.nimbus.PaintActivity.java
public String getGalleryPath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();// ww w. ja v a2s .c om return cursor.getString(column_index); } return null; }
From source file:me.piebridge.bible.Bible.java
private void setMetadata(SQLiteDatabase metadata, String dataversion, boolean change) { Cursor cursor = metadata.query(Provider.TABLE_BOOKS, Provider.COLUMNS_BOOKS, null, null, null, null, null); if (change) { osiss.clear();//from w ww .j av a 2s . c om books.clear(); chapters.clear(); humans.clear(); } try { while (cursor.moveToNext()) { String osis = cursor.getString(cursor.getColumnIndexOrThrow(Provider.COLUMN_OSIS)); String book = cursor.getString(cursor.getColumnIndexOrThrow(Provider.COLUMN_HUMAN)); String chapter = cursor.getString(cursor.getColumnIndexOrThrow(Provider.COLUMN_CHAPTERS)); if (book.endsWith(" 1")) { book = book.substring(0, book.length() - 2); } if (!allhuman.containsKey(book)) { allhuman.put(book, osis); } Cursor cursor_chapter = null; // select group_concat(replace(reference_osis, "Gen.", "")) as osis from chapters where reference_osis like 'Gen.%'; try { cursor_chapter = metadata.query(Provider.TABLE_CHAPTERS, new String[] { "group_concat(replace(reference_osis, \"" + osis + ".\", \"\")) as osis" }, "reference_osis like ?", new String[] { osis + ".%" }, null, null, null); if (cursor_chapter.moveToNext()) { // we have only one column chapter = cursor_chapter.getString(0); } } catch (Exception e) { } finally { if (cursor_chapter != null) { cursor_chapter.close(); } } if (change) { osiss.add(osis); books.add(book); chapters.add(chapter); humans.add(book); } } } finally { if (cursor != null) { cursor.close(); } } css = getVersionMetadata("css", metadata, ""); }
From source file:com.gsma.rcs.ri.messaging.adapter.TalkCursorAdapter.java
private void bindRcsFileTransferInView(View view, Cursor cursor) { final RcsFileTransferInViewHolder holder = (RcsFileTransferInViewHolder) view.getTag(); holder.getTimestampText()/*from ww w. j av a 2 s. c o m*/ .setText(DateUtils.getRelativeTimeSpanString(cursor.getLong(holder.getColumnTimestampIdx()), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE)); String mimeType = cursor.getString(holder.getColumnMimetypeIdx()); StringBuilder sb = new StringBuilder(cursor.getString(holder.getColumnFilenameIdx())); long filesize = cursor.getLong(holder.getColumnFilesizeIdx()); long transferred = cursor.getLong(holder.getColumnTransferredIdx()); final ImageView imageView = holder.getFileImageView(); imageView.setOnClickListener(null); imageView.setLayoutParams(mImageParamsDefault); imageView.setImageResource(R.drawable.ri_filetransfer_off); if (filesize != transferred) { holder.getProgressText() .setText(sb.append(" : ").append(Utils.getProgressLabel(transferred, filesize)).toString()); } else { imageView.setImageResource(R.drawable.ri_filetransfer_on); final Uri file = Uri.parse(cursor.getString(holder.getColumnContentIdx())); final RcsService.ReadStatus readStatus = RcsService.ReadStatus .valueOf(cursor.getInt(holder.getColumnReadStatusIdx())); final String id = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.ID)); if (Utils.isImageType(mimeType)) { final String filePath = FileUtils.getPath(mContext, file); if (filePath != null) { LruCache<String, BitmapCacheInfo> memoryCache = bitmapCache.getMemoryCache(); BitmapCacheInfo bitmapCacheInfo = memoryCache.get(filePath); if (bitmapCacheInfo == null) { ImageBitmapLoader loader = new ImageBitmapLoader(mContext, memoryCache, MAX_IMAGE_WIDTH, MAX_IMAGE_HEIGHT, new BitmapLoader.SetViewCallback() { @Override public void loadView(BitmapCacheInfo cacheInfo) { imageView.setImageBitmap(cacheInfo.getBitmap()); imageView.setLayoutParams(mImageParams); } }); loader.execute(filePath); } else { Bitmap imageBitmap = bitmapCacheInfo.getBitmap(); imageView.setImageBitmap(imageBitmap); imageView.setLayoutParams(mImageParams); } imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Utils.showPicture(mActivity, file); markFileTransferAsRead(id, readStatus); } }); } } else if (Utils.isAudioType(mimeType)) { imageView.setImageResource(R.drawable.headphone); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Utils.playAudio(mActivity, file); markFileTransferAsRead(id, readStatus); } }); } holder.getProgressText().setText(sb.append(" (") .append(FileUtils.humanReadableByteCount(filesize, true)).append(")").toString()); } holder.getStatusText().setText(getRcsFileTransferStatus(cursor, holder)); }
From source file:com.chaqianma.jd.fragment.CompanyInfoFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { switch (requestCode) { case REQUEST_SDK_IMGS: if (data != null && data.getData() != null) { Uri imgUri = data.getData(); ContentResolver resolver = getActivity().getContentResolver(); String[] pojo = { MediaStore.Images.Media.DATA }; Cursor cursor = null; try { cursor = resolver.query(imgUri, pojo, null, null, null); if (cursor != null && cursor.getCount() > 0) { int colunm_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); new Thread(new BaseFragment.ImgRunable(cursor.getString(colunm_index), Constants.BUSINESS_INFO, fileType, selCompanyIdxTag, new UpdateUIHandler())) .start(); } else { JDToast.showLongText(getActivity(), ""); }/*from www. ja v a 2s. co m*/ } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } } break; case REQUEST_TAKE_PHOTO: new Thread(new BaseFragment.ImgRunable(Constants.TEMPPATH, Constants.BUSINESS_INFO, fileType, selCompanyIdxTag, new UpdateUIHandler())).start(); break; default: break; } } }
From source file:com.ieeton.agency.activity.ChatActivity.java
/** * ??//ww w.j a va 2 s .co m * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { Toast.makeText(getApplicationContext(), "?", 0).show(); return; } if (file.length() > 10 * 1024 * 1024) { Toast.makeText(getApplicationContext(), "?10M", 0).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) message.setChatType(ChatType.GroupChat); message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); conversation.addMessage(message); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); addPitient(); setResult(RESULT_OK); }