Common Android Methods

Source: Internet
Author: User

/*** * Determine if the phone number is legal *@see11 Digits, 1 start *@paramMobiles *@returnBoolean*/     Public Static Booleanismobile (String mobiles) {if(NULL==mobiles) {            return false; }        if(Mobiles.length ()!=11) {            return false; }         for(inti = Mobiles.length ();--i>=0;){                  if(!Character.isdigit (Mobiles.charat (i))) {                return false; }              }        if(!mobiles.startswith ("1")) {            return false; }        return true; }
/*** Switch from DP unit to PX (pixel) According to the resolution of the phone*/       Public Static intDIP2PX (Context context,floatdpvalue) {          Final floatScale =context.getresources (). Getdisplaymetrics (). density; return(int) (Dpvalue * scale + 0.5f); }        /*** According to the resolution of the phone from PX (pixel) to the unit to become DP*/       Public Static intPx2dip (Context context,floatpxvalue) {          Final floatScale =context.getresources (). Getdisplaymetrics (). density; return(int) (Pxvalue/scale + 0.5f); }      
  Public StaticSimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd hh:mm");  Public StaticSimpleDateFormat SDF1 =NewSimpleDateFormat ("hh:mm");  Public StaticSimpleDateFormat SDF2 =NewSimpleDateFormat ("Mm-dd");  Public StaticSimpleDateFormat SDF3 =NewSimpleDateFormat ("Yy-mm-dd");  Public StaticSimpleDateFormat SDF4 =NewSimpleDateFormat ("yyyy");  Public StaticSimpleDateFormat Sdf5 =NewSimpleDateFormat ("Mm-dd hh:mm");  Public StaticSimpleDateFormat Sdf6 =NewSimpleDateFormat ("Yyyymmddhhmmss"); /**     * @paramString *@return* Private Messages List Time display Description: * Day: Display hours: minutes (hh:mm). * Non-day: Show month-day (MM-DD) * Non-year: Show year-month-day (YY-MM-DD)*/     Public StaticString Getletterlistdate (LongTime ) {Date nowdate=NewDate (); Date Date=NewDate (time); if(!Sdf4.format (nowdate). Equals (Sdf4.format (date)) {            returnSdf3.format (date); } Else if(Sdf3.format (nowdate). Equals (Sdf3.format (date))) {returnSdf1.format (date); } Else {            returnSdf2.format (date); }    }    /**     * @paramString *@return* Private Messages List Time display Description: * Day: Display hours: minutes (hh:mm). * Non-day: Show month-day (MM-DD) * Non-year: Show year-month-day (YY-MM-DD)*/     Public StaticString Getletterlistdatesimple (LongTime ) {Date nowdate=NewDate (); Date Date=NewDate (time); if(!Sdf4.format (nowdate). Equals (Sdf4.format (date)) {            returnSdf3.format (date); } Else if(Sdf3.format (nowdate). Equals (Sdf3.format (date))) {returnSdf1.format (date); } Else {            returnSdf2.format (date); }    }        /**     * @paramString *@return* Private Messages Chat window time display Description: * Day: Display hours: minutes (hh:mm). * Non-day: Show month-day Hours: minutes (mm-dd hh:mm) * Non-year: show years-month-day Hours: minutes (yy-mm-dd hh:mm)*/         Public StaticString Getletterdate (LongTime ) {Date nowdate=NewDate (); Date Date=NewDate (time); if(!Sdf4.format (nowdate). Equals (Sdf4.format (date)) {                returnSdf.format (date); } Else if(Sdf3.format (nowdate). Equals (Sdf3.format (date))) {returnSdf1.format (date); } Else {                returnSdf5.format (date); }        }
/*** Calculates the text word count, a Chinese character = Two English letters, one chinese punctuation = Two English punctuation Note: This function does not apply to the calculation of a single character, because a single character is rounded 1 * *@paramc *@return     */public staticLongcalculatelength (charsequence c) {DoubleLen = 0;  for(inti = 0; I < c.length (); i++) {            intTMP = (int) C.charat (i); if(tmp > 0 && tmp < 127) {len+ = 0.5; } Else{len++; }        }        returnMath.Round (len); }
 Public Static void Openactivityanim (activity activity) {        activity.overridependingtransition (r.anim.tran_next_in, R.anim.tran _next_out);    }      Public Static void Finishactivityanim (activity activity) {        activity.overridependingtransition (r.anim.left_in,r.anim.right _out);    }

Common Android Methods

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.