天天看點

SP存儲(記住密碼)及 補間動畫

//定義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();
           

繼續閱讀