示例#1
0
    public void run() {
      synchronized (mAccessibilityLock) {
        if (mCodeMatcher == null) {
          mCodeMatcher = mControlCodes.matcher(mAccessibilityBuffer);
        } else {
          mCodeMatcher.reset(mAccessibilityBuffer);
        }

        // Strip all control codes out.
        mAccessibilityBuffer = new StringBuffer(mCodeMatcher.replaceAll(" "));

        // Apply Backspaces using backspace character sequence
        int i = mAccessibilityBuffer.indexOf(BACKSPACE_CODE);
        while (i != -1) {
          mAccessibilityBuffer =
              mAccessibilityBuffer.replace(i == 0 ? 0 : i - 1, i + BACKSPACE_CODE.length(), "");
          i = mAccessibilityBuffer.indexOf(BACKSPACE_CODE);
        }

        if (mAccessibilityBuffer.length() > 0) {
          AccessibilityEvent event =
              AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
          event.setFromIndex(0);
          event.setAddedCount(mAccessibilityBuffer.length());
          event.getText().add(mAccessibilityBuffer);

          sendAccessibilityEventUnchecked(event);
          mAccessibilityBuffer.setLength(0);
        }
      }
    }
示例#2
0
  @Override
  public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    boolean populated = false;
    // This is an exceptional case which occurs when a window gets the
    // focus and sends a focus event via its focused child to announce
    // current focus/selection. CarouselAdapter fires selection but not focus
    // events so we change the event type here.
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
      event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED);
    }

    // we send selection events only from CarouselAdapter to avoid
    // generation of such event for each child
    View selectedView = getSelectedView();
    if (selectedView != null) {
      populated = selectedView.dispatchPopulateAccessibilityEvent(event);
    }

    if (!populated) {
      if (selectedView != null) {
        event.setEnabled(selectedView.isEnabled());
      }
      event.setItemCount(getCount());
      event.setCurrentItemIndex(getSelectedItemPosition());
    }

    return populated;
  }
 public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
   super.onInitializeAccessibilityEvent(accessibilityEvent);
   if (accessibilityEvent.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
     accessibilityEvent.setFromIndex(0);
     accessibilityEvent.setToIndex(0);
   }
 }
示例#4
0
  // BEGIN_INCLUDE (on_populate_accessibility_event)
  @Override
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    super.onPopulateAccessibilityEvent(event);

    // Detect what type of accessibility event is being passed in.
    int eventType = event.getEventType();

    // Common case: The user has interacted with our view in some way. State may or may not
    // have been changed. Read out the current status of the view.
    //
    // We also set some other metadata which is not used by TalkBack, but could be used by
    // other TTS engines.
    if (eventType == AccessibilityEvent.TYPE_VIEW_SELECTED
        || eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
      event.getText().add("Mode selected: " + Integer.toString(mActiveSelection + 1) + ".");
      event.setItemCount(SELECTION_COUNT);
      event.setCurrentItemIndex(mActiveSelection);
    }

    // When a user first focuses on our view, we'll also read out some simple instructions to
    // make it clear that this is an interactive element.
    if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
      event.getText().add("Tap to change.");
    }
  }
示例#5
0
 private void sendCustomAccessibilityEvent(int type, String text) {
   if (mAM.isEnabled()) {
     AccessibilityEvent event = AccessibilityEvent.obtain(type);
     onInitializeAccessibilityEvent(event);
     event.getText().add(text);
     mAM.sendAccessibilityEvent(event);
   }
 }
  @Override
  public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);

    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
      event.setFromIndex(0);
      event.setToIndex(0);
    }
  }
示例#7
0
    String toString(AccessibilityEvent event) {
      String str = "";
      str += "eventtype: " + AccessibilityEvent.eventTypeToString(event.getEventType());
      str += "\nsource: " + event.getSource();
      str += "\npackagename: " + event.getPackageName();
      str += "\nclassname: " + event.getClassName();

      return str;
    }
 private void sendCustomAccessibilityEvent(int type, String text) {
   AccessibilityManager accessibilityManager =
       (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
   if (accessibilityManager.isEnabled()) {
     AccessibilityEvent event = AccessibilityEvent.obtain(type);
     onInitializeAccessibilityEvent(event);
     event.getText().add(text);
     accessibilityManager.sendAccessibilityEvent(event);
   }
 }
 @Override
 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
   // Standard group layout onPopulateAccessibilityEvent() implementations
   // ignore content description, so populate manually
   if (mWifiVisible && mWifiGroup.getContentDescription() != null)
     event.getText().add(mWifiGroup.getContentDescription());
   if (mMobileVisible && mMobileGroup.getContentDescription() != null)
     event.getText().add(mMobileGroup.getContentDescription());
   return super.dispatchPopulateAccessibilityEvent(event);
 }
  @Override
  public void onAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) return;

    if (!Helper.GOOGLE_VOICE_PACKAGE.equals(event.getPackageName())) return;

    clearGoogleVoiceNotifications();

    startRefresh();
  }
  /**
   * Sends the specified text to the {@link AccessibilityManager} to be spoken.
   *
   * @param view The source view.
   * @param text The text to speak.
   */
  public void announceForAccessibility(final View view, final CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
      Log.e(TAG, "Attempted to speak when accessibility was disabled!");
      return;
    }

    // The following is a hack to avoid using the heavy-weight TextToSpeech
    // class. Instead, we're just forcing a fake AccessibilityEvent into
    // the screen reader to make it speak.
    final AccessibilityEvent event = AccessibilityEvent.obtain();

    event.setPackageName(PACKAGE);
    event.setClassName(CLASS);
    event.setEventTime(SystemClock.uptimeMillis());
    event.setEnabled(true);
    event.getText().add(text);

    // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use
    // announce events.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    } else {
      event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    final ViewParent viewParent = view.getParent();
    if ((viewParent == null) || !(viewParent instanceof ViewGroup)) {
      Log.e(TAG, "Failed to obtain ViewParent in announceForAccessibility");
      return;
    }

    viewParent.requestSendAccessibilityEvent(view, event);
  }
示例#12
0
 private void sendTapOutsideFolderAccessibilityEvent(boolean isEditingName) {
   AccessibilityManager accessibilityManager =
       (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
   if (accessibilityManager.isEnabled()) {
     int stringId = isEditingName ? R.string.folder_tap_to_rename : R.string.folder_tap_to_close;
     AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_FOCUSED);
     onInitializeAccessibilityEvent(event);
     event.getText().add(getContext().getString(stringId));
     accessibilityManager.sendAccessibilityEvent(event);
   }
 }
示例#13
0
  public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    event.setClassName(getClass().getName());
    event.setPackageName(mContext.getPackageName());

    LayoutParams params = getWindow().getAttributes();
    boolean isFullScreen =
        (params.width == LayoutParams.MATCH_PARENT) && (params.height == LayoutParams.MATCH_PARENT);
    event.setFullScreen(isFullScreen);

    return false;
  }
 public void onInitializeAccessibilityEvent(
     View paramView, AccessibilityEvent paramAccessibilityEvent) {
   super.onInitializeAccessibilityEvent(paramView, paramAccessibilityEvent);
   paramAccessibilityEvent.setClassName(ViewPager.class.getName());
   paramView = android.support.v4.view.a.a.a(paramAccessibilityEvent);
   paramView.a(a());
   if ((paramAccessibilityEvent.getEventType() == 4096) && (ViewPager.access$200(a) != null)) {
     paramView.a(ViewPager.access$200(a).getCount());
     paramView.b(ViewPager.access$300(a));
     paramView.c(ViewPager.access$300(a));
   }
 }
 @SuppressLint("NewApi")
 @Override
 public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
   if (super.onRequestSendAccessibilityEvent(child, event)) {
     AccessibilityEvent record = AccessibilityEvent.obtain();
     onInitializeAccessibilityEvent(record);
     child.dispatchPopulateAccessibilityEvent(record);
     event.appendRecord(record);
     return true;
   }
   return false;
 }
 @Override
 public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
   if (super.onRequestSendAccessibilityEvent(child, event)) {
     // Add a record for ourselves as well.
     AccessibilityEvent record = AccessibilityEvent.obtain();
     onInitializeAccessibilityEvent(record);
     // Populate with the text of the requesting child.
     child.dispatchPopulateAccessibilityEvent(record);
     event.appendRecord(record);
     return true;
   }
   return false;
 }
 @Override
 public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
   if (super.onRequestSendAccessibilityEvent(child, event)) {
     // Add a record for the entire layout since its content is somehow small.
     // The event comes from a leaf view that is interacted with.
     AccessibilityEvent record = AccessibilityEvent.obtain();
     onInitializeAccessibilityEvent(record);
     dispatchPopulateAccessibilityEvent(record);
     event.appendRecord(record);
     return true;
   }
   return false;
 }
示例#18
0
 @Override
 public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
   super.onPopulateAccessibilityEvent(host, event);
   if (sEventMessage != null) {
     populateEventFromJSON(event, sEventMessage);
     // No matter where the a11y focus is requested, we always force it back to the current vc
     // position.
     event.setSource(host, VIRTUAL_CURSOR_POSITION);
   }
   // We save the hover enter event so that we could reuse it for a subsequent accessibility
   // focus event.
   if (event.getEventType() != AccessibilityEvent.TYPE_VIEW_HOVER_ENTER) sEventMessage = null;
 }
    @Override
    protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) {
      if (mVirtualViews == null || mVirtualViews.size() <= virtualViewId) {
        // TODO(clholgat): Remove this work around when the Android bug is fixed.
        // crbug.com/420177
        event.setContentDescription(PLACE_HOLDER_STRING);
        return;
      }
      VirtualView view = mVirtualViews.get(virtualViewId);

      event.setContentDescription(view.getAccessibilityDescription());
      event.setClassName(CompositorViewHolder.class.getName());
    }
示例#20
0
 @Override
 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
   super.onInitializeAccessibilityEvent(event);
   int childCount = getChildCount();
   if (childCount > 0) {
     DeckChildView<T> backMostTask = (DeckChildView) getChildAt(0);
     DeckChildView<T> frontMostTask = (DeckChildView) getChildAt(childCount - 1);
     event.setFromIndex(mCallback.getData().indexOf(backMostTask.getAttachedKey()));
     event.setToIndex(mCallback.getData().indexOf(frontMostTask.getAttachedKey()));
   }
   event.setItemCount(mCallback.getData().size());
   event.setScrollY(mStackScroller.mScroller.getCurrY());
   event.setMaxScrollY(mStackScroller.progressToScrollRange(mLayoutAlgorithm.mMaxScrollP));
 }
  /** Announce the currently-selected date when launched. */
  @Override
  public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
      // Clear the event's current text so that only the current date will be spoken.
      event.getText().clear();
      int flags =
          DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY;

      String dateString = DateUtils.formatDateTime(getContext(), mDateMillis, flags);
      event.getText().add(dateString);
      return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
  }
 @Override
 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
   if (Build.VERSION.SDK_INT >= 14) {
     if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
       // Action mode started
       event.setSource(this);
       event.setClassName(getClass().getName());
       event.setPackageName(getContext().getPackageName());
       event.setContentDescription(mTitle);
     } else {
       super.onInitializeAccessibilityEvent(event);
     }
   }
 }
示例#23
0
 private static void sendDirectAccessibilityEvent(int eventType, JSONObject message) {
   final AccessibilityEvent accEvent = AccessibilityEvent.obtain(eventType);
   accEvent.setClassName(GeckoAccessibility.class.getName());
   accEvent.setPackageName(GeckoAppShell.getContext().getPackageName());
   populateEventFromJSON(accEvent, message);
   AccessibilityManager accessibilityManager =
       (AccessibilityManager)
           GeckoAppShell.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
   try {
     accessibilityManager.sendAccessibilityEvent(accEvent);
   } catch (IllegalStateException e) {
     // Accessibility is off.
   }
 }
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
 private void openHongBao(AccessibilityEvent event) {
   if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI".equals(event.getClassName())) {
     // 点中了红包,下一步就是去拆红包
     handleLuckyMoneyReceive();
   } else if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI"
       .equals(event.getClassName())) {
     // 拆完红包后看详细的纪录界面
     // nonething
   } else if ("com.tencent.mm.ui.LauncherUI".equals(event.getClassName())) {
     // 在聊天界面,去点中红包
     handleChatListHongBao();
   }
 }
 @Override
 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
   super.onInitializeAccessibilityEvent(event);
   if (!TextUtils.isEmpty(mAccessibilityClass)) {
     event.setClassName(mAccessibilityClass);
     if (Switch.class.getName().equals(mAccessibilityClass)) {
       String label =
           getResources()
               .getString(!mTileState ? R.string.switch_bar_on : R.string.switch_bar_off);
       event.setContentDescription(label);
       event.setChecked(!mTileState);
     }
   }
 }
 @Override
 public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
   // Standard group layout onPopulateAccessibilityEvent() implementations
   // ignore content description, so populate manually
   if (mEthernetVisible
       && mEthernetGroup != null
       && mEthernetGroup.getContentDescription() != null)
     event.getText().add(mEthernetGroup.getContentDescription());
   if (mWifiVisible && mWifiGroup != null && mWifiGroup.getContentDescription() != null)
     event.getText().add(mWifiGroup.getContentDescription());
   for (PhoneState state : mPhoneStates) {
     state.populateAccessibilityEvent(event);
   }
   return super.dispatchPopulateAccessibilityEventInternal(event);
 }
示例#27
0
文件: Toast.java 项目: Jiangyi/12055
 private void trySendAccessibilityEvent() {
   AccessibilityManager accessibilityManager =
       AccessibilityManager.getInstance(mView.getContext());
   if (!accessibilityManager.isEnabled()) {
     return;
   }
   // treat toasts as notifications since they are used to
   // announce a transient piece of information to the user
   AccessibilityEvent event =
       AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
   event.setClassName(getClass().getName());
   event.setPackageName(mView.getContext().getPackageName());
   mView.dispatchPopulateAccessibilityEvent(event);
   accessibilityManager.sendAccessibilityEvent(event);
 }
 public void onInitializeAccessibilityEvent(AccessibilityEvent paramAccessibilityEvent)
 {
   if (Build.VERSION.SDK_INT >= 14)
   {
     super.onInitializeAccessibilityEvent(paramAccessibilityEvent);
     paramAccessibilityEvent.setClassName(LinearLayoutCompat.class.getName());
   }
 }
  /** 打开通知栏消息 */
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  private void openNotify(AccessibilityEvent event) {
    if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification)) {
      return;
    }

    // 以下是精华,将微信的通知栏消息打开
    Notification notification = (Notification) event.getParcelableData();
    PendingIntent pendingIntent = notification.contentIntent;

    isFirstChecked = true;
    try {
      pendingIntent.send();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#30
0
 public final boolean dispatchPopulateAccessibilityEvent(
     View view, AccessibilityEvent accessibilityevent) {
   if (accessibilityevent.getEventType() == 32) {
     view = accessibilityevent.getText();
     accessibilityevent = FixedDrawerLayout.a(a);
     if (accessibilityevent != null) {
       int i = a.c(accessibilityevent);
       accessibilityevent = a.a(i);
       if (accessibilityevent != null) {
         view.add(accessibilityevent);
       }
     }
     return true;
   } else {
     return super.dispatchPopulateAccessibilityEvent(view, accessibilityevent);
   }
 }