1 /*
2  * Copyright 2020 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.car.ui.preference;
18 
19 import android.app.AlertDialog;
20 import android.content.DialogInterface;
21 import android.os.Bundle;
22 import android.view.View;
23 
24 import androidx.annotation.NonNull;
25 
26 /**
27  * A fragment that provides a layout with a seekbar within a dialog.
28  */
29 public class SeekbarPreferenceDialogFragment extends PreferenceDialogFragment {
30 
31     /**
32      * Returns a new instance of {@link SeekbarPreferenceDialogFragment} for the {@link
33      * CarUiSeekBarDialogPreference} with the given {@code key}.
34      */
newInstance(String key)35     public static SeekbarPreferenceDialogFragment newInstance(String key) {
36         SeekbarPreferenceDialogFragment fragment = new SeekbarPreferenceDialogFragment();
37         Bundle b = new Bundle(/* capacity= */ 1);
38         b.putString(ARG_KEY, key);
39         fragment.setArguments(b);
40         return fragment;
41     }
42 
43     @Override
onBindDialogView(@onNull View view)44     protected void onBindDialogView(@NonNull View view) {
45         super.onBindDialogView(view);
46 
47         DialogFragmentCallbacks dialogPreference = (DialogFragmentCallbacks) getPreference();
48         dialogPreference.onBindDialogView(view);
49     }
50 
51     @Override
onClick(DialogInterface dialog, int which)52     public void onClick(DialogInterface dialog, int which) {
53         super.onClick(dialog, which);
54 
55         DialogFragmentCallbacks dialogPreference = (DialogFragmentCallbacks) getPreference();
56         dialogPreference.onClick(dialog, which);
57     }
58 
59     @Override
onDialogClosed(boolean positiveResult)60     protected void onDialogClosed(boolean positiveResult) {
61         DialogFragmentCallbacks dialogPreference = (DialogFragmentCallbacks) getPreference();
62         dialogPreference.onDialogClosed(positiveResult);
63     }
64 
65     @Override
onPrepareDialogBuilder(@onNull AlertDialog.Builder builder)66     protected void onPrepareDialogBuilder(@NonNull AlertDialog.Builder builder) {
67         DialogFragmentCallbacks dialogPreference = (DialogFragmentCallbacks) getPreference();
68         dialogPreference.onPrepareDialogBuilder(builder);
69     }
70 }
71