blob: d0c8134176b2c7058dd20fe87d264310dbc30692 [file] [log] [blame]
Jason Monk783718ff2015-10-13 16:45:28 -04001/*
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
17package com.android.settings;
18
19import android.content.Context;
20import android.graphics.drawable.Drawable;
21import android.util.AttributeSet;
22import android.view.View;
23import android.widget.ImageView;
24import android.widget.SeekBar;
25
tmfang27c84de2018-06-28 11:39:05 +080026import com.android.settingslib.CustomDialogPreferenceCompat;
Juan Lang44828122017-05-10 17:26:02 -070027
Jason Monk783718ff2015-10-13 16:45:28 -040028/**
29 * Based on frameworks/base/core/java/android/preference/SeekBarDialogPreference.java
30 * except uses support lib preferences.
31 */
tmfang27c84de2018-06-28 11:39:05 +080032public class SeekBarDialogPreference extends CustomDialogPreferenceCompat {
Jason Monk783718ff2015-10-13 16:45:28 -040033 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}