@@ -0,0 +1,2275 @@
+package com.uxxu.konashi.lib;%0A%0Aimport android.bluetooth.BluetoothGatt;%0Aimport android.bluetooth.BluetoothGattCharacteristic;%0Aimport android.bluetooth.BluetoothGattService;%0Aimport android.os.Handler;%0Aimport android.os.HandlerThread;%0Aimport android.os.Message;%0Aimport android.util.Log;%0A%0Aimport com.uxxu.konashi.lib.entities.KonashiReadMessage;%0Aimport com.uxxu.konashi.lib.entities.KonashiWriteMessage;%0A%0A/**%0A * Created by izumin on 8/4/15.%0A */%0Apublic class KonashiMessageHandler extends Handler %7B%0A    public static final String TAG = KonashiMessageHandler.class.getSimpleName();%0A%0A    public static final int MESSAGE_WRITE = 0, MESSAGE_READ = 1;%0A%0A    private HandlerThread mHandlerThread;%0A    private BluetoothGatt mBluetoothGatt;%0A%0A    public KonashiMessageHandler(HandlerThread handlerThread) %7B%0A        super(handlerThread.getLooper());%0A        mHandlerThread = handlerThread;%0A    %7D%0A%0A    public void start() %7B%0A        mHandlerThread.start();%0A    %7D%0A%0A    public boolean stop() %7B%0A        return mHandlerThread.quitSafely();%0A    %7D%0A%0A    public void setBluetoothGatt(BluetoothGatt bluetoothGatt) %7B%0A        mBluetoothGatt = bluetoothGatt;%0A    %7D%0A%0A    @Override%0A    public void handleMessage(Message msg) %7B%0A        switch (msg.what) %7B%0A            case MESSAGE_WRITE:%0A                writeValue(new KonashiWriteMessage(msg.getData()));%0A                break;%0A            case MESSAGE_READ:%0A                readValue(new KonashiReadMessage(msg.getData()));%0A                break;%0A        %7D%0A    %7D%0A%0A    private void writeValue(KonashiWriteMessage msg) %7B%0A        if (mBluetoothGatt == null) %7B return; %7D%0A        BluetoothGattService service = mBluetoothGatt.getService(KonashiUUID.KONASHI_SERVICE_UUID);%0A        BluetoothGattCharacteristic characteristic = service.getCharacteristic(msg.getCharacteristicUuid());%0A        characteristic.setValue(msg.getData());%0A        mBluetoothGatt.writeCharacteristic(characteristic);%0A    %7D%0A%0A    private void readValue(KonashiReadMessage msg) %7B%0A        if (mBluetoothGatt == null) %7B return; %7D%0A        BluetoothGattService service = mBluetoothGatt.getService(msg.getServiceUuid());%0A        BluetoothGattCharacteristic characteristic = service.getCharacteristic(msg.getCharacteristicUuid());%0A        mBluetoothGatt.readCharacteristic(characteristic);%0A    %7D%0A%7D%0A

Add KonashiMessageHandler