17d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon/*
27d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * Copyright (C) 2011 The Android Open Source Project
37d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *
47d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * Licensed under the Apache License, Version 2.0 (the "License");
57d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * you may not use this file except in compliance with the License.
67d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * You may obtain a copy of the License at
77d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *
87d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *      http://www.apache.org/licenses/LICENSE-2.0
97d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *
107d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * Unless required by applicable law or agreed to in writing, software
117d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * distributed under the License is distributed on an "AS IS" BASIS,
127d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * See the License for the specific language governing permissions and
147d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * limitations under the License.
157d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon */
167d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
177d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonpackage com.android.phone;
187d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
197d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.content.Context;
207d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.preference.EditTextPreference;
217d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.util.AttributeSet;
227d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.view.View;
237d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonimport android.widget.TextView;
247d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
257d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon/**
267d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * Ultra-simple subclass of EditTextPreference that allows the "title" to wrap
277d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * onto multiple lines.
287d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *
297d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * (By default, the title of an EditTextPreference is singleLine="true"; see
307d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * preference_holo.xml under frameworks/base.  But in the "Respond via SMS"
317d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * settings UI we want titles to be multi-line, since the customized messages
327d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * might be fairly long, and should be able to wrap.)
337d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *
347d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * TODO: This is pretty cumbersome; it would be nicer for the framework to
357d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * either allow modifying the title's attributes in XML, or at least provide
367d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * some way from Java (given an EditTextPreference) to reach inside and get a
377d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * handle to the "title" TextView.
387d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *
397d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * TODO: Also, it would reduce clutter if this could be an inner class in
407d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * RespondViaSmsManager.java, but then there would be no way to reference the
417d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * class from XML.  That's because
427d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon *    <com.android.phone.RespondViaSmsManager$MultiLineTitleEditTextPreference ... />
437d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * isn't valid XML syntax due to the "$" character.  And Preference
447d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * elements don't have a "class" attribute, so you can't do something like
457d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon * <view class="com.android.phone.Foo$Bar"> as you can with regular views.
467d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon */
477d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordonpublic class MultiLineTitleEditTextPreference extends EditTextPreference {
487d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    public MultiLineTitleEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
497d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        super(context, attrs, defStyle);
507d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
517d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
527d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    public MultiLineTitleEditTextPreference(Context context, AttributeSet attrs) {
537d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        super(context, attrs);
547d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
557d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
567d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    public MultiLineTitleEditTextPreference(Context context) {
577d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        super(context);
587d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
597d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
607d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    // The "title" TextView inside an EditTextPreference defaults to
617d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    // singleLine="true" (see preference_holo.xml under frameworks/base.)
627d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    // We override onBindView() purely to look up that TextView and call
637d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    // setSingleLine(false) on it.
647d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    @Override
657d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    protected void onBindView(View view) {
667d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        super.onBindView(view);
677d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon
687d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        TextView textView = (TextView) view.findViewById(com.android.internal.R.id.title);
697d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        if (textView != null) {
707d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon            textView.setSingleLine(false);
717d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon        }
727d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon    }
737d4ddf6dc0d7c8158bac3a5dec7936e837e95bddSantos Cordon}
74