• 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 android.os.Bundle;
19 
20 import androidx.annotation.NonNull;
21 import androidx.appcompat.app.AppCompatActivity;
22 
23 import com.android.car.ui.baselayout.Insets;
24 import com.android.car.ui.baselayout.InsetsChangedListener;
25 import com.android.car.ui.core.CarUi;
26 import com.android.car.ui.paintbooth.R;
27 import com.android.car.ui.toolbar.NavButtonMode;
28 import com.android.car.ui.toolbar.ToolbarController;
29 
30 /**
31  * A demo activity showing off preferences that only take up half the screen, and
32  * have their own toolbar independent from the main toolbar.
33  */
34 public class SplitPreferenceActivity extends AppCompatActivity implements InsetsChangedListener {
35 
36     @Override
onCreate(Bundle savedInstanceState)37     protected void onCreate(Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39         setContentView(R.layout.split_preference_activity);
40 
41         ToolbarController mainToolbar = CarUi.getToolbar(this);
42         if (mainToolbar != null) {
43             mainToolbar.setNavButtonMode(NavButtonMode.BACK);
44             mainToolbar.setTitle("Split preferences sample");
45         }
46 
47         // We do this so that the insets are not automatically sent to the fragments.
48         // The fragments have their own insets handled by the installBaseLayoutAround().
49         CarUi.replaceInsetsChangedListenerWith(this, this);
50 
51         SplitPreferenceDemoFragment fragment = new SplitPreferenceDemoFragment();
52         ToolbarController subToolbar = CarUi.installBaseLayoutAround(
53                 requireViewById(R.id.preference_fragment_container),
54                 fragment, true);
55         fragment.setToolbar(subToolbar);
56 
57         if (savedInstanceState == null) {
58             getSupportFragmentManager()
59                     .beginTransaction()
60                     .replace(R.id.preference_fragment_container, fragment)
61                     .commitNow();
62         }
63     }
64 
65     @Override
onCarUiInsetsChanged(@onNull Insets insets)66     public void onCarUiInsetsChanged(@NonNull Insets insets) {
67         requireViewById(android.R.id.content)
68                 .setPadding(insets.getLeft(), insets.getTop(),
69                         insets.getRight(), insets.getBottom());
70     }
71 }
72