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.ntp; | 5 package org.chromium.chrome.browser.ntp; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.app.ActivityManager; | 9 import android.app.ActivityManager; |
10 import android.app.Dialog; | 10 import android.app.Dialog; |
11 import android.content.Context; | 11 import android.content.Context; |
12 import android.content.Intent; | 12 import android.content.Intent; |
13 import android.graphics.Canvas; | 13 import android.graphics.Canvas; |
14 import android.graphics.Color; | |
15 import android.graphics.Rect; | 14 import android.graphics.Rect; |
16 import android.net.Uri; | 15 import android.net.Uri; |
17 import android.os.Build; | 16 import android.os.Build; |
18 import android.view.ContextMenu; | 17 import android.view.ContextMenu; |
19 import android.view.LayoutInflater; | 18 import android.view.LayoutInflater; |
20 import android.view.Menu; | 19 import android.view.Menu; |
21 import android.view.MenuItem.OnMenuItemClickListener; | 20 import android.view.MenuItem.OnMenuItemClickListener; |
22 import android.view.View; | 21 import android.view.View; |
23 | 22 |
24 import org.chromium.base.ApiCompatibilityUtils; | 23 import org.chromium.base.ApiCompatibilityUtils; |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 */ | 574 */ |
576 public NewTabPage(Activity activity, Tab tab, TabModelSelector tabModelSelec
tor) { | 575 public NewTabPage(Activity activity, Tab tab, TabModelSelector tabModelSelec
tor) { |
577 mConstructedTimeNs = System.nanoTime(); | 576 mConstructedTimeNs = System.nanoTime(); |
578 | 577 |
579 mTab = tab; | 578 mTab = tab; |
580 mActivity = activity; | 579 mActivity = activity; |
581 mTabModelSelector = tabModelSelector; | 580 mTabModelSelector = tabModelSelector; |
582 mProfile = tab.getProfile(); | 581 mProfile = tab.getProfile(); |
583 | 582 |
584 mTitle = activity.getResources().getString(R.string.button_new_tab); | 583 mTitle = activity.getResources().getString(R.string.button_new_tab); |
585 mBackgroundColor = ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SNI
PPETS) | 584 mBackgroundColor = NtpColorUtils.getBackgroundColorResource(activity.get
Resources()); |
586 ? ApiCompatibilityUtils.getColor(activity.getResources(), R.colo
r.ntp_with_cards_bg) | |
587 : ApiCompatibilityUtils.getColor(activity.getResources(), R.colo
r.ntp_bg); | |
588 mThemeColor = ApiCompatibilityUtils.getColor( | 585 mThemeColor = ApiCompatibilityUtils.getColor( |
589 activity.getResources(), R.color.default_primary_color); | 586 activity.getResources(), R.color.default_primary_color); |
590 TemplateUrlService.getInstance().addObserver(this); | 587 TemplateUrlService.getInstance().addObserver(this); |
591 | 588 |
592 mTabObserver = new EmptyTabObserver() { | 589 mTabObserver = new EmptyTabObserver() { |
593 @Override | 590 @Override |
594 public void onShown(Tab tab) { | 591 public void onShown(Tab tab) { |
595 // Showing the NTP is only meaningful when the page has been loa
ded already. | 592 // Showing the NTP is only meaningful when the page has been loa
ded already. |
596 if (mIsLoaded) recordNTPShown(); | 593 if (mIsLoaded) recordNTPShown(); |
597 mIsVisible = true; | 594 mIsVisible = true; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 return mTitle; | 805 return mTitle; |
809 } | 806 } |
810 | 807 |
811 @Override | 808 @Override |
812 public int getBackgroundColor() { | 809 public int getBackgroundColor() { |
813 return mBackgroundColor; | 810 return mBackgroundColor; |
814 } | 811 } |
815 | 812 |
816 @Override | 813 @Override |
817 public int getThemeColor() { | 814 public int getThemeColor() { |
818 return isLocationBarShownInNTP() ? Color.WHITE : mThemeColor; | 815 return isLocationBarShownInNTP() |
| 816 ? NtpColorUtils.getBackgroundColorResource(mActivity.getResource
s()) |
| 817 : mThemeColor; |
819 } | 818 } |
820 | 819 |
821 @Override | 820 @Override |
822 public View getView() { | 821 public View getView() { |
823 return mNewTabPageView; | 822 return mNewTabPageView; |
824 } | 823 } |
825 | 824 |
826 @Override | 825 @Override |
827 public String getHost() { | 826 public String getHost() { |
828 return UrlConstants.NTP_HOST; | 827 return UrlConstants.NTP_HOST; |
829 } | 828 } |
830 | 829 |
831 @Override | 830 @Override |
832 public void updateForUrl(String url) { | 831 public void updateForUrl(String url) { |
833 } | 832 } |
834 | 833 |
835 // InvalidationAwareThumbnailProvider | 834 // InvalidationAwareThumbnailProvider |
836 | 835 |
837 @Override | 836 @Override |
838 public boolean shouldCaptureThumbnail() { | 837 public boolean shouldCaptureThumbnail() { |
839 return mNewTabPageView.shouldCaptureThumbnail(); | 838 return mNewTabPageView.shouldCaptureThumbnail(); |
840 } | 839 } |
841 | 840 |
842 @Override | 841 @Override |
843 public void captureThumbnail(Canvas canvas) { | 842 public void captureThumbnail(Canvas canvas) { |
844 mNewTabPageView.captureThumbnail(canvas); | 843 mNewTabPageView.captureThumbnail(canvas); |
845 } | 844 } |
846 } | 845 } |
OLD | NEW |