packages/apps/Gallery2
修订版 | deff258ea4e5723b351739418919251ae1048e46 (tree) |
---|---|
时间 | 2011-09-15 19:34:02 |
作者 | Ray Chen <raychen@goog...> |
Commiter | Ray Chen |
Fix 5290260 Unable to rotate left or right to album from Gallery
Separate menu operation and sharing options to different methods so
execution side is consistent with menu options.
Change-Id: Ia0105b333035051e33e9563fb2186cf1a29bc225
@@ -164,26 +164,25 @@ public class ActionModeHandler implements ActionMode.Callback { | ||
164 | 164 | return true; |
165 | 165 | } |
166 | 166 | |
167 | - private void updateMenuOptionsAndSharingIntent(JobContext jc) { | |
168 | - ArrayList<Path> paths = mSelectionManager.getSelected(true); | |
167 | + // Menu options are determined by selection set itself. | |
168 | + // We cannot expand it because MenuExecuter executes it based on | |
169 | + // the selection set instead of the expanded result. | |
170 | + // e.g. LocalImage can be rotated but collections of them (LocalAlbum) can't. | |
171 | + private void updateMenuOptions(JobContext jc) { | |
172 | + ArrayList<Path> paths = mSelectionManager.getSelected(false); | |
169 | 173 | if (paths.size() == 0) return; |
170 | 174 | |
171 | 175 | int operation = MediaObject.SUPPORT_ALL; |
172 | 176 | DataManager manager = mActivity.getDataManager(); |
173 | - final ArrayList<Uri> uris = new ArrayList<Uri>(); | |
174 | 177 | int type = 0; |
175 | 178 | for (Path path : paths) { |
176 | 179 | if (jc.isCancelled()) return; |
177 | 180 | int support = manager.getSupportedOperations(path); |
178 | 181 | type |= manager.getMediaType(path); |
179 | 182 | operation &= support; |
180 | - if ((support & MediaObject.SUPPORT_SHARE) != 0) { | |
181 | - uris.add(manager.getContentUri(path)); | |
182 | - } | |
183 | 183 | } |
184 | - final Intent intent = new Intent(); | |
185 | - final String mimeType = MenuExecutor.getMimeType(type); | |
186 | 184 | |
185 | + final String mimeType = MenuExecutor.getMimeType(type); | |
187 | 186 | if (paths.size() == 1) { |
188 | 187 | if (!GalleryUtils.isEditorAvailable((Context) mActivity, mimeType)) { |
189 | 188 | operation &= ~MediaObject.SUPPORT_EDIT; |
@@ -192,9 +191,42 @@ public class ActionModeHandler implements ActionMode.Callback { | ||
192 | 191 | operation &= SUPPORT_MULTIPLE_MASK; |
193 | 192 | } |
194 | 193 | |
194 | + final int supportedOperation = operation; | |
195 | + | |
196 | + mMainHandler.post(new Runnable() { | |
197 | + @Override | |
198 | + public void run() { | |
199 | + mMenuTask = null; | |
200 | + MenuExecutor.updateMenuOperation(mMenu, supportedOperation); | |
201 | + } | |
202 | + }); | |
203 | + } | |
204 | + | |
205 | + // Share intent needs to expand the selection set so we can get URI of | |
206 | + // each media item | |
207 | + private void updateSharingIntent(JobContext jc) { | |
208 | + if (mShareActionProvider == null) return; | |
209 | + ArrayList<Path> paths = mSelectionManager.getSelected(true); | |
210 | + if (paths.size() == 0) return; | |
211 | + | |
212 | + final ArrayList<Uri> uris = new ArrayList<Uri>(); | |
213 | + | |
214 | + DataManager manager = mActivity.getDataManager(); | |
215 | + int type = 0; | |
216 | + | |
217 | + final Intent intent = new Intent(); | |
218 | + for (Path path : paths) { | |
219 | + int support = manager.getSupportedOperations(path); | |
220 | + type |= manager.getMediaType(path); | |
221 | + | |
222 | + if ((support & MediaObject.SUPPORT_SHARE) != 0) { | |
223 | + uris.add(manager.getContentUri(path)); | |
224 | + } | |
225 | + } | |
226 | + | |
195 | 227 | final int size = uris.size(); |
196 | - Log.v(TAG, "Sharing intent MIME type=" + mimeType + ", uri size = "+ uris.size()); | |
197 | 228 | if (size > 0) { |
229 | + final String mimeType = MenuExecutor.getMimeType(type); | |
198 | 230 | if (size > 1) { |
199 | 231 | intent.setAction(Intent.ACTION_SEND_MULTIPLE).setType(mimeType); |
200 | 232 | intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); |
@@ -203,22 +235,15 @@ public class ActionModeHandler implements ActionMode.Callback { | ||
203 | 235 | intent.putExtra(Intent.EXTRA_STREAM, uris.get(0)); |
204 | 236 | } |
205 | 237 | intent.setType(mimeType); |
206 | - } | |
207 | - | |
208 | - final int supportedOperation = operation; | |
209 | - | |
210 | - mMainHandler.post(new Runnable() { | |
211 | - @Override | |
212 | - public void run() { | |
213 | - mMenuTask = null; | |
214 | - MenuExecutor.updateMenuOperation(mMenu, supportedOperation); | |
215 | 238 | |
216 | - if (mShareActionProvider != null && size > 0) { | |
239 | + mMainHandler.post(new Runnable() { | |
240 | + @Override | |
241 | + public void run() { | |
217 | 242 | Log.v(TAG, "Sharing intent is ready: action = " + intent.getAction()); |
218 | 243 | mShareActionProvider.setShareIntent(intent); |
219 | 244 | } |
220 | - } | |
221 | - }); | |
245 | + }); | |
246 | + } | |
222 | 247 | } |
223 | 248 | |
224 | 249 | public void updateSupportedOperation(Path path, boolean selected) { |
@@ -240,7 +265,8 @@ public class ActionModeHandler implements ActionMode.Callback { | ||
240 | 265 | // Generate sharing intent and update supported operations in the background |
241 | 266 | mMenuTask = mActivity.getThreadPool().submit(new Job<Void>() { |
242 | 267 | public Void run(JobContext jc) { |
243 | - updateMenuOptionsAndSharingIntent(jc); | |
268 | + updateMenuOptions(jc); | |
269 | + updateSharingIntent(jc); | |
244 | 270 | return null; |
245 | 271 | } |
246 | 272 | }); |