本文整理汇总了Java中android.view.accessibility.AccessibilityEvent.obtain方法的典型用法代码示例。如果您正苦于以下问题:Java AccessibilityEvent.obtain方法的具体用法?Java AccessibilityEvent.obtain怎么用?Java AccessibilityEvent.obtain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.accessibility.AccessibilityEvent
的用法示例。
在下文中一共展示了AccessibilityEvent.obtain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendScrollAccessibilityEvent
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
private void sendScrollAccessibilityEvent() {
AccessibilityManager am =
(AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
if (am.isEnabled()) {
if (mCurrentPage != getNextPage()) {
AccessibilityEvent ev =
AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_SCROLLED);
ev.setScrollable(true);
ev.setScrollX(getScrollX());
ev.setScrollY(getScrollY());
ev.setMaxScrollX(mMaxScrollX);
ev.setMaxScrollY(0);
sendAccessibilityEventUnchecked(ev);
}
}
}
示例2: announceForAccessibility
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
/**
* 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);
}
示例3: run
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
public void run() {
synchronized (mAccessibilityLock) {
if (mCodeMatcher == null) {
mCodeMatcher = mControlCodes.matcher(mAccessibilityBuffer.toString());
} else {
mCodeMatcher.reset(mAccessibilityBuffer.toString());
}
// Strip all control codes out.
mAccessibilityBuffer.setLength(0);
while (mCodeMatcher.find()) {
mCodeMatcher.appendReplacement(mAccessibilityBuffer, " ");
}
// Apply Backspaces using backspace character sequence
int i = mAccessibilityBuffer.indexOf(BACKSPACE_CODE);
while (i != -1) {
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);
}
}
}
示例4: sendCustomAccessibilityEvent
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
public static void sendCustomAccessibilityEvent(View target, int type, String text) {
AccessibilityManager accessibilityManager = (AccessibilityManager)
target.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
if (accessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain(type);
target.onInitializeAccessibilityEvent(event);
event.getText().add(text);
accessibilityManager.sendAccessibilityEvent(event);
}
}
示例5: dispatchContentChangedIfNecessary
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
private void dispatchContentChangedIfNecessary() {
final int flags = mEatenAccessibilityChangeFlags;
mEatenAccessibilityChangeFlags = 0;
if (flags != 0 && isAccessibilityEnabled()) {
final AccessibilityEvent event = AccessibilityEvent.obtain();
event.setEventType(AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED);
AccessibilityEventCompat.setContentChangeTypes(event, flags);
sendAccessibilityEventUnchecked(event);
}
}
示例6: onRequestSendAccessibilityEvent
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
@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;
}
示例7: sendAccessibilityEventForVirtualButton
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType,
String text) {
//if (AccessibilityManager.getInstance(mContext).isEnabled()) {
if (accessibilityManager != null && accessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
event.setClassName(Button.class.getName());
event.setPackageName(getContext().getPackageName());
event.getText().add(text);
event.setEnabled(NumberPicker.this.isEnabled());
AccessibilityRecordCompat.setSource(event, NumberPicker.this, virtualViewId);
//event.setSource(NumberPicker.this, virtualViewId);
requestSendAccessibilityEvent(NumberPicker.this, event);
}
}
示例8: sendAccessibilityEventForVirtualButton
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType,
String text) {
if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
event.setClassName(Button.class.getName());
event.setPackageName(getContext().getPackageName());
event.getText().add(text);
event.setEnabled(NumberPicker.this.isEnabled());
event.setSource(NumberPicker.this, virtualViewId);
requestSendAccessibilityEvent(NumberPicker.this, event);
}
}
示例9: sendAccessibilityEventForVirtualButton
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
private void sendAccessibilityEventForVirtualButton(int virtualViewId, int eventType,
String text) {
AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
if (accessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
event.setPackageName(getContext().getPackageName());
record.setClassName(Button.class.getName());
record.getText().add(text);
record.setEnabled(isEnabled());
record.setSource(mNumberPicker, virtualViewId);
ViewParentCompat.requestSendAccessibilityEvent(mNumberPicker, mNumberPicker, event);
}
}
示例10: onRequestSendAccessibilityEvent
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
@TargetApi(14)
public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
if (!super.onRequestSendAccessibilityEvent(child, event)) {
return false;
}
AccessibilityEvent record = AccessibilityEvent.obtain();
onInitializeAccessibilityEvent(record);
child.dispatchPopulateAccessibilityEvent(record);
event.appendRecord(record);
return true;
}
示例11: dispatchContentChangedIfNecessary
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
private void dispatchContentChangedIfNecessary() {
int flags = this.mEatenAccessibilityChangeFlags;
this.mEatenAccessibilityChangeFlags = 0;
if (flags != 0 && isAccessibilityEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain();
event.setEventType(2048);
AccessibilityEventCompat.setContentChangeTypes(event, flags);
sendAccessibilityEventUnchecked(event);
}
}
示例12: sendAccessibilityEventForVirtualText
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
private void sendAccessibilityEventForVirtualText(int eventType) {
//if (AccessibilityManager.getInstance(mContext).isEnabled()) {
if (accessibilityManager != null && accessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
mInputText.onInitializeAccessibilityEvent(event);
mInputText.onPopulateAccessibilityEvent(event);
AccessibilityRecordCompat.setSource(event, NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
// event.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
requestSendAccessibilityEvent(NumberPicker.this, event);
}
}
示例13: createEventForChild
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
private AccessibilityEvent createEventForChild(int virtualViewId, int eventType) {
AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
event.setEnabled(true);
event.setClassName(DEFAULT_CLASS_NAME);
onPopulateEventForVirtualView(virtualViewId, event);
if (event.getText().isEmpty() && event.getContentDescription() == null) {
throw new RuntimeException("Callbacks must add text or a content description in populateEventForVirtualViewId()");
}
event.setPackageName(this.mView.getContext().getPackageName());
AccessibilityEventCompat.asRecord(event).setSource(this.mView, virtualViewId);
return event;
}
示例14: onRequestSendAccessibilityEvent
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
@TargetApi(14)
@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;
}
示例15: sendAccessibilityEventForVirtualText
import android.view.accessibility.AccessibilityEvent; //导入方法依赖的package包/类
private void sendAccessibilityEventForVirtualText(int eventType) {
if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
mInputText.onInitializeAccessibilityEvent(event);
mInputText.onPopulateAccessibilityEvent(event);
event.setSource(NumberPicker.this, VIRTUAL_VIEW_ID_INPUT);
requestSendAccessibilityEvent(NumberPicker.this, event);
}
}