4.8
主页面和注册页面
• 所花时间:1
• 代码行数:298
• 博客容量:1
• 代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/mainBackground">
<TextView
android:id="@+id/tv_name"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello!!"
android:textSize="30sp"
android:textColor="@color/white"/>
<Button
android:id="@+id/setTaskOfWeek"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="80dp"
android:background="@drawable/my_button"
android:text="每周学习目标"
android:textColor="@color/white"
android:textSize="20sp"
/>
<Button
android:id="@+id/setTaskOfDay"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="80dp"
android:background="@drawable/my_button"
android:text="每日学习记录"
android:textColor="@color/white"
android:textSize="20sp"
/>
<Button
android:id="@+id/SummaryOfWeek"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="80dp"
android:background="@drawable/my_button"
android:text="能力达标分析"
android:textColor="@color/white"
android:textSize="20sp"
/>
<Button
android:id="@+id/SummaryOfMonth"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="80dp"
android:background="@drawable/my_button"
android:text="月度学习报告"
android:textColor="@color/white"
android:textSize="20sp"
/>
</LinearLayout>
package com.example.undertaking;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.example.undertaking.userDB.User;
import com.example.undertaking.userDB.UserDbUtil;
public class homePage extends AppCompatActivity implements View.OnClickListener {
private TextView tv_name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
tv_name = findViewById(R.id.tv_name);
tv_name.setText("HELLO!"+MyApplication.user.name);
findViewById(R.id.setTaskOfWeek).setOnClickListener(this);
findViewById(R.id.setTaskOfDay).setOnClickListener(this);
findViewById(R.id.SummaryOfMonth).setOnClickListener(this);
findViewById(R.id.SummaryOfWeek).setOnClickListener(this);
}
@Override
public void onClick(View v) {
if(v.getId()==R.id.setTaskOfWeek){
Intent intent=new Intent(this,setTaskOfWeek.class);
startActivity(intent);
}else if(v.getId()==R.id.setTaskOfDay){
Intent intent=new Intent(this,setTaskOfDay.class);
startActivity(intent);
}else if(v.getId()==R.id.SummaryOfMonth){
Intent intent=new Intent(this,SummaryOfMonth.class);
startActivity(intent);
}else if(v.getId()==R.id.SummaryOfWeek){
Intent intent=new Intent(this,SummaryOfWeek.class);
startActivity(intent);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/mainBackground">
<TextView
android:id="@+id/tv_name"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello!!"
android:textSize="30sp"
android:textColor="@color/white"/>
<Button
android:id="@+id/summaryEveryOne"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="80dp"
android:background="@drawable/my_button"
android:text="汇总统计"
android:textColor="@color/white"
android:textSize="20sp"
/>
<Button
android:id="@+id/everydaySelect"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="80dp"
android:background="@drawable/my_button"
android:text="每日总结查询"
android:textColor="@color/white"
android:textSize="20sp"
/>
<Button
android:id="@+id/selectFrequency"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="80dp"
android:background="@drawable/my_button"
android:text="获取所有每日总结记录"
android:textColor="@color/white"
android:textSize="20sp"
/>
</LinearLayout>
package com.example.undertaking;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class teacherHomePage extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_teacher_home_page);
TextView tv_name=findViewById(R.id.tv_name);
tv_name.setText("HELLO !!"+MyApplication.user.name);
findViewById(R.id.selectFrequency).setOnClickListener(this);
findViewById(R.id.summaryEveryOne).setOnClickListener(this);
findViewById(R.id.everydaySelect).setOnClickListener(this);
}
@Override
public void onClick(View v) {
if(v.getId()==R.id.selectFrequency){
Intent intent=new Intent(this,selectFrequency.class);
startActivity(intent);
}else if(v.getId()==R.id.summaryEveryOne){
Intent intent=new Intent(this,summaryEveryOne.class);
startActivity(intent);
}else if(v.getId()==R.id.everydaySelect){
Intent intent=new Intent(this,everydaySelect.class);
startActivity(intent);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/mainBackground"
android:orientation="vertical">
<TextView
android:layout_marginTop="100dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册"
android:textColor="@color/white"
android:textSize="35sp"
android:layout_gravity="center"
android:layout_marginBottom="25dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:text="请输入学号/ID:"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="17sp"
/>
<EditText
android:inputType="text"
android:id="@+id/stu_id"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/my_edit"
android:maxLength="30"
android:textColor="@color/white"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:text="请输入姓名:"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="17sp"
/>
<EditText
android:id="@+id/stu_name"
android:layout_weight="1"
android:layout_width="0dp"
android:inputType="text"
android:layout_height="wrap_content"
android:background="@drawable/my_edit"
android:maxLength="30"
android:textColor="@color/white"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:text="请输入手机号码:"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="17sp"
/>
<EditText
android:id="@+id/stu_phone"
android:layout_weight="1"
android:layout_width="0dp"
android:inputType="phone"
android:layout_height="wrap_content"
android:background="@drawable/my_edit"
android:maxLength="30"
android:textColor="@color/white"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:text="请输入班级/单位:"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="17sp"
/>
<EditText
android:id="@+id/stu_class"
android:layout_weight="1"
android:layout_width="0dp"
android:inputType="text"
android:layout_height="wrap_content"
android:background="@drawable/my_edit"
android:maxLength="30"
android:textColor="@color/white"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:text="请输入密码:"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="17sp"
/>
<EditText
android:id="@+id/stu_pass"
android:layout_weight="1"
android:layout_width="0dp"
android:inputType="textPassword"
android:layout_height="wrap_content"
android:background="@drawable/my_edit"
android:maxLength="30"
android:textColor="@color/white"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:text="确认密码:"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="17sp"
/>
<EditText
android:id="@+id/stu_confirm_pass"
android:layout_weight="1"
android:layout_width="0dp"
android:inputType="textPassword"
android:layout_height="wrap_content"
android:background="@drawable/my_edit"
android:maxLength="30"
android:textColor="@color/white"
/>
</LinearLayout>
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
>
<RadioButton
android:id="@+id/radioStudent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="学生"
android:checked="true"
android:textColor="@color/white"/>
<RadioButton
android:id="@+id/radioTeacher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="老师"
android:textColor="@color/white"/>
</RadioGroup>
<Button
android:id="@+id/bt_register"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_width="120dp"
android:layout_height="40dp"
android:background="@drawable/my_button"
android:text="提交"
android:textColor="@color/white"
android:textSize="22sp"
android:gravity="center"/>
</LinearLayout>
package com.example.undertaking;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import com.example.undertaking.userDB.User;
import com.example.undertaking.userDB.UserDAO;
import com.example.undertaking.userDB.UserDbUtil;
import com.example.undertaking.util.ToastUtil;
public class registerWindow extends AppCompatActivity implements View.OnClickListener {
private EditText stuId;
private EditText stuPassword;
private EditText stuName;
private EditText stuRePass;
private EditText stuPhone;
private RadioGroup stuSelect;
private int selectO;
private EditText sClass;
private SharedPreferences preferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register_window);
stuId = findViewById(R.id.stu_id);
stuPassword = findViewById(R.id.stu_pass);
stuName = findViewById(R.id.stu_name);
stuRePass = findViewById(R.id.stu_confirm_pass);
stuPhone = findViewById(R.id.stu_phone);
stuSelect = findViewById(R.id.radioGroup);
sClass = findViewById(R.id.stu_class);
findViewById(R.id.bt_register).setOnClickListener(this);
preferences = getSharedPreferences("config", MODE_PRIVATE);
}
@Override
public void onClick(View v) {
if(!stuPassword.getText().toString().equals(stuRePass.getText().toString())){
ToastUtil.show(this,"两次输入的密码不一致!");
return;
}
selectO = stuSelect.getCheckedRadioButtonId()==R.id.radioStudent?0:1;
User user=new User(stuName.getText().toString(),stuId.getText().toString(),stuPassword.getText().toString(),sClass.getText().toString(),stuPhone.getText().toString(),selectO);
boolean result;
UserDAO.DatabaseOperationListener listener = new UserDAO.DatabaseOperationListener() {
@Override
public void onOperationCompleted(boolean success) {
if (success) {
//更新application
MyApplication.user=user;
ToastUtil.show(registerWindow.this,"注册成功");
SharedPreferences.Editor edit=preferences.edit();
edit.putString("id",stuId.getText().toString());
edit.putString("password",stuPassword.getText().toString());
edit.commit();
Intent intent;
if(user.select==0){
intent=new Intent(registerWindow.this,homePage.class);
}else {
intent=new Intent(registerWindow.this,teacherHomePage.class);
}
startActivity(intent);
} else {
ToastUtil.show(registerWindow.this,"注册失败");
}
}
};
UserDAO.insert(user, listener);
}
}
浙公网安备 33010602011771号