1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.text.style; 17 18 import android.os.Parcel; 19 import android.os.Parcelable; 20 import android.text.TextUtils; 21 import android.view.View; 22 import android.view.accessibility.AccessibilityNodeInfo; 23 24 /** 25 * URLSpan's onClick method does not work from an accessibility service. This version of it does. 26 * It is used to replace URLSpans in {@link AccessibilityNodeInfo#setText(CharSequence)} 27 * @hide 28 */ 29 @SuppressWarnings("ParcelableCreator") 30 public class AccessibilityURLSpan extends URLSpan implements Parcelable { 31 final AccessibilityClickableSpan mAccessibilityClickableSpan; 32 33 /** 34 * @param spanToReplace The original span 35 */ AccessibilityURLSpan(URLSpan spanToReplace)36 public AccessibilityURLSpan(URLSpan spanToReplace) { 37 super(spanToReplace.getURL()); 38 mAccessibilityClickableSpan = 39 new AccessibilityClickableSpan(spanToReplace.getId()); 40 } 41 AccessibilityURLSpan(Parcel p)42 public AccessibilityURLSpan(Parcel p) { 43 super(p); 44 mAccessibilityClickableSpan = new AccessibilityClickableSpan(p); 45 } 46 47 @Override getSpanTypeId()48 public int getSpanTypeId() { 49 return getSpanTypeIdInternal(); 50 } 51 52 @Override getSpanTypeIdInternal()53 public int getSpanTypeIdInternal() { 54 return TextUtils.ACCESSIBILITY_URL_SPAN; 55 } 56 57 @Override writeToParcel(Parcel dest, int flags)58 public void writeToParcel(Parcel dest, int flags) { 59 writeToParcelInternal(dest, flags); 60 } 61 62 @Override writeToParcelInternal(Parcel dest, int flags)63 public void writeToParcelInternal(Parcel dest, int flags) { 64 super.writeToParcelInternal(dest, flags); 65 mAccessibilityClickableSpan.writeToParcel(dest, flags); 66 } 67 68 @Override onClick(View unused)69 public void onClick(View unused) { 70 mAccessibilityClickableSpan.onClick(unused); 71 } 72 73 /** 74 * Delegated to AccessibilityClickableSpan 75 * @param accessibilityNodeInfo 76 */ copyConnectionDataFrom(AccessibilityNodeInfo accessibilityNodeInfo)77 public void copyConnectionDataFrom(AccessibilityNodeInfo accessibilityNodeInfo) { 78 mAccessibilityClickableSpan.copyConnectionDataFrom(accessibilityNodeInfo); 79 } 80 } 81