blob: eeb69a39abe8a34f1b961ed5e5050d25984952a7 [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
19import android.content.Context;
20import android.graphics.drawable.Drawable;
John Reck014fea22011-06-15 16:46:36 -070021import android.util.AttributeSet;
22import android.view.View;
23import android.widget.ImageView;
24import android.widget.SeekBar;
25
Alan Viverette5c3188e2015-06-08 15:59:32 -070026import com.android.internal.R;
27
John Reck014fea22011-06-15 16:46:36 -070028/**
29 * @hide
30 */
31public class SeekBarDialogPreference extends DialogPreference {
Alan Viverette5c3188e2015-06-08 15:59:32 -070032 private final Drawable mMyIcon;
John Reck014fea22011-06-15 16:46:36 -070033
Alan Viverette617feb92013-09-09 18:09:13 -070034 public SeekBarDialogPreference(
35 Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
36 super(context, attrs, defStyleAttr, defStyleRes);
John Reck014fea22011-06-15 16:46:36 -070037
John Reck014fea22011-06-15 16:46:36 -070038 createActionButtons();
39
40 // Steal the XML dialogIcon attribute's value
41 mMyIcon = getDialogIcon();
Alan Viverette5c3188e2015-06-08 15:59:32 -070042
John Reck014fea22011-06-15 16:46:36 -070043 setDialogIcon(null);
44 }
45
Alan Viverette617feb92013-09-09 18:09:13 -070046 public SeekBarDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
47 this(context, attrs, defStyleAttr, 0);
48 }
49
50 public SeekBarDialogPreference(Context context, AttributeSet attrs) {
Alan Viverette5c3188e2015-06-08 15:59:32 -070051 this(context, attrs, R.attr.seekBarDialogPreferenceStyle);
Alan Viverette599d2a42013-09-16 13:48:29 -070052 }
53
54 public SeekBarDialogPreference(Context context) {
55 this(context, null);
Alan Viverette617feb92013-09-09 18:09:13 -070056 }
57
John Reck014fea22011-06-15 16:46:36 -070058 // Allow subclasses to override the action buttons
59 public void createActionButtons() {
Alan Viverette5c3188e2015-06-08 15:59:32 -070060 setPositiveButtonText(R.string.ok);
61 setNegativeButtonText(R.string.cancel);
John Reck014fea22011-06-15 16:46:36 -070062 }
63
64 @Override
65 protected void onBindDialogView(View view) {
66 super.onBindDialogView(view);
67
Alan Viverette5c3188e2015-06-08 15:59:32 -070068 final ImageView iconView = (ImageView) view.findViewById(R.id.icon);
John Reck014fea22011-06-15 16:46:36 -070069 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 Viverette5c3188e2015-06-08 15:59:32 -070077 return (SeekBar) dialogView.findViewById(R.id.seekbar);
John Reck014fea22011-06-15 16:46:36 -070078 }
79}