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

Unified Diff: blimp/client/core/contents/android/java/src/org/chromium/blimp/core/contents/input/WebInputConfirmationPanel.java

Issue 2393443004: Blimp: Added spinner to text input dialog (Closed)
Patch Set: Added animations Created 4 years, 2 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: blimp/client/core/contents/android/java/src/org/chromium/blimp/core/contents/input/WebInputConfirmationPanel.java
diff --git a/blimp/client/core/contents/android/java/src/org/chromium/blimp/core/contents/input/WebInputConfirmationPanel.java b/blimp/client/core/contents/android/java/src/org/chromium/blimp/core/contents/input/WebInputConfirmationPanel.java
new file mode 100644
index 0000000000000000000000000000000000000000..a2eec251013d6d6f7d54bc855387323d9a0c1276
--- /dev/null
+++ b/blimp/client/core/contents/android/java/src/org/chromium/blimp/core/contents/input/WebInputConfirmationPanel.java
@@ -0,0 +1,124 @@
+// 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.blimp.core.contents.input;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ProgressBar;
+import android.widget.RelativeLayout;
+
+/**
+ * A layout containing OK, Cancel buttons and a progress spinner which can be included at the bottom
+ * of a popup.
+ */
+public class WebInputConfirmationPanel extends RelativeLayout {
+ private static final String TAG = "WebInputConfirmationPanel";
+
+ // Whether or not to submit the form.
+ private boolean mSubmitForm;
David Trainor- moved to gerrit 2016/10/28 05:08:08 Do we need this here? This class shouldn't really
shaktisahu 2016/11/01 21:35:34 Removed.
+
+ /**
+ * Interface that gets notified of the user actions on this layout.
+ */
+ public interface Listener {
David Trainor- moved to gerrit 2016/10/28 05:08:08 Put this above all variables
shaktisahu 2016/11/01 21:35:34 Done.
+ /**
+ * The user has pressed OK button.
+ * @param submitForm Whether or not to submit the current form.
+ */
+ public void onConfirm(boolean submitForm);
+
+ /**
+ * The user has pressed cancel button.
+ */
+ public void onCancel();
+ }
+
+ private Listener mListener;
+
+ /**
+ * Builds a new {@link WebInputConfirmationPanel}.
+ * @param context The {@link Context} of the activity.
+ * @param attrs The {@link AttributeSet} associated with this layout.
+ */
+ public WebInputConfirmationPanel(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ inflate(context, R.layout.web_input_bottom_panel, this);
David Trainor- moved to gerrit 2016/10/28 05:08:08 If you address the class in the xml file you shoul
shaktisahu 2016/11/01 21:35:33 Somehow, the LayoutInflater is unable to inflate i
David Trainor- moved to gerrit 2016/11/03 03:07:54 Acknowledged.
+
+ intializeAnimators();
+ mSubmitForm = false;
+ }
+
+ /**
+ * Registers the listener that will be notified of changes to this panel.
+ * @param listener The listener to be notified.
+ */
+ public void setListener(Listener listener) {
+ mListener = listener;
+ }
+
+ private void intializeAnimators() {
David Trainor- moved to gerrit 2016/10/28 05:08:09 If you make the suggested comment above, put this
shaktisahu 2016/11/01 21:35:33 Changed this to onFinishInflate().
+ final Button ok = (Button) findViewById(R.id.btn_ok);
+ final Button cancel = (Button) findViewById(R.id.btn_cancel);
+ final ProgressBar spinner = (ProgressBar) findViewById(R.id.submit_spinner);
+
+ // Animation for hiding the OK/Cancel buttons and showing the spinner.
+ ObjectAnimator okAlphaAnim = ObjectAnimator.ofFloat(ok, View.ALPHA, 0.f);
+ ObjectAnimator cancelAlphaAnim = ObjectAnimator.ofFloat(cancel, View.ALPHA, 0.f);
+ ObjectAnimator spinnerAlphaAnim = ObjectAnimator.ofFloat(spinner, View.ALPHA, 0.f, 1.f);
+
+ ObjectAnimator okTranslateAnim = ObjectAnimator.ofFloat(ok, View.TRANSLATION_X, 0.f, 105.f);
David Trainor- moved to gerrit 2016/10/28 05:08:08 IIRC this is in pixels. Convert 105 -> dp? Pull
shaktisahu 2016/11/01 21:35:33 Moving this to dimens.xml file.
David Trainor- moved to gerrit 2016/11/03 03:07:54 Keeping the constants here is ok, but you just nee
+ ObjectAnimator cancelTranslateAnim =
+ ObjectAnimator.ofFloat(cancel, View.TRANSLATION_X, 0.f, 105.f);
+
+ final AnimatorSet animatorSet = new AnimatorSet();
+ animatorSet.playTogether(okAlphaAnim, cancelAlphaAnim, spinnerAlphaAnim, okTranslateAnim,
+ cancelTranslateAnim);
+ animatorSet.setDuration(250);
+
+ ok.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ animatorSet.start();
+ }
+ });
+
+ cancel.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mListener.onCancel();
David Trainor- moved to gerrit 2016/10/28 05:08:08 Check if listener is null?
shaktisahu 2016/11/01 21:35:33 Done.
+ }
+ });
+
+ animatorSet.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationStart(Animator animation) {
+ spinner.setVisibility(View.VISIBLE);
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ ok.setVisibility(View.INVISIBLE);
+ cancel.setVisibility(View.INVISIBLE);
+ mListener.onConfirm(mSubmitForm);
+ }
+ });
+ }
+
+ /**
+ * Confirms the user input by clicking on the OK button.
+ * @param submitForm Whether or not to submit the form.
+ */
+ public void confirmInput(boolean submitForm) {
+ mSubmitForm = submitForm;
David Trainor- moved to gerrit 2016/10/28 05:08:08 Can we decouple the animation from the button? Le
shaktisahu 2016/11/01 21:35:33 Done. Added a public method startAnimations() whic
+ final Button ok = (Button) findViewById(R.id.btn_ok);
+ ok.performClick();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698