• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 package com.android.car.ui.paintbooth.preferences;
17 
18 import androidx.annotation.NonNull;
19 import androidx.annotation.Nullable;
20 import androidx.fragment.app.Fragment;
21 
22 import com.android.car.ui.baselayout.Insets;
23 import com.android.car.ui.paintbooth.R;
24 import com.android.car.ui.toolbar.ToolbarController;
25 
26 /**
27  * A PreferenceFragment that can use a custom toolbar via the {@link #setToolbar(ToolbarController)}
28  * method.
29  */
30 public class SplitPreferenceDemoFragment extends PreferenceDemoFragment {
31 
32     private ToolbarController mToolbar;
33     private Insets mInsets;
34 
35     @Override
setupToolbar(@onNull ToolbarController toolbar)36     public void setupToolbar(@NonNull ToolbarController toolbar) {
37         toolbar.setLogo(R.drawable.ic_launcher);
38         if (getPreferenceScreen() != null) {
39             toolbar.setTitle(getPreferenceScreen().getTitle());
40         }
41     }
42 
43     @Override
getPreferenceToolbar(@onNull Fragment fragment)44     public ToolbarController getPreferenceToolbar(@NonNull Fragment fragment) {
45         return mToolbar;
46     }
47 
setToolbar(ToolbarController toolbar)48     public void setToolbar(ToolbarController toolbar) {
49         mToolbar = toolbar;
50     }
51 
52     @Nullable
53     @Override
getPreferenceInsets(@onNull Fragment fragment)54     protected Insets getPreferenceInsets(@NonNull Fragment fragment) {
55         return mInsets;
56     }
57 
58     @Override
onCarUiInsetsChanged(@onNull Insets insets)59     public void onCarUiInsetsChanged(@NonNull Insets insets) {
60         mInsets = insets;
61         super.onCarUiInsetsChanged(insets);
62     }
63 }
64