blob: a8e59924f896f7e9dd93b479b254e54a70dd1d72 [file] [log] [blame]
John Reck014fea22011-06-15 16:46:36 -07001/*
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 android.preference;
18
Mathew Inwoodeac8d0a2018-08-17 13:51:26 +010019import android.annotation.UnsupportedAppUsage;
John Reck014fea22011-06-15 16:46:36 -070020import android.content.Context;
21import android.graphics.drawable.Drawable;
John Reck014fea22011-06-15 16:46:36 -070022import android.util.AttributeSet;
23import android.view.View;
24import android.widget.ImageView;
25import android.widget.SeekBar;
26
Alan Viverette5c3188e2015-06-08 15:59:32 -070027import com.android.internal.R;
28
John Reck014fea22011-06-15 16:46:36 -070029/**
30 * @hide
31 */
32public class SeekBarDialogPreference extends DialogPreference {
Alan Viverette5c3188e2015-06-08 15:59:32 -070033 private final Drawable mMyIcon;
John Reck014fea22011-06-15 16:46:36 -070034
Alan Viverette617feb92013-09-09 18:09:13 -070035 public SeekBarDialogPreference(
36 Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
37 super(context, attrs, defStyleAttr, defStyleRes);
John Reck014fea22011-06-15 16:46:36 -070038
John Reck014fea22011-06-15 16:46:36 -070039 createActionButtons();
40
41 // Steal the XML dialogIcon attribute's value
42 mMyIcon = getDialogIcon();
Alan Viverette5c3188e2015-06-08 15:59:32 -070043
John Reck014fea22011-06-15 16:46:36 -070044 setDialogIcon(null);
45 }
46
Alan Viverette617feb92013-09-09 18:09:13 -070047 public SeekBarDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
48 this(context, attrs, defStyleAttr, 0);
49 }
50
Mathew Inwoodeac8d0a2018-08-17 13:51:26 +010051 @UnsupportedAppUsage
Alan Viverette617feb92013-09-09 18:09:13 -070052 public SeekBarDialogPreference(Context context, AttributeSet attrs) {
Alan Viverette5c3188e2015-06-08 15:59:32 -070053 this(context, attrs, R.attr.seekBarDialogPreferenceStyle);
Alan Viverette599d2a42013-09-16 13:48:29 -070054 }
55
56 public SeekBarDialogPreference(Context context) {
57 this(context, null);
Alan Viverette617feb92013-09-09 18:09:13 -070058 }
59
John Reck014fea22011-06-15 16:46:36 -070060 // Allow subclasses to override the action buttons
61 public void createActionButtons() {
Alan Viverette5c3188e2015-06-08 15:59:32 -070062 setPositiveButtonText(R.string.ok);
63 setNegativeButtonText(R.string.cancel);
John Reck014fea22011-06-15 16:46:36 -070064 }
65
66 @Override
67 protected void onBindDialogView(View view) {
68 super.onBindDialogView(view);
69
Alan Viverette5c3188e2015-06-08 15:59:32 -070070 final ImageView iconView = (ImageView) view.findViewById(R.id.icon);
John Reck014fea22011-06-15 16:46:36 -070071 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 Viverette5c3188e2015-06-08 15:59:32 -070079 return (SeekBar) dialogView.findViewById(R.id.seekbar);
John Reck014fea22011-06-15 16:46:36 -070080 }
81}