From 2fabb721734ce4ca15c23139abec5e003b52e709 Mon Sep 17 00:00:00 2001
From: Administrator <1512995449@qq.com>
Date: Fri, 3 Jan 2020 09:38:51 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8D=90=E6=AC=BE=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/src/main/AndroidManifest.xml | 3 +-
.../hunnu/sj/raise_money/DonateActivity.java | 155 ++++++++++++++++++
.../sj/raise_money/NewsContentActivity.java | 14 ++
app/src/main/res/layout/activity_donate.xml | 97 +++++++++++
4 files changed, 268 insertions(+), 1 deletion(-)
create mode 100644 app/src/main/java/hunnu/sj/raise_money/DonateActivity.java
create mode 100644 app/src/main/res/layout/activity_donate.xml
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index b79be0e..1702735 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -11,7 +11,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
-
+
+
diff --git a/app/src/main/java/hunnu/sj/raise_money/DonateActivity.java b/app/src/main/java/hunnu/sj/raise_money/DonateActivity.java
new file mode 100644
index 0000000..18547db
--- /dev/null
+++ b/app/src/main/java/hunnu/sj/raise_money/DonateActivity.java
@@ -0,0 +1,155 @@
+package hunnu.sj.raise_money;
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.Toast;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class DonateActivity extends AppCompatActivity {
+ Handler mHandler = new Handler(){//用于处理子线程传回的消息,对主线的UI进行修改
+ int flag = -1;
+ @Override
+ public void handleMessage(@NonNull Message msg) {
+ super.handleMessage(msg);
+ String txt;
+ switch (msg.what){
+ case 1:
+ flag = 1;
+ txt = (String) msg.obj;
+ number.setError(txt);
+ break;
+ case 2:
+ flag= 2;
+ txt = (String) msg.obj;
+ money.setError(txt);
+ case 3:
+ flag=3;
+ txt = (String) msg.obj;
+ name.setError(txt);
+ }
+
+ }
+ };
+ EditText name;
+ EditText number;
+ EditText money;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_donate);
+// Button commit = (Button) findViewById(R.id.commit);
+// commit.setOnClickListener(new View.OnClickListener() {
+// @Override
+// public void onClick(View v) {
+// Intent intent;
+// intent = new Intent(MainActivity.this,aActivity.class);
+// startActivity(intent);
+// }
+// });
+ }
+ public void onToMain(View view){
+ Intent intent = new Intent(DonateActivity.this, MainActivity.class);
+ startActivity(intent);
+ // MessageCommit();
+ }
+
+ public void onClick(View view){
+ name=findViewById(R.id.Name);
+ number=findViewById(R.id.TeleNumber);
+ money=findViewById(R.id.Money);
+ new CommitThread().start();
+
+ }
+ // private void MessageCommit(){
+// if(judge()){
+// startActivity(intent);
+// }
+//
+// }
+// private boolean judge(){
+//
+// }
+ private int judgenum(String num){
+ if(num.length()!=11) return 1;
+ Pattern p = null;
+ Matcher m = null;
+ boolean b = false;
+ p = Pattern.compile("^[1][3,5,8][0-9]{9}$"); // 验证手机号
+ m = p.matcher(num);
+ b = m.matches();
+ if(!b) return 2;
+ return 3;
+ }
+ private int judgemon(String mon){
+ String reg_money = "\\d+(\\.\\d{1,2})?";// 金额正则,可以没有小数,小数最多不超过两位
+ Pattern pattern = Pattern.compile(reg_money);
+ Matcher matcher = pattern.matcher(mon);
+ boolean ismatch = matcher.matches();
+ if(ismatch) return 1;
+ return 0;
+ }
+ private int judgenam(String nam){
+ String regEx = "[\u4E00-\u9FA5]{2,5}(?:·[\u4E00-\u9FA5]{2,5})*";
+ Pattern pattern = Pattern.compile(regEx);
+ Matcher matcher = pattern.matcher(nam);
+
+
+ boolean isMatch = matcher.matches();
+ if (isMatch) return 1;
+ return 0;
+ }
+ class CommitThread extends Thread{
+ @Override
+ public void run() {
+ int flag = -1;//先设置flag为-1
+ int flag1=-1;
+ int flag11=-1;
+ String mon = money.getText().toString();
+ String num = number.getText().toString();
+ String nam=name.getText().toString();
+ flag = judgenum(num);//用login函数来判断用户输入的用户名与密码是否正确
+ flag1=judgemon(mon);
+ flag11=judgenam(nam);
+ Message message = mHandler.obtainMessage();
+
+ if(flag==1){
+ message.what = 1;
+ message.obj = "电话号码位数不对";
+ mHandler.sendMessage(message);
+ }
+ else if(flag==2){
+ message.what = 1;
+ message.obj = "请输入正确的电话号码";
+ mHandler.sendMessage(message);
+ }
+ else if(flag1==0){
+ message.what = 2;
+ message.obj = "金额输入不对";
+ mHandler.sendMessage(message);
+ }else if(flag11==0){
+ message.what = 3;
+ message.obj = "姓名输入不对";
+ mHandler.sendMessage(message);
+ }
+ else{
+ Looper.prepare();
+ Toast toast=Toast.makeText(DonateActivity.this, "提交成功",Toast.LENGTH_LONG);
+ toast.setGravity(Gravity.CENTER, 100, 100);
+ toast.show();
+ Looper.loop();
+ finish();
+ }
+
+ }
+
+
+ }
+}
diff --git a/app/src/main/java/hunnu/sj/raise_money/NewsContentActivity.java b/app/src/main/java/hunnu/sj/raise_money/NewsContentActivity.java
index 30b1c03..b37ff5f 100644
--- a/app/src/main/java/hunnu/sj/raise_money/NewsContentActivity.java
+++ b/app/src/main/java/hunnu/sj/raise_money/NewsContentActivity.java
@@ -4,7 +4,9 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
+import android.view.View;
import android.view.Window;
+import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
@@ -26,7 +28,19 @@ public class NewsContentActivity extends AppCompatActivity{
NewsContentFragment newsContentFragment = (NewsContentFragment)
getFragmentManager().findFragmentById(R.id.news_content_fragment);
newsContentFragment.refresh(newsTitle, newsContent); // 刷新NewsContentFragment界面
+ onToDonate();
}
+ public void onToDonate( ){
+ Button button1 = (Button) findViewById(R.id.button);//id后面为上方button的id
+ button1.setOnClickListener(new View.OnClickListener() {
+
+ public void onClick(View v) {
+ Intent intent1 = new Intent();
+ intent1.setClass(NewsContentActivity.this, DonateActivity.class);//this前面为当前activty名称,class前面为要跳转到得activity名称
+ startActivity(intent1);
+ }
+ });
+ }
}
diff --git a/app/src/main/res/layout/activity_donate.xml b/app/src/main/res/layout/activity_donate.xml
new file mode 100644
index 0000000..8e8ec3e
--- /dev/null
+++ b/app/src/main/res/layout/activity_donate.xml
@@ -0,0 +1,97 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file