Android Imitation Sina microblogging personal information interface and other effects _android

Source: Internet
Author: User
Tags int size time interval file permissions

This tutorial for you to share the Android micro-blog Personal Information Interface design code for your reference, the specific content as follows

Get user information interface based on user id:
Http://open.weibo.com/wiki/2/users/show

If you have implemented the previous function that person's information interface is a piece of cake, not described here.

Add

1. Time Processing class:

Deal with the time between the current moment when the tweet is emitted. It should be quite easy to understand.

/** * Time Processing class */public class Dateutils {public string getinterval (String createtime) {//Incoming time format must be similar to 2012-8-21 17:53

    : 20 such format String interval = null;
    SimpleDateFormat sd = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
    Parseposition pos = new parseposition (0);

    Date D1 = Sd.parse (Createtime, POS); With the current interval of 1970, the new Date () GetTime () subtracts the previous time from the 1970 time interval D1.gettime () The time interval between the previous time and the present time is long.
    GetTime ()-d1.gettime ();//The resulting interval is milliseconds int day = 24 * 3600000;
    INT week = day * 7; if (time/1000 < && time/1000 >= 0) {//If the time interval is less than 10 seconds, the unit of the time interval that appears "just" time/10 is seconds interval = "

    Just "; else if (time/3600000 < && time/3600000 > 0) {//If the time interval is less than 24 hours, show how many hours ago int h = (int) (TI

    me/3600000)//The time interval of the unit is the hour interval = h + "hours ago"; "Else If" (time/60000 < && time/60000 > 0) {//If the interval is less than 60 minutes, show how many minutes ago int m = (int) (Time % 3600000)/60000);/the time to arriveThe unit of the interval is the minute interval = m + "minutes ago"; else if (time/1000 < && time/1000 > 0) {//If the interval is less than 60 seconds before the number of seconds before int se = (int) (Time% 6
      0000)/1000);

    Interval = se + "seconds ago";
      else if (Time/day < 7 && time/day > 0) {int d = (int) (time/day);
    Interval = d + "days ago";
      else if (Time/week < 5 && time/week > 0) {int w = (int) (Time/week);
    Interval = w + "Weeks ago";

      else {//greater than one months, displays the normal time, but does not display the second SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd hh:mm");
      Parseposition Pos2 = new Parseposition (0);

      Date D2 = (date) sdf.parse (Createtime, Pos2);
    Interval = Sdf.format (D2);
  return interval;

 }
}

2. Expression processing class in string:

The regular expression matches the corresponding expression field and, if matched, uses spannablestring to replace the text of the field with an expression picture.

public class StringUtils {public static spannablestring Getemotioncontent (final context, final TextView TV, S
    Tring source) {spannablestring spannablestring = new spannablestring (source);

    Resources res = context.getresources ();
    String regexemotion = "\\[([\u4e00-\u9fa5\\w]) +\\]";
    Pattern patternemotion = Pattern.compile (regexemotion);
    Matcher matcheremotion = Patternemotion.matcher (spannablestring);
    Bitmap Scalebitmap;
    int size = (int) tv.gettextsize ();
      while (Matcheremotion.find ()) {//Get match to the specific character String key = Matcheremotion.group ();
      Match the start position of the string int start = Matcheremotion.start ();
      Use the expression name to get to the corresponding picture Integer imgres = Emotionutils.getimgbyname (key); if (imgres!= null && size > 0) {//Compressed expression picture Bitmap Bitmap = Bitmapfactory.decoderesource (res,
        Imgres);

          if (bitmap!= null) {Scalebitmap = Bitmap.createscaledbitmap (bitmap, size, size, true); Imagespan span = new Imagespan (context, scalebitmap);
        Spannablestring.setspan (span, start, start + Key.length (), spannable.span_exclusive_exclusive);
  }} return spannablestring;

 }
}

3.manifest file:

Because the application involves many permissions, you need to declare permissions. Here because the last multiple pictures will overflow memory, you need to request additional memory

<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android= "http://schemas.android.com/apk/res/" Android "package=" Study.sinatest > <!--access to the network--> <uses-permission android:name= "android.permission. Access_network_state "/> <uses-permission android:name= Android.permission.INTERNET"/> <!-- Create and delete file permissions in SDcard--> <uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> < !--Write Data permissions to SDcard--> <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> < Application <!--here because the last multiple pictures will overflow the memory, you need to request additional memory--> android:largeheap= "true" android:allowbackup= "true" and Roid:hardwareaccelerated= "false" android:icon= "@mipmap/weibologo" android:label= "@string/app_name" Android:sup Portsrtl= "true" android:theme= "@style/apptheme" > <activity android:name=. Splashactivity "android:configchanges=" Keyboardhidden "android:launchmode=" SingLetask "android:screenorientation=" Portrait "> <intent-filter> <action android:name=" Androi D.intent.action.main "/> <category android:name=" Android.intent.category.LAUNCHER "/> </intent-fi lter> </activity> <activity android:name= ". Loginactivity "/> <activity android:name=". Mainactivity "/> <activity android:name=". Homeactivity "/> <activity android:name=". Writeactivity "/> <activity android:name=". Commentactivity "/> <activity android:name=". Meactivity "/> <activity android:name=". Moreactivity "/> <!--licensing page--> <activity android:name=". Oauthactivity "android:launchmode=" Singletask "> <intent-filter> <action android:name=" Andr Oid.intent.action.VIEW "/> <category android:name=" Android.intent.category.DEFAULT "/> <categor

  Y android:name= "Android.intent.category.BROWSABLE"/>      <data android:scheme= "Philn"/> </intent-filter> </activity> <!--Google Service privileges--> <meta-data android:name= "com.google.android.gms.version" android:value= "@integer/google_play_services_ver
    Sion "/> </application> <supports-screens android:anydensity=" true "android:largescreens=" true "
 Android:normalscreens= "true"/> </manifest>

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.