summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/current.xml495
-rw-r--r--core/java/android/app/Activity.java51
-rw-r--r--core/java/android/app/ContextualMode.java155
-rw-r--r--core/java/android/app/Dialog.java16
-rw-r--r--core/java/android/content/Context.java22
-rw-r--r--core/java/android/view/ActionMode.java151
-rw-r--r--core/java/android/view/View.java15
-rw-r--r--core/java/android/view/ViewGroup.java10
-rw-r--r--core/java/android/view/ViewParent.java14
-rw-r--r--core/java/android/view/ViewRoot.java4
-rw-r--r--core/java/android/view/Window.java8
-rw-r--r--core/java/com/android/internal/app/ActionBarImpl.java32
-rw-r--r--core/java/com/android/internal/widget/ActionBarContextView.java4
-rw-r--r--policy/src/com/android/internal/policy/impl/PhoneWindow.java17
14 files changed, 551 insertions, 443 deletions
diff --git a/api/current.xml b/api/current.xml
index 52b7217..a828736 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -21241,6 +21241,19 @@
visibility="protected"
>
</method>
+<method name="onStartActionMode"
+ return="android.view.ActionMode"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="callback" type="android.view.ActionMode.Callback">
+</parameter>
+</method>
<method name="onStop"
return="void"
abstract="false"
@@ -21900,6 +21913,19 @@
<parameter name="requestCode" type="int">
</parameter>
</method>
+<method name="startContextMode"
+ return="android.view.ActionMode"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="callback" type="android.view.ActionMode.Callback">
+</parameter>
+</method>
<method name="startIntentSenderForResult"
return="void"
abstract="false"
@@ -24546,194 +24572,6 @@
>
</method>
</class>
-<class name="ContextualMode"
- extends="java.lang.Object"
- abstract="true"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<constructor name="ContextualMode"
- type="android.app.ContextualMode"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</constructor>
-<method name="finish"
- return="void"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
-<method name="getCustomView"
- return="android.view.View"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
-<method name="getMenu"
- return="android.view.Menu"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
-<method name="getSubtitle"
- return="java.lang.CharSequence"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
-<method name="getTitle"
- return="java.lang.CharSequence"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
-<method name="invalidate"
- return="void"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
-<method name="setCustomView"
- return="void"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="view" type="android.view.View">
-</parameter>
-</method>
-<method name="setSubtitle"
- return="void"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="subtitle" type="java.lang.CharSequence">
-</parameter>
-</method>
-<method name="setTitle"
- return="void"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="title" type="java.lang.CharSequence">
-</parameter>
-</method>
-</class>
-<interface name="ContextualMode.Callback"
- abstract="true"
- static="true"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<method name="onContextualItemClicked"
- return="boolean"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="mode" type="android.app.ContextualMode">
-</parameter>
-<parameter name="item" type="android.view.MenuItem">
-</parameter>
-</method>
-<method name="onCreateContextualMode"
- return="boolean"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="mode" type="android.app.ContextualMode">
-</parameter>
-<parameter name="menu" type="android.view.Menu">
-</parameter>
-</method>
-<method name="onDestroyContextualMode"
- return="void"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="mode" type="android.app.ContextualMode">
-</parameter>
-</method>
-<method name="onPrepareContextualMode"
- return="boolean"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="mode" type="android.app.ContextualMode">
-</parameter>
-<parameter name="menu" type="android.view.Menu">
-</parameter>
-</method>
-</interface>
<class name="DatePickerDialog"
extends="android.app.AlertDialog"
abstract="false"
@@ -25466,6 +25304,19 @@
visibility="protected"
>
</method>
+<method name="onStartActionMode"
+ return="android.view.ActionMode"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="callback" type="android.view.ActionMode.Callback">
+</parameter>
+</method>
<method name="onStop"
return="void"
abstract="false"
@@ -40357,17 +40208,6 @@
visibility="public"
>
</method>
-<method name="finishContextualMode"
- return="void"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
<method name="getApplicationContext"
return="android.content.Context"
abstract="true"
@@ -41082,19 +40922,6 @@
<parameter name="intent" type="android.content.Intent">
</parameter>
</method>
-<method name="startContextualMode"
- return="android.app.ContextualMode"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="callback" type="android.app.ContextualMode.Callback">
-</parameter>
-</method>
<method name="startInstrumentation"
return="boolean"
abstract="true"
@@ -176384,6 +176211,194 @@
>
</field>
</class>
+<class name="ActionMode"
+ extends="java.lang.Object"
+ abstract="true"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<constructor name="ActionMode"
+ type="android.view.ActionMode"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</constructor>
+<method name="finish"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getCustomView"
+ return="android.view.View"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getMenu"
+ return="android.view.Menu"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getSubtitle"
+ return="java.lang.CharSequence"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getTitle"
+ return="java.lang.CharSequence"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="invalidate"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="setCustomView"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="view" type="android.view.View">
+</parameter>
+</method>
+<method name="setSubtitle"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="subtitle" type="java.lang.CharSequence">
+</parameter>
+</method>
+<method name="setTitle"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="title" type="java.lang.CharSequence">
+</parameter>
+</method>
+</class>
+<interface name="ActionMode.Callback"
+ abstract="true"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<method name="onActionItemClicked"
+ return="boolean"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="mode" type="android.view.ActionMode">
+</parameter>
+<parameter name="item" type="android.view.MenuItem">
+</parameter>
+</method>
+<method name="onCreateActionMode"
+ return="boolean"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="mode" type="android.view.ActionMode">
+</parameter>
+<parameter name="menu" type="android.view.Menu">
+</parameter>
+</method>
+<method name="onDestroyActionMode"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="mode" type="android.view.ActionMode">
+</parameter>
+</method>
+<method name="onPrepareActionMode"
+ return="boolean"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="mode" type="android.view.ActionMode">
+</parameter>
+<parameter name="menu" type="android.view.Menu">
+</parameter>
+</method>
+</interface>
<interface name="ContextMenu"
abstract="true"
static="false"
@@ -188811,6 +188826,19 @@
visibility="public"
>
</method>
+<method name="startActionMode"
+ return="android.view.ActionMode"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="callback" type="android.view.ActionMode.Callback">
+</parameter>
+</method>
<method name="startAnimation"
return="void"
abstract="false"
@@ -191588,6 +191616,21 @@
<parameter name="originalView" type="android.view.View">
</parameter>
</method>
+<method name="startActionModeForChild"
+ return="android.view.ActionMode"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="originalView" type="android.view.View">
+</parameter>
+<parameter name="callback" type="android.view.ActionMode.Callback">
+</parameter>
+</method>
<method name="startLayoutAnimation"
return="void"
abstract="false"
@@ -192278,6 +192321,21 @@
<parameter name="originalView" type="android.view.View">
</parameter>
</method>
+<method name="startActionModeForChild"
+ return="android.view.ActionMode"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="originalView" type="android.view.View">
+</parameter>
+<parameter name="callback" type="android.view.ActionMode.Callback">
+</parameter>
+</method>
</interface>
<class name="ViewStub"
extends="android.view.View"
@@ -194048,6 +194106,19 @@
visibility="public"
>
</method>
+<method name="onStartActionMode"
+ return="android.view.ActionMode"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="callback" type="android.view.ActionMode.Callback">
+</parameter>
+</method>
<method name="onWindowAttributesChanged"
return="void"
abstract="true"
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 431f66d..61fd5f3 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -16,8 +16,8 @@
package android.app;
-import java.util.ArrayList;
-import java.util.HashMap;
+import com.android.internal.app.ActionBarImpl;
+import com.android.internal.policy.PolicyManager;
import android.content.ComponentCallbacks;
import android.content.ComponentName;
@@ -52,7 +52,9 @@ import android.util.Config;
import android.util.EventLog;
import android.util.Log;
import android.util.SparseArray;
+import android.view.ActionMode;
import android.view.ContextMenu;
+import android.view.ContextMenu.ContextMenuInfo;
import android.view.ContextThemeWrapper;
import android.view.InflateException;
import android.view.KeyEvent;
@@ -62,21 +64,18 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
+import android.view.View.OnCreateContextMenuListener;
import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
import android.view.ViewManager;
import android.view.Window;
import android.view.WindowManager;
-import android.view.ContextMenu.ContextMenuInfo;
-import android.view.View.OnCreateContextMenuListener;
-import android.view.ViewGroup.LayoutParams;
import android.view.accessibility.AccessibilityEvent;
import android.widget.AdapterView;
import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-import com.android.internal.app.ActionBarImpl;
-import com.android.internal.policy.PolicyManager;
-import com.android.internal.widget.ActionBarView;
+import java.util.ArrayList;
+import java.util.HashMap;
/**
* An activity is a single, focused thing that the user can do. Almost all
@@ -4073,6 +4072,25 @@ public class Activity extends ContextThemeWrapper
}
}
+ /**
+ * Start a context mode.
+ *
+ * @param callback Callback that will manage lifecycle events for this context mode
+ * @return The ContextMode that was started, or null if it was canceled
+ *
+ * @see ActionMode
+ */
+ public ActionMode startContextMode(ActionMode.Callback callback) {
+ return mWindow.getDecorView().startActionMode(callback);
+ }
+
+ public ActionMode onStartActionMode(ActionMode.Callback callback) {
+ if (mActionBar != null) {
+ return mActionBar.startContextMode(callback);
+ }
+ return null;
+ }
+
// ------------------ Internal API ------------------
final void setParent(Activity parent) {
@@ -4286,19 +4304,4 @@ public class Activity extends ContextThemeWrapper
}
}
}
-
- @Override
- public ContextualMode startContextualMode(ContextualMode.Callback callback) {
- if (mActionBar == null) {
- return null;
- }
- return mActionBar.startContextualMode(callback);
- }
-
- @Override
- public void finishContextualMode() {
- if (mActionBar != null) {
- mActionBar.finishContextualMode();
- }
- }
}
diff --git a/core/java/android/app/ContextualMode.java b/core/java/android/app/ContextualMode.java
deleted file mode 100644
index 5e4b5df..0000000
--- a/core/java/android/app/ContextualMode.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) 2010 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.app;
-
-import android.content.Context;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-
-/**
- * Represents a contextual mode of the user interface. Contextual modes can be used for
- * modal interactions with content and replace parts of the normal UI until finished.
- * Examples of good contextual modes include selection modes, search, content editing, etc.
- */
-public abstract class ContextualMode {
- /**
- * Set the title of the contextual mode. This method will have no visible effect if
- * a custom view has been set.
- *
- * @param title Title string to set
- *
- * @see #setCustomView(View)
- */
- public abstract void setTitle(CharSequence title);
-
- /**
- * Set the subtitle of the contextual mode. This method will have no visible effect if
- * a custom view has been set.
- *
- * @param subtitle Subtitle string to set
- *
- * @see #setCustomView(View)
- */
- public abstract void setSubtitle(CharSequence subtitle);
-
- /**
- * Set a custom view for this contextual mode. The custom view will take the place of
- * the title and subtitle. Useful for things like search boxes.
- *
- * @param view Custom view to use in place of the title/subtitle.
- *
- * @see #setTitle(CharSequence)
- * @see #setSubtitle(CharSequence)
- */
- public abstract void setCustomView(View view);
-
- /**
- * Invalidate the contextual mode and refresh menu content. The contextual mode's
- * {@link ContextualMode.Callback} will have its
- * {@link Callback#onPrepareContextualMode(ContextualMode, Menu)} method called.
- * If it returns true the menu will be scanned for updated content and any relevant changes
- * will be reflected to the user.
- */
- public abstract void invalidate();
-
- /**
- * Finish and close this context mode. The context mode's {@link ContextualMode.Callback} will
- * have its {@link Callback#onDestroyContextualMode(ContextualMode)} method called.
- */
- public abstract void finish();
-
- /**
- * Returns the menu of actions that this contextual mode presents.
- * @return The contextual mode's menu.
- */
- public abstract Menu getMenu();
-
- /**
- * Returns the current title of this contextual mode.
- * @return Title text
- */
- public abstract CharSequence getTitle();
-
- /**
- * Returns the current subtitle of this contextual mode.
- * @return Subtitle text
- */
- public abstract CharSequence getSubtitle();
-
- /**
- * Returns the current custom view for this contextual mode.
- * @return The current custom view
- */
- public abstract View getCustomView();
-
- /**
- * Callback interface for contextual modes. Supplied to
- * {@link Context#startContextualMode(Callback)}, a Callback
- * configures and handles events raised by a user's interaction with a context mode.
- *
- * <p>A context mode's lifecycle is as follows:
- * <ul>
- * <li>{@link Callback#onCreateContextualMode(ContextualMode, Menu)} once on initial
- * creation</li>
- * <li>{@link Callback#onPrepareContextualMode(ContextualMode, Menu)} after creation
- * and any time the {@link ContextualMode} is invalidated</li>
- * <li>{@link Callback#onContextualItemClicked(ContextualMode, MenuItem)} any time a
- * contextual action button is clicked</li>
- * <li>{@link Callback#onDestroyContextualMode(ContextualMode)} when the context mode
- * is closed</li>
- * </ul>
- */
- public interface Callback {
- /**
- * Called when a contextual mode is first created. The menu supplied will be used to
- * generate action buttons for the contextual mode.
- *
- * @param mode ContextualMode being created
- * @param menu Menu used to populate contextual action buttons
- * @return true if the contextual mode should be created, false if entering this
- * mode should be aborted.
- */
- public boolean onCreateContextualMode(ContextualMode mode, Menu menu);
-
- /**
- * Called to refresh a contextual mode's action menu whenever it is invalidated.
- *
- * @param mode ContextualMode being prepared
- * @param menu Menu used to populate contextual action buttons
- * @return true if the menu or contextual mode was updated, false otherwise.
- */
- public boolean onPrepareContextualMode(ContextualMode mode, Menu menu);
-
- /**
- * Called to report a user click on a contextual action button.
- *
- * @param mode The current ContextualMode
- * @param item The item that was clicked
- * @return true if this callback handled the event, false if the standard MenuItem
- * invocation should continue.
- */
- public boolean onContextualItemClicked(ContextualMode mode, MenuItem item);
-
- /**
- * Called when a contextual mode is about to be exited and destroyed.
- *
- * @param mode The current ContextualMode being destroyed
- */
- public void onDestroyContextualMode(ContextualMode mode);
- }
-} \ No newline at end of file
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java
index da8c9e5..a9420b4 100644
--- a/core/java/android/app/Dialog.java
+++ b/core/java/android/app/Dialog.java
@@ -18,16 +18,18 @@ package android.app;
import com.android.internal.policy.PolicyManager;
-import android.content.Context;
-import android.content.DialogInterface;
import android.content.ComponentName;
+import android.content.Context;
import android.content.ContextWrapper;
+import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
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;
@@ -36,13 +38,12 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
+import android.view.View.OnCreateContextMenuListener;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
-import android.view.ContextMenu.ContextMenuInfo;
-import android.view.View.OnCreateContextMenuListener;
-import android.view.ViewGroup.LayoutParams;
import android.view.accessibility.AccessibilityEvent;
import java.lang.ref.WeakReference;
@@ -832,6 +833,11 @@ public class Dialog implements DialogInterface, Window.Callback,
}
}
+ public ActionMode onStartActionMode(ActionMode.Callback callback) {
+ // TODO Support context modes in dialogs
+ return null;
+ }
+
/**
* @return The activity associated with this dialog, or null if there is no assocaited activity.
*/
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index aceeed6..3d64984 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -16,7 +16,6 @@
package android.content;
-import android.app.ContextualMode;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
@@ -1983,25 +1982,4 @@ public abstract class Context {
public boolean isRestricted() {
return false;
}
-
- /**
- * Start a contextual mode controlled by <code>callback</code>.
- * The {@link ContextualMode.Callback} will receive lifecycle events for the duration
- * of the contextual mode. There can only be one contextual mode active at a time.
- * Starting a new contextual mode while one is already active will finish the old
- * contextual mode.
- *
- * @param callback Callback handler that will manage this context mode.
- * @return The new contextual mode started by this call, or <code>null</code>
- * if the mode was not started.
- */
- public ContextualMode startContextualMode(ContextualMode.Callback callback) {
- return null;
- }
-
- /**
- * Finish the current contextual mode if present.
- */
- public void finishContextualMode() {
- }
}
diff --git a/core/java/android/view/ActionMode.java b/core/java/android/view/ActionMode.java
new file mode 100644
index 0000000..d4f4b93
--- /dev/null
+++ b/core/java/android/view/ActionMode.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2010 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.view;
+
+
+/**
+ * Represents a contextual mode of the user interface. Action modes can be used for
+ * modal interactions with content and replace parts of the normal UI until finished.
+ * Examples of good action modes include selection modes, search, content editing, etc.
+ */
+public abstract class ActionMode {
+ /**
+ * Set the title of the action mode. This method will have no visible effect if
+ * a custom view has been set.
+ *
+ * @param title Title string to set
+ *
+ * @see #setCustomView(View)
+ */
+ public abstract void setTitle(CharSequence title);
+
+ /**
+ * Set the subtitle of the action mode. This method will have no visible effect if
+ * a custom view has been set.
+ *
+ * @param subtitle Subtitle string to set
+ *
+ * @see #setCustomView(View)
+ */
+ public abstract void setSubtitle(CharSequence subtitle);
+
+ /**
+ * Set a custom view for this action mode. The custom view will take the place of
+ * the title and subtitle. Useful for things like search boxes.
+ *
+ * @param view Custom view to use in place of the title/subtitle.
+ *
+ * @see #setTitle(CharSequence)
+ * @see #setSubtitle(CharSequence)
+ */
+ public abstract void setCustomView(View view);
+
+ /**
+ * Invalidate the action mode and refresh menu content. The mode's
+ * {@link ActionMode.Callback} will have its
+ * {@link Callback#onPrepareActionMode(ActionMode, Menu)} method called.
+ * If it returns true the menu will be scanned for updated content and any relevant changes
+ * will be reflected to the user.
+ */
+ public abstract void invalidate();
+
+ /**
+ * Finish and close this action mode. The action mode's {@link ActionMode.Callback} will
+ * have its {@link Callback#onDestroyActionMode(ActionMode)} method called.
+ */
+ public abstract void finish();
+
+ /**
+ * Returns the menu of actions that this action mode presents.
+ * @return The action mode's menu.
+ */
+ public abstract Menu getMenu();
+
+ /**
+ * Returns the current title of this action mode.
+ * @return Title text
+ */
+ public abstract CharSequence getTitle();
+
+ /**
+ * Returns the current subtitle of this action mode.
+ * @return Subtitle text
+ */
+ public abstract CharSequence getSubtitle();
+
+ /**
+ * Returns the current custom view for this action mode.
+ * @return The current custom view
+ */
+ public abstract View getCustomView();
+
+ /**
+ * Callback interface for action modes. Supplied to
+ * {@link View#startActionMode(Callback)}, a Callback
+ * configures and handles events raised by a user's interaction with an action mode.
+ *
+ * <p>An action mode's lifecycle is as follows:
+ * <ul>
+ * <li>{@link Callback#onCreateActionMode(ActionMode, Menu)} once on initial
+ * creation</li>
+ * <li>{@link Callback#onPrepareActionMode(ActionMode, Menu)} after creation
+ * and any time the {@link ActionMode} is invalidated</li>
+ * <li>{@link Callback#onActionItemClicked(ActionMode, MenuItem)} any time a
+ * contextual action button is clicked</li>
+ * <li>{@link Callback#onDestroyActionMode(ActionMode)} when the action mode
+ * is closed</li>
+ * </ul>
+ */
+ public interface Callback {
+ /**
+ * Called when action mode is first created. The menu supplied will be used to
+ * generate action buttons for the action mode.
+ *
+ * @param mode ActionMode being created
+ * @param menu Menu used to populate action buttons
+ * @return true if the action mode should be created, false if entering this
+ * mode should be aborted.
+ */
+ public boolean onCreateActionMode(ActionMode mode, Menu menu);
+
+ /**
+ * Called to refresh an action mode's action menu whenever it is invalidated.
+ *
+ * @param mode ActionMode being prepared
+ * @param menu Menu used to populate action buttons
+ * @return true if the menu or action mode was updated, false otherwise.
+ */
+ public boolean onPrepareActionMode(ActionMode mode, Menu menu);
+
+ /**
+ * Called to report a user click on an action button.
+ *
+ * @param mode The current ActionMode
+ * @param item The item that was clicked
+ * @return true if this callback handled the event, false if the standard MenuItem
+ * invocation should continue.
+ */
+ public boolean onActionItemClicked(ActionMode mode, MenuItem item);
+
+ /**
+ * Called when an action mode is about to be exited and destroyed.
+ *
+ * @param mode The current ActionMode being destroyed
+ */
+ public void onDestroyActionMode(ActionMode mode);
+ }
+} \ No newline at end of file
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index b1025c9..363aced 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -16,7 +16,6 @@
package android.view;
-import android.graphics.RectF;
import com.android.internal.R;
import com.android.internal.view.menu.MenuBuilder;
@@ -35,6 +34,7 @@ import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
+import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.Shader;
import android.graphics.drawable.ColorDrawable;
@@ -57,6 +57,7 @@ import android.util.PoolableManager;
import android.util.Pools;
import android.util.SparseArray;
import android.view.ContextMenu.ContextMenuInfo;
+import android.view.View.MeasureSpec;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityEventSource;
import android.view.accessibility.AccessibilityManager;
@@ -2541,6 +2542,18 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
}
/**
+ * Start an action mode.
+ *
+ * @param callback Callback that will control the lifecycle of the action mode
+ * @return The new action mode if it is started, null otherwise
+ *
+ * @see ActionMode
+ */
+ public ActionMode startActionMode(ActionMode.Callback callback) {
+ return getParent().startActionModeForChild(this, callback);
+ }
+
+ /**
* Register a callback to be invoked when a key is pressed in this view.
* @param l the key listener to attach to this view
*/
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index 3c161ca..a713efc 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -16,7 +16,6 @@
package android.view;
-import android.graphics.Matrix;
import com.android.internal.R;
import android.content.Context;
@@ -24,6 +23,7 @@ import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
@@ -35,6 +35,7 @@ import android.util.Config;
import android.util.EventLog;
import android.util.Log;
import android.util.SparseArray;
+import android.view.ViewGroup.LayoutParams;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
@@ -474,6 +475,13 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
}
/**
+ * {@inheritDoc}
+ */
+ public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) {
+ return mParent != null ? mParent.startActionModeForChild(originalView, callback) : null;
+ }
+
+ /**
* Find the nearest view in the specified direction that wants to take
* focus.
*
diff --git a/core/java/android/view/ViewParent.java b/core/java/android/view/ViewParent.java
index b456c5d..d7d4c3f 100644
--- a/core/java/android/view/ViewParent.java
+++ b/core/java/android/view/ViewParent.java
@@ -162,6 +162,20 @@ public interface ViewParent {
public void createContextMenu(ContextMenu menu);
/**
+ * Start an action mode for the specified view.
+ * <p>
+ * In most cases, a subclass does not need to override this. However, if the
+ * subclass is added directly to the window manager (for example,
+ * {@link ViewManager#addView(View, android.view.ViewGroup.LayoutParams)})
+ * then it should override this and start the action mode.
+ *
+ * @param originalView The source view where the action mode was first invoked
+ * @param callback The callback that will handle lifecycle events for the action mode
+ * @return The new action mode if it was started, null otherwise
+ */
+ public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback);
+
+ /**
* This method is called on the parent when a child's drawable state
* has changed.
*
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index 03cbb8a..877a302 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -2717,6 +2717,10 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
return false;
}
+ public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) {
+ return null;
+ }
+
public void createContextMenu(ContextMenu menu) {
}
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index be681cc..ed02456 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -299,6 +299,14 @@ public abstract class Window {
* @see android.app.Activity#onSearchRequested()
*/
public boolean onSearchRequested();
+
+ /**
+ * Called when an action mode is being started.
+ *
+ * @param callback Callback to control the lifecycle of this action mode
+ * @return The ActionMode that was started, or null if it was canceled
+ */
+ public ActionMode onStartActionMode(ActionMode.Callback callback);
}
public Window(Context context) {
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index 050f630..6515f25 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -24,11 +24,11 @@ import com.android.internal.widget.ActionBarView;
import android.app.ActionBar;
import android.app.Activity;
-import android.app.ContextualMode;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.graphics.drawable.Drawable;
import android.os.Handler;
+import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -66,7 +66,7 @@ public class ActionBarImpl extends ActionBar {
private TabImpl mSelectedTab;
private int mTabSwitchMode = TAB_SWITCH_ADD_REMOVE;
- private ContextMode mContextMode;
+ private ActionMode mContextMode;
private static final int CONTEXT_DISPLAY_NORMAL = 0;
private static final int CONTEXT_DISPLAY_SPLIT = 1;
@@ -229,8 +229,10 @@ public class ActionBarImpl extends ActionBar {
return mActionView.getDisplayOptions();
}
- public ContextualMode startContextualMode(ContextualMode.Callback callback) {
- finishContextualMode();
+ public ActionMode startContextMode(ActionMode.Callback callback) {
+ if (mContextMode != null) {
+ mContextMode.finish();
+ }
// Don't wait for the close context mode animation to finish.
if (mClosingContext) {
@@ -239,8 +241,8 @@ public class ActionBarImpl extends ActionBar {
mCloseContext.run();
}
- ContextMode mode = new ContextMode(callback);
- if (callback.onCreateContextualMode(mode, mode.getMenu())) {
+ ActionMode mode = new ContextModeImpl(callback);
+ if (callback.onCreateActionMode(mode, mode.getMenu())) {
mode.invalidate();
mUpperContextView.initForMode(mode);
mAnimatorView.setDisplayedChild(CONTEXT_VIEW);
@@ -254,12 +256,6 @@ public class ActionBarImpl extends ActionBar {
return null;
}
- public void finishContextualMode() {
- if (mContextMode != null) {
- mContextMode.finish();
- }
- }
-
private void configureTab(Tab tab, int position) {
final TabImpl tabi = (TabImpl) tab;
final boolean isFirstTab = mTabs.isEmpty();
@@ -365,12 +361,12 @@ public class ActionBarImpl extends ActionBar {
/**
* @hide
*/
- public class ContextMode extends ContextualMode implements MenuBuilder.Callback {
- private ContextualMode.Callback mCallback;
+ public class ContextModeImpl extends ActionMode implements MenuBuilder.Callback {
+ private ActionMode.Callback mCallback;
private MenuBuilder mMenu;
private WeakReference<View> mCustomView;
- public ContextMode(ContextualMode.Callback callback) {
+ public ContextModeImpl(ActionMode.Callback callback) {
mCallback = callback;
mMenu = new MenuBuilder(mActionView.getContext());
mMenu.setCallback(this);
@@ -388,7 +384,7 @@ public class ActionBarImpl extends ActionBar {
return;
}
- mCallback.onDestroyContextualMode(this);
+ mCallback.onDestroyActionMode(this);
mAnimatorView.setDisplayedChild(NORMAL_VIEW);
// Clear out the context mode views after the animation finishes
@@ -404,7 +400,7 @@ public class ActionBarImpl extends ActionBar {
@Override
public void invalidate() {
- if (mCallback.onPrepareContextualMode(this, mMenu)) {
+ if (mCallback.onPrepareActionMode(this, mMenu)) {
// Refresh content in both context views
}
}
@@ -441,7 +437,7 @@ public class ActionBarImpl extends ActionBar {
}
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
- return mCallback.onContextualItemClicked(this, item);
+ return mCallback.onActionItemClicked(this, item);
}
public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
diff --git a/core/java/com/android/internal/widget/ActionBarContextView.java b/core/java/com/android/internal/widget/ActionBarContextView.java
index 08405a3..a185e21 100644
--- a/core/java/com/android/internal/widget/ActionBarContextView.java
+++ b/core/java/com/android/internal/widget/ActionBarContextView.java
@@ -19,11 +19,11 @@ import com.android.internal.R;
import com.android.internal.view.menu.ActionMenuView;
import com.android.internal.view.menu.MenuBuilder;
-import android.app.ContextualMode;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
+import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -135,7 +135,7 @@ public class ActionBarContextView extends ViewGroup {
}
}
- public void initForMode(final ContextualMode mode) {
+ public void initForMode(final ActionMode mode) {
if (mCloseButton == null) {
mCloseButton = new ImageButton(getContext());
mCloseButton.setImageDrawable(mCloseDrawable);
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index cc91f31..5771e85 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -55,6 +55,7 @@ import android.util.Config;
import android.util.EventLog;
import android.util.Log;
import android.util.SparseArray;
+import android.view.ActionMode;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.InputQueue;
@@ -78,12 +79,9 @@ import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
-import android.widget.ListPopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;
-import java.lang.ref.WeakReference;
-
/**
* Android-specific Window.
* <p>
@@ -1930,6 +1928,19 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
return mContextMenuHelper != null;
}
+ @Override
+ public ActionMode startActionModeForChild(View originalView,
+ ActionMode.Callback callback) {
+ // originalView can be used here to be sure that we don't obscure
+ // relevant content with the context mode UI.
+ return startActionMode(callback);
+ }
+
+ @Override
+ public ActionMode startActionMode(ActionMode.Callback callback) {
+ return getCallback().onStartActionMode(callback);
+ }
+
public void startChanging() {
mChanging = true;
}