io.particle.android.sdk.cloud.ParticleDevice Java Examples
The following examples show how to use
io.particle.android.sdk.cloud.ParticleDevice.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CheckIfDeviceClaimedStep.java From particle-android with Apache License 2.0 | 6 votes |
@Override protected void onRunStep() throws SetupStepException { List<ParticleDevice> devices; try { devices = sparkCloud.getDevices(); } catch (ParticleCloudException e) { throw new SetupStepException(e); } log.d("Got devices back from the cloud..."); for (ParticleDevice device : devices) { if (deviceBeingConfiguredId.equalsIgnoreCase(device.getId())) { log.d("Success, device " + device.getId() + " claimed!"); needToClaimDevice = false; return; } } // device not found in the loop throw new SetupStepException("Device " + deviceBeingConfiguredId + " still not claimed."); }
Example #2
Source File: SuccessActivity.java From particle-android with Apache License 2.0 | 6 votes |
private void finishSetup(Context context, String deviceName, boolean isSuccess) { ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, true); Async.executeAsync(particleCloud, new Async.ApiWork<ParticleCloud, Void>() { @Override public Void callApi(@NonNull ParticleCloud cloud) throws ParticleCloudException, IOException { ParticleDevice device = particleCloud.getDevice(getIntent().getStringExtra(EXTRA_DEVICE_ID)); setDeviceName(device, deviceName); return null; } @Override public void onSuccess(@NonNull Void result) { leaveActivity(context, isSuccess); } @Override public void onFailure(@NonNull ParticleCloudException e) { ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, false); deviceNameView.setError(getString(R.string.device_naming_failure)); } }); }
Example #3
Source File: SuccessActivity.java From spark-setup-android with Apache License 2.0 | 6 votes |
private void finishSetup(Context context, String deviceName, boolean isSuccess) { ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, true); Async.executeAsync(particleCloud, new Async.ApiWork<ParticleCloud, Void>() { @Override public Void callApi(@NonNull ParticleCloud cloud) throws ParticleCloudException, IOException { ParticleDevice device = particleCloud.getDevice(getIntent().getStringExtra(EXTRA_DEVICE_ID)); setDeviceName(device, deviceName); return null; } @Override public void onSuccess(@NonNull Void result) { leaveActivity(context, isSuccess); } @Override public void onFailure(@NonNull ParticleCloudException e) { ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, false); deviceNameView.setError(getString(R.string.device_naming_failure)); } }); }
Example #4
Source File: CheckIfDeviceClaimedStep.java From spark-setup-android with Apache License 2.0 | 6 votes |
@Override protected void onRunStep() throws SetupStepException { List<ParticleDevice> devices; try { devices = sparkCloud.getDevices(); } catch (ParticleCloudException e) { throw new SetupStepException(e); } log.d("Got devices back from the cloud..."); for (ParticleDevice device : devices) { if (deviceBeingConfiguredId.equalsIgnoreCase(device.getID())) { log.d("Success, device " + device.getID() + " claimed!"); needToClaimDevice = false; return; } } // device not found in the loop throw new SetupStepException("Device " + deviceBeingConfiguredId + " still not claimed."); }
Example #5
Source File: UnclaimHelper.java From particle-android with Apache License 2.0 | 5 votes |
private static void unclaim(final Activity activity, final ParticleDevice device) { try { Async.executeAsync(device, new Async.ApiWork<ParticleDevice, Void>() { @Override public Void callApi(@NonNull ParticleDevice sparkDevice) throws ParticleCloudException, IOException { device.unclaim(); return null; } @Override public void onSuccess(@NonNull Void aVoid) { // FIXME: what else should happen here? Toaster.s(activity, "Unclaimed " + device.getName()); } @Override public void onFailure(@NonNull ParticleCloudException exception) { new AlertDialog.Builder(activity) .setMessage("Error: unable to unclaim '" + device.getName() + "'") .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss()) .show(); } }).andIgnoreCallbacksIfActivityIsFinishing(activity); } catch (ParticleCloudException e) { new AlertDialog.Builder(activity) .setMessage("Error: unable to unclaim '" + device.getName() + "'") .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss()) .show(); } }
Example #6
Source File: ConnectingProcessWorkerTask.java From particle-android with Apache License 2.0 | 5 votes |
@Override protected void onPostExecute(SetupProcessException error) { int resultCode; if (error != null) { resultCode = error.failedStep.getStepConfig().resultCode; } else { log.d("HUZZAH, VICTORY!"); resultCode = SuccessActivity.RESULT_SUCCESS; if (!BaseActivity.setupOnly) { EZ.runAsync(() -> { try { // collect a list of unique, non-null device names Set<String> names = set(Funcy.transformList( sparkCloud.getDevices(), Funcy.notNull(), ParticleDevice::getName, Py::truthy )); ParticleDevice device = sparkCloud.getDevice(deviceId); if (device != null && !truthy(device.getName())) { device.setName(CoreNameGenerator.generateUniqueName(names)); } } catch (Exception e) { e.printStackTrace(); } }); } } Activity activity = activityReference.get(); if (activity != null) { activity.startActivity(SuccessActivity.buildIntent(activity, resultCode, deviceId)); activity.finish(); } }
Example #7
Source File: UnclaimHelper.java From particle-android with Apache License 2.0 | 5 votes |
static void unclaimDeviceWithDialog(final FragmentActivity activity, final ParticleDevice device) { new AlertDialog.Builder(activity) .setMessage(R.string.unclaim_device_dialog_content) .setPositiveButton(R.string.unclaim, (dialog, which) -> unclaim(activity, device)) .setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()) .show(); }
Example #8
Source File: Async.java From particle-android with Apache License 2.0 | 5 votes |
public static <T> AsyncApiWorker<ParticleDevice, T> executeAsync(ParticleDevice particleDevice, ApiWork<ParticleDevice, T> work) throws ParticleCloudException { try { return (AsyncApiWorker<ParticleDevice, T>) new AsyncApiWorker<>(particleDevice, work) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (RejectedExecutionException ex) { throw new ParticleCloudException(ex); } }
Example #9
Source File: Async.java From spark-sdk-android with Apache License 2.0 | 5 votes |
public static <T> AsyncApiWorker<ParticleDevice, T> executeAsync(ParticleDevice particleDevice, ApiWork<ParticleDevice, T> work) throws ParticleCloudException { try { return (AsyncApiWorker<ParticleDevice, T>) new AsyncApiWorker<>(particleDevice, work) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (RejectedExecutionException ex) { throw new ParticleCloudException(ex); } }
Example #10
Source File: PartialDeviceListResultException.java From spark-sdk-android with Apache License 2.0 | 4 votes |
public PartialDeviceListResultException(List<ParticleDevice> devices) { super("Undefined error while fetching devices"); this.devices = devices; }
Example #11
Source File: SuccessActivity.java From spark-setup-android with Apache License 2.0 | 4 votes |
private void setDeviceName(ParticleDevice device, String deviceName) throws ParticleCloudException { //Set new device name only if it changed if (device.getName() != null && !device.getName().equals(deviceName)) { device.setName(deviceName); } }
Example #12
Source File: DeviceStateChange.java From spark-sdk-android with Apache License 2.0 | 4 votes |
public DeviceStateChange(ParticleDevice device, @NonNull ParticleDevice.ParticleDeviceState state) { this.device = device; this.state = state; }
Example #13
Source File: DeviceStateChange.java From spark-sdk-android with Apache License 2.0 | 4 votes |
@Override public void writeToParcel(Parcel dest, int flags) { dest.writeParcelable(this.device, flags); dest.writeInt(this.state == ParticleDevice.ParticleDeviceState.UNKNOWN ? -1 : this.state.ordinal()); }
Example #14
Source File: DeviceStateChange.java From spark-sdk-android with Apache License 2.0 | 4 votes |
protected DeviceStateChange(Parcel in) { this.device = in.readParcelable(ParticleDevice.class.getClassLoader()); int tmpState = in.readInt(); this.state = tmpState == -1 ? ParticleDevice.ParticleDeviceState.UNKNOWN : ParticleDevice.ParticleDeviceState.values()[tmpState]; }
Example #15
Source File: DeviceStateChange.java From spark-sdk-android with Apache License 2.0 | 4 votes |
public ParticleDevice getDevice() { return device; }
Example #16
Source File: DeviceStateChange.java From spark-sdk-android with Apache License 2.0 | 4 votes |
@NonNull public ParticleDevice.ParticleDeviceState getState() { return state; }
Example #17
Source File: ConnectingProcessWorkerTask.java From spark-setup-android with Apache License 2.0 | 4 votes |
@Override protected void onPostExecute(SetupProcessException error) { int resultCode; if (error != null) { resultCode = error.failedStep.getStepConfig().resultCode; } else { log.d("HUZZAH, VICTORY!"); // FIXME: handle "success, no ownership" case resultCode = SuccessActivity.RESULT_SUCCESS; if (!BaseActivity.setupOnly) { EZ.runAsync(() -> { try { // collect a list of unique, non-null device names Set<String> names = set(Funcy.transformList( sparkCloud.getDevices(), Funcy.notNull(), ParticleDevice::getName, Py::truthy )); ParticleDevice device = sparkCloud.getDevice(deviceId); if (device != null && !truthy(device.getName())) { device.setName(CoreNameGenerator.generateUniqueName(names)); } } catch (Exception e) { // FIXME: do real error handling here, and only // handle ParticleCloudException instead of swallowing everything e.printStackTrace(); } }); } } Activity activity = activityReference.get(); if (activity != null) { activity.startActivity(SuccessActivity.buildIntent(activity, resultCode, deviceId)); activity.finish(); } }
Example #18
Source File: PartialDeviceListResultException.java From spark-sdk-android with Apache License 2.0 | 4 votes |
public PartialDeviceListResultException(List<ParticleDevice> devices, RetrofitError error) { super(error); this.devices = devices; }
Example #19
Source File: PartialDeviceListResultException.java From spark-sdk-android with Apache License 2.0 | 4 votes |
public PartialDeviceListResultException(List<ParticleDevice> devices, Exception cause) { super(cause); this.devices = devices; }
Example #20
Source File: DeviceStateChange.java From particle-android with Apache License 2.0 | 4 votes |
@NonNull public ParticleDevice.ParticleDeviceState getState() { return state; }
Example #21
Source File: DeviceStateChange.java From particle-android with Apache License 2.0 | 4 votes |
public ParticleDevice getDevice() { return device; }
Example #22
Source File: DeviceStateChange.java From particle-android with Apache License 2.0 | 4 votes |
protected DeviceStateChange(Parcel in) { this.device = in.readParcelable(ParticleDevice.class.getClassLoader()); int tmpState = in.readInt(); this.state = tmpState == -1 ? ParticleDevice.ParticleDeviceState.UNKNOWN : ParticleDevice.ParticleDeviceState.values()[tmpState]; }
Example #23
Source File: DeviceStateChange.java From particle-android with Apache License 2.0 | 4 votes |
@Override public void writeToParcel(Parcel dest, int flags) { dest.writeParcelable(this.device, flags); dest.writeInt(this.state == ParticleDevice.ParticleDeviceState.UNKNOWN ? -1 : this.state.ordinal()); }
Example #24
Source File: DeviceStateChange.java From particle-android with Apache License 2.0 | 4 votes |
public DeviceStateChange(ParticleDevice device, @NonNull ParticleDevice.ParticleDeviceState state) { this.device = device; this.state = state; }
Example #25
Source File: PartialDeviceListResultException.java From particle-android with Apache License 2.0 | 4 votes |
public PartialDeviceListResultException(List<ParticleDevice> devices) { super("Undefined error while fetching devices"); this.devices = devices; }
Example #26
Source File: PartialDeviceListResultException.java From particle-android with Apache License 2.0 | 4 votes |
public PartialDeviceListResultException(List<ParticleDevice> devices, RetrofitError error) { super(error); this.devices = devices; }
Example #27
Source File: PartialDeviceListResultException.java From particle-android with Apache License 2.0 | 4 votes |
public PartialDeviceListResultException(List<ParticleDevice> devices, Exception cause) { super(cause); this.devices = devices; }
Example #28
Source File: SuccessActivity.java From particle-android with Apache License 2.0 | 4 votes |
private void setDeviceName(ParticleDevice device, String deviceName) throws ParticleCloudException { //Set new device name only if it changed if (device.getName() != null && !device.getName().equals(deviceName)) { device.setName(deviceName); } }