Search in sources :

Example 31 with InputFilter

use of android.text.InputFilter in project seven_develop by seven123456.

the class RxTool method setEdDecimal.

public static void setEdDecimal(EditText editText, int count) {
    if (count < 1) {
        count = 1;
    }
    editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
    // 设置字符过滤
    final int finalCount = count;
    editText.setFilters(new InputFilter[] { new InputFilter() {

        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            if (source.equals(".") && dest.toString().length() == 0) {
                return "0.";
            }
            if (dest.toString().contains(".")) {
                int index = dest.toString().indexOf(".");
                int mlength = dest.toString().substring(index).length();
                if (mlength == finalCount) {
                    return "";
                }
            }
            return null;
        }
    } });
}
Also used : InputFilter(android.text.InputFilter) Spanned(android.text.Spanned)

Example 32 with InputFilter

use of android.text.InputFilter in project Roblu by wdavies973.

the class EventCreateMethodPicker method importPublicRobluCloudEvent.

private void importPublicRobluCloudEvent() {
    // check for an internet connection
    if (!Utils.hasInternetConnection(getApplicationContext())) {
        Utils.showSnackbar(findViewById(R.id.advsettings), getApplicationContext(), "You are not connected to the internet", true, 0);
        return;
    }
    /*
             * We need to make sure that this thread has access to the internet
             */
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
    StrictMode.setThreadPolicy(policy);
    final RSettings settings = new IO(getApplicationContext()).loadSettings();
    RUI rui = settings.getRui();
    AlertDialog.Builder builder = new AlertDialog.Builder(EventCreateMethodPicker.this);
    LinearLayout layout = new LinearLayout(EventCreateMethodPicker.this);
    layout.setOrientation(LinearLayout.VERTICAL);
    // this is the team code input edit text
    final AppCompatEditText input = new AppCompatEditText(EventCreateMethodPicker.this);
    Utils.setInputTextLayoutColor(rui.getAccent(), null, input);
    input.setHighlightColor(rui.getAccent());
    input.setHintTextColor(rui.getText());
    input.setTextColor(rui.getText());
    input.setInputType(InputType.TYPE_CLASS_NUMBER);
    InputFilter[] FilterArray = new InputFilter[1];
    FilterArray[0] = new InputFilter.LengthFilter(30);
    input.setFilters(FilterArray);
    layout.addView(input);
    builder.setView(layout);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            importRobluCloudEvent(Integer.parseInt(input.getText().toString()));
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    TextView view = new TextView(EventCreateMethodPicker.this);
    view.setTextSize(Utils.DPToPX(getApplicationContext(), 5));
    view.setPadding(Utils.DPToPX(getApplicationContext(), 18), Utils.DPToPX(getApplicationContext(), 18), Utils.DPToPX(getApplicationContext(), 18), Utils.DPToPX(getApplicationContext(), 18));
    view.setText("FRC team number:");
    view.setTextColor(rui.getText());
    AlertDialog dialog = builder.create();
    dialog.setCustomTitle(view);
    if (dialog.getWindow() != null) {
        dialog.getWindow().getAttributes().windowAnimations = rui.getAnimation();
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(rui.getBackground()));
    }
    dialog.show();
    dialog.getButton(Dialog.BUTTON_NEGATIVE).setTextColor(rui.getAccent());
    dialog.getButton(Dialog.BUTTON_POSITIVE).setTextColor(rui.getAccent());
}
Also used : AlertDialog(android.app.AlertDialog) InputFilter(android.text.InputFilter) DialogInterface(android.content.DialogInterface) IO(com.cpjd.roblu.io.IO) FastDialogBuilder(com.cpjd.roblu.ui.dialogs.FastDialogBuilder) RUI(com.cpjd.roblu.models.RUI) StrictMode(android.os.StrictMode) AppCompatEditText(android.support.v7.widget.AppCompatEditText) ColorDrawable(android.graphics.drawable.ColorDrawable) TextView(android.widget.TextView) RSettings(com.cpjd.roblu.models.RSettings) LinearLayout(android.widget.LinearLayout)

Example 33 with InputFilter

use of android.text.InputFilter in project caronae-android by caronae.

the class MyProfileFrag method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_my_profile, container, false);
    ButterKnife.bind(this, view);
    callbackManager = ((MainAct) getActivity()).getFbCallbackManager();
    carOwner_sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            carOwnerSw();
        }
    });
    carPlate_et.setFilters(new InputFilter[] { new InputFilter.AllCaps() });
    loginButton.setReadPermissions("user_friends");
    loginButton.setFragment(this);
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.i("face", "onSuccess = " + loginResult.toString());
            Profile profile = Profile.getCurrentProfile();
            if (profile != null) {
                final String faceId = profile.getId();
                CaronaeAPI.service(getContext()).saveFaceId(new IdForJson(faceId)).enqueue(new Callback<ResponseBody>() {

                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        if (response.isSuccessful()) {
                            Log.i("saveFaceId", "face id saved");
                            User user = App.getUser();
                            user.setFaceId(faceId);
                            SharedPref.saveUser(user);
                        } else {
                            Util.treatResponseFromServer(response);
                            Util.toast(R.string.frag_myprofile_errorSaveFaceId);
                            Log.e("saveFaceId", response.message());
                        }
                    }

                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {
                        Util.toast(R.string.frag_myprofile_errorSaveFaceId);
                        Log.e("saveFaceId", t.getMessage());
                    }
                });
            }
        }

        @Override
        public void onCancel() {
            Log.i("face", "onCancel");
        }

        @Override
        public void onError(FacebookException exception) {
            Util.toast(R.string.frag_myprofile_errorFaceLogin);
            Log.e("face", "onError = " + exception.toString());
        }
    });
    setFieldValidatorsListeners();
    User user = App.getUser();
    if (user != null) {
        fillUserFields(user);
        CaronaeAPI.service(getContext()).getRidesHistoryCount(user.getDbId() + "").enqueue(new Callback<HistoryRideCountForJson>() {

            @Override
            public void onResponse(Call<HistoryRideCountForJson> call, Response<HistoryRideCountForJson> response) {
                if (response.isSuccessful()) {
                    HistoryRideCountForJson historyRideCountForJson = response.body();
                    ridesOffered_tv.setText(String.valueOf(historyRideCountForJson.getOfferedCount()));
                    ridesTaken_tv.setText(String.valueOf(historyRideCountForJson.getTakenCount()));
                } else {
                    Util.treatResponseFromServer(response);
                    Util.toast(R.string.act_profile_errorCountRidesHistory);
                    Log.e("getRidesHistoryCount", response.message());
                }
            }

            @Override
            public void onFailure(Call<HistoryRideCountForJson> call, Throwable t) {
                Util.toast(R.string.act_profile_errorCountRidesHistory);
                Log.e("getRidesHistoryCount", t.getMessage());
            }
        });
    }
    setETFormat();
    return view;
}
Also used : Call(retrofit2.Call) InputFilter(android.text.InputFilter) User(br.ufrj.caronae.models.User) LoginResult(com.facebook.login.LoginResult) CaretString(com.redmadrobot.inputmask.model.CaretString) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) Profile(com.facebook.Profile) Response(retrofit2.Response) FacebookCallback(com.facebook.FacebookCallback) Callback(retrofit2.Callback) FacebookException(com.facebook.FacebookException) IdForJson(br.ufrj.caronae.models.modelsforjson.IdForJson) HistoryRideCountForJson(br.ufrj.caronae.models.modelsforjson.HistoryRideCountForJson) CompoundButton(android.widget.CompoundButton)

Example 34 with InputFilter

use of android.text.InputFilter in project Gadgetbridge by Freeyourgadget.

the class ReminderDetails method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_reminder_details);
    reminder = (Reminder) getIntent().getSerializableExtra(Reminder.EXTRA_REMINDER);
    if (reminder == null) {
        GB.toast("No reminder provided to ReminderDetails Activity", Toast.LENGTH_LONG, GB.ERROR);
        finish();
        return;
    }
    reminderRepeat = findViewById(R.id.reminder_repeat);
    reminderDate = findViewById(R.id.reminder_date);
    reminderTime = findViewById(R.id.reminder_time);
    reminderText = findViewById(R.id.reminder_message);
    device = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE);
    final DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
    final String[] repeatStrings = getResources().getStringArray(R.array.reminder_repeat);
    repeatAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, repeatStrings);
    final View cardRepeat = findViewById(R.id.card_repeat);
    cardRepeat.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new AlertDialog.Builder(ReminderDetails.this).setAdapter(repeatAdapter, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    reminder.setRepetition(i);
                    updateUiFromReminder();
                }
            }).create().show();
        }
    });
    final View cardDate = findViewById(R.id.card_date);
    cardDate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final Calendar date = new GregorianCalendar();
            date.setTime(reminder.getDate());
            new DatePickerDialog(ReminderDetails.this, ReminderDetails.this, date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH)).show();
        }
    });
    final View cardTime = findViewById(R.id.card_time);
    cardTime.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new TimePickerDialog(ReminderDetails.this, ReminderDetails.this, reminder.getDate().getHours(), reminder.getDate().getMinutes(), DateFormat.is24HourFormat(GBApplication.getContext())).show();
        }
    });
    reminderText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(coordinator.getMaximumReminderMessageLength()) });
    reminderText.addTextChangedListener(new TextWatcher() {

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

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

        @Override
        public void afterTextChanged(final Editable s) {
            reminder.setMessage(s.toString());
        }
    });
    final FloatingActionButton fab = findViewById(R.id.fab_save);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            updateReminder();
            ReminderDetails.this.setResult(1);
            finish();
        }
    });
    updateUiFromReminder();
}
Also used : InputFilter(android.text.InputFilter) DialogInterface(android.content.DialogInterface) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) TimePickerDialog(android.app.TimePickerDialog) View(android.view.View) TextView(android.widget.TextView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator)

Example 35 with InputFilter

use of android.text.InputFilter in project NoteText by ViWu.

the class MainMenu method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_menu);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionbar = getSupportActionBar();
    initializeToolbar(toolbar, actionbar);
    // set up grid and insert new set
    gvItems = (GridView) findViewById(R.id.gvItems);
    // Represents each item in gridView
    Names = new ArrayList<String>();
    newSet = new Set();
    // set up adapter for grid
    itemsAdapter = new ArrayAdapter<String>(MainMenu.this, R.layout.grid_item, Names);
    gvItems.setAdapter(itemsAdapter);
    setupListViewListener();
    // create a floating action button to help the user
    FloatingActionButton help = (FloatingActionButton) findViewById(R.id.help);
    assert help != null;
    help.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Click on the name of the set to edit. Hold down to delete/rename. To add sets, tap the button to the left.", Snackbar.LENGTH_LONG).setAction("Action", null).show();
        }
    });
    // add button: Creates a popup window to type in name of new set
    FloatingActionButton add = (FloatingActionButton) findViewById(R.id.add);
    assert add != null;
    add.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {
            AlertDialog.Builder alert = new AlertDialog.Builder(MainMenu.this);
            final EditText setNameField = new EditText(MainMenu.this);
            alert.setMessage("Enter Name of New Set");
            alert.setTitle("Create New Set");
            alert.setView(setNameField);
            setNameField.requestFocus();
            final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
            setNameField.setFilters(new InputFilter[] { new InputFilter.LengthFilter(25) });
            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    String itemText = setNameField.getText().toString();
                    if (itemText.length() > 0) {
                        fileCreate(itemText, view);
                        newSet.setName(itemText);
                        Sets.add(newSet);
                        gvItems.smoothScrollToPosition(itemsAdapter.getCount() - 1);
                        setCount++;
                    } else {
                        String msg = "Create set failed! Set names need to be at least one character long!";
                        errorDialog(msg);
                    }
                    checkNoSetExists();
                    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, InputMethodManager.RESULT_UNCHANGED_SHOWN);
                }
            });
            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, InputMethodManager.RESULT_UNCHANGED_SHOWN);
                }
            });
            alert.show();
        }
    });
    loadInternalStorage();
    checkNoSetExists();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) InputFilter(android.text.InputFilter) DialogInterface(android.content.DialogInterface) InputMethodManager(android.view.inputmethod.InputMethodManager) GridView(android.widget.GridView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) FloatingActionButton(android.support.design.widget.FloatingActionButton) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

InputFilter (android.text.InputFilter)86 EditText (android.widget.EditText)31 TextView (android.widget.TextView)27 View (android.view.View)26 DialogInterface (android.content.DialogInterface)18 AlertDialog (android.app.AlertDialog)17 Paint (android.graphics.Paint)12 Editable (android.text.Editable)12 Spanned (android.text.Spanned)10 TextPaint (android.text.TextPaint)10 LinearLayout (android.widget.LinearLayout)10 TextWatcher (android.text.TextWatcher)9 Bundle (android.os.Bundle)8 SpannableStringBuilder (android.text.SpannableStringBuilder)8 ImageView (android.widget.ImageView)8 SmallTest (android.test.suitebuilder.annotation.SmallTest)7 Button (android.widget.Button)7 Context (android.content.Context)6 AlertDialog (android.support.v7.app.AlertDialog)6 Utf8ByteLengthFilter (com.android.settings.bluetooth.Utf8ByteLengthFilter)6