Search in sources :

Example 6 with Device

use of io.spark.core.android.cloud.api.Device in project android-app by spark.

the class DeviceListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.core_row, parent, false);
        ViewHolder holder = new ViewHolder();
        holder.activeStripe = Ui.findView(convertView, R.id.active_core_stripe);
        holder.coreName = Ui.findView(convertView, R.id.core_name);
        convertView.setTag(holder);
    }
    ViewHolder holder = (ViewHolder) convertView.getTag();
    final Device device = getItem(position);
    holder.coreName.setText(device.name);
    Drawable[] compoundDrawables = holder.coreName.getCompoundDrawables();
    GradientDrawable dotDrawable = (GradientDrawable) compoundDrawables[0];
    dotDrawable.setColor(device.color);
    holder.activeStripe.setBackgroundColor(device.color);
    if (convertView.isActivated()) {
        holder.activeStripe.setVisibility(View.VISIBLE);
    } else {
        holder.activeStripe.setVisibility(View.INVISIBLE);
    }
    return convertView;
}
Also used : Device(io.spark.core.android.cloud.api.Device) LayoutInflater(android.view.LayoutInflater) GradientDrawable(android.graphics.drawable.GradientDrawable) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 7 with Device

use of io.spark.core.android.cloud.api.Device in project android-app by spark.

the class CoreListActivity method panelClosed.

private void panelClosed() {
    Ui.findFrag(this, R.id.core_list).setHasOptionsMenu(false);
    Fragment tinkerFrag = Ui.findFrag(this, R.id.tinker_container);
    if (tinkerFrag != null) {
        tinkerFrag.setHasOptionsMenu(true);
    }
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    if (selectedItemId != null) {
        Device selectedDevice = DeviceState.getDeviceById(selectedItemId);
        if (selectedDevice != null && truthy(selectedDevice.name)) {
            setCustomActionBarTitle(selectedDevice.name);
        } else {
            setCustomActionBarTitle(getString(R.string._unnamed_core_));
        }
    } else {
        log.wtf("Selected item is null?");
    }
}
Also used : Device(io.spark.core.android.cloud.api.Device) Fragment(android.app.Fragment) TinkerFragment(io.spark.core.android.ui.tinker.TinkerFragment)

Example 8 with Device

use of io.spark.core.android.cloud.api.Device in project android-app by spark.

the class CoreListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String deviceIdToSelect = null;
    boolean openPane = true;
    // The below is to try to present the user with the "best"
    // activity on launch, but still allowing them to return to the Core
    // list.
    // TODO: document further
    Intent intentToSkipTo = null;
    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(STATE_SELECTED_DEVICE_ID)) {
            deviceIdToSelect = savedInstanceState.getString(STATE_SELECTED_DEVICE_ID);
        }
        if (savedInstanceState.containsKey(STATE_PANE_OPEN)) {
            openPane = savedInstanceState.getBoolean(STATE_PANE_OPEN);
        }
    } else if (getIntent().hasExtra(ARG_SKIP_TO_SMART_CONFIG)) {
        getIntent().removeExtra(ARG_SKIP_TO_SMART_CONFIG);
        intentToSkipTo = new Intent(this, SmartConfigActivity.class);
    } else if (getIntent().hasExtra(ARG_ENTERING_FROM_LAUNCH)) {
        log.i("Known devices count: " + DeviceState.getKnownDevices().size());
        if (DeviceState.getKnownDevices().isEmpty()) {
            intentToSkipTo = new Intent(this, SmartConfigActivity.class);
        } else if (DeviceState.getKnownDevices().size() == 1) {
            Device device = DeviceState.getKnownDevices().get(0);
            deviceIdToSelect = device.id;
        }
        getIntent().removeExtra(ARG_ENTERING_FROM_LAUNCH);
    } else if (getIntent().hasExtra(ARG_SELECT_DEVICE_ID)) {
        deviceIdToSelect = getIntent().getStringExtra(ARG_SELECT_DEVICE_ID);
        getIntent().removeExtra(ARG_SELECT_DEVICE_ID);
    }
    // NOTE EARLY RETURN!
    if (intentToSkipTo != null) {
        startActivity(intentToSkipTo);
        finish();
        return;
    }
    setContentView(R.layout.activity_core_list);
    actionBar = getActionBar();
    initActionBar();
    slidingLayout = (SlidingPaneLayout) findViewById(R.id.sliding_pane_layout);
    slidingLayout.setPanelSlideListener(new SliderListener());
    slidingLayout.getViewTreeObserver().addOnGlobalLayoutListener(new InitialLayoutListener());
    if (openPane) {
        slidingLayout.openPane();
    } else {
        slidingLayout.closePane();
    }
    if (deviceIdToSelect != null) {
        onItemSelected(deviceIdToSelect);
    }
}
Also used : Device(io.spark.core.android.cloud.api.Device) Intent(android.content.Intent) SmartConfigActivity(io.spark.core.android.ui.smartconfig.SmartConfigActivity)

Example 9 with Device

use of io.spark.core.android.cloud.api.Device in project android-app by spark.

the class CoreListActivity method onItemSelected.

/**
	 * Callback method from {@link CoreListFragment.Callbacks} indicating that
	 * the item with the given ID was selected.
	 */
@Override
public void onItemSelected(String id) {
    // same item selected, just close the pane
    if (id.equals(selectedItemId)) {
        slidingLayout.closePane();
        return;
    }
    Device deviceById = DeviceState.getDeviceById(id);
    setCustomActionBarTitle(deviceById.name);
    selectedItemId = id;
    getFragmentManager().beginTransaction().replace(R.id.tinker_container, TinkerFragment.newInstance(id)).commit();
    CoreListFragment listFrag = Ui.findFrag(this, R.id.core_list);
    listFrag.setActivatedItem(selectedItemId);
    slidingLayout.closePane();
}
Also used : Device(io.spark.core.android.cloud.api.Device)

Example 10 with Device

use of io.spark.core.android.cloud.api.Device in project android-app by spark.

the class NamingFragment method nameCurrentCore.

private void nameCurrentCore() {
    String name = coreNameText.getText().toString();
    Device existingDevice = DeviceState.getDeviceById(currentRenameAttemptHexId);
    // is this the name of an existing device?
    if (DeviceState.getExistingCoreNames().contains(name)) {
        // is it the current device?
        if (existingDevice == null || !name.equals(existingDevice.name)) {
            // No, it's not, which means this name belongs to another device
            // for this user, so it's a dupe name -- don't allow it.
            new NamingHelper(getActivity(), api).showDupeNameDialog(null);
            return;
        }
    }
    api.nameCore(currentRenameAttemptHexId, name);
    showProgress(true);
}
Also used : Device(io.spark.core.android.cloud.api.Device) NamingHelper(io.spark.core.android.ui.util.NamingHelper)

Aggregations

Device (io.spark.core.android.cloud.api.Device)12 Fragment (android.app.Fragment)1 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 LayoutInflater (android.view.LayoutInflater)1 SmartConfigActivity (io.spark.core.android.ui.smartconfig.SmartConfigActivity)1 TinkerFragment (io.spark.core.android.ui.tinker.TinkerFragment)1 NamingHelper (io.spark.core.android.ui.util.NamingHelper)1 Type (java.lang.reflect.Type)1 List (java.util.List)1