@@ -25,6 +25,10 @@ android { | |||
resValue("bool","superAdminTest","true") | |||
} | |||
} | |||
compileOptions { | |||
sourceCompatibility JavaVersion.VERSION_1_8 | |||
targetCompatibility JavaVersion.VERSION_1_8 | |||
} | |||
} | |||
dependencies { | |||
@@ -88,4 +92,14 @@ dependencies { | |||
debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.3' | |||
implementation files('libs/commons-codec-1.6.jar') | |||
//MQTT | |||
implementation files('libs\\org.eclipse.paho.android.service-1.1.1.jar') | |||
implementation files('libs\\org.eclipse.paho.client.mqttv3-1.2.5.jar') | |||
//Modbus | |||
// implementation 'com.github.licheedev:Modbus4Android:2.0.2' | |||
// //下载进度条 | |||
// implementation 'com.github.Ccapton:Android-ColorfulProgressBar:1.0.5' | |||
} |
@@ -8,12 +8,15 @@ | |||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 写存储的权限 --> | |||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- 读存储的权限 --> | |||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <!-- 0未知来源的应用权限,更新App --> | |||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <!-- 在SDCard中创建与删除文件权限 --> | |||
<!-- <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <!– 在SDCard中创建与删除文件权限 –>--> | |||
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" /> <!-- DownloadManager --> | |||
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <!-- 录音权限 --> | |||
<uses-permission android:name="android.permission.RECORD_VIDEO" /> <!-- 录像权限 --> | |||
<uses-permission android:name="android.permission.CAMERA" /> | |||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/><!-- 开电自启 --> | |||
<application | |||
android:name=".MainApplication" | |||
android:allowBackup="true" | |||
@@ -24,10 +27,12 @@ | |||
android:supportsRtl="true" | |||
android:theme="@style/AppTheme" | |||
tools:ignore="GoogleAppIndexingWarning" | |||
tools:node="merge"> | |||
tools:node="merge" | |||
android:largeHeap="true" | |||
android:hardwareAccelerated="false"> | |||
<activity | |||
android:name=".modules.home.fragment.from.SzActivity" | |||
android:exported="false" /> | |||
android:exported="false"/> | |||
<activity | |||
android:name=".modules.home.fragment.from.WhActivity" | |||
android:exported="false" /> | |||
@@ -81,6 +86,25 @@ | |||
</activity> | |||
<activity android:name=".modules.home.activity.BottomNavigation2Activity" /> | |||
<activity android:name=".modules.home.activity.BottomNavigationActivity" /> | |||
<service android:name="org.eclipse.paho.android.service.MqttService" /> | |||
<receiver android:name=".common.base.BootReceiver" | |||
android:exported="true"> | |||
<intent-filter> | |||
<action android:name="android.intent.action.BOOT_COMPLETED" /> | |||
<category android:name="android.intent.category.LAUNCHER" /> | |||
</intent-filter> | |||
</receiver> | |||
<!-- <provider--> | |||
<!-- android:name="androidx.core.content.FileProvider"--> | |||
<!-- android:authorities="${applicationId}.fileprovider"--> | |||
<!-- android:exported="false"--> | |||
<!-- android:grantUriPermissions="true">--> | |||
<!-- <meta-data--> | |||
<!-- android:name="android.support.FILE_PROVIDER_PATHS"--> | |||
<!-- android:resource="@xml/fileproviderpath" />--> | |||
<!-- </provider>--> | |||
</application> | |||
</manifest> |
@@ -44,7 +44,17 @@ public class MainApplication extends Application { | |||
public void onCreate() { | |||
super.onCreate(); | |||
context = getApplicationContext(); | |||
//0.全局异常捕获,保存为SD卡本级目录 crash | |||
// CrashHandler.getInstance().init(this); | |||
// | |||
// //1.设置程序active,初始化Main函数进程,初始化消息日志 | |||
// InitMsgLog();ConfigName.getInstance().dishesCon = this; | |||
// | |||
// //2.初始化SD卡,数据库DB | |||
// SdCart.getInstance().initSD(); | |||
// | |||
// //4.初始化Main | |||
// ConfigData.getInstance(); | |||
// activity生命周期管理 | |||
ActivityLifecycleManager.get().init(this); | |||
@@ -0,0 +1,274 @@ | |||
package com.bonait.bnframework.business; | |||
import android.util.Log; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.constant.MessageName; | |||
import com.bonait.bnframework.common.db.QueryDB; | |||
import com.bonait.bnframework.common.db.mode.BPA_SYSTEMSET; | |||
import com.bonait.bnframework.common.helper.ConfigUtil; | |||
import com.bonait.bnframework.common.helper.HttpUtils; | |||
import com.bonait.bnframework.common.helper.Json; | |||
import com.bonait.bnframework.common.helper.mode.OrderStatusChange; | |||
import com.bonait.bnframework.common.helper.mode.VersionMode; | |||
import java.util.ArrayList; | |||
/** | |||
* 主函数进程 | |||
* 主要进行配置文件-系统类 | |||
*/ | |||
public class ConfigData { | |||
//region 私有 | |||
private static ConfigData mInstance; //实例变量设置私有,防止直接通过类名访问 | |||
public static synchronized ConfigData getInstance() { //静态同步方法作为唯一的实例对象获取方式 | |||
if (mInstance == null) { | |||
mInstance = new ConfigData(); | |||
} | |||
return mInstance; | |||
} | |||
private ConfigData() { //默认构造函数私有,防止类外直接new创建对象 | |||
Init(); | |||
} | |||
//endregion | |||
//region 外部调用事件 | |||
/** | |||
* 初始化 | |||
*/ | |||
public void Init() { | |||
//1.加载系统设置 | |||
LoadSystem(); | |||
ToggleEnvironment(); | |||
//2.加载配置 | |||
LoadingDPPZ(); | |||
LoadingPZ(); | |||
//3.初始化业务 | |||
//4.初始化日志上报adad | |||
} | |||
/** | |||
* 加载系统配置 | |||
*/ | |||
public void LoadSystem() | |||
{ | |||
ArrayList<BPA_SYSTEMSET> bpa_systemsets= QueryDB.GetSystemsetALL(); | |||
for (int i = 0; i <12;i++){ | |||
int ty=i+1; | |||
BPA_SYSTEMSET set=new BPA_SYSTEMSET(); | |||
set.type=ty; | |||
switch (ty) | |||
{ | |||
case 1: | |||
set.value=String.valueOf(ConfigName.getInstance().OrderPushTime); | |||
break; | |||
case 2: | |||
set.value=String.valueOf(ConfigName.getInstance().SilosValuePushTime); | |||
break; | |||
case 3: | |||
set.value=String.valueOf(ConfigName.getInstance().OtherValuePushTime); | |||
break; | |||
case 4: | |||
set.value=String.valueOf(ConfigName.getInstance().PipeDrainCycleTime); | |||
break; | |||
case 5: | |||
set.value=String.valueOf(ConfigName.getInstance().OrderTimeout); | |||
break; | |||
case 6: | |||
set.value=String.valueOf(ConfigName.getInstance().SiloFeedThreshold); | |||
break; | |||
case 7: | |||
set.value=String.valueOf(ConfigName.getInstance().SiloAlarmThreshold); | |||
break; | |||
case 8: | |||
set.value=String.valueOf(ConfigName.getInstance().AICleanTime); | |||
break; | |||
case 9: | |||
set.value=ConfigName.getInstance().AutKey; | |||
break; | |||
case 10: | |||
set.value=ConfigName.getInstance().Address; | |||
break; | |||
case 11: | |||
set.value=String.valueOf(ConfigName.getInstance().Post); | |||
break; | |||
case 12: | |||
set.value=ConfigName.getInstance().Environment; | |||
break; | |||
} | |||
set.deviceID = ConfigName.getInstance().DeviceId; | |||
set.userID = ConfigName.getInstance().user.userID; | |||
BPA_SYSTEMSET find=null; | |||
for (BPA_SYSTEMSET item:bpa_systemsets) | |||
{ | |||
if(item.type==ty) | |||
{ | |||
find=item; | |||
break; | |||
} | |||
} | |||
if(find==null) | |||
{ | |||
QueryDB.AddSystemset(set); | |||
} | |||
} | |||
for (BPA_SYSTEMSET item:bpa_systemsets) | |||
{ | |||
switch (item.type) | |||
{ | |||
case 1: | |||
ConfigName.getInstance().OrderPushTime=Integer.parseInt(item.value); | |||
break; | |||
case 2: | |||
ConfigName.getInstance().SilosValuePushTime=Integer.parseInt(item.value); | |||
break; | |||
case 3: | |||
ConfigName.getInstance().OtherValuePushTime=Integer.parseInt(item.value); | |||
break; | |||
case 4: | |||
ConfigName.getInstance().PipeDrainCycleTime=Integer.parseInt(item.value); | |||
break; | |||
case 5: | |||
ConfigName.getInstance().OrderTimeout=Integer.parseInt(item.value); | |||
break; | |||
case 6: | |||
ConfigName.getInstance().SiloFeedThreshold=Integer.parseInt(item.value); | |||
break; | |||
case 7: | |||
ConfigName.getInstance().SiloAlarmThreshold=Integer.parseInt(item.value); | |||
break; | |||
case 8: | |||
ConfigName.getInstance().AICleanTime=Integer.parseInt(item.value); | |||
break; | |||
case 9: | |||
ConfigName.getInstance().AutKey=item.value; | |||
break; | |||
case 10: | |||
ConfigName.getInstance().Address=item.value; | |||
break; | |||
case 11: | |||
ConfigName.getInstance().Post=Integer.parseInt(item.value); | |||
break; | |||
case 12: | |||
ConfigName.getInstance().Environment=item.value; | |||
break; | |||
} | |||
} | |||
} | |||
/** | |||
* 切换环境 | |||
*/ | |||
public void ToggleEnvironment() | |||
{ | |||
if(ConfigName.getInstance().Environment.equals("开发环境")) | |||
{ | |||
ConfigName.getInstance().SaasAddress="https://bpa.black-pa.com:21527/"; | |||
ConfigName.getInstance().mqtt_userName="emqx_u_block"; | |||
ConfigName.getInstance().mqtt_passWord="emqx_p_admin8765490789"; | |||
ConfigName.getInstance().mqtt_ip="10.2.1.21"; | |||
ConfigName.getInstance().mqtt_post=1883; | |||
}else if(ConfigName.getInstance().Environment.equals("测试环境")) | |||
{ | |||
ConfigName.getInstance().SaasAddress="https://bpa.black-pa.com:21528/"; | |||
ConfigName.getInstance().mqtt_userName="emqx_u_block"; | |||
ConfigName.getInstance().mqtt_passWord="emqx_p_admin8456765490789"; | |||
ConfigName.getInstance().mqtt_ip="111.9.47.105"; | |||
ConfigName.getInstance().mqtt_post=18889; | |||
}else if(ConfigName.getInstance().Environment.equals("正式环境")) | |||
{ | |||
ConfigName.getInstance().SaasAddress="https://witt.black-pa.com/"; | |||
ConfigName.getInstance().mqtt_userName="emqx_u_block"; | |||
ConfigName.getInstance().mqtt_passWord="emqx_p_admin3658765490789"; | |||
ConfigName.getInstance().mqtt_ip="47.108.65.220"; | |||
ConfigName.getInstance().mqtt_post=1883; | |||
} | |||
} | |||
/** | |||
* 加载店铺配置 | |||
*/ | |||
public void LoadingDPPZ() { | |||
//ConfigName.getInstance().AutKey | |||
ConfigName.getInstance().Shop_Name="黑菠萝奶茶机"; | |||
ConfigName.getInstance().DeviceId="20020415-test"; | |||
} | |||
/** | |||
* 加载配置 | |||
*/ | |||
public void LoadingPZ() { | |||
//1.店铺配置 | |||
// ConfigName.getInstance().Shop_Name = ConfigUtil.read(ConfigName.getInstance().dishesCon, "Shop_Name", ConfigName.getInstance().Shop_Name); | |||
// ConfigName.getInstance().AutKey = ConfigUtil.read(ConfigName.getInstance().dishesCon, "AutKey", ConfigName.getInstance().AutKey); | |||
//2.用户名称 | |||
ConfigName.getInstance().user.account = ConfigUtil.read(ConfigName.getInstance().dishesCon, "username", ConfigName.getInstance().user.account); | |||
ConfigName.getInstance().user.pass = ConfigUtil.read(ConfigName.getInstance().dishesCon, "password", ConfigName.getInstance().user.pass); | |||
ConfigName.getInstance().IsUserDownOrder = ConfigUtil.read(ConfigName.getInstance().dishesCon, "IsUserDownOrder", ConfigName.getInstance().IsUserDownOrder); | |||
ConfigName.getInstance().Version = ConfigUtil.read(ConfigName.getInstance().dishesCon, "Version", ConfigName.getInstance().Version); | |||
} | |||
/** | |||
* 保存配置 | |||
*/ | |||
public void SavePZ() | |||
{ | |||
//1.店铺配置 | |||
// ConfigUtil.write(ConfigName.getInstance().dishesCon,"Shop_Name", ConfigName.getInstance().Shop_Name); | |||
// ConfigUtil.write(ConfigName.getInstance().dishesCon,"AutKey", ConfigName.getInstance().AutKey); | |||
//2.用户信息 | |||
ConfigUtil.write(ConfigName.getInstance().dishesCon,"username", ConfigName.getInstance().user.account); | |||
ConfigUtil.write(ConfigName.getInstance().dishesCon,"password", ConfigName.getInstance().user.pass); | |||
ConfigUtil.write(ConfigName.getInstance().dishesCon,"IsUserDownOrder", ConfigName.getInstance().IsUserDownOrder); | |||
ConfigUtil.write(ConfigName.getInstance().dishesCon,"IsUserDownOrder", ConfigName.getInstance().IsUserDownOrder); | |||
ConfigUtil.write(ConfigName.getInstance().dishesCon,"Version", ConfigName.getInstance().Version); | |||
} | |||
/** | |||
* 获取订单信息 | |||
*/ | |||
public void GetOrder(String orderNumber) | |||
{ | |||
//https://bpa.black-pa.com:21527/order/order/fullorderbynumber/202305111151562071 | |||
// orderNumber="454228787056480256"; | |||
//202202211310398967 | |||
//String api="https://bpa.black-pa.com:21528/kitchen/api/member-helper/memberinfobywechat/987654321"; | |||
Log.i("查询用户接口", ConfigName.getInstance().SaasAddress+ConfigName.getInstance().GetOrder+orderNumber); | |||
HttpUtils.httpGet(MessageName.GetOrderInformation,ConfigName.getInstance().SaasAddress+ConfigName.getInstance().GetOrder+orderNumber); | |||
} | |||
public void SetOrderChanged(OrderStatusChange data) | |||
{ | |||
//Authorize | |||
// new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());; | |||
// String header = ConfigName.getInstance().SaasAddress+ConfigName.getInstance().OrderChange+"_["+ Date..Ticks+"]"; | |||
// header=AES.encrypt(header); | |||
//密码加密 | |||
//String pwdAES = AESCBCUtils.encrypt_AES(AESKey, loginPassword.getText().toString(), AESIv); | |||
String msg= new Json<OrderStatusChange>().objectToJson(OrderStatusChange.class, data); | |||
HttpUtils.httpPost(MessageName.UpdateOrderStatus,ConfigName.getInstance().SaasAddress+ConfigName.getInstance().OrderChange,msg); | |||
} | |||
/** | |||
* 更新版本 | |||
*/ | |||
public void UpdateVersion() | |||
{ | |||
VersionMode mode=new VersionMode(); | |||
mode.productCode="1668085292913659904"; | |||
mode.moduleCode="naichaji"; | |||
mode.serverCode="1668175205545807872"; | |||
mode.branchCode="1668801915890962433"; | |||
String msg= new Json<VersionMode>().objectToJson(VersionMode.class, mode); | |||
HttpUtils.httpPost(MessageName.UpdateVersion,ConfigName.getInstance().UpdateVersion,msg); | |||
} | |||
//endregion | |||
} | |||
@@ -0,0 +1,15 @@ | |||
package com.bonait.bnframework.common.base; | |||
import android.content.BroadcastReceiver; | |||
import android.content.Context; | |||
import android.content.Intent; | |||
public class BootReceiver extends BroadcastReceiver { | |||
@Override | |||
public void onReceive(Context context, Intent intent) { | |||
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { | |||
Intent toIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); | |||
context.startActivity(toIntent); | |||
} | |||
} | |||
} |
@@ -0,0 +1,182 @@ | |||
package com.bonait.bnframework.common.constant; | |||
import android.content.Context; | |||
import com.bonait.bnframework.common.db.mode.BPA_USER; | |||
/** | |||
* 配置文件 | |||
*/ | |||
public class ConfigName { | |||
//region 单例模式 | |||
private static ConfigName mInstance; //实例变量设置私有,防止直接通过类名访问 | |||
private ConfigName() { //默认构造函数私有,防止类外直接new创建对象 | |||
} | |||
public static synchronized ConfigName getInstance() { //静态同步方法作为唯一的实例对象获取方式 | |||
if (mInstance==null) { | |||
mInstance = new ConfigName(); | |||
} | |||
return mInstance; | |||
} | |||
//endregion | |||
//region 程序进入界面 | |||
public Context dishesCon; | |||
public Context Home; | |||
//endregion | |||
//region SD卡路径设置 | |||
/** | |||
* SD卡路径 | |||
*/ | |||
public String sdCardPath; | |||
/** | |||
* 应用程序 Res 根路径 | |||
*/ | |||
public String appResRoot; | |||
/** | |||
* Db文件路径 | |||
*/ | |||
public static String dbPath = ""; | |||
//endregion | |||
//region 店铺配置 | |||
/** | |||
* 店铺名称 | |||
*/ | |||
public String Shop_Name="黑菠萝奶茶机"; | |||
/** | |||
* 店铺设备号 | |||
*/ | |||
public String AutKey="152.146"; | |||
public String ClientId="152"; | |||
public String DevId="146"; | |||
/** | |||
* 店铺设备号 | |||
*/ | |||
public String DeviceId="20020415-test"; | |||
//endregion | |||
//region MQTT配置中心 | |||
/** | |||
* 用户名 | |||
*/ | |||
public String mqtt_userName="emqx_u_block"; | |||
/** | |||
* 密码 | |||
*/ | |||
public String mqtt_passWord="emqx_p_admin8765490789"; | |||
/** | |||
* ip地址 | |||
*/ | |||
public String mqtt_ip="10.2.1.21"; | |||
/** | |||
* post端口 | |||
*/ | |||
public int mqtt_post=1883; | |||
/** | |||
* 订阅主题 | |||
*/ | |||
public String mqtt_topic="DOWN/MORKT/BUSINESS/"; | |||
public String mqtt_hearttopic="UP/MORKT/HEARTBEAT"; | |||
//endregion | |||
//region 环境配置 | |||
/** | |||
* 环境配置 | |||
*/ | |||
public String Environment="开发环境"; | |||
//endregion | |||
//region 登录信息 | |||
/** | |||
* 用户信息 | |||
*/ | |||
public BPA_USER user=new BPA_USER(); | |||
//endregion | |||
//region 版本信息 | |||
/** | |||
* 版本更新 | |||
*/ | |||
public String Version="1.0"; | |||
//endregion | |||
//region 是否手动下单 | |||
/** | |||
* 是否手动下单 | |||
*/ | |||
public Boolean IsUserDownOrder=false; | |||
//endregion | |||
//region 系统设置表 | |||
/** | |||
* 订单上报周期,默认一小时 *60 | |||
*/ | |||
public int OrderPushTime=3600; | |||
/** | |||
* 料仓余量上报周期,默认10分钟 *60 | |||
*/ | |||
public int SilosValuePushTime=600; | |||
/** | |||
* 其他传感器上报周期,默认10分钟 *60 | |||
*/ | |||
public int OtherValuePushTime=600; | |||
/** | |||
* 管道排空周期,默认一小时 *60 | |||
*/ | |||
public int PipeDrainCycleTime=3600; | |||
/** | |||
* 订单未制作超时规则,默认20分钟 *60 | |||
*/ | |||
public int OrderTimeout=1200; | |||
/** | |||
* 料仓补料阈值,500g | |||
*/ | |||
public int SiloFeedThreshold=500; | |||
/** | |||
* 料仓告警阈值,50g | |||
*/ | |||
public int SiloAlarmThreshold=50; | |||
/** | |||
* 自动清洗时间,默认一小时 *60 | |||
*/ | |||
public int AICleanTime=3600; | |||
//endregion | |||
//region PlC连接参数 | |||
/** | |||
* Plc地址 | |||
*/ | |||
public String Address="192.168.1.100"; | |||
/** | |||
* Plc端口 | |||
*/ | |||
public int Post=502; | |||
//endregion | |||
/** | |||
* 是否单杯制作 | |||
*/ | |||
public boolean IsSingleCupMake=true; | |||
/** | |||
* 是否测试 | |||
*/ | |||
public boolean IsTest=true; | |||
//region URL | |||
//Sass地址 | |||
public String SaasAddress="http://order.test1.com"; | |||
//public String SaasAddress="https://bpa.black-pa.com:21527"; | |||
//public String SaasAddress="https://witt.black-pa.com"; | |||
//获取订单详情接口 Get | |||
public String GetOrder="order/order/fullorderbynumber/"; | |||
//POST | |||
public String OrderChange="order/order/robotstatuschange"; | |||
public String UpdateVersion="http://111.9.47.105:18097/api/Version/GetLatest"; | |||
//endregion | |||
} |
@@ -0,0 +1,117 @@ | |||
package com.bonait.bnframework.common.constant; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.common.db.QueryDB; | |||
import com.bonait.bnframework.common.db.mode.BPA_ALERTLOG; | |||
import com.bonait.bnframework.common.db.mode.BPA_GOODS; | |||
import com.bonait.bnframework.common.db.mode.BPA_LOG; | |||
import com.bonait.bnframework.common.db.mode.BPA_SILOS; | |||
import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; | |||
import com.bonait.bnframework.common.db.res.MakeStatus; | |||
import com.bonait.bnframework.common.db.res.ResGoodsMake; | |||
import com.bonait.bnframework.common.db.res.ResGoodsRecipe; | |||
import com.bonait.bnframework.common.db.res.StatusMode; | |||
import com.bonait.bnframework.common.helper.mode.OrderA; | |||
import com.bonait.bnframework.common.helper.mode.ResultA; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* 单例模式 | |||
* 数据中心 | |||
*/ | |||
public class DataBus { | |||
//region 单例模式 | |||
private static DataBus mInstance; //实例变量设置私有,防止直接通过类名访问 | |||
private DataBus() { | |||
//默认构造函数私有,防止类外直接new创建对象 | |||
} | |||
public static synchronized DataBus getInstance() { //静态同步方法作为唯一的实例对象获取方式 | |||
if (mInstance==null) { | |||
mInstance = new DataBus(); | |||
} | |||
return mInstance; | |||
} | |||
//endregion | |||
//region 连接状态 | |||
/** | |||
* Plc是否连接 | |||
*/ | |||
public boolean PlcIsConnect=false; | |||
//endregion | |||
//region 数据中心 | |||
/** | |||
* 商品扫码等待制作列表 | |||
*/ | |||
public List<ResGoodsMake> GoodsSMMake = new ArrayList<ResGoodsMake>(); | |||
/** | |||
* 扫码商品订单制作 | |||
*/ | |||
//public order_adapter orderadapter; | |||
/** | |||
* 商品制作列表 | |||
*/ | |||
public List<ResGoodsMake> GoodsMake = new ArrayList<ResGoodsMake>(); | |||
/** | |||
* 商品制作完成列表 | |||
*/ | |||
public List<ResGoodsMake> GoodsMakeOver = new ArrayList<ResGoodsMake>(); | |||
/** | |||
* 商品制作 | |||
*/ | |||
//public makegood_adapter goodmakeadapter; | |||
/** | |||
* 获取是否可以下单 | |||
*/ | |||
public boolean GetIsPlaceAnOrder() | |||
{ | |||
try | |||
{ | |||
if(GoodsMake.size()<=0) | |||
{ | |||
return true; | |||
}else | |||
{ | |||
boolean issucess=true; | |||
for (ResGoodsMake item:GoodsMake) | |||
{ | |||
if(item.makeStatus!= MakeStatus.制作完成) | |||
{ | |||
issucess=false; | |||
} | |||
} | |||
return issucess; | |||
} | |||
}catch(Exception e){ | |||
return true; | |||
} | |||
} | |||
/** | |||
* 员工操作日志 | |||
*/ | |||
public List<BPA_LOG> bpa_logs = new ArrayList<BPA_LOG>(); | |||
/** | |||
* 订单操作日志 | |||
*/ | |||
public List<BPA_ALERTLOG> bpa_alertlogs = new ArrayList<BPA_ALERTLOG>(); | |||
/** | |||
* 设备状态列表 | |||
*/ | |||
public List<StatusMode> statusModes = new ArrayList<StatusMode>(); | |||
/** | |||
* 扫码订单 | |||
*/ | |||
public OrderA OrderSM = new OrderA(); | |||
//endregion | |||
} |
@@ -0,0 +1,9 @@ | |||
package com.bonait.bnframework.common.db.EnumMode; | |||
/** | |||
* 状态枚举 | |||
*/ | |||
public enum StatusEnum { | |||
stop, | |||
start | |||
} |
@@ -0,0 +1,222 @@ | |||
package com.bonait.bnframework.common.db.file; | |||
import android.content.Context; | |||
import android.database.sqlite.SQLiteDatabase; | |||
import android.database.sqlite.SQLiteOpenHelper; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; | |||
import com.bonait.bnframework.common.db.mode.BPA_ALERTLOG; | |||
import com.bonait.bnframework.common.db.mode.BPA_CRAFT; | |||
import com.bonait.bnframework.common.db.mode.BPA_CRAFTPROCESS; | |||
import com.bonait.bnframework.common.db.mode.BPA_GOODS; | |||
import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; | |||
import com.bonait.bnframework.common.db.mode.BPA_LOG; | |||
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; | |||
import com.bonait.bnframework.common.db.mode.BPA_MENU; | |||
import com.bonait.bnframework.common.db.mode.BPA_MENUANDUSER; | |||
import com.bonait.bnframework.common.db.mode.BPA_ORDER; | |||
import com.bonait.bnframework.common.db.mode.BPA_ORDERLOG; | |||
import com.bonait.bnframework.common.db.mode.BPA_ORDERLOGDESC; | |||
import com.bonait.bnframework.common.db.mode.BPA_SILOS; | |||
import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL; | |||
import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; | |||
import com.bonait.bnframework.common.db.mode.BPA_SUGAR; | |||
import com.bonait.bnframework.common.db.mode.BPA_SYSTEMSET; | |||
import com.bonait.bnframework.common.db.mode.BPA_USER; | |||
import java.lang.reflect.Field; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
/** | |||
* 数据库帮助类 | |||
*/ | |||
public class DBHelper extends SQLiteOpenHelper { | |||
private static DBHelper instance; | |||
private static int version = 4; | |||
public DBHelper(Context context) { | |||
super(context, ConfigName.getInstance().dbPath, null, version); | |||
} | |||
@Override | |||
public void onCreate(SQLiteDatabase db) { | |||
System.out.println("-----------------------------------------来了"); | |||
createTables(db, prepareTableInfo()); | |||
} | |||
@Override | |||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | |||
System.out.println("-----------------------------------------更新来了"); | |||
} | |||
public static DBHelper getInstance(Context context) { | |||
if (instance == null) { | |||
instance = new DBHelper(context); | |||
} | |||
return instance; | |||
} | |||
private ArrayList<Table> prepareTableInfo() { | |||
ArrayList<Table> tables = new ArrayList<Table>(); | |||
Table t; | |||
//t = new Table(TABLE_FOOD); // 通讯录 | |||
// t.addFeild(new Feild("NAME", "text")); // 姓名 | |||
// t.addFeild(new Feild("TYPE", "text")); // 号码 | |||
// t.addFeild(new Feild("STAR", "text")); // 号码 | |||
// t.addFeild(new Feild("PRICE", "text")); // 号码 | |||
// tables.add(t); | |||
return tables; | |||
} | |||
/** | |||
* 创建数据表 | |||
* | |||
* @param db | |||
* 数据库名称 | |||
* @param tables | |||
* 所要创建的数据库表列表 | |||
*/ | |||
private void createTables(SQLiteDatabase db, ArrayList<Table> tables) { | |||
db.beginTransaction(); | |||
for (Table table : tables) { | |||
db.execSQL(table.createSQL("")); | |||
} | |||
db.setTransactionSuccessful(); | |||
db.endTransaction(); | |||
} | |||
/** | |||
* 创建数据库表 | |||
*/ | |||
public void CreateTables() | |||
{ | |||
CreateTablesAll(BPA_MATERIAL.class,"id");//物料表 | |||
CreateTablesAll(BPA_SILOS.class,null);//料仓管理表 | |||
Map<String,String> smMap = new HashMap<String,String>(); | |||
smMap.put("materialID","BPA_MATERIAL (id)"); | |||
CreateRelationshipTables(BPA_SILOSANDMATERIAL.class,smMap);//料仓物料关联表 | |||
CreateTablesAll(BPA_GOODS.class,null);//商品表 | |||
CreateTablesAll(BPA_GOODSRECIPE.class,null);//商品配方明细表 | |||
CreateTablesAll(BPA_ORDER.class,null);//订单表 | |||
CreateTablesAll(BPA_SUBORDER.class,null);//订单子表 | |||
CreateTablesAll(BPA_ALERTLOG.class,null);//预警日志表 | |||
CreateTablesAll(BPA_LOG.class,null);//日志表 | |||
CreateTablesAll(BPA_ORDERLOG.class,null);//订单制作记录表 | |||
CreateTablesAll(BPA_ORDERLOGDESC.class,null);//订单制作记录描述表 | |||
CreateTablesAll(BPA_SYSTEMSET.class,null);//系统设置表 | |||
CreateTablesAll(BPA_USER.class,null);//账户表 | |||
CreateTablesAll(BPA_MENU.class,null);//菜单表 | |||
CreateTablesAll(BPA_MENUANDUSER.class,null);//菜单用户关联表 | |||
CreateTablesAll(BPA_SUGAR.class,null);//果糖表 | |||
CreateTablesAll(BPA_CRAFT.class,null);//工艺基础信息表 | |||
CreateTablesAll(BPA_CRAFTPROCESS.class,null);//工艺流程表 | |||
ForeignKeys(); | |||
} | |||
/** | |||
* 创建数据库表 | |||
* @param c | |||
*/ | |||
private void CreateTablesAll(Class c,String premarykey) | |||
{ | |||
if (premarykey == null){ | |||
premarykey=""; | |||
} | |||
SQLiteDatabase db =this.getWritableDatabase(); | |||
db.beginTransaction(); | |||
String TabName= c.getSimpleName();//表名称 | |||
ArrayList<Table> tables = new ArrayList<Table>(); | |||
Table t; | |||
t = new Table(TabName); // 创建表名称 | |||
for (Field field : c.getFields()){ | |||
String name=field.getName(); | |||
String type=field.getType().getSimpleName(); | |||
if(type.equals("String") || type.equals("Date")) | |||
{ | |||
type="text"; | |||
} | |||
t.addFeild(new Feild(name, type)); // 字段名称 | |||
} | |||
tables.add(t); | |||
for (Table table : tables) { | |||
db.execSQL(table.createSQL(premarykey)); | |||
} | |||
db.setTransactionSuccessful(); | |||
db.endTransaction(); | |||
} | |||
private void CreateRelationshipTables(Class c, Map<String,String> map){ | |||
SQLiteDatabase db =this.getWritableDatabase(); | |||
db.beginTransaction(); | |||
String TabName= c.getSimpleName();//表名称 | |||
ArrayList<Table> tables = new ArrayList<Table>(); | |||
Table t; | |||
t = new Table(TabName); // 创建表名称 | |||
for (Field field : c.getFields()){ | |||
String name=field.getName(); | |||
String type=field.getType().getSimpleName(); | |||
if(type.equals("String") || type.equals("Date")) | |||
{ | |||
type="text"; | |||
} | |||
t.addFeild(new Feild(name, type)); // 字段名称 | |||
} | |||
tables.add(t); | |||
for (Table table : tables) { | |||
db.execSQL(table.createSQL(map)); | |||
} | |||
db.setTransactionSuccessful(); | |||
db.endTransaction(); | |||
} | |||
/** | |||
* 开启外键约束 | |||
*/ | |||
private void ForeignKeys(){ | |||
SQLiteDatabase db =this.getWritableDatabase(); | |||
db.beginTransaction(); | |||
db.execSQL("PRAGMA foreign_keys = 1"); | |||
db.setTransactionSuccessful(); | |||
db.endTransaction(); | |||
} | |||
/** | |||
* 删除在创建 | |||
* @param c | |||
* @param premarykey | |||
*/ | |||
public void DeleteCreateTables(Class c,String premarykey) | |||
{ | |||
if (premarykey == null){ | |||
premarykey=""; | |||
} | |||
SQLiteDatabase db =this.getWritableDatabase(); | |||
db.beginTransaction(); | |||
String TabName= c.getSimpleName();//表名称 | |||
ArrayList<Table> tables = new ArrayList<Table>(); | |||
Table t; | |||
t = new Table(TabName); // 创建表名称 | |||
for (Field field : c.getFields()){ | |||
String name=field.getName(); | |||
String type=field.getType().getSimpleName(); | |||
if(type.equals("String") || type.equals("Date")) | |||
{ | |||
type="text"; | |||
} | |||
t.addFeild(new Feild(name, type)); // 字段名称 | |||
} | |||
tables.add(t); | |||
for (Table table : tables) { | |||
db.execSQL(table.deleteSql()); | |||
db.execSQL(table.createSQL(premarykey)); | |||
} | |||
db.setTransactionSuccessful(); | |||
db.endTransaction(); | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
package com.bonait.bnframework.common.db.file; | |||
/** | |||
* 数据库表基类结构 | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class Feild { | |||
public String name; | |||
public String type; | |||
public Feild(String name, String type) { | |||
super(); | |||
this.name = name; | |||
this.type = type; | |||
} | |||
} |
@@ -0,0 +1,93 @@ | |||
package com.bonait.bnframework.common.db.file; | |||
import android.util.Log; | |||
import java.util.ArrayList; | |||
import java.util.Map; | |||
/** | |||
* 数据库表 | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class Table { | |||
public String name; | |||
public ArrayList<Feild> feilds; | |||
public Table(String name, ArrayList<Feild> feilds) { | |||
super(); | |||
this.name = name; | |||
this.feilds = feilds; | |||
} | |||
public Table(String name) { | |||
super(); | |||
this.name = name; | |||
this.feilds = new ArrayList<Feild>(); | |||
} | |||
public void addFeild(Feild feild) { | |||
this.feilds.add(feild); | |||
} | |||
public String createSQL(String premarykey){ | |||
StringBuffer sb=new StringBuffer(); | |||
sb.append("CREATE TABLE "+this.name); | |||
sb.append("("); | |||
ArrayList<Feild> fs = this.feilds; | |||
for(Feild f:fs){ | |||
sb.append(f.name); | |||
sb.append(" "); | |||
sb.append(f.type); | |||
sb.append(" "); | |||
if (premarykey.equals(f.name)) {sb.append("PRIMARY KEY");}//主键 | |||
sb.append(","); | |||
} | |||
sb.deleteCharAt(sb.length()-1); | |||
sb.append(")"); | |||
Log.i("sql:",sb.toString()); | |||
return sb.toString(); | |||
} | |||
public String createSQL(Map<String,String> params){ | |||
StringBuffer sb=new StringBuffer(); | |||
sb.append("CREATE TABLE "+this.name); | |||
sb.append("("); | |||
ArrayList<Feild> fs = this.feilds; | |||
for(Feild f:fs){ | |||
if (params.containsKey(f.name)) { | |||
sb.append(f.name); | |||
sb.append(" "); | |||
sb.append(f.type); | |||
sb.append(" "); | |||
sb.append("REFERENCES"); | |||
sb.append(" "); | |||
sb.append(params.get(f.name)); | |||
sb.append(" "); | |||
sb.append("ON DELETE CASCADE"); | |||
sb.append(","); | |||
}else { | |||
sb.append(f.name); | |||
sb.append(" "); | |||
sb.append(f.type); | |||
sb.append(","); | |||
} | |||
} | |||
sb.deleteCharAt(sb.length()-1); | |||
sb.append(")"); | |||
Log.i("sql:",sb.toString()); | |||
return sb.toString(); | |||
} | |||
/** | |||
* 删除表 | |||
* @return | |||
*/ | |||
public String deleteSql() | |||
{ | |||
return "drop table "+this.name; | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_ALERTLOG[预警日志表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_ALERTLOG extends ModeBase{ | |||
/** | |||
* 类型: | |||
* 1 异常订单未制作日志、 | |||
* 2 料仓缺料日志 | |||
* 3 传感器异常日志等 | |||
*/ | |||
public int type; | |||
//日志描述 | |||
public String text; | |||
} |
@@ -0,0 +1,15 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_CRAFT[工艺基础信息表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_CRAFT { | |||
/** | |||
* 0:禁用 | |||
* 1:启用 | |||
*/ | |||
public int status; | |||
//日志描述 | |||
public String name; | |||
} |
@@ -0,0 +1,18 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_CRAFTPROCESS[工艺流程表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_CRAFTPROCESS { | |||
/** | |||
* 工艺id | |||
*/ | |||
public String gyid; | |||
//排序 | |||
public int sort; | |||
//出料数值:20g | |||
public int value; | |||
public String pfid; | |||
} |
@@ -0,0 +1,18 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_GOODS[商品表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_GOODS extends ModeBase { | |||
//商品名称 | |||
public String name; | |||
//商品Url | |||
public String url; | |||
//排序 | |||
public int sort; | |||
//状态:0 禁用 1 启用 | |||
public int status; | |||
//工艺id | |||
public String gyid; | |||
} |
@@ -0,0 +1,18 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_GOODSRECIPE[商品配方明细表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_GOODSRECIPE extends ModeBase { | |||
//商品ID | |||
public String goodsID; | |||
//物料ID | |||
public String materialID; | |||
//出料数值:20g | |||
public int value; | |||
//排序 | |||
public int sort; | |||
//物料类型 | |||
public int materialType; | |||
} |
@@ -0,0 +1,19 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_LOG[日志表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_LOG extends ModeBase{ | |||
/** | |||
* 类型: | |||
* 1 登录日志、 | |||
* 2 角色操作日志、 | |||
* 3 数据接收 | |||
* 4 上传日志 | |||
* 5 订单处理日志 | |||
*/ | |||
public int type; | |||
//日志描述 | |||
public String text; | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_MATERIAL[物料表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_MATERIAL extends ModeBase { | |||
//物料图片路径 | |||
public String imgUrl; | |||
//物料名称 | |||
public String name; | |||
public String getNameValue() { | |||
return name; | |||
} | |||
} |
@@ -0,0 +1,10 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_MENU[菜单表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_MENU extends ModeBase{ | |||
//菜单名称 | |||
public String name; | |||
} |
@@ -0,0 +1,10 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_MENUANDUSER[菜单用户关联表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_MENUANDUSER extends ModeBase{ | |||
//菜单ID | |||
public String menuID; | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_ORDER[订单表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_ORDER extends ModeBase { | |||
//第三方订单ID | |||
public String thirdPartyID; | |||
//状态:0 未开始 1 已制作 2 已超时 | |||
public int status; | |||
public String sortId;//取餐号 | |||
} |
@@ -0,0 +1,14 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_ORDERLOG[订单制作记录表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_ORDERLOG extends ModeBase{ | |||
//子订单ID | |||
public String suborderID; | |||
//状态:0 未开始 1 已制作 2 已超时 | |||
public int prewStatus; | |||
//状态:0 未开始 1 已制作 2 已超时 | |||
public int currentStatus; | |||
} |
@@ -0,0 +1,12 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_ORDERLOGDESC[订单制作记录描述表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_ORDERLOGDESC extends ModeBase{ | |||
//订单ID | |||
public String suborderID; | |||
//描述信息 | |||
public String text; | |||
} |
@@ -0,0 +1,26 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_SILOS[料仓管理表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_SILOS extends ModeBase { | |||
//料仓编号:1、2、3 | |||
public int num; | |||
//料仓名称 | |||
public String name; | |||
//补料阈值:例如 200g | |||
public int warningValue; | |||
//下线阈值:20g | |||
public int thrsoleValue; | |||
//PLC控制信号量 | |||
public String plcValue; | |||
//标准值 标准 1s出多少g(出场标准) | |||
public int bValue; | |||
//校准值 实际校准1s出多少g | |||
public int jValue; | |||
//状态 状态:0 禁用 1 启用 | |||
public int status; | |||
//优先级 优先出料顺序 | |||
public int Sort; | |||
} |
@@ -0,0 +1,12 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_SILOSANDMATERIAL[料仓物料关联表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_SILOSANDMATERIAL extends ModeBase { | |||
//料仓ID | |||
public String silosID; | |||
//物料ID | |||
public String materialID; | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_SUBORDER[订单子表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_SUBORDER extends ModeBase{ | |||
//主订单ID | |||
public String orderID; | |||
//商品ID | |||
public String goodsID; | |||
//数量:例如 *1 *2 | |||
public int number; | |||
//状态:0 未开始 1 制作中 2 已制作 3 已超时 | |||
public int status; | |||
//商品图片 | |||
public String goodImg; | |||
public double originalMoney;//原价 | |||
public double realMoney;//实际金额 | |||
} |
@@ -0,0 +1,7 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
public class BPA_SUGAR extends ModeBase{ | |||
public String sugarName; | |||
public String plcvar; | |||
} |
@@ -0,0 +1,30 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_SYSTEMSET[系统设置表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_SYSTEMSET extends ModeBase{ | |||
/** | |||
* 类型: | |||
* 1 订单上报周期 | |||
* 2 料仓余量上报周期 | |||
* 3 其他传感器上报周期 | |||
* 4 管道排空周期 | |||
* 5 订单未制作超时规则 | |||
* 6 料仓补料阈值 | |||
* 7 料仓告警阈值 | |||
* 8 自动清洗时间 | |||
* 9 设备id 店铺Autkey | |||
* 10 PLC地址 | |||
* 11 PLC端口 | |||
* 12 MQTT 用户名 | |||
* 13 MQTT 密码 | |||
* 14 mqtt ip | |||
* 15 mqtt 端口 | |||
* 16 mqtt 主题 | |||
*/ | |||
public int type; | |||
//值 | |||
public String value; | |||
} |
@@ -0,0 +1,14 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
/** | |||
* BPA_USER[账户表] | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_USER extends ModeBase{ | |||
//用户名称 | |||
public String name; | |||
//账户号 | |||
public String account; | |||
//密码 | |||
public String pass; | |||
} |
@@ -0,0 +1,34 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
import java.text.SimpleDateFormat; | |||
import java.util.Date; | |||
/** | |||
* 数据库基类 | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class ModeBase { | |||
//ID 号 | |||
public String id; | |||
//创建时间 统一用text存储 | |||
public String createTime; | |||
//修改时间 统一用text存储 | |||
public String updateTime; | |||
//删除时间 统一用text存储 | |||
public String deleteTime; | |||
//设备ID | |||
public String deviceID; | |||
//用户id | |||
public String userID; | |||
//是否删除:0:未删除 1 删除 | |||
public int isDelete; | |||
//备注 | |||
public String exp; | |||
public ModeBase() | |||
{ | |||
id=java.util.UUID.randomUUID().toString(); | |||
createTime= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());; | |||
isDelete=0; | |||
//Log.i("日志","创建时间:"+ createTime); | |||
} | |||
} |
@@ -0,0 +1,8 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
public enum AlertLogEnum { | |||
异常订单未制作日志, | |||
料仓缺料日志, | |||
传感器异常日志, | |||
其他 | |||
} |
@@ -0,0 +1,7 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
public enum MakeStatus { | |||
等待制作, | |||
制作中, | |||
制作完成 | |||
} |
@@ -0,0 +1,14 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
/** | |||
* 菜单Model | |||
*/ | |||
public class MenuMode { | |||
public String Name; | |||
public int Url; | |||
public MenuMode(String name,int url) | |||
{ | |||
this.Name=name; | |||
this.Url=url; | |||
} | |||
} |
@@ -0,0 +1,12 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
import com.bonait.bnframework.common.db.mode.BPA_ALERTLOG; | |||
/** | |||
* 返回预警Log信息 | |||
*/ | |||
public class ResAlertLog extends BPA_ALERTLOG { | |||
/** | |||
* 名称 | |||
*/ | |||
public String Name; | |||
} |
@@ -0,0 +1,50 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
import com.bonait.bnframework.common.db.mode.BPA_GOODS; | |||
import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; | |||
import java.util.ArrayList; | |||
/** | |||
* 商品制作列表 | |||
*/ | |||
public class ResGoodsMake { | |||
/** | |||
* 商品数据 | |||
*/ | |||
public BPA_GOODS good; | |||
/** | |||
* 商品制作配方 | |||
*/ | |||
public ArrayList<ResGoodsRecipe> recipes; | |||
/** | |||
* 商品订单数据 | |||
*/ | |||
public BPA_SUBORDER subOrder; | |||
/** | |||
* 制作状态 | |||
*/ | |||
public MakeStatus makeStatus; | |||
/** | |||
* 制作描述 | |||
*/ | |||
public String makeMs; | |||
/** | |||
* 制作进度 | |||
*/ | |||
public int makeProcess; | |||
/** | |||
* 是否可制作 | |||
*/ | |||
public boolean IsMake; | |||
public ResGoodsMake() | |||
{ | |||
good=new BPA_GOODS(); | |||
subOrder=new BPA_SUBORDER(); | |||
recipes=new ArrayList<>(); | |||
makeStatus=MakeStatus.等待制作; | |||
makeMs=""; | |||
makeProcess=0; | |||
IsMake=true; | |||
} | |||
} | |||
@@ -0,0 +1,31 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; | |||
/** | |||
* 界面显示商品配方结构 | |||
*/ | |||
public class ResGoodsRecipe extends BPA_GOODSRECIPE { | |||
/** | |||
* 唯一ID | |||
*/ | |||
public String id; | |||
/** | |||
* 物料名称 | |||
*/ | |||
public String materialName; | |||
/** | |||
* 1 为物料 | |||
* 2 为果糖 | |||
*/ | |||
public int materialType; | |||
/** | |||
* 是否运行 | |||
*/ | |||
public boolean IsRun=false; | |||
/** | |||
* 制作进度 | |||
*/ | |||
public int makeProcess; | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
import com.bonait.bnframework.common.db.mode.BPA_LOG; | |||
/** | |||
* 返回Log信息 | |||
*/ | |||
public class ResLog extends BPA_LOG { | |||
/** | |||
* 用户名称 | |||
*/ | |||
public String Name; | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
import com.bonait.bnframework.common.db.mode.BPA_ORDER; | |||
import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; | |||
import java.util.List; | |||
/** | |||
* 接收订单Model | |||
*/ | |||
public class ResReceiveOrder { | |||
/** | |||
* 主订单 | |||
*/ | |||
public BPA_ORDER order; | |||
/** | |||
* 子订单 | |||
*/ | |||
public List<BPA_SUBORDER> subOrder; | |||
} |
@@ -0,0 +1,14 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
import com.bonait.bnframework.common.db.mode.BPA_SILOS; | |||
public class ResSilosMode extends BPA_SILOS { | |||
//物料ID | |||
public String materialID; | |||
//物料图片路径 | |||
public String materialimgUrl; | |||
//物料名称 | |||
public String materialname; | |||
//当前余量 | |||
public int dvalue; | |||
} |
@@ -0,0 +1,17 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; | |||
/** | |||
* 返回子订单信息 | |||
*/ | |||
public class ResSubOrder extends BPA_SUBORDER { | |||
/** | |||
* 商品名称 | |||
*/ | |||
public String goodsName; | |||
/** | |||
* 状态描述 | |||
*/ | |||
public String statusText; | |||
} |
@@ -0,0 +1,19 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
/** | |||
* 状态Mode | |||
*/ | |||
public class StatusMode { | |||
public String Name; | |||
public Boolean Status; | |||
public int Url_open; | |||
public int Url_close; | |||
public StatusMode(String name,int Url_open,int Url_close,Boolean Status) | |||
{ | |||
this.Name=name; | |||
this.Status=Status; | |||
this.Url_open=Url_open; | |||
this.Url_close=Url_close; | |||
} | |||
} |
@@ -0,0 +1,9 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
public enum UserLogEnum { | |||
登录日志, | |||
角色操作日志, | |||
数据接收, | |||
上传日志, | |||
订单处理日志 | |||
} |
@@ -0,0 +1,23 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
import com.bonait.bnframework.common.db.mode.BPA_SILOS; | |||
public class lcMode extends BPA_SILOS { | |||
//物料名称 | |||
public String materialName; | |||
//料仓余料 | |||
public String silosmargin; | |||
//物料ID | |||
public String materialId; | |||
public lcMode(String id, int num,String materialName, String silosmargin,String materialId,int warningValue,int thrsoleValue) { | |||
this.materialName = materialName; | |||
this.silosmargin = silosmargin; | |||
this.num = num; | |||
this.id = id; | |||
this.materialId = materialId; | |||
this.warningValue=warningValue; | |||
this.thrsoleValue=thrsoleValue; | |||
} | |||
} |
@@ -0,0 +1,11 @@ | |||
package com.bonait.bnframework.common.db.res; | |||
public class mainGoods { | |||
public String id; | |||
public String name; | |||
public String message; | |||
public String url; | |||
} |
@@ -0,0 +1,154 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import java.math.BigInteger; | |||
import javax.crypto.Cipher; | |||
import javax.crypto.spec.SecretKeySpec; | |||
/** | |||
* AES 对称加密算法,加解密工具类 | |||
*/ | |||
public class AES { | |||
public static String key="bpa20210418bpa20210418bpa*******"; | |||
/** | |||
* 加密 | |||
* @return 加密后的字符串 | |||
*/ | |||
public static String Encrypt(String src) throws Exception { | |||
// 判断密钥是否为空 | |||
if (key == null) { | |||
System.out.print("密钥不能为空"); | |||
return null; | |||
} | |||
byte[] data = key.getBytes("utf-8"); | |||
SecretKeySpec skeySpec = new SecretKeySpec(data, "AES"); | |||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); // 算法/模式/补码方式 | |||
cipher.init(Cipher.ENCRYPT_MODE, skeySpec); | |||
byte[] encrypted = cipher.doFinal(src.getBytes("utf-8")); | |||
//return new Base64().encodeToString(encrypted);//base64 | |||
return binary(encrypted, 16); //十六进制 | |||
} | |||
/** | |||
* 解密 | |||
* @param src 解密字符串 | |||
* @return 解密后的字符串 | |||
*/ | |||
public static String Decrypt(String src) throws Exception { | |||
try { | |||
// 判断Key是否正确 | |||
if (key == null) { | |||
System.out.print("Key为空null"); | |||
return null; | |||
} | |||
byte[] data = key.getBytes("utf-8"); | |||
SecretKeySpec skeySpec = new SecretKeySpec(data, "AES"); | |||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); | |||
cipher.init(Cipher.DECRYPT_MODE, skeySpec); | |||
byte[] encrypted1 = toByteArray(src);//十六进制 | |||
try { | |||
byte[] original = cipher.doFinal(encrypted1); | |||
String originalString = new String(original,"utf-8"); | |||
return originalString; | |||
} catch (Exception e) { | |||
System.out.println(e.toString()); | |||
return null; | |||
} | |||
} catch (Exception ex) { | |||
System.out.println(ex.toString()); | |||
return null; | |||
} | |||
} | |||
/** | |||
* 将byte[]转为各种进制的字符串 | |||
* @param bytes byte[] | |||
* @param radix 可以转换进制的范围,从Character.MIN_RADIX到Character.MAX_RADIX,超出范围后变为10进制 | |||
* @return 转换后的字符串 | |||
*/ | |||
public static String binary(byte[] bytes, int radix){ | |||
return new BigInteger(1, bytes).toString(radix); // 这里的1代表正数 | |||
} | |||
/** | |||
* 16进制的字符串表示转成字节数组 | |||
* | |||
* @param hexString 16进制格式的字符串 | |||
* @return 转换后的字节数组 | |||
**/ | |||
public static byte[] toByteArray(String hexString) { | |||
if (hexString.isEmpty()) | |||
throw new IllegalArgumentException("this hexString must not be empty"); | |||
hexString = hexString.toLowerCase(); | |||
final byte[] byteArray = new byte[hexString.length() / 2]; | |||
int k = 0; | |||
for (int i = 0; i < byteArray.length; i++) {//因为是16进制,最多只会占用4位,转换成字节需要两个16进制的字符,高位在先 | |||
byte high = (byte) (Character.digit(hexString.charAt(k), 16) & 0xff); | |||
byte low = (byte) (Character.digit(hexString.charAt(k + 1), 16) & 0xff); | |||
byteArray[i] = (byte) (high << 4 | low); | |||
k += 2; | |||
} | |||
return byteArray; | |||
} | |||
/** | |||
* bytes转换成十六进制字符串 | |||
* @param b byte数组 | |||
* @return String 每个Byte值之间空格分隔 | |||
*/ | |||
public static String byte2HexStr(byte[] b) | |||
{ | |||
String stmp=""; | |||
StringBuilder sb = new StringBuilder(""); | |||
for (int n=0;n<b.length;n++) | |||
{ | |||
stmp = Integer.toHexString(b[n] & 0xFF); | |||
sb.append((stmp.length()==1)? "0"+stmp : stmp); | |||
sb.append(" "); | |||
} | |||
return sb.toString().toUpperCase().trim(); | |||
} | |||
/* | |||
* 16进制字符串转字节数组 | |||
*/ | |||
public static byte[] hexString2Bytes(String hex) { | |||
if ((hex == null) || (hex.equals(""))){ | |||
return null; | |||
} | |||
else if (hex.length()%2 != 0){ | |||
return null; | |||
} | |||
else{ | |||
hex = hex.toUpperCase(); | |||
int len = hex.length()/2; | |||
byte[] b = new byte[len]; | |||
char[] hc = hex.toCharArray(); | |||
for (int i=0; i<len; i++){ | |||
int p=2*i; | |||
b[i] = (byte) (charToByte(hc[p]) << 4 | charToByte(hc[p+1])); | |||
} | |||
return b; | |||
} | |||
} | |||
/* | |||
* 字符转换为字节 | |||
*/ | |||
private static byte charToByte(char c) { | |||
return (byte) "0123456789ABCDEF".indexOf(c); | |||
} | |||
} |
@@ -0,0 +1,136 @@ | |||
package com.bonait.bnframework.common.helper; | |||
public class ByteHelper { | |||
public static int byteToInt(byte[] bytes) { | |||
int value = 0; | |||
for (int i = 0; i < 4; i++) { | |||
int shift = (3 - i) * 8; | |||
value += (bytes[i] & 0xFF) << shift; | |||
} | |||
return value; | |||
} | |||
public static int getCRC2(byte[] bytes) { | |||
int CRC = 0x0000ffff; | |||
int POLYNOMIAL = 0x0000a001; | |||
int i, j; | |||
for (i = 0; i < bytes.length; i++) { | |||
CRC ^= (int) bytes[i]; | |||
for (j = 0; j < 8; j++) { | |||
if ((CRC & 0x00000001) == 1) { | |||
CRC >>= 1; | |||
CRC ^= POLYNOMIAL; | |||
} else { | |||
CRC >>= 1; | |||
} | |||
} | |||
} | |||
//高低位转换,看情况使用(譬如本人这次对led彩屏的通讯开发就规定校验码高位在前低位在后,也就不需要转换高低位) | |||
CRC = ((CRC & 0x0000FF00) >> 8) | ((CRC & 0x000000FF) << 8); | |||
return CRC; | |||
// return Integer.toHexString(CRC); | |||
} | |||
/** | |||
* byte[]转16进制字符串 | |||
* @param data | |||
* @return | |||
*/ | |||
public String bytes2String(byte[] data){ | |||
String getString = ""; | |||
for(int i = 0; i < data.length; i++){ | |||
getString += String.format("%02X", data[i]); | |||
} | |||
return getString; | |||
} | |||
/** | |||
* Char转byte | |||
* @param c | |||
* @return | |||
*/ | |||
private static byte charToByte(char c) { | |||
return (byte) "0123456789ABCDEF".indexOf(c); | |||
} | |||
/** | |||
* 16进制字符串转byte[] | |||
* @param data | |||
* @return | |||
*/ | |||
public byte[] StringtoBytes(String data){ | |||
if(data == null || data.equals("")){ | |||
return null; | |||
} | |||
data = data.toUpperCase(); | |||
char[] datachar = data.toCharArray(); | |||
byte[] getbytes = new byte[data.length() / 2]; | |||
for( int i = 0; i < data.length()/2 ; i++){ | |||
int pos = i * 2; | |||
getbytes[i] = (byte) (charToByte(datachar[pos]) << 4 | charToByte(datachar[pos + 1])); | |||
} | |||
return getbytes; | |||
} | |||
/** | |||
* 16进制字符串转int | |||
* @param hex | |||
* @return | |||
*/ | |||
public static int hexStringToAlgorism(String hex) { | |||
hex = hex.toUpperCase(); | |||
int max = hex.length(); | |||
int result = 0; | |||
for (int i = max; i > 0; i--) { | |||
char c = hex.charAt(i - 1); | |||
int algorism = 0; | |||
if (c >= '0' && c <= '9') { | |||
algorism = c - '0'; | |||
} else { | |||
algorism = c - 55; | |||
} | |||
result += Math.pow(16, max - i) * algorism; | |||
} | |||
return result; | |||
} | |||
public static String SixTweenToTen(String max){ | |||
int h = Integer.parseInt(max, 16); | |||
return String.valueOf(h); | |||
} | |||
private static byte[] hexBytes(String hexString) { | |||
int length; | |||
byte h; | |||
byte l; | |||
byte[] byteArray; | |||
length = null != hexString? hexString.length() : 0; | |||
length = (length - (length%2))/2; | |||
if (length < 1) { | |||
return null; | |||
} | |||
byteArray = new byte[length]; | |||
for (int i = 0; i < length; i++) { | |||
h = (byte)hexString.charAt(i*2); | |||
l = (byte)hexString.charAt(i*2 + 1); | |||
l = (byte)('0' <= l && l <= '9'? l - '0' : | |||
'A' <= l && l <= 'F'? (l - 'A') + 10 : | |||
'a' <= l && l <= 'f'? (l - 'a') + 10 : 0); | |||
h = (byte)('0' <= h && h <= '9'? h - '0' : | |||
'A' <= h && h <= 'F'? (h - 'A') + 10 : | |||
'a' <= h && h <= 'f'? (h - 'a') + 10 : 3); | |||
byteArray[i] = (byte)(0x0FF & ((h << 4) | l)); | |||
} | |||
return byteArray; | |||
} | |||
//b为传入的字节,i为第几位(范围0-7),如要获取bit0,则i=0 | |||
public static int getBit(byte b,int i) { | |||
int bit = (int) ((b >> i) & 0x1); | |||
return bit; | |||
} | |||
} |
@@ -0,0 +1,139 @@ | |||
package com.bonait.bnframework.common.helper; | |||
public class CRCHelper { | |||
/** | |||
* CRC16相关计算 | |||
*/ | |||
static byte[] crc16_tab_h = {(byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, | |||
(byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, | |||
(byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, | |||
(byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, | |||
(byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, | |||
(byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, | |||
(byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, | |||
(byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, | |||
(byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, | |||
(byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, | |||
(byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, | |||
(byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, | |||
(byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, | |||
(byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, | |||
(byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, | |||
(byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, | |||
(byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, | |||
(byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, | |||
(byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, | |||
(byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, | |||
(byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, | |||
(byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, | |||
(byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, | |||
(byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, | |||
(byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, | |||
(byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, | |||
(byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, | |||
(byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, | |||
(byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40}; | |||
static byte[] crc16_tab_l = {(byte) 0x00, (byte) 0xC0, (byte) 0xC1, (byte) 0x01, (byte) 0xC3, (byte) 0x03, (byte) 0x02, (byte) 0xC2, | |||
(byte) 0xC6, (byte) 0x06, (byte) 0x07, (byte) 0xC7, (byte) 0x05, (byte) 0xC5, (byte) 0xC4, (byte) 0x04, (byte) 0xCC, (byte) 0x0C, | |||
(byte) 0x0D, (byte) 0xCD, (byte) 0x0F, (byte) 0xCF, (byte) 0xCE, (byte) 0x0E, (byte) 0x0A, (byte) 0xCA, (byte) 0xCB, (byte) 0x0B, | |||
(byte) 0xC9, (byte) 0x09, (byte) 0x08, (byte) 0xC8, (byte) 0xD8, (byte) 0x18, (byte) 0x19, (byte) 0xD9, (byte) 0x1B, (byte) 0xDB, | |||
(byte) 0xDA, (byte) 0x1A, (byte) 0x1E, (byte) 0xDE, (byte) 0xDF, (byte) 0x1F, (byte) 0xDD, (byte) 0x1D, (byte) 0x1C, (byte) 0xDC, | |||
(byte) 0x14, (byte) 0xD4, (byte) 0xD5, (byte) 0x15, (byte) 0xD7, (byte) 0x17, (byte) 0x16, (byte) 0xD6, (byte) 0xD2, (byte) 0x12, | |||
(byte) 0x13, (byte) 0xD3, (byte) 0x11, (byte) 0xD1, (byte) 0xD0, (byte) 0x10, (byte) 0xF0, (byte) 0x30, (byte) 0x31, (byte) 0xF1, | |||
(byte) 0x33, (byte) 0xF3, (byte) 0xF2, (byte) 0x32, (byte) 0x36, (byte) 0xF6, (byte) 0xF7, (byte) 0x37, (byte) 0xF5, (byte) 0x35, | |||
(byte) 0x34, (byte) 0xF4, (byte) 0x3C, (byte) 0xFC, (byte) 0xFD, (byte) 0x3D, (byte) 0xFF, (byte) 0x3F, (byte) 0x3E, (byte) 0xFE, | |||
(byte) 0xFA, (byte) 0x3A, (byte) 0x3B, (byte) 0xFB, (byte) 0x39, (byte) 0xF9, (byte) 0xF8, (byte) 0x38, (byte) 0x28, (byte) 0xE8, | |||
(byte) 0xE9, (byte) 0x29, (byte) 0xEB, (byte) 0x2B, (byte) 0x2A, (byte) 0xEA, (byte) 0xEE, (byte) 0x2E, (byte) 0x2F, (byte) 0xEF, | |||
(byte) 0x2D, (byte) 0xED, (byte) 0xEC, (byte) 0x2C, (byte) 0xE4, (byte) 0x24, (byte) 0x25, (byte) 0xE5, (byte) 0x27, (byte) 0xE7, | |||
(byte) 0xE6, (byte) 0x26, (byte) 0x22, (byte) 0xE2, (byte) 0xE3, (byte) 0x23, (byte) 0xE1, (byte) 0x21, (byte) 0x20, (byte) 0xE0, | |||
(byte) 0xA0, (byte) 0x60, (byte) 0x61, (byte) 0xA1, (byte) 0x63, (byte) 0xA3, (byte) 0xA2, (byte) 0x62, (byte) 0x66, (byte) 0xA6, | |||
(byte) 0xA7, (byte) 0x67, (byte) 0xA5, (byte) 0x65, (byte) 0x64, (byte) 0xA4, (byte) 0x6C, (byte) 0xAC, (byte) 0xAD, (byte) 0x6D, | |||
(byte) 0xAF, (byte) 0x6F, (byte) 0x6E, (byte) 0xAE, (byte) 0xAA, (byte) 0x6A, (byte) 0x6B, (byte) 0xAB, (byte) 0x69, (byte) 0xA9, | |||
(byte) 0xA8, (byte) 0x68, (byte) 0x78, (byte) 0xB8, (byte) 0xB9, (byte) 0x79, (byte) 0xBB, (byte) 0x7B, (byte) 0x7A, (byte) 0xBA, | |||
(byte) 0xBE, (byte) 0x7E, (byte) 0x7F, (byte) 0xBF, (byte) 0x7D, (byte) 0xBD, (byte) 0xBC, (byte) 0x7C, (byte) 0xB4, (byte) 0x74, | |||
(byte) 0x75, (byte) 0xB5, (byte) 0x77, (byte) 0xB7, (byte) 0xB6, (byte) 0x76, (byte) 0x72, (byte) 0xB2, (byte) 0xB3, (byte) 0x73, | |||
(byte) 0xB1, (byte) 0x71, (byte) 0x70, (byte) 0xB0, (byte) 0x50, (byte) 0x90, (byte) 0x91, (byte) 0x51, (byte) 0x93, (byte) 0x53, | |||
(byte) 0x52, (byte) 0x92, (byte) 0x96, (byte) 0x56, (byte) 0x57, (byte) 0x97, (byte) 0x55, (byte) 0x95, (byte) 0x94, (byte) 0x54, | |||
(byte) 0x9C, (byte) 0x5C, (byte) 0x5D, (byte) 0x9D, (byte) 0x5F, (byte) 0x9F, (byte) 0x9E, (byte) 0x5E, (byte) 0x5A, (byte) 0x9A, | |||
(byte) 0x9B, (byte) 0x5B, (byte) 0x99, (byte) 0x59, (byte) 0x58, (byte) 0x98, (byte) 0x88, (byte) 0x48, (byte) 0x49, (byte) 0x89, | |||
(byte) 0x4B, (byte) 0x8B, (byte) 0x8A, (byte) 0x4A, (byte) 0x4E, (byte) 0x8E, (byte) 0x8F, (byte) 0x4F, (byte) 0x8D, (byte) 0x4D, | |||
(byte) 0x4C, (byte) 0x8C, (byte) 0x44, (byte) 0x84, (byte) 0x85, (byte) 0x45, (byte) 0x87, (byte) 0x47, (byte) 0x46, (byte) 0x86, | |||
(byte) 0x82, (byte) 0x42, (byte) 0x43, (byte) 0x83, (byte) 0x41, (byte) 0x81, (byte) 0x80, (byte) 0x40}; | |||
/** | |||
* 获取CRC16校验后数组 | |||
* | |||
* @param crcStr 需要计算的16进制的字符串 | |||
* @return 请求指令的16进制字节数组 | |||
*/ | |||
public static byte[] getRequestOrder(String crcStr) { | |||
//转化为字节数组 | |||
byte[] data = hexString2Bytes(crcStr); | |||
//获取CRC16校验值 | |||
int i = calcCrc16(data, 0, data.length, 0xffff); | |||
//转变高低校验值位置,低字节在前高字节在后 | |||
String format = String.format("%04x", i); | |||
String hight = format.substring(0, 2); | |||
String low = format.substring(2); | |||
String crc = low + hight; | |||
//拼接请求指令 | |||
String value = crcStr + crc; | |||
//转变为16进制的字节数组 | |||
return hexString2Bytes(value); | |||
} | |||
/** | |||
* 计算CRC16校验 | |||
* | |||
* @param data 需要计算的数组 | |||
* @param offset 起始位置 | |||
* @param len 长度 | |||
* @param preval 之前的校验值 | |||
* @return CRC16校验值 | |||
*/ | |||
public static int calcCrc16(byte[] data, int offset, int len, int preval) { | |||
int ucCRCHi = (preval & 0xff00) >> 8; | |||
int ucCRCLo = preval & 0x00ff; | |||
int iIndex; | |||
for (int i = 0; i < len; ++i) { | |||
iIndex = (ucCRCLo ^ data[offset + i]) & 0x00ff; | |||
ucCRCLo = ucCRCHi ^ crc16_tab_h[iIndex]; | |||
ucCRCHi = crc16_tab_l[iIndex]; | |||
} | |||
return ((ucCRCHi & 0x00ff) << 8) | (ucCRCLo & 0x00ff) & 0xffff; | |||
} | |||
/** | |||
* 将指定字符串src,以每两个字符分割转换为16进制形式 | |||
* 如:"2B44EFD9" --> byte[]{0x2B, 0x44, 0xEF, 0xD9} | |||
* | |||
* @param src String | |||
* @return byte[] | |||
*/ | |||
public static byte[] hexString2Bytes(String src) { | |||
byte[] ret = new byte[src.length() / 2]; | |||
byte[] tmp = src.getBytes(); | |||
for (int i = 0; i < src.length() / 2; i++) { | |||
ret[i] = uniteBytes(tmp[i * 2], tmp[i * 2 + 1]); | |||
} | |||
return ret; | |||
} | |||
/** | |||
* 将两个ASCII字符合成一个字节; | |||
* 如:"EF"--> 0xEF | |||
* | |||
* @param src0 byte | |||
* @param src1 byte | |||
* @return byte | |||
*/ | |||
public static byte uniteBytes(byte src0, byte src1) { | |||
byte b0 = Byte.decode("0x" + new String(new byte[]{src0})).byteValue(); | |||
b0 = (byte) (b0 << 4); | |||
byte _b1 = Byte.decode("0x" + new String(new byte[]{src1})).byteValue(); | |||
byte ret = (byte) (b0 ^ _b1); | |||
return ret; | |||
} | |||
} |
@@ -0,0 +1,148 @@ | |||
package com.bonait.bnframework.common.helper; | |||
/** | |||
* 汉字转拼音工具类 CharacterParser : | |||
*/ | |||
public class CharacterParser { | |||
/** | |||
* Java汉字转换为拼音 | |||
*/ | |||
private static int[] pyvalue = new int[]{-20319, -20317, -20304, -20295, -20292, -20283, -20265, -20257, -20242, -20230, -20051, -20036, -20032, | |||
-20026, -20002, -19990, -19986, -19982, -19976, -19805, -19784, -19775, -19774, -19763, -19756, -19751, -19746, -19741, -19739, -19728, | |||
-19725, -19715, -19540, -19531, -19525, -19515, -19500, -19484, -19479, -19467, -19289, -19288, -19281, -19275, -19270, -19263, -19261, | |||
-19249, -19243, -19242, -19238, -19235, -19227, -19224, -19218, -19212, -19038, -19023, -19018, -19006, -19003, -18996, -18977, -18961, | |||
-18952, -18783, -18774, -18773, -18763, -18756, -18741, -18735, -18731, -18722, -18710, -18697, -18696, -18526, -18518, -18501, -18490, | |||
-18478, -18463, -18448, -18447, -18446, -18239, -18237, -18231, -18220, -18211, -18201, -18184, -18183, -18181, -18012, -17997, -17988, | |||
-17970, -17964, -17961, -17950, -17947, -17931, -17928, -17922, -17759, -17752, -17733, -17730, -17721, -17703, -17701, -17697, -17692, | |||
-17683, -17676, -17496, -17487, -17482, -17468, -17454, -17433, -17427, -17417, -17202, -17185, -16983, -16970, -16942, -16915, -16733, | |||
-16708, -16706, -16689, -16664, -16657, -16647, -16474, -16470, -16465, -16459, -16452, -16448, -16433, -16429, -16427, -16423, -16419, | |||
-16412, -16407, -16403, -16401, -16393, -16220, -16216, -16212, -16205, -16202, -16187, -16180, -16171, -16169, -16158, -16155, -15959, | |||
-15958, -15944, -15933, -15920, -15915, -15903, -15889, -15878, -15707, -15701, -15681, -15667, -15661, -15659, -15652, -15640, -15631, | |||
-15625, -15454, -15448, -15436, -15435, -15419, -15416, -15408, -15394, -15385, -15377, -15375, -15369, -15363, -15362, -15183, -15180, | |||
-15165, -15158, -15153, -15150, -15149, -15144, -15143, -15141, -15140, -15139, -15128, -15121, -15119, -15117, -15110, -15109, -14941, | |||
-14937, -14933, -14930, -14929, -14928, -14926, -14922, -14921, -14914, -14908, -14902, -14894, -14889, -14882, -14873, -14871, -14857, | |||
-14678, -14674, -14670, -14668, -14663, -14654, -14645, -14630, -14594, -14429, -14407, -14399, -14384, -14379, -14368, -14355, -14353, | |||
-14345, -14170, -14159, -14151, -14149, -14145, -14140, -14137, -14135, -14125, -14123, -14122, -14112, -14109, -14099, -14097, -14094, | |||
-14092, -14090, -14087, -14083, -13917, -13914, -13910, -13907, -13906, -13905, -13896, -13894, -13878, -13870, -13859, -13847, -13831, | |||
-13658, -13611, -13601, -13406, -13404, -13400, -13398, -13395, -13391, -13387, -13383, -13367, -13359, -13356, -13343, -13340, -13329, | |||
-13326, -13318, -13147, -13138, -13120, -13107, -13096, -13095, -13091, -13076, -13068, -13063, -13060, -12888, -12875, -12871, -12860, | |||
-12858, -12852, -12849, -12838, -12831, -12829, -12812, -12802, -12607, -12597, -12594, -12585, -12556, -12359, -12346, -12320, -12300, | |||
-12120, -12099, -12089, -12074, -12067, -12058, -12039, -11867, -11861, -11847, -11831, -11798, -11781, -11604, -11589, -11536, -11358, | |||
-11340, -11339, -11324, -11303, -11097, -11077, -11067, -11055, -11052, -11045, -11041, -11038, -11024, -11020, -11019, -11018, -11014, | |||
-10838, -10832, -10815, -10800, -10790, -10780, -10764, -10587, -10544, -10533, -10519, -10331, -10329, -10328, -10322, -10315, -10309, | |||
-10307, -10296, -10281, -10274, -10270, -10262, -10260, -10256, -10254}; | |||
public static String[] pystr = new String[]{"a", "ai", "an", "ang", "ao", "ba", "bai", "ban", "bang", "bao", "bei", "ben", "beng", "bi", "bian", | |||
"biao", "bie", "bin", "bing", "bo", "bu", "ca", "cai", "can", "cang", "cao", "ce", "ceng", "cha", "chai", "chan", "chang", "chao", "che", | |||
"chen", "cheng", "chi", "chong", "chou", "chu", "chuai", "chuan", "chuang", "chui", "chun", "chuo", "ci", "cong", "cou", "cu", "cuan", | |||
"cui", "cun", "cuo", "da", "dai", "dan", "dang", "dao", "de", "deng", "di", "dian", "diao", "die", "ding", "diu", "dong", "dou", "du", | |||
"duan", "dui", "dun", "duo", "e", "en", "er", "fa", "fan", "fang", "fei", "fen", "feng", "fo", "fou", "fu", "ga", "gai", "gan", "gang", | |||
"gao", "ge", "gei", "gen", "geng", "gong", "gou", "gu", "gua", "guai", "guan", "guang", "gui", "gun", "guo", "ha", "hai", "han", "hang", | |||
"hao", "he", "hei", "hen", "heng", "hong", "hou", "hu", "hua", "huai", "huan", "huang", "hui", "hun", "huo", "ji", "jia", "jian", | |||
"jiang", "jiao", "jie", "jin", "jing", "jiong", "jiu", "ju", "juan", "jue", "jun", "ka", "kai", "kan", "kang", "kao", "ke", "ken", | |||
"keng", "kong", "kou", "ku", "kua", "kuai", "kuan", "kuang", "kui", "kun", "kuo", "la", "lai", "lan", "lang", "lao", "le", "lei", "leng", | |||
"li", "lia", "lian", "liang", "liao", "lie", "lin", "ling", "liu", "long", "lou", "lu", "lv", "luan", "lue", "lun", "luo", "ma", "mai", | |||
"man", "mang", "mao", "me", "mei", "men", "meng", "mi", "mian", "miao", "mie", "min", "ming", "miu", "mo", "mou", "mu", "na", "nai", | |||
"nan", "nang", "nao", "ne", "nei", "nen", "neng", "ni", "nian", "niang", "niao", "nie", "nin", "ning", "niu", "nong", "nu", "nv", "nuan", | |||
"nue", "nuo", "o", "ou", "pa", "pai", "pan", "pang", "pao", "pei", "pen", "peng", "pi", "pian", "piao", "pie", "pin", "ping", "po", "pu", | |||
"qi", "qia", "qian", "qiang", "qiao", "qie", "qin", "qing", "qiong", "qiu", "qu", "quan", "que", "qun", "ran", "rang", "rao", "re", | |||
"ren", "reng", "ri", "rong", "rou", "ru", "ruan", "rui", "run", "ruo", "sa", "sai", "san", "sang", "sao", "se", "sen", "seng", "sha", | |||
"shai", "shan", "shang", "shao", "she", "shen", "sheng", "shi", "shou", "shu", "shua", "shuai", "shuan", "shuang", "shui", "shun", | |||
"shuo", "si", "song", "sou", "su", "suan", "sui", "sun", "suo", "ta", "tai", "tan", "tang", "tao", "te", "teng", "ti", "tian", "tiao", | |||
"tie", "ting", "tong", "tou", "tu", "tuan", "tui", "tun", "tuo", "wa", "wai", "wan", "wang", "wei", "wen", "weng", "wo", "wu", "xi", | |||
"xia", "xian", "xiang", "xiao", "xie", "xin", "xing", "xiong", "xiu", "xu", "xuan", "xue", "xun", "ya", "yan", "yang", "yao", "ye", "yi", | |||
"yin", "ying", "yo", "yong", "you", "yu", "yuan", "yue", "yun", "za", "zai", "zan", "zang", "zao", "ze", "zei", "zen", "zeng", "zha", | |||
"zhai", "zhan", "zhang", "zhao", "zhe", "zhen", "zheng", "zhi", "zhong", "zhou", "zhu", "zhua", "zhuai", "zhuan", "zhuang", "zhui", | |||
"zhun", "zhuo", "zi", "zong", "zou", "zu", "zuan", "zui", "zun", "zuo"}; | |||
private StringBuilder buffer; | |||
private String resource; | |||
private static CharacterParser characterParser = new CharacterParser(); | |||
public static CharacterParser getInstance() { | |||
return characterParser; | |||
} | |||
public String getResource() { | |||
return resource; | |||
} | |||
public void setResource(String resource) { | |||
this.resource = resource; | |||
} | |||
/** | |||
* 汉字转成ASCII码 * * @param chs * @return | |||
*/ | |||
private static int getChsAscii(String chs) { | |||
int asc = 0; | |||
try { | |||
byte[] bytes = chs.getBytes("gb2312"); | |||
if (bytes == null || bytes.length > 2 || bytes.length <= 0) { | |||
throw new RuntimeException("illegal resource string"); | |||
} | |||
if (bytes.length == 1) { | |||
asc = bytes[0]; | |||
} | |||
if (bytes.length == 2) { | |||
int hightByte = 256 + bytes[0]; | |||
int lowByte = 256 + bytes[1]; | |||
asc = (256 * hightByte + lowByte) - 256 * 256; | |||
} | |||
} catch (Exception e) { | |||
System.out.println("ERROR:ChineseSpelling.class-getChsAscii(String chs)" + e); | |||
} | |||
return asc; | |||
} | |||
/** | |||
* 单字解析(把汉字变成拼音) | |||
* * * @param str * @return | |||
*/ | |||
public static String convert(String str) { | |||
String result = null; | |||
int ascii = getChsAscii(str); | |||
if (ascii > 0 && ascii < 160) { | |||
result = String.valueOf((char) ascii); | |||
} else { | |||
for (int i = (pyvalue.length - 1); i >= 0; i--) { | |||
if (pyvalue[i] <= ascii) { | |||
result = pystr[i]; | |||
break; | |||
} | |||
} | |||
} | |||
return result; | |||
} | |||
/** | |||
* 词组解析 * | |||
* | |||
* @param chs | |||
* @return 转换成拼音 | |||
*/ | |||
public String getSelling(String chs) { | |||
String key, value; | |||
buffer = new StringBuilder(); | |||
for (int i = 0; i < chs.length(); i++) { | |||
//一个一个字符截取 | |||
key = chs.substring(i, i + 1); | |||
if (key.getBytes().length >= 2) {//大于2个字节,说明是汉字 | |||
value = (String) convert(key);//把单个汉字装换成拼音 | |||
if (value == null) { | |||
value = "unknown"; | |||
} | |||
} else {//说明是英文的字母,或者1个字符的 | |||
if ((key.charAt(0) - 0) >= 65 && (key.charAt(0) - 0) <= 90) {//说明是大写字母,转换成小写字母 | |||
value = key.toLowerCase(); | |||
} else { | |||
value = key; | |||
} | |||
} | |||
buffer.append(value); | |||
} | |||
return buffer.toString(); | |||
} | |||
public String getSpelling() { | |||
return this.getSelling(this.getResource()); | |||
} | |||
} |
@@ -0,0 +1,71 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import android.content.Context; | |||
import android.content.SharedPreferences; | |||
/** | |||
* Config文件配置,读写类 shared_prefs | |||
*/ | |||
public class ConfigUtil { | |||
private static final String CONFIG_FILE = "ICS_CONF"; | |||
//读取配置参数 | |||
public static String read(Context context, String key, String defValue){ | |||
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0); | |||
return sp.getString(key, defValue); | |||
} | |||
public static long read(Context context,String key,long defValue){ | |||
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0); | |||
return sp.getLong(key, defValue); | |||
} | |||
public static int read(Context context,String key,int defValue){ | |||
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0); | |||
return sp.getInt(key, defValue); | |||
} | |||
public static float read(Context context,String key,float defValue){ | |||
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0); | |||
return sp.getFloat(key, defValue); | |||
} | |||
public static boolean read(Context context,String key,boolean defValue){ | |||
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0); | |||
return sp.getBoolean(key, defValue); | |||
} | |||
//写入配置参数 | |||
public static void write(Context context,String key,String value){ | |||
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0); | |||
SharedPreferences.Editor editor=sp.edit(); | |||
editor.putString(key, value); | |||
editor.commit(); | |||
} | |||
public static void write(Context context,String key,long value){ | |||
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0); | |||
SharedPreferences.Editor editor=sp.edit(); | |||
editor.putLong(key, value); | |||
editor.commit(); | |||
} | |||
public static void write(Context context,String key,int value){ | |||
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0); | |||
SharedPreferences.Editor editor=sp.edit(); | |||
editor.putInt(key, value); | |||
editor.commit(); | |||
} | |||
public static void write(Context context,String key,float value){ | |||
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0); | |||
SharedPreferences.Editor editor=sp.edit(); | |||
editor.putFloat(key, value); | |||
editor.commit(); | |||
} | |||
public static void write(Context context,String key,boolean value){ | |||
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0); | |||
SharedPreferences.Editor editor=sp.edit(); | |||
editor.putBoolean(key, value); | |||
editor.commit(); | |||
} | |||
public static void remove(Context context,String key){ | |||
SharedPreferences sp = context.getSharedPreferences(CONFIG_FILE,0); | |||
SharedPreferences.Editor editor=sp.edit(); | |||
editor.remove(key); | |||
editor.commit(); | |||
} | |||
} |
@@ -0,0 +1,232 @@ | |||
package com.bonait.bnframework.common.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,8 @@ | |||
package com.bonait.bnframework.common.helper; | |||
public enum DataFormat { | |||
ABCD, | |||
CDAB, | |||
BADC, | |||
DCBA | |||
} |
@@ -0,0 +1,63 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import java.text.ParseException; | |||
import java.text.SimpleDateFormat; | |||
import java.util.Date; | |||
public class DataHelper { | |||
// formatType格式为yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 HH时mm分ss秒 | |||
// data Date类型的时间 | |||
public static String dateToString(Date data, String formatType) { | |||
return new SimpleDateFormat(formatType).format(data); | |||
} | |||
// currentTime要转换的long类型的时间 | |||
// formatType要转换的string类型的时间格式 | |||
public static String longToString(long currentTime, String formatType) | |||
throws ParseException { | |||
Date date = longToDate(currentTime, formatType); // long类型转成Date类型 | |||
String strTime = dateToString(date, formatType); // date类型转成String | |||
return strTime; | |||
} | |||
// strTime要转换的string类型的时间,formatType要转换的格式yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 | |||
// HH时mm分ss秒, | |||
// strTime的时间格式必须要与formatType的时间格式相同 | |||
public static Date stringToDate(String strTime, String formatType) | |||
throws ParseException { | |||
SimpleDateFormat formatter = new SimpleDateFormat(formatType); | |||
Date date = null; | |||
date = formatter.parse(strTime); | |||
return date; | |||
} | |||
// currentTime要转换的long类型的时间 | |||
// formatType要转换的时间格式yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 HH时mm分ss秒 | |||
public static Date longToDate(long currentTime, String formatType) | |||
throws ParseException { | |||
Date dateOld = new Date(currentTime); // 根据long类型的毫秒数生命一个date类型的时间 | |||
String sDateTime = dateToString(dateOld, formatType); // 把date类型的时间转换为string | |||
Date date = stringToDate(sDateTime, formatType); // 把String类型转换为Date类型 | |||
return date; | |||
} | |||
// strTime要转换的String类型的时间 | |||
// formatType时间格式 | |||
// strTime的时间格式和formatType的时间格式必须相同 | |||
public static long stringToLong(String strTime, String formatType) | |||
throws ParseException { | |||
Date date = stringToDate(strTime, formatType); // String类型转成date类型 | |||
if (date == null) { | |||
return 0; | |||
} else { | |||
long currentTime = dateToLong(date); // date类型转成long类型 | |||
return currentTime; | |||
} | |||
} | |||
// date要转换的date类型的时间 | |||
public static long dateToLong(Date date) { | |||
return date.getTime(); | |||
} | |||
} |
@@ -0,0 +1,373 @@ | |||
package com.bonait.bnframework.common.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,119 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import java.text.ParseException; | |||
import java.text.SimpleDateFormat; | |||
import java.util.Date; | |||
public class DateUtils { | |||
/** | |||
* 比较两个日期的大小,日期格式为yyyy-MM-dd | |||
* | |||
* @param str1 the first date | |||
* @param str2 the second date | |||
* @return true <br/>false | |||
*/ | |||
public static boolean isDateOneBigger(String str1, String str2) { | |||
boolean isBigger = false; | |||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | |||
Date dt1 = null; | |||
Date dt2 = null; | |||
try { | |||
dt1 = sdf.parse(str1); | |||
dt2 = sdf.parse(str2); | |||
} catch (ParseException e) { | |||
e.printStackTrace(); | |||
} | |||
if (dt1.getTime() > dt2.getTime()) { | |||
isBigger = true; | |||
} else if (dt1.getTime() < dt2.getTime()) { | |||
isBigger = false; | |||
} | |||
return isBigger; | |||
} | |||
/** | |||
* 比较两个日期的大小,日期格式为yyyy-MM-dd | |||
* | |||
* @param str1 the first date | |||
* @param str2 the second date | |||
* @return true <br/>false | |||
*/ | |||
public static boolean isDate2Bigger(String str1, String str2) { | |||
boolean isBigger = false; | |||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | |||
Date dt1 = null; | |||
Date dt2 = null; | |||
try { | |||
dt1 = sdf.parse(str1); | |||
dt2 = sdf.parse(str2); | |||
} catch (ParseException e) { | |||
e.printStackTrace(); | |||
} | |||
if (dt1.getTime() > dt2.getTime()) { | |||
isBigger = false; | |||
} else if (dt1.getTime() <= dt2.getTime()) { | |||
isBigger = true; | |||
} | |||
return isBigger; | |||
} | |||
/** | |||
* 比较当前时间和服务器返回时间大小 | |||
* | |||
* @param nowDate | |||
* @param compareDate | |||
* @return | |||
*/ | |||
public static boolean compareDate(String nowDate, String compareDate) { | |||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
try { | |||
Date now = df.parse(nowDate); | |||
Date compare = df.parse(compareDate); | |||
if (now.before(compare)) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} catch (ParseException e) { | |||
e.printStackTrace(); | |||
return false; | |||
} | |||
} | |||
/*** | |||
* 获取当前日期距离过期时间的日期差值 | |||
* @param endTime | |||
* @return | |||
*/ | |||
public static long dateDiff(String endTime) { | |||
long strTime = 0; | |||
// 按照传入的格式生成一个simpledateformate对象 | |||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | |||
long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数 | |||
long nh = 1000 * 60 * 60;// 一小时的毫秒数 | |||
long nm = 1000 * 60;// 一分钟的毫秒数 | |||
long ns = 1000;// 一秒钟的毫秒数 | |||
long diff; | |||
long day = 0; | |||
String nowtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());; | |||
try { | |||
// 获得两个时间的毫秒时间差异 | |||
diff = simpleDateFormat.parse(nowtime).getTime() - simpleDateFormat.parse(endTime).getTime(); | |||
day = diff / nd;// 计算差多少天 | |||
long hour = diff % nd / nh;// 计算差多少小时 | |||
long min = diff % nd % nh / nm;// 计算差多少分钟 | |||
long sec = diff % nd % nh % nm / ns;// 计算差多少秒 | |||
// 输出结果 | |||
strTime = sec; | |||
return strTime; | |||
} catch (ParseException e) { | |||
e.printStackTrace(); | |||
} | |||
return strTime; | |||
} | |||
} | |||
@@ -0,0 +1,588 @@ | |||
package com.bonait.bnframework.common.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); | |||
} | |||
} |
@@ -0,0 +1,47 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import android.view.View; | |||
import android.view.animation.AlphaAnimation; | |||
import android.view.animation.Animation; | |||
import android.view.animation.LinearInterpolator; | |||
/** | |||
* Title:控件闪烁帮助类 | |||
* Description: | |||
* <p> | |||
* Created by pei | |||
* Date: 2018/4/22 | |||
*/ | |||
public class FlashHelper { | |||
private FlashHelper() {} | |||
private static class Holder { | |||
private static FlashHelper instance = new FlashHelper(); | |||
} | |||
public static FlashHelper getInstance() { | |||
return Holder.instance; | |||
} | |||
/**开启View闪烁效果**/ | |||
public void startFlick( View view) { | |||
if (null == view) { | |||
return; | |||
} | |||
Animation alphaAnimation = new AlphaAnimation(1, 0); | |||
alphaAnimation.setDuration(300); | |||
alphaAnimation.setInterpolator(new LinearInterpolator()); | |||
alphaAnimation.setRepeatCount(Animation.INFINITE); | |||
alphaAnimation.setRepeatMode(Animation.REVERSE); | |||
view.startAnimation(alphaAnimation); | |||
} | |||
/**取消View闪烁效果**/ | |||
public void stopFlick( View view) { | |||
if (null == view) { | |||
return; | |||
} | |||
view.clearAnimation(); | |||
} | |||
} |
@@ -0,0 +1,245 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.os.Message; | |||
import android.util.Log; | |||
import com.bonait.bnframework.common.message.MessageManager; | |||
import java.io.BufferedReader; | |||
import java.io.ByteArrayOutputStream; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.InputStreamReader; | |||
import java.io.OutputStream; | |||
import java.net.HttpURLConnection; | |||
import java.net.MalformedURLException; | |||
import java.net.URL; | |||
public class HttpUtils { | |||
public static int httpGet(final String name,final String urlPath) { | |||
new Thread() { | |||
@Override | |||
public void run() { | |||
String content = ""; | |||
// ---------------------请求数据----------------------- | |||
try { | |||
URL url = new URL(urlPath.trim()); | |||
Log.i("logB", "send url=" + url.toString()); | |||
//打开连接 | |||
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); | |||
if (200 == urlConnection.getResponseCode()) { | |||
//得到输入流 | |||
InputStream is = urlConnection.getInputStream(); | |||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||
byte[] buffer = new byte[1024]; | |||
int len = 0; | |||
while (-1 != (len = is.read(buffer))) { | |||
baos.write(buffer, 0, len); | |||
baos.flush(); | |||
} | |||
content = baos.toString("utf-8"); | |||
} else { | |||
} | |||
} catch (MalformedURLException e) { | |||
//e.printStackTrace(); | |||
} catch (IOException e) { | |||
//e.printStackTrace(); | |||
} | |||
MessageManager.getInstance().sendMessage(name,content); | |||
} | |||
}.start(); | |||
return 0; | |||
} | |||
public static void httpPost(final String name,final String urlPath,final String content) | |||
{ | |||
new Thread() | |||
{ | |||
@Override | |||
public void run() { | |||
// TODO Auto-generated method stub | |||
Looper.prepare(); | |||
URL url; | |||
try { | |||
url = new URL(urlPath); | |||
Log.i("logB","content="+content); | |||
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | |||
conn.setConnectTimeout(10000);//5 | |||
conn.setReadTimeout(10000); | |||
conn.setDoOutput(true);// 设置允许输出 | |||
conn.setRequestMethod("POST"); | |||
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");// "Fiddler" | |||
conn.setRequestProperty("Content-Type", "application/json"); | |||
conn.setRequestProperty("Charset", "UTF-8"); | |||
// conn.setRequestProperty("TenantId", ConfigName.getInstance().Shop_Id);//设置header | |||
OutputStream os = conn.getOutputStream(); | |||
os.write(content.getBytes()); | |||
os.close(); | |||
/* 服务器返回的响应码 */ | |||
int code = conn.getResponseCode(); | |||
Log.i("logB","code="+code); | |||
if (code == 200) { | |||
BufferedReader in = new BufferedReader( | |||
new InputStreamReader(conn.getInputStream(), "UTF-8")); | |||
String retData = null; | |||
String responseData = ""; | |||
while ((retData = in.readLine()) != null) { | |||
responseData += retData; | |||
} | |||
Log.i("logB","responseData="+responseData); | |||
in.close(); | |||
if(!name.isEmpty()) { MessageManager.getInstance().sendMessage(name,responseData); } | |||
} else { | |||
if(!name.isEmpty()) { MessageManager.getInstance().sendMessage(name,""); } | |||
} | |||
} catch (MalformedURLException e) { | |||
//e.printStackTrace(); | |||
if(!name.isEmpty()) { MessageManager.getInstance().sendMessage(name,""); } | |||
} catch (IOException e) { | |||
//e.printStackTrace(); | |||
if(!name.isEmpty()) { MessageManager.getInstance().sendMessage(name,""); } | |||
} catch (Exception e) { | |||
// TODO: handle exception | |||
// e.printStackTrace(); | |||
if(!name.isEmpty()) { MessageManager.getInstance().sendMessage(name,""); } | |||
} | |||
Looper.loop(); | |||
} | |||
}.start(); | |||
} | |||
public static int httpGet(final Context context, final String urlPath, final Handler mHandler, final int msgWhat) { | |||
new Thread() { | |||
@Override | |||
public void run() { | |||
int statusCode = -1; | |||
String content = ""; | |||
// ---------------------请求数据----------------------- | |||
try { | |||
URL url = new URL(urlPath.trim()); | |||
Log.i("logB", "send url=" + url.toString()); | |||
//打开连接 | |||
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); | |||
statusCode = urlConnection.getResponseCode(); | |||
if (200 == urlConnection.getResponseCode()) { | |||
//得到输入流 | |||
InputStream is = urlConnection.getInputStream(); | |||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||
byte[] buffer = new byte[1024]; | |||
int len = 0; | |||
while (-1 != (len = is.read(buffer))) { | |||
baos.write(buffer, 0, len); | |||
baos.flush(); | |||
} | |||
content = baos.toString("utf-8"); | |||
sendHandler(context, mHandler, msgWhat, content, statusCode); | |||
} else { | |||
sendHandler(context, mHandler, msgWhat, content, statusCode); | |||
} | |||
} catch (MalformedURLException e) { | |||
sendHandler(context, mHandler, msgWhat, content, statusCode); | |||
e.printStackTrace(); | |||
} catch (IOException e) { | |||
sendHandler(context, mHandler, msgWhat, content, statusCode); | |||
e.printStackTrace(); | |||
} | |||
} | |||
}.start(); | |||
return 0; | |||
} | |||
public static void httpPost(final Context context,final String urlPath, final String content, final Handler handler, final int msgWhat){ | |||
new Thread() | |||
{ | |||
@Override | |||
public void run() { | |||
// TODO Auto-generated method stub | |||
Looper.prepare(); | |||
URL url; | |||
try { | |||
url = new URL(urlPath); | |||
Log.i("logB","content="+content); | |||
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | |||
conn.setConnectTimeout(10000);//5 | |||
conn.setReadTimeout(10000); | |||
conn.setDoOutput(true);// 设置允许输出 | |||
conn.setRequestMethod("POST"); | |||
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");// "Fiddler" | |||
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); | |||
conn.setRequestProperty("Charset", "UTF-8"); | |||
OutputStream os = conn.getOutputStream(); | |||
os.write(content.getBytes()); | |||
os.close(); | |||
/* 服务器返回的响应码 */ | |||
int code = conn.getResponseCode(); | |||
Log.i("logB","code="+code); | |||
if (code == 200) { | |||
BufferedReader in = new BufferedReader( | |||
new InputStreamReader(conn.getInputStream(), "UTF-8")); | |||
String retData = null; | |||
String responseData = ""; | |||
while ((retData = in.readLine()) != null) { | |||
responseData += retData; | |||
} | |||
Log.i("logB","responseData="+responseData); | |||
in.close(); | |||
sendHandler(context,handler,msgWhat,responseData,code); | |||
} else { | |||
sendHandler(context,handler,msgWhat,"",code); | |||
} | |||
} catch (MalformedURLException e) { | |||
e.printStackTrace(); | |||
Log.i("logB","MalformedURLException"); | |||
sendHandler(context,handler,msgWhat,"",-1); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
Log.i("logB","IOException"); | |||
sendHandler(context,handler,msgWhat,"",-1); | |||
} catch (Exception e) { | |||
// TODO: handle exception | |||
e.printStackTrace(); | |||
sendHandler(context,handler,msgWhat,"",-1); | |||
} | |||
Looper.loop(); | |||
} | |||
}.start(); | |||
} | |||
private static void sendHandler(Context context, Handler mHandler, int msgWhat, String content, int statusCode){ | |||
if (context != null) { | |||
Message msg = mHandler.obtainMessage(msgWhat); | |||
Bundle bundle = new Bundle(); | |||
bundle.putString("content", content); // 往Bundle中存放数据 | |||
bundle.putInt("statusCode", statusCode); // 往Bundle中存放statusCode | |||
msg.setData(bundle); | |||
msg.obj=context; | |||
mHandler.sendMessage(msg); | |||
} | |||
} | |||
} |
@@ -0,0 +1,5 @@ | |||
package com.bonait.bnframework.common.helper.I; | |||
public interface IMessage { | |||
void MessageRecive(String topic, String Message); | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.bonait.bnframework.common.helper.I; | |||
import com.bonait.bnframework.common.db.res.AlertLogEnum; | |||
import com.bonait.bnframework.common.db.res.UserLogEnum; | |||
public interface IMessageLogNotify { | |||
void ErrorMsg(String msg); | |||
void InfoMsg(String msg); | |||
void WarnMsg(String msg); | |||
void UserMsg(UserLogEnum type, String msg); | |||
void AlertMsg(AlertLogEnum type, String msg); | |||
} |
@@ -0,0 +1,5 @@ | |||
package com.bonait.bnframework.common.helper.I; | |||
public interface IReadCallBack<T> { | |||
void onSuccess(T t); | |||
} |
@@ -0,0 +1,5 @@ | |||
package com.bonait.bnframework.common.helper.I; | |||
public interface IRun { | |||
void Run(); | |||
} |
@@ -0,0 +1,5 @@ | |||
package com.bonait.bnframework.common.helper.I; | |||
public interface IRunT<T> { | |||
void Run(T t); | |||
} |
@@ -0,0 +1,7 @@ | |||
package com.bonait.bnframework.common.helper.I; | |||
public interface IThread { | |||
void Run() throws InterruptedException; | |||
void RunComplete() throws InterruptedException; | |||
} |
@@ -0,0 +1,7 @@ | |||
package com.bonait.bnframework.common.helper.I; | |||
public interface IWriteCallBack { | |||
void onSuccess(); | |||
void onFailure(String ErrorMsg); | |||
} |
@@ -0,0 +1,41 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import com.google.gson.Gson; | |||
import java.lang.reflect.Type; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
public class Json<T>{ | |||
/** | |||
* 对象转化json | |||
*/ | |||
public String objectToJson(Class<T> clazz,T pointKMBean) { | |||
Gson gson = new Gson(); | |||
String jsonStr = gson.toJson(pointKMBean, clazz); | |||
return jsonStr; | |||
} | |||
/** | |||
* json转化对象 | |||
*/ | |||
public T jsonToobject(Class<T> clazz,String objectJson) { | |||
Gson gson = new Gson(); | |||
T pointKMBean = gson.fromJson(objectJson, clazz); | |||
return pointKMBean; | |||
} | |||
/** | |||
* 获取List | |||
*/ | |||
public static <T> List<T> jsonToListobject(Class<T> clazz, String strJson) { | |||
List<T> datalist = new ArrayList<>(); | |||
if (null == strJson) { | |||
return datalist; | |||
} | |||
Gson gson = new Gson(); | |||
// datalist = gson.fromJson(strJson, new TypeToken<List<T>>() {}.getType()); | |||
//改为下面的方法,clazz传入实际想要解析出来的类 | |||
Type listType = com.google.gson.internal.$Gson$Types.newParameterizedTypeWithOwner(null, ArrayList.class, clazz); | |||
datalist = gson.fromJson(strJson, listType); | |||
return datalist; | |||
} | |||
} |
@@ -0,0 +1,331 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import android.content.Context; | |||
import android.net.ConnectivityManager; | |||
import android.net.NetworkInfo; | |||
import android.util.Log; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.helper.I.IMessage; | |||
import com.bonait.bnframework.common.helper.I.IRun; | |||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; | |||
import org.eclipse.paho.client.mqttv3.MqttCallback; | |||
import org.eclipse.paho.client.mqttv3.MqttClient; | |||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions; | |||
import org.eclipse.paho.client.mqttv3.MqttException; | |||
import org.eclipse.paho.client.mqttv3.MqttMessage; | |||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; | |||
import java.io.IOException; | |||
import java.io.InputStreamReader; | |||
import java.io.LineNumberReader; | |||
/** | |||
* mqtt帮助类 | |||
*/ | |||
public class MQTT { | |||
//region 单例模式 | |||
private static volatile MQTT instance = null; | |||
public static MQTT get() { | |||
MQTT manager = instance; | |||
if (manager == null) { | |||
synchronized (MQTT.class) { | |||
manager = instance; | |||
if (manager == null) { | |||
manager = new MQTT(); | |||
instance = manager; | |||
} | |||
} | |||
} | |||
return manager; | |||
} | |||
private MQTT() { | |||
// Connect("emqx_u_block","emqx_p_admin8765490789","10.2.1.21",1883); | |||
} | |||
//endregion | |||
//region 变量 | |||
private String string_IMEI_ID = "奶茶机"+java.util.UUID.randomUUID().toString(); | |||
private String host = "tcp://broker.emqx.io:1883"; | |||
private String userName = "emqx_u_block"; | |||
private String passWord = "emqx_p_admin8765490789"; | |||
private MqttClient mqttClient;//客户端 | |||
private MqttConnectOptions options;//配置 保存控制客户端连接到服务器的方式的选项集。 | |||
public IMessage callback=null;//消息回调 | |||
public IRun ConnectOk=null; | |||
public IRun Disconnect=null; | |||
public boolean IsConnect=false; | |||
//endregion | |||
//region 公有函数 | |||
/** | |||
* 初始化配置Mqtt | |||
* @param name | |||
* @param Pass | |||
* @param Ip | |||
* @param post | |||
*/ | |||
public void Connect(String name, String Pass, final String Ip, int post) { | |||
try { | |||
userName=name; | |||
passWord=Pass; | |||
host="tcp://"+ Ip+":"+post; | |||
//(1)主机地址(2)客户端ID,一般以客户端唯一标识符(不能够和其它客户端重名)(3)最后一个参数是指数据保存在内存(具体保存什么数据,以后再说,其实现在我也不是很确定) | |||
mqttClient = new MqttClient(host, string_IMEI_ID, new MemoryPersistence()); | |||
} catch (MqttException e) { | |||
e.printStackTrace(); | |||
} | |||
options = new MqttConnectOptions();//MQTT的连接设置 | |||
options.setCleanSession(true);//设置是否清空session,这里如果设置为false表示服务器会保留客户端的连接记录,这里设置为true表示每次连接到服务器都以新的身份连接 | |||
options.setUserName(userName);//设置连接的用户名(自己的服务器没有设置用户名) | |||
options.setPassword(passWord.toCharArray());//设置连接的密码(自己的服务器没有设置密码) | |||
mqttClient.setCallback(new MqttCallback() { | |||
@Override//连接丢失后,会执行这里 | |||
public void connectionLost(Throwable throwable) { | |||
IsConnect=false; | |||
MessageLog.ShowInfo("mqtt断开连接,尝试重新连接..."); | |||
if(Disconnect!=null) | |||
{ | |||
Disconnect.Run(); | |||
} | |||
Reconnect(); | |||
} | |||
@Override//获取的消息会执行这里--arg0是主题,arg1是消息 | |||
public void messageArrived(final String ssr, MqttMessage mqttMessage) throws Exception { | |||
final String mqtt_zhuti = ssr;//主题 | |||
final String mqtt_message = mqttMessage.toString();//消息 | |||
if(callback!=null) | |||
{ | |||
callback.MessageRecive(mqtt_zhuti,mqtt_message); | |||
} | |||
} | |||
@Override//订阅主题后会执行到这里 | |||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) { | |||
} | |||
}); | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
boolean status = false; | |||
while (!status) { | |||
try { | |||
//status为0则代表通,为1则代表不通。 | |||
status =ping2(Ip,1,1); | |||
Thread.sleep(1000); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowInfo("MQTT " + Ip + " 网络验证失败"); | |||
} catch (Exception e) { | |||
MessageLog.ShowInfo("MQTT " + Ip+ " 网络验证失败"); | |||
} | |||
} | |||
ConnMqttBroken(true); | |||
} catch (Exception e) { | |||
} | |||
} | |||
}).start(); | |||
} | |||
/** | |||
* Ping PLC地址是否通畅 | |||
* @param address | |||
* @param pingTimes ping的次数 | |||
* @param timeOut 超时时间 10 | |||
* @return | |||
*/ | |||
public static boolean ping2(String address, int pingTimes, int timeOut) { | |||
Process process = null; | |||
try { | |||
process = Runtime.getRuntime().exec( "ping " + "-c " + pingTimes + " -w " + timeOut+ " "+address); | |||
InputStreamReader r = new InputStreamReader(process.getInputStream()); | |||
LineNumberReader returnData = new LineNumberReader(r); | |||
String returnMsg=""; | |||
String line = ""; | |||
while ((line = returnData.readLine()) != null) { | |||
System.out.println(line); | |||
returnMsg += line; | |||
} | |||
if(returnMsg.indexOf("100% packet loss")!=-1){ | |||
System.out.println("与 " +address +" 连接不畅通."); | |||
return false; | |||
} else{ | |||
System.out.println("与 " +address +" 连接畅通."); | |||
return true; | |||
} | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
return false; | |||
} | |||
/** | |||
* 连接 或者断开MQTT | |||
* @param bloConn | |||
*/ | |||
public void ConnMqttBroken(final boolean bloConn) | |||
{ | |||
// 必须开启新的线程执行 | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
if (bloConn) { | |||
try { | |||
if (mqttClient.isConnected() == false) { | |||
mqttClient.connect(options);//连接服务器,连接不上会阻塞在这 | |||
} | |||
MessageLog.ShowInfo("mqtt连接成功!"); | |||
IsConnect=true; | |||
if(ConnectOk!=null) | |||
{ | |||
ConnectOk.Run(); | |||
} | |||
} catch (MqttException e) { | |||
Log.i("MQTT", "mqtt重连接失败!"+e.getMessage()); | |||
} | |||
} else { | |||
try { | |||
if (mqttClient!=null && mqttClient.isConnected()) { | |||
mqttClient.disconnect(); | |||
} | |||
IsConnect=false; | |||
MessageLog.ShowInfo("mqtt断开成功!"); | |||
} catch (MqttException e) { | |||
MessageLog.ShowError("mqtt断开失败!"+e.getMessage()); | |||
} | |||
} | |||
} | |||
}).start(); | |||
} | |||
/** | |||
* 订阅主题 | |||
* @param topic | |||
*/ | |||
public void Subscrib(String[] topic) | |||
{ | |||
if (mqttClient == null || !mqttClient.isConnected()) | |||
{ | |||
return; | |||
} | |||
try | |||
{ | |||
for (String str:topic) | |||
{ | |||
MessageLog.ShowInfo("mqtt订阅主题:"+str); | |||
Log.v("IotMqttService:topic="+str, "订阅topic:"+str); | |||
mqttClient.subscribe(str,2); | |||
} | |||
} | |||
catch(MqttException e) | |||
{ | |||
MessageLog.ShowError("mqtt订阅主题失败!"+topic); | |||
} | |||
} | |||
/** | |||
* 发布 (向服务器发送消息) | |||
* @param topic | |||
* @param message | |||
*/ | |||
public void publish(String topic, String message) { | |||
Integer qos = 2; | |||
Boolean retained = false; | |||
try { | |||
if(mqttClient.isConnected()) | |||
{ | |||
//Log.v("IotMqttService:topic="+topic, "Mqtt发送消息:"+message); | |||
//参数分别为:主题、消息的字节数组、服务质量、是否在服务器保留断开连接后的最后一条消息 | |||
mqttClient.publish(topic, message.getBytes(), qos.intValue(), retained.booleanValue()); | |||
} | |||
} catch (MqttException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
/** | |||
* 判断网络是否连接 | |||
*/ | |||
private boolean isConnectIsNomarl() { | |||
ConnectivityManager connectivityManager = (ConnectivityManager) ConfigName.getInstance().dishesCon.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); | |||
NetworkInfo info = connectivityManager.getActiveNetworkInfo(); | |||
if (info != null && info.isAvailable()) { | |||
String name = info.getTypeName(); | |||
Log.i("网络", "当前网络名称:" + name); | |||
return true; | |||
} else { | |||
Log.i("网络", "没有可用网络"); | |||
/*没有可用网络的时候,延迟3秒再尝试重连*/ | |||
// new Handler().postDelayed(new Runnable() { | |||
// @Override | |||
// public void run() { | |||
// ConnMqttBroken(true); | |||
// } | |||
// }, 3000); | |||
return false; | |||
} | |||
} | |||
/** | |||
* 重新连接 | |||
*/ | |||
private void Reconnect() | |||
{ | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
Thread.sleep(2000); | |||
if (isConnectIsNomarl()) | |||
{ | |||
while (!isConnectIsNomarl()) | |||
{ | |||
try { | |||
Thread.sleep(2000); | |||
} catch (InterruptedException e) { | |||
} | |||
} | |||
} | |||
} catch (InterruptedException e) { | |||
} | |||
boolean flag = false; | |||
while (!mqttClient.isConnected()) | |||
{ | |||
try | |||
{ | |||
Log.i("MQTT", "mqtt重连中!"); | |||
ConnMqttBroken(true); | |||
Thread.sleep(3000); | |||
} | |||
catch (Exception ex) | |||
{ | |||
if (!flag) | |||
{ | |||
flag = true; | |||
} | |||
} | |||
} | |||
} | |||
}).start(); | |||
} | |||
//endregion | |||
} |
@@ -0,0 +1,12 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import android.content.Context; | |||
import android.util.Log; | |||
import android.widget.Toast; | |||
public class MY { | |||
public static void show(Context context, String str) { | |||
Toast.makeText(context, str, (int) 0).show(); | |||
Log.i(context.getPackageName(), str); | |||
} | |||
} |
@@ -0,0 +1,89 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import com.bonait.bnframework.common.db.res.AlertLogEnum; | |||
import com.bonait.bnframework.common.db.res.UserLogEnum; | |||
import com.bonait.bnframework.common.helper.I.IMessageLogNotify; | |||
import com.bonait.bnframework.common.helper.I.IRun; | |||
import java.text.SimpleDateFormat; | |||
import java.util.Date; | |||
public class MessageLog { | |||
public static IMessageLogNotify MsgNotify; | |||
/** | |||
* 日志触发通知 | |||
*/ | |||
public static IRun AddNotify; | |||
public static String MsgInfo = ""; | |||
public static void ShowInfo(String msg) { | |||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
Date date = new Date(); | |||
String tempMsg = formatter.format(date) + ":" + msg; | |||
if(MsgInfo.length()>=8000)MsgInfo=""; | |||
MsgInfo = tempMsg + "\r\n" + MsgInfo; | |||
if (MsgNotify != null) | |||
MsgNotify.InfoMsg(tempMsg); | |||
if (AddNotify != null) AddNotify.Run(); | |||
} | |||
public static void ShowWarning(String msg) { | |||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
Date date = new Date(); | |||
String tempMsg = formatter.format(date) + ":" + msg; | |||
if(MsgInfo.length()>=8000)MsgInfo=""; | |||
MsgInfo = tempMsg + "\r\n" + MsgInfo; | |||
if (MsgNotify != null) | |||
MsgNotify.WarnMsg(tempMsg); | |||
if (AddNotify != null) AddNotify.Run(); | |||
} | |||
public static void ShowError(String msg) { | |||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
Date date = new Date(); | |||
String tempMsg = formatter.format(date) + ":" + msg; | |||
if(MsgInfo.length()>=8000)MsgInfo=""; | |||
MsgInfo = tempMsg + "\r\n" + MsgInfo; | |||
if (MsgNotify != null) | |||
MsgNotify.ErrorMsg(tempMsg); | |||
if (AddNotify != null) AddNotify.Run(); | |||
} | |||
/** | |||
* 用户操作日志 | |||
* @param type | |||
* @param msg | |||
*/ | |||
public static void ShowUserMessage(UserLogEnum type, String msg) | |||
{ | |||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
Date date = new Date(); | |||
String tempMsg = formatter.format(date) + ":" + msg; | |||
if(MsgInfo.length()>=8000)MsgInfo=""; | |||
MsgInfo = tempMsg + "\r\n" + MsgInfo; | |||
if (MsgNotify != null) | |||
MsgNotify.UserMsg(type,tempMsg); | |||
if (AddNotify != null) AddNotify.Run(); | |||
} | |||
/** | |||
* 预警日志 | |||
* @param type | |||
* @param msg | |||
*/ | |||
public static void ShowAlertMessage(AlertLogEnum type, String msg) | |||
{ | |||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
Date date = new Date(); | |||
String tempMsg = formatter.format(date) + ":" + msg; | |||
if(MsgInfo.length()>=8000)MsgInfo=""; | |||
MsgInfo = tempMsg + "\r\n" + MsgInfo; | |||
if (MsgNotify != null) | |||
MsgNotify.AlertMsg(type,tempMsg); | |||
if (AddNotify != null) AddNotify.Run(); | |||
} | |||
} |
@@ -0,0 +1,96 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import android.content.Context; | |||
import android.graphics.Bitmap; | |||
import android.graphics.BitmapFactory; | |||
import android.os.Handler; | |||
import android.os.Message; | |||
import android.util.AttributeSet; | |||
import android.widget.ImageView; | |||
import android.widget.Toast; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.net.HttpURLConnection; | |||
import java.net.URL; | |||
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; | |||
//子线程不能操作UI,通过Handler设置图片 | |||
private Handler handler = new Handler() { | |||
@Override | |||
public void handleMessage(Message msg) { | |||
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(); | |||
break; | |||
case SERVER_ERROR: | |||
Toast.makeText(getContext(),"服务器发生错误",Toast.LENGTH_SHORT).show(); | |||
break; | |||
} | |||
} | |||
}; | |||
public MyImageView(Context context, AttributeSet attrs, int defStyleAttr) { | |||
super(context, attrs, defStyleAttr); | |||
} | |||
public MyImageView(Context context) { | |||
super(context); | |||
} | |||
public MyImageView(Context context, AttributeSet attrs) { | |||
super(context, attrs); | |||
} | |||
//设置网络图片 | |||
public void setImageURL(final String path) { | |||
//开启一个线程用于联网 | |||
new Thread() { | |||
@Override | |||
public void run() { | |||
try { | |||
//把传过来的路径转成URL | |||
URL url = new URL(path); | |||
//获取连接 | |||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | |||
//使用GET方法访问网络 | |||
connection.setRequestMethod("GET"); | |||
//超时时间为10秒 | |||
connection.setConnectTimeout(10000); | |||
//获取返回码 | |||
int code = connection.getResponseCode(); | |||
if (code == 200) { | |||
InputStream inputStream = connection.getInputStream(); | |||
//使用工厂把网络的输入流生产Bitmap | |||
Bitmap bitmap = BitmapFactory.decodeStream(inputStream); | |||
//利用Message把图片发给Handler | |||
Message msg = Message.obtain(); | |||
msg.obj = bitmap; | |||
msg.what = GET_DATA_SUCCESS; | |||
handler.sendMessage(msg); | |||
inputStream.close(); | |||
}else { | |||
//服务启发生错误 | |||
handler.sendEmptyMessage(SERVER_ERROR); | |||
} | |||
} catch (IOException e) { | |||
//e.printStackTrace(); | |||
//网络连接错误 | |||
handler.sendEmptyMessage(NETWORK_ERROR); | |||
}catch (Exception e) | |||
{ | |||
//网络连接错误 | |||
handler.sendEmptyMessage(NETWORK_ERROR); | |||
} | |||
} | |||
}.start(); | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import com.bonait.bnframework.common.helper.I.IRun; | |||
import java.util.concurrent.ConcurrentHashMap; | |||
/** | |||
* 上升沿操作 | |||
*/ | |||
public class RTrig { | |||
private static volatile ConcurrentHashMap<String, RTrig> _Instance; | |||
public static RTrig get(String name) { | |||
if (_Instance == null) | |||
_Instance = new ConcurrentHashMap<String, RTrig>(); | |||
if (!_Instance.containsKey(name)) | |||
_Instance.put(name, new RTrig()); | |||
return _Instance.get(name); | |||
} | |||
private RTrig() { | |||
} | |||
private boolean flag=false; | |||
private boolean Q=false; | |||
public boolean getQ() { | |||
return Q; | |||
} | |||
private void setIN(boolean falag) { | |||
Q = falag && !flag; | |||
flag = falag; | |||
} | |||
public void Start(boolean IN, IRun callback) { | |||
setIN(IN); | |||
if (Q) | |||
callback.Run(); | |||
} | |||
} |
@@ -0,0 +1,92 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import android.content.Context; | |||
import android.os.Environment; | |||
import android.util.Log; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.db.file.DBHelper; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.InputStream; | |||
/** | |||
* SD卡操作 | |||
*/ | |||
public class SdCart { | |||
//region 单例模式 | |||
private static SdCart mInstance; //实例变量设置私有,防止直接通过类名访问 | |||
private SdCart() { //默认构造函数私有,防止类外直接new创建对象 | |||
} | |||
public static synchronized SdCart getInstance() { //静态同步方法作为唯一的实例对象获取方式 | |||
if (mInstance==null) { | |||
mInstance = new SdCart(); | |||
} | |||
return mInstance; | |||
} | |||
//endregion | |||
/** | |||
* 初始化数据库到SD卡 | |||
*/ | |||
public void initSD() { | |||
File sdDir = null; | |||
boolean sdCardExist = Environment.getExternalStorageState().equals( | |||
Environment.MEDIA_MOUNTED); | |||
if (sdCardExist) { | |||
sdDir = Environment.getExternalStorageDirectory(); | |||
ConfigName.getInstance().sdCardPath = sdDir.toString(); | |||
} | |||
ConfigName.getInstance().appResRoot = ConfigName.getInstance().sdCardPath + "/hblxiaochaodb"; | |||
ConfigName.getInstance().dbPath = ConfigName.getInstance().appResRoot + "/hbl.db"; | |||
File rootFile = new File(ConfigName.getInstance().appResRoot); | |||
if (!rootFile.exists()) //创建目录 | |||
{ Log.i("日志",ConfigName.getInstance().sdCardPath); | |||
rootFile.mkdirs(); | |||
} | |||
File file = new File(ConfigName.getInstance().dbPath); | |||
if(!file.exists())//文件不存在那么创建数据库 | |||
{ | |||
Log.i("日志","初始化数据库:文件不存在准备新建!"); | |||
//1.复制本地文件到SD卡 | |||
copyFilesFassets(ConfigName.getInstance().dishesCon, ConfigName.getInstance().dbPath); | |||
//2.创建数据库结构 | |||
DBHelper.getInstance(ConfigName.getInstance().dishesCon).CreateTables(); | |||
} | |||
Log.i("日志","初始化数据库目录:"+ConfigName.getInstance().dbPath); | |||
} | |||
/** | |||
* 从assets目录中复制整个文件夹内容 | |||
* | |||
* @param context | |||
* Context 使用CopyFiles类的Activity | |||
* @param newPath | |||
* String 复制后路径 如:xx:/bb/cc | |||
*/ | |||
public void copyFilesFassets(Context context, String newPath) { | |||
try { | |||
// 如果是文件 | |||
InputStream is = context.getAssets().open("hbl.db"); | |||
FileOutputStream fos = new FileOutputStream(new File(newPath)); | |||
byte[] buffer = new byte[1024]; | |||
int byteCount = 0; | |||
while ((byteCount = is.read(buffer)) != -1) {// 循环从输入流读取 buffer字节 | |||
fos.write(buffer, 0, byteCount);// 将读取的输入流写入到输出流 | |||
} | |||
fos.flush();// 刷新缓冲区 | |||
is.close(); | |||
fos.close(); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,132 @@ | |||
package com.bonait.bnframework.common.helper; | |||
//import com.bpa.scalage.mode.Order.BPA_SubOrder; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
/** | |||
* 排序tools | |||
*/ | |||
public class SortTools { | |||
// /** | |||
// * 调用此方法 | |||
// * | |||
// * @param list | |||
// * @return | |||
// */ | |||
// public static List<BPA_SubOrder> listClassSort(List<BPA_SubOrder> list) { | |||
// BPA_SubOrder[] array = (BPA_SubOrder[]) list.toArray(new BPA_SubOrder[list.size()]); | |||
// for (int i = 0; i < array.length - 1; i++) { | |||
// for (int j = i + 1; j < array.length; j++) { | |||
// if (singleSort(array[i].sortNumber, array[j].sortNumber) == 1) { | |||
// BPA_SubOrder temp = array[i]; | |||
// array[i] = array[j]; | |||
// array[j] = temp; | |||
// } | |||
// } | |||
// } | |||
// return Arrays.asList(array); | |||
// } | |||
/** | |||
* 调用此方法 | |||
* | |||
* @param list | |||
* @return | |||
*/ | |||
public static List<String> listSort(List<String> list) { | |||
String[] array = (String[]) list.toArray(new String[list.size()]); | |||
for (int i = 0; i < array.length - 1; i++) { | |||
for (int j = i + 1; j < array.length; j++) { | |||
if (singleSort(array[i], array[j]) == 1) { | |||
String temp = array[i]; | |||
array[i] = array[j]; | |||
array[j] = temp; | |||
} | |||
} | |||
} | |||
return Arrays.asList(array); | |||
} | |||
/** | |||
* 比较两个字符 | |||
* | |||
* @param one | |||
* @param two | |||
* @return | |||
*/ | |||
public static int singleSort(String one, String two) { | |||
int[] left = stringToAscii(one); | |||
int[] right = stringToAscii(two); | |||
int size = left.length < right.length ? left.length : right.length; | |||
for (int i = 0; i < size; i++) { | |||
// 大于10000说明是汉字 并且在判断一下是否相等 不相等在判断 减少判断次数 | |||
if (left[i] > 10000 && right[i] > 10000 && left[i] != right[i]) { | |||
if (chineseCompare(one, two, i) != 0) { | |||
return chineseCompare(one, two, i); | |||
} | |||
} else { | |||
if (intCompare(left[i], right[i]) != 0) { | |||
return intCompare(left[i], right[i]); | |||
} | |||
} | |||
} | |||
return intCompare(left.length, right.length); | |||
} | |||
/** | |||
* 汉字比较 | |||
* | |||
* @param one | |||
* @param two | |||
* @param i | |||
* @return | |||
*/ | |||
private static int chineseCompare(String one, String two, int i) { | |||
String substringleft; | |||
String substringright; | |||
if (i > 0) { | |||
substringleft = one.substring(i - 1, i); | |||
substringright = two.substring(i - 1, i); | |||
} else { | |||
substringleft = one.substring(0, i); | |||
substringright = two.substring(0, i); | |||
} | |||
// 获得汉字拼音首字母的ASCII码 | |||
// 把他里面的CharacterParser.convert方法 改成 public static 不然会报错 | |||
int subLeft = stringToAscii(CharacterParser.convert(substringleft) | |||
.substring(0, 1))[0]; | |||
int subRight = stringToAscii(CharacterParser.convert(substringright) | |||
.substring(0, 1))[0]; | |||
System.out.println(CharacterParser.convert(substringleft).substring(0, | |||
1)); | |||
return intCompare(subLeft, subRight); | |||
} | |||
/** | |||
* 数字比较 | |||
* @param subLeft | |||
* @param subRight | |||
* @return | |||
*/ | |||
private static int intCompare(int subLeft, int subRight) { | |||
if (subLeft > subRight) { | |||
return 1; | |||
} else if (subLeft < subRight) { | |||
return -1; | |||
} else { | |||
return 0; | |||
} | |||
} | |||
/** | |||
* 获得ASCII码 | |||
* @param value | |||
* @return | |||
*/ | |||
public static int[] stringToAscii(String value) { | |||
char[] chars = value.toCharArray(); | |||
int j = chars.length; | |||
int[] array = new int[j]; | |||
for (int i = 0; i < chars.length; i++) { | |||
array[i] = (int) chars[i]; | |||
} | |||
return array; | |||
} | |||
} |
@@ -0,0 +1,75 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import com.bonait.bnframework.common.helper.I.IThread; | |||
import com.bonait.bnframework.common.helper.mode.ThreadModel; | |||
import java.util.concurrent.ConcurrentHashMap; | |||
public class ThreadManager { | |||
private static volatile ThreadManager _Instance; | |||
public static ThreadManager Get() { | |||
if (_Instance == null) | |||
_Instance = new ThreadManager(); | |||
return _Instance; | |||
} | |||
private ThreadManager() { | |||
} | |||
public long RestartInterval = 2000; | |||
ConcurrentHashMap<String, ThreadModel> ts = new ConcurrentHashMap<>(); | |||
private void Sleep(long millis) { | |||
try { | |||
Thread.sleep(millis); | |||
} catch (InterruptedException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
public void StartLong(String Key, boolean IsRestart, IThread _thread) { | |||
if (!ts.containsKey(Key)) { | |||
ts.put(Key, new ThreadModel()); | |||
ts.get(Key).RunThread = _thread; | |||
ts.get(Key).ThreadObj = new Thread(() -> { | |||
MessageLog.ShowInfo("启动线程:" + Key); | |||
while (!ts.get(Key).IsCancel) { | |||
if (IsRestart) { | |||
try { | |||
ts.get(Key).RunThread.Run(); | |||
} catch (Exception ex) { | |||
MessageLog.ShowError("多线程:" + Key + "运行发生异常,已重启,errorMsg:" + ex.toString()); | |||
Sleep(RestartInterval); | |||
} | |||
} else { | |||
try { | |||
ts.get(Key).RunThread.Run(); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("多线程:" + Key + "运行发生异常,已退出,errorMsg:" + e.toString()); | |||
} | |||
} | |||
} | |||
try { | |||
ts.get(Key).RunThread.RunComplete(); | |||
MessageLog.ShowInfo("线程:[" + Key + "]--执行完成"); | |||
} catch (InterruptedException e) { | |||
throw new RuntimeException(e); | |||
} | |||
ts.remove(Key); | |||
}); | |||
ts.get(Key).ThreadObj.setName(Key); | |||
ts.get(Key).ThreadObj.start(); | |||
} else { | |||
MessageLog.ShowWarning("任务-[" + Key + "]-已存在"); | |||
} | |||
} | |||
public void Stop(String Key) { | |||
if (ts.containsKey(Key)) { | |||
ts.get(Key).IsCancel = true; | |||
} | |||
} | |||
} |
@@ -0,0 +1,246 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import android.content.Context; | |||
import android.content.res.AssetManager; | |||
import android.graphics.Bitmap; | |||
import android.graphics.BitmapFactory; | |||
import android.graphics.Canvas; | |||
import android.graphics.Color; | |||
import android.graphics.Paint; | |||
import android.graphics.PorterDuff; | |||
import android.graphics.PorterDuffXfermode; | |||
import android.graphics.Rect; | |||
import android.graphics.RectF; | |||
import android.os.Build; | |||
import android.os.Environment; | |||
import android.view.View; | |||
import com.google.gson.Gson; | |||
import org.json.JSONException; | |||
import org.json.JSONObject; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.util.HashMap; | |||
import java.util.Iterator; | |||
import java.util.Map; | |||
/* | |||
* 系统工具类 | |||
* */ | |||
public class Tools { | |||
/** | |||
* 根据O object 获取值和变量 | |||
* @param object | |||
* @return | |||
*/ | |||
public static Map<String, Object> getObjValue(Object object) { | |||
String dataStr = new Gson().toJson(object); | |||
JSONObject json = null; | |||
Map<String, Object> map = new HashMap<String, Object>(); | |||
try { | |||
json = new JSONObject(dataStr); | |||
Iterator it = json.keys(); | |||
while (it.hasNext()) { | |||
String key = (String) it.next(); | |||
Object value = json.get(key); | |||
map.put(key, value); | |||
} | |||
} catch (JSONException e) { | |||
e.printStackTrace(); | |||
} | |||
return map; | |||
} | |||
/** | |||
* 判断有没有sd卡 | |||
* @return | |||
*/ | |||
public boolean hasSDCard() { | |||
String status = Environment.getExternalStorageState(); | |||
if (!status.equals(Environment.MEDIA_MOUNTED)) { | |||
return false; | |||
} | |||
return true; | |||
} | |||
/** | |||
* 获得根目录路径 | |||
* @return | |||
*/ | |||
public String getRootFilePath() { | |||
if (hasSDCard()) { | |||
return Environment.getExternalStorageDirectory().getAbsolutePath() | |||
+ "/";// filePath:/sdcard/ | |||
} else { | |||
return Environment.getDataDirectory().getAbsolutePath() + "/data/"; // filePath: | |||
// /data/data/ | |||
} | |||
} | |||
/** | |||
* 将定义的view装换成 bitmap格式 | |||
* @param view | |||
* @return | |||
*/ | |||
public Bitmap convertViewToBitmap(View view) { | |||
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), | |||
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); | |||
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); | |||
view.buildDrawingCache(); | |||
Bitmap bitmap = view.getDrawingCache(); | |||
return bitmap; | |||
} | |||
/** | |||
* 将px值转换为dip或dp值,保证尺寸大小不变 | |||
* @param context | |||
* @param pxValue | |||
* @return | |||
*/ | |||
public int px2dip(Context context, float pxValue) { | |||
final float scale = context.getResources().getDisplayMetrics().density; | |||
return (int) (pxValue / scale + 0.5f); | |||
} | |||
/** | |||
* 将dip或dp值转换为px值,保证尺寸大小不变 | |||
* @param context | |||
* @param dipValue | |||
* @return | |||
*/ | |||
public int dip2px(Context context, float dipValue) { | |||
final float scale = context.getResources().getDisplayMetrics().density; | |||
return (int) (dipValue * scale + 0.5f); | |||
} | |||
/** | |||
* 将px值转换为sp值,保证文字大小不变 | |||
* @param context | |||
* @param pxValue | |||
* @return | |||
*/ | |||
public int px2sp(Context context, float pxValue) { | |||
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; | |||
return (int) (pxValue / fontScale + 0.5f); | |||
} | |||
/** | |||
* 将px值转换为sp值,保证文字大小不变 | |||
* @param context | |||
* @param spValue | |||
* @return | |||
*/ | |||
public int sp2px(Context context, float spValue) { | |||
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; | |||
return (int) (spValue * fontScale + 0.5f); | |||
} | |||
public boolean hasGingerbread() { | |||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD; | |||
} | |||
public boolean hasHoneycomb() { | |||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; | |||
} | |||
/** | |||
* 检查是否存在SDCard | |||
* | |||
* @return | |||
*/ | |||
public boolean hasSdcard() { | |||
String state = Environment.getExternalStorageState(); | |||
if (state.equals(Environment.MEDIA_MOUNTED)) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
private final int STROKE_WIDTH = 4; | |||
/** | |||
* 从assets资源中获取图片 | |||
* @param context | |||
* @param filename | |||
* @return | |||
*/ | |||
public Bitmap getBitmap(Context context, String filename) { | |||
Bitmap image = null; | |||
AssetManager am = context.getResources().getAssets(); | |||
try { | |||
InputStream is = am.open(filename); | |||
image = BitmapFactory.decodeStream(is); | |||
is.close(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
return image; | |||
} | |||
public Bitmap toRoundBitmap(Context context, int id) { | |||
// Bitmap bitmap = getBitmap(context, filename); | |||
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), id); | |||
int width = bitmap.getWidth(); | |||
int height = bitmap.getHeight(); | |||
float roundPx; | |||
float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom; | |||
if (width <= height) { | |||
roundPx = width / 2; | |||
top = 0; | |||
left = 0; | |||
bottom = width; | |||
right = width; | |||
height = width; | |||
dst_left = 0; | |||
dst_top = 0; | |||
dst_right = width; | |||
dst_bottom = width; | |||
} else { | |||
roundPx = height / 2; | |||
float clip = (width - height) / 2; | |||
left = clip; | |||
right = width - clip; | |||
top = 0; | |||
bottom = height; | |||
width = height; | |||
dst_left = 0; | |||
dst_top = 0; | |||
dst_right = height; | |||
dst_bottom = height; | |||
} | |||
Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); | |||
Canvas canvas = new Canvas(output); | |||
final int color = 0xff424242; | |||
final Paint paint = new Paint(); | |||
final Rect src = new Rect((int) left, (int) top, (int) right, | |||
(int) bottom); | |||
final Rect dst = new Rect((int) dst_left, (int) dst_top, | |||
(int) dst_right, (int) dst_bottom); | |||
final RectF rectF = new RectF(dst); | |||
paint.setAntiAlias(true); | |||
canvas.drawARGB(0, 0, 0, 0); | |||
paint.setColor(Color.WHITE); | |||
paint.setStrokeWidth(4); | |||
canvas.drawRoundRect(rectF, roundPx, roundPx, paint); | |||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); | |||
canvas.drawBitmap(bitmap, src, dst, paint); | |||
// 画白色圆圈 | |||
paint.reset(); | |||
paint.setColor(Color.WHITE); | |||
paint.setStyle(Paint.Style.STROKE); | |||
paint.setStrokeWidth(STROKE_WIDTH); | |||
paint.setAntiAlias(true); | |||
canvas.drawCircle(width / 2, width / 2, width / 2 - STROKE_WIDTH / 2, | |||
paint); | |||
return output; | |||
} | |||
} |
@@ -0,0 +1,23 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import android.content.Context; | |||
/** | |||
* 获取当前的包版本 | |||
*/ | |||
public class Utils { | |||
/* | |||
* 获取当前app的versionCode | |||
* return int | |||
*/ | |||
public static int getversionCode(Context context) { | |||
int verCode = -1; | |||
try { | |||
verCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; | |||
} catch (Exception e) { | |||
android.util.Log.e("mUtils-gerversionCode", e.getMessage()); | |||
} | |||
return verCode; | |||
} | |||
} |
@@ -0,0 +1,29 @@ | |||
package com.bonait.bnframework.common.helper; | |||
import android.content.Context; | |||
import android.support.v7.widget.LinearLayoutManager; | |||
import android.support.v7.widget.RecyclerView; | |||
import android.util.AttributeSet; | |||
public class WrapContentLinearLayoutManager extends LinearLayoutManager { | |||
public WrapContentLinearLayoutManager(Context context) { | |||
super(context); | |||
} | |||
public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) { | |||
super(context, orientation, reverseLayout); | |||
} | |||
public WrapContentLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | |||
super(context, attrs, defStyleAttr, defStyleRes); | |||
} | |||
@Override | |||
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { | |||
try { | |||
super.onLayoutChildren(recycler, state); | |||
} catch (IndexOutOfBoundsException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,18 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
/** | |||
* 消息包 | |||
*/ | |||
public class BPAPackage { | |||
public int MessageId; | |||
public byte MessageVersion; | |||
public int ClientId; | |||
public int ClientType;//9 是MORKT | |||
public String Timestamp; | |||
public PushDeviceGoods Message; | |||
} |
@@ -0,0 +1,49 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
/** | |||
* 商品信息 | |||
*/ | |||
public class BPA_GoodsInfo { | |||
public String Id; | |||
public String Goods_Name; | |||
public String Goods_TypeID; | |||
public String Goods_Descritption; | |||
public String Goods_ImgUrl; | |||
public int Goods_ImgMode; | |||
public int Goods_Sort; | |||
public int Goods_Enable; | |||
public int IsDeleted; | |||
public String DeleteUpdateTime; | |||
public String Key; | |||
public String Code; | |||
public double Price; | |||
public String CreateAt; | |||
public String CreateBy; | |||
public int Status; | |||
public String DeleteAt; | |||
public String DeleteBy; | |||
public String UpdateAt; | |||
public String UpdateBy; | |||
public String GroupId; | |||
} |
@@ -0,0 +1,15 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
public class BPA_HeartPackage { | |||
public int MessageId; | |||
public byte MessageVersion; | |||
public int ClientId; | |||
public int ClientType;//9 是MORKT | |||
public String Timestamp; | |||
public Message_HeartModel Message; | |||
} |
@@ -0,0 +1,27 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
public class BatchingsInfo { | |||
public String Id; | |||
/// <summary> | |||
/// 物料名称 | |||
/// </summary> | |||
public String BatchingName; | |||
/// <summary> | |||
/// 物料id | |||
/// </summary> | |||
public String BatchingId; | |||
public long BatchingKey; | |||
/// <summary> | |||
/// 配方用量 | |||
/// </summary> | |||
public double BomQty ; | |||
/// <summary> | |||
/// 配方id | |||
/// </summary> | |||
public String BomId; | |||
public boolean IsReplace; | |||
/// <summary> | |||
/// 商品关联BomID | |||
/// </summary> | |||
public String GoodsBomId; | |||
} |
@@ -0,0 +1,13 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
public class Batchingstechnology { | |||
public String Id ; | |||
public String TechnologyName; | |||
/// <summary> | |||
/// 物料名称 | |||
/// </summary> | |||
public String BatchingsName ; | |||
public String BomentryId ; | |||
public String ChnologyId ; | |||
public int Sort; | |||
} |
@@ -0,0 +1,15 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
public class GoodsBom { | |||
public String BomId ; | |||
public String GoodsId ; | |||
public String BomName ; | |||
/// <summary> | |||
/// 是否主料配方 | |||
/// </summary> | |||
public boolean IsMain; | |||
/// <summary> | |||
/// 商品关联BomID | |||
/// </summary> | |||
public String GoodsBomId; | |||
} |
@@ -0,0 +1,7 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
public class Message_HeartModel { | |||
public int Healthy; | |||
public int DeviceType;//9 是MORKT | |||
} |
@@ -0,0 +1,39 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
import java.util.List; | |||
/** | |||
* 订单 | |||
*/ | |||
public class OrderA { | |||
public String orgId;//组织id | |||
public String orgName;//组织名称 | |||
public String id;//订单id | |||
public String sortId;//取餐号 | |||
public String customerId;//第三方用户id | |||
public int orderStatus;//订单状态 | |||
public int afterStatus;//订单状态 | |||
public int orderCount;//订单状态 | |||
public double orderOriginalMoney;//订单原价 | |||
public double discountMoney;//优惠金额 | |||
public double orderRealMoney;//实付金额 | |||
public int payMode;//支付方式 | |||
public String orderNumber;//订单流水号 | |||
public String tradeNo;// | |||
public String transactionId;// | |||
public int orderSettlementStatus;//订单结算状态 | |||
public String orderSettlementTime;//订单结算时间 | |||
public String orderSourceFrom;//订单来源 0 小程序 1大屏点餐 etc... | |||
public int orderType;//订单类型 0->正常 1->立即吃面2->盲盒3->其他 | |||
public String remark;//备注 | |||
public String createdAt;//创建时间 | |||
public int stutas;// | |||
public String troikaId;//三方ID | |||
public String refundStutasStr;//退款描述 | |||
//public String couponUseInfo;//优惠集合 | |||
public List<SuOrderA> orderDetail;//子订单 | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
public class OrderStatusChange { | |||
public String SuborderId; | |||
/** | |||
* 4 制作中 5 制作完成等待取餐 6 取餐完成 11废弃 | |||
*/ | |||
public Integer CookingStatus ; | |||
//商品名称 | |||
public String GoodName; | |||
//订单排序号 | |||
public String SortNum ; | |||
} |
@@ -0,0 +1,25 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
import java.util.List; | |||
/** | |||
* 接收物料信息 | |||
*/ | |||
public class PushDeviceGoods { | |||
/// <summary> | |||
/// 商品信息 | |||
/// </summary> | |||
public List<BPA_GoodsInfo> GoodsInfos; | |||
/// <summary> | |||
/// 商品绑定的配方信息 | |||
/// </summary> | |||
public List<GoodsBom> GoodsBomInfos; | |||
/// <summary> | |||
/// 配方绑定的物料信息 | |||
/// </summary> | |||
public List<BatchingsInfo> BatchingsInfos; | |||
/// <summary> | |||
/// 配方绑定的工艺 | |||
/// </summary> | |||
public List<Batchingstechnology> Batchingstechnologys; | |||
} |
@@ -0,0 +1,11 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
/** | |||
* 接收订单信息 | |||
*/ | |||
public class ReceiveOrder { | |||
//是否成功 | |||
public boolean isSuccess; | |||
//订单Model | |||
public OrderA data; | |||
} |
@@ -0,0 +1,12 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
/** | |||
* 接收版本信息 | |||
*/ | |||
public class ResVersion { | |||
public String trackId; | |||
public String code; | |||
public String message; | |||
public String isSuccess; | |||
public VersionResponse data; | |||
} |
@@ -0,0 +1,15 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
/** | |||
* 返回结果 | |||
*/ | |||
public class ResultA { | |||
/** | |||
* 是否可制作 | |||
*/ | |||
public boolean IsMake=false; | |||
/** | |||
* 描述 | |||
*/ | |||
public String Message=""; | |||
} |
@@ -0,0 +1,5 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
public class RunStatusModel { | |||
public int ChNumber; | |||
} |
@@ -0,0 +1,21 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
public class SuOrderA { | |||
public String id;//di | |||
public String beginCookTime;//开始制作时间 | |||
public String completedCookTime;//完成制作时间 | |||
public String completedTakeTime;//取餐时间 | |||
public String createdTime;//创建时间 | |||
public String goodName;//商品名称 | |||
public String goods_Id;//商品id | |||
public String goodImg;//商品图片 | |||
public String orderInfo_Id;//订单Id | |||
public int order_Status;//0等待制作 1制作中 2等待取餐 3取餐完成 99998正常订单 99999 异常订单 | |||
public double originalMoney;//原价 | |||
public double realMoney;//实际金额 | |||
public String storeName;//店铺名称 | |||
public String store_Id;//店铺id | |||
public int isVaild;// | |||
public String consumeUnit;//单位 | |||
public String remark;//备注 | |||
} |
@@ -0,0 +1,9 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
import com.bonait.bnframework.common.helper.I.IThread; | |||
public class ThreadModel { | |||
public IThread RunThread; | |||
public boolean IsCancel; | |||
public Thread ThreadObj; | |||
} |
@@ -0,0 +1,8 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
public class VersionMode { | |||
public String productCode; | |||
public String moduleCode; | |||
public String serverCode; | |||
public String branchCode; | |||
} |
@@ -0,0 +1,40 @@ | |||
package com.bonait.bnframework.common.helper.mode; | |||
/** | |||
* 版本响应 | |||
*/ | |||
public class VersionResponse { | |||
/** | |||
* 版本编号 | |||
*/ | |||
public String id; | |||
/** | |||
* 版本号 | |||
*/ | |||
public String versionNo; | |||
/** | |||
* 分支编号 | |||
*/ | |||
public String branchId; | |||
/** | |||
* 分支名称 | |||
*/ | |||
public String branchName; | |||
/** | |||
* 服务状态 | |||
*/ | |||
public int serverStatus; | |||
/** | |||
* 版本描述 | |||
*/ | |||
public String description; | |||
/** | |||
* 下载地址 | |||
*/ | |||
public String downloadLink; | |||
/** | |||
* 发布日期 | |||
*/ | |||
public String releaseDate; | |||
} |
@@ -0,0 +1,9 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<paths xmlns:android="http://schemas.android.com/apk/res/android"> | |||
<!--因为要安装的apk是存储在sd卡的,这里的映射就相当于: | |||
content:虚拟路径 映射到了-> Environment.getExternalStorageDirectory() | |||
--> | |||
<external-path | |||
name="external_path" | |||
path="." /> | |||
</paths> |