Permalink
Browse files

refine code

  • Loading branch information...
andrewleo committed Feb 18, 2013
1 parent 7c495fb commit bc8f6730b4dc7285e0b4592362e7b432b24bdbcc
@@ -59,7 +59,7 @@
+ MainPageActivity.class.getSimpleName();
private final int TIMEOUT = 20000;
private List<Programe> processList;
private ProcessInfo processInfo;
private Intent MonitorService;
@@ -90,7 +90,7 @@ public void onClick(View v) {
MonitorService.setClass(MainPageActivity.this,
EmmageeService.class);
if (isTesting) {
if (isRadioChecked == true) {
if (isRadioChecked) {
Intent intent = getPackageManager()
.getLaunchIntentForPackage(packageName);
Log.d(LOG_TAG, packageName);
@@ -129,7 +129,7 @@ private void createNewFile() {
settingTempFile = getBaseContext().getFilesDir().getPath()
+ "\\Emmagee_Settings.txt";
File settingFile = new File(settingTempFile);
if (!settingFile.exists())
if (!settingFile.exists()) {
try {
settingFile.createNewFile();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
@@ -139,13 +139,14 @@ private void createNewFile() {
} catch (IOException e) {
Log.d(LOG_TAG, "create new file exception :" + e.getMessage());
}
}
}
/**
* wait for test application started
* wait for test application started.
*
* @param packageName
* package name of test application
* package name of test application
*/
private void waitForAppStart(String packageName) {
Log.d(LOG_TAG, "wait for app start");
@@ -165,13 +166,14 @@ private void waitForAppStart(String packageName) {
}
}
}
if (isProcessStarted)
if (isProcessStarted) {
break;
}
}
}
/**
* show a dialog when click return key
* show a dialog when click return key.
*/
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
@@ -181,7 +183,9 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
}
/**
* set menu options
* set menu options.
*
* @return true
*/
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, Menu.FIRST, 0, "退出").setIcon(
@@ -191,6 +195,11 @@ public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
/**
* trigger menu options.
*
* @return false
*/
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getOrder()) {
case 0:
@@ -209,7 +218,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
/**
* create a dialog
* create a dialog.
*
* @return a dialog
*/
protected Dialog onCreateDialog(int id) {
switch (id) {
@@ -238,7 +249,7 @@ public void onClick(DialogInterface dialog,
}
/**
* customizing adapter
* customizing adapter.
*
*/
private class ListAdapter extends BaseAdapter {
@@ -40,7 +40,7 @@
private final String LOG_TAG = "Emmagee-"
+ SettingsActivity.class.getSimpleName();
private CheckBox chkFloat;
private EditText edtTime;
private String time;
@@ -54,34 +54,37 @@ public void onCreate(Bundle savedInstanceState) {
Intent intent = this.getIntent();
settingTempFile = intent.getStringExtra("settingTempFile");
chkFloat = (CheckBox) findViewById(R.id.floating);
edtTime = (EditText) findViewById(R.id.time);
Button btnSave = (Button) findViewById(R.id.save);
boolean floatingTag = true;
RandomAccessFile raf ;
try {
RandomAccessFile raf = new RandomAccessFile(settingTempFile, "r");
raf = new RandomAccessFile(settingTempFile, "r");
String f = raf.readLine();
if (f == null || (f != null && f.equals(""))) {
time = "5";
} else
} else {
time = f;
}
String tag = raf.readLine();
if (tag != null && tag.equals("false"))
if (tag != null && tag.equals("false")) {
floatingTag = false;
}
raf.close();
} catch (FileNotFoundException e) {
Log.e(LOG_TAG,
"FileNotFoundException: " + e.getMessage());
Log.e(LOG_TAG, "FileNotFoundException: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Log.e(LOG_TAG, "IOException: " + e.getMessage());
e.printStackTrace();
}
edtTime.setText(time);
chkFloat.setChecked(floatingTag);
// edtTime.setInputType(InputType.TYPE_CLASS_NUMBER);
// edtTime.setInputType(InputType.TYPE_CLASS_NUMBER);
btnSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@@ -131,11 +134,11 @@ protected void onDestroy() {
}
/**
* is input a number
* is input a number.
*
* @param inputStr
* input string
* @return
* @return true is numeric
*/
private boolean isNumeric(String inputStr) {
for (int i = inputStr.length(); --i >= 0;) {
@@ -18,7 +18,6 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
@@ -143,7 +142,7 @@ public void onStart(Intent intent, int startId) {
}
/**
* read configuration file
* read configuration file.
*
* @throws IOException
*/
@@ -153,15 +152,16 @@ private void readSettingInfo(Intent intent) {
settingTempFile), "r");
time = raf.readLine();
isFloating = raf.readLine().equals("true") ? true : false;
raf.close();
} catch (IOException e) {
time = "5";
isFloating = true;
Log.e(LOG_TAG, e.getMessage());
}
}
}
/**
* write the test result to csv format report
* write the test result to csv format report.
*/
private void createResultCsv() {
Calendar cal = Calendar.getInstance();
@@ -203,7 +203,7 @@ private void createResultCsv() {
}
/**
* create a floating window to show real-time data
* create a floating window to show real-time data.
*/
private void createFloatingWindow() {
SharedPreferences shared = getSharedPreferences("float_flag",
@@ -278,7 +278,7 @@ public void onClick(View v) {
}
/**
* show the image
* show the image.
*/
private void showImg() {
if (Math.abs(x - startX) < 1.5 && Math.abs(y - startY) < 1.5
@@ -299,7 +299,7 @@ public void run() {
};
/**
* refresh the performance data showing in floating window
* refresh the performance data showing in floating window.
*
* @throws FileNotFoundException
*
@@ -348,7 +348,7 @@ private void dataRefresh() {
}
/**
* update the position of floating window
* update the position of floating window.
*/
private void updateViewPosition() {
wmParams.x = (int) (x - mTouchStartX);
@@ -357,7 +357,7 @@ private void updateViewPosition() {
}
/**
* close all opened stream
* close all opened stream.
*/
public static void closeOpenedStream() {
try {
@@ -65,7 +65,7 @@ public CpuInfo(Context context, int pid, String uid) {
}
/**
* read the status of CPU
* read the status of CPU.
*
* @throws FileNotFoundException
*/
@@ -110,15 +110,16 @@ public void readCpuStat() {
}
/**
* get CPU name
* get CPU name.
*
* @return CPU name
*/
public String getCpuName() {
try {
RandomAccessFile cpu_stat = new RandomAccessFile("/proc/cpuinfo",
RandomAccessFile cpuStat = new RandomAccessFile("/proc/cpuinfo",
"r");
String[] cpu = cpu_stat.readLine().split(":"); // cpu信息的前一段是含有processor字符串,此处替换为不显示
String[] cpu = cpuStat.readLine().split(":"); // cpu信息的前一段是含有processor字符串,此处替换为不显示
cpuStat.close();
return cpu[1];
} catch (IOException e) {
Log.e(LOG_TAG, "IOException: " + e.getMessage());
@@ -128,7 +129,7 @@ public String getCpuName() {
/**
* reserve used ratio of process CPU and total CPU, meanwhile collect
* network traffic
* network traffic.
*
* @return network traffic ,used ratio of process CPU and total CPU in
* certain interval
@@ -31,7 +31,7 @@
+ MemoryInfo.class.getSimpleName();
/**
* get total memory of certain device
* get total memory of certain device.
*
* @return total memory of device
*/
@@ -49,6 +49,7 @@ public long getTotalMemory() {
memTotal = total[1].trim();
}
}
localBufferedReader.close();
String[] memKb = memTotal.split(" ");
memTotal = memKb[0].trim();
Log.d(LOG_TAG, "memTotal: " + memTotal);
@@ -60,7 +61,7 @@ public long getTotalMemory() {
}
/**
* get free memory
* get free memory.
*
* @return free memory of device
*
@@ -75,7 +76,7 @@ public long getFreeMemorySize(Context context) {
}
/**
* get the memory of process with certain pid
* get the memory of process with certain pid.
*
* @param pid
* pid of process
@@ -98,7 +99,7 @@ public int getPidMemorySize(int pid, Context context) {
}
/**
* get the sdk version of phone
* get the sdk version of phone.
*
* @return sdk version
*/
@@ -107,7 +108,7 @@ public String getSDKVersion() {
}
/**
* get phone type
* get phone type.
*
* @return phone type
*/
@@ -37,7 +37,7 @@
/**
* get information of all running processes,including package name ,process
* name ,icon ,pid and uid
* name ,icon ,pid and uid.
*
* @param context
* context of activity
@@ -73,7 +73,7 @@
}
programe.setPackageName(appinfo.processName);
programe.setProcessName(appinfo.loadLabel(pm).toString());
if (launchTag == true) {
if (launchTag) {
programe.setIcon(appinfo.loadIcon(pm));
}
progressList.add(programe);
@@ -82,7 +82,7 @@
}
/**
* get information of all applications
* get information of all applications.
*
* @param context
* context of activity
Oops, something went wrong.

0 comments on commit bc8f673

Please sign in to comment.