Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1519)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabRecyclerView.java

Issue 1812293002: Add new NTP layout with snippet cards and hide it behind a flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + CR comments + added background color to new NTP Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabRecyclerView.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabRecyclerView.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabRecyclerView.java
new file mode 100644
index 0000000000000000000000000000000000000000..54a7a6ebf4d3af39f768f4524a3f39c7d394025b
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabRecyclerView.java
@@ -0,0 +1,90 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.ntp;
+
+import android.content.Context;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.util.AttributeSet;
+import android.view.GestureDetector;
+import android.view.MotionEvent;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputConnection;
+
+/**
+ * Simple wrapper on top of a RecyclerView that will acquire focus when tapped. Ensures the
+ * New Tab page receives focus when clicked.
+ */
+public class NewTabRecyclerView extends RecyclerView {
dgn 2016/03/24 13:56:26 s/NewTabRecyclerView/NewTabPageRecyclerView ? Is t
newt (away) 2016/03/24 19:47:39 This name parallels NewTabScrollView, but is incon
dgn 2016/03/28 21:33:02 Done.
+ private static final String TAG = "NewTabScrollView";
+
+ /**
+ * Listener for scroll changes.
+ */
+ public interface OnScrollListener {
+ /**
+ * Triggered when the scroll changes. See ScrollView#onScrollChanged for more
+ * details.
+ */
+ void onScrollChanged(int l, int t, int oldl, int oldt);
+ }
+
+ private GestureDetector mGestureDetector;
+ private OnScrollListener mOnScrollListener;
+
+ /**
+ * Constructor needed to inflate from XML.
+ */
+ public NewTabRecyclerView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ mGestureDetector =
+ new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
+ @Override
+ public boolean onSingleTapUp(MotionEvent e) {
+ boolean retVal = super.onSingleTapUp(e);
+ requestFocus();
+ return retVal;
+ }
+ });
+ setLayoutManager(new LinearLayoutManager(getContext()));
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ mGestureDetector.onTouchEvent(ev);
dgn 2016/03/24 13:56:26 Q: Why is this done in onInterceptTouchEvent if we
newt (away) 2016/03/24 19:47:39 I'm not sure. Ted originally added this in https:/
+ return super.onInterceptTouchEvent(ev);
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev) {
+ // Action down would already have been handled in onInterceptTouchEvent
+ if (ev.getActionMasked() != MotionEvent.ACTION_DOWN) {
+ mGestureDetector.onTouchEvent(ev);
+ }
+ return super.onTouchEvent(ev);
+ }
+
+ /**
+ * Sets the listener to be notified of scroll changes.
+ * @param listener The listener to be updated on scroll changes.
+ */
+ public void setOnScrollListener(OnScrollListener listener) {
+ mOnScrollListener = listener;
+ }
+
+ @Override
+ protected void onScrollChanged(int l, int t, int oldl, int oldt) {
+ super.onScrollChanged(l, t, oldl, oldt);
+ if (mOnScrollListener != null) mOnScrollListener.onScrollChanged(l, t, oldl, oldt);
+ }
+
+ @Override
+ public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
+ // Fixes lanscape transitions when unfocusing the URL bar: crbug.com/288546
+ outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN;
+ return super.onCreateInputConnection(outAttrs);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698