Example usage for android.text ClipboardManager hasText

List of usage examples for android.text ClipboardManager hasText

Introduction

In this page you can find the example usage for android.text ClipboardManager hasText.

Prototype

public abstract boolean hasText();

Source Link

Document

Returns true if the clipboard contains text; false otherwise.

Usage

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog clipBoardDialog() {
    final int COPY_GAME = 0;
    final int COPY_POSITION = 1;
    final int PASTE = 2;

    List<CharSequence> lst = new ArrayList<CharSequence>();
    List<Integer> actions = new ArrayList<Integer>();
    lst.add(getString(R.string.copy_game));
    actions.add(COPY_GAME);/*from w w  w . j  av a  2s  .c o m*/
    lst.add(getString(R.string.copy_position));
    actions.add(COPY_POSITION);
    lst.add(getString(R.string.paste));
    actions.add(PASTE);
    final List<Integer> finalActions = actions;
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.tools_menu);
    builder.setItems(lst.toArray(new CharSequence[lst.size()]), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            switch (finalActions.get(item)) {
            case COPY_GAME: {
                String pgn = ctrl.getPGN();
                ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                clipboard.setText(pgn);
                break;
            }
            case COPY_POSITION: {
                String fen = ctrl.getFEN() + "\n";
                ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                clipboard.setText(fen);
                break;
            }
            case PASTE: {
                ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                if (clipboard.hasText()) {
                    String fenPgn = clipboard.getText().toString();
                    try {
                        ctrl.setFENOrPGN(fenPgn);
                        setBoardFlip(true);
                    } catch (ChessParseError e) {
                        Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT)
                                .show();
                    }
                }
                break;
            }
            }
        }
    });
    AlertDialog alert = builder.create();
    return alert;
}