You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.3 KiB
Java
68 lines
2.3 KiB
Java
package com.example.jinyu_rfid;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
import androidx.databinding.DataBindingUtil;
|
|
|
|
import android.content.Intent;
|
|
import android.content.res.Configuration;
|
|
import android.content.res.Resources;
|
|
import android.os.Bundle;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
|
|
import com.example.jinyu_rfid.databinding.ActivityAppLoginBinding;
|
|
import com.example.jinyu_rfid.uitls.SharedPreferencesUtils;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
|
|
public class AppLoginActivity extends AppCompatActivity {
|
|
private ActivityAppLoginBinding binding;
|
|
|
|
private Resources resources;
|
|
private Configuration config;
|
|
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
resources = getResources();
|
|
config = resources.getConfiguration();
|
|
var index = Integer.parseInt(SharedPreferencesUtils.getstring("languageIndex", "0"));
|
|
changeLanguage(index);
|
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_app_login);
|
|
binding.appLanguage.setSelection(index);
|
|
// 工作模式
|
|
var workmode = SharedPreferencesUtils.getInt("workmode", 0);
|
|
binding.mainWork.setSelection(workmode);
|
|
}
|
|
|
|
public void appLoginClick(View view) {
|
|
// 工作模式 0=net
|
|
var workModeStr = binding.mainWork.getSelectedItem().toString();
|
|
var strings = Arrays.asList(getResources().getStringArray(R.array.work_mode));
|
|
var value = strings.indexOf(workModeStr);
|
|
SharedPreferencesUtils.putInt("workmode", value);
|
|
// 选择语言
|
|
var index = binding.appLanguage.getSelectedItemPosition();
|
|
changeLanguage(index);
|
|
|
|
var intent = new Intent(this, ReadBlueToothActivity.class);
|
|
intent.putExtra("work", value);
|
|
SharedPreferencesUtils.putstring("languageIndex", index + "");
|
|
startActivity(intent);
|
|
finish();
|
|
}
|
|
|
|
private void changeLanguage(int index) {
|
|
if (index == 0) {
|
|
config.locale = Locale.CHINA;
|
|
} else if (index == 1) {
|
|
config.locale = Locale.ENGLISH;
|
|
} else {
|
|
config.locale = new Locale("vi", "VN");
|
|
}
|
|
resources.updateConfiguration(config, resources.getDisplayMetrics());
|
|
}
|
|
} |