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:br.com.thinkti.android.filechooserfrag.fragFileChooser.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    View v = info.targetView;/*from w w  w  . j a v  a  2 s. c  o m*/
    final Option o = adapter.getItem((int) info.id);
    switch (item.getItemId()) {
    case R.id.mnuDelete:
        String msg = String.format(getString(R.string.txtReallyDelete), o.getName());
        if (lib.ShowMessageYesNo(_main, msg, _main.getString(R.string.question)) == lib.yesnoundefined.yes) {
            try {
                File F = new File(o.getPath());
                boolean delete = false;
                if (F.exists()) {
                    if (F.isDirectory()) {
                        String[] deleteCmd = { "rm", "-r", F.getPath() };
                        Runtime runtime = Runtime.getRuntime();
                        runtime.exec(deleteCmd);
                        delete = true;
                    } else {
                        delete = F.delete();
                    }
                }

                if (delete)
                    adapter.remove(o);

            } catch (Exception ex) {
                lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
            }
        }
        //lib.ShowToast(_main,"delete " + t1.getText().toString() + " " + t2.getText().toString() + " " + o.getData() + " "  + o.getPath() + " " + o.getName());
        //editNote(info.id);
        return true;
    case R.id.mnuRename:
        String msg2 = String.format(getString(R.string.txtRenameFile), o.getName());
        AlertDialog.Builder A = new AlertDialog.Builder(_main);
        final EditText inputRename = new EditText(_main);
        A.setMessage(msg2);
        A.setTitle(getString(R.string.rename));

        // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
        inputRename.setInputType(InputType.TYPE_CLASS_TEXT);
        inputRename.setText(o.getName());
        A.setView(inputRename);
        A.setPositiveButton(_main.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String name = inputRename.getText().toString();
                final String pattern = ".+\\.(((?i)v.{2})|((?i)k.{2})|((?i)dic))$";
                Pattern vok = Pattern.compile(pattern);
                if (lib.libString.IsNullOrEmpty(name))
                    return;
                if (vok.matcher(name).matches()) {
                    try {

                        File F = new File(o.getPath());
                        File F2 = new File(F.getParent(), name);
                        if (!F2.exists()) {
                            final boolean b = F.renameTo(F2);
                            if (b) {
                                o.setName(name);
                                o.setPath(F2.getPath());
                                adapter.notifyDataSetChanged();
                            }
                        } else {
                            lib.ShowMessage(_main, getString(R.string.msgFileExists), "");
                        }

                    } catch (Exception ex) {
                        lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
                    }
                } else {
                    AlertDialog.Builder A = new AlertDialog.Builder(_main);
                    A.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    });
                    A.setMessage(getString(R.string.msgWrongExt2));
                    A.setTitle(getString(R.string.message));
                    AlertDialog dlg = A.create();
                    dlg.show();

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

            }
        });
        AlertDialog dlg = A.create();
        dlg.show();
        return true;
    case R.id.mnuCopy:
        _copiedFile = (o.getPath());
        _cutFile = null;
        return true;
    case R.id.mnuCut:
        _cutFile = (o.getPath());
        _cutOption = o;
        _copiedFile = null;
        return true;
    case R.id.mnuPaste:
        if (_cutFile != null && _copiedFile != null)
            return true;
        String path;
        File F = new File(o.getPath());
        if (F.isDirectory()) {
            path = F.getPath();
        } else {
            path = F.getParent();
        }
        if (_copiedFile != null) {
            File source = new File(_copiedFile);
            File dest = new File(path, source.getName());
            if (dest.exists()) {
                lib.ShowMessage(_main, getString(R.string.msgFileExists), "");
                return true;
            }
            String[] copyCmd;
            if (source.isDirectory()) {
                copyCmd = new String[] { "cp", "-r", _copiedFile, path };
            } else {
                copyCmd = new String[] { "cp", _copiedFile, path };
            }
            Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec(copyCmd);
                Option newOption;
                if (dest.getParent().equalsIgnoreCase(currentDir.getPath())) {
                    if (dest.isDirectory() && !dest.isHidden()) {
                        adapter.add(new Option(dest.getName(), getString(R.string.folder),
                                dest.getAbsolutePath(), true, false, false));
                    } else {
                        if (!dest.isHidden())
                            adapter.add(new Option(dest.getName(),
                                    getString(R.string.fileSize) + ": " + dest.length(), dest.getAbsolutePath(),
                                    false, false, false));
                    }
                }
            } catch (Exception ex) {
                lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
            }

        } else if (_cutFile != null) {
            File source = new File(_cutFile);
            File dest = new File(path, source.getName());
            if (dest.exists()) {
                lib.ShowMessage(_main, getString(R.string.msgFileExists), "");
                return true;
            }
            String[] copyCmd;
            if (source.isDirectory()) {
                copyCmd = new String[] { "mv", "-r", _cutFile, path };
            } else {
                copyCmd = new String[] { "mv", _cutFile, path };
            }
            Runtime runtime = Runtime.getRuntime();
            _cutFile = null;
            try {
                runtime.exec(copyCmd);
                Option newOption;
                try {
                    adapter.remove(_cutOption);
                    _cutOption = null;
                } catch (Exception e) {

                }
                if (dest.getParent().equalsIgnoreCase(currentDir.getPath())) {
                    if (dest.isDirectory() && !dest.isHidden()) {
                        adapter.add(new Option(dest.getName(), getString(R.string.folder),
                                dest.getAbsolutePath(), true, false, false));
                    } else {
                        if (!dest.isHidden())
                            adapter.add(new Option(dest.getName(),
                                    getString(R.string.fileSize) + ": " + dest.length(), dest.getAbsolutePath(),
                                    false, false, false));
                    }
                }
            } catch (Exception ex) {
                lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error)));
            }
        }
        return true;
    case R.id.mnuNewFolder:
        A = new AlertDialog.Builder(_main);
        //final EditText input = new EditText(_main);
        final EditText inputNF = new EditText(_main);
        A.setMessage(getString(R.string.msgEnterNewFolderName));
        A.setTitle(getString(R.string.cmnuNewFolder));

        // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
        inputNF.setInputType(InputType.TYPE_CLASS_TEXT);
        inputNF.setText("");
        A.setView(inputNF);
        A.setPositiveButton(_main.getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String name = inputNF.getText().toString();
                if (lib.libString.IsNullOrEmpty(name))
                    return;
                String NFpath;
                File NF = new File(o.getPath());
                if (NF.isDirectory()) {
                    NFpath = NF.getPath();
                } else {
                    NFpath = NF.getParent();
                }
                try {
                    File NewFolder = new File(NFpath, name);
                    NewFolder.mkdir();
                    adapter.add(new Option(NewFolder.getName(), getString(R.string.folder),
                            NewFolder.getAbsolutePath(), true, false, false));

                } catch (Exception ex) {
                    lib.ShowException(_main, ex);
                }
            }
        });
        A.setNegativeButton(_main.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        dlg = A.create();
        dlg.show();
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.morlunk.mumbleclient.channel.actionmode.UserActionModeCallback.java

@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
    try {/*  w w  w.j av a  2s.  c  om*/
        boolean ban = false;
        switch (menuItem.getItemId()) {
        //                case R.id.context_send_message:
        //                    if(mChatTargetProvider.getChatTarget() != null &&
        //                            mChatTargetProvider.getChatTarget().getUser() != null &&
        //                            mChatTargetProvider.getChatTarget().getUser().equals(mUser)) {
        //                        mChatTargetProvider.setChatTarget(null);
        //                    } else {
        //                        mChatTargetProvider.setChatTarget(new ChatTargetProvider.ChatTarget(mUser));
        //                    }
        //                    break;
        case R.id.context_ban:
            ban = true;
        case R.id.context_kick:
            AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext);
            alertBuilder.setTitle(R.string.user_menu_kick);
            final EditText reasonField = new EditText(mContext);
            reasonField.setHint(R.string.hint_reason);
            alertBuilder.setView(reasonField);
            final boolean finalBan = ban;
            alertBuilder.setPositiveButton(R.string.user_menu_kick, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        mService.kickBanUser(mUser.getSession(), reasonField.getText().toString(), finalBan);
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    }
                }
            });
            alertBuilder.setNegativeButton(android.R.string.cancel, null);
            alertBuilder.show();
            break;
        case R.id.context_mute:
            mService.setMuteDeafState(mUser.getSession(), !(mUser.isMuted() || mUser.isSuppressed()),
                    mUser.isDeafened());
            break;
        case R.id.context_deafen:
            mService.setMuteDeafState(mUser.getSession(), mUser.isMuted(), !mUser.isDeafened());
            break;
        case R.id.context_move:
            showChannelMoveDialog();
            break;
        case R.id.context_priority:
            mService.setPrioritySpeaker(mUser.getSession(), !mUser.isPrioritySpeaker());
            break;
        case R.id.context_local_mute:
            mUser.setLocalMuted(!mUser.isLocalMuted());
            mListener.onLocalUserStateUpdated(mUser);
            break;
        case R.id.context_ignore_messages:
            mUser.setLocalIgnored(!mUser.isLocalIgnored());
            mListener.onLocalUserStateUpdated(mUser);
            break;
        case R.id.context_change_comment:
            showUserComment(true);
            break;
        case R.id.context_view_comment:
            showUserComment(false);
            break;
        case R.id.context_reset_comment:
            new AlertDialog.Builder(mContext)
                    .setMessage(mContext.getString(R.string.confirm_reset_comment, mUser.getName()))
                    .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            try {
                                mService.setUserComment(mUser.getSession(), "");
                            } catch (RemoteException e) {
                                e.printStackTrace();
                            }
                        }
                    }).setNegativeButton(android.R.string.cancel, null).show();
            break;
        //                case R.id.context_info:
        //                    break;
        case R.id.context_register:
            mService.registerUser(mUser.getSession());
            break;
        }
    } catch (RemoteException e) {
        e.printStackTrace();
        return false;
    }
    actionMode.finish(); // FIXME?
    return true;
}

From source file:com.lu.takeaway.view.activity.MainActivity.java

public void sharedWeiXin() {

    // WXAPIFactory?IWXAPI
    api = WXAPIFactory.createWXAPI(this, "wxdbe2c330d4cfb36e", false);
    final EditText editor = new EditText(this);
    editor.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    editor.setText("takeaway");
    smg = editor.getText().toString();// w w  w .j  a  va 2  s.  c o m
    showAlert(this, "title text", smg, new MyOnClickListener());
}

From source file:com.b44t.ui.PasscodeActivity.java

@Override
public View createView(Context context) {
    actionBar/* w  w w .j av  a  2s  . co m*/
            .setBackButtonImage(screen == SCREEN0_SETTINGS ? R.drawable.ic_ab_back : R.drawable.ic_close_white);
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (passcodeSetStep == 0) {
                    processNext();
                } else if (passcodeSetStep == 1) {
                    processDone();
                }
            } else if (id == pin_item) {
                currentPasswordType = 0;
                updateDropDownTextView();
            } else if (id == password_item) {
                currentPasswordType = 1;
                updateDropDownTextView();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    if (screen != SCREEN0_SETTINGS) {
        ActionBarMenu menu = actionBar.createMenu();
        menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

        titleTextView = new TextView(context);
        titleTextView.setTextColor(0xff757575);
        if (screen == SCREEN1_ENTER_CODE1) {
            if (UserConfig.passcodeHash.length() != 0) {
                titleTextView
                        .setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode));
            } else {
                titleTextView.setText(
                        LocaleController.getString("EnterNewFirstPasscode", R.string.EnterNewFirstPasscode));
            }
        } else {
            titleTextView
                    .setText(LocaleController.getString("EnterCurrentPasscode", R.string.EnterCurrentPasscode));
        }
        titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
        frameLayout.addView(titleTextView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        layoutParams.topMargin = AndroidUtilities.dp(38);
        titleTextView.setLayoutParams(layoutParams);

        passwordEditText = new EditText(context);
        passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        passwordEditText.setTextColor(0xff000000);
        passwordEditText.setMaxLines(1);
        passwordEditText.setLines(1);
        passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
        passwordEditText.setSingleLine(true);
        if (screen == SCREEN1_ENTER_CODE1) {
            passcodeSetStep = 0;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        } else {
            passcodeSetStep = 1;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        }
        passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        passwordEditText.setTypeface(Typeface.DEFAULT);
        AndroidUtilities.clearCursorDrawable(passwordEditText);
        frameLayout.addView(passwordEditText);
        layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
        layoutParams.topMargin = AndroidUtilities.dp(90);
        layoutParams.height = AndroidUtilities.dp(36);
        layoutParams.leftMargin = AndroidUtilities.dp(40);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.rightMargin = AndroidUtilities.dp(40);
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        passwordEditText.setLayoutParams(layoutParams);
        passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (passcodeSetStep == 0) {
                    processNext();
                    return true;
                } else if (passcodeSetStep == 1) {
                    processDone();
                    return true;
                }
                return false;
            }
        });
        passwordEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (passwordEditText.length() == 4) {
                    if (screen == SCREEN2_ENTER_CODE2 && UserConfig.passcodeType == 0) {
                        processDone();
                    } else if (screen == SCREEN1_ENTER_CODE1 && currentPasswordType == 0) {
                        if (passcodeSetStep == 0) {
                            processNext();
                        } else if (passcodeSetStep == 1) {
                            processDone();
                        }
                    }
                }
            }
        });

        passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public void onDestroyActionMode(ActionMode mode) {
            }

            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });

        if (screen == SCREEN1_ENTER_CODE1) {
            dropDownContainer = new ActionBarMenuItem(context, menu, 0);
            dropDownContainer.setSubMenuOpenSide(1);
            dropDownContainer.addSubItem(pin_item,
                    LocaleController.getString("PasscodePIN", R.string.PasscodePIN), 0);
            dropDownContainer.addSubItem(password_item,
                    LocaleController.getString("PasscodePassword", R.string.PasscodePassword), 0);
            actionBar.addView(dropDownContainer);
            layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
            layoutParams.height = LayoutHelper.MATCH_PARENT;
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.rightMargin = AndroidUtilities.dp(40);
            layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64)
                    : AndroidUtilities.dp(56);
            layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
            dropDownContainer.setLayoutParams(layoutParams);
            dropDownContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dropDownContainer.toggleSubMenu();
                }
            });

            dropDown = new TextView(context);
            dropDown.setGravity(Gravity.LEFT);
            dropDown.setSingleLine(true);
            dropDown.setLines(1);
            dropDown.setMaxLines(1);
            dropDown.setEllipsize(TextUtils.TruncateAt.END);
            dropDown.setTextColor(0xffffffff);
            dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
            dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
            dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
            dropDownContainer.addView(dropDown);
            layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.height = LayoutHelper.WRAP_CONTENT;
            layoutParams.leftMargin = AndroidUtilities.dp(16);
            layoutParams.gravity = Gravity.CENTER_VERTICAL;
            layoutParams.bottomMargin = AndroidUtilities.dp(1);
            dropDown.setLayoutParams(layoutParams);
        } else {
            actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        }

        updateDropDownTextView();
    } else {
        actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        frameLayout.setBackgroundColor(0xfff0f0f0);
        listView = new ListView(context);
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == changePasscodeRow) {
                    presentFragment(new PasscodeActivity(SCREEN1_ENTER_CODE1));
                } else if (i == passcodeOnOffRow) {
                    TextCheckCell cell = (TextCheckCell) view;
                    if (UserConfig.passcodeHash.length() != 0) {
                        UserConfig.passcodeHash = "";
                        UserConfig.appLocked = false;
                        UserConfig.saveConfig(false);
                        int count = listView.getChildCount();
                        for (int a = 0; a < count; a++) {
                            View child = listView.getChildAt(a);
                            if (child instanceof TextSettingsCell) {
                                TextSettingsCell textCell = (TextSettingsCell) child;
                                textCell.setTextColor(0xffc6c6c6);
                                break;
                            }
                        }
                        cell.setChecked(UserConfig.passcodeHash.length() != 0);
                        NotificationCenter.getInstance()
                                .postNotificationName(NotificationCenter.didSetPasscode);
                    } else {
                        presentFragment(new PasscodeActivity(SCREEN1_ENTER_CODE1));
                    }
                } else if (i == autoLockRow) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock));
                    final NumberPicker numberPicker = new NumberPicker(getParentActivity());
                    numberPicker.setMinValue(0);
                    numberPicker.setMaxValue(4);
                    if (UserConfig.autoLockIn == 0) {
                        numberPicker.setValue(0);
                    } else if (UserConfig.autoLockIn == 60) {
                        numberPicker.setValue(1);
                    } else if (UserConfig.autoLockIn == 60 * 5) {
                        numberPicker.setValue(2);
                    } else if (UserConfig.autoLockIn == 60 * 60) {
                        numberPicker.setValue(3);
                    } else if (UserConfig.autoLockIn == 60 * 60 * 5) {
                        numberPicker.setValue(4);
                    }
                    numberPicker.setFormatter(new NumberPicker.Formatter() {
                        @Override
                        public String format(int value) {
                            if (value == 0) {
                                return LocaleController.getString("Disabled", R.string.Disabled);
                            } else if (value == 1) {
                                return ApplicationLoader.applicationContext.getResources()
                                        .getQuantityString(R.plurals.Minutes, 1, 1);
                            } else if (value == 2) {
                                return ApplicationLoader.applicationContext.getResources()
                                        .getQuantityString(R.plurals.Minutes, 5, 5);
                            } else if (value == 3) {
                                return ApplicationLoader.applicationContext.getResources()
                                        .getQuantityString(R.plurals.Hours, 1, 1);
                            } else if (value == 4) {
                                return ApplicationLoader.applicationContext.getResources()
                                        .getQuantityString(R.plurals.Hours, 5, 5);
                            }
                            return "";
                        }
                    });
                    numberPicker.setWrapSelectorWheel(false);
                    builder.setView(numberPicker);
                    builder.setNegativeButton(LocaleController.getString("Done", R.string.Done),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    which = numberPicker.getValue();
                                    if (which == 0) {
                                        UserConfig.autoLockIn = 0;
                                    } else if (which == 1) {
                                        UserConfig.autoLockIn = 60;
                                    } else if (which == 2) {
                                        UserConfig.autoLockIn = 60 * 5;
                                    } else if (which == 3) {
                                        UserConfig.autoLockIn = 60 * 60;
                                    } else if (which == 4) {
                                        UserConfig.autoLockIn = 60 * 60 * 5;
                                    }
                                    listView.invalidateViews();
                                    UserConfig.saveConfig(false);
                                }
                            });
                    showDialog(builder.create());
                } else if (i == fingerprintRow) {
                    UserConfig.useFingerprint = !UserConfig.useFingerprint;
                    UserConfig.saveConfig(false);
                    ((TextCheckCell) view).setChecked(UserConfig.useFingerprint);
                }
            }
        });
    }

    return fragmentView;
}

From source file:fr.enseirb.odroidx.remote_client.MainActivity.java

@Override
public void onClick(View v) {
    Log.v(TAG, "click event on a button");
    v.setBackgroundResource(R.color.blue_light);

    if (v == button_play)
        sendMessageToSTB(Commands.VIDEO_PLAY);
    else if (v == button_pause)
        sendMessageToSTB(Commands.VIDEO_PAUSE);
    else if (v == button_stop)
        sendMessageToSTB(Commands.VIDEO_STOP);
    else if (v == button_previous)
        sendMessageToSTB(Commands.VIDEO_PREVIOUS);
    else if (v == button_next)
        sendMessageToSTB(Commands.VIDEO_NEXT);
    else if (v == button_up)
        sendMessageToSTB(Commands.MOVE_UP);
    else if (v == button_down)
        sendMessageToSTB(Commands.MOVE_DOWN);
    else if (v == button_left)
        sendMessageToSTB(Commands.MOVE_LEFT);
    else if (v == button_right)
        sendMessageToSTB(Commands.MOVE_RIGHT);
    else if (v == button_select)
        sendMessageToSTB(Commands.SELECT);
    else if (v == button_back)
        sendMessageToSTB(Commands.BACK);
    else if (v == button_home)
        sendMessageToSTB(Commands.HOME);
    else if (v == button_sound_mute)
        sendMessageToSTB(Commands.SOUND_MUTE);
    else if (v == button_sound_plus)
        sendMessageToSTB(Commands.SOUND_PLUS);
    else if (v == button_sound_minus)
        sendMessageToSTB(Commands.SOUND_MINUS);
    else if (v == button_enter_text) {

        AlertDialog.Builder editalert = new AlertDialog.Builder(this);
        editalert.setTitle("Message to send to the STB");
        final EditText input = new EditText(this);
        editalert.setView(input);/* w ww  . j  a  v  a 2s  . com*/

        editalert.setPositiveButton("Send it", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

                sendMessageToSTB(Commands.USER_TEXT, input.getText().toString());
            }
        });

        editalert.show();
    }
}

From source file:eu.operando.operandoapp.filters.response.ResponseFiltersActivity.java

@OnClick(R.id.add_filter)
public void addFilter() {
    final EditText input = new EditText(this);
    input.setSingleLine(true);//w ww .j a  v  a  2 s .  c  o  m
    if (viewSelected == 0) { //User Filter
        input.setHint("Filtered String");
        AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle("New ResponseFilter")
                .setView(input).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        ResponseFilter responseFilter = new ResponseFilter();
                        responseFilter.setContent(input.getText().toString());
                        responseFilter.setSource(null);
                        db.createResponseFilter(responseFilter);
                        updateFiltersList();
                        userResponseFiltersAdapter.notifyItemInserted(userFilters.size() - 1);
                        recyclerView.scrollToPosition(userFilters.size() - 1);
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                    }
                });

        final AlertDialog dialog = builder.create();

        input.addTextChangedListener(new TextWatcher() {
            @Override
            public void afterTextChanged(Editable s) {
                if (s.length() >= 1) {
                    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
                } else
                    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }
        });

        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
            }
        });

        dialog.show();

    } else { //Imported filter list
        input.setHint("Enter URL");
        new AlertDialog.Builder(this).setTitle("Import filters from remote file").setView(input)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        final String importUrl = input.getText().toString();
                        importExternalFilters(importUrl);

                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                    }
                }).show();
    }
}

From source file:com.thousandthoughts.tutorials.SensorFusionActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from   w  ww .j a  va2  s . com
    layout = (RelativeLayout) findViewById(R.id.mainlayout);
    IP1 = "";
    IP2 = "";
    angle1 = 0.0f;
    angle2 = 0.0f;
    gyroOrientation[0] = 0.0f;
    gyroOrientation[1] = 0.0f;
    gyroOrientation[2] = 0.0f;

    // initialise gyroMatrix with identity matrix
    gyroMatrix[0] = 1.0f;
    gyroMatrix[1] = 0.0f;
    gyroMatrix[2] = 0.0f;
    gyroMatrix[3] = 0.0f;
    gyroMatrix[4] = 1.0f;
    gyroMatrix[5] = 0.0f;
    gyroMatrix[6] = 0.0f;
    gyroMatrix[7] = 0.0f;
    gyroMatrix[8] = 1.0f;

    // get sensorManager and initialise sensor listeners
    mSensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE);
    initListeners();

    // wait for one second until gyroscope and magnetometer/accelerometer
    // data is initialised then scedule the complementary filter task
    fuseTimer.scheduleAtFixedRate(new calculateFusedOrientationTask(), 1000, TIME_CONSTANT);

    // GUI stuff
    try {
        client1 = new MyCoapClient(this.IP1);
        client2 = new MyCoapClient(this.IP2);
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    json = new JSONObject();
    mHandler = new Handler();
    radioSelection = 0;
    d.setRoundingMode(RoundingMode.HALF_UP);
    d.setMaximumFractionDigits(3);
    d.setMinimumFractionDigits(3);

    /// Application layout here only

    RelativeLayout.LayoutParams left = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams right = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams up = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams down = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams button1 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams button2 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams text1 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams text2 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    ImageView img_left = new ImageView(this);
    ImageView img_right = new ImageView(this);
    ImageView img_up = new ImageView(this);
    ImageView img_down = new ImageView(this);
    ImageView img_button1 = new ImageView(this);
    ImageView img_button2 = new ImageView(this);
    final EditText edittext1 = new EditText(this);
    final EditText edittext2 = new EditText(this);
    img_left.setImageResource(R.drawable.left_button);
    img_right.setImageResource(R.drawable.right_button);
    img_up.setImageResource(R.drawable.up);
    img_down.setImageResource(R.drawable.down);
    img_button1.setImageResource(R.drawable.button);
    img_button2.setImageResource(R.drawable.button);

    left.setMargins(0, 66, 0, 0);
    right.setMargins(360, 66, 0, 0);
    up.setMargins(240, 90, 0, 0);
    down.setMargins(240, 240, 0, 0);
    button1.setMargins(440, 800, 0, 0);
    button2.setMargins(440, 900, 0, 0);
    text1.setMargins(5, 800, 0, 0);
    text2.setMargins(5, 900, 0, 0);

    layout.addView(img_left, left);
    layout.addView(img_right, right);
    layout.addView(img_up, up);
    layout.addView(img_down, down);
    layout.addView(img_button1, button1);
    layout.addView(edittext1, text1);
    layout.addView(img_button2, button2);
    layout.addView(edittext2, text2);

    img_left.getLayoutParams().height = 560;
    img_left.getLayoutParams().width = 280;
    img_right.getLayoutParams().height = 560;
    img_right.getLayoutParams().width = 280;
    img_up.getLayoutParams().height = 150;
    img_up.getLayoutParams().width = 150;
    img_down.getLayoutParams().height = 150;
    img_down.getLayoutParams().width = 150;
    img_button1.getLayoutParams().height = 100;
    img_button1.getLayoutParams().width = 200;
    edittext1.getLayoutParams().width = 400;
    edittext1.setText("84.248.76.84");
    edittext2.setText("84.248.76.84");
    img_button2.getLayoutParams().height = 100;
    img_button2.getLayoutParams().width = 200;
    edittext2.getLayoutParams().width = 400;

    /////////// Define and Remember Position for EACH PHYSICAL OBJECTS (LAPTOPS) /////////////////////
    img_button1.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // TODO Auto-generated method stub
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // POSITION OF LAPTOP 1 IS REMEMBERED
                angle1 = fusedOrientation[0];
                IP1 = edittext1.getText().toString();
                try {
                    // CREATE CLIENT CONNECT TO FIRST LAPTOP
                    client1 = new MyCoapClient(IP1);
                } catch (UnknownHostException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                //view.setImageResource(R.drawable.left_button);
                break;
            }
            return true;
        }

    });

    img_button2.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // TODO Auto-generated method stub
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // POSITION OF LAPTOP 2 IS REMEMBERED
                angle2 = fusedOrientation[0];
                IP2 = edittext2.getText().toString();
                try {
                    // CREATE CLIENT CONNECT TO SECOND LAPTOP
                    client2 = new MyCoapClient(IP2);
                } catch (UnknownHostException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                break;
            }
            return true;
        }

    });

    img_left.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.left_button_press);

                ///////////////////// PERFORM CLICK ACTION BASED ON POSITION OF 2 PHYSICAL OBJECTS (LAPTOPs) HERE/////////////////////////

                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0 < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0) {
                        client1.runClient("left pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0 < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0) {
                        client2.runClient("left pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.left_button);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("left released");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("left released");
                    }
                }
                break;
            }
            return true;
        }
    });

    img_right.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.right_button_press);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("right pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("right pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.right_button);
                break;
            }
            return true;
        }
    });

    img_up.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.up_press);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("up pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("up pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.up);
                break;
            }
            return true;
        }
    });

    img_down.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.down_press);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("down pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("down pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.down);
                break;
            }
            return true;
        }
    });
}

From source file:com.skalski.raspberrycontrol.Activity_RemoteControl.java

private AlertDialog makeAndShowDialogBox(final View Button) {

    final EditText setTag = new EditText(this);
    setTag.setText((String) Button.getTag());

    return new AlertDialog.Builder(this)

            .setTitle(getResources().getString(R.string.ir_msg_2))
            .setMessage(getResources().getString(R.string.ir_msg_1)).setView(setTag)

            .setPositiveButton(getResources().getString(R.string.com_msg_5),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {

                            String tag;
                            tag = setTag.getText().toString();

                            SharedPreferences sharedPreferences = PreferenceManager
                                    .getDefaultSharedPreferences(getBaseContext());
                            SharedPreferences.Editor Editor = sharedPreferences.edit();
                            Editor.putString("tag_" + Button.getId(), tag);
                            Editor.commit();
                            Button.setTag(tag);
                        }/*w w  w .j av a2s  . com*/
                    })

            .setNegativeButton(getResources().getString(R.string.com_msg_6),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                        }
                    })

            .create();
}

From source file:edu.cmu.hcii.hangg.beeksbeacon.Fragments.ManageBeaconFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.i(TAG, "bi.id: " + beaconInstance.id + ", bi.googleType: " + beaconInstance.googleType);
    View rootView = inflater.inflate(R.layout.fragment_manage_beacon, container, false);

    advertisedId_Type = (TextView) rootView.findViewById(R.id.advertisedId_Type);
    advertisedId_Id = (TextView) rootView.findViewById(R.id.advertisedId_Id);
    status = (TextView) rootView.findViewById(R.id.status);
    placeId = (TextView) rootView.findViewById(R.id.placeId);
    placeId.setOnClickListener(new View.OnClickListener() {
        @Override//from   ww  w.ja  v  a2  s.  c  o m
        public void onClick(View v) {
            editLatLngAction();
        }
    });
    latLng = (TextView) rootView.findViewById(R.id.latLng);
    latLng.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editLatLngAction();
        }
    });
    mapView = (ImageView) rootView.findViewById(R.id.mapView);
    mapView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editLatLngAction();
        }
    });

    expectedStability = (TextView) rootView.findViewById(R.id.expectedStability);
    expectedStability.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit Stability");
            final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
                    R.array.stability_enums, android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            final Spinner spinner = new Spinner(getActivity());
            spinner.setAdapter(adapter);
            // Set the position of the spinner to the current value.
            if (beaconInstance.expectedStability != null
                    && !beaconInstance.expectedStability.equals(BeaconInstance.STABILITY_UNSPECIFIED)) {
                for (int i = 0; i < spinner.getCount(); i++) {
                    if (beaconInstance.expectedStability.equals(spinner.getItemAtPosition(i))) {
                        spinner.setSelection(i);
                    }
                }
            }
            builder.setView(spinner);
            builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    beaconInstance.expectedStability = (String) spinner.getSelectedItem();
                    updateBeacon();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.show();
        }
    });

    description = (TextView) rootView.findViewById(R.id.description);
    description.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit description");
            final EditText editText = new EditText(getActivity());
            editText.setText(description.getText());
            builder.setView(editText);
            builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    beaconInstance.description = editText.getText().toString();
                    updateBeacon();
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.show();
        }
    });

    actionButton = (Button) rootView.findViewById(R.id.actionButton);

    decommissionButton = (Button) rootView.findViewById(R.id.decommissionButton);
    decommissionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(getActivity()).setTitle("Decommission Beacon")
                    .setMessage("Are you sure you want to decommission this beacon? This operation is "
                            + "irreversible and the beacon cannot be registered again")
                    .setPositiveButton("Decommission", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            Callback decommissionCallback = new Callback() {
                                @Override
                                public void onFailure(Request request, IOException e) {
                                    logErrorAndToast("Failed request: " + request, e);
                                }

                                @Override
                                public void onResponse(Response response) throws IOException {
                                    if (response.isSuccessful()) {
                                        beaconInstance.status = BeaconInstance.STATUS_DECOMMISSIONED;
                                        updateBeacon();
                                    } else {
                                        String body = response.body().string();
                                        logErrorAndToast("Unsuccessful decommissionBeacon request: " + body);
                                    }
                                }
                            };
                            client.decommissionBeacon(decommissionCallback, beaconInstance.getBeaconName());
                        }
                    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).show();
        }
    });

    attachmentsDivider = rootView.findViewById(R.id.attachmentsDivider);
    attachmentsLabel = (TextView) rootView.findViewById(R.id.attachmentsLabel);
    attachmentsTable = (TableLayout) rootView.findViewById(R.id.attachmentsTableLayout);

    // Fetch the namespace for the developer console project ID. We redraw the UI once that
    // request completes.
    // TODO: cache this.
    Callback listNamespacesCallback = new Callback() {
        @Override
        public void onFailure(Request request, IOException e) {
            logErrorAndToast("Failed request: " + request, e);
        }

        @Override
        public void onResponse(Response response) throws IOException {
            String body = response.body().string();
            if (response.isSuccessful()) {
                try {
                    JSONObject json = new JSONObject(body);
                    JSONArray namespaces = json.getJSONArray("namespaces");
                    // At present there can be only one namespace.
                    String tmp = namespaces.getJSONObject(0).getString("namespaceName");
                    if (tmp.startsWith("namespaces/")) {
                        namespace = tmp.substring("namespaces/".length());
                    } else {
                        namespace = tmp;
                    }
                    redraw();
                } catch (JSONException e) {
                    Log.e(TAG, "JSONException", e);
                }
            } else {
                logErrorAndToast("Unsuccessful listNamespaces request: " + body);
            }
        }
    };
    client.listNamespaces(listNamespacesCallback);
    return rootView;
}

From source file:com.mattprecious.smsfix.library.FixOld.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//from  w  w  w  . j av a  2s .c  om
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    switch (id) {
    case DIALOG_ID_START_DATE_PICKER:
        dialog = new DatePickerDialog(this, new OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                startCalendar.set(year, monthOfYear, dayOfMonth);

                updateButtons();
            }
        }, startCalendar.get(Calendar.YEAR), startCalendar.get(Calendar.MONTH),
                startCalendar.get(Calendar.DAY_OF_MONTH));
        break;
    case DIALOG_ID_START_TIME_PICKER:
        dialog = new TimePickerDialog(this, new OnTimeSetListener() {

            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                startCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                startCalendar.set(Calendar.MINUTE, minute);

                updateButtons();
            }
        }, startCalendar.get(Calendar.HOUR_OF_DAY), startCalendar.get(Calendar.MINUTE),
                DateFormat.is24HourFormat(this));
        break;
    case DIALOG_ID_END_DATE_PICKER:
        dialog = new DatePickerDialog(this, new OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                endCalendar.set(year, monthOfYear, dayOfMonth);

                updateButtons();
            }
        }, endCalendar.get(Calendar.YEAR), endCalendar.get(Calendar.MONTH),
                endCalendar.get(Calendar.DAY_OF_MONTH));
        break;
    case DIALOG_ID_END_TIME_PICKER:
        dialog = new TimePickerDialog(this, new OnTimeSetListener() {

            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                endCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                endCalendar.set(Calendar.MINUTE, minute);

                updateButtons();
            }
        }, endCalendar.get(Calendar.HOUR_OF_DAY), endCalendar.get(Calendar.MINUTE),
                DateFormat.is24HourFormat(this));
        break;
    case DIALOG_ID_OFFSET_PICKER:
        builder.setTitle(R.string.offset_hours);

        final EditText editText = new EditText(this);

        DecimalFormat df = new DecimalFormat("#.###");
        editText.setText(df.format(Math.abs(offset) / 3600000f));
        editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED
                | InputType.TYPE_NUMBER_FLAG_DECIMAL);

        builder.setView(editText);

        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                offset = (long) (Double.parseDouble(editText.getText().toString()) * 3600000);
                updateButtons();
            }
        });

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

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

        dialog = builder.create();
        break;
    case DIALOG_ID_CONFIRM:
        builder.setTitle(R.string.fix_old_confirm_title);
        builder.setMessage(R.string.fix_old_confirm_message);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

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

            }
        });

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

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

            }
        });

        dialog = builder.create();
        break;
    default:
        dialog = null;
    }

    return dialog;
}