• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 @android.ravenwood.annotation.RavenwoodKeepWholeClass
31 public class AccessibilityURLSpan extends URLSpan implements Parcelable {
32     final AccessibilityClickableSpan mAccessibilityClickableSpan;
33 
34     /**
35      * @param spanToReplace The original span
36      */
AccessibilityURLSpan(URLSpan spanToReplace)37     public AccessibilityURLSpan(URLSpan spanToReplace) {
38         super(spanToReplace.getURL());
39         mAccessibilityClickableSpan =
40                 new AccessibilityClickableSpan(spanToReplace.getId());
41     }
42 
AccessibilityURLSpan(Parcel p)43     public AccessibilityURLSpan(Parcel p) {
44         super(p);
45         mAccessibilityClickableSpan = new AccessibilityClickableSpan(p);
46     }
47 
48     @Override
getSpanTypeId()49     public int getSpanTypeId() {
50         return getSpanTypeIdInternal();
51     }
52 
53     @Override
getSpanTypeIdInternal()54     public int getSpanTypeIdInternal() {
55         return TextUtils.ACCESSIBILITY_URL_SPAN;
56     }
57 
58     @Override
writeToParcel(Parcel dest, int flags)59     public void writeToParcel(Parcel dest, int flags) {
60         writeToParcelInternal(dest, flags);
61     }
62 
63     @Override
writeToParcelInternal(Parcel dest, int flags)64     public void writeToParcelInternal(Parcel dest, int flags) {
65         super.writeToParcelInternal(dest, flags);
66         mAccessibilityClickableSpan.writeToParcel(dest, flags);
67     }
68 
69     @Override
onClick(View unused)70     public void onClick(View unused) {
71         mAccessibilityClickableSpan.onClick(unused);
72     }
73 
74     /**
75      * Delegated to AccessibilityClickableSpan
76      * @param accessibilityNodeInfo
77      */
copyConnectionDataFrom(AccessibilityNodeInfo accessibilityNodeInfo)78     public void copyConnectionDataFrom(AccessibilityNodeInfo accessibilityNodeInfo) {
79         mAccessibilityClickableSpan.copyConnectionDataFrom(accessibilityNodeInfo);
80     }
81 }
82