|
|
@@ -1,161 +1,145 @@
|
|
|
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.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.bean.oa.SelectBean;
|
|
|
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.util.alarm.AlarmManage;
|
|
|
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.ArrayList;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
+import static com.xzjmyk.pm.activity.ui.erp.util.alarm.AlarmManage.ALARMA_CLICK;
|
|
|
+import static com.xzjmyk.pm.activity.ui.erp.util.alarm.AlarmManage.AUTO_SIGNIN;
|
|
|
+
|
|
|
//签到提醒
|
|
|
-public class AlarmaActivity extends BaseActivity implements View.OnClickListener {
|
|
|
+public class AlarmaActivity extends BaseActivity implements View.OnClickListener, SwitchView.OnCheckedChangeListener {
|
|
|
@ViewInject(R.id.isalarma_sw)
|
|
|
private SwitchView isalarma_sw;
|
|
|
- @ViewInject(R.id.editText)
|
|
|
- private EditText editText;
|
|
|
- @ViewInject(R.id.editText2)
|
|
|
- private EditText editText2;
|
|
|
+ @ViewInject(R.id.auto_signin_sw)
|
|
|
+ private SwitchView auto_signin_sw;
|
|
|
+
|
|
|
@ViewInject(R.id.tv_alar)
|
|
|
private TextView tv_alar;//上班时间
|
|
|
+
|
|
|
@ViewInject(R.id.tv_ualar)
|
|
|
private TextView tv_ualar;//下班时间
|
|
|
- private boolean isClick;//判断是否为提醒
|
|
|
- private AlarmaActivity ct;
|
|
|
- private static String ALARMA_CLICK = "ALARMA_CLICK";//判断是否选中
|
|
|
- public static String KEY_ALAR_TIME = "KEY_ALAR_TIME";
|
|
|
- public static String KEY_UALAR_TIME = "KEY_UALAR_TIME";
|
|
|
- private long newTime = System.currentTimeMillis();//当前时间(先取网络时间再取本地时间)
|
|
|
+
|
|
|
+ private boolean isAlarm;//判断是否为提醒
|
|
|
+ private boolean isAuto;//判断是否为自动
|
|
|
+
|
|
|
+
|
|
|
+ public static String KEY_ALAR_TIME = "KEY_ALAR_TIME";//上班提醒时间
|
|
|
+ public static String KEY_UALAR_TIME = "KEY_UALAR_TIME";//下班时间
|
|
|
+
|
|
|
+ private AlarmManage manage;
|
|
|
|
|
|
@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);
|
|
|
- //初始化界面显示时间
|
|
|
+ isAlarm = CommonUtil.getSharedPreferencesBoolean(ct, ALARMA_CLICK, false);
|
|
|
+ isAuto = CommonUtil.getSharedPreferencesBoolean(ct, AUTO_SIGNIN, false);
|
|
|
+ isalarma_sw.setChecked(isAlarm);
|
|
|
+ auto_signin_sw.setChecked(isAuto);
|
|
|
+ manage = new AlarmManage();
|
|
|
+ manage.setSigninAlarm(ct);
|
|
|
tv_alar.setOnClickListener(this);
|
|
|
tv_ualar.setOnClickListener(this);
|
|
|
- isClick = CommonUtil.getSharedPreferencesBoolean(ct, ALARMA_CLICK, false);
|
|
|
- isalarma_sw.setChecked(isClick);
|
|
|
- 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);
|
|
|
+ isalarma_sw.setOnCheckedChangeListener(this);
|
|
|
+ auto_signin_sw.setOnCheckedChangeListener(this);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ String pre = null;
|
|
|
+ String[] time = getResources().getStringArray(R.array.alarm_time);
|
|
|
+ int requestCode = 0;
|
|
|
+ switch (view.getId()) {
|
|
|
+ case R.id.tv_alar:
|
|
|
+ pre = "提前";
|
|
|
+ requestCode = 0x21;
|
|
|
+ break;
|
|
|
+ case R.id.tv_ualar:
|
|
|
+ pre = "延迟";
|
|
|
+ requestCode = 0x22;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ pre = "提前";
|
|
|
+ requestCode = 0x21;
|
|
|
+ break;
|
|
|
}
|
|
|
- tv_alar.setText(uDateTime);
|
|
|
- tv_ualar.setText(dDateTime);
|
|
|
- if (isClick) {
|
|
|
- startThread(isClick);
|
|
|
+ ArrayList<SelectBean> beans = new ArrayList<>();
|
|
|
+ SelectBean bean = null;
|
|
|
+ for (String e : time) {
|
|
|
+ bean = new SelectBean();
|
|
|
+ bean.setName(pre + e);
|
|
|
+ bean.setClick(false);
|
|
|
+ beans.add(bean);
|
|
|
}
|
|
|
- isalarma_sw.setOnCheckedChangeListener(new SwitchView.OnCheckedChangeListener() {
|
|
|
- @Override
|
|
|
- public void onCheckedChanged(View view, boolean isChecked) {
|
|
|
- CommonUtil.putSharedPreferencesBoolean(ct, ALARMA_CLICK, isChecked);
|
|
|
- isClick = isChecked;
|
|
|
- startThread(isChecked);
|
|
|
- }
|
|
|
- });
|
|
|
+ Intent intent = new Intent(ct, SelectActivity.class);
|
|
|
+ intent.putExtra("type", 2);
|
|
|
+ intent.putParcelableArrayListExtra("data", beans);
|
|
|
+ intent.putExtra("title", "选择时间");
|
|
|
+ startActivityForResult(intent, requestCode);
|
|
|
}
|
|
|
|
|
|
- private void startThread(final boolean isChecked) {
|
|
|
- if (isChecked) {
|
|
|
- unArmmanager();
|
|
|
- initArmmanager();
|
|
|
- } else {
|
|
|
- unArmmanager();
|
|
|
+ @Override
|
|
|
+ public void onCheckedChanged(View view, boolean isChecked) {
|
|
|
+
|
|
|
+ switch (view.getId()) {
|
|
|
+ case R.id.isalarma_sw:
|
|
|
+ CommonUtil.setSharedPreferences(ct, AlarmManage.ALARMA_CLICK, isChecked);
|
|
|
+ break;
|
|
|
+ case R.id.auto_signin_sw:
|
|
|
+ CommonUtil.setSharedPreferences(ct, AlarmManage.AUTO_SIGNIN, isChecked);
|
|
|
+ break;
|
|
|
}
|
|
|
+ if (manage == null)
|
|
|
+ manage = new AlarmManage();
|
|
|
+ manage.setSigninAlarm(ct);
|
|
|
}
|
|
|
|
|
|
- //初始化提醒
|
|
|
- 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;
|
|
|
- }
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ if (data == null) return;
|
|
|
+ if (resultCode == 0x20) {
|
|
|
+ SelectBean b = data.getParcelableExtra("data");
|
|
|
+ if (b == null) return;
|
|
|
+ String name = StringUtils.isEmpty(b.getName()) ? "" : b.getName();
|
|
|
+ if (requestCode == 0x22) {
|
|
|
+ tv_ualar.setText(name);
|
|
|
+ CommonUtil.setSharedPreferences(ct, "ALARM_OFFWORK_TIME", getNumByString(name));
|
|
|
+ } else {
|
|
|
+ tv_alar.setText(name);
|
|
|
+ CommonUtil.setSharedPreferences(ct, "ALARM_WORK_TIME", getNumByString(name));
|
|
|
}
|
|
|
- }
|
|
|
- if (isOk) {//在当天允许提醒范围内
|
|
|
- setArmmanager(chche);
|
|
|
- } else {
|
|
|
- if (chchelong != 0) {
|
|
|
- chchelong += 24 * 60 * 60 * 1000;
|
|
|
- setArmmanager(chchelong);
|
|
|
+ if (requestCode == 0x21 || requestCode == 0x22) {
|
|
|
+ if (manage == null)
|
|
|
+ manage = new AlarmManage();
|
|
|
+ manage.setSigninAlarm(ct);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void setArmmanager(long time) {
|
|
|
- if (time <= 0) return;
|
|
|
- //操作:发送一个广播,广播接收后Toast提示定时操作完成
|
|
|
- Intent intent = new Intent(AlarmaActivity.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) {
|
|
|
+ private int getNumByString(String chche) {
|
|
|
if (StringUtils.isEmpty(chche)) return 5;
|
|
|
Pattern p = Pattern.compile("(\\d+)");
|
|
|
Matcher m = p.matcher(chche);
|
|
|
@@ -165,76 +149,4 @@ public class AlarmaActivity extends BaseActivity implements View.OnClickListener
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- private PendingIntent getPendingIntent(Intent intent) {
|
|
|
- return PendingIntent.getBroadcast(AlarmaActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
- }
|
|
|
-
|
|
|
- //清空提醒
|
|
|
- private void unArmmanager() {
|
|
|
- Intent intent = new Intent(AlarmaActivity.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());//保存下班签到的时间
|
|
|
- }
|
|
|
}
|