代码上传。
This commit is contained in:
parent
5c6bcfb3fe
commit
872893027c
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,23 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIDxTCCAq2gAwIBAgIBADANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMCVVMx
|
||||
EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAYBgNVBAoT
|
||||
EUdvRGFkZHkuY29tLCBJbmMuMTEwLwYDVQQDEyhHbyBEYWRkeSBSb290IENlcnRp
|
||||
ZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAwMFoXDTM3MTIzMTIz
|
||||
NTk1OVowgYMxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6b25hMRMwEQYDVQQH
|
||||
EwpTY290dHNkYWxlMRowGAYDVQQKExFHb0RhZGR5LmNvbSwgSW5jLjExMC8GA1UE
|
||||
AxMoR28gRGFkZHkgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgLSBHMjCCASIw
|
||||
DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL9xYgjx+lk09xvJGKP3gElY6SKD
|
||||
E6bFIEMBO4Tx5oVJnyfq9oQbTqC023CYxzIBsQU+B07u9PpPL1kwIuerGVZr4oAH
|
||||
/PMWdYA5UXvl+TW2dE6pjYIT5LY/qQOD+qK+ihVqf94Lw7YZFAXK6sOoBJQ7Rnwy
|
||||
DfMAZiLIjWltNowRGLfTshxgtDj6AozO091GB94KPutdfMh8+7ArU6SSYmlRJQVh
|
||||
GkSBjCypQ5Yj36w6gZoOKcUcqeldHraenjAKOc7xiID7S13MMuyFYkMlNAJWJwGR
|
||||
tDtwKj9useiciAF9n9T521NtYJ2/LOdYq7hfRvzOxBsDPAnrSTFcaUaz4EcCAwEA
|
||||
AaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYE
|
||||
FDqahQcQZyi27/a9BUFuIMGU2g/eMA0GCSqGSIb3DQEBCwUAA4IBAQCZ21151fmX
|
||||
WWcDYfF+OwYxdS2hII5PZYe096acvNjpL9DbWu7PdIxztDhC2gV7+AJ1uP2lsdeu
|
||||
9tfeE8tTEH6KRtGX+rcuKxGrkLAngPnon1rpN5+r5N9ss4UXnT3ZJE95kTXWXwTr
|
||||
gIOrmgIttRD02JDHBHNA7XIloKmf7J6raBKZV8aPEjoJpL1E/QYVN8Gb5DKj7Tjo
|
||||
2GTzLH4U/ALqn83/B2gX2yKQOC16jdFU8WnjXzPKej17CuPKf1855eJ1usV2GDPO
|
||||
LPAvTK33sefOT6jEm0pUBsV/fdUID+Ic/n4XuKxe9tQWskMJDE32p2u0mYRlynqI
|
||||
4uJEvlz36hz1
|
||||
-----END CERTIFICATE-----
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,11 @@
|
|||
欢迎您使用安顺祥智控。您可使用本应用以实现智能设备的控制、情景、设备分享等功能。
|
||||
我们深知隐私保护对您的重要性,为了更全面地呈现我们收集和使用您的个人信息的相关情况,我们依据最新法律法规要求在您使用我们的产品或服务(统称“服务”)重点内容包括一下信息:
|
||||
必要权限(用于该应用的基本服务和功能)
|
||||
· 获取手机帐号信息:
|
||||
用于应用内使用安顺祥智控帐号登录;
|
||||
· 获取位置信息:
|
||||
基于位置信息为您提供的服务,如配网,家庭切换天气服务;
|
||||
· 相册权限:基于图片/视频相关服务,用于从相册中选择图片、视频文件;
|
||||
· 麦克风权限:基于语音实现服务,如在线语音控制设备;
|
||||
· 消息通知权限:向您推送有关产品或服务、安防类的通知等功能。
|
||||
如果您不统一调用以上必须权限或功能,或不同意我们收集并使用以上信息,将导致本应用无法正常运行,您可选择退出本应用终止服务。
|
|
@ -0,0 +1,11 @@
|
|||
欢迎您使用Swaiot智控。您可使用本应用以实现智能设备的控制、情景、设备分享等功能。
|
||||
我们深知隐私保护对您的重要性,为了更全面地呈现我们收集和使用您的个人信息的相关情况,我们依据最新法律法规要求在您使用我们的产品或服务(统称“服务”)重点内容包括一下信息:
|
||||
必要权限(用于该应用的基本服务和功能)
|
||||
· 获取手机帐号信息:
|
||||
用于应用内使用Swaiot智控帐号登录;
|
||||
· 获取位置信息:
|
||||
基于位置信息为您提供的服务,如配网,家庭切换天气服务;
|
||||
· 相册权限:基于图片/视频相关服务,用于从相册中选择图片、视频文件;
|
||||
· 麦克风权限:基于语音实现服务,如在线语音控制设备;
|
||||
· 消息通知权限:向您推送有关产品或服务、安防类的通知等功能。
|
||||
如果您不统一调用以上必须权限或功能,或不同意我们收集并使用以上信息,将导致本应用无法正常运行,您可选择退出本应用终止服务。
|
|
@ -0,0 +1,11 @@
|
|||
欢迎您使用雅今智慧生活。您可使用本应用以实现智能设备的控制、情景、设备分享等功能。
|
||||
我们深知隐私保护对您的重要性,为了更全面地呈现我们收集和使用您的个人信息的相关情况,我们依据最新法律法规要求在您使用我们的产品或服务(统称“服务”)重点内容包括一下信息:
|
||||
必要权限(用于该应用的基本服务和功能)
|
||||
· 获取手机帐号信息:
|
||||
用于应用内使用雅今智慧生活帐号登录;
|
||||
· 获取位置信息:
|
||||
基于位置信息为您提供的服务,如配网,家庭切换天气服务;
|
||||
· 相册权限:基于图片/视频相关服务,用于从相册中选择图片、视频文件;
|
||||
· 麦克风权限:基于语音实现服务,如在线语音控制设备;
|
||||
· 消息通知权限:向您推送有关产品或服务、安防类的通知等功能。
|
||||
如果您不统一调用以上必须权限或功能,或不同意我们收集并使用以上信息,将导致本应用无法正常运行,您可选择退出本应用终止服务。
|
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
|
@ -0,0 +1,58 @@
|
|||
package com.common.openapi;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class ClassInstanceManager {
|
||||
private volatile static ClassInstanceManager classInstanceManager;
|
||||
private DeviceLocalCacheManager deviceLocalCacheManager;
|
||||
private DeviceDetailService deviceDetailService;
|
||||
private DeviceListService deviceListService;
|
||||
private DeviceRecordService deviceRecordService;
|
||||
private DeviceLocalCacheService deviceLocalCacheService;
|
||||
private DeviceSubAccountListService deviceSubAccountListService;
|
||||
|
||||
public static ClassInstanceManager newInstance() {
|
||||
if (classInstanceManager == null) {
|
||||
synchronized (ClassInstanceManager.class) {
|
||||
if (classInstanceManager == null) {
|
||||
classInstanceManager = new ClassInstanceManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return classInstanceManager;
|
||||
}
|
||||
|
||||
public void init(Context context) {
|
||||
deviceLocalCacheManager = new DeviceLocalCacheManager();
|
||||
deviceLocalCacheManager.init(context);
|
||||
deviceDetailService = new DeviceDetailService();
|
||||
deviceListService = new DeviceListService();
|
||||
deviceRecordService = new DeviceRecordService();
|
||||
deviceLocalCacheService = new DeviceLocalCacheService();
|
||||
deviceSubAccountListService = new DeviceSubAccountListService();
|
||||
}
|
||||
|
||||
public DeviceLocalCacheManager getDeviceLocalCacheManager() {
|
||||
return deviceLocalCacheManager;
|
||||
}
|
||||
|
||||
public DeviceDetailService getDeviceDetailService() {
|
||||
return deviceDetailService;
|
||||
}
|
||||
|
||||
public DeviceListService getDeviceListService() {
|
||||
return deviceListService;
|
||||
}
|
||||
|
||||
public DeviceRecordService getDeviceRecordService() {
|
||||
return deviceRecordService;
|
||||
}
|
||||
|
||||
public DeviceLocalCacheService getDeviceLocalCacheService() {
|
||||
return deviceLocalCacheService;
|
||||
}
|
||||
|
||||
public DeviceSubAccountListService getDeviceSubAccountListService() {
|
||||
return deviceSubAccountListService;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,295 @@
|
|||
package com.common.openapi;
|
||||
|
||||
import android.os.Message;
|
||||
|
||||
import com.common.openapi.entity.DeviceAlarmStatusData;
|
||||
import com.common.openapi.entity.DeviceChannelInfoData;
|
||||
import com.common.openapi.entity.DeviceModifyNameData;
|
||||
import com.common.openapi.entity.DeviceUnBindData;
|
||||
import com.common.openapi.entity.DeviceVersionListData;
|
||||
import com.mm.android.deviceaddmodule.device_wifi.CurWifiInfo;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessRunnable;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.base.LCBusinessHandler;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.BusinessErrorTip;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.HandleMessageCode;
|
||||
import com.mm.android.deviceaddmodule.openapi.DeviceAddOpenApiManager;
|
||||
|
||||
public class DeviceDetailService {
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备版本和可升级信息
|
||||
*
|
||||
* @param deviceVersionListData
|
||||
* @param deviceVersionCallBack
|
||||
*/
|
||||
public void deviceVersionList(final DeviceVersionListData deviceVersionListData, final IGetDeviceInfoCallBack.IDeviceVersionCallBack deviceVersionCallBack) {
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (deviceVersionCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
deviceVersionCallBack.deviceVersion((DeviceVersionListData.Response) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
deviceVersionCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
DeviceVersionListData.Response response = DeviceInfoOpenApiManager.deviceVersionList(deviceVersionListData);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, response).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备或通道名称
|
||||
*
|
||||
* @param deviceModifyNameData
|
||||
* @param modifyDeviceCallBack
|
||||
*/
|
||||
public void modifyDeviceName(final DeviceModifyNameData deviceModifyNameData, final IGetDeviceInfoCallBack.IModifyDeviceCallBack modifyDeviceCallBack) {
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (modifyDeviceCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
modifyDeviceCallBack.deviceModify((boolean) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
modifyDeviceCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
boolean b = DeviceInfoOpenApiManager.modifyDeviceName(deviceModifyNameData);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, b).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑设备
|
||||
*
|
||||
* @param deviceUnBindData
|
||||
* @param unbindDeviceCallBack
|
||||
*/
|
||||
public void unBindDevice(final DeviceUnBindData deviceUnBindData, final IGetDeviceInfoCallBack.IUnbindDeviceCallBack unbindDeviceCallBack) {
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (unbindDeviceCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
unbindDeviceCallBack.unBindDevice((boolean) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
unbindDeviceCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
boolean b = DeviceInfoOpenApiManager.unBindDevice(deviceUnBindData);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, b).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void deletePermission(final String deviceId, final String channelId, final IGetDeviceInfoCallBack.IUnbindDeviceCallBack unbindDeviceCallBack){
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (unbindDeviceCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
unbindDeviceCallBack.unBindDevice((boolean) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
unbindDeviceCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
boolean b = DeviceInfoOpenApiManager.deletePermission(deviceId,channelId);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, b).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个设备通道的详细信息获取
|
||||
*
|
||||
* @param deviceChannelInfoData
|
||||
* @param deviceChannelInfoCallBack
|
||||
*/
|
||||
public void bindDeviceChannelInfo(final DeviceChannelInfoData deviceChannelInfoData, final IGetDeviceInfoCallBack.IDeviceChannelInfoCallBack deviceChannelInfoCallBack) {
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (deviceChannelInfoCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
deviceChannelInfoCallBack.deviceChannelInfo((DeviceChannelInfoData.Response) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
deviceChannelInfoCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
DeviceChannelInfoData.Response response = DeviceInfoOpenApiManager.bindDeviceChannelInfo(deviceChannelInfoData);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, response).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置动检开关
|
||||
*
|
||||
* @param deviceAlarmStatusData
|
||||
* @param deviceAlarmStatusCallBack
|
||||
*/
|
||||
public void modifyDeviceAlarmStatus(final DeviceAlarmStatusData deviceAlarmStatusData, final IGetDeviceInfoCallBack.IDeviceAlarmStatusCallBack deviceAlarmStatusCallBack) {
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (deviceAlarmStatusCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
deviceAlarmStatusCallBack.deviceAlarmStatus((boolean) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
deviceAlarmStatusCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
boolean b = DeviceInfoOpenApiManager.modifyDeviceAlarmStatus(deviceAlarmStatusData);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, b).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备升级
|
||||
*
|
||||
* @param deviceId
|
||||
* @param deviceUpdateCallBack
|
||||
*/
|
||||
public void upgradeDevice(final String deviceId, final IGetDeviceInfoCallBack.IDeviceUpdateCallBack deviceUpdateCallBack) {
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (deviceUpdateCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
deviceUpdateCallBack.deviceUpdate((boolean) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
deviceUpdateCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
boolean b = DeviceInfoOpenApiManager.upgradeDevice(deviceId);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, b).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备当前连接热点信息
|
||||
*
|
||||
* @param deviceId
|
||||
* @param deviceCurrentWifiInfoCallBack
|
||||
*/
|
||||
public void currentDeviceWifi(final String deviceId, final IGetDeviceInfoCallBack.IDeviceCurrentWifiInfoCallBack deviceCurrentWifiInfoCallBack) {
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (deviceCurrentWifiInfoCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
deviceCurrentWifiInfoCallBack.deviceCurrentWifiInfo((CurWifiInfo) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
deviceCurrentWifiInfoCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
CurWifiInfo curWifiInfo = DeviceAddOpenApiManager.currentDeviceWifi(deviceId);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, curWifiInfo).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,337 @@
|
|||
package com.common.openapi;
|
||||
|
||||
import com.common.openapi.entity.CloudRecordsData;
|
||||
import com.common.openapi.entity.ControlMovePTZData;
|
||||
import com.common.openapi.entity.DeviceAlarmStatusData;
|
||||
import com.common.openapi.entity.DeviceChannelInfoData;
|
||||
import com.common.openapi.entity.DeviceDetailListData;
|
||||
import com.common.openapi.entity.DeviceListData;
|
||||
import com.common.openapi.entity.DeviceModifyNameData;
|
||||
import com.common.openapi.entity.DeviceUnBindData;
|
||||
import com.common.openapi.entity.DeviceVersionListData;
|
||||
import com.common.openapi.entity.LocalRecordsData;
|
||||
import com.common.openapi.entity.SubAccountDeviceData;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mm.android.deviceaddmodule.LCDeviceEngine;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
|
||||
import com.mm.android.deviceaddmodule.openapi.HttpSend;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DeviceInfoOpenApiManager {
|
||||
|
||||
private static int TIME_OUT = 10 * 1000;
|
||||
private static int DMS_TIME_OUT = 45 * 1000;
|
||||
|
||||
/**
|
||||
* 分页获取乐橙app添加或分享的设备通道基本信息
|
||||
*
|
||||
* @param deviceListData
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static DeviceListData.Response deviceBaseList(DeviceListData deviceListData) throws BusinessException {
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("bindId", deviceListData.data.baseBindId);
|
||||
paramsMap.put("limit", deviceListData.data.limit);
|
||||
paramsMap.put("type", deviceListData.data.type);
|
||||
paramsMap.put("needApInfo", deviceListData.data.needApInfo);
|
||||
JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_BASE_LIST,TIME_OUT);
|
||||
DeviceListData.Response response = new DeviceListData.Response();
|
||||
response.parseData(json);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取开放平台添加设备的通道基本信息
|
||||
*
|
||||
* @param deviceListData
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static DeviceListData.Response deviceOpenList(DeviceListData deviceListData) throws BusinessException {
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("bindId", deviceListData.data.openBindId);
|
||||
paramsMap.put("limit", deviceListData.data.limit);
|
||||
paramsMap.put("type", deviceListData.data.type);
|
||||
paramsMap.put("needApInfo", deviceListData.data.needApInfo);
|
||||
JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_OPEN_LIST,TIME_OUT);
|
||||
DeviceListData.Response response = new DeviceListData.Response();
|
||||
response.parseData(json);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量根据设备序列号、通道号列表和配件号列表,获取设备的详细信息
|
||||
*
|
||||
* @param deviceDetailListData
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static DeviceDetailListData.Response deviceOpenDetailList(DeviceDetailListData deviceDetailListData) throws BusinessException {
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceList", deviceDetailListData.data.deviceList);
|
||||
JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_OPEN_DETAIL_LIST,TIME_OUT);
|
||||
DeviceDetailListData.Response response = new DeviceDetailListData.Response();
|
||||
response.parseData(json);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量根据设备序列号、通道号列表和配件号列表,获取乐橙app添加或分享的设备的详细信息
|
||||
*
|
||||
* @param deviceDetailListData
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static DeviceDetailListData.Response deviceBaseDetailList(DeviceDetailListData deviceDetailListData) throws BusinessException {
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceList", deviceDetailListData.data.deviceList);
|
||||
JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_BASE_DETAIL_LIST,TIME_OUT);
|
||||
DeviceDetailListData.Response response = new DeviceDetailListData.Response();
|
||||
response.parseData(json);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑设备
|
||||
*
|
||||
* @param deviceUnBindData
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static boolean unBindDevice(DeviceUnBindData deviceUnBindData) throws BusinessException {
|
||||
// 解绑设备
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceId", deviceUnBindData.data.deviceId);
|
||||
HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_UN_BIND,TIME_OUT);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean deletePermission(String deviceId,String channelId) throws BusinessException {
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
// paramsMap.put("openid", LCDeviceEngine.newInstance().openid);
|
||||
paramsMap.put("channelId", channelId);
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceId", deviceId);
|
||||
HttpSend.execute(paramsMap, MethodConst.DELETE_DEVICE_PERMISSION,TIME_OUT);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备版本和可升级信息
|
||||
*
|
||||
* @param deviceVersionListData
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static DeviceVersionListData.Response deviceVersionList(DeviceVersionListData deviceVersionListData) throws BusinessException {
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceIds", deviceVersionListData.data.deviceIds);
|
||||
JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_VERSION_LIST,TIME_OUT);
|
||||
DeviceVersionListData.Response response = new DeviceVersionListData.Response();
|
||||
response.parseData(json);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备或通道名称
|
||||
*
|
||||
* @param deviceModifyNameData
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static boolean modifyDeviceName(DeviceModifyNameData deviceModifyNameData) throws BusinessException {
|
||||
// 解绑设备
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceId", deviceModifyNameData.data.deviceId);
|
||||
paramsMap.put("channelId", deviceModifyNameData.data.channelId);
|
||||
paramsMap.put("name", deviceModifyNameData.data.name);
|
||||
HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_MODIFY_NAME,TIME_OUT);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个设备通道的详细信息获取
|
||||
*
|
||||
* @param deviceChannelInfoData
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static DeviceChannelInfoData.Response bindDeviceChannelInfo(DeviceChannelInfoData deviceChannelInfoData) throws BusinessException {
|
||||
// 单个设备通道的详细信息获取
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceId", deviceChannelInfoData.data.deviceId);
|
||||
paramsMap.put("channelId", deviceChannelInfoData.data.channelId);
|
||||
JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_CHANNEL_INFO, DMS_TIME_OUT);
|
||||
DeviceChannelInfoData.Response response = new DeviceChannelInfoData.Response();
|
||||
response.parseData(json);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置动检开关
|
||||
*
|
||||
* @param deviceAlarmStatusData
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static boolean modifyDeviceAlarmStatus(DeviceAlarmStatusData deviceAlarmStatusData) throws BusinessException {
|
||||
// 解绑设备
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceId", deviceAlarmStatusData.data.deviceId);
|
||||
paramsMap.put("channelId", deviceAlarmStatusData.data.channelId);
|
||||
paramsMap.put("enable", deviceAlarmStatusData.data.enable);
|
||||
HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_MODIFY_ALARM_STATUS, DMS_TIME_OUT);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备升级
|
||||
*
|
||||
* @param deviceId
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static boolean upgradeDevice(String deviceId) throws BusinessException {
|
||||
// 解绑设备
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceId", deviceId);
|
||||
HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_UPDATE, DMS_TIME_OUT);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 倒序查询设备云录像片段
|
||||
*
|
||||
* @param cloudRecordsData
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static CloudRecordsData.Response getCloudRecords(CloudRecordsData cloudRecordsData) throws BusinessException {
|
||||
// 倒序查询设备云录像片段
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceId", cloudRecordsData.data.deviceId);
|
||||
paramsMap.put("channelId", cloudRecordsData.data.channelId);
|
||||
paramsMap.put("beginTime", cloudRecordsData.data.beginTime);
|
||||
paramsMap.put("endTime", cloudRecordsData.data.endTime);
|
||||
paramsMap.put("nextRecordId", cloudRecordsData.data.nextRecordId);
|
||||
paramsMap.put("count", cloudRecordsData.data.count);
|
||||
JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_GET_CLOUND_RECORDS,TIME_OUT);
|
||||
CloudRecordsData.Response response = new CloudRecordsData.Response();
|
||||
response.parseData(json);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备设备录像片段
|
||||
*
|
||||
* @param localRecordsData
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static LocalRecordsData.Response queryLocalRecords(LocalRecordsData localRecordsData) throws BusinessException {
|
||||
// 查询设备设备录像片段
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceId", localRecordsData.data.deviceId);
|
||||
paramsMap.put("channelId", localRecordsData.data.channelId);
|
||||
paramsMap.put("beginTime", localRecordsData.data.beginTime);
|
||||
paramsMap.put("endTime", localRecordsData.data.endTime);
|
||||
paramsMap.put("type", localRecordsData.data.type);
|
||||
paramsMap.put("queryRange", localRecordsData.data.queryRange);
|
||||
JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_QUERY_LOCAL_RECORD, DMS_TIME_OUT);
|
||||
LocalRecordsData.Response response = new LocalRecordsData.Response();
|
||||
response.parseData(json);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static int queryCloudUse(String deviceId,String channelId) throws BusinessException {
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceId", deviceId);
|
||||
paramsMap.put("channelId", channelId);
|
||||
JsonObject json = HttpSend.execute(paramsMap, MethodConst.GET_DEVICE_CLOUD, DMS_TIME_OUT);
|
||||
Integer state = json.get("strategyStatus").getAsInt();
|
||||
return state;
|
||||
}
|
||||
|
||||
public static String querySDState(String deviceId) throws BusinessException {
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceId", deviceId);
|
||||
JsonObject json = HttpSend.execute(paramsMap, MethodConst.SD_STATUE_QUERY, DMS_TIME_OUT);
|
||||
String state = json.get("status").getAsString();
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* 云台移动控制接口(V2版本)
|
||||
*
|
||||
* @param controlMovePTZData
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static void controlMovePTZ(ControlMovePTZData controlMovePTZData) throws BusinessException {
|
||||
// 云台移动控制接口(V2版本)
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("deviceId", controlMovePTZData.data.deviceId);
|
||||
paramsMap.put("channelId", controlMovePTZData.data.channelId);
|
||||
paramsMap.put("operation", controlMovePTZData.data.operation);
|
||||
paramsMap.put("duration", controlMovePTZData.data.duration);
|
||||
HttpSend.execute(paramsMap, MethodConst.METHOD_CONTROL_MOVE_PTZ, DMS_TIME_OUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备云录像片段
|
||||
*
|
||||
* @param recordRegionId
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static boolean deleteCloudRecords(String recordRegionId) throws BusinessException {
|
||||
// 删除设备云录像片段
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("recordRegionId", recordRegionId);
|
||||
HttpSend.execute(paramsMap, MethodConst.METHOD_DELETE_CLOUND_RECORDS,TIME_OUT);
|
||||
return true;
|
||||
}
|
||||
|
||||
//V7.12新增
|
||||
public static SubAccountDeviceData.Response getSubAccountDeviceListLight(int pageNo, int pageSize, String openid)throws BusinessException {
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("pageNo", pageNo);
|
||||
paramsMap.put("pageSize",pageSize);
|
||||
paramsMap.put("openid",openid);
|
||||
JsonObject json = HttpSend.execute(paramsMap, MethodConst.LIST_SUB_ACCOUNT_DEVICE,TIME_OUT);
|
||||
SubAccountDeviceData.Response response = new SubAccountDeviceData.Response();
|
||||
response.parseData(json);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static DeviceDetailListData.Response getSubAccountDeviceList(int pageNo, int pageSize)throws BusinessException {
|
||||
HashMap<String, Object> paramsMap = new HashMap<String, Object>();
|
||||
paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
|
||||
paramsMap.put("page", pageNo);
|
||||
paramsMap.put("pageSize",pageSize);
|
||||
JsonObject json = HttpSend.execute(paramsMap, MethodConst.SUB_ACCOUNT_DEVICE_LIST,TIME_OUT);
|
||||
DeviceDetailListData.Response response = new DeviceDetailListData.Response();
|
||||
response.parseData(json);
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
package com.common.openapi;
|
||||
|
||||
import android.os.Message;
|
||||
|
||||
import com.common.openapi.entity.DeviceDetailListData;
|
||||
import com.common.openapi.entity.DeviceListData;
|
||||
import com.google.gson.Gson;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessRunnable;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.base.LCBusinessHandler;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.BusinessErrorTip;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.HandleMessageCode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceListService {
|
||||
|
||||
public static final int pageSize=8;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备列表 1:开放平台添加的 2:乐橙App添加的
|
||||
*
|
||||
* @param deviceListData
|
||||
* @param getDeviceListCallBack
|
||||
*/
|
||||
public void deviceBaseList(final DeviceListData deviceListData, final IGetDeviceInfoCallBack.IDeviceListCallBack getDeviceListCallBack) {
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (getDeviceListCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
getDeviceListCallBack.deviceList((DeviceDetailListData.Response) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
getDeviceListCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
dealDeviceDetailList(handler, deviceListData);
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void dealDeviceDetailList(LCBusinessHandler handler, DeviceListData deviceListData) throws BusinessException {
|
||||
if (deviceListData == null) {
|
||||
deviceListData = new DeviceListData();
|
||||
}
|
||||
//成功返回值
|
||||
DeviceDetailListData.Response result = null;
|
||||
//获取乐橙添加的设备
|
||||
DeviceDetailListData.Response deviceBaseDetailList = getDeviceDetailListFromCloud(false, deviceListData);
|
||||
//乐橙返回
|
||||
if (deviceBaseDetailList.data != null && deviceBaseDetailList.data.deviceList != null && deviceBaseDetailList.data.deviceList.size() > 0) {
|
||||
result = new DeviceDetailListData.Response();
|
||||
result.data = new DeviceDetailListData.ResponseData();
|
||||
result.data.count = deviceBaseDetailList.data.deviceList.size();
|
||||
result.data.deviceList = new ArrayList<>();
|
||||
for (DeviceDetailListData.ResponseData.DeviceListBean a : deviceBaseDetailList.data.deviceList) {
|
||||
DeviceDetailListData.ResponseData.DeviceListBean b = new DeviceDetailListData.ResponseData.DeviceListBean();
|
||||
Gson gson = new Gson();
|
||||
b = gson.fromJson(gson.toJson(a), DeviceDetailListData.ResponseData.DeviceListBean.class);
|
||||
b.deviceSource=2;
|
||||
result.data.deviceList.add(b);
|
||||
}
|
||||
result.baseBindId = deviceBaseDetailList.baseBindId;
|
||||
if (result.data.deviceList.size() >= pageSize) {
|
||||
//单次已经达到8条不再拉取
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, result).sendToTarget();
|
||||
return;
|
||||
} else {
|
||||
//单次没有达到8条
|
||||
deviceListData.data.limit = (8 - result.data.deviceList.size()) + "";
|
||||
}
|
||||
}
|
||||
//获取开放平台添加的设备
|
||||
DeviceDetailListData.Response deviceOpenDetailList = getDeviceDetailListFromCloud(true, deviceListData);
|
||||
//开放平台返回
|
||||
if (deviceOpenDetailList.data != null && deviceOpenDetailList.data.deviceList != null && deviceOpenDetailList.data.deviceList.size() > 0) {
|
||||
if (result == null) {
|
||||
result = new DeviceDetailListData.Response();
|
||||
result.data = new DeviceDetailListData.ResponseData();
|
||||
result.data.count = deviceOpenDetailList.data.deviceList.size();
|
||||
result.data.deviceList = new ArrayList<>();
|
||||
for (DeviceDetailListData.ResponseData.DeviceListBean a : deviceOpenDetailList.data.deviceList) {
|
||||
DeviceDetailListData.ResponseData.DeviceListBean b = new DeviceDetailListData.ResponseData.DeviceListBean();
|
||||
Gson gson = new Gson();
|
||||
b = gson.fromJson(gson.toJson(a), DeviceDetailListData.ResponseData.DeviceListBean.class);
|
||||
b.deviceSource=1;
|
||||
result.data.deviceList.add(b);
|
||||
}
|
||||
} else {
|
||||
result.data.count = deviceOpenDetailList.data.count + result.data.count;
|
||||
for (DeviceDetailListData.ResponseData.DeviceListBean a : deviceOpenDetailList.data.deviceList) {
|
||||
DeviceDetailListData.ResponseData.DeviceListBean b = new DeviceDetailListData.ResponseData.DeviceListBean();
|
||||
Gson gson = new Gson();
|
||||
b = gson.fromJson(gson.toJson(a), DeviceDetailListData.ResponseData.DeviceListBean.class);
|
||||
result.data.deviceList.add(b);
|
||||
}
|
||||
}
|
||||
result.openBindId = deviceOpenDetailList.openBindId;
|
||||
}
|
||||
if (result == null) {
|
||||
result = new DeviceDetailListData.Response();
|
||||
}
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, result).sendToTarget();
|
||||
}
|
||||
|
||||
private DeviceDetailListData.Response getDeviceDetailListFromCloud(boolean isOpenPlatform, DeviceListData deviceListDat) throws BusinessException {
|
||||
DeviceDetailListData.Response result = new DeviceDetailListData.Response();
|
||||
DeviceListData.Response deviceList = null;
|
||||
//获取到设备基本信息列表
|
||||
if (isOpenPlatform) {
|
||||
deviceList = DeviceInfoOpenApiManager.deviceOpenList(deviceListDat);
|
||||
} else {
|
||||
deviceList = DeviceInfoOpenApiManager.deviceBaseList(deviceListDat);
|
||||
}
|
||||
if (deviceList.data == null || deviceList.data.deviceList == null || deviceList.data.deviceList.size() == 0) {
|
||||
return result;
|
||||
}
|
||||
//获取设备详情列表request参数封装
|
||||
DeviceDetailListData deviceDetailListData = new DeviceDetailListData();
|
||||
List<DeviceDetailListData.RequestData.DeviceListBean> deviceListBeans = new ArrayList<>();
|
||||
for (DeviceListData.ResponseData.DeviceListElement deviceListElement : deviceList.data.deviceList) {
|
||||
DeviceDetailListData.RequestData.DeviceListBean deviceListBean = new DeviceDetailListData.RequestData.DeviceListBean();
|
||||
deviceListBean.deviceId = deviceListElement.deviceId;
|
||||
StringBuilder stringBuilder=new StringBuilder();
|
||||
if (deviceListElement.channels.size()>0){
|
||||
for (DeviceListData.ResponseData.DeviceListElement.ChannelsElement channelsElement:deviceListElement.channels){
|
||||
stringBuilder.append(channelsElement.channelId).append(",");
|
||||
}
|
||||
deviceListBean.channelList=stringBuilder.substring(0,stringBuilder.length()-1);
|
||||
}
|
||||
deviceListBeans.add(deviceListBean);
|
||||
}
|
||||
deviceDetailListData.data.deviceList = deviceListBeans;
|
||||
//获取设备详情列表
|
||||
if (isOpenPlatform) {
|
||||
result = DeviceInfoOpenApiManager.deviceOpenDetailList(deviceDetailListData);
|
||||
} else {
|
||||
result = DeviceInfoOpenApiManager.deviceBaseDetailList(deviceDetailListData);
|
||||
}
|
||||
if (result == null) {
|
||||
result = new DeviceDetailListData.Response();
|
||||
}
|
||||
if (isOpenPlatform) {
|
||||
result.openBindId = Long.parseLong(deviceList.data.deviceList.get(deviceList.data.deviceList.size() - 1).bindId);
|
||||
} else {
|
||||
result.baseBindId = Long.parseLong(deviceList.data.deviceList.get(deviceList.data.deviceList.size() - 1).bindId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
package com.common.openapi;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import com.common.openapi.entity.DeviceLocalCacheData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceLocalCacheDatabase extends SQLiteOpenHelper {
|
||||
private static final String TAG = DeviceLocalCacheDatabase.class.getSimpleName();
|
||||
|
||||
private static final String DB_NAME = "device_local_cache";
|
||||
private static final String TABLE_NAME = "t_device_local_cache";
|
||||
|
||||
private static final String TABLE_CREATE_SQL = "create table " + TABLE_NAME + "(" +
|
||||
"cache_id integer primary key autoincrement, " +
|
||||
"device_id text, " +
|
||||
"device_name text, " +
|
||||
"channel_id text, " +
|
||||
"channel_name text, " +
|
||||
"pic_path text, " +
|
||||
"creation_time integer, " +
|
||||
"modify_time integer " +
|
||||
")";
|
||||
|
||||
private static final String[] TABLE_COLUMNS = {
|
||||
"cache_id",
|
||||
"device_id",
|
||||
"device_name",
|
||||
"channel_id",
|
||||
"channel_name",
|
||||
"pic_path",
|
||||
"creation_time",
|
||||
"modify_time"
|
||||
};
|
||||
|
||||
public DeviceLocalCacheDatabase(Context context) {
|
||||
super(context, DB_NAME, null, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL(TABLE_CREATE_SQL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
}
|
||||
|
||||
public int addLocalCache(DeviceLocalCacheData deviceLocalCacheData) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
ContentValues v = new ContentValues();
|
||||
v.put("device_id", deviceLocalCacheData.getDeviceId());
|
||||
v.put("device_name", deviceLocalCacheData.getDeviceName());
|
||||
v.put("channel_id", deviceLocalCacheData.getChannelId());
|
||||
v.put("channel_name", deviceLocalCacheData.getChannelName());
|
||||
v.put("pic_path", deviceLocalCacheData.getPicPath());
|
||||
v.put("creation_time", System.currentTimeMillis());
|
||||
v.put("modify_time", System.currentTimeMillis());
|
||||
long rowid = db.insert(TABLE_NAME, null, v);
|
||||
if (rowid != -1) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int updateLocalCache(DeviceLocalCacheData deviceLocalCacheData) {
|
||||
ContentValues v = new ContentValues();
|
||||
v.put("pic_path", deviceLocalCacheData.getPicPath());
|
||||
v.put("modify_time", System.currentTimeMillis());
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
int ret = db.update(TABLE_NAME, v, "cache_id=?", new String[]{String.valueOf(deviceLocalCacheData.getCacheId())});
|
||||
if (ret > 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public DeviceLocalCacheData findLocalCache(DeviceLocalCacheData deviceLocalCacheData) {
|
||||
StringBuilder selectionBuilder = new StringBuilder();
|
||||
List<String> selectionArgs = new ArrayList<>();
|
||||
boolean first = true;
|
||||
if (deviceLocalCacheData.getDeviceId() != null) {
|
||||
selectionBuilder.append(" device_id =? ");
|
||||
selectionArgs.add(deviceLocalCacheData.getDeviceId());
|
||||
first = false;
|
||||
}
|
||||
if (deviceLocalCacheData.getChannelId() != null) {
|
||||
if (!first) {
|
||||
selectionBuilder.append(" and ");
|
||||
}
|
||||
selectionBuilder.append(" channel_id =? ");
|
||||
selectionArgs.add(deviceLocalCacheData.getChannelId());
|
||||
}
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
try (Cursor c = db.query(TABLE_NAME, TABLE_COLUMNS, selectionBuilder.toString(), selectionArgs.toArray(new String[0]), null, null, null, "1")) {
|
||||
if (c.moveToFirst()) {
|
||||
return (buildLocalCacheFromCursor(c));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private DeviceLocalCacheData buildLocalCacheFromCursor(Cursor c) {
|
||||
DeviceLocalCacheData deviceLocalCacheData = new DeviceLocalCacheData();
|
||||
deviceLocalCacheData.setCacheId(c.getInt(0));
|
||||
deviceLocalCacheData.setDeviceId(c.getString(1));
|
||||
deviceLocalCacheData.setDeviceName(c.getString(2));
|
||||
deviceLocalCacheData.setChannelId(c.getString(3));
|
||||
deviceLocalCacheData.setChannelName(c.getString(4));
|
||||
deviceLocalCacheData.setPicPath(c.getString(5));
|
||||
deviceLocalCacheData.setCreationTime(c.getLong(6));
|
||||
deviceLocalCacheData.setModifyTime(c.getLong(7));
|
||||
return deviceLocalCacheData;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.common.openapi;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.common.openapi.entity.DeviceLocalCacheData;
|
||||
import com.lechange.demo.tools.MediaPlayHelper;
|
||||
|
||||
public class DeviceLocalCacheManager {
|
||||
|
||||
private DeviceLocalCacheDatabase deviceLocalCacheDatabase;
|
||||
|
||||
public void init(Context context) {
|
||||
deviceLocalCacheDatabase = new DeviceLocalCacheDatabase(context);
|
||||
}
|
||||
|
||||
public int addLocalCache(DeviceLocalCacheData deviceLocalCacheData) {
|
||||
DeviceLocalCacheData find = deviceLocalCacheDatabase.findLocalCache(deviceLocalCacheData);
|
||||
if (find == null) {
|
||||
int add = deviceLocalCacheDatabase.addLocalCache(deviceLocalCacheData);
|
||||
return add;
|
||||
} else {
|
||||
deviceLocalCacheData.setCacheId(find.getCacheId());
|
||||
int update = deviceLocalCacheDatabase.updateLocalCache(deviceLocalCacheData);
|
||||
//删除之前缓存文件
|
||||
MediaPlayHelper.delete(find.getPicPath());
|
||||
return update;
|
||||
}
|
||||
}
|
||||
|
||||
public DeviceLocalCacheData findLocalCache(DeviceLocalCacheData deviceLocalCacheData) {
|
||||
DeviceLocalCacheData find = deviceLocalCacheDatabase.findLocalCache(deviceLocalCacheData);
|
||||
return find;
|
||||
}
|
||||
|
||||
public int updateLocalCache(DeviceLocalCacheData deviceLocalCacheData) {
|
||||
DeviceLocalCacheData find = deviceLocalCacheDatabase.findLocalCache(deviceLocalCacheData);
|
||||
if (find == null) {
|
||||
return 0;
|
||||
}
|
||||
int update = deviceLocalCacheDatabase.updateLocalCache(find);
|
||||
return update;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.common.openapi;
|
||||
|
||||
import android.os.Message;
|
||||
|
||||
import com.common.openapi.entity.DeviceLocalCacheData;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessRunnable;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.base.LCBusinessHandler;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.BusinessErrorTip;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.HandleMessageCode;
|
||||
|
||||
public class DeviceLocalCacheService {
|
||||
|
||||
/**
|
||||
* 添加设备缓存信息
|
||||
* @param localCacheData
|
||||
*/
|
||||
public void addLocalCache(final DeviceLocalCacheData localCacheData) {
|
||||
new BusinessRunnable(null) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
DeviceLocalCacheManager deviceLocalCacheManager = ClassInstanceManager.newInstance().getDeviceLocalCacheManager();
|
||||
deviceLocalCacheManager.addLocalCache(localCacheData);
|
||||
} catch (Throwable e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备缓存信息
|
||||
* @param localCacheData
|
||||
* @param deviceCacheCallBack
|
||||
*/
|
||||
public void findLocalCache(final DeviceLocalCacheData localCacheData, final IGetDeviceInfoCallBack.IDeviceCacheCallBack deviceCacheCallBack) {
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (deviceCacheCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
deviceCacheCallBack.deviceCache((DeviceLocalCacheData) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
deviceCacheCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
DeviceLocalCacheData localCache = ClassInstanceManager.newInstance().getDeviceLocalCacheManager().findLocalCache(localCacheData);
|
||||
if (localCache != null) {
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, localCache).sendToTarget();
|
||||
} else {
|
||||
throw new BusinessException("null point");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,204 @@
|
|||
package com.common.openapi;
|
||||
|
||||
import android.os.Message;
|
||||
|
||||
import com.common.openapi.entity.CloudRecordsData;
|
||||
import com.common.openapi.entity.ControlMovePTZData;
|
||||
import com.common.openapi.entity.DeleteCloudRecordsData;
|
||||
import com.common.openapi.entity.LocalRecordsData;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessRunnable;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.base.LCBusinessHandler;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.BusinessErrorTip;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.HandleMessageCode;
|
||||
|
||||
public class DeviceRecordService {
|
||||
|
||||
/**
|
||||
* 倒序查询设备云录像片段
|
||||
*
|
||||
* @param cloudRecordsData
|
||||
* @param cloudRecordCallBack
|
||||
*/
|
||||
public void getCloudRecords(final CloudRecordsData cloudRecordsData, final IGetDeviceInfoCallBack.IDeviceCloudRecordCallBack cloudRecordCallBack) {
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (cloudRecordCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
cloudRecordCallBack.deviceCloudRecord((CloudRecordsData.Response) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
cloudRecordCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
CloudRecordsData.Response response = DeviceInfoOpenApiManager.getCloudRecords(cloudRecordsData);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, response).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备设备录像片段
|
||||
*
|
||||
* @param localRecordsData
|
||||
* @param deviceLocalRecordCallBack
|
||||
*/
|
||||
public void queryLocalRecords(final LocalRecordsData localRecordsData, final IGetDeviceInfoCallBack.IDeviceLocalRecordCallBack deviceLocalRecordCallBack) {
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (deviceLocalRecordCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
deviceLocalRecordCallBack.deviceLocalRecord((LocalRecordsData.Response) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
deviceLocalRecordCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
LocalRecordsData.Response response = DeviceInfoOpenApiManager.queryLocalRecords(localRecordsData);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, response).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void queryCloudUse(final String deviceId, final String channelId, final IGetDeviceInfoCallBack.ICommon iCommon){
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (iCommon == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
iCommon.onCommonBack(msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
iCommon.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
int response = DeviceInfoOpenApiManager.queryCloudUse(deviceId,channelId);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, response).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void querySDUse(final String deviceId, final IGetDeviceInfoCallBack.ICommon iCommon){
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (iCommon == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
iCommon.onCommonBack(msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
iCommon.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
String response = DeviceInfoOpenApiManager.querySDState(deviceId);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, response).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 云台移动控制接口(V2版本)
|
||||
*
|
||||
* @param controlMovePTZData
|
||||
*/
|
||||
public void controlMovePTZ(final ControlMovePTZData controlMovePTZData) {
|
||||
new BusinessRunnable(new LCBusinessHandler() {
|
||||
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
}
|
||||
}) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
DeviceInfoOpenApiManager.controlMovePTZ(controlMovePTZData);
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备云录像片段
|
||||
*
|
||||
* @param deleteCloudRecordsData
|
||||
* @param deviceDeleteRecordCallBack
|
||||
*/
|
||||
public void deleteCloudRecords(final DeleteCloudRecordsData deleteCloudRecordsData, final IGetDeviceInfoCallBack.IDeviceDeleteRecordCallBack deviceDeleteRecordCallBack) {
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (deviceDeleteRecordCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
deviceDeleteRecordCallBack.deleteDeviceRecord();
|
||||
} else {
|
||||
//失败
|
||||
deviceDeleteRecordCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
for (String id : deleteCloudRecordsData.data.recordRegionIds) {
|
||||
DeviceInfoOpenApiManager.deleteCloudRecords(id);
|
||||
}
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, null).sendToTarget();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package com.common.openapi;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import com.common.openapi.entity.DeviceDetailListData;
|
||||
import com.common.openapi.entity.SubAccountDeviceData;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessRunnable;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.base.LCBusinessHandler;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.BusinessErrorTip;
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.HandleMessageCode;
|
||||
|
||||
public class DeviceSubAccountListService {
|
||||
public static final int pageSize=10;
|
||||
|
||||
public void getDeviceListSubAccount(final int pageNo, final String openid, final IGetDeviceInfoCallBack.ISubAccountDevice<SubAccountDeviceData.Response> getDeviceListCallBack){
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (getDeviceListCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
getDeviceListCallBack.DeviceList((SubAccountDeviceData.Response) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
getDeviceListCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
dealSubAccountDeviceList(handler,pageNo,openid);
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void dealSubAccountDeviceList(Handler handler,int pageNo,String openid)throws BusinessException {
|
||||
SubAccountDeviceData.Response response= DeviceInfoOpenApiManager.getSubAccountDeviceListLight(pageNo,pageSize,openid);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, response).sendToTarget();
|
||||
}
|
||||
|
||||
public void getSubAccountDeviceList(final int pageNo, final IGetDeviceInfoCallBack.ISubAccountDevice<DeviceDetailListData.Response> getDeviceListCallBack){
|
||||
final LCBusinessHandler handler = new LCBusinessHandler() {
|
||||
@Override
|
||||
public void handleBusiness(Message msg) {
|
||||
if (getDeviceListCallBack == null) {
|
||||
return;
|
||||
}
|
||||
if (msg.what == HandleMessageCode.HMC_SUCCESS) {
|
||||
//成功
|
||||
getDeviceListCallBack.DeviceList(( DeviceDetailListData.Response) msg.obj);
|
||||
} else {
|
||||
//失败
|
||||
getDeviceListCallBack.onError(BusinessErrorTip.throwError(msg));
|
||||
}
|
||||
}
|
||||
};
|
||||
new BusinessRunnable(handler) {
|
||||
@Override
|
||||
public void doBusiness() throws BusinessException {
|
||||
try {
|
||||
getDeviceListAtSubAccount(handler,pageNo);
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void getDeviceListAtSubAccount(Handler handler,int pageNo)throws BusinessException {
|
||||
DeviceDetailListData.Response response= DeviceInfoOpenApiManager.getSubAccountDeviceList(pageNo,pageSize);
|
||||
handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, response).sendToTarget();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,218 @@
|
|||
package com.common.openapi;
|
||||
|
||||
import com.common.openapi.entity.CloudRecordsData;
|
||||
import com.common.openapi.entity.DeviceChannelInfoData;
|
||||
import com.common.openapi.entity.DeviceDetailListData;
|
||||
import com.common.openapi.entity.DeviceLocalCacheData;
|
||||
import com.common.openapi.entity.DeviceVersionListData;
|
||||
import com.common.openapi.entity.LocalRecordsData;
|
||||
import com.mm.android.deviceaddmodule.device_wifi.CurWifiInfo;
|
||||
|
||||
public interface IGetDeviceInfoCallBack {
|
||||
public interface IDeviceListCallBack {
|
||||
/**
|
||||
* 成功获取到设备列表
|
||||
*
|
||||
* @param responseData
|
||||
*/
|
||||
void deviceList(DeviceDetailListData.Response responseData);
|
||||
|
||||
/**
|
||||
* 错误回调
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface IDeviceVersionCallBack {
|
||||
/**
|
||||
* 获取设备版本和可升级信息
|
||||
*
|
||||
* @param responseData
|
||||
*/
|
||||
void deviceVersion(DeviceVersionListData.Response responseData);
|
||||
|
||||
/**
|
||||
* 错误回调
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface IModifyDeviceCallBack {
|
||||
/**
|
||||
* 修改设备或通道名称成功
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
void deviceModify(boolean result);
|
||||
|
||||
/**
|
||||
* 错误回调
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface IUnbindDeviceCallBack {
|
||||
/**
|
||||
* 解绑设备成功
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
void unBindDevice(boolean result);
|
||||
|
||||
/**
|
||||
* 错误回调
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface IDeviceChannelInfoCallBack {
|
||||
/**
|
||||
* 单个设备通道的详细信息获取
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
void deviceChannelInfo(DeviceChannelInfoData.Response result);
|
||||
|
||||
/**
|
||||
* 错误回调
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface IDeviceAlarmStatusCallBack {
|
||||
/**
|
||||
* 设置动检开关
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
void deviceAlarmStatus(boolean result);
|
||||
|
||||
/**
|
||||
* 错误回调
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface IDeviceUpdateCallBack {
|
||||
/**
|
||||
* 设备升级
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
void deviceUpdate(boolean result);
|
||||
|
||||
/**
|
||||
* 错误回调
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface IDeviceCloudRecordCallBack {
|
||||
/**
|
||||
* 倒序查询设备云录像片段
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
void deviceCloudRecord(CloudRecordsData.Response result);
|
||||
|
||||
/**
|
||||
* 错误回调
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface IDeviceLocalRecordCallBack {
|
||||
/**
|
||||
* 查询设备设备录像片段
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
void deviceLocalRecord(LocalRecordsData.Response result);
|
||||
|
||||
/**
|
||||
* 错误回调
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface IDeviceDeleteRecordCallBack {
|
||||
/**
|
||||
* 删除设备云录像片段
|
||||
*/
|
||||
void deleteDeviceRecord();
|
||||
|
||||
/**
|
||||
* 错误回调
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface IDeviceCacheCallBack {
|
||||
/**
|
||||
* 获取设备缓存信息
|
||||
*/
|
||||
void deviceCache(DeviceLocalCacheData deviceLocalCacheData);
|
||||
|
||||
/**
|
||||
* 错误回调
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface IDeviceCurrentWifiInfoCallBack {
|
||||
/**
|
||||
* 设备当前连接热点信息
|
||||
*/
|
||||
void deviceCurrentWifiInfo(CurWifiInfo curWifiInfo);
|
||||
|
||||
/**
|
||||
* 错误回调
|
||||
*
|
||||
* @param throwable
|
||||
*/
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface IModifyDeviceName {
|
||||
/**
|
||||
* 设备修改之后的名字
|
||||
*/
|
||||
void deviceName(String newName);
|
||||
}
|
||||
|
||||
public interface ISubAccountDevice<T>{
|
||||
void DeviceList(T response);
|
||||
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
public interface ICommon<T>{
|
||||
void onCommonBack(T response);
|
||||
void onError(Throwable throwable);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.common.openapi;
|
||||
|
||||
public class MethodConst {
|
||||
//分页获取乐橙app添加或分享的设备通道基本信息
|
||||
public static String METHOD_DEVICE_BASE_LIST = "deviceBaseList";
|
||||
//分页获取开放平台添加设备的通道基本信息
|
||||
public static String METHOD_DEVICE_OPEN_LIST = "deviceOpenList";
|
||||
//批量根据设备序列号、通道号列表和配件号列表,获取设备的详细信息
|
||||
public static String METHOD_DEVICE_OPEN_DETAIL_LIST = "deviceOpenDetailList";
|
||||
//批量根据设备序列号、通道号列表和配件号列表,获取乐橙app添加或分享的设备的详细信息
|
||||
public static String METHOD_DEVICE_BASE_DETAIL_LIST = "deviceBaseDetailList";
|
||||
//解绑设备
|
||||
public static String METHOD_DEVICE_UN_BIND = "unBindDevice";
|
||||
//获取设备版本和可升级信息
|
||||
public static String METHOD_DEVICE_VERSION_LIST = "deviceVersionList";
|
||||
//修改设备或通道名称
|
||||
public static String METHOD_DEVICE_MODIFY_NAME = "modifyDeviceName";
|
||||
//单个设备通道的详细信息获取
|
||||
public static String METHOD_DEVICE_CHANNEL_INFO = "bindDeviceChannelInfo";
|
||||
//设置动检开关
|
||||
public static String METHOD_DEVICE_MODIFY_ALARM_STATUS = "modifyDeviceAlarmStatus";
|
||||
//设备升级
|
||||
public static String METHOD_DEVICE_UPDATE = "upgradeDevice";
|
||||
//倒序查询设备云录像片段
|
||||
public static String METHOD_GET_CLOUND_RECORDS = "getCloudRecords";
|
||||
//查询设备设备录像片段
|
||||
public static String METHOD_QUERY_LOCAL_RECORD = "queryLocalRecords";
|
||||
//云台移动控制接口(V2版本)
|
||||
public static String METHOD_CONTROL_MOVE_PTZ = "controlMovePTZ";
|
||||
//查询设备云录像片
|
||||
public static String METHOD_QUERY_CLOUND_RECORDS = "queryCloudRecords";
|
||||
//删除设备云录像片段
|
||||
public static String METHOD_DELETE_CLOUND_RECORDS = "deleteCloudRecords";
|
||||
|
||||
public static String LIST_SUB_ACCOUNT_DEVICE = "listSubAccountDevice";
|
||||
|
||||
public static String SUB_ACCOUNT_DEVICE_LIST = "subAccountDeviceList";
|
||||
|
||||
public static String DELETE_DEVICE_PERMISSION = "deleteDevicePermission";
|
||||
|
||||
public static String SD_STATUE_QUERY = "deviceSdcardStatus";
|
||||
public static String GET_DEVICE_CLOUD = "getDeviceCloud";
|
||||
|
||||
|
||||
|
||||
public interface ParamConst {
|
||||
public String deviceDetail = "deviceDetail";
|
||||
public String recordType = "recordType";
|
||||
public String recordData = "recordsData";
|
||||
public int recordTypeLocal = 2;
|
||||
public int recordTypeCloud = 1;
|
||||
public String fromList = "list";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class CloudRecordsData implements Serializable {
|
||||
public CloudRecordsData.RequestData data = new CloudRecordsData.RequestData();
|
||||
|
||||
public static class Response {
|
||||
public CloudRecordsData.ResponseData data;
|
||||
|
||||
public void parseData(JsonObject json) {
|
||||
Gson gson = new Gson();
|
||||
this.data = gson.fromJson(json.toString(), CloudRecordsData.ResponseData.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ResponseData implements Serializable {
|
||||
public List<RecordsBean> records;
|
||||
|
||||
public static class RecordsBean implements Serializable {
|
||||
public String recordId;
|
||||
public String deviceId;
|
||||
public String channelId;
|
||||
public String beginTime;
|
||||
public String endTime;
|
||||
public String size;
|
||||
public String thumbUrl;
|
||||
public int encryptMode;
|
||||
public String recordRegionId;
|
||||
public String type;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RequestData implements Serializable {
|
||||
public String token;
|
||||
public String deviceId;
|
||||
public String channelId = "0";
|
||||
public String beginTime;
|
||||
public String endTime;
|
||||
public long nextRecordId=-1;
|
||||
public long count;
|
||||
public String queryRange;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ControlMovePTZData implements Serializable {
|
||||
public ControlMovePTZData.RequestData data = new ControlMovePTZData.RequestData();
|
||||
|
||||
public static class RequestData implements Serializable {
|
||||
public String token;
|
||||
public String deviceId;
|
||||
public String channelId = "0";
|
||||
//0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-停止
|
||||
public String operation;
|
||||
public long duration;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class DeleteCloudRecordsData implements Serializable {
|
||||
public DeleteCloudRecordsData.RequestData data = new DeleteCloudRecordsData.RequestData();
|
||||
|
||||
public static class RequestData implements Serializable {
|
||||
public String token;
|
||||
public List<String> recordRegionIds;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DeviceAlarmStatusData implements Serializable {
|
||||
public DeviceAlarmStatusData.RequestData data = new DeviceAlarmStatusData.RequestData();
|
||||
|
||||
public static class RequestData implements Serializable {
|
||||
public String token;
|
||||
public String deviceId;
|
||||
public String channelId="0";
|
||||
public boolean enable;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DeviceChannelInfoData implements Serializable {
|
||||
public DeviceChannelInfoData.RequestData data = new DeviceChannelInfoData.RequestData();
|
||||
|
||||
public static class Response {
|
||||
public DeviceChannelInfoData.ResponseData data;
|
||||
|
||||
public void parseData(JsonObject json) {
|
||||
Gson gson = new Gson();
|
||||
this.data = gson.fromJson(json.toString(), DeviceChannelInfoData.ResponseData.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ResponseData implements Serializable {
|
||||
public String deviceId;
|
||||
public int alarmStatus;
|
||||
public int channelId;
|
||||
public String channelName;
|
||||
public String channelOnline;
|
||||
public String channelPicUrl;
|
||||
public String shareStatus;
|
||||
public String shareFunctions;
|
||||
public String csStatus;
|
||||
public String channelAbility;
|
||||
}
|
||||
|
||||
public static class RequestData implements Serializable {
|
||||
public String token;
|
||||
public String deviceId;
|
||||
public String channelId="0";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,478 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceDetailListData implements Serializable {
|
||||
public DeviceDetailListData.RequestData data = new DeviceDetailListData.RequestData();
|
||||
|
||||
public static class RequestData implements Serializable {
|
||||
public String token;
|
||||
public List<DeviceListBean> deviceList;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RequestData{" +
|
||||
"token='" + token + '\'' +
|
||||
", deviceList=" + deviceList +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class DeviceListBean implements Serializable {
|
||||
public String deviceId;
|
||||
public String channelList;
|
||||
public String apList;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeviceListBean{" +
|
||||
"deviceId='" + deviceId + '\'' +
|
||||
", channelList='" + channelList + '\'' +
|
||||
", apList='" + apList + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Response {
|
||||
public DeviceDetailListData.ResponseData data;
|
||||
public long baseBindId = -1;
|
||||
public long openBindId = -1;
|
||||
|
||||
public void parseData(JsonObject json) {
|
||||
Gson gson = new Gson();
|
||||
this.data = gson.fromJson(json.toString(), DeviceDetailListData.ResponseData.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ResponseData implements Serializable {
|
||||
public int count;
|
||||
|
||||
public List<DeviceListBean> deviceList;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResponseData{" +
|
||||
"count=" + count +
|
||||
", deviceList=" + deviceList +
|
||||
'}';
|
||||
}
|
||||
|
||||
public List<DeviceListBean> getDeviceList() {
|
||||
if (deviceList == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
public void setDeviceList(List<DeviceListBean> deviceList) {
|
||||
this.deviceList = deviceList;
|
||||
}
|
||||
|
||||
public static class DeviceListBean implements Serializable {
|
||||
public String deviceId;
|
||||
public String id;
|
||||
public String status;
|
||||
public String deviceModel;
|
||||
public String catalog;
|
||||
public String brand;
|
||||
public String version;
|
||||
public String name;
|
||||
public String ability;
|
||||
public String accessType;
|
||||
public int checkedChannel;
|
||||
public String playToken;
|
||||
public int encryptMode;
|
||||
public String channelNum;
|
||||
public String permission;
|
||||
public String addressId;
|
||||
public String deviceType;
|
||||
//1:开放平台添加 2:乐橙App添加
|
||||
public int deviceSource;
|
||||
public List<ChannelsBean> channels = new ArrayList<>();
|
||||
public List<AplistBean> aplist;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeviceListBean{" +
|
||||
"deviceId='" + deviceId + '\'' +
|
||||
", status='" + status + '\'' +
|
||||
", deviceModel='" + deviceModel + '\'' +
|
||||
", catalog='" + catalog + '\'' +
|
||||
", brand='" + brand + '\'' +
|
||||
", version='" + version + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", ability='" + ability + '\'' +
|
||||
", accessType='" + accessType + '\'' +
|
||||
", checkedChannel=" + checkedChannel +
|
||||
", channelNum=" + channelNum +
|
||||
", playToken='" + playToken + '\'' +
|
||||
", deviceSource=" + deviceSource +
|
||||
", channels=" + channels +
|
||||
", aplist=" + aplist +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getAddressId() {
|
||||
return addressId == null ? "" : addressId;
|
||||
}
|
||||
|
||||
public void setAddressId(String addressId) {
|
||||
this.addressId = addressId == null ? "" : addressId;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType == null ? "" : deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType == null ? "" : deviceType;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id == null ? "" : id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id == null ? "" : id;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId == null ? "" : deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId == null ? "" : deviceId;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status == null ? "" : status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status == null ? "" : status;
|
||||
}
|
||||
|
||||
public String getDeviceModel() {
|
||||
return deviceModel == null ? "" : deviceModel;
|
||||
}
|
||||
|
||||
public void setDeviceModel(String deviceModel) {
|
||||
this.deviceModel = deviceModel == null ? "" : deviceModel;
|
||||
}
|
||||
|
||||
public String getCatalog() {
|
||||
return catalog == null ? "" : catalog;
|
||||
}
|
||||
|
||||
public void setCatalog(String catalog) {
|
||||
this.catalog = catalog == null ? "" : catalog;
|
||||
}
|
||||
|
||||
public String getBrand() {
|
||||
return brand == null ? "" : brand;
|
||||
}
|
||||
|
||||
public void setBrand(String brand) {
|
||||
this.brand = brand == null ? "" : brand;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version == null ? "" : version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version == null ? "" : version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name == null ? "" : name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name == null ? "" : name;
|
||||
}
|
||||
|
||||
public String getAbility() {
|
||||
return ability == null ? "" : ability;
|
||||
}
|
||||
|
||||
public void setAbility(String ability) {
|
||||
this.ability = ability == null ? "" : ability;
|
||||
}
|
||||
|
||||
public String getAccessType() {
|
||||
return accessType == null ? "" : accessType;
|
||||
}
|
||||
|
||||
public void setAccessType(String accessType) {
|
||||
this.accessType = accessType == null ? "" : accessType;
|
||||
}
|
||||
|
||||
public int getCheckedChannel() {
|
||||
return checkedChannel;
|
||||
}
|
||||
|
||||
public void setCheckedChannel(int checkedChannel) {
|
||||
this.checkedChannel = checkedChannel;
|
||||
}
|
||||
|
||||
public String getPlayToken() {
|
||||
return playToken == null ? "" : playToken;
|
||||
}
|
||||
|
||||
public void setPlayToken(String playToken) {
|
||||
this.playToken = playToken == null ? "" : playToken;
|
||||
}
|
||||
|
||||
public int getEncryptMode() {
|
||||
return encryptMode;
|
||||
}
|
||||
|
||||
public void setEncryptMode(int encryptMode) {
|
||||
this.encryptMode = encryptMode;
|
||||
}
|
||||
|
||||
public String getChannelNum() {
|
||||
return channelNum == null ? "" : channelNum;
|
||||
}
|
||||
|
||||
public void setChannelNum(String channelNum) {
|
||||
this.channelNum = channelNum == null ? "" : channelNum;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission == null ? "" : permission;
|
||||
}
|
||||
|
||||
public void setPermission(String permission) {
|
||||
this.permission = permission == null ? "" : permission;
|
||||
}
|
||||
|
||||
public int getDeviceSource() {
|
||||
return deviceSource;
|
||||
}
|
||||
|
||||
public void setDeviceSource(int deviceSource) {
|
||||
this.deviceSource = deviceSource;
|
||||
}
|
||||
|
||||
public List<ChannelsBean> getChannels() {
|
||||
if (channels == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return channels;
|
||||
}
|
||||
|
||||
public void setChannels(List<ChannelsBean> channels) {
|
||||
this.channels = channels;
|
||||
}
|
||||
|
||||
public List<AplistBean> getAplist() {
|
||||
if (aplist == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return aplist;
|
||||
}
|
||||
|
||||
public void setAplist(List<AplistBean> aplist) {
|
||||
this.aplist = aplist;
|
||||
}
|
||||
|
||||
public static class ChannelsBean implements Serializable {
|
||||
public String channelId;
|
||||
public String deviceId;
|
||||
public String channelName;
|
||||
public String ability;
|
||||
public String status;
|
||||
public String picUrl;
|
||||
public String remindStatus;
|
||||
public String cameraStatus;
|
||||
public String storageStrategyStatus;
|
||||
public String shareStatus;
|
||||
public String shareFunctions;
|
||||
public String permission;
|
||||
// public List<ResolutionBean> resolutions = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ChannelsBean{" +
|
||||
"channelId='" + channelId + '\'' +
|
||||
", deviceId='" + deviceId + '\'' +
|
||||
", channelName='" + channelName + '\'' +
|
||||
", ability='" + ability + '\'' +
|
||||
", status='" + status + '\'' +
|
||||
", picUrl='" + picUrl + '\'' +
|
||||
", remindStatus='" + remindStatus + '\'' +
|
||||
", cameraStatus='" + cameraStatus + '\'' +
|
||||
", storageStrategyStatus='" + storageStrategyStatus + '\'' +
|
||||
", shareStatus='" + shareStatus + '\'' +
|
||||
", shareFunctions='" + shareFunctions + '\'' +
|
||||
", permission='" + permission + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getChannelId() {
|
||||
return channelId == null ? "" : channelId;
|
||||
}
|
||||
|
||||
public void setChannelId(String channelId) {
|
||||
this.channelId = channelId == null ? "" : channelId;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId == null ? "" : deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId == null ? "" : deviceId;
|
||||
}
|
||||
|
||||
public String getChannelName() {
|
||||
return channelName == null ? "" : channelName;
|
||||
}
|
||||
|
||||
public void setChannelName(String channelName) {
|
||||
this.channelName = channelName == null ? "" : channelName;
|
||||
}
|
||||
|
||||
public String getAbility() {
|
||||
return ability == null ? "" : ability;
|
||||
}
|
||||
|
||||
public void setAbility(String ability) {
|
||||
this.ability = ability == null ? "" : ability;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status == null ? "" : status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status == null ? "" : status;
|
||||
}
|
||||
|
||||
public String getPicUrl() {
|
||||
return picUrl == null ? "" : picUrl;
|
||||
}
|
||||
|
||||
public void setPicUrl(String picUrl) {
|
||||
this.picUrl = picUrl == null ? "" : picUrl;
|
||||
}
|
||||
|
||||
public String getRemindStatus() {
|
||||
return remindStatus == null ? "" : remindStatus;
|
||||
}
|
||||
|
||||
public void setRemindStatus(String remindStatus) {
|
||||
this.remindStatus = remindStatus == null ? "" : remindStatus;
|
||||
}
|
||||
|
||||
public String getCameraStatus() {
|
||||
return cameraStatus == null ? "" : cameraStatus;
|
||||
}
|
||||
|
||||
public void setCameraStatus(String cameraStatus) {
|
||||
this.cameraStatus = cameraStatus == null ? "" : cameraStatus;
|
||||
}
|
||||
|
||||
public String getStorageStrategyStatus() {
|
||||
return storageStrategyStatus == null ? "" : storageStrategyStatus;
|
||||
}
|
||||
|
||||
public void setStorageStrategyStatus(String storageStrategyStatus) {
|
||||
this.storageStrategyStatus = storageStrategyStatus == null ? "" : storageStrategyStatus;
|
||||
}
|
||||
|
||||
public String getShareStatus() {
|
||||
return shareStatus == null ? "" : shareStatus;
|
||||
}
|
||||
|
||||
public void setShareStatus(String shareStatus) {
|
||||
this.shareStatus = shareStatus == null ? "" : shareStatus;
|
||||
}
|
||||
|
||||
public String getShareFunctions() {
|
||||
return shareFunctions == null ? "" : shareFunctions;
|
||||
}
|
||||
|
||||
public void setShareFunctions(String shareFunctions) {
|
||||
this.shareFunctions = shareFunctions == null ? "" : shareFunctions;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission == null ? "" : permission;
|
||||
}
|
||||
|
||||
public void setPermission(String permission) {
|
||||
this.permission = permission == null ? "" : permission;
|
||||
}
|
||||
|
||||
/*public List<ResolutionBean> getResolutions() {
|
||||
if (resolutions == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return resolutions;
|
||||
}
|
||||
|
||||
public void setResolutions(List<ResolutionBean> resolutions) {
|
||||
this.resolutions = resolutions;
|
||||
}*/
|
||||
|
||||
public static class ResolutionBean implements Serializable {
|
||||
public String name;
|
||||
public int imageSize;
|
||||
public int streamType;
|
||||
|
||||
public ResolutionBean(String name, int imageSize, int streamType) {
|
||||
this.name = name;
|
||||
this.imageSize = imageSize;
|
||||
this.streamType = streamType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResolutionBean{" +
|
||||
"name='" + name + '\'' +
|
||||
", imageSize=" + imageSize +
|
||||
", streamType=" + streamType +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class AplistBean implements Serializable {
|
||||
public String apId;
|
||||
public String apName;
|
||||
public String apType;
|
||||
public String apModel;
|
||||
public String ioType;
|
||||
public String apVersion;
|
||||
public String apStatus;
|
||||
public String apEnable;
|
||||
public String apCapacity;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AplistBean{" +
|
||||
"apId='" + apId + '\'' +
|
||||
", apName='" + apName + '\'' +
|
||||
", apType='" + apType + '\'' +
|
||||
", apModel='" + apModel + '\'' +
|
||||
", ioType='" + ioType + '\'' +
|
||||
", apVersion='" + apVersion + '\'' +
|
||||
", apStatus='" + apStatus + '\'' +
|
||||
", apEnable='" + apEnable + '\'' +
|
||||
", apCapacity='" + apCapacity + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceListData implements Serializable{
|
||||
public DeviceListData.RequestData data = new DeviceListData.RequestData();
|
||||
|
||||
public static class Response {
|
||||
public DeviceListData.ResponseData data;
|
||||
|
||||
public void parseData(JsonObject json) {
|
||||
Gson gson = new Gson();
|
||||
this.data = gson.fromJson(json.toString(), DeviceListData.ResponseData.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ResponseData implements Serializable {
|
||||
public String count;
|
||||
public List<DeviceListElement> deviceList;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResponseData{" +
|
||||
"count='" + count + '\'' +
|
||||
", deviceList=" + deviceList +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class DeviceListElement implements Serializable {
|
||||
public String bindId;
|
||||
public String deviceId;
|
||||
public List<ChannelsElement> channels;
|
||||
public List<AplistElement> aplist;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeviceListElement{" +
|
||||
"bindId='" + bindId + '\'' +
|
||||
", deviceId='" + deviceId + '\'' +
|
||||
", channels=" + channels +
|
||||
", aplist=" + aplist +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class ChannelsElement implements Serializable {
|
||||
public String channelName;
|
||||
public String channelId;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ChannelsElement{" +
|
||||
"channelName='" + channelName + '\'' +
|
||||
", channelId='" + channelId + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class AplistElement implements Serializable {
|
||||
public String apId;
|
||||
public String apName;
|
||||
public String apType;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AplistElement{" +
|
||||
"apId='" + apId + '\'' +
|
||||
", apName='" + apName + '\'' +
|
||||
", apType='" + apType + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class RequestData implements Serializable {
|
||||
public String token;
|
||||
public String limit="8";
|
||||
public String type="bindAndShare";
|
||||
public String needApInfo="false";
|
||||
public long baseBindId=-1;
|
||||
public long openBindId=-1;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RequestData{" +
|
||||
"token='" + token + '\'' +
|
||||
", limit='" + limit + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", needApInfo='" + needApInfo + '\'' +
|
||||
", baseBindId=" + baseBindId +
|
||||
", openBindId=" + openBindId +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DeviceLocalCacheData implements Serializable {
|
||||
private long cacheId;
|
||||
private String deviceId;
|
||||
private String deviceName;
|
||||
private String channelId;
|
||||
private String channelName;
|
||||
private String picPath;
|
||||
private long creationTime;
|
||||
private long modifyTime;
|
||||
|
||||
public long getCacheId() {
|
||||
return cacheId;
|
||||
}
|
||||
|
||||
public void setCacheId(long cacheId) {
|
||||
this.cacheId = cacheId;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getDeviceName() {
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
public void setDeviceName(String deviceName) {
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
public String getChannelId() {
|
||||
return channelId;
|
||||
}
|
||||
|
||||
public void setChannelId(String channelId) {
|
||||
this.channelId = channelId;
|
||||
}
|
||||
|
||||
public String getChannelName() {
|
||||
return channelName;
|
||||
}
|
||||
|
||||
public void setChannelName(String channelName) {
|
||||
this.channelName = channelName;
|
||||
}
|
||||
|
||||
public String getPicPath() {
|
||||
return picPath;
|
||||
}
|
||||
|
||||
public void setPicPath(String picPath) {
|
||||
this.picPath = picPath;
|
||||
}
|
||||
|
||||
public void setCreationTime(long creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
public void setModifyTime(long modifyTime) {
|
||||
this.modifyTime = modifyTime;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DeviceModifyNameData implements Serializable {
|
||||
public DeviceModifyNameData.RequestData data = new DeviceModifyNameData.RequestData();
|
||||
|
||||
public static class RequestData implements Serializable {
|
||||
public String token;
|
||||
public String deviceId;
|
||||
public String channelId;
|
||||
public String name;
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getChannelId() {
|
||||
return channelId;
|
||||
}
|
||||
|
||||
public void setChannelId(String channelId) {
|
||||
this.channelId = channelId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DeviceUnBindData implements Serializable {
|
||||
public DeviceUnBindData.RequestData data = new DeviceUnBindData.RequestData();
|
||||
|
||||
public static class RequestData implements Serializable {
|
||||
public String token;
|
||||
public String deviceId;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceVersionListData implements Serializable {
|
||||
public DeviceVersionListData.RequestData data = new DeviceVersionListData.RequestData();
|
||||
|
||||
public static class Response {
|
||||
public DeviceVersionListData.ResponseData data;
|
||||
|
||||
public void parseData(JsonObject json) {
|
||||
Gson gson = new Gson();
|
||||
this.data = gson.fromJson(json.toString(), DeviceVersionListData.ResponseData.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ResponseData implements Serializable {
|
||||
public String count;
|
||||
public List<DeviceVersionListBean> deviceVersionList;
|
||||
|
||||
public String getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(String count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public static class DeviceVersionListBean implements Serializable {
|
||||
public boolean canBeUpgrade;
|
||||
public String deviceId;
|
||||
public String version;
|
||||
public UpgradeInfoBean upgradeInfo;
|
||||
|
||||
public boolean isCanBeUpgrade() {
|
||||
return canBeUpgrade;
|
||||
}
|
||||
|
||||
public void setCanBeUpgrade(boolean canBeUpgrade) {
|
||||
this.canBeUpgrade = canBeUpgrade;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public UpgradeInfoBean getUpgradeInfo() {
|
||||
return upgradeInfo;
|
||||
}
|
||||
|
||||
public void setUpgradeInfo(UpgradeInfoBean upgradeInfo) {
|
||||
this.upgradeInfo = upgradeInfo;
|
||||
}
|
||||
|
||||
public static class UpgradeInfoBean implements Serializable {
|
||||
public String version;
|
||||
public String description;
|
||||
public String packageUrl;
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getPackageUrl() {
|
||||
return packageUrl;
|
||||
}
|
||||
|
||||
public void setPackageUrl(String packageUrl) {
|
||||
this.packageUrl = packageUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class RequestData implements Serializable {
|
||||
public String token;
|
||||
public String deviceIds;
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getDeviceIds() {
|
||||
return deviceIds;
|
||||
}
|
||||
|
||||
public void setDeviceIds(String deviceIds) {
|
||||
this.deviceIds = deviceIds;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class LocalRecordsData implements Serializable {
|
||||
public LocalRecordsData.RequestData data = new LocalRecordsData.RequestData();
|
||||
|
||||
public static class Response {
|
||||
public LocalRecordsData.ResponseData data;
|
||||
|
||||
public void parseData(JsonObject json) {
|
||||
Gson gson = new Gson();
|
||||
this.data = gson.fromJson(json.toString(), LocalRecordsData.ResponseData.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ResponseData implements Serializable {
|
||||
public List<RecordsBean> records;
|
||||
|
||||
public static class RecordsBean implements Serializable {
|
||||
public String recordId;
|
||||
public long fileLength;
|
||||
public String channelID;
|
||||
public String beginTime;
|
||||
public String endTime;
|
||||
public String type;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RequestData implements Serializable {
|
||||
public String token;
|
||||
public String deviceId;
|
||||
public String channelId = "0";
|
||||
public String beginTime;
|
||||
public String endTime;
|
||||
public String type;
|
||||
public String queryRange;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import com.lechange.demo.adapter.DeviceInnerRecordListAdapter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class RecordListData implements Serializable {
|
||||
public String period;
|
||||
public List<RecordsData> recordsData;
|
||||
public DeviceInnerRecordListAdapter deviceInnerRecordListAdapters;
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class RecordsData implements Serializable {
|
||||
//0 云录像 1设备录像
|
||||
public int recordType;
|
||||
//通用字段
|
||||
public String recordId;
|
||||
public String beginTime;
|
||||
public String endTime;
|
||||
public String type;
|
||||
public boolean check;
|
||||
//设备录像
|
||||
public long fileLength;
|
||||
public String channelID;
|
||||
//云录像
|
||||
public String deviceId;
|
||||
public String channelId;
|
||||
public String size;
|
||||
public String thumbUrl;
|
||||
public int encryptMode;
|
||||
public String recordRegionId;
|
||||
|
||||
public static RecordsData parseCloudData(CloudRecordsData.ResponseData.RecordsBean recordsBean){
|
||||
RecordsData recordsData=new RecordsData();
|
||||
recordsData.recordType=0;
|
||||
recordsData.recordId=recordsBean.recordId;
|
||||
recordsData.beginTime=recordsBean.beginTime;
|
||||
recordsData.endTime=recordsBean.endTime;
|
||||
recordsData.type=recordsBean.type;
|
||||
recordsData.deviceId=recordsBean.deviceId;
|
||||
recordsData.channelId=recordsBean.channelId;
|
||||
recordsData.size=recordsBean.size;
|
||||
recordsData.thumbUrl=recordsBean.thumbUrl;
|
||||
recordsData.encryptMode=recordsBean.encryptMode;
|
||||
recordsData.recordRegionId=recordsBean.recordRegionId;
|
||||
return recordsData;
|
||||
}
|
||||
|
||||
public static RecordsData parseLocalData(LocalRecordsData.ResponseData.RecordsBean recordsBean){
|
||||
RecordsData recordsData=new RecordsData();
|
||||
recordsData.recordType=1;
|
||||
recordsData.recordId=recordsBean.recordId;
|
||||
recordsData.beginTime=recordsBean.beginTime;
|
||||
recordsData.endTime=recordsBean.endTime;
|
||||
recordsData.type=recordsBean.type;
|
||||
recordsData.fileLength=recordsBean.fileLength;
|
||||
recordsData.channelID=recordsBean.channelID;
|
||||
return recordsData;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.common.openapi.entity;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class SubAccountDeviceData implements Serializable {
|
||||
|
||||
public static class Response {
|
||||
public SubAccountDeviceData.ResponseData data;
|
||||
|
||||
public void parseData(JsonObject json) {
|
||||
Gson gson = new Gson();
|
||||
this.data = gson.fromJson(json.toString(), SubAccountDeviceData.ResponseData.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ResponseData implements Serializable {
|
||||
public int pageNo;
|
||||
public int pageSize;
|
||||
public int total;
|
||||
List<DeviceList> deviceLists;
|
||||
|
||||
public static class DeviceList implements Serializable{
|
||||
public String deviceId;
|
||||
public String permission;
|
||||
List<ChannelList> channelLists;
|
||||
}
|
||||
|
||||
public static class ChannelList implements Serializable{
|
||||
public String channelId;
|
||||
public String permission;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,241 @@
|
|||
package com.ds.remote;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
public class Device {
|
||||
|
||||
//设备号定义
|
||||
public static enum DEVICE_TYPE { //设备类型
|
||||
C_AUX_DEVICE, //国外
|
||||
C_DVB_DEVICE, //国内DVB
|
||||
C_STB_DEVICE, //国外机顶盒
|
||||
C_ATV_DEVICE, //国内TV,或东南亚TV
|
||||
C_CTV_DEVICE, //国外TV
|
||||
C_DVD_DEVICE, //国外DVD
|
||||
C_ARC_DEVICE //
|
||||
}
|
||||
|
||||
//每个设备的最大码组数定义
|
||||
public static int C_AUX_GROUP_MAX = 501;
|
||||
public static int C_DVB_GROUP_MAX = 372;
|
||||
public static int C_STB_GROUP_MAX = 213;
|
||||
public static int C_ATV_GROUP_MAX = 550;
|
||||
public static int C_CTV_GROUP_MAX = 360;
|
||||
public static int C_DVD_GROUP_MAX = 315;
|
||||
public static int C_ARC_GROUP_MAX = 1000;
|
||||
|
||||
//通信命令定义
|
||||
public static int CMD_URC_INDEX = 0x01; //发送 URC 的设备号、码组号、键值给IRIC,并启动IRIC发送内部码
|
||||
public static int CMD_ARC_INDEX = 0x02; //发送 ARC 的码组号、空调状态变量给IRIC,并启动IRIC发送内部空调码
|
||||
public static int CMD_URC_FID = 0x03; //发送 URC 的数据文件号和键值给IRIC,并启动IRIC从MPU读取数据并发送红外码
|
||||
public static int CMD_ARC_FID = 0x04; //发送 ARC 的数据文件号和空调状态变量给IRIC,并启动IRIC从MPU读取数据并发送红外码
|
||||
public static int CMD_FILE_DATA = 0x05; //将在数据文件中读到的数据发送给IRIC(与IRIC向MPU发送的命令CMD_READ_FILE对应)
|
||||
public static int CMD_LEN_START = 0x06; //发送 学习命令给IRIC,并启动IRIC进入学习状态(与IRIC向MPU发送学习数据的命令CMD_LEN_DATA对应)
|
||||
public static int CMD_LEN_DATA = 0x07; //发送 LRC数据给IRIC,并启动IRIC发送该数据(与IRIC向MPU发送学习数据的命令CMD_LEN_DATA相同)
|
||||
//public static int CMD_READ_FILE = 0x80 //发送读数据文件命令给MPU,MPU根据文件号FILEID,偏移地址ADDR_OFS,需要读取的数据个数DataCnt,将数据取出后发给IRIC
|
||||
public static int CMD_ARC_VAR = 0x0A; //发送 检测IRIC程序版本命令给IRIC,并启动IRIC将版本号发给MPU(与IRIC向MPU发送版本信息的命令CMD_IRIC_VER相同)
|
||||
public static int CMD_IRIC_VER = 0x08; //IRIC将修正后的空调状态变量发给MPU,MPU收到后覆盖原来的空调状态变量(与MPU向IRIC发送空调命令CMD_ARC_FID,CMD_ARC_INDEX对应)
|
||||
public static int CMD_ARC_LEN_START = 0x0c; //空调学习命令
|
||||
public static int CMD_ARC_LEN_DATA = 0x0d; //发空调学习数据命令
|
||||
|
||||
|
||||
//
|
||||
public static int ADR_VAR_LEN = 14;
|
||||
|
||||
/**************
|
||||
* 学习返回状态
|
||||
****************************************/
|
||||
public static int NO_LEARN_DATA = 0;
|
||||
//public static int LEN_FLAS = 0xff
|
||||
public static int LEN_DOING = 0x01;
|
||||
public static int LEN_OK = 0x02;
|
||||
public static int LEN_ERROR = 0x03;
|
||||
|
||||
|
||||
//================================================================================================
|
||||
/* 空调变量数组 ADR_VAR[]说明 */
|
||||
public static int ADR_VAR_START = 0x00; //空调变量的存放位置(需要根据程序修改)
|
||||
public static int ADR_MODE = 0; //模式------------》变化范围"0~4"对应模式详见"模式常量"定义
|
||||
public static int ADR_TMP = 1; //温度------------》变化范围"0~16"对应温度"16~32"
|
||||
public static int ADR_FANLEV = 2; //风量------------》变化范围"0~3"对应风量"自动,低,中,高"
|
||||
public static int ADR_FANDIR = 3; //风向------------》按自动风向键清0,按手动风向键加1(在1~8之间变化)(用于自动风向和手动风向数据在同一位置)
|
||||
public static int ADR_AFANDIR = 4; //自动风向----》按自动风向键改变(在0~8之间变化),按手动风向键不变(用于自动风向和手动风向数据在不同位置)
|
||||
public static int ADR_MFANDIR = 5; //手动风向----》按手动风向键改变(在0~8之间变化),按自动风向键不变(用于自动风向和手动风向数据在不同位置,或只有一个风向键的时候)
|
||||
public static int ADR_CKHOUR = 6; //时钟小时
|
||||
public static int ADR_TIMEON = 7; //定开时间(小时)----》变化范围"0~12"对应定开时间"0~12"小时(只要用于定开定关数据在不同位置的时候)
|
||||
public static int ADR_TIMEOFF = 8; //定关时间(小时)----》变化范围"0~12"对应定关时间"0~12"小时(只要用于定开定关数据在不同位置的时候)
|
||||
public static int ADR_KEYVAL = 9; //键值------------》详见"按键常量"定义,空键:0FFH
|
||||
public static int ADR_SYSFLAG = 10; //功能标志---》详见"功能标志"常量定义
|
||||
public static int ADR_TMSTATE7 = 11; //定时状态(7种),详见"定时状态常量(7态)"
|
||||
public static int ADR_TMSTATE3 = 12; //定时状态(3种),详见"定时状态常量(3态)"
|
||||
//ADR_TM_MIN EQU 13 //定时分钟
|
||||
public static int ADR_CKMIN = 13; //时钟分钟
|
||||
//#define ADR_TMON_10MINS 14 //定时开分钟
|
||||
//#define ADR_TMOFF_10MINS 15 //定时关分钟
|
||||
|
||||
|
||||
/*ADR_SYSFLAG(功能标志)常量定义*/
|
||||
public static int SYSFLAG_POWER = 0x01; //00000001B //开关机标志----》开关=1,关机=0
|
||||
public static int ADSF_POWER = 0; //开关机标志位置
|
||||
public static int SYSFLAG_SLEEP = 0x02; //00000010B //睡眠标志--------》睡眠开=1,睡眠关=0
|
||||
public static int ADSF_SLEEP = 1; //睡眠标志位置
|
||||
public static int SYSFLAG_HEAT = 0x04; //00000100B //电辅热标志----》电辅热开=1,电辅热关=0
|
||||
public static int ADSF_HEAT = 2; //电辅热标志位置
|
||||
public static int SYSFLAG_TIME = 0x08; //00001000B //定时标志-------》 有定时= 1,没有定时 = 0
|
||||
public static int ADSF_TIME = 3; //定时标志位置
|
||||
public static int SYSFLAG_STRONG = 0x10; //00010000B //强力标志-------》 强力开= 1,强力关 = 0
|
||||
public static int ADSF_STRONG = 4; //强力标志位置
|
||||
public static int SYSFLAG_LIGHT = 0x20; //00100000B //灯光标志-------》 灯光开= 1,灯光关 = 0
|
||||
public static int ADSF_LIGHT = 5; //灯光标志位置
|
||||
public static int SYSFLAG_AIRCLEAR = 0x40; //01000000B //空清/净化/健康标志-------》 空清/净化/健康开= 1,空清/净化/健康关 = 0
|
||||
public static int ADSF_AIRCLEAR = 6; //空清/净化/健康标志位置
|
||||
public static int SYSFLAG_ECONOMIC = 0x80; //10000000B //经济标志-------》 经济开= 1,经济关 = 0
|
||||
public static int ADSF_ECONOMIC = 7; //经济标志位置
|
||||
|
||||
//返回值
|
||||
public static int SEND_CODE = 0x01; //按键有发送发码命令
|
||||
public static int SEND_END = 0x11; //发码结束
|
||||
|
||||
public static int LENTIMEOUT = 0x80;
|
||||
public static int UPDATE_ARC_DISP = 0xF0; //Tony 添加:用户ARC屏幕更新
|
||||
|
||||
|
||||
public static String urc_excode_file = "urc_excode.Bin";
|
||||
public static String arc_excode_file = "arc_excode.bin";
|
||||
|
||||
|
||||
//操作
|
||||
public static enum OPERATION {
|
||||
HB_IOCTL_INIT, //初始化,应用程序打开时,调用此函数
|
||||
HB_IOCTL_TIMER100, //定时器100ms到时,调用此函数
|
||||
HB_IOCTL_TIMER500, //RTC定时器500ms
|
||||
HB_IOCTL_CREATE_IRDevice, //新建红外设备(收藏红外设备时调用)
|
||||
//建立对应红外设备 数据
|
||||
//TV(设备类型),品牌,码组索引,学习数据
|
||||
//ARC:空调相关变量
|
||||
HB_IOCTL_Delete_Device, //删除红外设备(删除收藏记录时调用)
|
||||
HB_IOCTL_KeyDn, //设备按键按下,调用此函数发码
|
||||
HB_IOCTL_KeyUp,
|
||||
//序根据当前设备值,红外设备号,调用对应文件中对应数据,查表或运算后发码
|
||||
HB_IOCTL_Change_Device, // 更改设备类型,
|
||||
//应用层改变设备类型,红外设备,品牌,或者码组时,需要调用此函数更新红外系统内部变量
|
||||
HB_IOCTL_IRRX_BEGIN, //程序发码给HB1682 ,启动学习; 具体查询学习是否完成,在定时器中处理;
|
||||
HB_IOCTL_ARC_IRRX, //启动空调码学习
|
||||
HB_IOCTL_IRRX_END, // 在学习过程中,用户可以取消学习,则应用层需要调用此函数终止学习;
|
||||
HB_IOCTL_Send_LenCode, //发送URC学习的数据
|
||||
HB_IOCTL_Send_ArcLenCode, //发送ARC学习码
|
||||
HB_IOCTL_RX_ICVER, //读取IC 程序版本
|
||||
HB_IOCTL_RX_PRO, //串口接收数据处理
|
||||
HB_IOCTL_SEND_Search, //搜索发码
|
||||
} //ev_ioctl_e
|
||||
|
||||
//---------------------------------------------------------
|
||||
public static int m_group; //码组
|
||||
public static int m_device; //设备类型
|
||||
public static int m_keyval; //键值
|
||||
public static int m_arc_group; //空调码组
|
||||
public static int m_arc_group_1; //空调码组1
|
||||
public static int m_arc_group_2; //空调码组2
|
||||
public static int m_arc_group_3; //空调码组3
|
||||
|
||||
public static DEVICE_TYPE m_device_type; //当前设备类型(这个是类型,m_device是序号)
|
||||
public static boolean b_learn_mode; //是否在学习模式
|
||||
public static boolean b_recognition_mode; //是否在自动识别模式
|
||||
|
||||
public static int m_favorite_id; //收藏夹ID
|
||||
|
||||
//用于传递数据
|
||||
public static DEVICE_TYPE tmp_device_type; //临时设备类型
|
||||
public static String tmp_brand; //临时品牌
|
||||
public static String tmp_group_list; //临时码组列表
|
||||
public static boolean tmp_force_exit; //强制退出页面
|
||||
|
||||
|
||||
public static String get_title(Context context, DEVICE_TYPE device_type) {
|
||||
if (device_type == DEVICE_TYPE.C_ATV_DEVICE) {
|
||||
return Language.get(context, "atv");
|
||||
} else if (device_type == DEVICE_TYPE.C_STB_DEVICE) {
|
||||
return Language.get(context, "stb");
|
||||
} else if (device_type == DEVICE_TYPE.C_ARC_DEVICE) {
|
||||
return Language.get(context, "air");
|
||||
} else if (device_type == DEVICE_TYPE.C_AUX_DEVICE) {
|
||||
return Language.get(context, "aux");
|
||||
} else if (device_type == DEVICE_TYPE.C_CTV_DEVICE) {
|
||||
return Language.get(context, "ctv");
|
||||
} else if (device_type == DEVICE_TYPE.C_DVB_DEVICE) {
|
||||
return Language.get(context, "dvb");
|
||||
} else if (device_type == DEVICE_TYPE.C_DVD_DEVICE) {
|
||||
return Language.get(context, "dvd");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String get_title(Context context, int device_type) {
|
||||
if (device_type == DEVICE_TYPE.C_ATV_DEVICE.ordinal()) {
|
||||
return Language.get(context, "atv");
|
||||
} else if (device_type == DEVICE_TYPE.C_STB_DEVICE.ordinal()) {
|
||||
return Language.get(context, "stb");
|
||||
} else if (device_type == DEVICE_TYPE.C_ARC_DEVICE.ordinal()) {
|
||||
return Language.get(context, "air");
|
||||
} else if (device_type == DEVICE_TYPE.C_AUX_DEVICE.ordinal()) {
|
||||
return Language.get(context, "aux");
|
||||
} else if (device_type == DEVICE_TYPE.C_CTV_DEVICE.ordinal()) {
|
||||
return Language.get(context, "ctv");
|
||||
} else if (device_type == DEVICE_TYPE.C_DVB_DEVICE.ordinal()) {
|
||||
return Language.get(context, "dvb");
|
||||
} else if (device_type == DEVICE_TYPE.C_DVD_DEVICE.ordinal()) {
|
||||
return Language.get(context, "dvd");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static tagSerialPortRx get_RemoteRxData() {
|
||||
short[] rx = new short[3];
|
||||
rx = Device.HBioctlGetRemoteRxData();
|
||||
tagSerialPortRx RemoteRxData = new tagSerialPortRx();
|
||||
// RemoteRxData.RxBuf = BytesUtil.hexStringToBytes("168cd02333000011012c026500250021002500c504250000002500ffffffffffffffffffffffff0122211122222222222222121222212122123122121222222212222222222222211114000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006d4c08");
|
||||
// RemoteRxData.RxBuf = BytesUtil.hexStringToBytes("2333000011012c026500250021002500c504250000002500ffffffffffffffffffffffff0122211122222222222222121222212122123122121222222212222222222222211114000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006d");
|
||||
RemoteRxData.RemoteCMD = (byte) rx[0];
|
||||
RemoteRxData.wRxLen = rx[1];
|
||||
RemoteRxData.wRxPos = rx[2];
|
||||
return RemoteRxData;
|
||||
}
|
||||
|
||||
public static DEVICE_TYPE get_default_device_type() {
|
||||
if (Public.group_library == Public.GROUP_LIBRARY.america) {
|
||||
return Public.DEFAULT_DEVICE_TYPE_AMERICA;
|
||||
} else {
|
||||
return Public.DEFAULT_DEVICE_TYPE_ASIA;
|
||||
}
|
||||
}
|
||||
|
||||
public static void set_default_device() {
|
||||
Device.m_device = get_default_device_type().ordinal();
|
||||
Device.m_group = 0;
|
||||
Device.m_arc_group = 0;
|
||||
Device.m_arc_group_1 = 0;
|
||||
Device.m_arc_group_2 = 0;
|
||||
Device.m_arc_group_3 = 0;
|
||||
Device.m_favorite_id = 0;
|
||||
}
|
||||
|
||||
// TODO: 2017/7/3
|
||||
public native static int HBioctlGetArcGroupNum(int[] GroupNumber);
|
||||
|
||||
public native static int HBioctl(int cmd, Object arg);
|
||||
|
||||
public native static byte[] HBioctlGetAdrVar();
|
||||
|
||||
public native static int HBioctlSetAdrVar(Object arg);
|
||||
|
||||
public native static byte[] HBioctlGetArDispData();
|
||||
|
||||
public native static short[] HBioctlGetRemoteRxData();
|
||||
|
||||
public native static int HBFILEOpen(AssetManager ass, String filename, int type);
|
||||
|
||||
public native static int HBFILEClose();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.ds.remote;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
public class Language {
|
||||
public static String get(Context context, String lang) {
|
||||
Public.LANGUAGE l = Settings.get_language(context);
|
||||
Resources res = context.getResources();
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,178 @@
|
|||
package com.ds.remote;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public class Public {
|
||||
//串口服务
|
||||
public static SerialPortService serial_port_service;
|
||||
//串口名称
|
||||
//public static final String ComDefaultName = "/dev/s3c2410_serial3"; //Android 开发板靠边第一个串口
|
||||
public static final String ComDefaultName = "/dev/ttyS1"; //Android 开发板靠边第一个串口
|
||||
private static String ComName;
|
||||
//串口波特率
|
||||
public static final int ComBaudrate = 19200;
|
||||
|
||||
//数据库
|
||||
public static final String db_name = "remote.sqlite";
|
||||
public static final String table_name_favorite = "favorite";
|
||||
public static final String table_name_learn_code = "learn_code";
|
||||
|
||||
//Message
|
||||
public static final int MESSAGE_LEARN_BUTTON = 1; //更新学习的按钮
|
||||
public static final int MESSAGE_UPDATE_ARC_DISPLAY = 2; //更新arc显示
|
||||
public static final int MESSAGE_START_LEARN = 3; //开始学习
|
||||
public static final int MESSAGE_LEARN_TIMEOUT = 4; //学习超时
|
||||
public static final int MESSAGE_CHANGE_GROUP = 5; //变换码组
|
||||
public static final int MESSAGE_LEARN_SUCCEEDED = 6; //学习成功
|
||||
public static final int MESSAGE_LEARN_FAILED = 7; //学习失败
|
||||
public static final int MESSAGE_ON_RECEIVED = 8; //串口接收数据
|
||||
public static final int MESSAGE_SHOW_SIGNAL_FALG = 9; //显示发码标志
|
||||
public static final int MESSAGE_HIDE_SIGNAL_FALG = 10; //隐藏发码标志
|
||||
public static final int MESSAGE_AUTO_RECOGNITION = 11; //空调学习
|
||||
public static final int MESSAGE_RECOGNITION_TIMEOUT = 12; //识别超时
|
||||
public static final int MESSAGE_RECOGNITION_SUCCEEDED = 13; //识别超时
|
||||
public static final int MESSAGE_RECOGNITION_FAILED = 14; //学习失败
|
||||
|
||||
//常量
|
||||
public static final int REQUEST_LEARN = 0x01;
|
||||
public static final int REQUEST_RECOGNITION = 0x02;
|
||||
public static final int REQUEST_GROUP = 0x03;
|
||||
|
||||
//码库
|
||||
public static enum GROUP_LIBRARY {
|
||||
asia, //亚洲
|
||||
america //美洲/欧洲
|
||||
}
|
||||
|
||||
//语言
|
||||
public static enum LANGUAGE {
|
||||
simple_chinese, //中文
|
||||
english //英文
|
||||
}
|
||||
|
||||
public static GROUP_LIBRARY group_library;
|
||||
public static LANGUAGE language;
|
||||
|
||||
|
||||
//设置
|
||||
public static final String PREFS_NAME = "HbgRemote.Prefs";
|
||||
public static final String SETTING_GROUP_LIBRARY = "SETTING_GROUP_LIBRARY";
|
||||
public static final String SETTING_LANGUAGE = "SETTING_LANGUAGE";
|
||||
|
||||
//默认:亚洲码库,中文界面
|
||||
public static final GROUP_LIBRARY DEFAULT_GROUP_LIBRARY = GROUP_LIBRARY.asia;
|
||||
public static final LANGUAGE DEFAULT_LANGUAGE = LANGUAGE.simple_chinese;
|
||||
|
||||
public static final String SETTING_FAVORITE_ID = "SETTING_FAVORITE_ID";
|
||||
public static final String SETTING_LAST_DEVICE = "SETTING_DEVICE";
|
||||
public static final String SETTING_LAST_GROUP = "SETTING_LAST_DEIVCE";
|
||||
public static final String SETTING_IS_FIRST = "SETTING_IS_FIRST";
|
||||
|
||||
//默认设备
|
||||
public static final Device.DEVICE_TYPE DEFAULT_DEVICE_TYPE_ASIA = Device.DEVICE_TYPE.C_ATV_DEVICE;
|
||||
public static final Device.DEVICE_TYPE DEFAULT_DEVICE_TYPE_AMERICA = Device.DEVICE_TYPE.C_CTV_DEVICE;
|
||||
|
||||
public static boolean b_require_reload; //是否需要重新加载页面
|
||||
|
||||
|
||||
//////////////////////////
|
||||
public static void ShowAlert(String title, String msg, Context context) {
|
||||
new AlertDialog.Builder(context)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setTitle(title)
|
||||
.setMessage(msg)
|
||||
.setCancelable(false)
|
||||
.setNegativeButton("OK", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void ShowInfo(String title, String msg, Context context) {
|
||||
new AlertDialog.Builder(context)
|
||||
.setIcon(android.R.drawable.ic_dialog_info)
|
||||
.setTitle(title)
|
||||
.setMessage(msg)
|
||||
.setCancelable(false)
|
||||
.setNegativeButton("OK", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
public static String get_date() {
|
||||
int mYear;
|
||||
int mMonth;
|
||||
int mDay;
|
||||
|
||||
final Calendar c = Calendar.getInstance();
|
||||
|
||||
mYear = c.get(Calendar.YEAR);
|
||||
mMonth = c.get(Calendar.MONTH) + 1;
|
||||
mDay = c.get(Calendar.DAY_OF_MONTH);
|
||||
|
||||
String result = String.format("%04d-%02d-%02d", mYear, mMonth, mDay);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String get_date_time() {
|
||||
int mYear;
|
||||
int mMonth;
|
||||
int mDay;
|
||||
int mHour;
|
||||
int mMinute;
|
||||
int mSecond;
|
||||
|
||||
final Calendar c = Calendar.getInstance();
|
||||
|
||||
mYear = c.get(Calendar.YEAR);
|
||||
mMonth = c.get(Calendar.MONTH) + 1;
|
||||
mDay = c.get(Calendar.DAY_OF_MONTH);
|
||||
mHour = c.get(Calendar.HOUR_OF_DAY);
|
||||
mMinute = c.get(Calendar.MINUTE);
|
||||
mSecond = c.get(Calendar.SECOND);
|
||||
|
||||
String result = String.format("%04d-%02d-%02d %02d:%02d:%02d",
|
||||
mYear, mMonth, mDay, mHour, mMinute, mSecond);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int get_current_hour() {
|
||||
final Calendar c = Calendar.getInstance();
|
||||
return c.get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
|
||||
public static int get_current_minute() {
|
||||
final Calendar c = Calendar.getInstance();
|
||||
return c.get(Calendar.MINUTE);
|
||||
}
|
||||
|
||||
public static void debug(byte[] buf, int len) {
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (int i=0; i<len; i++) {
|
||||
str.append(String.format("%02X ", buf[i]));
|
||||
}
|
||||
Log.e("----", "DEBUG_BUF: " + str.toString());
|
||||
}
|
||||
|
||||
public static void setCommName(String com){
|
||||
ComName = com;
|
||||
}
|
||||
|
||||
public static String getCommName(){
|
||||
if(ComName == null)
|
||||
return ComDefaultName;
|
||||
else
|
||||
return ComName;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.ds.remote;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
public class Remote {
|
||||
int favorite_id;
|
||||
int device;
|
||||
int group;
|
||||
String brand_name;
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.ds.remote;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class SerialPort {
|
||||
private static final String TAG = "SerialPort";
|
||||
|
||||
/*
|
||||
* Do not remove or rename the field mFd: it is used by native method
|
||||
* close();
|
||||
*/
|
||||
private FileDescriptor mFd;
|
||||
private FileInputStream mFileInputStream;
|
||||
private FileOutputStream mFileOutputStream;
|
||||
|
||||
public SerialPort(File device, int baudrate, int flags)
|
||||
throws SecurityException, IOException {
|
||||
|
||||
/* Check access permission */
|
||||
if (!device.canRead() || !device.canWrite()) {
|
||||
try {
|
||||
/* Missing read/write permission, trying to chmod the file */
|
||||
Process su;
|
||||
su = Runtime.getRuntime().exec("/system/bin/su");
|
||||
String cmd = "chmod 666 " + device.getAbsolutePath() + "\n"
|
||||
+ "exit\n";
|
||||
su.getOutputStream().write(cmd.getBytes());
|
||||
if ((su.waitFor() != 0) || !device.canRead()
|
||||
|| !device.canWrite()) {
|
||||
throw new SecurityException();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "device operate fail");
|
||||
e.printStackTrace();
|
||||
throw new SecurityException();
|
||||
}
|
||||
}
|
||||
|
||||
mFd = open(device.getAbsolutePath(), baudrate, flags);
|
||||
if (mFd == null) {
|
||||
Log.e(TAG, "native open returns null");
|
||||
throw new IOException();
|
||||
}
|
||||
mFileInputStream = new FileInputStream(mFd);
|
||||
mFileOutputStream = new FileOutputStream(mFd);
|
||||
}
|
||||
|
||||
// Getters and setters
|
||||
public InputStream getInputStream() {
|
||||
return mFileInputStream;
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() {
|
||||
return mFileOutputStream;
|
||||
}
|
||||
|
||||
// JNI
|
||||
private native static FileDescriptor open(String path, int baudrate, int flags);
|
||||
|
||||
public native void close();
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package com.ds.remote;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
public class SerialPortService {
|
||||
private Context mContext;
|
||||
private Handler mHandler;
|
||||
private SerialPort mSerialPort;
|
||||
private OutputStream mOutputStream;
|
||||
private InputStream mInputStream;
|
||||
private ReadThread mReadThread;
|
||||
|
||||
public SerialPortService(Context context, Handler handler) {
|
||||
mContext = context;
|
||||
mHandler = handler;
|
||||
}
|
||||
|
||||
public void SetHandler(Handler handler) {
|
||||
mHandler = handler;
|
||||
}
|
||||
|
||||
public synchronized void start() {
|
||||
try {
|
||||
OpenSerialPort();
|
||||
mOutputStream = mSerialPort.getOutputStream();
|
||||
mInputStream = mSerialPort.getInputStream();
|
||||
|
||||
mReadThread = new ReadThread();
|
||||
mReadThread.start();
|
||||
} catch (SecurityException e) {
|
||||
// Public.ShowAlert("Error", mContext.getString(R.string.error_security), mContext);
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
//Public.ShowAlert("Error", mContext.getString(R.string.error_unknown), mContext);
|
||||
Public.ShowAlert("Error", mContext.getString(R.string.str_select_serial), mContext);
|
||||
} catch (InvalidParameterException e) {
|
||||
//Public.ShowAlert("Error", mContext.getString(R.string.error_configuration), mContext);
|
||||
Public.ShowAlert("Error", mContext.getString(R.string.str_select_serial), mContext);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void stop() {
|
||||
if (mReadThread != null) {
|
||||
mReadThread.interrupt();
|
||||
}
|
||||
CloseSerialPort();
|
||||
mSerialPort = null;
|
||||
}
|
||||
|
||||
public void OpenSerialPort() throws SecurityException, IOException,
|
||||
InvalidParameterException {
|
||||
if (mSerialPort == null) {
|
||||
String path = Public.getCommName(); //Public.ComName;
|
||||
int baudrate = Public.ComBaudrate;
|
||||
|
||||
Log.d("SerialPortService", "serial port : " + path);
|
||||
|
||||
mSerialPort = new SerialPort(new File(path), baudrate, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseSerialPort() {
|
||||
if (mSerialPort != null) {
|
||||
mSerialPort.close();
|
||||
mSerialPort = null;
|
||||
}
|
||||
}
|
||||
|
||||
private class ReadThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
while (!isInterrupted()) {
|
||||
int size = -1;
|
||||
if (mInputStream == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
byte[] buffer = new byte[1024];
|
||||
size = mInputStream.read(buffer);
|
||||
if (size > 0) {
|
||||
// Send the obtained bytes to the UI Activity
|
||||
mHandler.obtainMessage(Public.MESSAGE_ON_RECEIVED, size, -1, buffer).sendToTarget();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package com.ds.remote;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
public class Settings {
|
||||
public static Public.GROUP_LIBRARY get_group_library(Context context) {
|
||||
SharedPreferences settings = context.getSharedPreferences(Public.PREFS_NAME, 0);
|
||||
int lang = settings.getInt(Public.SETTING_GROUP_LIBRARY, Public.DEFAULT_GROUP_LIBRARY.ordinal());
|
||||
if (lang == 0) {
|
||||
return Public.GROUP_LIBRARY.asia;
|
||||
} else {
|
||||
return Public.GROUP_LIBRARY.america;
|
||||
}
|
||||
}
|
||||
|
||||
public static Public.LANGUAGE get_language(Context context) {
|
||||
SharedPreferences settings = context.getSharedPreferences(Public.PREFS_NAME, 0);
|
||||
int lang = settings.getInt(Public.SETTING_LANGUAGE, Public.DEFAULT_GROUP_LIBRARY.ordinal());
|
||||
if (lang == 0) {
|
||||
return Public.LANGUAGE.simple_chinese;
|
||||
} else {
|
||||
return Public.LANGUAGE.english;
|
||||
}
|
||||
}
|
||||
|
||||
public static Remote get_last_device(Context context) {
|
||||
SharedPreferences settings = context.getSharedPreferences(Public.PREFS_NAME, 0);
|
||||
Remote remote = new Remote();
|
||||
int first = settings.getInt(Public.SETTING_IS_FIRST, 0);
|
||||
if (first == 0) {
|
||||
remote.favorite_id = 0;
|
||||
remote.device = Device.get_default_device_type().ordinal();
|
||||
remote.group = 0;
|
||||
set_last_device(context, remote);
|
||||
} else {
|
||||
remote.favorite_id = settings.getInt(Public.SETTING_FAVORITE_ID, 0);
|
||||
remote.device = settings.getInt(Public.SETTING_LAST_DEVICE, 0);
|
||||
remote.group = settings.getInt(Public.SETTING_LAST_GROUP, 0);
|
||||
}
|
||||
return remote;
|
||||
}
|
||||
|
||||
public static void set_group_library(Context context, Public.GROUP_LIBRARY gl) {
|
||||
SharedPreferences settings = context.getSharedPreferences(Public.PREFS_NAME, 0);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putInt(Public.SETTING_GROUP_LIBRARY, gl.ordinal());
|
||||
editor.commit();
|
||||
|
||||
}
|
||||
|
||||
public static void set_language(Context context, Public.LANGUAGE lang) {
|
||||
SharedPreferences settings = context.getSharedPreferences(Public.PREFS_NAME, 0);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putInt(Public.SETTING_LANGUAGE, lang.ordinal());
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public static void set_last_device(Context context, Remote ld) {
|
||||
SharedPreferences settings = context.getSharedPreferences(Public.PREFS_NAME, 0);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putInt(Public.SETTING_IS_FIRST, 0x1234);
|
||||
editor.putInt(Public.SETTING_FAVORITE_ID, ld.favorite_id);
|
||||
editor.putInt(Public.SETTING_LAST_DEVICE, ld.device);
|
||||
editor.putInt(Public.SETTING_LAST_GROUP, ld.group);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public static void delete_all_settings(Context context) {
|
||||
SharedPreferences settings = context.getSharedPreferences(Public.PREFS_NAME, 0);
|
||||
settings.edit().clear().commit();
|
||||
}
|
||||
|
||||
public static void set_adr_var(Context context, int favorite_id, String adr_var) {
|
||||
SharedPreferences settings = context.getSharedPreferences(Public.PREFS_NAME, 0);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
String key = String.format("ADR_VAR_:%d", favorite_id);
|
||||
editor.putString(key, adr_var);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public static String get_adr_var(Context context, int favorite_id) {
|
||||
SharedPreferences settings = context.getSharedPreferences(Public.PREFS_NAME, 0);
|
||||
String key = String.format("ADR_VAR_:%d", favorite_id);
|
||||
String var = settings.getString(key, "");
|
||||
return var;
|
||||
}
|
||||
|
||||
public static void delete_adr_var(Context context, int favorite_id) {
|
||||
SharedPreferences settings = context.getSharedPreferences(Public.PREFS_NAME, 0);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
String key = String.format("ADR_VAR_:%d", favorite_id);
|
||||
editor.putString(key, ""); //清空,就等于删掉了
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.ds.remote;
|
||||
|
||||
public class tagSerialPortRx {
|
||||
byte RemoteCMD;
|
||||
public byte RxDone;
|
||||
public byte[] RxBuf;
|
||||
public short wRxPos;
|
||||
public short wRxLen;
|
||||
|
||||
public tagSerialPortRx() {
|
||||
RxBuf = new byte[256];
|
||||
RemoteCMD = 0;
|
||||
RxDone = 0;
|
||||
wRxPos = 0;
|
||||
wRxLen = 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.ds.remote;
|
||||
|
||||
public class type_CUR_group {
|
||||
public short group_aux;
|
||||
public short group_dvb;
|
||||
public short group_stb;
|
||||
public short group_atv;
|
||||
public short group_ctv;
|
||||
public short group_dvd;
|
||||
public short group_arc;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.ds.remote;
|
||||
|
||||
public class type_updatatime {
|
||||
public short arc_group;
|
||||
public byte clk_hour;
|
||||
public byte clk_min; //
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package com.lechange.demo.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.common.openapi.entity.RecordsData;
|
||||
import com.lechange.demo.tools.DateHelper;
|
||||
import com.lechange.demo.tools.ImageHelper;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceInnerRecordListAdapter extends RecyclerView.Adapter<DeviceInnerRecordListAdapter.DeviceInnerRecordListHolder> {
|
||||
private Context mContext;
|
||||
private List<RecordsData> recordsData;
|
||||
|
||||
public DeviceInnerRecordListAdapter(Context mContext, List<RecordsData> recordsData) {
|
||||
this.mContext = mContext;
|
||||
this.recordsData = recordsData;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DeviceInnerRecordListHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.item_record, parent, false);
|
||||
return new DeviceInnerRecordListAdapter.DeviceInnerRecordListHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final DeviceInnerRecordListHolder holder, final int position) {
|
||||
long time = DateHelper.string2Date(recordsData.get(position).endTime).getTime() - DateHelper.string2Date(recordsData.get(position).beginTime).getTime();
|
||||
holder.tvTimeM.setText(recordsData.get(position).beginTime.substring(11));
|
||||
holder.tvTimeS.setText(time / 1000 + "s");
|
||||
if (recordsData.get(position).recordType == 0) {
|
||||
try {
|
||||
ImageHelper.loadCacheImage(recordsData.get(position).thumbUrl, recordsData.get(position).deviceId, recordsData.get(position).deviceId, position, new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
try {
|
||||
if (recordsData.get(msg.arg1).thumbUrl.hashCode() == msg.what && msg.obj != null) {
|
||||
holder.ivBg.setImageDrawable((Drawable) msg.obj);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
holder.ivCheck.setVisibility(recordsData.get(position).check ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (editClickListener != null) {
|
||||
editClickListener.edit(position);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return recordsData == null ? 0 : recordsData.size();
|
||||
}
|
||||
|
||||
class DeviceInnerRecordListHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
ImageView ivBg;
|
||||
TextView tvTimeS;
|
||||
TextView tvTimeM;
|
||||
ImageView ivCheck;
|
||||
|
||||
public DeviceInnerRecordListHolder(View itemView) {
|
||||
super(itemView);
|
||||
ivBg = itemView.findViewById(R.id.iv_bg);
|
||||
ivCheck = itemView.findViewById(R.id.iv_check);
|
||||
tvTimeS = itemView.findViewById(R.id.tv_time_s);
|
||||
tvTimeM = itemView.findViewById(R.id.tv_time_m);
|
||||
}
|
||||
}
|
||||
|
||||
private EditClickListener editClickListener;
|
||||
|
||||
public interface EditClickListener {
|
||||
void edit(int innerPosition);
|
||||
}
|
||||
|
||||
public void setEditClickListener(EditClickListener editClickListener) {
|
||||
this.editClickListener = editClickListener;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.lechange.demo.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.common.openapi.entity.RecordListData;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceRecordListAdapter extends RecyclerView.Adapter<DeviceRecordListAdapter.DeviceListHolder> {
|
||||
|
||||
private Context mContext;
|
||||
private List<RecordListData> recordListDataList;
|
||||
|
||||
public DeviceRecordListAdapter(Context mContext, List<RecordListData> recordListDataList) {
|
||||
this.mContext = mContext;
|
||||
this.recordListDataList = recordListDataList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DeviceListHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(mContext).inflate(R.layout.item_record_list, parent, false);
|
||||
return new DeviceRecordListAdapter.DeviceListHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DeviceListHolder holder, final int position) {
|
||||
holder.tvTime.setText(recordListDataList.get(position).period);
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 4);
|
||||
holder.rcvRecord.setLayoutManager(gridLayoutManager);
|
||||
DeviceInnerRecordListAdapter deviceInnerRecordListAdapter = new DeviceInnerRecordListAdapter(mContext, recordListDataList.get(position).recordsData);
|
||||
deviceInnerRecordListAdapter.setEditClickListener(new DeviceInnerRecordListAdapter.EditClickListener() {
|
||||
@Override
|
||||
public void edit(int innerPosition) {
|
||||
if (editClickListener != null) {
|
||||
editClickListener.edit(position,innerPosition);
|
||||
}
|
||||
}
|
||||
});
|
||||
holder.rcvRecord.setAdapter(deviceInnerRecordListAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return recordListDataList == null ? 0 : recordListDataList.size();
|
||||
}
|
||||
|
||||
class DeviceListHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
RecyclerView rcvRecord;
|
||||
TextView tvTime;
|
||||
|
||||
public DeviceListHolder(View itemView) {
|
||||
super(itemView);
|
||||
rcvRecord = itemView.findViewById(R.id.rcv_record);
|
||||
tvTime = itemView.findViewById(R.id.tv_time);
|
||||
}
|
||||
}
|
||||
|
||||
private EditClickListener editClickListener;
|
||||
|
||||
public interface EditClickListener {
|
||||
void edit(int outPosition, int innerPosition);
|
||||
}
|
||||
|
||||
public void setEditClickListener(EditClickListener editClickListener) {
|
||||
this.editClickListener = editClickListener;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
package com.lechange.demo.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.common.openapi.entity.RecordsData;
|
||||
import com.lechange.demo.tools.ImageHelper;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MediaPlayRecordAdapter extends RecyclerView.Adapter<MediaPlayRecordAdapter.MediaPlayHolder> {
|
||||
private List<RecordsData> recordsBeanList;
|
||||
private Context context;
|
||||
|
||||
public MediaPlayRecordAdapter(List<RecordsData> recordsBeanList, Context context) {
|
||||
this.recordsBeanList = recordsBeanList;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MediaPlayHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.item_media_play_record, parent, false);
|
||||
return new MediaPlayRecordAdapter.MediaPlayHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final MediaPlayHolder holder, final int position) {
|
||||
if (position == recordsBeanList.size()) {
|
||||
holder.tvLoadingMore.setVisibility(View.VISIBLE);
|
||||
holder.tvLoadingMore.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (loadMoreClickListener != null) {
|
||||
loadMoreClickListener.loadMore();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
String time = recordsBeanList.get(position).beginTime.substring(11);
|
||||
holder.tvTime.setText(time);
|
||||
if (recordsBeanList.get(position).recordType == 0) {
|
||||
//云录像
|
||||
holder.tvLoadingMore.setVisibility(View.GONE);
|
||||
try {
|
||||
ImageHelper.loadCacheImage(recordsBeanList.get(position).thumbUrl, recordsBeanList.get(position).deviceId, recordsBeanList.get(position).deviceId, position, new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
try {
|
||||
if (recordsBeanList.get(msg.arg1).thumbUrl.hashCode() == msg.what && msg.obj != null) {
|
||||
holder.ivImg.setImageDrawable((Drawable) msg.obj);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
//设备录像
|
||||
holder.tvLoadingMore.setVisibility(View.GONE);
|
||||
holder.ivImg.setImageDrawable(context.getDrawable(R.mipmap.lc_demo_default_bg));
|
||||
}
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onItemClickListener != null) {
|
||||
onItemClickListener.click(recordsBeanList.get(position).recordType, position);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return recordsBeanList == null ? 0 : (recordsBeanList.size() == 6 ? 7 : (recordsBeanList.size() + 1));
|
||||
}
|
||||
|
||||
class MediaPlayHolder extends RecyclerView.ViewHolder {
|
||||
ImageView ivImg;
|
||||
TextView tvTime;
|
||||
TextView tvLoadingMore;
|
||||
|
||||
public MediaPlayHolder(View itemView) {
|
||||
super(itemView);
|
||||
ivImg = itemView.findViewById(R.id.iv_img);
|
||||
tvTime = itemView.findViewById(R.id.tv_time);
|
||||
tvLoadingMore = itemView.findViewById(R.id.tv_loadingmore);
|
||||
}
|
||||
}
|
||||
|
||||
private LoadMoreClickListener loadMoreClickListener;
|
||||
|
||||
public interface LoadMoreClickListener {
|
||||
void loadMore();
|
||||
}
|
||||
|
||||
public void setLoadMoreClickListener(LoadMoreClickListener loadMoreClickListener) {
|
||||
this.loadMoreClickListener = loadMoreClickListener;
|
||||
}
|
||||
|
||||
|
||||
private OnItemClickListener onItemClickListener;
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void click(int recordType, int position);
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
|
||||
this.onItemClickListener = onItemClickListener;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.lechange.demo.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.common.openapi.entity.DeviceDetailListData;
|
||||
import com.lechange.demo.view.LcPopupWindow;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PixelListAdapter extends RecyclerView.Adapter<PixelListAdapter.PixelHolder> implements View.OnClickListener {
|
||||
|
||||
|
||||
private Context mContext;
|
||||
private List<DeviceDetailListData.ResponseData.DeviceListBean.ChannelsBean.ResolutionBean> mPixelList;
|
||||
private LcPopupWindow.onRecyclerViewItemClickListener mItemClickListener;
|
||||
private RecyclerView mRecycleView;
|
||||
|
||||
|
||||
public PixelListAdapter(Context context, List<DeviceDetailListData.ResponseData.DeviceListBean.ChannelsBean.ResolutionBean> pixelList) {
|
||||
this.mContext = context;
|
||||
this.mPixelList = pixelList;
|
||||
}
|
||||
|
||||
|
||||
public void setOnItemClickListener(LcPopupWindow.onRecyclerViewItemClickListener onRecyclerViewItemClickListener) {
|
||||
this.mItemClickListener = onRecyclerViewItemClickListener;
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public PixelHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
mRecycleView = (RecyclerView) parent;
|
||||
View inflate = LayoutInflater.from(mContext).inflate(R.layout.item_pixel_list, parent, false);
|
||||
inflate.setOnClickListener(this);
|
||||
return new PixelHolder(inflate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull PixelHolder holder, int position) {
|
||||
holder.tvPixel.setText(mPixelList.get(position).name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mPixelList!=null?mPixelList.size():0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int childAdapterPosition = mRecycleView.getChildAdapterPosition(view);
|
||||
if(mItemClickListener!=null){
|
||||
mItemClickListener.onItemClick(mRecycleView,view,childAdapterPosition,
|
||||
mPixelList.get(childAdapterPosition).name,mPixelList.get(childAdapterPosition).imageSize,mPixelList.get(childAdapterPosition).streamType);
|
||||
}
|
||||
}
|
||||
|
||||
class PixelHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
public TextView tvPixel;
|
||||
|
||||
public PixelHolder(View itemView) {
|
||||
super(itemView);
|
||||
tvPixel = itemView.findViewById(R.id.tv_pixel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,114 @@
|
|||
package com.lechange.demo.business.entity;
|
||||
|
||||
|
||||
public class AlarmMessageInfo {
|
||||
|
||||
private String chnlUuid; // 通道的uuid
|
||||
|
||||
/** [long]消息ID */
|
||||
private long alarmId;
|
||||
|
||||
/** [int]报警类型 */
|
||||
private int type;
|
||||
|
||||
/** 设备或通道的名称 */
|
||||
private String name = "";
|
||||
|
||||
/** ***LLLJHHDF */
|
||||
private String thumbUrl = "";
|
||||
private String picUrl = "";
|
||||
|
||||
/** 报警时设备本地时间,格式如2014-12-12 12:12:12 */
|
||||
private String localDate = "";
|
||||
|
||||
private String deviceId; //设备ID
|
||||
private String deviceKey; //设备秘钥
|
||||
|
||||
/** [long]报警时间UNIX时间戳秒 */
|
||||
private long time;
|
||||
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public long getAlarmId() {
|
||||
return alarmId;
|
||||
}
|
||||
|
||||
public void setAlarmId(long alarmId) {
|
||||
this.alarmId = alarmId;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPicUrl() {
|
||||
return picUrl;
|
||||
}
|
||||
|
||||
public void setPicUrl(String picUrl) {
|
||||
this.picUrl = picUrl;
|
||||
}
|
||||
|
||||
public String getThumbUrl() {
|
||||
return thumbUrl;
|
||||
}
|
||||
|
||||
public void setThumbUrl(String thumbUrl) {
|
||||
this.thumbUrl = thumbUrl;
|
||||
}
|
||||
|
||||
public String getLocalDate() {
|
||||
return localDate;
|
||||
}
|
||||
|
||||
public void setLocalDate(String localDate) {
|
||||
this.localDate = localDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getChnlUuid() {
|
||||
return chnlUuid;
|
||||
}
|
||||
|
||||
public void setChnlUuid(String chnlUuid) {
|
||||
this.chnlUuid = chnlUuid;
|
||||
}
|
||||
|
||||
public String getDeviceKey() {
|
||||
return deviceKey;
|
||||
}
|
||||
|
||||
public void setDeviceKey(String deviceKey) {
|
||||
this.deviceKey = deviceKey;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
package com.lechange.demo.business.entity;
|
||||
|
||||
import com.tuya.sdk.blelib.channel.ChannelState;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChannelInfo {
|
||||
|
||||
private String id = UUID.randomUUID().toString();
|
||||
private int index; // 通道索引
|
||||
private String name; // 通道名称
|
||||
private ChannelState state; // 通道状态
|
||||
private String backgroudImgURL; // 背景图URL
|
||||
private String deviceCode; // 关联的设备id
|
||||
private String deviceModel; // 关联的设备型号
|
||||
private String encryptKey; // 秘钥的key
|
||||
private String deviceName; // 设备名称
|
||||
private String deviceType; // 设备类型
|
||||
private int encryptMode; // 秘钥模式:0-默认模式,1-自定义模式
|
||||
private int encrypt; // 是否支持加密
|
||||
private int ability;
|
||||
private int cloudMealStates; //云套餐状态
|
||||
private int alarmStatus; //动检计划状态
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType == null ? "" : deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public String getDeviceName() {
|
||||
return deviceName == null ? "" : deviceName;
|
||||
}
|
||||
|
||||
public void setDeviceName(String deviceName) {
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
public ChannelState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(ChannelState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id == null ? "" : id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name == null ? "" : name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getBackgroudImgURL() {
|
||||
return backgroudImgURL == null ? "" : backgroudImgURL;
|
||||
}
|
||||
|
||||
public void setBackgroudImgURL(String backgroudImgURL) {
|
||||
this.backgroudImgURL = backgroudImgURL;
|
||||
}
|
||||
|
||||
public String getDeviceCode() {
|
||||
return deviceCode == null ? "" : deviceCode;
|
||||
}
|
||||
|
||||
public void setDeviceCode(String deviceCode) {
|
||||
this.deviceCode = deviceCode;
|
||||
}
|
||||
|
||||
public String getDeviceModel() {
|
||||
return deviceModel == null ? "" : deviceModel;
|
||||
}
|
||||
|
||||
public void setDeviceModel(String deviceModel) {
|
||||
this.deviceModel = deviceModel;
|
||||
}
|
||||
|
||||
public String getEncryptKey() {
|
||||
return encryptKey == null ? "" : encryptKey;
|
||||
}
|
||||
|
||||
public void setEncryptKey(String encryptKey) {
|
||||
this.encryptKey = encryptKey;
|
||||
}
|
||||
|
||||
public int getEncryptMode() {
|
||||
return encryptMode;
|
||||
}
|
||||
|
||||
public void setEncryptMode(int encryptMode) {
|
||||
this.encryptMode = encryptMode;
|
||||
}
|
||||
|
||||
public int getEncrypt() {
|
||||
return encrypt;
|
||||
}
|
||||
|
||||
public void setEncrypt(int encrypt) {
|
||||
this.encrypt = encrypt;
|
||||
}
|
||||
|
||||
public int getAbility() {
|
||||
return ability;
|
||||
}
|
||||
|
||||
public void setAbility(int ability) {
|
||||
this.ability = ability;
|
||||
}
|
||||
|
||||
public int getCloudMealStates() {
|
||||
return cloudMealStates;
|
||||
}
|
||||
|
||||
public void setCloudMealStates(int cloudMealStates) {
|
||||
this.cloudMealStates = cloudMealStates;
|
||||
}
|
||||
|
||||
public int getAlarmStatus() {
|
||||
return alarmStatus;
|
||||
}
|
||||
|
||||
public void setAlarmStatus(int alarmStatus) {
|
||||
this.alarmStatus = alarmStatus;
|
||||
}
|
||||
|
||||
public enum ChannelState {
|
||||
Online, // 在线
|
||||
Offline, // 离线
|
||||
Upgrade, // 升级中
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备能力集合
|
||||
*
|
||||
* @author 23930
|
||||
*/
|
||||
public class Ability {
|
||||
public static final int WLAN = 1; // 设备支持接入无线局域网
|
||||
public static final int AlarmPIR = 2;// 设备支持人体红外报警
|
||||
public static final int AlarmMD = 4; // 设备支持动检报警
|
||||
public static final int AudioTalk = 8; // 设备支持语音对讲
|
||||
public static final int VVP2P = 16; // 设备支持威威网络P2P服务
|
||||
public static final int DHP2P = 32; // 设备支持大华P2P服务
|
||||
public static final int PTZ = 64; //设备支持云台操作
|
||||
public static final int HSEncrypt = 128; // 设备支持华视微讯码流加密
|
||||
public static final int CloudStorage = 256; // 设备支持华视微讯平台云存储
|
||||
public static final int SUPPORT_DHHTTP_LIVE = 512; //支持私有协议直播
|
||||
public static final int SUPPORT_DHHTTP_PLAYBACK = 1024; //支持私有协议回放
|
||||
public static final int SUPPORT_DHHTTP_TALK = 2048; //支持私有协议对讲
|
||||
public static final int TCM = 4096; //设备支持TCM能力
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package com.lechange.demo.business.entity;
|
||||
/**
|
||||
* 文件描述:package com.android.business.entity;
|
||||
* 功能说明:
|
||||
* 版权申明:
|
||||
* @author ding_qili
|
||||
* @version 2015-6-17下午3:29:12
|
||||
*/
|
||||
|
||||
public class ChannelPTZInfo {
|
||||
|
||||
public enum Operation{
|
||||
Move,//移动
|
||||
Locate,//定位
|
||||
Stop;//立即停止!
|
||||
}
|
||||
|
||||
|
||||
public enum Duration{//持续多久
|
||||
Forever,//永远
|
||||
Long,//长
|
||||
Generral,//普通
|
||||
Short;//短
|
||||
}
|
||||
|
||||
public enum Direction{//方向
|
||||
Left,
|
||||
Right,
|
||||
Up,
|
||||
Down,
|
||||
ZoomIn,
|
||||
ZoomOut;
|
||||
}
|
||||
|
||||
public ChannelPTZInfo(Operation operation,Direction direction) {
|
||||
this.operation = operation;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 操作行为;move表示移动,locate表示定位 */
|
||||
private Operation operation = Operation.Move;
|
||||
/**
|
||||
* 持续时间
|
||||
*/
|
||||
private Duration duration = Duration.Generral;
|
||||
/**
|
||||
* 方向
|
||||
*/
|
||||
private Direction direction = Direction.Left;
|
||||
/**
|
||||
* @return the operation
|
||||
*/
|
||||
public Operation getOperation() {
|
||||
return operation;
|
||||
}
|
||||
/**
|
||||
* @param operation the operation to set
|
||||
*/
|
||||
public void setOperation(Operation operation) {
|
||||
this.operation = operation;
|
||||
}
|
||||
/**
|
||||
* @return the duration
|
||||
*/
|
||||
public Duration getDuration() {
|
||||
return duration;
|
||||
}
|
||||
/**
|
||||
* @param duration the duration to set
|
||||
*/
|
||||
public void setDuration(Duration duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
/**
|
||||
* @return the direction
|
||||
*/
|
||||
public Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
/**
|
||||
* @param direction the direction to set
|
||||
*/
|
||||
public void setDirection(Direction direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
package com.lechange.demo.business.entity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class RecordInfo {
|
||||
|
||||
public enum RecordType
|
||||
{
|
||||
DeviceLocal, // 设备本地录像
|
||||
PrivateCloud, // 私有云
|
||||
PublicCloud, // 公有云
|
||||
}
|
||||
|
||||
public enum RecordEventType
|
||||
{
|
||||
All, // 所有录像
|
||||
Manual, // 手动录像
|
||||
Event, // 事件录像
|
||||
}
|
||||
|
||||
private String id = UUID.randomUUID().toString();
|
||||
private RecordType type; // 录像类型
|
||||
private float fileLength; // 文件长度
|
||||
private float downLength = -1; // 已下载长度
|
||||
private long startTime; // 开始时间
|
||||
private long endTime; // 结束时间
|
||||
private String deviceId; //设备ID
|
||||
private String deviceKey;
|
||||
private String backgroudImgUrl; // 录像文件Url
|
||||
private String chnlUuid; // 通道的uuid
|
||||
private RecordEventType eventType; // 事件类型
|
||||
private String recordID; //录像ID
|
||||
private String recordPath; //录像ID(设备录像)
|
||||
private String recordRegionId; //新的录像ID
|
||||
|
||||
|
||||
public String getRecordRegionId() {
|
||||
return recordRegionId;
|
||||
}
|
||||
public void setRecordRegionId(String recordRegionId) {
|
||||
this.recordRegionId = recordRegionId;
|
||||
}
|
||||
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
public String getDeviceKey() {
|
||||
return deviceKey;
|
||||
}
|
||||
public void setDeviceKey(String deviceKey) {
|
||||
this.deviceKey = deviceKey;
|
||||
}
|
||||
|
||||
public RecordType getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(RecordType type) {
|
||||
this.type = type;
|
||||
}
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
public float getFileLength() {
|
||||
return fileLength;
|
||||
}
|
||||
public void setFileLength(float fileLength) {
|
||||
this.fileLength = fileLength;
|
||||
}
|
||||
public float getDownLength() {
|
||||
return downLength;
|
||||
}
|
||||
public void setDownLength(float downLength) {
|
||||
this.downLength = downLength;
|
||||
}
|
||||
public void setStartTime(long startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
public void setEndTime(long endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
public String getBackgroudImgUrl() {
|
||||
return backgroudImgUrl;
|
||||
}
|
||||
public void setBackgroudImgUrl(String backgroudImgUrl) {
|
||||
this.backgroudImgUrl = backgroudImgUrl;
|
||||
}
|
||||
public String getChnlUuid() {
|
||||
return chnlUuid;
|
||||
}
|
||||
public void setChnlUuid(String chnlUuid) {
|
||||
this.chnlUuid = chnlUuid;
|
||||
}
|
||||
public RecordEventType getEventType() {
|
||||
return eventType;
|
||||
}
|
||||
public void setEventType(RecordEventType eventType) {
|
||||
this.eventType = eventType;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setRecordID(String id) {
|
||||
this.recordID = id;
|
||||
}
|
||||
public String getRecordID() {
|
||||
return this.recordID;
|
||||
}
|
||||
|
||||
public boolean isDownload() {
|
||||
return downLength >= 0;
|
||||
}
|
||||
public String getRecordPath() {
|
||||
return recordPath;
|
||||
}
|
||||
public void setRecordPath(String recordPath) {
|
||||
this.recordPath = recordPath;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,227 @@
|
|||
package com.lechange.demo.business.util;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
/**
|
||||
* @author 31833
|
||||
* @version Version Time Description<br>
|
||||
* 1.0 2017/3/4 13:45 封装HTTP的相关请求
|
||||
*/
|
||||
|
||||
public class HttpUtils {
|
||||
|
||||
private static final String ALLOWED_URL_CHARS = "@#&=*+-_.,:!?()/~'%";
|
||||
|
||||
private static final String CHARSET = "UTF-8";
|
||||
|
||||
private static final int connectTimeout = 5 * 1000;
|
||||
|
||||
private static final int readTimout = 10 * 1000;
|
||||
|
||||
private static HttpUtils instance;
|
||||
|
||||
private TrustManager[] trustAllCerts = {new TrustAllX509TrustManager()};
|
||||
|
||||
public static HttpUtils getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (HttpUtils.class) {
|
||||
if (instance == null) {
|
||||
instance = new HttpUtils();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private HttpUtils() {
|
||||
|
||||
try {
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(new NullhostNameVerifier());
|
||||
SSLContext sc = SSLContext.getInstance("TLS");
|
||||
sc.init(null, trustAllCerts, new SecureRandom());
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
HttpURLConnection.setFollowRedirects(true);
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public HttpURLConnection createConnection(String url) throws IOException {
|
||||
|
||||
String encodeUrl = Uri.encode(url, ALLOWED_URL_CHARS);
|
||||
HttpURLConnection conn = (HttpURLConnection) new URL(encodeUrl).openConnection();
|
||||
conn.setConnectTimeout(connectTimeout);
|
||||
conn.setReadTimeout(readTimout);
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
||||
public InputStream getInputStream(String url) {
|
||||
InputStream is = null;
|
||||
|
||||
try {
|
||||
HttpURLConnection conn = createConnection(url);
|
||||
conn.setRequestMethod("GET");
|
||||
is = conn.getInputStream();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
public String getString(String url) {
|
||||
String result = null;
|
||||
InputStream is = null;
|
||||
BufferedReader br = null;
|
||||
|
||||
try {
|
||||
is = getInputStream(url);
|
||||
br = new BufferedReader(new InputStreamReader(is, CHARSET));
|
||||
String line = null;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
result = sb.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (br != null) {
|
||||
br.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String postString(String url, String params) {
|
||||
String result = null;
|
||||
OutputStream os = null;
|
||||
InputStream is = null;
|
||||
BufferedReader br = null;
|
||||
|
||||
try {
|
||||
HttpURLConnection conn = createConnection(url);
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
conn.setUseCaches(false);
|
||||
|
||||
conn.setRequestProperty("Content_Type", "application/json;charset= " + CHARSET);
|
||||
|
||||
if (params != null) {
|
||||
os = conn.getOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(os);
|
||||
dos.write(params.getBytes(CHARSET));
|
||||
dos.flush();
|
||||
dos.close();
|
||||
;
|
||||
}
|
||||
|
||||
is = conn.getInputStream();
|
||||
br = new BufferedReader(new InputStreamReader(is, CHARSET));
|
||||
String line = null;
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
|
||||
result = sb.toString();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (os != null) {
|
||||
os.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (is != null) {
|
||||
is.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private boolean shouldBeProcessed(HttpURLConnection conn) throws IOException {
|
||||
return conn.getResponseCode() == 200;
|
||||
}
|
||||
|
||||
private static class NullhostNameVerifier implements HostnameVerifier {
|
||||
|
||||
public NullhostNameVerifier() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verify(String host, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TrustAllX509TrustManager implements X509TrustManager {
|
||||
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
package com.lechange.demo.business.util;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.BitmapFactory.Options;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.LruCache;
|
||||
|
||||
import com.lechange.demo.business.util.TaskPoolHelper.RunnableTask;
|
||||
import com.lechange.opensdk.utils.LCOpenSDK_Utils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
public class ImageHelper {
|
||||
|
||||
private final static String TAG = "ImageHelper";
|
||||
private static Options mDefaultOption;
|
||||
//最近最少使用算法的缓存策略
|
||||
private static LruCache<String, Drawable> mImageCache = new LruCache<String, Drawable>(100);
|
||||
|
||||
static{
|
||||
mDefaultOption = new Options();
|
||||
//demo里面为了降低使用内存,图片缩小了一倍
|
||||
mDefaultOption.inSampleSize = 2;
|
||||
mDefaultOption.inPreferredConfig = Config.RGB_565;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void loadRealImage(final String url, final Handler handler) {
|
||||
downloadImage(url, "real", handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载普通图片(缓存)
|
||||
* @param url
|
||||
* @param key
|
||||
* @param handler
|
||||
*/
|
||||
public static void loadCacheImage(final String url, final Handler handler) {
|
||||
String[] imageIDBuffer = url.split("[/?]");
|
||||
final String imageID = imageIDBuffer[imageIDBuffer.length - 2];
|
||||
Drawable drawable = mImageCache.get(imageID);
|
||||
if(drawable != null){
|
||||
Message msg = new Message();
|
||||
msg.what = url.hashCode();
|
||||
msg.obj = drawable;
|
||||
handler.handleMessage(msg);
|
||||
}
|
||||
else{
|
||||
downloadImage(url, imageID, handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 加载加密图片(实时)
|
||||
* @param url
|
||||
* @param key
|
||||
* @param handler
|
||||
*/
|
||||
public static void loadRealImage(final String url,String deviceId, String key, final Handler handler) {
|
||||
downloadImage(url, "real",deviceId, key, handler);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加载加密图片(缓存)
|
||||
* @param url
|
||||
* @param key
|
||||
* @param handler
|
||||
*/
|
||||
public static void loadCacheImage(final String url,final String deviceId, String key, final Handler handler) {
|
||||
String[] imageIDBuffer = url.split("[/?]");
|
||||
final String imageID = imageIDBuffer[imageIDBuffer.length - 2];
|
||||
Drawable drawable = mImageCache.get(imageID);
|
||||
if(drawable != null){
|
||||
Message msg = new Message();
|
||||
msg.what = url.hashCode();
|
||||
msg.obj = drawable;
|
||||
handler.handleMessage(msg);
|
||||
}
|
||||
else{
|
||||
downloadImage(url, imageID,deviceId, key, handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 下载普通图片任务
|
||||
* @param url
|
||||
* @param imageID
|
||||
* @param handler
|
||||
*/
|
||||
private static void downloadImage(final String url, final String imageID, final Handler handler) {
|
||||
TaskPoolHelper.addTask(new RunnableTask(imageID) {
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
Drawable drawable = null;
|
||||
try {
|
||||
//创建一个url对象
|
||||
URL resurl = new URL(url);
|
||||
//设置超时时间
|
||||
HttpURLConnection urlConn = (HttpURLConnection) resurl.openConnection();
|
||||
urlConn.setConnectTimeout(5000);
|
||||
urlConn.setReadTimeout(5000);
|
||||
//打开URL对应的资源输入流
|
||||
InputStream is= urlConn.getInputStream();
|
||||
//从InputStream流中解析出图片
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(is, null, mDefaultOption);
|
||||
if (bitmap != null) {
|
||||
drawable = new BitmapDrawable(bitmap);
|
||||
}
|
||||
//加入缓存
|
||||
mImageCache.put(imageID, drawable);
|
||||
//关闭输入流
|
||||
is.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 解析设备列表信息
|
||||
handler.obtainMessage(url.hashCode(), drawable).sendToTarget(); // 发送成功消息到界面
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载加密图片任务
|
||||
* @param url
|
||||
* @param imageID
|
||||
* @param key
|
||||
* @param handler
|
||||
*/
|
||||
private static void downloadImage(final String url, final String imageID, final String deviceId,final String key, final Handler handler) {
|
||||
TaskPoolHelper.addTask(new RunnableTask(imageID) {
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
Drawable drawable = null;
|
||||
try {
|
||||
//创建一个url对象
|
||||
URL resurl = new URL(url);
|
||||
//设置超时时间
|
||||
HttpURLConnection urlConn = (HttpURLConnection) resurl.openConnection();
|
||||
urlConn.setConnectTimeout(5000);
|
||||
urlConn.setReadTimeout(5000);
|
||||
//打开URL对应的资源输入流
|
||||
InputStream is= urlConn.getInputStream();
|
||||
//从InputStream流中解析出图片
|
||||
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
|
||||
byte[] buff = new byte[500];
|
||||
int rc = 0;
|
||||
int length = 0;
|
||||
while((rc = is.read(buff,0,500)) >0)
|
||||
{
|
||||
length += rc;
|
||||
swapStream.write(buff,0,rc);
|
||||
}
|
||||
|
||||
byte[] srcBuf = swapStream.toByteArray();
|
||||
byte[] dstBuf = new byte[500000];
|
||||
int[] dstLen = new int[1];
|
||||
dstLen[0] = 500000;
|
||||
Bitmap bitmap; //=null
|
||||
switch(LCOpenSDK_Utils.decryptPic(srcBuf,length,deviceId,key,dstBuf,dstLen)){
|
||||
case 0: //解密成功
|
||||
bitmap = BitmapFactory.decodeByteArray(dstBuf, 0, dstLen[0], mDefaultOption);
|
||||
if (bitmap != null) {
|
||||
drawable = new BitmapDrawable(bitmap);
|
||||
}
|
||||
break;
|
||||
case 3: //图片非加密
|
||||
bitmap = BitmapFactory.decodeByteArray(srcBuf, 0, length, mDefaultOption);
|
||||
if (bitmap != null) {
|
||||
drawable = new BitmapDrawable(bitmap);
|
||||
}
|
||||
break;
|
||||
default: //解密失败
|
||||
break;
|
||||
}
|
||||
//加入缓存
|
||||
mImageCache.put(imageID, drawable);
|
||||
//关闭输入流
|
||||
is.close();
|
||||
swapStream.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 解析设备列表信息
|
||||
handler.obtainMessage(url.hashCode(), drawable).sendToTarget(); // 发送成功消息到界面
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
TaskPoolHelper.clearTask();
|
||||
mImageCache.evictAll();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package com.lechange.demo.business.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class MD5Helper
|
||||
{
|
||||
private static byte[] hex = new byte[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
/**
|
||||
* 对字符串进行MD5加密
|
||||
* @param rawString 要加密的字符串
|
||||
* @return MD5摘要码
|
||||
*/
|
||||
public static String encode(String rawString)
|
||||
{
|
||||
String md5String = null;
|
||||
|
||||
try
|
||||
{
|
||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||
md5.update(rawString.getBytes());
|
||||
md5String = convertToHexString(md5.digest());
|
||||
}
|
||||
catch (NoSuchAlgorithmException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (null != md5String)
|
||||
{
|
||||
return md5String.toUpperCase();
|
||||
}
|
||||
|
||||
return md5String;
|
||||
}
|
||||
|
||||
public static String encodeToLowerCase(String rawString){
|
||||
return encode(rawString).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 对文件全文生成MD5摘要
|
||||
* @param file 要加密的文件
|
||||
* @return MD5摘要码
|
||||
*/
|
||||
public static String getMD5(File file) {
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
|
||||
fis = new FileInputStream(file);
|
||||
byte[] buffer = new byte[2048];
|
||||
int length = -1;
|
||||
while ((length = fis.read(buffer)) != -1) {
|
||||
md.update(buffer, 0, length);
|
||||
}
|
||||
byte[] b = md.digest();
|
||||
return convertToHexString(b);//byteToHexString(b);
|
||||
// 16位加密
|
||||
// return buf.toString().substring(8, 24);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String convertToHexString(byte[] digests)
|
||||
{
|
||||
byte[] md5String = new byte[digests.length * 2];
|
||||
|
||||
int index = 0;
|
||||
for (byte digest : digests)
|
||||
{
|
||||
md5String[index] = hex[(digest >> 4) & 0x0F];
|
||||
md5String[index + 1] = hex[digest &0x0F];
|
||||
index += 2;
|
||||
}
|
||||
|
||||
return new String(md5String);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
package com.lechange.demo.business.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Environment;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class MediaPlayHelper {
|
||||
|
||||
private final static String ProjectName = "LechangeDemo";
|
||||
|
||||
public enum DHFilesType {
|
||||
DHImage,
|
||||
DHVideo
|
||||
}
|
||||
|
||||
|
||||
public static void setFullScreen(Activity activity) {
|
||||
activity.getWindow().setFlags(
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
|
||||
public static void quitFullScreen(Activity activity) {
|
||||
final WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
|
||||
attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
activity.getWindow().setAttributes(attrs);
|
||||
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建文件路径
|
||||
* @param file
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
public static boolean createFilePath(File file, String filePath) {
|
||||
int index = filePath.indexOf("/");
|
||||
if (index == -1) {
|
||||
return false;
|
||||
}
|
||||
if (index == 0) {
|
||||
filePath = filePath.substring(index + 1, filePath.length());
|
||||
index = filePath.indexOf("/");
|
||||
}
|
||||
String path = filePath.substring(0, index);
|
||||
File fPath;
|
||||
if (file == null) {
|
||||
fPath = new File(path);
|
||||
} else {
|
||||
fPath = new File(file.getPath() + "/" + path);
|
||||
}
|
||||
if (!fPath.exists()) {
|
||||
if (!fPath.mkdir()) // SD卡已满无法在下载文件
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (index < (filePath.length() - 1)) {
|
||||
String exPath = filePath.substring(index + 1, filePath.length());
|
||||
createFilePath(fPath, exPath);
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成抓图路径或录像存放路径
|
||||
*
|
||||
*/
|
||||
public static String getCaptureAndVideoPath(DHFilesType type, String cameraName) {
|
||||
String path = null;
|
||||
String picType = null;
|
||||
java.util.Date now = new java.util.Date();
|
||||
SimpleDateFormat tf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String sdPath = Environment.getExternalStorageDirectory().getPath();
|
||||
if(type == DHFilesType.DHImage){
|
||||
picType = "image";
|
||||
path = sdPath + "/" + ProjectName + "/" + tf.format(now) + "_" + picType + "_"
|
||||
+ cameraName + ".jpg";
|
||||
} else{
|
||||
picType = "video";
|
||||
path = sdPath + "/" + ProjectName + "/" + tf.format(now) + "_" + picType + "_"
|
||||
+ cameraName + ".mp4";
|
||||
}
|
||||
createFilePath(null, path);
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成下载录像存放路径
|
||||
*
|
||||
*/
|
||||
public static String getDownloadVideoPath(int type, String recordID, long startTime) {
|
||||
String path = null;
|
||||
String sdPath = Environment.getExternalStorageDirectory().getPath();
|
||||
String picType = "download";
|
||||
picType += type==0 ? "_cloud" : "_remote";
|
||||
|
||||
java.util.Date now = new java.util.Date(startTime);
|
||||
SimpleDateFormat tf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
path = sdPath + "/" + ProjectName + "/" + tf.format(now) + "_" + picType + "_"
|
||||
+ recordID + ".mp4";
|
||||
createFilePath(null, path);
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除下载录像存放的录像
|
||||
*
|
||||
*/
|
||||
public static void deleteDownloadVideo(String recordID, long startTime) {
|
||||
String path = null;
|
||||
String sdPath = Environment.getExternalStorageDirectory().getPath();
|
||||
String picType = "download";
|
||||
java.util.Date now = new java.util.Date(startTime);
|
||||
SimpleDateFormat tf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
path = sdPath + "/" + ProjectName + "/" + tf.format(now) + "_" + picType + "_"
|
||||
+ recordID + ".mp4";
|
||||
|
||||
File soFile = new File(path);
|
||||
if (soFile.exists()) {
|
||||
soFile.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,192 @@
|
|||
package com.lechange.demo.business.util;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
||||
public class OpenApiHelper {
|
||||
|
||||
public final static String tag = "OpenApiHelper";
|
||||
|
||||
|
||||
public static void getAccessToken(final String host,
|
||||
final String phoneNumber, final String appid,
|
||||
final String appsecret, final Handler handler) {
|
||||
// 拼装url
|
||||
String url = "";
|
||||
if (host.endsWith(":443")) {
|
||||
url = "https://" + host + "/openapi/accessToken";
|
||||
} else {
|
||||
url = "http://" + host + "/openapi/accessToken";
|
||||
}
|
||||
Log.d(tag, url);
|
||||
getToken(url, phoneNumber, appid, appsecret, handler);
|
||||
}
|
||||
|
||||
public static void getUserToken(final String host,
|
||||
final String phoneNumber, final String appid,
|
||||
final String appsecret, final Handler handler) {
|
||||
// 拼装url
|
||||
String url = "";
|
||||
if (host.endsWith(":443")) {
|
||||
url = "https://" + host + "/openapi/userToken";
|
||||
} else {
|
||||
url = "http://" + host + "/openapi/userToken";
|
||||
}
|
||||
Log.d(tag, url);
|
||||
getToken(url, phoneNumber, appid, appsecret, handler);
|
||||
}
|
||||
|
||||
public static void userBindSms(final String host, final String phoneNumber,
|
||||
final String appid, final String appsecret, final Handler handler) {
|
||||
String url = "";
|
||||
if (host.endsWith(":443")) {
|
||||
url = "https://" + host + "/openapi/userBindSms";
|
||||
} else {
|
||||
url = "http://" + host + "/openapi/userBindSms";
|
||||
}
|
||||
Log.d(tag, url);
|
||||
|
||||
int code = -1;
|
||||
String result = null;
|
||||
try {
|
||||
JSONObject body = new JSONObject();
|
||||
String data = "{phone: \"" + phoneNumber + "\"}";
|
||||
body.put("params", new JSONObject(data));
|
||||
body.put("id", "1");// id号 随机值
|
||||
|
||||
body.put(
|
||||
"system",
|
||||
new JSONObject(SignHelper.getSystem(data, appid, appsecret,
|
||||
"1.1")));
|
||||
|
||||
String response = HttpUtils.getInstance().postString(url, body.toString());
|
||||
|
||||
JSONObject res = new JSONObject((String) response);
|
||||
if (res.getJSONObject("result").getString("code").equals("0")) {
|
||||
code = 0;
|
||||
result = res.getJSONObject("result").getString("msg");
|
||||
} else {
|
||||
code = -1;
|
||||
result = res.getJSONObject("result").getString("msg");
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
result = e.getMessage();
|
||||
}
|
||||
|
||||
handler.obtainMessage(code, result).sendToTarget();
|
||||
|
||||
}
|
||||
|
||||
public static void userBind(final String host, final String phoneNumber,
|
||||
final String appId, String appSecret, final String smsCode,
|
||||
final Handler handler) {
|
||||
String url = "";
|
||||
if (host.endsWith(":443")) {
|
||||
url = "https://" + host + "/openapi/userBind";
|
||||
} else {
|
||||
url = "http://" + host + "/openapi/userBind";
|
||||
}
|
||||
Log.d(tag, url);
|
||||
|
||||
|
||||
int code = -1;
|
||||
String result = null;
|
||||
try {
|
||||
JSONObject body = new JSONObject();
|
||||
String data = "{phone: \"" + phoneNumber + "\",smsCode:\"" + smsCode
|
||||
+ "\"}";
|
||||
body.put("params", new JSONObject(data));
|
||||
body.put("id", "1");// id号 随机值
|
||||
body.put(
|
||||
"system",
|
||||
new JSONObject(SignHelper.getSystem(data, appId, appSecret,
|
||||
"1.1")));
|
||||
|
||||
|
||||
String response = HttpUtils.getInstance().postString(url, body.toString());
|
||||
Log.d("Uriah", "response" + response);
|
||||
JSONObject res = new JSONObject((String) response);
|
||||
if (res.getJSONObject("result").getString("code").equals("0")) {
|
||||
code = 0;
|
||||
result = res.getJSONObject("result").getString("msg");
|
||||
} else {
|
||||
code = -1;
|
||||
result = res.getJSONObject("result").getString("msg");
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
result = e.getMessage();
|
||||
}
|
||||
|
||||
handler.obtainMessage(code, result).sendToTarget();
|
||||
}
|
||||
|
||||
private static void getToken(final String host, final String phoneNumber,
|
||||
final String appid, final String appsecret, final Handler handler) {
|
||||
|
||||
int code = -1;
|
||||
String result = null;
|
||||
try {
|
||||
JSONObject body = new JSONObject();
|
||||
String data = "{phone:\"" + phoneNumber + "\"}";
|
||||
body.put("params", new JSONObject(data));
|
||||
body.put("id", "1");// id号 随机值
|
||||
body.put(
|
||||
"system",
|
||||
new JSONObject(SignHelper.getSystem(data, appid, appsecret,
|
||||
"1.1")));
|
||||
|
||||
String response = HttpUtils.getInstance().postString(host, body.toString());
|
||||
|
||||
if(response != null){
|
||||
JSONObject res = new JSONObject((String) response);
|
||||
if (res.getJSONObject("result").getString("code").equals("0")) {
|
||||
code = 0;
|
||||
if (res.getJSONObject("result").getJSONObject("data")
|
||||
.has("accessToken")) {
|
||||
result = res.getJSONObject("result")
|
||||
.getJSONObject("data")
|
||||
.getString("accessToken");
|
||||
} else {
|
||||
result = res.getJSONObject("result")
|
||||
.getJSONObject("data")
|
||||
.getString("userToken");
|
||||
}
|
||||
} else {
|
||||
code = -1;
|
||||
result = res.getJSONObject("result").getString("msg");
|
||||
// 界面展示和业务需要 特殊处理
|
||||
if (res.getJSONObject("result").getString("code")
|
||||
.equals("TK1004"))
|
||||
code = 1;
|
||||
if (res.getJSONObject("result").getString("code")
|
||||
.equals("TK1006"))
|
||||
code = 1;
|
||||
|
||||
}
|
||||
}else{
|
||||
code = -1;
|
||||
result = "get Token failed,Response is null";
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
result = e.getMessage();
|
||||
}
|
||||
|
||||
handler.obtainMessage(code, result).sendToTarget();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.lechange.demo.business.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
|
||||
/**
|
||||
* @author 31833
|
||||
* @version Version Time Description<br>
|
||||
* 1.0 2017/4/27 15:42 运行时权限申请帮助类
|
||||
*/
|
||||
|
||||
public class PermissionHelper {
|
||||
|
||||
private static boolean isHasPermission(Context context, String permission){
|
||||
|
||||
if(Build.VERSION.SDK_INT < 23) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ActivityCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void requestPermission(Activity activity, String[] permissions) {
|
||||
boolean flag = true;
|
||||
|
||||
for (String permission : permissions) {
|
||||
if(isHasPermission(activity,permission)){
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if(flag) {
|
||||
ActivityCompat.requestPermissions(activity, permissions, permissions.length);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package com.lechange.demo.business.util;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class SignHelper {
|
||||
public static String getSystem(String data, String appId, String appSecret, String sysVersion){
|
||||
StringBuffer sign = new StringBuffer();
|
||||
try {
|
||||
JSONObject params = new JSONObject(data);
|
||||
Iterator<?> it = params.keys();
|
||||
List<String> keyList = new ArrayList<String>();
|
||||
while(it.hasNext()){
|
||||
keyList.add(it.next().toString());
|
||||
}
|
||||
Collections.sort(keyList);
|
||||
for(String key : keyList){
|
||||
sign.append("").append(key).append(":").append(params.get(key).toString()).append(",");
|
||||
}
|
||||
//System.out.println(sign);
|
||||
} catch (JSONException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String time = Long.toString(System.currentTimeMillis()/1000);
|
||||
String nonce = randomString(32);
|
||||
sign.append("time").append(":").append(time).append(",");
|
||||
sign.append("nonce").append(":").append(nonce).append(",");
|
||||
sign.append("appSecret").append(":").append(appSecret);
|
||||
//System.out.println(sign);
|
||||
JSONObject system = new JSONObject();
|
||||
try {
|
||||
system.put("ver", sysVersion);
|
||||
system.put("sign", md5Hex(sign.toString()));
|
||||
system.put("appId", appId);
|
||||
system.put("time", time);
|
||||
system.put("nonce", nonce);
|
||||
} catch (JSONException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return system.toString();
|
||||
}
|
||||
|
||||
public static String md5Hex(String str) {
|
||||
try {
|
||||
byte hash[] = MessageDigest.getInstance("MD5").digest(str.getBytes());
|
||||
StringBuilder hex = new StringBuilder(hash.length * 2);
|
||||
for (byte b : hash) {
|
||||
if ((b & 0xFF) < 0x10) {
|
||||
hex.append("0");
|
||||
}
|
||||
hex.append(Integer.toHexString(b & 0xFF));
|
||||
}
|
||||
return hex.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final static String VEC = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
||||
private static Random rand;
|
||||
public static String randomString(int length) {
|
||||
if (rand == null) {
|
||||
rand = new Random(System.currentTimeMillis());
|
||||
}
|
||||
String ret = "";
|
||||
for (int i = 0; i < length; i++) {
|
||||
ret = ret + VEC.charAt(rand.nextInt(VEC.length()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package com.lechange.demo.business.util;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
public class TaskPoolHelper {
|
||||
private final static String TAG = "TaskPoolHelper";
|
||||
|
||||
/**
|
||||
* 构造具备过滤的task
|
||||
*/
|
||||
public static abstract class RunnableTask implements Runnable{
|
||||
public String mTaskID;
|
||||
|
||||
public RunnableTask(String taskID){
|
||||
this.mTaskID = taskID;
|
||||
}
|
||||
}
|
||||
|
||||
//private static ExecutorService mPool = Executors.newFixedThreadPool(3);
|
||||
//队列属性的task
|
||||
private static ArrayBlockingQueue<RunnableTask> mQueueTask = new ArrayBlockingQueue<RunnableTask>(50);
|
||||
private static List<String> mFilteTask = new ArrayList<String>();
|
||||
private static Thread mQueueThread;
|
||||
|
||||
//实时属性的task
|
||||
private static RunnableTask mRealTask; //=null
|
||||
private static Thread mRealThread;
|
||||
|
||||
static {
|
||||
mQueueThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
super.run();
|
||||
while (true) {
|
||||
try {
|
||||
//自带阻塞光环
|
||||
RunnableTask task = mQueueTask.take();
|
||||
task.run();
|
||||
mFilteTask.remove(task.mTaskID);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
mQueueThread.start();
|
||||
|
||||
mRealThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
super.run();
|
||||
while (true) {
|
||||
if (mRealTask == null) {
|
||||
LockSupport.park();
|
||||
} else {
|
||||
RunnableTask task = mRealTask;
|
||||
mRealTask = null;
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
mRealThread.start();
|
||||
}
|
||||
|
||||
|
||||
public static void addTask(RunnableTask task) {
|
||||
//过滤
|
||||
if (task.mTaskID.equals("real")) {
|
||||
mRealTask = task;
|
||||
LockSupport.unpark(mRealThread);
|
||||
return;
|
||||
}
|
||||
if (mFilteTask.contains(task.mTaskID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
mQueueTask.add(task);
|
||||
mFilteTask.add(task.mTaskID);
|
||||
} catch(IllegalStateException e) {
|
||||
Log.w(TAG, e.getMessage());
|
||||
mQueueTask.clear();
|
||||
mFilteTask.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void clearTask(){
|
||||
mQueueTask.clear();
|
||||
mFilteTask.clear();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.lechange.demo.business.util;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class TimeHelper {
|
||||
|
||||
public static String getDateHMS(long time) {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
|
||||
Date date = new Date(time);
|
||||
String strdate = format.format(date);
|
||||
return strdate;// 2012-10-03 23:41:31
|
||||
}
|
||||
|
||||
public static String getTimeHMS(long time) {
|
||||
SimpleDateFormat format1 = new SimpleDateFormat("HH:mm:ss");
|
||||
Date date = new Date(time);
|
||||
String date1 = format1.format(date);
|
||||
return date1;// 2012-10-03 23:41:31
|
||||
}
|
||||
|
||||
public static String getDateEN(long time) {
|
||||
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = new Date(time);
|
||||
String date1 = format1.format(date);
|
||||
return date1;// 2012-10-03 23:41:31
|
||||
}
|
||||
|
||||
public static long getTimeStamp(String time) {
|
||||
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = null;
|
||||
try {
|
||||
date = format1.parse(time);
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (date == null) {
|
||||
return -1;
|
||||
}
|
||||
return date.getTime();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,379 @@
|
|||
package com.lechange.demo.business.util;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.DhcpInfo;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class WifiManagerUtil {
|
||||
private WifiManager mWifiManager;
|
||||
private WifiInfo mWifiInfo;
|
||||
private List<ScanResult> mWifiList;
|
||||
private List<WifiConfiguration> mWifiConfiguration;
|
||||
private WifiManager.WifiLock mWifiLock;
|
||||
private static int WIFI_TYPE_NO_PASSWORD = 1;
|
||||
private static int WIFI_TYPE_WEP = 2;
|
||||
private static int WIFI_TYPE_WPA = 3;
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public WifiManagerUtil(Context context) {
|
||||
this.mWifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
|
||||
this.mWifiInfo = this.mWifiManager.getConnectionInfo();
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public void openWifi() {
|
||||
if (!this.mWifiManager.isWifiEnabled()) {
|
||||
this.mWifiManager.setWifiEnabled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public void closeWifi() {
|
||||
if (this.mWifiManager.isWifiEnabled()) {
|
||||
this.mWifiManager.setWifiEnabled(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isWifi5G(Context context) {
|
||||
int freq = 0;
|
||||
if (Build.VERSION.SDK_INT > 21) {
|
||||
freq = this.mWifiInfo.getFrequency();
|
||||
} else {
|
||||
String ssid = this.mWifiInfo.getSSID();
|
||||
if (ssid != null && ssid.length() > 2) {
|
||||
String ssidTemp = ssid.substring(1, ssid.length() - 1);
|
||||
@SuppressLint("MissingPermission")
|
||||
List<ScanResult> scanResults = this.mWifiManager.getScanResults();
|
||||
Iterator var6 = scanResults.iterator();
|
||||
|
||||
while(var6.hasNext()) {
|
||||
ScanResult scanResult = (ScanResult)var6.next();
|
||||
if (scanResult.SSID.equals(ssidTemp)) {
|
||||
freq = scanResult.frequency;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return freq > 4900 && freq < 5900;
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public int checkState() {
|
||||
return this.mWifiManager.getWifiState();
|
||||
}
|
||||
|
||||
public void acquireWifiLock() {
|
||||
this.mWifiLock.acquire();
|
||||
}
|
||||
|
||||
public void releaseWifiLock() {
|
||||
if (this.mWifiLock.isHeld()) {
|
||||
this.mWifiLock.acquire();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void creatWifiLock() {
|
||||
this.mWifiLock = this.mWifiManager.createWifiLock("Test");
|
||||
}
|
||||
|
||||
public List<WifiConfiguration> getConfiguration() {
|
||||
return this.mWifiConfiguration;
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public void connectConfiguration(int index) {
|
||||
if (index <= this.mWifiConfiguration.size()) {
|
||||
this.mWifiManager.enableNetwork(((WifiConfiguration)this.mWifiConfiguration.get(index)).networkId, true);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public void startScan() {
|
||||
this.mWifiManager.startScan();
|
||||
this.mWifiList = this.mWifiManager.getScanResults();
|
||||
this.mWifiConfiguration = this.mWifiManager.getConfiguredNetworks();
|
||||
}
|
||||
|
||||
public List<ScanResult> getWifiList() {
|
||||
return this.mWifiList;
|
||||
}
|
||||
|
||||
public StringBuilder lookUpScan() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
for(int i = 0; i < this.mWifiList.size(); ++i) {
|
||||
stringBuilder.append("Index_" + (new Integer(i + 1)).toString() + ":");
|
||||
stringBuilder.append(((ScanResult)this.mWifiList.get(i)).toString());
|
||||
stringBuilder.append("/n");
|
||||
}
|
||||
|
||||
return stringBuilder;
|
||||
}
|
||||
|
||||
public String getMacAddress() {
|
||||
return this.mWifiInfo == null ? "NULL" : this.mWifiInfo.getMacAddress();
|
||||
}
|
||||
|
||||
public String getBSSID() {
|
||||
return this.mWifiInfo == null ? "NULL" : this.mWifiInfo.getBSSID();
|
||||
}
|
||||
|
||||
public int getIPAddress() {
|
||||
return this.mWifiInfo == null ? 0 : this.mWifiInfo.getIpAddress();
|
||||
}
|
||||
|
||||
public int getNetworkId() {
|
||||
return this.mWifiInfo == null ? 0 : this.mWifiInfo.getNetworkId();
|
||||
}
|
||||
|
||||
public String getWifiInfo() {
|
||||
return this.mWifiInfo == null ? "NULL" : this.mWifiInfo.toString();
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public boolean addNetwork(WifiConfiguration wcg) {
|
||||
int wcgID = this.mWifiManager.addNetwork(wcg);
|
||||
return this.mWifiManager.enableNetwork(wcgID, true);
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public void disconnectWifi(int netId) {
|
||||
this.mWifiManager.disableNetwork(netId);
|
||||
this.mWifiManager.disconnect();
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public WifiConfiguration createWifiInfo(String SSID, String Password, int Type) {
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
config.allowedAuthAlgorithms.clear();
|
||||
config.allowedGroupCiphers.clear();
|
||||
config.allowedKeyManagement.clear();
|
||||
config.allowedPairwiseCiphers.clear();
|
||||
config.allowedProtocols.clear();
|
||||
config.SSID = "\"" + SSID + "\"";
|
||||
WifiConfiguration tempConfig = this.IsExsits(SSID);
|
||||
if (tempConfig != null) {
|
||||
this.mWifiManager.removeNetwork(tempConfig.networkId);
|
||||
}
|
||||
|
||||
if (Type == WIFI_TYPE_NO_PASSWORD) {
|
||||
config.wepKeys[0] = "\"\"";
|
||||
config.allowedKeyManagement.set(0);
|
||||
config.wepTxKeyIndex = 0;
|
||||
}
|
||||
|
||||
if (Type == WIFI_TYPE_WEP) {
|
||||
config.hiddenSSID = true;
|
||||
config.wepKeys[0] = "\"" + Password + "\"";
|
||||
config.allowedAuthAlgorithms.set(1);
|
||||
config.allowedGroupCiphers.set(3);
|
||||
config.allowedGroupCiphers.set(2);
|
||||
config.allowedGroupCiphers.set(0);
|
||||
config.allowedGroupCiphers.set(1);
|
||||
config.allowedKeyManagement.set(0);
|
||||
config.wepTxKeyIndex = 0;
|
||||
}
|
||||
|
||||
if (Type == WIFI_TYPE_WPA) {
|
||||
config.preSharedKey = "\"" + Password + "\"";
|
||||
config.hiddenSSID = true;
|
||||
config.allowedAuthAlgorithms.set(0);
|
||||
config.allowedGroupCiphers.set(2);
|
||||
config.allowedKeyManagement.set(1);
|
||||
config.allowedPairwiseCiphers.set(1);
|
||||
config.allowedGroupCiphers.set(3);
|
||||
config.allowedPairwiseCiphers.set(2);
|
||||
config.status = 2;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private WifiConfiguration IsExsits(String SSID) {
|
||||
List<WifiConfiguration> existingConfigs = this.mWifiManager.getConfiguredNetworks();
|
||||
if (existingConfigs == null) {
|
||||
return null;
|
||||
} else {
|
||||
Iterator var3 = existingConfigs.iterator();
|
||||
|
||||
WifiConfiguration existingConfig;
|
||||
do {
|
||||
if (!var3.hasNext()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
existingConfig = (WifiConfiguration)var3.next();
|
||||
} while(!existingConfig.SSID.equals("\"" + SSID + "\""));
|
||||
|
||||
return existingConfig;
|
||||
}
|
||||
}
|
||||
@SuppressLint("MissingPermission")
|
||||
public boolean connectWifi(String SSID, String passWord) {
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
WifiConfiguration tempConfig = this.IsExsits(SSID);
|
||||
if (tempConfig != null) {
|
||||
return this.mWifiManager.enableNetwork(tempConfig.networkId, true);
|
||||
}
|
||||
}
|
||||
|
||||
return this.addNetwork(this.createWifiInfo(SSID, passWord, WIFI_TYPE_NO_PASSWORD));
|
||||
}
|
||||
@SuppressLint("MissingPermission")
|
||||
public String getGatewayIp() {
|
||||
DhcpInfo dhcpInfo = this.mWifiManager.getDhcpInfo();
|
||||
if (dhcpInfo != null) {
|
||||
long gatewayIps = (long)dhcpInfo.gateway;
|
||||
return this.long2ip(gatewayIps);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String long2ip(long ip) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(String.valueOf((int)(ip & 255L)));
|
||||
stringBuffer.append('.');
|
||||
stringBuffer.append(String.valueOf((int)(ip >> 8 & 255L)));
|
||||
stringBuffer.append('.');
|
||||
stringBuffer.append(String.valueOf((int)(ip >> 16 & 255L)));
|
||||
stringBuffer.append('.');
|
||||
stringBuffer.append(String.valueOf((int)(ip >> 24 & 255L)));
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public WifiInfo getCurrentWifiInfo() {
|
||||
this.mWifiInfo = this.mWifiManager.getConnectionInfo();
|
||||
return this.mWifiInfo;
|
||||
}
|
||||
@SuppressLint("MissingPermission")
|
||||
public boolean isWifi(Context context) {
|
||||
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (connectivity == null) {
|
||||
return false;
|
||||
} else {
|
||||
NetworkInfo curNetwork = connectivity.getActiveNetworkInfo();
|
||||
if (curNetwork != null && curNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getWifiEncryption(String capabilities) {
|
||||
int encryption = 255;
|
||||
String cap = capabilities.toUpperCase(Locale.US);
|
||||
if (cap.indexOf("WPA2") != -1) {
|
||||
if (cap.indexOf("WPA2-PSK-TKIP") != -1) {
|
||||
encryption = 6;
|
||||
} else if (cap.indexOf("WPA2-PSK-AES") != -1) {
|
||||
encryption = 7;
|
||||
} else if (cap.indexOf("WPA2-TKIP") != -1) {
|
||||
encryption = 10;
|
||||
} else if (cap.indexOf("WPA2-AES") != -1) {
|
||||
encryption = 11;
|
||||
} else if (cap.indexOf("WPA2-PSK-CCMP") != -1) {
|
||||
encryption = 12;
|
||||
}
|
||||
} else if (cap.indexOf("WPA") != -1) {
|
||||
if (cap.indexOf("WPA-PSK-TKIP") != -1) {
|
||||
encryption = 4;
|
||||
} else if (cap.indexOf("WPA-PSK-CCMP") != -1) {
|
||||
encryption = 5;
|
||||
} else if (cap.indexOf("WPA-TKIP") != -1) {
|
||||
encryption = 8;
|
||||
} else if (cap.indexOf("WPA-CCMP") != -1) {
|
||||
encryption = 9;
|
||||
}
|
||||
} else if (cap.indexOf("WEP") != -1) {
|
||||
if (cap.indexOf("WEP_Open") != -1) {
|
||||
encryption = 2;
|
||||
} else if (cap.indexOf("WEP_Shared") != -1) {
|
||||
encryption = 3;
|
||||
}
|
||||
} else {
|
||||
encryption = 255;
|
||||
}
|
||||
|
||||
return encryption;
|
||||
}
|
||||
|
||||
public ScanResult getScanResult() {
|
||||
ScanResult scanResult = null;
|
||||
if (this.mWifiManager == null) {
|
||||
return null;
|
||||
} else {
|
||||
this.getCurrentWifiInfo();
|
||||
if (this.mWifiInfo.getSSID() != null) {
|
||||
try {
|
||||
if (this.mWifiList == null) {
|
||||
this.startScan();
|
||||
}
|
||||
|
||||
if (this.mWifiList == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Iterator var2 = this.mWifiList.iterator();
|
||||
|
||||
while(var2.hasNext()) {
|
||||
ScanResult s = (ScanResult)var2.next();
|
||||
if (s.SSID.replaceAll("\"", "").equals(this.mWifiInfo.getSSID().replaceAll("\"", ""))) {
|
||||
scanResult = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception var4) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return scanResult;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNoPasswordWifi() {
|
||||
ScanResult scanResult = this.getScanResult();
|
||||
if (scanResult == null) {
|
||||
return false;
|
||||
} else {
|
||||
int encypt = this.getWifiEncryption(scanResult.capabilities);
|
||||
return encypt == 2 || encypt == 255;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDoorbellSSID(String deviceSn) {
|
||||
return "Doorbell-" + deviceSn;
|
||||
}
|
||||
|
||||
public boolean isConnectedDoorbellHot(String deviceSn) {
|
||||
WifiInfo wifiInfo = this.getCurrentWifiInfo();
|
||||
if (wifiInfo == null) {
|
||||
return false;
|
||||
} else {
|
||||
String ssid = this.getDoorbellSSID(deviceSn);
|
||||
ssid = "\"" + ssid + "\"";
|
||||
return wifiInfo.getSSID().equals(ssid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,264 @@
|
|||
package com.lechange.demo.common;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
/**
|
||||
* 工具类使用说明:左按钮,中间按钮,右按钮,均支持图片和文字背景二选一,左右按钮默认支持图片,中间按钮默认支持文字
|
||||
* xml使用注意:需要在xml文件中设置宽高和背景色
|
||||
*
|
||||
*/
|
||||
public class CommonTitle extends RelativeLayout
|
||||
{
|
||||
/**
|
||||
* 左侧按钮ID
|
||||
*/
|
||||
public static final int ID_LEFT = 0;
|
||||
|
||||
/**
|
||||
* 右侧按钮ID
|
||||
*/
|
||||
public static final int ID_RIGHT = 1;
|
||||
|
||||
/**
|
||||
* 中间按钮ID, 暂时不加监听器
|
||||
*/
|
||||
public static final int ID_CENTER = 2;
|
||||
|
||||
/**
|
||||
* 左侧按钮
|
||||
*/
|
||||
private ImageView mTitleLeft;
|
||||
|
||||
|
||||
/**
|
||||
* 右侧按钮
|
||||
*/
|
||||
private ImageView mTitleRight;
|
||||
|
||||
|
||||
/**
|
||||
* 文字标题
|
||||
*/
|
||||
private TextView mTitleCenter;
|
||||
|
||||
/**
|
||||
* 点击监听
|
||||
*/
|
||||
private OnTitleClickListener mListener;
|
||||
|
||||
private View mBottom;
|
||||
|
||||
/**
|
||||
* 默认隐藏左2和右2的按钮 ,创建一个新的实例CommonTitle.
|
||||
* @param context
|
||||
* @param attrs
|
||||
*/
|
||||
public CommonTitle(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
LayoutInflater.from(context).inflate(R.layout.widget_common_title, this);
|
||||
initView();
|
||||
setListeners();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
mBottom = findViewById(R.id.bottom_line);
|
||||
mTitleLeft = (ImageView) findViewById(R.id.title_left);
|
||||
mTitleRight = (ImageView) findViewById(R.id.title_right);
|
||||
|
||||
mTitleCenter = (TextView) findViewById(R.id.title_center);
|
||||
mTitleCenter.setTextColor(getResources().getColor(R.color.title_color_center));
|
||||
mTitleCenter.setTextSize(TypedValue.COMPLEX_UNIT_PX,
|
||||
getResources().getDimensionPixelSize(R.dimen.text_size_large));
|
||||
}
|
||||
|
||||
private void setListeners() {
|
||||
mTitleLeft.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mListener != null) {
|
||||
mListener.onCommonTitleClick(ID_LEFT);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mTitleRight.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mListener != null) {
|
||||
mListener.onCommonTitleClick(ID_RIGHT);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化参数,按钮均可支持图片或者文字背景
|
||||
*
|
||||
* @param leftResId 左按钮
|
||||
* @param rightResId 右按钮
|
||||
* @param centerResId 中间text
|
||||
*
|
||||
*/
|
||||
|
||||
public void initView(int leftResId, int rightResId, int centerResId) {
|
||||
setTitleLeftView(leftResId);
|
||||
setTitleRightView(rightResId);
|
||||
setTitleCenterView(centerResId, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
public TextView getTextViewCenter() {
|
||||
return mTitleCenter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 设置按钮是否可用
|
||||
* </p>
|
||||
*/
|
||||
public void setTitleEnabled(boolean enabled, int id) {
|
||||
View v = findView(id);
|
||||
if (v != null) {
|
||||
v.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
private View findView(int id) {
|
||||
switch (id) {
|
||||
case ID_LEFT:
|
||||
return mTitleLeft;
|
||||
case ID_RIGHT:
|
||||
return mTitleRight;
|
||||
case ID_CENTER:
|
||||
return mTitleCenter;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setTitleLeftView(int resId) {
|
||||
setTitleLeft(resId);
|
||||
}
|
||||
|
||||
public void setTitleRightView(int resId) {
|
||||
setTitleRight(resId);
|
||||
}
|
||||
|
||||
public void setTitleCenterView(int resId, int colorId, int textSizeDimenId) {
|
||||
setTitleCenter(resId);
|
||||
setTextColorCenter(colorId);
|
||||
setTextSizeCenter(textSizeDimenId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置左边按钮图片
|
||||
* @param leftResId
|
||||
*/
|
||||
private void setTitleLeft(int leftResId) {
|
||||
if (leftResId != 0) {
|
||||
if (mTitleLeft != null && mTitleLeft.getVisibility() != View.VISIBLE)
|
||||
mTitleLeft.setVisibility(VISIBLE);
|
||||
mTitleLeft.setImageResource(leftResId);
|
||||
}else {
|
||||
if (mTitleLeft != null)
|
||||
mTitleLeft.setVisibility(INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置右边按钮图片
|
||||
* @param rightResId
|
||||
*/
|
||||
private void setTitleRight(int rightResId) {
|
||||
if (rightResId != 0) {
|
||||
if (mTitleRight != null && mTitleRight.getVisibility() != View.VISIBLE)
|
||||
mTitleRight.setVisibility(VISIBLE);
|
||||
mTitleRight.setImageResource(rightResId);
|
||||
}else {
|
||||
if (mTitleRight != null)
|
||||
mTitleRight.setVisibility(INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置中间按钮文字
|
||||
* @param centerResId
|
||||
*/
|
||||
private void setTitleCenter(int centerResId) {
|
||||
if (centerResId != 0) {
|
||||
if (mTitleCenter != null && mTitleCenter.getVisibility() != View.VISIBLE)
|
||||
mTitleCenter.setVisibility(VISIBLE);
|
||||
mTitleCenter.setText(centerResId);
|
||||
}else {
|
||||
if (mTitleCenter != null)
|
||||
mTitleCenter.setVisibility(INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextColorCenter(int colorId) {
|
||||
if (mTitleCenter != null) {
|
||||
mTitleCenter.setTextColor(colorId != 0 ? getResources().getColor(colorId) : getResources().getColor(
|
||||
R.color.title_color_center));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setTextSizeCenter(int textSizeDimenId) {
|
||||
if (mTitleCenter != null) {
|
||||
mTitleCenter.setTextSize(TypedValue.COMPLEX_UNIT_PX,
|
||||
textSizeDimenId != 0 ? getResources().getDimensionPixelSize(textSizeDimenId) : getResources()
|
||||
.getDimensionPixelSize(R.dimen.text_size_large));
|
||||
}
|
||||
}
|
||||
|
||||
public void setVisibleLeft(int flag) {
|
||||
if (mTitleLeft != null) {
|
||||
mTitleLeft.setVisibility(flag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setVisibleRight(int flag) {
|
||||
if (mTitleRight != null) {
|
||||
mTitleRight.setVisibility(flag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setVisibleCenter(int flag) {
|
||||
if (mTitleCenter != null) {
|
||||
mTitleCenter.setVisibility(flag);
|
||||
}
|
||||
}
|
||||
|
||||
public void setVisibleBottom(int flag) {
|
||||
if (mBottom != null) {
|
||||
mBottom.setVisibility(flag);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnTitleClickListener(OnTitleClickListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public interface OnTitleClickListener {
|
||||
public void onCommonTitleClick(int id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,254 @@
|
|||
package com.lechange.demo.common;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.animation.AnticipateOvershootInterpolator;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.lechange.demo.common.datepicker.AbstractWheel;
|
||||
import com.lechange.demo.common.datepicker.OnWheelChangedListener;
|
||||
import com.lechange.demo.common.datepicker.adapters.NumericWheelAdapter;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public class DatePicker extends LinearLayout {
|
||||
private static final String TAG = "LCDatePicker";
|
||||
|
||||
public static final int ID_LEFT = 0;
|
||||
public static final int ID_RIGHT = 1;
|
||||
|
||||
private OnTimeClickListener mListener;
|
||||
|
||||
private AbstractWheel mYearWheel; //滚轮-年
|
||||
private AbstractWheel mMonthWheel; //滚轮-月
|
||||
private AbstractWheel mDayWheel; //滚轮-日
|
||||
|
||||
private Button mCancel; //取消按钮(左边按钮)
|
||||
private TextView mNotice; //提示信息(中间文本)
|
||||
private Button mSearch; //搜索按钮(右边按钮)
|
||||
|
||||
private Date mMinDate; //拾取器的最小日期 ,默认为当前时间往前50年
|
||||
private Date mMaxDate; //拾取器的最大日期,默认为当前时间往后50年
|
||||
private String mCurrentYear; //拾取器当前选中的年-yyyy
|
||||
private String mCurrentMonth; //拾取器当前选中的月-MM
|
||||
private String mCurrentDay; //拾取器当前选中的日-dd
|
||||
|
||||
public DatePicker(Context context){
|
||||
super(context);
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
|
||||
inflater.inflate(R.layout.widget_common_datepicker, this);
|
||||
init();
|
||||
resetWheels();
|
||||
|
||||
}
|
||||
|
||||
public DatePicker(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
|
||||
inflater.inflate(R.layout.widget_common_datepicker, this);
|
||||
init();
|
||||
resetWheels();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置时间拾取器可选时间范围
|
||||
* <p></p>
|
||||
* @author 16552 2016年2月29日 上午9:44:34
|
||||
* @param minDate
|
||||
* @param maxDate
|
||||
*/
|
||||
public void setMinMaxDate(Date minDate, Date maxDate) {
|
||||
this.mMinDate = minDate;
|
||||
this.mMaxDate = maxDate;
|
||||
resetWheels();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置按钮文本
|
||||
* @param leftText
|
||||
* @param centerText
|
||||
* @param rightText
|
||||
*/
|
||||
public void setText(String leftText,String centerText,String rightText){
|
||||
|
||||
mCancel.setText(leftText);
|
||||
mNotice.setText(centerText);
|
||||
mSearch.setText(rightText);
|
||||
}
|
||||
/**
|
||||
* 获取时间拾取器当前选中的时间
|
||||
* <p></p>
|
||||
* @author 16552 2016年2月29日 上午9:44:18
|
||||
* @return
|
||||
*/
|
||||
public Date getSelectedDate() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
Log.d("Business",mCurrentYear + mCurrentMonth + mCurrentDay);
|
||||
Date selectedDate = null;
|
||||
try {
|
||||
selectedDate = dateFormat.parse(mCurrentYear + mCurrentMonth + mCurrentDay );
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "getEndTime parse daile -> " + mCurrentYear + mCurrentMonth + mCurrentDay );
|
||||
}
|
||||
return selectedDate == null ? new Date() : selectedDate;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
Date currentDate = new Date();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(currentDate);
|
||||
calendar.add(Calendar.YEAR, 50);
|
||||
mMaxDate = calendar.getTime();
|
||||
calendar.add(Calendar.YEAR, -100);
|
||||
mMinDate = calendar.getTime();
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||
String dateString = sdf.format(currentDate);
|
||||
mCurrentYear = dateString.substring(0, 4);
|
||||
mCurrentMonth = dateString.substring(4, 6);
|
||||
mCurrentDay = dateString.substring(6, 8);
|
||||
|
||||
|
||||
mYearWheel = (AbstractWheel) findViewById(R.id.year_wheel);
|
||||
mMonthWheel = (AbstractWheel) findViewById(R.id.month_wheel);
|
||||
mDayWheel = (AbstractWheel) findViewById(R.id.day_wheel);
|
||||
|
||||
mCancel = (Button) findViewById(R.id.cancel);
|
||||
mNotice = (TextView) findViewById(R.id.notice);
|
||||
mSearch = (Button) findViewById(R.id.search);
|
||||
|
||||
mCancel.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
if(mListener != null) {
|
||||
mListener.onCommonTimeClick(ID_LEFT);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
mSearch.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
if(mListener != null) {
|
||||
mListener.onCommonTimeClick(ID_RIGHT);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void resetWheels() {
|
||||
|
||||
|
||||
|
||||
|
||||
if(mYearWheel == null)
|
||||
{
|
||||
Log.d("tag","mYearWheel is null");
|
||||
}
|
||||
mYearWheel.setViewAdapter(new NumericWheelAdapter(getContext(), mMinDate.getYear() + 1900, mMaxDate.getYear() + 1900, "%04d"));
|
||||
mYearWheel.setCyclic(false);
|
||||
mYearWheel.setInterpolator(new AnticipateOvershootInterpolator());
|
||||
mYearWheel.addChangingListener(new OnWheelChangedListener() {
|
||||
|
||||
@Override
|
||||
public void onChanged(AbstractWheel wheel, int oldValue, int newValue) {
|
||||
String format = "%04d";
|
||||
mCurrentYear = String.format(format, newValue + (mMinDate.getYear() + 1900));
|
||||
resetDayWheelAdapter();
|
||||
}
|
||||
});
|
||||
mYearWheel.setCurrentItem(Integer.valueOf(mCurrentYear) - (mMinDate.getYear() + 1900));
|
||||
|
||||
int thisMonth = Integer.valueOf(mCurrentMonth);
|
||||
mMonthWheel.setViewAdapter(new NumericWheelAdapter(getContext(), 1,12, "%02d"));
|
||||
mMonthWheel.setCyclic(true);
|
||||
mMonthWheel.setInterpolator(new AnticipateOvershootInterpolator());
|
||||
mMonthWheel.addChangingListener(new OnWheelChangedListener() {
|
||||
|
||||
@Override
|
||||
public void onChanged(AbstractWheel wheel, int oldValue, int newValue) {
|
||||
String format = "%02d";
|
||||
mCurrentMonth = String.format(format, newValue + 1);
|
||||
resetDayWheelAdapter();
|
||||
}
|
||||
});
|
||||
mMonthWheel.setCurrentItem(thisMonth - 1);
|
||||
|
||||
resetDayWheelAdapter();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 使用 mCurrentYear 和 mCurrentMonth 计算并重设 mDayWheel
|
||||
*/
|
||||
private void resetDayWheelAdapter() {
|
||||
|
||||
int thisDay = Integer.valueOf(mCurrentDay);
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMM");
|
||||
Calendar cal = Calendar.getInstance();
|
||||
Date month = null;
|
||||
try {
|
||||
month = dateFormat.parse(mCurrentYear + mCurrentMonth);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "dateFormat.parse daile -> " + mCurrentYear + mCurrentMonth);
|
||||
}
|
||||
if (month != null){
|
||||
cal.setTime(month);
|
||||
}else {
|
||||
cal.setTime(new Date());
|
||||
}
|
||||
int maxDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
|
||||
mDayWheel.setViewAdapter(new NumericWheelAdapter(getContext(), 1, maxDays, "%02d"));
|
||||
mDayWheel.setCyclic(true);
|
||||
mDayWheel.setInterpolator(new AnticipateOvershootInterpolator());
|
||||
mDayWheel.addChangingListener(new OnWheelChangedListener() {
|
||||
|
||||
@Override
|
||||
public void onChanged(AbstractWheel wheel, int oldValue, int newValue) {
|
||||
String format = "%02d";
|
||||
mCurrentDay = String.format(format, newValue + 1);
|
||||
}
|
||||
});
|
||||
|
||||
if(thisDay > maxDays){
|
||||
mDayWheel.setCurrentItem(maxDays - 1);
|
||||
}else {
|
||||
mDayWheel.setCurrentItem(thisDay - 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setOnTimeClickListener(OnTimeClickListener listener){
|
||||
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public interface OnTimeClickListener{
|
||||
|
||||
public void onCommonTimeClick(int id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package com.lechange.demo.common;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
|
||||
/**
|
||||
* 多个ProgressDialog映射一个线程,通过mThreadDialog字段标识
|
||||
* @author 31554
|
||||
*
|
||||
*/
|
||||
public class ProgressDialog extends TextView{
|
||||
|
||||
private static Thread mUIThread;
|
||||
private static ProgressDialog mThreadDialog;
|
||||
|
||||
private static StringBuilder mMsg;
|
||||
private static int mMsgIndex;
|
||||
private static Handler mHandler;
|
||||
static {
|
||||
mHandler = new Handler(){
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
//Log.d("ProgressDialog", "======" + mMsg.toString());
|
||||
if (mThreadDialog != null) {
|
||||
mThreadDialog.setText(mMsg.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
mUIThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
while (true) {
|
||||
if (mThreadDialog != null) {
|
||||
if(mMsgIndex >= 4){
|
||||
mMsgIndex = 0;
|
||||
mMsg.setLength(mMsg.length() - 8);
|
||||
}
|
||||
mMsg.append(" .");
|
||||
mMsgIndex++;
|
||||
mHandler.obtainMessage().sendToTarget();
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (Exception e) {
|
||||
// InterruptedException
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else
|
||||
LockSupport.park();
|
||||
}
|
||||
}
|
||||
};
|
||||
mUIThread.start();
|
||||
}
|
||||
|
||||
//构造
|
||||
public ProgressDialog(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public ProgressDialog(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ProgressDialog(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public void setStart(String msg){
|
||||
//Log.d("111", this + "=====start " + mThreadDialog + " : " + this);
|
||||
mMsgIndex = 0;
|
||||
mMsg = new StringBuilder(msg);
|
||||
if (mThreadDialog == null || mThreadDialog.hashCode() != this.hashCode()) {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setVisibility(View.VISIBLE);
|
||||
setText(mMsg);
|
||||
}
|
||||
});
|
||||
mThreadDialog = this;
|
||||
LockSupport.unpark(mUIThread);
|
||||
}
|
||||
}
|
||||
|
||||
public void setStop(){
|
||||
//Log.d("111", "=====stop " + mThreadDialog + " : " + this);
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
if (mThreadDialog != null && mThreadDialog.hashCode() == this.hashCode()) {
|
||||
mThreadDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//mUIThread.interrupt();
|
||||
//try {
|
||||
// mUIThread.join();
|
||||
//} catch (InterruptedException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
//}
|
|
@ -0,0 +1,33 @@
|
|||
package com.lechange.demo.common;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
public class RecoderSeekBar extends SeekBar{
|
||||
|
||||
private boolean canTouchAble = true;
|
||||
|
||||
public RecoderSeekBar(Context context,AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
public RecoderSeekBar(Context context,
|
||||
AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
public RecoderSeekBar(Context context) {
|
||||
super(context);
|
||||
}
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if(!canTouchAble){
|
||||
return true;
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
public void setCanTouchAble(boolean canTouchAble){
|
||||
this.canTouchAble = canTouchAble;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,889 @@
|
|||
package com.lechange.demo.common.datepicker;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.DataSetObserver;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.lechange.demo.common.datepicker.adapters.WheelViewAdapter;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract spinner spinnerwheel view
|
||||
* This class should be subclassed.
|
||||
*
|
||||
* @author Yuri Kanivets
|
||||
* @author Dimitri Fedorov
|
||||
*/
|
||||
public abstract class AbstractWheel extends View {
|
||||
|
||||
private static int itemID = -1;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final String LOG_TAG = AbstractWheel.class.getName() + " #" + (++itemID);
|
||||
|
||||
//----------------------------------
|
||||
// Default properties values
|
||||
//----------------------------------
|
||||
|
||||
/** Default count of visible items */
|
||||
private static final int DEF_VISIBLE_ITEMS = 4;
|
||||
private static final boolean DEF_IS_CYCLIC = false;
|
||||
|
||||
//----------------------------------
|
||||
// Class properties
|
||||
//----------------------------------
|
||||
|
||||
protected int mCurrentItemIdx = 0;
|
||||
|
||||
// Count of visible items
|
||||
protected int mVisibleItems;
|
||||
// Should all items be visible
|
||||
protected boolean mIsAllVisible;
|
||||
|
||||
protected boolean mIsCyclic;
|
||||
|
||||
// Scrolling
|
||||
protected WheelScroller mScroller;
|
||||
protected boolean mIsScrollingPerformed;
|
||||
protected int mScrollingOffset;
|
||||
|
||||
// Items layout
|
||||
protected LinearLayout mItemsLayout;
|
||||
|
||||
// The number of first item in layout
|
||||
protected int mFirstItemIdx;
|
||||
|
||||
// View adapter
|
||||
protected WheelViewAdapter mViewAdapter;
|
||||
|
||||
protected int mLayoutHeight;
|
||||
protected int mLayoutWidth;
|
||||
|
||||
// Recycle
|
||||
private WheelRecycler mRecycler = new WheelRecycler(this);
|
||||
|
||||
// Listeners
|
||||
private List<OnWheelChangedListener> changingListeners = new LinkedList<OnWheelChangedListener>();
|
||||
private List<OnWheelScrollListener> scrollingListeners = new LinkedList<OnWheelScrollListener>();
|
||||
private List<OnWheelClickedListener> clickingListeners = new LinkedList<OnWheelClickedListener>();
|
||||
|
||||
//XXX: I don't like listeners the way as they are now. -df
|
||||
|
||||
// Adapter listener
|
||||
private DataSetObserver mDataObserver;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a new AbstractWheel instance
|
||||
*
|
||||
* @param context the application environment.
|
||||
* @param attrs a collection of attributes.
|
||||
* @param defStyle The default style to apply to this view.
|
||||
*/
|
||||
public AbstractWheel(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs);
|
||||
initAttributes(attrs, defStyle);
|
||||
initData(context);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Initiating data and assets at start up
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Initiates data and parameters from styles
|
||||
*
|
||||
* @param attrs a collection of attributes.
|
||||
* @param defStyle The default style to apply to this view.
|
||||
*/
|
||||
protected void initAttributes(AttributeSet attrs, int defStyle) {
|
||||
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.AbstractWheelView, defStyle, 0);
|
||||
mVisibleItems = a.getInt(R.styleable.AbstractWheelView_visibleItems, DEF_VISIBLE_ITEMS);
|
||||
mIsAllVisible = a.getBoolean(R.styleable.AbstractWheelView_isAllVisible, false);
|
||||
mIsCyclic = a.getBoolean(R.styleable.AbstractWheelView_isCyclic, DEF_IS_CYCLIC);
|
||||
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates data
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
protected void initData(Context context) {
|
||||
|
||||
mDataObserver = new DataSetObserver() {
|
||||
@Override
|
||||
public void onChanged() {
|
||||
invalidateItemsLayout(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInvalidated() {
|
||||
invalidateItemsLayout(true);
|
||||
}
|
||||
};
|
||||
|
||||
// creating new scroller
|
||||
mScroller = createScroller(new WheelScroller.ScrollingListener() {
|
||||
|
||||
public void onStarted() {
|
||||
mIsScrollingPerformed = true;
|
||||
notifyScrollingListenersAboutStart();
|
||||
onScrollStarted();
|
||||
}
|
||||
|
||||
public void onTouch() {
|
||||
onScrollTouched();
|
||||
}
|
||||
|
||||
public void onTouchUp() {
|
||||
if (!mIsScrollingPerformed)
|
||||
onScrollTouchedUp(); // if scrolling IS performed, whe should use onFinished instead
|
||||
}
|
||||
|
||||
public void onScroll(int distance) {
|
||||
doScroll(distance);
|
||||
|
||||
int dimension = getBaseDimension();
|
||||
if (mScrollingOffset > dimension) {
|
||||
mScrollingOffset = dimension;
|
||||
mScroller.stopScrolling();
|
||||
} else if (mScrollingOffset < - dimension) {
|
||||
mScrollingOffset = - dimension;
|
||||
mScroller.stopScrolling();
|
||||
}
|
||||
}
|
||||
|
||||
public void onFinished() {
|
||||
if (mIsScrollingPerformed) {
|
||||
notifyScrollingListenersAboutEnd();
|
||||
mIsScrollingPerformed = false;
|
||||
onScrollFinished();
|
||||
}
|
||||
|
||||
mScrollingOffset = 0;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void onJustify() {
|
||||
if (Math.abs(mScrollingOffset) > WheelScroller.MIN_DELTA_FOR_SCROLLING) {
|
||||
mScroller.scroll(mScrollingOffset, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState() {
|
||||
//begin boilerplate code that allows parent classes to save state
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
SavedState ss = new SavedState(superState);
|
||||
//end
|
||||
|
||||
ss.currentItem = this.getCurrentItem();
|
||||
|
||||
return ss;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Parcelable state) {
|
||||
//begin boilerplate code so parent classes can restore state
|
||||
if(!(state instanceof SavedState)) {
|
||||
super.onRestoreInstanceState(state);
|
||||
return;
|
||||
}
|
||||
|
||||
final SavedState ss = (SavedState)state;
|
||||
super.onRestoreInstanceState(ss.getSuperState());
|
||||
//end
|
||||
|
||||
mCurrentItemIdx = ss.currentItem;
|
||||
|
||||
// dirty hack to re-draw child items correctly
|
||||
postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
invalidateItemsLayout(false);
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
static class SavedState extends BaseSavedState {
|
||||
int currentItem;
|
||||
|
||||
SavedState(Parcelable superState) {
|
||||
super(superState);
|
||||
}
|
||||
|
||||
private SavedState(Parcel in) {
|
||||
super(in);
|
||||
this.currentItem = in.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
super.writeToParcel(out, flags);
|
||||
out.writeInt(this.currentItem);
|
||||
}
|
||||
|
||||
//required field that makes Parcelables from a Parcel
|
||||
public static final Creator<SavedState> CREATOR =
|
||||
new Creator<SavedState>() {
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
abstract protected void recreateAssets(int width, int height);
|
||||
|
||||
abstract public void removeBitmap();
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Scroller operations
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates scroller appropriate for specific wheel implementation.
|
||||
*
|
||||
* @param scrollingListener listener to be passed to the scroller
|
||||
* @return Initialized scroller to be used
|
||||
*/
|
||||
abstract protected WheelScroller createScroller(WheelScroller.ScrollingListener scrollingListener);
|
||||
|
||||
/* These methods are not abstract, as we may want to override only some of them */
|
||||
protected void onScrollStarted() {}
|
||||
protected void onScrollTouched() {}
|
||||
protected void onScrollTouchedUp() {}
|
||||
protected void onScrollFinished() {}
|
||||
|
||||
/**
|
||||
* Stops scrolling
|
||||
*/
|
||||
public void stopScrolling() {
|
||||
mScroller.stopScrolling();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the the specified scrolling interpolator
|
||||
* @param interpolator the interpolator
|
||||
*/
|
||||
public void setInterpolator(Interpolator interpolator) {
|
||||
mScroller.setInterpolator(interpolator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scroll the spinnerwheel
|
||||
* @param itemsToScroll items to scroll
|
||||
* @param time scrolling duration
|
||||
*/
|
||||
public void scroll(int itemsToScroll, int time) {
|
||||
int distance = itemsToScroll * getItemDimension() - mScrollingOffset;
|
||||
onScrollTouched(); // we have to emulate touch when scrolling spinnerwheel programmatically to light up stuff
|
||||
mScroller.scroll(distance, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls the spinnerwheel
|
||||
* @param delta the scrolling value
|
||||
*/
|
||||
private void doScroll(int delta) {
|
||||
mScrollingOffset += delta;
|
||||
|
||||
int itemDimension = getItemDimension();
|
||||
int count = mScrollingOffset / itemDimension;
|
||||
|
||||
int pos = mCurrentItemIdx - count;
|
||||
int itemCount = mViewAdapter.getItemsCount();
|
||||
|
||||
int fixPos = mScrollingOffset % itemDimension;
|
||||
if (Math.abs(fixPos) <= itemDimension / 2) {
|
||||
fixPos = 0;
|
||||
}
|
||||
if (mIsCyclic && itemCount > 0) {
|
||||
if (fixPos > 0) {
|
||||
pos--;
|
||||
count++;
|
||||
} else if (fixPos < 0) {
|
||||
pos++;
|
||||
count--;
|
||||
}
|
||||
// fix position by rotating
|
||||
while (pos < 0) {
|
||||
pos += itemCount;
|
||||
}
|
||||
pos %= itemCount;
|
||||
} else {
|
||||
if (pos < 0) {
|
||||
count = mCurrentItemIdx;
|
||||
pos = 0;
|
||||
} else if (pos >= itemCount) {
|
||||
count = mCurrentItemIdx - itemCount + 1;
|
||||
pos = itemCount - 1;
|
||||
} else if (pos > 0 && fixPos > 0) {
|
||||
pos--;
|
||||
count++;
|
||||
} else if (pos < itemCount - 1 && fixPos < 0) {
|
||||
pos++;
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
int offset = mScrollingOffset;
|
||||
if (pos != mCurrentItemIdx) {
|
||||
setCurrentItem(pos, false);
|
||||
} else {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
// update offset
|
||||
int baseDimension = getBaseDimension();
|
||||
mScrollingOffset = offset - count * itemDimension;
|
||||
if (mScrollingOffset > baseDimension) {
|
||||
mScrollingOffset = mScrollingOffset % baseDimension + baseDimension;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Base measurements
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns base dimension of the spinnerwheel 鈥<EFBFBD>width for horizontal spinnerwheel, height for vertical
|
||||
*
|
||||
* @return width or height of the spinnerwheel
|
||||
*/
|
||||
abstract protected int getBaseDimension();
|
||||
|
||||
/**
|
||||
* Returns base dimension of base item 鈥<EFBFBD>width for horizontal spinnerwheel, height for vertical
|
||||
*
|
||||
* @return width or height of base item
|
||||
*/
|
||||
abstract protected int getItemDimension();
|
||||
|
||||
/**
|
||||
* Processes MotionEvent and returns relevant position 鈥<EFBFBD>x for horizontal spinnerwheel, y for vertical
|
||||
*
|
||||
* @param event MotionEvent to be processed
|
||||
* @return relevant position of the MotionEvent
|
||||
*/
|
||||
abstract protected float getMotionEventPosition(MotionEvent event);
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Layout creation and measurement operations
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates item layouts if necessary
|
||||
*/
|
||||
abstract protected void createItemsLayout();
|
||||
|
||||
/**
|
||||
* Sets layout width and height
|
||||
*/
|
||||
abstract protected void doItemsLayout();
|
||||
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
if (changed) {
|
||||
int w = r - l;
|
||||
int h = b - t;
|
||||
doItemsLayout();
|
||||
if (mLayoutWidth != w || mLayoutHeight != h) {
|
||||
recreateAssets(getMeasuredWidth(), getMeasuredHeight());
|
||||
}
|
||||
mLayoutWidth = w;
|
||||
mLayoutHeight = h;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates items layout
|
||||
*
|
||||
* @param clearCaches if true then cached views will be cleared
|
||||
*/
|
||||
public void invalidateItemsLayout(boolean clearCaches) {
|
||||
if (clearCaches) {
|
||||
mRecycler.clearAll();
|
||||
if (mItemsLayout != null) {
|
||||
mItemsLayout.removeAllViews();
|
||||
}
|
||||
mScrollingOffset = 0;
|
||||
} else if (mItemsLayout != null) {
|
||||
// cache all items
|
||||
mRecycler.recycleItems(mItemsLayout, mFirstItemIdx, new ItemsRange());
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Getters and setters
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Gets count of visible items
|
||||
*
|
||||
* @return the count of visible items
|
||||
*/
|
||||
public int getVisibleItems() {
|
||||
return mVisibleItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the desired count of visible items.
|
||||
* Actual amount of visible items depends on spinnerwheel layout parameters.
|
||||
* To apply changes and rebuild view call measure().
|
||||
*
|
||||
* @param count the desired count for visible items
|
||||
*/
|
||||
public void setVisibleItems(int count) {
|
||||
mVisibleItems = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all items to have no dim and makes them visible
|
||||
* @param isAllVisible
|
||||
*/
|
||||
public void setAllItemsVisible(boolean isAllVisible){
|
||||
mIsAllVisible = isAllVisible;
|
||||
invalidateItemsLayout(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets view adapter
|
||||
* @return the view adapter
|
||||
*/
|
||||
public WheelViewAdapter getViewAdapter() {
|
||||
return mViewAdapter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets view adapter. Usually new adapters contain different views, so
|
||||
* it needs to rebuild view by calling measure().
|
||||
*
|
||||
* @param viewAdapter the view adapter
|
||||
*/
|
||||
public void setViewAdapter(WheelViewAdapter viewAdapter) {
|
||||
if (this.mViewAdapter != null) {
|
||||
this.mViewAdapter.unregisterDataSetObserver(mDataObserver);
|
||||
}
|
||||
this.mViewAdapter = viewAdapter;
|
||||
if (this.mViewAdapter != null) {
|
||||
this.mViewAdapter.registerDataSetObserver(mDataObserver);
|
||||
}
|
||||
invalidateItemsLayout(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets current value
|
||||
*
|
||||
* @return the current value
|
||||
*/
|
||||
public int getCurrentItem() {
|
||||
return mCurrentItemIdx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current item. Does nothing when index is wrong.
|
||||
*
|
||||
* @param index the item index
|
||||
* @param animated the animation flag
|
||||
*/
|
||||
public void setCurrentItem(int index, boolean animated) {
|
||||
if (mViewAdapter == null || mViewAdapter.getItemsCount() == 0) {
|
||||
return; // throw?
|
||||
}
|
||||
|
||||
int itemCount = mViewAdapter.getItemsCount();
|
||||
if (index < 0 || index >= itemCount) {
|
||||
if (mIsCyclic) {
|
||||
while (index < 0) {
|
||||
index += itemCount;
|
||||
}
|
||||
index %= itemCount;
|
||||
} else{
|
||||
return; // throw?
|
||||
}
|
||||
}
|
||||
if (index != mCurrentItemIdx) {
|
||||
if (animated) {
|
||||
int itemsToScroll = index - mCurrentItemIdx;
|
||||
if (mIsCyclic) {
|
||||
int scroll = itemCount + Math.min(index, mCurrentItemIdx) - Math.max(index, mCurrentItemIdx);
|
||||
if (scroll < Math.abs(itemsToScroll)) {
|
||||
itemsToScroll = itemsToScroll < 0 ? scroll : -scroll;
|
||||
}
|
||||
}
|
||||
scroll(itemsToScroll, 0);
|
||||
} else {
|
||||
mScrollingOffset = 0;
|
||||
final int old = mCurrentItemIdx;
|
||||
mCurrentItemIdx = index;
|
||||
notifyChangingListeners(old, mCurrentItemIdx);
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current item w/o animation. Does nothing when index is wrong.
|
||||
*
|
||||
* @param index the item index
|
||||
*/
|
||||
public void setCurrentItem(int index) {
|
||||
setCurrentItem(index, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if spinnerwheel is cyclic. That means before the 1st item there is shown the last one
|
||||
* @return true if spinnerwheel is cyclic
|
||||
*/
|
||||
public boolean isCyclic() {
|
||||
return mIsCyclic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set spinnerwheel cyclic flag
|
||||
* @param isCyclic the flag to set
|
||||
*/
|
||||
public void setCyclic(boolean isCyclic) {
|
||||
this.mIsCyclic = isCyclic;
|
||||
invalidateItemsLayout(false);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Listener operations
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Adds spinnerwheel changing listener
|
||||
* @param listener the listener
|
||||
*/
|
||||
public void addChangingListener(OnWheelChangedListener listener) {
|
||||
changingListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes spinnerwheel changing listener
|
||||
* @param listener the listener
|
||||
*/
|
||||
public void removeChangingListener(OnWheelChangedListener listener) {
|
||||
changingListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies changing listeners
|
||||
* @param oldValue the old spinnerwheel value
|
||||
* @param newValue the new spinnerwheel value
|
||||
*/
|
||||
protected void notifyChangingListeners(int oldValue, int newValue) {
|
||||
for (OnWheelChangedListener listener : changingListeners) {
|
||||
listener.onChanged(this, oldValue, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds spinnerwheel scrolling listener
|
||||
* @param listener the listener
|
||||
*/
|
||||
public void addScrollingListener(OnWheelScrollListener listener) {
|
||||
scrollingListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes spinnerwheel scrolling listener
|
||||
* @param listener the listener
|
||||
*/
|
||||
public void removeScrollingListener(OnWheelScrollListener listener) {
|
||||
scrollingListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies listeners about starting scrolling
|
||||
*/
|
||||
protected void notifyScrollingListenersAboutStart() {
|
||||
for (OnWheelScrollListener listener : scrollingListeners) {
|
||||
listener.onScrollingStarted(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies listeners about ending scrolling
|
||||
*/
|
||||
protected void notifyScrollingListenersAboutEnd() {
|
||||
for (OnWheelScrollListener listener : scrollingListeners) {
|
||||
listener.onScrollingFinished(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds spinnerwheel clicking listener
|
||||
* @param listener the listener
|
||||
*/
|
||||
public void addClickingListener(OnWheelClickedListener listener) {
|
||||
clickingListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes spinnerwheel clicking listener
|
||||
* @param listener the listener
|
||||
*/
|
||||
public void removeClickingListener(OnWheelClickedListener listener) {
|
||||
clickingListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies listeners about clicking
|
||||
* @param item clicked item
|
||||
*/
|
||||
protected void notifyClickListenersAboutClick(int item) {
|
||||
for (OnWheelClickedListener listener : clickingListeners) {
|
||||
listener.onItemClicked(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Rebuilding items
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rebuilds spinnerwheel items if necessary. Caches all unused items.
|
||||
*
|
||||
* @return true if items are rebuilt
|
||||
*/
|
||||
protected boolean rebuildItems() {
|
||||
boolean updated;
|
||||
ItemsRange range = getItemsRange();
|
||||
|
||||
if (mItemsLayout != null) {
|
||||
int first = mRecycler.recycleItems(mItemsLayout, mFirstItemIdx, range);
|
||||
updated = mFirstItemIdx != first;
|
||||
mFirstItemIdx = first;
|
||||
} else {
|
||||
createItemsLayout();
|
||||
updated = true;
|
||||
}
|
||||
|
||||
if (!updated) {
|
||||
updated = mFirstItemIdx != range.getFirst() || mItemsLayout.getChildCount() != range.getCount();
|
||||
}
|
||||
|
||||
if (mFirstItemIdx > range.getFirst() && mFirstItemIdx <= range.getLast()) {
|
||||
for (int i = mFirstItemIdx - 1; i >= range.getFirst(); i--) {
|
||||
if (!addItemView(i, true)) {
|
||||
break;
|
||||
}
|
||||
mFirstItemIdx = i;
|
||||
}
|
||||
} else {
|
||||
mFirstItemIdx = range.getFirst();
|
||||
}
|
||||
|
||||
int first = mFirstItemIdx;
|
||||
for (int i = mItemsLayout.getChildCount(); i < range.getCount(); i++) {
|
||||
if (!addItemView(mFirstItemIdx + i, false) && mItemsLayout.getChildCount() == 0) {
|
||||
first++;
|
||||
}
|
||||
}
|
||||
mFirstItemIdx = first;
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
//----------------------------------
|
||||
// ItemsRange operations
|
||||
//----------------------------------
|
||||
|
||||
/**
|
||||
* Calculates range for spinnerwheel items
|
||||
* @return the items range
|
||||
*/
|
||||
private ItemsRange getItemsRange() {
|
||||
if (mIsAllVisible) {
|
||||
int baseDimension = getBaseDimension();
|
||||
int itemDimension = getItemDimension();
|
||||
if (itemDimension != 0)
|
||||
mVisibleItems = baseDimension / itemDimension + 1;
|
||||
}
|
||||
|
||||
int start = mCurrentItemIdx - mVisibleItems / 2;
|
||||
int end = start + mVisibleItems - (mVisibleItems % 2 == 0 ? 0 : 1);
|
||||
if (mScrollingOffset != 0) {
|
||||
if (mScrollingOffset > 0) {
|
||||
start--;
|
||||
} else {
|
||||
end++;
|
||||
}
|
||||
}
|
||||
if (!isCyclic()) {
|
||||
if (start < 0)
|
||||
start = 0;
|
||||
if (end > mViewAdapter.getItemsCount())
|
||||
end = mViewAdapter.getItemsCount();
|
||||
}
|
||||
return new ItemsRange(start, end - start + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether item index is valid
|
||||
* @param index the item index
|
||||
* @return true if item index is not out of bounds or the spinnerwheel is cyclic
|
||||
*/
|
||||
protected boolean isValidItemIndex(int index) {
|
||||
return (mViewAdapter != null) && (mViewAdapter.getItemsCount() > 0) &&
|
||||
(mIsCyclic || (index >= 0 && index < mViewAdapter.getItemsCount()));
|
||||
}
|
||||
|
||||
//----------------------------------
|
||||
// Operations with item view
|
||||
//----------------------------------
|
||||
|
||||
/**
|
||||
* Adds view for item to items layout
|
||||
* @param index the item index
|
||||
* @param first the flag indicates if view should be first
|
||||
* @return true if corresponding item exists and is added
|
||||
*/
|
||||
private boolean addItemView(int index, boolean first) {
|
||||
View view = getItemView(index);
|
||||
if (view != null) {
|
||||
if (first) {
|
||||
mItemsLayout.addView(view, 0);
|
||||
} else {
|
||||
mItemsLayout.addView(view);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns view for specified item
|
||||
* @param index the item index
|
||||
* @return item view or empty view if index is out of bounds
|
||||
*/
|
||||
private View getItemView(int index) {
|
||||
if (mViewAdapter == null || mViewAdapter.getItemsCount() == 0) {
|
||||
return null;
|
||||
}
|
||||
int count = mViewAdapter.getItemsCount();
|
||||
if (!isValidItemIndex(index)) {
|
||||
return mViewAdapter.getEmptyItem( mRecycler.getEmptyItem(), mItemsLayout);
|
||||
} else {
|
||||
while (index < 0) {
|
||||
index = count + index;
|
||||
}
|
||||
}
|
||||
index %= count;
|
||||
return mViewAdapter.getItem(index, mRecycler.getItem(), mItemsLayout);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Intercepting and processing touch event
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (!isEnabled() || getViewAdapter() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (getParent() != null) {
|
||||
getParent().requestDisallowInterceptTouchEvent(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (!mIsScrollingPerformed) {
|
||||
int distance = (int) getMotionEventPosition(event) - getBaseDimension() / 2;
|
||||
if (distance > 0) {
|
||||
distance += getItemDimension() / 2;
|
||||
} else {
|
||||
distance -= getItemDimension() / 2;
|
||||
}
|
||||
int items = distance / getItemDimension();
|
||||
if (items != 0 && isValidItemIndex(mCurrentItemIdx + items)) {
|
||||
notifyClickListenersAboutClick(mCurrentItemIdx + items);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return mScroller.onTouchEvent(event);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,325 @@
|
|||
package com.lechange.demo.common.datepicker;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
/**
|
||||
* Abstract spinner spinnerwheel view.
|
||||
* This class should be subclassed.
|
||||
*
|
||||
* @author Yuri Kanivets
|
||||
* @author Dimitri Fedorov
|
||||
*/
|
||||
public abstract class AbstractWheelView extends AbstractWheel {
|
||||
|
||||
private static int itemID = -1;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final String LOG_TAG = AbstractWheelView.class.getName() + " #" + (++itemID);
|
||||
|
||||
//----------------------------------
|
||||
// Default properties values
|
||||
//----------------------------------
|
||||
|
||||
protected static final int DEF_ITEMS_DIMMED_ALPHA = 50; // 60 in ICS
|
||||
|
||||
protected static final int DEF_SELECTION_DIVIDER_ACTIVE_ALPHA = 70;
|
||||
|
||||
protected static final int DEF_SELECTION_DIVIDER_DIMMED_ALPHA = 70;
|
||||
|
||||
protected static final int DEF_ITEM_OFFSET_PERCENT = 10;
|
||||
|
||||
protected static final int DEF_ITEM_PADDING = 10;
|
||||
|
||||
protected static final int DEF_SELECTION_DIVIDER_SIZE = 2;
|
||||
|
||||
//----------------------------------
|
||||
// Class properties
|
||||
//----------------------------------
|
||||
|
||||
// configurable properties
|
||||
|
||||
/** The alpha of the selector spinnerwheel when it is dimmed. */
|
||||
protected int mItemsDimmedAlpha;
|
||||
|
||||
/** The alpha of separators spinnerwheel when they are shown. */
|
||||
protected int mSelectionDividerActiveAlpha;
|
||||
|
||||
/** The alpha of separators when they are is dimmed. */
|
||||
protected int mSelectionDividerDimmedAlpha;
|
||||
|
||||
/** Top and bottom items offset */
|
||||
protected int mItemOffsetPercent;
|
||||
|
||||
/** Left and right padding value */
|
||||
protected int mItemsPadding;
|
||||
|
||||
/** Divider for showing item to be selected while scrolling */
|
||||
protected Drawable mSelectionDivider;
|
||||
|
||||
// the rest
|
||||
|
||||
/**
|
||||
* The {@link Paint} for drawing the selector.
|
||||
*/
|
||||
protected Paint mSelectorWheelPaint;
|
||||
|
||||
/**
|
||||
* The {@link Paint} for drawing the separators.
|
||||
*/
|
||||
protected Paint mSeparatorsPaint;
|
||||
|
||||
/**
|
||||
* {@link com.nineoldandroids.animation.Animator} for dimming the selector spinnerwheel.
|
||||
*/
|
||||
protected Animator mDimSelectorWheelAnimator;
|
||||
|
||||
/**
|
||||
* {@link com.nineoldandroids.animation.Animator} for dimming the selector spinnerwheel.
|
||||
*/
|
||||
protected Animator mDimSeparatorsAnimator;
|
||||
|
||||
/**
|
||||
* The property for setting the selector paint.
|
||||
*/
|
||||
protected static final String PROPERTY_SELECTOR_PAINT_COEFF = "selectorPaintCoeff";
|
||||
|
||||
/**
|
||||
* The property for setting the separators paint.
|
||||
*/
|
||||
protected static final String PROPERTY_SEPARATORS_PAINT_ALPHA = "separatorsPaintAlpha";
|
||||
|
||||
|
||||
protected Bitmap mSpinBitmap;
|
||||
// protected Bitmap mSeparatorsBitmap;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
public AbstractWheelView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Initiating assets and setters for paints
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
protected void initAttributes(AttributeSet attrs, int defStyle) {
|
||||
super.initAttributes(attrs, defStyle);
|
||||
|
||||
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.AbstractWheelView, defStyle, 0);
|
||||
mItemsDimmedAlpha = a.getInt(R.styleable.AbstractWheelView_itemsDimmedAlpha, DEF_ITEMS_DIMMED_ALPHA);
|
||||
mSelectionDividerActiveAlpha = a.getInt(R.styleable.AbstractWheelView_selectionDividerActiveAlpha, DEF_SELECTION_DIVIDER_ACTIVE_ALPHA);
|
||||
mSelectionDividerDimmedAlpha = a.getInt(R.styleable.AbstractWheelView_selectionDividerDimmedAlpha, DEF_SELECTION_DIVIDER_DIMMED_ALPHA);
|
||||
mItemOffsetPercent = a.getInt(R.styleable.AbstractWheelView_itemOffsetPercent, DEF_ITEM_OFFSET_PERCENT);
|
||||
mItemsPadding = a.getDimensionPixelSize(R.styleable.AbstractWheelView_itemsPadding, DEF_ITEM_PADDING);
|
||||
mSelectionDivider = a.getDrawable(R.styleable.AbstractWheelView_selectionDivider);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData(Context context) {
|
||||
super.initData(context);
|
||||
|
||||
// creating animators
|
||||
mDimSelectorWheelAnimator = ObjectAnimator.ofFloat(this, PROPERTY_SELECTOR_PAINT_COEFF, 1, 0);
|
||||
|
||||
mDimSeparatorsAnimator = ObjectAnimator.ofInt(this, PROPERTY_SEPARATORS_PAINT_ALPHA,
|
||||
mSelectionDividerActiveAlpha, mSelectionDividerDimmedAlpha
|
||||
);
|
||||
|
||||
// creating paints
|
||||
mSeparatorsPaint = new Paint();
|
||||
mSeparatorsPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
|
||||
mSeparatorsPaint.setAlpha(mSelectionDividerDimmedAlpha);
|
||||
|
||||
mSelectorWheelPaint = new Paint();
|
||||
mSelectorWheelPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
|
||||
}
|
||||
|
||||
/**
|
||||
* Recreates assets (like bitmaps) when layout size has been changed
|
||||
*
|
||||
* @param width New spinnerwheel width
|
||||
* @param height New spinnerwheel height
|
||||
*/
|
||||
@Override
|
||||
protected void recreateAssets(int width, int height) {
|
||||
if(mSpinBitmap == null){
|
||||
mSpinBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
// if(mSeparatorsBitmap == null){
|
||||
// mSeparatorsBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
// }
|
||||
setSelectorPaintCoeff(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the <code>alpha</code> of the {@link Paint} for drawing separators
|
||||
* spinnerwheel.
|
||||
* @param alpha alpha value from 0 to 255
|
||||
*/
|
||||
@SuppressWarnings("unused") // Called via reflection
|
||||
public void setSeparatorsPaintAlpha(int alpha) {
|
||||
mSeparatorsPaint.setAlpha(alpha);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBitmap(){
|
||||
if(mSpinBitmap != null && !mSpinBitmap.isRecycled()){
|
||||
mSpinBitmap.recycle();
|
||||
mSpinBitmap = null;
|
||||
}
|
||||
//
|
||||
// if(mSeparatorsBitmap != null && !mSeparatorsBitmap.isRecycled()){
|
||||
// mSeparatorsBitmap.recycle();
|
||||
// mSeparatorsBitmap = null;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the <code>coeff</code> of the {@link Paint} for drawing
|
||||
* the selector spinnerwheel.
|
||||
*
|
||||
* @param coeff Coefficient from 0 (selector is passive) to 1 (selector is active)
|
||||
*/
|
||||
abstract public void setSelectorPaintCoeff(float coeff);
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Processing scroller events
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
protected void onScrollTouched() {
|
||||
mDimSelectorWheelAnimator.cancel();
|
||||
mDimSeparatorsAnimator.cancel();
|
||||
setSelectorPaintCoeff(1);
|
||||
setSeparatorsPaintAlpha(mSelectionDividerActiveAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onScrollTouchedUp() {
|
||||
super.onScrollTouchedUp();
|
||||
fadeSelectorWheel(750);
|
||||
lightSeparators(750);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onScrollFinished() {
|
||||
fadeSelectorWheel(500);
|
||||
lightSeparators(500);
|
||||
}
|
||||
|
||||
//----------------------------------
|
||||
// Animating components
|
||||
//----------------------------------
|
||||
|
||||
/**
|
||||
* Fade the selector spinnerwheel via an animation.
|
||||
*
|
||||
* @param animationDuration The duration of the animation.
|
||||
*/
|
||||
private void fadeSelectorWheel(long animationDuration) {
|
||||
mDimSelectorWheelAnimator.setDuration(animationDuration);
|
||||
mDimSelectorWheelAnimator.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fade the selector spinnerwheel via an animation.
|
||||
*
|
||||
* @param animationDuration The duration of the animation.
|
||||
*/
|
||||
private void lightSeparators(long animationDuration) {
|
||||
mDimSeparatorsAnimator.setDuration(animationDuration);
|
||||
mDimSeparatorsAnimator.start();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Layout measuring
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Perform layout measurements
|
||||
*/
|
||||
abstract protected void measureLayout();
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Drawing stuff
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
if (mViewAdapter != null && mViewAdapter.getItemsCount() > 0) {
|
||||
if (rebuildItems()) {
|
||||
measureLayout();
|
||||
}
|
||||
doItemsLayout();
|
||||
drawItems(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws items on specified canvas
|
||||
*
|
||||
* @param canvas the canvas for drawing
|
||||
*/
|
||||
abstract protected void drawItems(Canvas canvas);
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.lechange.demo.common.datepicker;
|
||||
|
||||
/**
|
||||
* Range for visible items.
|
||||
*/
|
||||
public class ItemsRange {
|
||||
// First item number
|
||||
private int first;
|
||||
|
||||
// Items count
|
||||
private int count;
|
||||
|
||||
/**
|
||||
* Default constructor. Creates an empty range
|
||||
*/
|
||||
public ItemsRange() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param first the number of first item
|
||||
* @param count the count of items
|
||||
*/
|
||||
public ItemsRange(int first, int count) {
|
||||
this.first = first;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets number of first item
|
||||
* @return the number of the first item
|
||||
*/
|
||||
public int getFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets number of last item
|
||||
* @return the number of last item
|
||||
*/
|
||||
public int getLast() {
|
||||
return getFirst() + getCount() - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get items count
|
||||
* @return the count of items
|
||||
*/
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether item is contained by range
|
||||
* @param index the item number
|
||||
* @return true if item is contained
|
||||
*/
|
||||
public boolean contains(int index) {
|
||||
return index >= getFirst() && index <= getLast();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.lechange.demo.common.datepicker;
|
||||
|
||||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Wheel changed listener interface.
|
||||
* <p>The onChanged() method is called whenever current spinnerwheel positions is changed:
|
||||
* <li> New Wheel position is set
|
||||
* <li> Wheel view is scrolled
|
||||
*/
|
||||
public interface OnWheelChangedListener {
|
||||
/**
|
||||
* Callback method to be invoked when current item changed
|
||||
* @param wheel the spinnerwheel view whose state has changed
|
||||
* @param oldValue the old value of current item
|
||||
* @param newValue the new value of current item
|
||||
*/
|
||||
void onChanged(AbstractWheel wheel, int oldValue, int newValue);
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.lechange.demo.common.datepicker;
|
||||
|
||||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Wheel clicked listener interface.
|
||||
* <p>The onItemClicked() method is called whenever a spinnerwheel item is clicked
|
||||
* <li> New Wheel position is set
|
||||
* <li> Wheel view is scrolled
|
||||
*/
|
||||
public interface OnWheelClickedListener {
|
||||
/**
|
||||
* Callback method to be invoked when current item clicked
|
||||
* @param wheel the spinnerwheel view
|
||||
* @param itemIndex the index of clicked item
|
||||
*/
|
||||
void onItemClicked(AbstractWheel wheel, int itemIndex);
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.lechange.demo.common.datepicker;
|
||||
|
||||
/**
|
||||
* Wheel scrolled listener interface.
|
||||
*/
|
||||
public interface OnWheelScrollListener {
|
||||
/**
|
||||
* Callback method to be invoked when scrolling started.
|
||||
* @param wheel the spinnerwheel view whose state has changed.
|
||||
*/
|
||||
void onScrollingStarted(AbstractWheel wheel);
|
||||
|
||||
/**
|
||||
* Callback method to be invoked when scrolling ended.
|
||||
* @param wheel the spinnerwheel view whose state has changed.
|
||||
*/
|
||||
void onScrollingFinished(AbstractWheel wheel);
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.lechange.demo.common.datepicker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class WheelHorizontalScroller extends WheelScroller {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context
|
||||
* the current context
|
||||
* @param listener
|
||||
* the scrolling listener
|
||||
*/
|
||||
public WheelHorizontalScroller(Context context, ScrollingListener listener) {
|
||||
super(context, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCurrentScrollerPosition() {
|
||||
return scroller.getCurrX();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getFinalScrollerPosition() {
|
||||
return scroller.getFinalX();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMotionEventPosition(MotionEvent event) {
|
||||
// should be overriden
|
||||
return event.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void scrollerStartScroll(int distance, int time) {
|
||||
scroller.startScroll(0, 0, distance, 0, time);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void scrollerFling(int position, int velocityX, int velocityY) {
|
||||
final int maxPosition = 0x7FFFFFFF;
|
||||
final int minPosition = -maxPosition;
|
||||
scroller.fling(position, 0, -velocityX, 0, minPosition, maxPosition, 0,
|
||||
0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,371 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.lechange.demo.common.datepicker;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Shader;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
/**
|
||||
* Spinner wheel horizontal view.
|
||||
*
|
||||
* @author Yuri Kanivets
|
||||
* @author Dimitri Fedorov
|
||||
*/
|
||||
public class WheelHorizontalView extends AbstractWheelView {
|
||||
|
||||
private static int itemID = -1;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final String LOG_TAG = WheelVerticalView.class.getName() + " #" + (++itemID);
|
||||
|
||||
/**
|
||||
* The width of the selection divider.
|
||||
*/
|
||||
protected int mSelectionDividerWidth;
|
||||
|
||||
// Item width
|
||||
private int itemWidth = 0;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a new wheel horizontal view.
|
||||
*
|
||||
* @param context The application environment.
|
||||
*/
|
||||
public WheelHorizontalView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new wheel horizontal view.
|
||||
*
|
||||
* @param context The application environment.
|
||||
* @param attrs A collection of attributes.
|
||||
*/
|
||||
public WheelHorizontalView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, R.attr.abstractWheelViewStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new wheel horizontal view.
|
||||
*
|
||||
* @param context the application environment.
|
||||
* @param attrs a collection of attributes.
|
||||
* @param defStyle The default style to apply to this view.
|
||||
*/
|
||||
public WheelHorizontalView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Initiating assets and setter for selector paint
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
protected void initAttributes(AttributeSet attrs, int defStyle) {
|
||||
super.initAttributes(attrs, defStyle);
|
||||
|
||||
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.WheelHorizontalView, defStyle, 0);
|
||||
mSelectionDividerWidth = a.getDimensionPixelSize(R.styleable.WheelHorizontalView_selectionDividerWidth, DEF_SELECTION_DIVIDER_SIZE);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectorPaintCoeff(float coeff) {
|
||||
if (mItemsDimmedAlpha >= 100)
|
||||
return;
|
||||
|
||||
LinearGradient shader;
|
||||
|
||||
int w = getMeasuredWidth();
|
||||
int iw = getItemDimension();
|
||||
float p1 = (1 - iw/(float) w)/2;
|
||||
float p2 = (1 + iw/(float) w)/2;
|
||||
float z = mItemsDimmedAlpha * (1 - coeff);
|
||||
float c1f = z + 255 * coeff;
|
||||
|
||||
if (mVisibleItems == 2) {
|
||||
int c1 = Math.round( c1f ) << 24;
|
||||
int c2 = Math.round( z ) << 24;
|
||||
int[] colors = {c2, c1, 0xff000000, 0xff000000, c1, c2};
|
||||
float[] positions = { 0, p1, p1, p2, p2, 1};
|
||||
shader = new LinearGradient(0, 0, w, 0, colors, positions, Shader.TileMode.CLAMP);
|
||||
} else {
|
||||
float p3 = (1 - iw*3/(float) w)/2;
|
||||
float p4 = (1 + iw*3/(float) w)/2;
|
||||
|
||||
float s = 255 * p3/p1;
|
||||
float c3f = s * coeff ; // here goes some optimized stuff
|
||||
float c2f = z + c3f;
|
||||
|
||||
int c1 = Math.round( c1f ) << 24;
|
||||
int c2 = Math.round( c2f ) << 24;
|
||||
int c3 = Math.round( c3f ) << 24;
|
||||
|
||||
int[] colors = { c2, c2, c2, c2, 0xff000000, 0xff000000, c2, c2, c2, c2 };
|
||||
float[] positions = { 0, p3, p3, p1, p1, p2, p2, p4, p4, 1 };
|
||||
shader = new LinearGradient(0, 0, w, 0, colors, positions, Shader.TileMode.CLAMP);
|
||||
}
|
||||
mSelectorWheelPaint.setShader(shader);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Scroller-specific methods
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
protected WheelScroller createScroller(WheelScroller.ScrollingListener scrollingListener) {
|
||||
return new WheelHorizontalScroller(getContext(), scrollingListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMotionEventPosition(MotionEvent event) {
|
||||
return event.getX();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Base measurements
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
protected int getBaseDimension() {
|
||||
return getWidth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns height of spinnerwheel item
|
||||
* @return the item width
|
||||
*/
|
||||
@Override
|
||||
protected int getItemDimension() {
|
||||
if (itemWidth != 0) {
|
||||
return itemWidth;
|
||||
}
|
||||
|
||||
if (mItemsLayout != null && mItemsLayout.getChildAt(0) != null) {
|
||||
itemWidth = mItemsLayout.getChildAt(0).getMeasuredWidth();
|
||||
return itemWidth;
|
||||
}
|
||||
|
||||
return getBaseDimension() / mVisibleItems;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Debugging stuff
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
|
||||
@Override
|
||||
protected void onScrollTouchedUp() {
|
||||
super.onScrollTouchedUp();
|
||||
int cnt = mItemsLayout.getChildCount();
|
||||
View itm;
|
||||
Log.e(LOG_TAG, " ----- layout: " + mItemsLayout.getMeasuredWidth() + mItemsLayout.getMeasuredHeight());
|
||||
Log.e(LOG_TAG, " -------- dumping " + cnt + " items");
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
itm = mItemsLayout.getChildAt(i);
|
||||
Log.e(LOG_TAG, " item #" + i + ": " + itm.getWidth() + "x" + itm.getHeight());
|
||||
itm.forceLayout(); // forcing layout without re-rendering parent
|
||||
}
|
||||
Log.e(LOG_TAG, " ---------- dumping finished ");
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Layout creation and measurement operations
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates item layouts if necessary
|
||||
*/
|
||||
@Override
|
||||
protected void createItemsLayout() {
|
||||
if (mItemsLayout == null) {
|
||||
mItemsLayout = new LinearLayout(getContext());
|
||||
mItemsLayout.setOrientation(LinearLayout.HORIZONTAL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doItemsLayout() {
|
||||
mItemsLayout.layout(0, 0, getMeasuredWidth(), getMeasuredHeight() - 2 * mItemsPadding);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void measureLayout() {
|
||||
mItemsLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||
// XXX: Locating bug
|
||||
mItemsLayout.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(getWidth() + getItemDimension(), View.MeasureSpec.UNSPECIFIED),
|
||||
View.MeasureSpec.makeMeasureSpec(getHeight(), View.MeasureSpec.AT_MOST));
|
||||
}
|
||||
|
||||
//XXX: Most likely, measurements of mItemsLayout or/and its children are done inconrrectly.
|
||||
// Investigate and fix it
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int widthMode = View.MeasureSpec.getMode(widthMeasureSpec);
|
||||
int heightMode = View.MeasureSpec.getMode(heightMeasureSpec);
|
||||
int widthSize = View.MeasureSpec.getSize(widthMeasureSpec);
|
||||
int heightSize = View.MeasureSpec.getSize(heightMeasureSpec);
|
||||
|
||||
rebuildItems(); // rebuilding before measuring
|
||||
|
||||
int height = calculateLayoutHeight(heightSize, heightMode);
|
||||
|
||||
int width;
|
||||
if (widthMode == View.MeasureSpec.EXACTLY) {
|
||||
width = widthSize;
|
||||
} else {
|
||||
width = Math.max(
|
||||
getItemDimension() * (mVisibleItems - mItemOffsetPercent / 100),
|
||||
getSuggestedMinimumWidth()
|
||||
);
|
||||
|
||||
if (widthMode == View.MeasureSpec.AT_MOST) {
|
||||
width = Math.min(width, widthSize);
|
||||
}
|
||||
}
|
||||
setMeasuredDimension(width, height);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates control height and creates text layouts
|
||||
* @param heightSize the input layout height
|
||||
* @param mode the layout mode
|
||||
* @return the calculated control height
|
||||
*/
|
||||
private int calculateLayoutHeight(int heightSize, int mode) {
|
||||
mItemsLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||
mItemsLayout.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
|
||||
View.MeasureSpec.makeMeasureSpec(heightSize, View.MeasureSpec.UNSPECIFIED)
|
||||
);
|
||||
int height = mItemsLayout.getMeasuredHeight();
|
||||
|
||||
if (mode == View.MeasureSpec.EXACTLY) {
|
||||
height = heightSize;
|
||||
} else {
|
||||
height += 2 * mItemsPadding;
|
||||
|
||||
// Check against our minimum width
|
||||
height = Math.max(height, getSuggestedMinimumHeight());
|
||||
|
||||
if (mode == View.MeasureSpec.AT_MOST && heightSize < height) {
|
||||
height = heightSize;
|
||||
}
|
||||
}
|
||||
// forcing recalculating
|
||||
mItemsLayout.measure(
|
||||
// MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
|
||||
View.MeasureSpec.makeMeasureSpec(400, View.MeasureSpec.EXACTLY),
|
||||
View.MeasureSpec.makeMeasureSpec(height - 2 * mItemsPadding, View.MeasureSpec.EXACTLY)
|
||||
);
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Drawing items
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
protected void drawItems(Canvas canvas) {
|
||||
canvas.save();
|
||||
int w = getMeasuredWidth();
|
||||
int h = getMeasuredHeight();
|
||||
int iw = getItemDimension();
|
||||
|
||||
// resetting intermediate bitmap and recreating canvases
|
||||
mSpinBitmap.eraseColor(0);
|
||||
Canvas c = new Canvas(mSpinBitmap);
|
||||
Canvas cSpin = new Canvas(mSpinBitmap);
|
||||
|
||||
int left = (mCurrentItemIdx - mFirstItemIdx) * iw + (iw - getWidth()) / 2;
|
||||
c.translate(- left + mScrollingOffset, mItemsPadding);
|
||||
mItemsLayout.draw(c);
|
||||
|
||||
// mSeparatorsBitmap.eraseColor(0);
|
||||
Canvas cSeparators = new Canvas(mSpinBitmap);
|
||||
|
||||
if (mSelectionDivider != null) {
|
||||
// draw the top divider
|
||||
int leftOfLeftDivider = (getWidth() - iw - mSelectionDividerWidth) / 2;
|
||||
int rightOfLeftDivider = leftOfLeftDivider + mSelectionDividerWidth;
|
||||
mSelectionDivider.setBounds(leftOfLeftDivider, 0, rightOfLeftDivider, getHeight());
|
||||
mSelectionDivider.draw(cSeparators);
|
||||
|
||||
// draw the bottom divider
|
||||
int leftOfRightDivider = leftOfLeftDivider + iw;
|
||||
int rightOfRightDivider = rightOfLeftDivider + iw;
|
||||
mSelectionDivider.setBounds(leftOfRightDivider, 0, rightOfRightDivider, getHeight());
|
||||
mSelectionDivider.draw(cSeparators);
|
||||
}
|
||||
|
||||
cSpin.drawRect(0, 0, w, h, mSelectorWheelPaint);
|
||||
cSeparators.drawRect(0, 0, w, h, mSeparatorsPaint);
|
||||
|
||||
canvas.drawBitmap(mSpinBitmap, 0, 0, null);
|
||||
canvas.drawBitmap(mSpinBitmap, 0, 0, null);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.lechange.demo.common.datepicker;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Recycle stored spinnerwheel items to reuse.
|
||||
*/
|
||||
public class WheelRecycler {
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String LOG_TAG = WheelRecycler.class.getName();
|
||||
|
||||
// Cached items
|
||||
private List<View> items;
|
||||
|
||||
// Cached empty items
|
||||
private List<View> emptyItems;
|
||||
|
||||
// Wheel view
|
||||
private AbstractWheel wheel;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param wheel the spinnerwheel view
|
||||
*/
|
||||
public WheelRecycler(AbstractWheel wheel) {
|
||||
this.wheel = wheel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recycles items from specified layout.
|
||||
* There are saved only items not included to specified range.
|
||||
* All the cached items are removed from original layout.
|
||||
*
|
||||
* @param layout the layout containing items to be cached
|
||||
* @param firstItem the number of first item in layout
|
||||
* @param range the range of current spinnerwheel items
|
||||
* @return the new value of first item number
|
||||
*/
|
||||
public int recycleItems(LinearLayout layout, int firstItem, ItemsRange range) {
|
||||
int index = firstItem;
|
||||
for (int i = 0; i < layout.getChildCount();) {
|
||||
if (!range.contains(index)) {
|
||||
recycleView(layout.getChildAt(i), index);
|
||||
layout.removeViewAt(i);
|
||||
if (i == 0) { // first item
|
||||
firstItem++;
|
||||
}
|
||||
} else {
|
||||
i++; // go to next item
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return firstItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets item view
|
||||
* @return the cached view
|
||||
*/
|
||||
public View getItem() {
|
||||
return getCachedView(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets empty item view
|
||||
* @return the cached empty view
|
||||
*/
|
||||
public View getEmptyItem() {
|
||||
return getCachedView(emptyItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all views
|
||||
*/
|
||||
public void clearAll() {
|
||||
if (items != null) {
|
||||
items.clear();
|
||||
}
|
||||
if (emptyItems != null) {
|
||||
emptyItems.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds view to specified cache. Creates a cache list if it is null.
|
||||
* @param view the view to be cached
|
||||
* @param cache the cache list
|
||||
* @return the cache list
|
||||
*/
|
||||
private List<View> addView(View view, List<View> cache) {
|
||||
if (cache == null) {
|
||||
cache = new LinkedList<View>();
|
||||
}
|
||||
|
||||
cache.add(view);
|
||||
return cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds view to cache. Determines view type (item view or empty one) by index.
|
||||
* @param view the view to be cached
|
||||
* @param index the index of view
|
||||
*/
|
||||
private void recycleView(View view, int index) {
|
||||
int count = wheel.getViewAdapter().getItemsCount();
|
||||
|
||||
if ((index < 0 || index >= count) && !wheel.isCyclic()) {
|
||||
// empty view
|
||||
emptyItems = addView(view, emptyItems);
|
||||
} else {
|
||||
while (index < 0) {
|
||||
index = count + index;
|
||||
}
|
||||
index %= count;
|
||||
items = addView(view, items);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets view from specified cache.
|
||||
* @param cache the cache
|
||||
* @return the first view from cache.
|
||||
*/
|
||||
private View getCachedView(List<View> cache) {
|
||||
if (cache != null && cache.size() > 0) {
|
||||
View view = cache.get(0);
|
||||
cache.remove(0);
|
||||
return view;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,281 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.lechange.demo.common.datepicker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.GestureDetector.SimpleOnGestureListener;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.Scroller;
|
||||
|
||||
/**
|
||||
* Scroller class handles scrolling events and updates the spinnerwheel
|
||||
*/
|
||||
public abstract class WheelScroller {
|
||||
/**
|
||||
* Scrolling listener interface
|
||||
*/
|
||||
public interface ScrollingListener {
|
||||
/**
|
||||
* Scrolling callback called when scrolling is performed.
|
||||
* @param distance the distance to scroll
|
||||
*/
|
||||
void onScroll(int distance);
|
||||
|
||||
/**
|
||||
* This callback is invoked when scroller has been touched
|
||||
*/
|
||||
void onTouch();
|
||||
|
||||
/**
|
||||
* This callback is invoked when touch is up
|
||||
*/
|
||||
void onTouchUp();
|
||||
|
||||
/**
|
||||
* Starting callback called when scrolling is started
|
||||
*/
|
||||
void onStarted();
|
||||
|
||||
/**
|
||||
* Finishing callback called after justifying
|
||||
*/
|
||||
void onFinished();
|
||||
|
||||
/**
|
||||
* Justifying callback called to justify a view when scrolling is ended
|
||||
*/
|
||||
void onJustify();
|
||||
}
|
||||
|
||||
/** Scrolling duration */
|
||||
private static final int SCROLLING_DURATION = 400;
|
||||
|
||||
/** Minimum delta for scrolling */
|
||||
public static final int MIN_DELTA_FOR_SCROLLING = 1;
|
||||
|
||||
// Listener
|
||||
private ScrollingListener listener;
|
||||
|
||||
// Context
|
||||
private Context context;
|
||||
|
||||
// Scrolling
|
||||
private GestureDetector gestureDetector;
|
||||
protected Scroller scroller;
|
||||
private int lastScrollPosition;
|
||||
private float lastTouchedPosition;
|
||||
private boolean isScrollingPerformed;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param context the current context
|
||||
* @param listener the scrolling listener
|
||||
*/
|
||||
public WheelScroller(Context context, ScrollingListener listener) {
|
||||
gestureDetector = new GestureDetector(context, new SimpleOnGestureListener() {
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||
// Do scrolling in onTouchEvent() since onScroll() are not call immediately
|
||||
// when user touch and move the spinnerwheel
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||
lastScrollPosition = 0;
|
||||
scrollerFling(lastScrollPosition, (int) velocityX, (int) velocityY);
|
||||
setNextMessage(MESSAGE_SCROLL);
|
||||
return true;
|
||||
}
|
||||
|
||||
// public boolean onDown(MotionEvent motionEvent);
|
||||
|
||||
});
|
||||
gestureDetector.setIsLongpressEnabled(false);
|
||||
|
||||
scroller = new Scroller(context);
|
||||
|
||||
this.listener = listener;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the the specified scrolling interpolator
|
||||
* @param interpolator the interpolator
|
||||
*/
|
||||
public void setInterpolator(Interpolator interpolator) {
|
||||
scroller.forceFinished(true);
|
||||
scroller = new Scroller(context, interpolator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scroll the spinnerwheel
|
||||
* @param distance the scrolling distance
|
||||
* @param time the scrolling duration
|
||||
*/
|
||||
public void scroll(int distance, int time) {
|
||||
scroller.forceFinished(true);
|
||||
lastScrollPosition = 0;
|
||||
scrollerStartScroll(distance, time != 0 ? time : SCROLLING_DURATION);
|
||||
setNextMessage(MESSAGE_SCROLL);
|
||||
startScrolling();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops scrolling
|
||||
*/
|
||||
public void stopScrolling() {
|
||||
scroller.forceFinished(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles Touch event
|
||||
* @param event the motion event
|
||||
* @return
|
||||
*/
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
switch (event.getAction()) {
|
||||
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
lastTouchedPosition = getMotionEventPosition(event);
|
||||
scroller.forceFinished(true);
|
||||
clearMessages();
|
||||
listener.onTouch();
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (scroller.isFinished())
|
||||
listener.onTouchUp();
|
||||
break;
|
||||
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
// perform scrolling
|
||||
int distance = (int)(getMotionEventPosition(event) - lastTouchedPosition);
|
||||
if (distance != 0) {
|
||||
startScrolling();
|
||||
listener.onScroll(distance);
|
||||
lastTouchedPosition = getMotionEventPosition(event);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) {
|
||||
justify();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Messages
|
||||
private final int MESSAGE_SCROLL = 0;
|
||||
private final int MESSAGE_JUSTIFY = 1;
|
||||
|
||||
/**
|
||||
* Set next message to queue. Clears queue before.
|
||||
*
|
||||
* @param message the message to set
|
||||
*/
|
||||
private void setNextMessage(int message) {
|
||||
clearMessages();
|
||||
animationHandler.sendEmptyMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears messages from queue
|
||||
*/
|
||||
private void clearMessages() {
|
||||
animationHandler.removeMessages(MESSAGE_SCROLL);
|
||||
animationHandler.removeMessages(MESSAGE_JUSTIFY);
|
||||
}
|
||||
|
||||
// animation handler
|
||||
private Handler animationHandler = new Handler() {
|
||||
public void handleMessage(Message msg) {
|
||||
scroller.computeScrollOffset();
|
||||
int currPosition = getCurrentScrollerPosition();
|
||||
int delta = lastScrollPosition - currPosition;
|
||||
lastScrollPosition = currPosition;
|
||||
if (delta != 0) {
|
||||
listener.onScroll(delta);
|
||||
}
|
||||
|
||||
// scrolling is not finished when it comes to final Y
|
||||
// so, finish it manually
|
||||
if (Math.abs(currPosition - getFinalScrollerPosition()) < MIN_DELTA_FOR_SCROLLING) {
|
||||
// currPosition = getFinalScrollerPosition();
|
||||
scroller.forceFinished(true);
|
||||
}
|
||||
if (!scroller.isFinished()) {
|
||||
animationHandler.sendEmptyMessage(msg.what);
|
||||
} else if (msg.what == MESSAGE_SCROLL) {
|
||||
justify();
|
||||
} else {
|
||||
finishScrolling();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Justifies spinnerwheel
|
||||
*/
|
||||
private void justify() {
|
||||
listener.onJustify();
|
||||
setNextMessage(MESSAGE_JUSTIFY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts scrolling
|
||||
*/
|
||||
private void startScrolling() {
|
||||
if (!isScrollingPerformed) {
|
||||
isScrollingPerformed = true;
|
||||
listener.onStarted();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes scrolling
|
||||
*/
|
||||
protected void finishScrolling() {
|
||||
if (isScrollingPerformed) {
|
||||
listener.onFinished();
|
||||
isScrollingPerformed = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract int getCurrentScrollerPosition();
|
||||
|
||||
protected abstract int getFinalScrollerPosition();
|
||||
|
||||
protected abstract float getMotionEventPosition(MotionEvent event);
|
||||
|
||||
protected abstract void scrollerStartScroll(int distance, int time);
|
||||
|
||||
protected abstract void scrollerFling(int position, int velocityX, int velocityY);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.lechange.demo.common.datepicker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
/**
|
||||
* Scroller class handles scrolling events and updates the
|
||||
*/
|
||||
public class WheelVerticalScroller extends WheelScroller {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param context the current context
|
||||
* @param listener the scrolling listener
|
||||
*/
|
||||
public WheelVerticalScroller(Context context, ScrollingListener listener) {
|
||||
super(context, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCurrentScrollerPosition() {
|
||||
return scroller.getCurrY();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getFinalScrollerPosition() {
|
||||
return scroller.getFinalY();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMotionEventPosition(MotionEvent event) {
|
||||
// should be overriden
|
||||
return event.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void scrollerStartScroll(int distance, int time) {
|
||||
scroller.startScroll(0, 0, 0, distance, time);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void scrollerFling(int position, int velocityX, int velocityY) {
|
||||
final int maxPosition = 0x7FFFFFFF;
|
||||
final int minPosition = -maxPosition;
|
||||
scroller.fling(0, position, 0, -velocityY, 0, 0, minPosition, maxPosition);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,344 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.lechange.demo.common.datepicker;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Shader;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
/**
|
||||
* Spinner wheel vertical view.
|
||||
*
|
||||
* @author Yuri Kanivets
|
||||
* @author Dimitri Fedorov
|
||||
*/
|
||||
public class WheelVerticalView extends AbstractWheelView {
|
||||
|
||||
private static int itemID = -1;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final String LOG_TAG = WheelVerticalView.class.getName() + " #" + (++itemID);
|
||||
|
||||
/**
|
||||
* The height of the selection divider.
|
||||
*/
|
||||
protected int mSelectionDividerHeight;
|
||||
|
||||
// Cached item height
|
||||
private int mItemHeight = 0;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a new wheel vertical view.
|
||||
*
|
||||
* @param context The application environment.
|
||||
*/
|
||||
public WheelVerticalView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new wheel vertical view.
|
||||
*
|
||||
* @param context The application environment.
|
||||
* @param attrs A collection of attributes.
|
||||
*/
|
||||
public WheelVerticalView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, R.attr.abstractWheelViewStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new wheel vertical view.
|
||||
*
|
||||
* @param context the application environment.
|
||||
* @param attrs a collection of attributes.
|
||||
* @param defStyle The default style to apply to this view.
|
||||
*/
|
||||
public WheelVerticalView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Initiating assets and setter for selector paint
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
protected void initAttributes(AttributeSet attrs, int defStyle) {
|
||||
super.initAttributes(attrs, defStyle);
|
||||
|
||||
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.WheelVerticalView, defStyle, 0);
|
||||
mSelectionDividerHeight = a.getDimensionPixelSize(R.styleable.WheelVerticalView_selectionDividerHeight, DEF_SELECTION_DIVIDER_SIZE);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectorPaintCoeff(float coeff) {
|
||||
LinearGradient shader;
|
||||
|
||||
int h = getMeasuredHeight();
|
||||
int ih = getItemDimension();
|
||||
float p1 = (1 - ih/(float) h)/2;
|
||||
float p2 = (1 + ih/(float) h)/2;
|
||||
float z = mItemsDimmedAlpha * (1 - coeff);
|
||||
float c1f = z + 255 * coeff;
|
||||
|
||||
if (mVisibleItems == 2) {
|
||||
int c1 = Math.round( c1f ) << 24;
|
||||
int c2 = Math.round( z ) << 24;
|
||||
int[] colors = {c2, c1, 0xff000000, 0xff000000, c1, c2};
|
||||
float[] positions = { 0, p1, p1, p2, p2, 1};
|
||||
shader = new LinearGradient(0, 0, 0, h, colors, positions, Shader.TileMode.CLAMP);
|
||||
} else {
|
||||
float p3 = (1 - ih*3/(float) h)/2;
|
||||
float p4 = (1 + ih*3/(float) h)/2;
|
||||
|
||||
float s = 255 * p3/p1;
|
||||
float c3f = s * coeff ; // here goes some optimized stuff
|
||||
float c2f = z + c3f;
|
||||
|
||||
int c1 = Math.round( c1f ) << 24;
|
||||
int c2 = Math.round( c2f ) << 24;
|
||||
int c3 = Math.round( c3f ) << 24;
|
||||
|
||||
int[] colors = {0, c3, c2, c1, 0xff000000, 0xff000000, c1, c2, c3, 0};
|
||||
float[] positions = {0, p3, p3, p1, p1, p2, p2, p4, p4, 1};
|
||||
shader = new LinearGradient(0, 0, 0, h, colors, positions, Shader.TileMode.CLAMP);
|
||||
}
|
||||
mSelectorWheelPaint.setShader(shader);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Scroller-specific methods
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
protected WheelScroller createScroller(WheelScroller.ScrollingListener scrollingListener) {
|
||||
return new WheelVerticalScroller(getContext(), scrollingListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMotionEventPosition(MotionEvent event) {
|
||||
return event.getY();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Base measurements
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
protected int getBaseDimension() {
|
||||
return getHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns height of the spinnerwheel
|
||||
* @return the item height
|
||||
*/
|
||||
@Override
|
||||
protected int getItemDimension() {
|
||||
if (mItemHeight != 0) {
|
||||
return mItemHeight;
|
||||
}
|
||||
|
||||
if (mItemsLayout != null && mItemsLayout.getChildAt(0) != null) {
|
||||
mItemHeight = mItemsLayout.getChildAt(0).getMeasuredHeight();
|
||||
return mItemHeight;
|
||||
}
|
||||
|
||||
return getBaseDimension() / mVisibleItems;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Layout creation and measurement operations
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Creates item layout if necessary
|
||||
*/
|
||||
@Override
|
||||
protected void createItemsLayout() {
|
||||
if (mItemsLayout == null) {
|
||||
mItemsLayout = new LinearLayout(getContext());
|
||||
mItemsLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doItemsLayout() {
|
||||
mItemsLayout.layout(0, 0, getMeasuredWidth() - 2 * mItemsPadding, getMeasuredHeight());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void measureLayout() {
|
||||
mItemsLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||
|
||||
mItemsLayout.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(getWidth() - 2 * mItemsPadding, View.MeasureSpec.EXACTLY),
|
||||
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
|
||||
int widthMode = View.MeasureSpec.getMode(widthMeasureSpec);
|
||||
int heightMode = View.MeasureSpec.getMode(heightMeasureSpec);
|
||||
int widthSize = View.MeasureSpec.getSize(widthMeasureSpec);
|
||||
int heightSize = View.MeasureSpec.getSize(heightMeasureSpec);
|
||||
|
||||
rebuildItems(); // rebuilding before measuring
|
||||
|
||||
int width = calculateLayoutWidth(widthSize, widthMode);
|
||||
|
||||
int height;
|
||||
if (heightMode == View.MeasureSpec.EXACTLY) {
|
||||
height = heightSize;
|
||||
} else {
|
||||
height = Math.max(
|
||||
getItemDimension() * (mVisibleItems - mItemOffsetPercent / 100),
|
||||
getSuggestedMinimumHeight()
|
||||
);
|
||||
|
||||
if (heightMode == View.MeasureSpec.AT_MOST) {
|
||||
height = Math.min(height, heightSize);
|
||||
}
|
||||
}
|
||||
setMeasuredDimension(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates control width
|
||||
* @param widthSize the input layout width
|
||||
* @param mode the layout mode
|
||||
* @return the calculated control width
|
||||
*/
|
||||
private int calculateLayoutWidth(int widthSize, int mode) {
|
||||
mItemsLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||
mItemsLayout.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(widthSize, View.MeasureSpec.UNSPECIFIED),
|
||||
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
||||
);
|
||||
int width = mItemsLayout.getMeasuredWidth();
|
||||
|
||||
if (mode == View.MeasureSpec.EXACTLY) {
|
||||
width = widthSize;
|
||||
} else {
|
||||
width += 2 * mItemsPadding;
|
||||
|
||||
// Check against our minimum width
|
||||
width = Math.max(width, getSuggestedMinimumWidth());
|
||||
|
||||
if (mode == View.MeasureSpec.AT_MOST && widthSize < width) {
|
||||
width = widthSize;
|
||||
}
|
||||
}
|
||||
|
||||
// forcing recalculating
|
||||
mItemsLayout.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(width - 2 * mItemsPadding, View.MeasureSpec.EXACTLY),
|
||||
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
||||
);
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Drawing items
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
protected void drawItems(Canvas canvas) {
|
||||
canvas.save();
|
||||
int w = getMeasuredWidth();
|
||||
int h = getMeasuredHeight();
|
||||
int ih = getItemDimension();
|
||||
|
||||
// resetting intermediate bitmap and recreating canvases
|
||||
mSpinBitmap.eraseColor(0);
|
||||
Canvas c = new Canvas(mSpinBitmap);
|
||||
Canvas cSpin = new Canvas(mSpinBitmap);
|
||||
|
||||
int top = (mCurrentItemIdx - mFirstItemIdx) * ih + (ih - getHeight()) / 2;
|
||||
c.translate(mItemsPadding, - top + mScrollingOffset);
|
||||
mItemsLayout.draw(c);
|
||||
|
||||
// mSeparatorsBitmap.eraseColor(0);
|
||||
Canvas cSeparators = new Canvas(mSpinBitmap);
|
||||
|
||||
if (mSelectionDivider != null) {
|
||||
// draw the top divider
|
||||
int topOfTopDivider = (getHeight() - ih - mSelectionDividerHeight) / 2;
|
||||
int bottomOfTopDivider = topOfTopDivider + mSelectionDividerHeight;
|
||||
mSelectionDivider.setBounds(0, topOfTopDivider, w, bottomOfTopDivider);
|
||||
mSelectionDivider.draw(cSeparators);
|
||||
|
||||
// draw the bottom divider
|
||||
int topOfBottomDivider = topOfTopDivider + ih;
|
||||
int bottomOfBottomDivider = bottomOfTopDivider + ih;
|
||||
mSelectionDivider.setBounds(0, topOfBottomDivider, w, bottomOfBottomDivider);
|
||||
mSelectionDivider.draw(cSeparators);
|
||||
}
|
||||
|
||||
cSpin.drawRect(0, 0, w, h, mSelectorWheelPaint);
|
||||
cSeparators.drawRect(0, 0, w, h, mSeparatorsPaint);
|
||||
|
||||
canvas.drawBitmap(mSpinBitmap, 0, 0, null);
|
||||
canvas.drawBitmap(mSpinBitmap, 0, 0, null);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.lechange.demo.common.datepicker.adapters;
|
||||
|
||||
import android.database.DataSetObserver;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Abstract Wheel adapter.
|
||||
*/
|
||||
public abstract class AbstractWheelAdapter implements WheelViewAdapter {
|
||||
// Observers
|
||||
private List<DataSetObserver> datasetObservers;
|
||||
|
||||
@Override
|
||||
public View getEmptyItem(View convertView, ViewGroup parent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerDataSetObserver(DataSetObserver observer) {
|
||||
if (datasetObservers == null) {
|
||||
datasetObservers = new LinkedList<DataSetObserver>();
|
||||
}
|
||||
datasetObservers.add(observer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterDataSetObserver(DataSetObserver observer) {
|
||||
if (datasetObservers != null) {
|
||||
datasetObservers.remove(observer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies observers about data changing
|
||||
*/
|
||||
protected void notifyDataChangedEvent() {
|
||||
if (datasetObservers != null) {
|
||||
for (DataSetObserver observer : datasetObservers) {
|
||||
observer.onChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies observers about invalidating data
|
||||
*/
|
||||
protected void notifyDataInvalidatedEvent() {
|
||||
if (datasetObservers != null) {
|
||||
for (DataSetObserver observer : datasetObservers) {
|
||||
observer.onInvalidated();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,289 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.lechange.demo.common.datepicker.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Abstract spinnerwheel adapter provides common functionality for adapters.
|
||||
*/
|
||||
public abstract class AbstractWheelTextAdapter extends AbstractWheelAdapter {
|
||||
|
||||
/** Text view resource. Used as a default view for adapter. */
|
||||
public static final int TEXT_VIEW_ITEM_RESOURCE = -1;
|
||||
|
||||
/** No resource constant. */
|
||||
protected static final int NO_RESOURCE = 0;
|
||||
|
||||
/** Default text color */
|
||||
public static final int DEFAULT_TEXT_COLOR = 0xFF101010;
|
||||
|
||||
/** Default text color */
|
||||
public static final int LABEL_COLOR = 0xFF700070;
|
||||
|
||||
/** Default text size */
|
||||
public static final int DEFAULT_TEXT_SIZE = 24;
|
||||
|
||||
/// Custom text typeface
|
||||
private Typeface textTypeface;
|
||||
|
||||
// Text settings
|
||||
private int textColor = DEFAULT_TEXT_COLOR;
|
||||
private int textSize = DEFAULT_TEXT_SIZE;
|
||||
|
||||
// Current context
|
||||
protected Context context;
|
||||
// Layout inflater
|
||||
protected LayoutInflater inflater;
|
||||
|
||||
// Items resources
|
||||
protected int itemResourceId;
|
||||
protected int itemTextResourceId;
|
||||
|
||||
// Empty items resources
|
||||
protected int emptyItemResourceId;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param context the current context
|
||||
*/
|
||||
protected AbstractWheelTextAdapter(Context context) {
|
||||
this(context, TEXT_VIEW_ITEM_RESOURCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param context the current context
|
||||
* @param itemResource the resource ID for a layout file containing a TextView to use when instantiating items views
|
||||
*/
|
||||
protected AbstractWheelTextAdapter(Context context, int itemResource) {
|
||||
this(context, itemResource, NO_RESOURCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param context the current context
|
||||
* @param itemResource the resource ID for a layout file containing a TextView to use when instantiating items views
|
||||
* @param itemTextResource the resource ID for a text view in the item layout
|
||||
*/
|
||||
protected AbstractWheelTextAdapter(Context context, int itemResource, int itemTextResource) {
|
||||
this.context = context;
|
||||
itemResourceId = itemResource;
|
||||
itemTextResourceId = itemTextResource;
|
||||
|
||||
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets text color
|
||||
* @return the text color
|
||||
*/
|
||||
public int getTextColor() {
|
||||
return textColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text color
|
||||
* @param textColor the text color to set
|
||||
*/
|
||||
public void setTextColor(int textColor) {
|
||||
this.textColor = textColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text typeface
|
||||
* @param typeface typeface to set
|
||||
*/
|
||||
public void setTextTypeface(Typeface typeface) {
|
||||
this.textTypeface = typeface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets text size
|
||||
* @return the text size
|
||||
*/
|
||||
public int getTextSize() {
|
||||
return textSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text size
|
||||
* @param textSize the text size to set
|
||||
*/
|
||||
public void setTextSize(int textSize) {
|
||||
this.textSize = textSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets resource Id for items views
|
||||
* @return the item resource Id
|
||||
*/
|
||||
public int getItemResource() {
|
||||
return itemResourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets resource Id for items views
|
||||
* @param itemResourceId the resource Id to set
|
||||
*/
|
||||
public void setItemResource(int itemResourceId) {
|
||||
this.itemResourceId = itemResourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets resource Id for text view in item layout
|
||||
* @return the item text resource Id
|
||||
*/
|
||||
public int getItemTextResource() {
|
||||
return itemTextResourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets resource Id for text view in item layout
|
||||
* @param itemTextResourceId the item text resource Id to set
|
||||
*/
|
||||
public void setItemTextResource(int itemTextResourceId) {
|
||||
this.itemTextResourceId = itemTextResourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets resource Id for empty items views
|
||||
* @return the empty item resource Id
|
||||
*/
|
||||
public int getEmptyItemResource() {
|
||||
return emptyItemResourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets resource Id for empty items views
|
||||
* @param emptyItemResourceId the empty item resource Id to set
|
||||
*/
|
||||
public void setEmptyItemResource(int emptyItemResourceId) {
|
||||
this.emptyItemResourceId = emptyItemResourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns text for specified item
|
||||
* @param index the item index
|
||||
* @return the text of specified items
|
||||
*/
|
||||
protected abstract CharSequence getItemText(int index);
|
||||
|
||||
@Override
|
||||
public View getItem(int index, View convertView, ViewGroup parent) {
|
||||
if (index >= 0 && index < getItemsCount()) {
|
||||
if (convertView == null) {
|
||||
convertView = getView(itemResourceId, parent);
|
||||
}
|
||||
TextView textView = getTextView(convertView, itemTextResourceId);
|
||||
if (textView != null) {
|
||||
CharSequence text = getItemText(index);
|
||||
if (text == null) {
|
||||
text = "";
|
||||
}
|
||||
textView.setText(text);
|
||||
configureTextView(textView);
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getEmptyItem(View convertView, ViewGroup parent) {
|
||||
if (convertView == null) {
|
||||
convertView = getView(emptyItemResourceId, parent);
|
||||
}
|
||||
if (convertView instanceof TextView) {
|
||||
configureTextView((TextView)convertView);
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures text view. Is called for the TEXT_VIEW_ITEM_RESOURCE views.
|
||||
* @param view the text view to be configured
|
||||
*/
|
||||
protected void configureTextView(TextView view) {
|
||||
if (itemResourceId == TEXT_VIEW_ITEM_RESOURCE) {
|
||||
view.setTextColor(textColor);
|
||||
view.setGravity(Gravity.CENTER);
|
||||
view.setTextSize(textSize);
|
||||
view.setLines(1);
|
||||
}
|
||||
if (textTypeface != null) {
|
||||
view.setTypeface(textTypeface);
|
||||
} else {
|
||||
view.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a text view from view
|
||||
* @param view the text view or layout containing it
|
||||
* @param textResource the text resource Id in layout
|
||||
* @return the loaded text view
|
||||
*/
|
||||
private TextView getTextView(View view, int textResource) {
|
||||
TextView text = null;
|
||||
try {
|
||||
if (textResource == NO_RESOURCE && view instanceof TextView) {
|
||||
text = (TextView) view;
|
||||
} else if (textResource != NO_RESOURCE) {
|
||||
text = (TextView) view.findViewById(textResource);
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
Log.e("AbstractWheelAdapter", "You must supply a resource ID for a TextView");
|
||||
throw new IllegalStateException(
|
||||
"AbstractWheelAdapter requires the resource ID to be a TextView", e);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads view from resources
|
||||
* @param resource the resource Id
|
||||
* @return the loaded view or null if resource is not set
|
||||
*/
|
||||
private View getView(int resource, ViewGroup parent) {
|
||||
switch (resource) {
|
||||
case NO_RESOURCE:
|
||||
return null;
|
||||
case TEXT_VIEW_ITEM_RESOURCE:
|
||||
return new TextView(context);
|
||||
default:
|
||||
return inflater.inflate(resource, parent, false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.lechange.demo.common.datepicker.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* The simple Array spinnerwheel adapter
|
||||
*
|
||||
* @param <T>
|
||||
* the element type
|
||||
*/
|
||||
public class ArrayWheelAdapter<T> extends AbstractWheelTextAdapter {
|
||||
|
||||
// items
|
||||
private T items[];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context
|
||||
* the current context
|
||||
* @param items
|
||||
* the items
|
||||
*/
|
||||
public ArrayWheelAdapter(Context context, T items[]) {
|
||||
super(context);
|
||||
|
||||
// setEmptyItemResource(TEXT_VIEW_ITEM_RESOURCE);
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getItemText(int index) {
|
||||
if (index >= 0 && index < items.length) {
|
||||
T item = items[index];
|
||||
if (item instanceof CharSequence) {
|
||||
return (CharSequence) item;
|
||||
}
|
||||
return item.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemsCount() {
|
||||
return items.length;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.lechange.demo.common.datepicker.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* Numeric Wheel adapter.
|
||||
*/
|
||||
public class NumericWheelAdapter extends AbstractWheelTextAdapter {
|
||||
|
||||
/** The default min value */
|
||||
public static final int DEFAULT_MAX_VALUE = 9;
|
||||
|
||||
/** The default max value */
|
||||
private static final int DEFAULT_MIN_VALUE = 0;
|
||||
|
||||
// Values
|
||||
private int minValue;
|
||||
private int maxValue;
|
||||
|
||||
// format
|
||||
private String format;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context
|
||||
* the current context
|
||||
*/
|
||||
public NumericWheelAdapter(Context context) {
|
||||
this(context, DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context
|
||||
* the current context
|
||||
* @param minValue
|
||||
* the spinnerwheel min value
|
||||
* @param maxValue
|
||||
* the spinnerwheel max value
|
||||
*/
|
||||
public NumericWheelAdapter(Context context, int minValue, int maxValue) {
|
||||
this(context, minValue, maxValue, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context
|
||||
* the current context
|
||||
* @param minValue
|
||||
* the spinnerwheel min value
|
||||
* @param maxValue
|
||||
* the spinnerwheel max value
|
||||
* @param format
|
||||
* the format string
|
||||
*/
|
||||
public NumericWheelAdapter(Context context, int minValue, int maxValue,
|
||||
String format) {
|
||||
super(context);
|
||||
|
||||
this.minValue = minValue;
|
||||
this.maxValue = maxValue;
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getItemText(int index) {
|
||||
if (index >= 0 && index < getItemsCount()) {
|
||||
int value = minValue + index;
|
||||
return format != null ? String.format(format, value) : Integer
|
||||
.toString(value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemsCount() {
|
||||
return maxValue - minValue + 1;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* android-spinnerwheel
|
||||
* https://github.com/ai212983/android-spinnerwheel
|
||||
*
|
||||
* based on
|
||||
*
|
||||
* Android Wheel Control.
|
||||
* https://code.google.com/p/android-wheel/
|
||||
*
|
||||
* Copyright 2011 Yuri Kanivets
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.lechange.demo.common.datepicker.adapters;
|
||||
|
||||
import android.database.DataSetObserver;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* Wheel items adapter interface
|
||||
*/
|
||||
public interface WheelViewAdapter {
|
||||
/**
|
||||
* Gets items count
|
||||
* @return the count of spinnerwheel items
|
||||
*/
|
||||
public int getItemsCount();
|
||||
|
||||
/**
|
||||
* Get a View that displays the data at the specified position in the data set
|
||||
*
|
||||
* @param index the item index
|
||||
* @param convertView the old view to reuse if possible
|
||||
* @param parent the parent that this view will eventually be attached to
|
||||
* @return the spinnerwheel item View
|
||||
*/
|
||||
public View getItem(int index, View convertView, ViewGroup parent);
|
||||
|
||||
/**
|
||||
* Get a View that displays an empty spinnerwheel item placed before the first or after
|
||||
* the last spinnerwheel item.
|
||||
*
|
||||
* @param convertView the old view to reuse if possible
|
||||
* @param parent the parent that this view will eventually be attached to
|
||||
* @return the empty item View
|
||||
*/
|
||||
public View getEmptyItem(View convertView, ViewGroup parent);
|
||||
|
||||
/**
|
||||
* Register an observer that is called when changes happen to the data used by this adapter.
|
||||
* @param observer the observer to be registered
|
||||
*/
|
||||
public void registerDataSetObserver(DataSetObserver observer);
|
||||
|
||||
/**
|
||||
* Unregister an observer that has previously been registered
|
||||
* @param observer the observer to be unregistered
|
||||
*/
|
||||
void unregisterDataSetObserver(DataSetObserver observer);
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.lechange.demo.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
|
||||
public class DeviceUpdateDialog extends Dialog {
|
||||
private TextView tv_title;
|
||||
private TextView tv_msg;
|
||||
private TextView btn_ok;
|
||||
private TextView btn_cancel;
|
||||
|
||||
public DeviceUpdateDialog(Context context) {
|
||||
super(context, R.style.sign_dialog);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialog_device_update);
|
||||
tv_title = findViewById(R.id.tv_title);
|
||||
tv_msg = findViewById(R.id.tv_msg);
|
||||
btn_ok = findViewById(R.id.btn_ok);
|
||||
btn_cancel = findViewById(R.id.btn_cancel);
|
||||
btn_ok.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (mOnOkClickLisenter != null) {
|
||||
mOnOkClickLisenter.OnOK();
|
||||
}
|
||||
dismiss();
|
||||
|
||||
}
|
||||
});
|
||||
btn_cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dismiss();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface OnOkClickLisenter {
|
||||
void OnOK();
|
||||
}
|
||||
|
||||
private OnOkClickLisenter mOnOkClickLisenter;
|
||||
|
||||
public void setOnOkClickLisenter(OnOkClickLisenter lisenter) {
|
||||
this.mOnOkClickLisenter = lisenter;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.lechange.demo.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mm.android.deviceaddmodule.mobilecommon.widget.ClearEditText;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
public class EncryptKeyInputDialog extends Dialog {
|
||||
|
||||
private TextView tvTitle;
|
||||
private ClearEditText encryptKey;
|
||||
private TextView tvCancel;
|
||||
private TextView tvSure;
|
||||
private OnClick onClick;
|
||||
|
||||
public EncryptKeyInputDialog(Context context) {
|
||||
super(context, R.style.custom_dialog);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialog_encryptkey_input);
|
||||
setCanceledOnTouchOutside(false);
|
||||
initView();
|
||||
}
|
||||
|
||||
public void setText(String content){
|
||||
tvTitle.setText(content);
|
||||
}
|
||||
|
||||
|
||||
private void initView() {
|
||||
tvTitle = findViewById(R.id.tv_title);
|
||||
encryptKey = findViewById(R.id.encrypt_key);
|
||||
tvCancel = findViewById(R.id.tv_cancel);
|
||||
tvSure = findViewById(R.id.tv_sure);
|
||||
tvCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismissLoading();
|
||||
}
|
||||
});
|
||||
tvSure.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String key = encryptKey.getText().toString().trim();
|
||||
if (onClick != null && !TextUtils.isEmpty(key)) {
|
||||
onClick.onSure(key);
|
||||
dismissLoading();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void dismissLoading() {
|
||||
dismiss();
|
||||
}
|
||||
|
||||
public interface OnClick {
|
||||
void onSure(String txt);
|
||||
}
|
||||
|
||||
public void setOnClick(OnClick onClick) {
|
||||
this.onClick = onClick;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.lechange.demo.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
|
||||
public class LoadingDialog extends Dialog {
|
||||
ProgressBar av_anim;
|
||||
|
||||
public LoadingDialog(Context context) {
|
||||
super(context, R.style.custom_dialog);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.dialog_loading_view);
|
||||
setCanceledOnTouchOutside(false);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
av_anim = (ProgressBar) findViewById(R.id.av_anim);
|
||||
}
|
||||
|
||||
public void dismissLoading() {
|
||||
av_anim.setVisibility(View.GONE);
|
||||
dismiss();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
package com.lechange.demo.dialog;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.lechange.demo.listener.PasswordSetListener;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
public class PasswordDialog extends DialogFragment {
|
||||
|
||||
|
||||
private PasswordSetListener mListener;
|
||||
// private EditText mEditText;
|
||||
private EditText editText1;
|
||||
|
||||
private int currentType = -1; //1 表示设备密码 2表示wifi密码 设备初始化的密码
|
||||
|
||||
@Override
|
||||
public void setStyle(int style, int theme) {
|
||||
super.setStyle(style, theme);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
super.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelable(boolean cancelable) {
|
||||
super.setCancelable(cancelable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelable() {
|
||||
return super.isCancelable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注释原因:wifi密码从设备添加页面携带过来,不再从密码框输入中获取
|
||||
*
|
||||
* @param savedInstanceState
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// mEditText = new EditText(getActivity());
|
||||
editText1 = new EditText(getActivity());
|
||||
// mEditText.setHint(getResources().getString(R.string.please_input_connect_wifi_password));
|
||||
editText1.setHint(getResources().getString(R.string.please_input_init_password));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setMessage("请输入密码");
|
||||
LinearLayout linearLayout = new LinearLayout(getActivity());
|
||||
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
// linearLayout.addView(mEditText);
|
||||
linearLayout.addView(editText1);
|
||||
builder.setView(linearLayout);
|
||||
if (currentType == 1) {
|
||||
editText1.setHint(getResources().getString(R.string.please_input_init_password));
|
||||
editText1.setVisibility(View.VISIBLE);
|
||||
} else if (currentType == 2) {
|
||||
editText1.setHint(getResources().getString(R.string.please_input_init_password_old));
|
||||
editText1.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
editText1.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
builder.setPositiveButton(getResources().getString(R.string.dialog_positive), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if (null != mListener) {
|
||||
if (currentType == 1 || currentType == 2) {
|
||||
// mListener.onSaveSuccess(mEditText.getText().toString(),editText1.getText().toString());
|
||||
mListener.onSaveSuccess(editText1.getText().toString());
|
||||
} else {
|
||||
// mListener.onWifiPassWord(mEditText.getText().toString(),editText1.getText().toString());
|
||||
mListener.onWifiPassWord(editText1.getText().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(getResources().getString(R.string.dialog_negative), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
builder.setCancelable(false);
|
||||
AlertDialog alertDialog = builder.create();
|
||||
return alertDialog;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
|
||||
public void setListener(PasswordSetListener listener) {
|
||||
this.mListener = listener;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setCurrentType(int currentType) {
|
||||
this.currentType = currentType;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.lechange.demo.handler;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public abstract class ActivityHandler extends Handler {
|
||||
private WeakReference<FragmentActivity> mActivity;
|
||||
public ActivityHandler(FragmentActivity activity){
|
||||
super();
|
||||
this.mActivity = new WeakReference<FragmentActivity>(activity);
|
||||
}
|
||||
public abstract void handleMsg(Message msg);
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
FragmentActivity activity = mActivity.get();
|
||||
if(activity == null){
|
||||
return;
|
||||
}
|
||||
handleMsg(msg);
|
||||
super.handleMessage(msg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.lechange.demo.listener;
|
||||
|
||||
public interface PasswordSetListener {
|
||||
void onSaveSuccess(String psw1);
|
||||
void onWifiPassWord(String psw1);
|
||||
}
|
|
@ -0,0 +1,498 @@
|
|||
package com.lechange.demo.listview;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.lechange.common.log.Logger;
|
||||
import com.lechange.demo.business.Business;
|
||||
import com.lechange.demo.business.Business.RetObject;
|
||||
import com.lechange.demo.business.entity.ChannelInfo;
|
||||
import com.lechange.demo.common.CommonTitle;
|
||||
import com.lechange.demo.common.CommonTitle.OnTitleClickListener;
|
||||
import com.lechange.demo.common.ProgressDialog;
|
||||
import com.lechange.demo.manager.DeviceAddActivity;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DevicelistActivity extends Activity {
|
||||
private final String tag = "MainActivity";
|
||||
private ListView mListview;
|
||||
private CommonTitle mCommonTitle;
|
||||
private ProgressDialog mProgressDialog; //请求加载使用
|
||||
private List<ChannelInfo> mChannelInfoList;
|
||||
private ChannelAdapter mChnlAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_device_list);
|
||||
|
||||
//绘制标题
|
||||
mCommonTitle = (CommonTitle) findViewById(R.id.title);
|
||||
mCommonTitle.initView(R.drawable.title_btn_back, R.drawable.title_btn_deviceadd, R.string.devices_name);
|
||||
|
||||
mCommonTitle.setOnTitleClickListener(new OnTitleClickListener() {
|
||||
@Override
|
||||
public void onCommonTitleClick(int id) {
|
||||
// TODO Auto-generated method stub
|
||||
switch (id) {
|
||||
case CommonTitle.ID_LEFT:
|
||||
finish();
|
||||
break;
|
||||
case CommonTitle.ID_RIGHT:
|
||||
Intent intent = new Intent(DevicelistActivity.this, DeviceAddActivity.class);
|
||||
Log.d(tag, "LcnDeviceAddActivity");
|
||||
startActivityForResult(intent, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//开启请求加载控件
|
||||
mProgressDialog = (ProgressDialog) this.findViewById(R.id.query_load);
|
||||
mProgressDialog.setStart(getString(R.string.common_loading));
|
||||
|
||||
//绘制list
|
||||
mListview = (ListView) this.findViewById(R.id.list_devices);
|
||||
mChnlAdapter = new ChannelAdapter(this);
|
||||
mListview.setAdapter(mChnlAdapter);
|
||||
|
||||
// 初始化数据
|
||||
loadChannelList();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (resultCode) { //resultCode为回传的标记
|
||||
case RESULT_OK:
|
||||
loadChannelList();
|
||||
mChnlAdapter.notifyDataSetChanged();
|
||||
mProgressDialog.setStart(getString(R.string.common_loading));
|
||||
//Toast.makeText(DevicelistActivity.this, "刷新完成", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadChannelList() {
|
||||
|
||||
mChannelInfoList = new ArrayList<ChannelInfo>();
|
||||
|
||||
|
||||
// 初始化数据
|
||||
Business.getInstance().getChannelList(new Handler() {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
mProgressDialog.setStop(); //关闭加载窗口
|
||||
Business.RetObject retObject = (RetObject) msg.obj;
|
||||
if (msg.what == 0) {
|
||||
mChannelInfoList.addAll((List<ChannelInfo>) retObject.resp);
|
||||
// mChannelInfoList = (List<ChannelInfo>) retObject.resp;
|
||||
if (mChannelInfoList != null && mChannelInfoList.size() > 0) {
|
||||
mChnlAdapter.notifyDataSetChanged();
|
||||
// addDevices();
|
||||
} else {
|
||||
Toast.makeText(DevicelistActivity.this, R.string.toast_device_no_devices, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(DevicelistActivity.this, retObject.mMsg, Toast.LENGTH_LONG).show();
|
||||
Logger.e(tag, retObject.mMsg);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//国内支持共享设备和授权设备
|
||||
if (!Business.getInstance().isOversea) {
|
||||
Business.getInstance().getSharedDeviceList(new Handler() {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
mProgressDialog.setStop(); //关闭加载窗口
|
||||
Business.RetObject retObject = (RetObject) msg.obj;
|
||||
if (msg.what == 0 && retObject.resp != null) {
|
||||
mChannelInfoList.addAll((List<ChannelInfo>) retObject.resp);
|
||||
// mChannelInfoList = (List<ChannelInfo>) retObject.resp;
|
||||
if (mChannelInfoList != null && mChannelInfoList.size() > 0) {
|
||||
mChnlAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
Toast.makeText(DevicelistActivity.this, R.string.devices_no_shared_device, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(DevicelistActivity.this, retObject.mMsg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
System.out.println("devices");
|
||||
Business.getInstance().getBeAuthDeviceList(new Handler() {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
mProgressDialog.setStop(); //关闭加载窗口
|
||||
Business.RetObject retObject = (RetObject) msg.obj;
|
||||
if (msg.what == 0 && retObject.resp != null) {
|
||||
mChannelInfoList.addAll((List<ChannelInfo>) retObject.resp);
|
||||
// mChannelInfoList = (List<ChannelInfo>) retObject.resp;
|
||||
if (mChannelInfoList != null && mChannelInfoList.size() > 0) {
|
||||
mChnlAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
Toast.makeText(DevicelistActivity.this, R.string.devices_no_authorized_device, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(DevicelistActivity.this, retObject.mMsg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// try {
|
||||
// Thread.sleep(50000);
|
||||
// } catch (InterruptedException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
// addDevices();
|
||||
}
|
||||
|
||||
private void addDevices() {
|
||||
for (int i = 0; i < mChannelInfoList.size(); i++) {
|
||||
StringBuilder devicesJson = new StringBuilder();
|
||||
if (mChannelInfoList.size() > 0) {
|
||||
ChannelInfo c = mChannelInfoList.get(i);
|
||||
devicesJson.append("[{\"Sn\":\"" + c.getDeviceCode() + "\",");
|
||||
devicesJson.append("\"Port\":554,");
|
||||
devicesJson.append("\"User\":\"\",");
|
||||
devicesJson.append("\"Pwd\":\"\",");
|
||||
devicesJson.append("\"Type\":1}]");
|
||||
|
||||
Business.getInstance().addDevices(devicesJson.toString(), new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
Toast.makeText(DevicelistActivity.this, (String) msg.obj, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class ViewHolder {
|
||||
/*TextView mChannelName;
|
||||
ImageView mDelete;
|
||||
RelativeLayout mBgDevice;
|
||||
ImageView mLiveVideo;
|
||||
ImageView mLocalVideo;
|
||||
ImageView mCloudVideo;
|
||||
ImageView mMessage;
|
||||
ImageView mSetting;
|
||||
LinearLayout mListShade;
|
||||
ChannelInfo mInfo;*/
|
||||
}
|
||||
|
||||
private class ChannelAdapter extends BaseAdapter {
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
public ChannelAdapter(Context context) {
|
||||
mInflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mChannelInfoList != null ? mChannelInfoList.size() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelInfo getItem(int position) {
|
||||
return mChannelInfoList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
private void unBindDevice(final ChannelInfo info) {
|
||||
Business.getInstance().unBindDevice(info.getDeviceCode(), new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
RetObject retObject = (RetObject) msg.obj;
|
||||
if (msg.what == 0) {
|
||||
Toast.makeText(getApplicationContext(), R.string.toast_device_delete_success, Toast.LENGTH_SHORT).show();
|
||||
mChannelInfoList.remove(info);
|
||||
mChnlAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), retObject.mMsg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
final ViewHolder holder;
|
||||
|
||||
/*if (convertView == null) {
|
||||
convertView = mInflater.inflate(R.layout.activity_device_list_item, null);
|
||||
holder = new ViewHolder();
|
||||
holder.mChannelName = (TextView) convertView.findViewById(R.id.list_channel_name);
|
||||
holder.mDelete = (ImageView) convertView.findViewById(R.id.list_device_delete);
|
||||
holder.mBgDevice = (RelativeLayout) convertView.findViewById(R.id.list_bg_device);
|
||||
holder.mLiveVideo = (ImageView) convertView.findViewById(R.id.list_device_livevideo);
|
||||
holder.mLocalVideo = (ImageView) convertView.findViewById(R.id.list_device_localvideo);
|
||||
holder.mCloudVideo = (ImageView) convertView.findViewById(R.id.list_device_cloudvideo);
|
||||
holder.mMessage = (ImageView) convertView.findViewById(R.id.list_device_message);
|
||||
holder.mSetting = (ImageView) convertView.findViewById(R.id.list_device_setting);
|
||||
holder.mListShade = (LinearLayout) convertView.findViewById(R.id.list_shade);
|
||||
|
||||
//设置监听
|
||||
holder.mDelete.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
DialogInterface.OnClickListener dialogOnclicListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case Dialog.BUTTON_POSITIVE:
|
||||
unBindDevice(holder.mInfo);
|
||||
break;
|
||||
case Dialog.BUTTON_NEGATIVE:
|
||||
break;
|
||||
case Dialog.BUTTON_NEUTRAL:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
//dialog参数设置
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(DevicelistActivity.this); //先得到构造器
|
||||
builder.setTitle(R.string.devices_delete_dialog_title); //设置标题
|
||||
builder.setMessage(R.string.devices_delete_dialog_message); //设置内容
|
||||
builder.setPositiveButton(R.string.dialog_positive, dialogOnclicListener);
|
||||
builder.setNegativeButton(R.string.dialog_negative, dialogOnclicListener);
|
||||
builder.create().show();
|
||||
}
|
||||
});
|
||||
|
||||
holder.mListShade.setVisibility(View.GONE);
|
||||
|
||||
holder.mLiveVideo.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
// 启动实时视频
|
||||
final EditText et = new EditText(DevicelistActivity.this);
|
||||
if (holder.mInfo.getEncryptMode() == 1 && holder.mInfo.getEncryptKey() == null) {
|
||||
new AlertDialog.Builder(DevicelistActivity.this).setTitle(R.string.alarm_message_keyinput_dialog_title)
|
||||
.setIcon(android.R.drawable.ic_dialog_info).setView(et)
|
||||
.setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// TODO Auto-generated method stub
|
||||
holder.mInfo.setEncryptKey(et.getText().toString());
|
||||
Intent intent = new Intent(DevicelistActivity.this, MediaPlayActivity.class);
|
||||
intent.putExtra("UUID", holder.mInfo.getUuid());
|
||||
intent.putExtra("TYPE", MediaPlayActivity.IS_VIDEO_ONLINE);
|
||||
intent.putExtra("MEDIA_TITLE", R.string.live_play_name);
|
||||
DevicelistActivity.this.startActivityForResult(intent, 0);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.dialog_negative, null).show();
|
||||
} else {
|
||||
Intent intent = new Intent(DevicelistActivity.this, MediaPlayActivity.class);
|
||||
intent.putExtra("UUID", holder.mInfo.getUuid());
|
||||
intent.putExtra("TYPE", MediaPlayActivity.IS_VIDEO_ONLINE);
|
||||
intent.putExtra("MEDIA_TITLE", R.string.live_play_name);
|
||||
DevicelistActivity.this.startActivityForResult(intent, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
holder.mLocalVideo.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
// 启动本地录像
|
||||
final EditText et = new EditText(DevicelistActivity.this);
|
||||
if (holder.mInfo.getEncryptMode() == 1 && holder.mInfo.getEncryptKey() == null) {
|
||||
new AlertDialog.Builder(DevicelistActivity.this).setTitle(R.string.alarm_message_keyinput_dialog_title)
|
||||
.setIcon(android.R.drawable.ic_dialog_info).setView(et)
|
||||
.setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// TODO Auto-generated method stub
|
||||
holder.mInfo.setEncryptKey(et.getText().toString());
|
||||
Intent intent = new Intent(DevicelistActivity.this, RecordListActivity.class);
|
||||
intent.putExtra("UUID", holder.mInfo.getUuid());
|
||||
intent.putExtra("TYPE", MediaPlayActivity.IS_VIDEO_REMOTE_RECORD);
|
||||
intent.putExtra("MEDIA_TITLE", R.string.local_records_name);
|
||||
DevicelistActivity.this.startActivity(intent);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.dialog_negative, null).show();
|
||||
} else {
|
||||
Intent intent = new Intent(DevicelistActivity.this, RecordListActivity.class);
|
||||
intent.putExtra("UUID", holder.mInfo.getUuid());
|
||||
intent.putExtra("TYPE", MediaPlayActivity.IS_VIDEO_REMOTE_RECORD);
|
||||
intent.putExtra("MEDIA_TITLE", R.string.local_records_name);
|
||||
DevicelistActivity.this.startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
holder.mCloudVideo.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
// 启动云录像
|
||||
final EditText et = new EditText(DevicelistActivity.this);
|
||||
if (holder.mInfo.getEncryptMode() == 1 && holder.mInfo.getEncryptKey() == null) {
|
||||
new AlertDialog.Builder(DevicelistActivity.this).setTitle(R.string.alarm_message_keyinput_dialog_title)
|
||||
.setIcon(android.R.drawable.ic_dialog_info).setView(et)
|
||||
.setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// TODO Auto-generated method stub
|
||||
holder.mInfo.setEncryptKey(et.getText().toString());
|
||||
Intent intent = new Intent(DevicelistActivity.this, RecordListActivity.class);
|
||||
intent.putExtra("UUID", holder.mInfo.getUuid());
|
||||
intent.putExtra("MEDIA_TITLE", R.string.cloud_records_name);
|
||||
intent.putExtra("TYPE", MediaPlayActivity.IS_VIDEO_REMOTE_CLOUD_RECORD);
|
||||
DevicelistActivity.this.startActivity(intent);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.dialog_negative, null).show();
|
||||
} else {
|
||||
Intent intent = new Intent(DevicelistActivity.this, RecordListActivity.class);
|
||||
intent.putExtra("UUID", holder.mInfo.getUuid());
|
||||
intent.putExtra("MEDIA_TITLE", R.string.cloud_records_name);
|
||||
intent.putExtra("TYPE", MediaPlayActivity.IS_VIDEO_REMOTE_CLOUD_RECORD);
|
||||
DevicelistActivity.this.startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
holder.mMessage.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
// 启动报警图片
|
||||
final EditText et = new EditText(DevicelistActivity.this);
|
||||
if (holder.mInfo.getEncryptMode() == 1 && holder.mInfo.getEncryptKey() == null) {
|
||||
new AlertDialog.Builder(DevicelistActivity.this).setTitle(R.string.alarm_message_keyinput_dialog_title)
|
||||
.setIcon(android.R.drawable.ic_dialog_info).setView(et)
|
||||
.setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// TODO Auto-generated method stub
|
||||
holder.mInfo.setEncryptKey(et.getText().toString());
|
||||
Intent intent = new Intent(DevicelistActivity.this, AlarmMessageActivity.class);
|
||||
intent.putExtra("sn", holder.mInfo.getDeviceCode());
|
||||
intent.putExtra("UUID", holder.mInfo.getUuid());
|
||||
intent.putExtra("index", holder.mInfo.getIndex());
|
||||
DevicelistActivity.this.startActivity(intent);
|
||||
System.out.println("DeviceCode" + holder.mInfo.getDeviceCode());
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.dialog_negative, null).show();
|
||||
} else {
|
||||
Intent intent = new Intent(DevicelistActivity.this, AlarmMessageActivity.class);
|
||||
intent.putExtra("sn", holder.mInfo.getDeviceCode());
|
||||
intent.putExtra("UUID", holder.mInfo.getUuid());
|
||||
intent.putExtra("index", holder.mInfo.getIndex());
|
||||
DevicelistActivity.this.startActivity(intent);
|
||||
System.out.println("DeviceCode" + holder.mInfo.getDeviceCode());
|
||||
}
|
||||
}
|
||||
});
|
||||
//设备操作
|
||||
holder.mSetting.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
// 启动设备管理
|
||||
Intent intent = new Intent(DevicelistActivity.this, DeviceSetActivity.class);
|
||||
|
||||
intent.putExtra("UUID", holder.mInfo.getUuid());
|
||||
intent.putExtra("alarmPlanStatus", holder.mInfo.getAlarmStatus());
|
||||
intent.putExtra("cloudMealStatus", holder.mInfo.getCloudMealStates());
|
||||
|
||||
|
||||
DevicelistActivity.this.startActivity(intent);
|
||||
System.out.println("DeviceCode" + holder.mInfo.getDeviceCode());
|
||||
}
|
||||
});
|
||||
//屏蔽监听
|
||||
holder.mListShade.setOnTouchListener(new OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionevent) {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
//修改数据信息(含加密标识符)
|
||||
holder.mInfo = getItem(position);
|
||||
//Log.d(tag, "index : " + position);
|
||||
// holder.mChannelName.setText(holder.mInfo.getDeviceCode() + "-" + holder.mInfo.getIndex());
|
||||
if (holder.mInfo.getEncryptMode() == 1) {
|
||||
holder.mChannelName.setText(holder.mInfo.getName() + " - Encrypt");
|
||||
} else {
|
||||
holder.mChannelName.setText(holder.mInfo.getName());
|
||||
}
|
||||
|
||||
//加载背景图片
|
||||
holder.mBgDevice.setBackgroundResource(R.drawable.list_bg_device);
|
||||
if (holder.mInfo.getBackgroudImgURL() != null && holder.mInfo.getBackgroudImgURL().length() > 0) {
|
||||
//下载 注:由于有些请求的图片是经过加密处理的,所以需要使用带有解密功能的接口,默认密码为设备序列号
|
||||
ImageHelper.loadCacheImage(holder.mInfo.getBackgroudImgURL(), holder.mInfo.getDeviceCode(), holder.mInfo.getDeviceCode(), new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
// TODO Auto-generated method stub
|
||||
super.handleMessage(msg);
|
||||
if (holder.mInfo.getBackgroudImgURL().hashCode() == msg.what && msg.obj != null) {
|
||||
holder.mBgDevice.setBackgroundDrawable((Drawable) msg.obj);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//"在线" : "离线"
|
||||
if (holder.mInfo.getState() == ChannelInfo.ChannelState.Online) {
|
||||
holder.mListShade.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.mListShade.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
//是否自定义加密,效率不高
|
||||
if (holder.mInfo.getEncryptMode() == 1 && holder.mInfo.getEncryptKey() == null) {
|
||||
holder.mLiveVideo.setAlpha(128);
|
||||
holder.mLocalVideo.setAlpha(128);
|
||||
holder.mCloudVideo.setAlpha(128);
|
||||
holder.mMessage.setAlpha(128);
|
||||
} else {
|
||||
holder.mLiveVideo.setAlpha(255);
|
||||
holder.mLocalVideo.setAlpha(255);
|
||||
holder.mCloudVideo.setAlpha(255);
|
||||
holder.mMessage.setAlpha(255);
|
||||
}*/
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,475 @@
|
|||
package com.lechange.demo.localvideo;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import com.gavin.com.library.BuildConfig;
|
||||
import com.gavin.com.library.ClickInfo;
|
||||
import com.gavin.com.library.listener.OnGroupClickListener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/3/15.
|
||||
*/
|
||||
|
||||
public abstract class BaseDecoration extends RecyclerView.ItemDecoration {
|
||||
// TODO: 2018/4/13 加载更新后闪动
|
||||
|
||||
protected OnGroupClickListener mOnGroupClickListener;
|
||||
/**
|
||||
* 记录每个头部和悬浮头部的坐标信息【用于点击事件】
|
||||
* 位置由子类添加
|
||||
*/
|
||||
protected HashMap<Integer, ClickInfo> stickyHeaderPosArray = new HashMap<>();
|
||||
/**
|
||||
* group背景色,默认透明
|
||||
*/
|
||||
@ColorInt
|
||||
int mGroupBackground = Color.parseColor("#48BDFF");
|
||||
/**
|
||||
* 悬浮栏高度
|
||||
*/
|
||||
int mGroupHeight = 120;
|
||||
/**
|
||||
* 分割线颜色,默认灰色
|
||||
*/
|
||||
@ColorInt
|
||||
int mDivideColor = Color.parseColor("#CCCCCC");
|
||||
/**
|
||||
* 分割线宽度
|
||||
*/
|
||||
int mDivideHeight = 0;
|
||||
/**
|
||||
* RecyclerView头部数量
|
||||
* 最小为0
|
||||
*/
|
||||
int mHeaderCount;
|
||||
Paint mDividePaint;
|
||||
/**
|
||||
* 缓存分组第一个item的position
|
||||
*/
|
||||
private SparseIntArray firstInGroupCash = new SparseIntArray(100);
|
||||
/**
|
||||
* down事件在顶部悬浮栏中
|
||||
*/
|
||||
private boolean mDownInHeader;
|
||||
private GestureDetector gestureDetector;
|
||||
private GestureDetector.OnGestureListener gestureListener = new GestureDetector.OnGestureListener() {
|
||||
@Override
|
||||
public boolean onDown(MotionEvent e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowPress(MotionEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
return onTouchEvent(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public BaseDecoration() {
|
||||
mDividePaint = new Paint();
|
||||
mDividePaint.setColor(mDivideColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置点击事件
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
protected void setOnGroupClickListener(OnGroupClickListener listener) {
|
||||
this.mOnGroupClickListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分组名
|
||||
*
|
||||
* @param position position
|
||||
* @return group
|
||||
*/
|
||||
abstract String getGroupName(int position);
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
||||
super.getItemOffsets(outRect, view, parent, state);
|
||||
int position = parent.getChildAdapterPosition(view);
|
||||
RecyclerView.LayoutManager manager = parent.getLayoutManager();
|
||||
if (manager instanceof GridLayoutManager) {
|
||||
//网格布局
|
||||
int spanCount = ((GridLayoutManager) manager).getSpanCount();
|
||||
if (!isHeader(position)) {
|
||||
if (isFirstLineInGroup(position, spanCount)) {
|
||||
//为悬浮view预留空间
|
||||
outRect.top = mGroupHeight;
|
||||
} else {
|
||||
//为分割线预留空间
|
||||
outRect.top = mDivideHeight;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//其他的默认为线性布局
|
||||
//只有是同一组的第一个才显示悬浮栏
|
||||
if (!isHeader(position)) {
|
||||
if (isFirstInGroup(position)) {
|
||||
//为悬浮view预留空间
|
||||
outRect.top = mGroupHeight;
|
||||
} else {
|
||||
//为分割线预留空间
|
||||
outRect.top = mDivideHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是不是组中的第一个位置
|
||||
* 根据前一个组名,判断当前是否为新的组
|
||||
* 当前为groupId为null时,则与上一个为同一组
|
||||
*/
|
||||
protected boolean isFirstInGroup(int position) {
|
||||
int realPosition = position - mHeaderCount;
|
||||
if (realPosition < 0) {
|
||||
//小于header数量,不是第一个
|
||||
return false;
|
||||
} else if (realPosition == 0) {
|
||||
//等于header数量,为第一个
|
||||
return true;
|
||||
}
|
||||
String preGroupId;
|
||||
if (realPosition <= 0) {
|
||||
preGroupId = null;
|
||||
} else {
|
||||
preGroupId = getGroupName(realPosition - 1);
|
||||
}
|
||||
String curGroupId = getGroupName(realPosition);
|
||||
if (curGroupId == null) {
|
||||
return false;
|
||||
}
|
||||
return !TextUtils.equals(preGroupId, curGroupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否在RecyclerView处于第一个(header部分不算)
|
||||
*
|
||||
* @param position 总的position
|
||||
* @param index RecyclerView中的Index
|
||||
* @return
|
||||
*/
|
||||
protected boolean isFirstInRecyclerView(int position, int index) {
|
||||
return position >= mHeaderCount && index == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为Header
|
||||
*
|
||||
* @param position
|
||||
* @return
|
||||
*/
|
||||
protected boolean isHeader(int position) {
|
||||
return position < mHeaderCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是不是新组的第一行(GridLayoutManager使用)
|
||||
* 利用当前行的第一个对比前一个组名,判断当前是否为新组的第一样
|
||||
*/
|
||||
protected boolean isFirstLineInGroup(int position, int spanCount) {
|
||||
int realPosition = position - mHeaderCount;
|
||||
if (realPosition < 0) {
|
||||
//小于header数量,不是第一个
|
||||
return false;
|
||||
} else if (realPosition == 0) {
|
||||
return true;
|
||||
}
|
||||
if (position <= 0) {
|
||||
return true;
|
||||
} else {
|
||||
int posFirstInGroup = getFirstInGroupWithCash(position);
|
||||
if (position - posFirstInGroup < spanCount) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 网格布局需要调用
|
||||
*
|
||||
* @param recyclerView recyclerView
|
||||
* @param gridLayoutManager gridLayoutManager
|
||||
*/
|
||||
public void resetSpan(RecyclerView recyclerView, GridLayoutManager gridLayoutManager) {
|
||||
if (recyclerView == null) {
|
||||
throw new NullPointerException("recyclerView not allow null");
|
||||
}
|
||||
if (gridLayoutManager == null) {
|
||||
throw new NullPointerException("gridLayoutManager not allow null");
|
||||
}
|
||||
final int spanCount = gridLayoutManager.getSpanCount();
|
||||
//相当于weight
|
||||
GridLayoutManager.SpanSizeLookup lookup = new GridLayoutManager.SpanSizeLookup() {
|
||||
@Override
|
||||
public int getSpanSize(int position) {
|
||||
int span;
|
||||
int realPosition = position - mHeaderCount;
|
||||
if (realPosition < 0) {
|
||||
//小于header数量
|
||||
span = spanCount;
|
||||
} else {
|
||||
String curGroupId = getGroupName(position);
|
||||
String nextGroupId;
|
||||
try {
|
||||
//防止外面没判断,导致越界
|
||||
nextGroupId = getGroupName(position + 1);
|
||||
} catch (Exception e) {
|
||||
nextGroupId = curGroupId;
|
||||
}
|
||||
if (!TextUtils.equals(curGroupId, nextGroupId)) {
|
||||
//为本行的最后一个
|
||||
int posFirstInGroup = getFirstInGroupWithCash(position);
|
||||
span = spanCount - (position - posFirstInGroup) % spanCount;
|
||||
} else {
|
||||
span = 1;
|
||||
}
|
||||
}
|
||||
return span;
|
||||
}
|
||||
};
|
||||
gridLayoutManager.setSpanSizeLookup(lookup);
|
||||
}
|
||||
|
||||
/**
|
||||
* RecyclerView onInterceptEvent中down事件调用,用于处理点击穿透问题
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
public void onEventDown(MotionEvent event) {
|
||||
if (event == null) {
|
||||
mDownInHeader = false;
|
||||
return;
|
||||
}
|
||||
mDownInHeader = event.getY() > 0 && event.getY() < mGroupHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* RecyclerView onInterceptEvent中up事件调用,用于处理点击穿透问题
|
||||
*
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
public boolean onEventUp(MotionEvent event) {
|
||||
if (mDownInHeader) {
|
||||
float y = event.getY();
|
||||
boolean isInHeader = y > 0 && y < mGroupHeight;
|
||||
if (isInHeader) {
|
||||
return onTouchEvent(event);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到当前分组第一个item的position
|
||||
*
|
||||
* @param position position
|
||||
*/
|
||||
protected int getFirstInGroupWithCash(int position) {
|
||||
if (firstInGroupCash.get(position) == 0) {
|
||||
int firstPosition = getFirstInGroup(position);
|
||||
firstPosition = firstPosition > 0 ? firstPosition - mHeaderCount : firstPosition;
|
||||
firstInGroupCash.put(position, firstPosition);
|
||||
return firstPosition;
|
||||
} else {
|
||||
return firstInGroupCash.get(position);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到当前分组第一个item的position
|
||||
*
|
||||
* @param position position
|
||||
*/
|
||||
private int getFirstInGroup(int position) {
|
||||
if (position <= 0) {
|
||||
return 0;
|
||||
} else {
|
||||
if (isFirstInGroup(position)) {
|
||||
return position;
|
||||
} else {
|
||||
return getFirstInGroup(position - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断自己是否为group的最后一行
|
||||
*
|
||||
* @param recyclerView recyclerView
|
||||
* @param position position
|
||||
* @return
|
||||
*/
|
||||
protected boolean isLastLineInGroup(RecyclerView recyclerView, int position) {
|
||||
int realPosition = position - mHeaderCount;
|
||||
if (realPosition < 0) {
|
||||
return true;
|
||||
} else {
|
||||
String curGroupName = getGroupName(realPosition);
|
||||
String nextGroupName;
|
||||
RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
|
||||
//默认往下查找的数量
|
||||
int findCount = 1;
|
||||
if (manager instanceof GridLayoutManager) {
|
||||
int spanCount = ((GridLayoutManager) manager).getSpanCount();
|
||||
int firstPositionInGroup = getFirstInGroupWithCash(realPosition);
|
||||
findCount = spanCount - (realPosition - firstPositionInGroup) % spanCount;
|
||||
}
|
||||
try {
|
||||
nextGroupName = getGroupName(realPosition + findCount);
|
||||
} catch (Exception e) {
|
||||
nextGroupName = curGroupName;
|
||||
}
|
||||
if (nextGroupName == null) {
|
||||
return false;
|
||||
}
|
||||
return !TextUtils.equals(curGroupName, nextGroupName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
super.onDrawOver(c, parent, state);
|
||||
//点击事件处理
|
||||
if (gestureDetector == null) {
|
||||
gestureDetector = new GestureDetector(parent.getContext(), gestureListener);
|
||||
parent.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
return gestureDetector.onTouchEvent(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
stickyHeaderPosArray.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击事件调用
|
||||
*
|
||||
* @param position position
|
||||
*/
|
||||
private void onGroupClick(int position, int viewId) {
|
||||
if (mOnGroupClickListener != null) {
|
||||
mOnGroupClickListener.onClick(position, viewId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对touch事件处理,找到点击事件
|
||||
*
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
private boolean onTouchEvent(MotionEvent e) {
|
||||
for (Map.Entry<Integer, ClickInfo> entry : stickyHeaderPosArray.entrySet()) {
|
||||
|
||||
ClickInfo value = stickyHeaderPosArray.get(entry.getKey());
|
||||
float y = e.getY();
|
||||
float x = e.getX();
|
||||
if (value.mBottom - mGroupHeight <= y && y <= value.mBottom) {
|
||||
//如果点击到分组头
|
||||
if (value.mDetailInfoList == null || value.mDetailInfoList.size() == 0) {
|
||||
//没有子View的点击事件
|
||||
onGroupClick(entry.getKey(), value.mGroupId);
|
||||
} else {
|
||||
List<ClickInfo.DetailInfo> list = value.mDetailInfoList;
|
||||
boolean isChildViewClicked = false;
|
||||
for (ClickInfo.DetailInfo detailInfo : list) {
|
||||
if (detailInfo.top <= y && y <= detailInfo.bottom
|
||||
&& detailInfo.left <= x && detailInfo.right >= x) {
|
||||
//当前view被点击
|
||||
onGroupClick(entry.getKey(), detailInfo.id);
|
||||
isChildViewClicked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isChildViewClicked) {
|
||||
//点击范围不在带有id的子view中,则表示整个groupView被点击
|
||||
onGroupClick(entry.getKey(), value.mGroupId);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制分割线
|
||||
*
|
||||
* @param c
|
||||
* @param parent
|
||||
* @param childView
|
||||
* @param position
|
||||
* @param left
|
||||
* @param right
|
||||
*/
|
||||
protected void drawDivide(Canvas c, RecyclerView parent, View childView, int position, int left, int right) {
|
||||
if (mDivideHeight != 0 && !isHeader(position)) {
|
||||
RecyclerView.LayoutManager manager = parent.getLayoutManager();
|
||||
if (manager instanceof GridLayoutManager) {
|
||||
int spanCount = ((GridLayoutManager) manager).getSpanCount();
|
||||
if (!isFirstLineInGroup(position, spanCount)) {
|
||||
float bottom = childView.getTop() + parent.getPaddingTop();
|
||||
//高度小于顶部悬浮栏时,跳过绘制
|
||||
if (bottom >= mGroupHeight) {
|
||||
c.drawRect(left, bottom - mDivideHeight, right, bottom, mDividePaint);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
float bottom = childView.getTop();
|
||||
//高度小于顶部悬浮栏时,跳过绘制
|
||||
if (bottom >= mGroupHeight) {
|
||||
c.drawRect(left, bottom - mDivideHeight, right, bottom, mDividePaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void log(String content) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.i("StickDecoration", content);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.lechange.demo.localvideo;
|
||||
|
||||
/**
|
||||
* Created by gavin
|
||||
* Created date 17/5/24
|
||||
* Created log 市
|
||||
*/
|
||||
|
||||
public class City {
|
||||
/**
|
||||
* 城市名
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 所属省份
|
||||
*/
|
||||
private String province;
|
||||
/**
|
||||
* 省份icon
|
||||
*/
|
||||
private int icon;
|
||||
|
||||
private boolean expanded = true;
|
||||
|
||||
public City(String name, String province, int icon) {
|
||||
this.name = name;
|
||||
this.province = province;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getProvince() {
|
||||
return province;
|
||||
}
|
||||
|
||||
public void setProvince(String province) {
|
||||
this.province = province;
|
||||
}
|
||||
|
||||
public int getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(int icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public boolean isExpanded() {
|
||||
return expanded;
|
||||
}
|
||||
|
||||
public void setExpanded(boolean expanded) {
|
||||
this.expanded = expanded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "City{" +
|
||||
"name='" + name + '\'' +
|
||||
", province='" + province + '\'' +
|
||||
", icon=" + icon +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package com.lechange.demo.localvideo;
|
||||
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by gavin
|
||||
* Created date 17/5/31
|
||||
* Created log
|
||||
*/
|
||||
|
||||
public class CityUtil {
|
||||
|
||||
private static final String[] CITYS = {"福建省", "安徽省", "浙江省", "江苏省"};
|
||||
|
||||
/**
|
||||
* 获取城市名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List<City> getCityList() {
|
||||
List<City> dataList = new ArrayList<>();
|
||||
final String FU_JIAN = CITYS[0];
|
||||
final int FU_JIAN_ICON = R.mipmap.city1;
|
||||
dataList.add(new City("福州", FU_JIAN, FU_JIAN_ICON));
|
||||
dataList.add(new City("厦门", FU_JIAN, FU_JIAN_ICON));
|
||||
dataList.add(new City("泉州", FU_JIAN, FU_JIAN_ICON));
|
||||
dataList.add(new City("宁德", FU_JIAN, FU_JIAN_ICON));
|
||||
dataList.add(new City("漳州", FU_JIAN, FU_JIAN_ICON));
|
||||
final String AN_HUI = CITYS[1];
|
||||
final int AN_HUI_ICON = R.mipmap.city2;
|
||||
dataList.add(new City("合肥", AN_HUI, AN_HUI_ICON));
|
||||
dataList.add(new City("芜湖", AN_HUI, AN_HUI_ICON));
|
||||
dataList.add(new City("蚌埠", AN_HUI, AN_HUI_ICON));
|
||||
final String ZHE_JIANG = CITYS[2];
|
||||
final int ZHE_JIANG_ICON = R.mipmap.city3;
|
||||
dataList.add(new City("杭州", ZHE_JIANG, ZHE_JIANG_ICON));
|
||||
dataList.add(new City("宁波", ZHE_JIANG, ZHE_JIANG_ICON));
|
||||
dataList.add(new City("温州", ZHE_JIANG, ZHE_JIANG_ICON));
|
||||
dataList.add(new City("嘉兴", ZHE_JIANG, ZHE_JIANG_ICON));
|
||||
dataList.add(new City("绍兴", ZHE_JIANG, ZHE_JIANG_ICON));
|
||||
dataList.add(new City("金华", ZHE_JIANG, ZHE_JIANG_ICON));
|
||||
dataList.add(new City("湖州", ZHE_JIANG, ZHE_JIANG_ICON));
|
||||
dataList.add(new City("舟山", ZHE_JIANG, ZHE_JIANG_ICON));
|
||||
final String JIANG_SU = CITYS[3];
|
||||
final int JIANG_SU_ICOM = R.mipmap.city4;
|
||||
dataList.add(new City("南京", JIANG_SU, JIANG_SU_ICOM));
|
||||
return dataList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取城市名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List<City> getRandomCityList() {
|
||||
List<City> dataList = new ArrayList<>();
|
||||
Random random = new Random();
|
||||
int provinceSize = random.nextInt(5) + 3;
|
||||
for (int i = 0; i < provinceSize; i++) {
|
||||
String province = getRandomCityName();
|
||||
int citySize = random.nextInt(3) + 1;
|
||||
for (int j = 0; j < citySize; j++) {
|
||||
dataList.add(new City(province + " : city " + j, province, R.mipmap.city4));
|
||||
}
|
||||
}
|
||||
return dataList;
|
||||
}
|
||||
|
||||
private static String getRandomCityName() {
|
||||
Random random = new Random();
|
||||
return CITYS[random.nextInt(4)];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.lechange.demo.localvideo;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.gavin.com.library.BaseDecoration;
|
||||
|
||||
/**
|
||||
* Created by gavin
|
||||
* date 2018/8/26
|
||||
*/
|
||||
public class MyRecyclerView extends RecyclerView {
|
||||
|
||||
private BaseDecoration mDecoration;
|
||||
|
||||
public MyRecyclerView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public MyRecyclerView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public MyRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItemDecoration(ItemDecoration decor) {
|
||||
if (decor != null && decor instanceof BaseDecoration) {
|
||||
mDecoration = (BaseDecoration) decor;
|
||||
}
|
||||
super.addItemDecoration(decor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent e) {
|
||||
if (mDecoration != null) {
|
||||
switch (e.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
mDecoration.onEventDown(e);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (mDecoration.onEventUp(e)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
return super.onInterceptTouchEvent(e);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,331 @@
|
|||
package com.lechange.demo.localvideo;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.gavin.com.library.ClickInfo;
|
||||
import com.gavin.com.library.cache.CacheUtil;
|
||||
import com.gavin.com.library.listener.OnGroupClickListener;
|
||||
import com.gavin.com.library.listener.PowerGroupListener;
|
||||
import com.gavin.com.library.util.ViewUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/3/15.
|
||||
*/
|
||||
|
||||
public class PowerfulStickyDecoration extends BaseDecoration {
|
||||
|
||||
private Paint mGroutPaint;
|
||||
|
||||
/**
|
||||
* 缓存图片
|
||||
*/
|
||||
private CacheUtil<Bitmap> mBitmapCache = new CacheUtil<>();
|
||||
|
||||
/**
|
||||
* 缓存View
|
||||
*/
|
||||
private CacheUtil<View> mHeadViewCache = new CacheUtil<>();
|
||||
|
||||
private PowerGroupListener mGroupListener;
|
||||
|
||||
private PowerfulStickyDecoration(PowerGroupListener groupListener) {
|
||||
super();
|
||||
this.mGroupListener = groupListener;
|
||||
//设置悬浮栏的画笔---mGroutPaint
|
||||
mGroutPaint = new Paint();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
super.onDrawOver(c, parent, state);
|
||||
//绘制
|
||||
int itemCount = state.getItemCount();
|
||||
int childCount = parent.getChildCount();
|
||||
int left = parent.getPaddingLeft();
|
||||
int right = parent.getWidth() - parent.getPaddingRight();
|
||||
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
View childView = parent.getChildAt(i);
|
||||
int position = parent.getChildAdapterPosition(childView);
|
||||
if (isFirstInGroup(position) || isFirstInRecyclerView(position, i)) {
|
||||
int viewBottom = childView.getBottom();
|
||||
//top 决定当前顶部第一个悬浮Group的位置
|
||||
int bottom = Math.max(mGroupHeight, childView.getTop() + parent.getPaddingTop());
|
||||
if (position + 1 < itemCount) {
|
||||
//下一组的第一个View接近头部
|
||||
if (isLastLineInGroup(parent, position) && viewBottom < bottom) {
|
||||
bottom = viewBottom;
|
||||
}
|
||||
}
|
||||
drawDecoration(c, position, left, right, bottom);
|
||||
} else {
|
||||
//绘制分割线
|
||||
drawDivide(c, parent, childView, position, left, right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制悬浮框
|
||||
*
|
||||
* @param c Canvas
|
||||
* @param position position
|
||||
* @param left left
|
||||
* @param right right
|
||||
* @param bottom bottom
|
||||
*/
|
||||
private void drawDecoration(Canvas c, int position, int left, int right, int bottom) {
|
||||
c.drawRect(left, bottom - mGroupHeight, right, bottom, mGroutPaint);
|
||||
//根据position获取View
|
||||
View groupView;
|
||||
int firstPositionInGroup = getFirstInGroupWithCash(position);
|
||||
if (mHeadViewCache.get(firstPositionInGroup) == null) {
|
||||
groupView = getGroupView(firstPositionInGroup);
|
||||
if (groupView == null) {
|
||||
return;
|
||||
}
|
||||
measureAndLayoutView(groupView, left, right);
|
||||
mHeadViewCache.put(firstPositionInGroup, groupView);
|
||||
} else {
|
||||
groupView = mHeadViewCache.get(firstPositionInGroup);
|
||||
}
|
||||
Bitmap bitmap;
|
||||
if (mBitmapCache.get(firstPositionInGroup) != null) {
|
||||
bitmap = mBitmapCache.get(firstPositionInGroup);
|
||||
} else {
|
||||
bitmap = Bitmap.createBitmap(groupView.getDrawingCache());
|
||||
mBitmapCache.put(firstPositionInGroup, bitmap);
|
||||
}
|
||||
c.drawBitmap(bitmap, left, bottom - mGroupHeight, null);
|
||||
if (mOnGroupClickListener != null) {
|
||||
setClickInfo(groupView, left, bottom, position);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对view进行测量和布局
|
||||
*
|
||||
* @param groupView groupView
|
||||
* @param left left
|
||||
* @param right right
|
||||
*/
|
||||
private void measureAndLayoutView(View groupView, int left, int right) {
|
||||
groupView.setDrawingCacheEnabled(true);
|
||||
//手动对view进行测量,指定groupView的高度、宽度
|
||||
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(right, mGroupHeight);
|
||||
groupView.setLayoutParams(layoutParams);
|
||||
groupView.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(right, View.MeasureSpec.EXACTLY),
|
||||
View.MeasureSpec.makeMeasureSpec(mGroupHeight, View.MeasureSpec.EXACTLY));
|
||||
groupView.layout(left, 0 - mGroupHeight, right, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击的位置信息
|
||||
*
|
||||
* @param groupView
|
||||
* @param parentBottom
|
||||
* @param position
|
||||
*/
|
||||
private void setClickInfo(View groupView, int parentLeft, int parentBottom, int position) {
|
||||
int parentTop = parentBottom - mGroupHeight;
|
||||
List<ClickInfo.DetailInfo> list = new ArrayList<>();
|
||||
List<View> viewList = ViewUtil.getChildViewWithId(groupView);
|
||||
for (View view : viewList) {
|
||||
int top = view.getTop() + parentTop;
|
||||
int bottom = view.getBottom() + parentTop;
|
||||
int left = view.getLeft() + parentLeft;
|
||||
int right = view.getRight() + parentLeft;
|
||||
list.add(new ClickInfo.DetailInfo(view.getId(), left, right, top, bottom));
|
||||
}
|
||||
ClickInfo clickInfo = new ClickInfo(parentBottom, list);
|
||||
clickInfo.mGroupId = groupView.getId();
|
||||
stickyHeaderPosArray.put(position, clickInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组名
|
||||
*
|
||||
* @param position position
|
||||
* @return 组名
|
||||
*/
|
||||
@Override
|
||||
String getGroupName(int position) {
|
||||
if (mGroupListener != null) {
|
||||
return mGroupListener.getGroupName(position);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组View
|
||||
*
|
||||
* @param position position
|
||||
* @return 组名
|
||||
*/
|
||||
private View getGroupView(int position) {
|
||||
if (mGroupListener != null) {
|
||||
return mGroupListener.getGroupView(position);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否使用缓存
|
||||
*
|
||||
* @param b b
|
||||
*/
|
||||
public void setCacheEnable(boolean b) {
|
||||
mHeadViewCache.isCacheable(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
public void clearCache() {
|
||||
mHeadViewCache.clean();
|
||||
mBitmapCache.clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知重新绘制
|
||||
* 使用场景:网络图片加载后调用
|
||||
*
|
||||
* @param recyclerView recyclerView
|
||||
* @param position position
|
||||
*/
|
||||
public void notifyRedraw(RecyclerView recyclerView, View viewGroup, int position) {
|
||||
viewGroup.setDrawingCacheEnabled(false);
|
||||
int firstPositionInGroup = getFirstInGroupWithCash(position);
|
||||
mBitmapCache.remove(firstPositionInGroup);
|
||||
mHeadViewCache.remove(firstPositionInGroup);
|
||||
int left = recyclerView.getPaddingLeft();
|
||||
int right = recyclerView.getWidth() - recyclerView.getPaddingRight();
|
||||
measureAndLayoutView(viewGroup, left, right);
|
||||
mHeadViewCache.put(firstPositionInGroup, viewGroup);
|
||||
recyclerView.invalidate();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
PowerfulStickyDecoration mDecoration;
|
||||
|
||||
private Builder(PowerGroupListener listener) {
|
||||
mDecoration = new PowerfulStickyDecoration(listener);
|
||||
}
|
||||
|
||||
public static PowerfulStickyDecoration.Builder init(PowerGroupListener listener) {
|
||||
return new PowerfulStickyDecoration.Builder(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置Group高度
|
||||
*
|
||||
* @param groutHeight 高度
|
||||
* @return this
|
||||
*/
|
||||
public PowerfulStickyDecoration.Builder setGroupHeight(int groutHeight) {
|
||||
mDecoration.mGroupHeight = groutHeight;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置Group背景
|
||||
*
|
||||
* @param background 背景色
|
||||
*/
|
||||
public PowerfulStickyDecoration.Builder setGroupBackground(@ColorInt int background) {
|
||||
mDecoration.mGroupBackground = background;
|
||||
mDecoration.mGroutPaint.setColor(mDecoration.mGroupBackground);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置分割线高度
|
||||
*
|
||||
* @param height 高度
|
||||
* @return this
|
||||
*/
|
||||
public PowerfulStickyDecoration.Builder setDivideHeight(int height) {
|
||||
mDecoration.mDivideHeight = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置分割线颜色
|
||||
*
|
||||
* @param color color
|
||||
* @return this
|
||||
*/
|
||||
public PowerfulStickyDecoration.Builder setDivideColor(@ColorInt int color) {
|
||||
mDecoration.mDivideColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置点击事件
|
||||
*
|
||||
* @param listener 点击事件
|
||||
* @return this
|
||||
*/
|
||||
public PowerfulStickyDecoration.Builder setOnClickListener(OnGroupClickListener listener) {
|
||||
mDecoration.setOnGroupClickListener(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置span
|
||||
*
|
||||
* @param recyclerView recyclerView
|
||||
* @param gridLayoutManager gridLayoutManager
|
||||
* @return this
|
||||
*/
|
||||
public PowerfulStickyDecoration.Builder resetSpan(RecyclerView recyclerView, GridLayoutManager gridLayoutManager) {
|
||||
mDecoration.resetSpan(recyclerView, gridLayoutManager);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否使用缓存
|
||||
*
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
public PowerfulStickyDecoration.Builder setCacheEnable(boolean b) {
|
||||
mDecoration.setCacheEnable(b);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置头部数量
|
||||
* 用于顶部Header不需要设置悬浮的情况(仅LinearLayoutManager)
|
||||
*
|
||||
* @param headerCount
|
||||
* @return
|
||||
*/
|
||||
public PowerfulStickyDecoration.Builder setHeaderCount(int headerCount) {
|
||||
if (headerCount >= 0) {
|
||||
mDecoration.mHeaderCount = headerCount;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public PowerfulStickyDecoration build() {
|
||||
return mDecoration;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,883 @@
|
|||
package com.lechange.demo.localvideo;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gavin.com.library.listener.OnGroupClickListener;
|
||||
import com.gavin.com.library.listener.PowerGroupListener;
|
||||
import com.lechange.common.log.Logger;
|
||||
import com.lechange.demo.business.Business;
|
||||
import com.lechange.demo.business.Business.CloudStorageCode;
|
||||
import com.lechange.demo.business.Business.LocalDownloadCode;
|
||||
import com.lechange.demo.business.entity.RecordInfo;
|
||||
import com.lechange.demo.business.util.ImageHelper;
|
||||
import com.lechange.demo.business.util.MediaPlayHelper;
|
||||
import com.lechange.demo.business.util.TaskPoolHelper;
|
||||
import com.lechange.demo.business.util.TimeHelper;
|
||||
import com.lechange.demo.common.DatePicker;
|
||||
import com.lechange.demo.common.DatePicker.OnTimeClickListener;
|
||||
import com.lechange.demo.common.ProgressDialog;
|
||||
import com.lechange.demo.localvideo.calendar.CalendarPopipWindow;
|
||||
import com.lechange.demo.mediaplay.MediaPlayActivity;
|
||||
import com.lechange.opensdk.listener.LCOpenSDK_DownloadListener;
|
||||
import com.lechange.opensdk.media.LCOpenSDK_Download;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.activity.BaseActivity;
|
||||
import com.yonsz.z1.listener.OnTitleItemClickListener;
|
||||
import com.yonsz.z1.utils.DateTimeUitl;
|
||||
import com.yonsz.z1.utils.DensityUtil;
|
||||
import com.yonsz.z1.view.TitleView;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class RecordListActivity extends BaseActivity {
|
||||
private final String tag = "RecordList";
|
||||
private TitleView mTitleView;
|
||||
private RecyclerView mRv;
|
||||
private ImageView iv_back;
|
||||
private RadioButton rb_model_set, rb_model_time;
|
||||
private RelativeLayout mFuntion;
|
||||
private ListView mListview = null;
|
||||
private final Handler mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
//不显示进度
|
||||
int firstIndex = mListview.getFirstVisiblePosition();
|
||||
int lastIndex = mListview.getLastVisiblePosition();
|
||||
for (int i = firstIndex; i <= lastIndex; i++) {
|
||||
ViewHolder holder = (ViewHolder) mListview.getChildAt(i - firstIndex).getTag();
|
||||
//渲染下载更新
|
||||
ViewGroup.LayoutParams params = holder.mDownload_bg.getLayoutParams();
|
||||
if (holder.mInfo.isDownload()) {
|
||||
if (holder.mInfo.getDownLength() > 0) {
|
||||
if (holder.mInfo.getFileLength() > 0)
|
||||
params.width = (int) (holder.mDownload_icon.getWidth() / (holder.mInfo.getFileLength() / holder.mInfo.getDownLength()));
|
||||
else
|
||||
params.width = 0;
|
||||
}
|
||||
} else {
|
||||
params.width = 0;
|
||||
holder.mDownload_icon.setText(R.string.download);
|
||||
}
|
||||
holder.mDownload_bg.setLayoutParams(params);
|
||||
}
|
||||
sendEmptyMessageDelayed(0, 1000);
|
||||
}
|
||||
|
||||
;
|
||||
}; //定时器,每500ms刷新一次,
|
||||
private DatePicker mDatePicker;
|
||||
private LinearLayout mViewContainer; // 放置DatePicker的容器
|
||||
private ProgressDialog mProgressDialog; //请求加载使用
|
||||
private RecrodListAdapter mRecordListAdapt;
|
||||
private List<RecordInfo> mRecordList;
|
||||
private String mChannelUUID = null;
|
||||
private int mType;
|
||||
private int mIndex = -1; //当前正在下载的索引号,目前仅支持单个下载,日后会扩展多个下载
|
||||
private PowerfulStickyDecoration decoration;
|
||||
private List<RecordInfo> dataList = new ArrayList<>();
|
||||
private com.lechange.demo.localvideo.SimpleAdapter mAdapter;
|
||||
private TextView mCalendarTv, tv_before_day, tv_last_day;
|
||||
private boolean isChangeDate = false;
|
||||
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_record_list);
|
||||
Intent intent = getIntent();
|
||||
mChannelUUID = intent.getStringExtra("UUID");
|
||||
mType = intent.getIntExtra("TYPE", 0);
|
||||
Log.d(tag, mType + "::mChannelUUID:" + mChannelUUID);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
mTitleView = (TitleView) findViewById(R.id.title_local_video_list);
|
||||
mTitleView.setHead("本地录像");
|
||||
mTitleView.setTitleListener(new OnTitleItemClickListener() {
|
||||
@Override
|
||||
public void onBack() {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunction() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFunctionText() {
|
||||
|
||||
}
|
||||
});
|
||||
mRv = (RecyclerView) findViewById(R.id.rv);
|
||||
//绘制标题
|
||||
iv_back = (ImageView) findViewById(R.id.iv_back);
|
||||
rb_model_set = (RadioButton) findViewById(R.id.rb_model_set);
|
||||
rb_model_time = (RadioButton) findViewById(R.id.rb_model_time);
|
||||
mFuntion = (RelativeLayout) findViewById(R.id.iv_funtion);
|
||||
iv_back.setOnClickListener(this);
|
||||
rb_model_set.setOnClickListener(this);
|
||||
rb_model_time.setOnClickListener(this);
|
||||
mFuntion.setOnClickListener(this);
|
||||
|
||||
//日期控件
|
||||
mViewContainer = (LinearLayout) findViewById(R.id.timerContainer);
|
||||
//开启请求加载控件
|
||||
mProgressDialog = (ProgressDialog) this.findViewById(R.id.query_load);
|
||||
mProgressDialog.setStart(getString(R.string.common_loading));
|
||||
|
||||
//绘制list
|
||||
mListview = (ListView) this.findViewById(R.id.list_records);
|
||||
mRecordListAdapt = new RecrodListAdapter(this);
|
||||
mListview.setAdapter(mRecordListAdapt);
|
||||
|
||||
tv_before_day = (TextView) findViewById(R.id.tv_before_day);
|
||||
tv_last_day = (TextView) findViewById(R.id.tv_last_day);
|
||||
tv_before_day.setOnClickListener(this);
|
||||
tv_last_day.setOnClickListener(this);
|
||||
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
mCalendarTv = (TextView) findViewById(R.id.tv_calendar);
|
||||
mCalendarTv.setText(df.format(new Date()));
|
||||
String startTime = df.format(new Date()) + " 00:00:00";
|
||||
String endTime = df.format(new Date()) + " 23:59:59";
|
||||
//初始化数据
|
||||
if (null != getIntent().getExtras().get("dateString")) {
|
||||
String date = (String) getIntent().getExtras().get("dateString");
|
||||
if (mCalendarTv.getText().toString().compareTo(date) > 0) {
|
||||
tv_last_day.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mCalendarTv.setText(date);
|
||||
startTime = date + " 00:00:00";
|
||||
endTime = date + " 23:59:59";
|
||||
}
|
||||
loadRecrodList(startTime, endTime);
|
||||
|
||||
//设置监听
|
||||
setItemClick();
|
||||
|
||||
//设置云录像下载监听
|
||||
if (mType == MediaPlayActivity.IS_VIDEO_REMOTE_CLOUD_RECORD) {
|
||||
LCOpenSDK_Download.setListener(new CloudDownloadListener());
|
||||
} else {
|
||||
LCOpenSDK_Download.setListener(new LocalDownloadListener());
|
||||
}
|
||||
//开启定时刷新
|
||||
mHandler.obtainMessage().sendToTarget();
|
||||
|
||||
// setRecycleView();
|
||||
|
||||
mCalendarTv.setOnClickListener(this);
|
||||
mCalendarTv.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
String s1 = s.toString();
|
||||
if (s1.equals(df.format(new Date())) || s1.compareTo(df.format(new Date())) > 0) {
|
||||
tv_last_day.setVisibility(View.GONE);
|
||||
} else {
|
||||
tv_last_day.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setRecycleView() {
|
||||
//模拟数据
|
||||
// dataList.addAll(CityUtil.getCityList());
|
||||
GridLayoutManager manager = new GridLayoutManager(this, 4);
|
||||
// LinearLayoutManager manager = new LinearLayoutManager(this);
|
||||
mRv.setLayoutManager(manager);
|
||||
if (null != decoration) {
|
||||
mRv.removeItemDecoration(decoration);
|
||||
}
|
||||
decoration = PowerfulStickyDecoration.Builder
|
||||
.init(new PowerGroupListener() {
|
||||
@Override
|
||||
public String getGroupName(int position) {
|
||||
//获取组名,用于判断是否是同一组
|
||||
if (dataList.size() > position) {
|
||||
Log.i("TAG", "RecordListActivity getGroupName()" + String.valueOf(dataList.get(position).getStartTime()));
|
||||
SimpleDateFormat sdf2 = new SimpleDateFormat("HH");
|
||||
Log.i("TAG", "RecordListActivity getGroupName()" + sdf2.format(dataList.get(position).getStartTime()));
|
||||
return String.valueOf(sdf2.format(dataList.get(position).getStartTime()) + ":00");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getGroupView(int position) {
|
||||
//获取自定定义的组View
|
||||
if (dataList.size() > position) {
|
||||
SimpleDateFormat sdf2 = new SimpleDateFormat("HH");
|
||||
final View view = getLayoutInflater().inflate(R.layout.city_group, null, true);
|
||||
((TextView) view.findViewById(R.id.tv)).setText(sdf2.format(dataList.get(position).getStartTime()) + ":00");
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.iv);
|
||||
imageView.setImageResource(R.drawable.icon_style);
|
||||
return view;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.setCacheEnable(true)
|
||||
.resetSpan(mRv, manager)
|
||||
.setGroupHeight(DensityUtil.dip2px(RecordListActivity.this, 40))
|
||||
.setDivideHeight(0)
|
||||
.setOnClickListener(new OnGroupClickListener() {
|
||||
@Override
|
||||
public void onClick(int position, int id) {
|
||||
if (dataList.size() > position) {
|
||||
/*//修改数据
|
||||
changeExpandedState(position);
|
||||
City city = dataList.get(position);
|
||||
//修改悬浮窗
|
||||
final View view = getLayoutInflater().inflate(R.layout.city_group, null, false);
|
||||
((TextView) view.findViewById(R.id.tv)).setText(dataList.get(position).getProvince());
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.iv);
|
||||
imageView.setImageResource(dataList.get(position).getIcon());
|
||||
ImageView ivExpanded = (ImageView) view.findViewById(R.id.iv_expanded);
|
||||
int rotation = city.isExpanded() ? 0 : 180;
|
||||
ivExpanded.setRotation(rotation);
|
||||
//修改数据后,刷新指定的悬浮窗
|
||||
decoration.notifyRedraw(mRv, view, position);
|
||||
mAdapter.notifyDataSetChanged();*/
|
||||
}
|
||||
}
|
||||
})
|
||||
.build();
|
||||
//---------------- -------------
|
||||
mRv.addItemDecoration(decoration);
|
||||
mRv.setVisibility(View.VISIBLE);
|
||||
//------------- PowerfulStickyDecoration 使用部分 ----------------
|
||||
//下面是平时的RecyclerView操作
|
||||
mAdapter = new com.lechange.demo.localvideo.SimpleAdapter(this, dataList);
|
||||
mRv.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param position
|
||||
*/
|
||||
private void changeExpandedState(int position) {
|
||||
if (dataList.size() > position) {
|
||||
RecordInfo city = dataList.get(position);
|
||||
/*city.setExpanded(!city.isExpanded());
|
||||
position++;
|
||||
if (dataList.size() > position) {
|
||||
//下个是当前分组
|
||||
City city2 = dataList.get(position);
|
||||
if (TextUtils.equals(city.getProvince(), city2.getProvince())) {
|
||||
changeExpandedState(position);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.iv_back:
|
||||
finish();
|
||||
break;
|
||||
case R.id.rb_model_set:
|
||||
|
||||
break;
|
||||
case R.id.rb_model_time:
|
||||
|
||||
break;
|
||||
case R.id.iv_funtion:
|
||||
//添加时间选择控件
|
||||
Log.d("Business", "Business" + mViewContainer.getChildCount());
|
||||
if (mViewContainer.getChildCount() > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// undo 添加datepicker
|
||||
if (mDatePicker == null) {
|
||||
mDatePicker = new DatePicker(getApplicationContext());
|
||||
initDatePicker();
|
||||
}
|
||||
|
||||
LayoutParams lp = new LayoutParams(
|
||||
LayoutParams.MATCH_PARENT,
|
||||
LayoutParams.MATCH_PARENT);
|
||||
mViewContainer.addView(mDatePicker, lp);
|
||||
break;
|
||||
case R.id.tv_calendar:
|
||||
showCalendarBottom(mCalendarTv.getText().toString());
|
||||
break;
|
||||
case R.id.tv_before_day:
|
||||
String beforeFromTarget = DateTimeUitl.getBeforeFromTarget(mCalendarTv.getText().toString());
|
||||
mCalendarTv.setText(beforeFromTarget);
|
||||
showChooseDateVideo(beforeFromTarget);
|
||||
break;
|
||||
case R.id.tv_last_day:
|
||||
String futureFromTarget = DateTimeUitl.getFutureFromTarget(mCalendarTv.getText().toString());
|
||||
mCalendarTv.setText(futureFromTarget);
|
||||
showChooseDateVideo(futureFromTarget);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void showCalendarBottom(String date) {
|
||||
View rootview = LayoutInflater.from(this).inflate(R.layout.fragment_media_record, null);
|
||||
CalendarPopipWindow popupWindow = new CalendarPopipWindow(this, date.substring(0, 4) + "年" + date.substring(5, 7) + "月", new CalendarPopipWindow.OnCompleteListener() {
|
||||
@Override
|
||||
public void onComplete(String dayStr) {
|
||||
showChooseDateVideo(dayStr);
|
||||
mCalendarTv.setText(dayStr);
|
||||
}
|
||||
});
|
||||
popupWindow.showAtLocation(rootview, Gravity.BOTTOM, 0, 0);
|
||||
}
|
||||
|
||||
public void initDatePicker() {
|
||||
if (mDatePicker == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mDatePicker.setOnTimeClickListener(new OnTimeClickListener() {
|
||||
@Override
|
||||
public void onCommonTimeClick(int id) {
|
||||
if (id == DatePicker.ID_LEFT) { // 点击左边
|
||||
mViewContainer.removeView(mDatePicker);
|
||||
} else { // 点击右边
|
||||
// showChooseDateVideo();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showChooseDateVideo(String date) {
|
||||
if (mIndex != -1) {
|
||||
LCOpenSDK_Download.stopDownload(mIndex); //重新加载前停止下载
|
||||
MediaPlayHelper.deleteDownloadVideo(mRecordList.get(mIndex).getRecordID(), mRecordList.get(mIndex).getStartTime());
|
||||
//屏蔽操作
|
||||
mIndex = -1;
|
||||
}
|
||||
/*Date time = mDatePicker.getSelectedDate();
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String date = df.format(date1);*/
|
||||
/*int year = Integer.parseInt(date1.substring(0, 4));
|
||||
int month = Integer.parseInt(date1.substring(5, 7));
|
||||
int day = Integer.parseInt(date1.substring(date1.indexOf("月") + 1, date1.indexOf("日")));
|
||||
String date = DateTimeUitl.formatDateFromInt(year, month, day);*/
|
||||
|
||||
String startTime = date + " 00:00:00";
|
||||
String endTime = date + " 23:59:59";
|
||||
|
||||
mViewContainer.removeView(mDatePicker);
|
||||
isChangeDate = true;
|
||||
loadRecrodList(startTime, endTime);
|
||||
//清空屏幕
|
||||
if (mRecordList != null)
|
||||
mRecordList.clear(); //清数据 临时使用
|
||||
mRecordListAdapt.notifyDataSetChanged();
|
||||
|
||||
RecordListActivity.this.findViewById(R.id.list_records_novideo).setVisibility(View.GONE);
|
||||
RecordListActivity.this.findViewById(R.id.tv_records_novideo).setVisibility(View.GONE);
|
||||
mProgressDialog.setStart(getString(R.string.common_loading));
|
||||
}
|
||||
|
||||
public void setItemClick() {
|
||||
//单个录像监听
|
||||
mListview.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterview, View view, int position,
|
||||
long id) {
|
||||
// TODO Auto-generated method stub
|
||||
if (mIndex != -1) {
|
||||
Toast.makeText(RecordListActivity.this, R.string.toast_recordlist_onlyone, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Log.d(tag, "click:" + position + "-" + id + "ID:" + view.getId());
|
||||
Intent intent = new Intent(RecordListActivity.this, MediaPlayActivity.class);
|
||||
switch (mType) {
|
||||
case MediaPlayActivity.IS_VIDEO_REMOTE_RECORD:
|
||||
intent.putExtra("TYPE", MediaPlayActivity.IS_VIDEO_REMOTE_RECORD);
|
||||
break;
|
||||
case MediaPlayActivity.IS_VIDEO_REMOTE_CLOUD_RECORD:
|
||||
intent.putExtra("TYPE", MediaPlayActivity.IS_VIDEO_REMOTE_CLOUD_RECORD);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
intent.putExtra("ID", mRecordList.get(position).getId());
|
||||
intent.putExtra("MEDIA_TITLE", R.string.record_play_name);
|
||||
RecordListActivity.this.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void loadRecrodList(final String startTime, final String endTime) {
|
||||
switch (mType) {
|
||||
case MediaPlayActivity.IS_VIDEO_REMOTE_RECORD:
|
||||
//查询1天之内的后10条录像
|
||||
dataList.clear();
|
||||
Business.getInstance().queryRecordNum(mChannelUUID, startTime,
|
||||
endTime, new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (msg.what != 0) {
|
||||
mProgressDialog.setStop(); //关闭加载窗口
|
||||
Toast.makeText(RecordListActivity.this, getString(R.string.toast_recordlist_query_failed) + msg.what, Toast.LENGTH_SHORT).show();
|
||||
} else if (msg.what == 0) {
|
||||
if (msg.arg1 > 0) {
|
||||
Business.getInstance().queryRecordList(mChannelUUID, startTime,
|
||||
endTime, msg.arg2, msg.arg1, new Handler() {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
mProgressDialog.setStop(); //关闭加载窗口
|
||||
if (msg.what != 0) {
|
||||
Toast.makeText(RecordListActivity.this, getString(R.string.toast_recordlist_query_failed) + msg.obj, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
// mRecordList = (List<RecordInfo>) msg.obj;
|
||||
dataList.addAll((List<RecordInfo>) msg.obj);
|
||||
if (dataList != null && dataList.size() > 0) {
|
||||
Log.d(tag, "loadRecrodList mRecordList.size:" + dataList.size());
|
||||
Collections.reverse(dataList);
|
||||
// mRecordListAdapt.notifyDataSetChanged();
|
||||
setRecycleView();
|
||||
} else {
|
||||
mRv.setVisibility(View.GONE);
|
||||
RecordListActivity.this.findViewById(R.id.list_records_novideo).setVisibility(View.VISIBLE);
|
||||
RecordListActivity.this.findViewById(R.id.tv_records_novideo).setVisibility(View.VISIBLE);
|
||||
//Toast.makeText(RecordListActivity.this, "没有录像", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mRv.setVisibility(View.GONE);
|
||||
mProgressDialog.setStop(); //关闭加载窗口
|
||||
RecordListActivity.this.findViewById(R.id.list_records_novideo).setVisibility(View.VISIBLE);
|
||||
RecordListActivity.this.findViewById(R.id.tv_records_novideo).setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
case MediaPlayActivity.IS_VIDEO_REMOTE_CLOUD_RECORD:
|
||||
//查询1天之内的前10条录像
|
||||
Business.getInstance().queryCloudRecordNum(mChannelUUID, startTime,
|
||||
endTime, new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (msg.what != 0) {
|
||||
mProgressDialog.setStop(); //关闭加载窗口
|
||||
Toast.makeText(RecordListActivity.this, getString(R.string.toast_recordlist_query_failed) + msg.what, Toast.LENGTH_SHORT).show();
|
||||
} else if (msg.what == 0) {
|
||||
if (msg.arg1 > 0) {
|
||||
Business.getInstance().queryCloudRecordList(mChannelUUID, startTime,
|
||||
endTime, msg.arg2, msg.arg1, new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
mProgressDialog.setStop(); //关闭加载窗口
|
||||
if (msg.what != 0) {
|
||||
Toast.makeText(RecordListActivity.this, getString(R.string.toast_recordlist_query_failed) + msg.arg1, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
mRecordList = (List<RecordInfo>) msg.obj;
|
||||
if (mRecordList != null && mRecordList.size() > 0) {
|
||||
Log.d(tag, "loadRecrodList mRecordList.size:" + mRecordList.size() + mRecordList.toString());
|
||||
mRecordListAdapt.notifyDataSetChanged();
|
||||
} else {
|
||||
RecordListActivity.this.findViewById(R.id.list_records_novideo).setVisibility(View.VISIBLE);
|
||||
RecordListActivity.this.findViewById(R.id.tv_records_novideo).setVisibility(View.VISIBLE);
|
||||
//Toast.makeText(RecordListActivity.this, "没有录像", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mProgressDialog.setStop(); //关闭加载窗口
|
||||
RecordListActivity.this.findViewById(R.id.list_records_novideo).setVisibility(View.VISIBLE);
|
||||
RecordListActivity.this.findViewById(R.id.tv_records_novideo).setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
// TODO Auto-generated method stub
|
||||
super.onPause();
|
||||
if (mIndex != -1) {
|
||||
LCOpenSDK_Download.stopDownload(mIndex);
|
||||
MediaPlayHelper.deleteDownloadVideo(mRecordList.get(mIndex).getRecordID(), mRecordList.get(mIndex).getStartTime());
|
||||
mRecordList.get(mIndex).setDownLength(-1);
|
||||
//屏蔽操作
|
||||
mIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
// TODO Auto-generated method stub
|
||||
super.onDestroy();
|
||||
TaskPoolHelper.clearTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callBackUiThread(Message msg) {
|
||||
|
||||
}
|
||||
|
||||
static class ViewHolder {
|
||||
int mPosition;
|
||||
RelativeLayout mBgVideo;
|
||||
TextView mRecordTime;
|
||||
RecordInfo mInfo;
|
||||
FrameLayout mDownload;
|
||||
View mDownload_bg;
|
||||
TextView mDownload_icon;
|
||||
}
|
||||
|
||||
private class RecrodListAdapter extends BaseAdapter {
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
public RecrodListAdapter(Context context) {
|
||||
mInflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mRecordList != null ? mRecordList.size() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecordInfo getItem(int position) {
|
||||
return mRecordList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
final ViewHolder holder;
|
||||
|
||||
if (convertView == null) {
|
||||
convertView = mInflater.inflate(R.layout.activity_record_list_item, null);
|
||||
holder = new ViewHolder();
|
||||
holder.mBgVideo = (RelativeLayout) convertView.findViewById(R.id.list_bg_video);
|
||||
holder.mRecordTime = (TextView) convertView.findViewById(R.id.list_record_time);
|
||||
//云录像加载下载按钮
|
||||
// if (mType == MediaPlayActivity.IS_VIDEO_REMOTE_CLOUD_RECORD) {
|
||||
holder.mDownload = (FrameLayout) convertView.findViewById(R.id.list_record_download);
|
||||
holder.mDownload_bg = convertView.findViewById(R.id.record_download_bg);
|
||||
holder.mDownload_icon = (TextView) convertView.findViewById(R.id.record_download_icon);
|
||||
holder.mDownload.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
if (mIndex == -1 || mIndex == holder.mPosition)
|
||||
if (holder.mDownload_icon.getText().toString().equals(getString(R.string.download))) {
|
||||
//置为可以取消状态
|
||||
holder.mDownload_icon.setText(R.string.cancel);
|
||||
holder.mInfo.setDownLength(0);
|
||||
|
||||
String decryptKey = holder.mInfo.getDeviceKey() != null ? holder.mInfo.getDeviceKey() : holder.mInfo.getDeviceId();
|
||||
Logger.e("====decryptKey====", decryptKey);
|
||||
if (mType == MediaPlayActivity.IS_VIDEO_REMOTE_CLOUD_RECORD) {
|
||||
LCOpenSDK_Download.startDownload(holder.mPosition,
|
||||
MediaPlayHelper.getDownloadVideoPath(0, String.valueOf(holder.mPosition), holder.mInfo.getStartTime()),
|
||||
Business.getInstance().getToken(),
|
||||
holder.mInfo.getRecordRegionId(),
|
||||
holder.mInfo.getDeviceId(),
|
||||
String.valueOf(0),
|
||||
decryptKey,
|
||||
1000,
|
||||
5000);
|
||||
} else {
|
||||
LCOpenSDK_Download.startDownload(holder.mPosition, Business.getInstance().getToken(),
|
||||
holder.mInfo.getDeviceId(),
|
||||
MediaPlayHelper.getDownloadVideoPath(1, String.valueOf(holder.mPosition), holder.mInfo.getStartTime()),
|
||||
holder.mInfo.getRecordID(),
|
||||
decryptKey,
|
||||
0, //默认偏移为0
|
||||
0, //mp4格式
|
||||
16.0f);
|
||||
}
|
||||
//屏蔽操作
|
||||
mIndex = holder.mPosition;
|
||||
} else {
|
||||
//置为可以下载状态
|
||||
ViewGroup.LayoutParams params = holder.mDownload_bg.getLayoutParams();
|
||||
params.width = 0;
|
||||
holder.mDownload_bg.setLayoutParams(params);
|
||||
holder.mDownload_icon.setText(R.string.download);
|
||||
holder.mInfo.setDownLength(-1);
|
||||
LCOpenSDK_Download.stopDownload(holder.mPosition);
|
||||
|
||||
//删除文件
|
||||
MediaPlayHelper.deleteDownloadVideo(String.valueOf(holder.mPosition), holder.mInfo.getStartTime());
|
||||
//屏蔽操作
|
||||
mIndex = -1;
|
||||
}
|
||||
else
|
||||
Toast.makeText(RecordListActivity.this, R.string.toast_recordlist_onlyone, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
// }
|
||||
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
//修改数据信息
|
||||
holder.mPosition = position;
|
||||
holder.mInfo = getItem(position);
|
||||
//Log.d(tag, "index : " + position);
|
||||
|
||||
ViewGroup.LayoutParams params = holder.mDownload_bg.getLayoutParams();
|
||||
switch (mType) {
|
||||
case MediaPlayActivity.IS_VIDEO_REMOTE_RECORD:
|
||||
// 屏蔽平台返回的录像大小=0情况(easy4ip设备返回录像大小为0)
|
||||
if (holder.mInfo.getFileLength() > 0) {
|
||||
holder.mDownload.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.mDownload.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
//渲染下载更新
|
||||
if (holder.mInfo.isDownload()) {
|
||||
holder.mDownload_icon.setText(R.string.cancel);
|
||||
if (holder.mInfo.getDownLength() > 0) {
|
||||
params.width = (int) (holder.mDownload_icon.getWidth() / (holder.mInfo.getFileLength() / holder.mInfo.getDownLength()));
|
||||
} else {
|
||||
params.width = 0;
|
||||
}
|
||||
} else {
|
||||
holder.mDownload_icon.setText(R.string.download);
|
||||
params.width = 0;
|
||||
}
|
||||
holder.mDownload_bg.setLayoutParams(params);
|
||||
|
||||
//加载背景图片,设备录像,不用解密
|
||||
holder.mBgVideo.setBackgroundResource(R.drawable.list_bg_video);
|
||||
if (holder.mInfo.getBackgroudImgUrl() != null && holder.mInfo.getBackgroudImgUrl().length() > 0) {
|
||||
//下载
|
||||
ImageHelper.loadCacheImage(holder.mInfo.getBackgroudImgUrl(), new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
// TODO Auto-generated method stub
|
||||
super.handleMessage(msg);
|
||||
if (holder.mInfo.getBackgroudImgUrl().hashCode() == msg.what && msg.obj != null) {
|
||||
holder.mBgVideo.setBackgroundDrawable((Drawable) msg.obj);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
case MediaPlayActivity.IS_VIDEO_REMOTE_CLOUD_RECORD:
|
||||
// 屏蔽平台返回的录像大小=0情况(easy4ip设备返回录像大小为0)
|
||||
if (holder.mInfo.getFileLength() > 0) {
|
||||
holder.mDownload.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.mDownload.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
//渲染下载更新
|
||||
if (holder.mInfo.isDownload()) {
|
||||
holder.mDownload_icon.setText(R.string.cancel);
|
||||
if (holder.mInfo.getDownLength() > 0) {
|
||||
params.width = (int) (holder.mDownload_icon.getWidth() / (holder.mInfo.getFileLength() / holder.mInfo.getDownLength()));
|
||||
} else {
|
||||
params.width = 0;
|
||||
}
|
||||
} else {
|
||||
holder.mDownload_icon.setText(R.string.download);
|
||||
params.width = 0;
|
||||
}
|
||||
holder.mDownload_bg.setLayoutParams(params);
|
||||
//加载背景图片,云录像,要解密
|
||||
holder.mBgVideo.setBackgroundResource(R.drawable.list_bg_device);
|
||||
if (holder.mInfo.getBackgroudImgUrl() != null && holder.mInfo.getBackgroudImgUrl().length() > 0) {
|
||||
//下载
|
||||
ImageHelper.loadCacheImage(holder.mInfo.getBackgroudImgUrl(), holder.mInfo.getDeviceId(), holder.mInfo.getDeviceKey() != null ? holder.mInfo.getDeviceKey() : holder.mInfo.getDeviceId(), new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
// TODO Auto-generated method stub
|
||||
super.handleMessage(msg);
|
||||
if (holder.mInfo.getBackgroudImgUrl().hashCode() == msg.what && msg.obj != null) {
|
||||
holder.mBgVideo.setBackgroundDrawable((Drawable) msg.obj);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//时间
|
||||
holder.mRecordTime.setText(TimeHelper.getDateHMS(holder.mInfo.getStartTime()) + "--" + TimeHelper.getDateHMS(holder.mInfo.getEndTime()));
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
||||
private class CloudDownloadListener extends LCOpenSDK_DownloadListener {
|
||||
@Override
|
||||
public void onDownloadReceiveData(int index, int dataLen) {
|
||||
// TODO Auto-generated method stub
|
||||
if (mRecordList.size() != 0) {
|
||||
RecordInfo info = mRecordList.get((int) index);
|
||||
info.setDownLength(info.getDownLength() + dataLen);
|
||||
Logger.d(tag, "downLen:" + info.getDownLength());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloadState(final int index, String code, int Type) {
|
||||
// TODO Auto-generated method stub
|
||||
if (Type == Business.RESULT_SOURCE_OPENAPI
|
||||
|| code.equals(CloudStorageCode.HLS_DOWNLOAD_FAILD)
|
||||
|| code.equals(CloudStorageCode.HLS_SEEK_FAILD)
|
||||
|| code.equals(CloudStorageCode.HLS_KEY_ERROR)) {
|
||||
//重置为可以下载状态
|
||||
mRecordList.get((int) index).setDownLength(-1);
|
||||
if (mHandler != null) {
|
||||
mHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Toast.makeText(RecordListActivity.this, getString(R.string.toast_recordlist_download_failed) + ",index : " + index, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
//删除下载到一半的文件
|
||||
MediaPlayHelper.deleteDownloadVideo(String.valueOf(index), mRecordList.get(index).getStartTime());
|
||||
//屏蔽操作
|
||||
mIndex = -1;
|
||||
|
||||
}
|
||||
if (code.equals(CloudStorageCode.HLS_DOWNLOAD_END)) {
|
||||
Toast.makeText(RecordListActivity.this, getString(R.string.toast_recordlist_download_end) + ",index : " + index, Toast.LENGTH_SHORT).show();
|
||||
//重置为可以下载状态
|
||||
mRecordList.get((int) index).setDownLength(-1);
|
||||
if (mHandler != null) {
|
||||
mHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Toast.makeText(RecordListActivity.this, getString(R.string.toast_recordlist_download_end) + ",index : " + index, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
//通知图库刷新
|
||||
MediaScannerConnection.scanFile(RecordListActivity.this,
|
||||
new String[]{MediaPlayHelper.getDownloadVideoPath(0, String.valueOf(index), mRecordList.get(index).getStartTime())}, null, null);
|
||||
//屏蔽操作
|
||||
mIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class LocalDownloadListener extends LCOpenSDK_DownloadListener {
|
||||
@Override
|
||||
public void onDownloadReceiveData(int index, int dataLen) {
|
||||
// TODO Auto-generated method stub
|
||||
if (mRecordList.size() != 0) {
|
||||
RecordInfo info = mRecordList.get((int) index);
|
||||
info.setDownLength(info.getDownLength() + dataLen);
|
||||
|
||||
Logger.d(tag, "downLen:" + info.getDownLength());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloadState(final int index, String code, int Type) {
|
||||
// TODO Auto-generated method stub
|
||||
if (Type == Business.RESULT_SOURCE_OPENAPI
|
||||
|| code.equals(LocalDownloadCode.RTSP_DOWNLOAD_FRAME_ERROR)
|
||||
|| code.equals(LocalDownloadCode.RTSP_DOWNLOAD_TEARDOWN)
|
||||
|| code.equals(LocalDownloadCode.RTSP_DOWNLOAD_AUTHORIZATION_FAIL)
|
||||
|| code.equals(LocalDownloadCode.RTSP_DOWNLOAD_KEY_MISMATH)) {
|
||||
//重置为可以下载状态
|
||||
mRecordList.get((int) index).setDownLength(-1);
|
||||
if (mHandler != null) {
|
||||
mHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Toast.makeText(RecordListActivity.this, getString(R.string.toast_recordlist_download_failed) + ",index : " + index, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
//删除下载到一半的文件
|
||||
MediaPlayHelper.deleteDownloadVideo(String.valueOf(index), mRecordList.get(index).getStartTime());
|
||||
//屏蔽操作
|
||||
mIndex = -1;
|
||||
|
||||
}
|
||||
if (code.equals(LocalDownloadCode.RTSP_DOWNLOAD_OVER)) {
|
||||
Toast.makeText(RecordListActivity.this, getString(R.string.toast_recordlist_download_end) + ",index : " + index, Toast.LENGTH_SHORT).show();
|
||||
//重置为可以下载状态
|
||||
mRecordList.get((int) index).setDownLength(-1);
|
||||
LCOpenSDK_Download.stopDownload(index);
|
||||
if (mHandler != null) {
|
||||
mHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
Toast.makeText(RecordListActivity.this, getString(R.string.toast_recordlist_download_end) + ",index : " + index, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
//通知图库刷新
|
||||
MediaScannerConnection.scanFile(RecordListActivity.this,
|
||||
new String[]{MediaPlayHelper.getDownloadVideoPath(1, String.valueOf(index), mRecordList.get(index).getStartTime())}, null, null);
|
||||
//屏蔽操作
|
||||
mIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package com.lechange.demo.localvideo;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.lechange.demo.business.entity.RecordInfo;
|
||||
import com.lechange.demo.mediaplay.MediaPlayActivity;
|
||||
import com.lechange.demo.mediaplay.MediaPlayBackActivity;
|
||||
import com.yonsz.z1.R;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by gavin
|
||||
* Created date 17/6/5
|
||||
* Created log
|
||||
*/
|
||||
|
||||
public class SimpleAdapter extends RecyclerView.Adapter {
|
||||
private List<RecordInfo> mCities;
|
||||
private Context mContext;
|
||||
|
||||
public SimpleAdapter(Context context, List<RecordInfo> cities) {
|
||||
mCities = cities;
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_city, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
|
||||
ViewHolder holder = (ViewHolder) viewHolder;
|
||||
if (mCities.size() > position) {
|
||||
RecordInfo city = mCities.get(position);
|
||||
holder.mIvCity.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(mContext, MediaPlayBackActivity.class);
|
||||
intent.putExtra("TYPE", MediaPlayActivity.IS_VIDEO_REMOTE_RECORD);
|
||||
intent.putExtra("ID", mCities.get(position).getId());
|
||||
intent.putExtra("dateString", mCities.get(position).getStartTime());
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.getApplicationContext().startActivity(intent);
|
||||
}
|
||||
});
|
||||
long startTime = city.getStartTime();
|
||||
long endTime = city.getEndTime();
|
||||
long l = endTime - startTime;
|
||||
SimpleDateFormat sdf1 = new SimpleDateFormat("mm:ss");
|
||||
holder.mTvCity.setText(String.valueOf(sdf1.format(l)));
|
||||
SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
|
||||
holder.mTvBrief.setText(String.valueOf(sdf2.format(startTime)));
|
||||
/*if (city.isExpanded()) {
|
||||
ViewGroup.LayoutParams layoutParams = holder.mLlBg.getLayoutParams();
|
||||
layoutParams.height = DensityUtil.dip2px(mContext, 100);
|
||||
holder.mLlBg.setLayoutParams(layoutParams);
|
||||
//holder.itemView.setVisibility(View.VISIBLE);
|
||||
int i = position % 5 + 1;
|
||||
if (i == 1) {
|
||||
holder.mIvCity.setImageResource(R.mipmap.subject1);
|
||||
holder.mLlBg.setBackgroundColor(mContext.getResources().getColor(R.color.bg1));
|
||||
} else if (i == 2) {
|
||||
holder.mIvCity.setImageResource(R.mipmap.subject2);
|
||||
holder.mLlBg.setBackgroundColor(mContext.getResources().getColor(R.color.bg2));
|
||||
} else if (i == 3) {
|
||||
holder.mIvCity.setImageResource(R.mipmap.subject3);
|
||||
holder.mLlBg.setBackgroundColor(mContext.getResources().getColor(R.color.bg3));
|
||||
} else if (i == 4) {
|
||||
holder.mIvCity.setImageResource(R.mipmap.subject4);
|
||||
holder.mLlBg.setBackgroundColor(mContext.getResources().getColor(R.color.bg4));
|
||||
} else {
|
||||
holder.mIvCity.setImageResource(R.mipmap.subject5);
|
||||
holder.mLlBg.setBackgroundColor(mContext.getResources().getColor(R.color.bg5));
|
||||
}
|
||||
holder.mTvCity.setText(city.getName());
|
||||
} else {
|
||||
ViewGroup.LayoutParams layoutParams = holder.mLlBg.getLayoutParams();
|
||||
layoutParams.height = DensityUtil.dip2px(mContext, 0);
|
||||
holder.mLlBg.setLayoutParams(layoutParams);
|
||||
//holder.itemView.setVisibility(View.GONE);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mCities.size();
|
||||
}
|
||||
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
@BindView(R.id.iv_city)
|
||||
ImageView mIvCity;
|
||||
@BindView(R.id.tv_city)
|
||||
TextView mTvCity;
|
||||
@BindView(R.id.tv_brief)
|
||||
TextView mTvBrief;
|
||||
/*@BindView(R.id.ll_bg)
|
||||
LinearLayout mLlBg;*/
|
||||
|
||||
ViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,140 @@
|
|||
package com.lechange.demo.localvideo;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.lechange.demo.business.entity.ChannelInfo;
|
||||
import com.lechange.demo.business.entity.RecordInfo;
|
||||
import com.lechange.demo.mediaplay.MediaPlayBackActivity;
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.listener.OnRecyclerClickListener;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/2/27.
|
||||
*/
|
||||
|
||||
public class TodayLocalAdapter extends RecyclerView.Adapter<TodayLocalAdapter.MessageViewHolder> {
|
||||
|
||||
private List<RecordInfo> mOnLineRecordList = new ArrayList<>();
|
||||
private Context mContext;
|
||||
private String uuid;
|
||||
private OnRecyclerClickListener mOnItemClickListener;
|
||||
|
||||
public TodayLocalAdapter(Context mContext, List<RecordInfo> mRecordInfos, String uuid) {
|
||||
super();
|
||||
this.mContext = mContext;
|
||||
this.mOnLineRecordList = mRecordInfos;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public void setmOnItemClickListener(OnRecyclerClickListener mOnItemClickListener) {
|
||||
this.mOnItemClickListener = mOnItemClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_local_video_item,
|
||||
parent, false);
|
||||
return new TodayLocalAdapter.MessageViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(TodayLocalAdapter.MessageViewHolder holder, int position) {
|
||||
holder.setViews(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (mOnLineRecordList.size() < 5) {
|
||||
return mOnLineRecordList != null ? mOnLineRecordList.size() + 1 : 0;
|
||||
} else {
|
||||
return mOnLineRecordList != null ? 6 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return super.getItemId(position);
|
||||
}
|
||||
|
||||
class MessageViewHolder extends RecyclerView.ViewHolder {
|
||||
/*private TextView mChannelName;
|
||||
private ImageView mDelete;*/
|
||||
// private RelativeLayout mBgDevice;
|
||||
private ImageView mLiveVideo;
|
||||
/*private ImageView mLocalVideo;
|
||||
private ImageView mCloudVideo;
|
||||
private ImageView mMessage;
|
||||
private ImageView mSetting;*/
|
||||
private LinearLayout mListShade;
|
||||
private ChannelInfo mInfo;
|
||||
private ImageView iv;
|
||||
private TextView tv_more;
|
||||
private TextView tv_start_time;
|
||||
|
||||
public MessageViewHolder(View convertView) {
|
||||
super(convertView);
|
||||
/*mChannelName = (TextView) convertView.findViewById(R.id.list_channel_name);
|
||||
mDelete = (ImageView) convertView.findViewById(R.id.list_device_delete);*/
|
||||
// mBgDevice = (RelativeLayout) convertView.findViewById(R.id.list_bg_device);
|
||||
mLiveVideo = (ImageView) convertView.findViewById(R.id.list_device_livevideo);
|
||||
/*mLocalVideo = (ImageView) convertView.findViewById(R.id.list_device_localvideo);
|
||||
mCloudVideo = (ImageView) convertView.findViewById(R.id.list_device_cloudvideo);
|
||||
mMessage = (ImageView) convertView.findViewById(R.id.list_device_message);
|
||||
mSetting = (ImageView) convertView.findViewById(R.id.list_device_setting);*/
|
||||
mListShade = (LinearLayout) convertView.findViewById(R.id.list_shade);
|
||||
iv = (ImageView) itemView.findViewById(R.id.imageView);
|
||||
tv_more = (TextView) itemView.findViewById(R.id.tv_more);
|
||||
tv_start_time = (TextView) itemView.findViewById(R.id.tv_start_time);
|
||||
}
|
||||
|
||||
public void setViews(final int position) {
|
||||
//修改数据信息(含加密标识符)
|
||||
if (position == mOnLineRecordList.size() || position == 5) {
|
||||
iv.setVisibility(View.GONE);
|
||||
} else {
|
||||
iv.setVisibility(View.VISIBLE);
|
||||
SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
|
||||
tv_start_time.setText(String.valueOf(sdf2.format(mOnLineRecordList.get(position).getStartTime())));
|
||||
}
|
||||
iv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mOnItemClickListener != null) {
|
||||
mOnItemClickListener.onClick(v, position);
|
||||
}
|
||||
/*Intent intent = new Intent(mContext, MediaPlayBackActivity.class);
|
||||
if (TextUtils.isEmpty(mOnLineRecordList.get(position).getId())) {
|
||||
return;
|
||||
}
|
||||
intent.putExtra("TYPE", MediaPlayBackActivity.IS_VIDEO_REMOTE_RECORD);
|
||||
intent.putExtra("ID", mOnLineRecordList.get(position).getId());
|
||||
intent.putExtra("dateString", mOnLineRecordList.get(position).getStartTime());
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.getApplicationContext().startActivity(intent);*/
|
||||
}
|
||||
});
|
||||
tv_more.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent1 = new Intent(mContext, RecordListActivity.class);
|
||||
intent1.putExtra("UUID", uuid);
|
||||
intent1.putExtra("TYPE", MediaPlayBackActivity.IS_VIDEO_REMOTE_RECORD);
|
||||
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.getApplicationContext().startActivity(intent1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,136 @@
|
|||
package com.lechange.demo.localvideo.calendar;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.yonsz.z1.R;
|
||||
import com.yonsz.z1.utils.DateTimeUitl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2019/3/7.
|
||||
*/
|
||||
|
||||
public class CalendarPopipWindow extends PopupWindow {
|
||||
private Context context;
|
||||
private View contentView;
|
||||
private CustomCalendar cal;
|
||||
private String chooseDay;
|
||||
private OnCompleteListener onCompleteListener;
|
||||
|
||||
public CalendarPopipWindow(Context context, String chooseDay, OnCompleteListener onCompleteListener) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
this.chooseDay = chooseDay;
|
||||
this.onCompleteListener = onCompleteListener;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
contentView = LayoutInflater.from(context).inflate(R.layout.pop_calendar, null);
|
||||
cal = (CustomCalendar) contentView.findViewById(R.id.cal);
|
||||
final List<DayFinish> list = new ArrayList<>();
|
||||
cal.setRenwu(chooseDay, list);
|
||||
cal.setOnClickListener(new CustomCalendar.onClickListener() {
|
||||
@Override
|
||||
public void onLeftRowClick() {
|
||||
Toast.makeText(context, "点击减箭头", Toast.LENGTH_SHORT).show();
|
||||
cal.monthChange(-1);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
/*runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cal.setRenwu(list);
|
||||
}
|
||||
});*/
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightRowClick() {
|
||||
Toast.makeText(context, "点击加箭头", Toast.LENGTH_SHORT).show();
|
||||
cal.monthChange(1);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
/*runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cal.setRenwu(list);
|
||||
}
|
||||
});*/
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTitleClick(String monthStr, Date month) {
|
||||
Toast.makeText(context, "点击了标题:" + monthStr, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWeekClick(int weekIndex, String weekStr) {
|
||||
Toast.makeText(context, "点击了星期:" + weekStr, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDayClick(int day, String dayStr, DayFinish finish) {
|
||||
Toast.makeText(context, "点击了日期:" + dayStr, Toast.LENGTH_SHORT).show();
|
||||
// Log.w("", "点击了日期:" + dayStr);
|
||||
if (onCompleteListener != null) {
|
||||
int year = Integer.parseInt(dayStr.substring(0, 4));
|
||||
int month = Integer.parseInt(dayStr.substring(5, 7));
|
||||
String date = DateTimeUitl.formatDateFromInt(year, month, day);
|
||||
onCompleteListener.onComplete(date);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
setContentView(contentView);
|
||||
this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
// 设置可触
|
||||
this.setFocusable(true);
|
||||
this.setOutsideTouchable(true);
|
||||
this.setTouchable(true);
|
||||
ColorDrawable dw = new ColorDrawable(0x80000000);
|
||||
this.setBackgroundDrawable(dw);
|
||||
|
||||
this.setTouchInterceptor(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
//如果点击了popuWindow的外部,popuWindow也会消失
|
||||
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
|
||||
dismiss();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface OnCompleteListener {
|
||||
void onComplete(String dayStr);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue