|
|
@@ -0,0 +1,275 @@
|
|
|
+package com.xzjmyk.pm.activity.ui.erp.activity.oa;
|
|
|
+
|
|
|
+import android.app.AlarmManager;
|
|
|
+import android.app.PendingIntent;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.Intent;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.Switch;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.lidroid.xutils.ViewUtils;
|
|
|
+import com.lidroid.xutils.view.annotation.ViewInject;
|
|
|
+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.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.List;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+//签到提醒
|
|
|
+public class Sign_remindActivity extends BaseActivity implements View.OnClickListener {
|
|
|
+ @ViewInject(R.id.isalarma_sw)
|
|
|
+ private SwitchView isalarma_sw;
|
|
|
+ @ViewInject(R.id.autopunch_sw)
|
|
|
+ private SwitchView autopunch_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 boolean isClick;//判断是否为提醒
|
|
|
+ private boolean isAutoClick;//判断是否自动打卡
|
|
|
+ private Sign_remindActivity ct;
|
|
|
+ private static String ALARMA_CLICK = "ALARMA_CLICK";//判断是否选中
|
|
|
+ private static String AUTO_PUNCH = "AUTO_PUNCH";//是否开启自动打卡//
|
|
|
+ public static String KEY_ALAR_TIME = "KEY_ALAR_TIME";
|
|
|
+ public static String KEY_UALAR_TIME = "KEY_UALAR_TIME";
|
|
|
+ private long newTime = System.currentTimeMillis();//当前时间(先取网络时间再取本地时间)
|
|
|
+
|
|
|
+ @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_PUNCH, true);//
|
|
|
+ isalarma_sw.setChecked(isClick);
|
|
|
+ autopunch_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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ autopunch_sw.setOnCheckedChangeListener(new SwitchView.OnCheckedChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void onCheckedChanged(View view, boolean isChecked) {
|
|
|
+ CommonUtil.putSharedPreferencesBoolean(ct, AUTO_PUNCH, isChecked);
|
|
|
+ isAutoClick = isChecked;
|
|
|
+ if(autopunch_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){
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //初始化提醒
|
|
|
+ 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(Sign_remindActivity.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(Sign_remindActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
+ }
|
|
|
+
|
|
|
+ //清空提醒
|
|
|
+ private void unArmmanager() {
|
|
|
+ Intent intent = new Intent(Sign_remindActivity.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());//保存下班签到的时间
|
|
|
+ }
|
|
|
+}
|