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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/widget/ReaderModeControl.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.widget;
6
7 import android.content.Context;
8 import android.graphics.Rect;
9 import android.util.AttributeSet;
10 import android.view.View;
11 import android.view.ViewParent;
12 import android.widget.LinearLayout;
13 import android.widget.TextView;
14
15 import com.google.android.apps.chrome.R;
16
17 import org.chromium.ui.resources.dynamics.ViewResourceAdapter;
18
19 /**
20 * Root ControlContainer for the Reader Mode panel.
21 * Handles user interaction with the Reader Mode control.
22 * See {@link ContextualSearchControl} for inspiration, based on ToolbarControlC ontainer.
23 */
24 public class ReaderModeControl extends LinearLayout {
25 private ViewResourceAdapter mResourceAdapter;
26 private TextView mReaderViewText;
27 private boolean mIsDirty = false;
28
29 /**
30 * Constructs a new control container.
31 * <p>
32 * This constructor is used when inflating from XML.
33 *
34 * @param context The context used to build this view.
35 * @param attrs The attributes used to determine how to construct this view.
36 */
37 public ReaderModeControl(Context context, AttributeSet attrs) {
38 super(context, attrs);
39 }
40
41 /**
42 * @return The {@link ViewResourceAdapter} that exposes this {@link View} as a CC resource.
43 */
44 public ViewResourceAdapter getResourceAdapter() {
45 return mResourceAdapter;
46 }
47
48 @Override
49 public void onFinishInflate() {
50 super.onFinishInflate();
51
52 mReaderViewText = (TextView) findViewById(R.id.main_text);
53 mResourceAdapter = new ViewResourceAdapter(findViewById(R.id.reader_mode _view));
54 mIsDirty = true;
55 }
56
57 @Override
58 public ViewParent invalidateChildInParent(int[] location, Rect dirty) {
59 ViewParent parent = super.invalidateChildInParent(location, dirty);
60 // TODO(pedrosimonetti): ViewGroup#invalidateChildInParent() is being ca lled multiple
61 // times with different rectangles (for each of the individual repaints it seems). This
62 // means in order to invalidate it only once we need to keep track of th e dirty state,
63 // and call ViewResourceAdapter#invalidate() only once per change of sta te, passing
64 // "null" to indicate that the whole area should be invalidated. This ca n be deleted
65 // if we stop relying on an Android View to render our Search Bar Text.
66 if (mIsDirty && mResourceAdapter != null) {
67 mIsDirty = false;
68 mResourceAdapter.invalidate(null);
69 }
70 return parent;
71 }
72
73 /**
74 * Sets the reader mode text to display in the control.
75 */
76 public void setReaderModeText() {
77 mReaderViewText.setText(R.string.reader_view_text);
78 mIsDirty = true;
79 }
80
81 /**
82 * @param X X-coordinate in dp
83 * @param Y Y-coordinate in dp
84 * @return Whether a given coordinates are within the bounds of the "dismiss " button
85 */
86 public boolean isInsideDismissButton(float x, float y) {
87 View view = findViewById(R.id.main_close);
88 final int left = (int) (view.getLeft() + view.getTranslationX());
89 final int top = (int) (view.getTop() + view.getTranslationY());
90 final int right = left + view.getWidth();
91 final int bottom = top + view.getHeight();
92 final int ix = (int) x;
93 final int iy = (int) y;
94 return ix >= left && ix < right && iy >= top && iy < bottom;
95 }
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698