Example usage for java.lang CharSequence charAt

List of usage examples for java.lang CharSequence charAt

Introduction

In this page you can find the example usage for java.lang CharSequence charAt.

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:edu.cornell.med.icb.goby.util.SimulateBisulfiteReads.java

protected void writeTrueRatesBisulfite(DoubleList methylationRates, CharSequence segmentBases, int from,
        Writer writer) throws IOException {

    PrintWriter trueRateWriter = new PrintWriter(writer);
    // System.out.printf("segmentBases.length: %d %n", segmentBases.length());
    methylationForward = new Int2DoubleOpenHashMap();
    methylationReverse = new Int2DoubleOpenHashMap();
    trueRateWriter.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s%n", "index", "methylationRate", "strand",
            "chromosome", "position", "fromBase", "toBase", "context");
    final int segmentLength = segmentBases.length();
    DoubleIterator it = methylationRates.iterator();
    if (doForwardStrand) {
        // prepare methylation rates for each C position of the segment, forward strand:
        for (int i = 0; i < segmentBases.length(); i++) {
            char fromBase = segmentBases.charAt(i);
            if (fromBase == 'C') {
                char toBase = '.';
                if (!it.hasNext()) {
                    it = methylationRates.iterator();
                }/*from ww  w. j a va2  s  .c  om*/
                final double value = it.nextDouble();
                if (value == 1) {
                    toBase = 'C';
                } else if (value == 0) {
                    toBase = 'T';
                }
                // zero-based
                final int genomicPosition = i + from;
                methylationForward.put(genomicPosition, value);
                final double getterValue = getMethylationRateAtPosition(false, genomicPosition);
                assert getterValue == value;
                // write 1-based position
                trueRateWriter.printf("%d\t%g\t+1\t%s\t%d\t%c\t%c\t%s%n", i, getterValue, refChoice,
                        genomicPosition + 1, fromBase, toBase, context(i, segmentBases));
            }
        }
    }
    if (doReverseStrand) {
        it = methylationRates.iterator();
        CharSequence reverseStrandSegment = reverseComplement(segmentBases);
        // same for reverse strand:
        for (int i = 0; i < segmentLength; i++) {
            char fromBase = reverseStrandSegment.charAt(i);
            if (fromBase == 'C') {
                char toBase = '.';
                if (!it.hasNext()) {
                    it = methylationRates.iterator();
                }
                final double value = it.nextDouble();
                if (value == 1) {
                    toBase = 'C';
                } else if (value == 0) {
                    toBase = 'T';
                }

                // zero-based
                final int genomicPosition = segmentLength - (i + 1) + from;
                methylationReverse.put(genomicPosition, value);
                final double getterValue = getMethylationRateAtPosition(true, genomicPosition);
                assert getterValue == value : "getter must work for reverse strand";
                trueRateWriter.printf("%d\t%g\t-1\t%s\t%d\t%c\t%c\t%s%n", i, getterValue, refChoice,
                        genomicPosition + 1, fromBase, toBase,
                        reverseComplement(context(i, reverseStrandSegment))); // write 1-based position
            }
        }
    }

    trueRateWriter.close();
}

From source file:com.microsoft.mimickeralarm.mimics.MimicTongueTwisterFragment.java

private int levenshteinDistance(CharSequence lhs, CharSequence rhs) {
    if (lhs == null && rhs == null) {
        return 0;
    }//  w  w w .  jav a2 s.c om
    if (lhs == null) {
        return rhs.length();
    }
    if (rhs == null) {
        return lhs.length();
    }

    int len0 = lhs.length() + 1;
    int len1 = rhs.length() + 1;

    // the array of distances
    int[] cost = new int[len0];
    int[] newcost = new int[len0];

    // initial cost of skipping prefix in String s0
    for (int i = 0; i < len0; i++)
        cost[i] = i;

    // dynamically computing the array of distances

    // transformation cost for each letter in s1
    for (int j = 1; j < len1; j++) {
        // initial cost of skipping prefix in String s1
        newcost[0] = j;

        // transformation cost for each letter in s0
        for (int i = 1; i < len0; i++) {
            // matching current letters in both strings
            int match = (lhs.charAt(i - 1) == rhs.charAt(j - 1)) ? 0 : 1;

            // computing cost for each transformation
            int cost_replace = cost[i - 1] + match;
            int cost_insert = cost[i] + 1;
            int cost_delete = newcost[i - 1] + 1;

            // keep minimum cost
            newcost[i] = Math.min(Math.min(cost_insert, cost_delete), cost_replace);
        }

        // swap cost/newcost arrays
        int[] swap = cost;
        cost = newcost;
        newcost = swap;
    }

    // the distance is the cost for transforming all letters in both strings
    return cost[len0 - 1];
}

From source file:com.google.dart.tools.ui.internal.text.dart.DartAutoIndentStrategy_NEW.java

/**
 * Returns the visual length of a given <code>CharSequence</code> taking into account the visual
 * tabulator length.//from   w w  w  .j  av  a 2 s .  co  m
 * 
 * @param seq the string to measure
 * @param tabLength the length of a tab
 * @return the visual length of <code>seq</code>
 */
private int computeVisualLength(CharSequence seq, int tabLength) {

    int size = 0;

    if (seq != null) {
        for (int i = 0; i < seq.length(); i++) {
            char ch = seq.charAt(i);
            if (ch == '\t') {
                if (tabLength != 0) {
                    size += tabLength - size % tabLength;
                    // else: size stays the same
                }
            } else {
                size++;
            }
        }
    }

    return size;
}

From source file:com.jecelyin.editor.v2.core.text.TextUtils.java

public static void getChars(CharSequence s, int start, int end, char[] dest, int destoff) {
    Class<? extends CharSequence> c = s.getClass();

    if (c == String.class)
        ((String) s).getChars(start, end, dest, destoff);
    else if (c == StringBuffer.class)
        ((StringBuffer) s).getChars(start, end, dest, destoff);
    else if (c == StringBuilder.class)
        ((StringBuilder) s).getChars(start, end, dest, destoff);
    else if (s instanceof GetChars)
        ((GetChars) s).getChars(start, end, dest, destoff);
    else {/*  ww w .  j  a  v  a 2s.  co  m*/
        for (int i = start; i < end; i++)
            dest[destoff++] = s.charAt(i);
    }
}

From source file:com.huofu.RestaurantOS.ui.splash.activate.java

/**
 * ?/*  w  w w  .  j  av  a 2  s  . co  m*/
 */
public void widgetConfigure() {

    buttonActivate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            if (authDialog == null) {
                authDialog = new Dialog(activate.this, R.style.PauseDialog);
            }
            if (ttv.getParent() != null) {
                ttv = new TitanicTextView(ctxt);
            }

            String key = etActivteCode.getText().toString();
            if (key.length() >= 16) {
                CommonUtils.LogWuwei(tag, "key is " + key);
                CommonUtils.sendMsg("?", activate.SHOW_LOADING_TEXT, mUiHandler);
                activate(ctxt, key);
            } else {
                CommonUtils.sendMsg("????", activate.SHOW_ERROR_MESSAGE, mUiHandler);
            }

        }
    });

    InputFilter filter = new InputFilter() {

        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            // TODO Auto-generated method stub
            for (int i = start; i < end; i++) {
                //???'-'
                if (!Character.isLetter(source.charAt(i)) && source.charAt(i) != '-') {
                    return "";
                }
            }
            return null;
        }
    };

    InputFilter filterLength = new InputFilter.LengthFilter(19);

    etActivteCode.setCursorVisible(false);
    etActivteCode.setFilters(new InputFilter[] { filter, filterLength });
    etActivteCode.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) {
            // TODO Auto-generated method stub

            etActivteCode.setCursorVisible(true);
            etActivteCode.removeTextChangedListener(this);// ?
            etActivteCode.setText(s.toString().toUpperCase());// ?
            etActivteCode.setSelection(s.toString().length());// ??
            etActivteCode.addTextChangedListener(this);// ?
            String licensePlateNumber = etActivteCode.getText().toString().trim();

            if (s.length() == 19) {
                InputMethodUtils.HideKeyboard(etActivteCode);
            }

        }
    });
    etActivteCode.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if (keyCode == KeyEvent.KEYCODE_DEL) {
                CommonUtils.LogWuwei(tag, "delete");
                etActivteCode.setCursorVisible(false);
            }
            return false;
        }
    });

    rl_activate_qrscan_ready.setVisibility(View.INVISIBLE);

    OnClickListener oclGetQrCode = new OnClickListener() {
        @Override
        public void onClick(View v) {
            flagInQrcodeDialog = true;
            CommonUtils.sendMsg("??", SHOW_LOADING_TEXT, mUiHandler);

            if (LocalDataDeal.readFromLocalPublicKey(ctxt) == null
                    || LocalDataDeal.readFromLocalPublicKey(ctxt).equals("")) {
                ApisManager.GetPublicKey(new ApiCallback() {
                    @Override
                    public void success(Object object) {
                        sendUIMessage(HIDE_LOADING, "");
                        try {
                            org.json.JSONObject obj = new org.json.JSONObject((String) object);
                            String public_key = obj.getString("public_key");
                            LocalDataDeal.writeToLocalPublicKey(public_key, ctxt);//key?base64?
                        } catch (Exception e) {
                        }
                        CommonUtils.sendMsg("", GET_QRCODE, mUiHandler);
                    }

                    @Override
                    public void error(BaseApi.ApiResponse response) {
                        sendUIMessage(HIDE_LOADING, "");
                        sendUIMessage(SHOW_ERROR_MESSAGE, response.error_message);
                    }
                });
            } else {
                CommonUtils.sendMsg("", GET_QRCODE, mUiHandler);
            }

            rl_activate_input.setVisibility(View.INVISIBLE);
            rl_activate_qrscan_ready.setVisibility(View.VISIBLE);
            imageViewQrcode.setVisibility(View.INVISIBLE);
            rl_activate_qrscan_ready
                    .startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.small_2_big));

            textviewScanStauts.setTextColor(Color.parseColor("#898989"));
            textviewScanStauts.setText(R.string.activateByQrCodeTips);

            rl_activate_qrscan_ready
                    .startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.slide_left_in));
            rl_activate_input.startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.slide_right_out));
        }
    };

    buttonSwitchQrScan.setOnClickListener(oclGetQrCode);
    findViewById(R.id.rl_switch_activate_qrcode_way).setOnClickListener(oclGetQrCode);

    buttonSwitchInputCode.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            flagInQrcodeDialog = false;
            flagWaitingCmd = false;
            rl_activate_qrscan_ready.setVisibility(View.INVISIBLE);
            rl_activate_input.setVisibility(View.VISIBLE);
            rl_activate_input.startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.small_2_big));

            stopQrScanTimer();

            rl_activate_input.startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.slide_right_in));
            rl_activate_qrscan_ready
                    .startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.slide_left_out));

        }
    });

    findViewById(R.id.rl_switch_activate_keyboard_way).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            flagInQrcodeDialog = false;
            flagWaitingCmd = false;
            rl_activate_qrscan_ready.setVisibility(View.INVISIBLE);
            rl_activate_input.setVisibility(View.VISIBLE);
            rl_activate_input.startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.small_2_big));

            stopQrScanTimer();
        }
    });

    PackageManager manager;
    PackageInfo info = null;
    manager = this.getPackageManager();
    String versionName = null;
    try {
        info = manager.getPackageInfo(this.getPackageName(), 0);
        versionName = info.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    ((TextView) findViewById(R.id.tv_app_version))
            .setText(getResources().getString(R.string.app_name) + " V" + versionName);

    LocalDataDeal.writeToLocalVersion(versionName, ctxt);
    LocalDataDeal.writeToLocalVersionCode(info.versionCode, ctxt);

    ftpServiceStart();
}

From source file:com.duy.pascal.ui.view.console.ConsoleView.java

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    outAttrs.inputType = InputType.TYPE_NULL;
    //        outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE;
    return new InputConnection() {
        /**// w w w.j  a va  2  s  . c o  m
         * Used to handle composing text requests
         */
        private int mCursor;
        private int mComposingTextStart;
        private int mComposingTextEnd;
        private int mSelectedTextStart = 0;
        private int mSelectedTextEnd = 0;
        private boolean mInBatchEdit;

        private void sendText(CharSequence text) {
            DLog.d(TAG, "sendText: " + text);
            int n = text.length();
            for (int i = 0; i < n; i++) {
                mKeyBuffer.push(text.charAt(i));
                putString(Character.toString(text.charAt(i)));
            }
        }

        @Override
        public boolean performEditorAction(int actionCode) {
            DLog.d(TAG, "performEditorAction: " + actionCode);
            if (actionCode == EditorInfo.IME_ACTION_DONE || actionCode == EditorInfo.IME_ACTION_GO
                    || actionCode == EditorInfo.IME_ACTION_NEXT || actionCode == EditorInfo.IME_ACTION_SEND
                    || actionCode == EditorInfo.IME_ACTION_UNSPECIFIED) {
                sendText("\n");
                return true;
            }
            return false;
        }

        public boolean beginBatchEdit() {
            {
                DLog.w(TAG, "beginBatchEdit");
            }
            setImeBuffer("");
            mCursor = 0;
            mComposingTextStart = 0;
            mComposingTextEnd = 0;
            mInBatchEdit = true;
            return true;
        }

        public boolean clearMetaKeyStates(int arg0) {
            {
                DLog.w(TAG, "clearMetaKeyStates " + arg0);
            }
            return false;
        }

        public boolean commitCompletion(CompletionInfo arg0) {
            {
                DLog.w(TAG, "commitCompletion " + arg0);
            }
            return false;
        }

        @Override
        public boolean commitCorrection(CorrectionInfo correctionInfo) {
            return false;
        }

        public boolean endBatchEdit() {
            {
                DLog.w(TAG, "endBatchEdit");
            }
            mInBatchEdit = false;
            return true;
        }

        public boolean finishComposingText() {
            {
                DLog.w(TAG, "finishComposingText");
            }
            sendText(mImeBuffer);
            setImeBuffer("");
            mComposingTextStart = 0;
            mComposingTextEnd = 0;
            mCursor = 0;
            return true;
        }

        public int getCursorCapsMode(int arg0) {
            {
                DLog.w(TAG, "getCursorCapsMode(" + arg0 + ")");
            }
            return 0;
        }

        public ExtractedText getExtractedText(ExtractedTextRequest arg0, int arg1) {
            {
                DLog.w(TAG, "getExtractedText" + arg0 + "," + arg1);
            }
            return null;
        }

        public CharSequence getTextAfterCursor(int n, int flags) {
            {
                DLog.w(TAG, "getTextAfterCursor(" + n + "," + flags + ")");
            }
            int len = Math.min(n, mImeBuffer.length() - mCursor);
            if (len <= 0 || mCursor < 0 || mCursor >= mImeBuffer.length()) {
                return "";
            }
            return mImeBuffer.substring(mCursor, mCursor + len);
        }

        public CharSequence getTextBeforeCursor(int n, int flags) {
            {
                DLog.w(TAG, "getTextBeforeCursor(" + n + "," + flags + ")");
            }
            int len = Math.min(n, mCursor);
            if (len <= 0 || mCursor < 0 || mCursor >= mImeBuffer.length()) {
                return "";
            }
            return mImeBuffer.substring(mCursor - len, mCursor);
        }

        public boolean performContextMenuAction(int arg0) {
            {
                DLog.w(TAG, "performContextMenuAction" + arg0);
            }
            return true;
        }

        public boolean performPrivateCommand(String arg0, Bundle arg1) {
            {
                DLog.w(TAG, "performPrivateCommand" + arg0 + "," + arg1);
            }
            return true;
        }

        @Override
        public boolean requestCursorUpdates(int cursorUpdateMode) {
            return false;
        }

        @Override
        public Handler getHandler() {
            return null;
        }

        @Override
        public void closeConnection() {

        }

        @Override
        public boolean commitContent(@NonNull InputContentInfo inputContentInfo, int flags, Bundle opts) {
            return false;
        }

        public boolean reportFullscreenMode(boolean arg0) {
            {
                DLog.w(TAG, "reportFullscreenMode" + arg0);
            }
            return true;
        }

        public boolean commitText(CharSequence text, int newCursorPosition) {
            {
                DLog.w(TAG, "commitText(\"" + text + "\", " + newCursorPosition + ")");
            }
            char[] characters = text.toString().toCharArray();
            for (char character : characters) {
                mKeyBuffer.push(character);
            }
            clearComposingText();
            sendText(text);
            setImeBuffer("");
            mCursor = 0;
            return true;
        }

        private void clearComposingText() {
            setImeBuffer(
                    mImeBuffer.substring(0, mComposingTextStart) + mImeBuffer.substring(mComposingTextEnd));
            if (mCursor < mComposingTextStart) {
                // do nothing
            } else if (mCursor < mComposingTextEnd) {
                mCursor = mComposingTextStart;
            } else {
                mCursor -= mComposingTextEnd - mComposingTextStart;
            }
            mComposingTextEnd = mComposingTextStart = 0;
        }

        public boolean deleteSurroundingText(int leftLength, int rightLength) {
            {
                DLog.w(TAG, "deleteSurroundingText(" + leftLength + "," + rightLength + ")");
            }
            if (leftLength > 0) {
                for (int i = 0; i < leftLength; i++) {
                    sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
                }
            } else if ((leftLength == 0) && (rightLength == 0)) {
                // Delete key held down / repeating
                sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            }
            // TODO: handle forward deletes.
            return true;
        }

        @Override
        public boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) {
            return false;
        }

        public boolean sendKeyEvent(KeyEvent event) {
            {
                DLog.w(TAG, "sendKeyEvent(" + event + ")");
            }
            // Some keys are sent here rather than to commitText.
            // In particular, del and the digit keys are sent here.
            // (And I have reports that the HTC Magic also sends Return here.)
            // As a bit of defensive programming, handle every key.
            dispatchKeyEvent(event);
            return true;
        }

        public boolean setComposingText(CharSequence text, int newCursorPosition) {
            {
                DLog.w(TAG, "setComposingText(\"" + text + "\", " + newCursorPosition + ")");
            }

            setImeBuffer(mImeBuffer.substring(0, mComposingTextStart) + text
                    + mImeBuffer.substring(mComposingTextEnd));
            mComposingTextEnd = mComposingTextStart + text.length();
            mCursor = newCursorPosition > 0 ? mComposingTextEnd + newCursorPosition - 1
                    : mComposingTextStart - newCursorPosition;
            return true;
        }

        public boolean setSelection(int start, int end) {
            {
                DLog.w(TAG, "setSelection" + start + "," + end);
            }
            int length = mImeBuffer.length();
            if (start == end && start > 0 && start < length) {
                mSelectedTextStart = mSelectedTextEnd = 0;
                mCursor = start;
            } else if (start < end && start > 0 && end < length) {
                mSelectedTextStart = start;
                mSelectedTextEnd = end;
                mCursor = start;
            }
            return true;
        }

        public boolean setComposingRegion(int start, int end) {
            {
                DLog.w(TAG, "setComposingRegion " + start + "," + end);
            }
            if (start < end && start > 0 && end < mImeBuffer.length()) {
                clearComposingText();
                mComposingTextStart = start;
                mComposingTextEnd = end;
            }
            return true;
        }

        public CharSequence getSelectedText(int flags) {
            try {

                {
                    DLog.w(TAG, "getSelectedText " + flags);
                }

                if (mImeBuffer.length() < 1) {
                    return "";
                }

                return mImeBuffer.substring(mSelectedTextStart, mSelectedTextEnd + 1);

            } catch (Exception ignored) {

            }

            return "";
        }

    };
}

From source file:cn.sinobest.jzpt.framework.utils.string.StringUtils.java

/**
 * /*from w  ww  .j a  va  2s .  co m*/
 *
 * @param source
 * @param offset
 * @param keyword
 * @return
 */
public static boolean matchChars(CharSequence source, int offset, CharSequence keyword) {
    int max = offset + keyword.length();
    for (int i = offset; i < max; i++) {
        if (source.charAt(i) != keyword.charAt(i - offset)) {
            return false;
        }
    }
    return true;
}

From source file:org.codehaus.groovy.grails.web.pages.GroovyPageParser.java

private void write(CharSequence text, boolean gsp) {
    if (!gsp) {/*  ww w.  j a v  a 2s . co m*/
        out.print(text);
        return;
    }

    for (int ix = 0, ixz = text.length(); ix < ixz; ix++) {
        char c = text.charAt(ix);
        String rep = null;
        if (Character.isWhitespace(c)) {
            for (ix++; ix < ixz; ix++) {
                if (Character.isWhitespace(text.charAt(ix))) {
                    continue;
                }
                ix--;
                rep = " ";
                break;
            }
        } else if (c == '&') {
            if (match("&semi;", text, ix)) {
                rep = ";";
                ix += 5;
            } else if (match("&amp;", text, ix)) {
                rep = "&";
                ix += 4;
            } else if (match("&lt;", text, ix)) {
                rep = "<";
                ix += 3;
            } else if (match("&gt;", text, ix)) {
                rep = ">";
                ix += 3;
            }
        } else if (c == '<') {
            if (match("<br>", text, ix) || match("<hr>", text, ix)) {
                rep = "\n";
                //incrementLineNumber();
                ix += 3;
            } else {
                int end = match(PARA_BREAK, text, ix);
                if (end <= 0)
                    end = match(ROW_BREAK, text, ix);
                if (end > 0) {
                    rep = "\n";
                    //incrementLineNumber();
                    ix = end;
                }
            }
        }
        if (rep != null) {
            out.print(rep);
        } else {
            out.print(c);
        }
    }
}

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();//  w w w .j ava2 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;
}

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();/* ww  w  .  j  ava  2s. c  om*/

    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;
}