android.view.ViewStructure Java Examples

The following examples show how to use android.view.ViewStructure. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContentViewCore.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@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);
        }
    });
}
 
Example #2
Source File: TextInputLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public void dispatchProvideAutofillStructure(@NonNull 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.
  boolean wasProvidingHint = isProvidingHint;
  // Ensures a child TextInputEditText does not retrieve its hint from this TextInputLayout.
  isProvidingHint = false;
  final CharSequence hint = editText.getHint();
  editText.setHint(originalHint);
  try {
    super.dispatchProvideAutofillStructure(structure, flags);
  } finally {
    editText.setHint(hint);
    isProvidingHint = wasProvidingHint;
  }
}
 
Example #3
Source File: Switch.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void onProvideAutoFillStructureForAssistOrAutofill(ViewStructure structure) {
    CharSequence switchText = isChecked() ? mTextOn : mTextOff;
    if (!TextUtils.isEmpty(switchText)) {
        CharSequence oldText = structure.getText();
        if (TextUtils.isEmpty(oldText)) {
            structure.setText(switchText);
        } else {
            StringBuilder newText = new StringBuilder();
            newText.append(oldText).append(' ').append(switchText);
            structure.setText(newText);
        }
        // The style of the label text is provided via the base TextView class. This is more
        // relevant than the style of the (optional) on/off text on the switch button itself,
        // so ignore the size/color/style stored this.mTextPaint.
    }
}
 
Example #4
Source File: AssistStructure.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public ViewStructure asyncNewChild(int index) {
    synchronized (mAssist) {
        ViewNode node = new ViewNode();
        mNode.mChildren[index] = node;
        ViewNodeBuilder builder = new ViewNodeBuilder(mAssist, node, true);
        mAssist.mPendingAsyncChildren.add(builder);
        return builder;
    }
}
 
Example #5
Source File: CustomVirtualView.java    From input-samples with Apache License 2.0 5 votes vote down vote up
@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++;
    }
}
 
Example #6
Source File: CustomVirtualView.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
@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++;
    }
}
 
Example #7
Source File: TimePicker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #8
Source File: TimePicker.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #9
Source File: DatePicker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #10
Source File: AdapterView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>It also sets the autofill options in the structure; when overridden, it should set it as
 * well, either explicitly by calling {@link ViewStructure#setAutofillOptions(CharSequence[])}
 * or implicitly by calling {@code super.onProvideAutofillStructure(structure, flags)}.
 */
@Override
public void onProvideAutofillStructure(ViewStructure structure, int flags) {
    super.onProvideAutofillStructure(structure, flags);

    final Adapter adapter = getAdapter();
    if (adapter == null) return;

    final CharSequence[] options = adapter.getAutofillOptions();
    if (options != null) {
        structure.setAutofillOptions(options);
    }
}
 
Example #11
Source File: ViewStructureImpl.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
public ViewStructure newChild(int index) {
  final ViewStructureImpl child = new ViewStructureImpl();
  children[index] = child;
  return child;
}
 
Example #12
Source File: TEditText.java    From timecat with Apache License 2.0 4 votes vote down vote up
@Override
public void onProvideStructure(ViewStructure structure) {
    super.onProvideStructure(structure);
}
 
Example #13
Source File: TEditText.java    From timecat with Apache License 2.0 4 votes vote down vote up
@Override
public void onProvideAutofillStructure(ViewStructure structure, int flags) {
    super.onProvideAutofillStructure(structure, flags);
}
 
Example #14
Source File: NestedRelativeRadioGroup.java    From NestedRadioButton with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
@Override
public void onProvideAutofillStructure(ViewStructure structure, int flags) {
    super.onProvideAutofillStructure(structure, flags);
    nestedRadioGroupManager.onProvideAutofillStructure(structure);
}
 
Example #15
Source File: ViewStructureImpl.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Override
public ViewStructure asyncNewChild(int index) {
  return newChild(index);
}
 
Example #16
Source File: ContentView.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void onProvideVirtualStructure(final ViewStructure structure) {
    mContentViewCore.onProvideVirtualStructure(structure, false);
}
 
Example #17
Source File: ContentViewCore.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #18
Source File: NestedRadioGroupManager.java    From NestedRadioButton with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
public void onProvideAutofillStructure(ViewStructure structure) {
    structure.setDataIsSensitive(checkedId != initialCheckedId);
}
 
Example #19
Source File: NestedFrameRadioGroup.java    From NestedRadioButton with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
@Override
public void onProvideAutofillStructure(ViewStructure structure, int flags) {
    super.onProvideAutofillStructure(structure, flags);
    nestedRadioGroupManager.onProvideAutofillStructure(structure);
}
 
Example #20
Source File: NestedLinearRadioGroup.java    From NestedRadioButton with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
@Override
public void onProvideAutofillStructure(ViewStructure structure, int flags) {
    super.onProvideAutofillStructure(structure, flags);
    nestedRadioGroupManager.onProvideAutofillStructure(structure);
}
 
Example #21
Source File: NestedConstraintRadioGroup.java    From NestedRadioButton with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.O)
@Override
public void onProvideAutofillStructure(ViewStructure structure, int flags) {
    super.onProvideAutofillStructure(structure, flags);
    nestedRadioGroupManager.onProvideAutofillStructure(structure);
}
 
Example #22
Source File: CompoundButton.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onProvideAutofillStructure(ViewStructure structure, int flags) {
    super.onProvideAutofillStructure(structure, flags);

    structure.setDataIsSensitive(!mCheckedFromResource);
}
 
Example #23
Source File: RadioGroup.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onProvideAutofillStructure(ViewStructure structure, int flags) {
    super.onProvideAutofillStructure(structure, flags);
    structure.setDataIsSensitive(mCheckedId != mInitialCheckedId);
}
 
Example #24
Source File: Switch.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onProvideAutofillStructure(ViewStructure structure, int flags) {
    super.onProvideAutofillStructure(structure, flags);
    onProvideAutoFillStructureForAssistOrAutofill(structure);
}
 
Example #25
Source File: Switch.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onProvideStructure(ViewStructure structure) {
    super.onProvideStructure(structure);
    onProvideAutoFillStructureForAssistOrAutofill(structure);
}
 
Example #26
Source File: AssistStructure.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public ViewStructure newChild(int index) {
    ViewNode node = new ViewNode();
    mNode.mChildren[index] = node;
    return new ViewNodeBuilder(mAssist, node, false);
}
 
Example #27
Source File: WebView.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void onProvideVirtualStructure(ViewStructure structure) {
    mProvider.getViewDelegate().onProvideVirtualStructure(structure);
}
 
Example #28
Source File: WebView.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>The {@link ViewStructure} traditionally represents a {@link View}, while for web pages
 * it represent HTML nodes. Hence, it's necessary to "map" the HTML properties in a way that is
 * understood by the {@link android.service.autofill.AutofillService} implementations:
 *
 * <ol>
 *   <li>Only the HTML nodes inside a {@code FORM} are generated.
 *   <li>The source of the HTML is set using {@link ViewStructure#setWebDomain(String)} in the
 *   node representing the WebView.
 *   <li>If a web page has multiple {@code FORM}s, only the data for the current form is
 *   represented&mdash;if the user taps a field from another form, then the current autofill
 *   context is canceled (by calling {@link android.view.autofill.AutofillManager#cancel()} and
 *   a new context is created for that {@code FORM}.
 *   <li>Similarly, if the page has {@code IFRAME} nodes, they are not initially represented in
 *   the view structure until the user taps a field from a {@code FORM} inside the
 *   {@code IFRAME}, in which case it would be treated the same way as multiple forms described
 *   above, except that the {@link ViewStructure#setWebDomain(String) web domain} of the
 *   {@code FORM} contains the {@code src} attribute from the {@code IFRAME} node.
 *   <li>The W3C autofill field ({@code autocomplete} tag attribute) maps to
 *   {@link ViewStructure#setAutofillHints(String[])}.
 *   <li>If the view is editable, the {@link ViewStructure#setAutofillType(int)} and
 *   {@link ViewStructure#setAutofillValue(AutofillValue)} must be set.
 *   <li>The {@code placeholder} attribute maps to {@link ViewStructure#setHint(CharSequence)}.
 *   <li>Other HTML attributes can be represented through
 *   {@link ViewStructure#setHtmlInfo(android.view.ViewStructure.HtmlInfo)}.
 * </ol>
 *
 * <p>If the WebView implementation can determine that the value of a field was set statically
 * (for example, not through Javascript), it should also call
 * {@code structure.setDataIsSensitive(false)}.
 *
 * <p>For example, an HTML form with 2 fields for username and password:
 *
 * <pre class="prettyprint">
 *    &lt;label&gt;Username:&lt;/label&gt;
 *    &lt;input type="text" name="username" id="user" value="Type your username" autocomplete="username" placeholder="Email or username"&gt;
 *    &lt;label&gt;Password:&lt;/label&gt;
 *    &lt;input type="password" name="password" id="pass" autocomplete="current-password" placeholder="Password"&gt;
 * </pre>
 *
 * <p>Would map to:
 *
 * <pre class="prettyprint">
 *     int index = structure.addChildCount(2);
 *     ViewStructure username = structure.newChild(index);
 *     username.setAutofillId(structure.getAutofillId(), 1); // id 1 - first child
 *     username.setAutofillHints("username");
 *     username.setHtmlInfo(username.newHtmlInfoBuilder("input")
 *         .addAttribute("type", "text")
 *         .addAttribute("name", "username")
 *         .addAttribute("label", "Username:")
 *         .build());
 *     username.setHint("Email or username");
 *     username.setAutofillType(View.AUTOFILL_TYPE_TEXT);
 *     username.setAutofillValue(AutofillValue.forText("Type your username"));
 *     // Value of the field is not sensitive because it was created statically and not changed.
 *     username.setDataIsSensitive(false);
 *
 *     ViewStructure password = structure.newChild(index + 1);
 *     username.setAutofillId(structure, 2); // id 2 - second child
 *     password.setAutofillHints("current-password");
 *     password.setHtmlInfo(password.newHtmlInfoBuilder("input")
 *         .addAttribute("type", "password")
 *         .addAttribute("name", "password")
 *         .addAttribute("label", "Password:")
 *         .build());
 *     password.setHint("Password");
 *     password.setAutofillType(View.AUTOFILL_TYPE_TEXT);
 * </pre>
 */
@Override
public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) {
    mProvider.getViewDelegate().onProvideAutofillVirtualStructure(structure, flags);
}
 
Example #29
Source File: ViewStructureImpl.java    From material-components-android with Apache License 2.0 votes vote down vote up
public void setAutofillId(ViewStructure parent, int virtualId) {}