BluetoothDeviceCardScrollAdapter.java
Go to the documentation of this file.
00001 package com.riverlab.robotmanager.bluetooth;
00002 
00003 import android.bluetooth.BluetoothDevice;
00004 import android.content.Context;
00005 import android.view.View;
00006 import android.view.ViewGroup;
00007 import android.widget.ImageView;
00008 import android.widget.TextView;
00009 
00010 import com.google.android.glass.widget.CardScrollAdapter;
00011 import com.riverlab.robotmanager.R;
00012 import com.riverlab.robotmanager.R.id;
00013 import com.riverlab.robotmanager.R.layout;
00014 
00015 import java.util.List;
00016 
00017 public class BluetoothDeviceCardScrollAdapter extends CardScrollAdapter {
00018     List<BluetoothDevice> mBondedDevices;
00019 
00020     Context context;
00021 
00022     public BluetoothDeviceCardScrollAdapter(Context context, List<BluetoothDevice> devices) {
00023         mBondedDevices = devices;
00024         this.context = context;
00025     }
00026 
00027     public void addDevice(BluetoothDevice device) {
00028         mBondedDevices.add(device);
00029     }
00030 
00031     @Override
00032     public int getCount() {
00033         return mBondedDevices.size();
00034     }
00035 
00036     @Override
00037     public BluetoothDevice getItem(int position) {
00038         return mBondedDevices.get(position);
00039     }
00040 
00041     class ViewHolder {
00042         ImageView icon;
00043         TextView name;
00044         TextView address;
00045     }
00046 
00047     @Override
00048     public View getView(int position, View convertView, ViewGroup parent) {
00049         ViewHolder holder;
00050         if (convertView == null) {
00051             convertView = View.inflate(context, R.layout.device_card, null);
00052             holder = new ViewHolder();
00053 
00054             holder.icon = (ImageView) convertView.findViewById(R.id.imageView);
00055             holder.name = (TextView) convertView.findViewById(R.id.name);
00056             holder.address = (TextView) convertView.findViewById(R.id.address);
00057 
00058             convertView.setTag(holder);
00059         }
00060         else {
00061             holder = (ViewHolder) convertView.getTag();
00062         }
00063 
00064         BluetoothDevice device = getItem(position);
00065         holder.name.setText(device.getName());
00066         holder.address.setText(device.getAddress());
00067 
00068         return convertView;
00069     }
00070 
00071         @Override
00072         public int getPosition(Object arg0) {
00073                 // TODO Auto-generated method stub
00074                 return 0;
00075         }
00076 }


google_glass_driver
Author(s): Nicholas Otero
autogenerated on Fri Aug 28 2015 10:51:44