下面列出了android.app.AlertDialog#getListView ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void testMultipleAccounts_noCurrentAccount() {
when(mManagedProfileUtils.hasWorkProfile(any(Context.class))).thenReturn(false);
final AccountsSettingsFragment fragment =
(AccountsSettingsFragment) getActivity().mFragment;
final AlertDialog dialog = initDialog(fragment, null).mDialog;
final ListView lv = dialog.getListView();
// The 1st account should be checked by default.
assertEquals("checked-item", 0, lv.getCheckedItemPosition());
// There should be 4 accounts in the list.
assertEquals("count", 4, lv.getCount());
// The sign-out button shouldn't exist
assertEquals(View.GONE,
dialog.getButton(DialogInterface.BUTTON_NEUTRAL).getVisibility());
assertEquals(View.VISIBLE,
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).getVisibility());
assertEquals(View.VISIBLE,
dialog.getButton(DialogInterface.BUTTON_POSITIVE).getVisibility());
}
public void testMultipleAccounts_currentAccount() {
when(mManagedProfileUtils.hasWorkProfile(any(Context.class))).thenReturn(false);
final AccountsSettingsFragment fragment =
(AccountsSettingsFragment) getActivity().mFragment;
final AlertDialog dialog = initDialog(fragment, "[email protected]").mDialog;
final ListView lv = dialog.getListView();
// The 3rd account should be checked by default.
assertEquals("checked-item", 2, lv.getCheckedItemPosition());
// There should be 4 accounts in the list.
assertEquals("count", 4, lv.getCount());
// The sign-out button should be shown
assertEquals(View.VISIBLE,
dialog.getButton(DialogInterface.BUTTON_NEUTRAL).getVisibility());
assertEquals(View.VISIBLE,
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).getVisibility());
assertEquals(View.VISIBLE,
dialog.getButton(DialogInterface.BUTTON_POSITIVE).getVisibility());
}
public void showTrackModel(final TextView textView){
RadioOnClick OnClick = new RadioOnClick(textView);
AlertDialog ad =new Builder(activity).setTitle(activity.getResources().getString(R.string.trackig_mode))
.setSingleChoiceItems(R.array.trackig_mode_array,OnClick.getIndex(),OnClick).create();
ListView areaListView=ad.getListView();
ad.show();
}
private void parcelOtherUIAction(AlertDialog dialog) {
ListView listView = dialog.getListView();
UIUtils.addMagnifier(listView);
listView.setOnItemLongClickListener((parent, view, position, id) -> {
switch (position) {
case 0:
UIUtils.addLauncherShortcut(this, R.string.reboot, android.R.drawable.ic_menu_rotate, Shortcut.REBOOT, true);
break;
case 1:
UIUtils.addLauncherShortcut(this, R.string.shutdown, android.R.drawable.ic_menu_delete, Shortcut.SHUTDOWN, true);
break;
case 2:
UIUtils.addLauncherShortcut(this, R.string.recovery_short, android.R.drawable.ic_menu_today, Shortcut.RECOVERY, true);
break;
case 3:
UIUtils.addLauncherShortcut(this, R.string.fastboot_short, android.R.drawable.ic_menu_sort_by_size, Shortcut.FASTBOOT, true);
break;
case 4:
//热重启是一种永远都不被推荐的重启方式,它造成系统不稳定的可能性很大,所以使用截图警示图标
UIUtils.addLauncherShortcut(this, R.string.hot_reboot, android.R.drawable.ic_menu_report_image, Shortcut.HOT_REBOOT, false);
break;
case 5:
UIUtils.addLauncherShortcut(this, R.string.rebootui_short, android.R.drawable.ic_menu_view, Shortcut.REBOOT_UI, false);
break;
case 6:
//用于定点清除故障应用的安全模式,使用位置图标
UIUtils.addLauncherShortcut(this, R.string.safety, android.R.drawable.ic_menu_mylocation, Shortcut.SAFEMODE, false);
break;
case 7:
UIUtils.addLauncherShortcut(this, R.string.lockscreen, android.R.drawable.ic_menu_slideshow, Shortcut.LOCKSCREEN, false);
}
new TextToast(this, true, String.format(getString(R.string.launcher_shortcut_added), uiTextList[position]));
return true;
});
}
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
AlertDialog dialog = (AlertDialog) getDialog();
ListView listView = dialog.getListView();
ListPrefWrapperAdapter fontTypeAdapter = new ListPrefWrapperAdapter(listView.getAdapter());
listView.setAdapter(fontTypeAdapter);
int selectedPosition = findIndexOfValue(getValue());
if (selectedPosition != -1) {
listView.setItemChecked(selectedPosition, true);
listView.setSelection(selectedPosition);
}
}
public void testMultipleAccounts_noSettingsForManagedProfile() {
when(mManagedProfileUtils.hasWorkProfile(any(Context.class))).thenReturn(true);
final AccountsSettingsFragment fragment =
(AccountsSettingsFragment) getActivity().mFragment;
final AlertDialog dialog = initDialog(fragment, null).mDialog;
final ListView lv = dialog.getListView();
// Nothing to check/uncheck.
assertNull(fragment.findPreference(AccountsSettingsFragment.PREF_ACCCOUNT_SWITCHER));
}