23.实战演练--个人主页

news2024/11/25 6:59:32

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.LoginTest"
        tools:targetApi="31">
        <activity
            android:name=".EditProfileActivity"
            android:exported="false" />
        <activity
            android:name=".UserProfileActivity"
            android:exported="false" />
        <activity
            android:name=".LoginActivity"
            android:exported="true"
            android:label="登录">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".RegisterActivity"
            android:exported="false"
            android:label="注册" />
        <activity
            android:name=".MainActivity"
            android:exported="false"
            android:label="首页" />
    </application>

</manifest>

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyBtnStyle">
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">25sp</item>
        <item name="android:background">@drawable/btn_bg_selector</item>
        <item name="android:layout_marginTop">20dp</item>
        <item name="android:layout_marginRight">20dp</item>
        <item name="android:layout_marginLeft">20dp</item>
    </style>

    <style name="MyEditStyle">
        <item name="android:textSize">18sp</item>
        <item name="android:background">@drawable/edit_text_bg</item>
        <item name="android:paddingLeft">10dp</item>
        <item name="android:layout_height">50dp</item>
    </style>
</resources>

<resources>
    <string name="app_name">LoginTest</string>
    
    <string-array name="cities">
        <item>北京</item>
        <item>上海</item>
        <item>天津</item>
        <item>深圳</item>
        <item>广州</item>
        <item>福建</item>
        <item>江苏</item>
        <item>浙江</item>
        <item>江西</item>
        <item>湖北</item>
    </string-array>
</resources>

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="black">#FF000000</color>
    <color name="white">#FFFFFFFF</color>

    <color name="green_200">#C5E1A5</color>
    <color name="green_500">#8BC34A</color>
    <color name="green_700">#689F38</color>

    <color name="colorPrimary">@color/green_500</color>
    <color name="colorPrimaryDark">@color/green_700</color>
    <color name="accent">#F4511E</color>

    <color name="teal_200">#FF03DAC5</color>
    <color name="teal_700">#FF018786</color>
</resources>

<vector android:autoMirrored="true" android:height="24dp"
    android:tint="#093243" android:viewportHeight="24"
    android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="@android:color/white" android:pathData="M6.23,20.23l1.77,1.77l10,-10l-10,-10l-1.77,1.77l8.23,8.23z"/>
</vector>

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/colorPrimary"/>
    <item android:state_pressed="false" android:drawable="@color/colorPrimaryDark"/>
</selector>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke android:width="3dp" android:color="@color/colorPrimary"/>

    <corners android:radius="10dp"/>
</shape>

<?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"
    tools:context=".MainActivity"
    android:orientation="vertical">
    <TextView
        android:id="@+id/tv_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40sp"
        android:layout_marginTop="30dp"
        android:text="欢迎你:"
        android:layout_gravity="center_horizontal"/>
    <Button
        android:id="@+id/btn_logout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="退出登录"
        android:textSize="25sp"
        android:layout_margin="20dp"
        android:background="@drawable/btn_bg_selector"/>
</LinearLayout>

package com.example.logintest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btn_logout;
    private TextView tvContent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn_logout = findViewById(R.id.btn_logout);
        btn_logout.setOnClickListener(this);

        tvContent = findViewById(R.id.tv_content);

        Intent intent = getIntent();
        String account = intent.getStringExtra("account");
        tvContent.setText("欢迎你:"+account);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_logout) {
            SharedPreferences spf = getSharedPreferences("spfRecord",MODE_PRIVATE);
            SharedPreferences.Editor edit = spf.edit();
            edit.putBoolean("isLogin",false);
            edit.apply();

            Intent intent = new Intent(this, LoginActivity.class);
            startActivity(intent);
            this.finish();
        }
    }
}

<?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"
    tools:context=".RegisterActivity"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="账        号:"
            android:textSize="25sp"/>
        <EditText
            android:id="@+id/et_account"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="请输入用户名或手机号"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:paddingLeft="5dp"
            android:inputType="text"
            android:background="@drawable/edit_text_bg"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密        码:"
            android:textSize="25sp"/>
        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="请输入密码"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:paddingLeft="5dp"
            android:inputType="numberPassword"
            android:background="@drawable/edit_text_bg"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="确认密码:"
            android:textSize="25sp"/>
        <EditText
            android:id="@+id/et_password_confirm"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="再次输入密码"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:paddingLeft="5dp"
            android:inputType="numberPassword"
            android:background="@drawable/edit_text_bg"/>
    </LinearLayout>

    <Button
        android:id="@+id/btn_register"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="注册"
        android:textSize="25sp"
        android:background="@drawable/btn_bg_selector"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"/>
    <CheckBox
        android:id="@+id/rb_agree"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimary"
        android:text="同意用户协议?"
        android:layout_gravity="left"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp"/>
</LinearLayout>

package com.example.logintest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btnRegister;
    private EditText etAccount,etPass,etPassConfirm;
    private CheckBox rbAgree;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        btnRegister = findViewById(R.id.btn_register);
        btnRegister.setOnClickListener(this);

        etAccount = findViewById(R.id.et_account);
        etAccount.setOnClickListener(this);

        etPass = findViewById(R.id.et_password);
        etPass.setOnClickListener(this);

        etPassConfirm = findViewById(R.id.et_password_confirm);
        etPassConfirm.setOnClickListener(this);

        rbAgree = findViewById(R.id.rb_agree);
        rbAgree.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        String name = etAccount.getText().toString();
        String pass = etPass.getText().toString();
        String passConfirm = etPassConfirm.getText().toString();
        if (view.getId() == R.id.btn_register) {
            if (TextUtils.isEmpty(name)) {
                Toast.makeText(RegisterActivity.this, "用户名不能为空", Toast.LENGTH_LONG).show();
                return;
            }
            if (TextUtils.isEmpty(pass)) {
                Toast.makeText(RegisterActivity.this, "密码不能为空", Toast.LENGTH_LONG).show();
                return;
            }
            if (!TextUtils.equals(pass, passConfirm)) {
                Toast.makeText(RegisterActivity.this, "密码不一致", Toast.LENGTH_LONG).show();
                return;
            }
            if (!rbAgree.isChecked()) {
                Toast.makeText(RegisterActivity.this, "请同意用户协议", Toast.LENGTH_LONG).show();
                return;
            }

            SharedPreferences spf = getSharedPreferences("spfRecorid",MODE_PRIVATE);
            SharedPreferences.Editor edit = spf.edit();
            edit.putString("account",name);
            edit.putString("password",pass);

            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            bundle.putString("account",name);
            bundle.putString("password",pass);
            intent.putExtras(bundle);
            setResult(0,intent);

            Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_LONG).show();
            this.finish();
        }
    }
}

<?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"
    tools:context=".LoginActivity"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="账号:"
            android:textSize="25sp"/>
        <EditText
            android:id="@+id/et_account"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="请输入用户名或手机号"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:paddingLeft="5dp"
            android:inputType="text"
            android:background="@drawable/edit_text_bg"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="40dp"
        android:gravity="center_vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密码:"
            android:textSize="25sp"/>
        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:hint="请输入密码"
            android:textSize="18sp"
            android:layout_marginLeft="10dp"
            android:paddingLeft="5dp"
            android:inputType="numberPassword"
            android:background="@drawable/edit_text_bg"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">
        <CheckBox
            android:id="@+id/cb_remember"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="记住密码"/>
        <CheckBox
            android:id="@+id/cb_auto_login"
            android:visibility="visible"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="自动登录"
            android:layout_marginLeft="40dp"/>
    </LinearLayout>
    <Button
        android:id="@+id/btn_Login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登录"
        style="@style/MyBtnStyle"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"/>
    <TextView
        android:id="@+id/to_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/colorPrimary"
        android:text="还没有账号?"
        android:layout_gravity="right"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"/>

</LinearLayout>

package com.example.logintest;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
    public static final int REQUEST_CODE_REGISTER = 1;
    private Button btnLogin;
    private EditText etAccount,etPassword;
    private CheckBox cbRemember,cbAutoLogin;
    private TextView toRegister;

    private String userName = "admin";
    private String pass = "1234";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
        initData();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_Login) {
            String account = etAccount.getText().toString();
            String passWord = etPassword.getText().toString();
            if (TextUtils.isEmpty(userName)){
                Toast.makeText(LoginActivity.this, "对不起,你还没注册账号!", Toast.LENGTH_LONG).show();
                return;
            }
            if (TextUtils.equals(account, userName)) {
                if (TextUtils.equals(passWord, pass)) {
                    Toast.makeText(LoginActivity.this, "恭喜你,登陆成功!", Toast.LENGTH_LONG).show();
                    if (cbRemember.isChecked()){
                        SharedPreferences spf = getSharedPreferences("spfRecord",MODE_PRIVATE);
                        SharedPreferences.Editor edit = spf.edit();
                        edit.putString("account",account);
                        edit.putString("password",passWord);
                        edit.putBoolean("isRemember",true);
                        if (cbAutoLogin.isChecked()){
                            edit.putBoolean("isLogin",true);
                        }else {
                            edit.putBoolean("isLogin",false);
                        }
                        edit.apply();
                    }else {
                        SharedPreferences spf = getSharedPreferences("spfRecord",MODE_PRIVATE);
                        SharedPreferences.Editor edit = spf.edit();
                        edit.putBoolean("isRemember",false);
                        edit.apply();
                    }
                    Intent intent = new Intent(LoginActivity.this, UserProfileActivity.class);
                    intent.putExtra("account",account);
                    startActivity(intent);
                    LoginActivity.this.finish();
                } else {
                    Toast.makeText(LoginActivity.this, "密码错误!", Toast.LENGTH_LONG).show();
                }
            } else {
                Toast.makeText(LoginActivity.this, "用户名错误!", Toast.LENGTH_LONG).show();
            }
        } else if (view.getId() == R.id.to_register) {
            Intent intent = new Intent(this, RegisterActivity.class);

            startActivityForResult(intent, REQUEST_CODE_REGISTER);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE_REGISTER && resultCode == 0 && data!=null){
            Bundle extras = data.getExtras();
            String account = extras.getString("account", "");
            String password = extras.getString("password", "");

            etAccount.setText(account);
            etPassword.setText(password);

            userName = account;
            pass = password;
        }
    }

    private void initView(){
        btnLogin = findViewById(R.id.btn_Login);
        btnLogin.setOnClickListener(this);

        etAccount = findViewById(R.id.et_account);
        etAccount.setOnClickListener(this);

        etPassword = findViewById(R.id.et_password);
        etPassword.setOnClickListener(this);

        cbRemember = findViewById(R.id.cb_remember);
        cbRemember.setOnCheckedChangeListener(this::onCheckedChangedResult);
        cbAutoLogin = findViewById(R.id.cb_auto_login);
        cbAutoLogin.setOnCheckedChangeListener(this::onCheckedChanged);

        toRegister = findViewById(R.id.to_register);
        toRegister.setOnClickListener(this);
    }
    private void initData() {
        SharedPreferences spf = getSharedPreferences("spfRecord",MODE_PRIVATE);
        boolean isRemember = spf.getBoolean("isRemember",false);
        boolean isLogin = spf.getBoolean("isLogin",false);

        String account = spf.getString("account","");
        String password = spf.getString("password","");

        if (isLogin){
            Intent intent = new Intent(LoginActivity.this, UserProfileActivity.class);
            intent.putExtra("account",account);
            startActivity(intent);
            LoginActivity.this.finish();
        }


        userName = account;
        pass = password;

        if (isRemember){
            etAccount.setText(account);
            etPassword.setText(password);
            cbRemember.setChecked(true);
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        if (b){
            cbRemember.setChecked(true);
        }
    }

    public void onCheckedChangedResult(CompoundButton compoundButton, boolean b) {
        if (!b){
            cbAutoLogin.setChecked(false);
        }
    }
}

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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=".UserProfileActivity">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:background="@color/colorPrimary">

            <ImageView
                android:id="@+id/iv_avatar"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_centerInParent="true"
                android:src="@mipmap/ic_launcher" />

            <TextView
                android:id="@+id/tv_nick_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/iv_avatar"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:text="admin"
                android:textColor="@color/white"
                android:textSize="14sp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/tv_nick_name"
                android:gravity="center"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/tv_gender"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/iv_avatar"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="5dp"
                    android:text="男"
                    android:textColor="@color/white"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/tv_age"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/iv_avatar"
                    android:layout_centerHorizontal="true"
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="5dp"
                    android:text="21岁"
                    android:textColor="@color/white"
                    android:textSize="14sp" />

                <TextView
                    android:id="@+id/tv_city"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/iv_avatar"
                    android:layout_centerHorizontal="true"
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="5dp"
                    android:text="北京"
                    android:textColor="@color/white"
                    android:textSize="14sp" />
            </LinearLayout>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:paddingLeft="10dp">

            <TextView
                android:id="@+id/tv_account"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="账号"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/tv_account_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/tv_account"
                android:layout_toRightOf="@id/tv_account"
                android:gravity="center"
                android:text="admin"
                android:textSize="20sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:paddingLeft="10dp">

            <TextView
                android:id="@+id/tv_birth_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="出生时间"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/tv_birth_time_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@id/tv_birth_time"
                android:layout_toRightOf="@id/tv_birth_time"
                android:gravity="center"
                android:text="123234"
                android:textSize="20sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:paddingLeft="10dp">

            <TextView
                android:id="@+id/tv_home"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="城市"
                android:textSize="20sp"
                tools:ignore="InvalidId" />

            <TextView
                android:id="@+id/tv_home_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@id/tv_home"
                android:layout_toRightOf="@id/tv_home"
                android:gravity="center"
                android:text="北京"
                android:textSize="20sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:paddingLeft="10dp">

            <TextView
                android:id="@+id/tv_school"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="学校"
                android:textSize="20sp"
                tools:ignore="InvalidId" />

            <TextView
                android:id="@+id/tv_school_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@id/tv_school"
                android:layout_toRightOf="@id/tv_school"
                android:gravity="center"
                android:text="北京大学"
                android:textSize="20sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:paddingLeft="10dp">

            <TextView
                android:id="@+id/tv_sign"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="个人签名"
                android:textSize="20sp"
                tools:ignore="InvalidId" />

            <TextView
                android:id="@+id/tv_sign_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@id/tv_sign"
                android:layout_toRightOf="@id/tv_sign"
                android:gravity="center"
                android:text="这个人没有设置任何签名"
                android:textSize="14sp" />
        </RelativeLayout>

        <Button
            android:id="@+id/btn_toEdit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="@drawable/btn_bg_selector"
            android:text="编辑资料" />

        <Button
            android:id="@+id/btn_logout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="@drawable/btn_bg_selector"
            android:text="退出登录" />
    </LinearLayout>
</ScrollView>

package com.example.logintest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class UserProfileActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView tvNickName,tvAccount,tvAge,tvGender,tvCity,tvHome,tvSchool,tvSign,tvBirthdayTime;
    private String birthDayTime;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_profile);

        Button btn_toEdit = findViewById(R.id.btn_toEdit);
        btn_toEdit.setOnClickListener(this);
        Button btn_logout = findViewById(R.id.btn_logout);
        btn_logout.setOnClickListener(this);

        initView();
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }


    private void initData() {
        getDataFromspf();
    }

    private void getDataFromspf() {
        SharedPreferences spfRecord = getSharedPreferences("spfRecord",MODE_PRIVATE);
        String account = spfRecord.getString("account","");
        String nick_name = spfRecord.getString("nick_name","");
        String city = spfRecord.getString("city","");
        String gender = spfRecord.getString("gender","");
        String school = spfRecord.getString("school","");
        String birth_day_time = spfRecord.getString("birth_day_time","");
        String sign = spfRecord.getString("sign","");
        String home = spfRecord.getString("home","");
        String age = getAgeByBirthDay(birthDayTime);

        tvAccount.setText(account);
        tvNickName.setText(nick_name);
        tvAge.setText(age);
        tvHome.setText(home);
        tvSchool.setText(school);
        tvSign.setText(sign);
        tvBirthdayTime.setText(birth_day_time);
        tvGender.setText(gender);
        tvCity.setText(city);
    }

    private String getAgeByBirthDay(String birthDayTime) {
        if (TextUtils.isEmpty(birthDayTime)){
            return "";
        }
        try {
            int index = birthDayTime.indexOf("年");
            String result = birthDayTime.substring(0,index);

            int parseInt = Integer.parseInt(result);
            return String.valueOf(2021-parseInt);
        }catch (Exception e){
            e.printStackTrace();
        }
        return "";
    }

    private void initView() {
        tvAccount = findViewById(R.id.tv_account_text);
        tvNickName = findViewById(R.id.tv_nick_name);
        tvAge = findViewById(R.id.tv_age);
        tvHome = findViewById(R.id.tv_home_text);
        tvSchool = findViewById(R.id.tv_school_text);
        tvSign = findViewById(R.id.tv_sign_text);
        tvBirthdayTime = findViewById(R.id.tv_birth_time_text);
        tvGender = findViewById(R.id.tv_gender);
        tvCity = findViewById(R.id.tv_city);

    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_toEdit){
            Intent intent = new Intent(this, EditProfileActivity.class);
            startActivity(intent);
        } else if (view.getId() == R.id.btn_logout) {
            SharedPreferences spf = getSharedPreferences("spfRecord",MODE_PRIVATE);
            SharedPreferences.Editor edit = spf.edit();
            edit.putBoolean("isLogin",false);
            edit.apply();

            Intent intent = new Intent(this, LoginActivity.class);
            startActivity(intent);
            this.finish();
        }
    }
}

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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=".EditProfileActivity">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="250dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:text="更换头像"
                android:textSize="20sp" />

            <ImageView
                android:id="@+id/iv_avatar"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_centerInParent="true"
                android:src="@mipmap/ic_launcher" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/iv_avatar"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:orientation="horizontal">

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/btn_bg_selector"
                    android:text="拍照" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:background="@drawable/btn_bg_selector"
                    android:text="相册" />
            </LinearLayout>

        </RelativeLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_account"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="账号:"
                android:textSize="25sp" />

            <EditText
                android:id="@+id/et_account_text"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="10dp"
                android:background="@drawable/edit_text_bg"
                android:hint="请输入你的账号"
                android:paddingLeft="5dp"
                android:textSize="18sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_nick_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="昵称:"
                android:textSize="25sp" />

            <EditText
                android:id="@+id/et_nick_name_text"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="10dp"
                android:background="@drawable/edit_text_bg"
                android:hint="请输入你的账号"
                android:paddingLeft="5dp"
                android:textSize="18sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="性别"
                android:textSize="20sp"/>
            <RadioGroup
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center">
                <RadioButton
                    android:id="@+id/rb_boy"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="男"/>
                <RadioButton
                    android:id="@+id/rb_girl"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="女"
                    android:layout_marginLeft="10dp"/>
            </RadioGroup>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_birth_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="出生日期:"
                android:textSize="25sp" />

            <TextView
                android:id="@+id/tv_birth_time_text"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginLeft="10dp"
                android:text="1998年3月23 15点25分"
                android:paddingLeft="5dp"
                android:textSize="18sp" />
            <ImageView
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_gravity="center_vertical"
                android:src="@drawable/baseline_arrow_forward_24"
                android:layout_marginLeft="30dp"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_home"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="城市:"
                android:textSize="25sp" />

            <androidx.appcompat.widget.AppCompatSpinner
                android:id="@+id/sp_city"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="10dp"
                android:background="@drawable/edit_text_bg"
                android:entries="@array/cities"
                android:spinnerMode="dropdown"
                android:paddingLeft="5dp"
                android:textSize="18sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_school"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="学校:"
                android:textSize="25sp" />

            <EditText
                android:id="@+id/et_school_text"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="10dp"
                android:background="@drawable/edit_text_bg"
                android:hint="请输入你的学校"
                android:paddingLeft="5dp"
                android:textSize="18sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:gravity="center_vertical"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tv_sign"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="个人签名:"
                android:textSize="25sp" />

            <EditText
                android:id="@+id/et_sign_text"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:background="@drawable/edit_text_bg"
                android:hint="请设置你的个人签名"
                android:textSize="18sp" />
        </LinearLayout>


        <Button
            android:id="@+id/btn_save"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="@drawable/btn_bg_selector"
            android:text="保存" />

    </LinearLayout>
</ScrollView>

package com.example.logintest;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatSpinner;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.TimePicker;

public class EditProfileActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText etNickName,etAccount,etSchool,etSign;
    private  TextView tvBirthDayTime;
    private RadioButton rbBoy,rbGirl;
    private AppCompatSpinner spinnerCity;
    private String[] cities;
    private int selectedCityPosition;
    private String selectedCity;
    private String birthDay;
    private String birthDayTime;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_profile);
        Button btn_save = findViewById(R.id.btn_save);
        btn_save.setOnClickListener(this);
        
        initView();
        initData();
        
        initEvent();
    }

    private void initView() {
        etAccount = findViewById(R.id.et_account_text);
        etNickName = findViewById(R.id.et_nick_name_text);
        etSchool = findViewById(R.id.et_school_text);
        etSign = findViewById(R.id.et_sign_text);

        tvBirthDayTime = findViewById(R.id.tv_birth_time_text);
        rbBoy = findViewById(R.id.rb_boy);
        rbGirl = findViewById(R.id.rb_girl);
        spinnerCity = findViewById(R.id.sp_city);
    }
    private void initData() {
        cities = getResources().getStringArray(R.array.cities);

        getDataFromspf();
    }
    private void getDataFromspf() {
        SharedPreferences spfRecord = getSharedPreferences("spfRecord",MODE_PRIVATE);
        String account = spfRecord.getString("account","");
        String nick_name = spfRecord.getString("nick_name","");
        String age = spfRecord.getString("age","");
        String city = spfRecord.getString("city","");
        String gender = spfRecord.getString("gender","");
        String school = spfRecord.getString("school","");
        String birth_day_time = spfRecord.getString("birth_day_time","");
        String sign = spfRecord.getString("sign","");
        String home = spfRecord.getString("home","");

        etAccount.setText(account);
        etNickName.setText(nick_name);
        etSchool.setText(age);
        etSign.setText(home);
        tvBirthDayTime.setText(birthDayTime);

        if (TextUtils.equals("男",gender)){
            rbBoy.setChecked(true);
        }

        if (TextUtils.equals("女",gender)){
            rbGirl.setChecked(true);
        }

        for (int i = 0; i < cities.length; i++) {
            if (TextUtils.equals(cities[i],city)){
                selectedCityPosition = i;
                break;
            }
        }

        spinnerCity.setSelection(selectedCityPosition);
    }

    private void initEvent() {
        spinnerCity.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                selectedCityPosition = i;
                selectedCity = cities[i];
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });

        tvBirthDayTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new DatePickerDialog(EditProfileActivity.this, new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
                        int realMonth = i1+1;
                        birthDay = i+"年"+realMonth+"月"+i2+"日";

                        popTimePick();
                    }

                },2024,2,17).show();
            }
        });
    }
    private void popTimePick() {
        new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker timePicker, int i, int i1) {
                birthDayTime = birthDay+i+"时"+i1+"分";
                tvBirthDayTime.setText(birthDayTime);
            }
        },12,36,true).show();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_save){
            String account = etAccount.getText().toString();
            String sign = etSign.getText().toString();
            String school = etSchool.getText().toString();
            String nickName = etNickName.getText().toString();

            String gender = "男";
            if (rbBoy.isChecked()){
                gender = "男";
            }
            if (rbGirl.isChecked()){
                gender = "女";
            }

            SharedPreferences spfRecord = getSharedPreferences("spfRecord",MODE_PRIVATE);
            SharedPreferences.Editor editor = spfRecord.edit();
            editor.putString("account",account);
            editor.putString("sign",sign);
            editor.putString("school",school);
            editor.putString("nick_name",nickName);
            editor.putString("birth_day_time",birthDayTime);
            editor.putString("city",selectedCity);
            editor.putString("gender",gender);
            editor.apply();

            this.finish();
        }
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1393805.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

06-python数据容器-set(集合)入门基础操作

集合的定义 """ 演示数据容器集合的使用 """ #定义集合 my_set{"计算机","0854","考研上岸","计算机","0854","考研上岸","计算机","0854","考研上岸&qu…

IPv6自动隧道---6to4隧道

IPv6 over IPv4自动隧道特点 由于IPv4兼容IPv6隧道要求每一个主机都要有一个合法的IP地址,而且通讯的主机要支持双栈、支持IPv4兼容IPv6隧道,不适合大面积部署。目前该技术已经被6to4隧道所代替。 6to4隧道 集手动隧道和自动隧道的优点于一身,提出6to4的目的是为IPv4网络…

4种方法用Python批量实现多Excel多Sheet合并

目录 方法一&#xff1a;使用pandas库 方法二&#xff1a;使用openpyxl库 方法三&#xff1a;使用xlrd和xlwt库 方法四&#xff1a;使用os和glob库 在数据处理中&#xff0c;经常需要将多个Excel文件中的多个工作表进行合并。以下介绍了4种方法&#xff0c;使用Python批量实…

Failed to load class org.slf4j.impl.StaticLoggerBinder

Failed to load class org.slf4j.impl.StaticLoggerBinder 问题描述问题分析解决方案1解决方案2 问题描述 在使用Slf4J的时候发现报错了&#xff0c;日志一直都是使用了slf4j-api、slf4j-log4j12、log4j这三个包结合起来使用&#xff0c;新搭建了一个项目&#xff0c;然后创建了…

如何使用Docker本地部署Wiki.js容器并结合内网穿透实现知识库共享

文章目录 1. 安装Docker2. 获取Wiki.js镜像3. 本地服务器打开Wiki.js并添加知识库内容4. 实现公网访问Wiki.js5. 固定Wiki.js公网地址 不管是在企业中还是在自己的个人知识整理上&#xff0c;我们都需要通过某种方式来有条理的组织相应的知识架构&#xff0c;那么一个好的知识整…

uni-app的组件(二)

多项选择器checkbox-group 多项选择器&#xff0c;内部由多个 checkbox 组成。 <checkbox-group><checkbox checked color"red" value"1"></checkbox> 篮球<!-- disabled:是否禁用 --><checkbox disabled color"rgba(0,0…

Python开发环境安装:梦的起点

Python解释器安装 前言 解释器&#xff08;Interpreter&#xff09;&#xff0c;又译为直译器&#xff0c;是一种电脑程序能够把高级编程语言一行一行直接转译运行。解释器不会一次把整个程序转译出来&#xff0c;只像一位“中间人”&#xff0c;每次运行程序时都要先转成另一…

version-polling一款用于实时检测 web 应用更新的 JavaScript 库

为了解决后端部署之后&#xff0c;如何通知用户系统有新版本&#xff0c;并引导用户刷新页面以加载最新资源的问题。 实现原理 1.使用 Web Worker API 在浏览器后台轮询请求页面&#xff0c;不会影响主线程运行。 2.命中协商缓存&#xff0c;对比本地和服务器请求响应头etag字…

Qt 倒计时或定时器的简单实现

1.相关说明 QTimer类实现定时器或倒计时 2.界面绘制 3.相关主要代码 // widget.h typedef struct TimeHMS{qint32 hour;qint32 minute;qint32 second; }TimeHMS;// widget.cpp #include "widget.h" #include "ui_widget.h" #include <QTime> #inclu…

容器与K8s

一、容器 容器 vs 虚拟机 二、Docker容器使用 三个概念&#xff1a; 2.1 镜像 Docker镜像除了运行程序也打包了程序运行环境。 2.2 镜像仓库 存放镜像的仓库&#xff0c;需要login之后拉去响应的镜像。 2.3 容器 基于Docker镜像创建的linux容器&#xff0c;本质是宿主机上…

掌握Spring MVC拦截器整合技巧,实现灵活的请求处理与权限控制!

拦截器 1.1 拦截器概念1.2 拦截器入门案例1.2.1 环境准备1.2.2 拦截器开发步骤1:创建拦截器类步骤2:配置拦截器类步骤3:SpringMVC添加SpringMvcSupport包扫描步骤4:运行程序测试步骤5:修改拦截器拦截规则步骤6:简化SpringMvcSupport的编写 1.3 拦截器参数1.3.1 前置处理方法1.3…

【python】学习笔记01

一、基础语法 1. 字面量 - 什么是字面量&#xff1f; 在代码中&#xff0c;被写下来的的固定的值&#xff0c;称之为字面量。 - 常用的值类型 Python中常用的有6种值&#xff08;数据&#xff09;的类型。 666 13.14 "程序员"print(666) print(13.14) print(&qu…

深入解析JavaScript的原生原型

&#x1f9d1;‍&#x1f393; 个人主页&#xff1a;《爱蹦跶的大A阿》 &#x1f525;当前正在更新专栏&#xff1a;《VUE》 、《JavaScript保姆级教程》、《krpano》、《krpano中文文档》 ​ ​ ✨ 前言 在JavaScript中,除了自定义对象,还存在很多由JavaScript语言本身提供…

【分布式技术】分布式存储ceph之RGW接口

目录 1、对象存储概念 2、创建 RGW 接口 //在管理节点创建一个 RGW 守护进程 #创建成功后默认情况下会自动创建一系列用于 RGW 的存储池 #默认情况下 RGW 监听 7480 号端口 //开启 httphttps &#xff0c;更改监听端口 #更改监听端口 ​ //创建 RadosGW 账户 …

鸿蒙OS4.0兼容性测试

背景 OpenHarmony兼容性测评主要是验证合作伙伴的设备和业务应用满足OpenHarmony开源兼容性定义的技术要求&#xff0c;确保运行在OpenHarmony上的设备和业务应用能稳定、正常运行&#xff0c;同时使用OpenHarmony的设备和业务应用有一致性的接口和业务体验。 OpenHarmony兼容…

cesium内部相同坐标在不同高度的2个点的属性机制坐标会gltf模型角度值异常问题mars3d的处理办法

模型一直向上运动的正常效果&#xff1a; 问题场景&#xff1a; 1.new mars3d.graphic.ModelPrimitive({使用addDynamicPosition(设置并添加动画轨迹位置&#xff0c;按“指定时间”运动到达“指定位置”时发现&#xff0c;如果是同一个点位不同高度值的y轴竖直向上方向的运动…

2024年华数杯国际赛A题:放射性废水处理建模 思路模型代码解析

2024年华数杯国际赛A题&#xff1a;放射性废水处理建模&#xff08;Radioactive Wastewater from Japan&#xff09; 一、问题描述 2011年3月&#xff0c;日本东海岸发生了地震&#xff0c;引发了福岛第一核电站事故&#xff0c;导致三个核反应堆熔毁&#xff0c;并在一场巨大…

Verilog刷题笔记16

题目&#xff1a; Since digital circuits are composed of logic gates connected with wires, any circuit can be expressed as some combination of modules and assign statements. However, sometimes this is not the most convenient way to describe the circuit. Pro…

C# dataGridView 列的勾选框改变事件

dataGridView 增加一列 DataGridViewCheckBoxColumn 然后设置复选框值如下图&#xff1a; dataGridView增加两个事件 private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e){//提交改变&#xff0c;触发dataGridView1_CellValueChanged事件&…

【数学建模】2024年华数杯国际赛B题-光伏发电Photovoltaic Power 思路、代码、参考论文

1 问题背景 中国电力构成包括传统能源(如煤炭、石油、天然气)、可再生能源(如水电、风能、太阳能、核能)和其他形式的电力。这些发电模式在满足中国巨大的电力需求方面发挥着至关重要的作用。据最新数据显示&#xff0c;中国总发电量超过20万亿千瓦时&#xff0c;居世界第一。…