Example usage for android.support.v4.app DialogFragment getDialog

List of usage examples for android.support.v4.app DialogFragment getDialog

Introduction

In this page you can find the example usage for android.support.v4.app DialogFragment getDialog.

Prototype

public Dialog getDialog() 

Source Link

Usage

From source file:com.akhbulatov.wordkeeper.ui.fragment.CategoryListFragment.java

private void showCategoryEditorDialog(int titleId, int positiveTextId, int negativeTextId) {
    DialogFragment dialog = CategoryEditorDialog.newInstance(titleId, positiveTextId, negativeTextId);
    dialog.setTargetFragment(CategoryListFragment.this, CATEGORY_EDITOR_DIALOG_REQUEST);
    dialog.show(getActivity().getSupportFragmentManager(), null);

    // Receives and shows data of the selected category to edit in the dialog
    // Data is the name of the category
    if (positiveTextId == R.string.category_editor_action_rename) {
        // NOTE! If the method is not called, the app crashes
        getActivity().getSupportFragmentManager().executePendingTransactions();

        Dialog dialogView = dialog.getDialog();
        EditText editName = dialogView.findViewById(R.id.edit_category_name);
        editName.setText(getName());//  w w  w  .  ja v  a2s.c om
    }
}

From source file:net.zionsoft.obadiah.ui.fragments.TranslationListFragment.java

private void downloadTranslation(final TranslationInfo translationInfo) {
    final FragmentManager fm = getChildFragmentManager();
    ProgressDialogFragment.newInstance(R.string.progress_dialog_translation_downloading, 100).show(fm,
            TAG_DOWNLOAD_DIALOG_FRAGMENT);
    fm.executePendingTransactions();/*w  ww  . ja v  a 2s . c  o m*/

    mBible.downloadTranslation(translationInfo, new Bible.OnTranslationDownloadListener() {
        @Override
        public void onTranslationDownloaded(String translation, boolean isSuccessful) {
            if (!isAdded())
                return;

            final DialogFragment dialogFragment = (DialogFragment) getChildFragmentManager()
                    .findFragmentByTag(TAG_DOWNLOAD_DIALOG_FRAGMENT);
            if (dialogFragment != null) {
                dialogFragment.dismissAllowingStateLoss();
            }

            if (isSuccessful) {
                Toast.makeText(getActivity(), R.string.toast_translation_downloaded, Toast.LENGTH_SHORT).show();
                if (mCurrentTranslation == null) {
                    Analytics.trackTranslationSelection(translation);

                    mCurrentTranslation = translation;
                    mPreferences.edit().putString(Constants.PREF_KEY_LAST_READ_TRANSLATION, mCurrentTranslation)
                            .apply();
                }
                loadTranslations(false);
            } else {
                DialogHelper.showDialog(getActivity(), true, R.string.dialog_retry_network,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                downloadTranslation(translationInfo);
                            }
                        }, null);
            }
        }

        @Override
        public void onTranslationDownloadProgress(String translation, int progress) {
            if (!isAdded())
                return;

            final DialogFragment dialogFragment = (DialogFragment) getChildFragmentManager()
                    .findFragmentByTag(TAG_DOWNLOAD_DIALOG_FRAGMENT);
            if (dialogFragment != null) {
                ((ProgressDialog) dialogFragment.getDialog()).setProgress(progress);
            }
        }
    });
}