• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 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.actionbarcompat;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.view.Menu;
22 import android.view.MenuInflater;
23 
24 /**
25  * A base activity that defers common functionality across app activities to an {@link
26  * ActionBarHelper}.
27  *
28  * NOTE: dynamically marking menu items as invisible/visible is not currently supported.
29  *
30  * NOTE: this may used with the Android Compatibility Package by extending
31  * android.support.v4.app.FragmentActivity instead of {@link Activity}.
32  */
33 public abstract class ActionBarActivity extends Activity {
34     final ActionBarHelper mActionBarHelper = ActionBarHelper.createInstance(this);
35 
36     /**
37      * Returns the {@link ActionBarHelper} for this activity.
38      */
getActionBarHelper()39     protected ActionBarHelper getActionBarHelper() {
40         return mActionBarHelper;
41     }
42 
43     /**{@inheritDoc}*/
44     @Override
getMenuInflater()45     public MenuInflater getMenuInflater() {
46         return mActionBarHelper.getMenuInflater(super.getMenuInflater());
47     }
48 
49     /**{@inheritDoc}*/
50     @Override
onCreate(Bundle savedInstanceState)51     protected void onCreate(Bundle savedInstanceState) {
52         super.onCreate(savedInstanceState);
53         mActionBarHelper.onCreate(savedInstanceState);
54     }
55 
56     /**{@inheritDoc}*/
57     @Override
onPostCreate(Bundle savedInstanceState)58     protected void onPostCreate(Bundle savedInstanceState) {
59         super.onPostCreate(savedInstanceState);
60         mActionBarHelper.onPostCreate(savedInstanceState);
61     }
62 
63     /**
64      * Base action bar-aware implementation for
65      * {@link Activity#onCreateOptionsMenu(android.view.Menu)}.
66      *
67      * Note: marking menu items as invisible/visible is not currently supported.
68      */
69     @Override
onCreateOptionsMenu(Menu menu)70     public boolean onCreateOptionsMenu(Menu menu) {
71         boolean retValue = false;
72         retValue |= mActionBarHelper.onCreateOptionsMenu(menu);
73         retValue |= super.onCreateOptionsMenu(menu);
74         return retValue;
75     }
76 
77     /**{@inheritDoc}*/
78     @Override
onTitleChanged(CharSequence title, int color)79     protected void onTitleChanged(CharSequence title, int color) {
80         mActionBarHelper.onTitleChanged(title, color);
81         super.onTitleChanged(title, color);
82     }
83 }
84