AccessibilityURLSpan.java revision 23161e7170ec2493ec830d04205f5696be159026
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 */
16package android.text.style;
17
18import android.os.Parcel;
19import android.os.Parcelable;
20import android.text.TextUtils;
21import android.view.View;
22import 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 */
29public class AccessibilityURLSpan extends URLSpan implements Parcelable {
30    final AccessibilityClickableSpan mAccessibilityClickableSpan;
31
32    /**
33     * @param spanToReplace The original span
34     */
35    public AccessibilityURLSpan(URLSpan spanToReplace) {
36        super(spanToReplace.getURL());
37        mAccessibilityClickableSpan =
38                new AccessibilityClickableSpan(spanToReplace.getId());
39    }
40
41    public AccessibilityURLSpan(Parcel p) {
42        super(p);
43        mAccessibilityClickableSpan = new AccessibilityClickableSpan(p);
44    }
45
46    @Override
47    public int getSpanTypeId() {
48        return getSpanTypeIdInternal();
49    }
50
51    @Override
52    public int getSpanTypeIdInternal() {
53        return TextUtils.ACCESSIBILITY_URL_SPAN;
54    }
55
56    @Override
57    public void writeToParcel(Parcel dest, int flags) {
58        writeToParcelInternal(dest, flags);
59    }
60
61    @Override
62    public void writeToParcelInternal(Parcel dest, int flags) {
63        super.writeToParcelInternal(dest, flags);
64        mAccessibilityClickableSpan.writeToParcel(dest, flags);
65    }
66
67    @Override
68    public void onClick(View unused) {
69        mAccessibilityClickableSpan.onClick(unused);
70    }
71
72    /**
73     * Delegated to AccessibilityClickableSpan
74     * @param accessibilityNodeInfo
75     */
76    public void copyConnectionDataFrom(AccessibilityNodeInfo accessibilityNodeInfo) {
77        mAccessibilityClickableSpan.copyConnectionDataFrom(accessibilityNodeInfo);
78    }
79}
80