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