io.particle.android.sdk.utils.Funcy Java Examples
The following examples show how to use
io.particle.android.sdk.utils.Funcy.
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: EnsureSoftApNotVisible.java From particle-android with Apache License 2.0 | 6 votes |
private boolean isSoftApVisible() { List<SSID> scansPlusConnectedSsid = list(); SSID currentlyConnected = wifiFacade.getCurrentlyConnectedSSID(); if (currentlyConnected != null) { scansPlusConnectedSsid.add(currentlyConnected); } scansPlusConnectedSsid.addAll( Funcy.transformList(wifiFacade.getScanResults(), Funcy.notNull(), SSID::from) ); log.d("scansPlusConnectedSsid: " + scansPlusConnectedSsid); log.d("Soft AP we're looking for: " + softApName); SSID firstMatch = Funcy.findFirstMatch(scansPlusConnectedSsid, matchesSoftApSSID); log.d("Matching SSID result: '" + firstMatch + "'"); return firstMatch != null; }
Example #2
Source File: WifiScanResultLoader.java From particle-android with Apache License 2.0 | 6 votes |
@Override public Set<ScanResultNetwork> loadInBackground() { List<ScanResult> scanResults = wifiFacade.getScanResults(); log.d("Latest (unfiltered) scan results: " + scanResults); if (loadCount % 3 == 0) { wifiFacade.startScan(); } loadCount++; // filter the list, transform the matched results, then wrap those in a Set mostRecentResult = set(Funcy.transformList( scanResults, ssidStartsWithProductName, ScanResultNetwork::new)); if (mostRecentResult.isEmpty()) { log.i("No SSID scan results returned after filtering by product name. " + "Do you need to change the 'network_name_prefix' resource?"); } return mostRecentResult; }
Example #3
Source File: ParticleCloud.java From spark-sdk-android with Apache License 2.0 | 6 votes |
private void pruneDeviceMap(List<SimpleDevice> latestCloudDeviceList) { synchronized (devices) { // make a copy of the current keyset since we mutate `devices` below PySet<String> currentDeviceIds = set(devices.keySet()); PySet<String> newDeviceIds = set(Funcy.transformList(latestCloudDeviceList, toDeviceId)); // quoting the Sets docs for this next operation: // "The returned set contains all elements that are contained by set1 and // not contained by set2" // In short, this set is all the device IDs which we have in our devices map, // but which we did not hear about in this latest update from the cloud Set<String> toRemove = currentDeviceIds.getDifference(newDeviceIds); for (String deviceId : toRemove) { devices.remove(deviceId); } } }
Example #4
Source File: EnsureSoftApNotVisible.java From spark-setup-android with Apache License 2.0 | 6 votes |
private boolean isSoftApVisible() { List<SSID> scansPlusConnectedSsid = list(); SSID currentlyConnected = wifiFacade.getCurrentlyConnectedSSID(); if (currentlyConnected != null) { scansPlusConnectedSsid.add(currentlyConnected); } scansPlusConnectedSsid.addAll( Funcy.transformList(wifiFacade.getScanResults(), Funcy.notNull(), SSID::from) ); log.d("scansPlusConnectedSsid: " + scansPlusConnectedSsid); log.d("Soft AP we're looking for: " + softApName); SSID firstMatch = Funcy.findFirstMatch(scansPlusConnectedSsid, matchesSoftApSSID); log.d("Matching SSID result: '" + firstMatch + "'"); return firstMatch != null; }
Example #5
Source File: WifiScanResultLoader.java From spark-setup-android with Apache License 2.0 | 6 votes |
@Override public Set<ScanResultNetwork> loadInBackground() { List<ScanResult> scanResults = wifiFacade.getScanResults(); log.d("Latest (unfiltered) scan results: " + scanResults); if (loadCount % 3 == 0) { wifiFacade.startScan(); } loadCount++; // filter the list, transform the matched results, then wrap those in a Set mostRecentResult = set(Funcy.transformList( scanResults, ssidStartsWithProductName, ScanResultNetwork::new)); if (mostRecentResult.isEmpty()) { log.i("No SSID scan results returned after filtering by product name. " + "Do you need to change the 'network_name_prefix' resource?"); } return mostRecentResult; }
Example #6
Source File: ScanApCommandLoader.java From particle-android with Apache License 2.0 | 5 votes |
@Override public Set<ScanAPCommandResult> loadInBackground() { try { ScanApCommand.Response response = commandClient.sendCommand(new ScanApCommand(), ScanApCommand.Response.class); accumulatedResults.addAll(Funcy.transformList(response.getScans(), ScanAPCommandResult::new)); log.d("Latest accumulated scan results: " + accumulatedResults); return set(accumulatedResults); } catch (IOException e) { log.e("Error running scan-ap command: ", e); return null; } }
Example #7
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 #8
Source File: ParticleCloud.java From spark-sdk-android with Apache License 2.0 | 5 votes |
@WorkerThread public boolean userOwnsDevice(@NonNull String deviceId) throws ParticleCloudException { String idLower = deviceId.toLowerCase(); try { List<SimpleDevice> devices = mainApi.getDevices(); SimpleDevice firstMatch = Funcy.findFirstMatch(devices, testTarget -> idLower.equals(testTarget.id.toLowerCase()) ); return firstMatch != null; } catch (RetrofitError error) { throw new ParticleCloudException(error); } }
Example #9
Source File: ParticleCloud.java From spark-sdk-android with Apache License 2.0 | 5 votes |
private DeviceState fromCompleteDevice(CompleteDevice completeDevice) { // FIXME: we're sometimes getting back nulls in the list of functions... WUT? // Once analytics are in place, look into adding something here so we know where // this is coming from. In the meantime, filter out nulls from this list, since that's // obviously doubleplusungood. Set<String> functions = set(Funcy.filter(completeDevice.functions, Funcy.notNull())); Map<String, VariableType> variables = transformVariables(completeDevice); return new DeviceState.DeviceStateBuilder(completeDevice.deviceId, functions, variables) .name(completeDevice.name) .cellular(completeDevice.cellular) .connected(completeDevice.isConnected) .version(completeDevice.version) .deviceType(ParticleDeviceType.fromInt(completeDevice.productId)) .platformId(completeDevice.platformId) .productId(completeDevice.productId) .imei(completeDevice.imei) .iccid(completeDevice.lastIccid) .currentBuild(completeDevice.currentBuild) .defaultBuild(completeDevice.defaultBuild) .ipAddress(completeDevice.ipAddress) .lastAppName(completeDevice.lastAppName) .status(completeDevice.status) .requiresUpdate(completeDevice.requiresUpdate) .lastHeard(completeDevice.lastHeard) .build(); }
Example #10
Source File: ScanApCommandLoader.java From spark-setup-android with Apache License 2.0 | 5 votes |
@Override public Set<ScanAPCommandResult> loadInBackground() { try { ScanApCommand.Response response = commandClient.sendCommand(new ScanApCommand(), ScanApCommand.Response.class); accumulatedResults.addAll(Funcy.transformList(response.getScans(), ScanAPCommandResult::new)); log.d("Latest accumulated scan results: " + accumulatedResults); return set(accumulatedResults); } catch (IOException e) { log.e("Error running scan-ap command: ", e); return null; } }
Example #11
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(); } }