From 897a20f524cd71f4433b4703318bd142526f4441 Mon Sep 17 00:00:00 2001 From: tanc <2512769611@qq.com> Date: Mon, 27 May 2024 18:22:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=B3=A8=E5=86=8C=E3=80=81=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=95=8C=E9=9D=A2=E5=AE=8C=E5=96=84=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=EF=BC=8C=E5=AE=9E=E7=8E=B0=E6=B3=A8=E5=86=8C=E3=80=81=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E3=80=81=E5=BF=98=E8=AE=B0=E5=AF=86=E7=A0=81=E3=80=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81=E7=AD=89=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E5=8C=85=E6=8B=AC=E4=B8=80=E4=BA=9B=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0=E7=BE=8E=E5=8C=96=E5=B9=B6=E5=B0=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=BF=9B=E8=A1=8C=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=94=B9=E8=BF=9B=EF=BC=8C=E4=BE=8B=E5=A6=82=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E5=9B=9E=E9=80=80=E8=B7=B3=E8=BD=AC=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 1 + src/main/AndroidManifest.xml | 14 +++- .../ChangePasswordActivity.java | 66 +++++++++++++++++ .../com/example/liyueling_final/DBTools.java | 28 +++++++ .../liyueling_final/EnrollActivity.java | 65 ++++++++++------- .../ForgetPasswordActivity.java | 20 +++++ .../liyueling_final/LoginMainActivity.java | 73 ++++++++++++------- .../com/example/liyueling_final/Serch.java | 10 +++ .../example/liyueling_final/SpActivity.java | 47 ------------ .../example/liyueling_final/Study_mulu.java | 45 ------------ .../com/example/liyueling_final/welcome.java | 45 +++++++----- src/main/res/layout/activity_enroll.xml | 11 --- src/main/res/layout/activity_serch.xml | 2 +- src/main/res/layout/activity_sp.xml | 37 ---------- 14 files changed, 249 insertions(+), 215 deletions(-) create mode 100644 src/main/java/com/example/liyueling_final/DBTools.java delete mode 100644 src/main/java/com/example/liyueling_final/SpActivity.java delete mode 100644 src/main/res/layout/activity_sp.xml diff --git a/build.gradle.kts b/build.gradle.kts index b11895c..524d285 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -50,4 +50,5 @@ dependencies { implementation ("com.squareup.okhttp3:logging-interceptor:4.9.3") implementation ("com.squareup.retrofit2:retrofit:2.9.0") implementation ("com.squareup.retrofit2:converter-gson:2.9.0") + implementation("org.greenrobot:eventbus:3.3.1") } \ No newline at end of file diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 2aa9088..90d5871 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -27,7 +27,19 @@ android:name=".LoginMainActivity" android:exported="false" /> + + + + call = api2.Enroll(phoneNumber,userPassword); - call.enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - User user = response.body(); - if (user != null && user.password.equals(userPassword)) { - Intent intent = new Intent(EnrollActivity.this, LoginMainActivity.class); - startActivity(intent); - finish(); - } else { - // 注册失败 - Toast.makeText(EnrollActivity.this, "注册失败", Toast.LENGTH_SHORT).show(); - } - } - @Override - public void onFailure(Call call, Throwable t) { - Toast.makeText(EnrollActivity.this, "Network error", Toast.LENGTH_SHORT).show(); - } - }); - } catch (Exception e) { - Log.e("YourTag", "Error occurred: " + e.getMessage()); // 打印异常信息 - } + DBTools dbTools = new DBTools(EnrollActivity.this,"test",null,1);//数据库的名字 + SQLiteDatabase sqLiteDatabase = dbTools.getWritableDatabase(); + ContentValues contentValues = new ContentValues(); + contentValues.put("phone",phoneNumber); + contentValues.put("password",userPassword); + sqLiteDatabase.insert("user",null,contentValues); + + Intent intent = new Intent(EnrollActivity.this, LoginMainActivity.class); + startActivity(intent); + finish(); } - - }); findViewById(R.id.textView174).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(EnrollActivity.this,LoginMainActivity.class); + Intent intent = new Intent(EnrollActivity.this, LoginMainActivity.class); startActivity(intent); finish(); } diff --git a/src/main/java/com/example/liyueling_final/ForgetPasswordActivity.java b/src/main/java/com/example/liyueling_final/ForgetPasswordActivity.java index 0c1d2cb..b852d1b 100644 --- a/src/main/java/com/example/liyueling_final/ForgetPasswordActivity.java +++ b/src/main/java/com/example/liyueling_final/ForgetPasswordActivity.java @@ -2,21 +2,41 @@ package com.example.liyueling_final; import androidx.appcompat.app.AppCompatActivity; +import android.animation.ObjectAnimator; +import android.animation.PropertyValuesHolder; +import android.animation.ValueAnimator; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; import android.widget.Toast; public class ForgetPasswordActivity extends AppCompatActivity { EditText yanzhen; + TextView textView; + ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forget_password); yanzhen = findViewById(R.id.password1); + textView = findViewById(R.id.textView170); + imageView = findViewById(R.id.imageView141); + + PropertyValuesHolder propertyValuesHolder = PropertyValuesHolder.ofFloat("translationY",-100,0); + PropertyValuesHolder propertyValuesHolder3 = PropertyValuesHolder.ofFloat("alpha",0,1); + PropertyValuesHolder propertyValuesHolder4 = PropertyValuesHolder.ofFloat("rotation",-15,0); + ValueAnimator animator = ObjectAnimator.ofPropertyValuesHolder(imageView,propertyValuesHolder,propertyValuesHolder4,propertyValuesHolder3); + ValueAnimator animator2 = ObjectAnimator.ofPropertyValuesHolder(textView,propertyValuesHolder,propertyValuesHolder4,propertyValuesHolder3); + animator.setDuration(1000); + animator.start(); + animator2.setDuration(1000); + animator2.start(); + findViewById(R.id.fasong).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/src/main/java/com/example/liyueling_final/LoginMainActivity.java b/src/main/java/com/example/liyueling_final/LoginMainActivity.java index e8b1153..bf7fcba 100644 --- a/src/main/java/com/example/liyueling_final/LoginMainActivity.java +++ b/src/main/java/com/example/liyueling_final/LoginMainActivity.java @@ -1,12 +1,19 @@ package com.example.liyueling_final; +import android.animation.ObjectAnimator; +import android.animation.PropertyValuesHolder; +import android.animation.ValueAnimator; +import android.annotation.SuppressLint; import android.content.Intent; import android.content.SharedPreferences; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; +import android.widget.ImageView; import android.widget.RadioButton; import android.widget.TextView; import android.widget.Toast; @@ -24,6 +31,11 @@ public class LoginMainActivity extends AppCompatActivity { private RadioButton radioButton; EditText phone; EditText password; + + TextView textView; + ImageView imageView; + boolean flag; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -32,12 +44,30 @@ public class LoginMainActivity extends AppCompatActivity { phone = findViewById(R.id.phone); password = findViewById(R.id.password1); + textView = findViewById(R.id.textView170); + imageView = findViewById(R.id.imageView141); + + PropertyValuesHolder propertyValuesHolder = PropertyValuesHolder.ofFloat("translationY", -100, 0); + PropertyValuesHolder propertyValuesHolder3 = PropertyValuesHolder.ofFloat("alpha", 0, 1); + PropertyValuesHolder propertyValuesHolder4 = PropertyValuesHolder.ofFloat("rotation", -15, 0); + ValueAnimator animator = ObjectAnimator.ofPropertyValuesHolder(imageView, propertyValuesHolder, propertyValuesHolder4, propertyValuesHolder3); + ValueAnimator animator2 = ObjectAnimator.ofPropertyValuesHolder(textView, propertyValuesHolder, propertyValuesHolder4, propertyValuesHolder3); + animator.setDuration(1000); + animator.start(); + animator2.setDuration(1000); + animator2.start(); + + DBTools dbTools = new DBTools(LoginMainActivity.this, "test", null, 1);//数据库的名字 + SQLiteDatabase sqLiteDatabase = dbTools.getWritableDatabase(); + findViewById(R.id.enter).setOnClickListener(new View.OnClickListener() { + @SuppressLint("Range") @Override public void onClick(View v) { + flag = true; String phoneNumber = phone.getText().toString(); String userPassword = password.getText().toString(); @@ -50,40 +80,29 @@ public class LoginMainActivity extends AppCompatActivity { Toast.makeText(LoginMainActivity.this, "请同意协议", Toast.LENGTH_SHORT).show(); return; } - userApi api2 = RetrofitUtils.getRetrofit("https://dev.usemock.com/664ac0559e857b0cdafce629/").create(userApi.class); - try { - Call call = api2.Login(phoneNumber); - call.enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - User user = response.body(); - if (user != null && user.password.equals(userPassword)) { - Intent intent = new Intent(LoginMainActivity.this, MainActivity.class); - startActivity(intent); - finish(); - } else { - // 登录失败 - Toast.makeText(LoginMainActivity.this, "Login failed", Toast.LENGTH_SHORT).show(); - } - } - @Override - public void onFailure(Call call, Throwable t) { - Toast.makeText(LoginMainActivity.this, "Network error", Toast.LENGTH_SHORT).show(); - } - }); - } catch (Exception e) { - Log.e("YourTag", "Error occurred: " + e.getMessage()); // 打印异常信息 + Cursor cursor = sqLiteDatabase.query("user", new String[]{"id", "phone", "password"}, + "phone=?", new String[]{phoneNumber}, null, null, null); + while (cursor.moveToNext()) { + if (cursor != null && cursor.getString(cursor.getColumnIndex("password")).equals(userPassword)) { + Intent intent = new Intent(LoginMainActivity.this, MainActivity.class); + startActivity(intent); + finish(); + flag = false; + } } + if(flag==true){ + Toast.makeText(LoginMainActivity.this, "手机号或密码不正确", Toast.LENGTH_SHORT).show(); } - - + } }); + + findViewById(R.id.textView174).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(LoginMainActivity.this,EnrollActivity.class); + Intent intent = new Intent(LoginMainActivity.this, EnrollActivity.class); startActivity(intent); finish(); } @@ -91,7 +110,7 @@ public class LoginMainActivity extends AppCompatActivity { findViewById(R.id.textView175).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(LoginMainActivity.this,ForgetPasswordActivity.class); + Intent intent = new Intent(LoginMainActivity.this, ForgetPasswordActivity.class); startActivity(intent); finish(); } diff --git a/src/main/java/com/example/liyueling_final/Serch.java b/src/main/java/com/example/liyueling_final/Serch.java index aa5bcdd..207a283 100644 --- a/src/main/java/com/example/liyueling_final/Serch.java +++ b/src/main/java/com/example/liyueling_final/Serch.java @@ -1,14 +1,24 @@ package com.example.liyueling_final; import android.os.Bundle; +import android.view.View; +import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class Serch extends AppCompatActivity { + TextView cancel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_serch); + + findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + finish(); + } + }); } } \ No newline at end of file diff --git a/src/main/java/com/example/liyueling_final/SpActivity.java b/src/main/java/com/example/liyueling_final/SpActivity.java deleted file mode 100644 index f742341..0000000 --- a/src/main/java/com/example/liyueling_final/SpActivity.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.example.liyueling_final; - -import android.content.SharedPreferences; -import android.os.Bundle; -import android.util.Log; -import android.view.View; - -import androidx.appcompat.app.AppCompatActivity; - -public class SpActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_sp); - - findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE); - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putString("name","计科一班"); - editor.putBoolean("isLogin",true); - editor.commit(); - } - }); - findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE); - String name = sharedPreferences.getString("name",""); - boolean isLogin = sharedPreferences.getBoolean("isLogin",false); - Log.i("test",name+isLogin); - } - }); - findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE); - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.clear(); - editor.commit(); - } - }); - - } -} \ No newline at end of file diff --git a/src/main/java/com/example/liyueling_final/Study_mulu.java b/src/main/java/com/example/liyueling_final/Study_mulu.java index f599bd0..6a2d2c3 100644 --- a/src/main/java/com/example/liyueling_final/Study_mulu.java +++ b/src/main/java/com/example/liyueling_final/Study_mulu.java @@ -7,53 +7,8 @@ import android.view.ViewGroup; import androidx.fragment.app.Fragment; -/** - * A simple {@link Fragment} subclass. - * Use the {@link Study_mulu#newInstance} factory method to - * create an instance of this fragment. - */ public class Study_mulu extends Fragment { - // TODO: Rename parameter arguments, choose names that match - // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; - - // TODO: Rename and change types of parameters - private String mParam1; - private String mParam2; - - public Study_mulu() { - // Required empty public constructor - } - - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param param1 Parameter 1. - * @param param2 Parameter 2. - * @return A new instance of fragment Study_mulu. - */ - // TODO: Rename and change types and number of parameters - public static Study_mulu newInstance(String param1, String param2) { - Study_mulu fragment = new Study_mulu(); - Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); - fragment.setArguments(args); - return fragment; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); - } - } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { diff --git a/src/main/java/com/example/liyueling_final/welcome.java b/src/main/java/com/example/liyueling_final/welcome.java index ace209c..1599ddf 100644 --- a/src/main/java/com/example/liyueling_final/welcome.java +++ b/src/main/java/com/example/liyueling_final/welcome.java @@ -1,5 +1,8 @@ package com.example.liyueling_final; +import android.animation.ObjectAnimator; +import android.animation.PropertyValuesHolder; +import android.animation.ValueAnimator; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; @@ -14,11 +17,10 @@ import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class welcome extends AppCompatActivity { - - private TranslateAnimation ra; - private TranslateAnimation rb; TextView textView; ImageView imageView; + ImageView imageView2; + ImageView imageView3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -26,27 +28,32 @@ public class welcome extends AppCompatActivity { textView = findViewById(R.id.textView169); imageView = findViewById(R.id.imageView); - rb = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0, - Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0.5f); + imageView2 = findViewById(R.id.enter); + imageView3 = findViewById(R.id.imageView143); + + PropertyValuesHolder propertyValuesHolder = PropertyValuesHolder.ofFloat("translationY",-100,0); + PropertyValuesHolder propertyValuesHolder3 = PropertyValuesHolder.ofFloat("alpha",0,1); + PropertyValuesHolder propertyValuesHolder4 = PropertyValuesHolder.ofFloat("rotation",-15,0); + ValueAnimator animator = ObjectAnimator.ofPropertyValuesHolder(imageView,propertyValuesHolder,propertyValuesHolder4,propertyValuesHolder3); + ValueAnimator animator2 = ObjectAnimator.ofPropertyValuesHolder(textView,propertyValuesHolder,propertyValuesHolder4,propertyValuesHolder3); + animator.setDuration(1000); + animator.start(); + animator2.setDuration(1000); + animator2.start(); - ra = new TranslateAnimation(Animation.RELATIVE_TO_SELF,-0.5f,Animation.RELATIVE_TO_SELF,0.5f, - Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0); - ra.setDuration(1000); - ra.setRepeatMode(Animation.REVERSE); - ra.setInterpolator(new AccelerateInterpolator()); - ra.setFillAfter(true); - - rb.setDuration(1000); - rb.setRepeatMode(Animation.REVERSE); - rb.setInterpolator(new AccelerateInterpolator()); - rb.setFillAfter(true); - textView.startAnimation(rb); - imageView.startAnimation(rb); + ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(imageView,"translationY",-200,0); + objectAnimator2.setDuration(1000); + objectAnimator2.start(); findViewById(R.id.enter).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - v.startAnimation(ra); + PropertyValuesHolder propertyValuesHolder = PropertyValuesHolder.ofFloat("translationX",-50,50); + PropertyValuesHolder propertyValuesHolder3 = PropertyValuesHolder.ofFloat("alpha",1,0.2f); + ValueAnimator animator = ObjectAnimator.ofPropertyValuesHolder(imageView2,propertyValuesHolder,propertyValuesHolder3); + animator.setDuration(1000); + animator.start(); + Intent intent = new Intent(welcome.this, LoginMainActivity.class); startActivity(intent); diff --git a/src/main/res/layout/activity_enroll.xml b/src/main/res/layout/activity_enroll.xml index 4ac007d..8c80efe 100644 --- a/src/main/res/layout/activity_enroll.xml +++ b/src/main/res/layout/activity_enroll.xml @@ -115,17 +115,6 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/password1" /> - - - - -