LoginActivity.java
5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package com.huaheng.robot;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.InputType;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.huaheng.robot.login.ChooseStationActivity;
import com.huaheng.robot.login.NetworkSettingActivity;
import com.huaheng.robot.util.Constant;
import com.huaheng.robot.https.HttpInterface;
import com.huaheng.robot.https.Subscribers.ProgressSubscriber;
import com.huaheng.robot.https.Subscribers.SubscriberOnNextListener;
import com.huaheng.robot.login.UserBean;
import com.huaheng.robot.util.SpeechUtil;
import com.huaheng.robot.util.WMSUtils;
import java.util.ArrayList;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class LoginActivity extends Activity{
@BindView(com.huaheng.robot.R.id.userEdit)
EditText userEdit;
@BindView(com.huaheng.robot.R.id.passwordEdit)
EditText passwordEdit;
@BindView(com.huaheng.robot.R.id.loginBtn)
Button loginBtn;
@BindView(com.huaheng.robot.R.id.eyeImage)
ImageView eyeImage;
@BindView(com.huaheng.robot.R.id.logo)
ImageView logo;
private Context mContext;
private boolean passwordType = false;
private int times = 0;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.huaheng.robot.R.layout.activity_login);
ButterKnife.bind(this);
mContext = this;
initView();
WMSUtils.acquireWakeLock(WMSApplication.getContext());
WMSUtils.requestAppPermission(LoginActivity.this);
}
@Override
protected void onResume() {
super.onResume();
times = 0;
}
private void initView() {
String userName = WMSUtils.getData(Constant.LOGIN_NAME);
if (userName != null) {
userEdit.setText(userName);
WMSUtils.requestFocus(passwordEdit);
}
passwordEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
login();
return false;
}
});
logo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
times++;
if(times >= 3) {
WMSUtils.startActivity(mContext, NetworkSettingActivity.class);
}
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_MENU) {
// WMSUtils.startActivity(mContext, NetworkSettingActivity.class);
} else if(keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
@OnClick({com.huaheng.robot.R.id.eyeImage, com.huaheng.robot.R.id.loginBtn})
public void onViewClicked(View view) {
switch (view.getId()) {
case com.huaheng.robot.R.id.eyeImage:
if (passwordType) {
passwordEdit.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT);
passwordType = false;
eyeImage.setImageResource(com.huaheng.robot.R.mipmap.eye);
} else {
passwordEdit.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
passwordType = true;
eyeImage.setImageResource(com.huaheng.robot.R.mipmap.eyeoff);
}
break;
case com.huaheng.robot.R.id.loginBtn:
login();
break;
}
}
public void login() {
String userName = userEdit.getText().toString();
String password = passwordEdit.getText().toString();
if (TextUtils.isEmpty(userName)) {
WMSUtils.showShort(mContext.getString(com.huaheng.robot.R.string.enter_username));
WMSUtils.requestFocus(userEdit);
return;
}
if (TextUtils.isEmpty(password)) {
WMSUtils.showShort(mContext.getString(com.huaheng.robot.R.string.enter_username));
WMSUtils.requestFocus(passwordEdit);
return;
}
HttpInterface.getInsstance().reset();
HttpInterface.getInsstance().login(new ProgressSubscriber<ArrayList<UserBean>>(mContext, loginListener), userName, password);
}
SubscriberOnNextListener loginListener = new SubscriberOnNextListener<ArrayList<UserBean>>() {
@Override
public void onNext(ArrayList<UserBean> userBean) {
SpeechUtil.getInstance(mContext).speech(mContext.getString(com.huaheng.robot.R.string.login_success));
insertUserInfo(userEdit.getText().toString());
passwordEdit.setText("");
Intent intent = new Intent();
intent.setClass(mContext, ChooseStationActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("userBean", userBean);// 序列化
intent.putExtras(bundle);// 发送数据
startActivity(intent);
}
@Override
public void onError(String str) {
passwordEdit.setText("");
}
};
private void insertUserInfo(String userName) {
WMSUtils.saveData(Constant.LOGIN_NAME, userName);
}
}