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
17package com.android.settingslib.widget;
18
19import android.content.Context;
20import android.support.v4.content.res.TypedArrayUtils;
21import android.support.v7.preference.Preference;
22import android.support.v7.preference.PreferenceViewHolder;
23import android.text.method.LinkMovementMethod;
24import android.util.AttributeSet;
25import android.widget.TextView;
26
27import com.android.settingslib.R;
28
29/**
30 * A custom preference acting as "footer" of a page. It has a field for icon and text. It is added
31 * to screen as the last preference.
32 */
33public class FooterPreference extends Preference {
34
35    static final int ORDER_FOOTER = Integer.MAX_VALUE - 1;
36    static final String KEY_FOOTER = "footer_preference";
37
38    public FooterPreference(Context context, AttributeSet attrs) {
39        super(context, attrs, TypedArrayUtils.getAttr(
40                context, R.attr.footerPreferenceStyle, android.R.attr.preferenceStyle));
41        init();
42    }
43
44    public FooterPreference(Context context) {
45        this(context, null);
46    }
47
48    @Override
49    public void onBindViewHolder(PreferenceViewHolder holder) {
50        super.onBindViewHolder(holder);
51        TextView title = holder.itemView.findViewById(android.R.id.title);
52        title.setMovementMethod(new LinkMovementMethod());
53        title.setClickable(false);
54        title.setLongClickable(false);
55    }
56
57    private void init() {
58        setIcon(R.drawable.ic_info_outline_24dp);
59        setKey(KEY_FOOTER);
60        setOrder(ORDER_FOOTER);
61        setSelectable(false);
62    }
63}
64