1/*
2 * Copyright (C) 2017 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 com.android.settingslib.widget;
17
18import android.content.Context;
19import android.text.Spanned;
20import android.text.method.LinkMovementMethod;
21import android.text.style.ClickableSpan;
22import android.util.AttributeSet;
23import android.widget.TextView;
24
25/**
26 * Copied from setup wizard. This TextView performed two functions. The first is to make it so the
27 * link behaves properly and becomes clickable. The second was that it made the link visible to
28 * accessibility services, but from O forward support for links is provided natively.
29 */
30public class LinkTextView extends TextView {
31
32    public LinkTextView(Context context) {
33        this(context, null);
34    }
35
36    public LinkTextView(Context context, AttributeSet attrs) {
37        super(context, attrs);
38    }
39
40    @Override
41    public void setText(CharSequence text, BufferType type) {
42        super.setText(text, type);
43        if (text instanceof Spanned) {
44            final ClickableSpan[] spans =
45                    ((Spanned) text).getSpans(0, text.length(), ClickableSpan.class);
46            if (spans.length > 0) {
47                setMovementMethod(LinkMovementMethod.getInstance());
48            }
49        }
50    }
51}