Android Open Source - BluetoothGlass Bluetooth Devices Adapter






From Project

Back to project page BluetoothGlass.

License

The source code is released under:

GNU General Public License

If you think the Android project BluetoothGlass 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.vicmns.bluetoothglass.client.adapters;
//from   w  w  w  .  j a v  a  2s  .co  m
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.glass.app.Card;
import com.google.android.glass.widget.CardScrollAdapter;
import com.vicmns.bluetoothglass.client.callbacks.CardScrollCallBacks;
import com.vicmns.bluetoothglass.client.models.BluetoothDeviceModel;

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

/**
 * Created by Victor Cervantes on 3/14/14.
 */
public class BluetoothDevicesAdapter extends CardScrollAdapter {
    private Context ctx;
    private List<Card> mCards;
    private List<BluetoothDeviceModel> mDevices;
    private Card card;
    private CardScrollCallBacks cardScrollCallBacks;

    public BluetoothDevicesAdapter(Context ctx) {
        this.ctx = ctx;
        mCards = new ArrayList<Card>();
        mDevices = new ArrayList<BluetoothDeviceModel>();
    }

    public void setCardScrollCallBacks(CardScrollCallBacks cardScrollCallBacks) {
        this.cardScrollCallBacks = cardScrollCallBacks;
    }

    public void add(BluetoothDeviceModel bDevice) {
        for(BluetoothDeviceModel cDevice: mDevices) {
            if(cDevice.getDeviceMACAddress().equals(bDevice.getDeviceMACAddress()))
                return;
        }

        mDevices.add(bDevice);
        mCards.add(createDeviceCard(bDevice));
    }

    private Card createDeviceCard(BluetoothDeviceModel bDevice) {
        card = new Card(ctx);
        card.setText(bDevice.getDeviceName());
        card.setFootnote(bDevice.getDeviceMACAddress());
        return card;
    }

    @Override
    public int findIdPosition(Object arg0) {
        return 0;
    }

    @Override
    public int findItemPosition(Object item) {
        return mDevices.indexOf(item);
    }

    @Override
    public int getCount() {
        return mDevices.size();
    }

    @Override
    public Object getItem(int position) {
        return mDevices.get(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return mCards.get(position).toView();
    }
}




Java Source Code List

com.vicmns.bluetoothglass.client.MainApplication.java
com.vicmns.bluetoothglass.client.activities.BluetoothClient.java
com.vicmns.bluetoothglass.client.activities.MainActivity.java
com.vicmns.bluetoothglass.client.adapters.BluetoothDevicesAdapter.java
com.vicmns.bluetoothglass.client.bluetooth.SendFileToDeviceTask.java
com.vicmns.bluetoothglass.client.callbacks.CardScrollCallBacks.java
com.vicmns.bluetoothglass.client.data.BluetoothParametersHolder.java
com.vicmns.bluetoothglass.client.models.BluetoothDeviceModel.java
com.vicmns.bluetoothglass.client.services.GoogleVoiceTriggerService.java
com.vicmns.bluetoothglass.client.services.SendPictureToDevice.java
com.vicmns.bluetoothglass.client.tools.FileExtensionFilter.java
com.vicmns.bluetoothglass.client.views.CameraView.java
com.vicmns.bluetoothglass.client.views.OverlayView.java
com.vicmns.bluetoothglass.server.MainActivity.java
com.vicmns.bluetoothglass.server.MainApplication.java
com.vicmns.bluetoothglass.server.data.BluetoothParametersHolder.java
com.vicmns.bluetoothglass.server.handlers.BluetoothConnectionHandler.java
com.vicmns.bluetoothglass.server.handlers.BluetoothReadFromSocketHandler.java
com.vicmns.bluetoothglass.server.receivers.DeviceBootReceiver.java
com.vicmns.bluetoothglass.server.service.BluetoothService.java