Back to project page BLEService.
The source code is released under:
Copyright (c) 2014, Ratio LLC. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...
If you think the Android project BLEService listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.bluetooth.bledemo; /* w w w. j a v a2s . c o m*/ import java.util.ArrayList; import java.util.Locale; import android.app.Activity; import android.bluetooth.BluetoothGattCharacteristic; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; public class CharacteristicsListAdapter extends BaseAdapter { private ArrayList<BluetoothGattCharacteristic> mCharacteristics; private LayoutInflater mInflater; public CharacteristicsListAdapter(Activity parent) { super(); mCharacteristics = new ArrayList<BluetoothGattCharacteristic>(); mInflater = parent.getLayoutInflater(); } public void addCharacteristic(BluetoothGattCharacteristic ch) { if(mCharacteristics.contains(ch) == false) { mCharacteristics.add(ch); } } public BluetoothGattCharacteristic getCharacteristic(int index) { return mCharacteristics.get(index); } public void clearList() { mCharacteristics.clear(); } @Override public int getCount() { return mCharacteristics.size(); } @Override public Object getItem(int position) { return getCharacteristic(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // get already available view or create new if necessary FieldReferences fields; if (convertView == null) { convertView = mInflater.inflate(R.layout.peripheral_list_characteristic_item, null); fields = new FieldReferences(); fields.charName = (TextView)convertView.findViewById(R.id.peripheral_list_characteristic_name); fields.charUuid = (TextView)convertView.findViewById(R.id.peripheral_list_characteristic_uuid); convertView.setTag(fields); } else { fields = (FieldReferences) convertView.getTag(); } // set proper values into the view BluetoothGattCharacteristic ch = getCharacteristic(position); String uuid = ch.getUuid().toString().toLowerCase(Locale.getDefault()); String name = BleNamesResolver.resolveCharacteristicName(uuid); fields.charName.setText(name); fields.charUuid.setText(uuid); return convertView; } private class FieldReferences { TextView charName; TextView charUuid; } }