Example usage for android.text.style ForegroundColorSpan getForegroundColor

List of usage examples for android.text.style ForegroundColorSpan getForegroundColor

Introduction

In this page you can find the example usage for android.text.style ForegroundColorSpan getForegroundColor.

Prototype

@ColorInt
public int getForegroundColor() 

Source Link

Usage

From source file:cgeo.geocaching.CacheDetailActivity.java

private static void fixTextColor(final Spannable spannable, final int backgroundColor) {
    final ForegroundColorSpan[] spans = spannable.getSpans(0, spannable.length(), ForegroundColorSpan.class);

    for (final ForegroundColorSpan span : spans) {
        if (ColorUtils.getContrastRatio(span.getForegroundColor(), backgroundColor) < CONTRAST_THRESHOLD) {
            final int start = spannable.getSpanStart(span);
            final int end = spannable.getSpanEnd(span);

            //  Assuming that backgroundColor can be either white or black,
            // this will set opposite background color (white for black and black for white)
            spannable.setSpan(new BackgroundColorSpan(backgroundColor ^ 0x00ffffff), start, end,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }/*from  w ww.j av  a2s.c o m*/
    }
}

From source file:org.zywx.wbpalmstar.plugin.chatkeyboard.ACEChatKeyboardView.java

private void jsonSendDataJsonCallback() {
    // TODO send callback Json
    if (mUexBaseObj != null) {
        JSONObject jsonObject = new JSONObject();
        try {//from   ww w.  j  a  v a2  s .  c  o m
            Editable editable = mEditText.getText();
            jsonObject.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_EMOJICONS_TEXT, editable.toString());
            JSONArray array = new JSONArray();
            ForegroundColorSpan[] spans = editable.getSpans(0, editable.length(), ForegroundColorSpan.class);
            for (ForegroundColorSpan span : spans) {
                JSONObject insertObj = new JSONObject();
                int spanStart = editable.getSpanStart(span);
                int spanEnd = editable.getSpanEnd(span);
                String insertText = editable.subSequence(spanStart, spanEnd).toString();
                String insertTextColor = "#" + Integer.toHexString(span.getForegroundColor()).substring(2);
                insertObj.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_START, spanStart);
                insertObj.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_END, spanEnd);
                insertObj.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_INSERTTEXT, insertText);
                insertObj.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_INSERTTEXTCOLOR, insertTextColor);
                array.put(insertObj);
            }
            jsonObject.put(EChatKeyboardUtils.CHATKEYBOARD_PARAMS_JSON_KEY_INSERTTEXTS, array);
            String js = EUExChatKeyboard.SCRIPT_HEADER + "if("
                    + EChatKeyboardUtils.CHATKEYBOARD_FUN_ON_COMMIT_JSON + "){"
                    + EChatKeyboardUtils.CHATKEYBOARD_FUN_ON_COMMIT_JSON + "(" + jsonObject.toString() + ");}";
            mUexBaseObj.onCallback(js);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}