Skip to content

Commit

Permalink
refine code according to checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleo committed Feb 28, 2013
1 parent 87558e2 commit 2533df9
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 26 deletions.
10 changes: 6 additions & 4 deletions src/com/netease/qa/emmagee/activity/MainPageActivity.java
Expand Up @@ -54,16 +54,15 @@
import com.netease.qa.emmagee.R;

/**
* Main Page of Emmagee.
* @author andrewleo
* Main Page of Emmagee
*
*/
public class MainPageActivity extends Activity {

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

private final int TIMEOUT = 20000;
private static final int TIMEOUT = 20000;

private List<Programe> processList;
private ProcessInfo processInfo;
Expand Down Expand Up @@ -265,6 +264,9 @@ private class ListAdapter extends BaseAdapter {
List<Programe> programe;
int tempPosition = -1;

/**
* save status of all installed processes
*/
class Viewholder {
TextView txtAppName;
ImageView imgViAppIcon;
Expand Down
12 changes: 8 additions & 4 deletions src/com/netease/qa/emmagee/activity/SettingsActivity.java
Expand Up @@ -36,9 +36,13 @@

import com.netease.qa.emmagee.R;

/**
* Setting Page of Emmagee
*
*/
public class SettingsActivity extends Activity {

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

private CheckBox chkFloat;
Expand All @@ -64,13 +68,13 @@ public void onCreate(Bundle savedInstanceState) {
try {
raf = new RandomAccessFile(settingTempFile, "r");
String f = raf.readLine();
if (f == null || (f != null && f.equals(""))) {
if (f == null || ("".equals(f))) {
time = "5";
} else {
time = f;
}
String tag = raf.readLine();
if (tag != null && tag.equals("false")) {
if ("false".equals(tag)) {
floatingTag = false;
}
raf.close();
Expand All @@ -92,7 +96,7 @@ public void onClick(View v) {
Toast.makeText(SettingsActivity.this, "输入数据无效,请重新输入",
Toast.LENGTH_LONG).show();
edtTime.setText("");
} else if (time.equals("") || Long.parseLong(time) == 0) {
} else if ("".equals(time) || Long.parseLong(time) == 0) {
Toast.makeText(SettingsActivity.this, "输入数据为空,请重新输入",
Toast.LENGTH_LONG).show();
edtTime.setText("");
Expand Down
12 changes: 8 additions & 4 deletions src/com/netease/qa/emmagee/service/EmmageeService.java
Expand Up @@ -53,6 +53,10 @@
import com.netease.qa.emmagee.utils.MyApplication;
import com.netease.qa.emmagee.R;

/**
* Service running in background
*
*/
public class EmmageeService extends Service {

private final static String LOG_TAG = "Emmagee-"
Expand Down Expand Up @@ -151,7 +155,7 @@ private void readSettingInfo(Intent intent) {
RandomAccessFile raf = new RandomAccessFile(new File(
settingTempFile), "r");
time = raf.readLine();
isFloating = raf.readLine().equals("true") ? true : false;
isFloating = ("true".equals(raf.readLine())) ? true : false;
raf.close();
} catch (IOException e) {
time = "5";
Expand Down Expand Up @@ -322,8 +326,8 @@ private void dataRefresh() {
processCpuRatio = processInfo.get(0);
totalCpuRatio = processInfo.get(1);
trafficSize = processInfo.get(2);
if (trafficSize != null && !trafficSize.equals("")
&& !trafficSize.equals("-1")) {
if ("".equals(trafficSize)
&& !("-1".equals(trafficSize))) {
tempTraffic = Integer.parseInt(trafficSize);
if (tempTraffic > 1024) {
isMb = true;
Expand All @@ -336,7 +340,7 @@ private void dataRefresh() {
+ freeMemoryKb + "MB");
txtTotalMem.setText("占用CPU:" + processCpuRatio + "%"
+ ",总体CPU:" + totalCpuRatio + "%");
if (trafficSize.equals("-1")) {
if ("-1".equals(trafficSize)) {
txtTraffic.setText("本程序或本设备不支持流量统计");
} else if (isMb)
txtTraffic.setText("消耗流量:" + fomart.format(trafficMb)
Expand Down
21 changes: 13 additions & 8 deletions src/com/netease/qa/emmagee/utils/CpuInfo.java
Expand Up @@ -29,6 +29,10 @@
import android.content.Context;
import android.util.Log;

/**
* operate CPU information
*
*/
public class CpuInfo {

private static final String LOG_TAG = "Emmagee-"
Expand All @@ -46,7 +50,7 @@ public class CpuInfo {
private long lastestTraffic;
private long traffic;
private TrafficInfo trafficInfo;
private ArrayList<String> CpuUsedRatio;
private ArrayList<String> cpuUsedRatio;
private long totalCpu2;
private long processCpu2;
private long idleCpu2;
Expand All @@ -61,7 +65,7 @@ public CpuInfo(Context context, int pid, String uid) {
formatterFile = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
mi = new MemoryInfo();
totalMemorySize = mi.getTotalMemory();
CpuUsedRatio = new ArrayList<String>();
cpuUsedRatio = new ArrayList<String>();
}

/**
Expand Down Expand Up @@ -141,7 +145,7 @@ public ArrayList<String> getCpuRatioInfo() {
fomart.setMinimumFractionDigits(2);

readCpuStat();
CpuUsedRatio.clear();
cpuUsedRatio.clear();

try {
Calendar cal = Calendar.getInstance();
Expand All @@ -160,7 +164,8 @@ public ArrayList<String> getCpuRatioInfo() {
processCpuRatio = fomart
.format(100 * ((double) (processCpu - processCpu2) / (double) (totalCpu - totalCpu2)));
totalCpuRatio = fomart
.format(100 * ((double) ((totalCpu - idleCpu) - (totalCpu2 - idleCpu2)) / (double) (totalCpu - totalCpu2)));
.format(100 * ((double) ((totalCpu - idleCpu) - (totalCpu2 - idleCpu2))
/ (double) (totalCpu - totalCpu2)));
long pidMemory = mi.getPidMemorySize(pid, context);
String pMemory = fomart.format((double) pidMemory / 1024);
long freeMemory = mi.getFreeMemorySize(context);
Expand All @@ -186,14 +191,14 @@ public ArrayList<String> getCpuRatioInfo() {
totalCpu2 = totalCpu;
processCpu2 = processCpu;
idleCpu2 = idleCpu;
CpuUsedRatio.add(processCpuRatio);
CpuUsedRatio.add(totalCpuRatio);
CpuUsedRatio.add(String.valueOf(traffic));
cpuUsedRatio.add(processCpuRatio);
cpuUsedRatio.add(totalCpuRatio);
cpuUsedRatio.add(String.valueOf(traffic));
} catch (IOException e) {
e.printStackTrace();
// PttService.closeOpenedStream()
}
return CpuUsedRatio;
return cpuUsedRatio;

}

Expand Down
8 changes: 6 additions & 2 deletions src/com/netease/qa/emmagee/utils/MemoryInfo.java
Expand Up @@ -25,6 +25,10 @@
import android.os.Debug;
import android.util.Log;

/**
* operate memory information
*
*/
public class MemoryInfo {

private static final String LOG_TAG = "Emmagee-"
Expand Down Expand Up @@ -100,7 +104,7 @@ public int getPidMemorySize(int pid, Context context) {

/**
* get the sdk version of phone.
*
*
* @return sdk version
*/
public String getSDKVersion() {
Expand All @@ -109,7 +113,7 @@ public String getSDKVersion() {

/**
* get phone type.
*
*
* @return phone type
*/
public String getPhoneType() {
Expand Down
6 changes: 5 additions & 1 deletion src/com/netease/qa/emmagee/utils/MyApplication.java
Expand Up @@ -19,8 +19,12 @@
import android.app.Application;
import android.view.WindowManager;

/**
* my application class
*
*/
public class MyApplication extends Application {

private WindowManager.LayoutParams wmParams = new WindowManager.LayoutParams();

public WindowManager.LayoutParams getMywmParams() {
Expand Down
8 changes: 6 additions & 2 deletions src/com/netease/qa/emmagee/utils/ProcessInfo.java
Expand Up @@ -28,12 +28,16 @@
import android.content.pm.PackageManager;
import android.util.Log;

/**
* get information of processes
*
*/
public class ProcessInfo {

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

private final String PACKAGE_NAME = "com.netease.qa.emmagee";
private static final String PACKAGE_NAME = "com.netease.qa.emmagee";

/**
* get information of all running processes,including package name ,process
Expand Down
5 changes: 5 additions & 0 deletions src/com/netease/qa/emmagee/utils/Programe.java
Expand Up @@ -18,6 +18,11 @@

import android.graphics.drawable.Drawable;

/**
* details of installed processes ,including
* icon,packagename,pid,uid,processname
*
*/
public class Programe {
private Drawable icon;
private String processName;
Expand Down
6 changes: 5 additions & 1 deletion src/com/netease/qa/emmagee/utils/TrafficInfo.java
Expand Up @@ -22,6 +22,10 @@

import android.util.Log;

/**
* information of network traffic
*
*/
public class TrafficInfo {

private static final String LOG_TAG = "Emmagee-"
Expand Down Expand Up @@ -72,6 +76,6 @@ public long getTrafficInfo() {
if (rcvTraffic == -1 || sndTraffic == -1) {
return -1;
} else
return (rcvTraffic + sndTraffic);
return rcvTraffic + sndTraffic;
}
}

0 comments on commit 2533df9

Please sign in to comment.