Example usage for android.view.accessibility AccessibilityEvent TYPE_VIEW_FOCUSED

List of usage examples for android.view.accessibility AccessibilityEvent TYPE_VIEW_FOCUSED

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityEvent TYPE_VIEW_FOCUSED.

Prototype

int TYPE_VIEW_FOCUSED

To view the source code for android.view.accessibility AccessibilityEvent TYPE_VIEW_FOCUSED.

Click Source Link

Document

Represents the event of setting input focus of a android.view.View .

Usage

From source file:com.android.calendar.AllInOneActivity.java

private void setTitleInActionBar(EventInfo event) {
    if (event.eventType != EventType.UPDATE_TITLE) {
        return;/* w  w w. j  a v  a2  s  .  c o m*/
    }

    final long start = event.startTime.toMillis(false /* use isDst */);
    final long end;
    if (event.endTime != null) {
        end = event.endTime.toMillis(false /* use isDst */);
    } else {
        end = start;
    }

    final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong);
    CharSequence oldDate = mDateRange.getText();
    mDateRange.setText(msg);
    updateSecondaryTitleFields(event.selectedTime != null ? event.selectedTime.toMillis(true) : start);
    if (!TextUtils.equals(oldDate, msg)) {
        mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
        if (mShowWeekNum && mWeekTextView != null) {
            mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
        }
    }
}

From source file:com.android.calendar.event.EditEventView.java

private void sendAccessibilityEvent() {
    AccessibilityManager am = (AccessibilityManager) mActivity.getSystemService(Service.ACCESSIBILITY_SERVICE);
    if (!am.isEnabled() || mModel == null) {
        return;/* w ww  . j a v a2  s .  c  o m*/
    }
    StringBuilder b = new StringBuilder();
    addFieldsRecursive(b, mView);
    CharSequence msg = b.toString();

    AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    event.setClassName(getClass().getName());
    event.setPackageName(mActivity.getPackageName());
    event.getText().add(msg);
    event.setAddedCount(msg.length());

    am.sendAccessibilityEvent(event);
}

From source file:com.android.talkback.controller.CursorControllerApp.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    int eventType = event.getEventType();
    if (eventType == AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
        final AccessibilityNodeInfo node = event.getSource();
        if (node == null) {
            if (LogUtils.LOG_LEVEL <= Log.WARN) {
                Log.w(LOGTAG, "TYPE_VIEW_ACCESSIBILITY_FOCUSED event without a source.");
            }/* ww w . j av  a2 s  .c  o m*/
            return;
        }

        // When a new view gets focus, clear the state of the granularity
        // manager if this event came from a different node than the locked
        // node but from the same window.
        final AccessibilityNodeInfoCompat nodeCompat = new AccessibilityNodeInfoCompat(node);
        mGranularityManager.onNodeFocused(nodeCompat);
        if (mSwitchNodeWithGranularityDirection == AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY) {
            mGranularityManager.navigate(AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
        } else if (mSwitchNodeWithGranularityDirection == AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY) {
            mGranularityManager.startFromLastNode();
            mGranularityManager.navigate(AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);
        }
        mSwitchNodeWithGranularityDirection = 0;
        nodeCompat.recycle();
        mReachedEdge = false;
        mGranularityNavigationReachedEdge = false;
    } else if (eventType == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
        final AccessibilityNodeInfo node = event.getSource();
        if (node != null) {
            final AccessibilityNodeInfoCompat nodeCompat = new AccessibilityNodeInfoCompat(node);

            // Note: we also need to check ROLE_EDIT_TEXT for JB MR1 and lower and for
            // Chrome/WebView 51 and lower. We should check isEditable() first because it's
            // more semantically appropriate for what we want.
            if (nodeCompat.isEditable() || Role.getRole(nodeCompat) == Role.ROLE_EDIT_TEXT) {
                AccessibilityNodeInfoUtils.recycleNodes(mLastEditable);
                mLastEditable = nodeCompat;
            } else {
                nodeCompat.recycle();
            }
        }
    } else if (mIsWindowNavigationAvailable && eventType == AccessibilityEvent.TYPE_WINDOWS_CHANGED) {
        // Remove last focused nodes of non-existing windows.
        Set<Integer> windowIdsToBeRemoved = new HashSet(mLastFocusedNodeMap.keySet());
        for (AccessibilityWindowInfo window : mService.getWindows()) {
            windowIdsToBeRemoved.remove(window.getId());
        }
        for (Integer windowIdToBeRemoved : windowIdsToBeRemoved) {
            AccessibilityNodeInfoCompat removedNode = mLastFocusedNodeMap.remove(windowIdToBeRemoved);
            if (removedNode != null) {
                removedNode.recycle();
            }
        }
    }
}

From source file:com.android.calendar.EventInfoFragment.java

private void sendAccessibilityEvent() {
    AccessibilityManager am = (AccessibilityManager) getActivity()
            .getSystemService(Service.ACCESSIBILITY_SERVICE);
    if (!am.isEnabled()) {
        return;//w ww .  ja  va 2  s.  c  o m
    }

    AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    event.setClassName(EventInfoFragment.class.getName());
    event.setPackageName(getActivity().getPackageName());
    List<CharSequence> text = event.getText();

    addFieldToAccessibilityEvent(text, mTitle, null);
    addFieldToAccessibilityEvent(text, mWhenDateTime, null);
    addFieldToAccessibilityEvent(text, mWhere, null);
    addFieldToAccessibilityEvent(text, null, mDesc);

    if (mResponseRadioGroup.getVisibility() == View.VISIBLE) {
        int id = mResponseRadioGroup.getCheckedRadioButtonId();
        if (id != View.NO_ID) {
            text.add(((TextView) getView().findViewById(R.id.response_label)).getText());
            text.add((((RadioButton) (mResponseRadioGroup.findViewById(id))).getText() + PERIOD_SPACE));
        }
    }

    am.sendAccessibilityEvent(event);
}