自己为了写的一个动态刷新View,貌似有点慢!!!!
首先是Systeminfo.java
public class SystemInfo {
public final String Product = android.os.Build.PRODUCT;
public final String CPU_ABI = android.os.Build.CPU_ABI;
public final String TAGS = android.os.Build.TAGS;
public final int VERSION_CODES_BASE = android.os.Build.VERSION_CODES.BASE;
public final String MODEL = android.os.Build.MODEL;
public final String SDK = android.os.Build.VERSION.SDK;
public final String VERSION_RELEASE = android.os.Build.VERSION.RELEASE;
public final String DEVICE = android.os.Build.DEVICE;
public final String DISPLAY = android.os.Build.DISPLAY;
public final String BRAND = android.os.Build.BRAND;
public final String BOARD = android.os.Build.BOARD;
public final String FINGERPRINT = android.os.Build.FINGERPRINT;
public final String ID = android.os.Build.ID;
public final String MANUFACTURER = android.os.Build.MANUFACTURER;
public final String USER = android.os.Build.USER;
private String[] mCpuInfo = null;
private float mBattery = 0.0f;
private Context mContext;
public SystemInfo(Context c){
c.registerReceiver(batteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
mContext = c;
mCpuInfo = getCpuInfo();
}
public long getTotalMemory() {
String str1;
String str2 = null;
try {
FileReader fr = new FileReader("/proc/meminfo");//第一行是总内存大小(即用户可以使用的ram的大小)
BufferedReader localBufferedReader = new BufferedReader(fr, 8192);
str1 = localBufferedReader.readLine();
Pattern pattern = Pattern.compile("^MemTotal:");
//Pattern pattern = Pattern.compile("[^0-9]");
Matcher matcher = pattern.matcher(str1);
if (!matcher.find()) {
return 0;
}
pattern = Pattern.compile("[^0-9]");
matcher = pattern.matcher(str1);
str2 = matcher.replaceAll("");
//Log.d("zw","str2 = " + str2);
} catch (IOException e) {}
return Long.decode(str2);
}
//获取当前剩余内存(ram)大小的方法
public long getAvailMemory() {
ActivityManager am = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return mi.availMem;
}
//Available rom memory
public long getAvailInternalMemorySize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return blockSize * availableBlocks;
}
//Total rom memory
public long getTotalInternalMemorySize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();