19 Android Common Tool class Rollup _php instance

Source: Internet
Author: User
Tags current time response code serialization

The main introduction to the summary of the development of Android common tools classes, most of the same applies to Java.
Currently includes Httputils, Downloadmanagerpro, Shellutils, Packageutils, Preferencesutils, Jsonutils, FileUtils, Resourceutils, StringUtils, Parcelutils, Randomutils, Arrayutils, Imageutils, Listutils, Maputils, Objectutils, SerializeUtils, Systemutils, Timeutils.

The 中文版 version of this article see:android Common Utils

All code is in Trineaandroidcommon@github, Welcome to star or fork^_*, in addition to these tool classes this project also includes caching, Drop-down ListView, and so on. The detailed interface describes the visible Trineaandroidcommon API Guide.

Specific use: You can directly introduce Trineaandroidcommon as the library of your project (how to pull the substitution code and add a common library), or to extract some of its use.

1, Httputils

HTTP Network tool class, mainly includes HttpGet, HttpPost and HTTP parameter related methods, take httpget as example:
Static HttpResponse HttpGet (HttpRequest request)
Static HttpResponse HttpGet (java.lang.String httpurl)
static string httpgetstring (String httpurl)
Contains the above three methods, using GZIP compression by default and using BufferedReader to increase read speed.
HttpRequest can set the URL, timeout, useragent, and other HTTP parameters
HttpResponse can get the return content, HTTP response code, HTTP Expiration Time (Cache-control Max-age and expires), etc.
The first two methods can be advanced parameter settings and rich content return, the third method can simply pass in the URL to get the return content, httppost similar. More detailed settings can be used directly with the HttpURLConnection or Apache httpclient.
Source can be seen Httputils.java, more methods and more detailed parameters are visible httputils Api Guide.

2, Downloadmanagerpro

The Android system downloads Management Downloadmanager enhancements, which can be used to include download-related information such as:
Getstatusbyid (long) Get download status
Getdownloadbytes (long) get Download progress information
Getbytesandstatus (long) Get download progress information and status
GetFileName (long) Gets the download file path
GetURI (long) gets the download URI
GetReason (long) gets download failure or pause reason
Getpausedreason (long) Gets the download pause reason
GetErrorCode (long) gets the download error code
Source can be seen Downloadmanagerpro.java, more methods and more detailed parameters are visible Downloadmanagerpro Api Guide. About Android Downmanager use visible Downmanager Demo.

3, Shellutils

The Android Shell tool class, which can be used to check system root permissions and execute shell commands under the shell or root user. Such as:
Checkrootpermission () Check root permissions
ExecCommand (string[] commands, Boolean isRoot, Boolean isneedresultmsg) the shell environment executes the command, and the second parameter indicates whether root permissions Execute
ExecCommand (String command, Boolean isRoot) Shell Environment Execution command
Source can be seen Shellutils.java, more methods and more detailed parameters are visible shellutils Api Guide. About silent installations visible apk-root permissions are silently installed.

4, Packageutils

Android Package-related tools, which can be used for (root) installation applications, (root) uninstall applications, to determine whether system applications, etc., such as:
Install (context, String) installation application, if it is System application or already root, then silently installs, otherwise the general installation
Uninstall (context, String) Uninstall application, if it is System application or already root, then silently uninstall, otherwise general uninstall
Issystemapplication (context, String) to determine whether the application is a system application
Source can be seen Packageutils.java, more methods and more detailed parameters are visible shellutils Api Guide. About silent installations visible apk-root permissions are silently installed.

5, Preferencesutils

The Android sharedpreferences related tool class, which can be used to easily read and write related types of data to sharedpreferences, such as:
Putstring (Context, String, string) save String type data
Putint (context, String, int) Save int type data
GetString (context, String) getting String type data
GetInt (context, String) getting int type data
You can modify the preference name by modifying the preference_name variable
Source can be seen Preferencesutils.java, more methods and more detailed parameters are visible preferencesutils Api Guide.

6, Jsonutils

The Jsonutils tool class, which can be used to easily read and write related types of data to JSON, such as:
String getString (Jsonobject jsonobject, string key, String defaultvalue) gets string type value
String getString (String jsondata, String key, String defaultvalue) gets string type value
Represents the value of reading a string key from JSON

Getmap (Jsonobject jsonobject, String key) gets map
Getmap (String jsondata, string key) get map
Represents the value of reading a map type key from JSON
Source can be seen Jsonutils.java, more methods and more detailed parameters are visible jsonutils Api Guide.

7, FileUtils

A file tool class that can be used to read and write files and manipulate files. Such as:
ReadFile (String filePath) Read file
WriteFile (string FilePath, String content, Boolean append) write file
GetFileSize (String path) to get file size
DeleteFile (String path) Delete file
Source can be seen Fileutils.java, more methods and more detailed parameters are visible fileutils Api Guide.

8, Resourceutils

The Android Resource Tool class, which can be used to read content from the raw and assets directories of the Android resource directory, such as:
Gefilefromassets (context, String fileName) Gets the contents of a file in the assets directory
Gefilefromraw (context, int resid) Gets the contents of a file under the raw directory
Source can be seen Resourceutils.java, more methods and more detailed parameters are visible resourceutils Api Guide.

9, StringUtils

String tool class, which can be used for common string operations, such as:
IsEmpty (String str) determines whether the string is empty or length 0
IsBlank (String str) determines whether the string is empty or has a length of 0 or is made up of spaces
Utf8encode (String str) encoded in UTF-8 format
Capitalizefirstletter (String str) First Letter Capital
Source can be seen Stringutils.java, more methods and more detailed parameters are visible stringutils Api Guide.

10, Parcelutils

The Android Parcel tool class, which can be used to read or write special types of data from parcel, such as:
Readboolean (Parcel in) reads Boolean type data from Pacel
Readhashmap (Parcel in, ClassLoader loader) reads map type data from Pacel
Writeboolean (Boolean B, Parcel out) writes Boolean type data to Parcel
Writehashmap (map<k, v> map, Parcel out, int flags) writes MAP type data to Parcel
Source can be seen Parcelutils.java, more methods and more detailed parameters are visible parcelutils Api Guide.

11, Randomutils

A random number tool class that can be used to obtain random numbers of fixed-size fixed-word characters, such as:
Getrandom (char[] sourcechar, int length) generates random strings, all words enclosed within a string
getrandomnumbers (int length) generates random numbers
Source can be seen Randomutils.java, more methods and more detailed parameters are visible randomutils Api Guide.

12, Arrayutils

An array tool class that can be used in an array of commonly used operations, such as:
IsEmpty (v[] sourcearray) to determine whether the array is empty or length 0
GetLast (v[] sourcearray, v value, v DefaultValue, Boolean iscircle) gets the previous element of an element in the array, iscircle indicates whether the loop
GetNext (v[] sourcearray, v value, v DefaultValue, Boolean iscircle) gets the next element of an element in the array, iscircle indicates whether the loop
Source can be seen Arrayutils.java, more methods and more detailed parameters are visible arrayutils Api Guide.

13, Imageutils

Picture Tool class, which can be used for bitmap, byte array, conversion between drawable and image scaling, the current function is weak, the following will be enhanced. Such as:
Bitmaptodrawable (Bitmap B) Bimap converted to drawable
Drawabletobitmap (drawable D) drawable converted to bitmap
Drawabletobyte (drawable D) drawable converted to byte
Scaleimage (Bitmap org, float scalewidth, float scaleheight) zoom picture
Source can be seen Imageutils.java, more methods and more detailed parameters are visible imageutils Api Guide.

14, Listutils

List Tool class, which can be used for list operations such as:
IsEmpty (list<v> sourceList) determines whether the List is empty or has a length of 0
The Join (list<string> list, string separator) list is converted to a string and separated by a fixed delimiter
Adddistinctentry (list<v> sourceList, V entry) add a repeating element to the list
Source can be seen Listutils.java, more methods and more detailed parameters are visible listutils Api Guide.

15, Maputils

The Map tool class, which can be used for map common operations such as:
IsEmpty (map<k, v> sourcemap) determines whether the Map is empty or has a length of 0
Parsekeyandvaluetomap (string source, String keyandvalueseparator, String Keyandvaluepairseparator, Boolean Ignorespace) string resolution to map
Tojson (map<string, string> map) map converted to JSON format
Source can be seen Maputils.java, more methods and more detailed parameters are visible maputils Api Guide.

16, Objectutils

Object tool class, which you can use for object-common operations, such as:
Isequals (object actual, object expected) compares two objects for equality
Compare (v v1, v v2) compares two object sizes
Transformintarray (int[] source Integer array to int array
Source can be seen Objectutils.java, more methods and more detailed parameters are visible objectutils Api Guide.

17, Serializeutils

A serialization tool class that can be used to serialize an object to a file or deserialize an object from a file, such as:
Deserialization (String FilePath) Deserializes an object from a file
Serialization (String FilePath, Object obj) serializes an object to a file
Source can be seen Serializeutils.java, more methods and more detailed parameters are visible serializeutils Api Guide.

18, Systemutils

The System Information tool class, which can be used to get the appropriate size of the thread pool, is currently weak and will be enhanced later. Such as:
Getdefaultthreadpoolsize () Gets the thread pool size that corresponds to the system configuration
Source can be seen Systemutils.java, more methods and more detailed parameters are visible systemutils Api Guide.

19, Timeutils

A Time tool class that can be used for time-related operations, such as:
Getcurrenttimeinlong () Get current time
GetTime (Long Timeinmillis, SimpleDateFormat DateFormat) converts a long to a fixed-format time string
Source can be seen Timeutils.java, more methods and more detailed parameters are visible timeutils Api Guide.

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.