John Reck | 014fea2 | 2011-06-15 16:46:36 -0700 | [diff] [blame] | 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.preference.DialogPreference; |
| 22 | import android.util.AttributeSet; |
| 23 | import android.view.View; |
| 24 | import android.widget.ImageView; |
| 25 | import android.widget.SeekBar; |
| 26 | |
| 27 | /** |
| 28 | * @hide |
| 29 | */ |
| 30 | public class SeekBarDialogPreference extends DialogPreference { |
| 31 | private static final String TAG = "SeekBarDialogPreference"; |
| 32 | |
| 33 | private Drawable mMyIcon; |
| 34 | |
Alan Viverette | 617feb9 | 2013-09-09 18:09:13 -0700 | [diff] [blame] | 35 | public SeekBarDialogPreference( |
| 36 | Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 37 | super(context, attrs, defStyleAttr, defStyleRes); |
John Reck | 014fea2 | 2011-06-15 16:46:36 -0700 | [diff] [blame] | 38 | |
| 39 | setDialogLayoutResource(com.android.internal.R.layout.seekbar_dialog); |
| 40 | createActionButtons(); |
| 41 | |
| 42 | // Steal the XML dialogIcon attribute's value |
| 43 | mMyIcon = getDialogIcon(); |
| 44 | setDialogIcon(null); |
| 45 | } |
| 46 | |
Alan Viverette | 617feb9 | 2013-09-09 18:09:13 -0700 | [diff] [blame] | 47 | public SeekBarDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) { |
| 48 | this(context, attrs, defStyleAttr, 0); |
| 49 | } |
| 50 | |
| 51 | public SeekBarDialogPreference(Context context, AttributeSet attrs) { |
Alan Viverette | 599d2a4 | 2013-09-16 13:48:29 -0700 | [diff] [blame] | 52 | this(context, attrs, com.android.internal.R.attr.dialogPreferenceStyle); |
| 53 | } |
| 54 | |
| 55 | public SeekBarDialogPreference(Context context) { |
| 56 | this(context, null); |
Alan Viverette | 617feb9 | 2013-09-09 18:09:13 -0700 | [diff] [blame] | 57 | } |
| 58 | |
John Reck | 014fea2 | 2011-06-15 16:46:36 -0700 | [diff] [blame] | 59 | // Allow subclasses to override the action buttons |
| 60 | public void createActionButtons() { |
| 61 | setPositiveButtonText(android.R.string.ok); |
| 62 | setNegativeButtonText(android.R.string.cancel); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | protected void onBindDialogView(View view) { |
| 67 | super.onBindDialogView(view); |
| 68 | |
| 69 | final ImageView iconView = (ImageView) view.findViewById(android.R.id.icon); |
| 70 | if (mMyIcon != null) { |
| 71 | iconView.setImageDrawable(mMyIcon); |
| 72 | } else { |
| 73 | iconView.setVisibility(View.GONE); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | protected static SeekBar getSeekBar(View dialogView) { |
| 78 | return (SeekBar) dialogView.findViewById(com.android.internal.R.id.seekbar); |
| 79 | } |
| 80 | } |