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.ntp; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.graphics.Canvas; |
| 9 import android.util.AttributeSet; |
| 10 import android.view.View; |
| 11 import android.widget.FrameLayout; |
| 12 |
| 13 import com.google.android.apps.chrome.R; |
| 14 |
| 15 import org.chromium.chrome.browser.util.ViewUtils; |
| 16 |
| 17 /** |
| 18 * The New Tab Page for use in the incognito profile. |
| 19 */ |
| 20 public class IncognitoNewTabPageView extends FrameLayout { |
| 21 |
| 22 private IncognitoNewTabPageManager mManager; |
| 23 private boolean mFirstShow = true; |
| 24 private NewTabScrollView mScrollView; |
| 25 |
| 26 private int mSnapshotWidth; |
| 27 private int mSnapshotHeight; |
| 28 private int mSnapshotScrollY; |
| 29 |
| 30 /** |
| 31 * Manages the view interaction with the rest of the system. |
| 32 */ |
| 33 interface IncognitoNewTabPageManager { |
| 34 /** Loads a page explaining details about incognito mode in the current
tab. */ |
| 35 void loadIncognitoLearnMore(); |
| 36 |
| 37 /** |
| 38 * Called when the NTP has completely finished loading (all views will b
e inflated |
| 39 * and any dependent resources will have been loaded). |
| 40 */ |
| 41 void onLoadingComplete(); |
| 42 } |
| 43 |
| 44 /** Default constructor needed to inflate via XML. */ |
| 45 public IncognitoNewTabPageView(Context context, AttributeSet attrs) { |
| 46 super(context, attrs); |
| 47 } |
| 48 |
| 49 @Override |
| 50 protected void onFinishInflate() { |
| 51 super.onFinishInflate(); |
| 52 |
| 53 mScrollView = (NewTabScrollView) findViewById(R.id.ntp_scrollview); |
| 54 |
| 55 // FOCUS_BEFORE_DESCENDANTS is needed to support keyboard shortcuts. Oth
erwise, pressing |
| 56 // any shortcut causes the UrlBar to be focused. See ViewRootImpl.leaveT
ouchMode(). |
| 57 mScrollView.setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS); |
| 58 |
| 59 View learnMore = findViewById(R.id.learn_more); |
| 60 learnMore.setOnClickListener(new OnClickListener() { |
| 61 @Override |
| 62 public void onClick(View v) { |
| 63 mManager.loadIncognitoLearnMore(); |
| 64 } |
| 65 }); |
| 66 } |
| 67 |
| 68 /** |
| 69 * Initialize the incognito New Tab Page. |
| 70 * @param manager The manager that handles external dependencies of the view
. |
| 71 */ |
| 72 void initialize(IncognitoNewTabPageManager manager) { |
| 73 mManager = manager; |
| 74 } |
| 75 |
| 76 /** |
| 77 * @see org.chromium.chrome.browser.compositor.layouts.content. |
| 78 * InvalidationAwareThumbnailProvider#shouldCaptureThumbnail() |
| 79 */ |
| 80 boolean shouldCaptureThumbnail() { |
| 81 if (getWidth() == 0 || getHeight() == 0) return false; |
| 82 |
| 83 return getWidth() != mSnapshotWidth |
| 84 || getHeight() != mSnapshotHeight |
| 85 || mScrollView.getScrollY() != mSnapshotScrollY; |
| 86 } |
| 87 |
| 88 /** |
| 89 * @see org.chromium.chrome.browser.compositor.layouts.content. |
| 90 * InvalidationAwareThumbnailProvider#captureThumbnail(Canvas) |
| 91 */ |
| 92 void captureThumbnail(Canvas canvas) { |
| 93 ViewUtils.captureBitmap(this, canvas); |
| 94 mSnapshotWidth = getWidth(); |
| 95 mSnapshotHeight = getHeight(); |
| 96 mSnapshotScrollY = mScrollView.getScrollY(); |
| 97 } |
| 98 |
| 99 // OnAttachStateChangeListener overrides |
| 100 |
| 101 @Override |
| 102 public void onAttachedToWindow() { |
| 103 assert mManager != null; |
| 104 if (mFirstShow) { |
| 105 mManager.onLoadingComplete(); |
| 106 mFirstShow = false; |
| 107 } |
| 108 } |
| 109 } |
OLD | NEW |