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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchStaticEventFilter.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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 unified diff | Download patch
OLDNEW
(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.contextualsearch;
6
7 import android.content.Context;
8 import android.view.MotionEvent;
9
10 import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context ualSearchPanel;
11 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeHandl er;
12 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilter;
13 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilterHos t;
14
15 /**
16 * A {@link EventFilter} used to filter events in the Contextual Search Bar, whe n displayed
17 * in the StaticLayout.
18 */
19 public class ContextualSearchStaticEventFilter extends EventFilter {
20 /**
21 * The @{link ContextualSearchPanel} that controls Contextual Search's UI.
22 */
23 private final ContextualSearchPanel mSearchPanel;
24
25 /**
26 * The @{link SwipeRecognizer} that recognizes directional swipe gestures.
27 */
28 private final SwipeRecognizer mSwipeRecognizer;
29
30 private final ContextualSearchTapHandler mTapHandler;
31
32 /**
33 * Interface to handle taps on the contextual search bar..
34 */
35 public interface ContextualSearchTapHandler {
36 /**
37 * Handle a tap event on the contextual seach bar.
38 * @param time The time of the tap event.
39 * @param x The x position of the tap event.
40 * @param y The y position of the tap event.
41 */
42 void handleTapContextualSearchBar(long time, float x, float y);
43 }
44
45 /**
46 * Constructs a {@link ContextualSearchStaticEventFilter}.
47 *
48 * @param context The current Android {@link Context}.
49 * @param host The @{link EventFilterHost} associated to this filter.
50 * @param searchPanel The @{link ContextualSearchPanel} that controls Contex tual Seach's UI.
51 * @param swipeHandler The @{link EdgeSwipeHandler} for Contextual Search ev ents.
52 */
53 public ContextualSearchStaticEventFilter(Context context, EventFilterHost ho st,
54 ContextualSearchPanel searchPanel, EdgeSwipeHandler swipeHandler,
55 ContextualSearchTapHandler tapHandler) {
56 super(context, host);
57
58 mSearchPanel = searchPanel;
59 mSwipeRecognizer = new SwipeRecognizerImpl(context);
60 mSwipeRecognizer.setSwipeHandler(swipeHandler);
61 mTapHandler = tapHandler;
62 }
63
64 @Override
65 protected boolean onInterceptTouchEventInternal(MotionEvent event, boolean i sKeyboardShowing) {
66 // TODO(pedrosimonetti): isKeyboardShowing has the wrong value after
67 // rotating the device. We don't really need to check whether the
68 // keyboard is showing here because Contextual Search's Panel will
69 // be closed, if opened, when the keyboard shows up. Even so,
70 // it would be nice fixing this problem in Chrome-Android.
71 return mSearchPanel.isPeeking()
72 && mSearchPanel.isYCoordinateInsideSearchBar(
73 mSearchPanel.getFullscreenY(event.getY()) * mPxToDp);
74 }
75
76 @Override
77 protected boolean onTouchEventInternal(MotionEvent event) {
78 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
79 // To avoid a gray flash of empty content, show the search content
80 // view immediately on tap rather than waiting for panel expansion.
81 // TODO(pedrosimonetti): Once we implement "side-swipe to dismiss"
82 // we'll have to revisit this because we don't want to set the
83 // Content View visibility to true when the side-swipe is detected.
84 mSearchPanel.setSearchContentViewVisibility(true);
85 }
86
87 mSwipeRecognizer.onTouchEvent(event);
88 return true;
89 }
90
91 private class SwipeRecognizerImpl extends SwipeRecognizer {
92 public SwipeRecognizerImpl(Context context) {
93 super(context);
94 }
95
96 @Override
97 public boolean onSingleTapUp(MotionEvent event) {
98 if (mTapHandler == null) return true;
99 mTapHandler.handleTapContextualSearchBar(event.getEventTime(),
100 event.getX() * mPxToDp, mSearchPanel.getFullscreenY(event.ge tY()) * mPxToDp);
101 return true;
102 }
103 }
104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698