Android Open Source - Bluetooth-Manager-for-Glass Ble Characteristic Card Scroll Adapter

From Project

Back to project page Bluetooth-Manager-for-Glass.


The source code is released under:

MIT License

If you think the Android project Bluetooth-Manager-for-Glass listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.recursivepenguin.bluetoothmanagerforglass.ble;
// w  ww  .j  a v  a  2  s. c  om
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.movisens.smartgattlib.Characteristic;
import com.recursivepenguin.bluetoothmanagerforglass.R;

import java.util.List;

public class BleCharacteristicCardScrollAdapter extends CardScrollAdapter {
    List<BluetoothGattCharacteristic> mBleCharacteristics;

    Context context;

    public BleCharacteristicCardScrollAdapter(Context context, List<BluetoothGattCharacteristic> characteristics) {
        mBleCharacteristics = characteristics;
        this.context = context;

    public int getPosition(Object item) {
        return mBleCharacteristics.indexOf(item);

    public int getCount() {
        return mBleCharacteristics.size();

    public BluetoothGattCharacteristic getItem(int position) {
        return mBleCharacteristics.get(position);

    class ViewHolder {
        ImageView icon;
        TextView name;
        TextView text;
        TextView raw;

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.ble_chara_card, null);
            holder = new ViewHolder();

            holder.icon = (ImageView) convertView.findViewById(;
   = (TextView) convertView.findViewById(;
            holder.text = (TextView) convertView.findViewById(;
            holder.raw = (TextView) convertView.findViewById(;
        else {
            holder = (ViewHolder) convertView.getTag();

        BluetoothGattCharacteristic characteristic = getItem(position);, characteristic.getUuid().toString()));

        final byte[] data = characteristic.getValue();
        if (data != null && data.length > 0) {
            String text = characteristic.getStringValue(0);

            final StringBuilder stringBuilder = new StringBuilder(data.length);
            for (byte byteChar : data)
                stringBuilder.append(String.format("%02X ", byteChar));

        return convertView;

Java Source Code List