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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/FeedbackReportingView.java

Issue 197473006: Add FeedbackReporter for reporting distillation quality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed disableUI again and comment Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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.dom_distiller;
6
7 import android.content.Context;
8 import android.util.AttributeSet;
9 import android.view.LayoutInflater;
10 import android.view.MotionEvent;
11 import android.view.View;
12 import android.widget.ImageButton;
13
14 import org.chromium.chrome.R;
15 import org.chromium.chrome.browser.banners.SwipableOverlayView;
16 import org.chromium.content.browser.ContentView;
17
18 /**
19 * A view which displays a question to the user about the quality of distillatio n, where the user
20 * is given the option to respond.
21 *
22 * <p>The observer is called when the user makes a choice. After this point, it is not possible to
23 * interact with the view, and it is ready for dismissal. The selected option st ays visibly
24 * selected.
25 */
26 public class FeedbackReportingView extends SwipableOverlayView {
27 // XML layout for the BannerView.
28 private static final int VIEW_LAYOUT = R.layout.feedback_reporting_view;
29
30 // Class to alert about FeedbackReportingView events.
31 private FeedbackObserver mFeedbackObserver;
32
33 // The button to click for selecting 'No'.
34 private ImageButton mNoButton;
35
36 // The button to click for selecting 'Yes'.
37 private ImageButton mYesButton;
38
39 // Whether a selection has already been made, which means new events should be ignored.
40 private boolean mSelectionMade;
41
42 /**
43 * Called when the user makes a choice. After the call, it is not possible t o interact further
44 * with the view.
45 */
46 interface FeedbackObserver {
47 void onYesPressed(FeedbackReportingView view);
48
49 void onNoPressed(FeedbackReportingView view);
50 }
51
52 /**
53 * Creates a FeedbackReportingView and adds it to the given ContentView.
54 *
55 * @param contentView ContentView to display the FeedbackReportingView for.
56 * @param feedbackObserver Class that is alerted for FeedbackReportingView e vents.
57 * @return The created banner.
58 */
59 public static FeedbackReportingView create(ContentView contentView,
60 FeedbackObserver feedbackObserver ) {
61 Context context = contentView.getContext().getApplicationContext();
62 FeedbackReportingView banner =
63 (FeedbackReportingView) LayoutInflater.from(context).inflate(VIE W_LAYOUT, null);
64 banner.initialize(feedbackObserver);
65 banner.addToView(contentView);
66 return banner;
67 }
68
69 /**
70 * Creates a FeedbackReportingView.
71 *
72 * @param context Context for acquiring resources.
73 * @param attrs Attributes from the XML layout inflation.
74 */
75 public FeedbackReportingView(Context context, AttributeSet attrs) {
76 super(context, attrs);
77 }
78
79 private void initialize(FeedbackObserver feedbackObserver) {
80 mFeedbackObserver = feedbackObserver;
81 mNoButton = (ImageButton) findViewById(R.id.distillation_quality_answer_ no);
82 mYesButton = (ImageButton) findViewById(R.id.distillation_quality_answer _yes);
83 mNoButton.setClickable(true);
84 mYesButton.setClickable(true);
85 mNoButton.setOnClickListener(new OnClickListener() {
86 @Override
87 public void onClick(View v) {
88 if (mSelectionMade) return;
89 mSelectionMade = true;
90 mNoButton.setImageResource(R.drawable.distillation_quality_answe r_no_pressed);
91 disableUI();
92 if (mFeedbackObserver != null) {
93 mFeedbackObserver.onNoPressed(FeedbackReportingView.this);
94 }
95 }
96 });
97 mYesButton.setOnClickListener(new OnClickListener() {
98 @Override
99 public void onClick(View v) {
100 if (mSelectionMade) return;
101 mSelectionMade = true;
102 mYesButton.setImageResource(R.drawable.distillation_quality_answ er_yes_pressed);
103 disableUI();
104 if (mFeedbackObserver != null) {
105 mFeedbackObserver.onYesPressed(FeedbackReportingView.this);
106 }
107 }
108 });
109 }
110
111 private void disableUI() {
112 // Clear OnClickListener to assure no more calls and that everything is cleaned up.
113 mNoButton.setOnClickListener(null);
114 mYesButton.setOnClickListener(null);
115
116 // Disable the buttons, so the images for highlighted/non-highlighted wi ll not change if the
117 // user continues to tap the buttons while it is dismissing.
118 mNoButton.setEnabled(false);
119 mYesButton.setEnabled(false);
120 }
121
122 /**
123 * This is overridden since the method visibility is protected in the parent
124 * {@link SwipableOverlayView}. The
125 * {@link org.chromium.chrome.browser.dom_distiller.FeedbackReporter} needs to be able to
126 * dismiss this {@link org.chromium.chrome.browser.dom_distiller.FeedbackRep ortingView}, so by
127 * overriding this method in this class, it is callable from
128 * {@link org.chromium.chrome.browser.dom_distiller.FeedbackReporter}.
129 */
130 @Override
131 protected void dismiss() {
132 super.dismiss();
133 }
134
135 @Override
136 protected void onViewClicked() {
137 }
138
139 @Override
140 protected void onViewPressed(MotionEvent event) {
141 }
142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698