提交 7f3cdf22 编写于 作者: 黄庆兵 提交者: andrewleo

Fixed: code review and modify.

上级 39036cb5
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 连框颜色值 -->
<!-- border settings -->
<item>
<shape>
<solid android:color="@color/red" />
<corners android:radius="3dp" />
</shape>
</item>
<!-- 主体背景颜色值 -->
<item
android:bottom="1dp"
android:right="1dp"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom|center_horizontal|center_vertical"
android:background="@color/light_purple"
android:orientation="vertical">
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/light_purple"
android:gravity="bottom|center_horizontal|center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/navigation_bar" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/navigation_bar" />
</LinearLayout>
<ListView
android:id="@+id/processList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cacheColorHint="@color/light_purple"
android:listSelector="@color/light_purple"/>
android:id="@+id/processList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cacheColorHint="@color/light_purple"
android:listSelector="@color/light_purple" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/bottom_bg" >
android:layout_width="fill_parent"
android:layout_height="@dimen/layout_height_test"
android:background="@drawable/bottom_bg" >
<Button
android:id="@+id/test"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="6dp"
android:layout_marginBottom="2dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="@drawable/test_button"
android:text="@string/start_test"
android:textColor="#ffffff"
android:textSize="16sp" />
android:id="@+id/test"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="@dimen/layout_marginBottom_test"
android:layout_marginLeft="@dimen/layout_marginLeft_test"
android:layout_marginRight="@dimen/layout_marginRight_test"
android:layout_marginTop="@dimen/layout_marginTop_test"
android:background="@drawable/test_button"
android:text="@string/start_test"
android:textColor="@color/white"
android:textSize="@dimen/text_size_test" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -27,4 +27,12 @@
<dimen name="edit_margin">5px</dimen>
<dimen name="action_bar_height">60dp</dimen>
<dimen name="layout_height_test">50dp</dimen>
<dimen name="layout_marginTop_test">6dp</dimen>
<dimen name="layout_marginBottom_test">2dp</dimen>
<dimen name="layout_marginLeft_test">30dp</dimen>
<dimen name="layout_marginRight_test">30dp</dimen>
<dimen name="text_size_test">16sp</dimen>
</resources>
......@@ -8,7 +8,7 @@
<string name="start_test">Start Test</string>
<string name="stop_test">Stop Test</string>
<string name="collecting_frequency">Collecting Frequency(s)</string>
<string name="collecting_frequency">Collecting Interval(s)</string>
<string name="sender">Sender:</string>
<string name="password">Password:</string>
<string name="smtp">SMTP Server:</string>
......@@ -22,7 +22,7 @@
<string name="process_free_mem">App/Available Memory:</string>
<string name="process_overall_cpu">App/System CPU:</string>
<string name="start_time">Start Time:</string>
<string name="total_usage">Total Usage(%)</string>
<string name="total_usage">\u0020Total Usage(%)</string>
<string name="process_package">Package Name</string>
<string name="process_name">App Name</string>
<string name="process_pid">App PID</string>
......
......@@ -70,11 +70,11 @@ public class MainPageActivity extends Activity {
private boolean isServiceStop = false;
private UpdateReceiver receiver;
private TextView nb_title;
private ImageView go_back;
private ImageView btn_set;
private LinearLayout layBtnSet;
private Long mExitTime = (long) 0;
private TextView nbTitle;
private ImageView ivGoBack;
private ImageView ivBtnSet;
private LinearLayout layBtnSet;
private Long mExitTime = (long) 0;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -82,80 +82,81 @@ public class MainPageActivity extends Activity {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.mainpage);
initTitleLayout();
initTitleLayout();
createNewFile();
processInfo = new ProcessInfo();
btnTest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
monitorService = new Intent();
monitorService.setClass(MainPageActivity.this, EmmageeService.class);
if (getString(R.string.start_test).equals(btnTest.getText().toString())) {
if (isRadioChecked) {
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
String startActivity = "";
Log.d(LOG_TAG, packageName);
//clear logcat
try {
Runtime.getRuntime().exec("logcat -c");
} catch (IOException e) {
Log.d(LOG_TAG, e.getMessage());
}
try {
startActivity = intent.resolveActivity(getPackageManager()).getShortClassName();
startActivity(intent);
} catch (Exception e) {
Toast.makeText(MainPageActivity.this, getString(R.string.can_not_start_app_toast), Toast.LENGTH_LONG).show();
return;
}
waitForAppStart(packageName);
monitorService.putExtra("processName", processName);
monitorService.putExtra("pid", pid);
monitorService.putExtra("uid", uid);
monitorService.putExtra("packageName", packageName);
monitorService.putExtra("settingTempFile", settingTempFile);
monitorService.putExtra("startActivity", startActivity);
startService(monitorService);
btnTest.setText(getString(R.string.stop_test));
} else {
Toast.makeText(MainPageActivity.this, getString(R.string.choose_app_toast), Toast.LENGTH_LONG).show();
}
} else {
btnTest.setText(getString(R.string.start_test));
Toast.makeText(MainPageActivity.this, getString(R.string.test_result_file_toast) + EmmageeService.resultFilePath, Toast.LENGTH_LONG).show();
stopService(monitorService);
}
}
});
@Override
public void onClick(View v) {
monitorService = new Intent();
monitorService.setClass(MainPageActivity.this, EmmageeService.class);
if (getString(R.string.start_test).equals(btnTest.getText().toString())) {
if (isRadioChecked) {
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
String startActivity = "";
Log.d(LOG_TAG, packageName);
// clear logcat
try {
Runtime.getRuntime().exec("logcat -c");
} catch (IOException e) {
Log.d(LOG_TAG, e.getMessage());
}
try {
startActivity = intent.resolveActivity(getPackageManager()).getShortClassName();
startActivity(intent);
} catch (Exception e) {
Toast.makeText(MainPageActivity.this, getString(R.string.can_not_start_app_toast), Toast.LENGTH_LONG).show();
return;
}
waitForAppStart(packageName);
monitorService.putExtra("processName", processName);
monitorService.putExtra("pid", pid);
monitorService.putExtra("uid", uid);
monitorService.putExtra("packageName", packageName);
monitorService.putExtra("settingTempFile", settingTempFile);
monitorService.putExtra("startActivity", startActivity);
startService(monitorService);
btnTest.setText(getString(R.string.stop_test));
} else {
Toast.makeText(MainPageActivity.this, getString(R.string.choose_app_toast), Toast.LENGTH_LONG).show();
}
} else {
btnTest.setText(getString(R.string.start_test));
Toast.makeText(MainPageActivity.this, getString(R.string.test_result_file_toast) + EmmageeService.resultFilePath,
Toast.LENGTH_LONG).show();
stopService(monitorService);
}
}
});
lstViProgramme.setAdapter(new ListAdapter());
lstViProgramme.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
RadioButton rdBtn = (RadioButton)((LinearLayout)view).getChildAt(0);
rdBtn.setChecked(true);
}
});
nb_title.setText(getString(R.string.app_name));
go_back.setVisibility(ImageView.INVISIBLE);
btn_set.setImageResource(R.drawable.settings_button);
layBtnSet.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
goToSettingsActivity();
}
});
lstViProgramme.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
RadioButton rdBtn = (RadioButton) ((LinearLayout) view).getChildAt(0);
rdBtn.setChecked(true);
}
});
nbTitle.setText(getString(R.string.app_name));
ivGoBack.setVisibility(ImageView.INVISIBLE);
ivBtnSet.setImageResource(R.drawable.settings_button);
layBtnSet.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
goToSettingsActivity();
}
});
}
private void initTitleLayout() {
go_back = (ImageView) findViewById(R.id.go_back);
nb_title = (TextView) findViewById(R.id.nb_title);
btn_set = (ImageView) findViewById(R.id.btn_set);
lstViProgramme = (ListView) findViewById(R.id.processList);
btnTest = (Button) findViewById(R.id.test);
layBtnSet = (LinearLayout) findViewById(R.id.lay_btn_set);
}
private void initTitleLayout() {
ivGoBack = (ImageView) findViewById(R.id.go_back);
nbTitle = (TextView) findViewById(R.id.nb_title);
ivBtnSet = (ImageView) findViewById(R.id.btn_set);
lstViProgramme = (ListView) findViewById(R.id.processList);
btnTest = (Button) findViewById(R.id.test);
layBtnSet = (LinearLayout) findViewById(R.id.lay_btn_set);
}
/**
* customized BroadcastReceiver
......@@ -257,28 +258,28 @@ public class MainPageActivity extends Activity {
*/
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if ((System.currentTimeMillis() - mExitTime) > 2000) {
Toast.makeText(this, R.string.quite_alert, Toast.LENGTH_SHORT).show();
mExitTime = System.currentTimeMillis();
} else {
if (monitorService != null) {
if ((System.currentTimeMillis() - mExitTime) > 2000) {
Toast.makeText(this, R.string.quite_alert, Toast.LENGTH_SHORT).show();
mExitTime = System.currentTimeMillis();
} else {
if (monitorService != null) {
Log.d(LOG_TAG, "stop service");
stopService(monitorService);
}
Log.d(LOG_TAG, "exit Emmagee");
finish();
}
return true;
Log.d(LOG_TAG, "exit Emmagee");
finish();
}
return true;
}
return super.onKeyDown(keyCode, event);
}
private void goToSettingsActivity() {
Intent intent = new Intent();
intent.setClass(MainPageActivity.this, SettingsActivity.class);
intent.putExtra("settingTempFile", settingTempFile);
startActivityForResult(intent, Activity.RESULT_FIRST_USER);
}
private void goToSettingsActivity() {
Intent intent = new Intent();
intent.setClass(MainPageActivity.this, SettingsActivity.class);
intent.putExtra("settingTempFile", settingTempFile);
startActivityForResult(intent, Activity.RESULT_FIRST_USER);
}
/**
* customizing adapter.
......@@ -321,19 +322,19 @@ public class MainPageActivity extends Activity {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Programe pr = (Programe) programe.get(position);
Programe pr = (Programe) programe.get(position);
Viewholder holder = new Viewholder();
final int i = position;
convertView = MainPageActivity.this.getLayoutInflater().inflate(R.layout.list_item, null);
holder.imgViAppIcon = (ImageView) convertView.findViewById(R.id.image);
holder.imgViAppIcon.setImageDrawable(pr.getIcon());
holder.imgViAppIcon = (ImageView) convertView.findViewById(R.id.image);
holder.imgViAppIcon.setImageDrawable(pr.getIcon());
holder.txtAppName = (TextView) convertView.findViewById(R.id.text);
holder.txtAppName.setText(pr.getProcessName());
holder.txtAppName.setText(pr.getProcessName());
holder.rdoBtnApp = (RadioButton) convertView.findViewById(R.id.rb);
holder.rdoBtnApp.setFocusable(false);
holder.rdoBtnApp.setFocusable(false);
holder.rdoBtnApp.setId(position);
holder.rdoBtnApp.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
......
......@@ -74,11 +74,11 @@ public class SettingsActivity extends Activity {
SeekBar timeBar = (SeekBar) findViewById(R.id.timeline);
ImageView btnSave = (ImageView) findViewById(R.id.btn_set);
ImageView goBack = (ImageView) findViewById(R.id.go_back);
RelativeLayout floating_item = (RelativeLayout) findViewById(R.id.floating_item);
RelativeLayout floatingItem = (RelativeLayout) findViewById(R.id.floating_item);
LinearLayout layGoBack = (LinearLayout) findViewById(R.id.lay_go_back);
boolean floatingTag = true;
btnSave.setVisibility(ImageView.INVISIBLE);
try {
properties.load(new FileInputStream(settingTempFile));
......@@ -112,7 +112,7 @@ public class SettingsActivity extends Activity {
int interval = arg0.getProgress() + 1;
try {
Properties properties = new Properties();
properties.load(new FileInputStream(settingTempFile));
properties.load(new FileInputStream(settingTempFile));
properties.setProperty("interval", Integer.toString(interval));
FileOutputStream fos = new FileOutputStream(settingTempFile);
properties.store(fos, "Setting Data");
......@@ -122,7 +122,7 @@ public class SettingsActivity extends Activity {
}
}
});
layGoBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
......@@ -151,13 +151,13 @@ public class SettingsActivity extends Activity {
}
});
floating_item.setOnClickListener(new OnClickListener() {
floatingItem.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
chkFloat.setChecked(!chkFloat.isChecked());
Properties properties = new Properties();
properties.load(new FileInputStream(settingTempFile));
properties.load(new FileInputStream(settingTempFile));
properties.setProperty("isfloat", chkFloat.isChecked() ? "true" : "false");
FileOutputStream fos = new FileOutputStream(settingTempFile);
properties.store(fos, "Setting Data");
......
......@@ -106,10 +106,13 @@ public class CpuInfo {
} catch (IOException e) {
e.printStackTrace();
}
read_total_cpu_stat();
readTotalCpuStat();
}
private void read_total_cpu_stat() {
/**
* read stat of each CPU cores
*/
private void readTotalCpuStat() {
try {
// monitor total and idle cpu stat of certain process
RandomAccessFile cpuInfo = new RandomAccessFile(CPU_STAT, "r");
......@@ -142,6 +145,7 @@ public class CpuInfo {
while (null != (line = cpuStat.readLine())) {
String[] values = line.split(":");
if (values[0].contains(INTEL_CPU_NAME)) {
cpuStat.close();
return values[1];
}
}
......@@ -257,10 +261,14 @@ public class CpuInfo {
if (null != totalCpu2 && totalCpu2.size() > 0) {
processCpuRatio = fomart.format(100 * ((double) (processCpu - processCpu2) / ((double) (totalCpu.get(0) - totalCpu2.get(0)))));
for (int i = 0; i < (totalCpu.size() > totalCpu2.size() ? totalCpu2.size() : totalCpu.size()); i++) {
String cpuRatio = fomart.format(100 * ((double) ((totalCpu.get(i) - idleCpu.get(i)) - (totalCpu2.get(i) - idleCpu2.get(i))) / (double) (totalCpu
.get(i) - totalCpu2.get(i))));
String cpuRatio = "0.00";
if (totalCpu.get(i) - totalCpu2.get(i) > 0) {
cpuRatio = fomart
.format(100 * ((double) ((totalCpu.get(i) - idleCpu.get(i)) - (totalCpu2.get(i) - idleCpu2.get(i))) / (double) (totalCpu
.get(i) - totalCpu2.get(i))));
}
totalCpuRatio.add(cpuRatio);
totalCpuBuffer.append(cpuRatio+",");
totalCpuBuffer.append(cpuRatio + ",");
}
} else {
processCpuRatio = "0";
......@@ -271,7 +279,7 @@ public class CpuInfo {
idleCpu2 = (ArrayList<Long>) idleCpu.clone();
}
// 多核cpu的值写入csv文件中
for(int i =0;i<getCpuNum()-totalCpuRatio.size()+1;i++){
for (int i = 0; i < getCpuNum() - totalCpuRatio.size() + 1; i++) {
totalCpuBuffer.append("0.00,");
}
long pidMemory = mi.getPidMemorySize(pid, context);
......@@ -287,10 +295,12 @@ public class CpuInfo {
// whether certain device supports traffic statics or not
if (traffic == -1) {
EmmageeService.bw.write(mDateTime2 + "," + pMemory + "," + percent + "," + fMemory + "," + processCpuRatio + ","
+ totalCpuBuffer.toString() + "N/A" + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage + "\r\n");
+ totalCpuBuffer.toString() + "N/A" + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage
+ "\r\n");
} else {
EmmageeService.bw.write(mDateTime2 + "," + pMemory + "," + percent + "," + fMemory + "," + processCpuRatio + ","
+ totalCpuBuffer.toString() + traffic + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage + "\r\n");
+ totalCpuBuffer.toString() + traffic + "," + totalBatt + "," + currentBatt + "," + temperature + "," + voltage
+ "\r\n");
}
totalCpu2 = (ArrayList<Long>) totalCpu.clone();
processCpu2 = processCpu;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册