165 lines
5.6 KiB
Java
165 lines
5.6 KiB
Java
package com.gh.gamecenter;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.support.v4.content.ContextCompat;
|
|
import android.text.Editable;
|
|
import android.text.TextWatcher;
|
|
import android.view.View;
|
|
import android.widget.EditText;
|
|
import android.widget.ImageView;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
|
|
import com.gh.base.BaseActivity;
|
|
import com.gh.common.util.DisplayUtils;
|
|
import com.gh.common.util.PatternUtils;
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.OnClick;
|
|
|
|
/**
|
|
* Created by khy on 19/06/17.
|
|
*/
|
|
|
|
public class LoginActivity extends BaseActivity {
|
|
|
|
|
|
@BindView(R.id.login_phone_et)
|
|
EditText mLoginPhoneEt;
|
|
@BindView(R.id.login_pass_et)
|
|
EditText mLoginPassEt;
|
|
@BindView(R.id.login_captcha)
|
|
TextView mLoginCaptcha;
|
|
@BindView(R.id.login_hint)
|
|
TextView mLoginHint;
|
|
|
|
Handler mHandler = new Handler() {
|
|
@Override
|
|
public void handleMessage(Message msg) {
|
|
super.handleMessage(msg);
|
|
if (msg.what == 0) {
|
|
int arg1 = msg.arg1;
|
|
arg1--;
|
|
if (arg1 >= 0) {
|
|
Message message = new Message();
|
|
message.what = 0;
|
|
message.arg1 = arg1;
|
|
mHandler.sendMessageDelayed(message, 1000);
|
|
mLoginCaptcha.setText(String.valueOf(arg1));
|
|
} else {
|
|
mLoginCaptcha.setText("重新获取");
|
|
mLoginCaptcha.setTextColor(ContextCompat.getColor(LoginActivity.this, R.color.title));
|
|
mLoginCaptcha.setBackgroundResource(R.drawable.border_black_bg);
|
|
mLoginCaptcha.setEnabled(true);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
@Override
|
|
protected int getLayoutId() {
|
|
return R.layout.activity_login;
|
|
}
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
initTitle("登录光环助手");
|
|
|
|
// 添加老用户入口
|
|
ImageView oldUser = new ImageView(this);
|
|
oldUser.setImageResource(R.drawable.login_olduser_icon);
|
|
oldUser.setPadding(DisplayUtils.dip2px(this, 13), DisplayUtils.dip2px(this, 11)
|
|
, DisplayUtils.dip2px(this, 11), DisplayUtils.dip2px(this, 13));
|
|
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
|
DisplayUtils.dip2px(this, 48), DisplayUtils.dip2px(this, 48));
|
|
params.addRule(RelativeLayout.CENTER_VERTICAL);
|
|
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
|
RelativeLayout reuseActionbar = (RelativeLayout) mContentView.findViewById(
|
|
R.id.reuse_actionbar);
|
|
reuseActionbar.addView(oldUser, params);
|
|
|
|
|
|
mLoginPassEt.addTextChangedListener(new LoginTextWatcher(mLoginPassEt));
|
|
mLoginPhoneEt.addTextChangedListener(new LoginTextWatcher(mLoginPhoneEt));
|
|
|
|
|
|
oldUser.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
toast("老用户入口");
|
|
}
|
|
});
|
|
}
|
|
|
|
@OnClick({R.id.login_captcha, R.id.login_hint})
|
|
public void onViewClicked(View view) {
|
|
switch (view.getId()) {
|
|
case R.id.login_captcha:
|
|
String phoneNum = mLoginPhoneEt.getText().toString().trim();
|
|
if (PatternUtils.isPhoneNum(phoneNum)) {
|
|
Message message = new Message();
|
|
message.what = 0;
|
|
message.arg1 = 10;
|
|
mHandler.sendMessage(message);
|
|
mLoginCaptcha.setTextColor(ContextCompat.getColor(LoginActivity.this, R.color.hint));
|
|
mLoginCaptcha.setBackgroundResource(R.drawable.border_captcha_bg);
|
|
mLoginCaptcha.setEnabled(false);
|
|
} else {
|
|
toast("请输入正确的手机号");
|
|
}
|
|
break;
|
|
case R.id.login_hint:
|
|
break;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
super.onDestroy();
|
|
mHandler.removeCallbacksAndMessages(null);
|
|
}
|
|
|
|
private class LoginTextWatcher implements TextWatcher {
|
|
private EditText mEditText;
|
|
|
|
public LoginTextWatcher(EditText e) {
|
|
mEditText = e;
|
|
}
|
|
|
|
@Override
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
Drawable drawable;
|
|
int tvCount = s.length();
|
|
if (mEditText == mLoginPassEt) {
|
|
if (tvCount > 0) {
|
|
drawable = ContextCompat.getDrawable(LoginActivity.this, R.drawable.login_password_focused);
|
|
} else {
|
|
drawable = ContextCompat.getDrawable(LoginActivity.this, R.drawable.login_password_unfocused);
|
|
}
|
|
} else {
|
|
if (tvCount > 0) {
|
|
drawable = ContextCompat.getDrawable(LoginActivity.this, R.drawable.login_phone_focused);
|
|
} else {
|
|
drawable = ContextCompat.getDrawable(LoginActivity.this, R.drawable.login_phone_unfocused);
|
|
}
|
|
}
|
|
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
|
|
mEditText.setCompoundDrawables(drawable, null, null, null);
|
|
}
|
|
|
|
@Override
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
}
|
|
}
|
|
}
|