Skip to content

Commit

Permalink
ShellUtil、RandomUtil、SilentInstaller 三个类署名原作者喽
Browse files Browse the repository at this point in the history
  • Loading branch information
马天宇 committed Dec 12, 2014
1 parent bd77b5d commit 10eb4c8
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 170 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ LiteCommon是一系列通用类、辅助类、工具类的集合,有以下特
7. utils包:常用工具类
-----
- **AndroidUtil**: android信息, 获取android手机品牌、商家、版本号等信息
- **AppUtil**: app工具, 检测是否前台运行,服务是否运行中等
- **AppUtil**: app工具, 检测是否前台运行
- **BitmapUtil**: 位图操作, 拍照,裁剪,圆角,byte、string互转,压缩,放缩,保存等
- **ByteUtil**: byte工具类
- **ClassUtil**: 类工具, 新建实例,判断类的类型等
Expand All @@ -59,7 +59,6 @@ LiteCommon是一系列通用类、辅助类、工具类的集合,有以下特
- **NumberUtil**: 数字工具类,各种数字安全转化
- **PackageUtil**: 应用程序类,打开、安装,卸载,启动应用以及获取应用信息
- **RandomUtil**: 随机工具类,产生随机string或数字,随机洗牌等
- **SerializeUtil**: 序列化工具类
- **ShellUtil**: shell 命令工具类
- **TelephoneUtil**: 电话工具类,手机号、运营商、IMEI、IMSI等信息
- **VibrateUtil**: 震动工具类,调用系统震动功能
Expand Down
2 changes: 1 addition & 1 deletion src/com/litesuits/common/assist/SilentInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.io.File;

/**
* @author MaTianyu
* modify form <a href="http://www.trinea.cn" target="_blank">Trinea</a>
* @date 2014-12-10
*/
public class SilentInstaller {
Expand Down
60 changes: 0 additions & 60 deletions src/com/litesuits/common/utils/AppUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import java.io.File;
import java.io.FileFilter;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;

/**
* @author MaTianyu
Expand All @@ -20,8 +15,6 @@ public class AppUtil {
/**
* need < uses-permission android:name =“android.permission.GET_TASKS” />
* 判断是否前台运行
* @param context
* @return
*/
public static boolean isRunningForeground(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
Expand All @@ -35,58 +28,5 @@ public static boolean isRunningForeground(Context context) {
return false;
}

public static boolean isServiceRunning(Context ctx, String className) {
boolean isRunning = false;
ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> servicesList = activityManager.getRunningServices(Integer.MAX_VALUE);
Iterator<ActivityManager.RunningServiceInfo> l = servicesList.iterator();
while (l.hasNext()) {
ActivityManager.RunningServiceInfo si = (ActivityManager.RunningServiceInfo) l.next();
if (className.equals(si.service.getClassName())) {
isRunning = true;
}
}
return isRunning;
}

public static boolean stopRunningService(Context ctx, String className) {
Intent intent_service = null;
boolean ret = false;
try {
intent_service = new Intent(ctx, Class.forName(className));
} catch (Exception e) {
e.printStackTrace();
}
if (intent_service != null) {
ret = ctx.stopService(intent_service);
}
return ret;
}

public static int getCpuCores() {
try {
//Get directory containing CPU info
File dir = new File("/sys/devices/system/cpu/");
//Filter to only list the devices we care about
File[] files = dir.listFiles(new FileFilter(){

@Override
public boolean accept(File pathname) {
//Check if filename is "cpu", followed by “a” single digit number
if(Pattern.matches("cpu[0-9]", pathname.getName())) {
return true;
}
return false;
}

});
//Return the number of cores (virtual CPU devices)
return files.length;
} catch(Exception e) {
//Default to return 1 core
return 1;
}
}


}
8 changes: 4 additions & 4 deletions src/com/litesuits/common/utils/BitmapUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public static String bitmapToString(Bitmap bitmap) {
/**
* convert Drawable to Bitmap
*/
public static Bitmap drawableToBitmap(Drawable d) {
return d == null ? null : ((BitmapDrawable) d).getBitmap();
public static Bitmap drawableToBitmap(Drawable drawable) {
return drawable == null ? null : ((BitmapDrawable) drawable).getBitmap();
}

/**
* convert Bitmap to Drawable
*/
public static Drawable bitmapToDrawable(Bitmap b) {
return b == null ? null : new BitmapDrawable(b);
public static Drawable bitmapToDrawable(Bitmap bitmap) {
return bitmap == null ? null : new BitmapDrawable(bitmap);
}

/**
Expand Down
30 changes: 0 additions & 30 deletions src/com/litesuits/common/utils/PackageUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.litesuits.common.utils;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
Expand All @@ -18,7 +17,6 @@
import java.util.List;
import java.util.Map;


/**
* @author MaTianyu
* @date 14-11-7
Expand Down Expand Up @@ -237,32 +235,4 @@ public static boolean startAppByPackageName(Context context, String packageName,
return false;
}

/**
* 校验应用进程名字
*
* @param context
* @param processName
* @return
*/
public static boolean isNamedProcess(Context context, String processName) {
if (context == null || processName == null) {
return false;
}

ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) {
List<ActivityManager.RunningAppProcessInfo> processInfoList = manager.getRunningAppProcesses();
if (processInfoList != null) {
int pid = android.os.Process.myPid();
for (ActivityManager.RunningAppProcessInfo processInfo : processInfoList) {
if (processInfo.pid == pid && processName.equals(processInfo.processName)) {
return true;
}
}
}
}
return false;
}


}
2 changes: 1 addition & 1 deletion src/com/litesuits/common/utils/RandomUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* 随机工具类
* @author MaTianyu
* modify form <a href="http://www.trinea.cn" target="_blank">Trinea</a>
* @date 2014-12-10
*/
public class RandomUtil {
Expand Down
69 changes: 0 additions & 69 deletions src/com/litesuits/common/utils/SerializeUtil.java

This file was deleted.

4 changes: 1 addition & 3 deletions src/com/litesuits/common/utils/ShellUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import java.util.List;

/**
* modify from internet.
*
* @author MaTianyu
* modify form <a href="http://www.trinea.cn" target="_blank">Trinea</a>
* @date 2014-12-10
*/
public class ShellUtil {
Expand Down

0 comments on commit 10eb4c8

Please sign in to comment.