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