OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.bookmark; |
| 6 |
| 7 import android.content.Intent; |
| 8 import android.graphics.Bitmap; |
| 9 import android.graphics.Color; |
| 10 import android.view.ViewGroup; |
| 11 |
| 12 import com.google.android.apps.chrome.R; |
| 13 |
| 14 import org.chromium.chrome.browser.BookmarkUtils; |
| 15 import org.chromium.chrome.browser.UrlConstants; |
| 16 import org.chromium.chrome.browser.favicon.FaviconHelper; |
| 17 import org.chromium.chrome.browser.init.AsyncInitializationActivity; |
| 18 import org.chromium.chrome.browser.ntp.BookmarksPage; |
| 19 import org.chromium.chrome.browser.ntp.BookmarksPage.BookmarkSelectedListener; |
| 20 import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmarksShim; |
| 21 import org.chromium.chrome.browser.profiles.Profile; |
| 22 |
| 23 /** |
| 24 * Activity that allows the user to select a bookmark to add to their homescreen
as a shortcut. |
| 25 */ |
| 26 public class ShortcutActivity extends AsyncInitializationActivity implements |
| 27 BookmarkSelectedListener { |
| 28 private BookmarksPage mBookmarksPage; |
| 29 |
| 30 @Override |
| 31 protected void setContentView() { |
| 32 // We can't show anything until the native library is loaded. |
| 33 } |
| 34 |
| 35 @Override |
| 36 public void postInflationStartup() { |
| 37 setTitle(getResources().getString(R.string.bookmark_shortcut_choose_book
mark)); |
| 38 } |
| 39 |
| 40 @Override |
| 41 public void initializeState() { |
| 42 super.initializeState(); |
| 43 |
| 44 // Partner bookmarks need to be loaded explicitly. |
| 45 PartnerBookmarksShim.kickOffReading(this); |
| 46 |
| 47 Profile profile = Profile.getLastUsedProfile(); |
| 48 mBookmarksPage = BookmarksPage.buildPageInSelectBookmarkMode(this, profi
le, this); |
| 49 mBookmarksPage.updateForUrl(UrlConstants.BOOKMARKS_URL); |
| 50 |
| 51 setContentView(mBookmarksPage.getView(), new ViewGroup.LayoutParams( |
| 52 ViewGroup.LayoutParams.MATCH_PARENT, |
| 53 ViewGroup.LayoutParams.MATCH_PARENT)); |
| 54 } |
| 55 |
| 56 @Override |
| 57 public void onDestroy() { |
| 58 super.onDestroy(); |
| 59 if (mBookmarksPage != null) { |
| 60 mBookmarksPage.destroy(); |
| 61 mBookmarksPage = null; |
| 62 } |
| 63 } |
| 64 |
| 65 // BookmarkSelectedListener implementation |
| 66 |
| 67 @Override |
| 68 public void onNewTabOpened() { |
| 69 } |
| 70 |
| 71 @Override |
| 72 public void onBookmarkSelected(String url, String title, Bitmap favicon) { |
| 73 int dominantColor = FaviconHelper.getDominantColorForBitmap(favicon); |
| 74 Bitmap launcherIcon = BookmarkUtils.createLauncherIcon(this, favicon, ur
l, |
| 75 Color.red(dominantColor), Color.green(dominantColor), Color.blue
(dominantColor)); |
| 76 Intent intent = BookmarkUtils.createAddToHomeIntent(url, title, launcher
Icon); |
| 77 setResult(RESULT_OK, intent); |
| 78 finish(); |
| 79 } |
| 80 |
| 81 @Override |
| 82 public void onResumeWithNative() { } |
| 83 |
| 84 @Override |
| 85 public void onPauseWithNative() { } |
| 86 |
| 87 @Override |
| 88 public void onStopWithNative() { } |
| 89 } |
OLD | NEW |