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;
}
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?");
}
}
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);
}
}
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();
}
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);
}
Aggregations