1 /*
2  * Copyright (C) 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 
17 package com.android.permissioncontroller.permission.ui.handheld;
18 
19 import android.app.ActionBar;
20 import android.os.Bundle;
21 
22 import androidx.annotation.NonNull;
23 import androidx.annotation.Nullable;
24 import androidx.preference.PreferenceFragmentCompat;
25 
26 import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseFragment;
27 
28 /**
29  * Base class which act as a wrapper over a preference fragment
30  */
31 public abstract class PermissionsCollapsingToolbarBaseFragment
32         extends CollapsingToolbarBaseFragment {
33 
34     @Override
onActivityCreated(@ullable Bundle savedInstanceState)35     public void onActivityCreated(@Nullable Bundle savedInstanceState) {
36         super.onActivityCreated(savedInstanceState);
37 
38         ActionBar actionBar = requireActivity().getActionBar();
39         if (actionBar != null) {
40             actionBar.setDisplayHomeAsUpEnabled(true);
41         }
42 
43         PreferenceFragmentCompat preferenceFragment =
44                 (PreferenceFragmentCompat) getChildFragmentManager()
45                         .findFragmentById(
46                                 com.android.settingslib.collapsingtoolbar.R.id.content_frame);
47 
48         if (preferenceFragment == null) {
49             preferenceFragment = createPreferenceFragment();
50             preferenceFragment.setArguments(getArguments());
51             getChildFragmentManager().beginTransaction()
52                     .add(com.android.settingslib.collapsingtoolbar.R.id.content_frame,
53                             preferenceFragment)
54                     .commit();
55         }
56     }
57 
58     /**
59      * @return a new instance of a customized PermissionsFrameFragment.
60      */
61     @NonNull
createPreferenceFragment()62     public abstract PreferenceFragmentCompat createPreferenceFragment();
63 }
64