1 /* 2 * Copyright (C) 2007 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 17 package android.preference; 18 19 import android.content.Context; 20 import android.graphics.drawable.Drawable; 21 import android.util.AttributeSet; 22 import android.view.View; 23 import android.widget.ImageView; 24 import android.widget.SeekBar; 25 26 import com.android.internal.R; 27 28 /** 29 * @hide 30 */ 31 public class SeekBarDialogPreference extends DialogPreference { 32 private final Drawable mMyIcon; 33 SeekBarDialogPreference( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)34 public SeekBarDialogPreference( 35 Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 36 super(context, attrs, defStyleAttr, defStyleRes); 37 38 createActionButtons(); 39 40 // Steal the XML dialogIcon attribute's value 41 mMyIcon = getDialogIcon(); 42 43 setDialogIcon(null); 44 } 45 SeekBarDialogPreference(Context context, AttributeSet attrs, int defStyleAttr)46 public SeekBarDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) { 47 this(context, attrs, defStyleAttr, 0); 48 } 49 SeekBarDialogPreference(Context context, AttributeSet attrs)50 public SeekBarDialogPreference(Context context, AttributeSet attrs) { 51 this(context, attrs, R.attr.seekBarDialogPreferenceStyle); 52 } 53 SeekBarDialogPreference(Context context)54 public SeekBarDialogPreference(Context context) { 55 this(context, null); 56 } 57 58 // Allow subclasses to override the action buttons createActionButtons()59 public void createActionButtons() { 60 setPositiveButtonText(R.string.ok); 61 setNegativeButtonText(R.string.cancel); 62 } 63 64 @Override onBindDialogView(View view)65 protected void onBindDialogView(View view) { 66 super.onBindDialogView(view); 67 68 final ImageView iconView = (ImageView) view.findViewById(R.id.icon); 69 if (mMyIcon != null) { 70 iconView.setImageDrawable(mMyIcon); 71 } else { 72 iconView.setVisibility(View.GONE); 73 } 74 } 75 getSeekBar(View dialogView)76 protected static SeekBar getSeekBar(View dialogView) { 77 return (SeekBar) dialogView.findViewById(R.id.seekbar); 78 } 79 } 80