Example usage for android.widget EditText EditText

List of usage examples for android.widget EditText EditText

Introduction

In this page you can find the example usage for android.widget EditText EditText.

Prototype

public EditText(Context context) 

Source Link

Usage

From source file:com.example.android.contactslist.ui.eventEntry.EventEntryFragment.java

private void editWordCountTextDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.event_word_count_title);

    // Set up the input
    final EditText input = new EditText(getActivity());

    input.setText(mWordCountViewButton.getText());
    input.setSelected(true);/*www  .j av a 2s  . c  om*/

    // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
    input.setInputType(InputType.TYPE_CLASS_NUMBER);
    builder.setView(input);

    // Set up the buttons
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            mWordCountViewButton.setText(input.getText().toString());
            mWordCount = Integer.parseInt(input.getText().toString());
            mWordCountSeekBar.setProgress(mWordCount);

        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.show();
}

From source file:org.fox.ttrss.OnlineActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager()
            .findFragmentByTag(FRAG_HEADLINES);
    final ArticlePager ap = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);

    switch (item.getItemId()) {
    /* case android.R.id.home:
       finish();//  w w w  .j  av  a 2  s.  c om
       return true; */
    case R.id.headlines_toggle_sidebar:
        if (true && !isSmallScreen()) {
            View v = findViewById(R.id.headlines_fragment);

            if (v != null) {
                SharedPreferences.Editor editor = m_prefs.edit();
                editor.putBoolean("headlines_hide_sidebar",
                        !m_prefs.getBoolean("headlines_hide_sidebar", false));
                editor.commit();

                v.setVisibility(m_prefs.getBoolean("headlines_hide_sidebar", false) ? View.GONE : View.VISIBLE);
            }
        }
        return true;
    case R.id.subscribe_to_feed:
        Intent subscribe = new Intent(OnlineActivity.this, SubscribeActivity.class);
        startActivityForResult(subscribe, 0);
        return true;
    case R.id.toggle_attachments:
        if (true) {
            Article article = ap.getSelectedArticle();

            if (article != null && article.attachments != null && article.attachments.size() > 0) {
                CharSequence[] items = new CharSequence[article.attachments.size()];
                final CharSequence[] itemUrls = new CharSequence[article.attachments.size()];

                for (int i = 0; i < article.attachments.size(); i++) {
                    items[i] = article.attachments.get(i).title != null ? article.attachments.get(i).content_url
                            : article.attachments.get(i).content_url;

                    itemUrls[i] = article.attachments.get(i).content_url;
                }

                Dialog dialog = new Dialog(OnlineActivity.this);
                AlertDialog.Builder builder = new AlertDialog.Builder(OnlineActivity.this)
                        .setTitle(R.string.attachments_prompt).setCancelable(true)
                        .setSingleChoiceItems(items, 0, new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                //
                            }
                        }).setNeutralButton(R.string.attachment_copy, new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                int selectedPosition = ((AlertDialog) dialog).getListView()
                                        .getCheckedItemPosition();

                                copyToClipboard((String) itemUrls[selectedPosition]);
                            }
                        }).setPositiveButton(R.string.attachment_view, new OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int id) {
                                int selectedPosition = ((AlertDialog) dialog).getListView()
                                        .getCheckedItemPosition();

                                Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                                        Uri.parse((String) itemUrls[selectedPosition]));
                                startActivity(browserIntent);

                                dialog.cancel();
                            }
                        }).setNegativeButton(R.string.dialog_cancel, new OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });

                dialog = builder.create();
                dialog.show();
            }
        }
        return true;
    case R.id.donate:
        if (true) {
            openUnlockUrl();
        }
        return true;
    case R.id.logout:
        logout();
        return true;
    case R.id.login:
        login();
        return true;
    case R.id.go_offline:
        switchOffline();
        return true;
    case R.id.article_set_note:
        if (ap != null && ap.getSelectedArticle() != null) {
            editArticleNote(ap.getSelectedArticle());
        }
        return true;
    case R.id.preferences:
        Intent intent = new Intent(OnlineActivity.this, PreferencesActivity.class);
        startActivityForResult(intent, 0);
        return true;
    case R.id.search:
        if (hf != null && isCompatMode()) {
            Dialog dialog = new Dialog(this);

            final EditText edit = new EditText(this);

            AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(R.string.search)
                    .setPositiveButton(getString(R.string.search), new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            String query = edit.getText().toString().trim();

                            hf.setSearchQuery(query);

                        }
                    }).setNegativeButton(getString(R.string.cancel), new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            //

                        }
                    }).setView(edit);

            dialog = builder.create();
            dialog.show();
        }
        return true;
    case R.id.headlines_mark_as_read:
        if (hf != null) {

            int count = hf.getUnreadArticles().size();

            boolean confirm = m_prefs.getBoolean("confirm_headlines_catchup", true);

            if (count > 0) {
                if (confirm) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(OnlineActivity.this)
                            .setMessage(getString(R.string.mark_num_headlines_as_read, count))
                            .setPositiveButton(R.string.catchup, new Dialog.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {

                                    catchupVisibleArticles();

                                }
                            }).setNegativeButton(R.string.dialog_cancel, new Dialog.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {

                                }
                            });

                    AlertDialog dlg = builder.create();
                    dlg.show();
                } else {
                    catchupVisibleArticles();
                }
            }
        }
        return true;
    case R.id.headlines_view_mode:
        if (hf != null) {
            Dialog dialog = new Dialog(this);

            String viewMode = getViewMode();

            //Log.d(TAG, "viewMode:" + getViewMode());

            int selectedIndex = 0;

            if (viewMode.equals("all_articles")) {
                selectedIndex = 1;
            } else if (viewMode.equals("marked")) {
                selectedIndex = 2;
            } else if (viewMode.equals("published")) {
                selectedIndex = 3;
            } else if (viewMode.equals("unread")) {
                selectedIndex = 4;
            }

            AlertDialog.Builder builder = new AlertDialog.Builder(this)
                    .setTitle(R.string.headlines_set_view_mode)
                    .setSingleChoiceItems(new String[] { getString(R.string.headlines_adaptive),
                            getString(R.string.headlines_all_articles), getString(R.string.headlines_starred),
                            getString(R.string.headlines_published), getString(R.string.headlines_unread) },
                            selectedIndex, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    switch (which) {
                                    case 0:
                                        setViewMode("adaptive");
                                        break;
                                    case 1:
                                        setViewMode("all_articles");
                                        break;
                                    case 2:
                                        setViewMode("marked");
                                        break;
                                    case 3:
                                        setViewMode("published");
                                        break;
                                    case 4:
                                        setViewMode("unread");
                                        break;
                                    }
                                    dialog.cancel();

                                    refresh();
                                }
                            });

            dialog = builder.create();
            dialog.show();

        }
        return true;
    case R.id.headlines_select:
        if (hf != null) {
            Dialog dialog = new Dialog(this);
            AlertDialog.Builder builder = new AlertDialog.Builder(this)
                    .setTitle(R.string.headlines_select_dialog).setSingleChoiceItems(
                            new String[] { getString(R.string.headlines_select_all),
                                    getString(R.string.headlines_select_unread),
                                    getString(R.string.headlines_select_none) },
                            0, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    switch (which) {
                                    case 0:
                                        hf.setSelection(HeadlinesFragment.ArticlesSelection.ALL);
                                        break;
                                    case 1:
                                        hf.setSelection(HeadlinesFragment.ArticlesSelection.UNREAD);
                                        break;
                                    case 2:
                                        hf.setSelection(HeadlinesFragment.ArticlesSelection.NONE);
                                        break;
                                    }
                                    dialog.cancel();
                                    initMenu();
                                }
                            });

            dialog = builder.create();
            dialog.show();
        }
        return true;
    case R.id.share_article:
        if (ap != null) {
            shareArticle(ap.getSelectedArticle());
        }
        return true;
    case R.id.toggle_marked:
        if (ap != null & ap.getSelectedArticle() != null) {
            Article a = ap.getSelectedArticle();
            a.marked = !a.marked;
            saveArticleMarked(a);
            if (hf != null)
                hf.notifyUpdated();
        }
        return true;
    /* case R.id.selection_select_none:
       if (hf != null) {
    ArticleList selected = hf.getSelectedArticles();
    if (selected.size() > 0) {
       selected.clear();
       initMenu();
       hf.notifyUpdated();
    }
       }
       return true; */
    case R.id.selection_toggle_unread:
        if (hf != null) {
            ArticleList selected = hf.getSelectedArticles();

            if (selected.size() > 0) {
                for (Article a : selected)
                    a.unread = !a.unread;

                toggleArticlesUnread(selected);
                hf.notifyUpdated();
                initMenu();
            }
        }
        return true;
    case R.id.selection_toggle_marked:
        if (hf != null) {
            ArticleList selected = hf.getSelectedArticles();

            if (selected.size() > 0) {
                for (Article a : selected)
                    a.marked = !a.marked;

                toggleArticlesMarked(selected);
                hf.notifyUpdated();
                initMenu();
            }
        }
        return true;
    case R.id.selection_toggle_published:
        if (hf != null) {
            ArticleList selected = hf.getSelectedArticles();

            if (selected.size() > 0) {
                for (Article a : selected)
                    a.published = !a.published;

                toggleArticlesPublished(selected);
                hf.notifyUpdated();
                initMenu();
            }
        }
        return true;
    case R.id.toggle_published:
        if (ap != null && ap.getSelectedArticle() != null) {
            Article a = ap.getSelectedArticle();
            a.published = !a.published;
            saveArticlePublished(a);
            if (hf != null)
                hf.notifyUpdated();
        }
        return true;
    case R.id.catchup_above:
        if (hf != null) {
            if (ap != null && ap.getSelectedArticle() != null) {
                Article article = ap.getSelectedArticle();

                ArticleList articles = hf.getAllArticles();
                ArticleList tmp = new ArticleList();
                for (Article a : articles) {
                    if (article.id == a.id)
                        break;

                    if (a.unread) {
                        a.unread = false;
                        tmp.add(a);
                    }
                }
                if (tmp.size() > 0) {
                    toggleArticlesUnread(tmp);
                    hf.notifyUpdated();
                    initMenu();
                }
            }
        }
        return true;
    case R.id.set_unread:
        if (ap != null && ap.getSelectedArticle() != null) {
            Article a = ap.getSelectedArticle();

            if (a != null) {
                a.unread = !a.unread;
                saveArticleUnread(a);
            }

            if (hf != null)
                hf.notifyUpdated();
        }
        return true;
    case R.id.set_labels:
        if (ap != null && ap.getSelectedArticle() != null) {
            if (getApiLevel() != 7) {
                editArticleLabels(ap.getSelectedArticle());
            } else {
                toast(R.string.server_function_not_available);
            }

        }
        return true;
    case R.id.update_headlines:
        if (hf != null) {
            m_pullToRefreshAttacher.setRefreshing(true);
            hf.refresh(false);
        }
        return true;
    default:
        Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.realtek.simpleconfig.SCTest.java

/** ??? */
@SuppressWarnings("deprecation")
public void RenameDevProgressPopUp(final String input_pin, final String ip, final String dev_name) {
    final EditText editText = new EditText(SCTest.this);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(dev_name).setCancelable(false).setMessage("Please input the new name:").setView(editText)
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override//w w w .  j  a  v  a 2  s.c o  m
                public void onClick(DialogInterface dialog, int id) {
                    ReNameStr = editText.getText().toString();
                    if (ReNameStr.length() > 0) {

                        RenameDevFirstShow = true;
                        renameDevDialog.setTitle(dev_name);
                        if (ip.equals("0.0.0.0")) {
                            renameDevDialog.setMessage("  ?IP......");
                        } else {
                            SendCtlDevPacket(SCCtlOps.Flag.RenameDev, input_pin, ip, ReNameStr);
                            renameDevDialog.setMessage("    ???......");
                        }
                        renameDevDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        renameDevDialog.setCancelable(false);
                        renameDevDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                        renameDevDialog.show();
                    }
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    builder.show();
}

From source file:im.neon.fragments.VectorMessageListFragment.java

/**
 * The user reports a content problem to the server
 *
 * @param event the event to report//from  w w  w  . j  a v  a 2 s .  c  o m
 */
private void onMessageReport(final Event event) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.room_event_action_report_prompt_reason);

    // add a text input
    final EditText input = new EditText(getActivity());
    builder.setView(input);

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String reason = input.getText().toString();

            mRoom.report(event.eventId, -100, reason, new SimpleApiCallback<Void>(getActivity()) {
                @Override
                public void onSuccess(Void info) {
                    new AlertDialog.Builder(VectorApp.getCurrentActivity())
                            .setMessage(R.string.room_event_action_report_prompt_ignore_user)
                            .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();

                                    ArrayList<String> userIdsList = new ArrayList<>();
                                    userIdsList.add(event.sender);

                                    mSession.ignoreUsers(userIdsList, new SimpleApiCallback<Void>() {
                                        @Override
                                        public void onSuccess(Void info) {
                                        }
                                    });
                                }
                            }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            }).create().show();
                }
            });
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.show();
}

From source file:com.example.android.contactslist.ui.eventEntry.EventEntryFragment.java

private void editAddressTextDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    // Set up the input
    final EditText input = new EditText(getActivity());

    input.setText(mAddressViewButton.getText());

    input.setMinHeight(50);/* w  w  w . jav a  2s .com*/

    // Specify the type of input expected for each of the communications classes
    switch (mEventClass) {

    case EventInfo.EMAIL_CLASS:
        builder.setTitle(R.string.event_address_title);
        input.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
        break;
    case EventInfo.PHONE_CLASS:
    case EventInfo.SMS_CLASS:
        builder.setTitle(R.string.event_address_title_alt_phone);
        input.setInputType(InputType.TYPE_CLASS_PHONE);
        break;
    case EventInfo.MEETING_CLASS:
        builder.setTitle(R.string.event_address_title);
        input.setInputType(InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);
        break;
    case EventInfo.SKYPE:
    case EventInfo.GOOGLE_HANGOUTS:
    case EventInfo.FACEBOOK:

    default:
        input.setInputType(InputType.TYPE_CLASS_TEXT);
        builder.setTitle(R.string.event_address_title_alt_handle);

    }

    builder.setView(input);

    // Set up the buttons
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            mAddressViewButton.setText(input.getText().toString());
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.show();
}

From source file:org.botlibre.sdk.activity.ChatActivity.java

public void submitCorrection() {
    final EditText text = new EditText(this);
    MainActivity.prompt("Enter correction to the bot's response (what it should have said)", this, text,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    if (instance == null) {
                        return;
                    }/*  w ww  . j  a  v  a 2 s.  co  m*/

                    ChatConfig config = new ChatConfig();
                    config.instance = instance.id;
                    config.conversation = MainActivity.conversation;
                    config.speak = !MainActivity.deviceVoice;
                    config.avatar = avatarId;
                    if (MainActivity.disableVideo) {
                        config.avatarFormat = "image";
                    } else {
                        config.avatarFormat = MainActivity.webm ? "webm" : "mp4";
                    }
                    config.avatarHD = MainActivity.hd;

                    config.message = text.getText().toString().trim();
                    if (config.message.equals("")) {
                        return;
                    }
                    messages.add(config);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ListView list = (ListView) findViewById(R.id.chatList);
                            ((ChatListAdapter) list.getAdapter()).notifyDataSetChanged();
                            list.invalidateViews();
                        }

                    });

                    config.correction = true;

                    Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin);
                    config.emote = emoteSpin.getSelectedItem().toString();

                    HttpChatAction action = new HttpChatAction(ChatActivity.this, config);
                    action.execute();

                    EditText v = (EditText) findViewById(R.id.messageText);
                    v.setText("");
                    emoteSpin.setSelection(0);
                    resetToolbar();

                    WebView responseView = (WebView) findViewById(R.id.responseText);
                    responseView.loadDataWithBaseURL(null, "thinking...", "text/html", "utf-8", null);

                }
            });
}

From source file:org.cirdles.chroni.FilePickerActivity.java

public void onNewFolderButtonClicked(View v) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(this).setMessage("Enter the new folder's name below.");

    // creates the layout for the EditText, will be added to the dialog box
    final EditText newFolderText = new EditText(this);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.setMargins(25, 10, 20, 25);//  w w w .  j  a v a  2  s.com

    LinearLayout dialogLayout = new LinearLayout(this);
    dialogLayout.addView(newFolderText);
    newFolderText.setLayoutParams(params);

    dialog.setView(dialogLayout); // adds EditText to dialog box

    dialog.setPositiveButton("Create", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Editable newFolderName = newFolderText.getText();
            File newFolder = new File(mainDirectory.getAbsolutePath() + "/" + newFolderName.toString());

            // creates the folder if the length of the text is greater than 0 AND the folder does not already exist
            if (newFolderName.length() > 0 && !newFolder.exists()) {
                // creates the actual folder
                boolean createdSuccessfully = newFolder.mkdir();

                // alerts the user if the folder was not created
                if (!createdSuccessfully)
                    Toast.makeText(FilePickerActivity.this, "ERROR: Folder could not be created",
                            Toast.LENGTH_SHORT).show();

                else { // if it succeeded, updates the adapter
                    mAdapter.add(newFolder);
                    Toast.makeText(FilePickerActivity.this, "Folder Created!", Toast.LENGTH_SHORT).show();
                }

            } else
                Toast.makeText(FilePickerActivity.this, "ERROR: Invalid folder name", Toast.LENGTH_SHORT)
                        .show();

            dialog.dismiss();
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    dialog.show();
}

From source file:com.ccxt.whl.activity.SettingsFragment.java

/**
 * ??/* w w  w.ja va  2  s  . c  o m*/
 */
private void change_qianming(String qianming) {
    // TODO Auto-generated method stub
    final EditText texta = new EditText(getActivity());
    texta.setText(qianming);
    new AlertDialog.Builder(getActivity()).setTitle("??")
            .setIcon(android.R.drawable.ic_dialog_info).setView(texta)
            .setPositiveButton("", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    String nickname = texta.getEditableText().toString();
                    RequestParams params = new RequestParams();

                    params.add("user", DemoApplication.getInstance().getUser());
                    params.add("qianming", nickname);
                    params.add("param", "qianming");
                    params.add("uid", uid);
                    HttpRestClient.get(Constant.UPDATE_USER_URL, params, responseHandler);
                    pd.show();
                    dialog.dismiss();
                    //?  
                }
            }).setNegativeButton("?", null).show();
}

From source file:com.xperia64.timidityae.PlaylistFragment.java

public void add() {
    if (mode) {/*from  w  ww  .jav a 2s  .c  o m*/
        vola = parsePlist(tmpName = plistName);
        AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity());
        loki = vola.size();

        builderSingle.setIcon(R.drawable.ic_launcher);
        builderSingle.setTitle(getResources().getString(R.string.plist_addto));
        final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.select_dialog_item);
        arrayAdapter.add(getResources().getString(R.string.plist_addcs));
        arrayAdapter.add(getResources().getString(R.string.plist_adds));
        arrayAdapter.add(getResources().getString(R.string.plist_addf));
        arrayAdapter.add(getResources().getString(R.string.plist_addft));
        builderSingle.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });

        builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                vola = parsePlist(plistName);
                switch (which) {
                case 0:
                    setItem(((TimidityActivity) getActivity()).currSongName, 0);
                    write();
                    break;
                case 1:
                    new FileBrowserDialog().create(0,
                            (((Globals.showVideos) ? Globals.musicVideoFiles : Globals.musicFiles)),
                            PlaylistFragment.this, getActivity(), getActivity().getLayoutInflater(), false,
                            Globals.defaultFolder, getActivity().getResources().getString(R.string.fb_add));
                    break;
                case 2:
                    new FileBrowserDialog().create(1, null, PlaylistFragment.this, getActivity(),
                            getActivity().getLayoutInflater(), false, Globals.defaultFolder,
                            getActivity().getResources().getString(R.string.fb_add));
                    break;
                case 3:
                    new FileBrowserDialog().create(2, null, PlaylistFragment.this, getActivity(),
                            getActivity().getLayoutInflater(), false, Globals.defaultFolder,
                            getActivity().getResources().getString(R.string.fb_add));
                    break;
                }
            }
        });
        builderSingle.show();
    } else {
        AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());

        alert.setTitle(getResources().getString(R.string.plist_crea));

        final EditText input = new EditText(getActivity());
        alert.setView(input);

        alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                String value = input.getText().toString();
                File f = new File(playlistDir + value + ".tpl");

                if (!f.exists()) {
                    String[] needLol = null;
                    try {
                        new FileOutputStream(playlistDir + value + ".tpl").close();
                    } catch (FileNotFoundException e) {
                        needLol = Globals.getDocFilePaths(getActivity(), playlistDir);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    if (needLol != null) {
                        Globals.tryToCreateFile(getActivity(), playlistDir + value + ".tpl");
                    } else {
                        new File(playlistDir + value + ".tpl").delete();
                        try {
                            f.createNewFile();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }

                getPlaylists(null);
                dialog.dismiss();
            }

        });
        alert.show();
    }
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

/**
 * Handle add filter click *//ww  w .  j  a  v a  2  s.  c  o  m
 */
public void onAddFilterClick(View v) {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle(R.string.save_filter);
    alert.setMessage(R.string.save_filter_message);

    // Set an EditText view to get user input
    final EditText input = new EditText(this);
    alert.setView(input);
    input.setText(mFilter.getProposedName());

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Editable text = input.getText();
            String value;
            if (text == null) {
                value = "";
            } else {
                value = text.toString();
            }
            if (value.equals("")) {
                Util.showToastShort(getApplicationContext(), R.string.filter_name_empty);
            } else {
                SharedPreferences saved_filters = getSharedPreferences("filters", MODE_PRIVATE);
                int newId = saved_filters.getInt("max_id", 1) + 1;
                Set<String> filters = saved_filters.getStringSet("ids", new HashSet<String>());
                filters.add("filter_" + newId);
                saved_filters.edit().putStringSet("ids", filters).putInt("max_id", newId).apply();
                SharedPreferences test_filter_prefs = getSharedPreferences("filter_" + newId, MODE_PRIVATE);
                mFilter.setName(value);
                mFilter.saveInPrefs(test_filter_prefs);
                updateRightDrawer();
            }
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Canceled.
        }
    });

    alert.show();
}