//定义sp存储
private SharedPreferences sharedPreferences;
//todo 用户名
private EditText edit_username;
//todo 密码
private EditText edit_password;
//todo 注册
private CheckBox btn_register;
//todo 登录
private Button btn_login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
initView();
//TODO 获取sp对象
sharedPreferences = getSharedPreferences("1609A", MODE_PRIVATE);
//todo 设置是否选中的标签
boolean isCheck = sharedPreferences.getBoolean("isCheck", false);
//todo 如果被选中时,写入数据
if (isCheck) {
String name = sharedPreferences.getString("name", "");
String pawd = sharedPreferences.getString("pawd", "");
edit_username.setText(name);
edit_password.setText(pawd);
btn_register.setChecked(true);
}
//TODO 登录监听事件
//todo 写数据
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String u = edit_username.getText().toString().trim();
String p = edit_password.getText().toString().trim();
if("yjy".equals(u)&&"123456".equals(p)) {
//判断记住密码是否被选中
if(btn_register.isChecked()) {
//TODO 添加数据
SharedPreferences.Editor edit = sharedPreferences.edit();
edit.putBoolean("isCheck",true);
edit.putString("name",u);
edit.putString("pawd",p);
//todo 提交数据
edit.commit();
}else {
//todo 创建edit对象
SharedPreferences.Editor edit = sharedPreferences.edit();
//todo 清除
edit.clear();
edit.commit();
}
}
}
});
}
private void initView() {
edit_username = (EditText) findViewById(R.id.edit_username);
edit_password = (EditText) findViewById(R.id.edit_password);
btn_register = (CheckBox) findViewById(R.id.btn_register);
btn_login = (Button) findViewById(R.id.btn_login);
}
- [ ] ObjectAnimator(补间动画)
case R.id.btn_1://透明度
ObjectAnimator objectAnimator_alpha = ObjectAnimator.ofFloat(imageView, "alpha", 1f, 0f);
objectAnimator_alpha.setDuration(3000);
objectAnimator_alpha.setRepeatCount(-1);
objectAnimator_alpha.setRepeatMode(ValueAnimator.REVERSE);
objectAnimator_alpha.start();
break;
case R.id.btn_2://平移
ObjectAnimator objectAnimator_translationX = ObjectAnimator.ofFloat(imageView, "translationX", 0f, 1000f);
objectAnimator_translationX.setDuration(3000);
objectAnimator_translationX.setRepeatCount(-1);
objectAnimator_translationX.setRepeatMode(ValueAnimator.REVERSE);
objectAnimator_translationX.start();
break;
case R.id.btn_3://旋转
ObjectAnimator objectAnimator_rotation = ObjectAnimator.ofFloat(imageView, "rotation", 0f, 360f);
objectAnimator_rotation.setDuration(3000);
objectAnimator_rotation.setRepeatCount(-1);
objectAnimator_rotation.setRepeatMode(ValueAnimator.REVERSE);
objectAnimator_rotation.start();
break;
case R.id.btn_4://缩放
ObjectAnimator objectAnimator_scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 1f, 0.5f);
objectAnimator_scaleX.setDuration(3000);
objectAnimator_scaleX.setRepeatCount(-1);
objectAnimator_scaleX.setInterpolator(new OvershootInterpolator());
objectAnimator_scaleX.setRepeatMode(ValueAnimator.REVERSE);
objectAnimator_scaleX.start();
break;
case R.id.btn_5:
// ObjectAnimator alpha=ObjectAnimator.ofFloat(imageView,"alpha",1f,0f);
// ObjectAnimator translationX=ObjectAnimator.ofFloat(imageView,"translationX",0f,100f);
// ObjectAnimator rotation=ObjectAnimator.ofFloat(imageView,"rotation",0f,360f);
// ObjectAnimator scaleX=ObjectAnimator.ofFloat(imageView,"scaleX",1f,0.5f);
//
// AnimatorSet animatorSet=new AnimatorSet();
with(anim) 同时进行
// //before(anim) 在之前进行
//after(anim) 在之后进行
//after(Long) 延时执行
// animatorSet.play(alpha).with(translationX).after(rotation).before(scaleX);
// animatorSet.setDuration(5000);
// animatorSet.start();