1 /* 2 * Copyright (C) 2017 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 18 package com.android.settings.intelligence.search; 19 20 import androidx.fragment.app.FragmentActivity; 21 import androidx.fragment.app.Fragment; 22 import androidx.fragment.app.FragmentManager; 23 24 import android.content.pm.PackageManager; 25 import android.os.Bundle; 26 import android.view.WindowManager; 27 28 import com.android.settings.intelligence.R; 29 import com.android.settings.intelligence.search.car.CarSearchFragment; 30 31 public class SearchActivity extends FragmentActivity { 32 33 @Override onCreate(Bundle savedInstanceState)34 public void onCreate(Bundle savedInstanceState) { 35 if (isAutomotive()) { 36 // Automotive relies on a different theme. Apply before calling super so that 37 // fragments are restored properly on configuration changes. 38 setTheme(R.style.Theme_CarSettings); 39 } 40 super.onCreate(savedInstanceState); 41 setContentView(R.layout.search_main); 42 43 FragmentManager fragmentManager = getSupportFragmentManager(); 44 Fragment fragment = fragmentManager.findFragmentById(R.id.main_content); 45 if (fragment == null) { 46 fragment = isAutomotive() ? 47 new CarSearchFragment() : new SearchFragment(); 48 fragmentManager.beginTransaction() 49 .add(R.id.main_content, fragment) 50 .commit(); 51 } 52 } 53 54 @Override onNavigateUp()55 public boolean onNavigateUp() { 56 finish(); 57 return true; 58 } 59 isAutomotive()60 private boolean isAutomotive() { 61 return getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); 62 } 63 } 64