Search in sources :

Example 11 with TextWatcher

use of android.text.TextWatcher in project FBReaderJ by geometer.

the class FileChooserActivity method doCreateNewDir.

// doSwitchViewType()
/**
     * Confirms user to create new directory.
     */
private void doCreateNewDir() {
    if (mFileProvider instanceof LocalFileProvider && !Utils.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        Dlg.toast(this, R.string.afc_msg_app_doesnot_have_permission_to_create_files, Dlg._LengthShort);
        return;
    }
    if ((getLocation() instanceof File)) {
        if (!((File) getLocation()).canWrite()) {
            Dlg.toast(this, R.string.afc_msg_app_cant_create_folder, Dlg._LengthShort);
            return;
        }
    }
    final AlertDialog _dlg = Dlg.newDlg(this);
    View view = getLayoutInflater().inflate(R.layout.afc_simple_text_input_view, null);
    final EditText _textFile = (EditText) view.findViewById(R.id.afc_simple_text_input_view_text1);
    _textFile.setHint(mTextResources.get("folderNameHint"));
    _textFile.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                Ui.hideSoftKeyboard(FileChooserActivity.this, _textFile.getWindowToken());
                _dlg.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
                return true;
            }
            return false;
        }
    });
    _dlg.setView(view);
    _dlg.setTitle(mTextResources.get("newFolder"));
    _dlg.setIcon(android.R.drawable.ic_menu_add);
    _dlg.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String name = _textFile.getText().toString().trim();
            if (!FileUtils.isFilenameValid(name)) {
                Dlg.toast(FileChooserActivity.this, getString(R.string.afc_pmsg_filename_is_invalid, name), Dlg._LengthShort);
                return;
            }
            final IFileProvider fileProvider = mFileProvider;
            final IFile location = getLocation();
            if (fileProvider == null || location == null) {
                return;
            }
            IFile dir = fileProvider.fromPath(String.format("%s/%s", location.getAbsolutePath(), name));
            if (dir.mkdir()) {
                Dlg.toast(FileChooserActivity.this, getString(R.string.afc_msg_done), Dlg._LengthShort);
                setLocation(getLocation(), null);
            } else
                Dlg.toast(FileChooserActivity.this, getString(R.string.afc_pmsg_cannot_create_folder, name), Dlg._LengthShort);
        }
    });
    _dlg.show();
    final Button _btnOk = _dlg.getButton(DialogInterface.BUTTON_POSITIVE);
    _btnOk.setEnabled(false);
    _textFile.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {
            _btnOk.setEnabled(FileUtils.isFilenameValid(s.toString().trim()));
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) IFileProvider(group.pals.android.lib.ui.filechooser.services.IFileProvider) IFile(group.pals.android.lib.ui.filechooser.io.IFile) DialogInterface(android.content.DialogInterface) LocalFileProvider(group.pals.android.lib.ui.filechooser.services.LocalFileProvider) GridView(android.widget.GridView) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) IFile(group.pals.android.lib.ui.filechooser.io.IFile) File(java.io.File)

Example 12 with TextWatcher

use of android.text.TextWatcher in project FBReaderJ by geometer.

the class EditBookmarkActivity method onCreate.

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.edit_bookmark);
    myBookmark = FBReaderIntents.getBookmarkExtra(getIntent());
    if (myBookmark == null) {
        finish();
        return;
    }
    final DisplayMetrics dm = getResources().getDisplayMetrics();
    final int width = Math.min((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 500, dm), dm.widthPixels * 9 / 10);
    final int height = Math.min((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 350, dm), dm.heightPixels * 9 / 10);
    final TabHost tabHost = (TabHost) findViewById(R.id.edit_bookmark_tabhost);
    tabHost.setLayoutParams(new FrameLayout.LayoutParams(new ViewGroup.LayoutParams(width, height)));
    tabHost.setup();
    addTab(tabHost, "text", R.id.edit_bookmark_content_text);
    addTab(tabHost, "style", R.id.edit_bookmark_content_style);
    addTab(tabHost, "delete", R.id.edit_bookmark_content_delete);
    final ZLStringOption currentTabOption = new ZLStringOption("LookNFeel", "EditBookmark", "text");
    tabHost.setCurrentTabByTag(currentTabOption.getValue());
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        public void onTabChanged(String tag) {
            if (!"delete".equals(tag)) {
                currentTabOption.setValue(tag);
            }
        }
    });
    final EditText editor = (EditText) findViewById(R.id.edit_bookmark_text);
    editor.setText(myBookmark.getText());
    final int len = editor.getText().length();
    editor.setSelection(len, len);
    final Button saveTextButton = (Button) findViewById(R.id.edit_bookmark_save_text_button);
    saveTextButton.setEnabled(false);
    saveTextButton.setText(myResource.getResource("saveText").getValue());
    saveTextButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            myCollection.bindToService(EditBookmarkActivity.this, new Runnable() {

                public void run() {
                    myBookmark.setText(editor.getText().toString());
                    myCollection.saveBookmark(myBookmark);
                    saveTextButton.setEnabled(false);
                }
            });
        }
    });
    editor.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence sequence, int start, int before, int count) {
            final String originalText = myBookmark.getText();
            saveTextButton.setEnabled(!originalText.equals(editor.getText().toString()));
        }

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

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    final Button deleteButton = (Button) findViewById(R.id.edit_bookmark_delete_button);
    deleteButton.setText(myResource.getResource("deleteBookmark").getValue());
    deleteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            myCollection.bindToService(EditBookmarkActivity.this, new Runnable() {

                public void run() {
                    myCollection.deleteBookmark(myBookmark);
                    finish();
                }
            });
        }
    });
}
Also used : ZLStringOption(org.geometerplus.zlibrary.core.options.ZLStringOption) DisplayMetrics(android.util.DisplayMetrics) AmbilWarnaPrefWidgetView(yuku.ambilwarna.widget.AmbilWarnaPrefWidgetView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Example 13 with TextWatcher

use of android.text.TextWatcher in project TourGuide by worker8.

the class AdjustPaddingOverlayActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mActivity = this;
    setContentView(R.layout.activity_overlay_customization);
    final Button button = (Button) findViewById(R.id.button);
    Button next_button = (Button) findViewById(R.id.next_button);
    TextInputLayout textInputLayout = (TextInputLayout) findViewById(R.id.input_layout);
    final EditText paddingET = (EditText) findViewById(R.id.padding_edit_text);
    paddingET.setText(String.valueOf(10));
    textInputLayout.setVisibility(View.VISIBLE);
    next_button.setVisibility(View.GONE);
    final ToolTip toolTip = new ToolTip().setTitle("Hello!").setDescription(String.format("Current OVERLAY Padding: %s", paddingET.getText().toString()));
    final Overlay overlay = new Overlay().setBackgroundColor(Color.parseColor("#AAFF0000")).disableClick(false).disableClickThroughHole(false).setStyle(Overlay.Style.ROUNDED_RECTANGLE).setHolePadding(Integer.valueOf(paddingET.getText().toString())).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mTutorialHandler.cleanUp();
        }
    });
    // the return handler is used to manipulate the cleanup of all the tutorial elements
    mTutorialHandler = TourGuide.init(this).with(TourGuide.Technique.CLICK).setPointer(null).setToolTip(toolTip).setOverlay(overlay).playOn(button);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mTutorialHandler.cleanUp();
            mTutorialHandler.playOn(button);
        }
    });
    button.setText("   show   ");
    paddingET.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) {
            overlay.setHolePadding((charSequence.length() > 0 && TextUtils.isDigitsOnly(charSequence)) ? Integer.valueOf(charSequence.toString()) : 10);
            toolTip.setDescription(String.format("Current Overlay Padding: %s", charSequence));
            mTutorialHandler.setOverlay(overlay);
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
}
Also used : EditText(android.widget.EditText) ToolTip(tourguide.tourguide.ToolTip) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(android.support.design.widget.TextInputLayout) Overlay(tourguide.tourguide.Overlay) View(android.view.View)

Example 14 with TextWatcher

use of android.text.TextWatcher in project XobotOS by xamarin.

the class TextView method sendAfterTextChanged.

/**
     * Not private so it can be called from an inner class without going
     * through a thunk.
     */
void sendAfterTextChanged(Editable text) {
    if (mListeners != null) {
        final ArrayList<TextWatcher> list = mListeners;
        final int count = list.size();
        for (int i = 0; i < count; i++) {
            list.get(i).afterTextChanged(text);
        }
    }
}
Also used : TextWatcher(android.text.TextWatcher) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 15 with TextWatcher

use of android.text.TextWatcher in project Android-skin-support by ximsfei.

the class MDFirstFragment method initTextInputLayout2.

private void initTextInputLayout2() {
    textInputLayout2 = (TextInputLayout) mView.findViewById(R.id.textInputLayout2);
    textInputLayout2.setHint("请输入4位学号");
    editText2 = (EditText) mView.findViewById(R.id.editText2);
    editText2.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) {
            if (charSequence.length() > 4) {
                editText2.setError("学号输入错误");
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Aggregations

TextWatcher (android.text.TextWatcher)192 Editable (android.text.Editable)158 View (android.view.View)96 TextView (android.widget.TextView)75 Paint (android.graphics.Paint)37 ImageView (android.widget.ImageView)30 TextPaint (android.text.TextPaint)28 EditText (android.widget.EditText)28 Intent (android.content.Intent)25 KeyEvent (android.view.KeyEvent)24 AdapterView (android.widget.AdapterView)21 ListView (android.widget.ListView)17 RecyclerView (android.support.v7.widget.RecyclerView)15 DialogInterface (android.content.DialogInterface)13 SuppressLint (android.annotation.SuppressLint)12 OnClickListener (android.view.View.OnClickListener)12 Button (android.widget.Button)12 InputMethodManager (android.view.inputmethod.InputMethodManager)11 AlertDialog (android.app.AlertDialog)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)9