Support ActionBar in Dialogs
Dialogs planning on using an ActionBar must have an appropriate theme. (Later on this will likely be default.) Change-Id: I7fbf5f76eed3d10765fddeaf211e4decb4e89f87
This commit is contained in:
@@ -26353,6 +26353,17 @@
|
||||
<parameter name="id" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="getActionBar"
|
||||
return="android.app.ActionBar"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getContext"
|
||||
return="android.content.Context"
|
||||
abstract="false"
|
||||
@@ -213236,17 +213247,6 @@
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getVisibleTitleHeight"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getZoomControls"
|
||||
return="android.view.View"
|
||||
abstract="false"
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.app;
|
||||
|
||||
import com.android.internal.app.ActionBarImpl;
|
||||
import com.android.internal.policy.PolicyManager;
|
||||
|
||||
import android.content.ComponentName;
|
||||
@@ -27,9 +28,9 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.ActionMode;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.ActionMode;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
@@ -77,6 +78,7 @@ public class Dialog implements DialogInterface, Window.Callback,
|
||||
final WindowManager mWindowManager;
|
||||
Window mWindow;
|
||||
View mDecor;
|
||||
private ActionBarImpl mActionBar;
|
||||
/**
|
||||
* This field should be made private, so it is hidden from the SDK.
|
||||
* {@hide}
|
||||
@@ -177,6 +179,15 @@ public class Dialog implements DialogInterface, Window.Callback,
|
||||
return mContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the {@link ActionBar} attached to this dialog, if present.
|
||||
*
|
||||
* @return The ActionBar attached to the dialog or null if no ActionBar is present.
|
||||
*/
|
||||
public ActionBar getActionBar() {
|
||||
return mActionBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Activity that owns this dialog. An example use: This Dialog will
|
||||
* use the suggested volume control stream of the Activity.
|
||||
@@ -228,6 +239,11 @@ public class Dialog implements DialogInterface, Window.Callback,
|
||||
|
||||
onStart();
|
||||
mDecor = mWindow.getDecorView();
|
||||
|
||||
if (mActionBar == null && mWindow.hasFeature(Window.FEATURE_ACTION_BAR)) {
|
||||
mActionBar = new ActionBarImpl(this);
|
||||
}
|
||||
|
||||
WindowManager.LayoutParams l = mWindow.getAttributes();
|
||||
if ((l.softInputMode
|
||||
& WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) == 0) {
|
||||
@@ -834,12 +850,14 @@ public class Dialog implements DialogInterface, Window.Callback,
|
||||
}
|
||||
|
||||
public ActionMode onStartActionMode(ActionMode.Callback callback) {
|
||||
// TODO Support context modes in dialogs
|
||||
if (mActionBar != null) {
|
||||
return mActionBar.startActionMode(callback);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The activity associated with this dialog, or null if there is no assocaited activity.
|
||||
* @return The activity associated with this dialog, or null if there is no associated activity.
|
||||
*/
|
||||
private ComponentName getAssociatedActivity() {
|
||||
Activity activity = mOwnerActivity;
|
||||
|
||||
@@ -24,8 +24,10 @@ import com.android.internal.widget.ActionBarView;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.view.ActionMode;
|
||||
@@ -54,7 +56,9 @@ public class ActionBarImpl extends ActionBar {
|
||||
private static final int TAB_SWITCH_SHOW_HIDE = 0;
|
||||
private static final int TAB_SWITCH_ADD_REMOVE = 1;
|
||||
|
||||
private Context mContext;
|
||||
private Activity mActivity;
|
||||
private Dialog mDialog;
|
||||
|
||||
private ViewAnimator mAnimatorView;
|
||||
private ActionBarView mActionView;
|
||||
@@ -88,8 +92,17 @@ public class ActionBarImpl extends ActionBar {
|
||||
};
|
||||
|
||||
public ActionBarImpl(Activity activity) {
|
||||
final View decor = activity.getWindow().getDecorView();
|
||||
mActivity = activity;
|
||||
init(activity.getWindow().getDecorView());
|
||||
}
|
||||
|
||||
public ActionBarImpl(Dialog dialog) {
|
||||
mDialog = dialog;
|
||||
init(dialog.getWindow().getDecorView());
|
||||
}
|
||||
|
||||
private void init(View decor) {
|
||||
mContext = decor.getContext();
|
||||
mActionView = (ActionBarView) decor.findViewById(com.android.internal.R.id.action_bar);
|
||||
mUpperContextView = (ActionBarContextView) decor.findViewById(
|
||||
com.android.internal.R.id.action_context_bar);
|
||||
@@ -109,23 +122,23 @@ public class ActionBarImpl extends ActionBar {
|
||||
|
||||
@Override
|
||||
public void setStandardNavigationMode(int titleResId, int subtitleResId) {
|
||||
setStandardNavigationMode(mActivity.getString(titleResId),
|
||||
mActivity.getString(subtitleResId));
|
||||
setStandardNavigationMode(mContext.getString(titleResId),
|
||||
mContext.getString(subtitleResId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStandardNavigationMode(int titleResId) {
|
||||
setStandardNavigationMode(mActivity.getString(titleResId));
|
||||
setStandardNavigationMode(mContext.getString(titleResId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(int resId) {
|
||||
setTitle(mActivity.getString(resId));
|
||||
setTitle(mContext.getString(resId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubtitle(int resId) {
|
||||
setSubtitle(mActivity.getString(resId));
|
||||
setSubtitle(mContext.getString(resId));
|
||||
}
|
||||
|
||||
public void setCustomNavigationMode(View view) {
|
||||
@@ -345,6 +358,10 @@ public class ActionBarImpl extends ActionBar {
|
||||
|
||||
@Override
|
||||
public void setTabNavigationMode() {
|
||||
if (mActivity == null) {
|
||||
throw new IllegalStateException(
|
||||
"Tab navigation mode cannot be used outside of an Activity");
|
||||
}
|
||||
mActionView.setNavigationMode(NAVIGATION_MODE_TABS);
|
||||
}
|
||||
|
||||
@@ -396,7 +413,7 @@ public class ActionBarImpl extends ActionBar {
|
||||
|
||||
@Override
|
||||
public MenuInflater getMenuInflater() {
|
||||
return new MenuInflater(mActivity);
|
||||
return new MenuInflater(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -485,7 +502,7 @@ public class ActionBarImpl extends ActionBar {
|
||||
return true;
|
||||
}
|
||||
|
||||
new MenuPopupHelper(mActivity, subMenu).show();
|
||||
new MenuPopupHelper(mContext, subMenu).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user