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.jefftharris.passwdsafe.sync.MainActivity.java

/** Button onClick handler to clear an ownCloud account */
@SuppressWarnings({ "UnusedParameters", "unused" })
public void onOwncloudClear(View view) {
    DialogFragment prompt = ClearPromptDlg.newInstance(itsOwncloudUri);
    prompt.show(getSupportFragmentManager(), null);
}

From source file:com.weebly.opus1269.copyeverywhere.ui.main.MainActivity.java

private void showDeleteDialog() {
    final DialogFragment dialog = new DeleteDialogFragment();
    dialog.show(getSupportFragmentManager(), "DeleteDialogFragment");
}

From source file:com.jefftharris.passwdsafe.sync.MainActivity.java

/** Button onClick handler to clear a Google Drive account */
@SuppressWarnings({ "UnusedParameters", "unused" })
public void onGdriveClear(View view) {
    DialogFragment prompt = ClearPromptDlg.newInstance(itsGDrivePlayUri);
    prompt.show(getSupportFragmentManager(), null);
}

From source file:com.grottworkshop.wizardjr.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState != null) {
        mWizardModel.load(savedInstanceState.getBundle("model"));
    }// w  w w . j ava  2  s. c o m

    mWizardModel.registerListener(this);

    mPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mStepPagerStrip = (StepPagerStrip) findViewById(R.id.strip);
    mStepPagerStrip.setOnPageSelectedListener(new StepPagerStrip.OnPageSelectedListener() {
        @Override
        public void onPageStripSelected(int position) {
            position = Math.min(mPagerAdapter.getCount() - 1, position);
            if (mPager.getCurrentItem() != position) {
                mPager.setCurrentItem(position);
            }
        }
    });

    mNextButton = (Button) findViewById(R.id.next_button);
    mPrevButton = (Button) findViewById(R.id.prev_button);

    //ViewPager.setOnPageChangeListner is depreciated
    mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            mStepPagerStrip.setCurrentPage(position);

            if (mConsumePageSelectedEvent) {
                mConsumePageSelectedEvent = false;
                return;
            }

            mEditingAfterReview = false;
            updateBottomBar();
        }
    });

    mNextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mPager.getCurrentItem() == mCurrentPageSequence.size()) {
                DialogFragment dg = new DialogFragment() {
                    @NonNull
                    @Override
                    public Dialog onCreateDialog(Bundle savedInstanceState) {
                        return new AlertDialog.Builder(getActivity())
                                .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");
            } else {
                if (mEditingAfterReview) {
                    mPager.setCurrentItem(mPagerAdapter.getCount() - 1);
                } else {
                    mPager.setCurrentItem(mPager.getCurrentItem() + 1);
                }
            }
        }
    });

    mPrevButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mPager.setCurrentItem(mPager.getCurrentItem() - 1);
        }
    });

    onPageTreeChanged();
    updateBottomBar();
}

From source file:de.grobox.liberario.DirectionsFragment.java

public void showTimePickerDialog() {
    DialogFragment newFragment = new TimePickerFragment();
    newFragment.show(getActivity().getSupportFragmentManager(), "timePicker");
}

From source file:de.grobox.liberario.DirectionsFragment.java

public void showDatePickerDialog() {
    DialogFragment newFragment = new DatePickerFragment();
    newFragment.show(getActivity().getSupportFragmentManager(), "datePicker");
}

From source file:felixwiemuth.lincal.ui.CalendarViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.calendar_view, container, false);
    TextView titleView = (TextView) rootView.findViewById(R.id.cal_title);
    TextView authorView = (TextView) rootView.findViewById(R.id.cal_author);

    notificationsEnabled = (CheckBox) rootView.findViewById(R.id.notifications_enabled);
    textViewEarliestNotificationTime = (TextView) rootView
            .findViewById(R.id.setting_earliest_notification_time);
    earliestNotificationTimeEnabled = (CheckBox) rootView
            .findViewById(R.id.setting_earliest_notification_time_enabled);
    entryDisplayModeDate = (Spinner) rootView.findViewById(R.id.setting_entry_display_mode_date);
    entryDisplayModeDescription = (Spinner) rootView.findViewById(R.id.setting_entry_display_mode_description);
    buttonRemoveCalendar = (Button) rootView.findViewById(R.id.button_remove_cal);

    if (calendar == null) {
        titleView.setText(R.string.cal_title_error_loading);
        notificationsEnabled.setEnabled(false);
        earliestNotificationTimeEnabled.setEnabled(false);
        entryDisplayModeDate.setEnabled(false);
        entryDisplayModeDescription.setEnabled(false);
    } else {/*  w  w w. jav  a  2  s. co m*/
        titleView.setText(calendar.getTitle());
        authorView.setText(calendar.getAuthor());
        entryList = (RecyclerView) rootView.findViewById(R.id.entry_list_recycler_view);
        SimpleItemRecyclerViewAdapter adapter = new SimpleItemRecyclerViewAdapter();
        entryList.setAdapter(adapter);
        ((TextView) rootView.findViewById(R.id.cal_descr)).setText(calendar.getDescription());
        ((TextView) rootView.findViewById(R.id.cal_version)).setText(calendar.getVersion());
        ((TextView) rootView.findViewById(R.id.cal_date)).setText(calendar.getDateStr());
        if (calendar.hasForceEntryDisplayModeDate()) {
            entryDisplayModeDate.setEnabled(false);
        }
        if (calendar.hasForceEntryDisplayModeDescription()) {
            entryDisplayModeDescription.setEnabled(false);
        }
    }

    ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(getContext(),
            R.array.setting_entry_display_mode_options, android.R.layout.simple_spinner_item);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    entryDisplayModeDate.setAdapter(spinnerAdapter);
    entryDisplayModeDescription.setAdapter(spinnerAdapter);

    loadSettings(); // loading settings before adding listeners prevents them from firing due to initialization (e.g. Spinner)

    if (calendar != null) {
        // Set listeners
        final View.OnClickListener saveSettingsListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveSettings();
                NotificationService.runWithCalendar(getContext(),
                        Calendars.getInstance(getContext()).getConfigByPos(calendarPos).getId()); //TODO reconsider when to call
            }
        };

        notificationsEnabled.setOnClickListener(saveSettingsListener);
        textViewEarliestNotificationTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loadSettings(); // update earliestNotificationTime
                DialogFragment dialogFragment = new TimePickerFragment();
                Bundle arguments = new Bundle();
                arguments.putInt("hour", earliestNotificationTime.getHour());
                arguments.putInt("minute", earliestNotificationTime.getMinute());
                arguments.putInt("calendarPos", calendarPos);
                dialogFragment.setArguments(arguments);
                dialogFragment.show(getFragmentManager(), "timePicker");
            }
        });
        earliestNotificationTimeEnabled.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveSettingsListener.onClick(v);
                // have to update the displayed notification times (only show when enabled)
                entryList.getAdapter().notifyDataSetChanged();
            }
        });
        //TODO implement
        //        onScreenOnEnabled = (CheckBox) rootView.findViewById(R.id.setting_show_notification_on_screen_on);
        //        onScreenOnEnabled.setOnClickListener(saveSettingsListener);
        entryDisplayModeDate.setOnItemSelectedListener(new AdapterViewOnItemSelectedListener(
                entryDisplayModeDate.getSelectedItemPosition(), saveSettingsListener));
        entryDisplayModeDescription.setOnItemSelectedListener(new AdapterViewOnItemSelectedListener(
                entryDisplayModeDescription.getSelectedItemPosition(), saveSettingsListener));
    }

    buttonRemoveCalendar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setTitle(R.string.dialog_remove_cal_title).setMessage(R.string.dialog_remove_cal_msg)
                    .setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    }).setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // First remove this fragment, so that it cannot be used anymore
                            getActivity().getSupportFragmentManager().beginTransaction()
                                    .remove(CalendarViewFragment.this).commit();
                            Calendars calendars = Calendars.getInstance(getContext());
                            calendars.removeCalendarByPos(getContext(), calendarPos);
                            // Notify calendar list that the calendar with the given position was removed and return to calendar list in case of CalendarViewActivity
                            Activity hostActivity = getActivity();
                            if (hostActivity instanceof CalendarListActivity) {
                                ((CalendarListActivity) hostActivity).notifyCalendarRemoved(calendarPos);
                            } else if (hostActivity instanceof CalendarViewActivity) {
                                Intent resultData = new Intent();
                                resultData.putExtra(CalendarListActivity.EXTRA_RESULT_CAL_REMOVED, calendarPos);
                                hostActivity.setResult(Activity.RESULT_OK, resultData);
                                hostActivity.finish();
                            } else {
                                throw new RuntimeException(
                                        "CalendarViewFragment may only be contained in either CalendarListActivity or CalendarViewActivity.");
                            }
                        }
                    });
            builder.show();
        }
    });

    return rootView;
}

From source file:com.jefftharris.passwdsafe.sync.MainActivity.java

/** Button onClick handler to edit an ownCloud account */
@SuppressWarnings({ "UnusedParameters", "unused" })
public void onOwncloudEdit(View view) {
    String url = getOwncloudProvider().getUrl().toString();
    DialogFragment dialog = OwncloudEditDialog.newInstance(url, itsOwncloudSyncFreq);
    dialog.show(getSupportFragmentManager(), null);
}

From source file:eu.trentorise.smartcampus.jp.PlanNewJourneyFragment.java

protected void setUpTimingControls() {
    Date now = new Date();
    dateEditText = (EditText) getView().findViewById(R.id.plannew_date);

    /* check if date and time are stored */
    if (fromDate == null) {
        dateEditText.setTag(now);/*from w w w.j a  v a2  s.c  o m*/
        dateEditText.setText(Config.FORMAT_DATE_UI.format(now));
    } else {
        dateEditText.setTag(fromDate);
        dateEditText.setText(Config.FORMAT_DATE_UI.format(fromDate));
    }

    dateEditText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DialogFragment f = DatePickerDialogFragment.newInstance((EditText) v);
            // f.setArguments(DatePickerDialogFragment.prepareData(f.toString()));
            f.show(getSherlockActivity().getSupportFragmentManager(), "datePicker");
        }
    });

    timeEditText = (EditText) getView().findViewById(R.id.plannew_time);
    if (fromTime == null) {
        timeEditText.setTag(now);
        timeEditText.setText(Config.FORMAT_TIME_UI.format(now));
    } else {
        timeEditText.setTag(fromTime);
        timeEditText.setText(Config.FORMAT_TIME_UI.format(fromTime));
    }
    timeEditText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DialogFragment f = TimePickerDialogFragment.newInstance((EditText) v);
            f.setArguments(TimePickerDialogFragment.prepareData(timeEditText.toString()));
            f.show(getSherlockActivity().getSupportFragmentManager(), "timePicker");

        }
    });
    fromDate = fromTime = now;
}

From source file:com.farmerbb.notepad.fragment.NoteViewFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override/* ww  w .  j  a v a 2 s .  c om*/
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Set values
    setRetainInstance(true);
    setHasOptionsMenu(true);

    // Get filename of saved note
    filename = getArguments().getString("filename");

    // Change window title
    String title;

    try {
        title = listener.loadNoteTitle(filename);
    } catch (IOException e) {
        title = getResources().getString(R.string.view_note);
    }

    getActivity().setTitle(title);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.ic_recents_logo))
                .getBitmap();

        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, bitmap,
                ContextCompat.getColor(getActivity(), R.color.primary));
        getActivity().setTaskDescription(taskDescription);
    }

    // Show the Up button in the action bar.
    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Animate elevation change
    if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large")
            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        LinearLayout noteViewEdit = getActivity().findViewById(R.id.noteViewEdit);
        LinearLayout noteList = getActivity().findViewById(R.id.noteList);

        noteList.animate().z(0f);
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            noteViewEdit.animate()
                    .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land));
        else
            noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation));
    }

    // Set up content view
    TextView noteContents = getActivity().findViewById(R.id.textView);
    markdownView = getActivity().findViewById(R.id.markdownView);

    // Apply theme
    SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences",
            Context.MODE_PRIVATE);
    ScrollView scrollView = getActivity().findViewById(R.id.scrollView);
    String theme = pref.getString("theme", "light-sans");
    int textSize = -1;
    int textColor = -1;

    String fontFamily = null;

    if (theme.contains("light")) {
        if (noteContents != null) {
            noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary));
            noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
        }

        if (markdownView != null) {
            markdownView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
            textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary);
        }

        scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
    }

    if (theme.contains("dark")) {
        if (noteContents != null) {
            noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark));
            noteContents
                    .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
        }

        if (markdownView != null) {
            markdownView
                    .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
            textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark);
        }

        scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
    }

    if (theme.contains("sans")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.SANS_SERIF);

        if (markdownView != null)
            fontFamily = "sans-serif";
    }

    if (theme.contains("serif")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.SERIF);

        if (markdownView != null)
            fontFamily = "serif";
    }

    if (theme.contains("monospace")) {
        if (noteContents != null)
            noteContents.setTypeface(Typeface.MONOSPACE);

        if (markdownView != null)
            fontFamily = "monospace";
    }

    switch (pref.getString("font_size", "normal")) {
    case "smallest":
        textSize = 12;
        break;
    case "small":
        textSize = 14;
        break;
    case "normal":
        textSize = 16;
        break;
    case "large":
        textSize = 18;
        break;
    case "largest":
        textSize = 20;
        break;
    }

    if (noteContents != null)
        noteContents.setTextSize(textSize);

    String css = "";
    if (markdownView != null) {
        String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom)
                / getResources().getDisplayMetrics().density) + "px";
        String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right)
                / getResources().getDisplayMetrics().density) + "px";
        String fontSize = " " + Integer.toString(textSize) + "px";
        String fontColor = " #" + StringUtils.remove(Integer.toHexString(textColor), "ff");
        String linkColor = " #" + StringUtils.remove(
                Integer.toHexString(new TextView(getActivity()).getLinkTextColors().getDefaultColor()), "ff");

        css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; " + "font-family:"
                + fontFamily + "; " + "font-size:" + fontSize + "; " + "color:" + fontColor + "; " + "}"
                + "a { " + "color:" + linkColor + "; " + "}";

        markdownView.getSettings().setJavaScriptEnabled(false);
        markdownView.getSettings().setLoadsImagesAutomatically(false);
        markdownView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException | FileUriExposedException e) {
                        /* Gracefully fail */ }
                else
                    try {
                        startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        /* Gracefully fail */ }

                return true;
            }
        });
    }

    // Load note contents
    try {
        contentsOnLoad = listener.loadNote(filename);
    } catch (IOException e) {
        showToast(R.string.error_loading_note);

        // Add NoteListFragment or WelcomeFragment
        Fragment fragment;
        if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal"))
            fragment = new NoteListFragment();
        else
            fragment = new WelcomeFragment();

        getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment")
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
    }

    // Set TextView contents
    if (noteContents != null)
        noteContents.setText(contentsOnLoad);

    if (markdownView != null)
        markdownView.loadMarkdown(contentsOnLoad,
                "data:text/css;base64," + Base64.encodeToString(css.getBytes(), Base64.DEFAULT));

    // Show a toast message if this is the user's first time viewing a note
    final SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
    firstLoad = sharedPref.getInt("first-load", 0);
    if (firstLoad == 0) {
        // Show dialog with info
        DialogFragment firstLoad = new FirstViewDialogFragment();
        firstLoad.show(getFragmentManager(), "firstloadfragment");

        // Set first-load preference to 1; we don't need to show the dialog anymore
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putInt("first-load", 1);
        editor.apply();
    }

    // Detect single and double-taps using GestureDetector
    final GestureDetector detector = new GestureDetector(getActivity(),
            new GestureDetector.OnGestureListener() {
                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    return false;
                }

                @Override
                public void onShowPress(MotionEvent e) {
                }

                @Override
                public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                    return false;
                }

                @Override
                public void onLongPress(MotionEvent e) {
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    return false;
                }

                @Override
                public boolean onDown(MotionEvent e) {
                    return false;
                }
            });

    detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (sharedPref.getBoolean("show_double_tap_message", true)) {
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putBoolean("show_double_tap_message", false);
                editor.apply();
            }

            Bundle bundle = new Bundle();
            bundle.putString("filename", filename);

            Fragment fragment = new NoteEditFragment();
            fragment.setArguments(bundle);

            getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment")
                    .commit();

            return false;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            return false;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (sharedPref.getBoolean("show_double_tap_message", true) && showMessage) {
                showToastLong(R.string.double_tap);
                showMessage = false;
            }

            return false;
        }

    });

    if (noteContents != null)
        noteContents.setOnTouchListener((v, event) -> {
            detector.onTouchEvent(event);
            return false;
        });

    if (markdownView != null)
        markdownView.setOnTouchListener((v, event) -> {
            detector.onTouchEvent(event);
            return false;
        });
}