Jason Monk | 783718ff | 2015-10-13 16:45:28 -0400 | [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 com.android.settings; |
| 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 | |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 26 | import com.android.settingslib.CustomDialogPreferenceCompat; |
Juan Lang | 4482812 | 2017-05-10 17:26:02 -0700 | [diff] [blame] | 27 | |
Jason Monk | 783718ff | 2015-10-13 16:45:28 -0400 | [diff] [blame] | 28 | /** |
| 29 | * Based on frameworks/base/core/java/android/preference/SeekBarDialogPreference.java |
| 30 | * except uses support lib preferences. |
| 31 | */ |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 32 | public class SeekBarDialogPreference extends CustomDialogPreferenceCompat { |
Jason Monk | 783718ff | 2015-10-13 16:45:28 -0400 | [diff] [blame] | 33 | private final Drawable mMyIcon; |
| 34 | |
| 35 | public SeekBarDialogPreference(Context context, AttributeSet attrs) { |
| 36 | super(context, attrs); |
| 37 | setDialogLayoutResource(R.layout.preference_dialog_seekbar_material); |
| 38 | |
| 39 | createActionButtons(); |
| 40 | |
| 41 | // Steal the XML dialogIcon attribute's value |
| 42 | mMyIcon = getDialogIcon(); |
| 43 | |
| 44 | setDialogIcon(null); |
| 45 | } |
| 46 | |
| 47 | public SeekBarDialogPreference(Context context) { |
| 48 | this(context, null); |
| 49 | } |
| 50 | |
| 51 | // Allow subclasses to override the action buttons |
| 52 | public void createActionButtons() { |
| 53 | setPositiveButtonText(android.R.string.ok); |
| 54 | setNegativeButtonText(android.R.string.cancel); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | protected void onBindDialogView(View view) { |
| 59 | super.onBindDialogView(view); |
| 60 | |
| 61 | final ImageView iconView = (ImageView) view.findViewById(android.R.id.icon); |
| 62 | if (mMyIcon != null) { |
| 63 | iconView.setImageDrawable(mMyIcon); |
| 64 | } else { |
| 65 | iconView.setVisibility(View.GONE); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | protected static SeekBar getSeekBar(View dialogView) { |
| 70 | return (SeekBar) dialogView.findViewById(R.id.seekbar); |
| 71 | } |
| 72 | } |