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 package com.android.car.settings.common; 17 18 import android.os.Bundle; 19 import android.support.v7.app.AppCompatActivity; 20 import android.support.v7.widget.Toolbar; 21 22 import com.android.car.settings.R; 23 import com.android.car.settings.home.HomepageFragment; 24 25 /** 26 * Base activity class for car settings, provides a action bar with a back button that goes to 27 * previous activity. 28 */ 29 public class CarSettingActivity extends AppCompatActivity implements 30 BaseFragment.FragmentController { 31 32 @Override 33 protected void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 setContentView(R.layout.app_compat_activity); 36 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 37 setSupportActionBar(toolbar); 38 HomepageFragment homepageFragment = HomepageFragment.getInstance(); 39 homepageFragment.setFragmentController(this); 40 launchFragment(homepageFragment); 41 } 42 43 @Override 44 public void launchFragment(BaseFragment fragment) { 45 fragment.setFragmentController(this); 46 getFragmentManager() 47 .beginTransaction() 48 .setCustomAnimations( 49 R.animator.trans_right_in , 50 R.animator.trans_left_out, 51 R.animator.trans_left_in, 52 R.animator.trans_right_out) 53 .replace(R.id.fragment_container, fragment) 54 .addToBackStack(null) 55 .commit(); 56 } 57 58 @Override 59 public void goBack() { 60 if (getFragmentManager().getBackStackEntryCount() > 0) { 61 getFragmentManager().popBackStack(); 62 } 63 } 64 65 @Override 66 public void onBackPressed() { 67 if (getFragmentManager().getBackStackEntryCount() > 0) { 68 getFragmentManager().popBackStack(); 69 } else { 70 super.onBackPressed(); 71 } 72 } 73 } 74