Example usage for android.text InputFilter InputFilter

List of usage examples for android.text InputFilter InputFilter

Introduction

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

Prototype

InputFilter

Source Link

Usage

From source file:org.egov.android.view.activity.RegisterActivity.java

/**
 * It is used to initialize an activity. An Activity is an application component that provides a
 * screen with which users can interact in order to do something, To initialize the
 * RegisterActivity.Set click listener to the save button.
 *//*from   w ww  .jav  a  2s . c  o m*/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    ((Button) findViewById(R.id.register_doRegister)).setOnClickListener(this);
    ((Button) findViewById(R.id.btngotit)).setOnClickListener(this);

    sharedpreferences = getApplicationContext().getSharedPreferences(getString(R.string.app_name), 0); // 0 - for private mode

    if (AndroidLibrary.getInstance().getConfig().get("api.multicities", "false").equals("true")) {
        isMulticity = true;
        Spinner citydropdown = (Spinner) findViewById(R.id.citydropdown);
        if (isInternetAvailable()) {
            new getCitiesFromURL(RegisterActivity.this, citydropdown)
                    .execute(AndroidLibrary.getInstance().getConfig().getString("app.citiesJsonUrl"));
        } else {
            Toast.makeText(getApplicationContext(), "No Internet Connection!", Toast.LENGTH_LONG).show();
            this.finish();
        }
    } else {
        ((LinearLayout) findViewById(R.id.citydropdowncontainer)).setVisibility(View.GONE);
        baseServerURL = sharedpreferences.getString("api.baseUrl", null);
    }

    LinearLayout viewpwd = (LinearLayout) findViewById(R.id.passwordmsgcontainer);

    if (!sharedpreferences.getBoolean("register.pwdinfo", false)) {
        ((TextView) findViewById(R.id.passwordmsg)).setText(getPasswordConstraintInformation());
        viewpwd.setVisibility(View.VISIBLE);
    } else {
        viewpwd.setVisibility(View.GONE);
    }

    //name validation
    ((EditText) findViewById(R.id.register_name)).setFilters(new InputFilter[] { new InputFilter() {
        @Override
        public CharSequence filter(CharSequence src, int start, int end, Spanned dst, int dstart, int dend) {
            if (src.equals("")) { // for backspace
                return src;
            }
            if (src.toString().matches("[a-zA-Z ]+")) {
                return src;
            }
            return "";
        }
    } });

}

From source file:com.awt.supark.EditCar.java

public void radioListener() {
    InputFilter charFilter = filter = new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            for (int i = start; i < end; i++) {
                if (!Character.isLetterOrDigit(source.charAt(i))) {
                    return "";
                }/*from  w w  w.j  a v  a  2 s .  co  m*/
            }
            return null;
        }
    };
    if (radioNewSrb.isChecked()) {
        txtCity.setVisibility(View.VISIBLE);
        licensePlate.setBackgroundDrawable(getResources().getDrawable(R.drawable.licenseplate));

        updateLicensePlate(licenseNum);
        //txtNum.setFilters(new InputFilter[]{filter, new InputFilter.LengthFilter(7), new InputFilter.AllCaps()});
        carLicense.setFilters(
                new InputFilter[] { new InputFilter.LengthFilter(8), new InputFilter.AllCaps(), charFilter });
    } else if (radioGeneric.isChecked()) {
        txtCity.setVisibility(View.GONE);
        licensePlate.setBackgroundDrawable(getResources().getDrawable(R.drawable.licenseplate2));

        // Reset
        txtCity.setText("");
        updateLicensePlate(licenseNum);
        //txtNum.setFilters(new InputFilter[]{filter, new InputFilter.LengthFilter(12), new InputFilter.AllCaps()});
        carLicense.setFilters(
                new InputFilter[] { new InputFilter.LengthFilter(12), new InputFilter.AllCaps(), charFilter });
    }
}

From source file:com.amberfog.countryflagsdemo.BaseFlagFragment.java

protected void initUI(View rootView) {
    mSpinner = (Spinner) rootView.findViewById(R.id.spinner);
    mSpinner.setOnItemSelectedListener(mOnItemSelectedListener);

    mAdapter = new CountryAdapter(getActivity());

    mSpinner.setAdapter(mAdapter);//from www.  j av a  2s . c  om

    mPhoneEdit = (EditText) rootView.findViewById(R.id.phone);
    mPhoneEdit.addTextChangedListener(new CustomPhoneNumberFormattingTextWatcher(mOnPhoneChangedListener));
    InputFilter filter = new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            for (int i = start; i < end; i++) {
                char c = source.charAt(i);
                if (dstart > 0 && !Character.isDigit(c)) {
                    return "";
                }
            }
            return null;
        }
    };

    mPhoneEdit.setFilters(new InputFilter[] { filter });

    mPhoneEdit.setImeOptions(EditorInfo.IME_ACTION_SEND);
    mPhoneEdit.setImeActionLabel(getString(R.string.label_send), EditorInfo.IME_ACTION_SEND);
    mPhoneEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                send();
                return true;
            }
            return false;
        }
    });

}

From source file:org.egov.android.view.activity.EditProfileActivity.java

/**
 * To initialize and set the layout for the ProfileActivity.Set click listeners to the save
 * changes, change picture and calendar icon. Here we have checked the api level to set the
 * layout. If api level is greater than 13, then call activity_edit_profile layout else call
 * activity_lower_version_edit_profile layout. activity_edit_profile layout contains
 * EGovRoundedImageView component which is not supported in lower api levels. get all the user
 * profile field values from the intent that is passed from the Profile Activity and displays
 * those values to the corresponding UI fields of EditProfile Layout StorageManager is the
 * interface to the systems' storage service. The storage manager handles storage-related items.
 * profile picture is stored in /egovernments/profile directory on device storage area. profile
 * picture is displayed using setImageBitmap method.
 *///from   w w  w. j a  va2 s.  co  m
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    apiLevel = AndroidLibrary.getInstance().getSession().getInt("api_level", 0);
    if (apiLevel > 13) {
        setContentView(R.layout.activity_edit_profile);
    } else {
        setContentView(R.layout.activity_lower_version_edit_profile);
    }

    ((Button) findViewById(R.id.editprofile_doEditprofile)).setOnClickListener(this);
    ((Button) findViewById(R.id.changepicture)).setOnClickListener(this);
    ((ImageView) findViewById(R.id.edit_profile_calendar)).setOnClickListener(this);

    mobileNo = getIntent().getExtras().getString("mobileNo");
    userName = getIntent().getExtras().getString("userName");
    mailId = getIntent().getExtras().getString("mailId");
    gender = getIntent().getExtras().getString("gender");
    altContactNumber = getIntent().getExtras().getString("altContactNumber");
    dateOfBirth = getIntent().getExtras().getString("dateOfBirth");
    panCardNumber = getIntent().getExtras().getString("panCardNumber");
    aadhaarCardNumber = getIntent().getExtras().getString("aadhaarCardNumber");

    ((EditText) findViewById(R.id.edit_profile_name)).setText(userName);
    ((EditText) findViewById(R.id.edit_profile_alt_contact)).setText(altContactNumber);
    ((EditText) findViewById(R.id.edit_profile_pan)).setText(panCardNumber);
    ((EditText) findViewById(R.id.edit_profile_aadhaar)).setText(aadhaarCardNumber);
    ((TextView) findViewById(R.id.edit_profile_dob)).setText(dateOfBirth);

    InputFilter filter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            for (int i = start; i < end; i++) {
                if (!Character.isLetterOrDigit(source.charAt(i))) {
                    return "";
                }
            }
            return null;
        }
    };

    ((EditText) findViewById(R.id.edit_profile_pan)).setFilters(new InputFilter[] { filter });

    int selected_gender = (gender.equalsIgnoreCase("male")) ? R.id.male
            : (gender.equalsIgnoreCase("female")) ? R.id.female : R.id.male;

    ((RadioGroup) findViewById(R.id.gender)).check(selected_gender);

    StorageManager sm = new StorageManager();
    Object[] obj = sm.getStorageInfo(EditProfileActivity.this);
    profPath = obj[0].toString() + "/egovernments/profile";
    String path = profPath + "/photo_" + mobileNo + ".jpg";
    profileImage = new File(profPath + "/photo_temp_user.jpg");
    File imgFile = new File(path);
    if (imgFile.exists()) {
        ((ImageView) findViewById(R.id.profile_image)).setImageBitmap(_getBitmapImage(path));
    }
    if (profileImage.exists()) {
        profileImage.delete();
    }
}

From source file:de.schildbach.wallet.ui.RestoreWalletFromSeedDialogFragment.java

private void setupPasswordView() {
    passwordView.post(new Runnable() {
        @Override//from  w w w  .j  av a2s  .  com
        public void run() {
            KeyboardUtil.showSoftKeyboard(getActivity(), passwordView);
        }
    });
    passwordView.addTextChangedListener(new TextWatcher() {
        @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) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            setupRestoreButtonState();
        }
    });
    passwordView.setFilters(new InputFilter[] { new InputFilter() {
        public CharSequence filter(CharSequence src, int start, int end, Spanned dst, int dstart, int dend) {
            if (src.equals("")) { // for backspace
                return src;
            }
            int numOfWords = numOfWordsInPasswordView();
            if (numOfWords >= NUMBER_OF_WORDS_IN_SEED && src.equals(" ")) {
                return "";
            }
            if (src.toString().matches("[a-z ]+")) {
                return src;
            }
            return "";
        }
    } });
}

From source file:com.xperia64.timidityae.FileBrowserFragment.java

public void getDir(String dirPath) {
    currPath = dirPath;//w  ww.j  a  v  a 2  s  . c  om
    fname = new ArrayList<String>();
    path = new ArrayList<String>();
    if (currPath != null) {
        File f = new File(currPath);
        if (f.exists()) {
            File[] files = f.listFiles();
            if (files != null && files.length > 0) {

                Arrays.sort(files, new FileComparator());

                // System.out.println(currPath);
                if (!currPath.matches("[/]+")) {
                    fname.add("../");
                    path.add(f.getParent() + "/");
                    mCallback.needFileBackCallback(true);
                } else {
                    mCallback.needFileBackCallback(false);
                }
                for (int i = 0; i < files.length; i++) {
                    File file = files[i];
                    if ((!file.getName().startsWith(".") && !Globals.showHiddenFiles)
                            || Globals.showHiddenFiles) {
                        if (file.isFile()) {
                            int dotPosition = file.getName().lastIndexOf(".");
                            String extension = "";
                            if (dotPosition != -1) {
                                extension = (file.getName().substring(dotPosition)).toLowerCase(Locale.US);
                                if (extension != null) {

                                    if ((Globals.showVideos ? Globals.musicVideoFiles : Globals.musicFiles)
                                            .contains("*" + extension + "*")) {

                                        path.add(file.getAbsolutePath());
                                        fname.add(file.getName());
                                    }
                                } else if (file.getName().endsWith("/")) {
                                    path.add(file.getAbsolutePath() + "/");
                                    fname.add(file.getName() + "/");
                                }
                            }
                        } else {
                            path.add(file.getAbsolutePath() + "/");
                            fname.add(file.getName() + "/");
                        }
                    }
                }
            } else {
                if (!currPath.matches("[/]+")) {
                    fname.add("../");
                    path.add(f.getParent() + "/");

                }
            }
            ArrayAdapter<String> fileList = new ArrayAdapter<String>(getActivity(), R.layout.row, fname);
            getListView().setFastScrollEnabled(true);
            getListView().setOnItemLongClickListener(new OnItemLongClickListener() {

                @Override
                public boolean onItemLongClick(AdapterView<?> l, View v, final int position, long id) {
                    localfinished = false;
                    if (new File(path.get(position)).isFile() && Globals.isMidi(path.get(position))) {

                        AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());

                        alert.setTitle("Convert to WAV File");
                        alert.setMessage(
                                "Exports the MIDI/MOD file to WAV.\nNative Midi must be disabled in settings.\nWarning: WAV files are large.");
                        InputFilter filter = new InputFilter() {
                            public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                                    int dstart, int dend) {
                                for (int i = start; i < end; i++) {
                                    String IC = "*/*\n*\r*\t*\0*\f*`*?***\\*<*>*|*\"*:*";
                                    if (IC.contains("*" + source.charAt(i) + "*")) {
                                        return "";
                                    }
                                }
                                return null;
                            }
                        };
                        // Set an EditText view to get user input 
                        final EditText input = new EditText(getActivity());
                        input.setFilters(new InputFilter[] { filter });
                        alert.setView(input);

                        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                String value = input.getText().toString();
                                if (!value.toLowerCase(Locale.US).endsWith(".wav"))
                                    value += ".wav";
                                String parent = path.get(position).substring(0,
                                        path.get(position).lastIndexOf('/') + 1);
                                boolean aWrite = true;
                                boolean alreadyExists = new File(parent + value).exists();
                                String needRename = null;
                                String probablyTheRoot = "";
                                String probablyTheDirectory = "";
                                try {
                                    new FileOutputStream(parent + value, true).close();
                                } catch (FileNotFoundException e) {
                                    aWrite = false;
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                if (!alreadyExists && aWrite)
                                    new File(parent + value).delete();
                                if (aWrite && new File(parent).canWrite()) {
                                    value = parent + value;
                                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                                        && Globals.theFold != null) {
                                    // Write the file to getExternalFilesDir, then move it with the Uri
                                    // We need to tell JNIHandler that movement is needed.

                                    String[] tmp = Globals.getDocFilePaths(getActivity(), parent);
                                    probablyTheDirectory = tmp[0];
                                    probablyTheRoot = tmp[1];
                                    if (probablyTheDirectory.length() > 1) {
                                        needRename = parent.substring(
                                                parent.indexOf(probablyTheRoot) + probablyTheRoot.length())
                                                + value;
                                        value = probablyTheDirectory + '/' + value;
                                    } else {
                                        value = Environment.getExternalStorageDirectory().getAbsolutePath()
                                                + '/' + value;
                                    }
                                } else {
                                    value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/'
                                            + value;
                                }
                                final boolean canWrite = aWrite;
                                final String finalval = value;
                                final String needToRename = needRename;
                                final String probRoot = probablyTheRoot;
                                if (new File(finalval).exists()
                                        || (new File(probRoot + needRename).exists() && needToRename != null)) {
                                    AlertDialog dialog2 = new AlertDialog.Builder(getActivity()).create();
                                    dialog2.setTitle("Warning");
                                    dialog2.setMessage("Overwrite WAV file?");
                                    dialog2.setCancelable(false);
                                    dialog2.setButton(DialogInterface.BUTTON_POSITIVE,
                                            getResources().getString(android.R.string.yes),
                                            new DialogInterface.OnClickListener() {
                                                public void onClick(DialogInterface dialog, int buttonId) {
                                                    if (!canWrite
                                                            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                                        if (needToRename != null) {
                                                            Globals.tryToDeleteFile(getActivity(),
                                                                    probRoot + needToRename);
                                                            Globals.tryToDeleteFile(getActivity(), finalval);
                                                        } else {
                                                            Globals.tryToDeleteFile(getActivity(), finalval);
                                                        }
                                                    } else {
                                                        new File(finalval).delete();
                                                    }

                                                    saveWavPart2(position, finalval, needToRename);

                                                }

                                            });
                                    dialog2.setButton(DialogInterface.BUTTON_NEGATIVE,
                                            getResources().getString(android.R.string.no),
                                            new DialogInterface.OnClickListener() {
                                                public void onClick(DialogInterface dialog, int buttonId) {

                                                }
                                            });
                                    dialog2.show();
                                } else {
                                    saveWavPart2(position, finalval, needToRename);
                                }

                            }
                        });

                        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // Canceled.
                            }
                        });

                        alert.show();

                        return true;
                    } else {

                    }
                    return false;
                }

            });
            setListAdapter(fileList);
        }
    }
}

From source file:com.df.dfcarchecker.CarCheck.CarCheckBasicInfoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //        Random r=new Random();
    //        int uniqueNumber =(r.nextInt(999) + 100);
    //        uniqueId = Integer.toString(uniqueNumber);

    // ?uniqueId/*from  www  .  j  a  v  a2 s  .  c  om*/
    UUID uuid = UUID.randomUUID();
    uniqueId = uuid.toString();

    this.inflater = inflater;
    rootView = inflater.inflate(R.layout.fragment_car_check_basic_info, container, false);

    // <editor-fold defaultstate="collapsed" desc="??View?">
    tableLayout = (TableLayout) rootView.findViewById(R.id.bi_content_table);

    contentLayout = (LinearLayout) rootView.findViewById(R.id.brand_input);

    Button vinButton = (Button) rootView.findViewById(R.id.bi_vin_button);
    vinButton.setOnClickListener(this);

    brandOkButton = (Button) rootView.findViewById(R.id.bi_brand_ok_button);
    brandOkButton.setEnabled(false);
    brandOkButton.setOnClickListener(this);

    brandSelectButton = (Button) rootView.findViewById(R.id.bi_brand_select_button);
    brandSelectButton.setEnabled(false);
    brandSelectButton.setOnClickListener(this);

    // ??
    sketchPhotoEntities = new ArrayList<PhotoEntity>();

    // 
    Button matchButton = (Button) rootView.findViewById(R.id.ct_licencePhotoMatch_button);
    matchButton.setOnClickListener(this);

    // vin???
    InputFilter alphaNumericFilter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence arg0, int arg1, int arg2, Spanned arg3, int arg4, int arg5) {
            for (int k = arg1; k < arg2; k++) {
                if (!Character.isLetterOrDigit(arg0.charAt(k))) {
                    return "";
                }
            }
            return null;
        }
    };
    vin_edit = (EditText) rootView.findViewById(R.id.bi_vin_edit);
    vin_edit.setFilters(new InputFilter[] { alphaNumericFilter, new InputFilter.AllCaps() });

    brandEdit = (EditText) rootView.findViewById(R.id.bi_brand_edit);
    displacementEdit = (EditText) rootView.findViewById(R.id.csi_displacement_edit);
    transmissionEdit = (EditText) rootView.findViewById(R.id.csi_transmission_edit);
    runEdit = (EditText) rootView.findViewById(R.id.bi_mileage_edit);
    //
    //        transmissionSpinner = (Spinner)rootView.findViewById(R.id.csi_transmission_spinner);
    //        transmissionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    //            @Override
    //            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
    //                transmissionEdit.setText(adapterView.getSelectedItem().toString());
    //            }
    //
    //            @Override
    //            public void onNothingSelected(AdapterView<?> adapterView) {
    //
    //            }
    //        });

    // ??????
    ScrollView view = (ScrollView) rootView.findViewById(R.id.root);
    view.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.requestFocusFromTouch();
            return false;
        }
    });

    // ????????2?
    runEdit.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable edt) {
            String temp = edt.toString();

            if (temp.contains(".")) {
                int posDot = temp.indexOf(".");
                if (posDot <= 0)
                    return;
                if (temp.length() - posDot - 1 > 2) {
                    edt.delete(posDot + 3, posDot + 4);
                }
            } else {
                if (temp.length() > 2) {
                    edt.clear();
                    edt.append(temp.substring(0, 2));
                }
            }
        }

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

        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }
    });

    licencePhotoMatchEdit = (EditText) rootView.findViewById(R.id.ct_licencePhotoMatch_edit);
    licencePhotoMatchEdit.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            licencePhotoMatchEdit.setError(null);
        }

        @Override
        public void afterTextChanged(Editable editable) {
            licencePhotoMatchEdit.setError(null);
        }
    });

    // ??
    carNumberEdit = (EditText) rootView.findViewById(R.id.ci_plateNumber_edit);
    carNumberEdit.setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(10) });

    // ?
    portedProcedureRow = (TableRow) rootView.findViewById(R.id.ct_ported_procedure);

    // ?Spinner
    setRegLocationSpinner();
    setCarColorSpinner();
    setFirstLogTimeSpinner();
    setManufactureTimeSpinner();
    setTransferCountSpinner();
    setLastTransferTimeSpinner();
    setYearlyCheckAvailableDateSpinner();
    setAvailableDateYearSpinner();
    setBusinessInsuranceAvailableDateYearSpinner();
    setOtherSpinners();
    // </editor-fold>

    mCarSettings = new CarSettings();

    // ??xml
    if (vehicleModel == null) {
        mProgressDialog = ProgressDialog.show(rootView.getContext(), null, "?..", false, false);

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    ParseXml();

                    // jsonData??
                    if (!jsonData.equals("")) {
                        modifyMode = true;
                        letsEnterModifyMode();
                    }

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

        thread.start();
    }

    return rootView;
}

From source file:it.mb.whatshare.PairOutboundActivity.java

private void showPairingLayout() {
    View view = getLayoutInflater().inflate(R.layout.activity_qrcode, null);
    setContentView(view);/*from   www .ja  v  a  2 s  .  co m*/
    String paired = getOutboundPaired();
    if (paired != null) {
        ((TextView) findViewById(R.id.qr_instructions))
                .setText(getString(R.string.new_outbound_instructions, paired));
    }
    inputCode = (EditText) findViewById(R.id.inputCode);

    inputCode.setFilters(new InputFilter[] { new InputFilter() {
        /*
         * (non- Javadoc )
         * 
         * @see android .text. InputFilter # filter( java .lang.
         * CharSequence , int, int, android .text. Spanned , int, int)
         */
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            if (source instanceof SpannableStringBuilder) {
                SpannableStringBuilder sourceAsSpannableBuilder = (SpannableStringBuilder) source;
                for (int i = end - 1; i >= start; i--) {
                    char currentChar = source.charAt(i);
                    if (!Character.isLetterOrDigit(currentChar)) {
                        sourceAsSpannableBuilder.delete(i, i + 1);
                    }
                }
                return source;
            } else {
                StringBuilder filteredStringBuilder = new StringBuilder();
                for (int i = 0; i < end; i++) {
                    char currentChar = source.charAt(i);
                    if (Character.isLetterOrDigit(currentChar)) {
                        filteredStringBuilder.append(currentChar);
                    }
                }
                return filteredStringBuilder.toString();
            }
        }
    }, new InputFilter.LengthFilter(MAX_SHORTENED_URL_LENGTH) });

    inputCode.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                onSubmitPressed(null);
                return keepKeyboardVisible;
            }
            return false;
        }
    });

    final ImageView qrWrapper = (ImageView) findViewById(R.id.qr_code);
    qrWrapper.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        private boolean createdQRCode = false;

        @Override
        public void onGlobalLayout() {
            if (!createdQRCode) {
                try {
                    Bitmap qrCode = generateQRCode(generateRandomSeed(),
                            getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT
                                    ? qrWrapper.getHeight()
                                    : qrWrapper.getWidth());
                    if (qrCode != null) {
                        qrWrapper.setImageBitmap(qrCode);
                    }
                    createdQRCode = true;
                } catch (WriterException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}

From source file:com.df.app.procedures.CarRecogniseLayout.java

private void init(final Context context) {
    rootView = LayoutInflater.from(context).inflate(R.layout.car_recognise_layout, this);

    deleteLastLicensePhoto();/*from ww w.  j a va  2s . com*/

    mCarSettings = CarSettings.getInstance();

    licenseRecognise = new LicenseRecognise(context, AppCommon.licensePhotoPath);

    licenseImageView = (ImageView) findViewById(R.id.licenseImage);
    licenseImageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            licenseRecognise.takePhoto();
        }
    });

    // 
    recogniseButton = (Button) rootView.findViewById(R.id.recognise_button);
    recogniseButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // ???
            if (!mCarSettings.getBrandString().equals("")) {
                reRecognise(R.string.reRecognise1);
            } else if (!getEditViewText(rootView, R.id.plateNumber_edit).equals("")) {
                reRecognise(R.string.reRecognise);
            } else {
                //fillInDummyData();
                if (licensePhotoExist())
                    recogniseLicense();
                else
                    Toast.makeText(context, "???", Toast.LENGTH_SHORT).show();
            }
        }
    });

    // vin
    Button vinConfirmButton = (Button) rootView.findViewById(R.id.vinConfirm_button);
    vinConfirmButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // VIN??
            if (getEditViewText(rootView, R.id.vin_edit).equals("")) {
                Toast.makeText(rootView.getContext(), "VIN?", Toast.LENGTH_SHORT).show();
            } else {
                checkVinAndGetCarSettings();
            }
        }
    });

    // ?
    Button brandSelectButton = (Button) rootView.findViewById(R.id.brand_select_button);
    brandSelectButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            selectCarManually();
        }
    });

    vehicleTypeEdit = (EditText) rootView.findViewById(R.id.vehicleType_edit);
    vehicleTypeEdit.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_UP:
                choose(R.array.vehicleType_items, R.id.vehicleType_edit);
                break;
            }
            return false;
        }
    });

    useCharacterEdit = (EditText) rootView.findViewById(R.id.useCharacter_edit);
    useCharacterEdit.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_UP:
                choose(R.array.useCharacter_items, R.id.useCharacter_edit);
                break;
            }
            return false;
        }
    });

    // vin???
    InputFilter alphaNumericFilter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence arg0, int arg1, int arg2, Spanned arg3, int arg4, int arg5) {
            for (int k = arg1; k < arg2; k++) {
                if (!Character.isLetterOrDigit(arg0.charAt(k))) {
                    return "";
                }
            }
            return null;
        }
    };

    EditText vin_edit = (EditText) findViewById(R.id.vin_edit);
    vin_edit.setFilters(new InputFilter[] { alphaNumericFilter, new InputFilter.AllCaps(),
            new InputFilter.LengthFilter(17) });

    EditText plateNumberEdit = (EditText) findViewById(R.id.plateNumber_edit);
    plateNumberEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(10) });

    EditText licenseModelEdit = (EditText) findViewById(R.id.licenseModel_edit);
    licenseModelEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(22) });

    EditText engineSerialEdit = (EditText) findViewById(R.id.engineSerial_edit);
    engineSerialEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(17) });

    vehicleModel = MainActivity.vehicleModel;
}

From source file:com.df.kia.procedures.CarRecogniseLayout.java

private void init(final Context context) {
    rootView = LayoutInflater.from(context).inflate(R.layout.car_recognise_layout, this);

    deleteLastLicensePhoto();/*from  w ww  .  j a  v a 2  s  .c om*/

    mCarSettings = InputProceduresLayout.mCarSettings;

    licenseRecognise = new LicenseRecognise(context, AppCommon.licensePhotoPath);

    licenseImageView = (ImageView) findViewById(R.id.licenseImage);
    licenseImageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            licenseRecognise.takePhoto(mHandler);
        }
    });

    // 
    recogniseButton = (Button) rootView.findViewById(R.id.recognise_button);
    recogniseButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // ???
            if (!mCarSettings.getBrandString().equals("")) {
                reRecognise(R.string.reRecognise1);
            } else if (!getEditViewText(rootView, R.id.plateNumber_edit).equals("")) {
                reRecognise(R.string.reRecognise);
            } else {
                //fillInDummyData();
                if (licensePhotoExist())
                    recogniseLicense();
                else
                    Toast.makeText(context, "???", Toast.LENGTH_SHORT).show();
            }
        }
    });

    // vin
    Button vinConfirmButton = (Button) rootView.findViewById(R.id.vinConfirm_button);
    vinConfirmButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // VIN??
            if (getEditViewText(rootView, R.id.vin_edit).equals("")) {
                Toast.makeText(rootView.getContext(), "VIN?", Toast.LENGTH_SHORT).show();
            } else {
                checkVinAndGetCarSettings();
            }
        }
    });

    // ?
    Button brandSelectButton = (Button) rootView.findViewById(R.id.brand_select_button);
    brandSelectButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            selectCarManually();
        }
    });

    vehicleTypeEdit = (EditText) rootView.findViewById(R.id.vehicleType_edit);
    vehicleTypeEdit.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_UP:
                choose(R.array.vehicleType_items, R.id.vehicleType_edit);
                break;
            }
            return false;
        }
    });

    useCharacterEdit = (EditText) rootView.findViewById(R.id.useCharacter_edit);
    useCharacterEdit.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_UP:
                choose(R.array.useCharacter_items, R.id.useCharacter_edit);
                break;
            }
            return false;
        }
    });

    // vin???
    InputFilter alphaNumericFilter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence arg0, int arg1, int arg2, Spanned arg3, int arg4, int arg5) {
            for (int k = arg1; k < arg2; k++) {
                if (!Character.isLetterOrDigit(arg0.charAt(k))) {
                    return "";
                }
            }
            return null;
        }
    };

    EditText vin_edit = (EditText) findViewById(R.id.vin_edit);
    vin_edit.setFilters(new InputFilter[] { alphaNumericFilter, new InputFilter.AllCaps(),
            new InputFilter.LengthFilter(17) });

    EditText plateNumberEdit = (EditText) findViewById(R.id.plateNumber_edit);
    plateNumberEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(10) });

    EditText licenseModelEdit = (EditText) findViewById(R.id.licenseModel_edit);
    licenseModelEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(22) });

    EditText engineSerialEdit = (EditText) findViewById(R.id.engineSerial_edit);
    engineSerialEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(17) });

    vehicleModel = MainActivity.vehicleModel;
}