/* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.support.v4.app; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.Parcelable; import android.support.v4.view.MenuInflater; import android.util.AttributeSet; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.Window; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; /** * Base class for activities that want to use the support-based * {@link android.support.v4.app.Fragment} and * {@link android.support.v4.content.Loader} APIs. * *
When using this class as opposed to new platform's built-in fragment * and loader support, you must use the {@link #getSupportFragmentManager()} * and {@link #getSupportLoaderManager()} methods respectively to access * those features. * *
Known limitations:
*When using the <fragment> tag, this implementation can not * use the parent view's ID as the new fragment's ID. You must explicitly * specify an ID (or tag) in the <fragment>.
*Prior to Honeycomb (3.0), an activity's state was saved before pausing. * Fragments are a significant amount of new state, and dynamic enough that one * often wants them to change between pausing and stopping. These classes * throw an exception if you try to change the fragment state after it has been * saved, to avoid accidental loss of UI state. However this is too restrictive * prior to Honeycomb, where the state is saved before pausing. To address this, * when running on platforms prior to Honeycomb an exception will not be thrown * if you change fragments between the state save and the activity being stopped. * This means that in some cases if the activity is restored from its last saved * state, this may be a snapshot slightly before what the user last saw.
*The default implementation updates the system menu items based on the * activity's state. Deriving classes should always call through to the * base class implementation. * * @param menu The options menu as last shown or first initialized by * onCreateSupportOptionsMenu(). * * @return You must return true for the menu to be displayed; * if you return false it will not be shown. * * @see #onPrepareSupportOptionsMenu * @see #onCreateSupportOptionsMenu */ public boolean onPrepareSupportOptionsMenu(android.support.v4.view.Menu menu) { return true; } /** * Support library version of onCreateOptionsMenu. * * Initialize the contents of the Activity's standard options menu. You * should place your menu items in to menu. * *
This is only called once, the first time the options menu is * displayed. To update the menu every time it is displayed, see * {@link #onPrepareSupportOptionsMenu}. * *
The default implementation populates the menu with standard system * menu items. These are placed in the {@link android.support.v4.view.Menu#CATEGORY_SYSTEM} * group so that they will be correctly ordered with application-defined menu items. * Deriving classes should always call through to the base implementation. * *
You can safely hold on to menu (and any items created * from it), making modifications to it as desired, until the next * time onCreateSupportOptionsMenu() is called. * *
When you add items to the menu, you can implement the Activity's * {@link #onSupportOptionsItemSelected} method to handle them there. * * @param menu The options menu in which you place your items. * * @return You must return true for the menu to be displayed; * if you return false it will not be shown. * * @see #onCreateSupportOptionsMenu * @see #onPrepareSupportOptionsMenu * @see #onSupportOptionsItemSelected */ public boolean onCreateSupportOptionsMenu(android.support.v4.view.Menu menu) { return true; } /** * This hook is called whenever an item in your options menu is selected. * The default implementation simply returns false to have the normal * processing happen (calling the item's Runnable or sending a message to * its Handler as appropriate). You can use this method for any items * for which you would like to do processing without those other * facilities. * *
Derived classes should call through to the base class for it to * perform the default menu handling.
* * @param item The menu item that was selected. * * @return boolean Return false to allow normal menu processing to * proceed, true to consume it here. * * @see #onCreateSupportOptionsMenu */ public boolean onSupportOptionsItemSelected(android.support.v4.view.MenuItem item) { return false; } /** * Returns a {@link MenuInflater} with this context. */ public MenuInflater getSupportMenuInflater() { if (mMenuInflater == null) { mMenuInflater = createSupportMenuInflater(); } return mMenuInflater; } MenuInflater createSupportMenuInflater() { return null; } /** * Print the Activity's state into the given stream. This gets invoked if * you run "adb shell dumpsys activity