From: TrillGates Date: Thu, 20 May 2021 08:39:05 +0000 (+0800) Subject: add new cmd for beehome to set time unit. X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=555f68d4ab180cb150589c95fbc345e5e7bd324f;p=protocol_srv.git add new cmd for beehome to set time unit. --- diff --git a/app/release/ICSer_V782_2105112023_release.apk b/app/release/ICSer_V783_2105121430_release.apk similarity index 77% rename from app/release/ICSer_V782_2105112023_release.apk rename to app/release/ICSer_V783_2105121430_release.apk index 83a46e69..f445304e 100644 Binary files a/app/release/ICSer_V782_2105112023_release.apk and b/app/release/ICSer_V783_2105121430_release.apk differ diff --git a/app/release/output.json b/app/release/output.json index 0eca809e..ea1988e0 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":782,"versionName":"2105112023","enabled":true,"outputFile":"ICSer_V782_2105112023_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V782_2105112023_release.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":783,"versionName":"2105121430","enabled":true,"outputFile":"ICSer_V783_2105121430_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V783_2105121430_release.apk","properties":{}}] \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 817e2d0a..e7380f5e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -60,6 +60,7 @@ + diff --git a/app/src/main/java/com/enqualcomm/support/utils/TimeUtil.java b/app/src/main/java/com/enqualcomm/support/utils/TimeUtil.java index c7b89a91..153b0175 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/TimeUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/TimeUtil.java @@ -2,11 +2,9 @@ package com.enqualcomm.support.utils; import android.app.AlarmManager; import android.content.Context; -import android.os.SystemClock; import android.provider.Settings; import android.text.format.DateFormat; -import java.sql.Time; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -17,447 +15,487 @@ import java.util.TimeZone; import static android.content.Context.ALARM_SERVICE; public class TimeUtil { - public static String getLocalTime() { return getLocalTime(System.currentTimeMillis()); } - - public static String getLocalTime(long paramLong) { return (new SimpleDateFormat("yyyy/MM/dd,HH:mm:ss")).format(new Date(paramLong)); } - public static String getLocalTime2() { return getLocalTime2(System.currentTimeMillis()); } - - public static String getLocalTime2(long paramLong) { return (new SimpleDateFormat("MMddHHmmss")).format(new Date(paramLong)); } - - public static String getSystemTimeForCameraMark() { return (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date(System.currentTimeMillis())); } - - public static String getSystemTime() { return getSystemTime(System.currentTimeMillis()); } - - //此处不能随意改动,影响闹铃设置 - public static String getSystemTime(long paramLong) { return (new SimpleDateFormat("yyyy-MM-dd;HH:mm:ss")).format(new Date(paramLong)); } - - public static String getSystemTime2() { return getSystemTime2(System.currentTimeMillis()); } - - public static String getSystemTime2(long paramLong) { return (new SimpleDateFormat("yyyyMMdd;HHmmss")).format(new Date(paramLong)); } - - public static String getSystemTimeyyyyMMddHHmmss() { return getSystemTime3(System.currentTimeMillis()); } - public static String getSystemTime3() { return getSystemTime3(System.currentTimeMillis()); } - - public static String getSystemTime3(long paramLong) { return (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date(paramLong)); } - - public static String getSystemTime4() { return getSystemTime4(System.currentTimeMillis()); } - - public static String getSystemTime4(long paramLong) { return (new SimpleDateFormat("yyyyMMdd")).format(new Date(paramLong)); } - - public static String getSystemDateYYMMDD(){ - return (new SimpleDateFormat("yyMMdd")).format(new Date(System.currentTimeMillis())); - } - public static String getSystemTimeHHmmss(){ - return (new SimpleDateFormat("HHmmss")).format(new Date(System.currentTimeMillis())); - } - - public static String getUTCSystemDateYYMMDD(){ - return (new SimpleDateFormat("yyMMdd")).format(new Date(System.currentTimeMillis()-TimeZone.getDefault().getRawOffset())); - } - public static String getUTCSystemTimeHHmmss(){ - return (new SimpleDateFormat("HHmmss")).format(new Date(System.currentTimeMillis()-TimeZone.getDefault().getRawOffset())); - } - public static Date parseDatetiime(String date,String time){ + public static String getLocalTime() { + return getLocalTime(System.currentTimeMillis()); + } + + public static String getLocalTime(long paramLong) { + return (new SimpleDateFormat("yyyy/MM/dd,HH:mm:ss")).format(new Date(paramLong)); + } + + public static String getLocalTime2() { + return getLocalTime2(System.currentTimeMillis()); + } + + public static String getLocalTime2(long paramLong) { + return (new SimpleDateFormat("MMddHHmmss")).format(new Date(paramLong)); + } + + public static String getSystemTimeForCameraMark() { + return (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date(System.currentTimeMillis())); + } + + public static String getSystemTime() { + return getSystemTime(System.currentTimeMillis()); + } + + //此处不能随意改动,影响闹铃设置 + public static String getSystemTime(long paramLong) { + return (new SimpleDateFormat("yyyy-MM-dd;HH:mm:ss")).format(new Date(paramLong)); + } + + public static String getSystemTime2() { + return getSystemTime2(System.currentTimeMillis()); + } + + public static String getSystemTime2(long paramLong) { + return (new SimpleDateFormat("yyyyMMdd;HHmmss")).format(new Date(paramLong)); + } + + public static String getSystemTimeyyyyMMddHHmmss() { + return getSystemTime3(System.currentTimeMillis()); + } + + public static String getSystemTime3() { + return getSystemTime3(System.currentTimeMillis()); + } + + public static String getSystemTime3(long paramLong) { + return (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date(paramLong)); + } + + public static String getSystemTime4() { + return getSystemTime4(System.currentTimeMillis()); + } + + public static String getSystemTime4(long paramLong) { + return (new SimpleDateFormat("yyyyMMdd")).format(new Date(paramLong)); + } + + public static String getSystemDateYYMMDD() { + return (new SimpleDateFormat("yyMMdd")).format(new Date(System.currentTimeMillis())); + } + + public static String getSystemTimeHHmmss() { + return (new SimpleDateFormat("HHmmss")).format(new Date(System.currentTimeMillis())); + } + + public static String getUTCSystemDateYYMMDD() { + return (new SimpleDateFormat("yyMMdd")).format(new Date(System.currentTimeMillis() - TimeZone.getDefault().getRawOffset())); + } + + public static String getUTCSystemTimeHHmmss() { + return (new SimpleDateFormat("HHmmss")).format(new Date(System.currentTimeMillis() - TimeZone.getDefault().getRawOffset())); + } + + public static Date parseDatetiime(String date, String time) { // SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.ENGLISH);//输入的被转化的时间格式 - SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//需要转化成的时间格式 08:00:00,2016-01-12 + SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//需要转化成的时间格式 08:00:00,2016-01-12 // SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmmssSSS"); // SimpleDateFormat df3 = new SimpleDateFormat("yyyyMMddHHmmss"); - Date date1 = null; - try { - String dt=date+" "+time; - ICLogger.i("parseDatetiime " +dt); - date1 = df1.parse(dt); - return date1; - } catch (ParseException e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); - return null; - } + Date date1 = null; + try { + String dt = date + " " + time; + ICLogger.i("parseDatetiime " + dt); + date1 = df1.parse(dt); + return date1; + } catch (ParseException e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + return null; + } // String str1 = df1.format(date1); // String str2 = df2.format(date1); - } - public static Date parseDatetiime(String datetimeStr){ + } + + public static Date parseDatetiime(String datetimeStr) { // SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.ENGLISH);//输入的被转化的时间格式 // SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//需要转化成的时间格式 // SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmmssSSS"); - SimpleDateFormat df3 = new SimpleDateFormat("yyyyMMddHHmmss"); - Date date1 = null; - try { - date1 = df3.parse(datetimeStr); - return date1; - } catch (ParseException e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); - return null; - } + SimpleDateFormat df3 = new SimpleDateFormat("yyyyMMddHHmmss"); + Date date1 = null; + try { + date1 = df3.parse(datetimeStr); + return date1; + } catch (ParseException e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + return null; + } // String str1 = df1.format(date1); // String str2 = df2.format(date1); - } - /** - * 根据当前日期获得是星期几 - * - * @return - */ - public static String getWeek() { - String time =getSystemTime4(); - String Week = ""; - SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); - Calendar c = Calendar.getInstance(); - try { - c.setTime(format.parse(time)); - } catch (ParseException e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); - } - if (c.get(Calendar.DAY_OF_WEEK) == 1) { - Week += "周天"; - } - if (c.get(Calendar.DAY_OF_WEEK) == 2) { - Week += "周一"; - } - if (c.get(Calendar.DAY_OF_WEEK) == 3) { - Week += "周二"; - } - if (c.get(Calendar.DAY_OF_WEEK) == 4) { - Week += "周三"; - } - if (c.get(Calendar.DAY_OF_WEEK) == 5) { - Week += "周四"; - } - if (c.get(Calendar.DAY_OF_WEEK) == 6) { - Week += "周五"; - } - if (c.get(Calendar.DAY_OF_WEEK) == 7) { - Week += "周六"; - } - return Week; - } - /* 返回 2位年2位月2位日, 如2019-12-30 返回 191230*/ - public static String getShortDate() { - String DEFAULT_TIME_FORMAT = "yyMMdd"; - SimpleDateFormat dateFormatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT); - String dateStr = dateFormatter.format(Calendar.getInstance().getTime());//获取当前时间 - return dateStr; - } - /*061830: 格林尼治时间06 点18 分30 秒 */ - public static String getShortTime(){ - String DEFAULT_TIME_FORMAT = "HHmmss"; - //设置时间的格式 - // yyyy-MM-dd 1969-12-31 - // yyyy-MM-dd 1970-01-01 - // yyyy-MM-dd HH:mm 1969-12-31 16:00 - // yyyy-MM-dd HH:mm 1970-01-01 00:00 - // yyyy-MM-dd HH:mmZ 1969-12-31 16:00-0800 - // yyyy-MM-dd HH:mmZ 1970-01-01 00:00+0000 - // yyyy-MM-dd HH:mm:ss.SSSZ 1969-12-31 16:00:00.000-0800 - // yyyy-MM-dd HH:mm:ss.SSSZ 1970-01-01 00:00:00.000+0000 - // yyyy-MM-dd'T'HH:mm:ss.SSSZ 1969-12-31T16:00:00.000-0800 - // yyyy-MM-dd'T'HH:mm:ss.SSSZ 1970-01-01T00:00:00.000+0000 - //注:HH显示的是24小时制,hh显示的是12小时制 - - SimpleDateFormat dateFormatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT); - String dateStr = dateFormatter.format(Calendar.getInstance().getTime());//获取当前时间 + } + + /** + * 根据当前日期获得是星期几 + * + * @return + */ + public static String getWeek() { + String time = getSystemTime4(); + String Week = ""; + SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); + Calendar c = Calendar.getInstance(); + try { + c.setTime(format.parse(time)); + } catch (ParseException e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); + } + if (c.get(Calendar.DAY_OF_WEEK) == 1) { + Week += "周天"; + } + if (c.get(Calendar.DAY_OF_WEEK) == 2) { + Week += "周一"; + } + if (c.get(Calendar.DAY_OF_WEEK) == 3) { + Week += "周二"; + } + if (c.get(Calendar.DAY_OF_WEEK) == 4) { + Week += "周三"; + } + if (c.get(Calendar.DAY_OF_WEEK) == 5) { + Week += "周四"; + } + if (c.get(Calendar.DAY_OF_WEEK) == 6) { + Week += "周五"; + } + if (c.get(Calendar.DAY_OF_WEEK) == 7) { + Week += "周六"; + } + return Week; + } + + /* 返回 2位年2位月2位日, 如2019-12-30 返回 191230*/ + public static String getShortDate() { + String DEFAULT_TIME_FORMAT = "yyMMdd"; + SimpleDateFormat dateFormatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT); + String dateStr = dateFormatter.format(Calendar.getInstance().getTime());//获取当前时间 + return dateStr; + } + + /*061830: 格林尼治时间06 点18 分30 秒 */ + public static String getShortTime() { + String DEFAULT_TIME_FORMAT = "HHmmss"; + //设置时间的格式 + // yyyy-MM-dd 1969-12-31 + // yyyy-MM-dd 1970-01-01 + // yyyy-MM-dd HH:mm 1969-12-31 16:00 + // yyyy-MM-dd HH:mm 1970-01-01 00:00 + // yyyy-MM-dd HH:mmZ 1969-12-31 16:00-0800 + // yyyy-MM-dd HH:mmZ 1970-01-01 00:00+0000 + // yyyy-MM-dd HH:mm:ss.SSSZ 1969-12-31 16:00:00.000-0800 + // yyyy-MM-dd HH:mm:ss.SSSZ 1970-01-01 00:00:00.000+0000 + // yyyy-MM-dd'T'HH:mm:ss.SSSZ 1969-12-31T16:00:00.000-0800 + // yyyy-MM-dd'T'HH:mm:ss.SSSZ 1970-01-01T00:00:00.000+0000 + //注:HH显示的是24小时制,hh显示的是12小时制 + + SimpleDateFormat dateFormatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT); + String dateStr = dateFormatter.format(Calendar.getInstance().getTime());//获取当前时间 // SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.ENGLISH);//输入的被转化的时间格式 // SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//需要转化成的时间格式 // SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmmssSSS"); - return dateStr; - } - - public static boolean is24Hour(Context mContext){ - return DateFormat.is24HourFormat(mContext); - } - - public static void set24Hour(Context mContext,boolean _is24Hour){ - if (_is24Hour) { - android.provider.Settings.System.putString(mContext.getContentResolver(), - android.provider.Settings.System.TIME_12_24, "24"); - }else{ - android.provider.Settings.System.putString(mContext.getContentResolver(), - android.provider.Settings.System.TIME_12_24, "12"); - } - } - - public static boolean isTimeZoneAuto(Context mContext){ - try { - return android.provider.Settings.Global.getInt(mContext.getContentResolver(), - android.provider.Settings.Global.AUTO_TIME_ZONE) > 0; - } catch (Settings.SettingNotFoundException e) { - e.printStackTrace(); - return false; - } - } - public static void setAutoTimeZone(Context mContext,int checked){ - android.provider.Settings.Global.putInt(mContext.getContentResolver(), - android.provider.Settings.Global.AUTO_TIME_ZONE, checked); - } - - public static boolean isDateTimeAuto(Context mContext){ - try { - return android.provider.Settings.Global.getInt(mContext.getContentResolver(), - android.provider.Settings.Global.AUTO_TIME) > 0; - } catch (Settings.SettingNotFoundException e) { - e.printStackTrace(); - return false; - } - } - - public static void setAutoDateTime(Context mContext,int checked){ - android.provider.Settings.Global.putInt(mContext.getContentResolver(), - android.provider.Settings.Global.AUTO_TIME, checked); - } - - public static void setSysDateTime(Context mContext,Date datetime,int timezone,boolean addtimezoneToTime){ - - AlarmManager alarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE); - Locale.getDefault().getDisplayCountry(); - String timezone_name=""; - if(timezone>0) { - timezone_name=String.format("GMT+%1$02d:00", Math.abs(timezone)); - - }else{ - timezone_name=String.format("GMT-%1$02d:00", Math.abs(timezone)); - } - TimeZone tz = TimeZone.getTimeZone(timezone_name); - ICLogger.i("====set timezone "+tz.getDisplayName()); - - Calendar c = Calendar.getInstance(); - - ICLogger.i("====origin time " + c.getTime().toString()+" time zone "+c.getTimeZone()); - c.setTime(datetime); - if (addtimezoneToTime) { - if (is24Hour(mContext)) { - c.add(Calendar.HOUR_OF_DAY, timezone);//24小时制 - } else { - c.add(Calendar.HOUR, timezone);//12小时制 - } - c.setTimeZone(tz); + return dateStr; } -// alarmManager.setTimeZone(); - long when = c.getTimeInMillis(); - if (when / 1000 < Integer.MAX_VALUE) { - //SystemClock.setCurrentTimeMillis(when); - alarmManager.setTime(when); + public static boolean is24Hour(Context mContext) { + return DateFormat.is24HourFormat(mContext); + } + + public static void set24Hour(Context mContext, boolean _is24Hour) { + if (_is24Hour) { + android.provider.Settings.System.putString(mContext.getContentResolver(), + android.provider.Settings.System.TIME_12_24, "24"); + } else { + android.provider.Settings.System.putString(mContext.getContentResolver(), + android.provider.Settings.System.TIME_12_24, "12"); + } + } + + public static boolean isTimeZoneAuto(Context mContext) { + try { + return android.provider.Settings.Global.getInt(mContext.getContentResolver(), + android.provider.Settings.Global.AUTO_TIME_ZONE) > 0; + } catch (Settings.SettingNotFoundException e) { + e.printStackTrace(); + return false; + } } - Calendar d=Calendar.getInstance(); - long now = d.getTimeInMillis(); - //Log.d(TAG, "set tm="+when + ", now tm="+now); + public static void setAutoTimeZone(Context mContext, int checked) { + android.provider.Settings.Global.putInt(mContext.getContentResolver(), + android.provider.Settings.Global.AUTO_TIME_ZONE, checked); + } + + public static boolean isDateTimeAuto(Context mContext) { + try { + return android.provider.Settings.Global.getInt(mContext.getContentResolver(), + android.provider.Settings.Global.AUTO_TIME) > 0; + } catch (Settings.SettingNotFoundException e) { + e.printStackTrace(); + return false; + } + } - if(now - when > 1000) - { - ICLogger.i("====set time failed now("+now+")-when("+when+") > 1000 !"); + public static void setAutoDateTime(Context mContext, int checked) { + android.provider.Settings.Global.putInt(mContext.getContentResolver(), + android.provider.Settings.Global.AUTO_TIME, checked); } - ICLogger.i("====set time to " + d.getTime().toString()+" time zone "+d.getTimeZone()); + public static void setSysDateTime(Context mContext, Date datetime, int timezone, boolean addtimezoneToTime) { + + AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); + Locale.getDefault().getDisplayCountry(); + String timezone_name = ""; + if (timezone > 0) { + timezone_name = String.format("GMT+%1$02d:00", Math.abs(timezone)); + + } else { + timezone_name = String.format("GMT-%1$02d:00", Math.abs(timezone)); + } + TimeZone tz = TimeZone.getTimeZone(timezone_name); + ICLogger.i("====set timezone " + tz.getDisplayName()); + + Calendar c = Calendar.getInstance(); + + ICLogger.i("====origin time " + c.getTime().toString() + " time zone " + c.getTimeZone()); + c.setTime(datetime); + if (addtimezoneToTime) { + if (is24Hour(mContext)) { + c.add(Calendar.HOUR_OF_DAY, timezone);//24小时制 + } else { + c.add(Calendar.HOUR, timezone);//12小时制 + } + c.setTimeZone(tz); + } - } - public static void setSysDateTime(Context mContext,Date datetime,int timezone){ +// alarmManager.setTimeZone(); + long when = c.getTimeInMillis(); + if (when / 1000 < Integer.MAX_VALUE) { + //SystemClock.setCurrentTimeMillis(when); + alarmManager.setTime(when); + } - setSysDateTime(mContext,datetime,timezone,true); + Calendar d = Calendar.getInstance(); + long now = d.getTimeInMillis(); + //Log.d(TAG, "set tm="+when + ", now tm="+now); - } + if (now - when > 1000) { + ICLogger.i("====set time failed now(" + now + ")-when(" + when + ") > 1000 !"); + } - public static void setSysTime(Context mContext,int hour,int minute,int secounds){ - Calendar c = Calendar.getInstance(); - c.set(Calendar.HOUR_OF_DAY, hour); - c.set(Calendar.MINUTE, minute); - c.set(Calendar.SECOND, secounds); - c.set(Calendar.MILLISECOND, 0); + ICLogger.i("====set time to " + d.getTime().toString() + " time zone " + d.getTimeZone()); - long when = c.getTimeInMillis(); - ICLogger.i("====set time "+c.toString()); - if(when / 1000 < Integer.MAX_VALUE){ - ((AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE)).setTime(when); } - } - // 获取 “GMT+08:00”对应的时区 + public static void setSysDateTime(Context mContext, Date datetime, int timezone) { + + setSysDateTime(mContext, datetime, timezone, true); + + } + + public static void setSysTime(Context mContext, int hour, int minute, int secounds) { + Calendar c = Calendar.getInstance(); + c.set(Calendar.HOUR_OF_DAY, hour); + c.set(Calendar.MINUTE, minute); + c.set(Calendar.SECOND, secounds); + c.set(Calendar.MILLISECOND, 0); + + long when = c.getTimeInMillis(); + ICLogger.i("====set time " + c.toString()); + if (when / 1000 < Integer.MAX_VALUE) { + ((AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE)).setTime(when); + } + } + + // 获取 “GMT+08:00”对应的时区 // TimeZone china = TimeZone.getTimeZone("GMT+:08:00"); - // 获取 “中国/重庆”对应的时区 + // 获取 “中国/重庆”对应的时区 // TimeZone chongqing = TimeZone.getTimeZone("Asia/Chongqing"); - public static void setTimeZone(String timeZone){ - final Calendar now = Calendar.getInstance(); - TimeZone tz = TimeZone.getTimeZone(timeZone); - now.setTimeZone(tz); - } - public static void setTimeZone(Context context,int timeZone) { - - final Calendar now = Calendar.getInstance(); - String timezone_name=""; - if(timeZone>0) { - timezone_name=String.format("GMT+%1$02d:00", Math.abs(timeZone)); - - }else{ - timezone_name=String.format("GMT-%1$02d:00", Math.abs(timeZone)); - } - ICLogger.i("====set timezone "+timezone_name); - //TimeZone tz = TimeZone.getTimeZone(timezone_name); - updateTimeZone(context,timezone_name); - } - - public static void setTimeZone(int timeZone){ - final Calendar now = Calendar.getInstance(); - String timezone_name=""; - if(timeZone>0) { - timezone_name=String.format("GMT+%1$02d:00", Math.abs(timeZone)); + public static void setTimeZone(String timeZone) { + final Calendar now = Calendar.getInstance(); + TimeZone tz = TimeZone.getTimeZone(timeZone); + now.setTimeZone(tz); + } + + public static void setTimeZone(Context context, int timeZone) { + + final Calendar now = Calendar.getInstance(); + String timezone_name = ""; + if (timeZone > 0) { + timezone_name = String.format("GMT+%1$02d:00", Math.abs(timeZone)); + + } else { + timezone_name = String.format("GMT-%1$02d:00", Math.abs(timeZone)); + } + ICLogger.i("====set timezone " + timezone_name); + //TimeZone tz = TimeZone.getTimeZone(timezone_name); + updateTimeZone(context, timezone_name); + } + + public static void setTimeZone(int timeZone) { + final Calendar now = Calendar.getInstance(); + String timezone_name = ""; + if (timeZone > 0) { + timezone_name = String.format("GMT+%1$02d:00", Math.abs(timeZone)); + + } else { + timezone_name = String.format("GMT-%1$02d:00", Math.abs(timeZone)); + } + ICLogger.i("====set timezone " + timezone_name); + TimeZone tz = TimeZone.getTimeZone(timezone_name); + now.setTimeZone(tz); + TimeZone.setDefault(tz); - }else{ - timezone_name=String.format("GMT-%1$02d:00", Math.abs(timeZone)); } - ICLogger.i("====set timezone "+timezone_name); - TimeZone tz = TimeZone.getTimeZone(timezone_name); - now.setTimeZone(tz); - TimeZone.setDefault(tz); - } - public static String getDefaultTimeZone(){ - return TimeZone.getDefault().getDisplayName(); - } - - private static long HOURS12 = 12*60*60*1000 ; - private static long HOURS24 = 24*60*60*1000 ; - - public static String getCurrentSleepRecordDate(){ - return getCurrentSleepRecordDate(System.currentTimeMillis()); - } - public static String getCurrentSleepRecordDate(String date_yyyyMMddHHmmss){ - SimpleDateFormat df3 = new SimpleDateFormat("yyyyMMddHHmmss"); - Date date1 = null; - try { - //获取当天的开始睡眠检测时间 - date1 = df3.parse(date_yyyyMMddHHmmss); - } catch (ParseException e) { - e.printStackTrace(); - return null; - } - return getCurrentSleepRecordDate(date1.getTime()); - } - public static boolean isInSleepRange=false; - public static String getCurrentSleepRecordDate(long currentMS){ - //睡眠检测时间跨天,所以计算要注意日期问题。 - //默认时间段是当天的晚上21点到次日的上午9点。跨度12小时 - - /** currentDate yyyyMMdd */ - String currentDate=getSystemTime4(currentMS); - SimpleDateFormat df3 = new SimpleDateFormat("yyyyMMddHHmmss"); - - Date date1 = null; - try { - //获取当天的开始睡眠检测时间 - date1 = df3.parse(currentDate+"210000"); - } catch (ParseException e) { - e.printStackTrace(); - } - - if (date1!=null) { - //当天开始睡眠检测时间 - long sleep_check_starttime= date1.getTime(); - - long sleep_check_endtime=sleep_check_starttime+HOURS12; - - - long sleep_check_starttime_yestoday = sleep_check_starttime - HOURS24; - long sleep_check_endtime_yestoday=sleep_check_starttime_yestoday+HOURS12; - - if (currentMS > sleep_check_starttime && currentMS sleep_check_starttime_yestoday && currentMS sleep_check_endtime_yestoday && currentMS sleep_check_starttime && currentMS < sleep_check_endtime) { + //在当天的睡眠 检测阶段中,不上报 + isInSleepRange = true; + return getSystemTime4(sleep_check_starttime); + } else if (currentMS > sleep_check_starttime_yestoday && currentMS < sleep_check_endtime_yestoday) { + //在前一天的睡眠检测阶段中,不上报 + isInSleepRange = true; + return getSystemTime4(sleep_check_starttime_yestoday); + } else if (currentMS > sleep_check_endtime_yestoday && currentMS < sleep_check_starttime) { + //前一天的睡眠检测结束,当天睡眠检测还没开始,上报前一天的数据 + //返回 null + isInSleepRange = false; + return getSystemTime4(sleep_check_starttime_yestoday); + } + + } + return null; + } + + public static long diffBetween2DateInMinutes(String dateBefore_yyyyMMDDhhmmss, String dateAfter_yyyyMMDDhhmmss) { + long date1_ms = parseDatetiime(dateBefore_yyyyMMDDhhmmss).getTime(); + long date2_ms = parseDatetiime(dateAfter_yyyyMMDDhhmmss).getTime(); + return (date2_ms - date1_ms) / 60000; + } + + + public static void testUTCSystemtime() { + + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 + + + long currentTime = System.currentTimeMillis() - TimeZone.getDefault().getRawOffset(); + ICLogger.i("UTC currentTime = " + df.format(new Date(currentTime))); + currentTime = Calendar.getInstance().getTimeInMillis(); + ICLogger.i("currentTime = " + df.format(new Date(currentTime))); + currentTime = new Date().getTime(); + + + } + + static String getTimeZoneID_ByDisplayName(String tzname) { + String str = TimeZone.getDefault().getID(); + if (tzname.equals("GMT+03:30")) { + str = "Asia/Tehran"; + } else if (tzname.equals("GMT+04:30")) { + str = "Asia/Kabul"; + } else if (tzname.equals("GMT+05:30")) { + str = "Asia/Colombo"; + } else if (tzname.equals("GMT+06:30")) { + str = "Asia/Rangoon"; + } else if (tzname.equals("GMT+09:30")) { + str = "Australia/Darwin"; + } else if (tzname.equals("GMT+09:00")) { + str = "Asia/Tokyo"; + } + return str; + } + + static void updateTimeZone(Context context, String paramString) { + AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); + ICLogger.d("updateTimeZone:" + paramString); + if (paramString == null) { + ICLogger.d("updateTimeZone name is null"); + return; + } + String[] arrayOfString = TimeZone.getAvailableIDs(); + TimeZone timeZone = TimeZone.getDefault(); + boolean bool = false; + //遍历所有支持的ID,如果字串相同,则设置对应的timezone,否则直接用字符串进行设置 + for (int b = 0; b < arrayOfString.length; b++) { + String tztmp = arrayOfString[b]; + TimeZone timeZone1 = TimeZone.getTimeZone(tztmp); + String tzid = timeZone1.getID(); + // ICLogger.d(b+"/"+arrayOfString.length+" "+paramString+"== "+tztmp+"? ID="+tzid); + if (paramString.equals(timeZone1.getDisplayName(false, TimeZone.SHORT)) && timeZone1.getID().contains("Etc/GMT")) { + + String str1 = timeZone1.getTimeZone(tztmp).getDisplayName(); + String str2 = TimeZone.getTimeZone(tztmp).getID(); + + str1 = "I have find timeZoneDisplayName:" + str1 + " ID:" + str2; + ICLogger.d("===tmp:" + str1); + ICLogger.d("setTimeZone:" + timeZone1.getDisplayName()); + alarmManager.setTimeZone(timeZone1.getID()); + return; + } + } + ICLogger.d(paramString + " not found , set to default timezone " + timeZone.getID()); + alarmManager.setTimeZone(getTimeZoneID_ByDisplayName(paramString)); + } } diff --git a/app/src/main/java/com/ic/protocols/protocol_beehome.java b/app/src/main/java/com/ic/protocols/protocol_beehome.java index 625e1e9b..1cf36919 100644 --- a/app/src/main/java/com/ic/protocols/protocol_beehome.java +++ b/app/src/main/java/com/ic/protocols/protocol_beehome.java @@ -119,6 +119,8 @@ public class protocol_beehome { APHP,//上报心率血压血氧 BPHP, UNKNOWN_CMD, + BPTF,//时间设置 + APTF,//时间设置 } private static HashMap cmdMap = null; @@ -199,7 +201,8 @@ public class protocol_beehome { cmdMap.put(CMD_TYPE.BPS4, "BPS4"); cmdMap.put(CMD_TYPE.APHP, "APHP"); cmdMap.put(CMD_TYPE.BPHP, "BPHP"); - + cmdMap.put(CMD_TYPE.BPTF, "BPTF"); + cmdMap.put(CMD_TYPE.APTF, "APTF"); } @@ -1271,7 +1274,6 @@ public class protocol_beehome { .append(CMDSPLIT).append(ds.getLocationInstance().getLAC()) .append(CMDSPLIT).append(ds.getLocationInstance().getGSMStationCID()) .append(CMDEND).toString()); - } public void handleBPTM(String cmd) { @@ -1767,6 +1769,26 @@ public class protocol_beehome { .append(CMDEND).toString()); } + private void handleBPTF(String cmd, Connection mConnection, Runtime mRuntime) { + //时间格式修改 + //IWBPTF,353456789012345,1# + //参数=1,为24小时,参数=2,为12小时 + String[] split = cmd.split(CMDSPLIT); + if (split.length == 3) { + //第三个是值 + boolean is24Hour; + //24小时格式制 + //12小时格式制 + is24Hour = "1".equals(split[2]); + TimeUtil.set24Hour(mRuntime.getContextProxy().context, is24Hour); + mConnection.send( + genStringMessage(cmdMap.get(CMD_TYPE.APTF), new StringBuilder(CMDHEADER).append(cmdMap.get(CMD_TYPE.APTF)).append(CMDSPLIT) + .append(split[2]).append(CMDEND).toString()) + ); + } + } + + /** * 主要为久坐设置提醒时长。 * @@ -2060,13 +2082,16 @@ public class protocol_beehome { ICLogger.i("收到 提醒设置(时间段)"); mConnection.DeliverCMDMessageToSystem("APS4", cmd);//通知下面线程状态变化 break; + case BPTF: + handleBPTF(cmd, mConnection, mRuntime); + ICLogger.d("收到修改时间格式的指令..."); + break; } return ret; } - public boolean handleCmd(CMD_TYPE type, String cmd, byte[] bytes) { //只有需要传递二级制数据的才需要这个函数,目前只有BP28需要 diff --git a/app/version_code.properties b/app/version_code.properties index 5d48c0fb..868b4811 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,2 +1,2 @@ -#Tue May 11 20:23:28 CST 2021 -VERSION_CODE=782 +#Wed May 12 14:30:06 CST 2021 +VERSION_CODE=783