1 /* 2 * Copyright (C) 2012 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 package android.preference.cts; 17 18 import android.content.Context; 19 import android.content.res.TypedArray; 20 import android.graphics.drawable.Drawable; 21 import android.preference.EditTextPreference; 22 import android.util.AttributeSet; 23 24 public class CustomEditTextPreference extends EditTextPreference { 25 private Drawable mIcon; 26 private String mTitle; 27 28 public CustomEditTextPreference(Context context, AttributeSet attrs) { 29 super(context, attrs); 30 init(attrs); 31 setIcon(mIcon); 32 this.setTitle(mTitle); 33 } 34 35 public CustomEditTextPreference(Context context) { 36 super(context); 37 } 38 39 public CustomEditTextPreference(Context context, AttributeSet attrs, int defStyle) { 40 super(context, attrs, defStyle); 41 init(attrs); 42 setIcon(mIcon); 43 this.setTitle(mTitle); 44 } 45 46 private void init(AttributeSet attrs) { 47 TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustPref); 48 mTitle = a.getString(R.styleable.CustPref_title); 49 mIcon = a.getDrawable(R.styleable.CustPref_icon); 50 } 51 } 52