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