1.0.0发布
parent
49509d7c6d
commit
482f84f5a9
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,163 +0,0 @@
|
|||||||
package com.rehome.meetingbook.ZKUSBManager;
|
|
||||||
|
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.hardware.usb.UsbDevice;
|
|
||||||
import android.hardware.usb.UsbManager;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* usb permission and hotplug
|
|
||||||
*/
|
|
||||||
public class ZKUSBManager {
|
|
||||||
//usb's vendor id
|
|
||||||
private int vid = 0;
|
|
||||||
//usb's product id
|
|
||||||
private int pid = 0;
|
|
||||||
//application context
|
|
||||||
private Context mContext = null;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
|
||||||
//for usb permission
|
|
||||||
private static final String SOURCE_STRING = "0123456789-_abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ";
|
|
||||||
private static final int DEFAULT_LENGTH = 16;
|
|
||||||
private String ACTION_USB_PERMISSION;
|
|
||||||
private boolean mbRegisterFilter = false;
|
|
||||||
private ZKUSBManagerListener zknirusbManagerListener = null;
|
|
||||||
|
|
||||||
private BroadcastReceiver usbMgrReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
String action = intent.getAction();
|
|
||||||
if (ACTION_USB_PERMISSION.equals(action))
|
|
||||||
{
|
|
||||||
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
|
|
||||||
if (device.getVendorId() == vid && device.getProductId() == pid) {
|
|
||||||
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
|
|
||||||
zknirusbManagerListener.onCheckPermission(0);
|
|
||||||
} else {
|
|
||||||
zknirusbManagerListener.onCheckPermission(-2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action))
|
|
||||||
{
|
|
||||||
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
|
|
||||||
if (device.getVendorId() == vid && device.getProductId() == pid) {
|
|
||||||
zknirusbManagerListener.onUSBArrived(device);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action))
|
|
||||||
{
|
|
||||||
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
|
|
||||||
if (device.getVendorId() == vid && device.getProductId() == pid) {
|
|
||||||
zknirusbManagerListener.onUSBRemoved(device);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isNullOrEmpty(String target) {
|
|
||||||
if (null == target || "".equals(target) || target.isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String createRandomString(String source, int length) {
|
|
||||||
if (this.isNullOrEmpty(source)) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuffer result = new StringBuffer();
|
|
||||||
Random random = new Random();
|
|
||||||
|
|
||||||
for(int index = 0; index < length; index++) {
|
|
||||||
result.append(source.charAt(random.nextInt(source.length())));
|
|
||||||
}
|
|
||||||
return result.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean registerUSBPermissionReceiver()
|
|
||||||
{
|
|
||||||
if (null == mContext || mbRegisterFilter)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
IntentFilter filter = new IntentFilter();
|
|
||||||
filter.addAction(ACTION_USB_PERMISSION);
|
|
||||||
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
|
|
||||||
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
|
|
||||||
mContext.registerReceiver(usbMgrReceiver, filter);
|
|
||||||
mbRegisterFilter = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unRegisterUSBPermissionReceiver()
|
|
||||||
{
|
|
||||||
if (null == mContext || !mbRegisterFilter)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mContext.unregisterReceiver(usbMgrReceiver);
|
|
||||||
mbRegisterFilter = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//End USB Permission
|
|
||||||
/////////////////////////////////////////////
|
|
||||||
|
|
||||||
public ZKUSBManager(@NonNull Context context, @NonNull ZKUSBManagerListener listener)
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
if (null == context || null == listener)
|
|
||||||
{
|
|
||||||
throw new NullPointerException("context or listener is null");
|
|
||||||
}
|
|
||||||
zknirusbManagerListener = listener;
|
|
||||||
ACTION_USB_PERMISSION = createRandomString(SOURCE_STRING, DEFAULT_LENGTH);
|
|
||||||
mContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
//0 means success
|
|
||||||
//-1 means device no found
|
|
||||||
//-2 means device no permission
|
|
||||||
public void initUSBPermission(int vid, int pid){
|
|
||||||
UsbManager usbManager = (UsbManager)mContext.getSystemService(Context.USB_SERVICE);
|
|
||||||
UsbDevice usbDevice = null;
|
|
||||||
for (UsbDevice device : usbManager.getDeviceList().values()) {
|
|
||||||
int device_vid = device.getVendorId();
|
|
||||||
int device_pid = device.getProductId();
|
|
||||||
if (device_vid == vid && device_pid == pid)
|
|
||||||
{
|
|
||||||
usbDevice = device;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (null == usbDevice)
|
|
||||||
{
|
|
||||||
zknirusbManagerListener.onCheckPermission(-1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.vid = vid;
|
|
||||||
this.pid = pid;
|
|
||||||
if (!usbManager.hasPermission(usbDevice))
|
|
||||||
{
|
|
||||||
Intent intent = new Intent(this.ACTION_USB_PERMISSION);
|
|
||||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
|
|
||||||
usbManager.requestPermission(usbDevice, pendingIntent);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
zknirusbManagerListener.onCheckPermission(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package com.rehome.meetingbook.ZKUSBManager;
|
|
||||||
|
|
||||||
|
|
||||||
import android.hardware.usb.UsbDevice;
|
|
||||||
|
|
||||||
public interface ZKUSBManagerListener
|
|
||||||
{
|
|
||||||
//0 means success
|
|
||||||
//-1 means device no found
|
|
||||||
//-2 means device no permission
|
|
||||||
void onCheckPermission(int result);
|
|
||||||
|
|
||||||
void onUSBArrived(UsbDevice device);
|
|
||||||
|
|
||||||
void onUSBRemoved(UsbDevice device);
|
|
||||||
}
|
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package com.rehome.meetingbook.bean;
|
||||||
|
|
||||||
|
public class BaseApiBean {
|
||||||
|
//请求标识
|
||||||
|
private int flag;
|
||||||
|
//状态消息
|
||||||
|
private String msg;
|
||||||
|
//请求是否成功
|
||||||
|
private boolean success = false;
|
||||||
|
|
||||||
|
public int getFlag() {
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFlag(int flag) {
|
||||||
|
this.flag = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuccess(boolean success) {
|
||||||
|
this.success = success;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
package com.rehome.meetingbook.bean;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MeetingBookBean extends BaseApiBean{
|
||||||
|
|
||||||
|
private RowsBean data;
|
||||||
|
|
||||||
|
public RowsBean getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(RowsBean data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RowsBean {
|
||||||
|
//会议室名称
|
||||||
|
private String name;
|
||||||
|
//会议室状态
|
||||||
|
private String status;
|
||||||
|
//会议开始时间
|
||||||
|
private String startTime;
|
||||||
|
//会议结束时间
|
||||||
|
private String endTime;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartTime(String startTime) {
|
||||||
|
this.startTime = startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEndTime() {
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndTime(String endTime) {
|
||||||
|
this.endTime = endTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue