Merge "Add Confirmation Dialog" into main

This commit is contained in:
Daniel Huang
2025-03-05 05:51:36 -08:00
committed by Android (Google) Code Review
5 changed files with 145 additions and 32 deletions

View File

@@ -36,7 +36,6 @@ import android.app.Activity;
import android.app.Dialog;
import android.app.IActivityManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -100,6 +99,8 @@ public class LocaleListEditorTest {
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
private static final String ARG_DIALOG_TYPE = "arg_dialog_type";
private static final String
ARG_SHOW_DIALOG_FOR_NOT_TRANSLATED = "arg_show_dialog_for_not_translated";
private static final String TAG_DIALOG_CONFIRM_SYSTEM_DEFAULT = "dialog_confirm_system_default";
private static final String TAG_DIALOG_NOT_AVAILABLE = "dialog_not_available_locale";
private static final String TAG_DIALOG_ADD_SYSTEM_LOCALE = "dialog_add_system_locale";
@@ -123,6 +124,10 @@ public class LocaleListEditorTest {
@Mock
private LocaleStore.LocaleInfo mLocaleInfo;
@Mock
private LocaleStore.LocaleInfo mLocaleInfo1;
@Mock
private LocaleStore.LocaleInfo mLocaleInfo2;
@Mock
private FragmentManager mFragmentManager;
@Mock
private FragmentTransaction mFragmentTransaction;
@@ -270,7 +275,7 @@ public class LocaleListEditorTest {
public void showConfirmDialog_systemLocaleSelected_shouldShowLocaleChangeDialog()
throws Exception {
//pre-condition
setUpLocaleConditions();
setUpLocaleConditions(true);
final Configuration config = new Configuration();
config.setLocales((LocaleList.forLanguageTags("zh-TW,en-US")));
when(mActivityService.getConfiguration()).thenReturn(config);
@@ -299,6 +304,41 @@ public class LocaleListEditorTest {
eq(TAG_DIALOG_CONFIRM_SYSTEM_DEFAULT));
}
@Test
public void showConfirmDialog_2ndLocaleSelected_shouldShowLocaleChangeDialog()
throws Exception {
//pre-condition
Locale.setDefault(Locale.forLanguageTag("en-US"));
setUpLocaleConditions2();
final Configuration config = new Configuration();
config.setLocales((LocaleList.forLanguageTags("blo-BJ,en-US,zh-TW")));
when(mActivityService.getConfiguration()).thenReturn(config);
when(mAdapter.getFeedItemList()).thenReturn(mLocaleList);
when(mAdapter.getCheckedCount()).thenReturn(1);
when(mAdapter.getItemCount()).thenReturn(3);
when(mAdapter.isFirstLocaleChecked()).thenReturn(false);
ReflectionHelpers.setField(mLocaleListEditor, "mRemoveMode", true);
ReflectionHelpers.setField(mLocaleListEditor, "mShowingRemoveDialog", true);
//launch the first dialog
mLocaleListEditor.showRemoveLocaleWarningDialog();
final Dialog dialog = ShadowDialog.getLatestDialog();
assertThat(dialog).isNotNull();
// click the remove button
dialog.findViewById(R.id.button_ok).performClick();
ShadowLooper.idleMainLooper();
assertThat(dialog.isShowing()).isFalse();
// check the second dialog is showing
verify(mFragmentTransaction).add(any(LocaleDialogFragment.class),
eq(TAG_DIALOG_CONFIRM_SYSTEM_DEFAULT));
}
@Test
public void mayAppendUnicodeTags_appendUnicodeTags_success() {
LocaleStore.LocaleInfo localeInfo = LocaleStore.fromLocale(Locale.forLanguageTag("en-US"));
@@ -315,7 +355,8 @@ public class LocaleListEditorTest {
Bundle bundle = new Bundle();
bundle.putInt(ARG_DIALOG_TYPE, DIALOG_CONFIRM_SYSTEM_DEFAULT);
mIntent.putExtras(bundle);
setUpLocaleConditions();
mIntent.putExtra(ARG_SHOW_DIALOG_FOR_NOT_TRANSLATED, true);
setUpLocaleConditions(false);
mLocaleListEditor.onActivityResult(REQUEST_CONFIRM_SYSTEM_DEFAULT, Activity.RESULT_OK,
mIntent);
@@ -328,7 +369,7 @@ public class LocaleListEditorTest {
Bundle bundle = new Bundle();
bundle.putInt(ARG_DIALOG_TYPE, DIALOG_CONFIRM_SYSTEM_DEFAULT);
mIntent.putExtras(bundle);
setUpLocaleConditions();
setUpLocaleConditions(true);
mLocaleListEditor.onActivityResult(REQUEST_CONFIRM_SYSTEM_DEFAULT, Activity.RESULT_CANCELED,
mIntent);
@@ -338,7 +379,7 @@ public class LocaleListEditorTest {
@Test
public void onTouch_dragDifferentLocaleToTop_showConfirmDialog() throws Exception {
MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_UP, 0.0f, 0.0f, 0);
setUpLocaleConditions();
setUpLocaleConditions(true);
final Configuration config = new Configuration();
config.setLocales((LocaleList.forLanguageTags("zh-TW,en-US")));
when(mActivityService.getConfiguration()).thenReturn(config);
@@ -352,7 +393,7 @@ public class LocaleListEditorTest {
@Test
public void onTouch_dragSameLocaleToTop_updateAdapter() throws Exception {
MotionEvent event = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_UP, 0.0f, 0.0f, 0);
setUpLocaleConditions();
setUpLocaleConditions(true);
final Configuration config = new Configuration();
config.setLocales((LocaleList.forLanguageTags("en-US,zh-TW")));
when(mActivityService.getConfiguration()).thenReturn(config);
@@ -490,12 +531,26 @@ public class LocaleListEditorTest {
verify(mAdapter).setCheckBoxDescription(any(LocaleDragCell.class), any(), anyBoolean());
}
private void setUpLocaleConditions() {
private void setUpLocaleConditions(boolean isTranslated) {
ShadowActivityManager.setService(mActivityService);
mLocaleList = new ArrayList<>();
mLocaleList.add(mLocaleInfo);
when(mLocaleInfo.getFullNameNative()).thenReturn("English");
when(mLocaleInfo.getLocale()).thenReturn(LocaleList.forLanguageTags("en-US").get(0));
when(mLocaleInfo.isTranslated()).thenReturn(isTranslated);
when(mAdapter.getFeedItemList()).thenReturn(mLocaleList);
}
private void setUpLocaleConditions2() {
ShadowActivityManager.setService(mActivityService);
mLocaleList = new ArrayList<>();
mLocaleList.add(mLocaleInfo);
mLocaleList.add(mLocaleInfo1);
mLocaleList.add(mLocaleInfo2);
when(mLocaleInfo.getLocale()).thenReturn(Locale.forLanguageTag("blo-BJ"));
when(mLocaleInfo.isTranslated()).thenReturn(false);
when(mLocaleInfo2.getLocale()).thenReturn(Locale.forLanguageTag("zh-TW"));
when(mLocaleInfo2.isTranslated()).thenReturn(true);
when(mAdapter.getFeedItemList()).thenReturn(mLocaleList);
}
}