Search in sources :

Example 21 with GBDevice

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.

the class PebblePairingActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pebble_pairing);
    message = (TextView) findViewById(R.id.pebble_pair_message);
    Intent intent = getIntent();
    GBDeviceCandidate candidate = intent.getParcelableExtra(DeviceCoordinator.EXTRA_DEVICE_CANDIDATE);
    if (candidate != null) {
        macAddress = candidate.getMacAddress();
    }
    if (macAddress == null) {
        Toast.makeText(this, getString(R.string.message_cannot_pair_no_mac), Toast.LENGTH_SHORT).show();
        returnToPairingActivity();
        return;
    }
    mBtDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddress);
    if (mBtDevice == null) {
        GB.toast(this, "No such Bluetooth Device: " + macAddress, Toast.LENGTH_LONG, GB.ERROR);
        returnToPairingActivity();
        return;
    }
    isLEPebble = mBtDevice.getType() == BluetoothDevice.DEVICE_TYPE_LE;
    GBDevice gbDevice = null;
    if (isLEPebble) {
        if (mBtDevice.getName().startsWith("Pebble-LE ") || mBtDevice.getName().startsWith("Pebble Time LE ")) {
            if (!GBApplication.getPrefs().getBoolean("pebble_force_le", false)) {
                GB.toast(this, "Please switch on \"Always prefer BLE\" option in Pebble settings before pairing you Pebble LE", Toast.LENGTH_LONG, GB.ERROR);
                returnToPairingActivity();
                return;
            }
            gbDevice = getMatchingParentDeviceFromDB(mBtDevice);
            if (gbDevice == null) {
                return;
            }
        }
    }
    startPairing(gbDevice);
}
Also used : GBDeviceCandidate(nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate) Intent(android.content.Intent) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Example 22 with GBDevice

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.

the class DBHelper method findDevice.

public static Device findDevice(GBDevice gbDevice, DaoSession session) {
    DeviceDao deviceDao = session.getDeviceDao();
    Query<Device> query = deviceDao.queryBuilder().where(DeviceDao.Properties.Identifier.eq(gbDevice.getAddress())).build();
    List<Device> devices = query.list();
    if (devices.size() > 0) {
        return devices.get(0);
    }
    return null;
}
Also used : Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) DeviceDao(nodomain.freeyourgadget.gadgetbridge.entities.DeviceDao)

Example 23 with GBDevice

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDevice in project Gadgetbridge by Freeyourgadget.

the class DBHelper method getDevice.

/**
     * Looks up in the database the Device entity corresponding to the GBDevice. If a device
     * exists already, it will be updated with the current preferences values. If no device exists
     * yet, it will be created in the database.
     *
     * @param session
     * @return the device entity corresponding to the given GBDevice
     */
public static Device getDevice(GBDevice gbDevice, DaoSession session) {
    Device device = findDevice(gbDevice, session);
    if (device == null) {
        device = createDevice(gbDevice, session);
    } else {
        ensureDeviceUpToDate(device, gbDevice, session);
    }
    ensureDeviceAttributes(device, gbDevice, session);
    return device;
}
Also used : Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Aggregations

GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)23 Device (nodomain.freeyourgadget.gadgetbridge.entities.Device)7 BluetoothDevice (android.bluetooth.BluetoothDevice)4 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)3 DeviceAttributes (nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes)3 Test (org.junit.Test)3 Intent (android.content.Intent)2 View (android.view.View)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 DaoSession (nodomain.freeyourgadget.gadgetbridge.entities.DaoSession)2 DeviceDao (nodomain.freeyourgadget.gadgetbridge.entities.DeviceDao)2 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 BluetoothAdapter (android.bluetooth.BluetoothAdapter)1 DialogInterface (android.content.DialogInterface)1 IntentFilter (android.content.IntentFilter)1 Uri (android.net.Uri)1 Snackbar (android.support.design.widget.Snackbar)1