Example usage for java.lang Character isLetterOrDigit

List of usage examples for java.lang Character isLetterOrDigit

Introduction

In this page you can find the example usage for java.lang Character isLetterOrDigit.

Prototype

public static boolean isLetterOrDigit(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a letter or digit.

Usage

From source file:metabest.transformations.MetaModel2Use.java

private String getNameSwitch(String name) {
    if (isReserved(name)) {
        String fixedName = name + "_RESERVEDWORD";
        nameSwitch.put(name, fixedName);
        return fixedName;
    }/* w w  w .j a  v  a  2s. co m*/

    if (!StringUtils.isAlphanumeric(name)) {
        //if(name.equals("Co-author")) System.out.println("entering");
        String fixedName = name;

        for (char c : name.toCharArray())
            if (!Character.isLetterOrDigit(c) && c != '_') {
                //if(name.equals("Co-author")) System.out.println("true");
                fixedName = fixedName.replaceAll(String.valueOf(c), "_NONALPHANUMERICCHAR_");
            }

        //if(name.equals("Co-author")) System.out.println("here: " + fixedName);

        nameSwitch.put(name, fixedName);
        return fixedName;

    }

    nameSwitch.put(name, name);
    return name;
}

From source file:com.android.mms.ui.MessageUtils.java

public static boolean isAlias(String string) {
    if (!MmsConfig.isAliasEnabled()) {
        return false;
    }//w  ww. j a v  a  2  s. c  om

    int len = string == null ? 0 : string.length();

    if (len < MmsConfig.getAliasMinChars() || len > MmsConfig.getAliasMaxChars()) {
        return false;
    }

    if (!Character.isLetter(string.charAt(0))) { // Nickname begins with a letter
        return false;
    }
    for (int i = 1; i < len; i++) {
        char c = string.charAt(i);
        if (!(Character.isLetterOrDigit(c) || c == '.')) {
            return false;
        }
    }

    return true;
}

From source file:com.httrack.android.HTTrackActivity.java

/**
 * We just entered in a new pane.//from   w w w .  ja v a2  s. com
 */
protected void onEnterNewPane() {
    switch (layouts[pane_id]) {
    case R.layout.activity_startup:
        final TextView text = TextView.class.cast(this.findViewById(R.id.fieldDisplay));
        final TextView textDebug = TextView.class.cast(this.findViewById(R.id.fieldDebug));

        // Welcome message.
        final String html = getString(R.string.welcome_message).replace("\n-", "\n").replace("\n", "<br />")
                .replace("HTTrack Website Copier", "<b>HTTrack Website Copier</b>");
        text.setText(Html.fromHtml(html));

        // Debugging and information.
        final StringBuilder str = new StringBuilder();
        str.append("<i>");
        if (version != null) {
            str.append("<br />Version: ");
            // Library version
            str.append(version);
            str.append(versionFeatures);
            // Android version
            str.append(" (Android version ");
            str.append(versionCode);
            str.append(")");
        }
        // str.append("  Path: ");
        // str.append(getProjectRootFile().getAbsolutePath());
        str.append("  IPv6: ");
        final InetAddress addrV6 = getIPv6Address();
        str.append(addrV6 != null ? ("YES (" + addrV6.getHostAddress() + ")") : "NO");
        str.append("</i>");
        textDebug.setText(Html.fromHtml(str.toString()));

        // Enable or disable browse & cleanup button depending on existing
        // project(s)
        View.class.cast(this.findViewById(R.id.buttonClear)).setEnabled(hasProjectNames());
        View.class.cast(this.findViewById(R.id.buttonBrowseAll)).setEnabled(hasProjectRootIndexFile());

        break;
    case R.layout.activity_proj_name:
        // Refresh suggest
        refreshprojectNameSuggests();

        /* Base path */
        TextView.class.cast(findViewById(R.id.fieldBasePath)).setText(getProjectRootFile().getAbsolutePath());

        // "Next" button is disabled if no project name is defined
        switchEmptyProjectName = !OptionsMapper.isStringNonEmpty(mapper.getProjectName());
        View.class.cast(findViewById(R.id.buttonNext)).setEnabled(!switchEmptyProjectName);

        /*
         * Prior to Honeycomb (TODO FIXME: check that), the android browser is
         * unable to browse local file:// pages embedding spaces (%20 or +)
         * Therefore, warn the user.
         */
        warnPreHoneycombSpaceIssue = android.os.Build.VERSION.SDK_INT < VERSION_CODES.HONEYCOMB;

        /* Add text watcher for the "Next" button. */
        final AutoCompleteTextView name = AutoCompleteTextView.class
                .cast(this.findViewById(R.id.fieldProjectName));
        name.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(final CharSequence s, final int start, final int before,
                    final int count) {
                // Warn when seeing space
                if (warnPreHoneycombSpaceIssue) {
                    for (int i = start; i < start + count; i++) {
                        if (s.charAt(i) == ' ') {
                            showNotification(getString(R.string.warning_space_in_filename), true);
                            warnPreHoneycombSpaceIssue = false;
                            break;
                        }
                    }
                }
            }

            @Override
            public void afterTextChanged(final Editable s) {
                // Enable/disable next button
                boolean empty = true;
                for (int i = 0; i < s.length(); i++) {
                    if (Character.isLetterOrDigit(s.charAt(i))) {
                        empty = false;
                        break;
                    }
                }
                if (empty != switchEmptyProjectName) {
                    switchEmptyProjectName = empty;
                    View.class.cast(findViewById(R.id.buttonNext)).setEnabled(!empty);
                }

                // (re) Set category
                final String category = getProjectCategory(s.toString());
                TextView.class.cast(findViewById(R.id.fieldProjectCategory))
                        .setText(category != null ? category : "");
            }

            // NOOP
            @Override
            public void beforeTextChanged(final CharSequence s, final int start, final int count,
                    final int after) {
            }
        });
        break;
    case R.layout.activity_proj_setup:
        // Existing cache ?
        final boolean hasProfile = hasCacheFile();
        View.class.cast(this.findViewById(R.id.radioAction)).setEnabled(hasProfile);
        View.class.cast(this.findViewById(R.id.radioAction))
                .setVisibility(hasProfile ? View.VISIBLE : View.GONE);
        if (hasProfile) {
            // Update is the default unless something was broken
            RadioGroup.class.cast(this.findViewById(R.id.radioAction))
                    .check(isInterruptedProfile() ? R.id.radioItemContinue : R.id.radioItemUpdate);
        } else {
            // Reset
            RadioGroup.class.cast(this.findViewById(R.id.radioAction)).check(-1);
        }
        break;
    case R.layout.activity_mirror_progress:
        setProgressLinesInternal(new String[] { getString(R.string.starting_worker_thread) });
        startRunner();
        if (runner != null) {
            ProgressBar.class.cast(findViewById(R.id.progressMirror)).setVisibility(View.VISIBLE);
        }
        break;
    case R.layout.activity_mirror_finished:
        // Ensure the engine has stopped running
        if (runner != null) {
            runner.stopMirror(true);
        }

        // Enable browse button if index.html exists
        final boolean hasIndex = hasTargetIndexFile();
        View.class.cast(this.findViewById(R.id.buttonBrowse)).setEnabled(hasIndex);
        if (!hasIndex) {
            final File index = getTargetIndexFile();
            Log.d(getClass().getSimpleName(),
                    "no index found (" + (index != null ? index.getAbsolutePath() : "unknown location") + ")");
            final String template = getString(R.string.no_index_html_in_xx);
            if (template == null) {
                throw new RuntimeException("R.string.no_index_html_in_xx is null");
            }
            final File target = getTargetFile();
            if (target != null) {
                final String warning = template.replace("%s", target.getPath());
                showNotification(warning);
            }
        }

        // Enable logs if present
        final boolean hasLog = hasTargetLogFile();
        View.class.cast(this.findViewById(R.id.buttonLogs)).setEnabled(hasLog);
        if (!hasLog) {
            final File log = getTargetLogFile();
            Log.d(getClass().getSimpleName(),
                    "no log found (" + (log != null ? log.getAbsolutePath() : "unknown location") + ")");
        }

        // Final stats
        if (runner != null) {
            final HTTrackStats lastStats = runner.getLastStats();
            if (lastStats != null && lastStats.errorsCount != 0) {
                // TODO
            }
        }
        break;
    }
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

private void doubleSpace() {
    // if (!mAutoPunctuate) return;
    if (mCorrectionMode == Suggest.CORRECTION_NONE)
        return;/*from  ww  w  . j  av a2  s  .  c  o  m*/
    final InputConnection ic = getCurrentInputConnection();
    if (ic == null)
        return;
    CharSequence lastThree = ic.getTextBeforeCursor(3, 0);
    if (lastThree != null && lastThree.length() == 3 && Character.isLetterOrDigit(lastThree.charAt(0))
            && lastThree.charAt(1) == ASCII_SPACE && lastThree.charAt(2) == ASCII_SPACE) {
        ic.beginBatchEdit();
        ic.deleteSurroundingText(2, 0);
        ic.commitText(". ", 1);
        ic.endBatchEdit();
        updateShiftKeyState(getCurrentInputEditorInfo());
        mJustAddedAutoSpace = true;
    }
}

From source file:com.android.contacts.common.list.ContactListItemView.java

private String snippetize(String line, int matchIndex, int maxLength) {
    // Show up to maxLength characters. But we only show full tokens so show the last full token
    // up to maxLength characters. So as many starting tokens as possible before trying ending
    // tokens.//  w ww  . j a v a 2s .c  o m
    int remainingLength = maxLength;
    int tempRemainingLength = remainingLength;

    // Start the end token after the matched query.
    int index = matchIndex;
    int endTokenIndex = index;

    // Find the match token first.
    while (index < line.length()) {
        if (!Character.isLetterOrDigit(line.charAt(index))) {
            endTokenIndex = index;
            remainingLength = tempRemainingLength;
            break;
        }
        tempRemainingLength--;
        index++;
    }

    // Find as much content before the match.
    index = matchIndex - 1;
    tempRemainingLength = remainingLength;
    int startTokenIndex = matchIndex;
    while (index > -1 && tempRemainingLength > 0) {
        if (!Character.isLetterOrDigit(line.charAt(index))) {
            startTokenIndex = index;
            remainingLength = tempRemainingLength;
        }
        tempRemainingLength--;
        index--;
    }

    index = endTokenIndex;
    tempRemainingLength = remainingLength;
    // Find remaining content at after match.
    while (index < line.length() && tempRemainingLength > 0) {
        if (!Character.isLetterOrDigit(line.charAt(index))) {
            endTokenIndex = index;
        }
        tempRemainingLength--;
        index++;
    }
    // Append ellipse if there is content before or after.
    final StringBuilder sb = new StringBuilder();
    if (startTokenIndex > 0) {
        sb.append("...");
    }
    sb.append(line.substring(startTokenIndex, endTokenIndex));
    if (endTokenIndex < line.length()) {
        sb.append("...");
    }
    return sb.toString();
}

From source file:io.manasobi.utils.StringUtils.java

/**
 *  String? '?' '?' ?  ?.<br>// w  ww.j av a2s .  c  om
 * ? ??? ?? Java?  ? ? .<br>
 *  String? null? , false return.<br><br>
 * 
 * StringUtils.isLetterOrDigit("12") = true<br>
 * StringUtils.isLetterOrDigit("12@#%") = false
 *
 * @param str
 *            the String to check, may be null
 * @return true if String contains only letters or digits, false if not or
 *         null string input
 */
public static boolean isLetterOrDigit(String str) {
    if (str == null) {
        return false;
    }
    char[] chars = str.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        if (!Character.isLetterOrDigit(chars[i])) {
            return false;
        }
    }
    return true;
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java

private void onBufferDraw(Canvas canvas) {
    if (mKeyboardChanged) {
        invalidateAllKeys();//ww w  .  j  a va 2  s  .  c  om
        mKeyboardChanged = false;
    }

    canvas.getClipBounds(mDirtyRect);

    if (mKeyboard == null)
        return;

    final boolean drawKeyboardNameText = (mKeyboardNameTextSize > 1f)
            && AnyApplication.getConfig().getShowKeyboardNameText();

    final boolean drawHintText = (mHintTextSize > 1) && AnyApplication.getConfig().getShowHintTextOnKeys();
    // TODO: calls to AnyApplication.getConfig().getXXXXX() functions are
    // not yet implemented,
    // but need to when allowing preferences to override theme settings of
    // these values
    // right now just using what should be the default values for these
    // unimplemented preferences

    final boolean useCustomKeyTextColor = false;
    // TODO: final boolean useCustomKeyTextColor =
    // AnyApplication.getConfig().getUseCustomTextColorOnKeys();
    final ColorStateList keyTextColor = useCustomKeyTextColor
            ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFF6666FF })
            : mKeyTextColor;
    // TODO: ? AnyApplication.getConfig().getCustomKeyTextColorOnKeys() :
    // mKeyTextColor;

    final boolean useCustomHintColor = drawHintText && false;
    // TODO: final boolean useCustomHintColor = drawHintText &&
    // AnyApplication.getConfig().getUseCustomHintColorOnKeys();
    final ColorStateList hintColor = useCustomHintColor
            ? new ColorStateList(new int[][] { { 0 } }, new int[] { 0xFFFF6666 })
            : mHintTextColor;
    // TODO: ? AnyApplication.getConfig().getCustomHintColorOnKeys() :
    // mHintTextColor;

    // allow preferences to override theme settings for hint text position
    final boolean useCustomHintAlign = drawHintText && AnyApplication.getConfig().getUseCustomHintAlign();
    final int hintAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintAlign()
            : mHintLabelAlign;
    final int hintVAlign = useCustomHintAlign ? AnyApplication.getConfig().getCustomHintVAlign()
            : mHintLabelVAlign;

    final Paint paint = mPaint;
    final Drawable keyBackground = mKeyBackground;
    final Rect clipRegion = mClipRegion;
    final int kbdPaddingLeft = getPaddingLeft();
    final int kbdPaddingTop = getPaddingTop();
    final Key[] keys = mKeys;
    final Key invalidKey = mInvalidatedKey;

    boolean drawSingleKey = false;
    if (invalidKey != null && canvas.getClipBounds(clipRegion)) {
        // TODO we should use Rect.inset and Rect.contains here.
        // Is clipRegion completely contained within the invalidated key?
        if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left
                && invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top
                && invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right
                && invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) {
            drawSingleKey = true;
        }
    }
    final int keyCount = keys.length;
    for (int i = 0; i < keyCount; i++) {
        final AnyKey key = (AnyKey) keys[i];
        final boolean keyIsSpace = isSpaceKey(key);

        if (drawSingleKey && (invalidKey != key)) {
            continue;
        }
        if (!mDirtyRect.intersects(key.x + kbdPaddingLeft, key.y + kbdPaddingTop,
                key.x + key.width + kbdPaddingLeft, key.y + key.height + kbdPaddingTop)) {
            continue;
        }
        int[] drawableState = key.getCurrentDrawableState(mDrawableStatesProvider);

        if (keyIsSpace)
            paint.setColor(mKeyboardNameTextColor.getColorForState(drawableState, 0xFF000000));
        else
            paint.setColor(keyTextColor.getColorForState(drawableState, 0xFF000000));
        keyBackground.setState(drawableState);

        // Switch the character to uppercase if shift is pressed
        CharSequence label = key.label == null ? null : adjustCase(key).toString();

        final Rect bounds = keyBackground.getBounds();
        if ((key.width != bounds.right) || (key.height != bounds.bottom)) {
            keyBackground.setBounds(0, 0, key.width, key.height);
        }
        canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop);
        keyBackground.draw(canvas);

        if (TextUtils.isEmpty(label)) {
            Drawable iconToDraw = getIconToDrawForKey(key, false);
            if (iconToDraw != null/* && shouldDrawIcon */) {
                //http://developer.android.com/reference/android/graphics/drawable/Drawable.html#getCurrent()
                //http://stackoverflow.com/a/103600/1324235
                final boolean is9Patch = iconToDraw.getCurrent() instanceof NinePatchDrawable;

                // Special handing for the upper-right number hint icons
                final int drawableWidth;
                final int drawableHeight;
                final int drawableX;
                final int drawableY;

                drawableWidth = is9Patch ? key.width : iconToDraw.getIntrinsicWidth();
                drawableHeight = is9Patch ? key.height : iconToDraw.getIntrinsicHeight();
                drawableX = (key.width + mKeyBackgroundPadding.left - mKeyBackgroundPadding.right
                        - drawableWidth) / 2;
                drawableY = (key.height + mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom
                        - drawableHeight) / 2;

                canvas.translate(drawableX, drawableY);
                iconToDraw.setBounds(0, 0, drawableWidth, drawableHeight);
                iconToDraw.draw(canvas);
                canvas.translate(-drawableX, -drawableY);
                if (keyIsSpace && drawKeyboardNameText) {
                    // now a little hack, I'll set the label now, so it get
                    // drawn.
                    label = mKeyboardName;
                }
            } else {
                // ho... no icon.
                // I'll try to guess the text
                label = guessLabelForKey(key.codes[0]);
                if (TextUtils.isEmpty(label)) {
                    Log.w(TAG, "That's unfortunate, for key " + key.codes[0] + " at (" + key.x + ", " + key.y
                            + ") there is no icon nor label. Action ID is " + mKeyboardActionType);
                }
            }
        }

        if (label != null) {
            // For characters, use large font. For labels like "Done", use
            // small font.
            final FontMetrics fm;
            if (keyIsSpace) {
                paint.setTextSize(mKeyboardNameTextSize);
                paint.setTypeface(Typeface.DEFAULT_BOLD);
                if (mKeyboardNameFM == null)
                    mKeyboardNameFM = paint.getFontMetrics();
                fm = mKeyboardNameFM;
            } else if (label.length() > 1 && key.codes.length < 2) {
                paint.setTextSize(mLabelTextSize);
                paint.setTypeface(Typeface.DEFAULT_BOLD);
                if (mLabelFM == null)
                    mLabelFM = paint.getFontMetrics();
                fm = mLabelFM;
            } else {
                fm = setPaintToKeyText(paint);
            }

            final float labelHeight = -fm.top;
            // Draw a drop shadow for the text
            paint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mShadowColor);

            // (+)This is the trick to get RTL/LTR text correct
            // no matter what: StaticLayout
            // this should be in the top left corner of the key
            float textWidth = paint.measureText(label, 0, label.length());
            // I'm going to try something if the key is too small for the
            // text:
            // 1) divide the text size by 1.5
            // 2) if still too large, divide by 2.5
            // 3) show no text
            if (textWidth > key.width) {
                Log.d(TAG, "Label '" + label + "' is too large for the key. Reducing by 1.5.");
                paint.setTextSize(mKeyTextSize / 1.5f);
                textWidth = paint.measureText(label, 0, label.length());
                if (textWidth > key.width) {
                    Log.d(TAG, "Label '" + label + "' is too large for the key. Reducing by 2.5.");
                    paint.setTextSize(mKeyTextSize / 2.5f);
                    textWidth = paint.measureText(label, 0, label.length());
                    if (textWidth > key.width) {
                        Log.d(TAG, "Label '" + label + "' is too large for the key. Showing no text.");
                        paint.setTextSize(0f);
                        textWidth = paint.measureText(label, 0, label.length());
                    }
                }
            }

            // the center of the drawable space, which is value used
            // previously for vertically
            // positioning the key label
            final float centerY = mKeyBackgroundPadding.top
                    + ((key.height - mKeyBackgroundPadding.top - mKeyBackgroundPadding.bottom)
                            / (keyIsSpace ? 3 : 2));// the label on the space is a bit higher

            // the X coordinate for the center of the main label text is
            // unaffected by the hints
            final float centerX = mKeyBackgroundPadding.left
                    + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2;

            final float textX = centerX;
            final float textY;
            // Some devices (mostly pre-Honeycomb, have issues with RTL text
            // drawing.
            // Of course, there is no issue with a single character :)
            // so, we'll use the RTL secured drawing (via StaticLayout) for
            // labels.
            if (label.length() > 1 && !AnyApplication.getConfig().workaround_alwaysUseDrawText()) {
                // calculate Y coordinate of top of text based on center
                // location
                textY = centerY - ((labelHeight - paint.descent()) / 2);
                canvas.translate(textX, textY);
                Log.d(TAG, "Using RTL fix for key draw '" + label + "'");
                // RTL fix. But it costs, let do it when in need (more than
                // 1 character)
                StaticLayout labelText = new StaticLayout(label, new TextPaint(paint), (int) textWidth,
                        Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
                labelText.draw(canvas);
            } else {
                // to get Y coordinate of baseline from center of text,
                // first add half the height (to get to
                // bottom of text), then subtract the part below the
                // baseline. Note that fm.top is negative.
                textY = centerY + ((labelHeight - paint.descent()) / 2);
                canvas.translate(textX, textY);
                canvas.drawText(label, 0, label.length(), 0, 0, paint);
            }
            canvas.translate(-textX, -textY);
            // (-)

            // Turn off drop shadow
            paint.setShadowLayer(0, 0, 0, 0);
        }

        if (drawHintText) {
            if ((key.popupCharacters != null && key.popupCharacters.length() > 0) || (key.popupResId != 0)
                    || (key.longPressCode != 0)) {
                Paint.Align oldAlign = paint.getTextAlign();

                String hintText = null;

                if (key.hintLabel != null && key.hintLabel.length() > 0) {
                    hintText = key.hintLabel.toString();
                    // it is the responsibility of the keyboard layout
                    // designer to ensure that they do
                    // not put too many characters in the hint label...
                } else if (key.longPressCode != 0) {
                    if (Character.isLetterOrDigit(key.longPressCode))
                        hintText = Character.toString((char) key.longPressCode);
                } else if (key.popupCharacters != null) {
                    final String hintString = key.popupCharacters.toString();
                    final int hintLength = hintString.length();
                    if (hintLength <= 3)
                        hintText = hintString;
                }

                // if hintText is still null, it means it didn't fit one of
                // the above
                // cases, so we should provide the hint using the default
                if (hintText == null) {
                    if (mHintOverflowLabel != null)
                        hintText = mHintOverflowLabel.toString();
                    else {
                        // theme does not provide a defaultHintLabel
                        // use  if hints are above, ... if hints are
                        // below
                        // (to avoid being too close to main label/icon)
                        if (hintVAlign == Gravity.TOP)
                            hintText = "";
                        else
                            hintText = "...";
                    }
                }

                if (mKeyboard.isShifted())
                    hintText = hintText.toUpperCase();

                // now draw hint
                paint.setTypeface(Typeface.DEFAULT);
                paint.setColor(hintColor.getColorForState(drawableState, 0xFF000000));
                paint.setTextSize(mHintTextSize);
                // get the hint text font metrics so that we know the size
                // of the hint when
                // we try to position the main label (to try to make sure
                // they don't overlap)
                if (mHintTextFM == null) {
                    mHintTextFM = paint.getFontMetrics();
                }

                final float hintX;
                final float hintY;

                // the (float) 0.5 value is added or subtracted to just give
                // a little more room
                // in case the theme designer didn't account for the hint
                // label location
                if (hintAlign == Gravity.LEFT) {
                    // left
                    paint.setTextAlign(Paint.Align.LEFT);
                    hintX = mKeyBackgroundPadding.left + (float) 0.5;
                } else if (hintAlign == Gravity.CENTER) {
                    // center
                    paint.setTextAlign(Paint.Align.CENTER);
                    hintX = mKeyBackgroundPadding.left
                            + (key.width - mKeyBackgroundPadding.left - mKeyBackgroundPadding.right) / 2;
                } else {
                    // right
                    paint.setTextAlign(Paint.Align.RIGHT);
                    hintX = key.width - mKeyBackgroundPadding.right - (float) 0.5;
                }

                if (hintVAlign == Gravity.TOP) {
                    // above
                    hintY = mKeyBackgroundPadding.top - mHintTextFM.top + (float) 0.5;
                } else {
                    // below
                    hintY = key.height - mKeyBackgroundPadding.bottom - mHintTextFM.bottom - (float) 0.5;
                }

                canvas.drawText(hintText, hintX, hintY, paint);
                paint.setTextAlign(oldAlign);
            }
        }

        canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop);
    }
    mInvalidatedKey = null;
    // Overlay a dark rectangle to dim the keyboard
    if (mMiniKeyboard != null && mMiniKeyboardVisible) {
        paint.setColor((int) (mBackgroundDimAmount * 0xFF) << 24);
        canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
    }

    if (FeaturesSet.DEBUG_LOG) {
        if (mShowTouchPoints) {
            for (PointerTracker tracker : mPointerTrackers) {
                int startX = tracker.getStartX();
                int startY = tracker.getStartY();
                int lastX = tracker.getLastX();
                int lastY = tracker.getLastY();
                paint.setAlpha(128);
                paint.setColor(0xFFFF0000);
                canvas.drawCircle(startX, startY, 3, paint);
                canvas.drawLine(startX, startY, lastX, lastY, paint);
                paint.setColor(0xFF0000FF);
                canvas.drawCircle(lastX, lastY, 3, paint);
                paint.setColor(0xFF00FF00);
                canvas.drawCircle((startX + lastX) / 2, (startY + lastY) / 2, 2, paint);
            }
        }
    }

    mDrawPending = false;
    mDirtyRect.setEmpty();
}

From source file:com.juick.android.JuickMessagesAdapter.java

public static String urlToFileName(Context ctx, String url) {
    StringBuilder sb = new StringBuilder();
    String curl = Uri.encode(url);
    int ask = url.indexOf('?');
    if (ask != -1) {
        String suburl = url.substring(0, ask);
        if (isValidImageURl(ctx, suburl)) {
            int q = suburl.lastIndexOf('.');
            // somefile.jpg?zz=true   -> somefile.jpg?zz=true.jpg   -> somefile.jpg_zz_true.jpg
            url += suburl.substring(q);//from  ww w . j ava2  s. c om
        }
    }
    for (int i = 0; i < curl.length(); i++) {
        char c = curl.charAt(i);
        if (Character.isLetterOrDigit(c) || c == '.') {
            sb.append(c);
        } else {
            sb.append("_");
        }
    }
    String retval = sb.toString();
    if (retval.length() > 120) {
        String md5DigestForString = Utils.getMD5DigestForString(retval).replace("/", "_");
        int q = retval.lastIndexOf('.');
        return "longname_" + md5DigestForString + retval.substring(q);
    }
    return retval;
}

From source file:org.apache.hadoop.hive.metastore.MetaStoreUtils.java

public static String encodeTableName(String name) {
    // The encoding method is simple, e.g., replace
    // all the special characters with the corresponding number in ASCII.
    // Note that unicode is not supported in table names. And we have explicit
    // checks for it.
    StringBuilder sb = new StringBuilder();
    for (char ch : name.toCharArray()) {
        if (Character.isLetterOrDigit(ch) || ch == '_') {
            sb.append(ch);/*from  w  ww.ja v  a  2  s .  c  o  m*/
        } else {
            sb.append('-').append((int) ch).append('-');
        }
    }
    return sb.toString();
}