com.vise.log.ViseLog Java Examples

The following examples show how to use com.vise.log.ViseLog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FaceRectView.java    From ViseFace with Apache License 2.0 6 votes vote down vote up
/**
 * 绘制人脸识别框
 *
 * @param mDetectorData
 */
public <T> void drawFaceRect(DetectorData<T> mDetectorData) {
    Canvas canvas = mHolder.lockCanvas();
    if (null == canvas) {
        return;
    }

    if (mDetectorData == null || mDetectorData.getFaceRectList() == null) {
        mHolder.unlockCanvasAndPost(canvas);
        return;
    }

    canvas.drawColor(0, PorterDuff.Mode.CLEAR);
    if (mDetectorData.getFaceRectList() != null && mDetectorData.getFaceRectList().length > 0) {
        for (Rect rect : mDetectorData.getFaceRectList()) {
            FaceUtil.drawFaceRect(canvas, rect, mRectColor, mFaceIsRect);
        }
    } else {
        ViseLog.d("faces:0");
    }

    mHolder.unlockCanvasAndPost(canvas);
}
 
Example #2
Source File: BluetoothDeviceManager.java    From BLE with Apache License 2.0 6 votes vote down vote up
@Override
public void onSuccess(final byte[] data, BluetoothGattChannel bluetoothGattInfo, BluetoothLeDevice bluetoothLeDevice) {
    if (data == null) {
        return;
    }
    ViseLog.i("callback success:" + HexUtil.encodeHexStr(data));
    BusManager.getBus().post(callbackDataEvent.setData(data).setSuccess(true)
            .setBluetoothLeDevice(bluetoothLeDevice)
            .setBluetoothGattChannel(bluetoothGattInfo));
    if (bluetoothGattInfo != null && (bluetoothGattInfo.getPropertyType() == PropertyType.PROPERTY_INDICATE
            || bluetoothGattInfo.getPropertyType() == PropertyType.PROPERTY_NOTIFY)) {
        DeviceMirror deviceMirror = mDeviceMirrorPool.getDeviceMirror(bluetoothLeDevice);
        if (deviceMirror != null) {
            deviceMirror.setNotifyListener(bluetoothGattInfo.getGattInfoKey(), receiveCallback);
        }
    }
}
 
Example #3
Source File: DeviceMirror.java    From BLE with Apache License 2.0 6 votes vote down vote up
/**
 * 连接失败处理
 *
 * @param bleException 回调异常
 */
private void connectFailure(BleException bleException) {
    if (connectRetryCount < BleConfig.getInstance().getConnectRetryCount()) {
        connectRetryCount++;
        if (handler != null) {
            handler.removeMessages(MSG_CONNECT_TIMEOUT);
            handler.sendEmptyMessageDelayed(MSG_CONNECT_RETRY, BleConfig.getInstance().getConnectRetryInterval());
        }
        ViseLog.i("connectFailure connectRetryCount is " + connectRetryCount);
    } else {
        if (bleException instanceof TimeoutException) {
            connectState = ConnectState.CONNECT_TIMEOUT;
        } else {
            connectState = ConnectState.CONNECT_FAILURE;
        }
        close();
        if (connectCallback != null) {
            connectCallback.onConnectFailure(bleException);
        }
        ViseLog.i("connectFailure " + bleException);
    }
}
 
Example #4
Source File: DeviceMirror.java    From BLE with Apache License 2.0 6 votes vote down vote up
/**
 * 清除设备资源,在不使用该设备时调用
 */
public synchronized void clear() {
    ViseLog.i("deviceMirror clear.");
    disconnect();
    refreshDeviceCache();
    close();
    if (bleCallbackMap != null) {
        bleCallbackMap.clear();
    }
    if (receiveCallbackMap != null) {
        receiveCallbackMap.clear();
    }
    if (writeInfoMap != null) {
        writeInfoMap.clear();
    }
    if (readInfoMap != null) {
        readInfoMap.clear();
    }
    if (enableInfoMap != null) {
        enableInfoMap.clear();
    }
    if (handler != null) {
        handler.removeCallbacksAndMessages(null);
    }
}
 
Example #5
Source File: DeviceMirror.java    From BLE with Apache License 2.0 6 votes vote down vote up
/**
 * 写入数据
 *
 * @param data
 */
public void writeData(byte[] data) {
    if (data == null || data.length > 20) {
        ViseLog.e("this data is null or length beyond 20 byte.");
        return;
    }
    if (!checkBluetoothGattInfo(writeInfoMap)) {
        return;
    }
    if (handler != null) {
        handler.removeMessages(MSG_WRITE_DATA_TIMEOUT);
        handler.removeMessages(MSG_WRITE_DATA_RETRY);
    }
    writeDataRetryCount = 0;
    writeData = data;
    write(data);
}
 
Example #6
Source File: DeviceMirror.java    From BLE with Apache License 2.0 6 votes vote down vote up
/**
 * 写入属性描述值,主要用来根据当前属性描述值写入数据到设备
 * @param gatt GATT
 * @param descriptor 属性描述值
 * @param status 当前状态
 */
@Override
public void onDescriptorWrite(BluetoothGatt gatt, final BluetoothGattDescriptor descriptor, final int status) {
    ViseLog.i("onDescriptorWrite  status: " + status + ", data:" + HexUtil.encodeHexStr(descriptor.getValue()) +
            "  ,thread: " + Thread.currentThread());
    if (status == BluetoothGatt.GATT_SUCCESS) {
        handleSuccessData(writeInfoMap, descriptor.getValue(), status, false);
    } else {
        writeFailure(new GattException(status), true);
    }
    if (status == BluetoothGatt.GATT_SUCCESS) {
        handleSuccessData(enableInfoMap, descriptor.getValue(), status, false);
    } else {
        enableFailure(new GattException(status), true);
    }
}
 
Example #7
Source File: DeviceMirror.java    From BLE with Apache License 2.0 6 votes vote down vote up
/**
 * 特征值改变,主要用来接收设备返回的数据信息
 * @param gatt GATT
 * @param characteristic 特征值
 */
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
    ViseLog.i("onCharacteristicChanged data:" + HexUtil.encodeHexStr(characteristic.getValue()) +
            "  ,thread: " + Thread.currentThread());
    for (Map.Entry<String, IBleCallback> receiveEntry : receiveCallbackMap.entrySet()) {
        String receiveKey = receiveEntry.getKey();
        IBleCallback receiveValue = receiveEntry.getValue();
        for (Map.Entry<String, BluetoothGattChannel> gattInfoEntry : enableInfoMap.entrySet()) {
            String bluetoothGattInfoKey = gattInfoEntry.getKey();
            BluetoothGattChannel bluetoothGattInfoValue = gattInfoEntry.getValue();
            if (receiveKey.equals(bluetoothGattInfoKey)) {
                receiveValue.onSuccess(characteristic.getValue(), bluetoothGattInfoValue, bluetoothLeDevice);
            }
        }
    }
}
 
Example #8
Source File: DeviceMirror.java    From BLE with Apache License 2.0 6 votes vote down vote up
/**
 * 发现服务,主要用来获取设备支持的服务列表
 * @param gatt GATT
 * @param status 当前状态
 */
@Override
public void onServicesDiscovered(final BluetoothGatt gatt, final int status) {
    ViseLog.i("onServicesDiscovered  status: " + status + "  ,thread: " + Thread.currentThread());
    if (handler != null) {
        handler.removeMessages(MSG_CONNECT_TIMEOUT);
    }
    if (status == 0) {
        ViseLog.i("onServicesDiscovered connectSuccess.");
        bluetoothGatt = gatt;
        connectState = ConnectState.CONNECT_SUCCESS;
        if (connectCallback != null) {
            isActiveDisconnect = false;
            ViseBle.getInstance().getDeviceMirrorPool().addDeviceMirror(deviceMirror);
            connectCallback.onConnectSuccess(deviceMirror);
        }
    } else {
        connectFailure(new ConnectException(gatt, status));
    }
}
 
Example #9
Source File: DeviceMirror.java    From BLE with Apache License 2.0 6 votes vote down vote up
/**
 * 连接状态改变,主要用来分析设备的连接与断开
 * @param gatt GATT
 * @param status 改变前状态
 * @param newState 改变后状态
 */
@Override
public void onConnectionStateChange(final BluetoothGatt gatt, final int status, final int newState) {
    ViseLog.i("onConnectionStateChange  status: " + status + " ,newState: " + newState +
            "  ,thread: " + Thread.currentThread());
    if (newState == BluetoothGatt.STATE_CONNECTED) {
        gatt.discoverServices();
    } else if (newState == BluetoothGatt.STATE_DISCONNECTED) {
        close();
        if (connectCallback != null) {
            if (handler != null) {
                handler.removeCallbacksAndMessages(null);
            }
            ViseBle.getInstance().getDeviceMirrorPool().removeDeviceMirror(deviceMirror);
            if (status == BluetoothGatt.GATT_SUCCESS) {
                connectState = ConnectState.CONNECT_DISCONNECT;
                connectCallback.onDisconnect(isActiveDisconnect);
            } else {
                connectState = ConnectState.CONNECT_FAILURE;
                connectCallback.onConnectFailure(new ConnectException(gatt, status));
            }
        }
    } else if (newState == BluetoothGatt.STATE_CONNECTING) {
        connectState = ConnectState.CONNECT_PROCESS;
    }
}
 
Example #10
Source File: ViseBle.java    From BLE with Apache License 2.0 6 votes vote down vote up
/**
 * 连接设备
 *
 * @param bluetoothLeDevice
 * @param connectCallback
 */
public void connect(BluetoothLeDevice bluetoothLeDevice, IConnectCallback connectCallback) {
    if (bluetoothLeDevice == null || connectCallback == null) {
        ViseLog.e("This bluetoothLeDevice or connectCallback is null.");
        return;
    }
    if (deviceMirrorPool != null && !deviceMirrorPool.isContainDevice(bluetoothLeDevice)) {
        DeviceMirror deviceMirror = new DeviceMirror(bluetoothLeDevice);
        if (lastDeviceMirror != null && !TextUtils.isEmpty(lastDeviceMirror.getUniqueSymbol())
                && lastDeviceMirror.getUniqueSymbol().equals(deviceMirror.getUniqueSymbol())) {
            deviceMirror = lastDeviceMirror;//防止重复创建设备镜像
        }
        deviceMirror.connect(connectCallback);
        lastDeviceMirror = deviceMirror;
    } else {
        ViseLog.i("This device is connected.");
    }
}
 
Example #11
Source File: FaceDetectorActivity.java    From ViseFace with Apache License 2.0 5 votes vote down vote up
@Override
public void checkPixels(long pixels, boolean isSupport) {
    ViseLog.i("checkPixels" + pixels);
    if (!isSupport) {
        Toast.makeText(mContext, "手机相机像素达不到要求!", Toast.LENGTH_SHORT).show();
        finish();
    }
}
 
Example #12
Source File: DeviceMirror.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 使能失败
 *
 * @param bleException
 * @param isRemoveCall
 */
private void enableFailure(BleException bleException, boolean isRemoveCall) {
    if (receiveDataRetryCount < BleConfig.getInstance().getOperateRetryCount()) {
        receiveDataRetryCount++;
        if (handler != null) {
            handler.removeMessages(MSG_RECEIVE_DATA_TIMEOUT);
            handler.sendEmptyMessageDelayed(MSG_RECEIVE_DATA_RETRY, BleConfig.getInstance().getOperateRetryInterval());
        }
        ViseLog.i("enableFailure receiveDataRetryCount is " + receiveDataRetryCount);
    } else {
        handleFailureData(enableInfoMap, bleException, isRemoveCall);
        ViseLog.i("enableFailure " + bleException);
    }
}
 
Example #13
Source File: DeviceMirror.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 检查BluetoothGattChannel集合是否有值
 *
 * @param bluetoothGattInfoHashMap
 * @return
 */
private boolean checkBluetoothGattInfo(HashMap<String, BluetoothGattChannel> bluetoothGattInfoHashMap) {
    if (bluetoothGattInfoHashMap == null || bluetoothGattInfoHashMap.size() == 0) {
        ViseLog.e("this bluetoothGattInfo map is not value.");
        return false;
    }
    return true;
}
 
Example #14
Source File: FaceDetectorActivity.java    From ViseFace with Apache License 2.0 5 votes vote down vote up
@Override
public void checkPermission(boolean isAllow) {
    ViseLog.i("checkPermission" + isAllow);
    if (!isAllow) {
        Toast.makeText(mContext, "权限申请被拒绝,请进入设置打开权限再试!", Toast.LENGTH_SHORT).show();
        finish();
    }
}
 
Example #15
Source File: ViseBle.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 连接指定设备名称的设备
 *
 * @param name            设备名称
 * @param connectCallback 连接回调
 */
public void connectByName(String name, final IConnectCallback connectCallback) {
    if (name == null || connectCallback == null) {
        ViseLog.e("This name or connectCallback is null.");
        return;
    }
    startScan(new SingleFilterScanCallback(new IScanCallback() {
        @Override
        public void onDeviceFound(BluetoothLeDevice bluetoothLeDevice) {

        }

        @Override
        public void onScanFinish(final BluetoothLeDeviceStore bluetoothLeDeviceStore) {
            if (bluetoothLeDeviceStore.getDeviceList().size() > 0) {
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        connect(bluetoothLeDeviceStore.getDeviceList().get(0), connectCallback);
                    }
                });
            } else {
                connectCallback.onConnectFailure(new TimeoutException());
            }
        }

        @Override
        public void onScanTimeout() {
            connectCallback.onConnectFailure(new TimeoutException());
        }

    }).setDeviceName(name));
}
 
Example #16
Source File: DeviceMirror.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 读取数据失败
 *
 * @param bleException
 * @param isRemoveCall
 */
private void readFailure(BleException bleException, boolean isRemoveCall) {
    if (readDataRetryCount < BleConfig.getInstance().getOperateRetryCount()) {
        readDataRetryCount++;
        if (handler != null) {
            handler.removeMessages(MSG_READ_DATA_TIMEOUT);
            handler.sendEmptyMessageDelayed(MSG_READ_DATA_RETRY, BleConfig.getInstance().getOperateRetryInterval());
        }
        ViseLog.i("readFailure readDataRetryCount is " + readDataRetryCount);
    } else {
        handleFailureData(readInfoMap, bleException, isRemoveCall);
        ViseLog.i("readFailure " + bleException);
    }
}
 
Example #17
Source File: DeviceMirror.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 写入数据失败
 *
 * @param bleException
 * @param isRemoveCall
 */
private void writeFailure(BleException bleException, boolean isRemoveCall) {
    if (writeDataRetryCount < BleConfig.getInstance().getOperateRetryCount()) {
        writeDataRetryCount++;
        if (handler != null) {
            handler.removeMessages(MSG_WRITE_DATA_TIMEOUT);
            handler.sendEmptyMessageDelayed(MSG_WRITE_DATA_RETRY, BleConfig.getInstance().getOperateRetryInterval());
        }
        ViseLog.i("writeFailure writeDataRetryCount is " + writeDataRetryCount);
    } else {
        handleFailureData(writeInfoMap, bleException, isRemoveCall);
        ViseLog.i("writeFailure " + bleException);
    }
}
 
Example #18
Source File: DeviceScanActivity.java    From BLE with Apache License 2.0 5 votes vote down vote up
@Override
public void onDeviceFound(final BluetoothLeDevice bluetoothLeDevice) {
    ViseLog.i("Founded Scan Device:" + bluetoothLeDevice);
    bluetoothLeDeviceStore.addDevice(bluetoothLeDevice);
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (adapter != null && bluetoothLeDeviceStore != null) {
                adapter.setListAll(bluetoothLeDeviceStore.getDeviceList());
                updateItemCount(adapter.getCount());
            }
        }
    });
}
 
Example #19
Source File: MainActivity.java    From BLE with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ViseLog.getLogConfig().configAllowLog(true);//配置日志信息
    ViseLog.plant(new LogcatTree());//添加Logcat打印信息
    BluetoothDeviceManager.getInstance().init(this);
    BusManager.getBus().register(this);
    init();
}
 
Example #20
Source File: BluetoothDeviceManager.java    From BLE with Apache License 2.0 5 votes vote down vote up
@Override
public void onSuccess(final byte[] data, BluetoothGattChannel bluetoothGattInfo, BluetoothLeDevice bluetoothLeDevice) {
    if (data == null) {
        return;
    }
    ViseLog.i("notify success:" + HexUtil.encodeHexStr(data));
    BusManager.getBus().post(notifyDataEvent.setData(data)
            .setBluetoothLeDevice(bluetoothLeDevice)
            .setBluetoothGattChannel(bluetoothGattInfo));
}
 
Example #21
Source File: BluetoothDeviceManager.java    From BLE with Apache License 2.0 5 votes vote down vote up
@Override
public void onFailure(BleException exception) {
    if (exception == null) {
        return;
    }
    ViseLog.i("notify fail:" + exception.getDescription());
}
 
Example #22
Source File: BluetoothDeviceManager.java    From BLE with Apache License 2.0 5 votes vote down vote up
@Override
public void onFailure(BleException exception) {
    if (exception == null) {
        return;
    }
    ViseLog.i("callback fail:" + exception.getDescription());
    BusManager.getBus().post(callbackDataEvent.setSuccess(false));
}
 
Example #23
Source File: MainActivity.java    From ViseLog with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.print_normal_message:
            Log.v("message", "test message");
            ViseLog.v("test message");
            break;
        case R.id.print_normal_object:
            ViseLog.i(new Boolean(true));
            break;
        case R.id.print_bundle_object:
            ViseLog.d(new Bundle());
            break;
        case R.id.print_collection_object:
            printList();
            break;
        case R.id.print_intent_object:
            ViseLog.w(new Intent());
            break;
        case R.id.print_map_object:
            printMap();
            break;
        case R.id.print_reference_object:
            ViseLog.wtf(new SoftReference(0));
            break;
        case R.id.print_throwable_object:
            ViseLog.e(new NullPointerException("this object is null!"));
            break;
        case R.id.print_json_message:
            printJson();
            break;
        case R.id.print_xml_message:
            printXml();
            break;
        default:
            break;
    }
}
 
Example #24
Source File: MainActivity.java    From ViseLog with Apache License 2.0 5 votes vote down vote up
private void printList() {
    List<String> list = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        list.add("test" + i);
    }
    ViseLog.i(list);
}
 
Example #25
Source File: MainActivity.java    From ViseLog with Apache License 2.0 5 votes vote down vote up
private void printMap() {
    Map<String, String> map = new HashMap<>();
    for (int i = 0; i < 5; i++) {
        map.put("xyy" + i, "test" + i);
    }
    ViseLog.d(map);
}
 
Example #26
Source File: AppApplication.java    From ViseLog with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    if(BuildConfig.DEBUG){
        ViseLog.getLogConfig().configAllowLog(true)
                .configShowBorders(false);
        ViseLog.plant(new FileTree(this, "Log"));
        ViseLog.plant(new ConsoleTree());
        ViseLog.plant(new LogcatTree());
    }
}
 
Example #27
Source File: Tree.java    From ViseLog with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前堆栈信息
 * @return
 */
private StackTraceElement getCurrentStackTrace() {
    StackTraceElement[] trace = Thread.currentThread().getStackTrace();
    int stackOffset = getStackOffset(trace, ViseLog.class);
    if (stackOffset == -1) {
        return null;
    }
    return trace[stackOffset];
}
 
Example #28
Source File: Tree.java    From ViseLog with Apache License 2.0 5 votes vote down vote up
/**
 * 获取堆栈信息下标
 * @param trace
 * @param cla
 * @return
 */
private int getStackOffset(StackTraceElement[] trace, Class cla) {
    for (int i = LogConstant.MIN_STACK_OFFSET; i < trace.length; i++) {
        StackTraceElement e = trace[i];
        String name = e.getClassName();
        if (cla.equals(ViseLog.class) && i < trace.length - 1 && trace[i + 1].getClassName()
                .equals(ViseLog.class.getName())) {
            continue;
        }
        if (name.equals(cla.getName())) {
            return ++i;
        }
    }
    return -1;
}
 
Example #29
Source File: HexUtil.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 将字节数组转换为十六进制字符串
 *
 * @param data     byte[]
 * @param toDigits 用于控制输出的char[]
 * @return 十六进制String
 */
protected static String encodeHexStr(byte[] data, char[] toDigits) {
    if (data == null) {
        ViseLog.e("this data is null.");
        return "";
    }
    return new String(encodeHex(data, toDigits));
}
 
Example #30
Source File: DeviceMirror.java    From BLE with Apache License 2.0 5 votes vote down vote up
/**
 * 连接设备
 *
 * @param connectCallback
 */
public synchronized void connect(IConnectCallback connectCallback) {
    if (connectState == ConnectState.CONNECT_SUCCESS || connectState == ConnectState.CONNECT_PROCESS
            || (connectState == ConnectState.CONNECT_INIT && connectRetryCount != 0)) {
        ViseLog.e("this connect state is connecting, connectSuccess or current retry count less than config connect retry count.");
        return;
    }
    if (handler != null) {
        handler.removeCallbacksAndMessages(null);
    }
    this.connectCallback = connectCallback;
    connectRetryCount = 0;
    connect();
}