Example usage for android.text Editable toString

List of usage examples for android.text Editable toString

Introduction

In this page you can find the example usage for android.text Editable toString.

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

From source file:eu.geopaparazzi.core.ui.dialogs.NewProjectDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle bundle) {

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    try {/*from   www . j a v a2  s . co  m*/
        final File sdcardDir = ResourcesManager.getInstance(getActivity()).getSdcardDir();
        final String projectExistingString = getString(eu.geopaparazzi.core.R.string.chosen_project_exists);

        final String newGeopaparazziProjectName = ResourcesManager.getInstance(getContext())
                .getApplicationName() + "_" //$NON-NLS-1$
                + TimeUtilities.INSTANCE.TIMESTAMPFORMATTER_LOCAL.format(new Date());

        View newProjectDialogView = getActivity().getLayoutInflater()
                .inflate(R.layout.fragment_dialog_newproject, null);
        builder.setView(newProjectDialogView); // add GUI to dialog

        errorTextView = (TextView) newProjectDialogView.findViewById(R.id.newProjectErrorView);

        projectEditText = (EditText) newProjectDialogView.findViewById(R.id.newProjectEditText);
        projectEditText.setText(newGeopaparazziProjectName);
        projectEditText.addTextChangedListener(new TextWatcher() {
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // ignore
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // ignore
            }

            public void afterTextChanged(Editable s) {
                String newName = s.toString();
                if (!newName.endsWith(LibraryConstants.GEOPAPARAZZI_DB_EXTENSION)) {
                    newName = newName + LibraryConstants.GEOPAPARAZZI_DB_EXTENSION;
                }
                File newProjectFile = new File(sdcardDir, newName);
                if (newName.length() < 1) {
                    alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
                } else if (newProjectFile.exists()) {
                    alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
                    errorTextView.setVisibility(View.VISIBLE);
                    errorTextView.setText(projectExistingString);
                    return;
                } else {
                    alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
                }
                errorTextView.setVisibility(View.GONE);
            }
        });

        builder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                try {
                    Editable value = projectEditText.getText();
                    String newName = value.toString();
                    GeopaparazziApplication.getInstance().closeDatabase();
                    File newGeopaparazziFile = new File(sdcardDir.getAbsolutePath(),
                            newName + LibraryConstants.GEOPAPARAZZI_DB_EXTENSION);
                    DatabaseUtilities.setNewDatabase(getContext(), GeopaparazziApplication.getInstance(),
                            newGeopaparazziFile.getAbsolutePath());

                    if (appChangeListener != null) {
                        appChangeListener.onApplicationNeedsRestart();
                    }
                } catch (Exception e) {
                    GPLog.error(this, e.getLocalizedMessage(), e);
                    Toast.makeText(getActivity(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
                }
            }
        });

        builder.setNegativeButton(getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
            }
        });

    } catch (Exception e) {
        e.printStackTrace();
    }

    alertDialog = builder.create();
    return alertDialog;
}

From source file:me.acristoffers.tracker.fragments.PackageEditFragment.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    final int id = item.getItemId();

    if (id == R.id.save) {
        String name = "";
        boolean active = true;

        final EditText editText = (EditText) view.findViewById(R.id.name);
        if (editText != null) {
            final Editable editable = editText.getText();
            if (editable != null) {
                name = editable.toString();
            }//from   www.j a v  a2 s.  co m
        }

        final SwitchCompat switchCompat = (SwitchCompat) view.findViewById(R.id.active);
        if (switchCompat != null) {
            active = switchCompat.isChecked();
        }

        pkg.setName(name);
        pkg.setActive(active);
        pkg.save();

        if (PackageListActivity.isTablet()) {
            final PackageListActivity listActivity = (PackageListActivity) getActivity();
            listActivity.onCardViewClicked(pkg);
        } else {
            getActivity().finish();
        }

        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:wizard.ui.BalanceInfoFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mAmountView.addTextChangedListener(new TextWatcher() {
        @Override//from w ww .  j a v a 2 s .c  om
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(BalanceInfoPage.AMOUNT_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mDescriptionView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(BalanceInfoPage.DESC_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });
}

From source file:org.sufficientlysecure.keychain.remote.ui.SelectPublicKeyFragment.java

@Override
public void afterTextChanged(Editable editable) {
    mQuery = !TextUtils.isEmpty(editable.toString()) ? editable.toString() : null;
    getLoaderManager().restartLoader(0, null, this);
}

From source file:com.github.runoshun.in_app_survey.ui.QuestionFragment.java

protected View onCreateFreeWritingView(final FreeWritingQuestion question, LayoutInflater inflater,
        ViewGroup container, @SuppressWarnings("UnusedParameters") Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_default_freewriting, container, false);
    TextView questionView = (TextView) view.findViewById(R.id.survey_question);
    EditText answerView = (EditText) view.findViewById(R.id.survey_textarea);

    questionView.setText(question.question);

    answerView.addTextChangedListener(new TextWatcher() {
        @Override/*w w w. j a v a 2 s .  co m*/
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            Log.v("FreeWriting", "editable = " + editable.toString());
            question.saveAnswer(editable.toString());
        }
    });

    return view;
}

From source file:syncthing.android.ui.folderpicker.FolderPickerPresenter.java

public void createNewFolder() {
    dialogPresenter.showDialog(context -> {
        final EditText editText = new EditText(context);
        editText.setSingleLine(true);//from w  ww . j a  v a  2 s  .c  o  m
        editText.setInputType(editText.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
        return new AlertDialog.Builder(context).setTitle(R.string.new_folder).setView(editText)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Editable e = editText.getText();
                        if (e != null) {
                            onFolderSelected(path + e.toString());
                        }
                    }
                }).setNegativeButton(android.R.string.cancel, null).create();
    });
}

From source file:view.WindowDimensionFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mWindowWidthView.addTextChangedListener(new TextWatcher() {
        @Override//from   ww  w .  ja  v  a 2  s  .c  o  m
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(WindowDimensionPage.WINDOW_WIDTH_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mWindowHeightView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(WindowDimensionPage.WINDOW_HEIGHT_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });
}

From source file:de.azapps.mirakel.helper.TaskDialogHelpers.java

@SuppressLint("NewApi")
public static void handleSubtask(final Context ctx, final Task task, final OnTaskChangedListner taskChanged,
        final boolean asSubtask) {
    final List<Pair<Long, String>> names = Task.getTaskNames();
    final CharSequence[] values = new String[names.size()];
    for (int i = 0; i < names.size(); i++) {
        values[i] = names.get(i).second;
    }//  www.  j  a va 2 s  .  co  m
    final View v = ((Activity) ctx).getLayoutInflater().inflate(R.layout.select_subtask, null, false);
    final ListView lv = (ListView) v.findViewById(R.id.subtask_listview);
    final List<Task> tasks = Task.cursorToTaskList(
            ctx.getContentResolver().query(MirakelInternalContentProvider.TASK_URI, Task.allColumns,
                    ModelBase.ID + "=" + task.getId() + " AND " + Task.BASIC_FILTER_DISPLAY_TASKS, null, null));
    subtaskAdapter = new SubtaskAdapter(ctx, 0, tasks, task, asSubtask);
    lv.post(new Runnable() {
        @Override
        public void run() {
            lv.setAdapter(subtaskAdapter);
        }
    });
    searchString = "";
    done = false;
    content = false;
    reminder = false;
    optionEnabled = false;
    newTask = true;
    listId = SpecialList.firstSpecialSafe().getId();
    final EditText search = (EditText) v.findViewById(R.id.subtask_searchbox);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        Drawable left = ctx.getResources().getDrawable(android.R.drawable.ic_menu_search);
        Drawable right = null;
        left.setBounds(0, 0, 42, 42);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
                && ctx.getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
            right = ctx.getResources().getDrawable(android.R.drawable.ic_menu_search);
            right.setBounds(0, 0, 42, 42);
            left = null;
        }
        search.setCompoundDrawables(left, null, right, null);
    }
    search.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(final Editable s) {
            // Nothing
        }

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

        @Override
        public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
            searchString = s.toString();
            updateListView(subtaskAdapter, task, lv, ctx);
        }
    });
    final Button options = (Button) v.findViewById(R.id.subtasks_options);
    final LinearLayout wrapper = (LinearLayout) v.findViewById(R.id.subtask_option_wrapper);
    wrapper.setVisibility(View.GONE);
    options.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (optionEnabled) {
                wrapper.setVisibility(View.GONE);
            } else {
                wrapper.setVisibility(View.VISIBLE);
                final InputMethodManager imm = (InputMethodManager) ctx
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(search.getWindowToken(), 0);
            }
            optionEnabled = !optionEnabled;
        }
    });
    final ViewSwitcher switcher = (ViewSwitcher) v.findViewById(R.id.subtask_switcher);
    final Button subtaskNewtask = (Button) v.findViewById(R.id.subtask_newtask);
    final Button subtaskSelectOld = (Button) v.findViewById(R.id.subtask_select_old);
    final boolean darkTheme = MirakelCommonPreferences.isDark();
    if (asSubtask) {
        v.findViewById(R.id.subtask_header).setVisibility(View.GONE);
        switcher.showNext();
        newTask = false;
    } else {
        subtaskNewtask.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(final View v) {
                if (newTask) {
                    return;
                }
                switcher.showPrevious();
                subtaskNewtask
                        .setTextColor(ctx.getResources().getColor(darkTheme ? R.color.White : R.color.Black));
                subtaskSelectOld.setTextColor(ctx.getResources().getColor(R.color.Grey));
                newTask = true;
            }
        });
        subtaskSelectOld.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(final View v) {
                if (!newTask) {
                    return;
                }
                switcher.showNext();
                subtaskNewtask.setTextColor(ctx.getResources().getColor(R.color.Grey));
                subtaskSelectOld
                        .setTextColor(ctx.getResources().getColor(darkTheme ? R.color.White : R.color.Black));
                if (subtaskAdapter != null) {
                    subtaskAdapter.notifyDataSetChanged();
                }
                newTask = false;
                lv.invalidateViews();
                updateListView(subtaskAdapter, task, lv, ctx);
            }
        });
    }
    final CheckBox doneBox = (CheckBox) v.findViewById(R.id.subtask_done);
    doneBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            done = isChecked;
            updateListView(subtaskAdapter, task, lv, ctx);
        }
    });
    final CheckBox reminderBox = (CheckBox) v.findViewById(R.id.subtask_reminder);
    reminderBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            reminder = isChecked;
            updateListView(subtaskAdapter, task, lv, ctx);
        }
    });
    final Button list = (Button) v.findViewById(R.id.subtask_list);
    list.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            final List<ListMirakel> lists = ListMirakel.all(true);
            final CharSequence[] names = new String[lists.size()];
            for (int i = 0; i < names.length; i++) {
                names[i] = lists.get(i).getName();
            }
            new AlertDialog.Builder(ctx).setSingleChoiceItems(names, -1, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    listId = lists.get(which).getId();
                    updateListView(subtaskAdapter, task, lv, ctx);
                    list.setText(lists.get(which).getName());
                    dialog.dismiss();
                }
            }).show();
        }
    });
    final CheckBox contentBox = (CheckBox) v.findViewById(R.id.subtask_content);
    contentBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            content = isChecked;
            updateListView(subtaskAdapter, task, lv, ctx);
        }
    });
    final EditText newTaskEdit = (EditText) v.findViewById(R.id.subtask_add_task_edit);
    final AlertDialog dialog = new AlertDialog.Builder(ctx).setTitle(ctx.getString(R.string.add_subtask))
            .setView(v).setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    if (newTask && newTaskEdit.getText().length() > 0) {
                        newSubtask(newTaskEdit.getText().toString(), task, ctx);
                    } else if (!newTask) {
                        final List<Task> checked = subtaskAdapter.getSelected();
                        for (final Task t : checked) {
                            if (!asSubtask) {
                                if (!t.hasSubtasksLoop(task)) {
                                    task.addSubtask(t);
                                } else {
                                    ErrorReporter.report(ErrorType.TASKS_CANNOT_FORM_LOOP);
                                }
                            } else {
                                if (!task.hasSubtasksLoop(t)) {
                                    t.addSubtask(task);
                                } else {
                                    ErrorReporter.report(ErrorType.TASKS_CANNOT_FORM_LOOP);
                                }
                            }
                        }
                    }
                    if (taskChanged != null) {
                        taskChanged.onTaskChanged(task);
                    }
                    ((Activity) ctx).getWindow()
                            .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
                    dialog.dismiss();
                }
            }).setNegativeButton(android.R.string.cancel, dialogDoNothing).show();
    newTaskEdit.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                newSubtask(v.getText().toString(), task, ctx);
                v.setText(null);
                if (taskChanged != null) {
                    taskChanged.onTaskChanged(task);
                }
                dialog.dismiss();
            }
            return false;
        }
    });
}

From source file:view.FenceDimensionFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mFenceLengthView.addTextChangedListener(new TextWatcher() {
        @Override// w  w  w  . ja va  2  s.  co m
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(WindowDimensionPage.WINDOW_WIDTH_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });

    mFenceWalkGateView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            mPage.getData().putString(WindowDimensionPage.WINDOW_HEIGHT_DATA_KEY,
                    (editable != null) ? editable.toString() : null);
            mPage.notifyDataChanged();
        }
    });
}

From source file:org.exoplatform.shareextension.ComposeFragment.java

private ComposeFragment() {
    postValidator = new TextWatcher() {
        @Override//from  ww  w.j  a v a2  s .c o m
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // Enables the post button if the composer text field contains a message
            enableDisableMainButton();
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }

        @Override
        public void afterTextChanged(Editable e) {
            // Update the value of post message after edit
            getShareActivity().setPostMessage(e.toString());
        }
    };
}