1 /* 2 * Copyright (C) 2019 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.twopanelsettingsoverlay; 18 19 import android.app.Fragment; 20 import android.os.Bundle; 21 import android.util.Log; 22 23 import androidx.annotation.Keep; 24 25 import com.android.tv.settings.SettingsFragmentProvider; 26 import com.android.tv.settings.help.SupportFeatureProvider; 27 import com.android.tv.settings.help.SupportFeatureProviderImpl; 28 import com.android.tv.settings.offline.OfflineFeatureProvider; 29 import com.android.tv.settings.offline.OfflineFeatureProviderImpl; 30 import com.android.tv.settings.overlay.FeatureFactory; 31 32 /** 33 * Two panel customized implementation of the feature factory. 34 */ 35 @Keep 36 public class FeatureFactoryImpl extends FeatureFactory { 37 38 @Override getSettingsFragmentProvider()39 public SettingsFragmentProvider getSettingsFragmentProvider() { 40 return SettingsFragment::newInstance; 41 } 42 43 @Override getSupportFeatureProvider()44 public SupportFeatureProvider getSupportFeatureProvider() { 45 return new SupportFeatureProviderImpl(); 46 } 47 48 @Override getOfflineFeatureProvider()49 public OfflineFeatureProvider getOfflineFeatureProvider() { 50 return new OfflineFeatureProviderImpl(); 51 } 52 53 @Override isTwoPanelLayout()54 public boolean isTwoPanelLayout() { 55 return true; 56 } 57 58 /** A settings fragment suitable for displaying in the two panel layout. */ 59 public static class SettingsFragment extends TwoPanelBaseSettingsFragment { 60 SettingsFragment()61 public SettingsFragment() {} 62 63 /** Constructs a new instance of a settings fragment. */ newInstance(String className, Bundle arguments)64 public static SettingsFragment newInstance(String className, Bundle arguments) { 65 SettingsFragment fragment = new SettingsFragment(); 66 Bundle args = arguments == null ? new Bundle() : new Bundle(arguments); 67 args.putString(EXTRA_FRAGMENT_CLASS_NAME, className); 68 fragment.setArguments(args); 69 return fragment; 70 } 71 72 @Override onPreferenceStartInitialScreen()73 public void onPreferenceStartInitialScreen() { 74 try { 75 String className = getArguments().getString(EXTRA_FRAGMENT_CLASS_NAME); 76 final Fragment fragment = (Fragment) Class.forName(className).newInstance(); 77 fragment.setArguments(getArguments()); 78 startPreferenceFragment(fragment); 79 } catch (IllegalAccessException | ClassNotFoundException 80 | java.lang.InstantiationException e) { 81 Log.e(FeatureFactory.TAG, "Unable to start initial preference screen.", e); 82 } 83 } 84 } 85 } 86