package com.example.eitc_erm_app.sightGlass;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatActivity;

import com.gnhz.clinic.eitc_erm_app.R;

import java.util.Locale;

public class BaseActivity extends Activity {
    public static final String TAG = "czb";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置全面屏
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setLanguage();
        setContentView(R.layout.activity_base);
    }

    int ReadLanguageConfig() {
        SharedPreferences sharedata = getSharedPreferences("tcflanguageconfig", 0);
        return sharedata.getInt("language", 1);
    }

    void SaveLanguageConfig(int mlg_Language) {
        SharedPreferences.Editor sharepre = getSharedPreferences("tcflanguageconfig", 0).edit();
        sharepre.putInt("language", mlg_Language);
        sharepre.apply();
    }

    void setLanguage() {
        Resources resources = getResources();
        final Configuration configuration = resources.getConfiguration();
        DisplayMetrics displayMetrics = resources.getDisplayMetrics();
        switch (ReadLanguageConfig()) {
            case 0:
                configuration.setLocale(Locale.ENGLISH);
                break;
            case 1:
                configuration.setLocale(Locale.SIMPLIFIED_CHINESE);
                break;
            case 2:
                configuration.setLocale(Locale.TRADITIONAL_CHINESE);
                break;
            case 3:
                configuration.setLocale(Locale.JAPANESE);
                break;
            case 4:
                configuration.setLocale(Locale.FRENCH);
                break;
            default:
                configuration.setLocale(Locale.getDefault());
                break;
        }
        resources.updateConfiguration(configuration, displayMetrics);
    }


    public String[] getSSIDPWD() {
        String[] strings = new String[2];
        SharedPreferences sharedPreferences = getSharedPreferences("WIFISDK", MODE_PRIVATE);
        strings[0] = sharedPreferences.getString("SSID", "TP-LINK_1B55");
        strings[1] = sharedPreferences.getString("PWD", "aa123456");
        return strings;
    }

    public void saveSSIDPWD(String ssid, String pwd) {
        SharedPreferences.Editor sharedPreferences = getSharedPreferences("WIFISDK", MODE_PRIVATE).edit();
        sharedPreferences.putString("SSID", ssid);
        sharedPreferences.putString("PWD", pwd);
        sharedPreferences.apply();
    }
    public String getString(String value) {
        SharedPreferences sharedPreferences = getSharedPreferences("WIFISDK", MODE_PRIVATE);
        return sharedPreferences.getString(value, "");
    }

    public int getInt(String value) {
        SharedPreferences sharedPreferences = getSharedPreferences("WIFISDK", MODE_PRIVATE);
        return sharedPreferences.getInt(value, 0);
    }



    public void saveInt(String key, int value) {
        SharedPreferences.Editor shared = getSharedPreferences("WIFISDK", MODE_PRIVATE).edit();
        shared.putInt(key, value);
        shared.apply();
    }

    public void saveString(String key, String value) {
        SharedPreferences.Editor sharedPreferences = getSharedPreferences("WIFISDK", MODE_PRIVATE).edit();
        sharedPreferences.putString(key, value);
        sharedPreferences.apply();
    }
}