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.youku.player.base.YoukuBasePlayerActivity.java

public void showDialog() {
    DialogFragment newFragment = PasswordInputDialog
            .newInstance(R.string.player_error_dialog_password_required);
    newFragment.show(getSupportFragmentManager(), "dialog");
}

From source file:com.dwdesign.tweetings.util.Utils.java

public static void openImage(final Context context, final Uri uri, final boolean is_possibly_sensitive) {
    if (context == null || uri == null)
        return;// w  w  w.  ja va2  s. c  o  m
    final Intent intent = new Intent(INTENT_ACTION_VIEW_IMAGE);
    intent.setDataAndType(uri, "image/*");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
        intent.setClass(context, ImageViewerGLActivity.class);
    } else {
        intent.setClass(context, ImageViewerActivity.class);
    }
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    if (context instanceof FragmentActivity && is_possibly_sensitive
            && !prefs.getBoolean(PREFERENCE_KEY_DISPLAY_SENSITIVE_CONTENTS, false)) {
        final FragmentActivity activity = (FragmentActivity) context;
        final FragmentManager fm = activity.getSupportFragmentManager();
        final DialogFragment fragment = new SensitiveContentWarningDialogFragment();
        final Bundle args = new Bundle();
        args.putParcelable(INTENT_KEY_URI, uri);
        fragment.setArguments(args);
        fragment.show(fm, "sensitive_content_warning");
    } else {
        context.startActivity(intent);
    }
}

From source file:com.djkim.slap.group.EditGroupActivity.java

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

    group = (Group) getIntent().getExtras().getSerializable(EDIT_GROUP_EXTRA);
    mWizardModel = createWizardModel(group);

    FacebookSdk.sdkInitialize(this.getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    createAppGroupDialog = new CreateAppGroupDialog(this);
    createAppGroupDialog.registerCallback(callbackManager, new FacebookCallback<CreateAppGroupDialog.Result>() {
        public void onSuccess(CreateAppGroupDialog.Result result) {
            String id = result.getId();
            group.set_facebookGroupId(id);
            group.saveInBackground(new GroupCallback() {
                @Override/*from  w  w  w. j a v  a2  s . c  om*/
                public void done() {
                    Toast.makeText(EditGroupActivity.this, "Successfully created the group!",
                            Toast.LENGTH_SHORT).show();

                    Intent intent = new Intent();
                    intent.putExtra(EDIT_GROUP_EXTRA, group);
                    setResult(RESULT_OK, intent);
                    finish();
                }
            });
        }

        public void onCancel() {
            group.saveInBackground(new GroupCallback() {
                @Override
                public void done() {
                    Toast.makeText(EditGroupActivity.this, "Failed to create the group!", Toast.LENGTH_SHORT)
                            .show();

                    Intent intent = new Intent();
                    intent.putExtra(EDIT_GROUP_EXTRA, group);
                    setResult(RESULT_OK, intent);
                    finish();
                }
            });
        }

        public void onError(FacebookException error) {
        }
    });

    if (savedInstanceState != null) {
        mWizardModel.load(savedInstanceState.getBundle("model"));
    }

    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);
    mPager.setOnPageChangeListener(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() {
                    @Override
                    public Dialog onCreateDialog(Bundle savedInstanceState) {
                        return new AlertDialog.Builder(getActivity())
                                .setMessage(R.string.submit_confirm_message)
                                .setPositiveButton(R.string.submit_confirm_button,
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                createGroup();
                                                if (group.get_facebookGroupId() == null) {
                                                    onClickCreateButton();
                                                } else {
                                                    group.saveInBackground(new GroupCallback() {
                                                        @Override
                                                        public void done() {
                                                            Intent intent = new Intent();
                                                            intent.putExtra(EDIT_GROUP_EXTRA, group);
                                                            setResult(RESULT_OK, intent);
                                                            finish();
                                                        }
                                                    });
                                                }
                                            }
                                        })
                                .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) {
            if (mPager.getCurrentItem() == 0) {
                setResult(RESULT_CANCELED);
                finish();
            } else {
                mPager.setCurrentItem(mPager.getCurrentItem() - 1);
            }
        }
    });

    onPageTreeChanged();
    updateBottomBar();
}

From source file:com.davidmascharka.lips.TrackerActivity.java

/**
 * Let the user pick what partitioning scheme they want to use
 *//*  ww w  .j  a va 2s.c o  m*/
private void showSelectPartitionDialog() {
    DialogFragment dialog = new SelectPartitionDialogFragment();
    dialog.show(getSupportFragmentManager(), "SelectPartitionDialogFragment");
}

From source file:com.ichi2.anki.CardBrowser.java

private DialogFragment showDialogFragment(int id) {
    DialogFragment dialogFragment = null;
    String tag = null;//  ww  w  .  j  a v  a  2 s.com
    switch (id) {
    case DIALOG_TAGS:
        TagsDialog dialog = com.ichi2.anki.dialogs.TagsDialog.newInstance(TagsDialog.TYPE_FILTER_BY_TAG,
                new ArrayList<String>(), new ArrayList<String>(getCol().getTags().all()));
        dialog.setTagsDialogListener(new TagsDialogListener() {
            @Override
            public void onPositive(List<String> selectedTags, int option) {
                mSearchView.setQuery("", false);
                String tags = selectedTags.toString();
                mSearchView.setQueryHint(getResources().getString(R.string.card_browser_tags_shown,
                        tags.substring(1, tags.length() - 1)));
                StringBuilder sb = new StringBuilder();
                switch (option) {
                case 1:
                    sb.append("is:new ");
                    break;
                case 2:
                    sb.append("is:due ");
                    break;
                default:
                    // Logging here might be appropriate : )
                    break;
                }
                int i = 0;
                for (String tag : selectedTags) {
                    if (i != 0) {
                        sb.append("or ");
                    } else {
                        sb.append("("); // Only if we really have selected tags
                    }
                    sb.append("tag:").append(tag).append(" ");
                    i++;
                }
                if (i > 0) {
                    sb.append(")"); // Only if we added anything to the tag list
                }
                mSearchTerms = sb.toString();
                searchCards();
            }
        });
        dialogFragment = dialog;
        break;
    default:
        break;
    }

    dialogFragment.show(getSupportFragmentManager(), tag);
    return dialogFragment;
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void openImage(final Context context, final long accountId, final String uri,
        final boolean isPossiblySensitive) {
    if (context == null || uri == null)
        return;//from  w w  w . j av a  2  s  .co  m
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    if (context instanceof FragmentActivity && isPossiblySensitive
            && !prefs.getBoolean(KEY_DISPLAY_SENSITIVE_CONTENTS, false)) {
        final FragmentActivity activity = (FragmentActivity) context;
        final FragmentManager fm = activity.getSupportFragmentManager();
        final DialogFragment fragment = new SensitiveContentWarningDialogFragment();
        final Bundle args = new Bundle();
        args.putLong(EXTRA_ACCOUNT_ID, accountId);
        args.putParcelable(EXTRA_URI, Uri.parse(uri));
        fragment.setArguments(args);
        fragment.show(fm, "sensitive_content_warning");
    } else {
        openImageDirectly(context, accountId, uri);
    }
}

From source file:de.escoand.readdaily.MainActivity.java

@Override
public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
    DialogFragment dialog = null;
    Intent intent = null;/*from   ww  w .  j  ava2s  . c o m*/

    layout.closeDrawers();

    switch (item.getItemId()) {

    // today
    case R.id.button_today:
        handler.onDateSelected(new Date());
        break;

    // list dialogs
    case R.id.button_list:
        dialog = new ListDialogFragment();
        ((ListDialogFragment) dialog).setFilter(
                Database.COLUMN_TYPE + "=? AND " + Database.COLUMN_SOURCE + "!=''",
                new String[] { Database.TYPE_EXEGESIS });
        ((ListDialogFragment) dialog).setOnDateSelectedListener(handler);
        break;
    case R.id.button_list_intro:
        dialog = new ListDialogFragment();
        ((ListDialogFragment) dialog).setTitle(getString(R.string.navigation_intro));
        ((ListDialogFragment) dialog).setFilter(
                Database.COLUMN_TYPE + "=? AND " + Database.COLUMN_TITLE + "!=''",
                new String[] { Database.TYPE_INTRO });
        ((ListDialogFragment) dialog).setMapping(new String[] { Database.COLUMN_TITLE, Database.COLUMN_READ },
                new int[] { R.id.list_title, R.id.list_image });
        ((ListDialogFragment) dialog).setOnDateSelectedListener(new OnIntroSelectedListener());
        break;
    case R.id.button_list_voty:
        dialog = new ListDialogFragment();
        ((ListDialogFragment) dialog).setTitle(getString(R.string.navigation_voty));
        ((ListDialogFragment) dialog).setFilter(
                Database.COLUMN_TYPE + "=? AND " + Database.COLUMN_SOURCE + "!=''",
                new String[] { Database.TYPE_YEAR });
        ((ListDialogFragment) dialog).setOrder(Database.COLUMN_DATE);
        ((ListDialogFragment) dialog).setOnDateSelectedListener(new OnVotySelectedListener());
        break;

    // calendar
    case R.id.button_calendar:
        dialog = new CalendarDialogFragment();
        ((CalendarDialogFragment) dialog).setOnDateSelectedListener(handler);
        break;

    // search
    case R.id.button_search:
        if (searchButton != null) {
            searchButton.setVisibility(View.VISIBLE);
            searchButton.setIconified(false);
            searchButton.requestFocus();
            /*for (DataListener tmp : listener)
                tmp.onDataUpdated(null, null);*/
        }
        break;

    // reminder
    case R.id.button_reminder:
        dialog = new ReminderDialogFragment();
        break;

    // settings
    case R.id.button_settings:
        intent = new Intent(this, SettingsActivity.class);
        break;

    // store
    case R.id.button_store:
        intent = new Intent(this, StoreActivity.class);
        break;

    // about
    case R.id.button_about:
        intent = new Intent(this, AboutActivity.class);
        break;

    // do nothing
    default:
        break;
    }

    // start dialog
    if (dialog != null) {
        dialog.show(getSupportFragmentManager(), "dialog");
    }

    // start intent
    // TODO check intent-ed application
    else if (intent != null)
        startActivityForResult(intent, 1);

    return true;
}

From source file:com.vegnab.vegnab.MainVNActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    Tracker optionsMenuTracker = ((VNApplication) getApplication())
            .getTracker(VNApplication.TrackerName.APP_TRACKER);
    FragmentManager fm = getSupportFragmentManager();
    DialogFragment editProjDlg;
    switch (item.getItemId()) { // some of these are from Fragments, but handled here in the Activity
    case R.id.action_app_info:
        Toast.makeText(getApplicationContext(), "''App Info'' is not implemented yet", Toast.LENGTH_SHORT)
                .show();/*from  w  ww  . j av a2  s  . co m*/
        return true;

    case R.id.action_legal_notices:
        // following is required, to use Drive API
        String legalInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this);
        AlertDialog.Builder legalInfoDialog = new AlertDialog.Builder(this);
        legalInfoDialog.setTitle(this.getResources().getString(R.string.action_legal_notices));
        legalInfoDialog.setMessage(legalInfo);
        legalInfoDialog.show();
        return true;

    case R.id.action_edit_proj:
        //         EditProjectDialog editProjDlg = new EditProjectDialog();
        /*
        fm.executePendingTransactions(); // assure all are done
        NewVisitFragment newVis = (NewVisitFragment) fm.findFragmentByTag("NewVisitScreen");
        if (newVis == null) {
        Toast.makeText(getApplicationContext(), "Can't get New Visit Screen fragment", Toast.LENGTH_SHORT).show();
        return true;
        }
        // wait, we don't need to regenerate the default project Id, it's stored in Preferences*/
        SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
        long defaultProjId = sharedPref.getLong(Prefs.DEFAULT_PROJECT_ID, 1);
        editProjDlg = EditProjectDialog.newInstance(defaultProjId);
        editProjDlg.show(fm, "frg_edit_proj");
        return true;
    case R.id.action_new_proj:
        editProjDlg = EditProjectDialog.newInstance(0);
        editProjDlg.show(fm, "frg_new_proj");
        return true;
    case R.id.action_del_proj:
        DelProjectDialog delProjDlg = new DelProjectDialog();
        delProjDlg.show(fm, "frg_del_proj");
        return true;
    case R.id.action_new_plottype:
        //         Toast.makeText(getApplicationContext(), "''New Plot Type'' is still under construction", Toast.LENGTH_SHORT).show();
        showWebViewScreen(Tags.WEBVIEW_PLOT_TYPES);
        /*      public static final String WEBVIEW_TUTORIAL = "WebviewTutorial";
        public static final String WEBVIEW_PLOT_TYPES = "WebviewPlotTypes";
        public static final String WEBVIEW_REGIONAL_LISTS = "WebviewSppLists";
        */
        return true;
    case R.id.action_get_species:
        goToGetSppScreen();
        return true;

    case R.id.action_export_db:
        exportDB();
        return true;

    // following, moved to NewVisit fragment
    //        case R.id.action_unhide_visits: // from New Visit fragment
    //            if (mCtHiddenVisits == 0) {
    //                Toast.makeText(this,
    //                        this.getResources().getString(R.string.new_visit_unhide_visit_none),
    //                        Toast.LENGTH_SHORT).show();
    //            } else {
    ////                Toast.makeText(getApplicationContext(), mCtHiddenVisits + " hidden visit(s), but "
    ////                        + "''Un-hide Visits'' is not implemented yet", Toast.LENGTH_SHORT).show();
    //                UnHideVisitDialog unHideVisDlg = new UnHideVisitDialog();
    //                unHideVisDlg.show(fm, "frg_unhide_vis");
    //            }
    //            return true;

    case R.id.action_settings:
        if (LDebug.ON)
            Log.d(LOG_TAG, "Showing 'Settings' dialog");
        optionsMenuTracker.send(new HitBuilders.EventBuilder().setCategory("Options Menu").setAction("Settings")
                .setLabel("Show Settings").setValue(1).build());
        Bundle settingsArgs = new Bundle(); // we don't do anything with this yet
        SettingsDialog settingsDlg = SettingsDialog.newInstance(settingsArgs);
        settingsDlg.show(getSupportFragmentManager(), "frg_show_settings");
        return true;

    case R.id.action_donate:
        goToDonateScreen();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.android.wizardpager.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

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

    mWizardModel.registerListener(this);

    mPagerAdapter = new MyPagerAdapter(getActivity().getSupportFragmentManager());
    mPager = (ViewPager) rootView.findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mStepPagerStrip = (StepPagerStrip) rootView.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) rootView.findViewById(R.id.next_button);
    mPrevButton = (Button) rootView.findViewById(R.id.prev_button);

    mPager.setOnPageChangeListener(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() {
                    @Override
                    public Dialog onCreateDialog(Bundle savedInstanceState) {
                        return new AlertDialog.Builder(getActivity())
                                .setMessage(R.string.submit_confirm_message)
                                .setPositiveButton(R.string.submit_confirm_button,
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {

                                                Post post = new Post();
                                                post.setPostDate(new Date());

                                                for (Page p : mWizardModel.getCurrentPageSequence()) {
                                                    switch (p.getKey()) {
                                                    case PermutaSepWizardModel.CONTACT_INFO_KEY:
                                                        User user = new User(
                                                                p.getData().getString(
                                                                        ProfessorContactInfoPage.NAME_DATA_KEY),
                                                                p.getData().getString(
                                                                        ProfessorContactInfoPage.EMAIL_DATA_KEY),
                                                                p.getData().getString(
                                                                        ProfessorContactInfoPage.PHONE_DATA_KEY));
                                                        post.setUser(user);
                                                        break;
                                                    case PermutaSepWizardModel.CITY_FROM_KEY:
                                                        post.setStateFrom((State) p.getData().getParcelable(
                                                                ProfessorCityFromPage.STATE_DATA_KEY));
                                                        post.setCityFrom((City) p.getData().getParcelable(
                                                                ProfessorCityFromPage.MUNICIPALITY_DATA_KEY));
                                                        post.setTownFrom((Town) p.getData().getParcelable(
                                                                ProfessorCityFromPage.LOCALITY_DATA_KEY));
                                                        break;
                                                    case PermutaSepWizardModel.CITY_TO_KEY:
                                                        post.setStateTo((State) p.getData().getParcelable(
                                                                ProfessorCityToPage.STATE_TO_DATA_KEY));
                                                        post.setCityTo((City) p.getData().getParcelable(
                                                                ProfessorCityToPage.MUNICIPALITY_TO_DATA_KEY));
                                                        post.setTownTo((Town) p.getData().getParcelable(
                                                                ProfessorCityToPage.LOCALITY_TO_DATA_KEY));
                                                        break;
                                                    case PermutaSepWizardModel.POSITION_TYPE_KEY:
                                                        post.setPositionType(
                                                                p.getData().getString(p.SIMPLE_DATA_KEY));
                                                        break;
                                                    case PermutaSepWizardModel.WORKDAY_TYPE_KEY:
                                                        post.setWorkdayType(
                                                                p.getData().getString(p.SIMPLE_DATA_KEY));
                                                        break;
                                                    case PermutaSepWizardModel.TEACHING_CAREER_KEY:
                                                        post.setIsTeachingCareer(
                                                                p.getData().getString(p.SIMPLE_DATA_KEY)
                                                                        .equals("Si") ? true : false);
                                                        break;
                                                    }
                                                }

                                            }
                                        })
                                .setNegativeButton(android.R.string.cancel, null).create();
                    }
                };
                dg.show(getActivity().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();

    return rootView;
}