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:org.codehaus.groovy.grails.web.pages.Parse.java

private String escapeGroovy(CharSequence text) {
    StringBuffer buf = new StringBuffer();
    for (int ix = 0, ixz = text.length(); ix < ixz; ix++) {
        char c = text.charAt(ix);
        String rep = null;/*  ww  w  .  j  a  v  a2 s.c o m*/
        if (c == '\n') {
            incrementLineNumber();
            rep = "\\n";
        } else if (c == '\r')
            rep = "\\r";
        else if (c == '\t')
            rep = "\\t";
        else if (c == '\'')
            rep = "\\'";
        else if (c == '\\')
            rep = "\\\\";
        if (rep != null)
            buf.append(rep);
        else
            buf.append(c);
    }
    return buf.toString();
}

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

static boolean doesNotNeedBidi(CharSequence s, int start, int end) {
    for (int i = start; i < end; i++) {
        if (s.charAt(i) >= FIRST_RIGHT_TO_LEFT) {
            return false;
        }/*w w w .  j  a va  2  s . c om*/
    }
    return true;
}

From source file:nu.yona.app.ui.profile.EditDetailsProfileFragment.java

@Nullable
@Override/*w ww  . j  a  va 2 s.  c o m*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.edit_profile_detail_fragment, null);
    final View activityRootView = view.findViewById(R.id.main_content);

    activityRootView.getViewTreeObserver()
            .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (isAdded()) {
                        if (AppUtils.checkKeyboardOpen(activityRootView)) {
                            ((YonaActivity) getActivity()).changeBottomTabVisibility(false);
                        } else {
                            ((YonaActivity) getActivity()).changeBottomTabVisibility(true);
                        }
                    }
                }
            });

    setupToolbar(view);

    changeProfileImageClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            YonaActivity.getActivity().chooseImage();
        }
    };
    textWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

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

        @Override
        public void afterTextChanged(Editable s) {
            if (s != null && s.length() > 0 && (s.length() == 1 || s.charAt(s.length() - 1) == ' ')
                    && isAdding) {
                firstName.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
                lastName.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
                nickName.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
            }
        }
    };

    onFocusChangeListener = new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean b) {
            if (b) {
                ((EditText) view).setSelection(((EditText) view).getText().length());
            }
        }
    };
    inflateView(view);

    setHook(new YonaAnalytics.BackHook(AnalyticsConstant.BACK_FROM_EDIT_PROFILE));

    YonaApplication.getEventChangeManager().registerListener(this);
    return view;
}

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

private void showPairingLayout() {
    View view = getLayoutInflater().inflate(R.layout.activity_qrcode, null);
    setContentView(view);/* w  ww. 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.jecelyin.editor.v2.core.text.TextUtils.java

/**
 * Returns the length that the specified CharSequence would have if
 * spaces and control characters were trimmed from the start and end,
 * as by {@link String#trim}.//from w w  w . j a v  a2s . co m
 */
public static int getTrimmedLength(CharSequence s) {
    int len = s.length();

    int start = 0;
    while (start < len && s.charAt(start) <= ' ') {
        start++;
    }

    int end = len;
    while (end > start && s.charAt(end - 1) <= ' ') {
        end--;
    }

    return end - start;
}

From source file:com.rks.musicx.misc.utils.Helper.java

/**
 * Filter space EditText/* w  ww  . j  a v a 2s . co  m*/
 *
 * @return
 */
@NonNull
public static InputFilter inputFilter() {
    return new InputFilter() {
        @Override
        public CharSequence filter(CharSequence charSequence, int start, int end, Spanned spanned, int i2,
                int i3) {
            String filter = "";
            for (int k = start; k < end; k++) {
                char chz = charSequence.charAt(k);
                if (!Character.isWhitespace(chz)) {
                    filter += chz;
                }
            }
            return filter;
        }
    };
}

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

/**
 * Returns whether the given CharSequence contains only digits.
 *//*from w ww .ja v a  2 s.c om*/
public static boolean isDigitsOnly(CharSequence str) {
    final int len = str.length();
    for (int i = 0; i < len; i++) {
        if (!Character.isDigit(str.charAt(i))) {
            return false;
        }
    }
    return true;
}

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

/**
 * @hide//from   w  w w . j a v  a  2  s .c o m
 */
public static boolean isPrintableAsciiOnly(final CharSequence str) {
    final int len = str.length();
    for (int i = 0; i < len; i++) {
        if (!isPrintableAscii(str.charAt(i))) {
            return false;
        }
    }
    return true;
}

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

public void getDir(String dirPath) {
    currPath = dirPath;/*  ww w .ja  v  a 2  s  . c  o m*/
    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.jecelyin.editor.v2.core.text.TextUtils.java

/**
 * Returns whether the given CharSequence contains any printable characters.
 *//*w  w w  . j  av  a 2 s  .  co  m*/
public static boolean isGraphic(CharSequence str) {
    final int len = str.length();
    for (int i = 0; i < len; i++) {
        int gc = Character.getType(str.charAt(i));
        if (gc != Character.CONTROL && gc != Character.FORMAT && gc != Character.SURROGATE
                && gc != Character.UNASSIGNED && gc != Character.LINE_SEPARATOR
                && gc != Character.PARAGRAPH_SEPARATOR && gc != Character.SPACE_SEPARATOR) {
            return true;
        }
    }
    return false;
}