| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.enhancedbookmarks; | 5 package org.chromium.chrome.browser.enhancedbookmarks; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
| 11 import android.net.Uri; | 11 import android.net.Uri; |
| 12 import android.os.AsyncTask; | 12 import android.os.AsyncTask; |
| 13 import android.os.Bundle; | 13 import android.os.Bundle; |
| 14 import android.provider.Browser; | 14 import android.provider.Browser; |
| 15 import android.text.TextUtils; |
| 15 | 16 |
| 16 import org.chromium.base.ApiCompatibilityUtils; | 17 import org.chromium.base.ApiCompatibilityUtils; |
| 18 import org.chromium.base.metrics.RecordHistogram; |
| 17 import org.chromium.base.metrics.RecordUserAction; | 19 import org.chromium.base.metrics.RecordUserAction; |
| 18 import org.chromium.chrome.R; | 20 import org.chromium.chrome.R; |
| 19 import org.chromium.chrome.browser.ChromeBrowserProviderClient; | 21 import org.chromium.chrome.browser.ChromeBrowserProviderClient; |
| 20 import org.chromium.chrome.browser.IntentHandler; | 22 import org.chromium.chrome.browser.IntentHandler; |
| 21 import org.chromium.chrome.browser.UrlConstants; | 23 import org.chromium.chrome.browser.UrlConstants; |
| 22 import org.chromium.chrome.browser.bookmark.BookmarksBridge; | 24 import org.chromium.chrome.browser.bookmark.BookmarksBridge; |
| 23 import org.chromium.chrome.browser.bookmark.BookmarksBridge.BookmarkItem; | 25 import org.chromium.chrome.browser.bookmark.BookmarksBridge.BookmarkItem; |
| 24 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | 26 import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
| 25 import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarksModel.AddB
ookmarkCallback; | 27 import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarksModel.AddB
ookmarkCallback; |
| 26 import org.chromium.chrome.browser.favicon.FaviconHelper; | 28 import org.chromium.chrome.browser.favicon.FaviconHelper; |
| 29 import org.chromium.chrome.browser.ntp.NewTabPageUma; |
| 27 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; | 30 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; |
| 28 import org.chromium.chrome.browser.offlinepages.OfflinePageFreeUpSpaceCallback; | 31 import org.chromium.chrome.browser.offlinepages.OfflinePageFreeUpSpaceCallback; |
| 29 import org.chromium.chrome.browser.offlinepages.OfflinePageFreeUpSpaceDialog; | 32 import org.chromium.chrome.browser.offlinepages.OfflinePageFreeUpSpaceDialog; |
| 30 import org.chromium.chrome.browser.offlinepages.OfflinePageOpenStorageSettingsDi
alog; | 33 import org.chromium.chrome.browser.offlinepages.OfflinePageOpenStorageSettingsDi
alog; |
| 31 import org.chromium.chrome.browser.offlinepages.OfflinePageStorageSpacePolicy; | 34 import org.chromium.chrome.browser.offlinepages.OfflinePageStorageSpacePolicy; |
| 32 import org.chromium.chrome.browser.offlinepages.OfflinePageUtils; | 35 import org.chromium.chrome.browser.offlinepages.OfflinePageUtils; |
| 33 import org.chromium.chrome.browser.snackbar.Snackbar; | 36 import org.chromium.chrome.browser.snackbar.Snackbar; |
| 34 import org.chromium.chrome.browser.snackbar.SnackbarManager; | 37 import org.chromium.chrome.browser.snackbar.SnackbarManager; |
| 35 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController; | 38 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController; |
| 36 import org.chromium.chrome.browser.tab.Tab; | 39 import org.chromium.chrome.browser.tab.Tab; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 259 |
| 257 /** | 260 /** |
| 258 * Shows enhanced bookmark main UI, if it is turned on. Does nothing if it i
s turned off. | 261 * Shows enhanced bookmark main UI, if it is turned on. Does nothing if it i
s turned off. |
| 259 * @return True if enhanced bookmark is on, false otherwise. | 262 * @return True if enhanced bookmark is on, false otherwise. |
| 260 */ | 263 */ |
| 261 public static boolean showEnhancedBookmarkIfEnabled(Activity activity) { | 264 public static boolean showEnhancedBookmarkIfEnabled(Activity activity) { |
| 262 if (!isEnhancedBookmarkEnabled()) { | 265 if (!isEnhancedBookmarkEnabled()) { |
| 263 return false; | 266 return false; |
| 264 } | 267 } |
| 265 if (DeviceFormFactor.isTablet(activity)) { | 268 if (DeviceFormFactor.isTablet(activity)) { |
| 266 openBookmark(activity, UrlConstants.BOOKMARKS_URL); | 269 openUrl(activity, UrlConstants.BOOKMARKS_URL); |
| 267 } else { | 270 } else { |
| 268 activity.startActivity(new Intent(activity, EnhancedBookmarkActivity
.class)); | 271 activity.startActivity(new Intent(activity, EnhancedBookmarkActivity
.class)); |
| 269 } | 272 } |
| 270 return true; | 273 return true; |
| 271 } | 274 } |
| 272 | 275 |
| 273 /** | 276 /** |
| 274 * Starts an {@link EnhancedBookmarkEditActivity} for the given {@link Bookm
arkId}. | 277 * Starts an {@link EnhancedBookmarkEditActivity} for the given {@link Bookm
arkId}. |
| 275 */ | 278 */ |
| 276 public static void startEditActivity( | 279 public static void startEditActivity( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 315 |
| 313 /** | 316 /** |
| 314 * Retrieve the bookmark previously saved in the arguments bundle. | 317 * Retrieve the bookmark previously saved in the arguments bundle. |
| 315 * @param bundle Argument holder or savedInstanceState of the fragment/activ
ity. | 318 * @param bundle Argument holder or savedInstanceState of the fragment/activ
ity. |
| 316 * @return The ID of the bookmark to retrieve. | 319 * @return The ID of the bookmark to retrieve. |
| 317 */ | 320 */ |
| 318 public static BookmarkId getBookmarkIdFromBundle(Bundle bundle) { | 321 public static BookmarkId getBookmarkIdFromBundle(Bundle bundle) { |
| 319 return BookmarkId.getBookmarkIdFromString(bundle.getString(BOOKMARK_SAVE
_NAME)); | 322 return BookmarkId.getBookmarkIdFromString(bundle.getString(BOOKMARK_SAVE
_NAME)); |
| 320 } | 323 } |
| 321 | 324 |
| 322 public static void openBookmark(Activity activity, String url) { | 325 /** |
| 326 * Opens a bookmark depending on connection status and reports UMA. |
| 327 * @param model Enhanced bookmarks model to manage the bookmark. |
| 328 * @param activity Activity requesting to open the bookmark. |
| 329 * @param bookmarkId ID of the bookmark to be opened. |
| 330 * @param launchLocation Location from which the bookmark is being opened. |
| 331 * @return Whether the bookmark was successfully opened. |
| 332 */ |
| 333 public static boolean openBookmark(EnhancedBookmarksModel model, Activity ac
tivity, |
| 334 BookmarkId bookmarkId, int launchLocation) { |
| 335 if (model.getBookmarkById(bookmarkId) == null) return false; |
| 336 |
| 337 String url = model.getLaunchUrlAndMarkAccessed(activity, bookmarkId); |
| 338 |
| 339 // TODO(jianli): Notify the user about the failure. |
| 340 if (TextUtils.isEmpty(url)) return false; |
| 341 |
| 342 NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_BOOKMARK); |
| 343 if (url.startsWith("file:")) { |
| 344 RecordHistogram.recordEnumeratedHistogram( |
| 345 "OfflinePages.LaunchLocation", launchLocation, LaunchLocatio
n.COUNT); |
| 346 } else { |
| 347 RecordHistogram.recordEnumeratedHistogram( |
| 348 "Stars.LaunchLocation", launchLocation, LaunchLocation.COUNT
); |
| 349 } |
| 350 |
| 351 openUrl(activity, url); |
| 352 return true; |
| 353 } |
| 354 |
| 355 private static void openUrl(Activity activity, String url) { |
| 323 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | 356 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
| 324 intent.setClassName(activity.getApplicationContext().getPackageName(), | 357 intent.setClassName(activity.getApplicationContext().getPackageName(), |
| 325 ChromeLauncherActivity.class.getName()); | 358 ChromeLauncherActivity.class.getName()); |
| 326 intent.putExtra(Browser.EXTRA_APPLICATION_ID, | 359 intent.putExtra(Browser.EXTRA_APPLICATION_ID, |
| 327 activity.getApplicationContext().getPackageName()); | 360 activity.getApplicationContext().getPackageName()); |
| 328 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 361 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 329 IntentHandler.startActivityForTrustedIntent(intent, activity); | 362 IntentHandler.startActivityForTrustedIntent(intent, activity); |
| 330 } | 363 } |
| 331 | 364 |
| 332 /** | 365 /** |
| (...skipping 23 matching lines...) Expand all Loading... |
| 356 | 389 |
| 357 /** | 390 /** |
| 358 * Closes the EnhancedBookmark Activity on Phone. Does nothing on tablet. | 391 * Closes the EnhancedBookmark Activity on Phone. Does nothing on tablet. |
| 359 */ | 392 */ |
| 360 public static void finishActivityOnPhone(Context context) { | 393 public static void finishActivityOnPhone(Context context) { |
| 361 if (context instanceof EnhancedBookmarkActivity) { | 394 if (context instanceof EnhancedBookmarkActivity) { |
| 362 ((Activity) context).finish(); | 395 ((Activity) context).finish(); |
| 363 } | 396 } |
| 364 } | 397 } |
| 365 } | 398 } |
| OLD | NEW |