Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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 android.widget; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 21 | import android.content.pm.PackageManager; |
| 22 | import android.content.pm.ResolveInfo; |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 23 | import android.graphics.drawable.Drawable; |
| 24 | import android.util.TypedValue; |
| 25 | import android.view.ActionProvider; |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 26 | import android.view.Menu; |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 27 | import android.view.MenuItem; |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 28 | import android.view.MenuItem.OnMenuItemClickListener; |
Adam Powell | 961dd11 | 2011-07-12 14:25:23 -0700 | [diff] [blame] | 29 | import android.view.SubMenu; |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 30 | import android.view.View; |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 31 | import android.widget.ActivityChooserModel.OnChooseActivityListener; |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 32 | |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 33 | import com.android.internal.R; |
| 34 | |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 35 | /** |
| 36 | * This is a provider for a share action. It is responsible for creating views |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 37 | * that enable data sharing and also to show a sub menu with sharing activities |
| 38 | * if the hosting item is placed on the overflow menu. |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 39 | * <p> |
| 40 | * Here is how to use the action provider with custom backing file in a {@link MenuItem}: |
| 41 | * </p> |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 42 | * <pre> |
kmccormick | 43d5abb | 2013-04-03 17:28:14 -0700 | [diff] [blame] | 43 | * // In Activity#onCreateOptionsMenu |
| 44 | * public boolean onCreateOptionsMenu(Menu menu) { |
| 45 | * // Get the menu item. |
| 46 | * MenuItem menuItem = menu.findItem(R.id.my_menu_item); |
| 47 | * // Get the provider and hold onto it to set/change the share intent. |
| 48 | * mShareActionProvider = (ShareActionProvider) menuItem.getActionProvider(); |
| 49 | * // Set history different from the default before getting the action |
| 50 | * // view since a call to {@link MenuItem#getActionView() MenuItem.getActionView()} calls |
| 51 | * // {@link ActionProvider#onCreateActionView()} which uses the backing file name. Omit this |
| 52 | * // line if using the default share history file is desired. |
| 53 | * mShareActionProvider.setShareHistoryFileName("custom_share_history.xml"); |
| 54 | * . . . |
| 55 | * } |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 56 | * |
kmccormick | 43d5abb | 2013-04-03 17:28:14 -0700 | [diff] [blame] | 57 | * // Somewhere in the application. |
| 58 | * public void doShare(Intent shareIntent) { |
| 59 | * // When you want to share set the share intent. |
| 60 | * mShareActionProvider.setShareIntent(shareIntent); |
| 61 | * }</pre> |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 62 | * <p> |
| 63 | * <strong>Note:</strong> While the sample snippet demonstrates how to use this provider |
| 64 | * in the context of a menu item, the use of the provider is not limited to menu items. |
| 65 | * </p> |
| 66 | * |
| 67 | * @see ActionProvider |
| 68 | */ |
| 69 | public class ShareActionProvider extends ActionProvider { |
| 70 | |
| 71 | /** |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 72 | * Listener for the event of selecting a share target. |
| 73 | */ |
| 74 | public interface OnShareTargetSelectedListener { |
| 75 | |
| 76 | /** |
| 77 | * Called when a share target has been selected. The client can |
Svetoslav Ganov | b33eacd | 2012-04-13 12:32:17 -0700 | [diff] [blame] | 78 | * decide whether to perform some action before the sharing is |
| 79 | * actually performed. |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 80 | * <p> |
| 81 | * <strong>Note:</strong> Modifying the intent is not permitted and |
| 82 | * any changes to the latter will be ignored. |
| 83 | * </p> |
Svetoslav Ganov | b33eacd | 2012-04-13 12:32:17 -0700 | [diff] [blame] | 84 | * <p> |
| 85 | * <strong>Note:</strong> You should <strong>not</strong> handle the |
| 86 | * intent here. This callback aims to notify the client that a |
| 87 | * sharing is being performed, so the client can update the UI |
| 88 | * if necessary. |
| 89 | * </p> |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 90 | * |
| 91 | * @param source The source of the notification. |
| 92 | * @param intent The intent for launching the chosen share target. |
Svetoslav Ganov | b33eacd | 2012-04-13 12:32:17 -0700 | [diff] [blame] | 93 | * @return The return result is ignored. Always return false for consistency. |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 94 | */ |
| 95 | public boolean onShareTargetSelected(ShareActionProvider source, Intent intent); |
| 96 | } |
| 97 | |
| 98 | /** |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 99 | * The default for the maximal number of activities shown in the sub-menu. |
| 100 | */ |
| 101 | private static final int DEFAULT_INITIAL_ACTIVITY_COUNT = 4; |
| 102 | |
| 103 | /** |
| 104 | * The the maximum number activities shown in the sub-menu. |
| 105 | */ |
| 106 | private int mMaxShownActivityCount = DEFAULT_INITIAL_ACTIVITY_COUNT; |
| 107 | |
| 108 | /** |
| 109 | * Listener for handling menu item clicks. |
| 110 | */ |
| 111 | private final ShareMenuItemOnMenuItemClickListener mOnMenuItemClickListener = |
| 112 | new ShareMenuItemOnMenuItemClickListener(); |
| 113 | |
| 114 | /** |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 115 | * The default name for storing share history. |
| 116 | */ |
| 117 | public static final String DEFAULT_SHARE_HISTORY_FILE_NAME = "share_history.xml"; |
| 118 | |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 119 | /** |
| 120 | * Context for accessing resources. |
| 121 | */ |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 122 | private final Context mContext; |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * The name of the file with share history data. |
| 126 | */ |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 127 | private String mShareHistoryFileName = DEFAULT_SHARE_HISTORY_FILE_NAME; |
| 128 | |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 129 | private OnShareTargetSelectedListener mOnShareTargetSelectedListener; |
| 130 | |
| 131 | private OnChooseActivityListener mOnChooseActivityListener; |
| 132 | |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 133 | /** |
| 134 | * Creates a new instance. |
| 135 | * |
| 136 | * @param context Context for accessing resources. |
| 137 | */ |
| 138 | public ShareActionProvider(Context context) { |
| 139 | super(context); |
| 140 | mContext = context; |
| 141 | } |
| 142 | |
| 143 | /** |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 144 | * Sets a listener to be notified when a share target has been selected. |
| 145 | * The listener can optionally decide to handle the selection and |
| 146 | * not rely on the default behavior which is to launch the activity. |
| 147 | * <p> |
| 148 | * <strong>Note:</strong> If you choose the backing share history file |
| 149 | * you will still be notified in this callback. |
| 150 | * </p> |
| 151 | * @param listener The listener. |
| 152 | */ |
| 153 | public void setOnShareTargetSelectedListener(OnShareTargetSelectedListener listener) { |
| 154 | mOnShareTargetSelectedListener = listener; |
| 155 | setActivityChooserPolicyIfNeeded(); |
| 156 | } |
| 157 | |
| 158 | /** |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 159 | * {@inheritDoc} |
| 160 | */ |
| 161 | @Override |
| 162 | public View onCreateActionView() { |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 163 | // Create the view and set its data model. |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 164 | ActivityChooserView activityChooserView = new ActivityChooserView(mContext); |
Deepanshu Gupta | 14bf0ce | 2013-12-12 12:16:24 -0800 | [diff] [blame] | 165 | if (!activityChooserView.isInEditMode()) { |
| 166 | ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName); |
| 167 | activityChooserView.setActivityChooserModel(dataModel); |
| 168 | } |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 169 | |
| 170 | // Lookup and set the expand action icon. |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 171 | TypedValue outTypedValue = new TypedValue(); |
| 172 | mContext.getTheme().resolveAttribute(R.attr.actionModeShareDrawable, outTypedValue, true); |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 173 | Drawable drawable = mContext.getDrawable(outTypedValue.resourceId); |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 174 | activityChooserView.setExpandActivityOverflowButtonDrawable(drawable); |
Adam Powell | 823f074 | 2011-09-21 17:17:01 -0700 | [diff] [blame] | 175 | activityChooserView.setProvider(this); |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 176 | |
Svetoslav Ganov | 7085377 | 2011-09-30 19:57:35 -0700 | [diff] [blame] | 177 | // Set content description. |
| 178 | activityChooserView.setDefaultActionButtonContentDescription( |
| 179 | R.string.shareactionprovider_share_with_application); |
| 180 | activityChooserView.setExpandActivityOverflowButtonContentDescription( |
| 181 | R.string.shareactionprovider_share_with); |
| 182 | |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 183 | return activityChooserView; |
| 184 | } |
| 185 | |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 186 | /** |
| 187 | * {@inheritDoc} |
| 188 | */ |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 189 | @Override |
Adam Powell | 961dd11 | 2011-07-12 14:25:23 -0700 | [diff] [blame] | 190 | public boolean hasSubMenu() { |
| 191 | return true; |
| 192 | } |
| 193 | |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 194 | /** |
| 195 | * {@inheritDoc} |
| 196 | */ |
Adam Powell | 961dd11 | 2011-07-12 14:25:23 -0700 | [diff] [blame] | 197 | @Override |
| 198 | public void onPrepareSubMenu(SubMenu subMenu) { |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 199 | // Clear since the order of items may change. |
| 200 | subMenu.clear(); |
| 201 | |
| 202 | ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName); |
| 203 | PackageManager packageManager = mContext.getPackageManager(); |
| 204 | |
| 205 | final int expandedActivityCount = dataModel.getActivityCount(); |
| 206 | final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount); |
| 207 | |
| 208 | // Populate the sub-menu with a sub set of the activities. |
| 209 | for (int i = 0; i < collapsedActivityCount; i++) { |
| 210 | ResolveInfo activity = dataModel.getActivity(i); |
| 211 | subMenu.add(0, i, i, activity.loadLabel(packageManager)) |
| 212 | .setIcon(activity.loadIcon(packageManager)) |
| 213 | .setOnMenuItemClickListener(mOnMenuItemClickListener); |
| 214 | } |
| 215 | |
Svetoslav Ganov | 414051b | 2011-07-17 22:28:42 -0700 | [diff] [blame] | 216 | if (collapsedActivityCount < expandedActivityCount) { |
| 217 | // Add a sub-menu for showing all activities as a list item. |
| 218 | SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, |
| 219 | collapsedActivityCount, |
| 220 | mContext.getString(R.string.activity_chooser_view_see_all)); |
| 221 | for (int i = 0; i < expandedActivityCount; i++) { |
| 222 | ResolveInfo activity = dataModel.getActivity(i); |
| 223 | expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager)) |
| 224 | .setIcon(activity.loadIcon(packageManager)) |
| 225 | .setOnMenuItemClickListener(mOnMenuItemClickListener); |
| 226 | } |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 227 | } |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Sets the file name of a file for persisting the share history which |
| 232 | * history will be used for ordering share targets. This file will be used |
| 233 | * for all view created by {@link #onCreateActionView()}. Defaults to |
| 234 | * {@link #DEFAULT_SHARE_HISTORY_FILE_NAME}. Set to <code>null</code> |
| 235 | * if share history should not be persisted between sessions. |
| 236 | * <p> |
| 237 | * <strong>Note:</strong> The history file name can be set any time, however |
| 238 | * only the action views created by {@link #onCreateActionView()} after setting |
Svetoslav Ganov | 775bcac | 2012-02-07 12:18:04 -0800 | [diff] [blame] | 239 | * the file name will be backed by the provided file. Therefore, if you want to |
| 240 | * use different history files for sharing specific types of content, every time |
| 241 | * you change the history file {@link #setShareHistoryFileName(String)} you must |
| 242 | * call {@link android.app.Activity#invalidateOptionsMenu()} to recreate the |
| 243 | * action view. You should <strong>not</strong> call |
| 244 | * {@link android.app.Activity#invalidateOptionsMenu()} from |
kmccormick | 43d5abb | 2013-04-03 17:28:14 -0700 | [diff] [blame] | 245 | * {@link android.app.Activity#onCreateOptionsMenu(Menu)}. |
| 246 | * </p> |
| 247 | * <pre> |
Svetoslav Ganov | 775bcac | 2012-02-07 12:18:04 -0800 | [diff] [blame] | 248 | * private void doShare(Intent intent) { |
| 249 | * if (IMAGE.equals(intent.getMimeType())) { |
| 250 | * mShareActionProvider.setHistoryFileName(SHARE_IMAGE_HISTORY_FILE_NAME); |
| 251 | * } else if (TEXT.equals(intent.getMimeType())) { |
| 252 | * mShareActionProvider.setHistoryFileName(SHARE_TEXT_HISTORY_FILE_NAME); |
| 253 | * } |
| 254 | * mShareActionProvider.setIntent(intent); |
| 255 | * invalidateOptionsMenu(); |
kmccormick | 43d5abb | 2013-04-03 17:28:14 -0700 | [diff] [blame] | 256 | * }</pre> |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 257 | * @param shareHistoryFile The share history file name. |
| 258 | */ |
| 259 | public void setShareHistoryFileName(String shareHistoryFile) { |
| 260 | mShareHistoryFileName = shareHistoryFile; |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 261 | setActivityChooserPolicyIfNeeded(); |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Sets an intent with information about the share action. Here is a |
| 266 | * sample for constructing a share intent: |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 267 | * <pre> |
kmccormick | 43d5abb | 2013-04-03 17:28:14 -0700 | [diff] [blame] | 268 | * Intent shareIntent = new Intent(Intent.ACTION_SEND); |
| 269 | * shareIntent.setType("image/*"); |
| 270 | * Uri uri = Uri.fromFile(new File(getFilesDir(), "foo.jpg")); |
Katie McCormick | f2ef28d | 2013-11-26 11:10:54 -0800 | [diff] [blame] | 271 | * shareIntent.putExtra(Intent.EXTRA_STREAM, uri));</pre> |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 272 | * |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 273 | * @param shareIntent The share intent. |
| 274 | * |
| 275 | * @see Intent#ACTION_SEND |
| 276 | * @see Intent#ACTION_SEND_MULTIPLE |
| 277 | */ |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 278 | public void setShareIntent(Intent shareIntent) { |
Craig Mautner | 411d2aed | 2014-05-08 09:07:43 -0700 | [diff] [blame] | 279 | if (shareIntent != null) { |
| 280 | final String action = shareIntent.getAction(); |
| 281 | if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) { |
| 282 | shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 283 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); |
Craig Mautner | 411d2aed | 2014-05-08 09:07:43 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 286 | ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, |
| 287 | mShareHistoryFileName); |
| 288 | dataModel.setIntent(shareIntent); |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Reusable listener for handling share item clicks. |
| 293 | */ |
| 294 | private class ShareMenuItemOnMenuItemClickListener implements OnMenuItemClickListener { |
| 295 | @Override |
| 296 | public boolean onMenuItemClick(MenuItem item) { |
| 297 | ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, |
| 298 | mShareHistoryFileName); |
| 299 | final int itemId = item.getItemId(); |
| 300 | Intent launchIntent = dataModel.chooseActivity(itemId); |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 301 | if (launchIntent != null) { |
Craig Mautner | 411d2aed | 2014-05-08 09:07:43 -0700 | [diff] [blame] | 302 | final String action = launchIntent.getAction(); |
| 303 | if (Intent.ACTION_SEND.equals(action) || |
| 304 | Intent.ACTION_SEND_MULTIPLE.equals(action)) { |
| 305 | launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | |
Dianne Hackborn | 13420f2 | 2014-07-18 15:43:56 -0700 | [diff] [blame] | 306 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); |
Craig Mautner | 411d2aed | 2014-05-08 09:07:43 -0700 | [diff] [blame] | 307 | } |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 308 | mContext.startActivity(launchIntent); |
| 309 | } |
Svetoslav Ganov | 76559a6 | 2011-07-06 17:17:52 -0700 | [diff] [blame] | 310 | return true; |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 313 | |
| 314 | /** |
| 315 | * Set the activity chooser policy of the model backed by the current |
| 316 | * share history file if needed which is if there is a registered callback. |
| 317 | */ |
| 318 | private void setActivityChooserPolicyIfNeeded() { |
| 319 | if (mOnShareTargetSelectedListener == null) { |
| 320 | return; |
| 321 | } |
| 322 | if (mOnChooseActivityListener == null) { |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 323 | mOnChooseActivityListener = new ShareActivityChooserModelPolicy(); |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 324 | } |
| 325 | ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName); |
| 326 | dataModel.setOnChooseActivityListener(mOnChooseActivityListener); |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Policy that delegates to the {@link OnShareTargetSelectedListener}, if such. |
| 331 | */ |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 332 | private class ShareActivityChooserModelPolicy implements OnChooseActivityListener { |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 333 | @Override |
| 334 | public boolean onChooseActivity(ActivityChooserModel host, Intent intent) { |
| 335 | if (mOnShareTargetSelectedListener != null) { |
Svetoslav Ganov | b33eacd | 2012-04-13 12:32:17 -0700 | [diff] [blame] | 336 | mOnShareTargetSelectedListener.onShareTargetSelected( |
Svetoslav Ganov | 8c6c79f | 2011-07-29 20:14:09 -0700 | [diff] [blame] | 337 | ShareActionProvider.this, intent); |
| 338 | } |
| 339 | return false; |
| 340 | } |
| 341 | } |
Svetoslav Ganov | 51ac0e9 | 2011-06-17 13:45:13 -0700 | [diff] [blame] | 342 | } |