From c273ff38ee923fe82f0073642b66ca547078bf2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BA=E5=AE=87=E6=88=90?= Date: Mon, 23 Dec 2019 10:14:47 +0800 Subject: [PATCH] [Add]: [class & onlyRead test] --- app/src/main/AndroidManifest.xml | 1 + .../main/java/com/hyc/parrot/FourActivity.kt | 24 ++++++ .../java/com/hyc/parrot/ThreeActivity.java | 80 +++++++++++++------ app/src/main/res/layout/activity_four.xml | 13 +++ app/src/main/res/layout/activity_main.xml | 20 +++++ 5 files changed, 114 insertions(+), 24 deletions(-) create mode 100644 app/src/main/java/com/hyc/parrot/FourActivity.kt create mode 100644 app/src/main/res/layout/activity_four.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 65ac360..215d3b9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,6 +19,7 @@ + \ No newline at end of file diff --git a/app/src/main/java/com/hyc/parrot/FourActivity.kt b/app/src/main/java/com/hyc/parrot/FourActivity.kt new file mode 100644 index 0000000..b929523 --- /dev/null +++ b/app/src/main/java/com/hyc/parrot/FourActivity.kt @@ -0,0 +1,24 @@ +package com.hyc.parrot + +import android.os.Bundle +import com.hyc.parrot_lib.InitCache +import kotlinx.android.synthetic.main.activity_four.tv_user + +/** + * @author: 贺宇成 + * @date: 2019-12-23 10:04 + * @desc: + */ +class FourActivity : BaseActivity() { + + @InitCache("curUser", onlyRead = true) + private lateinit var curUser: UserBean + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_four) + tv_user.text = curUser.toString() + curUser = UserBean("李四", "123", 0, 0.0f) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/hyc/parrot/ThreeActivity.java b/app/src/main/java/com/hyc/parrot/ThreeActivity.java index 1d334b3..df36b6d 100644 --- a/app/src/main/java/com/hyc/parrot/ThreeActivity.java +++ b/app/src/main/java/com/hyc/parrot/ThreeActivity.java @@ -1,9 +1,14 @@ package com.hyc.parrot; +import android.content.Intent; import android.os.Bundle; +import android.text.TextUtils; import android.util.Log; import android.view.View; +import android.widget.Button; +import android.widget.EditText; import android.widget.TextView; +import android.widget.Toast; import com.hyc.parrot_lib.InitCache; import com.hyc.parrot_lib.InitClassParam; import com.hyc.parrot_lib.InitDataStructure; @@ -23,9 +28,9 @@ public class ThreeActivity extends BaseActivity { @InitParam("int") private int i = 1; @InitParam("long") - private long l =2; + private long l = 2; @InitParam("double") - private double d=3; + private double d = 3; @InitParam("float") private float f = 8.0f; @InitParam("string") @@ -39,26 +44,31 @@ public class ThreeActivity extends BaseActivity { private UserBean user; @InitClassParam private Student student; - @InitDataStructure({"str1","str2"}) + @InitDataStructure({ "str1", "str2" }) public String[] strings; - @InitDataStructure({"int","long","double","longString","floatString"}) + @InitDataStructure({ "int", "long", "double", "longString", "floatString" }) private Bundle bundle; - @InitDataStructure({"int","long","double","longString","floatString"}) + @InitDataStructure({ "int", "long", "double", "longString", "floatString" }) private Map map; - @InitDataStructure({"int","long","double","longString","floatString"}) + @InitDataStructure({ "int", "long", "double", "longString", "floatString" }) private Set set; - @InitDataStructure({"int","long","double","longString","floatString"}) + @InitDataStructure({ "int", "long", "double", "longString", "floatString" }) private List list; - @InitDataStructure({"int","long","double","longString","floatString"}) + @InitDataStructure({ "int", "long", "double", "longString", "floatString" }) private int[] intArray; - @InitDataStructure({"int","intString"}) + @InitDataStructure({ "int", "intString" }) private int[] intArray1; private String prefix; - @InitCache(value = "clickCount",prefixKey = MyPrefixProvider.DATE) + @InitCache(value = "clickCount", prefixKey = MyPrefixProvider.DATE) private int clickCount = 0; + @InitCache("curUser") + private UserBean curUser; + + private EditText etAccount; + private EditText etPassword; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -67,40 +77,62 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_main); printParam(); final TextView tvTitle = findViewById(R.id.tv_title); - tvTitle.setText("今日共计点击了多少次:"+clickCount); + tvTitle.setText("今日共计点击了多少次:" + clickCount); tvTitle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - tvTitle.setText("今日共计点击了多少次:"+(++clickCount)); + tvTitle.setText("今日共计点击了多少次:" + (++clickCount)); } }); + initUser(); } - private void printParam(){ + private void initUser() { + etAccount = findViewById(R.id.et_account); + etPassword = findViewById(R.id.et_password); + if (curUser != null) { + etAccount.setText(curUser.getUsername()); + etPassword.setText(curUser.getPassword()); + } + Button button = findViewById(R.id.btn_login); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (TextUtils.isEmpty(etAccount.getText().toString()) || TextUtils.isEmpty(etPassword.getText().toString())){ + Toast.makeText(ThreeActivity.this, "账号密码不能为空", Toast.LENGTH_SHORT).show(); + return; + } + curUser = + new UserBean(etAccount.getText().toString(), etPassword.getText().toString(), 0, 0); + startActivity(new Intent(ThreeActivity.this,FourActivity.class)); + } + }); + } + + private void printParam() { Log.d("ThreeActivity", String.valueOf(i)); Log.d("ThreeActivity", String.valueOf(l)); Log.d("ThreeActivity", String.valueOf(d)); Log.d("ThreeActivity", String.valueOf(f)); Log.d("ThreeActivity", s); - Log.d("ThreeActivity",userBean.toString()); + Log.d("ThreeActivity", userBean.toString()); Log.d("ThreeActivity", String.valueOf(intString)); Log.d("ThreeActivity", String.valueOf(longString)); Log.d("ThreeActivity", String.valueOf(doubleString)); Log.d("ThreeActivity", String.valueOf(floatString)); - Log.d("ThreeActivity",user.toString()); - Log.d("ThreeActivity",student.toString()); + Log.d("ThreeActivity", user.toString()); + Log.d("ThreeActivity", student.toString()); for (String string : strings) { - Log.d("ThreeActivity","数组:"+string); + Log.d("ThreeActivity", "数组:" + string); } - Log.d("ThreeActivity",""+map.size()); - Log.d("ThreeActivity",""+bundle.keySet().size()); - Log.d("ThreeActivity",""+set.size()); - Log.d("ThreeActivity",""+list.size()); - Log.d("ThreeActivity",""+intArray.length); + Log.d("ThreeActivity", "" + map.size()); + Log.d("ThreeActivity", "" + bundle.keySet().size()); + Log.d("ThreeActivity", "" + set.size()); + Log.d("ThreeActivity", "" + list.size()); + Log.d("ThreeActivity", "" + intArray.length); for (int i1 : intArray) { - Log.d("ThreeActivity","intArray1 "+i1); + Log.d("ThreeActivity", "intArray1 " + i1); } } - } diff --git a/app/src/main/res/layout/activity_four.xml b/app/src/main/res/layout/activity_four.xml new file mode 100644 index 0000000..4867b17 --- /dev/null +++ b/app/src/main/res/layout/activity_four.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4b095b7..d921954 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -14,6 +14,26 @@ android:layout_height="wrap_content" android:text="Hello World!" /> + + + +