diff options
author | Brandon Maxwell <maxwelb@google.com> | 2016-03-15 22:55:00 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-03-15 22:55:00 +0000 |
commit | 724ee71dbb1e7b1fcb8cd332663772c215eb7e63 (patch) | |
tree | e7bfebe94fe33d73e6585f851d44e697e31c8721 | |
parent | 24fdf0da0966a7a4108db7fc7e23f6c5a3b651a3 (diff) | |
parent | a98b35c260a8527dd7a952fe0dd3342fce06b89a (diff) |
Merge "Keeping migration dialog up while migration in progress" into nyc-dev
am: a98b35c260
* commit 'a98b35c260a8527dd7a952fe0dd3342fce06b89a':
Keeping migration dialog up while migration in progress
3 files changed, 50 insertions, 19 deletions
diff --git a/src/com/android/dialer/filterednumber/BlockedNumbersMigrator.java b/src/com/android/dialer/filterednumber/BlockedNumbersMigrator.java index de201d98a..555e647bc 100644 --- a/src/com/android/dialer/filterednumber/BlockedNumbersMigrator.java +++ b/src/com/android/dialer/filterednumber/BlockedNumbersMigrator.java @@ -22,7 +22,6 @@ import android.content.ContentResolver; import android.content.ContentValues; import android.database.Cursor; import android.os.AsyncTask; -import android.support.annotation.Nullable; import com.android.dialer.compat.BlockedNumbersSdkCompat; import com.android.dialer.compat.FilteredNumberCompat; diff --git a/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragment.java b/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragment.java index efcb50591..f29796125 100644 --- a/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragment.java +++ b/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragment.java @@ -22,10 +22,12 @@ import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; +import android.content.DialogInterface.OnShowListener; import android.os.Bundle; +import android.view.View; import com.android.dialer.R; +import com.android.dialer.filterednumber.BlockedNumbersMigrator.Listener; /** * Dialog fragment shown to users when they need to migrate to use @@ -57,20 +59,43 @@ public class MigrateBlockedNumbersDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { super.onCreateDialog(savedInstanceState); - return new AlertDialog.Builder(getActivity()) + AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.migrate_blocked_numbers_dialog_title) .setMessage(R.string.migrate_blocked_numbers_dialog_message) - .setPositiveButton(R.string.migrate_blocked_numbers_dialog_allow_button, - newPositiveButtonOnClickListener()) + .setPositiveButton(R.string.migrate_blocked_numbers_dialog_allow_button, null) .setNegativeButton(R.string.migrate_blocked_numbers_dialog_cancel_button, null) .create(); + // The Dialog's buttons aren't available until show is called, so an OnShowListener + // is used to set the positive button callback. + dialog.setOnShowListener(new OnShowListener() { + @Override + public void onShow(DialogInterface dialog) { + final AlertDialog alertDialog = (AlertDialog) dialog; + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) + .setOnClickListener(newPositiveButtonOnClickListener(alertDialog)); + } + }); + return dialog; } - private DialogInterface.OnClickListener newPositiveButtonOnClickListener() { - return new OnClickListener() { + /* + * Creates a new View.OnClickListener to be used as the positive button in this dialog. The + * OnClickListener will grey out the dialog's positive and negative buttons while the migration + * is underway, and close the dialog once the migrate is complete. + */ + private View.OnClickListener newPositiveButtonOnClickListener(final AlertDialog alertDialog) { + return new View.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { - mBlockedNumbersMigrator.migrate(mMigrationListener); + public void onClick(View v) { + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); + alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setEnabled(false); + mBlockedNumbersMigrator.migrate(new Listener() { + @Override + public void onComplete() { + alertDialog.dismiss(); + mMigrationListener.onComplete(); + } + }); } }; } diff --git a/tests/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragmentInstrumentationTest.java b/tests/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragmentInstrumentationTest.java index 16b6f3fac..0bfa6bcb2 100644 --- a/tests/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragmentInstrumentationTest.java +++ b/tests/src/com/android/dialer/filterednumber/MigrateBlockedNumbersDialogFragmentInstrumentationTest.java @@ -16,12 +16,9 @@ package com.android.dialer.filterednumber; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import android.app.AlertDialog; import android.app.DialogFragment; +import android.content.ContentResolver; import android.content.DialogInterface; import android.test.ActivityInstrumentationTestCase2; @@ -40,9 +37,8 @@ public class MigrateBlockedNumbersDialogFragmentInstrumentationTest extends private static final String SHOW_TAG = "ShowTag"; - @Mock private BlockedNumbersMigrator mBlockedNumbersMigrator; + private BlockedNumbersMigrator mBlockedNumbersMigrator; @Mock private Listener mListener; - private DialtactsActivity mActivity; private DialogFragment mMigrateDialogFragment; public MigrateBlockedNumbersDialogFragmentInstrumentationTest() { @@ -53,13 +49,14 @@ public class MigrateBlockedNumbersDialogFragmentInstrumentationTest extends public void setUp() throws Exception { super.setUp(); MockitoAnnotations.initMocks(this); - mActivity = getActivity(); + mBlockedNumbersMigrator = new SynchronousBlockedNumbersMigrator( + getActivity().getContentResolver()); mMigrateDialogFragment = MigrateBlockedNumbersDialogFragment .newInstance(mBlockedNumbersMigrator, mListener); getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { - mMigrateDialogFragment.show(mActivity.getFragmentManager(), SHOW_TAG); + mMigrateDialogFragment.show(getActivity().getFragmentManager(), SHOW_TAG); } }); getInstrumentation().waitForIdleSync(); @@ -70,7 +67,6 @@ public class MigrateBlockedNumbersDialogFragmentInstrumentationTest extends } public void testDialogPositiveButtonPress() { - when(mBlockedNumbersMigrator.migrate(mListener)).thenReturn(true); getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { @@ -81,6 +77,17 @@ public class MigrateBlockedNumbersDialogFragmentInstrumentationTest extends getInstrumentation().waitForIdleSync(); // Dialog was dismissed assertNull(mMigrateDialogFragment.getDialog()); - verify(mBlockedNumbersMigrator).migrate(mListener); + } + + private static class SynchronousBlockedNumbersMigrator extends BlockedNumbersMigrator { + public SynchronousBlockedNumbersMigrator(ContentResolver contentResolver) { + super(contentResolver); + } + + @Override + public boolean migrate(BlockedNumbersMigrator.Listener listener) { + listener.onComplete(); + return true; + } } } |