本文整理汇总了Java中android.os.CancellationSignal.setOnCancelListener方法的典型用法代码示例。如果您正苦于以下问题:Java CancellationSignal.setOnCancelListener方法的具体用法?Java CancellationSignal.setOnCancelListener怎么用?Java CancellationSignal.setOnCancelListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.CancellationSignal
的用法示例。
在下文中一共展示了CancellationSignal.setOnCancelListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPreview
import android.os.CancellationSignal; //导入方法依赖的package包/类
/**
* Generates the widget preview on {@link AsyncTask#THREAD_POOL_EXECUTOR}. Must be
* called on UI thread
*
* @return a request id which can be used to cancel the request.
*/
public CancellationSignal getPreview(WidgetItem item, int previewWidth,
int previewHeight, WidgetCell caller, boolean animate) {
String size = previewWidth + "x" + previewHeight;
WidgetCacheKey key = new WidgetCacheKey(item.componentName, item.user, size);
PreviewLoadTask task = new PreviewLoadTask(key, item, previewWidth, previewHeight, caller,
animate);
task.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
CancellationSignal signal = new CancellationSignal();
signal.setOnCancelListener(task);
return signal;
}
示例2: onFillRequest
import android.os.CancellationSignal; //导入方法依赖的package包/类
@Override
public void onFillRequest(FillRequest request, CancellationSignal cancellationSignal,
FillCallback callback) {
AssistStructure structure = request.getFillContexts()
.get(request.getFillContexts().size() - 1).getStructure();
String packageName = structure.getActivityComponent().getPackageName();
if (!SharedPrefsPackageVerificationRepository.getInstance()
.putPackageSignatures(getApplicationContext(), packageName)) {
callback.onFailure(
getApplicationContext().getString(R.string.invalid_package_signature));
return;
}
final Bundle clientState = request.getClientState();
if (logVerboseEnabled()) {
logv("onFillRequest(): clientState=%s", bundleToString(clientState));
}
dumpStructure(structure);
cancellationSignal.setOnCancelListener(() ->
logw("Cancel autofill not implemented in this sample.")
);
// Parse AutoFill data in Activity
StructureParser parser = new StructureParser(getApplicationContext(), structure);
// TODO: try / catch on other places (onSave, auth activity, etc...)
try {
parser.parseForFill();
} catch (SecurityException e) {
// TODO: handle cases where DAL didn't pass by showing a custom UI asking the user
// to confirm the mapping. Might require subclassing SecurityException.
logw(e, "Security exception handling %s", request);
callback.onFailure(e.getMessage());
return;
}
AutofillFieldMetadataCollection autofillFields = parser.getAutofillFields();
FillResponse.Builder responseBuilder = new FillResponse.Builder();
// Check user's settings for authenticating Responses and Datasets.
boolean responseAuth = MyPreferences.getInstance(this).isResponseAuth();
AutofillId[] autofillIds = autofillFields.getAutofillIds();
if (responseAuth && !Arrays.asList(autofillIds).isEmpty()) {
// If the entire Autofill Response is authenticated, AuthActivity is used
// to generate Response.
IntentSender sender = AuthActivity.getAuthIntentSenderForResponse(this);
RemoteViews presentation = AutofillHelper
.newRemoteViews(getPackageName(), getString(R.string.autofill_sign_in_prompt),
R.drawable.ic_lock_black_24dp);
responseBuilder
.setAuthentication(autofillIds, sender, presentation);
callback.onSuccess(responseBuilder.build());
} else {
boolean datasetAuth = MyPreferences.getInstance(this).isDatasetAuth();
HashMap<String, FilledAutofillFieldCollection> clientFormDataMap =
SharedPrefsAutofillRepository.getInstance().getFilledAutofillFieldCollection(
this, autofillFields.getFocusedHints(), autofillFields.getAllHints());
FillResponse response = AutofillHelper.newResponse
(this, clientState, datasetAuth, autofillFields, clientFormDataMap);
callback.onSuccess(response);
}
}