19 Android Common Tools class summary, Android Tool class summary _php tutorial

Source: Internet
Author: User
Tags response code

19 Android Common Tools class summary, Android tool class summary


Mainly introduced in the summary of Android development commonly used tool 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 the code is in Trineaandroidcommon@github, Welcome to star or fork^_*, except for these tool classes this project also includes caching, Dropdown listview, and so on. The detailed interface describes the visible Trineaandroidcommon API guide.

Specific use: You can directly introduce Trineaandroidcommon as your project's library (how to pull a replacement code and add a public library), or extract some of its own use.

1, Httputils

HTTP Network tool classes, mainly including HttpGet, HttpPost, and HTTP parameter related methods, take httpget as an 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, using BufferedReader to improve read speed.
HttpRequest can set the URL, timeout, useragent and other HTTP parameters
Return content, HTTP response code, HTTP Expiration Time (Cache-control Max-age and expires) can be obtained in HttpResponse, etc.
The first two methods can be advanced parameter setting 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 visible Httputils.java, more methods and more detailed parameters of the Httputils Api Guide can be seen.

2, Downloadmanagerpro

Android system Download Management Downloadmanager enhancement method that can be used to include information about downloads such as:
Getstatusbyid (long) Get download status
Getdownloadbytes (long) get Download progress information
Getbytesandstatus (long) Get download progress information and status
GetFileName (long) get the download file path
GetURI (long) get download URI
GetReason (long) gets the download failure or pause reason
Getpausedreason (long) get download pause reason
GetErrorCode (long) get download error code
Source visible Downloadmanagerpro.java, more methods and more detailed parameters of the Downloadmanagerpro Api Guide can be seen. About Android Downmanager using the 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 the root permission is executed
ExecCommand (String command, Boolean isRoot) Shell Environment Execution command
Source visible Shellutils.java, more methods and more detailed parameters of the Shellutils Api Guide can be seen. Silent installation of visible Apk-root permissions on silent installation.

4, Packageutils

Android Package Related tool class, can be used to (root) install the application, (root) Uninstall the application, determine whether the system application, such as:
Install the app (Context, String), install silently if it is a system application or root, otherwise install normally
Uninstall (Context, String) Uninstall the application, if it is a system application or has root, then silently uninstall, otherwise general uninstall
Issystemapplication (Context, String) to determine if the application is a system application
Source visible Packageutils.java, more methods and more detailed parameters of the Shellutils Api Guide can be seen. Silent installation of visible Apk-root permissions on silent installation.

5, Preferencesutils

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

6, Jsonutils

The Jsonutils tool class 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 the string type value
String getString (String jsondata, String key, String defaultvalue) Gets the string type value
Represents the value of reading a string type key from JSON

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

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 the file size
DeleteFile (String path) Delete file
Source visible Fileutils.java, more methods and more detailed parameters of the Fileutils Api Guide can be seen.

8, Resourceutils

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

9, StringUtils

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

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) Read Boolean type data from Pacel
Readhashmap (Parcel in, ClassLoader loader) read map type data from Pacel
Writeboolean (Boolean B, Parcel out) writes Boolean type data to Parcel
Writehashmap (Map map, Parcel out, int flags) writes map type data to Parcel
Source visible Parcelutils.java, more methods and more detailed parameters of the Parcelutils Api Guide can be seen.

11, Randomutils

The random Number tool class, which can be used to obtain a random number of fixed-size fixed character characters, such as:
Getrandom (char[] sourcechar, int length) generates a random string, all characters nonspacing within a string
getrandomnumbers (int length) generates random numbers
Source visible Randomutils.java, more methods and more detailed parameters of the Randomutils Api Guide can be seen.

12, Arrayutils

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

13, Imageutils

The Picture tool class, which can be used for conversion between bitmap, byte array, drawable, and image scaling, is currently weak and will be enhanced later. Such as:
Bitmaptodrawable (Bitmap B) bimap convert to Drawable
Drawabletobitmap (drawable D) drawable convert to bitmap
Drawabletobyte (drawable D) drawable convert to Byte
Scaleimage (Bitmap org, float scalewidth, float scaleheight) zoom picture
Source visible Imageutils.java, more methods and more detailed parameters of the Imageutils Api Guide can be seen.

14, Listutils

The list tool class, which can be used for list common operations, such as:
IsEmpty (list sourceList) determines whether the list is empty or has a length of 0
Join (List list, string separator) list is converted to a string and split with a fixed delimiter
Adddistinctentry (List sourceList, V Entry) adds non-repeating elements to the list
Source visible Listutils.java, more methods and more detailed parameters of the Listutils Api Guide can be seen.

15, Maputils

The Map tool class, which can be used for map common operations such as:
IsEmpty (Map sourcemap) to determine whether the map is empty or length is 0
Parsekeyandvaluetomap (string source, String keyandvalueseparator, String Keyandvaluepairseparator, Boolean Ignorespace) string parsing to map
ToJson (map map) Map converted to JSON format
Source visible Maputils.java, more methods and more detailed parameters of the Maputils Api Guide can be seen.

16, Objectutils

The Object tool class, which can be used for object common operations, such as:
Isequals (object actual, object expected) compares two objects for equality
Compare (v v1, v V2) compare two object sizes
Transformintarray (int[] source) Integer array converted to int array
Source visible Objectutils.java, more methods and more detailed parameters of the Objectutils Api Guide can be seen.

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 objects to a file
Source visible Serializeutils.java, more methods and more detailed parameters of the Serializeutils Api Guide can be seen.

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 () Get the thread pool size that matches the system configuration
Source visible Systemutils.java, more methods and more detailed parameters of the Systemutils Api Guide can be seen.

19, Timeutils

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

http://www.bkjia.com/PHPjc/935484.html www.bkjia.com true http://www.bkjia.com/PHPjc/935484.html techarticle 19 Android Common Tools class summary, Android Tool class summary mainly describes the summary of Android development commonly used tool classes, most of the same applies to Java. Currently includes Httputils, Downloa ...

  • 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.