Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/FeedbackReportingView.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/FeedbackReportingView.java b/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/FeedbackReportingView.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e75cf9a9b3f85481cc4bf42de00b051e7d8c0cb9 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/FeedbackReportingView.java |
| @@ -0,0 +1,130 @@ |
| +// Copyright 2014 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.dom_distiller; |
| + |
| +import android.content.Context; |
| +import android.util.AttributeSet; |
| +import android.view.LayoutInflater; |
| +import android.view.MotionEvent; |
| +import android.view.View; |
| +import android.widget.ImageButton; |
| + |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.banners.SwipableOverlayView; |
| +import org.chromium.content.browser.ContentView; |
| + |
| +/** |
| + * A view which displays a question to the user about the quality of distillation, where the user |
| + * is given the option to respond. |
| + * <p/> |
|
shashi
2014/03/14 20:33:24
nit: <p/> missing <p>.
nyquist
2014/03/17 20:13:42
As a standalone <p/> I think this is fine. It is a
|
| + * The observer is called when the user makes a choice. After this point, it is not possible to |
| + * interact with the view, and it is ready for dismissal. The selected option stays visibly |
| + * selected. |
| + */ |
| +public class FeedbackReportingView extends SwipableOverlayView { |
| + // XML layout for the BannerView. |
| + private static final int VIEW_LAYOUT = R.layout.feedback_reporting_view; |
| + |
| + // Class to alert about FeedbackReportingView events. |
| + private Observer mObserver; |
| + |
| + // The button to click for selecting 'No'. |
| + private ImageButton mNoButton; |
| + |
| + // The button to click for selecting 'Yes'. |
| + private ImageButton mYesButton; |
| + |
| + // Whether a selection has already been made, which means new events should be ignored. |
| + private boolean mSelectionMade; |
| + |
| + /** |
| + * Called when the user makes a choice. After the call, it is not possible to interact further |
| + * with the view. |
| + */ |
| + interface Observer { |
|
newt (away)
2014/03/17 18:19:19
The code below might be clearer if this name were
nyquist
2014/03/17 20:13:42
Done.
|
| + void onYesPressed(FeedbackReportingView view); |
| + |
| + void onNoPressed(FeedbackReportingView view); |
| + } |
| + |
| + /** |
| + * Creates a BannerView and adds it to the given ContentView. |
|
shashi
2014/03/14 20:33:24
nit: BannerView or FeedbackReportingView?
nyquist
2014/03/17 20:13:42
Done.
|
| + * |
| + * @param contentView ContentView to display the FeedbackReportingView for. |
| + * @param observer Class that is alerted for FeedbackReportingView events. |
| + * @return The created banner. |
| + */ |
| + public static FeedbackReportingView create(ContentView contentView, Observer observer) { |
| + Context context = contentView.getContext().getApplicationContext(); |
| + FeedbackReportingView banner = |
| + (FeedbackReportingView) LayoutInflater.from(context).inflate(VIEW_LAYOUT, null); |
| + banner.initialize(observer); |
| + banner.addToView(contentView); |
| + return banner; |
| + } |
| + |
| + /** |
| + * Creates a SwipableOverlayView. |
|
newt (away)
2014/03/17 18:19:19
FeedbackReportingView
nyquist
2014/03/17 20:13:42
Done.
|
| + * |
| + * @param context Context for acquiring resources. |
| + * @param attrs Attributes from the XML layout inflation. |
| + */ |
| + public FeedbackReportingView(Context context, AttributeSet attrs) { |
| + super(context, attrs); |
| + } |
| + |
| + private void initialize(Observer observer) { |
| + mObserver = observer; |
| + mNoButton = (ImageButton) findViewById(R.id.distillation_quality_answer_no); |
| + mYesButton = (ImageButton) findViewById(R.id.distillation_quality_answer_yes); |
| + mNoButton.setClickable(true); |
| + mYesButton.setClickable(true); |
| + mNoButton.setOnClickListener(new OnClickListener() { |
| + @Override |
| + public void onClick(View v) { |
| + if (mSelectionMade) return; |
| + mSelectionMade = true; |
| + mNoButton.setImageResource(R.drawable.distillation_quality_answer_no_pressed); |
| + disableUI(); |
| + if (mObserver != null) mObserver.onNoPressed(FeedbackReportingView.this); |
| + } |
| + }); |
| + mYesButton.setOnClickListener(new OnClickListener() { |
| + @Override |
| + public void onClick(View v) { |
| + if (mSelectionMade) return; |
| + mSelectionMade = true; |
| + mYesButton.setImageResource(R.drawable.distillation_quality_answer_yes_pressed); |
| + disableUI(); |
| + if (mObserver != null) mObserver.onYesPressed(FeedbackReportingView.this); |
| + } |
| + }); |
| + } |
| + |
| + private void disableUI() { |
| + mNoButton.setOnClickListener(null); |
| + mYesButton.setOnClickListener(null); |
| + mNoButton.setEnabled(false); |
| + mYesButton.setEnabled(false); |
| + mNoButton.setClickable(false); |
|
shashi
2014/03/14 20:33:24
this seems to be really exhaustive :).
nyquist
2014/03/17 20:13:42
Done.
Kept setEnabled(false) and cleared OnClickL
|
| + mYesButton.setClickable(false); |
| + } |
| + |
| + /** |
| + * This is overridden since the method is protected in the parent {@link SwipableOverlayView}. |
|
newt (away)
2014/03/17 18:19:19
Why is this needed?
nyquist
2014/03/17 20:13:42
Added an exhaustive comment.
|
| + */ |
| + @Override |
| + protected void dismiss() { |
| + super.dismiss(); |
| + } |
| + |
| + @Override |
| + protected void onViewClicked() { |
| + } |
| + |
| + @Override |
| + protected void onViewPressed(MotionEvent event) { |
| + } |
| +} |