Android开发 几个常用工具类

本文整理了10个常用的Android开发工具类,包括日志管理、Toast管理等,旨在提升开发效率并确保代码质量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文出自【张鸿洋的博客】并 做了部分修改。

转载请标明出处:http://blog.youkuaiyun.com/lmj623565791/article/details/38965311

打开大家手上的项目,基本都会有一大批的辅助类,今天特此整理出10个基本每个项目中都会使用的工具类,用于快速开发~~

在此感谢群里给我发项目中工具类的兄弟/姐妹~

1、日志工具类L.java

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.zhy.utils;  
  2.   
  3. import android.util.Log;  
  4.   
  5. /** 
  6.  * Log统一管理类 
  7.  *  
  8.  *  
  9.  *  
  10.  */  
  11. public class L  
  12. {  
  13.   
  14.     private L()  
  15.     {  
  16.         /* cannot be instantiated */  
  17.         throw new UnsupportedOperationException("cannot be instantiated");  
  18.     }  
  19.   
  20.     public static boolean isDebug = true;// 是否需要打印bug,可以在application的onCreate函数里面初始化  
  21.     private static final String TAG = "way";  
  22.   
  23.     // 下面四个是默认tag的函数  
  24.     public static void i(String msg)  
  25.     {  
  26.         if (isDebug)  
  27.             Log.i(TAG, msg);  
  28.     }  
  29.   
  30.     public static void d(String msg)  
  31.     {  
  32.         if (isDebug)  
  33.             Log.d(TAG, msg);  
  34.     }  
  35.   
  36.     public static void e(String msg)  
  37.     {  
  38.         if (isDebug)  
  39.             Log.e(TAG, msg);  
  40.     }  
  41.   
  42.     public static void v(String msg)  
  43.     {  
  44.         if (isDebug)  
  45.             Log.v(TAG, msg);  
  46.     }  
  47.   
  48.     // 下面是传入自定义tag的函数  
  49.     public static void i(String tag, String msg)  
  50.     {  
  51.         if (isDebug)  
  52.             Log.i(tag, msg);  
  53.     }  
  54.   
  55.     public static void d(String tag, String msg)  
  56.     {  
  57.         if (isDebug)  
  58.             Log.i(tag, msg);  
  59.     }  
  60.   
  61.     public static void e(String tag, String msg)  
  62.     {  
  63.         if (isDebug)  
  64.             Log.i(tag, msg);  
  65.     }  
  66.   
  67.     public static void v(String tag, String msg)  
  68.     {  
  69.         if (isDebug)  
  70.             Log.i(tag, msg);  
  71.     }  
  72. }  


网上看到的类,注释上应该原创作者的名字,很简单的一个类;网上也有很多提供把日志记录到SDCard上的,不过我是从来没记录过,所以引入个最简单的,大家可以进行评价是否需要扩充~~

2、Toast统一管理类 

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.zhy.utils;  
  2.   
  3. import android.content.Context;  
  4. import android.widget.Toast;  
  5.   
  6. /** 
  7.  * Toast统一管理类 
  8.  *  
  9.  */  
  10. public class T  
  11. {  
  12.   
  13.     private T()  
  14.     {  
  15.         /* cannot be instantiated */  
  16.         throw new UnsupportedOperationException("cannot be instantiated");  
  17.     }  
  18.   
  19.     public static boolean isShow = true;  
  20.   
  21.     /** 
  22.      * 短时间显示Toast 
  23.      *  
  24.      * @param context 
  25.      * @param message 
  26.      */  
  27.     public static void showShort(Context context, CharSequence message)  
  28.     {  
  29.         if (isShow)  
  30.             Toast.makeText(context, message, Toast.LENGTH_SHORT).show();  
  31.     }  
  32.   
  33.     /** 
  34.      * 短时间显示Toast 
  35.      *  
  36.      * @param context 
  37.      * @param message 
  38.      */  
  39.     public static void showShort(Context context, int message)  
  40.     {  
  41.         if (isShow)  
  42.             Toast.makeText(context, message, Toast.LENGTH_SHORT).show();  
  43.     }  
  44.   
  45.     /** 
  46.      * 长时间显示Toast 
  47.      *  
  48.      * @param context 
  49.      * @param message 
  50.      */  
  51.     public static void showLong(Context context, CharSequence message)  
  52.     {  
  53.         if (isShow)  
  54.             Toast.makeText(context, message, Toast.LENGTH_LONG).show();  
  55.     }  
  56.   
  57.     /** 
  58.      * 长时间显示Toast 
  59.      *  
  60.      * @param context 
  61.      * @param message 
  62.      */  
  63.     public static void showLong(Context context, int message)  
  64.     {  
  65.         if (isShow)  
  66.             Toast.makeText(context, message, Toast.LENGTH_LONG).show();  
  67.     }  
  68.   
  69.     /** 
  70.      * 自定义显示Toast时间 
  71.      *  
  72.      * @param context 
  73.      * @param message 
  74.      * @param duration 
  75.      */  
  76.     public static void show(Context context, CharSequence message, int duration)  
  77.     {  
  78.         if (isShow)  
  79.             Toast.makeText(context, message, duration).show();  
  80.     }  
  81.   
  82.     /** 
  83.      * 自定义显示Toast时间 
  84.      *  
  85.      * @param context 
  86.      * @param message 
  87.      * @param duration 
  88.      */  
  89.     public static void show(Context context, int message, int duration)  
  90.     {  
  91.         if (isShow)  
  92.             Toast.makeText(context, message, duration).show();  
  93.     }  
  94.   
  95. }  


也是非常简单的一个封装,能省则省了~~

3、SharedPreferences封装类SPUtils

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.zhy.utils;  
  2.   
  3. import java.lang.reflect.InvocationTargetException;  
  4. import java.lang.reflect.Method;  
  5. import java.util.Map;  
  6.   
  7. import android.content.Context;  
  8. import android.content.SharedPreferences;  
  9.   
  10. public class SPUtils  
  11. {  
  12.     /** 
  13.      * 保存在手机里面的文件名 
  14.      */  
  15.     public static final String FILE_NAME = "share_data";  
  16.   
  17.     /** 
  18.      * 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法 
  19.      *  
  20.      * @param context 
  21.      * @param key 
  22.      * @param object 
  23.      */  
  24.     public static void put(Context context, String key, Object object)  
  25.     {  
  26.   
  27.         SharedPreferences sp = context.getSharedPreferences(FILE_NAME,  
  28.                 Context.MODE_PRIVATE);  
  29.         SharedPreferences.Editor editor = sp.edit();  
  30.   
  31.         if (object instanceof String)  
  32.         {  
  33.             editor.putString(key, (String) object);  
  34.         } else if (object instanceof Integer)  
  35.         {  
  36.             editor.putInt(key, (Integer) object);  
  37.         } else if (object instanceof Boolean)  
  38.         {  
  39.             editor.putBoolean(key, (Boolean) object);  
  40.         } else if (object instanceof Float)  
  41.         {  
  42.             editor.putFloat(key, (Float) object);  
  43.         } else if (object instanceof Long)  
  44.         {  
  45.             editor.putLong(key, (Long) object);  
  46.         } else  
  47.         {  
  48.             editor.putString(key, object.toString());  
  49.         }  
  50.   
  51.         SharedPreferencesCompat.apply(editor);  
  52.     }  
  53.   
  54.     /** 
  55.      * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值 
  56.      *  
  57.      * @param context 
  58.      * @param key 
  59.      * @param defaultObject 
  60.      * @return 
  61.      */  
  62.     public static Object get(Context context, String key, Object defaultObject)  
  63.     {  
  64.         SharedPreferences sp = context.getSharedPreferences(FILE_NAME,  
  65.                 Context.MODE_PRIVATE);  
  66.   
  67.         if (defaultObject instanceof String)  
  68.         {  
  69.             return sp.getString(key, (String) defaultObject);  
  70.         } else if (defaultObject instanceof Integer)  
  71.         {  
  72.             return sp.getInt(key, (Integer) defaultObject);  
  73.         } else if (defaultObject instanceof Boolean)  
  74.         {  
  75.             return sp.getBoolean(key, (Boolean) defaultObject);  
  76.         } else if (defaultObject instanceof Float)  
  77.         {  
  78.             return sp.getFloat(key, (Float) defaultObject);  
  79.         } else if (defaultObject instanceof Long)  
  80.         {  
  81.             return sp.getLong(key, (Long) defaultObject);  
  82.         }  
  83.   
  84.         return null;  
  85.     }  
  86.   
  87.     /** 
  88.      * 移除某个key值已经对应的值 
  89.      * @param context 
  90.      * @param key 
  91.      */  
  92.     public static void remove(Context context, String key)  
  93.     {  
  94.         SharedPreferences sp = context.getSharedPreferences(FILE_NAME,  
  95.                 Context.MODE_PRIVATE);  
  96.         SharedPreferences.Editor editor = sp.edit();  
  97.         editor.remove(key);  
  98.         SharedPreferencesCompat.apply(editor);  
  99.     }  
  100.   
  101.     /** 
  102.      * 清除所有数据 
  103.      * @param context 
  104.      */  
  105.     public static void clear(Context context)  
  106.     {  
  107.         SharedPreferences sp = context.getSharedPreferences(FILE_NAME,  
  108.                 Context.MODE_PRIVATE);  
  109.         SharedPreferences.Editor editor = sp.edit();  
  110.         editor.clear();  
  111.         SharedPreferencesCompat.apply(editor);  
  112.     }  
  113.   
  114.     /** 
  115.      * 查询某个key是否已经存在 
  116.      * @param context 
  117.      * @param key 
  118.      * @return 
  119.      */  
  120.     public static boolean contains(Context context, String key)  
  121.     {  
  122.         SharedPreferences sp = context.getSharedPreferences(FILE_NAME,  
  123.                 Context.MODE_PRIVATE);  
  124.         return sp.contains(key);  
  125.     }  
  126.   
  127.     /** 
  128.      * 返回所有的键值对 
  129.      *  
  130.      * @param context 
  131.      * @return 
  132.      */  
  133.     public static Map<String, ?> getAll(Context context)  
  134.     {  
  135.         SharedPreferences sp = context.getSharedPreferences(FILE_NAME,  
  136.                 Context.MODE_PRIVATE);  
  137.         return sp.getAll();  
  138.     }  
  139.   
  140.     /** 
  141.      * 创建一个解决SharedPreferencesCompat.apply方法的一个兼容类 
  142.      *  
  143.      * @author zhy 
  144.      *  
  145.      */  
  146.     private static class SharedPreferencesCompat  
  147.     {  
  148.         private static final Method sApplyMethod = findApplyMethod();  
  149.   
  150.         /** 
  151.          * 反射查找apply的方法 
  152.          *  
  153.          * @return 
  154.          */  
  155.         @SuppressWarnings({ "unchecked""rawtypes" })  
  156.         private static Method findApplyMethod()  
  157.         {  
  158.             try  
  159.             {  
  160.                 Class clz = SharedPreferences.Editor.class;  
  161.                 return clz.getMethod("apply");  
  162.             } catch (NoSuchMethodException e)  
  163.             {  
  164.             }  
  165.   
  166.             return null;  
  167.         }  
  168.   
  169.         /** 
  170.          * 如果找到则使用apply执行,否则使用commit 
  171.          *  
  172.          * @param editor 
  173.          */  
  174.         public static void apply(SharedPreferences.Editor editor)  
  175.         {  
  176.             try  
  177.             {  
  178.                 if (sApplyMethod != null)  
  179.                 {  
  180.                     sApplyMethod.invoke(editor);  
  181.                     return;  
  182.                 }  
  183.             } catch (IllegalArgumentException e)  
  184.             {  
  185.             } catch (IllegalAccessException e)  
  186.             {  
  187.             } catch (InvocationTargetException e)  
  188.             {  
  189.             }  
  190.             editor.commit();  
  191.         }  
  192.     }  
  193.   
  194. }  

对SharedPreference的使用做了建议的封装,对外公布出put,get,remove,clear等等方法;

注意一点,里面所有的commit操作使用了SharedPreferencesCompat.apply进行了替代,目的是尽可能的使用apply代替commit

首先说下为什么,因为commit方法是同步的,并且我们很多时候的commit操作都是UI线程中,毕竟是IO操作,尽可能异步;

所以我们使用apply进行替代,apply异步的进行写入;

但是apply相当于commit来说是new API呢,为了更好的兼容,我们做了适配;

SharedPreferencesCompat也可以给大家创建兼容类提供了一定的参考~~


4、单位转换类 DensityUtils

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.zhy.utils;  
  2.   
  3. import android.content.Context;  
  4. import android.util.TypedValue;  
  5.   
  6. /** 
  7.  * 常用单位转换的辅助类 
  8.  *  
  9.  *  
  10.  *  
  11.  */  
  12. public class DensityUtils  
  13. {  
  14.     private DensityUtils()  
  15.     {  
  16.         /* cannot be instantiated */  
  17.         throw new UnsupportedOperationException("cannot be instantiated");  
  18.     }  
  19.   
  20.     /** 
  21.      * dp转px 
  22.      *  
  23.      * @param context 
  24.      * @param val 
  25.      * @return 
  26.      */  
  27.     public static int dp2px(Context context, float dpVal)  
  28.     {  
  29.         return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,  
  30.                 dpVal, context.getResources().getDisplayMetrics());  
  31.     }  
  32.   
  33.     /** 
  34.      * sp转px 
  35.      *  
  36.      * @param context 
  37.      * @param val 
  38.      * @return 
  39.      */  
  40.     public static int sp2px(Context context, float spVal)  
  41.     {  
  42.         return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,  
  43.                 spVal, context.getResources().getDisplayMetrics());  
  44.     }  
  45.   
  46.     /** 
  47.      * px转dp 
  48.      *  
  49.      * @param context 
  50.      * @param pxVal 
  51.      * @return 
  52.      */  
  53.     public static float px2dp(Context context, float pxVal)  
  54.     {  
  55.         final float scale = context.getResources().getDisplayMetrics().density;  
  56.         return (pxVal / scale);  
  57.     }  
  58.   
  59.     /** 
  60.      * px转sp 
  61.      *  
  62.      * @param fontScale 
  63.      * @param pxVal 
  64.      * @return 
  65.      */  
  66.     public static float px2sp(Context context, float pxVal)  
  67.     {  
  68.         return (pxVal / context.getResources().getDisplayMetrics().scaledDensity);  
  69.     }  
  70.   
  71. }  

5、SD卡相关辅助类 SDCardUtils

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.zhy.utils;  
  2.   
  3. import java.io.File;  
  4.   
  5. import android.os.Environment;  
  6. import android.os.StatFs;  
  7.   
  8. /** 
  9.  * SD卡相关的辅助类 
  10.  *  
  11.  *  
  12.  *  
  13.  */  
  14. public class SDCardUtils  
  15. {  
  16.     private SDCardUtils()  
  17.     {  
  18.         /* cannot be instantiated */  
  19.         throw new UnsupportedOperationException("cannot be instantiated");  
  20.     }  
  21.   
  22.     /** 
  23.      * 判断SDCard是否可用 
  24.      *  
  25.      * @return 
  26.      */  
  27.     public static boolean isSDCardEnable()  
  28.     {  
  29.         return Environment.getExternalStorageState().equals(  
  30.                 Environment.MEDIA_MOUNTED);  
  31.   
  32.     }  
  33.   
  34.     /** 
  35.      * 获取SD卡路径 
  36.      *  
  37.      * @return 
  38.      */  
  39.     public static String getSDCardPath()  
  40.     {  
  41.         return Environment.getExternalStorageDirectory().getAbsolutePath()  
  42.                 + File.separator;  
  43.     }  
  44.   
  45.     /** 
  46.      * 获取SD卡的剩余容量 单位byte 
  47.      *  
  48.      * @return 
  49.      */  
  50.     public static long getSDCardAllSize()  
  51.     {  
  52.         if (isSDCardEnable())  
  53.         {  
  54.             StatFs stat = new StatFs(getSDCardPath());  
  55.             // 获取空闲的数据块的数量  
  56.             long availableBlocks = (long) stat.getAvailableBlocks() - 4;  
  57.             // 获取单个数据块的大小(byte)  
  58.             long freeBlocks = stat.getAvailableBlocks();  
  59.             return freeBlocks * availableBlocks;  
  60.         }  
  61.         return 0;  
  62.     }  
  63.   
  64.     /** 
  65.      * 获取指定路径所在空间的剩余可用容量字节数,单位byte 
  66.      *  
  67.      * @param filePath 
  68.      * @return 容量字节 SDCard可用空间,内部存储可用空间 
  69.      */  
  70.     public static long getFreeBytes(String filePath)  
  71.     {  
  72.         // 如果是sd卡的下的路径,则获取sd卡可用容量  
  73.         if (filePath.startsWith(getSDCardPath()))  
  74.         {  
  75.             filePath = getSDCardPath();  
  76.         } else  
  77.         {// 如果是内部存储的路径,则获取内存存储的可用容量  
  78.             filePath = Environment.getDataDirectory().getAbsolutePath();  
  79.         }  
  80.         StatFs stat = new StatFs(filePath);  
  81.         long availableBlocks = (long) stat.getAvailableBlocks() - 4;  
  82.         return stat.getBlockSize() * availableBlocks;  
  83.     }  
  84.   
  85.     /** 
  86.      * 获取系统存储路径 
  87.      *  
  88.      * @return 
  89.      */  
  90.     public static String getRootDirectoryPath()  
  91.     {  
  92.         return Environment.getRootDirectory().getAbsolutePath();  
  93.     }  
  94.   
  95.   
  96. }  

6、屏幕相关辅助类 ScreenUtils

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.zhy.utils;  
  2.   
  3. import android.app.Activity;  
  4. import android.content.Context;  
  5. import android.graphics.Bitmap;  
  6. import android.graphics.Rect;  
  7. import android.util.DisplayMetrics;  
  8. import android.view.View;  
  9. import android.view.WindowManager;  
  10.   
  11. /** 
  12.  * 获得屏幕相关的辅助类 
  13.  *  
  14.  *  
  15.  *  
  16.  */  
  17. public class ScreenUtils  
  18. {  
  19.     private ScreenUtils()  
  20.     {  
  21.         /* cannot be instantiated */  
  22.         throw new UnsupportedOperationException("cannot be instantiated");  
  23.     }  
  24.   
  25.     /** 
  26.      * 获得屏幕高度 
  27.      *  
  28.      * @param context 
  29.      * @return 
  30.      */  
  31.     public static int getScreenWidth(Context context)  
  32.     {  
  33.         WindowManager wm = (WindowManager) context  
  34.                 .getSystemService(Context.WINDOW_SERVICE);  
  35.         DisplayMetrics outMetrics = new DisplayMetrics();  
  36.         wm.getDefaultDisplay().getMetrics(outMetrics);  
  37.         return outMetrics.widthPixels;  
  38.     }  
  39.   
  40.     /** 
  41.      * 获得屏幕宽度 
  42.      *  
  43.      * @param context 
  44.      * @return 
  45.      */  
  46.     public static int getScreenHeight(Context context)  
  47.     {  
  48.         WindowManager wm = (WindowManager) context  
  49.                 .getSystemService(Context.WINDOW_SERVICE);  
  50.         DisplayMetrics outMetrics = new DisplayMetrics();  
  51.         wm.getDefaultDisplay().getMetrics(outMetrics);  
  52.         return outMetrics.heightPixels;  
  53.     }  
  54.   
  55.     /** 
  56.      * 获得状态栏的高度 
  57.      *  
  58.      * @param context 
  59.      * @return 
  60.      */  
  61.     public static int getStatusHeight(Context context)  
  62.     {  
  63.   
  64.         int statusHeight = -1;  
  65.         try  
  66.         {  
  67.             Class<?> clazz = Class.forName("com.android.internal.R$dimen");  
  68.             Object object = clazz.newInstance();  
  69.             int height = Integer.parseInt(clazz.getField("status_bar_height")  
  70.                     .get(object).toString());  
  71.             statusHeight = context.getResources().getDimensionPixelSize(height);  
  72.         } catch (Exception e)  
  73.         {  
  74.             e.printStackTrace();  
  75.         }  
  76.         return statusHeight;  
  77.     }  
  78.   
  79.     /** 
  80.      * 获取当前屏幕截图,包含状态栏 
  81.      *  
  82.      * @param activity 
  83.      * @return 
  84.      */  
  85.     public static Bitmap snapShotWithStatusBar(Activity activity)  
  86.     {  
  87.         View view = activity.getWindow().getDecorView();  
  88.         view.setDrawingCacheEnabled(true);  
  89.         view.buildDrawingCache();  
  90.         Bitmap bmp = view.getDrawingCache();  
  91.         int width = getScreenWidth(activity);  
  92.         int height = getScreenHeight(activity);  
  93.         Bitmap bp = null;  
  94.         bp = Bitmap.createBitmap(bmp, 00, width, height);  
  95.         view.destroyDrawingCache();  
  96.         return bp;  
  97.   
  98.     }  
  99.   
  100.     /** 
  101.      * 获取当前屏幕截图,不包含状态栏 
  102.      *  
  103.      * @param activity 
  104.      * @return 
  105.      */  
  106.     public static Bitmap snapShotWithoutStatusBar(Activity activity)  
  107.     {  
  108.         View view = activity.getWindow().getDecorView();  
  109.         view.setDrawingCacheEnabled(true);  
  110.         view.buildDrawingCache();  
  111.         Bitmap bmp = view.getDrawingCache();  
  112.         Rect frame = new Rect();  
  113.         activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);  
  114.         int statusBarHeight = frame.top;  
  115.   
  116.         int width = getScreenWidth(activity);  
  117.         int height = getScreenHeight(activity);  
  118.         Bitmap bp = null;  
  119.         bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height  
  120.                 - statusBarHeight);  
  121.         view.destroyDrawingCache();  
  122.         return bp;  
  123.   
  124.     }  
  125.   
  126. }  

7、App相关辅助类

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.zhy.utils;  
  2.   
  3. import android.content.Context;  
  4. import android.content.pm.PackageInfo;  
  5. import android.content.pm.PackageManager;  
  6. import android.content.pm.PackageManager.NameNotFoundException;  
  7.   
  8. /** 
  9.  * 跟App相关的辅助类 
  10.  *  
  11.  *  
  12.  *  
  13.  */  
  14. public class AppUtils  
  15. {  
  16.   
  17.     private AppUtils()  
  18.     {  
  19.         /* cannot be instantiated */  
  20.         throw new UnsupportedOperationException("cannot be instantiated");  
  21.   
  22.     }  
  23.   
  24.     /** 
  25.      * 获取应用程序名称 
  26.      */  
  27.     public static String getAppName(Context context)  
  28.     {  
  29.         try  
  30.         {  
  31.             PackageManager packageManager = context.getPackageManager();  
  32.             PackageInfo packageInfo = packageManager.getPackageInfo(  
  33.                     context.getPackageName(), 0);  
  34.             int labelRes = packageInfo.applicationInfo.labelRes;  
  35.             return context.getResources().getString(labelRes);  
  36.         } catch (NameNotFoundException e)  
  37.         {  
  38.             e.printStackTrace();  
  39.         }  
  40.         return null;  
  41.     }  
  42.   
  43.     /** 
  44.      * [获取应用程序版本名称信息] 
  45.      *  
  46.      * @param context 
  47.      * @return 当前应用的版本名称 
  48.      */  
  49.     public static String getVersionName(Context context)  
  50.     {  
  51.         try  
  52.         {  
  53.             PackageManager packageManager = context.getPackageManager();  
  54.             PackageInfo packageInfo = packageManager.getPackageInfo(  
  55.                     context.getPackageName(), 0);  
  56.             return packageInfo.versionName;  
  57.   
  58.         } catch (NameNotFoundException e)  
  59.         {  
  60.             e.printStackTrace();  
  61.         }  
  62.         return null;  
  63.     }  
  64.   
  65. }  

8、软键盘相关辅助类KeyBoardUtils

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.zhy.utils;  
  2.   
  3. import android.content.Context;  
  4. import android.view.inputmethod.InputMethodManager;  
  5. import android.widget.EditText;  
  6.   
  7. /** 
  8.  * 打开或关闭软键盘 
  9.  *  
  10.  * @author zhy 
  11.  *  
  12.  */  
  13. public class KeyBoardUtils  
  14. {  
  15.     /** 
  16.      * 打卡软键盘 
  17.      *  
  18.      * @param mEditText 
  19.      *            输入框 
  20.      * @param mContext 
  21.      *            上下文 
  22.      */  
  23.     public static void openKeybord(EditText mEditText, Context mContext)  
  24.     {  
  25.         InputMethodManager imm = (InputMethodManager) mContext  
  26.                 .getSystemService(Context.INPUT_METHOD_SERVICE);  
  27.         imm.showSoftInput(mEditText, InputMethodManager.RESULT_SHOWN);  
  28.         imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,  
  29.                 InputMethodManager.HIDE_IMPLICIT_ONLY);  
  30.     }  
  31.   
  32.     /** 
  33.      * 关闭软键盘 
  34.      *  
  35.      * @param mEditText 
  36.      *            输入框 
  37.      * @param mContext 
  38.      *            上下文 
  39.      */  
  40.     public static void closeKeybord(EditText mEditText, Context mContext)  
  41.     {  
  42.         InputMethodManager imm = (InputMethodManager) mContext  
  43.                 .getSystemService(Context.INPUT_METHOD_SERVICE);  
  44.   
  45.         imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);  
  46.     }  
  47. }  

9、网络相关辅助类 NetUtils

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.zhy.utils;  
  2.   
  3. import android.app.Activity;  
  4. import android.content.ComponentName;  
  5. import android.content.Context;  
  6. import android.content.Intent;  
  7. import android.net.ConnectivityManager;  
  8. import android.net.NetworkInfo;  
  9.   
  10. /** 
  11.  * 跟网络相关的工具类 
  12.  *  
  13.  *  
  14.  *  
  15.  */  
  16. public class NetUtils  
  17. {  
  18.     private NetUtils()  
  19.     {  
  20.         /* cannot be instantiated */  
  21.         throw new UnsupportedOperationException("cannot be instantiated");  
  22.     }  
  23.   
  24.     /** 
  25.      * 判断网络是否连接 
  26.      *  
  27.      * @param context 
  28.      * @return 
  29.      */  
  30.     public static boolean isConnected(Context context)  
  31.     {  
  32.   
  33.         ConnectivityManager connectivity = (ConnectivityManager) context  
  34.                 .getSystemService(Context.CONNECTIVITY_SERVICE);  
  35.   
  36.         if (null != connectivity)  
  37.         {  
  38.   
  39.             NetworkInfo info = connectivity.getActiveNetworkInfo();  
  40.             if (null != info && info.isConnected())  
  41.             {  
  42.                 if (info.getState() == NetworkInfo.State.CONNECTED)  
  43.                 {  
  44.                     return true;  
  45.                 }  
  46.             }  
  47.         }  
  48.         return false;  
  49.     }  
  50.   
  51.     /** 
  52.      * 判断是否是wifi连接 
  53.      */  
  54.     public static boolean isWifi(Context context)  
  55.     {  
  56.         ConnectivityManager cm = (ConnectivityManager) context  
  57.                 .getSystemService(Context.CONNECTIVITY_SERVICE);  
  58.   
  59.         if (cm == null)  
  60.             return false;  
  61.         return cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI;  
  62.   
  63.     }  
  64.   
  65.     /** 
  66.      * 打开网络设置界面 
  67.      */  
  68.     public static void openSetting(Activity activity)  
  69.     {  
  70.         Intent intent = new Intent("/");  
  71.         ComponentName cm = new ComponentName("com.android.settings",  
  72.                 "com.android.settings.WirelessSettings");  
  73.         intent.setComponent(cm);  
  74.         intent.setAction("android.intent.action.VIEW");  
  75.         activity.startActivityForResult(intent, 0);  
  76.     }  
  77.   
  78. }  


10、Http相关辅助类 HttpUtils

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.zhy.utils;  
  2.   
  3. import java.io.BufferedReader;  
  4. import java.io.ByteArrayOutputStream;  
  5. import java.io.IOException;  
  6. import java.io.InputStream;  
  7. import java.io.InputStreamReader;  
  8. import java.io.PrintWriter;  
  9. import java.net.HttpURLConnection;  
  10. import java.net.URL;  
  11.   
  12. /** 
  13.  * Http请求的工具类 
  14.  *  
  15.  * @author zhy 
  16.  *  
  17.  */  
  18. public class HttpUtils  
  19. {  
  20.   
  21.     private static final int TIMEOUT_IN_MILLIONS = 5000;  
  22.   
  23.     public interface CallBack  
  24.     {  
  25.         void onRequestComplete(String result);  
  26.     }  
  27.   
  28.   
  29.     /** 
  30.      * 异步的Get请求 
  31.      *  
  32.      * @param urlStr 
  33.      * @param callBack 
  34.      */  
  35.     public static void doGetAsyn(final String urlStr, final CallBack callBack)  
  36.     {  
  37.         new Thread()  
  38.         {  
  39.             public void run()  
  40.             {  
  41.                 try  
  42.                 {  
  43.                     String result = doGet(urlStr);  
  44.                     if (callBack != null)  
  45.                     {  
  46.                         callBack.onRequestComplete(result);  
  47.                     }  
  48.                 } catch (Exception e)  
  49.                 {  
  50.                     e.printStackTrace();  
  51.                 }  
  52.   
  53.             };  
  54.         }.start();  
  55.     }  
  56.   
  57.     /** 
  58.      * 异步的Post请求 
  59.      * @param urlStr 
  60.      * @param params 
  61.      * @param callBack 
  62.      * @throws Exception 
  63.      */  
  64.     public static void doPostAsyn(final String urlStr, final String params,  
  65.             final CallBack callBack) throws Exception  
  66.     {  
  67.         new Thread()  
  68.         {  
  69.             public void run()  
  70.             {  
  71.                 try  
  72.                 {  
  73.                     String result = doPost(urlStr, params);  
  74.                     if (callBack != null)  
  75.                     {  
  76.                         callBack.onRequestComplete(result);  
  77.                     }  
  78.                 } catch (Exception e)  
  79.                 {  
  80.                     e.printStackTrace();  
  81.                 }  
  82.   
  83.             };  
  84.         }.start();  
  85.   
  86.     }  
  87.   
  88.     /** 
  89.      * Get请求,获得返回数据 
  90.      *  
  91.      * @param urlStr 
  92.      * @return 
  93.      * @throws Exception 
  94.      */  
  95.     public static String doGet(String urlStr)   
  96.     {  
  97.         URL url = null;  
  98.         HttpURLConnection conn = null;  
  99.         InputStream is = null;  
  100.         ByteArrayOutputStream baos = null;  
  101.         try  
  102.         {  
  103.             url = new URL(urlStr);  
  104.             conn = (HttpURLConnection) url.openConnection();  
  105.             conn.setReadTimeout(TIMEOUT_IN_MILLIONS);  
  106.             conn.setConnectTimeout(TIMEOUT_IN_MILLIONS);  
  107.             conn.setRequestMethod("GET");  
  108.             conn.setRequestProperty("accept""*/*");  
  109.             conn.setRequestProperty("connection""Keep-Alive");  
  110.             if (conn.getResponseCode() == 200)  
  111.             {  
  112.                 is = conn.getInputStream();  
  113.                 baos = new ByteArrayOutputStream();  
  114.                 int len = -1;  
  115.                 byte[] buf = new byte[128];  
  116.   
  117.                 while ((len = is.read(buf)) != -1)  
  118.                 {  
  119.                     baos.write(buf, 0, len);  
  120.                 }  
  121.                 baos.flush();  
  122.                 return baos.toString();  
  123.             } else  
  124.             {  
  125.                 throw new RuntimeException(" responseCode is not 200 ... ");  
  126.             }  
  127.   
  128.         } catch (Exception e)  
  129.         {  
  130.             e.printStackTrace();  
  131.         } finally  
  132.         {  
  133.             try  
  134.             {  
  135.                 if (is != null)  
  136.                     is.close();  
  137.             } catch (IOException e)  
  138.             {  
  139.             }  
  140.             try  
  141.             {  
  142.                 if (baos != null)  
  143.                     baos.close();  
  144.             } catch (IOException e)  
  145.             {  
  146.             }  
  147.             conn.disconnect();  
  148.         }  
  149.           
  150.         return null ;  
  151.   
  152.     }  
  153.   
  154.     /**  
  155.      * 向指定 URL 发送POST方法的请求  
  156.      *   
  157.      * @param url  
  158.      *            发送请求的 URL  
  159.      * @param param  
  160.      *            请求参数,请求参数应该是 name1=value1&name2=value2 的形式。  
  161.      * @return 所代表远程资源的响应结果  
  162.      * @throws Exception  
  163.      */  
  164.     public static String doPost(String url, String param)   
  165.     {  
  166.         PrintWriter out = null;  
  167.         BufferedReader in = null;  
  168.         String result = "";  
  169.         try  
  170.         {  
  171.             URL realUrl = new URL(url);  
  172.             // 打开和URL之间的连接  
  173.             HttpURLConnection conn = (HttpURLConnection) realUrl  
  174.                     .openConnection();  
  175.             // 设置通用的请求属性  
  176.             conn.setRequestProperty("accept""*/*");  
  177.             conn.setRequestProperty("connection""Keep-Alive");  
  178.             conn.setRequestMethod("POST");  
  179.             conn.setRequestProperty("Content-Type",  
  180.                     "application/x-www-form-urlencoded");  
  181.             conn.setRequestProperty("charset""utf-8");  
  182.             conn.setUseCaches(false);  
  183.             // 发送POST请求必须设置如下两行  
  184.             conn.setDoOutput(true);  
  185.             conn.setDoInput(true);  
  186.             conn.setReadTimeout(TIMEOUT_IN_MILLIONS);  
  187.             conn.setConnectTimeout(TIMEOUT_IN_MILLIONS);  
  188.   
  189.             if (param != null && !param.trim().equals(""))  
  190.             {  
  191.                 // 获取URLConnection对象对应的输出流  
  192.                 out = new PrintWriter(conn.getOutputStream());  
  193.                 // 发送请求参数  
  194.                 out.print(param);  
  195.                 // flush输出流的缓冲  
  196.                 out.flush();  
  197.             }  
  198.             // 定义BufferedReader输入流来读取URL的响应  
  199.             in = new BufferedReader(  
  200.                     new InputStreamReader(conn.getInputStream()));  
  201.             String line;  
  202.             while ((line = in.readLine()) != null)  
  203.             {  
  204.                 result += line;  
  205.             }  
  206.         } catch (Exception e)  
  207.         {  
  208.             e.printStackTrace();  
  209.         }  
  210.         // 使用finally块来关闭输出流、输入流  
  211.         finally  
  212.         {  
  213.             try  
  214.             {  
  215.                 if (out != null)  
  216.                 {  
  217.                     out.close();  
  218.                 }  
  219.                 if (in != null)  
  220.                 {  
  221.                     in.close();  
  222.                 }  
  223.             } catch (IOException ex)  
  224.             {  
  225.                 ex.printStackTrace();  
  226.             }  
  227.         }  
  228.         return result;  
  229.     }  
  230. }  

如果大家在使用过程中出现什么错误,或者有更好的建议,欢迎大家留言提出~~可以不断的改进这些类~


源码点击下载


11. Android 进度提示圆圈

protected AlertDialog mProgressDialog;
 public void showDialog(){
  
  mProgressDialog = createProgressDialog(this);
  if((mProgressDialog != null) && !mProgressDialog.isShowing()){
   
   try{
    mProgressDialog.show();
    LayoutInflater inflater = LayoutInflater.from(this);
    View v = inflater.inflate(R.layout.xct_lthj_layout_dialog_progressbar,null);
    Window window = mProgressDialog.getWindow();
    WindowManager.LayoutParams lp = window.getAttributes();
    // 设置透明度为0.3
    lp.alpha = 1.0f;
    // 设置暗色度
    lp.dimAmount = 0.0f;
    lp.gravity = Gravity.CENTER;
    window.setAttributes(lp);
    window.setContentView(v);
    mProgressDialog.setOnKeyListener(MyKeyListener);
   }catch(BadTokenException e){
    // TODO check WHY!
    e.printStackTrace();
   }
  }  
 }
 public OnKeyListener MyKeyListener = new OnKeyListener() {
  @Override
  public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_SEARCH) {
    return true;
   }
   return false;
  }
 };
 
 
 protected AlertDialog createProgressDialog(Context pContext) {
  AlertDialog.Builder builder = new AlertDialog.Builder(pContext);
  final AlertDialog progressDialog = builder.create();
  progressDialog.setCanceledOnTouchOutside(false);
  return progressDialog;
 }
 public void closeDialog(){
  if(mProgressDialog != null && mProgressDialog.isShowing()){
   mProgressDialog.dismiss();
  }
 }


12、Toast工具类2

package com.zftlive.android.tools;


import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Handler;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

import com.zftlive.android.MApplication;

/**
 * 自定义Toast控件
 * @author 曾繁添
 * @version 1.0
 */
public class ToolToast {
	
	private static Toast mToast;
	private static Handler mHandler = new Handler();
	private static Runnable r = new Runnable() {
		public void run() {
			mToast.cancel();
		}
	}; 
	
	/**
	 * 弹出较长时间提示信息
	 * @param context 上下文对象
	 * @param msg 要显示的信息
	 */
	public static void showLong(Context context, String msg){
		buildToast(context,msg,Toast.LENGTH_LONG).show();
	}
	
	/**
	 * 弹出较长时间提示信息
	 * @param msg 要显示的信息
	 */
	public static void showLong(String msg){
		buildToast(MApplication.gainContext(),msg,Toast.LENGTH_LONG).show();
	}
	
	/**
	 * 弹出较短时间提示信息
	 * @param context 上下文对象
	 * @param msg 要显示的信息
	 */
	public static void showShort(Context context, String msg){
		buildToast(context,msg,Toast.LENGTH_SHORT).show();
	}
	
	/**
	 * 弹出较短时间提示信息
	 * @param msg 要显示的信息
	 */
	public static void showShort(String msg){
		buildToast(MApplication.gainContext(),msg,Toast.LENGTH_SHORT).show();
	}
	
	/**
	 * 构造Toast
	 * @param context 上下文
	 * @return
	 */
	private static Toast buildToast(Context context,String msg,int duration){
		return buildToast(context,msg,duration,"#000000",16);
	}
	

	/**
	 * 构造Toast
	 * @param context 上下文
	 * @param msg 消息
	 * @param duration 显示时间
	 * @param bgColor 背景颜色
	 * @return
	 */
	public static Toast buildToast(Context context,String msg,int duration,String bgColor){
		return buildToast(context,msg,duration,bgColor,16);
	}
	
	
	/**
	 * 构造Toast
	 * @param context 上下文
	 * @param msg	消息
	 * @param duration 显示时间
	 * @param bgColor 背景颜色
	 * @param textSp  文字大小
	 * @return
	 */
	public static Toast buildToast(Context context,String msg,int duration,String bgColor,int textSp){
		return buildToast(context,msg,duration,bgColor,textSp,10);
	}
	
	/**
	 * 构造Toast
	 * @param context 上下文
	 * @param msg	消息
	 * @param duration 显示时间
	 * @param bgColor 背景颜色
	 * @param textSp  文字大小
	 * @param cornerRadius  四边圆角弧度
	 * @return
	 */
	public static Toast buildToast(Context context,String msg,int duration,String bgColor,int textSp,int cornerRadius){
		mHandler.removeCallbacks(r);
		
		if(null == mToast){
			//构建Toast
			mToast = Toast.makeText(context, null, duration);
			mToast.setGravity(Gravity.CENTER, 0, 0);
			//取消toast
			mHandler.postDelayed(r, duration);
		}
		
		//设置Toast文字
		TextView tv = new TextView(context);
		int dpPadding = ToolUnit.dipTopx(10);
		tv.setPadding(dpPadding, dpPadding, dpPadding, dpPadding);
		tv.setGravity(Gravity.CENTER);
		tv.setText(msg);
		tv.setTextColor(Color.WHITE);
		tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSp);
		
		//Toast文字TextView容器
        LinearLayout mLayout = new LinearLayout(context);
        GradientDrawable shape = new GradientDrawable();
	    shape.setColor(Color.parseColor(bgColor));
	    shape.setCornerRadius(cornerRadius);
	    shape.setStroke(1, Color.parseColor(bgColor));
	    shape.setAlpha(180);
        mLayout.setBackground(shape);
        mLayout.setOrientation(LinearLayout.VERTICAL);
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);  
		//设置layout_gravity
		params.gravity = Gravity.CENTER;  
		mLayout.setLayoutParams(params);
	    //设置gravity
		mLayout.setGravity(Gravity.CENTER);
        mLayout.addView(tv);
        
        //将自定义View覆盖Toast的View
        mToast.setView(mLayout);
        
		return mToast;
	}
}

13、图片工具类

package com.zftlive.android.tools;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.NinePatchDrawable;
import android.media.ExifInterface;
import android.view.View;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.zftlive.android.config.SysEnv;

/**
 * 图片工具类
 * @author 曾繁添
 * @version 1.0
 */
public class ToolPicture {
	
	/**
	 * 截取应用程序界面(去除状态栏)
	 * @param activity 界面Activity
	 * @return Bitmap对象
	 */
	public static Bitmap takeScreenShot(Activity activity){  
        View view =activity.getWindow().getDecorView();  
        view.setDrawingCacheEnabled(true);  
        view.buildDrawingCache();  
        Bitmap bitmap = view.getDrawingCache();  
        Rect rect = new Rect();  
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);  
        int statusBarHeight = rect.top;  
          
        /**
         * 
         *WindowManager windowMgr = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
		  windowMgr.getDefaultDisplay().getMetrics(mDisplayMetrics);
		  return mDisplayMetrics;
         */
        
        
        Bitmap bitmap2 = Bitmap.createBitmap(bitmap,0,statusBarHeight, SysEnv.SCREEN_WIDTH, SysEnv.SCREEN_HEIGHT - statusBarHeight);  
        view.destroyDrawingCache();  
        return bitmap2;  
    }
	
	/**
	 * 截取应用程序界面
	 * @param activity 界面Activity
	 * @return Bitmap对象
	 */
	public static Bitmap takeFullScreenShot(Activity activity){  
		
		activity.getWindow().getDecorView().setDrawingCacheEnabled(true);

		Bitmap bmp = activity.getWindow().getDecorView().getDrawingCache();
		
		
		View view = activity.getWindow().getDecorView();

		Bitmap bmp2 = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888);

		//view.draw(new Canvas(bmp2));

		//bmp就是截取的图片了,可通过bmp.compress(CompressFormat.PNG, 100, new FileOutputStream(file));把图片保存为文件。
		
		//1、得到状态栏高度
		Rect rect = new Rect();
		view.getWindowVisibleDisplayFrame(rect);
		int statusBarHeight = rect.top;
		System.out.println("状态栏高度:" + statusBarHeight);
		
		//2、得到标题栏高度
		int wintop = activity.getWindow().findViewById(android.R.id.content).getTop();
		int titleBarHeight = wintop - statusBarHeight;
		System.out.println("标题栏高度:" + titleBarHeight);
		
//		//把两个bitmap合到一起
//		Bitmap bmpall=Biatmap.createBitmap(width,height,Config.ARGB_8888);
//		Canvas canvas=new Canvas(bmpall);
//		canvas.drawBitmap(bmp1,x,y,paint);
//		canvas.drawBitmap(bmp2,x,y,paint);
		
        return bmp;  
    }
	
	/**
	 * 根据指定内容生成自定义宽高的二维码图片 
	 * @param content 需要生成二维码的内容
	 * @param width 二维码宽度
	 * @param height 二维码高度
	 * @throws WriterException 生成二维码异常
	 */
	public static Bitmap makeQRImage(String content, int width, int height)
			throws WriterException {
		// 判断URL合法性
		if (!ToolString.isNoBlankAndNoNull(content))
			return null;

		Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
		hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
		// 图像数据转换,使用了矩阵转换
		BitMatrix bitMatrix = new QRCodeWriter().encode(content,
				BarcodeFormat.QR_CODE, width, height, hints);
		int[] pixels = new int[width * height];
		// 按照二维码的算法,逐个生成二维码的图片,两个for循环是图片横列扫描的结果
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				if (bitMatrix.get(x, y))
					pixels[y * width + x] = 0xff000000;
				else
					pixels[y * width + x] = 0xffffffff;
			}
		}
		// 生成二维码图片的格式,使用ARGB_8888
		Bitmap bitmap = Bitmap.createBitmap(width, height,
				Bitmap.Config.ARGB_8888);
		bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
		
		return bitmap;
	}
	
	/**
	 * 读取图片属性:旋转的角度
	 * 
	 * @param path 图片绝对路径
	 * @return degree 旋转的角度
	 * @throws IOException
	 */
	public static int gainPictureDegree(String path) throws Exception {
		int degree = 0;
		try {
			ExifInterface exifInterface = new ExifInterface(path);
			int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL);
			switch (orientation) {
				case ExifInterface.ORIENTATION_ROTATE_90:
					degree = 90;
					break;
				case ExifInterface.ORIENTATION_ROTATE_180:
					degree = 180;
					break;
				case ExifInterface.ORIENTATION_ROTATE_270:
					degree = 270;
					break;
			}
		} catch (Exception e) {
			throw(e);
		}
		
		return degree;
	}
	
    /**
     * 旋转图片 
     * @param angle 角度
     * @param bitmap 源bitmap
     * @return Bitmap 旋转角度之后的bitmap
     */  
    public static Bitmap rotaingBitmap(int angle,Bitmap bitmap) {  
        //旋转图片 动作   
        Matrix matrix = new Matrix();;  
        matrix.postRotate(angle);  
        //重新构建Bitmap
        Bitmap resizedBitmap = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix, true);  
        return resizedBitmap;  
    }
    
    /**
     * Drawable转成Bitmap 
     * @param drawable
     * @return
     */
    public static Bitmap drawableToBitmap(Drawable drawable) {
        if (drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        } else if (drawable instanceof NinePatchDrawable) {
            Bitmap bitmap = Bitmap
                    .createBitmap(
                            drawable.getIntrinsicWidth(),
                            drawable.getIntrinsicHeight(),
                            drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
                                    : Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(bitmap);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
                    drawable.getIntrinsicHeight());
            drawable.draw(canvas);
            return bitmap;
        } else {
            return null;
        }
    }
    
    /**
     * 从资源文件中获取图片
     * @param context 上下文
     * @param drawableId 资源文件id
     * @return
     */
    public static Bitmap gainBitmap(Context context,int drawableId){
        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), drawableId);
        return bmp;
    }
    
    /**
     * 灰白图片(去色)
     * @param bitmap 需要灰度的图片
     * @return 去色之后的图片
     */
    public static Bitmap toBlack(Bitmap bitmap) {
        Bitmap resultBMP = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(),
                Bitmap.Config.RGB_565);
        Canvas c = new Canvas(resultBMP);
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
        paint.setColorFilter(f);
        c.drawBitmap(bitmap, 0, 0, paint);
        return resultBMP;
    }
    
    /**
     * 将bitmap转成 byte数组
     * 
     * @param bitmap
     * @return
     */
    public static byte[] toBtyeArray(Bitmap bitmap) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
        return baos.toByteArray();
    }
    
    /**
     * 将byte数组转成 bitmap
     * 
     * @param b
     * @return
     */
    public static Bitmap bytesToBimap(byte[] b) {
        if (b.length != 0) {
            return BitmapFactory.decodeByteArray(b, 0, b.length);
        } else {
            return null;
        }
    }
    
    /**
     * 将Bitmap转换成指定大小
     * 
     * @param bitmap 需要改变大小的图片
     * @param width 宽
     * @param height 高
     * @return
     */
    public static Bitmap createBitmapBySize(Bitmap bitmap, int width, int height) {
        return Bitmap.createScaledBitmap(bitmap, width, height, true);
    }
    
    
    /**
     * 在图片右下角添加水印
     * @param srcBMP 原图
     * @param markBMP 水印图片
     * @return 合成水印后的图片
     */
    public static Bitmap composeWatermark(Bitmap srcBMP, Bitmap markBMP) {
        if (srcBMP == null) {
            return null;
        }
        
        // 创建一个新的和SRC长度宽度一样的位图
        Bitmap newb = Bitmap.createBitmap(srcBMP.getWidth(), srcBMP.getHeight(), Config.ARGB_8888);
        Canvas cv = new Canvas(newb);
        // 在 0,0坐标开始画入原图
        cv.drawBitmap(srcBMP, 0, 0, null);
        // 在原图的右下角画入水印
        cv.drawBitmap(markBMP, srcBMP.getWidth() - markBMP.getWidth() + 5, srcBMP.getHeight() - markBMP.getHeight() + 5, null);
        // 保存
        cv.save(Canvas.ALL_SAVE_FLAG);
        // 存储
        cv.restore();
        
        return newb;
    }
    
    /**
     * 将图片转成指定弧度(角度)的图片
     * 
     * @param bitmap 需要修改的图片
     * @param pixels 圆角的弧度
     * @return 圆角图片
     */
    public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
        //根据图片创建画布
        Canvas canvas = new Canvas(output);
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(rect);
        final float roundPx = pixels;
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(0xff424242);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
        return output;
    }
    
	/**
	 * 缩放图片
	 * 
	 * @param bmp 需要缩放的图片源
	 * @param newW 需要缩放成的图片宽度
	 * @param newH 需要缩放成的图片高度
	 * @return 缩放后的图片
	 */
	public static Bitmap zoom(Bitmap bmp, int newW, int newH) {
		
		// 获得图片的宽高
		int width = bmp.getWidth();
		int height = bmp.getHeight();
		
		// 计算缩放比例
		float scaleWidth = ((float) newW) / width;
		float scaleHeight = ((float) newH) / height;
		
		// 取得想要缩放的matrix参数
		Matrix matrix = new Matrix();
		matrix.postScale(scaleWidth, scaleHeight);
		
		// 得到新的图片
		Bitmap newbm = Bitmap.createBitmap(bmp, 0, 0, width, height, matrix,true);
		
		return newbm;
	}
    
	/**
	 * 获得倒影的图片
	 * @param bitmap 原始图片
	 * @return 带倒影的图片
	 */
	public static Bitmap makeReflectionImage(Bitmap bitmap){  
        final int reflectionGap = 4;  
        int width = bitmap.getWidth();  
        int height = bitmap.getHeight();  
          
        Matrix matrix = new Matrix();  
        matrix.preScale(1, -1);  
        
        Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height/2, width, height/2, matrix, false);  
        Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height/2), Config.ARGB_8888);  
          
        Paint deafalutPaint = new Paint();  
        Canvas canvas = new Canvas(bitmapWithReflection);  
        canvas.drawBitmap(bitmap, 0, 0, null);  
        canvas.drawRect(0, height,width,height + reflectionGap, deafalutPaint);  
        canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);  
          
        Paint paint = new Paint();  
        LinearGradient shader = new LinearGradient(0,bitmap.getHeight(),0,bitmapWithReflection.getHeight()+reflectionGap,0x70ffffff,0x00ffffff,TileMode.CLAMP);  
        paint.setShader(shader);  
        paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));  
        canvas.drawRect(0,height,width,bitmapWithReflection.getHeight()+reflectionGap,paint);  
   
        return bitmapWithReflection;  
    }  
	
	/**
	 * 获取验证码图片
	 * @param width 验证码宽度
	 * @param height 验证码高度
	 * @return 验证码Bitmap对象
	 */
	public synchronized static Bitmap makeValidateCode(int width, int height){
		return ValidateCodeGenerator.createBitmap(width, height);
	}
	
	/**
	 * 获取验证码值
	 * @return 验证码字符串
	 */
	public synchronized static String gainValidateCodeValue(){
		return ValidateCodeGenerator.getCode();
	}
    
    /**
     * 随机生成验证码内部类
     *
     */
    final static class ValidateCodeGenerator{
    	private static final char[] CHARS = {
    		'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    		'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 
    		'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
    		'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 
    		'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
    	};
    	
    	//default settings
    	private static final int DEFAULT_CODE_LENGTH = 4;
    	private static final int DEFAULT_FONT_SIZE = 20;
    	private static final int DEFAULT_LINE_NUMBER = 3;
    	private static final int BASE_PADDING_LEFT = 5, RANGE_PADDING_LEFT = 10, BASE_PADDING_TOP = 15, RANGE_PADDING_TOP = 10;
    	private static final int DEFAULT_WIDTH = 60, DEFAULT_HEIGHT = 30;
    	
    	//variables
    	private static String value;
    	private static int padding_left, padding_top;
    	private static Random random = new Random();
    	
    	public static Bitmap createBitmap(int width,int height) {
    		padding_left = 0;
    		//创建画布
    		Bitmap bp = Bitmap.createBitmap(width, height, Config.ARGB_8888); 
    		Canvas c = new Canvas(bp);

    		//随机生成验证码字符
    		StringBuilder buffer = new StringBuilder();
    		for (int i = 0; i < DEFAULT_CODE_LENGTH; i++) {
    			buffer.append(CHARS[random.nextInt(CHARS.length)]);
    		}
    		value = buffer.toString();
    		
    		//设置颜色
    		c.drawColor(Color.WHITE);
    		
    		//设置画笔大小
    		Paint paint = new Paint();
    		paint.setTextSize(DEFAULT_FONT_SIZE);
    		for (int i = 0; i < value.length(); i++) {
    			//随机样式
    			randomTextStyle(paint);
        		padding_left += BASE_PADDING_LEFT + random.nextInt(RANGE_PADDING_LEFT);
        		padding_top = BASE_PADDING_TOP + random.nextInt(RANGE_PADDING_TOP);
    			c.drawText(value.charAt(i) + "", padding_left, padding_top, paint);
    		}
    		for (int i = 0; i < DEFAULT_LINE_NUMBER; i++) {
    			drawLine(c, paint);
    		}
    		//保存  
    		c.save(Canvas.ALL_SAVE_FLAG);
    		c.restore();
    		
    		return bp;
    	}
    	
    	public static String getCode() {
    		return value;
    	}
    	
    	private static void randomTextStyle(Paint paint) {
    		int color = randomColor(1);
    		paint.setColor(color);
    		paint.setFakeBoldText(random.nextBoolean());//true为粗体,false为非粗体
    		float skewX = random.nextInt(11) / 10;
    		skewX = random.nextBoolean() ? skewX : -skewX;
    		paint.setTextSkewX(skewX); //float类型参数,负数表示右斜,整数左斜
    		paint.setUnderlineText(true); //true为下划线,false为非下划线
    		paint.setStrikeThruText(true); //true为删除线,false为非删除线
    	}
    	
    	private static void drawLine(Canvas canvas, Paint paint) {
    		int color = randomColor(1);
    		int startX = random.nextInt(DEFAULT_WIDTH);
    		int startY = random.nextInt(DEFAULT_HEIGHT);
    		int stopX = random.nextInt(DEFAULT_WIDTH);
    		int stopY = random.nextInt(DEFAULT_HEIGHT);
    		paint.setStrokeWidth(1);
    		paint.setColor(color);
    		canvas.drawLine(startX, startY, stopX, stopY, paint);
    	}
    	
    	private static int randomColor(int rate) {
    		int red = random.nextInt(256) / rate;
    		int green = random.nextInt(256) / rate;
    		int blue = random.nextInt(256) / rate;
    		return Color.rgb(red, green, blue);
    	}
    }
}

14、Properties文件 工具类

package com.zftlive.android.tools;

import java.io.InputStream;
import java.util.Properties;

import android.content.Context;

import com.zftlive.android.MApplication;

/**
 * 配置文件工具类
 * 
 * @author 曾繁添
 * @version 1.0
 * 
 */
public final class ToolProperties extends Properties {

	private static Properties property = new Properties();

	public static String readAssetsProp(String fileName, String key) {
		String value = "";
		try {
			InputStream in = MApplication.gainContext().getAssets().open(fileName);
			property.load(in);
			value = property.getProperty(key);
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		return value;
	}
	
	public static String readAssetsProp(Context context,String fileName, String key) {
		String value = "";
		try {
			InputStream in = context.getAssets().open(fileName);
			property.load(in);
			value = property.getProperty(key);
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		return value;
	}

	public static String readAssetsProp(String fileName, String key,String defaultValue) {
		String value = "";
		try {
			InputStream in = MApplication.gainContext().getAssets().open(fileName);
			property.load(in);
			value = property.getProperty(key, defaultValue);
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		return value;
	}
	
	public static String readAssetsProp(Context context,String fileName, String key,String defaultValue) {
		String value = "";
		try {
			InputStream in = context.getAssets().open(fileName);
			property.load(in);
			value = property.getProperty(key, defaultValue);
		} catch (Exception e1) {
			e1.printStackTrace();
		}

		return value;
	}
}

15、网络工具类2:network

package com.zftlive.android.tools;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.provider.Settings;
import android.util.Log;

/**
 * 基于静态内部类实现的单例,保证线程安全的网络信息工具类 <per> 使用该工具类之前,记得在AndroidManifest.xml添加权限许可 <xmp>
 * <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 * </xmp> </per>
 * 
 * 安卓判断网络状态,只需要在相应的Activity的相关方法(onCreat/onResum)调用一行代码即可
 * NetWorkUtils.getInstance(getActivity()).validateNetWork();
 * 
 * @author 曾繁添
 * @version 1.0
 */
public class ToolNetwork {

	public final static String NETWORK_CMNET = "CMNET";
	public final static String NETWORK_CMWAP = "CMWAP";
	public final static String NETWORK_WIFI = "WIFI";
	public final static String TAG = "ToolNetwork";
	private static NetworkInfo networkInfo = null;
	private Context mContext = null;

	private ToolNetwork() {
	}

	public static ToolNetwork getInstance() {
		return SingletonHolder.instance;
	}

	public ToolNetwork init(Context context){
		this.mContext = context;
		return this;
	}
	
	/**
	 * 判断网络是否可用
	 * 
	 * @return 是/否
	 */
	public boolean isAvailable() {
		ConnectivityManager manager = (ConnectivityManager) mContext
				.getApplicationContext().getSystemService(
						Context.CONNECTIVITY_SERVICE);
		if (null == manager) {
			return false;
		}
		networkInfo = manager.getActiveNetworkInfo();
		if (null == networkInfo || !networkInfo.isAvailable()) {
			return false;
		}
		return true;
	}

	/**
	 * 判断网络是否已连接
	 * 
	 * @return 是/否
	 */
	public boolean isConnected() {
		if (!isAvailable()) {
			return false;
		}
		if (!networkInfo.isConnected()) {
			return false;
		}
		return true;
	}

	/**
	 * 检查当前环境网络是否可用,不可用跳转至开启网络界面,不设置网络强制关闭当前Activity
	 */
	public void validateNetWork() {

		if (!isConnected()) {
			Builder dialogBuilder = new AlertDialog.Builder(mContext);
			dialogBuilder.setTitle("网络设置");
			dialogBuilder.setMessage("网络不可用,是否现在设置网络?");
			dialogBuilder.setPositiveButton(android.R.string.ok,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							((Activity) mContext).startActivityForResult(
									new Intent(
											Settings.ACTION_SETTINGS),
									which);
						}
					});
			dialogBuilder.setNegativeButton(android.R.string.cancel,
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							dialog.cancel();
						}
					});
			dialogBuilder.create();
			dialogBuilder.show();
		}
	}

	/**
	 * 获取网络连接信息</br> 无网络:</br> WIFI网络:WIFI</br> WAP网络:CMWAP</br>
	 * NET网络:CMNET</br>
	 * 
	 * @return
	 */
	public String getNetworkType() {
		if (isConnected()) {
			int type = networkInfo.getType();
			if (ConnectivityManager.TYPE_MOBILE == type) {
				Log.i(TAG,
						"networkInfo.getExtraInfo()-->"
								+ networkInfo.getExtraInfo());
				if (NETWORK_CMWAP.equals(networkInfo.getExtraInfo()
						.toLowerCase())) {
					return NETWORK_CMWAP;
				} else {
					return NETWORK_CMNET;
				}
			} else if (ConnectivityManager.TYPE_WIFI == type) {
				return NETWORK_WIFI;
			}
		}

		return "";
	}

	private static class SingletonHolder {

		private static ToolNetwork instance = new ToolNetwork();
	}
}

16、调用系统服务(打电话,发短信,获取相册,调用浏览器。。。)

package com.zftlive.android.tools;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.MediaStore;
import android.provider.Settings;
import android.telephony.PhoneNumberUtils;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.Toast;

/**
 * 手机相关操作API
 * @author 曾繁添
 * @version 1.0
 *
 */
public class ToolPhone {
	
	/**
	 * 直接呼叫指定的号码(需要<uses-permission android:name="android.permission.CALL_PHONE"/>权限)
	 * @param mContext 上下文Context
	 * @param phoneNumber 需要呼叫的手机号码
	 */
	public static void callPhone(Context mContext,String phoneNumber){
		Uri uri = Uri.parse("tel:" + phoneNumber);
		Intent call = new Intent(Intent.ACTION_CALL, uri);
		mContext.startActivity(call);
	}
	
	/**
	 * 跳转至拨号界面
	 * @param mContext 上下文Context
	 * @param phoneNumber 需要呼叫的手机号码
	 */
	public static void toCallPhoneActivity(Context mContext,String phoneNumber){
		Uri uri = Uri.parse("tel:" + phoneNumber);
		Intent call = new Intent(Intent.ACTION_DIAL, uri);
		mContext.startActivity(call);
	}
	
	/**
	 * 直接调用短信API发送信息(设置监听发送和接收状态)
	 * @param strPhone 手机号码
	 * @param strMsgContext 短信内容
	 */
	public static void sendMessage(final Context mContext,final String strPhone,final String strMsgContext){
		
		//处理返回的发送状态 
		String SENT_SMS_ACTION = "SENT_SMS_ACTION";
		Intent sentIntent = new Intent(SENT_SMS_ACTION);
		PendingIntent sendIntent= PendingIntent.getBroadcast(mContext, 0, sentIntent,0);
		// register the Broadcast Receivers
		mContext.registerReceiver(new BroadcastReceiver() {
		    @Override
		    public void onReceive(Context _context, Intent _intent) {
		        switch (getResultCode()) {
		        case Activity.RESULT_OK:
		            Toast.makeText(mContext,"短信发送成功", Toast.LENGTH_SHORT).show();
		            break;
		        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
		        	break;
		        case SmsManager.RESULT_ERROR_RADIO_OFF:
		        	break;
		        case SmsManager.RESULT_ERROR_NULL_PDU:
		        	break;
		        }
		    }
		}, new IntentFilter(SENT_SMS_ACTION));
		
		//处理返回的接收状态 
		String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION";
		// create the deilverIntent parameter
		Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION);
		PendingIntent backIntent= PendingIntent.getBroadcast(mContext, 0,deliverIntent, 0);
		mContext.registerReceiver(new BroadcastReceiver() {
				   @Override
				   public void onReceive(Context _context, Intent _intent) {
				       Toast.makeText(mContext,strPhone+"已经成功接收", Toast.LENGTH_SHORT).show();
				   }
				}, 
				new IntentFilter(DELIVERED_SMS_ACTION)
		);
		
		//拆分短信内容(手机短信长度限制)
		SmsManager smsManager = SmsManager.getDefault();
		ArrayList<String> msgList = smsManager.divideMessage(strMsgContext);
		for (String text : msgList) {
			smsManager.sendTextMessage(strPhone, null, text, sendIntent, backIntent);
		}
	}
	
	/**
	 * 跳转至发送短信界面(自动设置接收方的号码)
	 * @param mActivity Activity
	 * @param strPhone 手机号码
	 * @param strMsgContext 短信内容
	 */
	public static void toSendMessageActivity(Context mContext,String strPhone,String strMsgContext){
		if(PhoneNumberUtils.isGlobalPhoneNumber(strPhone)){
            Uri uri = Uri.parse("smsto:" + strPhone);
            Intent sendIntent = new Intent(Intent.ACTION_VIEW, uri);
            sendIntent.putExtra("sms_body", strMsgContext);
            mContext.startActivity(sendIntent);
        }
	}
	
	/**
	 * 跳转至联系人选择界面
	 * @param mContext 上下文
	 * @param requestCode 请求返回区分代码
	 */
	public static void toChooseContactsList(Activity mContext,int requestCode){
		Intent intent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
		mContext.startActivityForResult(intent, requestCode);
	}
	
	/**
	 * 获取选择的联系人的手机号码
	 * @param mContext 上下文
	 * @param resultCode 请求返回Result状态区分代码
	 * @param data onActivityResult返回的Intent
	 * @return
	 */
	public static String getChoosedPhoneNumber(Activity mContext,int resultCode,Intent data) {
		//返回结果
		String phoneResult = "";
		if (Activity.RESULT_OK == resultCode) 
		{
			Uri uri = data.getData();
			Cursor mCursor = mContext.managedQuery(uri, null, null, null, null);
			mCursor.moveToFirst();  
		
			int phoneColumn = mCursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);
			int phoneNum = mCursor.getInt(phoneColumn);
			if (phoneNum > 0) {
				// 获得联系人的ID号
				int idColumn = mCursor.getColumnIndex(ContactsContract.Contacts._ID);
				String contactId = mCursor.getString(idColumn);
				// 获得联系人的电话号码的cursor;
				Cursor phones = mContext.getContentResolver().query(
						ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
						null,
						ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = "
								+ contactId, null, null);
				if (phones.moveToFirst()) {
					// 遍历所有的电话号码
					for (; !phones.isAfterLast(); phones.moveToNext()) {
						int index = phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
						int typeindex = phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE);
						int phone_type = phones.getInt(typeindex);
						String phoneNumber = phones.getString(index);
						switch (phone_type) {
						case 2:
							phoneResult = phoneNumber;
							break;
						}
					}
					if (!phones.isClosed()) {
						phones.close();
					}
				}
			}
			//关闭游标
			mCursor.close();
		}
		
		return phoneResult;
	}
	
	/**
	 * 跳转至拍照程序界面
	 * @param mContext 上下文
	 * @param requestCode 请求返回Result区分代码
	 */
	public static void toCameraActivity(Activity mContext,int requestCode){
		Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
		mContext.startActivityForResult(intent, requestCode);
	}
	
	/**
	 * 跳转至相册选择界面
	 * @param mContext 上下文
	 * @param requestCode 
	 */
	public static void toImagePickerActivity(Activity mContext,int requestCode){
		Intent intent = new Intent(Intent.ACTION_PICK, null);
        intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,"image/*");
        mContext.startActivityForResult(intent, requestCode);
	}
	
	/**
	 * 获得选中相册的图片
	 * @param mContext 上下文
	 * @param data onActivityResult返回的Intent
	 * @return
	 */
	public static Bitmap getChoosedImage(Activity mContext,Intent data){
		if (data == null) {
            return null;
        }
		
		Bitmap bm = null;

        // 外界的程序访问ContentProvider所提供数据 可以通过ContentResolver接口
        ContentResolver resolver = mContext.getContentResolver();

        // 此处的用于判断接收的Activity是不是你想要的那个
        try {
            Uri originalUri = data.getData(); // 获得图片的uri
            bm = MediaStore.Images.Media.getBitmap(resolver, originalUri); // 显得到bitmap图片
            // 这里开始的第二部分,获取图片的路径:
            String[] proj = {
                    MediaStore.Images.Media.DATA
            };
            // 好像是android多媒体数据库的封装接口,具体的看Android文档
            Cursor cursor = mContext.managedQuery(originalUri, proj, null, null, null);
            // 按我个人理解 这个是获得用户选择的图片的索引值
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            // 将光标移至开头 ,这个很重要,不小心很容易引起越界
            cursor.moveToFirst();
            // 最后根据索引值获取图片路径
            String path = cursor.getString(column_index);
            //不用了关闭游标
            cursor.close();
        } catch (Exception e) {
        	Log.e("ToolPhone", e.getMessage());
        }
        
        return bm;
	}
	
	/**
	 * 调用本地浏览器打开一个网页
	 * @param mContext 上下文
	 * @param strSiteUrl 网页地址
	 */
	public static void openWebSite(Context mContext,String strSiteUrl){
		Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strSiteUrl));  
		mContext.startActivity(webIntent);
	}
	
	/**
	 * 跳转至系统设置界面
	 * @param mContext 上下文
	 */
	public static void toSettingActivity(Context mContext){
		Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);  
		mContext.startActivity(settingsIntent);  
	}
	
	/**
	 * 跳转至WIFI设置界面
	 * @param mContext 上下文
	 */
	public static void toWIFISettingActivity(Context mContext){
		Intent wifiSettingsIntent = new Intent(Settings.ACTION_WIFI_SETTINGS);  
		mContext.startActivity(wifiSettingsIntent); 
	}
	
	/**
	 * 启动本地应用打开PDF
	 * @param mContext 上下文
	 * @param filePath 文件路径
	 */
	public static void openPDFFile(Context mContext, String filePath) {
		try {
			File file = new File(filePath);
			if (file.exists()) {
				Uri path = Uri.fromFile(file);
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setDataAndType(path, "application/pdf");
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				mContext.startActivity(intent);
			}
		} catch (Exception e) {
			Toast.makeText(mContext, "未检测到可打开PDF相关软件", Toast.LENGTH_SHORT)
					.show();
		}
	}
	
	/**
	 * 启动本地应用打开PDF
	 * @param mContext 上下文
	 * @param filePath 文件路径
	 */
	public static void openWordFile(Context mContext, String filePath) {
		try {
			File file = new File(filePath);
			if (file.exists()) {
				Uri path = Uri.fromFile(file);
				Intent intent = new Intent("android.intent.action.VIEW");
			    intent.addCategory("android.intent.category.DEFAULT");
			    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			    intent.setDataAndType(path, "application/msword");
				mContext.startActivity(intent);
			}
		} catch (Exception e) {
			Toast.makeText(mContext, "未检测到可打开Word文档相关软件", Toast.LENGTH_SHORT)
					.show();
		}
	}
	
	/**
	 * 调用WPS打开office文档
	 * http://bbs.wps.cn/thread-22349340-1-1.html
	 * @param mContext 上下文
	 * @param filePath 文件路径
	 */
	public static void openOfficeByWPS(Context mContext, String filePath){
		
		try {
			
			//文件存在性检查
			File file = new File(filePath);
			if (!file.exists()) {
				Toast.makeText(mContext, filePath+"文件路径不存在", Toast.LENGTH_SHORT).show();
				return;
			}
			
			//检查是否安装WPS
			String wpsPackageEng = "cn.wps.moffice_eng";//普通版与英文版一样
//			String wpsActivity = "cn.wps.moffice.documentmanager.PreStartActivity";
			String wpsActivity2 = "cn.wps.moffice.documentmanager.PreStartActivity2";//默认第三方程序启动
			
			Intent intent = new Intent();
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		    intent.addCategory(Intent.CATEGORY_DEFAULT);
		    intent.setClassName(wpsPackageEng,wpsActivity2);
		    
		    Uri uri = Uri.fromFile(new File(filePath));
			intent.setData(uri);
			mContext.startActivity(intent);
			
		}catch (ActivityNotFoundException e){
			Toast.makeText(mContext, "本地未安装WPS", Toast.LENGTH_SHORT).show();
		} catch (Exception e) {
			Toast.makeText(mContext, "打开文档失败", Toast.LENGTH_SHORT).show();
		}
	}
	
	/**
	 * 判断是否安装指定包名的APP
	 * @param mContext 上下文
	 * @param packageName 包路径
	 * @return
	 */
	public static boolean isInstalledApp(Context mContext, String packageName) {
		if (packageName == null || "".equals(packageName)) {
			return false;
		}

		try {
			ApplicationInfo info = mContext.getPackageManager()
					.getApplicationInfo(packageName,
							PackageManager.GET_UNINSTALLED_PACKAGES);
			return true;
		} catch (NameNotFoundException e) {
			return false;
		}
	}
	
	/**
	 * 判断是否存在指定的Activity
	 * @param mContext 上下文
	 * @param packageName 包名
	 * @param className activity全路径类名
	 * @return
	 */
	public static boolean isExistActivity(Context mContext, String packageName,String className) {
		
		Boolean result = true;
		Intent intent = new Intent();
		intent.setClassName(packageName, className);

		if (mContext.getPackageManager().resolveActivity(intent, 0) == null) {
			result =  false;
		} else if (intent.resolveActivity(mContext.getPackageManager()) == null) {
			result =  false;
		} else {
			List<ResolveInfo> list = mContext.getPackageManager()
					.queryIntentActivities(intent, 0);
			if (list.size() == 0) {
				result =  false;
			}
		}

		return result;
	}
	
}

17、文件操作工具 包括sdcard等

package com.zftlive.android.tools;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Environment;
import android.os.StatFs;
import android.util.Log;

/**
 * 文件工具类
 * 
 * @author 曾繁添
 * @version 1.0
 */
public class ToolFile {

	private static final String TAG = ToolFile.class.getSimpleName();

	/**
	 * 检查是否已挂载SD卡镜像(是否存在SD卡)
	 * 
	 * @return
	 */
	public static boolean isMountedSDCard() {
		if (Environment.MEDIA_MOUNTED.equals(Environment
				.getExternalStorageState())) {
			return true;
		} else {
			Log.w(TAG, "SDCARD is not MOUNTED !");
			return false;
		}
	}

	/**
	 * 获取SD卡剩余容量(单位Byte)
	 * 
	 * @return
	 */
	public static long gainSDFreeSize() {
		if (isMountedSDCard()) {
			// 取得SD卡文件路径
			File path = Environment.getExternalStorageDirectory();
			StatFs sf = new StatFs(path.getPath());
			// 获取单个数据块的大小(Byte)
			long blockSize = sf.getBlockSize();
			// 空闲的数据块的数量
			long freeBlocks = sf.getAvailableBlocks();

			// 返回SD卡空闲大小
			return freeBlocks * blockSize; // 单位Byte
		} else {
			return 0;
		}
	}

	/**
	 * 获取SD卡总容量(单位Byte)
	 * 
	 * @return
	 */
	public static long gainSDAllSize() {
		if (isMountedSDCard()) {
			// 取得SD卡文件路径
			File path = Environment.getExternalStorageDirectory();
			StatFs sf = new StatFs(path.getPath());
			// 获取单个数据块的大小(Byte)
			long blockSize = sf.getBlockSize();
			// 获取所有数据块数
			long allBlocks = sf.getBlockCount();
			// 返回SD卡大小(Byte)
			return allBlocks * blockSize;
		} else {
			return 0;
		}
	}

	/**
	 * 获取可用的SD卡路径(若SD卡不没有挂载则返回"")
	 * 
	 * @return
	 */
	public static String gainSDCardPath() {
		if (isMountedSDCard()) {
			File sdcardDir = Environment.getExternalStorageDirectory();
			if (!sdcardDir.canWrite()) {
				Log.w(TAG, "SDCARD can not write !");
			}
			return sdcardDir.getPath();
		}
		return "";
	}

	/**
	 * 以行为单位读取文件内容,一次读一整行,常用于读面向行的格式化文件
	 * @param filePath 文件路径
	 */
	public static String readFileByLines(String filePath) throws IOException
	{
		BufferedReader reader = null;
		StringBuffer sb = new StringBuffer();
		try
		{
			reader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath),System.getProperty("file.encoding")));
			String tempString = null;
			while ((tempString = reader.readLine()) != null)
			{
				sb.append(tempString);
				sb.append("\n");
			}
			reader.close();
		} catch (IOException e)
		{
			e.printStackTrace();
		} finally
		{
			if (reader != null){reader.close();}
		}

		return sb.toString();

	}
	
	/**
	 * 以行为单位读取文件内容,一次读一整行,常用于读面向行的格式化文件
	 * @param filePath 文件路径
	 * @param encoding 写文件编码
	 */
	public static String readFileByLines(String filePath,String encoding) throws IOException
	{
		BufferedReader reader = null;
		StringBuffer sb = new StringBuffer();
		try
		{
			reader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath),encoding));
			String tempString = null;
			while ((tempString = reader.readLine()) != null)
			{
				sb.append(tempString);
				sb.append("\n");
			}
			reader.close();
		} catch (IOException e)
		{
			e.printStackTrace();
		} finally
		{
			if (reader != null){reader.close();}
		}

		return sb.toString();
	}
	
	
	/**
	 * 保存内容
	 * @param filePath 文件路径
	 * @param content 保存的内容
	 * @throws IOException
	 */
	public static void saveToFile(String filePath,String content) throws IOException
	{
		saveToFile(filePath,content,System.getProperty("file.encoding"));
	}

	/**
	 * 指定编码保存内容
	 * @param filePath 文件路径
	 * @param content 保存的内容
	 * @param encoding 写文件编码
	 * @throws IOException
	 */
	public static void saveToFile(String filePath,String content,String encoding) throws IOException
	{
		BufferedWriter writer = null;
		File file = new File(filePath);
		try
		{
			if(!file.getParentFile().exists())
			{
				file.getParentFile().mkdirs();
			}
			writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), encoding));
			writer.write(content);

		} finally
		{
			if (writer != null){writer.close();}
		}
	}
	
	/**
	 * 追加文本
	 * @param content 需要追加的内容
	 * @param file 待追加文件源
	 * @throws IOException
	 */
	public static void appendToFile(String content, File file) throws IOException
	{
		appendToFile(content, file, System.getProperty("file.encoding"));
	}

	/**
	 * 追加文本
	 * @param content 需要追加的内容
	 * @param file 待追加文件源
	 * @param encoding 文件编码
	 * @throws IOException
	 */
	public static void appendToFile(String content, File file, String encoding) throws IOException
	{
		BufferedWriter writer = null;
		try
		{
			if(!file.getParentFile().exists())
			{
				file.getParentFile().mkdirs();
			}
			writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true), encoding));
			writer.write(content);
		} finally
		{
			if (writer != null){writer.close();}
		}
	}
	
	/**
	 * 判断文件是否存在
	 * @param filePath 文件路径
	 * @return 是否存在
	 * @throws Exception
	 */
	public static Boolean isExsit(String filePath)
	{
		Boolean flag = false ;
		try
		{
			File file = new File(filePath);
			if(file.exists())
			{
				flag = true;
			}
		}catch(Exception e){
			System.out.println("判断文件失败-->"+e.getMessage()); 
		} 
		
		return flag;
	}
	
	/**
	 * 快速读取程序应用包下的文件内容
	 * 
	 * @param context
	 *            上下文
	 * @param filename
	 *            文件名称
	 * @return 文件内容
	 * @throws IOException
	 */
	public static String read(Context context, String filename) throws IOException {
		FileInputStream inStream = context.openFileInput(filename);
		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int len = 0;
		while ((len = inStream.read(buffer)) != -1) {
			outStream.write(buffer, 0, len);
		}
		byte[] data = outStream.toByteArray();
		return new String(data);
	}

	/**
	 * 读取指定目录文件的文件内容
	 * 
	 * @param fileName
	 *            文件名称
	 * @return 文件内容
	 * @throws Exception
	 */
	public static String read(String fileName) throws IOException {
		FileInputStream inStream = new FileInputStream(fileName);
		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int len = 0;
		while ((len = inStream.read(buffer)) != -1) {
			outStream.write(buffer, 0, len);
		}
		byte[] data = outStream.toByteArray();
		return new String(data);
	}

	/***
	 * 以行为单位读取文件内容,一次读一整行,常用于读面向行的格式化文件
	 * 
	 * @param fileName
	 *            文件名称
	 * @param encoding
	 *            文件编码
	 * @return 字符串内容
	 * @throws IOException
	 */
	public static String read(String fileName, String encoding)
			throws IOException {
		BufferedReader reader = null;
		StringBuffer sb = new StringBuffer();
		try {
			reader = new BufferedReader(new InputStreamReader(
					new FileInputStream(fileName), encoding));
			String tempString = null;
			while ((tempString = reader.readLine()) != null) {
				sb.append(tempString);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				reader.close();
			}
		}

		return sb.toString();
	}

	/**
	 * 读取raw目录的文件内容
	 * 
	 * @param context
	 *            内容上下文
	 * @param rawFileId
	 *            raw文件名id
	 * @return
	 */
	public static String readRawValue(Context context, int rawFileId) {
		String result = "";
		try {
			InputStream is = context.getResources().openRawResource(rawFileId);
			int len = is.available();
			byte[] buffer = new byte[len];
			is.read(buffer);
			result = new String(buffer, "UTF-8");
			is.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 读取assets目录的文件内容
	 * 
	 * @param context
	 *            内容上下文
	 * @param fileName
	 *            文件名称,包含扩展名
	 * @return
	 */
	public static String readAssetsValue(Context context, String fileName) {
		String result = "";
		try {
			InputStream is = context.getResources().getAssets().open(fileName);
			int len = is.available();
			byte[] buffer = new byte[len];
			is.read(buffer);
			result = new String(buffer, "UTF-8");
			is.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
	/**
	 * 读取assets目录的文件内容
	 * 
	 * @param context
	 *            内容上下文
	 * @param fileName
	 *            文件名称,包含扩展名
	 * @return
	 */
	public static List<String> readAssetsListValue(Context context, String fileName) {
		List<String> list = new ArrayList<String>();
		try {
			InputStream in = context.getResources().getAssets().open(fileName);
			BufferedReader br = new BufferedReader(new InputStreamReader(in,"UTF-8"));
			String str = null;
			while ((str = br.readLine()) != null) {
				list.add(str);
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 获取SharedPreferences文件内容
	 * 
	 * @param context
	 *            上下文
	 * @param fileNameNoExt
	 *            文件名称(不用带后缀名)
	 * @return
	 */
	public static Map<String, ?> readShrePerface(Context context,String fileNameNoExt) {
		SharedPreferences preferences = context.getSharedPreferences(
				fileNameNoExt, Context.MODE_PRIVATE);
		return preferences.getAll();
	}

	/**
	 * 写入SharedPreferences文件内容
	 * 
	 * @param context
	 *            上下文
	 * @param fileNameNoExt
	 *            文件名称(不用带后缀名)
	 * @param values
	 *            需要写入的数据Map(String,Boolean,Float,Long,Integer)
	 * @return
	 */
	public static void writeShrePerface(Context context, String fileNameNoExt,Map<String, ?> values) {
		try {
			SharedPreferences preferences = context.getSharedPreferences(fileNameNoExt, Context.MODE_PRIVATE);
			SharedPreferences.Editor editor = preferences.edit();
			for (Iterator iterator = values.entrySet().iterator(); iterator.hasNext();) 
			{
				Map.Entry<String, ?> entry = (Map.Entry<String, ?>) iterator.next();
				if (entry.getValue() instanceof String) {
					editor.putString(entry.getKey(), (String) entry.getValue());
				} else if (entry.getValue() instanceof Boolean) {
					editor.putBoolean(entry.getKey(),(Boolean) entry.getValue());
				} else if (entry.getValue() instanceof Float) {
					editor.putFloat(entry.getKey(), (Float) entry.getValue());
				} else if (entry.getValue() instanceof Long) {
					editor.putLong(entry.getKey(), (Long) entry.getValue());
				} else if (entry.getValue() instanceof Integer) {
					editor.putInt(entry.getKey(),(Integer) entry.getValue());
				}
			}
			editor.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 写入应用程序包files目录下文件
	 * 
	 * @param context
	 *            上下文
	 * @param fileName
	 *            文件名称
	 * @param content
	 *            文件内容
	 */
	public static void write(Context context, String fileName, String content) {
		try {

			FileOutputStream outStream = context.openFileOutput(fileName,
					Context.MODE_PRIVATE);
			outStream.write(content.getBytes());
			outStream.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 写入应用程序包files目录下文件
	 * 
	 * @param context
	 *            上下文
	 * @param fileName
	 *            文件名称
	 * @param content
	 *            文件内容
	 */
	public static void write(Context context, String fileName, byte[] content) {
		try {

			FileOutputStream outStream = context.openFileOutput(fileName,
					Context.MODE_PRIVATE);
			outStream.write(content);
			outStream.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 写入应用程序包files目录下文件
	 * 
	 * @param context
	 *            上下文
	 * @param fileName
	 *            文件名称
	 * @param modeType
	 *            文件写入模式(Context.MODE_PRIVATE、Context.MODE_APPEND、Context.
	 *            MODE_WORLD_READABLE、Context.MODE_WORLD_WRITEABLE)
	 * @param content
	 *            文件内容
	 */
	public static void write(Context context, String fileName, byte[] content,
			int modeType) {
		try {

			FileOutputStream outStream = context.openFileOutput(fileName,
					modeType);
			outStream.write(content);
			outStream.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 指定编码将内容写入目标文件
	 * 
	 * @param target
	 *            目标文件
	 * @param content
	 *            文件内容
	 * @param encoding
	 *            写入文件编码
	 * @throws Exception
	 */
	public static void write(File target, String content, String encoding)
			throws IOException {
		BufferedWriter writer = null;
		try {
			if (!target.getParentFile().exists()) {
				target.getParentFile().mkdirs();
			}
			writer = new BufferedWriter(new OutputStreamWriter(
					new FileOutputStream(target, false), encoding));
			writer.write(content);

		} finally {
			if (writer != null) {
				writer.close();
			}
		}
	}
	
	/**
	 * 指定目录写入文件内容
	 * @param filePath 文件路径+文件名
	 * @param content 文件内容
	 * @throws IOException
	 */
	public static void write(String filePath, byte[] content)
			throws IOException {
		FileOutputStream fos = null;

		try {
			File file = new File(filePath);
			if (!file.getParentFile().exists()) {
				file.getParentFile().mkdirs();
			}
			fos = new FileOutputStream(file);
			fos.write(content);
			fos.flush();
		} finally {
			if (fos != null) {
				fos.close();
			}
		}
	}
	
	/**
	 * 写入文件
	 * 
	 * @param inputStream下载文件的字节流对象
	 * @param filePath文件的存放路径(带文件名称)
	 * @throws IOException 
	 */
	public static File write(InputStream inputStream, String filePath) throws IOException {
		OutputStream outputStream = null;
		// 在指定目录创建一个空文件并获取文件对象
		File mFile = new File(filePath);
		if (!mFile.getParentFile().exists())
			mFile.getParentFile().mkdirs();
		try {
			outputStream = new FileOutputStream(mFile);
			byte buffer[] = new byte[4 * 1024];
			int lenght = 0 ;
			while ((lenght = inputStream.read(buffer)) > 0) {
				outputStream.write(buffer,0,lenght);
			}
			outputStream.flush();
			return mFile;
		} catch (IOException e) {
			Log.e(TAG, "写入文件失败,原因:"+e.getMessage());
			throw e;
		}finally{
			try {
				inputStream.close();
				outputStream.close();
			} catch (IOException e) {
			}
		}
	}
	
	/**
	 * 指定目录写入文件内容
	 * @param filePath 文件路径+文件名
	 * @param content 文件内容
	 * @throws IOException
	 */
	public static void saveAsJPEG(Bitmap bitmap,String filePath)
			throws IOException {
		FileOutputStream fos = null;

		try {
			File file = new File(filePath);
			if (!file.getParentFile().exists()) {
				file.getParentFile().mkdirs();
			}
			fos = new FileOutputStream(file);
			bitmap.compress(Bitmap.CompressFormat.JPEG, 100,fos);
			fos.flush();
		} finally {
			if (fos != null) {
				fos.close();
			}
		}
	}
	
	/**
	 * 指定目录写入文件内容
	 * @param filePath 文件路径+文件名
	 * @param content 文件内容
	 * @throws IOException
	 */
	public static void saveAsPNG(Bitmap bitmap,String filePath)
			throws IOException {
		FileOutputStream fos = null;

		try {
			File file = new File(filePath);
			if (!file.getParentFile().exists()) {
				file.getParentFile().mkdirs();
			}
			fos = new FileOutputStream(file);
			bitmap.compress(Bitmap.CompressFormat.PNG, 100,fos);
			fos.flush();
		} finally {
			if (fos != null) {
				fos.close();
			}
		}
	}
}









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值