1014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck/*
2014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * Copyright (C) 2007 The Android Open Source Project
3014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck *
4014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * Licensed under the Apache License, Version 2.0 (the "License");
5014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * you may not use this file except in compliance with the License.
6014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * You may obtain a copy of the License at
7014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck *
8014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck *      http://www.apache.org/licenses/LICENSE-2.0
9014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck *
10014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * Unless required by applicable law or agreed to in writing, software
11014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * distributed under the License is distributed on an "AS IS" BASIS,
12014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * See the License for the specific language governing permissions and
14014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * limitations under the License.
15014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck */
16014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck
17014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckpackage android.preference;
18014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck
19014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckimport android.content.Context;
20014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckimport android.graphics.drawable.Drawable;
21014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckimport android.preference.DialogPreference;
22014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckimport android.util.AttributeSet;
23014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckimport android.view.View;
24014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckimport android.widget.ImageView;
25014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckimport android.widget.SeekBar;
26014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck
27014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck/**
28014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * @hide
29014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck */
30014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckpublic class SeekBarDialogPreference extends DialogPreference {
31014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck    private static final String TAG = "SeekBarDialogPreference";
32014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck
33014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck    private Drawable mMyIcon;
34014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck
35617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    public SeekBarDialogPreference(
36617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette            Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
37617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette        super(context, attrs, defStyleAttr, defStyleRes);
38014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck
39014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        setDialogLayoutResource(com.android.internal.R.layout.seekbar_dialog);
40014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        createActionButtons();
41014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck
42014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        // Steal the XML dialogIcon attribute's value
43014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        mMyIcon = getDialogIcon();
44014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        setDialogIcon(null);
45014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck    }
46014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck
47617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    public SeekBarDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
48617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette        this(context, attrs, defStyleAttr, 0);
49617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    }
50617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette
51617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    public SeekBarDialogPreference(Context context, AttributeSet attrs) {
52599d2a49e84bf0a4ee752e263a2c29d2ae942c3eAlan Viverette        this(context, attrs, com.android.internal.R.attr.dialogPreferenceStyle);
53599d2a49e84bf0a4ee752e263a2c29d2ae942c3eAlan Viverette    }
54599d2a49e84bf0a4ee752e263a2c29d2ae942c3eAlan Viverette
55599d2a49e84bf0a4ee752e263a2c29d2ae942c3eAlan Viverette    public SeekBarDialogPreference(Context context) {
56599d2a49e84bf0a4ee752e263a2c29d2ae942c3eAlan Viverette        this(context, null);
57617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    }
58617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette
59014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck    // Allow subclasses to override the action buttons
60014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck    public void createActionButtons() {
61014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        setPositiveButtonText(android.R.string.ok);
62014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        setNegativeButtonText(android.R.string.cancel);
63014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck    }
64014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck
65014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck    @Override
66014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck    protected void onBindDialogView(View view) {
67014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        super.onBindDialogView(view);
68014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck
69014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        final ImageView iconView = (ImageView) view.findViewById(android.R.id.icon);
70014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        if (mMyIcon != null) {
71014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck            iconView.setImageDrawable(mMyIcon);
72014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        } else {
73014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck            iconView.setVisibility(View.GONE);
74014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        }
75014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck    }
76014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck
77014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck    protected static SeekBar getSeekBar(View dialogView) {
78014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck        return (SeekBar) dialogView.findViewById(com.android.internal.R.id.seekbar);
79014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck    }
80014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck}
81