use of com.jaku.model.Device in project RoMote by wseemann.
the class AvailableDevicesLoader method loadInBackground.
/**
* This is where the bulk of our work is done. This function is
* called in a background thread and should generate a new set of
* data to be published by the loader.
*/
@Override
public List<Device> loadInBackground() {
// Retrieve all Device.
List<Device> devices = DBUtils.getAllDevices(getContext());
List<Device> availableDevices = new ArrayList<Device>();
try {
List<Device> rokuDevices = DeviceRequests.discoverDevices();
for (Device device : rokuDevices) {
boolean exists = false;
for (int j = 0; j < devices.size(); j++) {
if (devices.get(j).getSerialNumber().equals(device.getSerialNumber())) {
exists = true;
break;
}
}
if (!exists) {
availableDevices.add(device);
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
// Done!
return availableDevices;
}
use of com.jaku.model.Device in project RoMote by wseemann.
the class AltMainActivity method showMenu.
private void showMenu(final View v) {
PopupMenu popup = new PopupMenu(this, v);
// This activity implements OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Device device = (Device) v.getTag();
switch(item.getItemId()) {
case R.id.action_info:
Intent intent = new Intent(AltMainActivity.this, DeviceInfoActivity.class);
intent.putExtra("serial_number", device.getSerialNumber());
intent.putExtra("host", device.getHost());
startActivity(intent);
return true;
case R.id.action_unpair:
PreferenceUtils.setConnectedDevice(AltMainActivity.this, "");
DBUtils.removeDevice(AltMainActivity.this, device.getSerialNumber());
refreshList(false);
return true;
default:
return false;
}
}
});
popup.inflate(R.menu.device_menu);
Device device = (Device) v.getTag();
if (DBUtils.getDevice(this, device.getSerialNumber()) == null) {
popup.getMenu().removeItem(R.id.action_unpair);
}
popup.show();
}
use of com.jaku.model.Device in project RoMote by wseemann.
the class SupportAvailableDevicesLoader method loadInBackground.
/**
* This is where the bulk of our work is done. This function is
* called in a background thread and should generate a new set of
* data to be published by the loader.
*/
@Override
public List<Device> loadInBackground() {
// Retrieve all Device.
List<Device> devices = DBUtils.getAllDevices(getContext());
List<Device> availableDevices = new ArrayList<Device>();
try {
List<Device> rokuDevices = DeviceRequests.discoverDevices();
for (Device device : rokuDevices) {
boolean exists = false;
for (int j = 0; j < devices.size(); j++) {
if (devices.get(j).getSerialNumber().equals(device.getSerialNumber())) {
exists = true;
break;
}
}
if (!exists) {
availableDevices.add(device);
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
// Done!
return availableDevices;
}
use of com.jaku.model.Device in project RoMote by wseemann.
the class CommandHelper method getDeviceURL.
public static String getDeviceURL(Context context) {
String url = "";
try {
Device device = PreferenceUtils.getConnectedDevice(context);
url = device.getHost();
} catch (Exception ex) {
}
return url;
}
use of com.jaku.model.Device in project RoMote by wseemann.
the class PreferenceUtils method getConnectedDevice.
public static Device getConnectedDevice(Context context) throws Exception {
Device device = null;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String serialNumber = prefs.getString("serial_number", null);
device = DBUtils.getDevice(context, serialNumber);
if (device == null) {
throw new Exception("Device not connected");
}
return device;
}
Aggregations