@@ -45,4 +45,10 @@ dependencies { | |||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' | |||
implementation files('libs\\sdkapi.jar') | |||
compileOnly files('libs/sdkapi.jar') | |||
implementation 'com.lzy.net:okgo:3.0.4' | |||
//图片加载 | |||
implementation 'com.github.bumptech.glide:glide:4.11.0' | |||
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' | |||
} |
@@ -176,6 +176,11 @@ public class MenuSelectionActivity extends AppCompatActivity{ | |||
{ | |||
DataBus.getInstance().organize=model.data; | |||
ConfigName.getInstance().Shop_Id=DataBus.getInstance().organize.id; | |||
if(!ConfigName.getInstance().Shop_Name.equals(model.data.store_Name)) | |||
{ | |||
ConfigName.getInstance().Shop_Name=model.data.store_Name; | |||
Main.getInstance().SavePZ(); | |||
} | |||
//拉取菜菜品 | |||
Main.getInstance().GetCaiPin(); | |||
}else | |||
@@ -4,6 +4,9 @@ import android.app.Application; | |||
import android.content.Context; | |||
import android.os.Environment; | |||
import com.bpa.scalage.helper.CrashHandler; | |||
import com.lzy.okgo.OkGo; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.InputStream; | |||
@@ -21,6 +24,9 @@ public class ICSAppFood extends Application { | |||
@Override | |||
public void onCreate() { | |||
super.onCreate(); | |||
OkGo.getInstance().init(this); | |||
//0.全局异常捕获,保存为SD卡本级目录 crash | |||
CrashHandler.getInstance().init(this); | |||
initSD(); | |||
//ImageLoaderConfig.initImageLoader(this, Constants.BASE_IMAGE_CACHE); | |||
@@ -36,14 +36,31 @@ public class Main { | |||
{ | |||
//1.加载配置 | |||
LoadingPZ(); | |||
//0.加载环境配置 | |||
ToggleEnvironment(); | |||
//2.获取组织信息 | |||
GetOrganize(); | |||
} | |||
/** | |||
* 切换环境 | |||
*/ | |||
public void ToggleEnvironment() { | |||
if (ConfigName.getInstance().Environment.equals("开发环境")) { | |||
ConfigName.getInstance().SaasAddress = "https://bpa.black-pa.com:21527"; | |||
} else if (ConfigName.getInstance().Environment.equals("测试环境")) { | |||
ConfigName.getInstance().SaasAddress = "https://bpa.black-pa.com:21528"; | |||
} else if (ConfigName.getInstance().Environment.equals("正式环境")) { | |||
ConfigName.getInstance().SaasAddress = "https://witt.black-pa.com"; | |||
} | |||
} | |||
/** | |||
* 加载配置 | |||
*/ | |||
public void LoadingPZ() | |||
{ | |||
ConfigName.getInstance().Environment =ConfigUtil.read(DataBus.getInstance().dishesCon,"Environment", ConfigName.getInstance().Environment); | |||
//1.店铺配置 | |||
ConfigName.getInstance().Shop_Name =ConfigUtil.read(DataBus.getInstance().dishesCon,"Shop_Name", ConfigName.getInstance().Shop_Name); | |||
ConfigName.getInstance().AutKey =ConfigUtil.read(DataBus.getInstance().dishesCon,"AutKey", ConfigName.getInstance().AutKey); | |||
@@ -64,6 +81,7 @@ public class Main { | |||
*/ | |||
public void SavePZ() | |||
{ | |||
ConfigUtil.write(DataBus.getInstance().dishesCon,"Environment", ConfigName.getInstance().Environment); | |||
//1.店铺配置 | |||
ConfigUtil.write(DataBus.getInstance().dishesCon,"Shop_Name", ConfigName.getInstance().Shop_Name); | |||
ConfigUtil.write(DataBus.getInstance().dishesCon,"AutKey", ConfigName.getInstance().AutKey); | |||
@@ -77,6 +95,8 @@ public class Main { | |||
ConfigUtil.write(DataBus.getInstance().dishesCon,"Plate_Com_Name", ConfigName.getInstance().Plate_Com_Name); | |||
ConfigUtil.write(DataBus.getInstance().dishesCon,"Plate_Com_Port", ConfigName.getInstance().Plate_Com_Port); | |||
ConfigUtil.write(DataBus.getInstance().dishesCon,"Plate_Com_Format", ConfigName.getInstance().Plate_Com_Format); | |||
ToggleEnvironment(); | |||
} | |||
/** | |||
@@ -26,7 +26,7 @@ public class ConfigName { | |||
/** | |||
* 店铺设备号 | |||
*/ | |||
public String AutKey="95"; | |||
public String AutKey="79"; | |||
/** | |||
* 店铺ID | |||
*/ | |||
@@ -36,22 +36,31 @@ public class ConfigName { | |||
*/ | |||
public String Shop_DeviceId=java.util.UUID.randomUUID().toString(); | |||
//region | |||
//region 环境配置 | |||
/** | |||
* 环境配置 | |||
*/ | |||
public String Environment = "开发环境"; | |||
//endregion | |||
//region uRL | |||
//Sass地址 | |||
public String SaasAddress="https://bpa.black-pa.com:21527"; | |||
//public String SaasAddress="https://witt.black-pa.com"; | |||
//public String SaasAddress="https://bpa.black-pa.com:21528"; | |||
public String SaasAddress="https://witt.black-pa.com"; | |||
//获取店铺菜品接口 Get | |||
public String GetFruitUrl=SaasAddress+"/kitchen/api/StoreHelper/StoreGoodsMenuByStoreId?storeId="; | |||
public String GetFruitUrl="/kitchen/api/StoreHelper/StoreGoodsMenuByStoreId?storeId="; | |||
//获取店铺详细信息 Get | |||
public String GetStore=SaasAddress+"/kitchen/api/StoreHelper/GetStoreInfoById?storeId="; | |||
public String GetStore="/kitchen/api/StoreHelper/GetStoreInfoById?storeId="; | |||
//获取用户信息uRL | |||
public String GetUserUrl=SaasAddress+"/kitchen/api/member-helper/memberinfobywechat/"; | |||
public String GetUserUrl="/kitchen/api/member-helper/memberinfobywechat/"; | |||
//查询Vip用户信息 | |||
public String GetVipUserUrl=SaasAddress+"/kitchen/api/member-helper/memberinfobymemberid_wechat/"; | |||
public String GetVipUserUrl="/kitchen/api/member-helper/memberinfobymemberid_wechat/"; | |||
//获取用户与卡的订单的关联关系 https://bpa.black-pa.com:21528/order/order/orderantusericard/64F9D80311A204E0/d55b4e04-d17f-45df-bc0a-12e39734ff00 | |||
public String GetUserOrCartGX=SaasAddress+"/order/order/orderantusericard/"; | |||
public String GetUserOrCartGX="/order/order/orderantusericard/"; | |||
//创建子订单接口 | |||
public String AddSuOrderUrl=SaasAddress+"/order/order/orderdetail"; | |||
public String AddSuOrderUrl="/order/order/orderdetail"; | |||
//endregion | |||
//region 菜品放置区 | |||
@@ -62,7 +62,7 @@ public class FruitAdapter extends ArrayAdapter<FoodModel> { | |||
}); | |||
} | |||
// 设置要显示的图片和文字 | |||
fruitimage.setImageURL(fruit.cover); | |||
fruitimage.glideAppLoadUrlImage(fruit.cover); | |||
fruitname.setText(fruit.name); | |||
fruitprice.setText("非会员 ¥"+new java.text.DecimalFormat("#.00").format(fruit.price)+"/50g"); | |||
fruitvipprice.setText("会员 ¥"+new java.text.DecimalFormat("#.00").format(fruit.vipPrice)+"/50g"); | |||
@@ -1,4 +1,5 @@ | |||
package com.bpa.scalage.control; | |||
import android.content.Context; | |||
import android.graphics.Bitmap; | |||
import android.graphics.BitmapFactory; | |||
@@ -7,12 +8,17 @@ import android.os.Message; | |||
import android.util.AttributeSet; | |||
import android.widget.ImageView; | |||
import android.widget.Toast; | |||
import com.bpa.scalage.R; | |||
import com.bumptech.glide.Glide; | |||
import com.bumptech.glide.load.engine.DiskCacheStrategy; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.net.HttpURLConnection; | |||
import java.net.URL; | |||
public class MyImageView extends ImageView { | |||
public class MyImageView extends ImageView { | |||
public static final int GET_DATA_SUCCESS = 1; | |||
public static final int NETWORK_ERROR = 2; | |||
public static final int SERVER_ERROR = 3; | |||
@@ -20,16 +26,16 @@ public class MyImageView extends ImageView { | |||
private Handler handler = new Handler() { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
switch (msg.what){ | |||
switch (msg.what) { | |||
case GET_DATA_SUCCESS: | |||
Bitmap bitmap = (Bitmap) msg.obj; | |||
setImageBitmap(bitmap); | |||
break; | |||
case NETWORK_ERROR: | |||
Toast.makeText(getContext(),"网络连接失败",Toast.LENGTH_SHORT).show(); | |||
Toast.makeText(getContext(), "网络连接失败", Toast.LENGTH_SHORT).show(); | |||
break; | |||
case SERVER_ERROR: | |||
Toast.makeText(getContext(),"服务器发生错误",Toast.LENGTH_SHORT).show(); | |||
Toast.makeText(getContext(), "服务器发生错误", Toast.LENGTH_SHORT).show(); | |||
break; | |||
} | |||
} | |||
@@ -74,7 +80,7 @@ public class MyImageView extends ImageView { | |||
msg.what = GET_DATA_SUCCESS; | |||
handler.sendMessage(msg); | |||
inputStream.close(); | |||
}else { | |||
} else { | |||
//服务启发生错误 | |||
handler.sendEmptyMessage(SERVER_ERROR); | |||
} | |||
@@ -87,4 +93,23 @@ public class MyImageView extends ImageView { | |||
}.start(); | |||
} | |||
/** | |||
* 通过GlideApp加载网络图片 | |||
* | |||
* @param img | |||
*/ | |||
public void glideAppLoadUrlImage(String img) { | |||
Glide.with(getContext()).load(img) | |||
//.override(width, height) | |||
// .thumbnail(0.1f) // 加载原始图片的10%作为缩略图 | |||
//.fitCenter() // 缩放图片以适应ImageView的尺寸 | |||
.override(800, 400) // 设置目标图片的宽度和高度 | |||
.placeholder(R.mipmap.gli) | |||
.error(R.mipmap.gli1) | |||
.skipMemoryCache(true) // 禁用内存缓存 | |||
.diskCacheStrategy(DiskCacheStrategy.NONE) | |||
//.diskCacheStrategy(DiskCacheStrategy.ALL) // 缓存所有版本的图片 | |||
.into(this); | |||
} | |||
} |
@@ -0,0 +1,232 @@ | |||
package com.bpa.scalage.helper; | |||
import android.annotation.SuppressLint; | |||
import android.content.Context; | |||
import android.content.Intent; | |||
import android.content.pm.PackageInfo; | |||
import android.content.pm.PackageManager; | |||
import android.content.pm.PackageManager.NameNotFoundException; | |||
import android.os.Build; | |||
import android.os.Environment; | |||
import android.os.Looper; | |||
import android.os.SystemClock; | |||
import android.util.Log; | |||
import android.widget.Toast; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.FilenameFilter; | |||
import java.io.PrintWriter; | |||
import java.io.StringWriter; | |||
import java.io.Writer; | |||
import java.lang.Thread.UncaughtExceptionHandler; | |||
import java.lang.reflect.Field; | |||
import java.text.DateFormat; | |||
import java.text.SimpleDateFormat; | |||
import java.util.Date; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
@SuppressLint("SimpleDateFormat") | |||
public class CrashHandler implements UncaughtExceptionHandler { | |||
public static String TAG = "MyCrash"; | |||
// ϵͳĬ�ϵ�UncaughtException������ | |||
private UncaughtExceptionHandler mDefaultHandler; | |||
private static CrashHandler instance = new CrashHandler(); | |||
private Context mContext; | |||
// �����洢�豸��Ϣ���쳣��Ϣ | |||
private Map<String, String> infos = new HashMap<String, String>(); | |||
// ���ڸ�ʽ������,��Ϊ��־�ļ�����һ���� | |||
private DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); | |||
/** ��ֻ֤��һ��CrashHandlerʵ�� */ | |||
private CrashHandler() { | |||
} | |||
/** ��ȡCrashHandlerʵ�� ,����ģʽ */ | |||
public static CrashHandler getInstance() { | |||
return instance; | |||
} | |||
/** | |||
* ��ʼ�� | |||
* | |||
* @param context | |||
*/ | |||
public void init(Context context) { | |||
mContext = context; | |||
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler(); | |||
Thread.setDefaultUncaughtExceptionHandler(this); | |||
autoClear(120); | |||
} | |||
/** | |||
* ��UncaughtException����ʱ��ת��ú��������� | |||
*/ | |||
@Override | |||
public void uncaughtException(Thread thread, Throwable ex) { | |||
if (!handleException(ex) && mDefaultHandler != null) { | |||
mDefaultHandler.uncaughtException(thread, ex); | |||
} else { | |||
SystemClock.sleep(3000); | |||
android.os.Process.killProcess(android.os.Process.myPid()); | |||
System.exit(1); | |||
} | |||
} | |||
/** | |||
* �Զ��������,�ռ�������Ϣ ���ʹ���Ȳ������ڴ����. | |||
* | |||
* @param ex | |||
* @return true:��������˸��쳣��Ϣ; ����false. | |||
*/ | |||
private boolean handleException(Throwable ex) { | |||
if (ex == null) | |||
return false; | |||
try { | |||
new Thread() { | |||
@Override | |||
public void run() { | |||
Looper.prepare(); | |||
Toast.makeText(mContext, "大爷我崩溃了.自动修复中!!!", | |||
Toast.LENGTH_LONG).show(); | |||
Looper.loop(); | |||
} | |||
}.start(); | |||
collectDeviceInfo(mContext); | |||
saveCrashInfoFile(ex); | |||
Intent intent = mContext.getPackageManager().getLaunchIntentForPackage(mContext.getPackageName()); | |||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |||
mContext.startActivity(intent); | |||
SystemClock.sleep(3000); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
return true; | |||
} | |||
/** | |||
* �ռ��豸������Ϣ | |||
* | |||
* @param ctx | |||
*/ | |||
public void collectDeviceInfo(Context ctx) { | |||
try { | |||
PackageManager pm = ctx.getPackageManager(); | |||
PackageInfo pi = pm.getPackageInfo(ctx.getPackageName(), | |||
PackageManager.GET_ACTIVITIES); | |||
if (pi != null) { | |||
String versionName = pi.versionName + ""; | |||
String versionCode = pi.versionCode + ""; | |||
infos.put("versionName", versionName); | |||
infos.put("versionCode", versionCode); | |||
} | |||
} catch (NameNotFoundException e) { | |||
Log.e(TAG, "an error occured when collect package info", e); | |||
} | |||
Field[] fields = Build.class.getDeclaredFields(); | |||
for (Field field : fields) { | |||
try { | |||
field.setAccessible(true); | |||
infos.put(field.getName(), field.get(null).toString()); | |||
} catch (Exception e) { | |||
Log.e(TAG, "an error occured when collect crash info", e); | |||
} | |||
} | |||
} | |||
/** | |||
* ���������Ϣ���ļ��� | |||
* @param ex | |||
* @return �����ļ�����,���ڽ��ļ����͵������� | |||
* @throws Exception | |||
*/ | |||
private String saveCrashInfoFile(Throwable ex) throws Exception { | |||
StringBuffer sb = new StringBuffer(); | |||
try { | |||
SimpleDateFormat sDateFormat = new SimpleDateFormat( | |||
"yyyy-MM-dd HH:mm:ss"); | |||
String date = sDateFormat.format(new Date()); | |||
sb.append("\r\n" + date + "\n"); | |||
for (Map.Entry<String, String> entry : infos.entrySet()) { | |||
String key = entry.getKey(); | |||
String value = entry.getValue(); | |||
sb.append(key + "=" + value + "\n"); | |||
} | |||
Writer writer = new StringWriter(); | |||
PrintWriter printWriter = new PrintWriter(writer); | |||
ex.printStackTrace(printWriter); | |||
Throwable cause = ex.getCause(); | |||
while (cause != null) { | |||
cause.printStackTrace(printWriter); | |||
cause = cause.getCause(); | |||
} | |||
printWriter.flush(); | |||
printWriter.close(); | |||
String result = writer.toString(); | |||
sb.append(result); | |||
String fileName = writeFile(sb.toString()); | |||
return fileName; | |||
} catch (Exception e) { | |||
Log.e(TAG, "an error occured while writing file...", e); | |||
sb.append("an error occured while writing file...\r\n"); | |||
writeFile(sb.toString()); | |||
} | |||
return null; | |||
} | |||
private String writeFile(String sb) throws Exception { | |||
String time = formatter.format(new Date()); | |||
String fileName = "crash-" + time + ".log"; | |||
if (FileUtil.hasSdcard()) { | |||
String path = getGlobalpath(); | |||
File dir = new File(path); | |||
if (!dir.exists()) | |||
dir.mkdirs(); | |||
FileOutputStream fos = new FileOutputStream(path + fileName, true); | |||
fos.write(sb.getBytes()); | |||
fos.flush(); | |||
fos.close(); | |||
} | |||
return fileName; | |||
} | |||
public static String getGlobalpath() { | |||
return Environment.getExternalStorageDirectory().getAbsolutePath() | |||
+ File.separator + "crash" + File.separator; | |||
} | |||
public static void setTag(String tag) { | |||
TAG = tag; | |||
} | |||
/** | |||
* �ļ�ɾ�� | |||
* @param �ļ��������� | |||
*/ | |||
public void autoClear(final int autoClearDay) { | |||
FileUtil.delete(getGlobalpath(), new FilenameFilter() { | |||
@Override | |||
public boolean accept(File file, String filename) { | |||
String s = FileUtil.getFileNameWithoutExtension(filename); | |||
int day = autoClearDay < 0 ? autoClearDay : -1 * autoClearDay; | |||
String date = "crash-" + DateUtil.getOtherDay(day); | |||
return date.compareTo(s) >= 0; | |||
} | |||
}); | |||
} | |||
} |
@@ -0,0 +1,374 @@ | |||
package com.bpa.scalage.helper; | |||
import android.annotation.SuppressLint; | |||
import java.text.ParseException; | |||
import java.text.SimpleDateFormat; | |||
import java.util.Calendar; | |||
import java.util.Date; | |||
@SuppressLint("SimpleDateFormat") | |||
public final class DateUtil { | |||
/** yyyy-MM-dd HH:mm:ss�ַ��� */ | |||
public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; | |||
/** yyyy-MM-dd�ַ��� */ | |||
public static final String DEFAULT_FORMAT_DATE = "yyyy-MM-dd"; | |||
/** HH:mm:ss�ַ��� */ | |||
public static final String DEFAULT_FORMAT_TIME = "HH:mm:ss"; | |||
/** yyyy-MM-dd HH:mm:ss��ʽ */ | |||
public static final ThreadLocal<SimpleDateFormat> defaultDateTimeFormat = new ThreadLocal<SimpleDateFormat>() { | |||
@Override | |||
protected SimpleDateFormat initialValue() { | |||
return new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT); | |||
} | |||
}; | |||
/** yyyy-MM-dd��ʽ */ | |||
public static final ThreadLocal<SimpleDateFormat> defaultDateFormat = new ThreadLocal<SimpleDateFormat>() { | |||
@Override | |||
protected SimpleDateFormat initialValue() { | |||
return new SimpleDateFormat(DEFAULT_FORMAT_DATE); | |||
} | |||
}; | |||
/** HH:mm:ss��ʽ */ | |||
public static final ThreadLocal<SimpleDateFormat> defaultTimeFormat = new ThreadLocal<SimpleDateFormat>() { | |||
@Override | |||
protected SimpleDateFormat initialValue() { | |||
return new SimpleDateFormat(DEFAULT_FORMAT_TIME); | |||
} | |||
}; | |||
private DateUtil() { | |||
throw new RuntimeException("�� 3��"); | |||
} | |||
/** | |||
* ��longʱ��ת��yyyy-MM-dd HH:mm:ss�ַ���<br> | |||
* @param timeInMillis ʱ��longֵ | |||
* @return yyyy-MM-dd HH:mm:ss | |||
*/ | |||
public static String getDateTimeFromMillis(long timeInMillis) { | |||
return getDateTimeFormat(new Date(timeInMillis)); | |||
} | |||
/** | |||
* ��longʱ��ת��yyyy-MM-dd�ַ���<br> | |||
* @param timeInMillis | |||
* @return yyyy-MM-dd | |||
*/ | |||
public static String getDateFromMillis(long timeInMillis) { | |||
return getDateFormat(new Date(timeInMillis)); | |||
} | |||
/** | |||
* ��dateת��yyyy-MM-dd HH:mm:ss�ַ��� | |||
* <br> | |||
* @param date Date���� | |||
* @return yyyy-MM-dd HH:mm:ss | |||
*/ | |||
public static String getDateTimeFormat(Date date) { | |||
return dateSimpleFormat(date, defaultDateTimeFormat.get()); | |||
} | |||
/** | |||
* �������յ�intת��yyyy-MM-dd���ַ��� | |||
* @param year �� | |||
* @param month �� 1-12 | |||
* @param day �� | |||
* ע���±�ʾCalendar���£���ʵ��С1 | |||
* ��������δ���ж� | |||
*/ | |||
public static String getDateFormat(int year, int month, int day) { | |||
return getDateFormat(getDate(year, month, day)); | |||
} | |||
/** | |||
* ��dateת��yyyy-MM-dd�ַ���<br> | |||
* @param date Date���� | |||
* @return yyyy-MM-dd | |||
*/ | |||
public static String getDateFormat(Date date) { | |||
return dateSimpleFormat(date, defaultDateFormat.get()); | |||
} | |||
/** | |||
* ���HH:mm:ss��ʱ�� | |||
* @param date | |||
* @return | |||
*/ | |||
public static String getTimeFormat(Date date) { | |||
return dateSimpleFormat(date, defaultTimeFormat.get()); | |||
} | |||
/** | |||
* ��ʽ��������ʾ��ʽ | |||
* @param sdate ԭʼ���ڸ�ʽ "yyyy-MM-dd" | |||
* @param format ��ʽ�������ڸ�ʽ | |||
* @return ��ʽ�����������ʾ | |||
*/ | |||
public static String dateFormat(String sdate, String format) { | |||
SimpleDateFormat formatter = new SimpleDateFormat(format); | |||
java.sql.Date date = java.sql.Date.valueOf(sdate); | |||
return dateSimpleFormat(date, formatter); | |||
} | |||
/** | |||
* ��ʽ��������ʾ��ʽ | |||
* @param date Date���� | |||
* @param format ��ʽ�������ڸ�ʽ | |||
* @return ��ʽ�����������ʾ | |||
*/ | |||
public static String dateFormat(Date date, String format) { | |||
SimpleDateFormat formatter = new SimpleDateFormat(format); | |||
return dateSimpleFormat(date, formatter); | |||
} | |||
/** | |||
* ��dateת���ַ��� | |||
* @param date Date | |||
* @param format SimpleDateFormat | |||
* <br> | |||
* ע�� SimpleDateFormatΪ��ʱ������Ĭ�ϵ�yyyy-MM-dd HH:mm:ss��ʽ | |||
* @return yyyy-MM-dd HH:mm:ss | |||
*/ | |||
public static String dateSimpleFormat(Date date, SimpleDateFormat format) { | |||
if (format == null) | |||
format = defaultDateTimeFormat.get(); | |||
return (date == null ? "" : format.format(date)); | |||
} | |||
/** | |||
* ��"yyyy-MM-dd HH:mm:ss" ��ʽ���ַ���ת��Date | |||
* @param strDate ʱ���ַ��� | |||
* @return Date | |||
*/ | |||
public static Date getDateByDateTimeFormat(String strDate) { | |||
return getDateByFormat(strDate, defaultDateTimeFormat.get()); | |||
} | |||
/** | |||
* ��"yyyy-MM-dd" ��ʽ���ַ���ת��Date | |||
* @param strDate | |||
* @return Date | |||
*/ | |||
public static Date getDateByDateFormat(String strDate) { | |||
return getDateByFormat(strDate, defaultDateFormat.get()); | |||
} | |||
/** | |||
* ��ָ����ʽ��ʱ���ַ���ת��Date���� | |||
* @param strDate ʱ���ַ��� | |||
* @param format ��ʽ���ַ��� | |||
* @return Date | |||
*/ | |||
public static Date getDateByFormat(String strDate, String format) { | |||
return getDateByFormat(strDate, new SimpleDateFormat(format)); | |||
} | |||
/** | |||
* ��String�ַ�������һ����ʽת��Date<br> | |||
* ע�� SimpleDateFormatΪ��ʱ������Ĭ�ϵ�yyyy-MM-dd HH:mm:ss��ʽ | |||
* @param strDate ʱ���ַ��� | |||
* @param format SimpleDateFormat���� | |||
* @exception ParseException ���ڸ�ʽת������ | |||
*/ | |||
private static Date getDateByFormat(String strDate, SimpleDateFormat format) { | |||
if (format == null) | |||
format = defaultDateTimeFormat.get(); | |||
try { | |||
return format.parse(strDate); | |||
} catch (ParseException e) { | |||
e.printStackTrace(); | |||
} | |||
return null; | |||
} | |||
/** | |||
* �������յ�intת��date | |||
* @param year �� | |||
* @param month �� 1-12 | |||
* @param day �� | |||
* ע���±�ʾCalendar���£���ʵ��С1 | |||
*/ | |||
public static Date getDate(int year, int month, int day) { | |||
Calendar mCalendar = Calendar.getInstance(); | |||
mCalendar.set(year, month - 1, day); | |||
return mCalendar.getTime(); | |||
} | |||
/** | |||
* ����������������� | |||
* | |||
* @param strat ��ʼ���ڣ���ʽyyyy-MM-dd | |||
* @param end ��ֹ���ڣ���ʽyyyy-MM-dd | |||
* @return ��������������� | |||
*/ | |||
public static long getIntervalDays(String strat, String end) { | |||
return ((java.sql.Date.valueOf(end)).getTime() - (java.sql.Date | |||
.valueOf(strat)).getTime()) / (3600 * 24 * 1000); | |||
} | |||
/** | |||
* ��õ�ǰ��� | |||
* @return year(int) | |||
*/ | |||
public static int getCurrentYear() { | |||
Calendar mCalendar = Calendar.getInstance(); | |||
return mCalendar.get(Calendar.YEAR); | |||
} | |||
/** | |||
* ��õ�ǰ�·� | |||
* @return month(int) 1-12 | |||
*/ | |||
public static int getCurrentMonth() { | |||
Calendar mCalendar = Calendar.getInstance(); | |||
return mCalendar.get(Calendar.MONTH) + 1; | |||
} | |||
/** | |||
* ��õ��¼��� | |||
* @return day(int) | |||
*/ | |||
public static int getDayOfMonth() { | |||
Calendar mCalendar = Calendar.getInstance(); | |||
return mCalendar.get(Calendar.DAY_OF_MONTH); | |||
} | |||
/** | |||
* ��ý��������(��ʽ��yyyy-MM-dd) | |||
* @return yyyy-MM-dd | |||
*/ | |||
public static String getToday() { | |||
Calendar mCalendar = Calendar.getInstance(); | |||
return getDateFormat(mCalendar.getTime()); | |||
} | |||
/** | |||
* ������������(��ʽ��yyyy-MM-dd) | |||
* @return yyyy-MM-dd | |||
*/ | |||
public static String getYesterday() { | |||
Calendar mCalendar = Calendar.getInstance(); | |||
mCalendar.add(Calendar.DATE, -1); | |||
return getDateFormat(mCalendar.getTime()); | |||
} | |||
/** | |||
* ���ǰ�������(��ʽ��yyyy-MM-dd) | |||
* @return yyyy-MM-dd | |||
*/ | |||
public static String getBeforeYesterday() { | |||
Calendar mCalendar = Calendar.getInstance(); | |||
mCalendar.add(Calendar.DATE, -2); | |||
return getDateFormat(mCalendar.getTime()); | |||
} | |||
/** | |||
* ��ü���֮ǰ������֮������� | |||
* @param diff ��ֵ�����������ƣ�������ǰ�� | |||
* @return | |||
*/ | |||
public static String getOtherDay(int diff) { | |||
Calendar mCalendar = Calendar.getInstance(); | |||
mCalendar.add(Calendar.DATE, diff); | |||
return getDateFormat(mCalendar.getTime()); | |||
} | |||
/** | |||
* ȡ�ø������ڼ���һ������������ڶ���. | |||
* | |||
* @param date ���������ڶ��� | |||
* @param amount ��Ҫ��ӵ��������������ǰ��������ʹ�ø����Ϳ���. | |||
* @return Date ����һ�������Ժ��Date����. | |||
*/ | |||
public static String getCalcDateFormat(String sDate, int amount) { | |||
Date date = getCalcDate(getDateByDateFormat(sDate), amount); | |||
return getDateFormat(date); | |||
} | |||
/** | |||
* ȡ�ø������ڼ���һ������������ڶ���. | |||
* | |||
* @param date ���������ڶ��� | |||
* @param amount ��Ҫ��ӵ��������������ǰ��������ʹ�ø����Ϳ���. | |||
* @return Date ����һ�������Ժ��Date����. | |||
*/ | |||
public static Date getCalcDate(Date date, int amount) { | |||
Calendar cal = Calendar.getInstance(); | |||
cal.setTime(date); | |||
cal.add(Calendar.DATE, amount); | |||
return cal.getTime(); | |||
} | |||
/** | |||
* ���һ������ʮ����֮������ڶ��� | |||
* @param date | |||
* @param hOffset ʱƫ��������Ϊ�� | |||
* @param mOffset ��ƫ��������Ϊ�� | |||
* @param sOffset ��ƫ��������Ϊ�� | |||
* @return | |||
*/ | |||
public static Date getCalcTime(Date date, int hOffset, int mOffset, int sOffset) { | |||
Calendar cal = Calendar.getInstance(); | |||
if (date != null) | |||
cal.setTime(date); | |||
cal.add(Calendar.HOUR_OF_DAY, hOffset); | |||
cal.add(Calendar.MINUTE, mOffset); | |||
cal.add(Calendar.SECOND, sOffset); | |||
return cal.getTime(); | |||
} | |||
/** | |||
* ����ָ����������Сʱ���룬����һ��java.Util.Date���� | |||
* | |||
* @param year �� | |||
* @param month �� 0-11 | |||
* @param date �� | |||
* @param hourOfDay Сʱ 0-23 | |||
* @param minute �� 0-59 | |||
* @param second �� 0-59 | |||
* @return һ��Date���� | |||
*/ | |||
public static Date getDate(int year, int month, int date, int hourOfDay, | |||
int minute, int second) { | |||
Calendar cal = Calendar.getInstance(); | |||
cal.set(year, month, date, hourOfDay, minute, second); | |||
return cal.getTime(); | |||
} | |||
/** | |||
* ������������� | |||
* @param sDate yyyy-MM-dd��ʽ | |||
* @return arr[0]:�꣬ arr[1]:�� 0-11 , arr[2]�� | |||
*/ | |||
public static int[] getYearMonthAndDayFrom(String sDate) { | |||
return getYearMonthAndDayFromDate(getDateByDateFormat(sDate)); | |||
} | |||
/** | |||
* ������������� | |||
* @return arr[0]:�꣬ arr[1]:�� 0-11 , arr[2]�� | |||
*/ | |||
public static int[] getYearMonthAndDayFromDate(Date date) { | |||
Calendar calendar = Calendar.getInstance(); | |||
calendar.setTime(date); | |||
int[] arr = new int[3]; | |||
arr[0] = calendar.get(Calendar.YEAR); | |||
arr[1] = calendar.get(Calendar.MONTH); | |||
arr[2] = calendar.get(Calendar.DAY_OF_MONTH); | |||
return arr; | |||
} | |||
} |
@@ -0,0 +1,588 @@ | |||
package com.bpa.scalage.helper; | |||
import android.os.Environment; | |||
import android.text.TextUtils; | |||
import java.io.BufferedReader; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.io.FileOutputStream; | |||
import java.io.FileWriter; | |||
import java.io.FilenameFilter; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.InputStreamReader; | |||
import java.io.OutputStream; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.List; | |||
public final class FileUtil { | |||
private FileUtil() { | |||
throw new Error("���n��"); | |||
} | |||
/** �ָ���. */ | |||
public final static String FILE_EXTENSION_SEPARATOR = "."; | |||
/**"/"*/ | |||
public final static String SEP = File.separator; | |||
/** SD����Ŀ¼ */ | |||
public static final String SDPATH = Environment | |||
.getExternalStorageDirectory() + File.separator; | |||
/** | |||
* �ж�SD���Ƿ���� | |||
* @return SD�����÷���true | |||
*/ | |||
public static boolean hasSdcard() { | |||
String status = Environment.getExternalStorageState(); | |||
return Environment.MEDIA_MOUNTED.equals(status); | |||
} | |||
/** | |||
* ��ȡ�ļ������� | |||
* <br> | |||
* Ĭ��utf-8���� | |||
* @param filePath �ļ�·�� | |||
* @return �ַ��� | |||
* @throws IOException | |||
*/ | |||
public static String readFile(String filePath) throws IOException { | |||
return readFile(filePath, "utf-8"); | |||
} | |||
/** | |||
* ��ȡ�ļ������� | |||
* @param filePath �ļ�Ŀ¼ | |||
* @param charsetName �ַ����� | |||
* @return String�ַ��� | |||
*/ | |||
public static String readFile(String filePath, String charsetName) | |||
throws IOException { | |||
if (TextUtils.isEmpty(filePath)) | |||
return null; | |||
if (TextUtils.isEmpty(charsetName)) | |||
charsetName = "utf-8"; | |||
File file = new File(filePath); | |||
StringBuilder fileContent = new StringBuilder(""); | |||
if (file == null || !file.isFile()) | |||
return null; | |||
BufferedReader reader = null; | |||
try { | |||
InputStreamReader is = new InputStreamReader(new FileInputStream( | |||
file), charsetName); | |||
reader = new BufferedReader(is); | |||
String line = null; | |||
while ((line = reader.readLine()) != null) { | |||
if (!fileContent.toString().equals("")) { | |||
fileContent.append("\r\n"); | |||
} | |||
fileContent.append(line); | |||
} | |||
return fileContent.toString(); | |||
} finally { | |||
if (reader != null) { | |||
try { | |||
reader.close(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* ��ȡ�ı��ļ���List�ַ���������(Ĭ��utf-8����) | |||
* @param filePath �ļ�Ŀ¼ | |||
* @return �ļ������ڷ���null�������ַ������� | |||
* @throws IOException | |||
*/ | |||
public static List<String> readFileToList(String filePath) | |||
throws IOException { | |||
return readFileToList(filePath, "utf-8"); | |||
} | |||
/** | |||
* ��ȡ�ı��ļ���List�ַ��������� | |||
* @param filePath �ļ�Ŀ¼ | |||
* @param charsetName �ַ����� | |||
* @return �ļ������ڷ���null�������ַ������� | |||
*/ | |||
public static List<String> readFileToList(String filePath, | |||
String charsetName) throws IOException { | |||
if (TextUtils.isEmpty(filePath)) | |||
return null; | |||
if (TextUtils.isEmpty(charsetName)) | |||
charsetName = "utf-8"; | |||
File file = new File(filePath); | |||
List<String> fileContent = new ArrayList<String>(); | |||
if (file == null || !file.isFile()) { | |||
return null; | |||
} | |||
BufferedReader reader = null; | |||
try { | |||
InputStreamReader is = new InputStreamReader(new FileInputStream( | |||
file), charsetName); | |||
reader = new BufferedReader(is); | |||
String line = null; | |||
while ((line = reader.readLine()) != null) { | |||
fileContent.add(line); | |||
} | |||
return fileContent; | |||
} finally { | |||
if (reader != null) { | |||
try { | |||
reader.close(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* ���ļ���д������ | |||
* @param filePath �ļ�Ŀ¼ | |||
* @param content Ҫд������� | |||
* @param append ���Ϊ true��������д���ļ�ĩβ����������д���ļ���ʼ�� | |||
* @return д��ɹ�����true�� д��ʧ�ܷ���false | |||
* @throws IOException | |||
*/ | |||
public static boolean writeFile(String filePath, String content, | |||
boolean append) throws IOException { | |||
if (TextUtils.isEmpty(filePath)) | |||
return false; | |||
if (TextUtils.isEmpty(content)) | |||
return false; | |||
FileWriter fileWriter = null; | |||
try { | |||
createFile(filePath); | |||
fileWriter = new FileWriter(filePath, append); | |||
fileWriter.write(content); | |||
fileWriter.flush(); | |||
return true; | |||
} finally { | |||
if (fileWriter != null) { | |||
try { | |||
fileWriter.close(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* ���ļ���д������<br> | |||
* Ĭ�����ļ���ʼ������д������ | |||
* @param filePath �ļ�Ŀ¼ | |||
* @param stream �ֽ������� | |||
* @return д��ɹ�����true������false | |||
* @throws IOException | |||
*/ | |||
public static boolean writeFile(String filePath, InputStream stream) | |||
throws IOException { | |||
return writeFile(filePath, stream, false); | |||
} | |||
/** | |||
* ���ļ���д������ | |||
* @param filePath �ļ�Ŀ¼ | |||
* @param stream �ֽ������� | |||
* @param append ���Ϊ true��������д���ļ�ĩβ���� | |||
* Ϊfalseʱ�����ԭ�������ݣ���ͷ��ʼд | |||
* @return д��ɹ�����true������false | |||
* @throws IOException | |||
*/ | |||
public static boolean writeFile(String filePath, InputStream stream, | |||
boolean append) throws IOException { | |||
if (TextUtils.isEmpty(filePath)) | |||
throw new NullPointerException("filePath is Empty"); | |||
if (stream == null) | |||
throw new NullPointerException("InputStream is null"); | |||
return writeFile(new File(filePath), stream, | |||
append); | |||
} | |||
/** | |||
* ���ļ���д������ | |||
* Ĭ�����ļ���ʼ������д������ | |||
* @param file ָ���ļ� | |||
* @param stream �ֽ������� | |||
* @return д��ɹ�����true������false | |||
* @throws IOException | |||
*/ | |||
public static boolean writeFile(File file, InputStream stream) | |||
throws IOException { | |||
return writeFile(file, stream, false); | |||
} | |||
/** | |||
* ���ļ���д������ | |||
* @param file ָ���ļ� | |||
* @param stream �ֽ������� | |||
* @param append Ϊtrueʱ�����ļ���ʼ������д�����ݣ� | |||
* Ϊfalseʱ�����ԭ�������ݣ���ͷ��ʼд | |||
* @return д��ɹ�����true������false | |||
* @throws IOException | |||
*/ | |||
public static boolean writeFile(File file, InputStream stream, | |||
boolean append) throws IOException { | |||
if (file == null) | |||
throw new NullPointerException("file = null"); | |||
OutputStream out = null; | |||
try { | |||
createFile(file.getAbsolutePath()); | |||
out = new FileOutputStream(file, append); | |||
byte data[] = new byte[1024]; | |||
int length = -1; | |||
while ((length = stream.read(data)) != -1) { | |||
out.write(data, 0, length); | |||
} | |||
out.flush(); | |||
return true; | |||
} finally { | |||
if (out != null) { | |||
try { | |||
out.close(); | |||
stream.close(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* �����ļ� | |||
* @param sourceFilePath Դ�ļ�Ŀ¼��Ҫ���Ƶ��ļ�Ŀ¼�� | |||
* @param destFilePath Ŀ���ļ�Ŀ¼�����ƺ���ļ�Ŀ¼�� | |||
* @return �����ļ��ɹ�����true������false | |||
* @throws IOException | |||
*/ | |||
public static boolean copyFile(String sourceFilePath, String destFilePath) | |||
throws IOException { | |||
InputStream inputStream = null; | |||
inputStream = new FileInputStream(sourceFilePath); | |||
return writeFile(destFilePath, inputStream); | |||
} | |||
/** | |||
* ��ȡij��Ŀ¼�µ��ļ��� | |||
* @param dirPath Ŀ¼ | |||
* @param fileFilter ������ | |||
* @return ij��Ŀ¼�µ������ļ��� | |||
*/ | |||
public static List<String> getFileNameList(String dirPath, | |||
FilenameFilter fileFilter) { | |||
if (fileFilter == null) | |||
return getFileNameList(dirPath); | |||
if (TextUtils.isEmpty(dirPath)) | |||
return Collections.emptyList(); | |||
File dir = new File(dirPath); | |||
File[] files = dir.listFiles(fileFilter); | |||
if (files == null) | |||
return Collections.emptyList(); | |||
List<String> conList = new ArrayList<String>(); | |||
for (File file : files) { | |||
if (file.isFile()) | |||
conList.add(file.getName()); | |||
} | |||
return conList; | |||
} | |||
/** | |||
* ��ȡij��Ŀ¼�µ��ļ��� | |||
* @param dirPath Ŀ¼ | |||
* @return ij��Ŀ¼�µ������ļ��� | |||
*/ | |||
public static List<String> getFileNameList(String dirPath) { | |||
if (TextUtils.isEmpty(dirPath)) | |||
return Collections.emptyList(); | |||
File dir = new File(dirPath); | |||
File[] files = dir.listFiles(); | |||
if (files == null) | |||
return Collections.emptyList(); | |||
List<String> conList = new ArrayList<String>(); | |||
for (File file : files) { | |||
if (file.isFile()) | |||
conList.add(file.getName()); | |||
} | |||
return conList; | |||
} | |||
/** | |||
* ��ȡij��Ŀ¼�µ�ָ����չ�����ļ����� | |||
* @param dirPath Ŀ¼ | |||
* @return ij��Ŀ¼�µ������ļ��� | |||
*/ | |||
public static List<String> getFileNameList(String dirPath, | |||
final String extension) { | |||
if (TextUtils.isEmpty(dirPath)) | |||
return Collections.emptyList(); | |||
File dir = new File(dirPath); | |||
File[] files = dir.listFiles(new FilenameFilter() { | |||
@Override | |||
public boolean accept(File dir, String filename) { | |||
if (filename.indexOf("." + extension) > 0) | |||
return true; | |||
return false; | |||
} | |||
}); | |||
if (files == null) | |||
return Collections.emptyList(); | |||
List<String> conList = new ArrayList<String>(); | |||
for (File file : files) { | |||
if (file.isFile()) | |||
conList.add(file.getName()); | |||
} | |||
return conList; | |||
} | |||
/** | |||
* ����ļ�����չ�� | |||
* @param filePath �ļ�·�� | |||
* @return ���û����չ��������"" | |||
*/ | |||
public static String getFileExtension(String filePath) { | |||
if (TextUtils.isEmpty(filePath)) { | |||
return filePath; | |||
} | |||
int extenPosi = filePath.lastIndexOf(FILE_EXTENSION_SEPARATOR); | |||
int filePosi = filePath.lastIndexOf(File.separator); | |||
if (extenPosi == -1) { | |||
return ""; | |||
} | |||
return (filePosi >= extenPosi) ? "" : filePath.substring(extenPosi + 1); | |||
} | |||
/** | |||
* �����ļ� | |||
* @param path �ļ��ľ���·�� | |||
* @return | |||
*/ | |||
public static boolean createFile(String path) { | |||
if (TextUtils.isEmpty(path)) | |||
return false; | |||
return createFile(new File(path)); | |||
} | |||
/** | |||
* �����ļ� | |||
* @param file | |||
* @return �����ɹ�����true | |||
*/ | |||
public static boolean createFile(File file) { | |||
if (file == null || !makeDirs(getFolderName(file.getAbsolutePath()))) | |||
return false; | |||
if (!file.exists()) | |||
try { | |||
return file.createNewFile(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
return false; | |||
} | |||
return false; | |||
} | |||
/** | |||
* ����Ŀ¼�������Ƕ���� | |||
* @param filePath Ŀ¼·�� | |||
* @return ���·��Ϊ��ʱ������false�����Ŀ¼�����ɹ�����true������false | |||
*/ | |||
public static boolean makeDirs(String filePath) { | |||
if (TextUtils.isEmpty(filePath)) { | |||
return false; | |||
} | |||
File folder = new File(filePath); | |||
return (folder.exists() && folder.isDirectory()) ? true : folder | |||
.mkdirs(); | |||
} | |||
/** | |||
* ����Ŀ¼�������Ƕ���� | |||
* @param dir Ŀ¼ | |||
* @return ���Ŀ¼�����ɹ�����true������false | |||
*/ | |||
public static boolean makeDirs(File dir) { | |||
if (dir == null) | |||
return false; | |||
return (dir.exists() && dir.isDirectory()) ? true : dir.mkdirs(); | |||
} | |||
/** | |||
* �ж��ļ��Ƿ���� | |||
* @param filePath �ļ�·�� | |||
* @return ���·��Ϊ�ջ���Ϊ�հ��ַ������ͷ���false������ļ����ڣ������ļ��� | |||
* �ͷ���true����������ļ����߲����ڣ���false | |||
*/ | |||
public static boolean isFileExist(String filePath) { | |||
if (TextUtils.isEmpty(filePath)) { | |||
return false; | |||
} | |||
File file = new File(filePath); | |||
return (file.exists() && file.isFile()); | |||
} | |||
/** | |||
* ��ò�����չ�����ļ����� | |||
* @param filePath �ļ�·�� | |||
* @return | |||
*/ | |||
public static String getFileNameWithoutExtension(String filePath) { | |||
if (TextUtils.isEmpty(filePath)) { | |||
return filePath; | |||
} | |||
int extenPosi = filePath.lastIndexOf(FILE_EXTENSION_SEPARATOR); | |||
int filePosi = filePath.lastIndexOf(File.separator); | |||
if (filePosi == -1) { | |||
return (extenPosi == -1 ? filePath : filePath.substring(0, | |||
extenPosi)); | |||
} | |||
if (extenPosi == -1) { | |||
return filePath.substring(filePosi + 1); | |||
} | |||
return (filePosi < extenPosi ? filePath.substring(filePosi + 1, | |||
extenPosi) : filePath.substring(filePosi + 1)); | |||
} | |||
/** | |||
* ����ļ��� | |||
* @param filePath �ļ�·�� | |||
* @return ���·��Ϊ�ջ�մ�������·��������Ϊ��ʱ�������ļ��� | |||
*/ | |||
public static String getFileName(String filePath) { | |||
if (TextUtils.isEmpty(filePath)) { | |||
return filePath; | |||
} | |||
int filePosi = filePath.lastIndexOf(File.separator); | |||
return (filePosi == -1) ? filePath : filePath.substring(filePosi + 1); | |||
} | |||
/** | |||
* �������Ŀ¼���� | |||
* @param filePath �ļ��ľ���·�� | |||
* @return ���·��Ϊ�ջ�մ�������·��������Ϊ��ʱ�����Ϊ��Ŀ¼������""; | |||
* ������Ǹ�Ŀ¼����������Ŀ¼���ƣ���ʽ�磺C:/Windows/Boot | |||
*/ | |||
public static String getFolderName(String filePath) { | |||
if (TextUtils.isEmpty(filePath)) { | |||
return filePath; | |||
} | |||
int filePosi = filePath.lastIndexOf(File.separator); | |||
return (filePosi == -1) ? "" : filePath.substring(0, filePosi); | |||
} | |||
/** | |||
* �ж�Ŀ¼�Ƿ���� | |||
* @param ¼·�� | |||
* @return ���·��Ϊ�ջ�հ��ַ���������false�����Ŀ¼�����ң�ȷʵ��Ŀ¼�ļ��У� | |||
* ����true����������ļ��л��߲����ڣ���false | |||
*/ | |||
public static boolean isFolderExist(String directoryPath) { | |||
if (TextUtils.isEmpty(directoryPath)) { | |||
return false; | |||
} | |||
File dire = new File(directoryPath); | |||
return (dire.exists() && dire.isDirectory()); | |||
} | |||
/** | |||
* ɾ��ָ���ļ���ָ��Ŀ¼�ڵ������ļ� | |||
* @param path �ļ���Ŀ¼�ľ���·�� | |||
* @return ·��Ϊ�ջ�հ��ַ���������true���ļ������ڣ�����true���ļ�ɾ������true�� | |||
* �ļ�ɾ���쳣����false | |||
*/ | |||
public static boolean deleteFile(String path) { | |||
if (TextUtils.isEmpty(path)) { | |||
return true; | |||
} | |||
return deleteFile(new File(path)); | |||
} | |||
/** | |||
* ɾ��ָ���ļ���ָ��Ŀ¼�ڵ������ļ� | |||
* @param file | |||
* @return ·��Ϊ�ջ�հ��ַ���������true���ļ������ڣ�����true���ļ�ɾ������true�� | |||
* �ļ�ɾ���쳣����false | |||
*/ | |||
public static boolean deleteFile(File file) { | |||
if (file == null) | |||
throw new NullPointerException("file is null"); | |||
if (!file.exists()) { | |||
return true; | |||
} | |||
if (file.isFile()) { | |||
return file.delete(); | |||
} | |||
if (!file.isDirectory()) { | |||
return false; | |||
} | |||
File[] files = file.listFiles(); | |||
if (files == null) | |||
return true; | |||
for (File f : files) { | |||
if (f.isFile()) { | |||
f.delete(); | |||
} else if (f.isDirectory()) { | |||
deleteFile(f.getAbsolutePath()); | |||
} | |||
} | |||
return file.delete(); | |||
} | |||
/** | |||
* ɾ��ָ��Ŀ¼���ض����ļ� | |||
* @param dir | |||
* @param filter | |||
*/ | |||
public static void delete(String dir, FilenameFilter filter) { | |||
if (TextUtils.isEmpty(dir)) | |||
return; | |||
File file = new File(dir); | |||
if (!file.exists()) | |||
return; | |||
if (file.isFile()) | |||
file.delete(); | |||
if (!file.isDirectory()) | |||
return; | |||
File[] lists = null; | |||
if (filter != null) | |||
lists = file.listFiles(filter); | |||
else | |||
lists = file.listFiles(); | |||
if (lists == null) | |||
return; | |||
for (File f : lists) { | |||
if (f.isFile()) { | |||
f.delete(); | |||
} | |||
} | |||
} | |||
/** | |||
* ����ļ����ļ��еĴ�С | |||
* @param path �ļ���Ŀ¼�ľ���·�� | |||
* @return ���ص�ǰĿ¼�Ĵ�С ��ע�����ļ������ڣ�Ϊ�գ�����Ϊ�հ��ַ��������� -1 | |||
*/ | |||
public static long getFileSize(String path) { | |||
if (TextUtils.isEmpty(path)) { | |||
return -1; | |||
} | |||
File file = new File(path); | |||
return (file.exists() && file.isFile() ? file.length() : -1); | |||
} | |||
} |
@@ -18,11 +18,28 @@ import android.util.Log; | |||
import com.bpa.scalage.config.ConfigName; | |||
import com.bpa.scalage.config.MessageName; | |||
import com.bpa.scalage.message.MessageManager; | |||
import com.lzy.okgo.OkGo; | |||
import com.lzy.okgo.callback.StringCallback; | |||
import com.lzy.okgo.model.Response; | |||
public class HttpUtils { | |||
public static int httpGet(final String name,final String urlPath) { | |||
// OkGo.<String>get(urlPath) | |||
// .execute(new StringCallback() { | |||
// @Override | |||
// public void onSuccess(Response<String> response) { | |||
// // 请求成功回调 | |||
// MessageManager.getInstance().sendMessage(name,response.body()); | |||
// } | |||
// | |||
// @Override | |||
// public void onError(Response<String> response) { | |||
// // 请求失败回调 | |||
// } | |||
// }); | |||
String Url=ConfigName.getInstance().SaasAddress+urlPath; | |||
new Thread() { | |||
@Override | |||
@@ -31,7 +48,7 @@ public class HttpUtils { | |||
String content = ""; | |||
// ---------------------请求数据----------------------- | |||
try { | |||
URL url = new URL(urlPath.trim()); | |||
URL url = new URL(Url.trim()); | |||
Log.i("logB", "send url=" + url.toString()); | |||
//打开连接 | |||
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); | |||
@@ -49,9 +66,11 @@ public class HttpUtils { | |||
} else { | |||
} | |||
} catch (MalformedURLException e) { | |||
Log.e("错误", e.getMessage()); | |||
//e.printStackTrace(); | |||
} catch (IOException e) { | |||
//e.printStackTrace(); | |||
Log.e("错误", e.getMessage()); | |||
} | |||
MessageManager.getInstance().sendMessage(name,content); | |||
} | |||
@@ -61,6 +80,8 @@ public class HttpUtils { | |||
public static void httpPost(final String name,final String urlPath,final String content) | |||
{ | |||
String Url=ConfigName.getInstance().SaasAddress+urlPath; | |||
new Thread() | |||
{ | |||
@Override | |||
@@ -69,7 +90,7 @@ public class HttpUtils { | |||
Looper.prepare(); | |||
URL url; | |||
try { | |||
url = new URL(urlPath); | |||
url = new URL(Url); | |||
Log.i("logB","content="+content); | |||
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | |||
conn.setConnectTimeout(10000);//5 | |||
@@ -82,7 +103,6 @@ public class HttpUtils { | |||
conn.setRequestProperty("TenantId", ConfigName.getInstance().Shop_Id);//设置header | |||
OutputStream os = conn.getOutputStream(); | |||
os.write(content.getBytes()); | |||
os.close(); | |||
@@ -1,14 +1,20 @@ | |||
package com.bpa.scalage.helper; | |||
import android.content.Context; | |||
import android.util.Log; | |||
import android.widget.TextView; | |||
import android.widget.Toast; | |||
import com.bpa.scalage.R; | |||
/** | |||
* 自定义打印吐司函数 | |||
*/ | |||
public class T { | |||
public static void show(Context context, String str){ | |||
Toast.makeText(context, str, (int)0).show(); | |||
Toast t= Toast.makeText(context, str, (int)0); | |||
TextView tv = (TextView) t.getView().findViewById(android.R.id.message); | |||
tv.setTextSize(50); | |||
t.show(); | |||
Log.i(context.getPackageName(),str); | |||
} | |||
} |
@@ -4,6 +4,7 @@ import android.os.ParcelUuid; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.EditText; | |||
import android.widget.Spinner; | |||
import android.widget.SpinnerAdapter; | |||
@@ -16,6 +17,10 @@ import com.bpa.scalage.app.Main; | |||
import com.bpa.scalage.config.ConfigName; | |||
import com.bpa.scalage.helper.T; | |||
import java.util.ArrayList; | |||
import java.util.LinkedHashMap; | |||
import java.util.Map; | |||
/** | |||
* 其他页面 | |||
*/ | |||
@@ -31,15 +36,17 @@ public class ParameterSetFragment extends Fragment { | |||
//region 界面变量 | |||
//店铺信息 | |||
private EditText Shop_Name,AutKey,Shop_DeviceId,SaasAddress; | |||
private EditText Shop_Name,AutKey,Shop_DeviceId; | |||
//菜品放置区 | |||
private Spinner Dishes_Com_Name,Dishes_Com_Port; | |||
private Spinner Dishes_Com_Name,Dishes_Com_Port,environment; | |||
//菜品放置区 | |||
private Spinner Plate_Com_Name,Plate_Com_Port,Plate_Com_Format; | |||
//当前界面 | |||
private View MainView; | |||
//保存按钮 | |||
private TextView Save; | |||
Map<String, Integer> material_map = new LinkedHashMap<>(); | |||
//endregion | |||
//region 界面函数 | |||
@@ -48,16 +55,24 @@ public class ParameterSetFragment extends Fragment { | |||
*/ | |||
public void Init() | |||
{ | |||
material_map.put("开发环境", 0); | |||
material_map.put("测试环境", 1); | |||
material_map.put("正式环境", 2); | |||
Shop_Name=MainView.findViewById(R.id.tv_dp_name); | |||
AutKey=MainView.findViewById(R.id.tv_dp_id); | |||
Shop_DeviceId=MainView.findViewById(R.id.tv_dp_devid); | |||
SaasAddress=MainView.findViewById(R.id.tv_cp_url); | |||
environment=MainView.findViewById(R.id.environment); | |||
Dishes_Com_Name=MainView.findViewById(R.id.tv_cp_com); | |||
Dishes_Com_Port=MainView.findViewById(R.id.tv_cp_port); | |||
Plate_Com_Name=MainView.findViewById(R.id.tv_cpgy_com); | |||
Plate_Com_Port=MainView.findViewById(R.id.tv_cpgy_port); | |||
Plate_Com_Format=MainView.findViewById(R.id.tv_cpgy_jy); | |||
Save=MainView.findViewById(R.id.parameter_save); | |||
SetShowText(); | |||
Save.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
@@ -75,7 +90,13 @@ public class ParameterSetFragment extends Fragment { | |||
Shop_Name.setText(ConfigName.getInstance().Shop_Name); | |||
AutKey.setText(ConfigName.getInstance().AutKey); | |||
Shop_DeviceId.setText(ConfigName.getInstance().Shop_DeviceId); | |||
SaasAddress.setText(ConfigName.getInstance().SaasAddress); | |||
ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_text_item, new ArrayList<>(material_map.keySet())); | |||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item); | |||
environment.setAdapter(adapter); | |||
SelectText(environment,ConfigName.getInstance().Environment); | |||
SelectText(Dishes_Com_Name,ConfigName.getInstance().Dishes_Com_Name); | |||
SelectText(Dishes_Com_Port, Integer.toString(ConfigName.getInstance().Dishes_Com_Port)); | |||
SelectText(Plate_Com_Name,ConfigName.getInstance().Plate_Com_Name); | |||
@@ -103,11 +124,7 @@ public class ParameterSetFragment extends Fragment { | |||
T.show(MainView.getContext(),"设备ID不能为空!"); | |||
return; | |||
} | |||
if (SaasAddress.getText().toString().isEmpty()) | |||
{ | |||
T.show(MainView.getContext(),"Sass地址不能为空!"); | |||
return; | |||
} | |||
if (Dishes_Com_Name.getSelectedItem().toString().isEmpty()) | |||
{ | |||
T.show(MainView.getContext(),"菜品放置区串口号不能为空!"); | |||
@@ -133,10 +150,10 @@ public class ParameterSetFragment extends Fragment { | |||
T.show(MainView.getContext(),"餐盘感应区域数据位、校验位、停止位不能为空!"); | |||
return; | |||
} | |||
ConfigName.getInstance().Environment = environment.getSelectedItem().toString(); | |||
ConfigName.getInstance().Shop_Name=Shop_Name.getText().toString(); | |||
ConfigName.getInstance().AutKey=AutKey.getText().toString(); | |||
ConfigName.getInstance().Shop_DeviceId=Shop_DeviceId.getText().toString(); | |||
ConfigName.getInstance().SaasAddress=SaasAddress.getText().toString(); | |||
ConfigName.getInstance().Dishes_Com_Name=Dishes_Com_Name.getSelectedItem().toString(); | |||
ConfigName.getInstance().Dishes_Com_Port=Integer.valueOf(Dishes_Com_Port.getSelectedItem().toString()).intValue(); | |||
ConfigName.getInstance().Plate_Com_Name=Plate_Com_Name.getSelectedItem().toString(); | |||
@@ -1,34 +1,28 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > | |||
<!-- 第一组item:设置边框 --> | |||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | |||
<!-- 第一组item:设置Spinner背景边框 --> | |||
<item> | |||
<shape> | |||
<!-- 设置边框线宽度和颜色 --> | |||
<stroke | |||
android:width="0.5dp" | |||
android:color="#000000" > | |||
android:width="1dp" | |||
android:color="#B0B0B0"> | |||
</stroke> | |||
<!-- 设置圆角度数 --> | |||
<corners android:radius="5dp" /> | |||
<corners android:radius="0dp" /> | |||
<!-- 设置背景颜色 --> | |||
<solid android:color="#8A8C8A" /> | |||
<!-- padding:设置边距 --> | |||
<!-- <padding--> | |||
<!-- android:bottom="5dp"--> | |||
<!-- android:left="5dp"--> | |||
<!-- android:right="5dp"--> | |||
<!-- android:top="5dp" >--> | |||
<!-- </padding>--> | |||
<padding | |||
android:bottom="0dp" | |||
android:left="30dp" | |||
android:right="5dp" | |||
android:top="0dp" > | |||
</padding> | |||
</shape> | |||
<!-- 第二组item:设置spinner箭头图片 --> | |||
</item> | |||
<item> | |||
<bitmap | |||
android:gravity="end" | |||
android:src="@mipmap/spinner_down_2"> | |||
</bitmap> | |||
<!-- 第二组item:设置spinner箭头图片(替换默认箭头) --> | |||
<!-- <item>--> | |||
<!-- <!– bitmap.gravity:设置spinner的箭头放置位置 –>--> | |||
<!-- <!– bitmap.src:设置替换原spinner的箭头的图片资源 –>--> | |||
<!-- <bitmap--> | |||
<!-- android:gravity="end"--> | |||
<!-- android:src="@mipmap/drop_down">--> | |||
<!-- </bitmap>--> | |||
<!-- </item>--> | |||
</item> | |||
</layer-list> |
@@ -49,7 +49,7 @@ | |||
android:layout_width="0dp" | |||
android:layout_height="match_parent" | |||
android:scrollbars="none" | |||
android:layout_weight="0.5" | |||
android:layout_weight="0.8" | |||
android:background="#f4f4f4"> | |||
</ListView> | |||
<View | |||
@@ -2,12 +2,12 @@ | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:minHeight="60dp" | |||
android:minHeight="80dp" | |||
android:gravity="center" | |||
android:orientation="vertical" > | |||
<TextView | |||
android:id="@+id/tv_zcd" | |||
android:layout_width="wrap_content" | |||
android:layout_height="match_parent" | |||
android:textSize="@dimen/submit_text_size"/> | |||
android:textSize="28dp"/> | |||
</LinearLayout> |
@@ -0,0 +1,12 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:id="@+id/checkedTextViewCustom_1" | |||
style="?android:attr/spinnerDropDownItemStyle" | |||
android:layout_width="match_parent" | |||
android:layout_height="35dp" | |||
android:background="#D8D8D8" | |||
android:ellipsize="marquee" | |||
android:singleLine="true" | |||
android:text="11111" | |||
android:textAlignment="inherit" | |||
android:textSize="19dp"/> |
@@ -0,0 +1,17 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:id="@+id/textViewCustom" | |||
style="?android:attr/spinnerItemStyle" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:ellipsize="marquee" | |||
android:singleLine="true" | |||
android:textAlignment="inherit" | |||
android:gravity="center_vertical" | |||
android:text="请选择" | |||
android:textSize="19dp" | |||
android:textColor="@color/black"> | |||
</TextView> | |||
@@ -113,19 +113,24 @@ | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="后台地址:" | |||
android:text="连接环境:" | |||
android:textColor="#000" | |||
android:textSize="@dimen/text_size" /> | |||
<EditText | |||
android:id="@+id/tv_cp_url" | |||
<!-- <EditText--> | |||
<!-- android:id="@+id/tv_cp_url"--> | |||
<!-- android:layout_width="440dp"--> | |||
<!-- android:layout_height="40dp"--> | |||
<!-- android:hint="请输入经营管理系统地址"--> | |||
<!-- android:singleLine="true"--> | |||
<!-- android:textSize="@dimen/text_size" />--> | |||
<Spinner | |||
android:id="@+id/environment" | |||
android:layout_width="440dp" | |||
android:layout_height="40dp" | |||
android:hint="请输入经营管理系统地址" | |||
android:singleLine="true" | |||
android:layout_height="wrap_content" | |||
android:entries="@array/com" | |||
android:spinnerMode="dropdown" | |||
android:textSize="@dimen/text_size" /> | |||
</LinearLayout> | |||
<!--称重区域连接端口配置 --> | |||
@@ -13,6 +13,19 @@ | |||
<item name="android:windowFullscreen">true</item> | |||
</style> | |||
<style name="commonSpinnerStyle" parent="Widget.AppCompat.Spinner"> | |||
<item name="android:background">@drawable/spinner_border</item> | |||
<!-- <item name="android:popupBackground">@color/main_background</item>--> | |||
<item name="android:dropDownVerticalOffset">30dp</item> | |||
<item name="android:paddingLeft">0dp</item> | |||
<item name="android:paddingRight">4dp</item> | |||
<item name="android:paddingTop">0dp</item> | |||
<item name="android:paddingBottom">0dp</item> | |||
<item name="android:layout_height">26dp</item> | |||
<item name="android:layout_marginLeft">5dp</item> | |||
<item name="android:textColor">@color/black</item> | |||
</style> | |||
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar"> | |||
<item name="android:background">@color/black_overlay</item> | |||
</style> | |||
@@ -7,7 +7,7 @@ buildscript { | |||
} | |||
dependencies { | |||
classpath 'com.android.tools.build:gradle:3.5.2' | |||
classpath 'com.android.tools.build:gradle:7.0.0' | |||
// NOTE: Do not place your application dependencies here; they belong | |||
// in the individual module build.gradle files | |||
} | |||
@@ -1,6 +1,6 @@ | |||
#Mon Feb 13 15:26:21 CST 2023 | |||
#Thu Sep 14 11:43:52 CST 2023 | |||
distributionBase=GRADLE_USER_HOME | |||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip | |||
distributionPath=wrapper/dists | |||
zipStoreBase=GRADLE_USER_HOME | |||
zipStorePath=wrapper/dists | |||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip | |||
zipStoreBase=GRADLE_USER_HOME |