|
|
@@ -6,7 +6,6 @@ import android.location.LocationManager;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
-import android.provider.Settings;
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
@@ -41,14 +40,15 @@ import com.xzjmyk.pm.activity.ui.erp.util.CodeUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.JsonValidator;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.WifiReceiverUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.tool.ThreadUtil;
|
|
|
import com.xzjmyk.pm.activity.util.BaiduMapUtil;
|
|
|
import com.xzjmyk.pm.activity.util.CalendarUtils;
|
|
|
+import com.xzjmyk.pm.activity.util.MacAndIDUtil;
|
|
|
import com.xzjmyk.pm.activity.util.TimeUtils;
|
|
|
import com.xzjmyk.pm.activity.view.crouton.Crouton;
|
|
|
import com.xzjmyk.pm.activity.view.wheel.OASigninPicker;
|
|
|
|
|
|
-import java.io.FileInputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
@@ -103,6 +103,7 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
private int loginNum = 0; //登陆次数
|
|
|
private boolean isReOne = true;//判断是否是第一次重新定位
|
|
|
private boolean isMacInNet = true;//是否提交过mac地址
|
|
|
+ private String macError = null;
|
|
|
|
|
|
private Handler handler = new Handler() {
|
|
|
@Override
|
|
|
@@ -128,7 +129,7 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
if (loginNum < 3) {
|
|
|
returnLogin();
|
|
|
}
|
|
|
- Crouton.makeText(ct, "当前账号没有分配公司地址,请联系管理员!!");
|
|
|
+ Crouton.makeText(ct, R.string.not_addr_message);
|
|
|
}
|
|
|
if (jsonObject.containsKey("wd_degree")) {//当该用户有排班
|
|
|
//用户有排班时候
|
|
|
@@ -139,20 +140,20 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
loadLog(TimeUtils.s_long_2_str(selectTime));//获取打卡时间
|
|
|
} else {
|
|
|
//如果返回失败
|
|
|
- Crouton.makeText(ct, "系统尚未找到您的班次,请联系管理员设置班次");
|
|
|
+ Crouton.makeText(ct, R.string.not_workdata);
|
|
|
}
|
|
|
break;
|
|
|
case 0x12:
|
|
|
if (parseObject(message).containsKey("listdata")) {
|
|
|
setDataByLogs(parseObject(message).getJSONArray("listdata"));
|
|
|
} else {
|
|
|
- Crouton.makeText(ct, "系统尚未找到您的打卡记录,请联系管理员设置班次");
|
|
|
+ Crouton.makeText(ct, R.string.not_workdata);
|
|
|
}
|
|
|
break;
|
|
|
case 0x13:
|
|
|
//签到成功
|
|
|
if (parseObject(message).containsKey("success") && parseObject(message).getBoolean("success")) {
|
|
|
- Crouton.makeText(ct, "签到成功!");
|
|
|
+ Crouton.makeText(ct, R.string.signin_ok);
|
|
|
handler.postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
@@ -161,7 +162,7 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
}, 20000);
|
|
|
loadLog(selectTime == 0 ? TimeUtils.s_long_2_str(System.currentTimeMillis()) : TimeUtils.s_long_2_str(selectTime));
|
|
|
} else
|
|
|
- Crouton.makeText(ct, "签到失败");
|
|
|
+ Crouton.makeText(ct, R.string.signin_error);
|
|
|
break;
|
|
|
case 0x15:
|
|
|
JSONObject object = JSON.parseObject(message);
|
|
|
@@ -196,23 +197,22 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
if (validator.validate(message)) {
|
|
|
Crouton.makeText(ct, message);
|
|
|
}
|
|
|
- if (loginNum < 3 && StringUtils.isInclude(message, "会话已断开") || StringUtils.isInclude(message, "程序错误")) {
|
|
|
+ if (loginNum < 3 && StringUtils.isInclude(message, getResources().getString(R.string.session_out)) || StringUtils.isInclude(message, "程序错误")) {
|
|
|
returnLogin();
|
|
|
- } else if (StringUtils.isInclude(message, "该设备不是考勤打卡常用设备")
|
|
|
- || StringUtils.isInclude(message, "该设备已被他人绑定")) {
|
|
|
- showError(message);
|
|
|
- } else if (StringUtils.isInclude(message, "404")) {
|
|
|
- CodeUtil.getInstance().getCode(ct, "CardLog", new CodeUtil.OnCodeLinstener() {
|
|
|
- @Override
|
|
|
- public void callBack(String code) {
|
|
|
- doSignin(code);
|
|
|
- }
|
|
|
- });
|
|
|
+ } else if (StringUtils.isInclude(message, getString(R.string.mac_other))) {
|
|
|
+ macError = getResources().getString(R.string.mac_other);
|
|
|
+ } else if (StringUtils.isInclude(message, "该设备不是考勤打卡常用设备")) {
|
|
|
+ showError(getString(R.string.other_phone_error));
|
|
|
+ } else if (StringUtils.isInclude(message, "设备正处于申请变更绑定阶段")) {
|
|
|
+ macError = getResources().getString(R.string.mac_changing);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
+ private String macAddress;
|
|
|
+ private WifiReceiverUtil wifiReceiver;
|
|
|
+ private MacAndIDUtil util;
|
|
|
|
|
|
//生命周期
|
|
|
@Override
|
|
|
@@ -224,6 +224,8 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
@Override
|
|
|
public void onStop() {
|
|
|
super.onStop();
|
|
|
+ if (wifiReceiver != null)
|
|
|
+ wifiReceiver.unRegReceiver(ct);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -264,17 +266,18 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
Crouton.makeText(ct, "当前网络不可用,请检查网络连接");
|
|
|
return;
|
|
|
}
|
|
|
- CodeUtil.getInstance().getCode(ct, "CardLog", new CodeUtil.OnCodeLinstener() {
|
|
|
- @Override
|
|
|
- public void callBack(String code) {
|
|
|
- doSignin(code);
|
|
|
- }
|
|
|
- });
|
|
|
-// if (isMacInNet) {
|
|
|
-// validatorMac();
|
|
|
-// } else {
|
|
|
-// showFristMac();
|
|
|
-// }
|
|
|
+ //TODO 上传文件
|
|
|
+// CodeUtil.getInstance().getCode(ct, "CardLog", new CodeUtil.OnCodeLinstener() {
|
|
|
+// @Override
|
|
|
+// public void callBack(String code) {
|
|
|
+// doSignin(code);
|
|
|
+// }
|
|
|
+// });
|
|
|
+ if (isMacInNet) {
|
|
|
+ validatorMac();
|
|
|
+ } else {
|
|
|
+ showFristMac();
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
case R.id.title:
|
|
|
@@ -366,6 +369,23 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ //初始化mac地址
|
|
|
+ util = new MacAndIDUtil();
|
|
|
+ macAddress = util.getMac(ct);
|
|
|
+ if (StringUtils.isEmpty(macAddress)) {
|
|
|
+ //mac地址不合法时候 提示开启wifi
|
|
|
+ wifiReceiver = new WifiReceiverUtil();
|
|
|
+ wifiReceiver.regReceiver(ct, new WifiReceiverUtil.OnWifiStatusChangeLinstener() {
|
|
|
+ @Override
|
|
|
+ public void callBack(boolean isOpen) {
|
|
|
+ Log.i("gongpengming", "isOpen=" + isOpen);
|
|
|
+ if (isOpen) {
|
|
|
+ macAddress = util.getMac(ct);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void setBaiduLocation() {
|
|
|
@@ -385,20 +405,14 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
listview.setAdapter(adapter);
|
|
|
office_addr.setText(Html.fromHtml("<font color=\'#575757\'>当前位置 " + "</font><font color=\'#000000\'>" + addr + "</font>"));
|
|
|
loadNetData(System.currentTimeMillis());//获取打卡班次信息
|
|
|
-// getMacByNet();
|
|
|
+ getMacByNet();
|
|
|
//判断是否有定位权限
|
|
|
if (!isOpenGps()) {
|
|
|
Crouton.makeText(ct, "为了更好体验,请打开GPS", 3000);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void showError(String m) {
|
|
|
- String message = "";
|
|
|
- if (StringUtils.isInclude(m, "该设备已被他人绑定")) {
|
|
|
- message = "该设备已被他人绑定!若手机更换请先填写手机变更单再来签到";
|
|
|
- } else {
|
|
|
- message = "请在常用手机签到!若手机更换请先填写手机变更单再来签到";
|
|
|
- }
|
|
|
+ private void showError(String message) {
|
|
|
MaterialDialog dialog = new MaterialDialog.Builder(ct).title("提示").content(message)
|
|
|
.positiveText("确定").negativeText("取消").autoDismiss(false).callback(new MaterialDialog.ButtonCallback() {
|
|
|
@Override
|
|
|
@@ -421,8 +435,8 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
|
|
|
//提示用户是否同意第一次上传mac
|
|
|
private void showFristMac() {
|
|
|
- MaterialDialog dialog = new MaterialDialog.Builder(ct).title("提示").content("本次打卡会将本机设为常用签到手机,是否继续签到?")
|
|
|
- .positiveText("确定").negativeText("取消").autoDismiss(false).callback(new MaterialDialog.ButtonCallback() {
|
|
|
+ MaterialDialog dialog = new MaterialDialog.Builder(ct).title(R.string.prompt_title).content(R.string.show_frist_mac)
|
|
|
+ .positiveText(R.string.sure).negativeText(R.string.cancel).autoDismiss(false).callback(new MaterialDialog.ButtonCallback() {
|
|
|
@Override
|
|
|
public void onPositive(MaterialDialog dialog) {
|
|
|
validatorMac();
|
|
|
@@ -463,20 +477,24 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
Crouton.makeText(ct, ct.getString(R.string.networks_out));
|
|
|
return false;
|
|
|
}
|
|
|
+ if (!StringUtils.isEmpty(macError)) {
|
|
|
+ Crouton.makeText(ct, macError);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
if (isSignining) {
|
|
|
- Crouton.makeText(ct, "请不要频繁打卡");
|
|
|
+ Crouton.makeText(ct, R.string.not_signin_agin);
|
|
|
return false;
|
|
|
}
|
|
|
if (companyDistance == -1) {
|
|
|
- Crouton.makeText(ct, "您当前账号没有设置打卡地址信息,请联系管理员");
|
|
|
+ Crouton.makeText(ct, R.string.not_addr_message);
|
|
|
return false;
|
|
|
}
|
|
|
if (companyDistance < distance) {
|
|
|
- Crouton.makeText(ct, "您当前位置距离考勤地点太远,请移往目标或重新定位");
|
|
|
+ Crouton.makeText(ct, R.string.too_long);
|
|
|
return false;
|
|
|
}
|
|
|
if (!isToday) {
|
|
|
- Crouton.makeText(ct, "当前所在日期无法签到");
|
|
|
+ Crouton.makeText(ct, R.string.not_today);
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
@@ -496,63 +514,6 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
return re;
|
|
|
}
|
|
|
|
|
|
- public static String getMac() {
|
|
|
- return Settings.Secure.getString(MyApplication.getInstance().getContentResolver(),
|
|
|
- Settings.Secure.ANDROID_ID);
|
|
|
-// String macSerial = "";
|
|
|
-// try {
|
|
|
-// Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address");
|
|
|
-// InputStreamReader ir = new InputStreamReader(pp.getInputStream());
|
|
|
-// LineNumberReader input = new LineNumberReader(ir);
|
|
|
-// String line;
|
|
|
-// while ((line = input.readLine()) != null) {
|
|
|
-// macSerial += line.trim();
|
|
|
-// }
|
|
|
-// input.close();
|
|
|
-// } catch (IOException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// return macSerial;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static String getLocalMacAddress() {
|
|
|
- String mac = null;
|
|
|
- try {
|
|
|
- String path = "sys/class/net/eth0/address";
|
|
|
- FileInputStream fis_name = new FileInputStream(path);
|
|
|
- byte[] buffer_name = new byte[8192];
|
|
|
- int byteCount_name = fis_name.read(buffer_name);
|
|
|
- if (byteCount_name > 0) {
|
|
|
- mac = new String(buffer_name, 0, byteCount_name, "utf-8");
|
|
|
- }
|
|
|
- if (mac == null) {
|
|
|
- fis_name.close();
|
|
|
- return "";
|
|
|
- }
|
|
|
- fis_name.close();
|
|
|
- } catch (Exception io) {
|
|
|
- String path = "sys/class/net/wlan0/address";
|
|
|
- FileInputStream fis_name;
|
|
|
- try {
|
|
|
- fis_name = new FileInputStream(path);
|
|
|
- byte[] buffer_name = new byte[8192];
|
|
|
- int byteCount_name = fis_name.read(buffer_name);
|
|
|
- if (byteCount_name > 0) {
|
|
|
- mac = new String(buffer_name, 0, byteCount_name, "utf-8");
|
|
|
- }
|
|
|
- fis_name.close();
|
|
|
- } catch (Exception e) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- if (mac == null) {
|
|
|
- return "";
|
|
|
- } else {
|
|
|
- return mac.trim();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
//前后90分钟,isU--是否是上班
|
|
|
private String getEndSignin(String workTime, boolean isU) {
|
|
|
@@ -695,7 +656,7 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
|
|
|
private void setDataForAdapter(List<SigninBean> beans) {
|
|
|
if (companyDistance == -1 || (companyX == 0 && companyY == 0)) {
|
|
|
- Crouton.makeText(ct, "未获取正确考勤地点,请重试或重新登陆");
|
|
|
+ Crouton.makeText(ct, R.string.not_addr_message);
|
|
|
}
|
|
|
if (adapter == null) {
|
|
|
adapter = new SigninAdapter(ct);
|
|
|
@@ -744,15 +705,16 @@ public class SigninFragment extends EasyFragment implements View.OnClickListener
|
|
|
//获取网络数据
|
|
|
String url = "mobile/queryMobileMac.action";
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("macaddress", macAddress);
|
|
|
loadNet(url, param, 0x15);
|
|
|
}
|
|
|
|
|
|
private void validatorMac() {
|
|
|
//获取网络数据
|
|
|
String url = "mobile/addMobileMac.action";
|
|
|
- String mac = getLocalMacAddress();
|
|
|
+
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
- param.put("macAddress", mac);
|
|
|
+ param.put("macAddress", macAddress);
|
|
|
loadNet(url, param, 0x17);
|
|
|
}
|
|
|
|