提交 615ee0b7 编写于 作者: A andrewleo2013

solve some issues on github,refine code

上级 232debd7
......@@ -26,8 +26,11 @@ import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
......@@ -55,7 +58,7 @@ import com.netease.qa.emmagee.R;
/**
* Main Page of Emmagee
*
*
*/
public class MainPageActivity extends Activity {
......@@ -69,10 +72,11 @@ public class MainPageActivity extends Activity {
private Intent monitorService;
private ListView lstViProgramme;
private Button btnTest;
private boolean isTesting = true;
private boolean isRadioChecked = false;
private int pid, uid;
private String processName, packageName, settingTempFile;
private boolean isServiceStop = false;
private UpdateReceiver receiver;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -86,19 +90,24 @@ public class MainPageActivity extends Activity {
processInfo = new ProcessInfo();
lstViProgramme = (ListView) findViewById(R.id.processList);
btnTest = (Button) findViewById(R.id.test);
lstViProgramme.setAdapter(new ListAdapter());
btnTest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
monitorService = new Intent();
monitorService.setClass(MainPageActivity.this,
EmmageeService.class);
if (isTesting) {
if ("开始测试".equals(btnTest.getText().toString())) {
if (isRadioChecked) {
Intent intent = getPackageManager()
.getLaunchIntentForPackage(packageName);
Log.d(LOG_TAG, packageName);
startActivity(intent);
try {
startActivity(intent);
} catch (NullPointerException e) {
Toast.makeText(MainPageActivity.this, "该程序无法启动",
Toast.LENGTH_LONG).show();
return;
}
waitForAppStart(packageName);
monitorService.putExtra("processName", processName);
monitorService.putExtra("pid", pid);
......@@ -108,14 +117,12 @@ public class MainPageActivity extends Activity {
settingTempFile);
startService(monitorService);
btnTest.setText("停止测试");
isTesting = false;
} else {
Toast.makeText(MainPageActivity.this, "请选择需要测试的应用程序",
Toast.LENGTH_LONG).show();
}
} else {
btnTest.setText("开始测试");
isTesting = true;
Toast.makeText(MainPageActivity.this,
"测试结果文件:" + EmmageeService.resultFilePath,
Toast.LENGTH_LONG).show();
......@@ -125,6 +132,36 @@ public class MainPageActivity extends Activity {
});
}
public class UpdateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
isServiceStop = intent.getExtras().getBoolean("isServiceStop");
if (isServiceStop) {
btnTest.setText("开始测试");
}
}
}
protected void onStart() {
Log.d(LOG_TAG, "onStart");
receiver = new UpdateReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction("com.netease.action.emmageeService");
this.registerReceiver(receiver, filter);
super.onStart();
}
@Override
public void onResume() {
super.onResume();
Log.d(LOG_TAG, "onResume");
if (EmmageeService.isStop) {
btnTest.setText("开始测试");
}
lstViProgramme.setAdapter(new ListAdapter());
}
/**
* create new file to reserve setting data.
*/
......@@ -192,7 +229,7 @@ public class MainPageActivity extends Activity {
/**
* set menu options,including cancel and setting options.
*
*
* @return true
*/
public boolean onCreateOptionsMenu(Menu menu) {
......@@ -205,7 +242,7 @@ public class MainPageActivity extends Activity {
/**
* trigger menu options.
*
*
* @return false
*/
public boolean onOptionsItemSelected(MenuItem item) {
......@@ -227,7 +264,7 @@ public class MainPageActivity extends Activity {
/**
* create a dialog.
*
*
* @return a dialog
*/
protected Dialog onCreateDialog(int id) {
......@@ -258,7 +295,7 @@ public class MainPageActivity extends Activity {
/**
* customizing adapter.
*
*
*/
private class ListAdapter extends BaseAdapter {
List<Programe> programe;
......@@ -343,6 +380,11 @@ public class MainPageActivity extends Activity {
super.finish();
}
protected void onStop() {
unregisterReceiver(receiver);
super.onStop();
}
@Override
protected void onDestroy() {
super.onDestroy();
......
......@@ -49,6 +49,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
//import com.netease.qa.emmagee.activity.MainPageActivity;
import com.netease.qa.emmagee.utils.CpuInfo;
import com.netease.qa.emmagee.utils.MemoryInfo;
import com.netease.qa.emmagee.utils.MyApplication;
......@@ -87,16 +88,20 @@ public class EmmageeService extends Service {
private boolean isFloating;
private String processName, packageName, settingTempFile;
private int pid, uid;
private boolean isServiceStop = false;
public static BufferedWriter bw;
public static FileOutputStream out;
public static OutputStreamWriter osw;
public static String resultFilePath;
public static boolean isStop = false;
@Override
public void onCreate() {
Log.i(LOG_TAG, "onCreate");
super.onCreate();
isServiceStop = false;
isStop = false;
memoryInfo = new MemoryInfo();
fomart = new DecimalFormat();
fomart.setMaximumFractionDigits(2);
......@@ -143,7 +148,7 @@ public class EmmageeService extends Service {
createFloatingWindow();
}
createResultCsv();
handler.postDelayed(task, delaytime);
handler.postDelayed(task, 1000);
}
/**
......@@ -300,11 +305,20 @@ public class EmmageeService extends Service {
}
private Runnable task = new Runnable() {
public void run() {
dataRefresh();
handler.postDelayed(this, delaytime);
if (isFloating)
windowManager.updateViewLayout(viFloatingWindow, wmParams);
if (!isServiceStop) {
dataRefresh();
handler.postDelayed(this, delaytime);
if (isFloating)
windowManager.updateViewLayout(viFloatingWindow, wmParams);
} else {
Intent intent = new Intent();
intent.putExtra("isServiceStop", true);
intent.setAction("com.netease.action.emmageeService");// action与接收器相同
sendBroadcast(intent);
stopSelf();
}
}
};
......@@ -340,6 +354,11 @@ public class EmmageeService extends Service {
}
}
}
if ("0".equals(processMemory) && "0.00".equals(processCpuRatio)) {
closeOpenedStream();
isServiceStop = true;
return;
}
if (processCpuRatio != null && totalCpuRatio != null) {
txtUnusedMem.setText("占用内存:" + processMemory + "MB" + ",机器剩余:"
+ freeMemoryKb + "MB");
......@@ -384,15 +403,18 @@ public class EmmageeService extends Service {
@Override
public void onDestroy() {
Log.i(LOG_TAG, "onDestroy");
super.onDestroy();
if (windowManager != null)
windowManager.removeView(viFloatingWindow);
handler.removeCallbacks(task);
closeOpenedStream();
isStop = true;
Toast.makeText(this, "测试结果文件:" + EmmageeService.resultFilePath,
Toast.LENGTH_LONG).show();
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
}
\ No newline at end of file
......@@ -19,8 +19,6 @@ package com.netease.qa.emmagee.utils;
import java.util.ArrayList;
import java.util.List;
import com.netease.qa.emmagee.activity.MainPageActivity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册