Skip to content

Commit eaa0e3e

Browse files
committed
新增主页面,下拉框暂未适配。
1 parent 4b1960b commit eaa0e3e

File tree

7 files changed

+266
-17
lines changed

7 files changed

+266
-17
lines changed

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
android {
66
compileSdkVersion 30
7-
buildToolsVersion "30.0.2"
7+
buildToolsVersion '30.0.3'
88

99
defaultConfig {
1010
applicationId "com.zmide.xuexiton"

app/src/main/java/com/zmide/xuexiton/MainActivity.java

+96-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.zmide.xuexiton;
22

3+
import android.content.ClipData;
4+
import android.content.ClipboardManager;
35
import android.content.Context;
46
import android.content.DialogInterface;
57
import android.content.Intent;
@@ -57,13 +59,85 @@ public class MainActivity extends AppCompatActivity {
5759
Context mContext;
5860
boolean isVip = false;
5961

62+
63+
private Button paste;
64+
private Button search;
65+
private Button clear;
66+
private EditText question;
67+
private TextView answer01;
68+
69+
6070
@Override
6171
protected void onCreate(@Nullable Bundle savedInstanceState) {
6272
super.onCreate(savedInstanceState);
6373
setContentView(R.layout.activity_main);
6474
mContext = this;
6575

6676

77+
//主页面控件绑定
78+
paste = (Button) findViewById(R.id.paste);
79+
clear = (Button) findViewById(R.id.clear);
80+
question = (EditText) findViewById(R.id.question);
81+
search = (Button) findViewById(R.id.search);
82+
answer01 = (TextView) findViewById(R.id.answer);
83+
84+
paste.setOnClickListener(new View.OnClickListener() {
85+
@Override
86+
public void onClick(View v) {
87+
// 获取剪贴板数据
88+
String content = null;
89+
ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
90+
try {
91+
ClipData data = cm.getPrimaryClip();
92+
ClipData.Item item = data.getItemAt(0);
93+
content = item.getText().toString();
94+
question.setText(content);
95+
} catch (Exception e) {
96+
e.printStackTrace();
97+
}
98+
}
99+
});
100+
101+
clear.setOnClickListener(new View.OnClickListener() {
102+
@Override
103+
public void onClick(View v) {
104+
question.setText("");
105+
toast("已清空.....");
106+
}
107+
});
108+
109+
search.setOnClickListener(new View.OnClickListener() {
110+
@Override
111+
public void onClick(View v) {
112+
new Thread(new Runnable() {
113+
@Override
114+
public void run() {
115+
if (question.getText().toString().isEmpty()) {
116+
answer01.setText("请输入题目后搜索");
117+
toast("请输入题目后搜索");
118+
} else {
119+
answer01.setText("正在搜索中.....");
120+
toast("正在搜索中.....");
121+
searchServer searchServer = new searchServer();
122+
String answer = null;
123+
try {
124+
answer = searchServer.searchDao(question.getText().toString());
125+
answer = answer.replace("李恒雅", "查题君");
126+
answer = answer.replace("并发限制,请使用token(公众号:叛逆青年旅舍 申请)", "");
127+
answer01.setText(answer);
128+
toast(answer);
129+
} catch (Exception e) {
130+
e.printStackTrace();
131+
}
132+
}
133+
}
134+
}).start();
135+
}
136+
});
137+
138+
139+
140+
// 悬浮窗开始
67141
if (Build.VERSION.SDK_INT >= 23) {
68142
if (Settings.canDrawOverlays(MainActivity.this)) {
69143

@@ -109,11 +183,29 @@ public void onClick(View view) {
109183
mJrqqText.setOnClickListener(new View.OnClickListener() {
110184
@Override
111185
public void onClick(View view) {
112-
String group = "811831860";
186+
/*String group = "964722860";
113187
String url = "mqqwpa://im/chat?chat_type=group&uin=" + group;
114188
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
115189
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
116-
getBaseContext().startActivity(intent);
190+
getBaseContext().startActivity(intent);*/
191+
/****************
192+
*
193+
* 发起添加群流程。群号:查题君(964722860) 的 key 为: TI8c6LLADvf811TMU3SfD3Pcf50lpvLP
194+
* 调用 joinQQGroup(TI8c6LLADvf811TMU3SfD3Pcf50lpvLP) 即可发起手Q客户端申请加群 查题君(964722860)
195+
*
196+
* @param key 由官网生成的key
197+
* @return 返回true表示呼起手Q成功,返回false表示呼起失败
198+
******************/
199+
Intent intent = new Intent();
200+
intent.setData(Uri.parse("mqqopensdkapi://bizAgent/qm/qr?url=http%3A%2F%2Fqm.qq.com%2Fcgi-bin%2Fqm%2Fqr%3Ffrom%3Dapp%26p%3Dandroid%26jump_from%3Dwebapi%26k%3D" + "TI8c6LLADvf811TMU3SfD3Pcf50lpvLP"));
201+
// 此Flag可根据具体产品需要自定义,如设置,则在加群界面按返回,返回手Q主界面,不设置,按返回会返回到呼起产品界面 //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
202+
try {
203+
toast("正在加入QQ群...");
204+
startActivity(intent);
205+
} catch (Exception e) {
206+
toast("加入QQ群失败,请检查是否安装QQ客户端.");
207+
}
208+
117209
}
118210
});
119211

@@ -269,7 +361,8 @@ public void run() {
269361
}
270362

271363
// 处理接口返回脏数据
272-
dn = dn.replace("李恒雅", "好傻好天真");
364+
dn = dn.replace("李恒雅", "查题君");
365+
dn = dn.replace("并发限制,请使用token(公众号:叛逆青年旅舍 申请)", "");
273366

274367
toast(dn);
275368
setDN(dn);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.zmide.xuexiton;
2+
3+
import org.json.JSONException;
4+
import org.json.JSONObject;
5+
6+
import java.io.IOException;
7+
8+
import okhttp3.MediaType;
9+
import okhttp3.MultipartBody;
10+
import okhttp3.OkHttpClient;
11+
import okhttp3.Request;
12+
import okhttp3.RequestBody;
13+
import okhttp3.Response;
14+
15+
16+
public class searchDao {
17+
private OkHttpClient client = new OkHttpClient();
18+
19+
/*
20+
public String searchDao1(final String question) throws IOException, JSONException {
21+
new Thread(new Runnable() {
22+
@Override
23+
public void run() {
24+
try {
25+
String a = searchDao(question);
26+
} catch (IOException e) {
27+
e.printStackTrace();
28+
} catch (JSONException e) {
29+
e.printStackTrace();
30+
}
31+
}
32+
}).start();
33+
34+
35+
return question;
36+
}
37+
*/
38+
39+
public String searchDao(String question) throws IOException, JSONException {
40+
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
41+
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
42+
.addFormDataPart("question", question)
43+
.build();
44+
Request request = new Request.Builder()
45+
.url("http://cx.icodef.com/wyn-nb?v=2")
46+
.method("POST", body)
47+
.addHeader("Content-type", "application/x-www-form-urlencoded")
48+
.build();
49+
Response response = client.newCall(request).execute();
50+
String data = response.body().string();
51+
JSONObject jsonObject = new JSONObject(data);
52+
String answer = "【题库1】 " + jsonObject.getString("data");
53+
System.out.println(answer);
54+
return answer;
55+
}
56+
57+
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.zmide.xuexiton;
2+
import com.zmide.xuexiton.searchDao;
3+
4+
5+
public class searchServer {
6+
7+
public String searchDao(String question) throws Exception {
8+
searchDao searchDao = new searchDao();
9+
String answer = searchDao.searchDao(question);
10+
return answer;
11+
}
12+
}

app/src/main/res/layout/activity_main.xml

+84-12
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,96 @@
66
android:gravity="center"
77
android:orientation="vertical">
88

9+
<EditText
10+
android:id="@+id/question"
11+
android:layout_width="match_parent"
12+
android:layout_height="189dp"
13+
android:layout_marginTop="5dp"
14+
android:layout_marginLeft="10dp"
15+
android:layout_marginRight="10dp"
16+
android:hint="@string/question"
17+
android:text="" />
18+
919
<LinearLayout
1020
android:layout_width="match_parent"
1121
android:layout_height="wrap_content"
12-
android:layout_weight="1"
13-
android:gravity="center">
22+
android:orientation="horizontal"
23+
android:gravity="center"
24+
android:layout_marginBottom="15dp">
25+
<Spinner
26+
android:id="@+id/spinner"
27+
android:layout_width="wrap_content"
28+
android:layout_height="wrap_content"
29+
android:layout_weight="1"
30+
android:entries="@array/plantes"/>
31+
32+
<Button
33+
android:id="@+id/paste"
34+
android:layout_width="wrap_content"
35+
android:layout_height="wrap_content"
36+
android:text="@string/paste"/>
37+
38+
<Button
39+
android:id="@+id/search"
40+
android:layout_width="wrap_content"
41+
android:layout_height="wrap_content"
42+
android:text="@string/search"/>
43+
1444
<Button
15-
android:id="@+id/main_start_btn"
45+
android:id="@+id/clear"
1646
android:layout_width="wrap_content"
1747
android:layout_height="wrap_content"
18-
android:text="开始答题" />
48+
android:text="@string/clear" />
1949
</LinearLayout>
50+
<Button
51+
android:id="@+id/main_start_btn"
52+
android:layout_width="wrap_content"
53+
android:layout_height="wrap_content"
54+
android:text="@string/main_start_btn"
55+
android:layout_marginBottom="15dp"/>
56+
<ScrollView
57+
android:layout_width="match_parent"
58+
android:layout_height="wrap_content">
59+
60+
<LinearLayout
61+
android:orientation="vertical"
62+
android:layout_width="match_parent"
63+
android:layout_height="wrap_content">
64+
<TextView
65+
android:id="@+id/answer"
66+
android:layout_width="359dp"
67+
android:layout_height="235dp"
68+
android:text="@string/answer"
69+
android:textIsSelectable="true" />
70+
71+
</LinearLayout>
72+
</ScrollView>
73+
74+
<!-- 底部信息 -->
75+
<LinearLayout
76+
android:id="@+id/content"
77+
android:layout_width="fill_parent"
78+
android:layout_height="0dp"
79+
android:layout_weight="1"
80+
android:orientation="vertical">
81+
</LinearLayout>
82+
<LinearLayout
83+
android:layout_width="fill_parent"
84+
android:layout_height="wrap_content"
85+
android:gravity="bottom"
86+
android:orientation="vertical">
87+
<TextView
88+
android:id="@+id/main_jrqq_text"
89+
android:layout_width="wrap_content"
90+
android:layout_height="wrap_content"
91+
android:layout_alignParentBottom="true"
92+
android:textIsSelectable="true"
93+
android:layout_marginLeft="10dp"
94+
android:layout_marginRight="10dp"
95+
android:text="@string/bottom"
96+
android:gravity="center"/>
97+
</LinearLayout>
98+
2099

21100

22101

@@ -36,14 +115,7 @@
36115
android:textColor="#FFC107"
37116
android:text="305 寝室专属版,拥有安院专属题库(禁止外传)"/>
38117

39-
<TextView
40-
android:id="@+id/main_jrqq_text"
41-
android:textIsSelectable="true"
42-
android:textColor="#000"
43-
android:layout_width="wrap_content"
44-
android:layout_height="wrap_content"
45-
android:gravity="center"
46-
android:text="该项目为免费开源,禁止用于商业用途!包括但不限于出售软件,使用软件代考等一切商业用途!\n问题反馈建议QQ群(也可以加入一起唠嗑哦):811831860"/>
118+
47119
</LinearLayout>
48120

49121
</LinearLayout>

app/src/main/res/values/strings.xml

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
<resources>
22
<string name="app_name">学你🐎</string>
3+
<string name="main_start_btn">打开悬浮窗</string>
4+
<string name="paste">粘贴</string>
5+
<string name="search">搜索</string>
6+
<string name="clear">清空</string>
7+
<string name="question">请输入题目</string>
8+
<string name="answer">这是答案!!这是答案!!这是答案!!这是答案!!这是答案!!这是答案!!这是答案!!</string>
9+
<string name="bottom">该项目为免费开源,禁止用于商业用途!包括但不限于出售软件,使用软件代考等一切商业用途!\n问题反馈建议QQ群(也可以加入一起唠嗑哦):964722860(点击加群)</string>
10+
<string-array name="plantes">
11+
<item>题库1</item>
12+
<item>题库2</item>
13+
<item>题库3</item>
14+
<item>题库4</item>
15+
<item>更多题库正在添加中..</item>
16+
</string-array>
317
</resources>

floatwindow/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
22

33
android {
44
compileSdkVersion 26
5-
buildToolsVersion "26.0.2"
5+
buildToolsVersion '30.0.3'
66

77

88
defaultConfig {

0 commit comments

Comments
 (0)