當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。