Search in sources :

Example 6 with Device

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;
}
Also used : Device(com.jaku.model.Device) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 7 with Device

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();
}
Also used : Device(com.jaku.model.Device) MenuItem(android.view.MenuItem) Intent(android.content.Intent) PopupMenu(android.support.v7.widget.PopupMenu)

Example 8 with Device

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;
}
Also used : Device(com.jaku.model.Device) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 9 with Device

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;
}
Also used : Device(com.jaku.model.Device)

Example 10 with Device

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;
}
Also used : SharedPreferences(android.content.SharedPreferences) Device(com.jaku.model.Device)

Aggregations

Device (com.jaku.model.Device)20 ArrayList (java.util.ArrayList)6 Intent (android.content.Intent)5 RokuRequestTypes (wseemann.media.romote.utils.RokuRequestTypes)4 SharedPreferences (android.content.SharedPreferences)3 Bundle (android.os.Bundle)3 View (android.view.View)3 TextView (android.widget.TextView)3 JakuRequest (com.jaku.core.JakuRequest)3 DeviceParser (com.jaku.parser.DeviceParser)3 QueryDeviceInfoRequest (com.jaku.request.QueryDeviceInfoRequest)3 RequestCallback (wseemann.media.romote.tasks.RequestCallback)3 RequestTask (wseemann.media.romote.tasks.RequestTask)3 SuppressLint (android.annotation.SuppressLint)2 AppWidgetManager (android.appwidget.AppWidgetManager)2 ComponentName (android.content.ComponentName)2 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 PopupMenu (android.support.v7.widget.PopupMenu)2 MenuItem (android.view.MenuItem)2