android密码错误提醒,android 锁屏 密码错误震动效果

public class MainActivity extends Activity {

private GridView gridViewPwd;

private ImageView mImg1;

private ImageView mImg2;

private ImageView mImg3;

private ImageView mImg4;

private ImageView mImg5;

private ImageView mImg6;

private ImageView[] mImages;

private LoginPwdAdapter loginAdapter;

private String pwdStr = "";

private Animation mShakeAnimation;

private Animation mAlphaAnimation;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

init();

}

private void init() {

mImg1 = (ImageView) findViewById(R.id.img1);

mImg2 = (ImageView) findViewById(R.id.img2);

mImg3 = (ImageView) findViewById(R.id.img3);

mImg4 = (ImageView) findViewById(R.id.img4);

mImg5 = (ImageView) findViewById(R.id.img5);

mImg6 = (ImageView) findViewById(R.id.img6);

mShakeAnimation = AnimationUtils.loadAnimation(this, R.anim.shake);

mAlphaAnimation = AnimationUtils.loadAnimation(this, R.anim.alpha);

mImages = new ImageView[] { mImg1, mImg2, mImg3, mImg4, mImg5, mImg6 };

gridViewPwd = (GridView) findViewById(R.id.gridviewPwd);

loginAdapter = new LoginPwdAdapter(this);

gridViewPwd.setAdapter(loginAdapter);

gridViewPwd

.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView> adapterView,

View view, int i, long l) {

// TextView v= (TextView) adapterView.getSelectedItem();

// String num=v.getText().toString();

int value = i + 1;

if (i == 9) {// 取消

for (int num = 0; num < pwdStr.length(); num++) {

mImages[num]

.setImageResource(R.drawable.page_indicator_unfocused);

}

pwdStr = "";

} else if (i == 11) {// 回退

int len = pwdStr.length();

if (len > 0) {

pwdStr = pwdStr.substring(0, len - 1);

mImages[len - 1]

.setImageResource(R.drawable.page_indicator_unfocused);

}

} else if (i == 10) {

if (pwdStr.length() < 6) {// 密码为六位

pwdStr = pwdStr + "0";

int len = pwdStr.length();

mImages[len - 1]

.setImageResource(R.drawable.page_indicator_focused);

}

} else {

if (pwdStr.length() < 6) {// 密码为六位

pwdStr = pwdStr + value;

int len = pwdStr.length();

mImages[len - 1]

.setImageResource(R.drawable.page_indicator_focused);

}

}

checkPwd(pwdStr);

}

});

}

//密码为8888888时才是正确的

private void checkPwd(String pwdStr) {

if (pwdStr.length() == 6) {

if ("888888".equals(pwdStr)) {

alphaView();

} else {

shakeView();

}

}

}

private void shakeView() {

for (int i = 0; i < mImages.length; i++) {

mImages[i].setImageResource(R.drawable.page_indicator_unfocused);

mImages[i].startAnimation(mShakeAnimation);

}

pwdStr = "";

}

private void alphaView() {

for (int i = 0; i < mImages.length; i++) {

mImages[i].startAnimation(mAlphaAnimation);

}

pwdStr = "";

mAlphaAnimation.setAnimationListener(new Animation.AnimationListener() {

@Override

public void onAnimationStart(Animation animation) {

}

@Override

public void onAnimationEnd(Animation animation) {

/*

* Intent intent = new Intent(MainActivity.this,

* BaseActivity.class);

* intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

* startActivity(intent); finish();

*/

}

@Override

public void onAnimationRepeat(Animation animation) {

}

});

}

}

你可能感兴趣的:(android密码错误提醒)