2024/03/22(2024春季)

学习时长:2小时

代码行数:200多行

博客数量: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"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="0sp"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:orientation="vertical">

            <TextView
                android:id="@+id/username"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="3"
                android:gravity="center"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="3"
                android:gravity="center"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/phone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="3"
                android:gravity="center"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/user_class"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="3"
                android:gravity="center"
                android:textSize="20sp" />
        </LinearLayout>

        <Button
            android:id="@+id/QUIT_LOGIN"
            android:layout_width="0sp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="@string/quit_login"
            android:textSize="20sp" />
    </LinearLayout>

    <Space
        android:layout_width="match_parent"
        android:layout_height="20sp" />

    <TextView
        android:id="@+id/today"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textSize="40sp" />

    <Space
        android:layout_width="match_parent"
        android:layout_height="20sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical">

            <Button
                android:id="@+id/set_goals"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/set_goals"
                android:textSize="30sp" />

            <Space
                android:layout_width="match_parent"
                android:layout_height="20sp" />

            <Button
                android:id="@+id/study_record"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/study_record"
                android:textSize="30sp" />

            <Space
                android:layout_width="match_parent"
                android:layout_height="20sp" />

            <Button
                android:id="@+id/study_record1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/study_record1"
                android:textSize="30sp" />

            <Space
                android:layout_width="match_parent"
                android:layout_height="20sp" />

            <Button
                android:id="@+id/analyse"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/analyse"
                android:textSize="30sp" />


        </LinearLayout>
    </LinearLayout>
</LinearLayout>

 

package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.pojo.User;
import com.example.myapplication.utils.WeekDayUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class HomeActivity extends AppCompatActivity {
    private Button set_goals;
    private Button study_records;
    private Button analyse;
    private Button study_records1;
    private TextView today_v;
    private TextView username_v;
    private Button quit_login;
    private TextView name_v;
    private TextView phone_v;
    private TextView user_class_v;
    private User user=null;
    private SharedPreferences preferences;
    private Date date;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_home);
        init();




        quit_login.setOnClickListener(v -> {
            Intent intent=new Intent(HomeActivity.this,MainActivity.class);
            startActivity(intent);
        });


        set_goals.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            startActivity(new Intent(HomeActivity.this,GoalsActivity.class));
            }
        });


        study_records.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            startActivity(new Intent(HomeActivity.this,RecordActivity.class));
            }
        });


        study_records1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            startActivity(new Intent(HomeActivity.this, RecordListActivity.class));
            }
        });

        analyse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            startActivity(new Intent(HomeActivity.this,AnalyseActivity.class));
            }
        });



    }
    private void remUser(User user)
    {
        preferences = getSharedPreferences("user2", Context.MODE_PRIVATE);
        System.out.println(user);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("username", user.getUsername());
        editor.putString("name", user.getName());
        editor.putString("phone",user.getPhone());
        editor.putString("class_no",user.getClass_no());
        editor.commit();
    }
    @SuppressLint("SetTextI18n")
    private void init()
    {
        username_v=findViewById(R.id.username);
        name_v=findViewById(R.id.name);
        phone_v=findViewById(R.id.phone);
        user_class_v=findViewById(R.id.user_class);
        quit_login=findViewById(R.id.QUIT_LOGIN);
        today_v=findViewById(R.id.today);
        set_goals=findViewById(R.id.set_goals);
        study_records=findViewById(R.id.study_record);
        analyse=findViewById(R.id.analyse);
        study_records1=findViewById(R.id.study_record1);


        Bundle bundle=getIntent().getExtras();
        user=(User)bundle.getSerializable("user");
        username_v.setText("用户名:"+user.getUsername());
        name_v.setText("姓名:"+user.getName());
        phone_v.setText("电话号码:"+user.getPhone());
        user_class_v.setText("班级:"+user.getClass_no());
        remUser(user);


        date=new Date();
        String date_now=null;
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd");
        date_now = dateformat.format(date);
        String weekday=new WeekDayUtils().getWeekOfDate(date);
        today_v.setText(date_now+"  "+weekday);
        if(!weekday.equals("星期一"))
        {
            set_goals.setText("今天为"+weekday+",你只能在星期一制定本周的学习目标");
            set_goals.setEnabled(false);
        }
    }
}

 

posted @ 2024-03-22 21:47  伐木工熊大  阅读(3)  评论(0编辑  收藏  举报