Skip to content

Commit

Permalink
[Add]: [class & onlyRead test]
Browse files Browse the repository at this point in the history
  • Loading branch information
old-traveler committed Dec 23, 2019
1 parent b96711e commit c273ff3
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 24 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</activity>
<activity android:name=".SecondActivity"/>
<activity android:name=".ThreeActivity"/>
<activity android:name=".FourActivity"/>
</application>

</manifest>
24 changes: 24 additions & 0 deletions app/src/main/java/com/hyc/parrot/FourActivity.kt
Original file line number Diff line number Diff line change
@@ -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)
}

}
80 changes: 56 additions & 24 deletions app/src/main/java/com/hyc/parrot/ThreeActivity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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")
Expand All @@ -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) {
Expand All @@ -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);
}
}

}
13 changes: 13 additions & 0 deletions app/src/main/res/layout/activity_four.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">


<TextView
android:id="@+id/tv_user"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</FrameLayout>
20 changes: 20 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@
android:layout_height="wrap_content"
android:text="Hello World!" />

<EditText
android:hint="请输入账号"
android:id="@+id/et_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />

<EditText
android:hint="请输入密码"
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:inputType="textPassword" />

<Button
android:text="登录"
android:id="@+id/btn_login"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</LinearLayout>

0 comments on commit c273ff3

Please sign in to comment.