1/*
2 * Copyright (C) 2011 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.server.telecom;
18
19import android.content.Context;
20import android.preference.EditTextPreference;
21import android.util.AttributeSet;
22import android.view.View;
23import android.widget.TextView;
24
25/**
26 * Ultra-simple subclass of EditTextPreference that allows the "title" to wrap
27 * onto multiple lines.
28 *
29 * (By default, the title of an EditTextPreference is singleLine="true"; see
30 * preference_holo.xml under frameworks/base.  But in the "Respond via SMS"
31 * settings UI we want titles to be multi-line, since the customized messages
32 * might be fairly long, and should be able to wrap.)
33 *
34 * TODO: This is pretty cumbersome; it would be nicer for the framework to
35 * either allow modifying the title's attributes in XML, or at least provide
36 * some way from Java (given an EditTextPreference) to reach inside and get a
37 * handle to the "title" TextView.
38 *
39 * TODO: Also, it would reduce clutter if this could be an inner class in
40 * RespondViaSmsManager.java, but then there would be no way to reference the
41 * class from XML.  That's because
42 *    <com.android.server.telecom.MultiLineTitleEditTextPreference ... />
43 * isn't valid XML syntax due to the "$" character.  And Preference
44 * elements don't have a "class" attribute, so you can't do something like
45 * <view class="com.android.server.telecom.Foo$Bar"> as you can with regular views.
46 */
47public class MultiLineTitleEditTextPreference extends EditTextPreference {
48    public MultiLineTitleEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
49        super(context, attrs, defStyle);
50    }
51
52    public MultiLineTitleEditTextPreference(Context context, AttributeSet attrs) {
53        super(context, attrs);
54    }
55
56    public MultiLineTitleEditTextPreference(Context context) {
57        super(context);
58    }
59
60    // The "title" TextView inside an EditTextPreference defaults to
61    // singleLine="true" (see preference_holo.xml under frameworks/base.)
62    // We override onBindView() purely to look up that TextView and call
63    // setSingleLine(false) on it.
64    @Override
65    protected void onBindView(View view) {
66        super.onBindView(view);
67
68        TextView textView = (TextView) view.findViewById(com.android.internal.R.id.title);
69        if (textView != null) {
70            textView.setSingleLine(false);
71        }
72    }
73}
74