android源码里那些常用的Utils工具类
来源:互联网 发布:8080端口的作用 编辑:程序博客网 时间:2024/06/03 06:44
之前写项目遇到调用次数多的功能代码时,就需要写一个全局静态函数,并放在一个工具类中。不过后来发现,android系统本身提供了不少有用但不被发掘的工具类可供调用,使用系统类有助于缩减apk包大小,下面就和大家一起分析分析,如果有其他建议,可以在评论下面回复我哦。
1,android.database.DatabaseUtils
appendSelectionArgs:
函数功能:合并两个String数组,并返回合并后的数组。
public static String[] appendSelectionArgs(String[] originalValues, String[] newValues) {
//。。。省去无数代码
return result;
}
getSqlStatementType:
函数功能:判断sql语句的类型(SEL、INS、UPD、REP、DEL、ATT、COM、END、ROL、BEG、PRA、CRE、DRO、ALT、ANA、DET)
public static int getSqlStatementType(String sql) {
//。。。省去无数代码
return STATEMENT_OTHER;
}
cursor***ToContentValuesIfPresent(支持常用数据类型):
函数功能:将Cursor中指定的字段放到ContentValues数据中。
public static void cursor***ToContentValuesIfPresent(Cursor cursor, ContentValues values,
String column) {
final int index = cursor.getColumnIndex(column);
if (index != -1 && !cursor.isNull(index)) {
values.put(column, cursor.getFloat(index));
}
}
queryIsEmpty:
函数功能:判断表是否为空
public static boolean queryIsEmpty(SQLiteDatabase db, String table) {
long isEmpty = longForQuery(db, "select exists(select 1 from " + table + ")", null);
return isEmpty == 0;
}
queryNumEntries:
函数功能:查询表中数据的行数
public static long queryNumEntries(SQLiteDatabase db, String table, String selection,
String[] selectionArgs) {
String s = (!TextUtils.isEmpty(selection)) ? " where " + selection : "";
return longForQuery(db, "select count(*) from " + table + s,
selectionArgs);
}
2,android.util.MonthDisplayHelper
绘制6行x7列日历时,帮助开发者计算行列值的日期和月份
getYear\getMonth\getWeekStartDay\getFirstDayOfMonth\getNumberOfDaysInMonth,这5个函数的功能分别是获取年份、月份、一周开始日(周一或周日)、本月开始日是周几、本月有多少天。
getDigitsForRow:
函数功能:获取日历每行的日期范围
public int[] getDigitsForRow(int row) {
//。。。省去无数代码
return result;
}
previousMonth:
函数功能: 在当前日期基础上回退一个月
public void previousMonth() {
//。。。
}
nextMonth:
函数功能: 在当前日期基础上前进一个月
public void nextMonth() {
//。。。
}
isWithinCurrentMonth:
函数功能:判断指定列行的日期是否在本月之内
public boolean isWithinCurrentMonth(int row, int column) {
//。。。
return true;
}
3, android.view.View.inflate函数:
函数功能:类似于LayoutInflater
public static View inflate(Context context, @LayoutRes int resource, ViewGroup root) {
LayoutInflater factory = LayoutInflater.from(context);
return factory.inflate(resource, root);
}
android.view.View.generateViewId:
函数功能:生成一个和aapt、R.id不冲突的id值,可用于setId时
public static int generateViewId() {
//。。。省去无数代码
}
- android源码里那些常用的Utils工具类
- Android:常用Utils工具类
- Android:常用Utils工具类
- Android的Utils工具类的NetworkUtils
- java常用utils工具类
- Utils(上)一些常用的工具类
- Utils(下)一些常用的工具类
- 【造轮子】utils工具类(常用方法的封装)
- android工具类Utils集合
- android 工具类utils --01
- Android Utils工具类集合
- android/java常用的工具类源码
- Android---工具类Utils(你想不到的完美)
- android utils 日期工具
- android utils Log工具
- android utils Toast工具
- android快速开发--常用utils类
- android快速开发--常用utils类
- 设计模式初探-外观模式(FACADE)也叫门面模式
- Linux Shell编程入门
- strtok和strtok_r
- 使用 Interface Builder 兼容 iOS6 和iOS7
- 博客2013年度数据统计和排行
- android源码里那些常用的Utils工具类
- LLVM(三):Tablegen简介
- 求出栈序列,二叉树,二叉搜索树的计数问题
- 杭电OJ 1355:The Peanuts
- Oracle 同义词
- 2014年3月4号CSDN博客签到帖
- C++矩阵运算库推荐
- oauth对接淘宝订单
- #ifndef#define#endif的用法(整理)