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.farmerbb.notepad.fragment.NoteListFragment.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override/* www  .java 2s  .co  m*/
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.action_start_selection:
        listener.startMultiSelect();
        return true;
    case R.id.action_settings:
        Intent intentSettings = new Intent(getActivity(), SettingsActivity.class);
        startActivity(intentSettings);
        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);
    }
}

From source file:de.vanita5.twittnuker.activity.support.DataImportActivity.java

public void showImportTypeDialog(final String path, final Integer flags) {
    final DialogFragment df = new DataExportImportTypeSelectorDialogFragment();
    final Bundle args = new Bundle();
    args.putString(EXTRA_PATH, path);//from  w  ww  .  j  av  a 2s  . com
    args.putString(EXTRA_TITLE, getString(R.string.export_settings_type_dialog_title));
    if (flags != null) {
        args.putInt(EXTRA_FLAGS, flags);
    } else {
        args.putInt(EXTRA_FLAGS, 0);
    }
    df.setArguments(args);
    df.show(getSupportFragmentManager(), "select_import_type");
}

From source file:it.gmariotti.changelog.demo.MainActivity.java

/**
 * Opens the dialog//  w  w  w  . j a  v a  2 s. co m
 *
 * @param dialogStandardFragment
 */
private void openDialogFragment(DialogFragment dialogStandardFragment) {
    if (dialogStandardFragment != null) {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        Fragment prev = fm.findFragmentByTag("changelogdemo_dialog");
        if (prev != null) {
            ft.remove(prev);
        }
        dialogStandardFragment.show(ft, "changelogdemo_dialog");
    }
}

From source file:mobisocial.musubi.ui.fragments.FeedViewFragment.java

void showMenuForObj(int position) {
    //this first cursor is the internal one
    Cursor cursor = (Cursor) mObjects.getItem(position);
    long objId = cursor.getLong(0);

    DbObj obj = mMusubi.objForId(objId);
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    Fragment prev = getFragmentManager().findFragmentByTag("dialog");
    if (prev != null) {
        ft.remove(prev);//from  w  ww.j  ava 2s  .c o  m
    }
    ft.addToBackStack(null);

    // Create and show the dialog.
    DialogFragment newFragment = new ObjMenuDialogFragment(obj);
    newFragment.show(ft, "dialog");
}

From source file:com.googlecode.networklog.ExportDialog.java

public ExportDialog(final Context context) {
    this.context = context;
    Resources res = context.getResources();
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.exportdialog, null);

    startDateButton = (Button) view.findViewById(R.id.exportStartDateButton);
    endDateButton = (Button) view.findViewById(R.id.exportEndDateButton);
    filenameButton = (Button) view.findViewById(R.id.exportFilenameButton);

    GregorianCalendar today = new GregorianCalendar();
    startDate = new GregorianCalendar(today.get(Calendar.YEAR), today.get(Calendar.MONTH), 1).getTime();
    endDate = today.getTime();//from ww w.  jav a2s.  co  m
    file = new File(
            Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + defaultFilename());

    startDateButton.setText(dateDisplayFormat.format(startDate));
    endDateButton.setText(dateDisplayFormat.format(endDate));
    filenameButton.setText(file.getAbsolutePath());

    startDateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            datePickerMode = DatePickerMode.START_DATE;
            DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker view, int year, int month, int day) {
                    startDate = new GregorianCalendar(year, month, day).getTime();
                    startDateButton.setText(dateDisplayFormat.format(startDate));
                    updateFilename();
                }
            };

            Calendar cal = Calendar.getInstance();
            cal.setTime(startDate);
            DialogFragment newFragment = new DatePickerFragment(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
                    cal.get(Calendar.DAY_OF_MONTH), listener);
            newFragment.show(NetworkLog.instance.getSupportFragmentManager(), "exportDatePicker");
        }
    });

    endDateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            datePickerMode = DatePickerMode.END_DATE;
            DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker view, int year, int month, int day) {
                    endDate = new GregorianCalendar(year, month, day, 23, 59, 59).getTime();
                    endDateButton.setText(dateDisplayFormat.format(endDate));
                    updateFilename();
                }
            };

            Calendar cal = Calendar.getInstance();
            cal.setTime(endDate);
            DialogFragment newFragment = new DatePickerFragment(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
                    cal.get(Calendar.DAY_OF_MONTH), listener);
            newFragment.show(NetworkLog.instance.getSupportFragmentManager(), "exportDatePicker");
        }
    });

    filenameButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            OnHandleFileListener saveListener = new OnHandleFileListener() {
                public void handleFile(final String filePath) {
                    file = new File(filePath);
                    filenameButton.setText(filePath);
                }
            };
            new FileSelector(context, FileOperation.SAVE, saveListener, defaultFilename(),
                    new String[] { "*.*", "*.csv" }).show();
        }
    });

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(res.getString(R.string.export_title)).setView(view).setCancelable(true)
            .setPositiveButton(res.getString(R.string.export_button), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface d, int id) {
                    // see show() method for implementation -- avoids dismiss() unless validation passes
                }
            }).setNegativeButton(res.getString(R.string.cancel), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface d, int id) {
                    dialog.cancel();
                    dialog = null;
                }
            });
    dialog = builder.create();
}

From source file:com.mattprecious.notisync.activity.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_accessibility:
        DialogFragment newFragment = new AccessibilityDialogFragment();
        newFragment.show(getSupportFragmentManager(), null);

        return true;
    case R.id.menu_preferences:
        startActivity(new Intent(this, SettingsActivity.class));
        return true;
    case R.id.menu_wizard:
        startActivityForResult(new Intent(this, WizardActivity.class), REQUEST_CODE_WIZARD);

        return true;
    case R.id.menu_samsung_tts:
        showSamsungTtsDialog();// www  . j  av a  2 s . c  o  m
        return true;
    case R.id.menu_feedback:
        Helpers.openSupportPage(this);
        return true;
    case R.id.menu_about:
        startActivity(buildAboutIntent());
        return true;
    case R.id.menu_dev_tools:
        startActivity(new Intent(this, DevToolsActivity.class));
        return true;
    case R.id.menu_notifications:
        startActivity(new Intent(this, NotificationListActivity.class));
    }

    return super.onOptionsItemSelected(item);
}

From source file:biz.easymenu.easymenung.MenuPagerAdapter.java

private Object instantiateItemGrid(View pager, int position) {
    View v = li.inflate(R.layout.menupager, null);
    GridView listview = (GridView) v.findViewById(R.id.gridview);
    TextView tv = (TextView) v.findViewById(R.id.menuTitle);
    tv.setText(menuTitles.get(position).getLabel());

    ItemAdapter adapter = new ItemAdapter(context, position);
    ItemAdaptersList.add(position, adapter);
    listview.setAdapter(adapter);//from   w w  w .  j ava 2s.c o m

    listview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            //Toast.makeText(context, "" + position, Toast.LENGTH_SHORT).show();
            FragmentManager fm = ((FragmentActivity) context).getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            DialogFragment f = new ItemFragment((DBRowItem) parent.getAdapter().getItem(position));
            Fragment prev = fm.findFragmentByTag("itemDialog");
            if (prev != null) {
                ft.remove(prev);
                ft.commit();
            }
            f.show(ft, "itemDialog");
        }
    });
    ((ViewPager) pager).addView(v, 0);
    return v;
}

From source file:biz.easymenu.easymenung.MenuPagerAdapter.java

private Object instantiateItemList(View pager, int position) {
    View v = li.inflate(R.layout.menupager1, null);
    ListView listview = (ListView) v.findViewById(R.id.list);

    TextView tv = (TextView) v.findViewById(R.id.menuTitle);
    tv.setText(menuTitles.get(position).getLabel());

    ItemAdapter adapter = new ItemAdapter(context, position);
    ItemAdaptersList.add(position, adapter);
    listview.setAdapter(adapter);//from   w  ww .  j a  v  a 2s. c  o m

    listview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            //Toast.makeText(context, "" + position, Toast.LENGTH_SHORT).show();
            FragmentManager fm = ((FragmentActivity) context).getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            DialogFragment f = new ItemFragment((DBRowItem) parent.getAdapter().getItem(position));
            Fragment prev = fm.findFragmentByTag("itemDialog");
            if (prev != null) {
                ft.remove(prev);
                ft.commit();
            }
            f.show(ft, "itemDialog");
        }
    });
    ((ViewPager) pager).addView(v, 0);
    return v;
}

From source file:com.shinymayhem.radiopresets.ActivityMain.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.mark_event) {
        if (LOCAL_LOGV)
            log("--------------------------------------", "i");
        if (LOCAL_LOGV)
            log("Event button pressed", "i");
        if (LOCAL_LOGV)
            log("--------------------------------------", "i");
        DialogFragment dialog = new DialogFragmentEvent();
        dialog.show(this.getSupportFragmentManager(), "DialogFragmentEvent");
        return true;
    }// ww  w.j  a  v  a  2s  . com
    return false;

}

From source file:com.shinymayhem.radiopresets.FragmentStations.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.add_station) {
        if (LOCAL_LOGV)
            log("add station button clicked", "v");
        DialogFragment dialog = new DialogFragmentAdd();
        dialog.show(this.getFragmentManager(), "DialogFragmentAdd");
        return true;
    }//from w  ww.j  ava  2  s  .  co m
    return super.onOptionsItemSelected(item);

}