If you insert the topic and the @ symbol:
Final class topichelper {Private Static final string topic = "# Insert the topic name #"; private writeblog activity; Public void inserttext () {final edittext = activity. etmblog; Final int selectionstart = edittext. getselectionstart (); Final int secletionend = edittext. getselectionend (); final string text = edittext. gettext (). tostring (); If (selectionstart =-1 | secletionend =-1 | selectionstart> secletionend) {activity. etmblog. append (topichelper. topic); Final int totallength = activity. etmblog. gettext (). tostring (). length (); activity. etmblog. setselection (totallength-topichelper. topic. length () + 1, totallength-1);} else {final stringbuilder sb = new stringbuilder (); sb. append (text. substring (0, selectionstart); sb. append (topic); sb. append (text. substring (secletionend); edittext. settext (sb. tostring (); selection. setselection (edittext. gettext (), selectionstart + 1, selectionstart + topic. length ()-1) ;}} topichelper (writeblog activity) {super (); this. activity = activity ;}}
Final class atedithelper {Private Static final string at = "@ enter username"; private writeblog activity; Public void inserttext () {final edittext = activity. etmblog; Final int selectionstart = edittext. getselectionstart (); // obtain the final int secletionend = edittext where the cursor is located. getselectionend (); final string text = edittext. gettext (). tostring (); If (selectionstart =-1 | secletionend =-1 | selectionstart> secletionend) {activity. etmblog. append (atedithelper. at); Final int totallength = activity. etmblog. gettext (). tostring (). length (); activity. etmblog. setselection (totallength-atedithelper. at. length () + 1, totallength-1);} else {final stringbuilder sb = new stringbuilder (); sb. append (text. substring (0, selectionstart); sb. append (atedithelper. at); sb. append (text. substring (secletionend); edittext. settext (sb. tostring (); selection. setselection (edittext. gettext (), selectionstart + 1, selectionstart + atedithelper. at. length ()-1) ;}} atedithelper (writeblog activity) {super (); this. activity = activity ;}}
When you exit Weibo, you need to save the image and content:
// Default_draft_text_path = getfilesdir (). getabsolutepath () + "/Draft/text. dat "; private Boolean savedraft (string text) {try {file F = new file (default_draft_text_path); fileutils. makesurefileexist (default_draft_text_path); fileutils. saveobject (text, new fileoutputstream (default_draft_text_path);} catch (final exception e) {} return false;} // This method ensures that the path has public static void makesurefileexist (string path) {string separator = file. separator; int Index = path. lastindexof (separator); Path = path. substring (0, index); file F = new file (PATH); F. mkdirs (); file F1 = new file (PATH); try {f1.createnewfile ();} catch (ioexception e) {e. printstacktrace () ;}} public static void saveobject (string text, fileoutputstream FOS) {try {objectoutputstream OOS = new objectoutputstream (FOS); OOS. writeobject (text); OOS. flush (); OOS. close ();} catch (ioexception ex) {ex. printstacktrace ();}}
Save image:
// Both path1 and path2 should be the pathpublic static void copy (string inputfilepath, string path2) {string separator = file. separator; int Index = path2.lastindexof (separator); string Path = path2.substring (0, index); file temp = new file (PATH); If (! Temp. exists () {temp. mkdirs ();} file tempfile = new file (path2); try {tempfile. createnewfile ();} catch (ioexception E1) {e1.printstacktrace ();} fileinputstream inputstream = NULL; fileoutputstream outputstream = NULL; try {inputstream = new fileinputstream (inputfilepath ); outputstream = new fileoutputstream (path2); byte buffer [] = new byte [4*1024]; int Len =-1; while (LEN = inputstream. read (buffer ))! =-1) {outputstream. write (buffer, 0, Len);} outputstream. flush ();} catch (exception e) {// todo auto-generated catch blocke. printstacktrace ();}}
//defaultDraftPath = activity.getFilesDir().getAbsolutePath()+ "/draft/bitmap_temp.jpg";// defaultTempPath = activity.getFilesDir().getAbsolutePath()+ "/pic/" + System.currentTimeMillis() + ".jpg";void saveDraft() {FileUtils.copy(defaultTempPath, defaultDraftPath);}
When you enter this page again, load the page content:
private void loadDraft() {String str = FileUtils.loadObject(DEFAULT_DRAFT_TEXT_PATH);etMblog.setText(str);etMblog.setSelection(str.length());if (mImageLoadingHelper.doesDraftExist()) {mImageLoadingHelper.loadDraft();}}public static String loadObject(String str) { Object obj = null; File f = new File(str);try {FileInputStream fis = new FileInputStream(f);ObjectInputStream ois = new ObjectInputStream(fis);obj = ois.readObject();} catch (Exception ex) {ex.printStackTrace();}return (String)obj;}void loadDraft() {FileUtils.copy(defaultDraftPath, defaultTempPath);activity.displayInsertBitmap();}
The code can be downloaded at http://download.csdn.net/detail/baidu_nod/7708705.