当前位置: 首页>>代码示例>>Java>>正文


Java CancellationSignal.setOnCancelListener方法代码示例

本文整理汇总了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;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:20,代码来源:WidgetPreviewLoader.java

示例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);
    }
}
 
开发者ID:googlesamples,项目名称:android-AutofillFramework,代码行数:59,代码来源:MyAutofillService.java


注:本文中的android.os.CancellationSignal.setOnCancelListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。