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 17 package com.android.settings.widget; 18 19 import android.content.Context; 20 import android.support.v4.content.res.TypedArrayUtils; 21 import android.support.v7.preference.Preference; 22 import android.support.v7.preference.PreferenceViewHolder; 23 import android.text.method.LinkMovementMethod; 24 import android.util.AttributeSet; 25 import android.widget.TextView; 26 27 import com.android.settings.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 */ 33 public 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