Android. Util Namespace
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Classes
Base class for all checked exceptions thrown by the Android frameworks.
Base class for all unchecked exceptions thrown by the Android frameworks.
ArrayMap is a generic key->value mapping data structure that is designed to be more memory efficient than a traditional java.util.HashMap .
ArraySet is a generic set data structure that is designed to be more memory efficient than a traditional java.util.HashSet .
Helper class for performing atomic operations on a file by writing to a new file and renaming it into the place of the original file after the write has successfully completed.
Utilities for encoding and decoding the Base64 representation of binary data.
This exception is thrown by Base64InputStream or Base64OutputStream when an error is detected in the data being decoded.
An InputStream that does Base64 decoding on the data read through it.
An OutputStream that does Base64 encoding on the data written to it, writing the resulting data to another OutputStream.
CloseGuard is a mechanism for flagging implicit finalizer cleanup of resources that should have been cleaned up by explicit close methods (aka «explicit termination methods» in Effective Java).
Various utilities for debugging and logging.
A structure describing general information about a display, such as its size, density, and font scaling.
Access to the system diagnostic event record.
A previously logged event read from the logs.
Math routines similar to those found in java.lang.Math .
An implementation of android.util.Property to be used specifically with fields of type float .
The Half class is a wrapper and a utility class to manipulate half-precision 16-bit
An implementation of android.util.Property to be used specifically with fields of type int .
Reads a JSON (
A structure, name or value type in a JSON-encoded string.
Writes a JSON (
A class for defining layout directions.
Mock Log implementation for testing on non android host.
Implementation of a android.util.Printer that sends its output to the system log.
SparseArray mapping longs to Objects.
A cache that holds strong references to a limited number of values.
Thrown when a reader encounters malformed JSON.
Helps answer common questions that come up when displaying a month in a 6 row calendar grid format.
Thrown when code requests a Property on a class that does not expose the appropriate method or field.
Container to ease passing around a tuple of two objects.
Commonly used regular expression patterns.
Implementation of a android.util.Printer that sends its output to a java.io.PrintStream .
Implementation of a android.util.Printer that sends its output to a java.io.PrintWriter .
A property is an abstraction that can be used to represent a mutable value that is held in a host object.
Immutable class for describing the range of two numeric values.
An immutable data type representation a rational number.
Immutable class for describing width and height dimensions in pixels.
Immutable class for describing width and height dimensions in some arbitrary unit.
SparseArray maps integers to Objects and, unlike a normal array of Objects, its indices can contain gaps.
SparseArrays map integers to Objects.
SparseBooleanArrays map integers to booleans.
SparseIntArrays map integers to integers.
SparseLongArrays map integers to longs.
State sets are arrays of positive ints where each element represents the state of a android.view.View (e.
Implementation of a android.util.Printer that sends its output to a StringBuilder .
A class containing utility methods related to time zones.
A utility class to help log timings splits throughout a method call.
Container for a dynamically typed data value.
XML utility methods.
Supported character encodings.
Interfaces
A collection of attributes, as found associated with a tag in an XML document.
Simple interface for printing text, allowing redirection to various targets.
Enums
Enumerates values returned by several types and taken as a parameter of several types.
Enumerates values returned by several methods of ComplexType.
Enumerates values returned by several methods of ComplexUnitType and taken as a parameter of the F:Android.Util.TypedValue.ApplyDimension, and F:Android.Widget.TextView.SetTextSize members.
Enumerates values returned by several types and taken as a parameter of the CoerceToString() member.
Enumerates values returned by several types.
Enumerates values returned by several types.
Enumerates values returned by several methods of LogPriority and taken as a parameter of several types.
Источник
john1jan / PrefKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
/** |
* Created by john.francis on 24/05/16. |
*/ |
public class PrefKeys < |
public static final String USER_INCOME = » USER_INCOME » ; |
public static final String USER_MARITAL_STATUS = » USER_MARITAL_STATUS » ; |
public static final String USER_SALARY_FLOAT = » USER_SALARY_FLOAT » ; |
public static final String USER_SALARY_LONG = » USER_SALARY_LONG » ; |
public static final String USER_AGE = » USER_AGE » ; |
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
import android.content.Context ; |
import android.content.SharedPreferences ; |
import android.preference.PreferenceManager ; |
import android.util.Log ; |
import java.lang.ref.WeakReference ; |
/** |
* Created by john.francis on 16/12/15. |
*/ |
public class PrefUtils < |
/** |
* Called to save supplied value in shared preferences against given key. |
* |
* @param context Context of caller activity |
* @param key Key of value to save against |
* @param value Value to save |
*/ |
public static void saveToPrefs ( Context context , String key , Object value ) < |
WeakReference Context > contextWeakReference = new WeakReference Context > (context); |
if (contextWeakReference . get() != null ) < |
SharedPreferences prefs = |
PreferenceManager . getDefaultSharedPreferences(contextWeakReference . get()); |
final SharedPreferences . Editor editor = prefs . edit(); |
if (value instanceof Integer ) < |
editor . putInt(key, (( Integer ) value) . intValue()); |
> else if (value instanceof String ) < |
editor . putString(key, value . toString()); |
> else if (value instanceof Boolean ) < |
editor . putBoolean(key, (( Boolean ) value) . booleanValue()); |
> else if (value instanceof Long ) < |
editor . putLong(key, (( Long ) value) . longValue()); |
> else if (value instanceof Float ) < |
editor . putFloat(key, (( Float ) value) . floatValue()); |
> else if (value instanceof Double ) < |
editor . putLong(key, Double . doubleToRawLongBits(( double ) value)); |
> |
editor . commit(); |
> |
> |
/** |
* Called to retrieve required value from shared preferences, identified by given key. |
* Default value will be returned of no value found or error occurred. |
* |
* @param context Context of caller activity |
* @param key Key to find value against |
* @param defaultValue Value to return if no data found against given key |
* @return Return the value found against given key, default if not found or any error occurs |
*/ |
public static Object getFromPrefs ( Context context , String key , Object defaultValue ) < |
WeakReference Context > contextWeakReference = new WeakReference Context > (context); |
if (contextWeakReference . get() != null ) < |
SharedPreferences sharedPrefs = |
PreferenceManager . getDefaultSharedPreferences(contextWeakReference . get()); |
try < |
if (defaultValue instanceof String ) < |
return sharedPrefs . getString(key, defaultValue . toString()); |
> else if (defaultValue instanceof Integer ) < |
return sharedPrefs . getInt(key, (( Integer ) defaultValue) . intValue()); |
> else if (defaultValue instanceof Boolean ) < |
return sharedPrefs . getBoolean(key, (( Boolean ) defaultValue) . booleanValue()); |
> else if (defaultValue instanceof Long ) < |
return sharedPrefs . getLong(key, (( Long ) defaultValue) . longValue()); |
> else if (defaultValue instanceof Float ) < |
return sharedPrefs . getFloat(key, (( Float ) defaultValue) . floatValue()); |
> else if (defaultValue instanceof Double ) < |
return Double . longBitsToDouble(sharedPrefs . getLong(key, Double . doubleToLongBits(( double ) defaultValue))); |
> |
> catch ( Exception e) < |
Log . e( » Execption » , e . getMessage()); |
return defaultValue; |
> |
> |
return defaultValue; |
> |
/** |
* @param context Context of caller activity |
* @param key Key to delete from SharedPreferences |
*/ |
public static void removeFromPrefs ( Context context , String key ) < |
WeakReference Context > contextWeakReference = new WeakReference Context > (context); |
if (contextWeakReference . get() != null ) < |
SharedPreferences prefs = |
PreferenceManager . getDefaultSharedPreferences(contextWeakReference . get()); |
final SharedPreferences . Editor editor = prefs . edit(); |
editor . remove(key); |
editor . commit(); |
> |
> |
public static boolean hasKey ( Context context , String key ) < |
WeakReference Context > contextWeakReference = new WeakReference Context > (context); |
if (contextWeakReference . get() != null ) < |
SharedPreferences prefs = |
PreferenceManager . getDefaultSharedPreferences(contextWeakReference . get()); |
return prefs . contains(key); |
> |
return false ; |
> |
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Источник
Utils class in android
Android工具类库
类 | 介绍 |
---|---|
AnimationUtils | Animation 工具类 |
AppUtils | APP 相关信息工具类 |
AssetDatabaseOpenHelper | 读取 Asset 目录中数据库工具类 |
BitmapUtil | Bitmap 工具类主要包括获取 Bitmap 和对 Bitmap 的操作 |
CipherUtils | 加密与解密的工具类 |
Colors | 常用颜色色值工具类 |
CommonUtil | 一些通用的方法 |
ChannelUtil | 为打包而生的渠道工具类 极速打包传送门 |
DataCleanManager | 应用数据清除类,主要功能有清除内/外缓存,清除数据库,清除 SharedPreference,清除 files 和清除自定义目录 |
DatabaseExportUtils | 导出应用数据库工具类 |
DateUtils | 日期工具类 |
DeviceStatusUtils | 手机状态工具类 主要包括网络、蓝牙、屏幕亮度、飞行模式、音量等 |
DisplayUtils | 系统显示相关工具类 |
DoubleKeyValueMap | 双键值对 |
DownloadManagerPro | 下载管理工具类 |
FileUtils | 文件操作工具类 |
HanziToPinyin | 汉字转拼音工具类 |
ImsiUtil | IMSI 工具类 |
JSONUtils | Json 解析工具类 |
LocationUtils | 根据经纬度查询地址信息和根据地址信息查询经纬度 |
LogUtils | Log工具类。课参考博文:Android Log 工具类。 |
NetUtil | 网络工具类 |
PackageUtils | 应用安装下载相关 |
PhoneUtil | 手机组件调用工具类 |
PollingUtils | 轮询服务工具类 |
PreferencesCookieStore | Cookie 存储工具类 |
RUtils | R 反射资源 ID 工具类 |
RandomUtils | 随机工具类 |
RegUtils | 数据校验工具类 |
ResourceUtils | 文件资源读取工具类 |
SDCardUtils | SDcard 操作工具类 |
SettingUtils | 应用配置工具类 |
ShellUtils | shell 工具类 |
ShortCutUtils | 快捷方式工具类 |
Singleton | 单例模式抽象类 |
StringUtils | 字符串操作工具包。字符串其他操作可以使用 TextUtils 类。 |
ViewAnimationUtils | 视图动画工具箱,提供简单的控制视图的动画的工具方法 |
ViewUtils | View 相关工具类 |
ViewFinder | findViewById 替代工具类 |
WindowUtils | 窗口工具类 |
BaseApplication | 应用 Application 此处主要是为了错误处理。 |
BaseCrashHandler | 在 Application 中统一捕获异常,保存到文件中下次再打开时上传 |
RebootThreadExceptionHandler | 重启线程异常处理器,当发生未知异常时会提示异常信息并在一秒钟后重新启动应用。 |
StartAppReceiver | 重启应用广播接收器。 |
ToastsUtils | Toasts弹框。 |
SharesUtils | 分享,调用手机自带的分享字符串或图片。 |
DeviceUtils | 获取设备唯一标志 |
如何使用 (How to install)
发布正式版本注释 Log 只需要设置 LogUtils.DEBUG_LEVEL = Log.ASSERT 。
代码混淆只需要在 Proguard 规则文件中添加如下代码即可( Eclipse 下为 proguard.cfg 文件):
About
It contains most of the Android utility classes.
Источник