|
|
@@ -1,383 +0,0 @@
|
|
|
-package com.xzjmyk.pm.activity.ui.erp.activity.oa;
|
|
|
-
|
|
|
-import android.app.AlarmManager;
|
|
|
-import android.app.Notification;
|
|
|
-import android.app.NotificationManager;
|
|
|
-import android.app.PendingIntent;
|
|
|
-import android.content.Context;
|
|
|
-import android.content.DialogInterface;
|
|
|
-import android.content.Intent;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.os.Message;
|
|
|
-import android.support.v7.app.AlertDialog;
|
|
|
-import android.support.v7.app.NotificationCompat;
|
|
|
-import android.view.View;
|
|
|
-import android.widget.EditText;
|
|
|
-import android.widget.TextView;
|
|
|
-
|
|
|
-import com.lidroid.xutils.ViewUtils;
|
|
|
-import com.lidroid.xutils.view.annotation.ViewInject;
|
|
|
-import com.xzjmyk.pm.activity.MyApplication;
|
|
|
-import com.xzjmyk.pm.activity.R;
|
|
|
-import com.xzjmyk.pm.activity.bean.oa.SigninBean;
|
|
|
-import com.xzjmyk.pm.activity.db.dao.SigninDao;
|
|
|
-import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.net.ViewUtil;
|
|
|
-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.ListUtils;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
|
-import com.xzjmyk.pm.activity.ui.erp.view.SwitchView;
|
|
|
-import com.xzjmyk.pm.activity.util.TimeUtils;
|
|
|
-import com.xzjmyk.pm.activity.view.crouton.Crouton;
|
|
|
-
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.regex.Matcher;
|
|
|
-import java.util.regex.Pattern;
|
|
|
-
|
|
|
-//签到提醒
|
|
|
-public class SignremindActivity extends BaseActivity implements View.OnClickListener {
|
|
|
- @ViewInject(R.id.isalarma_sw)
|
|
|
- private SwitchView isalarma_sw;
|
|
|
- @ViewInject(R.id.autosign_sw)
|
|
|
- private SwitchView autosign_sw;
|
|
|
- @ViewInject(R.id.editText)
|
|
|
- private EditText editText;
|
|
|
- @ViewInject(R.id.editText2)
|
|
|
- private EditText editText2;
|
|
|
- @ViewInject(R.id.tv_alar)
|
|
|
- private TextView tv_alar;//上班时间
|
|
|
- @ViewInject(R.id.tv_ualar)
|
|
|
- private TextView tv_ualar;//下班时间
|
|
|
- private int distance = 300; //当前距离
|
|
|
- private String addr = "";//详细
|
|
|
- private String loaction = "";
|
|
|
- private boolean isClick;//判断是否为提醒
|
|
|
- private boolean isAutoClick;//判断是否自动打卡
|
|
|
- private SignremindActivity ct;
|
|
|
- private String code;//账号员工编号
|
|
|
- private String clockin_time = "08:28"; //上班自动打卡时间
|
|
|
- private String clockout_time = "15:20"; //下班自动打卡时间
|
|
|
- private static String ALARMA_CLICK = "ALARMA_CLICK";//判断是否开启考勤提醒
|
|
|
- private static String AUTO_SIGN = "AUTO_SIGN";//判断是否开启自动打卡
|
|
|
- private boolean isSignining = false;//是否正在提交过程
|
|
|
- public static String KEY_ALAR_TIME = "KEY_ALAR_TIME";
|
|
|
- public static String KEY_UALAR_TIME = "KEY_UALAR_TIME";
|
|
|
- private long newTime = System.currentTimeMillis();//当前时间(先取网络时间再取本地时间)
|
|
|
- private android.os.Handler handler = new android.os.Handler() {
|
|
|
- @Override
|
|
|
- public void handleMessage(Message msg) {
|
|
|
- String message = msg.getData().getString("result");
|
|
|
- if (ct.progressDialog.isShowing())
|
|
|
- ct.progressDialog.dismiss();
|
|
|
- switch (msg.what) {
|
|
|
- case 0x13:
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- private String url;
|
|
|
- private Map<String, Object> param;
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreate(Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_oa_alarma);
|
|
|
- ViewUtils.inject(this);
|
|
|
- ct = this;
|
|
|
- initView();
|
|
|
- }
|
|
|
-
|
|
|
- private void initView() {
|
|
|
- //测试使用
|
|
|
- editText.setVisibility(View.GONE);
|
|
|
- editText2.setVisibility(View.GONE);
|
|
|
- //初始化界面显示时间
|
|
|
- tv_alar.setOnClickListener(this);
|
|
|
- tv_ualar.setOnClickListener(this);
|
|
|
- isClick = CommonUtil.getSharedPreferencesBoolean(ct, ALARMA_CLICK, true);//默认打卡提醒开启
|
|
|
- isAutoClick = CommonUtil.getSharedPreferencesBoolean(ct, AUTO_SIGN, true);//默认自动打卡开启
|
|
|
- isalarma_sw.setChecked(isClick);
|
|
|
- autosign_sw.setChecked(isAutoClick);//
|
|
|
- String uDateTime = CommonUtil.getSharedPreferences(ct, KEY_ALAR_TIME);
|
|
|
- String dDateTime = CommonUtil.getSharedPreferences(ct, KEY_UALAR_TIME);
|
|
|
-
|
|
|
- if (uDateTime == null) {
|
|
|
- uDateTime = "提前5分钟";
|
|
|
- CommonUtil.setSharedPreferences(ct, KEY_ALAR_TIME, uDateTime);
|
|
|
- }
|
|
|
- if (dDateTime == null) {
|
|
|
- dDateTime = "延后5分钟";
|
|
|
- CommonUtil.setSharedPreferences(ct, KEY_ALAR_TIME, dDateTime);
|
|
|
- }
|
|
|
- tv_alar.setText(uDateTime);
|
|
|
- tv_ualar.setText(dDateTime);
|
|
|
- if (isClick) {
|
|
|
- startThread(isClick);
|
|
|
- }
|
|
|
-
|
|
|
- isalarma_sw.setOnCheckedChangeListener(new SwitchView.OnCheckedChangeListener() {
|
|
|
- @Override
|
|
|
- public void onCheckedChanged(View view, boolean isChecked) {
|
|
|
- CommonUtil.putSharedPreferencesBoolean(ct, ALARMA_CLICK, isChecked);
|
|
|
- isClick = isChecked;
|
|
|
- if (isalarma_sw.isChecked()) {
|
|
|
- ToastMessage("你已关闭打卡提醒功能,请自行注意打卡时间");
|
|
|
- } else {
|
|
|
- startThread(isChecked);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- autosign_sw.setOnCheckedChangeListener(new SwitchView.OnCheckedChangeListener() {
|
|
|
- @Override
|
|
|
- public void onCheckedChanged(View view, boolean isChecked) {
|
|
|
- CommonUtil.putSharedPreferencesBoolean(ct, AUTO_SIGN, isChecked);
|
|
|
- isAutoClick = isChecked;
|
|
|
- if(autosign_sw.isChecked()){
|
|
|
- ToastMessage("你已关闭自动打卡功能,请自行注意打卡时间");
|
|
|
- }else{
|
|
|
-
|
|
|
- ToastMessage("你已开启自动打卡功能,在打卡有效范围内,系统将自动为你打卡");
|
|
|
- startAutoThread(isChecked);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void startThread(final boolean isChecked) {
|
|
|
- if (isChecked) {
|
|
|
- unArmmanager();
|
|
|
- initArmmanager();
|
|
|
- } else {
|
|
|
- unArmmanager();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 开启自动打卡模式
|
|
|
- */
|
|
|
- private void startAutoThread(final boolean isChecked ){
|
|
|
- if(isChecked){
|
|
|
- String c_time = TimeUtils.long2str(System.currentTimeMillis(), "HH:mm"); //获取当前时间的时分
|
|
|
-
|
|
|
- autosign(code);//执行打卡操作
|
|
|
-/*
|
|
|
- if(c_time.equals(clockin_time)||c_time.equals(clockout_time)){
|
|
|
- if (!CommonUtil.isNetWorkConnected(ct)) {
|
|
|
- Crouton.makeText(ct, "当前网络不可用,请检查网络连接");
|
|
|
- return;
|
|
|
- }
|
|
|
- CodeUtil.getInstance().getCode(ct, "CardLog", new CodeUtil.OnCodeLinstener() {
|
|
|
- @Override
|
|
|
- public void callBack(String code) {
|
|
|
- autosign(code);//执行打卡操作
|
|
|
- }
|
|
|
- });
|
|
|
- }*/
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void autosign(String code){
|
|
|
- url = "mobile/saveCardLog.action";
|
|
|
- param = new HashMap<>();
|
|
|
- Map<String, Object> form = new HashMap<>();
|
|
|
- form.put("cl_code", code);
|
|
|
- form.put("cl_address", addr);
|
|
|
- form.put("cl_phone", MyApplication.getInstance().mLoginUser.getTelephone());
|
|
|
- form.put("cl_emcode", CommonUtil.getSharedPreferences(ct, "erp_username"));
|
|
|
- form.put("cl_emname", MyApplication.getInstance().mLoginUser.getNickName());
|
|
|
- form.put("cl_location", loaction);
|
|
|
- form.put("cl_distance", distance);
|
|
|
- String formStore = StringUtils.mapToJson(form);
|
|
|
- param.put("caller", "CardLog");
|
|
|
- param.put("formStore", formStore);
|
|
|
- loadNet(url, param, 0x13);
|
|
|
- sendsignedremind(); //推送已打卡提醒:确保打卡成功后才推送
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //请求合并,抽取共同代码
|
|
|
- private void loadNet(String urlCheche, Map<String, Object> param, int what) {
|
|
|
- ct.progressDialog.show();
|
|
|
- String url = CommonUtil.getSharedPreferences(ct, "erp_baseurl") + urlCheche;
|
|
|
- if (StringUtils.isEmpty(code)) {
|
|
|
- code = CommonUtil.getSharedPreferences(ct, "erp_username");
|
|
|
- }
|
|
|
- param.put("emcode", code);
|
|
|
- param.put("master", CommonUtil.getSharedPreferences(ct, "erp_master"));
|
|
|
- param.put("sessionUser", CommonUtil.getSharedPreferences(ct, "erp_username"));
|
|
|
- param.put("sessionId", CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
- LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
- headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
- ViewUtil.httpSendRequest(ct, url, param, handler, headers, what, null, null, "get");
|
|
|
- }
|
|
|
-
|
|
|
- private void sendsignedremind(){
|
|
|
- NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
- NotificationCompat.Builder builder = new NotificationCompat.Builder(
|
|
|
- this.getApplicationContext());
|
|
|
- builder.setSmallIcon(R.drawable.uuu);
|
|
|
- builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
|
|
|
- builder.setAutoCancel(true);
|
|
|
- builder.setContentTitle("已签到提醒");
|
|
|
- CharSequence stringExtra = "系统已自动帮你打好卡,详情请点击查看";
|
|
|
- builder.setContentText(stringExtra);
|
|
|
-
|
|
|
- Intent intent = new Intent(this, SigninActivity.class);
|
|
|
- //startActivityForResult(intent, 0x13);
|
|
|
- PendingIntent pendingIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
- builder.setContentIntent(pendingIntent);
|
|
|
- mNotificationManager.notify(1000, builder.build());
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //初始化提醒
|
|
|
- private void initArmmanager() {
|
|
|
- //1.获取打卡时间
|
|
|
- List<SigninBean> beans = SigninDao.getInstance(ct).queryByEmcode();
|
|
|
- if (ListUtils.isEmpty(beans)) return;
|
|
|
- //判断最近的时间是哪个
|
|
|
- //获取提前和往后提醒时间
|
|
|
- int uTime = getMin(CommonUtil.getSharedPreferences(ct, KEY_ALAR_TIME));
|
|
|
- int dTime = getMin(CommonUtil.getSharedPreferences(ct, KEY_UALAR_TIME));
|
|
|
- long utime = (uTime * 60 * 1000);//与上班时间提前的时间
|
|
|
- long dtime = (dTime * 60 * 1000);//与下班时间延后的时间
|
|
|
- long chche = 0;//时间毫秒数
|
|
|
- long chchelong = 0;
|
|
|
- boolean isOk = false;
|
|
|
- for (SigninBean e : beans) {
|
|
|
- //获取与当前时间最近的时间
|
|
|
- if (!StringUtils.isEmpty(e.getWorkTime())) {
|
|
|
- chche = TimeUtils.f_str_2_long(TimeUtils.s_long_2_str(System.currentTimeMillis()) + " " + e.getWorkTime() + ":00") - utime;
|
|
|
- if (chchelong == 0)
|
|
|
- chchelong = chche;
|
|
|
- if (chche > System.currentTimeMillis()) {//在允许范围
|
|
|
- isOk = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- if (!StringUtils.isEmpty(e.getOffTime())) {
|
|
|
- chche = TimeUtils.f_str_2_long(TimeUtils.s_long_2_str(System.currentTimeMillis()) + " " + e.getOffTime() + ":00") + dtime;
|
|
|
- if (chche > System.currentTimeMillis()) {//在允许范围
|
|
|
- isOk = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (isOk) {//在当天允许提醒范围内
|
|
|
- setArmmanager(chche);
|
|
|
- } else {
|
|
|
- if (chchelong != 0) {
|
|
|
- chchelong += 24 * 60 * 60 * 1000;
|
|
|
- setArmmanager(chchelong);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void setArmmanager(long time) {
|
|
|
- if (time <= 0) return;
|
|
|
- //操作:发送一个广播,广播接收后Toast提示定时操作完成
|
|
|
- Intent intent = new Intent(SignremindActivity.this, AlarmReceiver.class);
|
|
|
- intent.setAction("ALARMA_ACTION");
|
|
|
- AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTimeInMillis(time);
|
|
|
- Crouton.makeText(ct, "将在" + TimeUtils.long2str(time, "yyyy-MM-dd HH:mm") + "为您提醒");
|
|
|
- alarm.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), getPendingIntent(intent));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private int getMin(String chche) {
|
|
|
- if (StringUtils.isEmpty(chche)) return 5;
|
|
|
- Pattern p = Pattern.compile("(\\d+)");
|
|
|
- Matcher m = p.matcher(chche);
|
|
|
- if (m.find()) {
|
|
|
- return Integer.parseInt(m.group(0));
|
|
|
- }
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- private PendingIntent getPendingIntent(Intent intent) {
|
|
|
- return PendingIntent.getBroadcast(SignremindActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
- }
|
|
|
-
|
|
|
- //清空提醒
|
|
|
- private void unArmmanager() {
|
|
|
- Intent intent = new Intent(SignremindActivity.this, AlarmReceiver.class);
|
|
|
- intent.setAction("ALARMA_ACTION");
|
|
|
- PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
- AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
- alarm.cancel(pi);
|
|
|
- }
|
|
|
-
|
|
|
- private void showSelectDalog(final TextView tv, final boolean isU) {
|
|
|
- /*
|
|
|
- *上班时间设置,弹出框:提前1分钟,提前2分钟,提前5分钟,提前10分钟,提前20分钟,提前30分钟
|
|
|
- *下班时间设置,弹出款:延迟1分钟,延迟2分钟,延迟5分钟,延迟10分钟,延迟20分钟,延迟30分钟
|
|
|
- */
|
|
|
- final String[] str = new String[6];
|
|
|
- if (isU) {
|
|
|
- str[0] = "提前1分钟";
|
|
|
- str[1] = "提前2分钟";
|
|
|
- str[2] = "提前5分钟";
|
|
|
- str[3] = "提前10分钟";
|
|
|
- str[4] = "提前20分钟";
|
|
|
- str[5] = "提前30分钟";
|
|
|
- } else {
|
|
|
- str[0] = "延迟1分钟";
|
|
|
- str[1] = "延迟2分钟";
|
|
|
- str[2] = "延迟5分钟";
|
|
|
- str[3] = "延迟10分钟";
|
|
|
- str[4] = "延迟20分钟";
|
|
|
- str[5] = "延迟30分钟";
|
|
|
- }
|
|
|
- AlertDialog.Builder builder = new AlertDialog.Builder(ct);
|
|
|
- builder.setTitle("选择时间");
|
|
|
- builder.setItems(str, new DialogInterface.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
- tv.setText(str[i]);
|
|
|
- if (isU) {
|
|
|
- CommonUtil.setSharedPreferences(ct, KEY_ALAR_TIME, str[i]);//保存上班签到的
|
|
|
- } else {
|
|
|
- CommonUtil.setSharedPreferences(ct, KEY_UALAR_TIME, str[i]);//保存下班签到的
|
|
|
- }
|
|
|
- if (isClick) {
|
|
|
- startThread(isClick);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- builder.show();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onClick(View view) {
|
|
|
- switch (view.getId()) {
|
|
|
- case R.id.tv_ualar:
|
|
|
- showSelectDalog(tv_ualar, false);
|
|
|
- break;
|
|
|
- case R.id.tv_alar:
|
|
|
- showSelectDalog(tv_alar, true);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onDestroy() {
|
|
|
- super.onDestroy();
|
|
|
- //退出时候保存时间到本地
|
|
|
- CommonUtil.setSharedPreferences(ct, KEY_ALAR_TIME, tv_alar.getText().toString().trim());//保存上班签到的
|
|
|
- CommonUtil.setSharedPreferences(ct, KEY_UALAR_TIME, tv_ualar.getText().toString().trim());//保存下班签到的时间
|
|
|
- }
|
|
|
-}
|