Skip to content

Commit

Permalink
refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleo committed Feb 18, 2013
1 parent 7c495fb commit bc8f673
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 50 deletions.
31 changes: 21 additions & 10 deletions src/com/netease/qa/emmagee/activity/MainPageActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class MainPageActivity extends Activity {
+ MainPageActivity.class.getSimpleName();

private final int TIMEOUT = 20000;

private List<Programe> processList;
private ProcessInfo processInfo;
private Intent MonitorService;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand All @@ -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");
Expand All @@ -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) {
Expand All @@ -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(
Expand All @@ -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:
Expand All @@ -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) {
Expand Down Expand Up @@ -238,7 +249,7 @@ public void onClick(DialogInterface dialog,
}

/**
* customizing adapter
* customizing adapter.
*
*/
private class ListAdapter extends BaseAdapter {
Expand Down
25 changes: 14 additions & 11 deletions src/com/netease/qa/emmagee/activity/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class SettingsActivity extends Activity {

private final String LOG_TAG = "Emmagee-"
+ SettingsActivity.class.getSimpleName();

private CheckBox chkFloat;
private EditText edtTime;
private String time;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;) {
Expand Down
18 changes: 9 additions & 9 deletions src/com/netease/qa/emmagee/service/EmmageeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -143,7 +142,7 @@ public void onStart(Intent intent, int startId) {
}

/**
* read configuration file
* read configuration file.
*
* @throws IOException
*/
Expand All @@ -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();
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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
*
Expand Down Expand Up @@ -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);
Expand All @@ -357,7 +357,7 @@ private void updateViewPosition() {
}

/**
* close all opened stream
* close all opened stream.
*/
public static void closeOpenedStream() {
try {
Expand Down
11 changes: 6 additions & 5 deletions src/com/netease/qa/emmagee/utils/CpuInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public CpuInfo(Context context, int pid, String uid) {
}

/**
* read the status of CPU
* read the status of CPU.
*
* @throws FileNotFoundException
*/
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/com/netease/qa/emmagee/utils/MemoryInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class MemoryInfo {
+ MemoryInfo.class.getSimpleName();

/**
* get total memory of certain device
* get total memory of certain device.
*
* @return total memory of device
*/
Expand All @@ -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);
Expand All @@ -60,7 +61,7 @@ public long getTotalMemory() {
}

/**
* get free memory
* get free memory.
*
* @return free memory of device
*
Expand All @@ -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
Expand All @@ -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
*/
Expand All @@ -107,7 +108,7 @@ public String getSDKVersion() {
}

/**
* get phone type
* get phone type.
*
* @return phone type
*/
Expand Down
6 changes: 3 additions & 3 deletions src/com/netease/qa/emmagee/utils/ProcessInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ProcessInfo {

/**
* 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
Expand Down Expand Up @@ -73,7 +73,7 @@ public List<Programe> getRunningProcess(Context context) {
}
programe.setPackageName(appinfo.processName);
programe.setProcessName(appinfo.loadLabel(pm).toString());
if (launchTag == true) {
if (launchTag) {
programe.setIcon(appinfo.loadIcon(pm));
}
progressList.add(programe);
Expand All @@ -82,7 +82,7 @@ public List<Programe> getRunningProcess(Context context) {
}

/**
* get information of all applications
* get information of all applications.
*
* @param context
* context of activity
Expand Down
Loading

0 comments on commit bc8f673

Please sign in to comment.