Example usage for android.text Editable length

List of usage examples for android.text Editable length

Introduction

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

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:android.support.designox.widget.TextInputLayout.java

private void setEditText(EditText editText) {
    // If we already have an EditText, throw an exception
    if (mEditText != null) {
        throw new IllegalArgumentException("We already have an EditText, can only have one");
    }/*from w  w  w  .  j av  a  2s.c o m*/

    if (!(editText instanceof TextInputEditText)) {
        Log.i(LOG_TAG,
                "EditText added is not a TextInputEditText. Please switch to using that" + " class instead.");
    }

    mEditText = editText;

    // Use the EditText's typeface, and it's text size for our expanded text
    mCollapsingTextHelper.setTypefaces(mEditText.getTypeface());
    mCollapsingTextHelper.setExpandedTextSize(mEditText.getTextSize());
    mCollapsingTextHelper.setExpandedTextGravity(mEditText.getGravity());

    // Add a TextWatcher so that we know when the text input has changed
    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            updateLabelState(true);
            if (mCounterEnabled) {
                updateCounter(s.length());
            }
        }

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

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

    // Use the EditText's hint colors if we don't have one set
    if (mDefaultTextColor == null) {
        mDefaultTextColor = mEditText.getHintTextColors();
    }

    // If we do not have a valid hint, try and retrieve it from the EditText, if enabled
    if (mHintEnabled && TextUtils.isEmpty(mHint)) {
        setHint(mEditText.getHint());
        // Clear the EditText's hint as we will display it ourselves
        mEditText.setHint(null);
    }

    if (mCounterView != null) {
        updateCounter(mEditText.getText().length());
    }

    if (mIndicatorArea != null) {
        adjustIndicatorPadding();
    }

    // Update the label visibility with no animation
    updateLabelState(false);
}

From source file:org.tpmkranz.notifyme.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.main_menu_checkaccessibility:
        prefs.setPrevVersion(0);//w  w w .j  ava 2  s  . c o m
        ((TemporaryStorage) getApplicationContext()).accessGranted(false);
        finish();
        startActivity(getIntent());
        return true;
    case R.id.main_menu_popup:
        final View view = ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE))
                .inflate(R.layout.main_menu_popup, null);
        if (android.os.Build.VERSION.SDK_INT >= 11)
            view.findViewById(R.id.main_menu_popup_background).setVisibility(View.GONE);
        ((CheckBox) view.findViewById(R.id.main_menu_popup_background_checkbox))
                .setChecked(prefs.isBackgroundColorInverted());
        view.findViewById(R.id.main_menu_popup_background_caption)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((CheckBox) view.findViewById(R.id.main_menu_popup_background_checkbox)).toggle();
                    }
                });
        ((CheckBox) view.findViewById(R.id.main_menu_popup_orientation_checkbox))
                .setChecked(prefs.isOrientationFixed());
        view.findViewById(R.id.main_menu_popup_orientation_caption)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((CheckBox) view.findViewById(R.id.main_menu_popup_orientation_checkbox)).toggle();
                    }
                });
        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r)).setMax(255);
        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r))
                .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        if (fromUser) {
                            ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_r))
                                    .setText((progress == 0 ? "" : String.valueOf(progress)));
                        }

                        ((ImageView) view.findViewById(R.id.main_menu_popup_color_preview))
                                .setImageDrawable(new ColorDrawable(Color.rgb(progress,
                                        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g))
                                                .getProgress(),
                                        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b))
                                                .getProgress())));
                    }
                });
        ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_r))
                .addTextChangedListener(new TextWatcher() {
                    @Override
                    public void afterTextChanged(Editable s) {
                        try {
                            if (Integer.parseInt(s.toString()) > 255) {
                                s.replace(0, s.length(), "255");
                                return;
                            } else if (Integer.parseInt(s.toString()) < 0) {
                                s.replace(0, s.length(), "0");
                                return;
                            }
                            ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r))
                                    .setProgress(Integer.parseInt(s.toString()));
                        } catch (Exception e) {
                            ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r)).setProgress(0);
                            s.clear();
                        }
                    }

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

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                    }
                });
        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g)).setMax(255);
        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g))
                .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        if (fromUser) {
                            ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_g))
                                    .setText((progress == 0 ? "" : String.valueOf(progress)));
                        }
                        ((ImageView) view.findViewById(R.id.main_menu_popup_color_preview))
                                .setImageDrawable(new ColorDrawable(Color.rgb(
                                        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r))
                                                .getProgress(),
                                        progress,
                                        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b))
                                                .getProgress())));
                    }
                });
        ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_g))
                .addTextChangedListener(new TextWatcher() {
                    @Override
                    public void afterTextChanged(Editable s) {
                        try {
                            if (Integer.parseInt(s.toString()) > 255) {
                                s.replace(0, s.length(), "255");
                                return;
                            } else if (Integer.parseInt(s.toString()) < 0) {
                                s.replace(0, s.length(), "0");
                                return;
                            }
                            ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g))
                                    .setProgress(Integer.parseInt(s.toString()));
                        } catch (Exception e) {
                            ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g)).setProgress(0);
                            s.clear();
                        }
                    }

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

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                    }
                });
        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b)).setMax(255);
        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b))
                .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        if (fromUser) {
                            ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_b))
                                    .setText((progress == 0 ? "" : String.valueOf(progress)));
                        }
                        ((ImageView) view.findViewById(R.id.main_menu_popup_color_preview))
                                .setImageDrawable(new ColorDrawable(Color.rgb(
                                        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r))
                                                .getProgress(),
                                        ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g))
                                                .getProgress(),
                                        progress)));
                    }
                });
        ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_b))
                .addTextChangedListener(new TextWatcher() {
                    @Override
                    public void afterTextChanged(Editable s) {
                        try {
                            if (Integer.parseInt(s.toString()) > 255) {
                                s.replace(0, s.length(), "255");
                                return;
                            } else if (Integer.parseInt(s.toString()) < 0) {
                                s.replace(0, s.length(), "0");
                                return;
                            }
                            ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b))
                                    .setProgress(Integer.parseInt(s.toString()));
                        } catch (Exception e) {
                            ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b)).setProgress(0);
                            s.clear();
                        }
                    }

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

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                    }
                });
        ((ImageView) view.findViewById(R.id.main_menu_popup_color_preview))
                .setImageDrawable(new ColorDrawable(Color.rgb(prefs.getSliderBackgroundR(),
                        prefs.getSliderBackgroundG(), prefs.getSliderBackgroundB())));
        ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_r))
                .setText(String.valueOf(prefs.getSliderBackgroundR()));
        ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_g))
                .setText(String.valueOf(prefs.getSliderBackgroundG()));
        ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_b))
                .setText(String.valueOf(prefs.getSliderBackgroundB()));
        ((EditText) view.findViewById(R.id.main_menu_popup_timeout_editor)).setText(
                (prefs.getScreenTimeout() == 0L ? "" : String.valueOf(prefs.getScreenTimeout() / 1000L)));
        ((EditText) view.findViewById(R.id.main_menu_popup_timeout_editor))
                .addTextChangedListener(new TextWatcher() {
                    @Override
                    public void afterTextChanged(Editable s) {
                        if (s.toString().equals(""))
                            return;
                        try {
                            if (Long.parseLong(s.toString()) > 9999L)
                                s.replace(0, s.length(), "9999");
                            else if (Long.parseLong(s.toString()) < 0L)
                                s.replace(0, s.length(), "0");
                        } catch (Exception e) {
                            s.clear();
                        }
                    }

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

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                    }
                });
        ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                .setChecked(prefs.isInterfaceSlider());
        ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(0)
                                .setEnabled(((CheckBox) v).isChecked());
                        for (int i = 0; i < 3; i++) {
                            ((ViewGroup) ((ViewGroup) ((ViewGroup) view
                                    .findViewById(R.id.main_menu_popup_color)).getChildAt(1)).getChildAt(i))
                                            .getChildAt(0).setEnabled(((CheckBox) v).isChecked());
                            ((ViewGroup) ((ViewGroup) ((ViewGroup) view
                                    .findViewById(R.id.main_menu_popup_color)).getChildAt(1)).getChildAt(i))
                                            .getChildAt(1).setEnabled(((CheckBox) v).isChecked());
                        }
                        ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(2)
                                .setVisibility((((CheckBox) v).isChecked() ? View.VISIBLE : View.INVISIBLE));
                    }
                });
        ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(0).setEnabled(
                ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)).isChecked());
        for (int i = 0; i < 3; i++) {
            ((ViewGroup) ((ViewGroup) ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(1))
                    .getChildAt(i)).getChildAt(0)
                            .setEnabled(((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                                    .isChecked());
            ((ViewGroup) ((ViewGroup) ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(1))
                    .getChildAt(i)).getChildAt(1)
                            .setEnabled(((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                                    .isChecked());
        }
        ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(2).setVisibility(
                (((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)).isChecked()
                        ? View.VISIBLE
                        : View.INVISIBLE));
        view.findViewById(R.id.main_menu_popup_interface_caption)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)).toggle();
                        ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(0).setEnabled(
                                ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                                        .isChecked());
                        for (int i = 0; i < 3; i++) {
                            ((ViewGroup) ((ViewGroup) ((ViewGroup) view
                                    .findViewById(R.id.main_menu_popup_color)).getChildAt(1)).getChildAt(i))
                                            .getChildAt(0)
                                            .setEnabled(((CheckBox) view
                                                    .findViewById(R.id.main_menu_popup_interface_checkbox))
                                                            .isChecked());
                            ((ViewGroup) ((ViewGroup) ((ViewGroup) view
                                    .findViewById(R.id.main_menu_popup_color)).getChildAt(1)).getChildAt(i))
                                            .getChildAt(1)
                                            .setEnabled(((CheckBox) view
                                                    .findViewById(R.id.main_menu_popup_interface_checkbox))
                                                            .isChecked());
                        }
                        ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(2).setVisibility(
                                (((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                                        .isChecked() ? View.VISIBLE : View.INVISIBLE));
                    }
                });
        new AlertDialog.Builder(this).setView(view)
                .setPositiveButton(R.string.main_menu_popup_save_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        prefs.setBackgroundColorInverted(
                                ((CheckBox) view.findViewById(R.id.main_menu_popup_background_checkbox))
                                        .isChecked());
                        prefs.setInterfaceSlider(
                                ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox))
                                        .isChecked());
                        prefs.setSliderBackground(
                                ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r))
                                        .getProgress(),
                                ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g))
                                        .getProgress(),
                                ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b))
                                        .getProgress());
                        prefs.setScreenTimeout(
                                (((EditText) view.findViewById(R.id.main_menu_popup_timeout_editor)).getText()
                                        .toString().equals("")
                                                ? 0L
                                                : Long.parseLong(((EditText) view
                                                        .findViewById(R.id.main_menu_popup_timeout_editor))
                                                                .getText().toString())
                                                        * 1000L));
                        prefs.setOrientationFixed(
                                ((CheckBox) view.findViewById(R.id.main_menu_popup_orientation_checkbox))
                                        .isChecked());
                    }
                }).setNegativeButton(R.string.main_menu_popup_cancel_button, null).show();
        return true;
    case R.id.main_menu_help:
        new AlertDialog.Builder(this).setMessage(R.string.main_menu_help_message)
                .setTitle(R.string.main_menu_help_title)
                .setPositiveButton(R.string.main_menu_help_ok_button, null).setNegativeButton(
                        R.string.main_menu_help_question_button, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                startActivity(new Intent(Intent.ACTION_VIEW,
                                        Uri.parse("http://forum.xda-developers.com/showthread.php?t=2173226"))
                                                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                            }
                        })
                .show();
        return true;
    case R.id.main_menu_about:
        ViewGroup about = (ViewGroup) ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE))
                .inflate(R.layout.main_menu_about, null);
        ((TextView) about.getChildAt(0)).setMovementMethod(LinkMovementMethod.getInstance());
        new AlertDialog.Builder(this).setView(about).setTitle(R.string.main_menu_about_title)
                .setPositiveButton(R.string.main_menu_about_ok_button, null).show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:tv.acfun.a63.CommentsActivity.java

String getComment() {
    Editable text = SpannableStringBuilder.valueOf(mCommentText.getText());
    Quote quote = TextViewUtils.getLast(text, Quote.class);
    int start = text.getSpanStart(quote);
    int end = text.getSpanEnd(quote);
    if (start < 0)
        return text.toString();
    else if (start == 0) {
        return text.subSequence(end, text.length()).toString();
    } else/*w  w w  .j a  v a  2s.c o m*/
        return text.subSequence(0, start).toString() + text.subSequence(end, text.length()).toString();
}

From source file:demo.design.TextInputLayout.java

private void setEditText(EditText editText) {
    // If we already have an EditText, throw an exception
    if (mEditText != null) {
        throw new IllegalArgumentException("We already have an EditText, can only have one");
    }/*from  w w  w. j a  v a  2s.  com*/

    if (!(editText instanceof TextInputEditText)) {
        Log.i(LOG_TAG,
                "EditText added is not a TextInputEditText. Please switch to using that" + " class instead.");
    }

    mEditText = editText;

    // Use the EditText's typeface, and it's text size for our expanded text
    mCollapsingTextHelper.setTypefaces(mEditText.getTypeface());
    mCollapsingTextHelper.setExpandedTextSize(mEditText.getTextSize());

    final int editTextGravity = mEditText.getGravity();
    mCollapsingTextHelper.setCollapsedTextGravity(
            Gravity.TOP | (editTextGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK));
    mCollapsingTextHelper.setExpandedTextGravity(editTextGravity);

    // Add a TextWatcher so that we know when the text input has changed
    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            updateLabelState(true);
            if (mCounterEnabled) {
                updateCounter(s.length());
            }
        }

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

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

    // Use the EditText's hint colors if we don't have one set
    if (mDefaultTextColor == null) {
        mDefaultTextColor = mEditText.getHintTextColors();
    }

    // If we do not have a valid hint, try and retrieve it from the EditText, if enabled
    if (mHintEnabled && TextUtils.isEmpty(mHint)) {
        setHint(mEditText.getHint());
        // Clear the EditText's hint as we will display it ourselves
        mEditText.setHint(null);
    }

    if (mCounterView != null) {
        updateCounter(mEditText.getText().length());
    }

    if (mIndicatorArea != null) {
        adjustIndicatorPadding();
    }

    // Update the label visibility with no animation
    updateLabelState(false);
}

From source file:com.example.emachine.FXcalcActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_fxcalc);

    //    String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned";
    //    SharedPreferences sp = PreferenceManager
    //            .getDefaultSharedPreferences(this);
    //    sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true)
    //            .commit();
    //    ((MyApplication) getApplication()).component().inject(this);

    TextView todayView = (TextView) findViewById(R.id.date);

    long millis = getIntent().getLongExtra(KEY_MILLIS, -1);
    //    DateTime dateTime = (millis > 0) ? new DateTime(millis) : clock.getNow();
    //    todayView.setText(DateUtils.format(dateTime));

    btn_calc = (Button) findViewById(R.id.btn_calc);

    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager()
            .findFragmentById(R.id.navigation_drawer);
    mTitle = getTitle();/*  w  w  w  .  j  av a2s .com*/

    // Set up the drawer.

    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
    //    mNavigationDrawerFragment.setMenuVisibility(false);

    download();

    pb_us = (AnimatedProgressBar) findViewById(R.id.pb_us);
    pb_england = (AnimatedProgressBar) findViewById(R.id.pb_england);
    pb_euro = (AnimatedProgressBar) findViewById(R.id.pb_euro);
    pb_brazil = (AnimatedProgressBar) findViewById(R.id.pb_brazil);
    pb_japan = (AnimatedProgressBar) findViewById(R.id.pb_japan);

    et_us = (EditText) findViewById(R.id.et_us);
    tv_england = (TextView) findViewById(R.id.tv_england);
    tv_euro = (TextView) findViewById(R.id.tv_euro);
    tv_brazil = (TextView) findViewById(R.id.tv_brazil);
    tv_japan = (TextView) findViewById(R.id.tv_japan);

    appIcon = (View) findViewById(R.id.appIcon);
    cv_england = (View) findViewById(R.id.cv_england);
    cv_euro = (View) findViewById(R.id.cv_euro);
    cv_brazil = (View) findViewById(R.id.cv_brazil);
    cv_japan = (View) findViewById(R.id.cv_japan);
    observeGraph();

    et_us.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            if (s.length() > 0)
                clearScreen();
        }

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

        }
    });

    appIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hideKeyboard();
            ArrayList<String> dialogItemList = new ArrayList<String>();
            dialogItemList.add("BAD QA");
            dialogItemList.add("Curious, how about a field of fields?");
            //        showDialog("Field of Dreams, the grass is greener?", dialogItemList, dialogItemList.size());
            textDialog("Decisions, Decisions", "No logical way out now, so be curious");
        }
    });

    cv_england.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alert(getString(R.string.str_england_rate) + englandRate);
        }
    });

    cv_euro.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alert(getString(R.string.str_euro_rate) + euroRate);
        }
    });

    cv_brazil.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alert(getString(R.string.str_brazil_rate) + brazilRate);
        }
    });

    cv_japan.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alert(getString(R.string.str_japan_rate) + japanRate);
        }
    });
}

From source file:org.mariotaku.twidere.fragment.MessagesConversationFragment.java

private void setupEditText() {
    EditTextEnterHandler.attach(mEditText, new EnterListener() {
        @Override//from w ww .  j a v a  2 s .  com
        public boolean shouldCallListener() {
            return true;
        }

        @Override
        public boolean onHitEnter() {
            sendDirectMessage();
            return true;
        }
    }, mPreferences.getBoolean(KEY_QUICK_SEND, false));
    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(final Editable s) {
            mTextChanged = s.length() == 0;
        }

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

        }

        @Override
        public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
            if (mSendButton == null || s == null)
                return;
            mSendButton.setEnabled(mValidator.isValidDirectMessage(s.toString()));
        }
    });
}

From source file:me.albertonicoletti.latex.activities.EditorActivity.java

/**
 * Used to maintain the same indentation as the upper line
 * @param editable Text//w w  w .  j  a  v a 2 s .c o m
 * @param spannable Spannable
 * @param span Modified span
 */
private void autoIndentAndTabEditor(Editable editable, SpannableString spannable, RelativeSizeSpan span) {
    int beginIndex = spannable.getSpanStart(span);
    int endIndex = spannable.getSpanEnd(span);
    // If the last written character is a newline
    if (editable.length() > 0) {
        if (editable.charAt(endIndex - 1) == '\n') {
            int lineModified = editor.getLayout().getLineForOffset(beginIndex);
            int modifiedBeginIndex = editor.getLayout().getLineStart(lineModified);
            int modifiedEndIndex = editor.getLayout().getLineEnd(lineModified);
            String str = editable.subSequence(modifiedBeginIndex, modifiedEndIndex).toString();
            // Collects the whitespaces and tabulations in the upper line
            String whitespaces = "";
            int i = 0;
            while (str.charAt(i) == ' ' || str.charAt(i) == '\t') {
                whitespaces += str.charAt(i);
                i++;
            }
            // And inserts them in the newline
            editable.insert(beginIndex + 1, whitespaces);
        }
        if (editable.charAt(endIndex - 1) == '\t') {
            int tabSize = Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(this)
                    .getString(SettingsActivity.TAB_SIZE, ""));
            String whitespaces = "";
            for (int i = 0; i < tabSize; i++) {
                whitespaces += " ";
            }
            editable.replace(beginIndex, beginIndex + 1, whitespaces);
        }
    }
}

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);//from   w w w .j  a  v a2  s  .  co  m

    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.jamiealtizer.cordova.inappbrowser.InAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject//www. ja v a 2s .co  m
 */
public String showWebPage(final String url, HashMap<String, Boolean> features) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    showZoomControls = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean zoom = features.get(ZOOM);
        if (zoom != null) {
            showZoomControls = zoom.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON);
        if (hardwareBack != null) {
            hadwareBackButton = hardwareBack.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }

    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            final Context ctx = cordova.getActivity();
            dialog = new InAppBrowserDialog(ctx, android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setInAppBroswer(getInAppBrowser());

            // Main container layout
            LinearLayout main = new LinearLayout(ctx);
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(ctx);
            //Please, no more black!
            toolbar.setBackgroundColor(android.graphics.Color.LTGRAY); // JAMIE REVIEW
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(ctx);
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            final ButtonAwesome back = new ButtonAwesome(ctx);
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            back.setBackgroundResource(ExternalResourceHelper.getDrawable(ctx, "buttonbackground"));
            back.setTextColor(ExternalResourceHelper.getColor(ctx, "gray"));
            back.setText(ExternalResourceHelper.getStrings(ctx, "fa_chevron_left"));
            back.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
            //            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
            //                {
            //                    back.setBackgroundDrawable(backIcon);
            //                }
            //                else
            //                {
            //                    back.setBackground(backIcon);
            //                }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            final ButtonAwesome forward = new ButtonAwesome(ctx);
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            forward.setBackgroundResource(ExternalResourceHelper.getDrawable(ctx, "buttonbackground"));
            forward.setTextColor(ExternalResourceHelper.getColor(ctx, "gray"));
            forward.setText(ExternalResourceHelper.getStrings(ctx, "fa_chevron_right"));
            forward.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
            //            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
            //                {
            //                    forward.setBackgroundDrawable(fwdIcon);
            //                }
            //                else
            //                {
            //                    forward.setBackground(fwdIcon);
            //                }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // external button
            ButtonAwesome external = new ButtonAwesome(ctx);
            RelativeLayout.LayoutParams externalLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            externalLayoutParams.addRule(RelativeLayout.RIGHT_OF, 3);
            external.setLayoutParams(externalLayoutParams);
            external.setContentDescription("Back Button");
            external.setId(7);
            external.setBackgroundResource(ExternalResourceHelper.getDrawable(ctx, "buttonbackground"));
            external.setTextColor(ExternalResourceHelper.getColor(ctx, "white"));
            external.setText(ExternalResourceHelper.getStrings(ctx, "fa_external_link"));
            external.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
            external.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    openExternal(edittext.getText().toString());
                    closeDialog();
                }
            });

            // Edit Text Box
            edittext = new EditText(ctx);
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    if (s.length() > 0) {
                        if (inAppWebView.canGoBack()) {
                            back.setTextColor(ExternalResourceHelper.getColor(ctx, "white"));
                        } else {
                            back.setTextColor(ExternalResourceHelper.getColor(ctx, "gray"));
                        }
                        if (inAppWebView.canGoForward()) {
                            forward.setTextColor(ExternalResourceHelper.getColor(ctx, "white"));
                        } else {
                            forward.setTextColor(ExternalResourceHelper.getColor(ctx, "gray"));
                        }
                    }
                }

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

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close/Done button
            ButtonAwesome close = new ButtonAwesome(ctx);
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            close.setContentDescription("Close Button");
            close.setId(5);
            close.setBackgroundResource(ExternalResourceHelper.getDrawable(ctx, "buttonbackground"));
            close.setText(ExternalResourceHelper.getStrings(ctx, "fa_times"));
            close.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
            close.setTextColor(ExternalResourceHelper.getColor(ctx, "white"));
            //            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
            //                {
            //                    close.setBackgroundDrawable(closeIcon);
            //                }
            //                else
            //                {
            //                    close.setBackground(closeIcon);
            //                }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            inAppWebView = new WebView(ctx);
            inAppWebView.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(showZoomControls);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null ? true
                    : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = ctx.getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE)
                        .getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (clearAllCache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);
            actionButtonContainer.addView(external);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            if (getShowLocationBar()) {
                toolbar.addView(edittext);
            }
            toolbar.setBackgroundColor(ExternalResourceHelper.getColor(ctx, "green"));
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            //if (getShowLocationBar()) {
            // Add our toolbar to our main view/layout
            main.addView(toolbar);
            //}

            // Add our webview to our main view/layout
            main.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.ibuildapp.romanblack.FanWallPlugin.FanWallPlugin.java

@Override
public void afterTextChanged(Editable editable) {
    if (editable.length() > 150) {
        editable.replace(editable.length() - 1, editable.length(), "");
        Toast.makeText(this, R.string.romanblack_fanwall_alert_big_text, Toast.LENGTH_SHORT).show();
    }/*from  w w  w .j a  v a 2  s  .  c o m*/
}