Android Open Source - BluetoothHidEmu Bluetooth Device Array Adapter






From Project

Back to project page BluetoothHidEmu.

License

The source code is released under:

Apache License

If you think the Android project BluetoothHidEmu 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 andraus.bluetoothhidemu.view;
// www .  j a va2  s .  c  o  m
import java.util.Set;

import andraus.bluetoothhidemu.R;
import andraus.bluetoothhidemu.settings.Settings;
import andraus.bluetoothhidemu.spoof.Spoof.SpoofMode;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * Custom ArrayAdapter
 *
 */
public class BluetoothDeviceArrayAdapter extends ArrayAdapter<BluetoothDeviceView> {
    
    /**
     * Constructor
     * 
     * Note: ArrayAdapter will be empty. needs to be populate afterwards.
     * 
     * @param context
     */
    public BluetoothDeviceArrayAdapter(Context context) {
        super(context, R.layout.spinner_layout);
        setDropDownViewResource(R.layout.spinner_dropdown_layout);
        setNotifyOnChange(true);
    }
    
    /**
     * Re-populates the adapter. Will clean any previous data.
     * 
     * @param bondedDeviceSet
     */
    public void rePopulate(Set<BluetoothDevice> bondedDeviceSet) {

        if (!isEmpty()) {
            clear();
        }
        
        //Add "null" element
        add(BluetoothDeviceView.getNullBluetoothDeviceView(getContext().getResources().getString(R.string.msg_device_list_null)));
        
        for (BluetoothDevice device: bondedDeviceSet) {
            BluetoothDeviceView deviceView = new BluetoothDeviceView(device, Settings.getEmulationMode(getContext(), device));
            add(deviceView);
        }
        
        sort(BluetoothDeviceView.getComparator());
        
    }

    /**
     * 
     * @param bluetoothAddress
     * @return
     */
    public int getPositionByAddress(String bluetoothAddress) {
        for (int i = 0; i < getCount(); i++) {
            BluetoothDeviceView deviceView = getItem(i);
            if (deviceView.getAddress().equals(bluetoothAddress)) {
                return i;
            }
        }
        
        return -1;
    }
    
    /**
     * Returns the position for null element (tipically 0)
     * @return
     */
    public int getNullPosition() {
        for (int i = 0; i < getCount(); i++) {
            BluetoothDeviceView deviceView = getItem(i);
            if (deviceView.isNull()) {
                return i;
            }
        }
        
        throw new IllegalStateException("No null value found!");
    }
    
    /**
     * 
     */
    @Override
    public void add(BluetoothDeviceView deviceView) {
        if (deviceView.getSpoofMode() != SpoofMode.INVALID) {
            super.add(deviceView);
        }
    }

    /**
     * 
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        // Set spinner text to "empty" if null element is selected (disconnect option)
        View view = super.getView(position, convertView, parent);
        if (getItem(position).isNull()) {
            ((TextView) view).setText("");
        }
        
        return view;
    }
    
    

}




Java Source Code List

andraus.bluetoothhidemu.BluetoothHidEmuActivity.java
andraus.bluetoothhidemu.ButtonClickListener.java
andraus.bluetoothhidemu.Constants.java
andraus.bluetoothhidemu.KeyboardKeyListener.java
andraus.bluetoothhidemu.KeyboardTextWatcher.java
andraus.bluetoothhidemu.SpecialKeyListener.java
andraus.bluetoothhidemu.TouchpadListener.java
andraus.bluetoothhidemu.settings.BluetoothAdapterStateReceiver.java
andraus.bluetoothhidemu.settings.BluetoothDeviceStateReceiver.java
andraus.bluetoothhidemu.settings.Settings.java
andraus.bluetoothhidemu.sock.BluetoothSocketThread.java
andraus.bluetoothhidemu.sock.SocketManager.java
andraus.bluetoothhidemu.sock.payload.HidConsumerPayload.java
andraus.bluetoothhidemu.sock.payload.HidKeyPair.java
andraus.bluetoothhidemu.sock.payload.HidKeyboardPayload.java
andraus.bluetoothhidemu.sock.payload.HidPayload.java
andraus.bluetoothhidemu.sock.payload.HidPointerPayload.java
andraus.bluetoothhidemu.sock.payload.HidSixaxisPayload.java
andraus.bluetoothhidemu.spoof.BluetoothAdapterSpooferFactory.java
andraus.bluetoothhidemu.spoof.BluetoothAdapterSpooferGeneric.java
andraus.bluetoothhidemu.spoof.BluetoothAdapterSpooferMotoReflect.java
andraus.bluetoothhidemu.spoof.BluetoothAdapterSpooferMoto.java
andraus.bluetoothhidemu.spoof.BluetoothAdapterSpoofer.java
andraus.bluetoothhidemu.spoof.CleanupExceptionHandler.java
andraus.bluetoothhidemu.spoof.Spoof.java
andraus.bluetoothhidemu.spoof.jni.BluetoothSocketJni.java
andraus.bluetoothhidemu.ui.GenericUiControls.java
andraus.bluetoothhidemu.ui.Ps3KeypadUiControls.java
andraus.bluetoothhidemu.ui.UiControls.java
andraus.bluetoothhidemu.util.DoLog.java
andraus.bluetoothhidemu.view.ArrowButton.java
andraus.bluetoothhidemu.view.BluetoothDeviceArrayAdapter.java
andraus.bluetoothhidemu.view.BluetoothDeviceView.java
andraus.bluetoothhidemu.view.EchoEditText.java
andraus.bluetoothhidemu.view.ViewUtils.java