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

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

Introduction

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

Prototype

public int show(FragmentTransaction transaction, String tag) 

Source Link

Document

Display the dialog, adding the fragment using an existing transaction and then committing the transaction.

Usage

From source file:com.pixplicity.wizardpager.sample.MainActivity.java

@Override
public void onSubmit() {
    DialogFragment dg = new DialogFragment() {

        @Override//from  w  w  w .  ja  va2s .  c o m
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            return new AlertDialog.Builder(getActivity()).setTitle(R.string.submit_confirm_title)
                    .setMessage(R.string.submit_confirm_message)
                    .setPositiveButton(R.string.submit_confirm_button, null)
                    .setNegativeButton(android.R.string.cancel, null).create();
        }
    };
    dg.show(getSupportFragmentManager(), "place_order_dialog");
}

From source file:com.ultrafunk.network_info.config.ConfigActivity.java

private void initMobileSettingsScreenView() {
    LinearLayout mobileSettingsScreenLinearLayout = (LinearLayout) findViewById(
            R.id.mobileSettingsScreenLinearLayout);
    onDialogSelectionChanged(widgetConfig.getMobileDataSettingsScreen());

    mobileSettingsScreenLinearLayout.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w  ww  . jav  a  2s. c  om*/
        public void onClick(View view) {
            DialogFragment dialogFragment = new SettingsScreenDialogFragment();

            Bundle bundle = new Bundle();
            bundle.putInt(Constants.PREF_MOBILE_DATA_SETTINGS_SCREEN,
                    widgetConfig.getMobileDataSettingsScreen());
            dialogFragment.setArguments(bundle);
            dialogFragment.show(getSupportFragmentManager(), "SettingsScreenDialogFragment");
        }
    });
}

From source file:de.skubware.opentraining.activity.create_workout.ExerciseTypeDetailFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.exercise_detail_menu, menu);

    // configure menu_item_add_exercise
    MenuItem menu_item_add_exercise = (MenuItem) menu.findItem(R.id.menu_item_add_exercise);
    menu_item_add_exercise.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {

            // assert, that an exercise was choosen
            if (mExercise == null) {
                Log.wtf(TAG, "No exercise has been choosen. This should not happen");
                return true;
            }/*  w ww . j  a v  a2 s  . c om*/

            // add exercise to workout or create a new one
            if (mWorkout == null) {
                SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity());
                String defaultWorkoutName = settings.getString("default_workout_name", "Workout");

                mWorkout = new Workout(defaultWorkoutName, new FitnessExercise(mExercise));
            } else {

                // assert that there is not already such an exercise in the
                // workout
                for (FitnessExercise fEx : mWorkout.getFitnessExercises()) {
                    if (fEx.getExType().equals(mExercise)) {
                        Toast.makeText(getActivity(), getString(R.string.exercise_already_in_workout),
                                Toast.LENGTH_LONG).show();
                        return true;
                    }
                }

                mWorkout.addFitnessExercise(new FitnessExercise(mExercise));
            }

            // update Workout in Activity
            if (getActivity() instanceof Callbacks) {
                // was launched by ExerciseTypeListActivity
                ((Callbacks) getActivity()).onWorkoutChanged(mWorkout);
            } else {
                // was launched by ExerciseTypeDetailActivity
                Intent i = new Intent();
                i.putExtra(ExerciseTypeListActivity.ARG_WORKOUT, mWorkout);
                getActivity().setResult(Activity.RESULT_OK, i);
                getActivity().finish();
            }

            Toast.makeText(getActivity(), getString(R.string.exercise) + " " + mExercise.getLocalizedName()
                    + " " + getString(R.string.has_been_added), Toast.LENGTH_SHORT).show();

            return true;
        }
    });

    // configure menu_item_license_info
    MenuItem menu_item_license_info = (MenuItem) menu.findItem(R.id.menu_item_license_info);
    menu_item_license_info.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(getString(R.string.license_info));

            String license = "";

            if (mExercise.getImageLicenseMap().values().iterator().hasNext()) {
                license = mExercise.getImageLicenseMap().values().iterator().next().toString();
            } else {
                license = getString(R.string.no_license_available);
            }

            builder.setMessage(license);
            builder.create().show();

            return true;
        }
    });

    // configure menu_item_description
    MenuItem menu_item_description = (MenuItem) menu.findItem(R.id.menu_item_description);
    menu_item_description.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            if (mExercise.getDescription() == null || mExercise.getDescription().equals("")) {
                Toast.makeText(getActivity(), getString(R.string.no_description_available), Toast.LENGTH_LONG)
                        .show();
                return true;
            }

            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(getString(R.string.description));

            builder.setMessage(Html.fromHtml(mExercise.getDescription()));
            builder.create().show();

            return true;
        }
    });

    // configure menu_item_delete_exercise
    if (mExercise != null && mExercise.getExerciseSource() == ExerciseSource.CUSTOM) {
        MenuItem menu_item_delete_exercise = (MenuItem) menu.findItem(R.id.menu_item_delete_exercise);
        menu_item_delete_exercise.setVisible(true);
        menu_item_delete_exercise.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                IDataProvider dataProvider = new DataProvider(getActivity());
                dataProvider.deleteCustomExercise(mExercise);

                if (getActivity() instanceof Callbacks) {
                    // was launched by ExerciseTypeListActivity
                    ((Callbacks) getActivity()).onExerciseDeleted(mExercise);
                } else {
                    // was launched by ExerciseTypeDetailActivity
                    Intent i = new Intent();
                    i.putExtra(ARG_DELETED_EXERCISE, mExercise);
                    getActivity().setResult(RESULT_EXERCISE_CHANGED, i);
                    getActivity().finish();
                }

                return false;
            }
        });
    }

    // configure menu_item_upload_exercise
    MenuItem menu_item_upload_exercise = (MenuItem) menu.findItem(R.id.menu_item_upload_exercise);
    menu_item_upload_exercise.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            Context context = ExerciseTypeDetailFragment.this.getActivity();

            //UploadExerciseAsyncTask exUpload = new UploadExerciseAsyncTask(context);
            //exUpload.execute(mExercise);

            UploadExerciseImagesAsyncTask exImageUpload = new UploadExerciseImagesAsyncTask(context);
            exImageUpload.execute(mExercise);

            return true;
        }
    });

    // configure menu_item_send_exercise_feedback
    MenuItem menu_item_delete_exercise = (MenuItem) menu.findItem(R.id.menu_item_send_exercise_feedback);
    menu_item_delete_exercise.setVisible(true);
    menu_item_delete_exercise.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {

            FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
            Fragment prev = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
            if (prev != null) {
                ft.remove(prev);
            }
            ft.addToBackStack(null);

            // Create and show the dialog.
            DialogFragment newFragment = SendExerciseFeedbackDialogFragment.newInstance(mExercise);
            newFragment.show(ft, "dialog");

            return false;
        }
    });

}

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());/*from ww w.j  ava 2  s. c om*/
    }
}

From source file:com.joeyturczak.jtscanner.ui.AdvancedSettingsFragment.java

@Override
public void onDisplayPreferenceDialog(Preference preference) {
    DialogFragment dialogFragment = null;
    if (preference instanceof NumberPickerPreference) {
        dialogFragment = new NumberPickerPreferenceFragment();
        Bundle bundle = new Bundle();
        bundle.putString("key", preference.getKey());
        dialogFragment.setArguments(bundle);
    }/*from w w  w  .  j av a  2 s  .  c o m*/

    if (dialogFragment != null) {
        dialogFragment.setTargetFragment(this, 0);
        dialogFragment.show(this.getFragmentManager(), NUMBER_PICKER_TAG);
    } else {
        super.onDisplayPreferenceDialog(preference);
    }
}

From source file:com.m2dl.mini_projet.mini_projet_android.MainActivity.java

private void selectTags() {
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
    if (prev != null) {
        ft.remove(prev);//from   w  w  w  . j  a v a 2s  . c  o m
    }
    ft.addToBackStack(null);
    DialogFragment newFragment = TagSelectDialogFragment.newInstance(new ArrayList<>(allTags),
            new ArrayList<>(selectedTags));
    newFragment.show(ft, "dialog");
}

From source file:com.notepadlite.NoteListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.action_settings:
        Intent intentSettings = new Intent(getActivity(), SettingsActivity.class);
        startActivity(intentSettings);//from  w w  w.ja  va  2  s .  co  m
        return true;
    case R.id.action_import:
        try {
            getActivity().getExternalFilesDir(null);
            Intent intent = new Intent(getActivity(), ImportActivity.class);
            startActivity(intent);
        } catch (NullPointerException e) {
            // Throws a NullPointerException if no external storage is present
            showToastLong(R.string.no_external_storage);
        }
        return true;
    case R.id.action_about:
        DialogFragment aboutFragment = new AboutDialogFragment();
        aboutFragment.show(getFragmentManager(), "about");
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.ess.tudarmstadt.de.sleepsense.usersdata.UsersDataFragment.java

private void addEntryRow() {
    idToUpdate = -1;//from w  w w .  j av a 2 s . c  o m
    FragmentManager fm = this.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("datePicker");
    if (prev != null) {
        ft.remove(prev);
    }

    DialogFragment newFragment = new DatePickerFragment();
    newFragment.show(fm, "datePicker");

}

From source file:mobi.daytoday.DayToDay.BetweenDatesFragment.java

private void showDatePickerDialogWith(String date) {
    FragmentTransaction ft = getFragmentManager().beginTransaction();

    Fragment prev = getFragmentManager().findFragmentByTag(DatePickerDialogFragment.DATE_PICKER_ID);
    if (prev != null) {
        ft.remove(prev);/*from  w  w  w  .  ja v a 2s. c  o  m*/
        firstActive = secondActive = false;
    }
    ft.addToBackStack(null);

    DialogFragment frag = new DatePickerDialogFragment();
    ((DatePickerDialogFragment) frag).setCallbackFragment((Fragment) BetweenDatesFragment.this);
    Bundle args = new Bundle();
    args.putString(DateWrap.CUR_DATE, date);
    frag.setArguments(args);
    frag.show(ft, DatePickerDialogFragment.DATE_PICKER_ID);
}

From source file:com.anjalimacwan.fragment.NoteListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    /*case R.id.action_settings:
        Intent intentSettings = new Intent(getActivity(), SettingsActivity.class);
        startActivity(intentSettings);//w  ww  . j  a  v a  2  s .  c  o m
        return true;
    case R.id.action_import:
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"text/plain", "text/html", "text/x-markdown"});
        intent.setType("*//*");
                                   
                           try {
                           getActivity().startActivityForResult(intent, MainActivity.IMPORT);
                           } catch (ActivityNotFoundException e) {
                           showToast(R.string.error_importing_notes);
                           }
                           return true;*/
    case R.id.action_about:
        DialogFragment aboutFragment = new AboutDialogFragment();
        aboutFragment.show(getFragmentManager(), "about");
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}