package com.example.tesst_denglv;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText edit_pass;
private EditText edit_name;
private CheckBox check_jz;
private CheckBox check_zd;
private Button but_login;
private SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initdata();
boolean check_zdUI = sharedPreferences.getBoolean("check_zdUI",false);
boolean check_jzUI = sharedPreferences.getBoolean("check_jzUI",false);
if (check_zdUI) {
Intent intent = new Intent(MainActivity.this,login.class);
startActivity(intent);
finish();
}
if (check_jzUI) {
String username = sharedPreferences.getString("username", "");
String password = sharedPreferences.getString("password", "");
edit_pass.setText(password);
edit_name.setText(username);
check_jz.setChecked(true);
}
but_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Editor edit = sharedPreferences.edit();
String username = edit_name.getText().toString().trim();
String password = edit_pass.getText().toString().trim();
if (check_jz.isChecked()) {
edit.putBoolean("check_jzUI", true);
}
if (check_zd.isChecked()) {
edit.putBoolean("check_zdUI", true);
}
edit.putString("username", username);
edit.putString("password", password);
edit.commit();
Intent intent = new Intent(MainActivity.this,login.class);
startActivity(intent);
finish();
}
});
}
private void initdata() {
// TODO Auto-generated method stub
edit_name = (EditText) findViewById(R.id.edit_name);
edit_pass = (EditText) findViewById(R.id.edit_pass);
check_jz = (CheckBox) findViewById(R.id.check_jz);
check_zd = (CheckBox) findViewById(R.id.check_zd);
but_login = (Button) findViewById(R.id.but_log);
sharedPreferences = getSharedPreferences("1606B", MODE_PRIVATE);
}
}