Commit d78a94ea by 宁斌

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	base-module/src/main/java/com/gingersoft/gsa/cloud/database/bean/Function.java
#	table-module/src/main/java/com/gingersoft/gsa/cloud/bean/mvp/presenter/orderManager/AllOrderPresenter.java
#	table-module/src/main/java/com/gingersoft/gsa/cloud/bean/mvp/ui/activity/orderManager/OrderDetailActivity.java
#	table-module/src/main/java/com/gingersoft/gsa/cloud/bean/mvp/ui/adapter/OrderCenterAdapter.java
#	table-module/src/main/java/com/gingersoft/gsa/cloud/bean/mvp/ui/adapter/TableAdapter.java
parents 5ff59c46 4fc55fca
......@@ -45,7 +45,7 @@ android {
/**
* 版本号
*/
schemaVersion 15
schemaVersion 16
/**
* greendao输出dao的数据库操作实体类文件夹(相对路径 包名+自定义路径名称,包将创建于包名的直接路径下)
*/
......
......@@ -4,7 +4,7 @@ import android.util.Log;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.utils.encryption.Aes;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtil;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
import com.gingersoft.gsa.cloud.constans.AppConstans;
import com.gingersoft.gsa.cloud.constans.HttpsConstans;
import com.gingersoft.gsa.cloud.globalconfig.applyOptions.intercept.LoggingInterceptor;
......@@ -260,7 +260,7 @@ public class OkHttp3Utils {
public static void noticePersonnel(String errCode, String pushContent) {
String restaurantInfo =
"版本號:" + DeviceUtils.getVersionName(GsaCloudApplication.getAppContext()) + "|" + DeviceUtils.getVersionCode(GsaCloudApplication.getAppContext()) +
"時間:" + TimeUtil.getCurrentDate(TimeUtil.dateFormatYMDHMS) +
"時間:" + TimeUtils.getCurrentDate(TimeUtils.DEFAULT_DATE_FORMAT) +
"報錯CODE:" + errCode +
"品牌名:" + GsaCloudApplication.getBrandName() +
"餐廳名:" + GsaCloudApplication.getRestaurantName() +
......
/*
*
*/
package com.gingersoft.gsa.cloud.base.utils.time;
import android.annotation.SuppressLint;
import android.util.Log;
import com.gingersoft.gsa.cloud.base.utils.log.LogUtil;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
/**
* 描述:日期处理类.
*/
@SuppressWarnings("all")
public class TimeUtil {
/**
* one day millisecond count
*/
public static final long ONE_DAY_MILLISECONDS = 1000 * 3600 * 24;
public static final long ONE_HOUR_MILLISECONDS = 1000 * 3600;
public static final long ONE_MIN_MILLISECONDS = 1000 * 60;
/**
* 时间日期格式化到年月日时分秒.
*/
public static String dateFormatYMDHMS = "yyyy-MM-dd HH:mm:ss";
public static String dateFormatYMDHMS_f = "yyyyMMddHHmmss";
public static String dateFormatMDHM = "MM-dd HH:mm";
public static String dateFormat = "yyyy-MM-dd HH:mm";
/**
* 时间日期格式化到年月日.
*/
public static String dateFormatYMD = "yyyy-MM-dd";
/**
* 时间日期格式化到年月日时分.中文显示
*/
public static String dateFormatYMDHMofChinese = "yyyy年MM月dd日 HH:mm";
/**
* 时间日期格式化到年月日.中文显示
*/
public static String dateFormatYMDofChinese = "yyyy年MM月dd日";
/**
* 时间日期格式化到月日.中文显示
*/
public static String dateFormatMDofChinese = "MM月dd日";
/**
* 时间日期格式化到月.中文显示
*/
public static String dateFormatMofChinese = "MM月";
/**
* 时间日期格式化到年月.
*/
public static String dateFormatYM = "yyyy-MM";
/**
* 时间日期格式化到年月日时分.
*/
public static String dateFormatYMDHM = "yyyy-MM-dd HH:mm";
/**
* 时间日期格式化到月日.
*/
public static String dateFormatMD = "MM/dd";
public static String dateFormatM_D = "MM-dd";
public static String dateFormatM = "MM月";
public static String dateFormatD = "dd";
public static String dateFormatM2 = "MM";
public static String dateFormatMDHMofChinese = "MM月dd日HH时mm分";
public static String dateFormatHMofChinese = "HH时mm分";
/**
* 时分秒.
*/
public static String dateFormatHMS = "HH:mm:ss";
/**
* 时分.
*/
public static String dateFormatHM = "HH:mm";
/**
* 上午/下午时分
*/
public static String dateFormatAHM = "aHH:mm";
public static String dateFormatYMDE = "yyyy/MM/dd E";
public static String dateFormatYMD2 = "yyyy/MM/dd";
private final static ThreadLocal<SimpleDateFormat> dateFormater = new ThreadLocal<SimpleDateFormat>() {
@SuppressLint("SimpleDateFormat")
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}
};
@SuppressLint("SimpleDateFormat")
private final static ThreadLocal<SimpleDateFormat> dateFormater2 = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd");
}
};
/**
* 时间戳转特定格式时间
*
* @param format
* @param timeStamp
* @return
*/
public static String StampToData(String format, long timeStamp) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(new Date(timeStamp));
}
/***
* 将字符串转为时间戳
* @param time
* @param format
* @return
*/
public static String getTimeToStamp(String time, String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.CHINA);
Date date = new Date();
try {
date = sdf.parse(time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String tmptime = String.valueOf(date.getTime()).substring(0, 10);
return tmptime;
}
/***
* 将字符串转为时间戳
* @param time
* @param format
* @return Integer
*/
public static long getTimeToStamp2(String time, String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.CHINA);
Date date = new Date();
try {
date = sdf.parse(time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String tmptime = String.valueOf(date.getTime()).substring(0, 10);
return Long.parseLong(tmptime);
}
public static long getTimeToStamp3(String time, String format) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
Date date = null;
try {
date = simpleDateFormat.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
long ts = date.getTime();
return Long.parseLong(String.valueOf(ts));
}
/**
* 将毫秒转换成秒
*
* @param time
* @return
*/
public static int convertToSecond(Long time) {
Date date = new Date();
date.setTime(time);
return date.getSeconds();
}
/**
* 描述:String类型的日期时间转化为Date类型.
*
* @param strDate String形式的日期时间
* @param format 格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @return Date Date类型日期时间
*/
public static Date getDateByFormat(String strDate, String format) {
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
Date date = null;
try {
date = mSimpleDateFormat.parse(strDate);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
/**
* 描述:获取偏移之后的Date.
*
* @param date 日期时间
* @param calendarField Calendar属性,对应offset的值, 如(Calendar.DATE,表示+offset天,Calendar.HOUR_OF_DAY,表示+offset小时)
* @param offset 偏移(值大于0,表示+,值小于0,表示-)
* @return Date 偏移之后的日期时间
*/
public Date getDateByOffset(Date date, int calendarField, int offset) {
Calendar c = new GregorianCalendar();
try {
c.setTime(date);
c.add(calendarField, offset);
} catch (Exception e) {
e.printStackTrace();
}
return c.getTime();
}
/**
* 描述:获取指定日期时间的字符串(可偏移).
*
* @param strDate String形式的日期时间
* @param format 格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @param calendarField Calendar属性,对应offset的值, 如(Calendar.DATE,表示+offset天,Calendar.HOUR_OF_DAY,表示+offset小时)
* @param offset 偏移(值大于0,表示+,值小于0,表示-)
* @return String String类型的日期时间
*/
public static String getStringByOffset(String strDate, String format, int calendarField, int offset) {
String mDateTime = null;
try {
Calendar c = new GregorianCalendar();
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
c.setTime(mSimpleDateFormat.parse(strDate));
c.add(calendarField, offset);
mDateTime = mSimpleDateFormat.format(c.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
return mDateTime;
}
/**
* 描述:Date类型转化为String类型(可偏移).
*
* @param date the date
* @param format the format
* @param calendarField the calendar field
* @param offset the offset
* @return String String类型日期时间
*/
public static String getStringByOffset(Date date, String format, int calendarField, int offset) {
String strDate = null;
try {
Calendar c = new GregorianCalendar();
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
c.setTime(date);
c.add(calendarField, offset);
strDate = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return strDate;
}
/***
* from yyyy-MM-dd HH:mm:ss to MM-dd HH:mm
* @param before 之前的时间
* @param beforeformat 之前的时间格式
* @param afterformat 之后的时间格式
* @return
*/
public static String formatDate(String before, String beforeformat, String afterformat) {
String after;
try {
Date date = new SimpleDateFormat(beforeformat, Locale.getDefault()).parse(before);
after = new SimpleDateFormat(afterformat, Locale.getDefault()).format(date);
} catch (ParseException e) {
return before;
}
return after;
}
/**
* 描述:Date类型转化为String类型.
*
* @param date the date
* @param format the format
* @return String String类型日期时间
*/
public static String getStringByFormat(Date date, String format) {
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
String strDate = null;
try {
strDate = mSimpleDateFormat.format(date);
} catch (Exception e) {
e.printStackTrace();
}
return strDate;
}
/**
* 描述:获取指定日期时间的字符串,用于导出想要的格式.
*
* @param strDate String形式的日期时间,必须为yyyy-MM-dd HH:mm:ss格式
* @param format 输出格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @return String 转换后的String类型的日期时间
*/
public static String getStringByFormat(String strDate, String format) {
String mDateTime = null;
try {
Calendar c = new GregorianCalendar();
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
c.setTime(mSimpleDateFormat.parse(strDate));
SimpleDateFormat mSimpleDateFormat2 = new SimpleDateFormat(format);
mDateTime = mSimpleDateFormat2.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return mDateTime;
}
/**
* 描述:获取milliseconds表示的日期时间的字符串.
*
* @param format 格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @return String 日期时间字符串
*/
public static String getStringByFormat(long milliseconds, String format) {
String thisDateTime = null;
try {
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
thisDateTime = mSimpleDateFormat.format(milliseconds);
} catch (Exception e) {
e.printStackTrace();
}
return thisDateTime;
}
/**
* 描述:获取表示当前日期时间的字符串.
*
* @param format 格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @return String String类型的当前日期时间
*/
public static String getCurrentDate(String format) {
String curDateTime = null;
try {
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
Calendar c = new GregorianCalendar();
curDateTime = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return curDateTime;
}
/**
* 区分白天还是夜晚
*
* @param time
* @return
*/
public static boolean getDuringOrNight(String time) {
String before = TimeUtil.formatDate(time, "yyyy-MM-dd HH:mm:ss", "HH");
int k = Integer.parseInt(before);
if ((k >= 0 && k < 6) || (k >= 18 && k < 24)) {
return true;
} else {
return false;
}
}
//获取当前系统当天日期
public static String getCurrentDay() {
String curDateTime = null;
try {
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(dateFormat);
Calendar c = new GregorianCalendar();
c.add(Calendar.DAY_OF_MONTH, 0);
curDateTime = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return curDateTime;
}
//获取当前系统当天日期
public static String getCurrentDay2() {
String curDateTime = null;
try {
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(dateFormatYMDHMS);
Calendar c = new GregorianCalendar();
c.add(Calendar.DAY_OF_MONTH, 0);
curDateTime = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return curDateTime;
}
//获取当前系统前后第几天
public static String getNextDay(int i) {
String curDateTime = null;
try {
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(dateFormat);
Calendar c = new GregorianCalendar();
c.add(Calendar.DAY_OF_MONTH, i);
curDateTime = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return curDateTime;
}
//获取当前系统前后第几小时
public static String getNextHour(int i) {
String curDateTime = null;
try {
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(dateFormat);
Calendar c = new GregorianCalendar();
c.add(Calendar.HOUR_OF_DAY, i);
curDateTime = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return curDateTime;
}
/**
* 描述:获取表示当前日期时间的字符串(可偏移).
*
* @param format 格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @param calendarField Calendar属性,对应offset的值, 如(Calendar.DATE,表示+offset天,Calendar.HOUR_OF_DAY,表示+offset小时)
* @param offset 偏移(值大于0,表示+,值小于0,表示-)
* @return String String类型的日期时间
*/
public static String getCurrentDateByOffset(String format, int calendarField, int offset) {
String mDateTime = null;
try {
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
Calendar c = new GregorianCalendar();
c.add(calendarField, offset);
mDateTime = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return mDateTime;
}
/**
* 描述:计算两个日期所差的天数.
*
* @param date1 第一个时间的毫秒表示
* @param date2 第二个时间的毫秒表示
* @return int 所差的天数
*/
public static int getOffectDay(long date1, long date2) {
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
//先判断是否同年
int y1 = calendar1.get(Calendar.YEAR);
int y2 = calendar2.get(Calendar.YEAR);
int d1 = calendar1.get(Calendar.DAY_OF_YEAR);
int d2 = calendar2.get(Calendar.DAY_OF_YEAR);
int maxDays = 0;
int day = 0;
if (y1 - y2 > 0) {
maxDays = calendar2.getActualMaximum(Calendar.DAY_OF_YEAR);
day = d1 - d2 + maxDays;
} else if (y1 - y2 < 0) {
maxDays = calendar1.getActualMaximum(Calendar.DAY_OF_YEAR);
day = d1 - d2 - maxDays;
} else {
day = d1 - d2;
}
return day;
}
/**
* 描述:计算两个日期所差的小时数.
*
* @param date1 第一个时间的毫秒表示
* @param date2 第二个时间的毫秒表示
* @return int 所差的小时数
*/
public static int getOffectHour(long date1, long date2) {
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
int h1 = calendar1.get(Calendar.HOUR_OF_DAY);
int h2 = calendar2.get(Calendar.HOUR_OF_DAY);
int h = 0;
int day = getOffectDay(date1, date2);
h = h1 - h2 + day * 24;
return h;
}
/**
* 描述:计算两个日期所差的分钟数.
*
* @param date1 第一个时间的毫秒表示
* @param date2 第二个时间的毫秒表示
* @return int 所差的分钟数
*/
public static int getOffectMinutes(long date1, long date2) {
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
int m1 = calendar1.get(Calendar.MINUTE);
int m2 = calendar2.get(Calendar.MINUTE);
int h = getOffectHour(date1, date2);
int m = 0;
m = m1 - m2 + h * 60;
return m;
}
/**
* 两个时间相差距离多少天多少小时多少分多少秒
*
* @param str1 时间参数 1 格式:1990-01-01 12:00:00
* @param str2 时间参数 2 格式:2009-01-01 12:00:00
* @return long[] 返回值为:{天, 时, 分, 秒}
*/
public static long[] getDistanceTimes(String str1, String str2) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date one;
Date two;
long day = 0;
long hour = 0;
long min = 0;
long sec = 0;
try {
one = df.parse(str1);
two = df.parse(str2);
long time1 = one.getTime();
long time2 = two.getTime();
long diff;
if (time1 < time2) {
diff = time2 - time1;
} else {
diff = time1 - time2;
}
day = diff / (24 * 60 * 60 * 1000);
hour = (diff / (60 * 60 * 1000) - day * 24);
min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
} catch (ParseException e) {
e.printStackTrace();
}
long[] times = {day, hour, min, sec};
return times;
}
public static long[] getDistanceTimes2(String str1, String str2) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date one;
Date two;
long day = 0;
long hour = 0;
long min = 0;
long sec = 0;
try {
one = df.parse(str1);
two = df.parse(str2);
long time1 = one.getTime();
long time2 = two.getTime();
long diff;
if (time1 < time2) {
diff = time2 - time1;
} else {
diff = time1 - time2;
}
day = diff / (24 * 60 * 60 * 1000);
hour = (diff / (60 * 60 * 1000) - day * 24);
min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
} catch (ParseException e) {
e.printStackTrace();
}
// if (day != 0) {
// hour += day * 24;
// }
// if (hour != 0) {
// min += hour * 60;
// }
long[] times = {day, hour, min};
return times;
}
/**
* 描述:获取本周一.
*
* @param format the format
* @return String String类型日期时间
*/
public static String getFirstDayOfWeek(String format) {
return getDayOfWeek(format, Calendar.MONDAY);
}
/**
* 描述:获取本周日.
*
* @param format the format
* @return String String类型日期时间
*/
public static String getLastDayOfWeek(String format) {
return getDayOfWeek(format, Calendar.SUNDAY);
}
/**
* 描述:获取本周的某一天.
*
* @param format the format
* @param calendarField the calendar field
* @return String String类型日期时间
*/
private static String getDayOfWeek(String format, int calendarField) {
String strDate = null;
try {
Calendar c = new GregorianCalendar();
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
int week = c.get(Calendar.DAY_OF_WEEK);
if (week == calendarField) {
strDate = mSimpleDateFormat.format(c.getTime());
} else {
int offectDay = calendarField - week;
if (calendarField == Calendar.SUNDAY) {
offectDay = 7 - Math.abs(offectDay);
}
c.add(Calendar.DATE, offectDay);
strDate = mSimpleDateFormat.format(c.getTime());
}
} catch (Exception e) {
e.printStackTrace();
}
return strDate;
}
/**
* 描述:获取本月第一天.
*
* @param format the format
* @return String String类型日期时间
*/
public static String getFirstDayOfMonth(String format) {
String strDate = null;
try {
Calendar c = new GregorianCalendar();
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
//当前月的第一天
c.set(GregorianCalendar.DAY_OF_MONTH, 1);
strDate = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return strDate;
}
/**
* 描述:获取本月最后一天.
*
* @param format the format
* @return String String类型日期时间
*/
public static String getLastDayOfMonth(String format) {
String strDate = null;
try {
Calendar c = new GregorianCalendar();
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
// 当前月的最后一天
c.set(Calendar.DATE, 1);
c.roll(Calendar.DATE, -1);
strDate = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return strDate;
}
/**
* 描述:获取表示当前日期的0点时间毫秒数.
*
* @return the first time of day
*/
public static long getFirstTimeOfDay() {
Date date = null;
try {
String currentDate = getCurrentDate(dateFormatYMD);
date = getDateByFormat(currentDate + " 00:00:00", dateFormatYMDHMS);
return date.getTime();
} catch (Exception e) {
}
return -1;
}
/**
* 描述:获取表示当前日期24点时间毫秒数.
*
* @return the last time of day
*/
public static long getLastTimeOfDay() {
Date date = null;
try {
String currentDate = getCurrentDate(dateFormatYMD);
date = getDateByFormat(currentDate + " 24:00:00", dateFormatYMDHMS);
return date.getTime();
} catch (Exception e) {
}
return -1;
}
/**
* 描述:判断是否是闰年()
* <p>(year能被4整除 并且 不能被100整除) 或者 year能被400整除,则该年为闰年.
*
* @param year 年代(如2012)
* @return boolean 是否为闰年
*/
public static boolean isLeapYear(int year) {
if ((year % 4 == 0 && year % 400 != 0) || year % 400 == 0) {
return true;
} else {
return false;
}
}
/**
* 描述:根据时间返回几天前或几分钟的描述.
*
* @param strDate the str date
* @return the string
*/
// public static String formatDateStr2Desc(Context context, String strDate, String outFormat) {
//
// DateFormat df = new SimpleDateFormat(dateFormatYMDHM);
// Calendar c1 = Calendar.getInstance();
// Calendar c2 = Calendar.getInstance();
// try {
// c2.setTime(df.parse(strDate));
// c1.setTime(new Date());
// int d = getOffectDay(c1.getTimeInMillis(), c2.getTimeInMillis());
// if (d == 0) {
// int h = getOffectHour(c1.getTimeInMillis(), c2.getTimeInMillis());
// if (h > 0) {
// return h + context.getString(R.string.an_hour_ago);
// } else if (h < 0) {
// return Math.abs(h) + context.getString(R.string.after_hours);
// } else if (h == 0) {
// int m = getOffectMinutes(c1.getTimeInMillis(), c2.getTimeInMillis());
// if (m > 0) {
// return m + context.getString(R.string.minutes_ago);
// } else if (m < 0) {
// return Math.abs(m) + context.getString(R.string.minutes_later);
// } else {
// return context.getString(R.string.just);
// }
// }
// } else if (d > 0) {
// if (d == 1) {
// return context.getString(R.string.yesterday);
// } else if (d == 2) {
// return context.getString(R.string.day_before_yesterday);
// }
// } else if (d < 0) {
// if (d == -1) {
// return context.getString(R.string.tomorrow);
// } else if (d == -2) {
// return context.getString(R.string.acquired);
// }
// return Math.abs(d) + context.getString(R.string.days_later);
// }
//
// String out = getStringByFormat(strDate, outFormat);
// if (!TextUtils.isEmpty(out)) {
// return out;
// }
// } catch (Exception e) {
// }
// return strDate;
// }
/**
* 取指定日期为星期几
*
* @param strDate 指定日期
* @param inFormat 指定日期格式
* @return String 星期几
*/
public static String getWeekNumber(String strDate, String inFormat) {
String week = "星期日";
Calendar calendar = new GregorianCalendar();
DateFormat df = new SimpleDateFormat(inFormat);
try {
calendar.setTime(df.parse(strDate));
} catch (Exception e) {
return "錯誤";
}
int intTemp = calendar.get(Calendar.DAY_OF_WEEK) - 1;
switch (intTemp) {
case 0:
week = "星期日日";
break;
case 1:
week = "星期一";
break;
case 2:
week = "星期二";
break;
case 3:
week = "星期三";
break;
case 4:
week = "星期四";
break;
case 5:
week = "星期五";
break;
case 6:
week = "星期六";
break;
}
return week;
}
/**
* 将字符串转位日期类型
*
* @param sdate
* @return
*/
private static Date toDate(String sdate) {
try {
return dateFormater.get().parse(sdate);
} catch (ParseException e) {
return null;
}
}
/**
* 以友好的方式显示时间
*
* @param ms
* @return
*/
public static String getfriendlyTime(String sdate) {
if (sdate == null)
return "";
Date time = toDate(sdate);
// Date time = new Date(ms);
if (time == null) {
return "Unknown";
}
String ftime = "";
Calendar cal = Calendar.getInstance();
// 判断是否是同一天
String curDate = dateFormater2.get().format(cal.getTime());
String paramDate = dateFormater2.get().format(time);
LogUtil.d("getfriendlyTime: " + paramDate);
if (curDate.equals(paramDate)) {
int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
if (hour == 0) {
if (((cal.getTimeInMillis() - time.getTime()) / 60000) < 1) {
ftime = "剛剛";
} else {
ftime = Math.max((cal.getTimeInMillis() - time.getTime()) / 60000, 1) + "分鐘前";
}
} else {
ftime = hour + "小時前";
}
return ftime;
}
long lt = time.getTime() / 86400000;
long ct = cal.getTimeInMillis() / 86400000;
int days = (int) (ct - lt);
if (days == 0) {
int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
if (hour == 0)
ftime = Math.max(
(cal.getTimeInMillis() - time.getTime()) / 60000, 1)
+ "分鐘前";
else
ftime = hour + "小時前";
} else if (days == 1) {
ftime = "昨天";
} else if (days == 2) {
ftime = "前天";
} else if (days > 2 && days <= 10) {
ftime = days + "天前";
} else if (days > 10) {
ftime = dateFormater2.get().format(time);
}
return ftime;
}
/**
* 距离当前多少个小时
*
* @param dateStr
* @return
*/
@SuppressLint("SimpleDateFormat")
public static int getExpiredHour(String dateStr) {
int ret = -1;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date;
try {
date = sdf.parse(dateStr);
Date dateNow = new Date();
long times = date.getTime() - dateNow.getTime();
if (times > 0) {
ret = ((int) (times / ONE_HOUR_MILLISECONDS));
} else {
ret = -1;
}
} catch (ParseException e) {
e.printStackTrace();
}
return ret;
}
/**
* 过了多少个小时
*
* @param dateStr
* @return
*/
@SuppressLint("SimpleDateFormat")
public static int getExpiredHour2(String dateStr) {
int ret = -1;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date sendDate;
try {
sendDate = sdf.parse(dateStr);
Date dateNow = new Date(System.currentTimeMillis());
Log.e("JPush", "date=" + sendDate);
long times = dateNow.getTime() - sendDate.getTime();
Log.e("JPush", "date.getTime()=" + sendDate.getTime());
if (times > 0) {
ret = ((int) (times / ONE_HOUR_MILLISECONDS));
int sdqf = (int) Math.floor(times / ONE_HOUR_MILLISECONDS);
} else {
ret = -1;
}
} catch (ParseException e) {
e.printStackTrace();
}
Log.e("JPush", "ret=" + ret);
return ret;
}
/**
* 判断给定字符串时间是否为今日
*
* @param sdate
* @return boolean
*/
public static boolean isToday(String sdate) {
boolean b = false;
Date time = toDate(sdate);
Date today = new Date();
if (time != null) {
String nowDate = dateFormater2.get().format(today);
String timeDate = dateFormater2.get().format(time);
if (nowDate.equals(timeDate)) {
b = true;
}
}
return b;
}
/**
* 判断给定字符串时间是否为今日
*
* @param sdate
* @return boolean
*/
public static boolean isToday(long sdate) {
boolean b = false;
Date time = new Date(sdate);
Date today = new Date();
if (time != null) {
String nowDate = dateFormater2.get().format(today);
String timeDate = dateFormater2.get().format(time);
if (nowDate.equals(timeDate)) {
b = true;
}
}
return b;
}
/**
* 根据用户生日计算年龄
*/
public static int getAgeByBirthday(Date birthday) {
Calendar cal = Calendar.getInstance();
if (cal.before(birthday)) {
throw new IllegalArgumentException(
"The birthDay is before Now.It's unbelievable!");
}
int yearNow = cal.get(Calendar.YEAR);
int monthNow = cal.get(Calendar.MONTH) + 1;
int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
cal.setTime(birthday);
int yearBirth = cal.get(Calendar.YEAR);
int monthBirth = cal.get(Calendar.MONTH) + 1;
int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
int age = yearNow - yearBirth;
LogUtil.d("age: " + age);
if (monthNow <= monthBirth) {
if (monthNow == monthBirth) {
// monthNow==monthBirth
if (dayOfMonthNow < dayOfMonthBirth) {
age--;
}
} else {
// monthNow>monthBirth
age--;
}
}
return age;
}
/**
* 友好显示时间差
*
* @param diff 毫秒
* @return
*/
public static String getFriendTimeOffer(long diff) {
int day = (int) (diff / (24 * 60 * 60 * 1000));
if (day > 0)
return day + "天";
int time = (int) (diff / (60 * 60 * 1000));
if (time > 0)
return time + "小時";
int min = (int) (diff / (60 * 1000));
if (min > 0)
return min + "分鐘";
int sec = (int) diff / 1000;
if (sec > 0)
return sec + "秒";
return "1秒";
}
/**
* 友好的时间间隔
*
* @param duration 秒
* @return
*/
public static String getFriendlyDuration(long duration) {
String str = "";
long tmpDuration = duration;
str += (tmpDuration / 60 > 10 ? tmpDuration / 60 : "0" + tmpDuration / 60) + ":";
tmpDuration %= 60;
str += (tmpDuration / 1 >= 10 ? tmpDuration / 1 : "0" + tmpDuration / 1);
tmpDuration %= 1;
return str;
}
/**
* 友好的时间间隔2
*
* @param duration 秒
* @return
*/
public static String getFriendlyDuration2(long duration) {
String str = "";
long tmpDuration = duration;
str += (tmpDuration / 60 > 0 ? tmpDuration / 60 + "'" : "");
tmpDuration %= 60;
str += (tmpDuration / 1 >= 10 ? tmpDuration / 1 + "''" : "0" + tmpDuration / 1 + "''");
tmpDuration %= 1;
return str;
}
public static String getFriendlyMusicDuration(long duration) {
String str = "-";
int tmpDuration = (int) (duration / 1000);//秒
str += (tmpDuration / 3600 > 10 ? tmpDuration / 3600 : "0" + tmpDuration / 3600) + ":";
tmpDuration %= 3600;
str += (tmpDuration / 60 > 10 ? tmpDuration / 60 : "0" + tmpDuration / 60) + ":";
tmpDuration %= 60;
str += (tmpDuration / 1 >= 10 ? tmpDuration / 1 : "0" + tmpDuration / 1);
tmpDuration %= 1;
return str;
}
/**
* 通过日期来确定星座
*
* @param mouth
* @param day
* @return
*/
public static String getStarSeat(int mouth, int day) {
String starSeat = null;
if ((mouth == 3 && day >= 21) || (mouth == 4 && day <= 19)) {
starSeat = "白羊座";
} else if ((mouth == 4 && day >= 20) || (mouth == 5 && day <= 20)) {
starSeat = "金牛座";
} else if ((mouth == 5 && day >= 21) || (mouth == 6 && day <= 21)) {
starSeat = "雙子座";
} else if ((mouth == 6 && day >= 22) || (mouth == 7 && day <= 22)) {
starSeat = "巨蟹座";
} else if ((mouth == 7 && day >= 23) || (mouth == 8 && day <= 22)) {
starSeat = "獅子座";
} else if ((mouth == 8 && day >= 23) || (mouth == 9 && day <= 22)) {
starSeat = "處女座";
} else if ((mouth == 9 && day >= 23) || (mouth == 10 && day <= 23)) {
starSeat = "天秤座";
} else if ((mouth == 10 && day >= 24) || (mouth == 11 && day <= 22)) {
starSeat = "天蝎座";
} else if ((mouth == 11 && day >= 23) || (mouth == 12 && day <= 21)) {
starSeat = "射手座";
} else if ((mouth == 12 && day >= 22) || (mouth == 1 && day <= 19)) {
starSeat = "摩羯座";
} else if ((mouth == 1 && day >= 20) || (mouth == 2 && day <= 18)) {
starSeat = "水平座";
} else {
starSeat = "雙魚座";
}
return starSeat;
}
/**
* 返回聊天时间
*
* @return
*/
public static String getChatTimeForShow(long time) {
if (TimeUtil.isToday(time)) {
return TimeUtil.getStringByFormat(time, TimeUtil.dateFormatHMofChinese);
} else {
return TimeUtil.getStringByFormat(time, TimeUtil.dateFormatMDHMofChinese);
}
}
/**
* 获取指定时间的毫秒值
*/
public static long getDatelongMills(String fomat, String dateStr) {
SimpleDateFormat sdf = new SimpleDateFormat(fomat);
Date date = null;
try {
date = sdf.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
long longDate = date.getTime();
return longDate;
}
/**
* 两个日期比较
*
* @param DATE1
* @param DATE2
* @return
*/
public static int compare_date(String DATE1, String DATE2) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
try {
Date dt1 = df.parse(DATE1);
Date dt2 = df.parse(DATE2);
if (dt1.getTime() - dt2.getTime() > 0) {//date1>date2
return 1;
} else {
return -1;
}
} catch (Exception exception) {
exception.printStackTrace();
}
return 0;
}
/**
* 格式化时间
*
* @param hour 小时
* @param minute 分钟
* @return 格式化后的时间:[xx:xx]
*/
public static String formatTime(int hour, int minute) {
return addZero(hour) + ":" + addZero(minute);
}
/**
* 时间补零
*
* @param time 需要补零的时间
* @return 补零后的时间
*/
public static String addZero(int time) {
if (String.valueOf(time).length() == 1) {
return "0" + time;
}
return String.valueOf(time);
}
}
package com.gingersoft.gsa.cloud.base.utils.time;
import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.util.Log;
import com.gingersoft.gsa.cloud.base.utils.log.LogUtil;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
......@@ -19,49 +23,1027 @@ import timber.log.Timber;
*/
public class TimeUtils {
public static final SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//, Locale.CHINESE
public static final SimpleDateFormat DEFAULT_DATE_FORMAT_YMDHM = new SimpleDateFormat("yyyy-MM-dd HH:mm");//, Locale.CHINESE
public static final SimpleDateFormat DATE_FORMAT_DATE = new SimpleDateFormat("yyyy-MM-dd");
public static final SimpleDateFormat DATE_FORMAT_DATE1 = new SimpleDateFormat("HH:mm");
public static final SimpleDateFormat DATE_FORMAT_DATE_HM = new SimpleDateFormat("HH:mm");
public static final SimpleDateFormat DATE_FORMAT_DATE_H = new SimpleDateFormat("HH");
public static final SimpleDateFormat DEFAULT_DATE_MDHM = new SimpleDateFormat("MM-dd HH:mm");//, Locale.CHINESE
public static final SimpleDateFormat DEFAULT_DATE_MD = new SimpleDateFormat("MM-dd");
public static final SimpleDateFormat DEFAULT_DATE_Y = new SimpleDateFormat("yyyy-");
public static final SimpleDateFormat DATE_Y = new SimpleDateFormat("yyyy");
public static final SimpleDateFormat DATE_FORMAT_YMDE = new SimpleDateFormat("yyyy/MM/dd E");
/**
* one day millisecond count
*/
public static final long ONE_DAY_MILLISECONDS = 1000 * 3600 * 24;
public static final long ONE_HOUR_MILLISECONDS = 1000 * 3600;
public static final long ONE_MIN_MILLISECONDS = 1000 * 60;
/**
* 时间戳转特定格式时间
*
* @param format
* @param timeStamp
* @return
*/
public static String StampToData(SimpleDateFormat format, long timeStamp) {
return format.format(new Date(timeStamp));
}
/***
* 将字符串转为时间戳
* @param time
* @param format
* @return
*/
public static String getTimeToStamp(String time, String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.CHINA);
Date date = new Date();
try {
date = sdf.parse(time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String tmptime = String.valueOf(date.getTime()).substring(0, 10);
return tmptime;
}
/***
* 将字符串转为时间戳
* @param time
* @param format
* @return Integer
*/
public static long getTimeToStamp2(String time, String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.CHINA);
Date date = new Date();
try {
date = sdf.parse(time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String tmptime = String.valueOf(date.getTime()).substring(0, 10);
return Long.parseLong(tmptime);
}
public static long getTimeToStamp3(String time, String format) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
Date date = null;
try {
date = simpleDateFormat.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
long ts = date.getTime();
return Long.parseLong(String.valueOf(ts));
}
/**
* 将毫秒转换成秒
*
* @param time
* @return
*/
public static int convertToSecond(Long time) {
Date date = new Date();
date.setTime(time);
return date.getSeconds();
}
/**
* 描述:String类型的日期时间转化为Date类型.
*
* @param strDate String形式的日期时间
* @param format 格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @return Date Date类型日期时间
*/
public static Date getDateByFormat(String strDate, SimpleDateFormat format) {
Date date = null;
try {
date = format.parse(strDate);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
/**
* 描述:获取偏移之后的Date.
*
* @param date 日期时间
* @param calendarField Calendar属性,对应offset的值, 如(Calendar.DATE,表示+offset天,Calendar.HOUR_OF_DAY,表示+offset小时)
* @param offset 偏移(值大于0,表示+,值小于0,表示-)
* @return Date 偏移之后的日期时间
*/
public Date getDateByOffset(Date date, int calendarField, int offset) {
Calendar c = new GregorianCalendar();
try {
c.setTime(date);
c.add(calendarField, offset);
} catch (Exception e) {
e.printStackTrace();
}
return c.getTime();
}
/**
* 描述:获取指定日期时间的字符串(可偏移).
*
* @param strDate String形式的日期时间
* @param format 格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @param calendarField Calendar属性,对应offset的值, 如(Calendar.DATE,表示+offset天,Calendar.HOUR_OF_DAY,表示+offset小时)
* @param offset 偏移(值大于0,表示+,值小于0,表示-)
* @return String String类型的日期时间
*/
public static String getStringByOffset(String strDate, String format, int calendarField, int offset) {
String mDateTime = null;
try {
Calendar c = new GregorianCalendar();
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
c.setTime(mSimpleDateFormat.parse(strDate));
c.add(calendarField, offset);
mDateTime = mSimpleDateFormat.format(c.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
return mDateTime;
}
/**
* 描述:Date类型转化为String类型(可偏移).
*
* @param date the date
* @param format the format
* @param calendarField the calendar field
* @param offset the offset
* @return String String类型日期时间
*/
public static String getStringByOffset(Date date, String format, int calendarField, int offset) {
String strDate = null;
try {
Calendar c = new GregorianCalendar();
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
c.setTime(date);
c.add(calendarField, offset);
strDate = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return strDate;
}
/**
* 描述:Date类型转化为String类型.
*
* @param date the date
* @param format the format
* @return String String类型日期时间
*/
public static String getStringByFormat(Date date, SimpleDateFormat format) {
String strDate = null;
try {
strDate = format.format(date);
} catch (Exception e) {
e.printStackTrace();
}
return strDate;
}
/**
* 描述:获取指定日期时间的字符串,用于导出想要的格式.
*
* @param strDate String形式的日期时间,必须为yyyy-MM-dd HH:mm:ss格式
* @param format 输出格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @return String 转换后的String类型的日期时间
*/
public static String getStringByFormat(String strDate, String format) {
String mDateTime = null;
try {
Calendar c = new GregorianCalendar();
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
c.setTime(mSimpleDateFormat.parse(strDate));
SimpleDateFormat mSimpleDateFormat2 = new SimpleDateFormat(format);
mDateTime = mSimpleDateFormat2.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return mDateTime;
}
/**
* 描述:获取表示当前日期时间的字符串.
*
* @param format 格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @return String String类型的当前日期时间
*/
public static String getCurrentDate(SimpleDateFormat format) {
String curDateTime = null;
try {
Calendar c = new GregorianCalendar();
curDateTime = format.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return curDateTime;
}
//获取当前系统当天日期
public static String getCurrentDay() {
String curDateTime = null;
try {
Calendar c = new GregorianCalendar();
c.add(Calendar.DAY_OF_MONTH, 0);
curDateTime = DEFAULT_DATE_FORMAT_YMDHM.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return curDateTime;
}
//获取当前系统当天日期
public static String getCurrentDay2() {
String curDateTime = null;
try {
Calendar c = new GregorianCalendar();
c.add(Calendar.DAY_OF_MONTH, 0);
curDateTime = DEFAULT_DATE_FORMAT.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return curDateTime;
}
//获取当前系统前后第几天
public static String getNextDay(int i) {
String curDateTime = null;
try {
Calendar c = new GregorianCalendar();
c.add(Calendar.DAY_OF_MONTH, i);
curDateTime = DEFAULT_DATE_FORMAT_YMDHM.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return curDateTime;
}
//获取当前系统前后第几小时
public static String getNextHour(int i) {
String curDateTime = null;
try {
Calendar c = new GregorianCalendar();
c.add(Calendar.HOUR_OF_DAY, i);
curDateTime = DEFAULT_DATE_FORMAT_YMDHM.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return curDateTime;
}
/**
* 描述:获取表示当前日期时间的字符串(可偏移).
*
* @param format 格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @param calendarField Calendar属性,对应offset的值, 如(Calendar.DATE,表示+offset天,Calendar.HOUR_OF_DAY,表示+offset小时)
* @param offset 偏移(值大于0,表示+,值小于0,表示-)
* @return String String类型的日期时间
*/
public static String getCurrentDateByOffset(String format, int calendarField, int offset) {
String mDateTime = null;
try {
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
Calendar c = new GregorianCalendar();
c.add(calendarField, offset);
mDateTime = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return mDateTime;
}
/**
* 描述:计算两个日期所差的天数.
*
* @param date1 第一个时间的毫秒表示
* @param date2 第二个时间的毫秒表示
* @return int 所差的天数
*/
public static int getOffectDay(long date1, long date2) {
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
//先判断是否同年
int y1 = calendar1.get(Calendar.YEAR);
int y2 = calendar2.get(Calendar.YEAR);
int d1 = calendar1.get(Calendar.DAY_OF_YEAR);
int d2 = calendar2.get(Calendar.DAY_OF_YEAR);
int maxDays = 0;
int day = 0;
if (y1 - y2 > 0) {
maxDays = calendar2.getActualMaximum(Calendar.DAY_OF_YEAR);
day = d1 - d2 + maxDays;
} else if (y1 - y2 < 0) {
maxDays = calendar1.getActualMaximum(Calendar.DAY_OF_YEAR);
day = d1 - d2 - maxDays;
} else {
day = d1 - d2;
}
return day;
}
/**
* 描述:计算两个日期所差的小时数.
*
* @param date1 第一个时间的毫秒表示
* @param date2 第二个时间的毫秒表示
* @return int 所差的小时数
*/
public static int getOffectHour(long date1, long date2) {
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
int h1 = calendar1.get(Calendar.HOUR_OF_DAY);
int h2 = calendar2.get(Calendar.HOUR_OF_DAY);
int h = 0;
int day = getOffectDay(date1, date2);
h = h1 - h2 + day * 24;
return h;
}
/**
* 描述:计算两个日期所差的分钟数.
*
* @param date1 第一个时间的毫秒表示
* @param date2 第二个时间的毫秒表示
* @return int 所差的分钟数
*/
public static int getOffectMinutes(long date1, long date2) {
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
int m1 = calendar1.get(Calendar.MINUTE);
int m2 = calendar2.get(Calendar.MINUTE);
int h = getOffectHour(date1, date2);
int m = 0;
m = m1 - m2 + h * 60;
return m;
}
/**
* 两个时间相差距离多少天多少小时多少分多少秒
*
* @param str1 时间参数 1 格式:1990-01-01 12:00:00
* @param str2 时间参数 2 格式:2009-01-01 12:00:00
* @return long[] 返回值为:{天, 时, 分, 秒}
*/
public static long[] getDistanceTimes(String str1, String str2) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date one;
Date two;
long day = 0;
long hour = 0;
long min = 0;
long sec = 0;
try {
one = df.parse(str1);
two = df.parse(str2);
long time1 = one.getTime();
long time2 = two.getTime();
long diff;
if (time1 < time2) {
diff = time2 - time1;
} else {
diff = time1 - time2;
}
day = diff / (24 * 60 * 60 * 1000);
hour = (diff / (60 * 60 * 1000) - day * 24);
min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
} catch (ParseException e) {
e.printStackTrace();
}
long[] times = {day, hour, min, sec};
return times;
}
public static long[] getDistanceTimes2(String str1, String str2) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date one;
Date two;
long day = 0;
long hour = 0;
long min = 0;
long sec = 0;
try {
one = df.parse(str1);
two = df.parse(str2);
long time1 = one.getTime();
long time2 = two.getTime();
long diff;
if (time1 < time2) {
diff = time2 - time1;
} else {
diff = time1 - time2;
}
day = diff / (24 * 60 * 60 * 1000);
hour = (diff / (60 * 60 * 1000) - day * 24);
min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
sec = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
} catch (ParseException e) {
e.printStackTrace();
}
// if (day != 0) {
// hour += day * 24;
// }
// if (hour != 0) {
// min += hour * 60;
// }
long[] times = {day, hour, min};
return times;
}
/**
* 描述:获取本周一.
*
* @param format the format
* @return String String类型日期时间
*/
public static String getFirstDayOfWeek(String format) {
return getDayOfWeek(format, Calendar.MONDAY);
}
/**
* 描述:获取本周日.
*
* @param format the format
* @return String String类型日期时间
*/
public static String getLastDayOfWeek(String format) {
return getDayOfWeek(format, Calendar.SUNDAY);
}
/**
* 描述:获取本周的某一天.
*
* @param format the format
* @param calendarField the calendar field
* @return String String类型日期时间
*/
private static String getDayOfWeek(String format, int calendarField) {
String strDate = null;
try {
Calendar c = new GregorianCalendar();
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
int week = c.get(Calendar.DAY_OF_WEEK);
if (week == calendarField) {
strDate = mSimpleDateFormat.format(c.getTime());
} else {
int offectDay = calendarField - week;
if (calendarField == Calendar.SUNDAY) {
offectDay = 7 - Math.abs(offectDay);
}
c.add(Calendar.DATE, offectDay);
strDate = mSimpleDateFormat.format(c.getTime());
}
} catch (Exception e) {
e.printStackTrace();
}
return strDate;
}
/**
* 描述:获取本月第一天.
*
* @param format the format
* @return String String类型日期时间
*/
public static String getFirstDayOfMonth(SimpleDateFormat format) {
String strDate = null;
try {
Calendar c = new GregorianCalendar();
//当前月的第一天
c.set(GregorianCalendar.DAY_OF_MONTH, 1);
strDate = format.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return strDate;
}
/**
* 獲得今年第一天的日期
* cal.set(Calendar.DAY_OF_YEAR, cal.getActualMinimum(Calendar.DAY_OF_YEAR));
* 獲得今年最後一天的日期
* cal.set(Calendar.DAY_OF_YEAR, cal.getActualMaximum(Calendar.DAY_OF_YEAR));
* 描述:获取本月最后一天.
*
* @param format the format
* @return String String类型日期时间
*/
public static String getLastDayOfMonth(String format) {
String strDate = null;
try {
Calendar c = new GregorianCalendar();
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
// 当前月的最后一天
c.set(Calendar.DATE, 1);
c.roll(Calendar.DATE, -1);
strDate = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return strDate;
}
/**
* 描述:获取表示当前日期的0点时间毫秒数.
*
* @return the first time of day
*/
public static long getFirstTimeOfDay() {
Date date = null;
try {
String currentDate = getCurrentDate(DATE_FORMAT_DATE);
date = getDateByFormat(currentDate + " 00:00:00", DEFAULT_DATE_FORMAT);
return date.getTime();
} catch (Exception e) {
}
return -1;
}
/**
* 描述:获取表示当前日期24点时间毫秒数.
*
* @return the last time of day
*/
public static long getLastTimeOfDay() {
Date date = null;
try {
String currentDate = getCurrentDate(DATE_FORMAT_DATE);
date = getDateByFormat(currentDate + " 24:00:00", DEFAULT_DATE_FORMAT);
return date.getTime();
} catch (Exception e) {
}
return -1;
}
/**
* 描述:判断是否是闰年()
* <p>(year能被4整除 并且 不能被100整除) 或者 year能被400整除,则该年为闰年.
*
* @param year 年代(如2012)
* @return boolean 是否为闰年
*/
public static boolean isLeapYear(int year) {
if ((year % 4 == 0 && year % 400 != 0) || year % 400 == 0) {
return true;
} else {
return false;
}
}
/**
* 取指定日期为星期几
*
* @param strDate 指定日期
* @param inFormat 指定日期格式
* @return String 星期几
*/
public static String getWeekNumber(String strDate, String inFormat) {
String week = "星期日";
Calendar calendar = new GregorianCalendar();
DateFormat df = new SimpleDateFormat(inFormat);
try {
calendar.setTime(df.parse(strDate));
} catch (Exception e) {
return "錯誤";
}
int intTemp = calendar.get(Calendar.DAY_OF_WEEK) - 1;
switch (intTemp) {
case 0:
week = "星期日日";
break;
case 1:
week = "星期一";
break;
case 2:
week = "星期二";
break;
case 3:
week = "星期三";
break;
case 4:
week = "星期四";
break;
case 5:
week = "星期五";
break;
case 6:
week = "星期六";
break;
}
return week;
}
/**
* 将字符串转位日期类型
*
* @param sdate
* @return
*/
private static Date toDate(String sdate) {
try {
return DEFAULT_DATE_FORMAT.parse(sdate);
} catch (ParseException e) {
return null;
}
}
/**
* 以友好的方式显示时间
*/
public static String getfriendlyTime(String sdate) {
if (sdate == null)
return "";
Date time = toDate(sdate);
// Date time = new Date(ms);
if (time == null) {
return "Unknown";
}
String ftime = "";
Calendar cal = Calendar.getInstance();
// 判断是否是同一天
String curDate = DATE_FORMAT_DATE.format(cal.getTime());
String paramDate = DATE_FORMAT_DATE.format(time);
LogUtil.d("getfriendlyTime: " + paramDate);
if (curDate.equals(paramDate)) {
int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
if (hour == 0) {
if (((cal.getTimeInMillis() - time.getTime()) / 60000) < 1) {
ftime = "剛剛";
} else {
ftime = Math.max((cal.getTimeInMillis() - time.getTime()) / 60000, 1) + "分鐘前";
}
} else {
ftime = hour + "小時前";
}
return ftime;
}
long lt = time.getTime() / 86400000;
long ct = cal.getTimeInMillis() / 86400000;
int days = (int) (ct - lt);
if (days == 0) {
int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
if (hour == 0)
ftime = Math.max(
(cal.getTimeInMillis() - time.getTime()) / 60000, 1)
+ "分鐘前";
else
ftime = hour + "小時前";
} else if (days == 1) {
ftime = "昨天";
} else if (days == 2) {
ftime = "前天";
} else if (days > 2 && days <= 10) {
ftime = days + "天前";
} else if (days > 10) {
ftime = DATE_FORMAT_DATE.format(time);
}
return ftime;
}
/**
* 时间日期格式化到年月日时分秒.
* 距离当前多少个小时
*
* @param dateStr
* @return
*/
public static String dateFormatYMDHMS = "yyyy-MM-dd HH:mm:ss";
public static String dateFormatYMDHMS_f = "yyyyMMddHHmmss";
public static String dateFormatMDHM = "MM-dd HH:mm";
public static String dateFormat = "yyyy-MM-dd HH:mm";
@SuppressLint("SimpleDateFormat")
public static int getExpiredHour(String dateStr) {
int ret = -1;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date;
try {
date = sdf.parse(dateStr);
Date dateNow = new Date();
long times = date.getTime() - dateNow.getTime();
if (times > 0) {
ret = ((int) (times / ONE_HOUR_MILLISECONDS));
} else {
ret = -1;
}
} catch (ParseException e) {
e.printStackTrace();
}
return ret;
}
/**
* 时间日期格式化到年月日.
* 过了多少个小时
*
* @param dateStr
* @return
*/
public static String dateFormatYMD = "yyyy-MM-dd";
@SuppressLint("SimpleDateFormat")
public static int getExpiredHour2(String dateStr) {
int ret = -1;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date sendDate;
try {
sendDate = sdf.parse(dateStr);
Date dateNow = new Date(System.currentTimeMillis());
Log.e("JPush", "date=" + sendDate);
long times = dateNow.getTime() - sendDate.getTime();
Log.e("JPush", "date.getTime()=" + sendDate.getTime());
if (times > 0) {
ret = ((int) (times / ONE_HOUR_MILLISECONDS));
int sdqf = (int) Math.floor(times / ONE_HOUR_MILLISECONDS);
} else {
ret = -1;
}
} catch (ParseException e) {
e.printStackTrace();
}
Log.e("JPush", "ret=" + ret);
return ret;
}
/**
* 时分秒.
* 判断给定字符串时间是否为今日
*
* @param sdate
* @return boolean
*/
public static String dateFormatHMS = "HH:mm:ss";
public static boolean isToday(String sdate) {
boolean b = false;
Date time = toDate(sdate);
Date today = new Date();
if (time != null) {
String nowDate = DATE_FORMAT_DATE.format(today);
String timeDate = DATE_FORMAT_DATE.format(time);
if (nowDate.equals(timeDate)) {
b = true;
}
}
return b;
}
/**
* 时分.
* 判断给定字符串时间是否为今日
*
* @param sdate
* @return boolean
*/
public static String dateFormatHM = "HH:mm";
public static boolean isToday(long sdate) {
boolean b = false;
Date time = new Date(sdate);
Date today = new Date();
if (time != null) {
String nowDate = DATE_FORMAT_DATE.format(today);
String timeDate = DATE_FORMAT_DATE.format(time);
if (nowDate.equals(timeDate)) {
b = true;
}
}
return b;
}
/**
* 上午/下午时分
* 根据用户生日计算年龄
*/
public static String dateFormatAHM = "aHH:mm";
public static int getAgeByBirthday(Date birthday) {
Calendar cal = Calendar.getInstance();
if (cal.before(birthday)) {
throw new IllegalArgumentException(
"The birthDay is before Now.It's unbelievable!");
}
int yearNow = cal.get(Calendar.YEAR);
int monthNow = cal.get(Calendar.MONTH) + 1;
int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
cal.setTime(birthday);
int yearBirth = cal.get(Calendar.YEAR);
int monthBirth = cal.get(Calendar.MONTH) + 1;
int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
public static SimpleDateFormat dateFormatYMDE = new SimpleDateFormat("yyyy/MM/dd E");//, Locale.TRADITIONAL_CHINESE
public static String dateFormatYMD2 = "yyyy/MM/dd";
int age = yearNow - yearBirth;
LogUtil.d("age: " + age);
if (monthNow <= monthBirth) {
if (monthNow == monthBirth) {
// monthNow==monthBirth
if (dayOfMonthNow < dayOfMonthBirth) {
age--;
}
} else {
// monthNow>monthBirth
age--;
}
}
return age;
}
/**
* 友好显示时间差
*
* @param diff 毫秒
* @return
*/
public static String getFriendTimeOffer(long diff) {
int day = (int) (diff / (24 * 60 * 60 * 1000));
if (day > 0)
return day + "天";
int time = (int) (diff / (60 * 60 * 1000));
if (time > 0)
return time + "小時";
int min = (int) (diff / (60 * 1000));
if (min > 0)
return min + "分鐘";
int sec = (int) diff / 1000;
if (sec > 0)
return sec + "秒";
return "1秒";
}
/**
* 友好的时间间隔
*
* @param duration 秒
* @return
*/
public static String getFriendlyDuration(long duration) {
String str = "";
long tmpDuration = duration;
str += (tmpDuration / 60 > 10 ? tmpDuration / 60 : "0" + tmpDuration / 60) + ":";
tmpDuration %= 60;
str += (tmpDuration / 1 >= 10 ? tmpDuration / 1 : "0" + tmpDuration / 1);
tmpDuration %= 1;
return str;
}
/**
* 友好的时间间隔2
*
* @param duration 秒
* @return
*/
public static String getFriendlyDuration2(long duration) {
String str = "";
long tmpDuration = duration;
str += (tmpDuration / 60 > 0 ? tmpDuration / 60 + "'" : "");
tmpDuration %= 60;
str += (tmpDuration / 1 >= 10 ? tmpDuration / 1 + "''" : "0" + tmpDuration / 1 + "''");
tmpDuration %= 1;
return str;
}
public static String getFriendlyMusicDuration(long duration) {
String str = "-";
int tmpDuration = (int) (duration / 1000);//秒
str += (tmpDuration / 3600 > 10 ? tmpDuration / 3600 : "0" + tmpDuration / 3600) + ":";
tmpDuration %= 3600;
str += (tmpDuration / 60 > 10 ? tmpDuration / 60 : "0" + tmpDuration / 60) + ":";
tmpDuration %= 60;
str += (tmpDuration / 1 >= 10 ? tmpDuration / 1 : "0" + tmpDuration / 1);
tmpDuration %= 1;
return str;
}
/**
* 通过日期来确定星座
*
* @param mouth
* @param day
* @return
*/
public static String getStarSeat(int mouth, int day) {
String starSeat = null;
if ((mouth == 3 && day >= 21) || (mouth == 4 && day <= 19)) {
starSeat = "白羊座";
} else if ((mouth == 4 && day >= 20) || (mouth == 5 && day <= 20)) {
starSeat = "金牛座";
} else if ((mouth == 5 && day >= 21) || (mouth == 6 && day <= 21)) {
starSeat = "雙子座";
} else if ((mouth == 6 && day >= 22) || (mouth == 7 && day <= 22)) {
starSeat = "巨蟹座";
} else if ((mouth == 7 && day >= 23) || (mouth == 8 && day <= 22)) {
starSeat = "獅子座";
} else if ((mouth == 8 && day >= 23) || (mouth == 9 && day <= 22)) {
starSeat = "處女座";
} else if ((mouth == 9 && day >= 23) || (mouth == 10 && day <= 23)) {
starSeat = "天秤座";
} else if ((mouth == 10 && day >= 24) || (mouth == 11 && day <= 22)) {
starSeat = "天蝎座";
} else if ((mouth == 11 && day >= 23) || (mouth == 12 && day <= 21)) {
starSeat = "射手座";
} else if ((mouth == 12 && day >= 22) || (mouth == 1 && day <= 19)) {
starSeat = "摩羯座";
} else if ((mouth == 1 && day >= 20) || (mouth == 2 && day <= 18)) {
starSeat = "水平座";
} else {
starSeat = "雙魚座";
}
return starSeat;
}
/**
* 返回聊天时间
*
* @return
*/
public static String getChatTimeForShow(long time) {
if (isToday(time)) {
return getStringByFormat(time, DATE_FORMAT_DATE);
} else {
return getStringByFormat(time, DATE_FORMAT_DATE);
}
}
/**
* 获取指定时间的毫秒值
*/
public static long getDatelongMills(String fomat, String dateStr) {
SimpleDateFormat sdf = new SimpleDateFormat(fomat);
Date date = null;
try {
date = sdf.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
long longDate = date.getTime();
return longDate;
}
/**
* 两个日期比较
*
* @param DATE1
* @param DATE2
* @return
*/
public static int compare_date(String DATE1, String DATE2) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
try {
Date dt1 = df.parse(DATE1);
Date dt2 = df.parse(DATE2);
if (dt1.getTime() - dt2.getTime() > 0) {//date1>date2
return 1;
} else {
return -1;
}
} catch (Exception exception) {
exception.printStackTrace();
}
return 0;
}
/**
* 格式化时间
*
* @param hour 小时
* @param minute 分钟
* @return 格式化后的时间:[xx:xx]
*/
public static String formatTime(int hour, int minute) {
return addZero(hour) + ":" + addZero(minute);
}
/**
* 时间补零
*
* @param time 需要补零的时间
* @return 补零后的时间
*/
public static String addZero(int time) {
if (String.valueOf(time).length() == 1) {
return "0" + time;
}
return String.valueOf(time);
}
private TimeUtils() {
throw new AssertionError();
......@@ -243,7 +1225,7 @@ public class TimeUtils {
* @Description: TODO(这里用一句话描述这个方法的作用)
*/
public static String ConverToString(Date date) {
return DATE_FORMAT_DATE1.format(date);
return DATE_FORMAT_DATE_HM.format(date);
}
/**
......@@ -377,50 +1359,16 @@ public class TimeUtils {
* @param format 格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @return String 日期时间字符串
*/
public static String getStringByFormat(long milliseconds, String format) {
public static String getStringByFormat(long milliseconds, SimpleDateFormat format) {
String thisDateTime = null;
try {
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
thisDateTime = mSimpleDateFormat.format(milliseconds);
thisDateTime = format.format(milliseconds);
} catch (Exception e) {
e.printStackTrace();
}
return thisDateTime;
}
/**
* 描述:获取表示当前日期时间的字符串.
*
* @param format 格式化字符串,如:"yyyy-MM-dd HH:mm:ss"
* @return String String类型的当前日期时间
*/
public static String getCurrentDate(String format) {
String curDateTime = null;
try {
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
Calendar c = new GregorianCalendar();
curDateTime = mSimpleDateFormat.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return curDateTime;
}
/**
* 描述:获取表示当前日期时间的字符串.
*
* @return String String类型的当前日期时间
*/
public static String getCurrentDate(SimpleDateFormat format) {
String curDateTime = null;
try {
Calendar c = new GregorianCalendar();
curDateTime = format.format(c.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return curDateTime;
}
/**
* 区分白天还是夜晚
......@@ -429,8 +1377,7 @@ public class TimeUtils {
* @return
*/
public static boolean getDuringOrNight(String time) {
String before = formatDate(time, "yyyy-MM-dd HH:mm:ss", "HH");
String before = formatDate(time, DEFAULT_DATE_FORMAT, DATE_FORMAT_DATE_H);
int k = Integer.parseInt(before);
if ((k >= 0 && k < 6) || (k >= 18 && k < 24)) {
......@@ -447,12 +1394,11 @@ public class TimeUtils {
* @param afterformat 之后的时间格式
* @return
*/
public static String formatDate(String before, String beforeformat, String afterformat) {
public static String formatDate(String before, SimpleDateFormat beforeformat, SimpleDateFormat afterformat) {
String after;
try {
Date date = new SimpleDateFormat(beforeformat, Locale.getDefault())
.parse(before);
after = new SimpleDateFormat(afterformat, Locale.getDefault()).format(date);
Date date = beforeformat.parse(before);
after = afterformat.format(date);
} catch (ParseException e) {
return before;
}
......@@ -500,6 +1446,22 @@ public class TimeUtils {
return time;
}
public static String parseDateToString(Date date, SimpleDateFormat dateFormat){
return dateFormat.format(date);
}
public static Date parseTimeToDate(String time, SimpleDateFormat format) {
Date date = new Date();
try {
date = new Date(time);
} catch (IllegalArgumentException e) {
try {
date = format.parse(time);
} catch (ParseException ex) {
}
}
return date;
}
/**
* 计算两个日期的相隔天数
......
package com.gingersoft.gsa.cloud.database.bean;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.Generated;
import java.util.Date;
import org.greenrobot.greendao.annotation.Transient;
/**
* 作者:ELEGANT_BIN
......@@ -37,10 +36,15 @@ public class ExpandInfo {
*/
private String remark;
private int dataType;//配置的數據類型 1:整形,2:字符型,3:布爾型,4:日期類型
private String sort;//排序
private int valueBoolean;//是否在雲端GSA上配置:0 否,1 是
@Transient
private boolean isUpdate = false;//是否被編輯了
@Generated(hash = 1553907136)
public ExpandInfo(Long id, int restaurantId, String settingName, Integer valueInt,
String valueChar, String valueDatetime, String remark) {
@Generated(hash = 136088095)
public ExpandInfo(Long id, int restaurantId, String settingName, Integer valueInt, String valueChar,
String valueDatetime, String remark, int dataType, String sort, int valueBoolean) {
this.id = id;
this.restaurantId = restaurantId;
this.settingName = settingName;
......@@ -48,6 +52,9 @@ public class ExpandInfo {
this.valueChar = valueChar;
this.valueDatetime = valueDatetime;
this.remark = remark;
this.dataType = dataType;
this.sort = sort;
this.valueBoolean = valueBoolean;
}
@Generated(hash = 9429432)
......@@ -110,4 +117,44 @@ public class ExpandInfo {
public void setValueDatetime(String valueDatetime) {
this.valueDatetime = valueDatetime;
}
public int getDataType() {
return dataType;
}
public void setDataType(int dataType) {
this.dataType = dataType;
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public int getValueBoolean() {
return valueBoolean;
}
public void setValueBoolean(int valueBoolean) {
this.valueBoolean = valueBoolean;
}
public boolean isUpdate() {
return isUpdate;
}
public void setUpdate(boolean update) {
isUpdate = update;
}
public boolean getIsUpdate() {
return this.isUpdate;
}
public void setIsUpdate(boolean isUpdate) {
this.isUpdate = isUpdate;
}
}
......@@ -14,10 +14,10 @@ import org.greenrobot.greendao.identityscope.IdentityScopeType;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* Master of DAO (schema version 15): knows all DAOs.
* Master of DAO (schema version 16): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
public static final int SCHEMA_VERSION = 15;
public static final int SCHEMA_VERSION = 16;
/** Creates underlying database table using DAOs. */
public static void createAllTables(Database db, boolean ifNotExists) {
......
......@@ -3,13 +3,13 @@ package com.gingersoft.gsa.cloud.database.greendao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import com.gingersoft.gsa.cloud.database.bean.ExpandInfo;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import com.gingersoft.gsa.cloud.database.bean.ExpandInfo;
import org.greenrobot.greendao.internal.DaoConfig;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
......@@ -31,6 +31,9 @@ public class ExpandInfoDao extends AbstractDao<ExpandInfo, Long> {
public final static Property ValueChar = new Property(4, String.class, "valueChar", false, "VALUE_CHAR");
public final static Property ValueDatetime = new Property(5, String.class, "valueDatetime", false, "VALUE_DATETIME");
public final static Property Remark = new Property(6, String.class, "remark", false, "REMARK");
public final static Property DataType = new Property(7, int.class, "dataType", false, "DATA_TYPE");
public final static Property Sort = new Property(8, String.class, "sort", false, "SORT");
public final static Property ValueBoolean = new Property(9, int.class, "valueBoolean", false, "VALUE_BOOLEAN");
}
......@@ -52,7 +55,10 @@ public class ExpandInfoDao extends AbstractDao<ExpandInfo, Long> {
"\"VALUE_INT\" INTEGER," + // 3: valueInt
"\"VALUE_CHAR\" TEXT," + // 4: valueChar
"\"VALUE_DATETIME\" TEXT," + // 5: valueDatetime
"\"REMARK\" TEXT);"); // 6: remark
"\"REMARK\" TEXT," + // 6: remark
"\"DATA_TYPE\" INTEGER NOT NULL ," + // 7: dataType
"\"SORT\" TEXT," + // 8: sort
"\"VALUE_BOOLEAN\" INTEGER NOT NULL );"); // 9: valueBoolean
}
/** Drops the underlying database table. */
......@@ -95,6 +101,13 @@ public class ExpandInfoDao extends AbstractDao<ExpandInfo, Long> {
if (remark != null) {
stmt.bindString(7, remark);
}
stmt.bindLong(8, entity.getDataType());
String sort = entity.getSort();
if (sort != null) {
stmt.bindString(9, sort);
}
stmt.bindLong(10, entity.getValueBoolean());
}
@Override
......@@ -131,6 +144,13 @@ public class ExpandInfoDao extends AbstractDao<ExpandInfo, Long> {
if (remark != null) {
stmt.bindString(7, remark);
}
stmt.bindLong(8, entity.getDataType());
String sort = entity.getSort();
if (sort != null) {
stmt.bindString(9, sort);
}
stmt.bindLong(10, entity.getValueBoolean());
}
@Override
......@@ -147,7 +167,10 @@ public class ExpandInfoDao extends AbstractDao<ExpandInfo, Long> {
cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3), // valueInt
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // valueChar
cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // valueDatetime
cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6) // remark
cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // remark
cursor.getInt(offset + 7), // dataType
cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // sort
cursor.getInt(offset + 9) // valueBoolean
);
return entity;
}
......@@ -161,6 +184,9 @@ public class ExpandInfoDao extends AbstractDao<ExpandInfo, Long> {
entity.setValueChar(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
entity.setValueDatetime(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
entity.setRemark(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
entity.setDataType(cursor.getInt(offset + 7));
entity.setSort(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
entity.setValueBoolean(cursor.getInt(offset + 9));
}
@Override
......
......@@ -133,6 +133,4 @@ public class ExpandInfoDaoUtils {
return mManager.getDaoSession().queryRaw(ExpandInfo.class, sql, conditions);
}
}
......@@ -15,16 +15,14 @@ import android.os.Build
import android.os.IBinder
import android.os.PowerManager
import android.util.Log
import android.view.WindowManager
import android.widget.RemoteViews
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.gingersoft.gsa.cloud.base.R
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication
import com.gingersoft.gsa.cloud.base.utils.SoundPoolUtils
import com.gingersoft.gsa.cloud.base.utils.okhttpUtils.OkHttp3Utils
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtil
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils
import com.gingersoft.gsa.cloud.constans.AppConstans
import com.gingersoft.gsa.cloud.constans.HttpsConstans
import com.google.gson.Gson
......@@ -356,7 +354,7 @@ class GetInfoUpdateService : Service() {
* 向日誌添加數據
*/
private fun putTimeLog(content: String) {
loginfo.append(TimeUtil.getCurrentDate(TimeUtil.dateFormatYMDHMS))
loginfo.append(TimeUtils.getCurrentDate(TimeUtils.DEFAULT_DATE_FORMAT))
loginfo.append(":")
loginfo.append(content)
loginfo.append("\n")
......
......@@ -157,9 +157,7 @@ public class ColdChainMainActivity extends BaseFragmentActivity<ColdChainMainPre
autoReceivingOrders.setChecked(RestaurantExpandInfoUtils.getValue(ExpandConstant.FrozenChainAutoOrder, false));
autoReceivingOrders.setOnCheckedChangeListener((buttonView, isChecked) -> {
RestaurantExpandInfoUtils.setValue(ExpandConstant.FrozenChainAutoOrder, isChecked);
if (autoOrderDisposable != null && !autoOrderDisposable.isDisposed()) {
autoOrderDisposable.dispose();
}
......@@ -192,7 +190,6 @@ public class ColdChainMainActivity extends BaseFragmentActivity<ColdChainMainPre
});
}
public void getNumByOrderTypeInvoke(String functionName) {
Class[] parameterTypes = {SupplementInfoBean.class};
try {
......@@ -274,13 +271,13 @@ public class ColdChainMainActivity extends BaseFragmentActivity<ColdChainMainPre
|| type == 6 || type == 7) {//ColdChainConstants.orderType
fragments.get(viewPager.getCurrentItem()).onRefreshData();
mPresenter.getBalance();
if(autoReceivingOrders.isChecked()){
mPresenter.startToBeConfirmedOrderList(restaurantId);
}
}
if (type == 3 || type == 6 || type == 7) {
getNumByOrderTypeInvoke("loadNumber");
}
if (autoReceivingOrders.isChecked()) {
mPresenter.startToBeConfirmedOrderList(restaurantId);
}
});
bind.execute(aBoolean -> null);
bind.setJumpActivity(ColdChainMainActivity.class);
......
......@@ -50,7 +50,7 @@ ext {
"autosize" : 'me.jessyan:autosize:1.1.2',
"butterknife" : "com.jakewharton:butterknife:${version["butterknifeSdkVersion"]}",
"butterknife-compiler" : "com.jakewharton:butterknife-compiler:${version["butterknifeSdkVersion"]}",
"pickerview" : "com.contrarywind:Android-PickerView:3.2.5",
"pickerview" : "com.contrarywind:Android-PickerView:4.1.9",
"photoview" : "com.github.chrisbanes.photoview:library:1.2.3",
"numberprogressbar" : "com.daimajia.numberprogressbar:library:1.2@aar",
"nineoldandroids" : "com.nineoldandroids:library:2.4.0",
......
......@@ -340,7 +340,7 @@
// * 向日誌添加數據
// */
// private fun putTimeLog(content: String) {
// loginfo.append(TimeUtil.getCurrentDate(TimeUtil.dateFormatYMDHMS))
// loginfo.append(TimeUtils.getCurrentDate(TimeUtil.dateFormatYMDHMS))
// loginfo.append(":")
// loginfo.append(content)
// loginfo.append("\n")
......
......@@ -2,7 +2,7 @@ package com.gingersoft.gsa.delivery_pick_mode.ui.adapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtil
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils
import com.gingersoft.gsa.delivery_pick_mode.R
import com.gingersoft.gsa.delivery_pick_mode.data.model.bean.ServiceChargeRecordBean
......@@ -15,7 +15,7 @@ class ThirdExpensesAdapter(data: MutableList<ServiceChargeRecordBean.DataX>?) :
holder.setText(R.id.tv_third_expenses_amount, "金額")
} else {
holder.setText(R.id.tv_third_expenses_user, "" + item.updateName)
holder.setText(R.id.tv_third_expenses_time, TimeUtil.StampToData(TimeUtil.dateFormatYMDHMS, item.updateTime))
holder.setText(R.id.tv_third_expenses_time, TimeUtils.StampToData(TimeUtils.DEFAULT_DATE_FORMAT, item.updateTime))
holder.setText(R.id.tv_third_expenses_amount, "+$" + item.paymentValue)
}
}
......
......@@ -2,7 +2,7 @@ package com.gingersoft.gsa.cloud.login.mvp.ui.adapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtil;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
import com.gingersoft.gsa.cloud.login.R;
import com.gingersoft.gsa.cloud.login.mvp.bean.LoginLimitBean;
......@@ -21,6 +21,6 @@ public class LoginLimitAdapter extends BaseQuickAdapter<LoginLimitBean, BaseView
@Override
protected void convert(@NotNull BaseViewHolder baseViewHolder,LoginLimitBean loginLimitBean) {
baseViewHolder.setText(R.id.tv_login_limit_account, loginLimitBean.getUserName());
baseViewHolder.setText(R.id.tv_login_limit_time, TimeUtil.getStringByFormat(loginLimitBean.getDateTime(), TimeUtil.dateFormatYMDHMS));
baseViewHolder.setText(R.id.tv_login_limit_time, TimeUtils.getStringByFormat(loginLimitBean.getDateTime(), TimeUtils.DEFAULT_DATE_FORMAT));
}
}
......@@ -7,6 +7,7 @@
<activity
android:name=".mvp.ui.activity.NewMainActivity"
android:launchMode="singleTask" />
<activity android:name=".mvp.ui.activity.ExpandListActivity"/>
<activity android:name=".mvp.ui.activity.MainActivity" />
<activity android:name=".mvp.ui.activity.ReportActivity" />
<activity android:name=".mvp.ui.activity.SettlementActivity" />
......
......@@ -17,7 +17,7 @@
android:networkSecurityConfig="@xml/network_android"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".mvp.ui.activity.ExpandListActivity"></activity>
<activity android:name=".mvp.ui.activity.ExpandListActivity"/>
<activity android:name=".mvp.ui.activity.RestaurantQrCodeActivity" />
<activity android:name=".mvp.ui.activity.LanguageActivity" />
<activity android:name=".mvp.ui.activity.ReportActivity" />
......
package com.gingersoft.gsa.cloud.main.mvp.contract;
import com.gingersoft.gsa.cloud.database.bean.Function;
import com.gingersoft.gsa.cloud.main.mvp.model.bean.FunctionBean;
import com.jess.arms.mvp.IView;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import com.gingersoft.gsa.cloud.database.bean.ExpandInfo;
import com.jess.arms.mvp.IModel;
import com.jess.arms.mvp.IView;
import java.util.List;
......@@ -13,11 +13,11 @@ import io.reactivex.Observable;
public interface ExpandListContract {
//对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
interface View extends IView {
void loadExpandList(List<Function> data);
void loadExpandList(List<ExpandInfo> data);
}
//Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
interface Model extends IModel {
Observable<FunctionBean> getExpandList(long userId);
Observable<BaseResult> getExpandList(int restaurantId);
}
}
......@@ -2,6 +2,7 @@ package com.gingersoft.gsa.cloud.main.mvp.model;
import android.app.Application;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import com.gingersoft.gsa.cloud.main.mvp.contract.ExpandListContract;
import com.gingersoft.gsa.cloud.main.mvp.model.bean.FunctionBean;
import com.gingersoft.gsa.cloud.main.mvp.model.service.ExpandListService;
......@@ -36,7 +37,7 @@ public class ExpandListModel extends BaseModel implements ExpandListContract.Mod
@Override
public Observable<FunctionBean> getExpandList(long userId) {
return mRepositoryManager.obtainRetrofitService(ExpandListService.class).getExpandList(userId);
public Observable<BaseResult> getExpandList(int restaurantId) {
return mRepositoryManager.obtainRetrofitService(ExpandListService.class).getExpandList(restaurantId);
}
}
\ No newline at end of file
package com.gingersoft.gsa.cloud.main.mvp.model.service;
import com.gingersoft.gsa.cloud.main.mvp.model.bean.FunctionBean;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import io.reactivex.Observable;
import me.jessyan.retrofiturlmanager.RetrofitUrlManager;
......@@ -9,6 +9,6 @@ import retrofit2.http.Query;
public interface ExpandListService {
@GET("user/resource/list" + RetrofitUrlManager.IDENTIFICATION_PATH_SIZE + 2)
Observable<FunctionBean> getExpandList(@Query("userId") long userId);
@GET("restaurant/ext/list" + RetrofitUrlManager.IDENTIFICATION_PATH_SIZE + 2)
Observable<BaseResult> getExpandList(@Query("restaurantId") int restaurantId);
}
......@@ -3,14 +3,18 @@ package com.gingersoft.gsa.cloud.main.mvp.presenter;
import android.app.Application;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import com.gingersoft.gsa.cloud.base.utils.JsonUtils;
import com.gingersoft.gsa.cloud.database.bean.ExpandInfo;
import com.gingersoft.gsa.cloud.main.mvp.contract.ExpandListContract;
import com.gingersoft.gsa.cloud.main.mvp.model.bean.FunctionBean;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.integration.AppManager;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.utils.RxLifecycleUtils;
import java.util.List;
import javax.inject.Inject;
import io.reactivex.android.schedulers.AndroidSchedulers;
......@@ -45,17 +49,24 @@ public class ExpandListPresenter extends BasePresenter<ExpandListContract.Model,
}
public void getExpandInfoList() {
mModel.getExpandList(GsaCloudApplication.getMemberId())
mModel.getExpandList(GsaCloudApplication.getRestaurantId())
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> mRootView.showLoading(""))
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> mRootView.hideLoading())
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<FunctionBean>(mErrorHandler) {
.subscribe(new ErrorHandleSubscriber<BaseResult>(mErrorHandler) {
@Override
public void onNext(FunctionBean functionBean) {
mRootView.loadExpandList(functionBean.getData());
public void onNext(BaseResult result) {
if (result.isSuccess()) {
if (result.getData() != null) {
List<ExpandInfo> expandInfoList = JsonUtils.parseArray(result.getData(), ExpandInfo.class);
mRootView.loadExpandList(expandInfoList);
}
}
}
});
}
......
......@@ -2,32 +2,45 @@ package com.gingersoft.gsa.cloud.main.mvp.ui.activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.gingersoft.gsa.cloud.database.bean.Function;
import com.gingersoft.gsa.cloud.database.bean.ExpandInfo;
import com.gingersoft.gsa.cloud.main.R;
import com.gingersoft.gsa.cloud.main.R2;
import com.gingersoft.gsa.cloud.main.di.component.DaggerExpandListComponent;
import com.gingersoft.gsa.cloud.main.di.module.ExpandListModule;
import com.gingersoft.gsa.cloud.main.mvp.contract.ExpandListContract;
import com.gingersoft.gsa.cloud.main.mvp.presenter.ExpandListPresenter;
import com.gingersoft.gsa.cloud.main.mvp.ui.adapter.ExpandListAdapter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.qmuiteam.qmui.alpha.QMUIAlphaButton;
import com.qmuiteam.qmui.widget.QMUITopBar;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;
import static com.jess.arms.utils.Preconditions.checkNotNull;
public class ExpandListActivity extends BaseActivity<ExpandListPresenter> implements ExpandListContract.View {
public class ExpandListActivity extends BaseActivity<ExpandListPresenter> implements ExpandListContract.View, View.OnClickListener {
@BindView(R2.id.rv_expand_list)
RecyclerView rvExpandList;
private ExpandListAdapter expandListAdapter;
@BindView(R2.id.topbar_expand_list)
QMUITopBar topBar;
@BindView(R2.id.btn_expand_save)
QMUIAlphaButton btnSave;
@Override
public void setupActivityComponent(@NonNull AppComponent appComponent) {
......@@ -56,7 +69,9 @@ public class ExpandListActivity extends BaseActivity<ExpandListPresenter> implem
@Override
public void initTopBar() {
topBar.setBackgroundColor(ContextCompat.getColor(this, R.color.theme_color));
topBar.addLeftBackImageButton().setOnClickListener(v -> killMyself());
topBar.setTitle("配置列表");
}
@Override
......@@ -102,7 +117,31 @@ public class ExpandListActivity extends BaseActivity<ExpandListPresenter> implem
}
@Override
public void loadExpandList(List<Function> data) {
public void loadExpandList(List<ExpandInfo> data) {
expandListAdapter = new ExpandListAdapter(data);
rvExpandList.setAdapter(expandListAdapter);
rvExpandList.setLayoutManager(new LinearLayoutManager(mContext));
}
@OnClick(R2.id.btn_expand_save)
@Override
public void onClick(View v) {
int viewId = v.getId();
if (viewId == R.id.btn_expand_save) {
//保存
List<ExpandInfo> data = expandListAdapter.getData();
List<ExpandInfo> updateDate = new ArrayList<>();
for (int i = 0; i < data.size(); i++) {
if (data.get(i).getIsUpdate()) {
updateDate.add(data.get(i));
}
}
if (updateDate.size() > 0) {
//調用接口批量修改
} else {
killMyself();
}
}
}
}
......@@ -403,12 +403,12 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl
.setActionName("showTableManageActivity")
.build()
.call();
} else if(name.equals("冷鏈接單")){
} else if (name.equals("冷鏈接單") || name.equals("凍鏈接單")) {
CC.obtainBuilder("Component.ColdChain")
.setActionName("Component.ColdChain")
.build()
.call();
} else if(name.equals("二維碼")){
} else if (name.equals("二維碼")) {
launchActivity(new Intent(mContext, RestaurantQrCodeActivity.class));
} else if (name.equals("配置列表")) {
launchActivity(new Intent(mContext, ExpandListActivity.class));
......
......@@ -138,7 +138,7 @@ public class SettlementActivity extends BaseActivity<SettlementPresenter> implem
this.mSettlementReportBean = datasBean;
if(mSettlementReportBean.getRestaurantOperation() != null) {
String lastSettlementText = LanguageUtils.get_language_system(this, "", "上次清機時間:");
setLastTime(lastSettlementText + TimeUtils.getStringByFormat(mSettlementReportBean.getRestaurantOperation().getOperationTime(), TimeUtils.dateFormatYMDHMS) );
setLastTime(lastSettlementText + TimeUtils.getStringByFormat(mSettlementReportBean.getRestaurantOperation().getOperationTime(), TimeUtils.DEFAULT_DATE_FORMAT) );
}
}
......
......@@ -27,7 +27,6 @@ import com.gingersoft.gsa.cloud.base.utils.LanguageUtils;
import com.gingersoft.gsa.cloud.base.utils.MoneyUtil;
import com.gingersoft.gsa.cloud.base.utils.PrintTransitUtils;
import com.gingersoft.gsa.cloud.base.utils.other.SPUtils;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtil;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
import com.gingersoft.gsa.cloud.constans.PrintConstans;
import com.gingersoft.gsa.cloud.main.R;
......@@ -333,7 +332,7 @@ public class SettlementReportActivity extends BaseActivity<SettlementReportPrese
SettlementReport.DataBean.RestaurantOperationBean restaurantOperationBean = datasBean.getRestaurantOperation();
if (restaurantOperationBean != null) {
tv_business_area_title.setText(dailyBusinessReportText);
tv_last_time.setText(lastSettlementText + TimeUtils.getStringByFormat(restaurantOperationBean.getOperationTime(), TimeUtils.dateFormatYMDHMS));
tv_last_time.setText(lastSettlementText + TimeUtils.getStringByFormat(restaurantOperationBean.getOperationTime(), TimeUtils.DEFAULT_DATE_FORMAT));
}
tv_start_time.setText(byBusinessDateText + datasBean.getStartTime());
......@@ -541,8 +540,8 @@ public class SettlementReportActivity extends BaseActivity<SettlementReportPrese
/**本月累計營業額*/
if (analysisBeanMap.containsKey(cumulativeTurnoverMonthText)) {
SettlementReport.DataBean.AnalysisBean analysisBean = analysisBeanMap.get(cumulativeTurnoverMonthText);
String firstDayOfMonth = TimeUtil.getFirstDayOfMonth(TimeUtil.dateFormatYMD) + " 00:00:00";
String currentDate = TimeUtil.getCurrentDate(TimeUtil.dateFormatYMDHMS);
String firstDayOfMonth = TimeUtils.getFirstDayOfMonth(TimeUtils.DATE_FORMAT_DATE) + " 00:00:00";
String currentDate = TimeUtils.getCurrentDate(TimeUtils.DEFAULT_DATE_FORMAT);
settlementReportItem5s.add(new SectionTextItem5(null, null, null, null, null));
settlementReportItem5s.add(new SectionTextItem5("==============================================================", null, null, null, null));
settlementReportItem5s.add(new SectionTextItem5(cumulativeTurnoverMonthText, null, null, null, null));
......@@ -553,7 +552,7 @@ public class SettlementReportActivity extends BaseActivity<SettlementReportPrese
/**報表完結*/
String memberName = GsaCloudApplication.getMemberName();
String currentDate = TimeUtils.getCurrentDate(TimeUtils.dateFormatYMDHMS);
String currentDate = TimeUtils.getCurrentDate(TimeUtils.DEFAULT_DATE_FORMAT);
settlementReportItem5s.add(new SectionTextItem5(null, null, null, null, null));
settlementReportItem5s.add(new SectionTextItem5("==============================================================", null, null, null, null));
settlementReportItem5s.add(new SectionTextItem5("報表完結", null, null, null, null));
......@@ -633,7 +632,7 @@ public class SettlementReportActivity extends BaseActivity<SettlementReportPrese
for (int i = 0; i < dateNum.size(); i++) {
SendSettlement.DataBean.DateNumBean dateNumBean = dateNum.get(i);
Map<String, Object> map = new HashMap<>();
map.put("date", TimeUtil.formatDate(dateNumBean.getDate(),TimeUtil.dateFormatYMD ,TimeUtil.dateFormatM_D));
map.put("date", TimeUtils.formatDate(dateNumBean.getDate(),TimeUtils.DATE_FORMAT_DATE ,TimeUtils.DEFAULT_DATE_MD));
map.put("num", dateNumBean.getNum());
lists.add(map);
}
......
package com.gingersoft.gsa.cloud.main.mvp.ui.adapter;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;
import com.bigkoo.pickerview.TimePickerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.gingersoft.gsa.cloud.base.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
import com.gingersoft.gsa.cloud.database.bean.ExpandInfo;
import com.gingersoft.gsa.cloud.main.R;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.List;
public class ExpandListAdapter extends BaseQuickAdapter<ExpandInfo, BaseViewHolder> {
public ExpandListAdapter(@Nullable List<ExpandInfo> data) {
super(R.layout.main_expand_item, data);
for (int i = 0; i < data.size(); i++) {
data.get(i).setDataType(i);
}
}
@Override
protected void convert(@NotNull BaseViewHolder baseViewHolder, ExpandInfo function) {
baseViewHolder.setText(R.id.tv_expand_name, function.getRemark());
EditText editText = baseViewHolder.getView(R.id.ed_expand_edit);
Switch btn = baseViewHolder.getView(R.id.switch_expand_boolean);
TextView tvTime = baseViewHolder.getView(R.id.tv_expand_time);
if (function.getDataType() == 1) {
//整形
btn.setVisibility(View.GONE);
tvTime.setVisibility(View.GONE);
editText.setVisibility(View.VISIBLE);
editText.setInputType(EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_VARIATION_NORMAL);
editText.setText(function.getValueInt() + "");
} else if (function.getDataType() == 2) {
//字符
btn.setVisibility(View.GONE);
tvTime.setVisibility(View.GONE);
editText.setVisibility(View.VISIBLE);
editText.setInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_NORMAL);
editText.setText(function.getValueChar());
} else if (function.getDataType() == 3) {
//布爾
editText.setVisibility(View.GONE);
tvTime.setVisibility(View.GONE);
btn.setVisibility(View.VISIBLE);
btn.setChecked(function.getValueInt() == 0);
btn.setOnCheckedChangeListener((buttonView, isChecked) -> {
function.setValueInt(isChecked ? 0 : 1);
function.setUpdate(true);
});
} else if (function.getDataType() == 4) {
//日期
editText.setVisibility(View.GONE);
btn.setVisibility(View.GONE);
tvTime.setVisibility(View.VISIBLE);
Calendar calendar = Calendar.getInstance();
try {
calendar.setTime(DateFormat.getDateTimeInstance().parse(function.getValueDatetime()));
} catch (ParseException e) {
e.printStackTrace();
}
tvTime.setText(TimeUtils.getStringByFormat(calendar.getTime(), TimeUtils.DATE_FORMAT_DATE));
//Sep 11, 2020 6:10:42 PM
tvTime.setOnClickListener(v -> {
//时间选择器
new TimePickerView.Builder(getContext(), (date, view) -> {
tvTime.setText(TimeUtils.parseDateToString(date, TimeUtils.DATE_FORMAT_DATE));
function.setUpdate(true);
})
.setDate(calendar)
.setType(TimePickerView.Type.YEAR_MONTH_DAY)
.setContentSize(24)
.setLabel("", "", "", "", "", "")
.build()
.show();
});
} else {
btn.setVisibility(View.GONE);
tvTime.setVisibility(View.GONE);
editText.setVisibility(View.GONE);
}
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Log.e("eee", "beforeTextChanged——" + s);
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.e("eee", "onTextChanged——" + s);
}
@Override
public void afterTextChanged(Editable s) {
Log.e("eee", "afterTextChanged—" + function.getDataType() + "—" + s);
if (function.getDataType() == 1) {
if (TextUtil.isNotEmptyOrNullOrUndefined(s.toString())) {
function.setValueInt(Integer.parseInt(s.toString()));
function.setUpdate(true);
}
} else if (function.getDataType() == 2) {
if (TextUtil.isNotEmptyOrNullOrUndefined(s.toString())) {
function.setValueChar(s.toString());
function.setUpdate(true);
}
}
}
});
}
}
......@@ -17,7 +17,6 @@ import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.utils.MoneyUtil;
import com.gingersoft.gsa.cloud.base.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.main.R;
import com.gingersoft.gsa.cloud.main.R2;
import com.gingersoft.gsa.cloud.main.di.component.DaggerMainTopComponent;
......@@ -121,7 +120,7 @@ public class MainTopFragment extends BaseFragment<MainTopPresenter> implements M
@Override
public void initData(@Nullable Bundle savedInstanceState) {
// getInfo();
time.setText(TimeUtils.getCurrentTimeInString(TimeUtils.dateFormatYMDE));
time.setText(TimeUtils.getCurrentTimeInString(TimeUtils.DATE_FORMAT_YMDE));
}
private void getInfo() {
......
......@@ -17,9 +17,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.utils.time.TimePickerUtils;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtil;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.main.R;
import com.gingersoft.gsa.cloud.main.R2;
import com.gingersoft.gsa.cloud.main.di.component.DaggerPaymentMethodReportComponent;
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/white"
android:orientation="vertical">
<com.qmuiteam.qmui.widget.QMUITopBar
android:id="@+id/topbar_expand_list"
android:layout_width="match_parent"
app:qmui_topbar_title_color="@color/theme_white_color"
android:layout_height="@dimen/head_height" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_expand_list"
android:layout_below="@id/topbar_expand_list"
android:layout_width="match_parent"
android:layout_above="@id/btn_expand_save"
android:layout_height="match_parent" />
<com.qmuiteam.qmui.alpha.QMUIAlphaButton
android:id="@+id/btn_expand_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="@dimen/dp_20"
android:layout_alignParentBottom="true"
android:layout_marginTop="@dimen/dp_20"
android:layout_marginRight="@dimen/dp_20"
android:layout_marginBottom="@dimen/dp_10"
android:background="@drawable/shape_app_btn"
android:gravity="center"
android:text="保存"
android:textColor="@color/white"
android:textSize="@dimen/dp_16" />
</LinearLayout>
\ No newline at end of file
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/dp_10"
android:paddingRight="@dimen/dp_10">
<TextView
android:id="@+id/tv_expand_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
android:layout_marginBottom="@dimen/dp_10"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
tools:text="配置名稱" />
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="true"
android:focusableInTouchMode="true"
android:paddingRight="@dimen/dp_10">
<EditText
android:id="@+id/ed_expand_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:visibility="gone" />
<TextView
android:id="@+id/tv_expand_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:visibility="visible"
tools:text="當前時間" />
<Switch
android:id="@+id/switch_expand_boolean"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:thumb="@drawable/shape_thumb_on"
android:track="@drawable/selector_switch_track"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
<include
layout="@layout/include_horizontal_color_e8_dividing_line"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_0_5"
android:layout_gravity="bottom" />
</FrameLayout>
\ No newline at end of file
......@@ -121,7 +121,8 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
return 0; //R.layout.print_bitmap如果你不需要框架帮你设置 setContentView(id) 需要 自行设置,请返回 0
}
// ImageView bitmapIv;
// ImageView bitmapIv;
@Override
public void initData(@Nullable Bundle savedInstanceState) {
// bitmapIv = findViewById(R.id.iv_bitmap);
......@@ -225,6 +226,11 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
if (isShowDialog) {
initDialog();
}
// if (defaultPrint.getPrinterDeviceType() == 2 && PrintConstans.PRINT_MODEL_WISEPOS.contains(Build.MODEL)) {
// //本機打印並且是BBPOS
//
// }
//獲得對應的圖片
Map<String, List<Bitmap>> listMap = printerInIt.getPrintBitmapByCount(mContext, defaultPrint);
if (listMap != null) {
......
package com.joe.print.mvp.ui.adapter;
import android.graphics.Typeface;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
......@@ -23,9 +24,26 @@ public class KitChenPrjPrintFoodAdapter extends BaseQuickAdapter<PrjBean.DataBea
private int indentation = 0;
private PrinterDeviceBean printerDeviceBean;
private int foodFontSize = 24;
private int modifierFontSize = 24;
private int foodIsBold;
private int modifierIsBold;
private int foodIsItalic;
private int modifierIsItalic;
public KitChenPrjPrintFoodAdapter(@Nullable List<PrjBean.DataBean.Bean> data, PrinterDeviceBean printerDeviceBean) {
super(R.layout.print_kitchen_item_parent, data);
this.printerDeviceBean = printerDeviceBean;
try {
this.foodFontSize = Integer.parseInt(printerDeviceBean.getFoodFont()) * 2;
this.modifierFontSize = Integer.parseInt(printerDeviceBean.getModifierFont()) * 2;
} catch (NumberFormatException e) {
e.printStackTrace();
}
this.foodIsBold = printerDeviceBean.getFoodIsBold();
this.modifierIsBold = printerDeviceBean.getModifierIsBold();
this.foodIsItalic = printerDeviceBean.getFoodIsItalic();
this.modifierIsItalic = printerDeviceBean.getModifierIsItalic();
}
@Override
......@@ -60,19 +78,50 @@ public class KitChenPrjPrintFoodAdapter extends BaseQuickAdapter<PrjBean.DataBea
indentation = new BigDecimal(tvFoodName.getPaint().measureText("哈")).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
}
boolean isBold, isItalic;
int paddingLeft;
if (itemType == 2) {
//細項,縮進
paddingLeft = indentation;
tvFoodName.setTextSize(modifierFontSize);
tvFoodNum.setTextSize(modifierFontSize);
isBold = modifierIsBold == 1;
isItalic = modifierIsItalic == 1;
} else if (itemType == 3) {
//細項,縮進
paddingLeft = indentation * 2;
tvFoodName.setTextSize(modifierFontSize);
tvFoodNum.setTextSize(modifierFontSize);
isBold = modifierIsBold == 1;
isItalic = modifierIsItalic == 1;
} else {
paddingLeft = 0;
tvFoodName.setTextSize(foodFontSize);
tvFoodNum.setTextSize(foodFontSize);
isBold = foodIsBold == 1;
isItalic = foodIsItalic == 1;
}
tvFoodName.setPadding(paddingLeft, tvFoodName.getPaddingTop(), tvFoodName.getPaddingRight(), tvFoodName.getPaddingBottom());
tvFoodNum.setText(String.valueOf(foodNumber));
tvFoodName.setText(foodName);
if (isBold && isItalic) {
tvFoodName.setTypeface(null, Typeface.BOLD_ITALIC);
tvFoodNum.setTypeface(null, Typeface.BOLD_ITALIC);
} else if (isBold) {
tvFoodName.setTypeface(null, Typeface.BOLD);
tvFoodNum.setTypeface(null, Typeface.BOLD);
} else if (isItalic) {
tvFoodName.setTypeface(null, Typeface.ITALIC);
tvFoodNum.setTypeface(null, Typeface.ITALIC);
} else {
tvFoodName.setTypeface(null, Typeface.NORMAL);
tvFoodNum.setTypeface(null, Typeface.NORMAL);
}
return view;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment