Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.bluetooth.BluetoothGattCharacteristic;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public final static Object properties[][] = new Object[][] {
            new Object[] { BluetoothGattCharacteristic.PROPERTY_BROADCAST, "is broadcastable" },
            new Object[] { BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS, "has extended properties" },
            new Object[] { BluetoothGattCharacteristic.PROPERTY_INDICATE, "supports indication" },
            new Object[] { BluetoothGattCharacteristic.PROPERTY_NOTIFY, "supports notification" },
            new Object[] { BluetoothGattCharacteristic.PROPERTY_READ, "is readable" },
            new Object[] { BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE, "supports write with signature" },
            new Object[] { BluetoothGattCharacteristic.PROPERTY_WRITE, "can be written" }, new Object[] {
                    BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE, "can be written without response" }, };
    public final static Object permissions[][] = new Object[][] {
            new Object[] { BluetoothGattCharacteristic.PERMISSION_READ, "allows read operations" },
            new Object[] { BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED,
                    "allows encrypted read operations" },
            new Object[] { BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED_MITM,
                    "allows reading with man-in-the-middle protection" },
            new Object[] { BluetoothGattCharacteristic.PERMISSION_WRITE, "allows writes" },
            new Object[] { BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED, "allows encrypted writes" },
            new Object[] { BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM,
                    "allows encrypted writes with man-in-the-middle protection" },
            new Object[] { BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED, "allows signed write operations" },
            new Object[] { BluetoothGattCharacteristic.PERMISSION_WRITE_SIGNED_MITM,
                    "allows signed write operations with man-in-the-middle protection" }, };

    public static String getReadableCharacteristicProperties(BluetoothGattCharacteristic c) {

        List<String> qualities = new ArrayList<String>();

        StringBuilder s = new StringBuilder();

        int cProps = c.getProperties();
        for (Object[] property : properties) {
            if ((cProps & ((Integer) property[0])) != 0) {
                s.append((String) property[1]);
                s.append('\n');
            }
        }

        int cPerms = c.getPermissions();
        for (Object[] permission : permissions) {
            if ((cProps & ((Integer) permission[0])) != 0) {
                s.append((String) permission[1]);
                s.append('\n');
            }
        }

        return s.toString();
    }
}