@Override public void dispatchProvideAutofillStructure(ViewStructure structure, int flags) { if (mOriginalHint == null || mEditText == null) { super.dispatchProvideAutofillStructure(structure, flags); return; } // Temporarily sets child's hint to its original value so it is properly set in the // child's ViewStructure. final CharSequence hint = mEditText.getHint(); mEditText.setHint(mOriginalHint); try { super.dispatchProvideAutofillStructure(structure, flags); } finally { mEditText.setHint(hint); } }
@Override public void dispatchProvideAutofillStructure(ViewStructure structure, int flags) { if (originalHint == null || editText == null) { super.dispatchProvideAutofillStructure(structure, flags); return; } // Temporarily sets child's hint to its original value so it is properly set in the // child's ViewStructure. final CharSequence hint = editText.getHint(); editText.setHint(originalHint); try { super.dispatchProvideAutofillStructure(structure, flags); } finally { editText.setHint(hint); } }
@TargetApi(Build.VERSION_CODES.M) public void onProvideVirtualStructure( final ViewStructure structure, final boolean ignoreScrollOffset) { // Do not collect accessibility tree in incognito mode if (getWebContents().isIncognito()) { structure.setChildCount(0); return; } structure.setChildCount(1); final ViewStructure viewRoot = structure.asyncNewChild(0); getWebContents().requestAccessibilitySnapshot(new AccessibilitySnapshotCallback() { @Override public void onAccessibilitySnapshot(AccessibilitySnapshotNode root) { viewRoot.setClassName(""); viewRoot.setHint(mProductVersion); if (root == null) { viewRoot.asyncCommit(); return; } createVirtualStructure(viewRoot, root, ignoreScrollOffset); } }); }
@Override public void onProvideStructure(ViewStructure structure) { super.onProvideStructure(structure); if (allowAssistant && Build.VERSION.SDK_INT >= 23) { if (currentMessageObject.messageText != null && currentMessageObject.messageText.length() > 0) { structure.setText(currentMessageObject.messageText); } else if (currentMessageObject.caption != null && currentMessageObject.caption.length() > 0) { structure.setText(currentMessageObject.caption); } } }
@Override public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) { // Build a ViewStructure that will get passed to the AutofillService by the framework // when it is time to find autofill suggestions. structure.setClassName(getClass().getName()); int childrenSize = mVirtualViews.size(); if (DEBUG) { Log.d(TAG, "onProvideAutofillVirtualStructure(): flags = " + flags + ", items = " + childrenSize + ", extras: " + bundleToString(structure.getExtras())); } int index = structure.addChildCount(childrenSize); // Traverse through the view hierarchy, including virtual child views. For each view, we // need to set the relevant autofill metadata and add it to the ViewStructure. for (int i = 0; i < childrenSize; i++) { Item item = mVirtualViews.valueAt(i); if (DEBUG) Log.d(TAG, "Adding new child at index " + index + ": " + item); ViewStructure child = structure.newChild(index); child.setAutofillId(structure.getAutofillId(), item.id); child.setAutofillHints(item.hints); child.setAutofillType(item.type); child.setAutofillValue(item.getAutofillValue()); child.setDataIsSensitive(!item.sanitized); child.setFocused(item.focused); child.setVisibility(View.VISIBLE); child.setDimens(item.line.mBounds.left, item.line.mBounds.top, 0, 0, item.line.mBounds.width(), item.line.mBounds.height()); child.setId(item.id, getContext().getPackageName(), null, item.idEntry); child.setClassName(item.getClassName()); child.setDimens(item.line.mBounds.left, item.line.mBounds.top, 0, 0, item.line.mBounds.width(), item.line.mBounds.height()); index++; } }
@TargetApi(Build.VERSION_CODES.O) @Override public void dispatchProvideAutofillStructure(ViewStructure structure, int flags) { // This view is self-sufficient for autofill, so it needs to call // onProvideAutoFillStructure() to fill itself, but it does not need to call // dispatchProvideAutoFillStructure() to fill its children. structure.setAutofillId(getAutofillId()); onProvideAutofillStructure(structure, flags); }
@Override public ViewStructure newChild(int index) { final ViewStructureImpl child = new ViewStructureImpl(); children[index] = child; return child; }
@Override public ViewStructure asyncNewChild(int index) { return newChild(index); }
@Override public void onProvideVirtualStructure(final ViewStructure structure) { mContentViewCore.onProvideVirtualStructure(structure, false); }
@TargetApi(Build.VERSION_CODES.M) private void createVirtualStructure(ViewStructure viewNode, AccessibilitySnapshotNode node, final boolean ignoreScrollOffset) { viewNode.setClassName(node.className); if (node.hasSelection) { viewNode.setText(node.text, node.startSelection, node.endSelection); } else { viewNode.setText(node.text); } int left = (int) mRenderCoordinates.fromLocalCssToPix(node.x); int top = (int) mRenderCoordinates.fromLocalCssToPix(node.y); int width = (int) mRenderCoordinates.fromLocalCssToPix(node.width); int height = (int) mRenderCoordinates.fromLocalCssToPix(node.height); Rect boundsInParent = new Rect(left, top, left + width, top + height); if (node.isRootNode) { // Offset of the web content relative to the View. boundsInParent.offset(0, (int) mRenderCoordinates.getContentOffsetYPix()); if (!ignoreScrollOffset) { boundsInParent.offset(-(int) mRenderCoordinates.getScrollXPix(), -(int) mRenderCoordinates.getScrollYPix()); } } viewNode.setDimens(boundsInParent.left, boundsInParent.top, 0, 0, width, height); viewNode.setChildCount(node.children.size()); if (node.hasStyle) { // The text size should be in physical pixels, not CSS pixels. float textSize = mRenderCoordinates.fromLocalCssToPix(node.textSize); int style = (node.bold ? ViewNode.TEXT_STYLE_BOLD : 0) | (node.italic ? ViewNode.TEXT_STYLE_ITALIC : 0) | (node.underline ? ViewNode.TEXT_STYLE_UNDERLINE : 0) | (node.lineThrough ? ViewNode.TEXT_STYLE_STRIKE_THRU : 0); viewNode.setTextStyle(textSize, node.color, node.bgcolor, style); } for (int i = 0; i < node.children.size(); i++) { createVirtualStructure(viewNode.asyncNewChild(i), node.children.get(i), true); } viewNode.asyncCommit(); }
public void setAutofillId(ViewStructure parent, int virtualId) {}