IconPreferenceScreen.java revision 498d90474b4208fd28cc2ae84d5759ddad7bfc0c
1498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani/* 2498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * Copyright (C) 2009 The Android Open Source Project 3498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * 4498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * Licensed under the Apache License, Version 2.0 (the "License"); 5498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * you may not use this file except in compliance with the License. 6498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * You may obtain a copy of the License at 7498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * 8498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * http://www.apache.org/licenses/LICENSE-2.0 9498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * 10498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * Unless required by applicable law or agreed to in writing, software 11498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * distributed under the License is distributed on an "AS IS" BASIS, 12498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * See the License for the specific language governing permissions and 14498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani * limitations under the License. 15498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani */ 16498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani 17498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasanipackage com.android.settings; 18498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani 19498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasaniimport android.content.Context; 20498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasaniimport android.content.res.TypedArray; 21498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasaniimport android.graphics.drawable.Drawable; 22498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasaniimport android.preference.Preference; 23498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasaniimport android.util.AttributeSet; 24498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasaniimport android.view.View; 25498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasaniimport android.widget.ImageView; 26498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani 27498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasanipublic class IconPreferenceScreen extends Preference { 28498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani 29498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani private Drawable mIcon; 30498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani 31498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani public IconPreferenceScreen(Context context, AttributeSet attrs) { 32498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani this(context, attrs, 0); 33498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani } 34498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani 35498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani public IconPreferenceScreen(Context context, AttributeSet attrs, int defStyle) { 36498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani super(context, attrs, defStyle); 37498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani setLayoutResource(R.layout.preference_icon); 38498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani TypedArray a = context.obtainStyledAttributes(attrs, 39498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani R.styleable.IconPreferenceScreen, defStyle, 0); 40498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani mIcon = a.getDrawable(R.styleable.IconPreferenceScreen_icon); 41498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani } 42498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani 43498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani @Override 44498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani public void onBindView(View view) { 45498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani super.onBindView(view); 46498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani ImageView imageView = (ImageView) view.findViewById(R.id.icon); 47498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani if (imageView != null && mIcon != null) { 48498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani imageView.setImageDrawable(mIcon); 49498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani } 50498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani } 51498d90474b4208fd28cc2ae84d5759ddad7bfc0cAmith Yamasani} 52