• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
26 import com.android.settingslib.CustomDialogPreferenceCompat;
27 
28 /**
29  * Based on frameworks/base/core/java/android/preference/SeekBarDialogPreference.java
30  * except uses support lib preferences.
31  */
32 public class SeekBarDialogPreference extends CustomDialogPreferenceCompat {
33     private final Drawable mMyIcon;
34 
SeekBarDialogPreference(Context context, AttributeSet attrs)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 
SeekBarDialogPreference(Context context)47     public SeekBarDialogPreference(Context context) {
48         this(context, null);
49     }
50 
51     // Allow subclasses to override the action buttons
createActionButtons()52     public void createActionButtons() {
53         setPositiveButtonText(android.R.string.ok);
54         setNegativeButtonText(android.R.string.cancel);
55     }
56 
57     @Override
onBindDialogView(View view)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 
getSeekBar(View dialogView)69     protected static SeekBar getSeekBar(View dialogView) {
70         return (SeekBar) dialogView.findViewById(R.id.seekbar);
71     }
72 }
73