Example usage for java.lang Character toString

List of usage examples for java.lang Character toString

Introduction

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

Prototype

public static String toString(int codePoint) 

Source Link

Document

Returns a String object representing the specified character (Unicode code point).

Usage

From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.por.PORFileReader.java

private String parseStringField(BufferedReader reader) throws IOException {
    String temp = null;// www.j a  v  a 2s.c  o  m
    char[] tmp = new char[1];
    StringBuilder sb = new StringBuilder();
    while (reader.read(tmp) > 0) {
        temp = Character.toString(tmp[0]);//new String(tmp);
        if (temp.equals("/")) {
            break;
        } else {
            sb.append(temp);
        }
        //temp = sb.toString();//new String(tmp);
    }
    String base30numberString = sb.toString();
    //dbgLog.fine("base30numberString="+base30numberString);
    int base10equivalent = Integer.valueOf(base30numberString, 30);
    //dbgLog.fine("base10equivalent="+base10equivalent);
    char[] stringBody = new char[base10equivalent];
    reader.read(stringBody);
    String stringData = new String(stringBody);
    dbgLog.finer("stringData=" + stringData);
    return stringData;
}

From source file:gephi.spade.panel.fcsFile.java

/**
 * printFCSFile ---//from  ww w  .  ja  va  2 s  . c o  m
 * <p>
 * Prints all the fields of <code>fcsFile</code> f to standard output - for
 * testing.
 * <p>
 *
 * @param f
 *            <code>fcsFile</code> object to print to standard output.
 */
public static void printFCSFile(fcsFile f) {
    System.out.println("Version ID -=" + f.version + "=-");
    System.out.println("Text starts at -=" + f.textStart + "=-");
    System.out.println("Text ends at -=" + f.textEnd + "=-");
    System.out.println("Data starts at -=" + f.dataStart + "=-");
    System.out.println("Data ends at -=" + f.dataEnd + "=-");
    System.out.println("Analysis starts at -=" + f.analysisStart + "=-");
    System.out.println("Analysis ends at -=" + f.analysisEnd + "=-");
    System.out.println("Text delimiter -=" + Character.toString(f.delimiter) + "=-");
    System.out.println("Data type -=" + f.dataType + "=-");
    System.out.println("Cytometer -=" + f.cytometer + "=-");
    System.out.println("Lasers -=" + f.lasers + "=-");
    /*
     * System.out.println("LaserName (Count: " + f.laserASF.length + "):");
     * for(int i = 0; i < f.laserASF.length; i++) {
     * System.out.println("\t::" + f.laserASF[i]); }
     *
     * System.out.println("LaserASF (Count: " + f.laserName.length + "):");
     * for(int i = 0; i < f.laserName.length; i++) {
     * System.out.println("\t::" + f.laserName[i]); }
     *
     * System.out.println("LaserDelay (Count: " + f.laserDelay.length +
     * "):"); for(int i = 0; i < f.laserDelay.length; i++) {
     * System.out.println("\t::" + f.laserDelay[i]); }
     *
     * System.out.println("MODE -=" + f.mode + "=-");
     * System.out.println("Instrument -=" + f.instrument + "=-");
     * System.out.println("Experiment Time -=" + f.expTime + "=-");
     * System.out.println("Experiment File Name -=" + f.expFile + "=-");
     * System.out.println("Operator -=" + f.operatorName + "=-");
     * System.out.println("OS -=" + f.operatingSystem + "=-");
     * System.out.println("Date -=" + f.experimentDate + "=-");
     * System.out.println("Creator Software -=" + f.creatorSoftware + "=-");
     * System.out.println("Cytometer Number -=" + f.cytometerNumber + "=-");
     * System.out.println("Experiment Name -=" + f.experimentName + "=-");
     * System.out.println("Export Time -=" + f.exportTime + "=-");
     * System.out.println("Export User -=" + f.exportUser + "=-");
     * System.out.println("GUID -=" + f.GUID + "=-");
     * System.out.println("Window Extension -=" + f.windowExtension + "=-");
     * System.out.println("Threshold -=" + f.threshold + "=-");
     * System.out.println("Spill String -=" + f.spillString + "=-");
     * System.out.println("Tube Name -=" + f.tubeName + "=-");
     * System.out.println("Time Step -=" + f.timeStep + "=-");
     * System.out.println("Source -=" + f.source + "=-");
     * System.out.println("Text Ends -=" + f.endsText + "=-");
     * System.out.println("Next Data -=" + f.nextData + "=-");
     * System.out.println("B Time -=" + f.bTime + "=-");
     * System.out.println("Apply Compensation -=" + f.applyCompensation +
     * "=-"); System.out.println("Sample name -=" + f.sampleName + "=-");
     * System.out.println("Parameters -=" + f.parameters + "=-");
     * System.out.println("Total events -=" + f.totalEvents + "=-");
     *
     * System.out.println("Channel names (Count: " + f.channelName.length +
     * "):"); for(int i = 0; i < f.channelName.length; i++) {
     * System.out.println("\t::" + f.channelName[i]); }
     *
     * System.out.println("Channel short names (Count: " +
     * f.channelShortname.length + "):"); for(int i = 0; i <
     * f.channelShortname.length; i++) { System.out.println("\t::" +
     * f.channelShortname[i]); }
     *
     * System.out.println("Channel gains (Count: " + f.channelGain.length +
     * "):"); for(int i = 0; i < f.channelGain.length; i++) {
     * System.out.println("\t::" + f.channelGain[i]); }
     *
     * System.out.println(
     * "Channel amps (4=log, 0=linear -- aka the number of decades on the plot) (Count: "
     * + f.channelAmp.length + "):"); for(int i = 0; i <
     * f.channelAmp.length; i++) { System.out.println("\t::" +
     * f.channelAmp[i]); }
     *
     * System.out.println("Therefore, are channels log? (Count: " +
     * f.isLog.length + "):"); for(int i = 0; i < f.isLog.length; i++) {
     * System.out.println("\t::" + f.isLog[i]); }
     *
     * System.out.println("Display as log? (Count: " + f.displayLog.length +
     * "):"); for(int i = 0; i < f.displayLog.length; i++) {
     * System.out.println("\t::" + f.displayLog[i]); }
     *
     * System.out.println("Amp values (Count: " + f.ampValue.length + "):");
     * for(int i = 0; i < f.ampValue.length; i++) {
     * System.out.println("\t::" + f.ampValue[i]); }
     *
     * System.out.println("Channel bits (Count: " + f.channelBits.length +
     * "):"); for(int i = 0; i < f.channelBits.length; i++) {
     * System.out.println("\t::" + f.channelBits[i]); }
     *
     * System.out.println(
     * "Channel ranges (maximum number of bins; 1024 on Calibur; 262144 on LSRII) (Count: "
     * + f.channelRange.length + "):"); for(int i = 0; i <
     * f.channelRange.length; i++) { System.out.println("\t::" +
     * f.channelRange[i]); }
     *
     * System.out.println(
     * "Channel voltages (not working for Calibur yet) (Count: " +
     * f.channelVoltage.length + "):"); for(int i = 0; i <
     * f.channelVoltage.length; i++) { System.out.println("\t::" +
     * f.channelVoltage[i]); }
     *
     * System.out.println("All settings key / value pairs:");
     * //f.getSettings().list(System.out);
     *
     * // Get the settings Properties settings = f.getSettings();
     *
     * // Get all the keys Enumeration keys = settings.propertyNames();
     *
     * // Create a list to hold all the keys ArrayList keysList = new
     * ArrayList();
     *
     * String key;
     *
     * // Loop through all the keys getting their values
     * while(keys.hasMoreElements()) { // Get the current key key =
     * (String)keys.nextElement();
     *
     * // Add the current key to the list of keys keysList.add(key); }
     *
     * if(keysList.size() > 1) { // If there are more than one key in the
     * list of keys, then sort it. Collections.sort(keysList); }
     *
     * // Loop through the list of keys for(int i = 0; i < keysList.size();
     * i++) { // Get the current key key = (String)keysList.get(i);
     *
     * // Print the key/value pair System.out.print(key);
     * System.out.print("="); System.out.println(settings.getProperty(key));
     * }
     */

    // System.out.println("The entire text section (unformatted) -=" +
    // f.text + "=-");
    // Print out the first 50 events, if there are any
    f.printEvents(50);
}

From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.por.PORFileReader.java

private String getNumericFieldAsRawString(BufferedReader reader) throws IOException {
    String temp = null;/*from  ww  w .jav a  2 s  . c  o  m*/
    char[] tmp = new char[1];
    StringBuilder sb = new StringBuilder();
    while (reader.read(tmp) > 0) {
        temp = Character.toString(tmp[0]);//new String(tmp);
        if (temp.equals("/")) {
            break;
        } else {
            sb.append(temp);
        }
        //temp = sb.toString();//new String(tmp);
    }
    String base30numberString = sb.toString();
    dbgLog.finer("base30numberString=" + base30numberString);

    return base30numberString;
}

From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java

public String currencyRender(String currency, String currencyid) throws SessionExpiredException {
    KWLCurrency cur = (KWLCurrency) hibernateTemplate.load(KWLCurrency.class, currencyid);
    String symbol = cur.getHtmlcode();
    char temp = (char) Integer.parseInt(symbol, 16);
    symbol = Character.toString(temp);
    float v = 0;//from  ww w. j  a v  a  2  s  .  c om
    DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
    if (currency.equals("")) {
        return symbol;
    }
    v = Float.parseFloat(currency);
    String fmt = decimalFormat.format(v);
    fmt = symbol + fmt;
    return fmt;
}

From source file:com.yek.keyboard.anysoftkeyboard.AnySoftKeyboard.java

private void onNonFunctionKey(final int primaryCode, final Keyboard.Key key, final int multiTapIndex,
        final int[] nearByKeyCodes, final boolean fromUI) {
    if (BuildConfig.DEBUG)
        Logger.d(TAG, "onFunctionKey %d", primaryCode);

    final InputConnection ic = getCurrentInputConnection();

    switch (primaryCode) {
    case KeyCodes.ENTER:
        if (mShiftKeyState.isPressed() && ic != null) {
            //power-users feature ahead: Shift+Enter
            //getting away from firing the default editor action, by forcing newline
            ic.commitText("\n", 1);
            break;
        }/*from  w w  w .  j av  a  2  s  .co  m*/
        final EditorInfo editorInfo = getCurrentInputEditorInfo();
        final int imeOptionsActionId = IMEUtil.getImeOptionsActionIdFromEditorInfo(editorInfo);
        if (ic != null && IMEUtil.IME_ACTION_CUSTOM_LABEL == imeOptionsActionId) {
            // Either we have an actionLabel and we should performEditorAction with
            // actionId regardless of its value.
            ic.performEditorAction(editorInfo.actionId);
        } else if (ic != null && EditorInfo.IME_ACTION_NONE != imeOptionsActionId) {
            // We didn't have an actionLabel, but we had another action to execute.
            // EditorInfo.IME_ACTION_NONE explicitly means no action. In contrast,
            // EditorInfo.IME_ACTION_UNSPECIFIED is the default value for an action, so it
            // means there should be an action and the app didn't bother to set a specific
            // code for it - presumably it only handles one. It does not have to be treated
            // in any specific way: anything that is not IME_ACTION_NONE should be sent to
            // performEditorAction.
            ic.performEditorAction(imeOptionsActionId);
        } else {
            handleSeparator(primaryCode);
        }
        break;
    case KeyCodes.SPACE:
        //shortcut. Nothing more.
        handleSeparator(primaryCode);
        //should we switch to alphabet keyboard?
        if (!isInAlphabetKeyboardMode()) {
            Logger.d(TAG, "SPACE/ENTER while in symbols mode");
            if (mAskPrefs.getSwitchKeyboardOnSpace()) {
                Logger.d(TAG, "Switching to Alphabet is required by the user");
                getKeyboardSwitcher().nextKeyboard(getCurrentInputEditorInfo(),
                        KeyboardSwitcher.NextKeyboardType.Alphabet);
            }
        }
        break;
    case KeyCodes.TAB:
        sendTab();
        break;
    case KeyCodes.ESCAPE:
        sendEscape();
        break;
    default:
        if (isWordSeparator(primaryCode)) {
            handleSeparator(primaryCode);
        } else {
            if (mControlKeyState.isActive() && primaryCode >= 32 && primaryCode < 127) {
                // http://en.wikipedia.org/wiki/Control_character#How_control_characters_map_to_keyboards
                int controlCode = primaryCode & 31;
                Logger.d(TAG, "CONTROL state: Char was %d and now it is %d", primaryCode, controlCode);
                if (controlCode == 9) {
                    sendTab();
                } else {
                    ic.commitText(Character.toString((char) controlCode), 1);
                }
            } else {
                handleCharacter(primaryCode, key, multiTapIndex, nearByKeyCodes);
            }
            mJustAddedAutoSpace = false;
        }
        break;
    }
}

From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java

public String currencyRender(String currency, KWLCurrency cur) throws SessionExpiredException {
    String symbol = "";
    try {/*  www  .j  a  v a2s. co m*/
        char temp = (char) Integer.parseInt(cur.getHtmlcode(), 16);
        symbol = Character.toString(temp);
    } catch (Exception e) {
        symbol = cur.getHtmlcode();
    }
    float v = 0;
    DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
    if (currency.equals("")) {
        return symbol;
    }
    v = Float.parseFloat(currency);
    String fmt = decimalFormat.format(v);
    fmt = symbol + " " + fmt;
    return fmt;
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

private void onNonFunctionKey(final int primaryCode, final Key key, final int multiTapIndex,
        final int[] nearByKeyCodes, final boolean fromUI) {
    if (BuildConfig.DEBUG)
        Logger.d(TAG, "onFunctionKey %d", primaryCode);

    final InputConnection ic = getCurrentInputConnection();

    switch (primaryCode) {
    case KeyCodes.ENTER:
        if (mShiftKeyState.isPressed() && ic != null) {
            //power-users feature ahead: Shift+Enter
            //getting away from firing the default editor action, by forcing newline
            ic.commitText("\n", 1);
            break;
        }//from www .  j ava2 s .c o m
        final EditorInfo editorInfo = getCurrentInputEditorInfo();
        final int imeOptionsActionId = IMEUtil.getImeOptionsActionIdFromEditorInfo(editorInfo);
        if (ic != null && IMEUtil.IME_ACTION_CUSTOM_LABEL == imeOptionsActionId) {
            // Either we have an actionLabel and we should performEditorAction with
            // actionId regardless of its value.
            ic.performEditorAction(editorInfo.actionId);
        } else if (ic != null && EditorInfo.IME_ACTION_NONE != imeOptionsActionId) {
            // We didn't have an actionLabel, but we had another action to execute.
            // EditorInfo.IME_ACTION_NONE explicitly means no action. In contrast,
            // EditorInfo.IME_ACTION_UNSPECIFIED is the default value for an action, so it
            // means there should be an action and the app didn't bother to set a specific
            // code for it - presumably it only handles one. It does not have to be treated
            // in any specific way: anything that is not IME_ACTION_NONE should be sent to
            // performEditorAction.
            ic.performEditorAction(imeOptionsActionId);
        } else {
            handleSeparator(primaryCode);
        }
        break;
    case KeyCodes.SPACE:
        //shortcut. Nothing more.
        handleSeparator(primaryCode);
        //should we switch to alphabet keyboard?
        if (!isInAlphabetKeyboardMode()) {
            Logger.d(TAG, "SPACE/ENTER while in symbols mode");
            if (mAskPrefs.getSwitchKeyboardOnSpace()) {
                Logger.d(TAG, "Switching to Alphabet is required by the user");
                getKeyboardSwitcher().nextKeyboard(getCurrentInputEditorInfo(), NextKeyboardType.Alphabet);
            }
        }
        break;
    case KeyCodes.TAB:
        sendTab();
        break;
    case KeyCodes.ESCAPE:
        sendEscape();
        break;
    default:
        if (isWordSeparator(primaryCode)) {
            handleSeparator(primaryCode);
        } else {
            if (mControlKeyState.isActive() && primaryCode >= 32 && primaryCode < 127) {
                // http://en.wikipedia.org/wiki/Control_character#How_control_characters_map_to_keyboards
                int controlCode = primaryCode & 31;
                Logger.d(TAG, "CONTROL state: Char was %d and now it is %d", primaryCode, controlCode);
                if (controlCode == 9) {
                    sendTab();
                } else {
                    ic.commitText(Character.toString((char) controlCode), 1);
                }
            } else {
                handleCharacter(primaryCode, key, multiTapIndex, nearByKeyCodes);
            }
            mJustAddedAutoSpace = false;
        }
        break;
    }
}

From source file:com.rapidminer.tools.Tools.java

/**
 * Replace quote chars in-quote characters by escapeChar+quotingChar
 *
 * Example: seperatorPatern = ',' , quotingChar = '"' , escapeCahr = '\\'
 *
 * line = '"Charles says:/*from  www . java  2  s  .c om*/
 * "Some people never go crazy, What truly horrible lives they must live"", 1968, "
 * US"' return = '"Charles says:
 * \"Some people never go crazy, What truly horrible lives they must live\"", "1968", "US"'
 */
public static String escapeQuoteCharsInQuotes(String line, Pattern separatorPattern, char quotingChar,
        char escapeChar, boolean showWarning) {
    // first remember quoteChar positions which should be escaped:
    char lastChar = '0';
    boolean openedQuote = false;

    List<Integer> rememberQuotePosition = new LinkedList<>();
    for (int i = 0; i < line.length(); i++) {
        if (lastChar == quotingChar) {
            if (openedQuote) {
                boolean matches = Pattern.matches(separatorPattern.pattern() + ".*", line.substring(i));
                if (matches) {
                    openedQuote = false;
                } else {
                    rememberQuotePosition.add(i - 1);
                }

            } else {
                openedQuote = true;
            }
        }
        lastChar = line.charAt(i);
    }
    if (openedQuote && lastChar == quotingChar) {
        openedQuote = false;
    }

    // print warning
    if (showWarning && !rememberQuotePosition.isEmpty()) {

        StringBuilder positions = new StringBuilder();
        int j = 1;
        for (int i = 0; i < rememberQuotePosition.size(); i++) {
            if (j % 10 == 0) {
                positions.append("\n");
            }
            positions.append(rememberQuotePosition.get(i));
            if (i + 1 < rememberQuotePosition.size()) {
                positions.append(", ");
            }
            j++;
        }

        String lineBeginning = line;
        if (line.length() > 20) {
            lineBeginning = line.substring(0, 20);
        }
        String warning = "While reading the line starting with \n\n\t" + lineBeginning + "   ...\n\n"
                + ",an unescaped quote character was substituted by an escaped quote at the position(s) "
                + positions.toString() + ". " + "In particular der character '" + Character.toString(lastChar)
                + "' was replaced by '" + Character.toString(escapeChar) + Character.toString(lastChar) + ".";

        LogService.getRoot().log(Level.WARNING, warning);
    }

    // then build new line:
    if (!rememberQuotePosition.isEmpty()) {
        String newLine = "";
        int pos = rememberQuotePosition.remove(0);
        int i = 0;
        for (Character c : line.toCharArray()) {
            if (i == pos) {
                newLine += Character.toString(escapeChar) + c;
                if (!rememberQuotePosition.isEmpty()) {
                    pos = rememberQuotePosition.remove(0);
                }
            } else {
                newLine += c;
            }
            i++;
        }
        line = newLine;
    }
    return line;
}

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

private void onBufferDraw(Canvas canvas) {
    if (mKeyboardChanged) {
        invalidateAllKeys();/*from  w  w w . j ava2  s.c o m*/
        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.mirth.connect.donkey.server.data.jdbc.JdbcDao.java

@Override
public List<ConnectorMessage> getConnectorMessages(String channelId, String serverId, int metaDataId,
        Status status, int offset, int limit, Long minMessageId, Long maxMessageId) {
    List<ConnectorMessage> connectorMessages = new ArrayList<ConnectorMessage>();

    if (limit == 0) {
        return connectorMessages;
    }/*  w  ww.ja  v  a  2 s  . co  m*/

    PreparedStatement statement = null;
    ResultSet resultSet = null;

    try {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("localChannelId", getLocalChannelId(channelId));
        params.put("offset", offset);
        params.put("limit", limit);

        if (minMessageId == null || maxMessageId == null) {
            statement = connection.prepareStatement(
                    querySource.getQuery("getConnectorMessagesByMetaDataIdAndStatusWithLimit", params));
            statement.setInt(1, metaDataId);
            statement.setString(2, Character.toString(status.getStatusCode()));
            statement.setString(3, serverId);
        } else {
            statement = connection.prepareStatement(
                    querySource.getQuery("getConnectorMessagesByMetaDataIdAndStatusWithLimitAndRange", params));
            statement.setInt(1, metaDataId);
            statement.setString(2, Character.toString(status.getStatusCode()));
            statement.setString(3, serverId);
            statement.setLong(4, minMessageId);
            statement.setLong(5, maxMessageId);
        }

        resultSet = statement.executeQuery();

        while (resultSet.next()) {
            connectorMessages.add(getConnectorMessageFromResultSet(channelId, resultSet, true, true));
        }

        return connectorMessages;
    } catch (SQLException e) {
        throw new DonkeyDaoException(e);
    } finally {
        close(resultSet);
        close(statement);
    }
}