19a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati/*
29a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati * Copyright (C) 2014 The Android Open Source Project
39a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati *
49a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati * Licensed under the Apache License, Version 2.0 (the "License");
59a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati * you may not use this file except in compliance with the License.
69a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati * You may obtain a copy of the License at
79a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati *
89a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati *      http://www.apache.org/licenses/LICENSE-2.0
99a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati *
109a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati * Unless required by applicable law or agreed to in writing, software
119a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati * distributed under the License is distributed on an "AS IS" BASIS,
129a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati * See the License for the specific language governing permissions and
149a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati * limitations under the License.
159a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati */
169a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati
179a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapatipackage com.android.phone.common.widget;
189a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati
199a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapatiimport android.content.Context;
209a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapatiimport android.content.res.TypedArray;
219a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapatiimport android.util.AttributeSet;
229a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapatiimport android.widget.EditText;
239a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati
249a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapatiimport com.android.phone.common.R;
259a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapatiimport com.android.phone.common.util.ViewUtil;
269a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati
279a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati/**
289a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati * EditText which resizes dynamically with respect to text length.
299a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati */
309a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapatipublic class ResizingTextEditText extends EditText {
319a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati    private final int mOriginalTextSize;
329a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati    private final int mMinTextSize;
339a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati
349a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati    public ResizingTextEditText(Context context, AttributeSet attrs) {
359a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati        super(context, attrs);
369a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati        mOriginalTextSize = (int) getTextSize();
379a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ResizingText);
389a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati        mMinTextSize = (int) a.getDimension(R.styleable.ResizingText_resizing_text_min_size,
399a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati                mOriginalTextSize);
409a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati        a.recycle();
419a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati    }
429a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati
439a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati    @Override
449a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati    protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
459a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati        super.onTextChanged(text, start, lengthBefore, lengthAfter);
469a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati        ViewUtil.resizeText(this, mOriginalTextSize, mMinTextSize);
479a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati    }
489a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati
499a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati    @Override
509a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
519a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati        super.onSizeChanged(w, h, oldw, oldh);
529a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati        ViewUtil.resizeText(this, mOriginalTextSize, mMinTextSize);
539a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati    }
549a17f0e3e1a3957c8c2b530171281943bec435f1Sai Cheemalapati}
55