Java源码示例:io.particle.android.sdk.utils.Py
示例1
@Nullable
public static synchronized ParticleAccessToken fromSavedSession() {
SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
String accessToken = sensitiveDataStorage.getToken();
String refreshToken = sensitiveDataStorage.getRefreshToken();
Date expirationDate = sensitiveDataStorage.getTokenExpirationDate();
// are either of the fields "falsey" or has the expr date passed?
if (!Py.truthy(accessToken) || !Py.truthy(expirationDate) || expirationDate.before(new Date())) {
return null;
}
ParticleAccessToken token = new ParticleAccessToken(accessToken, expirationDate, refreshToken,
new Handler(Looper.getMainLooper()));
token.scheduleExpiration();
return token;
}
示例2
@Nullable
public static synchronized ParticleAccessToken fromSavedSession() {
SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
String accessToken = sensitiveDataStorage.getToken();
String refreshToken = sensitiveDataStorage.getRefreshToken();
Date expirationDate = sensitiveDataStorage.getTokenExpirationDate();
// are either of the fields "falsey" or has the expr date passed?
if (!Py.truthy(accessToken) || !Py.truthy(expirationDate) || expirationDate.before(new Date())) {
return null;
}
ParticleAccessToken token = new ParticleAccessToken(accessToken, expirationDate, refreshToken,
new Handler(Looper.getMainLooper()));
token.scheduleExpiration();
return token;
}
示例3
@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();
}
}
示例4
public static synchronized ParticleAccessToken fromNewSession(Responses.LogInResponse logInResponse) {
if (!Py.truthy(logInResponse.getAccessToken()) || !"bearer".equalsIgnoreCase(logInResponse.getTokenType())) {
throw new IllegalArgumentException("Invalid LogInResponse: " + logInResponse);
}
long expirationMillis = logInResponse.getExpiresInSeconds() * 1000;
Date expirationDate = new Date(System.currentTimeMillis() + expirationMillis);
return fromTokenData(expirationDate, logInResponse.getAccessToken(), logInResponse.getRefreshToken());
}
示例5
public static synchronized ParticleAccessToken fromNewSession(Responses.LogInResponse logInResponse) {
if (!Py.truthy(logInResponse.accessToken) || !"bearer".equalsIgnoreCase(logInResponse.tokenType)) {
throw new IllegalArgumentException("Invalid LogInResponse: " + logInResponse);
}
long expirationMillis = logInResponse.expiresInSeconds * 1000;
Date expirationDate = new Date(System.currentTimeMillis() + expirationMillis);
return fromTokenData(expirationDate, logInResponse.accessToken, logInResponse.refreshToken);
}
示例6
@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();
}
}