本文整理汇总了Java中com.google.android.gms.tasks.Task.addOnCompleteListener方法的典型用法代码示例。如果您正苦于以下问题:Java Task.addOnCompleteListener方法的具体用法?Java Task.addOnCompleteListener怎么用?Java Task.addOnCompleteListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.tasks.Task
的用法示例。
在下文中一共展示了Task.addOnCompleteListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addImage
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
public void addImage(StorageReference storageRef, String filePath, String storyId) {
storyId += "-photo";
removeStuffWithThisKey(storyId);
final ImageView imageThing = new ImageView(myContext);
int gridThingPixels = (int) myContext.getResources().getDimension(R.dimen.grid_thing);
imageThing.setMaxHeight(gridThingPixels);
imageThing.setMaxWidth(gridThingPixels);
gridContents.add(new TaggedView(imageThing, storyId));
this.notifyDataSetChanged();
// and a photo (up to 10mb)
Task<byte[]> imageDownloadTask = storageRef.child(filePath).getBytes(100 * 1024 * 1024);
imageDownloadTask.addOnCompleteListener(new OnCompleteListener<byte[]>() {
@Override
public void onComplete(@NonNull Task<byte[]> task) {
byte[] imageBytes = task.getResult();
Bitmap imageBitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
imageThing.setImageBitmap(imageBitmap);
StoryAdapter.this.notifyDataSetChanged();
}
});
}
示例2: getRegisterRequest
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
private void getRegisterRequest() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS)
== PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, "getRegisterRequest permission is granted");
Task<RegisterRequestParams> getRegisterRequestTask = asyncGetRegisterRequest(false);
getRegisterRequestTask.addOnCompleteListener(
new OnCompleteListener<RegisterRequestParams>() {
@Override
public void onComplete(@NonNull Task<RegisterRequestParams> task) {
RegisterRequestParams registerRequest = task.getResult();
if (registerRequest == null) {
Log.d(TAG, "registerRequest is null");
return;
}
sendRegisterRequestToClient(registerRequest);
}
});
} else {
Log.i(TAG, "getRegisterRequest permission is requested");
ActivityCompat.requestPermissions(
this,
new String[]{Manifest.permission.GET_ACCOUNTS},
GET_ACCOUNTS_PERMISSIONS_REQUEST_REGISTER);
}
}
示例3: updateRegisterResponseToServer
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
private void updateRegisterResponseToServer(RegisterResponseData registerResponseData) {
/* assume this operation can only happen within short time after getRegisterRequest,
which has already checked permission
*/
Task<String> updateRegisterResponseToServerTask =
asyncUpdateRegisterResponseToServer(registerResponseData);
updateRegisterResponseToServerTask.addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
String securityKeyToken = task.getResult();
if (securityKeyToken == null) {
Toast.makeText(
U2FDemoActivity.this,
"security key registration failed",
Toast.LENGTH_SHORT)
.show();
return;
}
updateAndDisplayRegisteredKeys();
Log.i(TAG, "Update register response to server with securityKeyToken: "
+ securityKeyToken);
}
});
}
示例4: getSignRequest
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
private void getSignRequest() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS)
== PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, "getSignRequest permission is granted");
Task<SignRequestParams> getSignRequestTask = asyncGetSignRequest();
getSignRequestTask.addOnCompleteListener(new OnCompleteListener<SignRequestParams>() {
@Override
public void onComplete(@NonNull Task<SignRequestParams> task) {
SignRequestParams signRequest = task.getResult();
if (signRequest == null) {
Log.i(TAG, "signRequest is null");
return;
}
sendSignRequestToClient(signRequest);
}
});
} else {
Log.i(TAG, "getSignRequest permission is requested");
ActivityCompat.requestPermissions(
this,
new String[]{Manifest.permission.GET_ACCOUNTS},
GET_ACCOUNTS_PERMISSIONS_REQUEST_SIGN);
}
}
示例5: updateSignResponseToServer
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
private void updateSignResponseToServer(SignResponseData signResponseData) {
/* assume this operation can only happen within short time after getSignRequest,
which has already checked permission
*/
Task<String> updateSignResponseToServerTask =
asyncUpdateSignResponseToServer(signResponseData);
updateSignResponseToServerTask.addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
String pubKey = task.getResult();
if (pubKey == null) {
Toast.makeText(
U2FDemoActivity.this,
"this security key has not been registered!",
Toast.LENGTH_SHORT).
show();
return;
}
Log.i(TAG, "authenticated key's pub_key is " + pubKey);
highlightAuthenticatedToken(pubKey);
}
});
}
示例6: updateAndDisplayRegisteredKeys
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
private void updateAndDisplayRegisteredKeys() {
mProgressBar.setVisibility(View.VISIBLE);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS)
== PackageManager.PERMISSION_GRANTED) {
Log.i(TAG, "updateAndDisplayRegisteredKeys permission is granted");
Task<List<Map<String, String>>> refreshSecurityKeyTask = asyncRefreshSecurityKey();
refreshSecurityKeyTask.addOnCompleteListener(
new OnCompleteListener<List<Map<String, String>>>() {
@Override
public void onComplete(@NonNull Task<List<Map<String, String>>> task) {
List<Map<String, String>> tokens = task.getResult();
securityTokens = tokens;
mAdapter.clearSecurityTokens();
mAdapter.addSecurityToken(securityTokens);
displayRegisteredKeys();
}
});
} else {
Log.i(TAG, "updateAndDisplayRegisteredKeys permission is requested");
ActivityCompat.requestPermissions(
this,
new String[]{Manifest.permission.GET_ACCOUNTS},
GET_ACCOUNTS_PERMISSIONS_ALL_TOKENS);
}
}
示例7: fetchData
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
private void fetchData() {
// The logic can be modified according to your need.
sharedPreferences = getSharedPreferences(SHARED_PREF, MODE_PRIVATE);
firstTime = sharedPreferences.getBoolean(KEY_FIRST_TIME, true);
if (firstTime) {
Log.v(TAG, "Fetching account info from API");
AccountTransferClient client = AccountTransfer.getAccountTransferClient(this);
final Task<byte[]> transferBytes = client.retrieveData(ACCOUNT_TYPE);
transferBytes.addOnCompleteListener(this, new OnCompleteListener<byte[]>() {
@Override
public void onComplete(@NonNull Task<byte[]> task) {
if (task.isSuccessful()) {
Log.d(TAG, "Success retrieving data. Importing it.");
try {
AccountTransferUtil.importAccounts(task.getResult(), MainActivity.this);
} catch (JSONException e) {
Log.e(TAG, "Encountered failure while retrieving data", e);
return;
}
populateAccountTextView();
} else {
// No need to notify API about failure, as it's running outside setup of
// device.
Log.e(TAG, "Encountered failure while retrieving data", task.getException());
}
// Don't try the next time
sharedPreferences.edit().putBoolean(KEY_FIRST_TIME, false).apply();
}
});
}
}
示例8: showCurrentPlace
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
private void showCurrentPlace() {
if (map == null || !mLocationPermissionGranted) {
return;
}
@SuppressLint("MissingPermission") Task locationResult =
mFusedLocationClient.getLastLocation();
locationResult.addOnCompleteListener(this, new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()) {
// Set the map's camera position to the current location of the device.
mCurrentLocation = (Location) task.getResult();
PieceShape markerPic = new PieceSquareShape(PIECE_SIZE);
if (mCurrentLocation!=null) {
marker = placeMarker(PiecePicker.getPiece(markerPic, piece), mCurrentLocation);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(mCurrentLocation.getLatitude(),
mCurrentLocation.getLongitude()), zoom));
} else {
marker = placeMarker(PiecePicker.getPiece(markerPic, piece), mDefaultLocation);
}
} else {
Log.d("MAP", "Current location is null. Using defaults.");
Log.e("MAP", "Exception: %s", task.getException());
map.moveCamera(CameraUpdateFactory.newLatLngZoom(mDefaultLocation, zoom));
map.getUiSettings().setMyLocationButtonEnabled(false);
}
}
});
}
示例9: assignOnTask
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
public static <T> void assignOnTask(MaybeEmitter<? super T> emitter, Task<T> task) {
RxHandler handler = new RxHandler(emitter);
task.addOnSuccessListener(handler);
task.addOnFailureListener(handler);
try {
task.addOnCompleteListener(handler);
} catch (Throwable t) {
// ignore
}
}
示例10: assignOnTask
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
public static <T> void assignOnTask(CompletableEmitter completableEmitter, Task<T> task) {
RxCompletableHandler handler = new RxCompletableHandler(completableEmitter);
task.addOnFailureListener(handler);
task.addOnSuccessListener(handler);
try {
task.addOnCompleteListener(handler);
} catch (Throwable t) {
// ignore
}
}
示例11: getDeviceLocation
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
private void getDeviceLocation() {
/*
* Get the best and most recent location of the device, which may be null in rare
* cases when a location is not available.
*/
try {
if (mLocationPermissionGranted) {
Intent intent = new Intent(this, LocationUpdaterService.class);
startService(intent);
Task locationResult = mFusedLocationProviderClient.getLastLocation();
locationResult.addOnCompleteListener(this, new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()) {
// Set the map's camera position to the current location of the device.
mLastKnownLocation = (Location) task.getResult();
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(mLastKnownLocation.getLatitude(),
mLastKnownLocation.getLongitude()), DEFAULT_ZOOM));
} else {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mDefaultLocation, DEFAULT_ZOOM));
mMap.getUiSettings().setMyLocationButtonEnabled(false);
}
}
});
}
} catch (SecurityException e) {
}
}
示例12: subscribeActual
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
@Override
protected void subscribeActual(MaybeObserver<? super T> observer) {
Task<T> task = run();
MaybeTaskCallback<T> callback = new MaybeTaskCallback(task, observer);
observer.onSubscribe(callback);
task.addOnCompleteListener(callback);
}
示例13: subscribeActual
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
@Override
protected void subscribeActual(SingleObserver<? super T> observer) {
Task<T> task = run();
SingleTaskCallback<T> callback = new SingleTaskCallback(task, observer);
observer.onSubscribe(callback);
task.addOnCompleteListener(callback);
}
示例14: subscribeActual
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
@Override
protected void subscribeActual(CompletableObserver observer) {
Task<Void> task = run();
CompletableTaskCallback callback = new CompletableTaskCallback(task, observer);
observer.onSubscribe(callback);
task.addOnCompleteListener(callback);
}
示例15: subscribeActual
import com.google.android.gms.tasks.Task; //导入方法依赖的package包/类
@Override
protected void subscribeActual(Observer<? super T> observer) {
ObservableTaskCallback<T> callback = new ObservableTaskCallback(observer);
observer.onSubscribe(callback);
Task<Void> task = run(callback);
task.addOnCompleteListener(callback);
}