Android Imitation Sina Weibo micro-blog Interface Design (5) _android

Source: Internet
Author: User
Tags delete key gettext oauth prepare

This tutorial for you to share the Android release microblogging, add facial features such as the specific code, for your reference, the specific content as follows

Post a new microblogging interface: Http://open.weibo.com/wiki/2/statuses/update
Upload a picture and post a new microblogging interface: Http://open.weibo.com/wiki/2/statuses/upload

1. According to have no picture to choose the corresponding interface.
2. Judge the number of words according to the change of the input frame.
3. Create a girlview display sent pictures, the maximum of 9, here because of the request parameters of the reason, upload a picture, select more than one picture, upload the last picture. (Official demo and network multiple demo can upload only one picture.) If there are reader to solve the upload, please be sure to contact me! )
4. Display expression: Using regular expressions to traverse the text content, generation and expression to match the content, with spannablestring will be the expression of the image in the TextView.
5. Expression Panel implementation: Create a display expression of the GridView, the expression group into which, listening to the GridView click events, the expression input into the edittext. The realization of the concrete expression function please refer to: http://www.jb51.net/article/97862.htm
5. The final text, expression, and number of pictures, depending on the state of each parameter when the button is triggered.
6. Delete the selected picture, get its location using Imageitem.remove (position) and remove it from the ArrayList.

public class Writeactivity extends activity implements Adapterview.onitemclicklistener {private Button onput, Addexpres
 Sion
 Private EditText write;
 Private GridView GridView;
 Private TextView total_text_num = null;
 Private LinearLayout Ll_emotion_dashboard;
 Private Viewpager Vp_emotion_dashboard;
 Send the path of the picture private String image_path;
 Private Bitmap bmp;
 Private arraylist<string> imagepaths;
 Private arraylist 

The

Publish Weibo method is located in Tools.java. Since the uploaded data is multipart/form-data encoded, a third party Httptmime.jar package is introduced here to handle the request parameters.

 /** * publishes a micro-blog without pictures * * @param context * @param text */public void Postwhittext (final context, final String
 Text) {if (OAuth = null) {OAuth = Oauth.getoauth (context); New Thread () {@Override public void run () {try {HttpPost post = new HttpPost ("Https://api.weibo.com/2/statu
   Ses/update "+". JSON ");
   list<namevaluepair> params = new arraylist<namevaluepair> ();
   Params.add (New Basicnamevaluepair ("Access_token", Oauth.getaccesstoken ());
   Params.add (New Basicnamevaluepair ("status", text); Post.setentity (New urlencodedformentity (params, HTTP).
   Utf_8));
   HttpResponse response = Httpclient.execute (POST);
   if (Response.getstatusline (). Getstatuscode () = Looper.prepare ();
   Toast.maketext (Context, "Publish success", Toast.length_short). Show ();
   Looper.loop ();
   else {looper.prepare ();
   Toast.maketext (Context, "Publish failure", Toast.length_short). Show ();
   Looper.loop (); } catch (Unsupportedencodingexception e) {E.prinTstacktrace ();
  catch (Clientprotocolexception e) {e.printstacktrace ();
  catch (IOException e) {e.printstacktrace ();
 }}.start (); /** * publishes a micro-blog with pictures * * @param context * @param/public void Postwhittextandimages (final context, final S Tring text, final list<string> filespath) {new Thread () {@Override public void run () {try {//httpclie
   NT Object HttpClient httpclient = new Defaulthttpclient ();
   The request mode of post is HttpPost HttpPost = new HttpPost ("Https://upload.api.weibo" + ". Com/2/statuses/upload.json");
   Multipartentity object, requires Httpmime-4.1.1.jar file.
   Multipartentity multipartentity = new multipartentity ();
   Stringbody object, parameter stringbody param = new Stringbody (Oauth.getaccesstoken ());
   Multipartentity.addpart ("Access_token", param);
   Stringbody param1 = new Stringbody (Urlencoder.encode (text));
   Multipartentity.addpart ("status", param1); Filespath is a List<string> object that contains the address for the file that needs to be uploaded (String path:filEspath) {log.i ("------------", Path);
   Filebody object that needs to be uploaded files contentbody file = new Filebody (new file (path));
   Multipartentity.addpart ("Pic", file);
   ///Assign the Multipartentity object to HttpPost httppost.setentity (multipartentity);

   HttpResponse response = null;

   Executes the request and returns the result httpresponse response = Httpclient.execute (HttpPost);
   if (Response.getstatusline (). Getstatuscode () = Looper.prepare ();
   Toast.maketext (Context, "Publish success", Toast.length_short). Show ();
   Looper.loop ();
   else {looper.prepare ();
   Toast.maketext (Context, "Publish failure", Toast.length_short). Show ();
   Looper.loop ();
  } catch (Clientprotocolexception e) {e.printstacktrace ();
  catch (IOException e) {e.printstacktrace ();
 }}.start ();
 }

Effect Chart:

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.