From 931d2d25caace670b16fb83bac6721993f466489 Mon Sep 17 00:00:00 2001 From: Michael Kwan Date: Wed, 12 Oct 2016 18:40:49 -0700 Subject: Fix issue where dialog buttons were not functional if the ID changed. Bug: 31779188 Change-Id: Ifb42b6505fcd8a1928d31c6a20620b24450e420f --- .../support/wearable/view/AcceptDenyDialog.java | 34 +++++++++------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'src/android') diff --git a/src/android/support/wearable/view/AcceptDenyDialog.java b/src/android/support/wearable/view/AcceptDenyDialog.java index 8ccccd5d..8961ee71 100644 --- a/src/android/support/wearable/view/AcceptDenyDialog.java +++ b/src/android/support/wearable/view/AcceptDenyDialog.java @@ -37,7 +37,7 @@ import com.android.packageinstaller.R; * no click listener attached by default, the buttons are hidden be default. */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) -public class AcceptDenyDialog extends Dialog implements View.OnClickListener { +public class AcceptDenyDialog extends Dialog { /** Icon at the top of the dialog. */ protected ImageView mIcon; /** Title at the top of the dialog. */ @@ -63,6 +63,16 @@ public class AcceptDenyDialog extends Dialog implements View.OnClickListener { /** Spacer between the positive and negative button. Hidden if one button is hidden. */ protected View mSpacer; + private final View.OnClickListener mButtonHandler = (v) -> { + if (v == mPositiveButton && mPositiveButtonListener != null) { + mPositiveButtonListener.onClick(this, DialogInterface.BUTTON_POSITIVE); + dismiss(); + } else if (v == mNegativeButton && mNegativeButtonListener != null) { + mNegativeButtonListener.onClick(this, DialogInterface.BUTTON_NEGATIVE); + dismiss(); + } + }; + public AcceptDenyDialog(Context context) { this(context, 0 /* use default context theme */); } @@ -76,31 +86,13 @@ public class AcceptDenyDialog extends Dialog implements View.OnClickListener { mMessage = (TextView) findViewById(android.R.id.message); mIcon = (ImageView) findViewById(android.R.id.icon); mPositiveButton = (ImageButton) findViewById(android.R.id.button1); - mPositiveButton.setOnClickListener(this); + mPositiveButton.setOnClickListener(mButtonHandler); mNegativeButton = (ImageButton) findViewById(android.R.id.button2); - mNegativeButton.setOnClickListener(this); + mNegativeButton.setOnClickListener(mButtonHandler); mSpacer = (Space) findViewById(R.id.spacer); mButtonPanel = findViewById(R.id.buttonPanel); } - @Override - public void onClick(View v) { - switch (v.getId()) { - case android.R.id.button1: - if (mPositiveButtonListener != null) { - mPositiveButtonListener.onClick(this, DialogInterface.BUTTON_POSITIVE); - } - dismiss(); - break; - case android.R.id.button2: - if (mNegativeButtonListener != null) { - mNegativeButtonListener.onClick(this, DialogInterface.BUTTON_NEGATIVE); - } - dismiss(); - break; - } - } - public ImageButton getButton(int whichButton) { switch (whichButton) { case DialogInterface.BUTTON_POSITIVE: -- cgit v1.2.3