You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
349 lines
13 KiB
349 lines
13 KiB
package com.icssoft.icspda.activity;
|
|
|
|
import android.Manifest;
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Intent;
|
|
import android.content.pm.PackageManager;
|
|
import android.graphics.Color;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.service.autofill.Dataset;
|
|
import android.view.KeyEvent;
|
|
import android.view.View;
|
|
import android.view.inputmethod.EditorInfo;
|
|
import android.widget.ArrayAdapter;
|
|
import android.widget.Button;
|
|
import android.widget.EditText;
|
|
import android.widget.Spinner;
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
|
|
import androidx.annotation.Nullable;
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.icssoft.icspda.R;
|
|
import com.icssoft.icspda.entity.ApplicationModel;
|
|
import com.icssoft.icspda.entity.UserData;
|
|
import com.icssoft.icspda.entity.VersionData;
|
|
import com.icssoft.icspda.entity.WorkPointData;
|
|
import com.icssoft.icspda.net.WebServiceUtil;
|
|
import com.icssoft.icspda.util.HelpUtil;
|
|
import com.icssoft.icspda.util.SharedPreUtil;
|
|
import com.icssoft.icspda.util.UpdateManager;
|
|
|
|
import java.sql.SQLOutput;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
public class LoginActivity extends AppCompatActivity {
|
|
private TextView tvMsg;
|
|
private EditText login_account;
|
|
private EditText login_pwd;
|
|
private Button set;
|
|
private Button login;
|
|
private Button cancel;
|
|
private Spinner sp_iplist;
|
|
private int Version;
|
|
private int thisVersion;
|
|
private String Url;
|
|
private List<WorkPointData> lst;
|
|
private ArrayAdapter<WorkPointData> arrayAdapter;
|
|
private String ErrorMsg = "";
|
|
private String result="";
|
|
private boolean isLogin = false;
|
|
public static UserData user = new UserData();
|
|
|
|
private Handler handler = new Handler() {
|
|
@Override
|
|
public void handleMessage(Message msg) {
|
|
super.handleMessage(msg);
|
|
switch (msg.what) {
|
|
case 0:
|
|
setSpinner();
|
|
break;
|
|
case 1:
|
|
if (isLogin){
|
|
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
|
|
startActivity(intent);
|
|
LoginActivity.this.finish();
|
|
}
|
|
break;
|
|
case 98:
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, ErrorMsg);
|
|
break;
|
|
case 99:
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, ErrorMsg);
|
|
break;
|
|
case 100:
|
|
UpdateAction();
|
|
break;
|
|
|
|
}
|
|
}
|
|
};
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activtity_login);
|
|
bindView();
|
|
}
|
|
@Override
|
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
if (resultCode == 1) {
|
|
//GET_CODE是自定义的页面跳转识别码
|
|
WebServiceUtil.WSDL_URL= (String) SharedPreUtil.getData(this,"ip","");
|
|
new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
spInit();
|
|
}
|
|
}).start();
|
|
}
|
|
}
|
|
|
|
private void bindView() {
|
|
this.setTitle("用户登录");
|
|
set = findViewById(R.id.btn_set);
|
|
login = findViewById(R.id.btn_login);
|
|
cancel = findViewById(R.id.btn_cancel);
|
|
sp_iplist=findViewById(R.id.sp_iplist);
|
|
login_account=findViewById(R.id.et_login_account);
|
|
login_pwd=findViewById(R.id.et_login_pwd);
|
|
tvMsg = findViewById(R.id.tv_login_versioncode);
|
|
|
|
//设置站点
|
|
if ( SharedPreUtil.getData(this,"ip","")==null||SharedPreUtil.getData(this,"ip","").equals("")){
|
|
SharedPreUtil.saveData(this,"ip","http://192.168.0.143:80/ZNZKPDA/PDA.asmx");
|
|
// SharedPreUtil.saveData(this,"ip","http://192.168.1.29/icspda/PDA.asmx");
|
|
}
|
|
WebServiceUtil.WSDL_URL= (String) SharedPreUtil.getData(this,"ip","");
|
|
login_account.setText((String)SharedPreUtil.getData(this,"usercode",""));
|
|
//打开设置站点页面
|
|
set.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
Intent intent = new Intent(LoginActivity.this, SetSiteActivity.class);
|
|
startActivityForResult(intent,1);
|
|
}
|
|
});
|
|
login.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
try {
|
|
new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
login();
|
|
|
|
}
|
|
}).start();
|
|
|
|
} catch (Exception exception) {
|
|
ErrorMsg = exception.getMessage();
|
|
handler.sendEmptyMessage(99);
|
|
}
|
|
}
|
|
});
|
|
login_pwd.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
@Override
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
if (actionId == EditorInfo.IME_ACTION_SEND || actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT
|
|
|| (event != null && KeyEvent.KEYCODE_ENTER == event.getKeyCode() && KeyEvent.ACTION_DOWN == event.getAction())) {
|
|
if (v.getText().length() > 0) {
|
|
new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
login();
|
|
}
|
|
}).start();
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
});
|
|
cancel.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
exit();
|
|
}
|
|
});
|
|
//动态加载下拉框页面
|
|
new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
spInit();
|
|
getNewVersion();
|
|
|
|
}
|
|
}).start();
|
|
// login.setOnClickListener(new View.OnClickListener() {
|
|
// @Override
|
|
// public void onClick(View v) {
|
|
// Intent intent = new Intent(LoginActivity.this, MainActivity.class);
|
|
// startActivity(intent);
|
|
// }
|
|
// });
|
|
}
|
|
|
|
private void UpdateAction() {
|
|
if (thisVersion < Version) {
|
|
// 这里来检测版本是否需要更新
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
int REQUEST_CODE_CONTACT = 101;
|
|
String[] permissions = {
|
|
Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
|
//验证是否许可权限
|
|
for (String str : permissions) {
|
|
if (LoginActivity.this.checkSelfPermission(str) != PackageManager.PERMISSION_GRANTED) {
|
|
//申请权限
|
|
LoginActivity.this.requestPermissions(permissions, REQUEST_CODE_CONTACT);
|
|
return;
|
|
} else {
|
|
//这里就是权限打开之后自己要操作的逻辑
|
|
UpdateManager mUpdateManager = new UpdateManager(LoginActivity.this);
|
|
mUpdateManager.setApkUrl(Url);
|
|
mUpdateManager.checkUpdateInfo();
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
Toast.makeText(LoginActivity.this,"无需更新",Toast.LENGTH_SHORT).show();
|
|
}
|
|
}
|
|
|
|
private void getNewVersion() {
|
|
thisVersion = getVerCode();
|
|
Map params = new HashMap();
|
|
params.put("projectName","PDA移动终端");
|
|
params.put("version",thisVersion+"");
|
|
try {
|
|
result = WebServiceUtil.GetWSReturnInfo("GetNewVersion",params);
|
|
// System.out.println(result);
|
|
if (result!=null&&!result.equals("")){
|
|
VersionData data= new Gson().fromJson(result, VersionData.class);
|
|
Version = Integer.parseInt(data.getVersion());
|
|
Url = data.getUrl();
|
|
}
|
|
handler.sendEmptyMessage(100);
|
|
} catch (Exception exception) {
|
|
exception.printStackTrace();
|
|
}
|
|
}
|
|
|
|
// 获取当前应用的版本号
|
|
public int getVerCode() {
|
|
int verCode = -1;
|
|
try {
|
|
verCode = getPackageManager().getPackageInfo("com.icssoft.icspda", 0).versionCode;
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
}
|
|
return verCode;
|
|
}
|
|
|
|
private void exit() {
|
|
LoginActivity.this.finish();
|
|
System.exit(0);
|
|
}
|
|
|
|
private void login() {
|
|
try {
|
|
Map params = new HashMap();
|
|
String userCode = login_account.getText().toString().trim();
|
|
String userPwd = login_pwd.getText().toString().trim();
|
|
String workPointCode = ((WorkPointData)sp_iplist.getSelectedItem()).getWorkPointCode();
|
|
if (userCode==null||userCode.equals("")){
|
|
ErrorMsg="请输入登录名";
|
|
handler.sendEmptyMessage(99);
|
|
return;
|
|
} else if (userPwd==null||userPwd.equals("")){
|
|
ErrorMsg="请输入密码";
|
|
handler.sendEmptyMessage(99);
|
|
return;
|
|
}
|
|
params.put("workPointCode",workPointCode);
|
|
params.put("userCode",userCode);
|
|
params.put("userPwd",userPwd);
|
|
result = WebServiceUtil.GetWSReturnInfo("Login",params);
|
|
if (!result.equals("True")){
|
|
ErrorMsg = result;
|
|
handler.sendEmptyMessage(98);
|
|
}else{
|
|
isLogin=true;
|
|
getUserByCodeNew();
|
|
getButton();
|
|
handler.sendEmptyMessage(1);
|
|
}
|
|
} catch (Exception exception) {
|
|
exception.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
private void getButton() {
|
|
try {
|
|
Map params = new HashMap();
|
|
params.put("UserId",user.getID());
|
|
params.put("WorkPointCode",user.getWorkPointCode());
|
|
params.put("MenuCode","1.01");
|
|
|
|
result = WebServiceUtil.GetWSReturnInfo("GetButton",params);
|
|
// System.out.println(result);
|
|
SharedPreUtil.saveData(this,"ButtonData",result);
|
|
// System.out.println((String)SharedPreUtil.getData(this,"ButtonData","[{}]"));
|
|
} catch (Exception exception) {
|
|
exception.printStackTrace();
|
|
}
|
|
}
|
|
|
|
private void getUserByCodeNew() {
|
|
try {
|
|
Map params = new HashMap();
|
|
String workPointCode = ((WorkPointData)sp_iplist.getSelectedItem()).getWorkPointCode();
|
|
String userCode = login_account.getText().toString().trim();
|
|
params.put("workPointCode",workPointCode);
|
|
params.put("userCode",userCode);
|
|
result = WebServiceUtil.GetWSReturnInfo("GetUserByCodeNew",params);
|
|
if (!result.equals("[{}]")){
|
|
UserData[] userData = new Gson().fromJson(result, UserData[].class);
|
|
user = userData[0];
|
|
SharedPreUtil.saveData(this,"usercode",user.getUserCode());
|
|
}
|
|
} catch (Exception exception) {
|
|
exception.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
// android主线程中不能对网络进行访问,
|
|
// 对ui页面的修改调整必须在主线程中(可以使用handler解决)
|
|
private void spInit() {
|
|
try {
|
|
result = WebServiceUtil.GetWSReturnInfo2("GetCompanyListNew");
|
|
if (!result.equals("[{}]")||result!=null){
|
|
WorkPointData[] data = new Gson().fromJson(result, WorkPointData[].class);
|
|
WorkPointData[] workPointData = new WorkPointData[]{};
|
|
lst=new ArrayList<WorkPointData>();
|
|
for (WorkPointData wpd : data) {
|
|
lst.add(wpd);
|
|
}
|
|
handler.sendEmptyMessage(0);
|
|
}
|
|
} catch (Exception exception) {
|
|
exception.printStackTrace();
|
|
}
|
|
}
|
|
|
|
private void setSpinner() {
|
|
arrayAdapter = new ArrayAdapter<WorkPointData>(this, R.layout.simple_spinner_dropdown_item, lst);
|
|
arrayAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
|
|
sp_iplist.setAdapter(arrayAdapter);
|
|
}
|
|
|
|
}
|