From 5f0b647c2524c3b60788d0e8ca6a51e4ede80f81 Mon Sep 17 00:00:00 2001 From: huangjian Date: Wed, 1 Dec 2021 10:27:26 +0800 Subject: [PATCH] =?UTF-8?q?bug=20fix:1.=E5=8F=91=E8=B5=B7=E8=B7=A8?= =?UTF-8?q?=E6=88=BFPK=E8=87=AA=E5=AE=9A=E4=B9=89=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=96=B9=E5=BC=8F=E4=BC=98=E5=8C=96=202.?= =?UTF-8?q?=E9=92=BB=E7=9F=B3=E5=BC=80=E7=AE=B1=E6=98=AF=E5=90=A6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=A4=84=E7=90=86=E6=97=B6=E9=97=B4=E7=9B=B8=E7=AD=89?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5=203.=E5=8E=BB=E6=8E=89=E9=87=8DPK?= =?UTF-8?q?=E6=96=B9=E8=BF=9B=E5=85=A5=E6=88=BF=E9=97=B4=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=204.PK=E9=9D=A2=E6=9D=BF=E6=9C=89=E6=97=B6?= =?UTF-8?q?=E5=80=99=E5=B1=95=E5=BC=80=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../avroom/anotherroompk/RoomPKBoardView.kt | 13 +- .../anotherroompk/RoomPKCreateActivity.kt | 19 +- .../erban/avroom/widget/MessageView.java | 3 - .../res/layout/activity_room_pk_create.xml | 3 +- .../res/layout/layout_room_pk_board_view.xml | 487 +++++++------- .../res/layout/layout_room_pk_help_view.xml | 1 - .../utils/TimeUtils.java | 610 +++++++++--------- 7 files changed, 576 insertions(+), 560 deletions(-) diff --git a/app/src/main/java/com/yizhuan/erban/avroom/anotherroompk/RoomPKBoardView.kt b/app/src/main/java/com/yizhuan/erban/avroom/anotherroompk/RoomPKBoardView.kt index 32c0a9594..f0a7dfc59 100644 --- a/app/src/main/java/com/yizhuan/erban/avroom/anotherroompk/RoomPKBoardView.kt +++ b/app/src/main/java/com/yizhuan/erban/avroom/anotherroompk/RoomPKBoardView.kt @@ -8,6 +8,7 @@ import android.util.AttributeSet import android.view.Gravity import android.view.LayoutInflater import android.view.View +import android.widget.FrameLayout import android.widget.PopupWindow import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.view.isVisible @@ -54,14 +55,14 @@ class RoomPKBoardView @JvmOverloads constructor( if (CommonUtils.isFastDoubleClick(1000)) return@setOnClickListener binding.groupRank.isVisible = !binding.groupRank.isVisible if (binding.groupRank.isVisible) { - binding.root.setBackgroundResource(R.drawable.bg_room_pk_board) - binding.root.updateLayoutParams { + binding.clRoot.setBackgroundResource(R.drawable.bg_room_pk_board) + binding.clRoot.updateLayoutParams { width = ScreenUtil.dip2px(339f) height = ScreenUtil.dip2px(233f) } } else { - binding.root.setBackgroundResource(R.drawable.bg_room_pk_board_small) - binding.root.updateLayoutParams { + binding.clRoot.setBackgroundResource(R.drawable.bg_room_pk_board_small) + binding.clRoot.updateLayoutParams { width = ScreenUtil.dip2px(339f) height = ScreenUtil.dip2px(137f) } @@ -84,7 +85,7 @@ class RoomPKBoardView @JvmOverloads constructor( binding.tvGoAnotherRoom.setOnClickListener { roomPkBean?.let { - AVRoomActivity.startForFromType(context, it.aUid, AVRoomActivity.FROM_TYPE_ROOM_PK) + AVRoomActivity.start(context, it.aUid) } } @@ -137,6 +138,8 @@ class RoomPKBoardView @JvmOverloads constructor( binding.tvTime.text = roomPkBean?.endTime?.let { val remainTime = (it - CurrentTimeUtils.getCurrentTime()).toInt() / 1000 binding.tvTime.setTextColor(Color.parseColor(if (remainTime <= 30) "#ff87a1" else "#fff600")) + binding.tvTime.isVisible = remainTime > 0 + binding.tvEndHint.isVisible = remainTime <= 0 TimeUtil.secToTime(remainTime) } ?: "00:00" } diff --git a/app/src/main/java/com/yizhuan/erban/avroom/anotherroompk/RoomPKCreateActivity.kt b/app/src/main/java/com/yizhuan/erban/avroom/anotherroompk/RoomPKCreateActivity.kt index 74159f8b1..071f519cc 100644 --- a/app/src/main/java/com/yizhuan/erban/avroom/anotherroompk/RoomPKCreateActivity.kt +++ b/app/src/main/java/com/yizhuan/erban/avroom/anotherroompk/RoomPKCreateActivity.kt @@ -58,21 +58,21 @@ class RoomPKCreateActivity : BaseViewBindingActivity - if (isChecked){ + if (isChecked) { pkTime = 10 binding.editTime.setText("") checkCommitEnable() } } binding.rbMin20.setOnCheckedChangeListener { _, isChecked -> - if (isChecked){ + if (isChecked) { pkTime = 20 binding.editTime.setText("") checkCommitEnable() } } binding.rbMin30.setOnCheckedChangeListener { _, isChecked -> - if (isChecked){ + if (isChecked) { pkTime = 30 binding.editTime.setText("") checkCommitEnable() @@ -84,12 +84,6 @@ class RoomPKCreateActivity : BaseViewBindingActivity 180) { - binding.editTime.setText("180") - } - if (pkTime < 5) { - binding.editTime.setText("5") - } if (pkTime != 0) { binding.rg.clearCheck() } @@ -99,7 +93,10 @@ class RoomPKCreateActivity : BaseViewBindingActivity 180) { + "PK时长在5-180分钟内,请重新输入!".toast() + return@setOnClickListener + } currSimpleRoomInfo?.let { RoomPKModel.initiateRoomPK( it.roomUid, @@ -114,7 +111,7 @@ class RoomPKCreateActivity : BaseViewBindingActivity - dialogManager.showTipsDialog(throwable.message,null) + dialogManager.showTipsDialog(throwable.message, null) } ) } diff --git a/app/src/main/java/com/yizhuan/erban/avroom/widget/MessageView.java b/app/src/main/java/com/yizhuan/erban/avroom/widget/MessageView.java index d6d9a408a..05073014f 100644 --- a/app/src/main/java/com/yizhuan/erban/avroom/widget/MessageView.java +++ b/app/src/main/java/com/yizhuan/erban/avroom/widget/MessageView.java @@ -2557,9 +2557,6 @@ public class MessageView extends FrameLayout { enterText = " 的邀请,进入了房间"; } - if (fromType == AVRoomActivity.FROM_TYPE_ROOM_PK) { - enterText = " 从PK方进入了房间"; - } text.append(enterText, new ForegroundColorSpan(whiteColor)); //如果自己在麦上,增加一个欢迎ta的按钮,并且这条消息不是自己的 diff --git a/app/src/main/res/layout/activity_room_pk_create.xml b/app/src/main/res/layout/activity_room_pk_create.xml index 28c622b5a..e672b113e 100644 --- a/app/src/main/res/layout/activity_room_pk_create.xml +++ b/app/src/main/res/layout/activity_room_pk_create.xml @@ -186,6 +186,7 @@ android:background="@drawable/bg_room_pk_common_btn" android:hint="自定义(5-180)" android:inputType="number" + android:maxLength="3" android:paddingStart="20dp" android:paddingEnd="50dp" android:textColor="@color/text_title_white" @@ -223,9 +224,9 @@ android:layout_marginEnd="12dp" android:background="@drawable/bg_room_pk_common_btn" android:hint="选填,10个字以内" + android:maxLength="10" android:paddingStart="20dp" android:paddingEnd="50dp" - android:maxLength="10" android:textColor="@color/text_title_white" android:textColorHint="@color/white_transparent_50" android:textSize="15sp" diff --git a/app/src/main/res/layout/layout_room_pk_board_view.xml b/app/src/main/res/layout/layout_room_pk_board_view.xml index 48884f37c..4eb32ca04 100644 --- a/app/src/main/res/layout/layout_room_pk_board_view.xml +++ b/app/src/main/res/layout/layout_room_pk_board_view.xml @@ -1,260 +1,283 @@ - + android:layout_height="233dp"> - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + - + - + - + - + - + - + - + - + - \ No newline at end of file + + + diff --git a/app/src/main/res/layout/layout_room_pk_help_view.xml b/app/src/main/res/layout/layout_room_pk_help_view.xml index 724ea03d9..a6f694aba 100644 --- a/app/src/main/res/layout/layout_room_pk_help_view.xml +++ b/app/src/main/res/layout/layout_room_pk_help_view.xml @@ -14,7 +14,6 @@ android:layout_marginStart="10dp" android:layout_marginTop="24dp" android:layout_marginEnd="10dp" - android:lineSpacingExtra="3dp" android:text="@string/room_pk_help" android:textColor="@color/text_title_white" android:textSize="12sp" /> diff --git a/library/src/main/java/com/yizhuan/xchat_android_library/utils/TimeUtils.java b/library/src/main/java/com/yizhuan/xchat_android_library/utils/TimeUtils.java index e54adb5e3..945bd22c4 100644 --- a/library/src/main/java/com/yizhuan/xchat_android_library/utils/TimeUtils.java +++ b/library/src/main/java/com/yizhuan/xchat_android_library/utils/TimeUtils.java @@ -48,6 +48,7 @@ public class TimeUtils { public static final String DATE_FORMAT = "yyyy-MM-dd"; public static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + public static final long MILLIS_OF_SEC = 1000; public static String getCurrentDateStr() { SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.getDefault()); @@ -157,8 +158,6 @@ public class TimeUtils { return c.getTimeInMillis(); } - public static final long MILLIS_OF_SEC = 1000; - /** * Get current time in secs. * @@ -427,6 +426,308 @@ public class TimeUtils { return t * scale; } + /** + * 将毫秒转换为年月日时分秒 ,只拿时分秒 + * + * @author GaoHuanjie + */ + public static String getYearMonthDayHourMinuteSecond(long timeMillis) { + int timezone = 8; // 时区 + long totalSeconds = timeMillis / 1000; + totalSeconds += 60 * 60 * timezone; + int second = (int) (totalSeconds % 60);// 秒 + long totalMinutes = totalSeconds / 60; + int minute = (int) (totalMinutes % 60);// 分 + long totalHours = totalMinutes / 60; + int hour = (int) (totalHours % 24);// 时 + int totalDays = (int) (totalHours / 24); + int _year = 1970; + int year = _year + totalDays / 366; + int month = 1; + int day = 1; + int diffDays; + boolean leapYear; + while (true) { + int diff = (year - _year) * 365; + diff += (year - 1) / 4 - (_year - 1) / 4; + diff -= ((year - 1) / 100 - (_year - 1) / 100); + diff += (year - 1) / 400 - (_year - 1) / 400; + diffDays = totalDays - diff; + leapYear = (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0); + if (!leapYear && diffDays < 365 || leapYear && diffDays < 366) { + break; + } else { + year++; + } + } + + int[] monthDays; + if (diffDays >= 59 && leapYear) { + monthDays = new int[]{-1, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}; + } else { + monthDays = new int[]{-1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; + } + for (int i = monthDays.length - 1; i >= 1; i--) { + if (diffDays >= monthDays[i]) { + month = i; + day = diffDays - monthDays[i] + 1; + break; + } + } + String hours; + String minutes; + String seconds; + if (hour < 10) { + hours = "0" + hour; + } else { + hours = "" + hour; + } + if (minute < 10) { + minutes = "0" + minute; + } else { + minutes = "" + minute; + } + if (second < 10) { + seconds = "0" + second; + } else { + seconds = "" + second; + } + +// return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second; + return hours + ":" + minutes + ":" + seconds; + } + + public static Date getTimesnight(int i) { + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.HOUR_OF_DAY, i); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.MILLISECOND, 0); + return cal.getTime(); + } + + /*获得指定天数的0点和24点*/ + public static Date getTimesnights(Date time) { + Calendar cal = Calendar.getInstance(); + cal.setTime(time); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.MILLISECOND, 0); + return cal.getTime(); + } + + /** + * 将时间戳ms 转成星座 + * 白羊:0321~0420 天秤:0924~1023 + * 金牛:0421~0521 天蝎:1024~1122 + * 双子:0522~0621 射手:1123~1221 + * 巨蟹:0622~0722 摩羯:1222~0120 + * 狮子:0723~0823 水瓶:0121~0219 + * 处女:0824~0923 双鱼:0220~0320 + */ + public static String msToConstellation(long ms) { + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(ms); + int month = calendar.get(Calendar.MONTH) + 1; + int day = calendar.get(Calendar.DAY_OF_MONTH); + Log.e("mouse_debug", month + ", " + day); + String xingzuo = ""; + switch (month) { + case 1: + xingzuo = day < 21 ? "摩羯座" : "水瓶座"; + break; + case 2: + xingzuo = day < 20 ? "水瓶座" : "双鱼座"; + break; + case 3: + xingzuo = day < 21 ? "双鱼座" : "白羊座"; + break; + case 4: + xingzuo = day < 21 ? "白羊座" : "金牛座"; + break; + case 5: + xingzuo = day < 22 ? "金牛座" : "双子座"; + break; + case 6: + xingzuo = day < 22 ? "双子座" : "巨蟹座"; + break; + case 7: + xingzuo = day < 23 ? "巨蟹座" : "狮子座"; + break; + case 8: + xingzuo = day < 24 ? "狮子座" : "处女座"; + break; + case 9: + xingzuo = day < 24 ? "处女座" : "天秤座"; + break; + case 10: + xingzuo = day < 24 ? "天秤座" : "天蝎座"; + break; + case 11: + xingzuo = day < 23 ? "天蝎座" : "射手座"; + break; + case 12: + xingzuo = day < 22 ? "射手座" : "摩羯座"; + break; + } + return xingzuo; + } + + /** + * 判断是不是 第二天 + * + * @param cacheTime 和 当前时间对比,判断现在是不是第二天了 + * @return + */ + public static boolean isTomorrow(long cacheTime) { + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + int currYear = calendar.get(Calendar.YEAR); + int currMonth = calendar.get(Calendar.MONTH); + int currDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); + calendar.setTimeInMillis(cacheTime); + int cacheYear = calendar.get(Calendar.YEAR); + int cacheMonth = calendar.get(Calendar.MONTH); + int cacheDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); + if (currYear > cacheYear) { + return true; + } + boolean equalYear = currYear == cacheYear; + if (equalYear && currMonth > cacheMonth) { + return true; + } + return equalYear && currMonth == cacheMonth && currDayOfMonth > cacheDayOfMonth; + } + + /** + * @param cacheTime 和 当前时间对比,判断现在是不是当天 + * @return - + */ + public static boolean isToday(long cacheTime) { + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + int currYear = calendar.get(Calendar.YEAR); + int currMonth = calendar.get(Calendar.MONTH); + int currDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); + calendar.setTimeInMillis(cacheTime); + int cacheYear = calendar.get(Calendar.YEAR); + int cacheMonth = calendar.get(Calendar.MONTH); + int cacheDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); + return currYear == cacheYear && currMonth == cacheMonth && currDayOfMonth == cacheDayOfMonth; + } + + /** + * @param cacheTime 和 当前时间对比,是不是同一年 + * @return - + */ + public static boolean isSameYear(long cacheTime) { + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(System.currentTimeMillis()); + int currYear = calendar.get(Calendar.YEAR); + calendar.setTimeInMillis(cacheTime); + int cacheYear = calendar.get(Calendar.YEAR); + return currYear == cacheYear; + } + + /** + * 获得系统时间 年、月、日、小时、分钟 + * + * @return HashMap + */ + public static int getTime24() { + SimpleDateFormat hh = new SimpleDateFormat("HH", Locale.CHINA); + SimpleDateFormat mm = new SimpleDateFormat("mm", Locale.CHINA); + hh.setTimeZone(TimeZone.getTimeZone("GMT+08")); // 获取指定时区的时间 + mm.setTimeZone(TimeZone.getTimeZone("GMT+08")); + Date date = new Date(); + String hour = hh.format(date); + String minute = mm.format(date); + return Integer.parseInt(hour + minute); + } + + public static boolean getTimeLimit(int start_hour, int end_hour) { + if (start_hour == end_hour) return false; + SimpleDateFormat hh = new SimpleDateFormat("HH", Locale.CHINA); + SimpleDateFormat mm = new SimpleDateFormat("mm", Locale.CHINA); + hh.setTimeZone(TimeZone.getTimeZone("GMT+08")); // 获取指定时区的时间 + mm.setTimeZone(TimeZone.getTimeZone("GMT+08")); + Date date = new Date(); + String hour = hh.format(date); + String minute = mm.format(date); + Log.i("stf", "--hour:minute-->" + hour + ":" + minute); + int currentTime = Integer.parseInt(hour + minute); + LogUtil.print("start" + start_hour); + LogUtil.print("end" + end_hour); + LogUtil.print("minuteOfDay" + currentTime); + if (currentTime >= start_hour && currentTime <= end_hour) { + LogUtil.print("工作时间内" + hour + ":" + minute); + return true; + } else { + if (start_hour > end_hour) { + if (currentTime >= start_hour || currentTime <= end_hour) { + return true; + } + } + LogUtil.print("工作时间外" + hour + ":" + minute); + return false; + } + } + + /** + * 获取指定年月的第一天 + * + * @param ym yyyy-MM + * @return + */ + public static String getFirstDayOfMonth(String ym) { + String arr[] = ym.split("-"); + + int year = Integer.parseInt(arr[0]); + int month = Integer.parseInt(arr[1]); + + Calendar cal = Calendar.getInstance(); + //设置年份 + cal.set(Calendar.YEAR, year); + + //设置月份 + cal.set(Calendar.MONTH, month - 1); + //获取某月最小天数 + int firstDay = cal.getMinimum(Calendar.DATE); + //设置日历中月份的最小天数 + cal.set(Calendar.DAY_OF_MONTH, firstDay); + //格式化日期 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + + return sdf.format(cal.getTime()); + } + + /** + * 获取指定年月的最后一天 + * + * @param ym + * @return + */ + public static String getLastDayOfMonth(String ym) { + String arr[] = ym.split("-"); + + int year = Integer.parseInt(arr[0]); + int month = Integer.parseInt(arr[1]); + + Calendar cal = Calendar.getInstance(); + //设置年份 + cal.set(Calendar.YEAR, year); + //设置月份 + cal.set(Calendar.MONTH, month - 1); + //获取某月最大天数 + int lastDay = cal.getActualMaximum(Calendar.DATE); + //设置日历中月份的最大天数 + cal.set(Calendar.DAY_OF_MONTH, lastDay); + //格式化日期 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + return sdf.format(cal.getTime()); + } + public static class YEARS { public static long toMillis(long years) { return checkOverflow(years, DAYS_OF_YEAR * HOURS_OF_DAY * MINUTES_OF_HOUR * SECONDS_OF_MINUTE * MILLIS_OF_SECOND); @@ -609,311 +910,6 @@ public class TimeUtils { } } - /** - * 将毫秒转换为年月日时分秒 ,只拿时分秒 - * - * @author GaoHuanjie - */ - public static String getYearMonthDayHourMinuteSecond(long timeMillis) { - int timezone = 8; // 时区 - long totalSeconds = timeMillis / 1000; - totalSeconds += 60 * 60 * timezone; - int second = (int) (totalSeconds % 60);// 秒 - long totalMinutes = totalSeconds / 60; - int minute = (int) (totalMinutes % 60);// 分 - long totalHours = totalMinutes / 60; - int hour = (int) (totalHours % 24);// 时 - int totalDays = (int) (totalHours / 24); - int _year = 1970; - int year = _year + totalDays / 366; - int month = 1; - int day = 1; - int diffDays; - boolean leapYear; - while (true) { - int diff = (year - _year) * 365; - diff += (year - 1) / 4 - (_year - 1) / 4; - diff -= ((year - 1) / 100 - (_year - 1) / 100); - diff += (year - 1) / 400 - (_year - 1) / 400; - diffDays = totalDays - diff; - leapYear = (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0); - if (!leapYear && diffDays < 365 || leapYear && diffDays < 366) { - break; - } else { - year++; - } - } - - int[] monthDays; - if (diffDays >= 59 && leapYear) { - monthDays = new int[]{-1, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}; - } else { - monthDays = new int[]{-1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; - } - for (int i = monthDays.length - 1; i >= 1; i--) { - if (diffDays >= monthDays[i]) { - month = i; - day = diffDays - monthDays[i] + 1; - break; - } - } - String hours; - String minutes; - String seconds; - if (hour < 10) { - hours = "0" + hour; - } else { - hours = "" + hour; - } - if (minute < 10) { - minutes = "0" + minute; - } else { - minutes = "" + minute; - } - if (second < 10) { - seconds = "0" + second; - } else { - seconds = "" + second; - } - -// return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second; - return hours + ":" + minutes + ":" + seconds; - } - - public static Date getTimesnight(int i) { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.HOUR_OF_DAY, i); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.MILLISECOND, 0); - return cal.getTime(); - } - - /*获得指定天数的0点和24点*/ - public static Date getTimesnights(Date time) { - Calendar cal = Calendar.getInstance(); - cal.setTime(time); - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.MILLISECOND, 0); - return cal.getTime(); - } - - /** - * 将时间戳ms 转成星座 - * 白羊:0321~0420 天秤:0924~1023 - * 金牛:0421~0521 天蝎:1024~1122 - * 双子:0522~0621 射手:1123~1221 - * 巨蟹:0622~0722 摩羯:1222~0120 - * 狮子:0723~0823 水瓶:0121~0219 - * 处女:0824~0923 双鱼:0220~0320 - */ - public static String msToConstellation(long ms) { - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(ms); - int month = calendar.get(Calendar.MONTH) + 1; - int day = calendar.get(Calendar.DAY_OF_MONTH); - Log.e("mouse_debug", month + ", " + day); - String xingzuo = ""; - switch (month) { - case 1: - xingzuo = day < 21 ? "摩羯座" : "水瓶座"; - break; - case 2: - xingzuo = day < 20 ? "水瓶座" : "双鱼座"; - break; - case 3: - xingzuo = day < 21 ? "双鱼座" : "白羊座"; - break; - case 4: - xingzuo = day < 21 ? "白羊座" : "金牛座"; - break; - case 5: - xingzuo = day < 22 ? "金牛座" : "双子座"; - break; - case 6: - xingzuo = day < 22 ? "双子座" : "巨蟹座"; - break; - case 7: - xingzuo = day < 23 ? "巨蟹座" : "狮子座"; - break; - case 8: - xingzuo = day < 24 ? "狮子座" : "处女座"; - break; - case 9: - xingzuo = day < 24 ? "处女座" : "天秤座"; - break; - case 10: - xingzuo = day < 24 ? "天秤座" : "天蝎座"; - break; - case 11: - xingzuo = day < 23 ? "天蝎座" : "射手座"; - break; - case 12: - xingzuo = day < 22 ? "射手座" : "摩羯座"; - break; - } - return xingzuo; - } - - /** - * 判断是不是 第二天 - * - * @param cacheTime 和 当前时间对比,判断现在是不是第二天了 - * @return - */ - public static boolean isTomorrow(long cacheTime) { - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - int currYear = calendar.get(Calendar.YEAR); - int currMonth = calendar.get(Calendar.MONTH); - int currDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); - calendar.setTimeInMillis(cacheTime); - int cacheYear = calendar.get(Calendar.YEAR); - int cacheMonth = calendar.get(Calendar.MONTH); - int cacheDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); - if (currYear > cacheYear) { - return true; - } - boolean equalYear = currYear == cacheYear; - if (equalYear && currMonth > cacheMonth) { - return true; - } - return equalYear && currMonth == cacheMonth && currDayOfMonth > cacheDayOfMonth; - } - - /** - * - * - * @param cacheTime 和 当前时间对比,判断现在是不是当天 - * @return - - */ - public static boolean isToday(long cacheTime) { - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - int currYear = calendar.get(Calendar.YEAR); - int currMonth = calendar.get(Calendar.MONTH); - int currDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); - calendar.setTimeInMillis(cacheTime); - int cacheYear = calendar.get(Calendar.YEAR); - int cacheMonth = calendar.get(Calendar.MONTH); - int cacheDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); - return currYear == cacheYear && currMonth == cacheMonth && currDayOfMonth == cacheDayOfMonth; - } - - /** - * - * - * @param cacheTime 和 当前时间对比,是不是同一年 - * @return - - */ - public static boolean isSameYear(long cacheTime) { - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(System.currentTimeMillis()); - int currYear = calendar.get(Calendar.YEAR); - calendar.setTimeInMillis(cacheTime); - int cacheYear = calendar.get(Calendar.YEAR); - return currYear == cacheYear; - } - - - - /** - * 获得系统时间 年、月、日、小时、分钟 - * @return HashMap - */ - public static int getTime24(){ - SimpleDateFormat hh = new SimpleDateFormat("HH", Locale.CHINA); - SimpleDateFormat mm = new SimpleDateFormat("mm", Locale.CHINA); - hh.setTimeZone(TimeZone.getTimeZone("GMT+08")); // 获取指定时区的时间 - mm.setTimeZone(TimeZone.getTimeZone("GMT+08")); - Date date = new Date(); - String hour = hh.format(date); - String minute = mm.format(date); - return Integer.parseInt(hour +minute); - } - - public static boolean getTimeLimit(int start_hour,int end_hour) { - SimpleDateFormat hh = new SimpleDateFormat("HH", Locale.CHINA); - SimpleDateFormat mm = new SimpleDateFormat("mm", Locale.CHINA); - hh.setTimeZone(TimeZone.getTimeZone("GMT+08")); // 获取指定时区的时间 - mm.setTimeZone(TimeZone.getTimeZone("GMT+08")); - Date date = new Date(); - String hour = hh.format(date); - String minute = mm.format(date); - Log.i("stf", "--hour:minute-->" + hour + ":" + minute); - int currentTime = Integer.parseInt(hour +minute); - LogUtil.print("start" +start_hour); - LogUtil.print("end" +end_hour); - LogUtil.print("minuteOfDay" +currentTime); - if (currentTime >= start_hour && currentTime <= end_hour) { - LogUtil.print("工作时间内" + hour + ":" + minute); - return true; - } else { - if (start_hour > end_hour){ - if (currentTime >= start_hour || currentTime <= end_hour){ - return true; - } - } - LogUtil.print( "工作时间外" + hour + ":" + minute); - return false; - } - } - - /** - * 获取指定年月的第一天 - * @param ym yyyy-MM - * @return - */ - public static String getFirstDayOfMonth(String ym) { - String arr[] = ym.split("-"); - - int year = Integer.parseInt(arr[0]); - int month = Integer.parseInt(arr[1]); - - Calendar cal = Calendar.getInstance(); - //设置年份 - cal.set(Calendar.YEAR, year); - - //设置月份 - cal.set(Calendar.MONTH, month - 1); - //获取某月最小天数 - int firstDay = cal.getMinimum(Calendar.DATE); - //设置日历中月份的最小天数 - cal.set(Calendar.DAY_OF_MONTH, firstDay); - //格式化日期 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - - return sdf.format(cal.getTime()); - } - - /** - * 获取指定年月的最后一天 - * @param ym - * @return - */ - public static String getLastDayOfMonth(String ym) { - String arr[] = ym.split("-"); - - int year = Integer.parseInt(arr[0]); - int month = Integer.parseInt(arr[1]); - - Calendar cal = Calendar.getInstance(); - //设置年份 - cal.set(Calendar.YEAR, year); - //设置月份 - cal.set(Calendar.MONTH, month - 1); - //获取某月最大天数 - int lastDay = cal.getActualMaximum(Calendar.DATE); - //设置日历中月份的最大天数 - cal.set(Calendar.DAY_OF_MONTH, lastDay); - //格式化日期 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - return sdf.format(cal.getTime()); - } - - // public static boolean getTimeLimit() { // SimpleDateFormat hh = new SimpleDateFormat("HH", Locale.CHINA);