OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.share; | 5 package org.chromium.chrome.browser.share; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.app.AlertDialog; | 8 import android.app.AlertDialog; |
9 import android.content.ComponentName; | 9 import android.content.ComponentName; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 30 matching lines...) Expand all Loading... | |
41 | 41 |
42 /** | 42 /** |
43 * A helper class that helps to start an intent to share titles and URLs. | 43 * A helper class that helps to start an intent to share titles and URLs. |
44 */ | 44 */ |
45 public class ShareHelper { | 45 public class ShareHelper { |
46 | 46 |
47 private static final String TAG = "ShareHelper"; | 47 private static final String TAG = "ShareHelper"; |
48 | 48 |
49 private static final String PACKAGE_NAME_KEY = "last_shared_package_name"; | 49 private static final String PACKAGE_NAME_KEY = "last_shared_package_name"; |
50 private static final String CLASS_NAME_KEY = "last_shared_class_name"; | 50 private static final String CLASS_NAME_KEY = "last_shared_class_name"; |
51 private static final String EXTRA_RAW_FILE_PATH = "raw-file-path"; | |
51 | 52 |
52 /** | 53 /** |
53 * Directory name for screenshots. | 54 * Directory name for screenshots. |
54 */ | 55 */ |
55 private static final String SCREENSHOT_DIRECTORY_NAME = "screenshot"; | 56 private static final String SCREENSHOT_DIRECTORY_NAME = "screenshot"; |
56 | 57 |
57 private ShareHelper() {} | 58 private ShareHelper() {} |
58 | 59 |
59 private static void deleteScreenshotFiles(File file) { | 60 private static void deleteScreenshotFiles(File file) { |
60 if (!file.exists()) return; | 61 if (!file.exists()) return; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 @Override | 174 @Override |
174 protected Intent doInBackground(Void... params) { | 175 protected Intent doInBackground(Void... params) { |
175 return getDirectShareIntentForComponent( | 176 return getDirectShareIntentForComponent( |
176 activity, title, url, screenshot, component); | 177 activity, title, url, screenshot, component); |
177 } | 178 } |
178 | 179 |
179 @Override | 180 @Override |
180 protected void onPostExecute(Intent intent) { | 181 protected void onPostExecute(Intent intent) { |
181 if (ApplicationStatus.getStateForApplication() | 182 if (ApplicationStatus.getStateForApplication() |
182 != ApplicationState.HAS_DESTROYED_ACTIVITIES) { | 183 != ApplicationState.HAS_DESTROYED_ACTIVITIES) { |
184 String rawFilePath = intent.getStringExtra(EXTRA_RAW_FIL E_PATH); | |
185 if (rawFilePath != null) { | |
186 intent.putExtra(Intent.EXTRA_STREAM, UiUtils.getUriF orImageCaptureFile( | |
187 activity, new File(rawFilePath))); | |
188 intent.removeExtra(EXTRA_RAW_FILE_PATH); | |
189 } | |
183 activity.startActivity(intent); | 190 activity.startActivity(intent); |
184 } | 191 } |
185 } | 192 } |
186 }.execute(); | 193 }.execute(); |
187 } | 194 } |
188 } | 195 } |
189 | 196 |
190 /** | 197 /** |
191 * Set the icon and the title for the menu item used for direct share. | 198 * Set the icon and the title for the menu item used for direct share. |
192 * | 199 * |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 UiUtils.getDirectoryForImageCapture(context), SCREENSHOT _DIRECTORY_NAME); | 239 UiUtils.getDirectoryForImageCapture(context), SCREENSHOT _DIRECTORY_NAME); |
233 if (path.exists() || path.mkdir()) { | 240 if (path.exists() || path.mkdir()) { |
234 File saveFile = File.createTempFile( | 241 File saveFile = File.createTempFile( |
235 String.valueOf(System.currentTimeMillis()), ".jpg", path); | 242 String.valueOf(System.currentTimeMillis()), ".jpg", path); |
236 fOut = new FileOutputStream(saveFile); | 243 fOut = new FileOutputStream(saveFile); |
237 screenshot.compress(Bitmap.CompressFormat.JPEG, 85, fOut); | 244 screenshot.compress(Bitmap.CompressFormat.JPEG, 85, fOut); |
238 fOut.flush(); | 245 fOut.flush(); |
239 fOut.close(); | 246 fOut.close(); |
240 | 247 |
241 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | 248 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
242 intent.putExtra(Intent.EXTRA_STREAM, | 249 intent.putExtra(EXTRA_RAW_FILE_PATH, saveFile.getAbsolutePat h()); |
Ted C
2015/03/04 00:09:57
Hmm...I don't really like that we have to muck wit
Jaekyun Seok (inactive)
2015/03/04 00:39:13
Done.
| |
243 UiUtils.getUriForImageCaptureFile(context, saveFile) ); | |
244 } | 250 } |
245 } catch (IOException ie) { | 251 } catch (IOException ie) { |
246 if (fOut != null) { | 252 if (fOut != null) { |
247 try { | 253 try { |
248 fOut.close(); | 254 fOut.close(); |
249 } catch (IOException e) { | 255 } catch (IOException e) { |
250 // Ignore exception. | 256 // Ignore exception. |
251 } | 257 } |
252 } | 258 } |
253 } | 259 } |
(...skipping 19 matching lines...) Expand all Loading... | |
273 } | 279 } |
274 | 280 |
275 private static void setLastShareComponentName(Context context, ComponentName component) { | 281 private static void setLastShareComponentName(Context context, ComponentName component) { |
276 SharedPreferences preferences = PreferenceManager.getDefaultSharedPrefer ences(context); | 282 SharedPreferences preferences = PreferenceManager.getDefaultSharedPrefer ences(context); |
277 SharedPreferences.Editor editor = preferences.edit(); | 283 SharedPreferences.Editor editor = preferences.edit(); |
278 editor.putString(PACKAGE_NAME_KEY, component.getPackageName()); | 284 editor.putString(PACKAGE_NAME_KEY, component.getPackageName()); |
279 editor.putString(CLASS_NAME_KEY, component.getClassName()); | 285 editor.putString(CLASS_NAME_KEY, component.getClassName()); |
280 editor.apply(); | 286 editor.apply(); |
281 } | 287 } |
282 } | 288 } |
OLD | NEW |