Skip to content

Commit e55332f

Browse files
author
likai.yang
committed
优化配置管理页面
1 parent 0bca3d2 commit e55332f

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

app/src/main/java/com/kevin/testool/activity/ConfigActivity.java

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
import android.support.v7.app.AlertDialog;
77
import android.os.Bundle;
88
import android.view.LayoutInflater;
9+
import android.view.Menu;
10+
import android.view.MenuInflater;
11+
import android.view.MenuItem;
912
import android.view.View;
1013
import android.view.ViewGroup;
1114
import android.widget.EditText;
1215
import android.widget.LinearLayout;
1316
import android.widget.ScrollView;
1417
import android.widget.TextView;
15-
1618
import com.kevin.share.Common;
1719
import com.kevin.share.utils.ToastUtils;
18-
import com.kevin.share.utils.logUtil;
1920
import com.kevin.testool.MyApplication;
2021
import com.kevin.testool.R;
2122

@@ -52,10 +53,10 @@ protected void onCreate(Bundle savedInstanceState) {
5253
LinearLayout viewItem = new LinearLayout(this);
5354
LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(
5455
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
55-
vp.setMargins(15, 5, 15, 5);
56+
vp.setMargins(15, 5, 15, 20);
5657
viewItem.setLayoutParams(vp);//设置布局参数
5758
viewItem.setOrientation(LinearLayout.VERTICAL);// 设置子View的Linearlayout// 为垂直方向布局
58-
viewItem.setBackgroundColor(getResources().getColor(R.color.alice_blue));
59+
viewItem.setBackgroundColor(getResources().getColor(R.color.white));
5960

6061
TextView tv1 = new TextView(this);
6162
TextView tv2 = new TextView(this);
@@ -98,6 +99,55 @@ public void onClick(View view) {
9899

99100
}
100101

102+
@Override
103+
public boolean onCreateOptionsMenu(Menu menu){
104+
MenuInflater inflater = getMenuInflater();
105+
inflater.inflate(R.menu.menu_config, menu);
106+
return true;
107+
}
108+
109+
@Override
110+
public boolean onOptionsItemSelected(MenuItem item) {
111+
int id = item.getItemId();
112+
if (id == R.id.toConfigDetail) {
113+
AlertDialog.Builder popWindow = new AlertDialog.Builder(ConfigActivity.this);
114+
View dialogView = LayoutInflater.from(ConfigActivity.this).inflate(R.layout.case_detail,null);
115+
//设置对话框标题
116+
popWindow.setTitle("配置文件");
117+
// 设置对话框消息
118+
popWindow.setView(dialogView);
119+
// String res = FileUtils.readJsonFile(CONFIG_FILE);
120+
String res = Common.reloadCONFIG().toString();
121+
final TextView case_detail = dialogView.findViewById(R.id.case_detail);
122+
case_detail.setText(res.replace("}},","}},\n").replace("\",", "\",\n").replace("\n\n", "\n"));
123+
case_detail.setTextIsSelectable(true);
124+
125+
// 添加选择按钮并注册监听
126+
popWindow.setPositiveButton("编辑", (dialog, which) -> {
127+
AlertDialog.Builder editWindow = new AlertDialog.Builder(ConfigActivity.this);
128+
View editWindowView = LayoutInflater.from(MyApplication.getContext()).inflate(R.layout.case_edit,null);
129+
// editWindow.setTitle("编辑用例");
130+
editWindow.setView(editWindowView);
131+
final EditText et = editWindowView.findViewById(R.id.caseEdit);
132+
et.setText(res.replace("}},","}},\n").replace("\",", "\",\n").replace("\n\n", "\n"));
133+
editWindow.setPositiveButton("保存", (dialog1, which1) -> {
134+
Common.updateCONFIG(et.getText().toString());
135+
136+
});
137+
editWindow.setNegativeButton("取消", null);
138+
editWindow.show();
139+
});
140+
popWindow.setNegativeButton("关闭", null);
141+
//对话框显示
142+
popWindow.show();
143+
144+
145+
return true;
146+
}
147+
148+
return super.onOptionsItemSelected(item);
149+
}
150+
101151
private Object exchangeType(String value, String theType) throws Exception {
102152
switch (theType) {
103153
case "Integer":
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:tools="http://schemas.android.com/tools"
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto">
5+
6+
<item
7+
android:id="@+id/toConfigDetail"
8+
android:icon="@android:drawable/ic_menu_set_as"
9+
android:orderInCategory="100"
10+
android:title="@string/config"
11+
app:showAsAction="always" />
12+
13+
</menu>

0 commit comments

Comments
 (0)