1 /* 2 * Copyright 2012 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.example.android.tabcompat.lib; 18 19 import com.example.android.tabcompat.lib.TabHelper; 20 21 import android.os.Bundle; 22 import android.support.v4.app.FragmentActivity; 23 24 /** 25 * A base activity that defers tab functionality to a {@link TabHelper}. 26 * 27 * When building an activity with tabs, extend this class in order to provide compatibility with API 28 * level 5 and above. Using this class along with the {@link TabHelper} and {@link com.example.android.tabcompat.lib.CompatTab} 29 * classes, you can build a tab UI that's built using the {@link android.app.ActionBar} on 30 * Honeycomb+ and the {@link android.widget.TabWidget} on all older versions. 31 * 32 * The {@link TabHelper} APIs obfuscate all the compatibility work for you. 33 */ 34 public abstract class TabCompatActivity extends FragmentActivity { 35 36 TabHelper mTabHelper; 37 38 @Override onCreate(Bundle savedInstanceState)39 protected void onCreate(Bundle savedInstanceState) { 40 super.onCreate(savedInstanceState); 41 mTabHelper = TabHelper.createInstance(this); 42 } 43 44 @Override onSaveInstanceState(Bundle outState)45 protected void onSaveInstanceState(Bundle outState) { 46 super.onSaveInstanceState(outState); 47 mTabHelper.onSaveInstanceState(outState); 48 } 49 50 @Override onRestoreInstanceState(Bundle savedInstanceState)51 protected void onRestoreInstanceState(Bundle savedInstanceState) { 52 super.onRestoreInstanceState(savedInstanceState); 53 mTabHelper.onRestoreInstanceState(savedInstanceState); 54 } 55 56 /** 57 * Returns the {@link TabHelper} for this activity. 58 */ getTabHelper()59 protected TabHelper getTabHelper() { 60 mTabHelper.setUp(); 61 return mTabHelper; 62 } 63 } 64