Java 类android.app.assist.AssistStructure 实例源码

项目:android-AutofillFramework    文件:AuthActivity.java   
private void onSuccess() {
    Intent intent = getIntent();
    boolean forResponse = intent.getBooleanExtra(EXTRA_FOR_RESPONSE, true);
    Bundle clientState = intent.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE);
    AssistStructure structure = intent.getParcelableExtra(EXTRA_ASSIST_STRUCTURE);
    StructureParser parser = new StructureParser(getApplicationContext(), structure);
    parser.parseForFill();
    AutofillFieldMetadataCollection autofillFields = parser.getAutofillFields();
    int saveTypes = autofillFields.getSaveType();
    mReplyIntent = new Intent();
    HashMap<String, FilledAutofillFieldCollection> clientFormDataMap =
            SharedPrefsAutofillRepository.getInstance().getFilledAutofillFieldCollection
                    (this, autofillFields.getFocusedHints(), autofillFields.getAllHints());
    if (forResponse) {
        setResponseIntent(AutofillHelper.newResponse
                (this, clientState, false, autofillFields, clientFormDataMap));
    } else {
        String datasetName = intent.getStringExtra(EXTRA_DATASET_NAME);
        setDatasetIntent(AutofillHelper.newDataset
                (this, autofillFields, clientFormDataMap.get(datasetName), false));
    }
}
项目:RecentTask    文件:BBVoiceInteractionSession.java   
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onHandleAssist(Bundle data, AssistStructure structure, AssistContent content) {
    super.onHandleAssist(data, structure, content);
    ComponentName componentName=structure.getActivityComponent();
    if (componentName.getPackageName().equals(HIDE_FLOAT_VIEW_PACKAGE_NAME)){
        tipViewController.hide();
    }else {
        tipViewController.show(1,"");
    }

}
项目:android-AutofillFramework    文件:Util.java   
public static void dumpStructure(AssistStructure structure) {
    if (logVerboseEnabled()) {
        int nodeCount = structure.getWindowNodeCount();
        logv("dumpStructure(): component=%s numberNodes=%d",
                structure.getActivityComponent(), nodeCount);
        for (int i = 0; i < nodeCount; i++) {
            logv("node #%d", i);
            WindowNode node = structure.getWindowNodeAt(i);
            dumpNode(new StringBuilder(), "  ", node.getRootViewNode(), 0);
        }
    }
}
项目:android-AutofillFramework    文件:Util.java   
/**
 * Gets a node if it matches the filter criteria for the given id.
 */
public static ViewNode findNodeByFilter(@NonNull AssistStructure structure, @NonNull Object id,
        @NonNull NodeFilter filter) {
    logv("Parsing request for activity %s", structure.getActivityComponent());
    final int nodes = structure.getWindowNodeCount();
    for (int i = 0; i < nodes; i++) {
        final WindowNode windowNode = structure.getWindowNodeAt(i);
        final ViewNode rootNode = windowNode.getRootViewNode();
        final ViewNode node = findNodeByFilter(rootNode, id, filter);
        if (node != null) {
            return node;
        }
    }
    return null;
}
项目:android-AutofillFramework    文件:Util.java   
public static void dumpStructure(AssistStructure structure) {
    int nodeCount = structure.getWindowNodeCount();
    Log.v(TAG, "dumpStructure(): component=" + structure.getActivityComponent()
            + " numberNodes=" + nodeCount);
    for (int i = 0; i < nodeCount; i++) {
        Log.v(TAG, "node #" + i);
        WindowNode node = structure.getWindowNodeAt(i);
        dumpNode("  ", node.getRootViewNode());
    }
}
项目:RecentTask    文件:BBVoiceInteractionSession.java   
@Override
public void onHandleAssistSecondary(Bundle data, AssistStructure structure, AssistContent content, int index, int count) {
    super.onHandleAssistSecondary(data, structure, content, index, count);
}
项目:Bigbang    文件:BBVoiceInteractionSession.java   
@Override
public void onHandleAssist(Bundle data, AssistStructure structure, AssistContent content) {
    super.onHandleAssist(data, structure, content);
}
项目:Bigbang    文件:BBVoiceInteractionSession.java   
@Override
public void onHandleAssistSecondary(Bundle data, AssistStructure structure, AssistContent content, int index, int count) {
    super.onHandleAssistSecondary(data, structure, content, index, count);
}
项目:android-AutofillFramework    文件:StructureParser.java   
StructureParser(Context context, AssistStructure structure) {
    mContext = context;
    mStructure = structure;
}
项目:android-AutofillFramework    文件:MyAutofillService.java   
@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);
    }
}
项目:android-AutofillFramework    文件:MyAutofillService.java   
@Override
public void onSaveRequest(SaveRequest request, SaveCallback callback) {
    List<FillContext> fillContexts = request.getFillContexts();
    int size = fillContexts.size();
    AssistStructure structure = fillContexts.get(size - 1).getStructure();
    String packageName = structure.getActivityComponent().getPackageName();
    if (!SharedPrefsPackageVerificationRepository.getInstance()
            .putPackageSignatures(getApplicationContext(), packageName)) {
        callback.onFailure(getApplicationContext().getString(R.string.invalid_package_signature));
        return;
    }
    Bundle clientState = request.getClientState();
    if (logVerboseEnabled()) {
        logv("onSaveRequest(): clientState=%s", bundleToString(clientState));
    }
    dumpStructure(structure);

    // TODO: hardcode check for partial username
    if (clientState != null) {
        String usernameKey =
                String.format(CLIENT_STATE_PARTIAL_ID_TEMPLATE, View.AUTOFILL_HINT_USERNAME);
        AutofillId usernameId = clientState.getParcelable(usernameKey);
        logd("client state for %s: %s", usernameKey, usernameId);
        if (usernameId != null) {
            String passwordKey =
                    String.format(CLIENT_STATE_PARTIAL_ID_TEMPLATE, View.AUTOFILL_HINT_PASSWORD);
            AutofillId passwordId = clientState.getParcelable(passwordKey);

            logd("Scanning %d contexts for username ID %s and password ID %s.", size,
                    usernameId, passwordId);
            AssistStructure.ViewNode usernameNode =
                    findNodeByFilter(fillContexts, usernameId, AUTOFILL_ID_FILTER);
            AssistStructure.ViewNode passwordNode =
                    findNodeByFilter(fillContexts, passwordId, AUTOFILL_ID_FILTER);
            String username = null, password = null;
            if (usernameNode != null) {
                username = usernameNode.getAutofillValue().getTextValue().toString();
            }
            if (passwordNode != null) {
                password = passwordNode.getAutofillValue().getTextValue().toString();
            }

            if (username != null && password != null) {
                logd("user: %s, pass: %s", username, password);
                // TODO: save it
                callback.onFailure("TODO: save " + username + "/" + password);
                return;
            } else {
                logw(" missing user (%s) or pass (%s)", username, password);
            }
        }
    }

    StructureParser parser = new StructureParser(getApplicationContext(), structure);
    parser.parseForSave();
    FilledAutofillFieldCollection filledAutofillFieldCollection = parser.getClientFormData();
    SharedPrefsAutofillRepository.getInstance()
            .saveFilledAutofillFieldCollection(this, filledAutofillFieldCollection);
}
项目:Saiy-PS    文件:SaiyInteractionSession.java   
@Override
public void onHandleAssist(Bundle data, AssistStructure structure, AssistContent content) {
}