1 /*
2  * Copyright (C) 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.tv.settings.slice;
18 
19 import android.os.Bundle;
20 
21 import androidx.fragment.app.Fragment;
22 
23 import com.android.tv.settings.TvSettingsActivity;
24 import com.android.tv.twopanelsettings.slices.SliceFragment;
25 import com.android.tv.twopanelsettings.slices.SlicesConstants;
26 
27 /**
28  * Extend this class to implement slice settings activity.
29  */
30 public class SliceActivity extends TvSettingsActivity {
31     private static final String EXTRA_SLICE_URI = "slice_uri";
32     private static final String EXTRA_STARTUP_VERIFICATION_REQUIRED =
33             "startup_verification_required";
34 
35     /** Provide slice uri */
getSliceUri()36     public String getSliceUri() {
37         return getIntent().getStringExtra(EXTRA_SLICE_URI);
38     }
39 
40     /** Provide slice screen title */
getScreenTitle()41     public String getScreenTitle() {
42         return null;
43     }
44 
45     @Override
createSettingsFragment()46     protected Fragment createSettingsFragment() {
47         Bundle bundle = new Bundle();
48         String sliceUri = getSliceUri();
49         if (sliceUri == null) {
50             return null;
51         }
52         bundle.putString(SlicesConstants.TAG_TARGET_URI, sliceUri);
53         bundle.putString(SlicesConstants.TAG_SCREEN_TITLE, getScreenTitle());
54         return com.android.tv.settings.overlay.FlavorUtils.getFeatureFactory(
55                 this).getSettingsFragmentProvider()
56                 .newSettingsFragment(SliceFragment.class.getName(), bundle);
57     }
58 
59     // The startup verification requirement is assumed unless otherwise specified in the Intent, as
60     // this Activity may be started with "SLICE_SETTINGS" action combined with an URL extra
61     // corresponding to a sensitive settings page such as account settings.
62     @Override
isStartupVerificationRequired()63     protected boolean isStartupVerificationRequired() {
64         return getIntent().getBooleanExtra(EXTRA_STARTUP_VERIFICATION_REQUIRED, true);
65     }
66 }
67