1ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad/* 2ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * Copyright (C) 2011 The Android Open Source Project 3ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * 4ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * Licensed under the Apache License, Version 2.0 (the "License"); 5ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * you may not use this file except in compliance with the License. 6ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * You may obtain a copy of the License at 7ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * 8ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * http://www.apache.org/licenses/LICENSE-2.0 9ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * 10ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * Unless required by applicable law or agreed to in writing, software 11ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * distributed under the License is distributed on an "AS IS" BASIS, 12ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * See the License for the specific language governing permissions and 14ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * limitations under the License. 15ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad */ 16ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad 177cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunnpackage com.android.server.telecom; 18ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad 19ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awadimport android.content.Context; 20ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awadimport android.preference.EditTextPreference; 21ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awadimport android.util.AttributeSet; 22ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awadimport android.view.View; 23ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awadimport android.widget.TextView; 24ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad 25ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad/** 26ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * Ultra-simple subclass of EditTextPreference that allows the "title" to wrap 27ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * onto multiple lines. 28ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * 29ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * (By default, the title of an EditTextPreference is singleLine="true"; see 30ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * preference_holo.xml under frameworks/base. But in the "Respond via SMS" 31ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * settings UI we want titles to be multi-line, since the customized messages 32ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * might be fairly long, and should be able to wrap.) 33ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * 34ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * TODO: This is pretty cumbersome; it would be nicer for the framework to 35ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * either allow modifying the title's attributes in XML, or at least provide 36ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * some way from Java (given an EditTextPreference) to reach inside and get a 37ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * handle to the "title" TextView. 38ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * 39ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * TODO: Also, it would reduce clutter if this could be an inner class in 40ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * RespondViaSmsManager.java, but then there would be no way to reference the 41ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * class from XML. That's because 427cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn * <com.android.server.telecom.MultiLineTitleEditTextPreference ... /> 43ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * isn't valid XML syntax due to the "$" character. And Preference 44ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad * elements don't have a "class" attribute, so you can't do something like 457cc70b4f0ad1064a4a0dce6056ad82b205887160Tyler Gunn * <view class="com.android.server.telecom.Foo$Bar"> as you can with regular views. 46ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad */ 47ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awadpublic class MultiLineTitleEditTextPreference extends EditTextPreference { 48ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad public MultiLineTitleEditTextPreference(Context context, AttributeSet attrs, int defStyle) { 49ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad super(context, attrs, defStyle); 50ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad } 51ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad 52ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad public MultiLineTitleEditTextPreference(Context context, AttributeSet attrs) { 53ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad super(context, attrs); 54ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad } 55ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad 56ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad public MultiLineTitleEditTextPreference(Context context) { 57ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad super(context); 58ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad } 59ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad 60ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad // The "title" TextView inside an EditTextPreference defaults to 61ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad // singleLine="true" (see preference_holo.xml under frameworks/base.) 62ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad // We override onBindView() purely to look up that TextView and call 63ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad // setSingleLine(false) on it. 64ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad @Override 65ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad protected void onBindView(View view) { 66ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad super.onBindView(view); 67ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad 68ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad TextView textView = (TextView) view.findViewById(com.android.internal.R.id.title); 69ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad if (textView != null) { 70ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad textView.setSingleLine(false); 71ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad } 72ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad } 73ff7493a8f620509d41dd8a5106c1d0dcd27cd274Ihab Awad} 74