提交 5d166f8b 编写于 作者: L Liu Xiao 提交者: GitHub

Merge pull request #86 from NetEase/develop

Develop
......@@ -9,5 +9,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="lib" path="libs/commons-io-2.5.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.netease.qa.emmagee"
android:versionCode="32"
android:versionName="2.4.1" >
<uses-sdk android:minSdkVersion="8" />
<application android:name=".utils.MyApplication"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<application
android:name=".utils.MyApplication"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
<activity
android:name=".activity.MainPageActivity"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
android:name=".activity.MainPageActivity"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleInstance"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.SettingsActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:theme="@style/customTheme" />
<activity
android:name=".activity.AboutActivity"
android:screenOrientation="portrait" />
<activity
android:name=".activity.MailSettingsActivity"
android:screenOrientation="portrait" />
<activity
android:name=".activity.TestListActivity"
android:screenOrientation="portrait" />
<activity
android:name=".activity.TestReportActivity"
android:screenOrientation="portrait" />
<activity android:name=".activity.SettingsActivity"
android:theme="@style/customTheme"
android:screenOrientation="portrait"/>
<activity android:name=".activity.AboutActivity"
android:screenOrientation="portrait"/>
<activity android:name=".activity.MailSettingsActivity"
android:screenOrientation="portrait"/>
<service android:name="com.netease.qa.emmagee.service.EmmageeService"/>
<service android:name="com.netease.qa.emmagee.service.EmmageeService" />
</application>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_LOGS"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>
\ No newline at end of file
......@@ -8,4 +8,4 @@
# project structure.
# Project target.
target=android-8
target=android-19
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="@color/gray" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
</shape>
\ No newline at end of file
......@@ -104,6 +104,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:clickable="false"
android:background="@drawable/custom_checkbox"
android:button="@null"
android:checked="true"
......@@ -131,12 +132,41 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:clickable="false"
android:background="@drawable/custom_checkbox"
android:button="@null"
android:checked="true"
android:paddingLeft="@dimen/image_padding"
android:paddingRight="@dimen/image_padding" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/wake_lock_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="@dimen/layout_vertical_margin_small" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wake_lock"
android:textColor="@color/black"
android:textSize="@dimen/text_size" />
<CheckBox
android:id="@+id/wake_lock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:clickable="false"
android:background="@drawable/custom_checkbox"
android:button="@null"
android:checked="false"
android:paddingLeft="@dimen/image_padding"
android:paddingRight="@dimen/image_padding" />
</RelativeLayout>
<LinearLayout
android:id="@+id/heap_item"
......@@ -169,6 +199,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:clickable="false"
android:background="@drawable/custom_checkbox"
android:button="@null"
android:checked="false"
......@@ -185,7 +216,38 @@
android:layout_marginTop="@dimen/textview_horizontal_margin"
android:background="@color/white"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/test_report"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="@dimen/layout_vertical_margin_small" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test_report"
android:textColor="@color/black"
android:textSize="@dimen/text_size" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/right_arrow"
android:textSize="@dimen/text_size" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/line_height"
android:background="@color/light_gray" />
<LinearLayout
android:id="@+id/mail_settings"
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/attrib_name"
android:textStyle="bold"/>
<TextView
android:id="@+id/attrib_value"
android:gravity="right"
android:textStyle="normal"/>
</LinearLayout>
<?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: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" >
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/navigation_bar" />
</LinearLayout>
<ListView
android:id="@+id/test_list"
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>
\ No newline at end of file
<?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:orientation="horizontal" >
<TextView
android:id="@+id/package_name"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:ellipsize="end"
android:textSize="18sp"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="#5B5B5B"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
</LinearLayout>
\ No newline at end of file
<?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:background="@color/light_purple"
android:orientation="vertical" >
<LinearLayout
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" />
</LinearLayout>
<ScrollView
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="horizontal|vertical" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableLayout
android:id="@+id/table_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp" >
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
\ No newline at end of file
......@@ -89,4 +89,8 @@
<string name="update_list">列表更新成功</string>
<string name="nougat_warning">由于Google的限制,Emmagee无法支持7.0及以上版本</string>
<string name="wake_lock">屏幕保持常亮</string>
<string name="wake_lock_on_toast">WakeLock已开启,屏幕会保持常亮</string>
<string name="test_report">测试报告</string>
</resources>
......@@ -88,4 +88,7 @@
<string name="update_list">Update List Successfully</string>
<string name="nougat_warning">Don\'t support 7.0 and above while Google has restricted access to shell commands and file system</string>
<string name="wake_lock">WakeLock</string>
<string name="wake_lock_on_toast">WakeLock is on,screen will stay awake</string>
<string name="test_report">Test Reports</string>
</resources>
......@@ -23,12 +23,15 @@ import com.netease.qa.emmagee.R;
import com.netease.qa.emmagee.service.EmmageeService;
import com.netease.qa.emmagee.utils.ProcessInfo;
import com.netease.qa.emmagee.utils.Programe;
import com.netease.qa.emmagee.utils.Settings;
import com.netease.qa.emmagee.utils.WakeLockHelper;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
......@@ -83,6 +86,7 @@ public class MainPageActivity extends Activity {
setContentView(R.layout.mainpage);
initTitleLayout();
loadSettings();
processInfo = new ProcessInfo();
btnTest.setOnClickListener(new OnClickListener() {
@Override
......@@ -177,6 +181,15 @@ public class MainPageActivity extends Activity {
btnTest = (Button) findViewById(R.id.test);
layBtnSet = (LinearLayout) findViewById(R.id.lay_btn_set);
}
private void loadSettings() {
SharedPreferences preferences = Settings.getDefaultSharedPreferences(this);
boolean wakeLock = preferences.getBoolean(Settings.KEY_WACK_LOCK, false);
if (wakeLock) {
Toast.makeText(this, R.string.wake_lock_on_toast, Toast.LENGTH_LONG).show();
Settings.getDefaultWakeLock(this).acquireFullWakeLock();
}
}
/**
* customized BroadcastReceiver
......@@ -248,8 +261,7 @@ public class MainPageActivity extends Activity {
Log.d(LOG_TAG, "stop service");
stopService(monitorService);
}
Log.d(LOG_TAG, "exit Emmagee");
finish();
System.exit(0);
}
return true;
}
......@@ -349,7 +361,7 @@ public class MainPageActivity extends Activity {
@Override
protected void onDestroy() {
unregisterReceiver(receiver);
super.onDestroy();
unregisterReceiver(receiver);
}
}
......@@ -20,6 +20,7 @@ import java.io.DataOutputStream;
import com.netease.qa.emmagee.R;
import com.netease.qa.emmagee.utils.Settings;
import com.netease.qa.emmagee.utils.WakeLockHelper;
import android.app.Activity;
import android.content.Intent;
......@@ -50,11 +51,14 @@ public class SettingsActivity extends Activity {
private CheckBox chkFloat;
private CheckBox chkRoot;
private CheckBox chkAutoStop;
private CheckBox chkWakeLock;
private TextView tvTime;
private LinearLayout about;
private LinearLayout mailSettings;
private LinearLayout testReport;
private SharedPreferences preferences;
private WakeLockHelper wakeLockHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -63,19 +67,24 @@ public class SettingsActivity extends Activity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.settings);
wakeLockHelper = Settings.getDefaultWakeLock(this);
// init views
chkFloat = (CheckBox) findViewById(R.id.floating);
chkRoot = (CheckBox) findViewById(R.id.is_root);
chkAutoStop = (CheckBox) findViewById(R.id.auto_stop);
chkWakeLock = (CheckBox) findViewById(R.id.wake_lock);
tvTime = (TextView) findViewById(R.id.time);
testReport = (LinearLayout) findViewById(R.id.test_report);
about = (LinearLayout) findViewById(R.id.about);
mailSettings = (LinearLayout) findViewById(R.id.mail_settings);
SeekBar timeBar = (SeekBar) findViewById(R.id.timeline);
ImageView btnSave = (ImageView) findViewById(R.id.btn_set);
RelativeLayout floatingItem = (RelativeLayout) findViewById(R.id.floating_item);
RelativeLayout autoStopItem = (RelativeLayout) findViewById(R.id.auto_stop_item);
RelativeLayout wakeLockItem = (RelativeLayout) findViewById(R.id.wake_lock_item);
LinearLayout layGoBack = (LinearLayout) findViewById(R.id.lay_go_back);
LinearLayout layHeapItem = (LinearLayout) findViewById(R.id.heap_item);
btnSave.setVisibility(ImageView.INVISIBLE);
......@@ -84,11 +93,19 @@ public class SettingsActivity extends Activity {
boolean isfloat = preferences.getBoolean(Settings.KEY_ISFLOAT, true);
boolean isRoot = preferences.getBoolean(Settings.KEY_ROOT, false);
boolean autoStop = preferences.getBoolean(Settings.KEY_AUTO_STOP, true);
boolean wakeLock = preferences.getBoolean(Settings.KEY_WACK_LOCK, false);
tvTime.setText(String.valueOf(interval));
chkFloat.setChecked(isfloat);
chkRoot.setChecked(isRoot);
chkAutoStop.setChecked(autoStop);
chkWakeLock.setChecked(wakeLock);
// start activity listener
layGoBack.setOnClickListener(startActivityListener(MainPageActivity.class));
testReport.setOnClickListener(startActivityListener(TestListActivity.class));
mailSettings.setOnClickListener(startActivityListener(MailSettingsActivity.class));
about.setOnClickListener(startActivityListener(AboutActivity.class));
timeBar.setProgress(interval);
timeBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
......@@ -109,34 +126,6 @@ public class SettingsActivity extends Activity {
}
});
layGoBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
SettingsActivity.this.finish();
Intent intent = new Intent();
intent.setClass(SettingsActivity.this, MainPageActivity.class);
startActivity(intent);
}
});
mailSettings.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent();
intent.setClass(SettingsActivity.this, MailSettingsActivity.class);
startActivity(intent);
}
});
about.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent();
intent.setClass(SettingsActivity.this, AboutActivity.class);
startActivity(intent);
}
});
floatingItem.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
......@@ -155,6 +144,20 @@ public class SettingsActivity extends Activity {
}
});
wakeLockItem.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
boolean isChecked = chkWakeLock.isChecked();
chkWakeLock.setChecked(!isChecked);
preferences.edit().putBoolean(Settings.KEY_WACK_LOCK, !isChecked).commit();
if (chkWakeLock.isChecked()) {
wakeLockHelper.acquireFullWakeLock();
} else {
wakeLockHelper.releaseWakeLock();
}
}
});
// get root permission
layHeapItem.setOnClickListener(new OnClickListener() {
@Override
......@@ -181,11 +184,17 @@ public class SettingsActivity extends Activity {
});
}
@Override
public void finish() {
super.finish();
}
private OnClickListener startActivityListener(final Class<?> specClass) {
return new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent();
intent.setClass(SettingsActivity.this, specClass);
startActivityForResult(intent, Activity.RESULT_FIRST_USER);
}
};
}
@Override
protected void onDestroy() {
super.onDestroy();
......
/*
* Copyright (c) 2012-2013 NetEase, Inc. and other contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.netease.qa.emmagee.activity;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.netease.qa.emmagee.R;
import com.netease.qa.emmagee.utils.Settings;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
/**
* Test Report
*
* @author andrewleo
*/
public class TestListActivity extends Activity {
private static final String LOG_TAG = "Emmagee-"
+ TestListActivity.class.getSimpleName();
static final String CSV_PATH_KEY = "csvPath";
private ListAdapter la;
private ListView lstViReport;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(LOG_TAG, "onCreate");
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.test_list);
TextView title = (TextView)findViewById(R.id.nb_title);
lstViReport = (ListView)findViewById(R.id.test_list);
ImageView btnSave = (ImageView) findViewById(R.id.btn_set);
btnSave.setVisibility(ImageView.INVISIBLE);
title.setText(R.string.test_report);
LinearLayout layGoBack = (LinearLayout) findViewById(R.id.lay_go_back);
layGoBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
TestListActivity.this.finish();
}
});
la = new ListAdapter(listReports());
lstViReport.setAdapter(la);
lstViReport.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent();
intent.setClass(TestListActivity.this, TestReportActivity.class);
intent.putExtra(CSV_PATH_KEY, la.getCSVPath(i));
startActivity(intent);
}
});
}
/**
* customizing adapter.
*
* @author andrewleo
*/
private class ListAdapter extends BaseAdapter {
List<String> reports;
public ListAdapter(List<String> reports) {
this.reports = reports;
}
@Override
public int getCount() {
return reports.size();
}
@Override
public Object getItem(int position) {
return reports.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public String getCSVPath(int position) {
return Settings.EMMAGEE_RESULT_DIR + getItem(position) + ".csv";
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
String pr = (String) reports.get(position);
if (convertView == null)
convertView = getLayoutInflater().inflate(R.layout.test_list_item, parent, false);
Viewholder holder = (Viewholder) convertView.getTag();
if (holder == null) {
holder = new Viewholder();
convertView.setTag(holder);
holder.name = (TextView) convertView.findViewById(R.id.package_name);
}
holder.name.setText(pr);
return convertView;
}
}
private static class Viewholder {
TextView name;
}
/**
* list all test report
*/
private ArrayList<String> listReports() {
ArrayList<String> reportList = new ArrayList<String>();
File reportDir = new File(Settings.EMMAGEE_RESULT_DIR);
if (reportDir.isDirectory()) {
File files[] = reportDir.listFiles();
Arrays.sort(files, Collections.reverseOrder());
for (File file: files) {
if (isLegalReport(file)) {
String baseName = file.getName().substring(0, file.getName().lastIndexOf("."));
reportList.add(baseName);
}
}
}
return reportList;
}
private boolean isLegalReport(File file) {
return !file.isDirectory() && file.getName().endsWith(".csv");
}
}
/*
* Copyright (c) 2012-2013 NetEase, Inc. and other contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.netease.qa.emmagee.activity;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import com.netease.qa.emmagee.R;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
/**
* About Page of Emmagee
*
* @author andrewleo
*/
public class TestReportActivity extends Activity {
private static final String LOG_TAG = "Emmagee-" + TestReportActivity.class.getSimpleName();
private TableLayout tl;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(LOG_TAG, "onCreate");
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.test_report);
TextView title = (TextView) findViewById(R.id.nb_title);
ImageView btnSave = (ImageView) findViewById(R.id.btn_set);
tl = (TableLayout) findViewById(R.id.table_layout);
btnSave.setVisibility(ImageView.INVISIBLE);
title.setText(R.string.test_report);
LinearLayout layGoBack = (LinearLayout) findViewById(R.id.lay_go_back);
layGoBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
TestReportActivity.this.finish();
}
});
Intent intent = getIntent();
String csvPath = intent.getStringExtra(TestListActivity.CSV_PATH_KEY);
try {
String content = FileUtils.readFileToString(new File(csvPath), "gbk");
String[] lines = content.split("\r\n");
int index = 0;
for (String line: lines) {
addTableRow(line, index);
index++;
}
} catch (IOException e) {
e.printStackTrace();
}
}
private void addTableRow(String line, int index) {
TableRow row = new TableRow(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
row.setLayoutParams(lp);
String[] items = line.split(",");
int i = 0;
for (String item: items) {
TextView tv = new TextView(this);
tv.setTextColor(Color.BLACK);
tv.setTextSize(18);
tv.setText(item);
tv.setBackgroundResource(R.drawable.table_border);
if (i != 0) {
tv.setGravity(Gravity.RIGHT);
}
row.addView(tv, i);
i++;
}
tl.addView(row, index);
}
}
......@@ -277,28 +277,13 @@ public class EmmageeService extends Service {
private void createResultCsv() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
String mDateTime;
String heapData = "";
if ((Build.MODEL.equals("sdk")) || (Build.MODEL.equals("google_sdk")))
mDateTime = formatter.format(cal.getTime().getTime() + 8 * 60 * 60
* 1000);
else
mDateTime = formatter.format(cal.getTime().getTime());
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
// 在4.0以下的低版本上/sdcard连接至/mnt/sdcard,而4.0以上版本则连接至/storage/sdcard0,所以有外接sdcard,/sdcard路径一定存在
resultFilePath = "/sdcard" + File.separator + "Emmagee_TestResult_"
+ mDateTime + ".csv";
// resultFilePath =
// android.os.Environment.getExternalStorageDirectory() +
// File.separator + "Emmagee_TestResult_" + mDateTime + ".csv";
} else {
resultFilePath = getBaseContext().getFilesDir().getPath()
+ File.separator + "Emmagee_TestResult_" + mDateTime
+ ".csv";
}
String mDateTime = formatter.format(cal.getTime().getTime());
resultFilePath = Settings.EMMAGEE_RESULT_DIR + mDateTime + "_" + packageName
+ ".csv";
try {
File resultFile = new File(resultFilePath);
resultFile.getParentFile().mkdirs();
resultFile.createNewFile();
out = new FileOutputStream(resultFile);
osw = new OutputStreamWriter(out);
......@@ -598,10 +583,6 @@ public class EmmageeService extends Service {
public void closeOpenedStream() {
try {
if (bw != null) {
bw.write(getString(R.string.comment1) + Constants.LINE_END
+ getString(R.string.comment2) + Constants.LINE_END
+ getString(R.string.comment3) + Constants.LINE_END
+ getString(R.string.comment4) + Constants.LINE_END);
bw.close();
}
if (osw != null)
......
......@@ -16,6 +16,8 @@
*/
package com.netease.qa.emmagee.utils;
import java.io.File;
import android.app.Application;
import android.view.WindowManager;
......@@ -31,4 +33,19 @@ public class MyApplication extends Application {
public WindowManager.LayoutParams getMywmParams() {
return wmParams;
}
@Override
public void onCreate() {
initAppConfig();
super.onCreate();
}
private void initAppConfig() {
// create directory of emmagee
File dir = new File(Settings.EMMAGEE_RESULT_DIR);
if (!dir.exists()) {
dir.mkdirs();
}
}
}
......@@ -20,9 +20,19 @@ public final class Settings {
public static final String KEY_INTERVAL = "interval";
public static final String KEY_ROOT = "root";
public static final String KEY_AUTO_STOP = "autoStop";
public static final String KEY_WACK_LOCK = "wakeLock";
public static final String EMMAGEE_RESULT_DIR = "/sdcard/Emmagee/";
private static WakeLockHelper wakeLockHelper;
public static SharedPreferences getDefaultSharedPreferences(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context);
}
public static WakeLockHelper getDefaultWakeLock(Context context) {
if (wakeLockHelper == null) {
wakeLockHelper = new WakeLockHelper(context);
}
return wakeLockHelper;
}
}
package com.netease.qa.emmagee.utils;
import android.content.Context;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
public class WakeLockHelper {
private WakeLock wakeLock = null;
private Context context;
public WakeLockHelper(Context context) {
this.context = context;
}
public void acquireFullWakeLock() {
if (null == wakeLock) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "WakeLock");
}
wakeLock.acquire();
}
public void releaseWakeLock() {
if (null != wakeLock) {
wakeLock.release();
wakeLock = null;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册