/** * Some common functions */public class Functionutil {private static long Lastclicktime = 0;/** * Start with this, and then no limit, call Checkphone method. Determine if the phone format is correct, when registering and modifying the mobile phone number to use the * * @param mobiles * @return true: The correct mobile phone number */public static Boolean Ismobileno (String mobiles) { Pattern.compile ("^ (13[0-9) | ( 15[^4,\\D]) | (18[0,5-9])) \\d{8}$ "); Pattern p = pattern.compile ("^ (1 ([358][0-9]) | ( 4[57])) \\d{8}$ "); Matcher m = p.matcher (mobiles); return m.matches ();} /** * Check Phone number * * @param context * @param phone * @return */public static Boolean Checkphone (context context, String phone ) {if (null = = Phone | | ". Equals (phone) | |" ". Equals (Phone.trim ())) {Functionutil.toastmessage (context, "Please enter mobile phone number"); return false;} else if (Phone.length ()! = 11 | |! Phone.startswith ("1")) {Functionutil.toastmessage (context, "cell phone number is not formatted"); return false;} return true;} /** * Whether the user name contains special characters when registering with illegal characters * * @return true: Contains special characters, Fasle does not contain */public static Boolean Containinvalidchars (String STR) {if (str = = NULL | | "". Equals (str)) return false; String Special_stR = "#[email protected]%^&* ();" \ "? ><[]{}\\|,:/=+-" "'. ' $;,.! @#¥%......&* ()--+? "; for (int i = 0; I < str.length (); i++) {if (Special_str.indexof (Str.charat (i))! =-1) {return true;}} return false;} /** * Determine if all are numbers * * @param str * @return true: All is digital */public static Boolean Isnumer (String str) {Pattern pattern = pattern . Compile ("[0-9]*"); Matcher isnum = Pattern.matcher (str), if (!isnum.matches ()) {return false;} return true;} /** * Determine if the email format is correct * * @param email * @return */public static Boolean isemail (string email) {Final string str_email = "^ ([a-za-z0-9_\\-\\.] +) @ ((\\[[0-9]{1,3}\\. [0-9] {1,3}\\. [0-9] {1,3}\\.) | ([a-za-z0-9\\-]+\\.) +)) ([a-za-z]{2,4}| [0-9] {1,3}) (\\]?) $"; Pattern p = pattern.compile (Str_email); Matcher m = p.matcher (email); return m.matches ();} TOAST hint statement public static void Toastmessage (context context, String message) {Toast.maketext (context, message, Toast.length_short). Show ();} /** * Use when printing information to the console test, when packaging the code in the comment */public static void Sysmessage (String message) {System.out.println (message);} public static String GetTime () {Calendar c = calendar.getinstance ();//Get East Eight zone time SimpleDateFormat s = new SimpleDateFormat (" Yyyy-mm-dd HH:mm:ss "); return S.format (C.gettime ()); Current date}public static String getTime2 () {Calendar c = calendar.getinstance ();//Get East Eight zone time SimpleDateFormat s = new Simpledat Eformat ("Mm-dd hh:mm"); return S.format (C.gettime ()); Current date}/** * format time, minus seconds * * @param times * @return */public static string Deletesecond (string "{") {if ' = ' null | | ' Null ". Equals (time) | | ". Equals (time)) return" ";D ateformat format = new SimpleDateFormat (" Yyyy-mm-dd HH:mm:ss ");D ate ddate = null;try {ddate = f Ormat.parse (time);} catch (ParseException e) {e.printstacktrace ();} format = new SimpleDateFormat ("Yyyy-mm-dd hh:mm"); return Format.format (ddate);} /** * Format time, remove year, seconds * * @param times * @return */public static string Deletenm (String "{if") {if * = NULL | | "null". Equals (time) | | ". Equals (time)) return" ";D ateformat format = new SimpleDateFormat (" yyyy-Mm-dd HH:mm:ss ");D ate ddate = null;try {ddate = Format.parse (time),} catch (ParseException e) {e.printstacktrace ();} format = new SimpleDateFormat ("Mm-dd hh:mm"); return Format.format (ddate);} /** * Format time, go to hours, minutes, seconds * * @param times * @return */public static string Deletehhmmss (string "{if") {if * = NULL | | "null". Equals (time) | | ". Equals (time)) return" ";D ateformat format = new SimpleDateFormat (" Yyyy-mm-dd HH:mm:ss ");D ate ddate = null;try {ddate = f Ormat.parse (time);} catch (ParseException e) {e.printstacktrace ();} format = new SimpleDateFormat ("Yyyy-mm-dd"); return Format.format (ddate);} /** * Format time, get a few months a few days * * * * * * * * * * * @param @return */public static string Getmonthanddate (string times) {if (!strnotnull (time)) {return "";} DateFormat format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");D ate ddate = null;try {ddate = Format.parse (time);} catch (ParseException e) {E.printstacktrace ();} format = new SimpleDateFormat ("Mm-dd"); return Format.format (ddate);} /** * Format time, get hours and minutes * * @param times * @reTurn */public static string Gethourandminute (string time) {if (!strnotnull (time)) {return "";} DateFormat format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");D ate ddate = null;try {ddate = Format.parse (time);} catch (ParseException e) {E.printstacktrace ();} format = new SimpleDateFormat ("hh:mm"); return Format.format (ddate);} /** * Gets the time to display * * @param days * day * @param diff * to the time (in microseconds) * @param hours * when * @para M minutes * minutes * @param seconds * seconds * @return */public static String getshowtime (Long days, long diff , long hours, long minutes, long seconds) {days = diff/(+ +); hours = (Diff-days * (1000 * 60 * 60 * 24 )/(minutes *): (Diff-days * (+ +)-hours * (+ *))/(+ +); seconds = (( Diff-days * (+ +)-hours * (+ +)-minutes * (+))/(+); if (Days > 0) {return Days + "Day" + Hours + "time" + minutes + "min" + seconds + "seconds";} else IF (Hours <= 0 && minutes > 0) {return minutes + "min" + seconds + "SEC";} else if (hours <= 0 && Minu TES <= 0) {return seconds + "SEC";} Elsereturn Hours + "when" + minutes + "min" + seconds + "SEC";} Intercept string public static string capturestring (String str) {if (Strnotnull (str) && str.length () > 4) {return str.su Bstring (Str.length ()-3);} else {return "";}} /** * According to the resolution of the phone from the DP unit to the PX (pixel) */public static int dip2px (context context, float Dpvalue) {final float scale = Context. Getresources (). Getdisplaymetrics (). Density;return (int) (Dpvalue * scale + 0.5f);} /** * According to the resolution of the phone from px (pixels) to the unit to be the DP */public static int Px2dip (context context, float Pxvalue) {final float scale = Context. Getresources (). Getdisplaymetrics (). Density;return (int) (Pxvalue/scale + 0.5f);} Generate a note color ball (6+1) public static int[] RANDOMSSQ () {list<integer> List = new arraylist<integer> (); int[] array = NE W int[7];int number =-1; Random random = new random (), for (int i = 0; i < 6; i++) {Number = (Random.nextint (33) + 1); [1,34]//System.out.println ("for--------------------"), while (true) {//System.out.println (" While--------------------"+ number", if (list.contains (number)) {number = (Random.nextint) + 1),//[1,34)} else {list. Add (number); array[i] = Number;break;}}} list = null; Arrays.sort (array, 0, 6);//Sort [0,6] array[6] = (Random.nextint (16) + 1); [1,17] return array;} Generate a note big Lotto data (5+2) public static int[] RANDOMDLT () {list<integer> List = new arraylist<integer> (); int[] array = New Int[7];int number =-1; Random random = new random (), for (int i = 0; i < 5; i++) {number = (Random.nextint) + 1);//[1,36)//System.out.pri Ntln ("for--------------------"), while (true) {//System.out.println ("while--------------------" + number); if ( List.contains (number)) {Number = (Random.nextint (+) + 1);//[1,36)} else {list.add (number); array[i] = Number;break;}}} list = null; Arrays.sort (Array, 0, 5);//Sort [0,5] array[5] = (Random.nextint (12) + 1); [1,13] Number = (Random.nextint (12) + 1); [1,13] while (number = = Array[5]) {number = (Random.nextint) + 1);//[1,13]}array[6] = number; Arrays.sort (Array, 5, 7);//Sort [5,7) return array;} Generate a note of fast three data (3 numbers in 1-6 range) public static int[] RandomK3 (String playtype) {list<integer> List = new arraylist< Integer> (); int[] array = new Int[3];int number =-1; Random random = new random (), if ("501". Equals (Playtype)) {//and value for (int i = 0; i < 3; i++) {number = (Random.nextint (6) + 1); [1,7]//System.out.println ("for--------------------"); array[i] = number;}} else if ("506". Equals (Playtype)) {//three different numbers for (int i = 0; i < 3; i++) {number = (Random.nextint (6) + 1);//[1,7]//System. Out.println ("for--------------------"), while (true) {//System.out.println ("while--------------------" + number); if (List.contains (number)) {Number = (Random.nextint (6) + 1);//[1,7]} else {list.add (number); array[i] = Number;break;}}} else if ("503". Equals (Playtype)) {//Triple Radio number = (Random.nextint (6) + 1);//[1,7) for (int i = 0; I < 3; i++) {//System.out.println ("for--------------------"); array[i] = number;}} else if ("507". Equals (Playtype)) {//two different number array = new Int[2];number = (Random.nextint (6) + 1);//[1,7] array[0] = number;list. Add (number), while (true) {//System.out.println ("while--------------------" + number), if (list.contains (number)) { Number = (Random.nextint (6) + 1); [1,7]} else {array[1] = Number;break;}}} Arrays.sort (array);//Sort return array;} Generate a note 11 Select 5 data (5 numbers are within 1-11 range) public static int[] RANDOM11CHOOSE5 (String play_type) {int numberlenth = 8;if ("208". Equals ( Play_type)) {numberlenth = 8;} else if ("207". Equals (Play_type)) {numberlenth = 7;} else if ("206". Equals (Play_type)) {numberlenth = 6;} else if ("205". Equals (Play_type)) {numberlenth = 5;} else if ("204". Equals (Play_type)) {numberlenth = 4;} else if ("203". Equals (Play_type)) {numberlenth = 3;} else if ("202". Equals (Play_type)) {numberlenth = 2;} list<integer> list = new arraylist<integer> (); int[] array = new Int[numberlenth];int number =-1; Random random = new random (), for (int i = 0; i < Numberlenth; i++) {number = (Random.nextint (one) + 1);//[1,12]//Syst Em.out.println ("for--------------------"), while (true) {//System.out.println ("while--------------------" + number) if (list.contains (number)) {Number = (Random.nextint (one) + 1),//[1,12)} else {list.add (number); array[i] = Number;break; }}}arrays.sort (array);//Sort return array;} /** * Prevent users from continuously clicking * * @return */public static Boolean Isfastdoubleclick () {if (Lastclicktime = = 0) {//Just start the first run Lastclicktime = System.currenttimemillis (); return false;} Previously run in place, now in another activity run long time = System.currenttimemillis (); Long timedistanse = time-lastclicktime;if (0 < Ti Medistanse && Timedistanse <) {return true;} Lastclicktime = Time;return false;} Determines whether the string is empty, NOT NULL returns truepublic static Boolean Strnotnull (String str) {if (str = = NULL | | "null". Equals (str) | | "". Equals (Str.trim ())) {return false;} return true;} Determines whether the list is empty and does not return truepublic static Boolean Listnotnull (list<object> list) {if (list = = NULL | | list.size () = = 0) {return false;} return true;} Determines whether the list is empty, does not return truepublic static Boolean liststringnotnull (list<string> list) {if (list = = NULL | | list.size () = = 0) {return false;} return true;} Determines whether the array is empty, NOT NULL returns truepublic static Boolean Arraynotnull (object[] array) {if (array = = NULL | | array.length = = 0) {retur n false;} return true;} Determines whether the map is empty, NOT NULL returns truepublic static Boolean Mapnotnull (map map) {if (map = = NULL | | map.size () = = 0) {return false;} return true;} /** * List Sort * * @param code * @return */public static arraylist<string> Sortarray (arraylist<string> code) {/ /Remove all for (int i = 0; i < code.size (); i++) Code.set (i, code.get (i) = = null? "0": Code.get (i). ReplaceAll ("//d+", "")); for (int i = 0; I < code.size (); i++) {for (int j = i, J < Code.size (); j + +) {if (Integer.valueof (Code.get (i)) > Integer.valueof (Code.get (j))) {Strin G TMP = Code.get (j); Code.set (J, Code.get (i)); Code.set (i, TMP);}}} RetUrn Code;} }
Common common functions and methods of the company's Android project