How to Write a Weibo page (including inserting images, inserting emotices, inserting topics, and inserting Location) (1)
First:
First look at the page layout:
// These five buttons are at the bottom.Android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_weight = "1">
// This includes the thumbnail and locationAndroid: id = "@ + id/marks" android: layout_width = "fill_parent" android: layout_height = "50dp" android: padding = "3dp" android: layout_above = "@ id/btns_bottom">
// This is the bodyAndroid: id = "@ + id/et_mblog" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: layout_above = "@ id/marks" android: background = "@ null" android: capitalize = "sentences" android: imeOptions = "actionDone" android: gravity = "top | left" android: layout_margin = "3px"/>
// This is at the outermost layer, and the bottom of the interface is an emoticons interface. It is implemented using the gridview.
First, load image from the mobile album:
private void startToMediaActivity() {startActivityForResult(new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI),WriteBlog.REQUEST_CODE_GALLERY);}private void startToCameraActivity() {if (FileUtils.isSdCardAvailable()) {final Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);final Uri picUri = Uri.fromFile(sdcardTempFile);i.putExtra(MediaStore.EXTRA_OUTPUT, picUri);startActivityForResult(i, WriteBlog.REQUEST_CODE_CAMERA);}else {Toast.makeText(this, R.string.pls_insert_sdcard, Toast.LENGTH_SHORT).show();}}
Processing class of an Image:
final class ImageLoadingHelper {private File picfile;private WriteBlog activity;private String defaultTempPath;private String defaultDraftPath;Bitmap createThumbnail() {Options thumbnailOpts = new BitmapFactory.Options();if (!hasBitmap()) { throw new IllegalStateException("There is no pic!"); }return BitmapFactory.decodeFile(getTempPath(),thumbnailOpts);}synchronized boolean hasBitmap() {String picfileName = picfile.getName();if(picfileName.matches(".avi")|| picfileName.matches(".rm")||picfileName.matches(".mp4")||picfileName.matches(".rmvb")||picfileName.matches(".wmv")||picfileName.matches(".flv")){return false;}else{return FileUtils.doesExisted(picfile);}}synchronized void importBitmapFile(Uri uri) {if (uri.getScheme().equals("content")) {InputStream inputStream = null;try {inputStream = activity.getContentResolver().openInputStream(uri);} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}FileUtils.file_put_contents(inputStream,picfile);}}boolean doesDraftExist() {return FileUtils.doesExisted(defaultDraftPath);}String getTempPath() {return picfile == null ? "" : picfile.getAbsolutePath();}void loadDraft() {FileUtils.copy(defaultDraftPath, defaultTempPath);activity.displayInsertBitmap();}void saveDraft() {FileUtils.copy(defaultTempPath, defaultDraftPath);}ImageLoadingHelper(WriteBlog activity) {this.activity = activity;if (FileUtils.isSdCardAvailable()) {defaultTempPath = FileUtils.getSDPath() + "/temp/"+ System.currentTimeMillis() + ".jpg";}else {defaultTempPath = activity.getFilesDir().getAbsolutePath()+ "/pic/" + System.currentTimeMillis() + ".jpg";}defaultDraftPath = activity.getFilesDir().getAbsolutePath()+ "/draft/bitmap_temp.jpg";if (FileUtils.doesExisted(defaultTempPath)) {defaultTempPath.replace(".jpg", "(1).jpg");}picfile = new File(defaultTempPath);}}
After selecting the image, we will call onactivityResult:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {if ((requestCode == WriteBlog.REQUEST_CODE_CAMERA)|| (WriteBlog.REQUEST_CODE_GALLERY == requestCode)) {if (resultCode != Activity.RESULT_OK) { return; }Uri uri = null;if ((requestCode == WriteBlog.REQUEST_CODE_CAMERA)&& FileUtils.doesExisted(sdcardTempFile)) {uri = Uri.fromFile(sdcardTempFile);}else if (WriteBlog.REQUEST_CODE_GALLERY == requestCode) {uri = data.getData();}if (uri != null) {displayImageUri(uri);}}}private void displayImageUri(Uri uri) {mImageLoadingHelper.importBitmapFile(uri);displayInsertBitmap();}void displayInsertBitmap() {insertPicView.setImageBitmap(mImageLoadingHelper.createThumbnail());insertPicView.setVisibility(View.VISIBLE);}