下面列出了android.widget.ExpandableListView.ExpandableListContextMenuInfo#androidx.fragment.app.DialogFragment 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void showScannerList() {
FragmentManager fm = getSupportFragmentManager();
DialogFragment fragment = (DialogFragment) fm.findFragmentByTag(SANNER_LIST_TAG);
FragmentTransaction transaction = fm.beginTransaction();
if (fragment == null) {
fragment = PDFScanManager.createScannerFragment(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
PDFScanManager.unregisterManagerListener(scanManagerListener);
ScannerListActivity.this.finish();
}
});
} else {
transaction.remove(fragment);
}
transaction.add(fragment, SANNER_LIST_TAG);
transaction.commitAllowingStateLoss();
PDFScanManager.registerManagerListener(scanManagerListener);
}
@Override
public void onDisplayPreferenceDialog(Preference preference) {
DialogFragment dialogFragment = null;
if (preference instanceof ColorPickerPreference) {
dialogFragment = ColorPickerPreferenceDialogFragmentCompat.newInstance(preference.getKey());
} else if (preference instanceof CustomDefaultPreference) {
dialogFragment = CustomDefaultPreference.CustomDefaultPreferenceDialogFragmentCompat.newInstance(preference.getKey());
}
if (dialogFragment != null) {
dialogFragment.setTargetFragment(this, 0);
dialogFragment.show(getFragmentManager(), "android.support.v7.preference.PreferenceFragment.DIALOG");
} else {
super.onDisplayPreferenceDialog(preference);
}
}
public ProgressBottomSheet<T> build() {
if (sources == null)
throw new RuntimeException("You must pass a list of observables");
if (listener == null)
Log.w(TAG, "You have not set a listener");
ProgressBottomSheet<T> bottomSheet = new ProgressBottomSheet<>();
bottomSheet.setTitle(title);
bottomSheet.setAutoDismiss(autoDismiss);
bottomSheet.setShowCancel(showCancel);
bottomSheet.setSources(sources);
bottomSheet.setListener(listener);
bottomSheet.setStyle(DialogFragment.STYLE_NORMAL, R.style.AppTheme);
return bottomSheet;
}
/**
* @return a new instance of this DialogFragment.
*/
public static DialogFragment newInstance(Provider provider, JSONObject errorJson) {
MainActivityErrorDialog dialogFragment = new MainActivityErrorDialog();
dialogFragment.provider = provider;
try {
if (errorJson.has(ERRORS)) {
dialogFragment.reasonToFail = errorJson.getString(ERRORS);
} else {
//default error msg
dialogFragment.reasonToFail = dialogFragment.getString(R.string.error_io_exception_user_message);
}
if (errorJson.has(ERRORID)) {
dialogFragment.downloadError = valueOf(errorJson.getString(ERRORID));
}
} catch (Exception e) {
e.printStackTrace();
dialogFragment.reasonToFail = dialogFragment.getString(R.string.error_io_exception_user_message);
}
return dialogFragment;
}
@SuppressWarnings("RestrictedApi")
@Override
public void onDisplayPreferenceDialog(Preference preference) {
if (preference instanceof NumberPickerPreference) {
boolean handled = false;
if (getCallbackFragment() instanceof OnPreferenceDisplayDialogCallback) {
handled = ((OnPreferenceDisplayDialogCallback) getCallbackFragment()).onPreferenceDisplayDialog(this, preference);
}
if (!handled && getActivity() instanceof OnPreferenceDisplayDialogCallback) {
handled = ((OnPreferenceDisplayDialogCallback) getActivity()).onPreferenceDisplayDialog(this, preference);
}
if (handled) {
return;
}
if (getFragmentManager().findFragmentByTag("numberpicker") != null) {
return;
}
DialogFragment f = NumberPickerPreference.NumberPickerPreferenceDialogFragmentCompat.newInstance(preference.getKey());
f.setTargetFragment(this, 0);
f.show(getFragmentManager(), "numberpicker");
} else
super.onDisplayPreferenceDialog(preference);
}
@Override
public void onStop() {
super.onStop();
String input = etConfigEditor.getText().toString();
if (input.isEmpty()) {
return;
}
if (!input.equals(savedText) && getFragmentManager() != null) {
DialogFragment dialogFragment = DialogSaveConfigChanges.newInstance();
Bundle bundle = new Bundle();
bundle.putString("moduleName", moduleName);
bundle.putString("filePath", filePath);
bundle.putString("fileText", input);
dialogFragment.setArguments(bundle);
dialogFragment.show(getFragmentManager(), "DialogSaveConfigChanges");
}
}
@Override
public void onDisplayPreferenceDialog(Preference preference) {
String TAG = "NumberPickerPreference";
FragmentManager fm = getFragmentManager();
if (fm.findFragmentByTag(TAG) != null) {
return;
}
if (preference instanceof NumberPickerPreference) {
final DialogFragment f = NumberPickerPreferenceDialog.newInstance(preference.getKey());
f.setTargetFragment(this, 0);
f.show(fm, TAG);
} else {
super.onDisplayPreferenceDialog(preference);
}
}
private void createGotoDialog() {
Bundle args = new Bundle();
args.putInt("page", mPagerAdapter.getCount());
args.putInt("floor", mReplyCount);
DialogFragment df = new GotoDialogFragment();
df.setArguments(args);
df.setTargetFragment(this, ActivityUtils.REQUEST_CODE_JUMP_PAGE);
FragmentManager fm = getActivity().getSupportFragmentManager();
Fragment prev = fm.findFragmentByTag(GOTO_TAG);
if (prev != null) {
fm.beginTransaction().remove(prev).commit();
}
df.show(fm, GOTO_TAG);
}
public static void showIconShapeChooser(@NonNull FragmentManager fm) {
FragmentTransaction ft = fm.beginTransaction();
Fragment prev = fm.findFragmentByTag(TAG);
if (prev != null) {
ft.remove(prev);
}
try {
DialogFragment dialog = IconShapeFragment.newInstance();
dialog.show(ft, TAG);
} catch (IllegalArgumentException | IllegalStateException ignored) {
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mViewManager = new GDPRViewManager(getArguments(), savedInstanceState);
mForceActivityToImplementCallback = getArguments().getBoolean(ARG_PARENT_MUST_IMPLEMENT_CALLBACK);
GDPRCustomTexts customTexts = mViewManager.getSetup().getCustomTexts();
if (customTexts.hasTitle() && customTexts.getTitle(getContext()).isEmpty()) {
setStyle(DialogFragment.STYLE_NO_TITLE, mViewManager.getSetup().customDialogTheme());
} else {
setStyle(DialogFragment.STYLE_NORMAL, mViewManager.getSetup().customDialogTheme());
}
}
public static void showIconPreview(@NonNull FragmentManager fm, @NonNull String name, int id) {
FragmentTransaction ft = fm.beginTransaction();
Fragment prev = fm.findFragmentByTag(TAG);
if (prev != null) {
ft.remove(prev);
}
try {
DialogFragment dialog = IconPreviewFragment.newInstance(name, id);
dialog.show(ft, TAG);
} catch (IllegalArgumentException | IllegalStateException ignored) {
}
}
@Override
public void showDeleteDialog() {
Bundle bundle = new Bundle();
bundle.putInt("dialog_title", R.string.dialog_delete_button_title);
DialogFragment deleteFragment = new DeleteDialogFragment();
deleteFragment.setArguments(bundle);
deleteFragment.show(getSupportFragmentManager(), "delete");
}
public static void showOtherAppsDialog(@NonNull FragmentManager fm) {
FragmentTransaction ft = fm.beginTransaction();
Fragment prev = fm.findFragmentByTag(TAG);
if (prev != null) {
ft.remove(prev);
}
try {
DialogFragment dialog = OtherAppsFragment.newInstance();
dialog.show(ft, TAG);
} catch (IllegalStateException | IllegalArgumentException ignored) {
}
}
public static void showLicensesDialog(FragmentManager fm) {
FragmentTransaction ft = fm.beginTransaction();
Fragment prev = fm.findFragmentByTag(TAG);
if (prev != null) {
ft.remove(prev);
}
try {
DialogFragment dialog = LicensesFragment.newInstance();
dialog.show(ft, TAG);
} catch (IllegalArgumentException | IllegalStateException ignored) {
}
}
@Test
public void testGetPromptParentView()
{
final DialogFragment dialogFragment = spy(new DialogFragment());
final ViewGroup parent = mock(ViewGroup.class);
final ViewGroup view = mock(ViewGroup.class);
final SupportFragmentResourceFinder resourceFinder = new SupportFragmentResourceFinder(dialogFragment);
when(dialogFragment.getView()).thenReturn(view);
when(view.getParent()).thenReturn(parent);
assertEquals(parent, resourceFinder.getPromptParentView());
assertEquals(parent, resourceFinder.getPromptParentView());
}
public static DialogFragment createForMessageRecord(@NonNull MessageRecord messageRecord) {
DialogFragment fragment = new ReactWithAnyEmojiBottomSheetDialogFragment();
Bundle args = new Bundle();
args.putLong(ARG_MESSAGE_ID, messageRecord.getId());
args.putBoolean(ARG_IS_MMS, messageRecord.isMms());
fragment.setArguments(args);
return fragment;
}
public static DialogFragment create(long messageId, boolean isMms) {
Bundle args = new Bundle();
DialogFragment fragment = new ReactionsBottomSheetDialogFragment();
args.putLong(ARGS_MESSAGE_ID, messageId);
args.putBoolean(ARGS_IS_MMS, isMms);
fragment.setArguments(args);
return fragment;
}
@NonNull
@Override
protected DialogFragment onCreateDialogFragment(String key) {
final NumberPickerPreferenceDialogFragment
fragment = new NumberPickerPreferenceDialogFragment();
final Bundle b = new Bundle(1);
b.putString(PreferenceDialogFragment.ARG_KEY, key);
fragment.setArguments(b);
return fragment;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
setStyle(DialogFragment.STYLE_NORMAL,
ThemeUtil.isDarkTheme(requireContext()) ? R.style.Theme_Signal_RecipientBottomSheet
: R.style.Theme_Signal_RecipientBottomSheet_Light);
super.onCreate(savedInstanceState);
}
@Override
public void showBackButtonDialog(String filename) {
Bundle bundle = new Bundle();
bundle.putString("filename", filename);
DialogFragment backFragment = new BackButtonDialogFragment();
backFragment.setArguments(bundle);
backFragment.show(getSupportFragmentManager(), "back");
}
@Override
public void onDestroy() {
super.onDestroy();
Fragment prev = getSupportFragmentManager().findFragmentByTag("BottomDialogFragment");
if (prev != null) {
DialogFragment df = (DialogFragment) prev;
df.dismiss();
}
}
/**
* @return a new instance of this DialogFragment.
*/
public static DialogFragment newInstance(Provider provider, String reasonToFail, EIP.EIPErrors error) {
MainActivityErrorDialog dialogFragment = new MainActivityErrorDialog();
dialogFragment.reasonToFail = reasonToFail;
dialogFragment.provider = provider;
dialogFragment.downloadError = error;
return dialogFragment;
}
@NonNull
@Override
protected DialogFragment onCreateDialogFragment(String key) {
final ListPreferenceDialogFragment
fragment = new ListPreferenceDialogFragment();
final Bundle b = new Bundle(1);
b.putString(PreferenceDialogFragment.ARG_KEY, key);
fragment.setArguments(b);
return fragment;
}
public static void showDialog(FragmentManager manager, DialogFragment fragment) {
FragmentTransaction ft = manager.beginTransaction();
Fragment prev = manager.findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
fragment.show(ft, "dialog");
}
public static void showDialog(FragmentManager manager, DialogFragment fragment) {
FragmentTransaction ft = manager.beginTransaction();
Fragment prev = manager.findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
fragment.show(ft, "dialog");
}
@NonNull
@Override
protected DialogFragment onCreateDialogFragment(String key) {
final EditTextPreferenceDialogFragment
fragment = new EditTextPreferenceDialogFragment();
final Bundle b = new Bundle(1);
b.putString(PreferenceDialogFragment.ARG_KEY, key);
fragment.setArguments(b);
return fragment;
}
public Window getCurrentWindow() {
DialogFragment dialogFragment = getDialogFragment();
if (dialogFragment != null && dialogFragment.isAdded()) {
return dialogFragment.getDialog().getWindow();
} else {
return getWindow();
}
}
@NonNull
private DialogFragmentDestination getDestination(@NonNull DialogFragment dialogFragment) {
Class<? extends Screen> screenClass = mNavigationFactory.getScreenClass(dialogFragment);
if (screenClass == null) {
throw new IllegalArgumentException("Failed to get screen class from " + dialogFragment.getClass().getSimpleName());
}
Destination destination = mNavigationFactory.getDestination(screenClass);
if (!(destination instanceof DialogFragmentDestination)) {
throw new IllegalArgumentException("Failed to get destination from " + dialogFragment.getClass().getSimpleName());
}
return (DialogFragmentDestination) destination;
}
@NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
if (this.getActivity() != null && shouldUseDefaultDialogStyle()) {
setStyle(DialogFragment.STYLE_NO_TITLE,
themeManager.getAttributeForTheme(getDialogStyle()).resourceId);
}
return super.onCreateDialog(savedInstanceState);
}
@Test
public void testGetDrawable()
{
final int resourceId = 64532;
final DialogFragment dialogFragment = spy(new DialogFragment());
final SupportFragmentResourceFinder resourceFinder = new SupportFragmentResourceFinder(dialogFragment);
final Drawable resource = mock(Drawable.class);
final Resources resources = mock(Resources.class);
final Context context = mock(Context.class);
when(dialogFragment.getContext()).thenReturn(context);
when(dialogFragment.getResources()).thenReturn(resources);
when(resources.getDrawable(resourceId)).thenReturn(resource);
assertEquals(resource, resourceFinder.getDrawable(resourceId));
}