Skip to content

Commit

Permalink
Added: NetEase#12 add "stop test" button on floating window
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleo committed Dec 24, 2013
1 parent 630c877 commit 611c969
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 42 deletions.
6 changes: 0 additions & 6 deletions res/layout/floating.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
android:layout_marginTop="4dp"
android:src="@drawable/meminfo" />

<ImageView
android:id="@+id/img2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/close" />

<LinearLayout
android:id="@+id/Lin"
android:layout_width="wrap_content"
Expand Down
58 changes: 22 additions & 36 deletions src/com/netease/qa/emmagee/service/EmmageeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
Expand Down Expand Up @@ -56,7 +55,6 @@
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -90,7 +88,7 @@ public class EmmageeService extends Service {
private TextView txtTotalMem;
private TextView txtUnusedMem;
private TextView txtTraffic;
private ImageView imgViIcon;
private Button btnStop;
private Button btnWifi;
private int delaytime;
private DecimalFormat fomart;
Expand All @@ -114,7 +112,6 @@ public class EmmageeService extends Service {
public static boolean isStop = false;

private String totalBatt;
private String currentBatt;
private String temperature;
private String voltage;
private CurrentInfo currentInfo;
Expand Down Expand Up @@ -146,7 +143,7 @@ public void onCreate() {
/**
* 电池信息监控监听器
*
* @author [email protected]
* @author andrewleo
*
*/
public class BatteryInfoBroadcastReceiver extends BroadcastReceiver {
Expand Down Expand Up @@ -204,11 +201,11 @@ public void onStart(Intent intent, int startId) {
txtUnusedMem.setTextColor(android.graphics.Color.RED);
txtTotalMem.setTextColor(android.graphics.Color.RED);
txtTraffic.setTextColor(android.graphics.Color.RED);
imgViIcon = (ImageView) viFloatingWindow.findViewById(R.id.img2);
imgViIcon.setVisibility(View.GONE);
imgViIcon.setOnClickListener(new OnClickListener() {
btnStop = (Button) viFloatingWindow.findViewById(R.id.stop);
btnStop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
isServiceStop = true;
Toast.makeText(EmmageeService.this, "测试结果文件:" + resultFilePath, Toast.LENGTH_LONG).show();
stopSelf();
}
Expand All @@ -219,13 +216,6 @@ public void onClick(View v) {
handler.postDelayed(task, 1000);
}

/**
* 点击左上的关闭按钮可以停止测试
*/
private void closeTest() {

}

/**
* read configuration file.
*
Expand Down Expand Up @@ -278,8 +268,8 @@ private void createResultCsv() {
String totalMemory = fomart.format((double) totalMemorySize / 1024);
bw.write("指定应用的CPU内存监控情况\r\n" + "应用包名:," + packageName + "\r\n" + "应用名称: ," + processName + "\r\n" + "应用PID: ," + pid + "\r\n"
+ "机器内存大小(MB):," + totalMemory + "MB\r\n" + "机器CPU型号:," + cpuInfo.getCpuName() + "\r\n" + "机器android系统版本:,"
+ memoryInfo.getSDKVersion() + "\r\n" + "手机型号:," + memoryInfo.getPhoneType() + "\r\n" + "UID:," + uid + "\r\n"
+ "启动时间:," + START_TIME + "\r\n");
+ memoryInfo.getSDKVersion() + "\r\n" + "手机型号:," + memoryInfo.getPhoneType() + "\r\n" + "UID:," + uid + "\r\n" + "启动时间:,"
+ START_TIME + "\r\n");
bw.write("时间" + "," + "应用占用内存PSS(MB)" + "," + "应用占用内存比(%)" + "," + " 机器剩余内存(MB)" + "," + "应用占用CPU率(%)" + "," + "CPU总使用率(%)" + ","
+ "流量(KB)" + "," + "电量(%)" + "," + "电流(mA)" + "," + "温度(C)" + "," + "电压(V)" + "\r\n");
} catch (IOException e) {
Expand Down Expand Up @@ -312,22 +302,19 @@ public boolean onTouch(View v, MotionEvent event) {
y = event.getRawY() - 25;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// state = MotionEvent.ACTION_DOWN;
startX = x;
startY = y;
mTouchStartX = event.getX();
mTouchStartY = event.getY();
Log.d("startP", "startX" + mTouchStartX + "====startY" + mTouchStartY);
break;
case MotionEvent.ACTION_MOVE:
// state = MotionEvent.ACTION_MOVE;
updateViewPosition();
break;

case MotionEvent.ACTION_UP:
// state = MotionEvent.ACTION_UP;
updateViewPosition();
showImg();
// showImg();
mTouchStartX = mTouchStartY = 0;
break;
}
Expand Down Expand Up @@ -357,16 +344,17 @@ public void onClick(View v) {
});
}

/**
* show the image.
*/
private void showImg() {
if (Math.abs(x - startX) < 1.5 && Math.abs(y - startY) < 1.5 && !imgViIcon.isShown()) {
imgViIcon.setVisibility(View.VISIBLE);
} else if (imgViIcon.isShown()) {
imgViIcon.setVisibility(View.GONE);
}
}
// /**
// * show the image.
// */
// private void showImg() {
// if (Math.abs(x - startX) < 1.5 && Math.abs(y - startY) < 1.5 &&
// !btnStop.isShown()) {
// btnStop.setVisibility(View.VISIBLE);
// } else if (btnStop.isShown()) {
// btnStop.setVisibility(View.GONE);
// }
// }

private Runnable task = new Runnable() {

Expand Down Expand Up @@ -534,7 +522,9 @@ public void onDestroy() {
}

/**
* Replaces all matches for replaceType within this replaceString in file on the filePath
* Replaces all matches for replaceType within this replaceString in file on
* the filePath
*
* @param filePath
* @param replaceType
* @param replaceString
Expand Down Expand Up @@ -562,8 +552,4 @@ private void replaceFileString(String filePath, String replaceType, String repla
public IBinder onBind(Intent intent) {
return null;
}

private void is_double() {

}
}

0 comments on commit 611c969

Please sign in to comment.