diff --git a/app/src/androidTest/java/com/zhuazhu/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/zhuazhu/ExampleInstrumentedTest.java index a0e4e8b..dffc353 100644 --- a/app/src/androidTest/java/com/zhuazhu/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/zhuazhu/ExampleInstrumentedTest.java @@ -7,7 +7,9 @@ import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import conm.zhuazhu.common.utils.EncryptUtils; + +import static org.junit.Assert.assertEquals; /** * Instrumented test, which will execute on an Android device. @@ -23,4 +25,9 @@ public void useAppContext() throws Exception { assertEquals("com.zhuazhu", appContext.getPackageName()); } + @Test + public void test(){ + String m5 = EncryptUtils.encryptMD5ToString("123456"); + System.out.println(m5); + } } diff --git a/app/src/test/java/com/zhuazhu/ExampleUnitTest.java b/app/src/test/java/com/zhuazhu/ExampleUnitTest.java index b6ac4bf..3f67209 100644 --- a/app/src/test/java/com/zhuazhu/ExampleUnitTest.java +++ b/app/src/test/java/com/zhuazhu/ExampleUnitTest.java @@ -2,7 +2,9 @@ import org.junit.Test; -import static org.junit.Assert.*; +import conm.zhuazhu.common.utils.EncryptUtils; + +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). @@ -14,4 +16,10 @@ public class ExampleUnitTest { public void addition_isCorrect() throws Exception { assertEquals(4, 2 + 2); } + @Test + public void test(){ + String m5 = EncryptUtils.encryptMD5ToString("123456"); + + System.out.println(m5); + } } \ No newline at end of file diff --git a/common/src/main/java/conm/zhuazhu/common/utils/AppUtils.java b/common/src/main/java/conm/zhuazhu/common/utils/AppUtils.java index 451fdc7..ca819ae 100644 --- a/common/src/main/java/conm/zhuazhu/common/utils/AppUtils.java +++ b/common/src/main/java/conm/zhuazhu/common/utils/AppUtils.java @@ -244,6 +244,19 @@ public static void exitApp() { System.exit(0); } + /** + * 获取meta-data的value + * @param key + * @return + * @throws PackageManager.NameNotFoundException + */ + public static String metaData(String key) throws PackageManager.NameNotFoundException { + ApplicationInfo applicationInfo = Utils.getApp().getPackageManager() + .getApplicationInfo(getAppPackageName(), PackageManager + .GET_META_DATA); + return applicationInfo.metaData.getString("key"); + } + /** * 获取 App 包名 * diff --git a/common/src/main/java/conm/zhuazhu/common/utils/MD5Utils.java b/common/src/main/java/conm/zhuazhu/common/utils/MD5Utils.java deleted file mode 100644 index db4598f..0000000 --- a/common/src/main/java/conm/zhuazhu/common/utils/MD5Utils.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 文 件 名: MD5SignUtil.java - * 版 权: 四川嘉信商运物业服务有限公司, All rights reserved - * 描 述: 描述 - * 创 建 人: admin - * 修 改 人: - * 修改时间: 2015年8月25日 - * 修改内容: 修改内容 - */ -package conm.zhuazhu.common.utils; - -import android.annotation.SuppressLint; - -import java.security.MessageDigest; - -/** - * MD5签名/加密工具 - * - * @author admin - * @version 0.0.1 - * @date 2015年8月25日 - * @see [相关类/方法] - */ -@SuppressLint("DefaultLocale") -public class MD5Utils { - /** - * MD5加密算法 - * - * @param s - * @return - * @see [类、类#方法、类#成员] - */ - public final static String MD5(String s) { - char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - try { - byte[] btInput = s.getBytes("UTF-8"); - MessageDigest mdInst = MessageDigest.getInstance("MD5"); - mdInst.update(btInput); - byte[] md = mdInst.digest(); - int j = md.length; - char str[] = new char[j * 2]; - int k = 0; - for (int i = 0; i < j; i++) { - byte byte0 = md[i]; - str[k++] = hexDigits[byte0 >>> 4 & 0xf]; - str[k++] = hexDigits[byte0 & 0xf]; - } - return new String(str); - } catch (Exception e) { - return null; - } - } -} diff --git a/common/src/main/java/conm/zhuazhu/common/utils/VibrateUtils.java b/common/src/main/java/conm/zhuazhu/common/utils/VibrateUtils.java index 0297bb2..9492c4f 100644 --- a/common/src/main/java/conm/zhuazhu/common/utils/VibrateUtils.java +++ b/common/src/main/java/conm/zhuazhu/common/utils/VibrateUtils.java @@ -15,24 +15,22 @@ public class VibrateUtils { /** * {@link android.Manifest.permission#VIBRATE}. * - * @param context * @param milliseconds The number of milliseconds to vibrate. */ - public static void vibrate(Context context, long milliseconds) { - Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + public static void vibrate(long milliseconds) { + Vibrator vibrator = (Vibrator) Utils.getApp().getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(milliseconds); } /** * {@link android.Manifest.permission#VIBRATE}. * - * @param context * @param pattern an array of longs of times for which to turn the vibrator on or off. * @param repeat the index into pattern at which to repeat, or -1 if * you don't want to repeat. */ - public static void vibrate(Context context, long[] pattern, int repeat) { - Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + public static void vibrate(long[] pattern, int repeat) { + Vibrator vibrator = (Vibrator) Utils.getApp().getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(pattern, repeat); } } diff --git a/common/src/main/java/conm/zhuazhu/common/utils/VoiceUtils.java b/common/src/main/java/conm/zhuazhu/common/utils/VoiceUtils.java index 580b3bd..5b8242c 100644 --- a/common/src/main/java/conm/zhuazhu/common/utils/VoiceUtils.java +++ b/common/src/main/java/conm/zhuazhu/common/utils/VoiceUtils.java @@ -1,6 +1,5 @@ package conm.zhuazhu.common.utils; -import android.content.Context; import android.media.MediaPlayer; import android.support.annotation.RawRes; @@ -13,13 +12,10 @@ public class VoiceUtils { /** * 播放语音 - * @param context * @param raw */ - public static void play(Context context,@RawRes int raw){ - - MediaPlayer player = MediaPlayer.create(context,raw); - + public static void play(@RawRes int raw){ + MediaPlayer player = MediaPlayer.create(Utils.getApp(),raw); player.start(); } } diff --git a/common/src/main/java/conm/zhuazhu/common/utils/WindowUtils.java b/common/src/main/java/conm/zhuazhu/common/utils/WindowUtils.java index 39017fc..033ffcf 100644 --- a/common/src/main/java/conm/zhuazhu/common/utils/WindowUtils.java +++ b/common/src/main/java/conm/zhuazhu/common/utils/WindowUtils.java @@ -2,8 +2,6 @@ import android.Manifest; import android.content.Context; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.support.v4.app.ActivityCompat; import android.telephony.TelephonyManager; @@ -17,61 +15,6 @@ */ public class WindowUtils { - /** - * 获取meta-data的value - * @param context - * @param key - * @return - * @throws PackageManager.NameNotFoundException - */ - public static String metaData(Context context, String key) throws - PackageManager.NameNotFoundException { - ApplicationInfo applicationInfo = context.getPackageManager() - .getApplicationInfo(context.getPackageName(), PackageManager - .GET_META_DATA); - return applicationInfo.metaData.getString("key"); - } - - /** - * 获取版本code - * - * @param context - * @return - * @throws Exception - */ - public static int versionCode(Context context) throws Exception { - // 获取packagemanager的实例 - PackageManager packageManager = context.getPackageManager(); - // getPackageName()是你当前类的包名,0代表是获取版本信息 - PackageInfo packInfo = packageManager.getPackageInfo(context - .getPackageName(), 0); - int version = packInfo.versionCode; - return version; - } - - /** - * 获取版本 - * - * @param context - * @return - * @throws Exception - */ - public static String versionName(Context context) { - // 获取packagemanager的实例 - PackageManager packageManager = context.getPackageManager(); - // getPackageName()是你当前类的包名,0代表是获取版本信息 - PackageInfo packInfo = null; - try { - packInfo = packageManager.getPackageInfo(context.getPackageName() - , 0); - } catch (Exception e) { - e.printStackTrace(); - } - if (packInfo == null) { - return null; - } - return packInfo.versionName; - } /** * 获取设备id