summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget/ActivityChooserModel.java
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2011-07-29 20:14:09 -0700
committerSvetoslav Ganov <svetoslavganov@google.com>2011-08-04 07:56:49 -0700
commit8c6c79f0909ceabeb8abe1013648c31c7582b7ad (patch)
tree8ef1991f4552ef196567f078b2d9dca59ec6f518 /core/java/android/widget/ActivityChooserModel.java
parent7abaecc3dbb610b24e22685e6aa749c7011be1eb (diff)
downloadframeworks_base-8c6c79f0909ceabeb8abe1013648c31c7582b7ad.zip
frameworks_base-8c6c79f0909ceabeb8abe1013648c31c7582b7ad.tar.gz
frameworks_base-8c6c79f0909ceabeb8abe1013648c31c7582b7ad.tar.bz2
Adding a callback to ShareActionProvider + make ActivityChooserView popup hide on action bar hide.
1. Added a callback to ShareActionProvider allowing clients to be notified when an activity is chosed given them a change to say update their UI and also decide whether to handle the activity launch themselves. 2. The popup of the ActivityChooserView was not hiding on hiding the action bar. bug:5094963 bug:5095004 Change-Id: I6c8e8cc1f22d07e707e2218eb108f9101417b23b
Diffstat (limited to 'core/java/android/widget/ActivityChooserModel.java')
-rw-r--r--core/java/android/widget/ActivityChooserModel.java59
1 files changed, 55 insertions, 4 deletions
diff --git a/core/java/android/widget/ActivityChooserModel.java b/core/java/android/widget/ActivityChooserModel.java
index 4b0a6da..9fea506 100644
--- a/core/java/android/widget/ActivityChooserModel.java
+++ b/core/java/android/widget/ActivityChooserModel.java
@@ -131,6 +131,30 @@ public class ActivityChooserModel extends DataSetObservable {
}
/**
+ * Listener for choosing an activity.
+ */
+ public interface OnChooseActivityListener {
+
+ /**
+ * Called when an activity has been chosen. The client can decide whether
+ * an activity can be chosen and if so the caller of
+ * {@link ActivityChooserModel#chooseActivity(int)} will receive and {@link Intent}
+ * for launching it.
+ * <p>
+ * <strong>Note:</strong> Modifying the intent is not permitted and
+ * any changes to the latter will be ignored.
+ * </p>
+ *
+ * @param host The listener's host model.
+ * @param intent The intent for launching the chosen activity.
+ * @return Whether the intent is handled and should not be delivered to clients.
+ *
+ * @see ActivityChooserModel#chooseActivity(int)
+ */
+ public boolean onChooseActivity(ActivityChooserModel host, Intent intent);
+ }
+
+ /**
* Flag for selecting debug mode.
*/
private static final boolean DEBUG = false;
@@ -287,6 +311,11 @@ public class ActivityChooserModel extends DataSetObservable {
private final Handler mHandler = new Handler();
/**
+ * Policy for controlling how the model handles chosen activities.
+ */
+ private OnChooseActivityListener mActivityChoserModelPolicy;
+
+ /**
* Gets the data model backed by the contents of the provided file with historical data.
* Note that only one data model is backed by a given file, thus multiple calls with
* the same file name will return the same model instance. If no such instance is present
@@ -426,9 +455,11 @@ public class ActivityChooserModel extends DataSetObservable {
* the client solely to let additional customization before the start.
* </p>
*
- * @return Whether adding succeeded.
+ * @return An {@link Intent} for launching the activity or null if the
+ * policy has consumed the intent.
*
* @see HistoricalRecord
+ * @see OnChooseActivityListener
*/
public Intent chooseActivity(int index) {
ActivityResolveInfo chosenActivity = mActivites.get(index);
@@ -436,17 +467,37 @@ public class ActivityChooserModel extends DataSetObservable {
ComponentName chosenName = new ComponentName(
chosenActivity.resolveInfo.activityInfo.packageName,
chosenActivity.resolveInfo.activityInfo.name);
- HistoricalRecord historicalRecord = new HistoricalRecord(chosenName,
- System.currentTimeMillis(), DEFAULT_HISTORICAL_RECORD_WEIGHT);
- addHisoricalRecord(historicalRecord);
Intent choiceIntent = new Intent(mIntent);
choiceIntent.setComponent(chosenName);
+ if (mActivityChoserModelPolicy != null) {
+ // Do not allow the policy to change the intent.
+ Intent choiceIntentCopy = new Intent(choiceIntent);
+ final boolean handled = mActivityChoserModelPolicy.onChooseActivity(this,
+ choiceIntentCopy);
+ if (handled) {
+ return null;
+ }
+ }
+
+ HistoricalRecord historicalRecord = new HistoricalRecord(chosenName,
+ System.currentTimeMillis(), DEFAULT_HISTORICAL_RECORD_WEIGHT);
+ addHisoricalRecord(historicalRecord);
+
return choiceIntent;
}
/**
+ * Sets the listener for choosing an activity.
+ *
+ * @param listener The listener.
+ */
+ public void setOnChooseActivityListener(OnChooseActivityListener listener) {
+ mActivityChoserModelPolicy = listener;
+ }
+
+ /**
* Gets the default activity, The default activity is defined as the one
* with highest rank i.e. the first one in the list of activities that can
* handle the intent.