Example usage for android.graphics Typeface ITALIC

List of usage examples for android.graphics Typeface ITALIC

Introduction

In this page you can find the example usage for android.graphics Typeface ITALIC.

Prototype

int ITALIC

To view the source code for android.graphics Typeface ITALIC.

Click Source Link

Usage

From source file:cgeo.geocaching.CacheDetailActivity.java

private void addWarning(final UnknownTagsHandler unknownTagsHandler, final Editable description) {
    if (unknownTagsHandler.isProblematicDetected()) {
        final int startPos = description.length();
        final IConnector connector = ConnectorFactory.getConnector(cache);
        if (StringUtils.isNotEmpty(cache.getUrl())) {
            final Spanned tableNote = Html.fromHtml(res.getString(R.string.cache_description_table_note,
                    "<a href=\"" + cache.getUrl() + "\">" + connector.getName() + "</a>"));
            description.append("\n\n").append(tableNote);
            description.setSpan(new StyleSpan(Typeface.ITALIC), startPos, description.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }/*from w w  w.  ja  v a 2  s  . c  o m*/
    }
}

From source file:com.codename1.impl.android.AndroidImplementation.java

@Override
public Object deriveTrueTypeFont(Object font, float size, int weight) {
    NativeFont fnt = (NativeFont) font;/*from   ww  w  .  j  a va 2 s  .c o m*/
    CodenameOneTextPaint paint = (CodenameOneTextPaint) fnt.font;
    paint.setAntiAlias(true);
    Typeface type = paint.getTypeface();
    int fontstyle = Typeface.NORMAL;
    if ((weight & Font.STYLE_BOLD) != 0 || type.isBold()) {
        fontstyle |= Typeface.BOLD;
    }
    if ((weight & Font.STYLE_ITALIC) != 0 || type.isItalic()) {
        fontstyle |= Typeface.ITALIC;
    }
    type = Typeface.create(type, fontstyle);
    CodenameOneTextPaint newPaint = new CodenameOneTextPaint(type);
    newPaint.setTextSize(size);
    newPaint.setAntiAlias(true);
    NativeFont n = new NativeFont(com.codename1.ui.Font.FACE_SYSTEM, weight, com.codename1.ui.Font.SIZE_MEDIUM,
            newPaint, fnt.fileName, size, weight);
    return n;
}

From source file:com.codename1.impl.android.AndroidImplementation.java

@Override
public Object createFont(int face, int style, int size) {
    Typeface typeface = null;//from   ww w .j  a  v a 2  s  .  co m
    switch (face) {
    case Font.FACE_MONOSPACE:
        typeface = Typeface.MONOSPACE;
        break;
    default:
        typeface = Typeface.DEFAULT;
        break;
    }

    int fontstyle = Typeface.NORMAL;
    if ((style & Font.STYLE_BOLD) != 0) {
        fontstyle |= Typeface.BOLD;
    }
    if ((style & Font.STYLE_ITALIC) != 0) {
        fontstyle |= Typeface.ITALIC;
    }

    int height = this.defaultFontHeight;
    int diff = height / 3;

    switch (size) {
    case Font.SIZE_SMALL:
        height -= diff;
        break;
    case Font.SIZE_LARGE:
        height += diff;
        break;
    }

    Paint font = new CodenameOneTextPaint(Typeface.create(typeface, fontstyle));
    font.setAntiAlias(true);
    font.setUnderlineText((style & Font.STYLE_UNDERLINED) != 0);
    font.setTextSize(height);
    return new NativeFont(face, style, size, font);

}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * Loads a native font based on a lookup for a font name and attributes.
 * Font lookup values can be separated by commas and thus allow fallback if
 * the primary font isn't supported by the platform.
 *
 * @param lookup string describing the font
 * @return the native font object//from  ww  w.java2 s.  co  m
 */
public Object loadNativeFont(String lookup) {
    try {
        lookup = lookup.split(";")[0];
        int typeface = Typeface.NORMAL;
        String familyName = lookup.substring(0, lookup.indexOf("-"));
        String style = lookup.substring(lookup.indexOf("-") + 1, lookup.lastIndexOf("-"));
        String size = lookup.substring(lookup.lastIndexOf("-") + 1, lookup.length());

        if (style.equals("bolditalic")) {
            typeface = Typeface.BOLD_ITALIC;
        } else if (style.equals("italic")) {
            typeface = Typeface.ITALIC;
        } else if (style.equals("bold")) {
            typeface = Typeface.BOLD;
        }
        Paint font = new CodenameOneTextPaint(Typeface.create(familyName, typeface));
        font.setAntiAlias(true);
        font.setTextSize(Integer.parseInt(size));
        return new NativeFont(0, 0, 0, font);
    } catch (Exception err) {
        return null;
    }
}

From source file:com.eveningoutpost.dexdrip.Home.java

private void displayCurrentInfoFromReading(BgReading lastBgReading, boolean predictive) {
    double estimate = 0;
    double estimated_delta = 0;

    String slope_arrow = lastBgReading.slopeArrow();
    String extrastring = "";
    if ((new Date().getTime()) - stale_data_millis() - lastBgReading.timestamp > 0) {
        notificationText.setText(R.string.signal_missed);
        if (!predictive) {
            estimate = lastBgReading.calculated_value;
        } else {//from w  w  w. j  a v a  2  s.c  o  m
            estimate = BgReading.estimated_bg(lastBgReading.timestamp + (6000 * 7));
        }
        currentBgValueText.setText(bgGraphBuilder.unitized_string(estimate));
        currentBgValueText.setPaintFlags(currentBgValueText.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        dexbridgeBattery.setPaintFlags(dexbridgeBattery.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
    } else {
        if (notificationText.getText().length() == 0) {
            notificationText.setTextColor(Color.WHITE);
        }
        boolean bg_from_filtered = prefs.getBoolean("bg_from_filtered", false);
        if (!predictive) {

            estimate = lastBgReading.calculated_value; // normal
            currentBgValueText.setTypeface(null, Typeface.NORMAL);

            // if noise has settled down then switch off filtered mode
            if ((bg_from_filtered) && (BgGraphBuilder.last_noise < BgGraphBuilder.NOISE_FORGIVE)
                    && (prefs.getBoolean("bg_compensate_noise", false))) {
                bg_from_filtered = false;
                prefs.edit().putBoolean("bg_from_filtered", false).apply();

            }

            if ((BgGraphBuilder.last_noise > BgGraphBuilder.NOISE_TRIGGER)
                    && (BgGraphBuilder.best_bg_estimate > 0) && (BgGraphBuilder.last_bg_estimate > 0)
                    && (prefs.getBoolean("bg_compensate_noise", false))) {
                estimate = BgGraphBuilder.best_bg_estimate; // this maybe needs scaling based on noise intensity
                estimated_delta = BgGraphBuilder.best_bg_estimate - BgGraphBuilder.last_bg_estimate;
                slope_arrow = BgReading
                        .slopeToArrowSymbol(estimated_delta / (BgGraphBuilder.DEXCOM_PERIOD / 60000)); // delta by minute
                currentBgValueText.setTypeface(null, Typeface.ITALIC);
                extrastring = "\u26A0"; // warning symbol !
            }

            if ((BgGraphBuilder.last_noise > BgGraphBuilder.NOISE_HIGH) && (DexCollectionType.hasFiltered())) {
                bg_from_filtered = true; // force filtered mode
            }

            if (bg_from_filtered) {
                currentBgValueText
                        .setPaintFlags(currentBgValueText.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
                estimate = lastBgReading.filtered_calculated_value;
            } else {
                currentBgValueText
                        .setPaintFlags(currentBgValueText.getPaintFlags() & ~Paint.UNDERLINE_TEXT_FLAG);
            }
            String stringEstimate = bgGraphBuilder.unitized_string(estimate);
            if ((lastBgReading.hide_slope) || (bg_from_filtered)) {
                slope_arrow = "";
            }
            currentBgValueText.setText(stringEstimate + " " + slope_arrow);
        } else {
            estimate = BgReading.activePrediction();
            String stringEstimate = bgGraphBuilder.unitized_string(estimate);
            currentBgValueText.setText(stringEstimate + " " + BgReading.activeSlopeArrow());
        }
        if (extrastring.length() > 0)
            currentBgValueText.setText(extrastring + currentBgValueText.getText());
    }
    int minutes = (int) (System.currentTimeMillis() - lastBgReading.timestamp) / (60 * 1000);

    if ((!small_width) || (notificationText.length() > 0))
        notificationText.append("\n");
    if (!small_width) {
        notificationText.append(minutes + ((minutes == 1) ? getString(R.string.space_minute_ago)
                : getString(R.string.space_minutes_ago)));
    } else {
        // small screen
        notificationText.append(minutes + getString(R.string.space_mins));
        currentBgValueText.setPadding(0, 0, 0, 0);
    }

    if (small_screen) {
        if (currentBgValueText.getText().length() > 4)
            currentBgValueText.setTextSize(25);
    }

    // do we actually need to do this query here if we again do it in unitizedDeltaString
    List<BgReading> bgReadingList = BgReading.latest(2, is_follower);
    if (bgReadingList != null && bgReadingList.size() == 2) {
        // same logic as in xDripWidget (refactor that to BGReadings to avoid redundancy / later inconsistencies)?

        display_delta = bgGraphBuilder.unitizedDeltaString(true, true, is_follower);

        // TODO reduce duplication of logic
        if ((BgGraphBuilder.last_noise > BgGraphBuilder.NOISE_TRIGGER) && (BgGraphBuilder.best_bg_estimate > 0)
                && (BgGraphBuilder.last_bg_estimate > 0) && (prefs.getBoolean("bg_compensate_noise", false))) {
            //final double estimated_delta = BgGraphBuilder.best_bg_estimate - BgGraphBuilder.last_bg_estimate;
            display_delta = bgGraphBuilder.unitizedDeltaStringRaw(true, true, estimated_delta);
            addDisplayDelta();
            if (!prefs.getBoolean("show_noise_workings", false)) {
                notificationText.append("\nNoise: " + bgGraphBuilder.noiseString(BgGraphBuilder.last_noise));
            }
        } else {
            addDisplayDelta();
        }

    }
    if (bgGraphBuilder.unitized(estimate) <= bgGraphBuilder.lowMark) {
        currentBgValueText.setTextColor(Color.parseColor("#C30909"));
    } else if (bgGraphBuilder.unitized(estimate) >= bgGraphBuilder.highMark) {
        currentBgValueText.setTextColor(Color.parseColor("#FFBB33"));
    } else {
        currentBgValueText.setTextColor(Color.WHITE);
    }
}

From source file:com.ichi2.anki2.Reviewer.java

private void displayCardQuestion() {
    // show timer, if activated in the deck's preferences
    initTimer();//from   w ww  . j a v  a 2  s.  co  m

    sDisplayAnswer = false;

    if (mButtonHeight == 0 && mRelativeButtonSize != 100) {
        mButtonHeight = mFlipCard.getHeight() * mRelativeButtonSize / 100;
        mFlipCard.setHeight(mButtonHeight);
        mEase1.setHeight(mButtonHeight);
        mEase2.setHeight(mButtonHeight);
        mEase3.setHeight(mButtonHeight);
        mEase4.setHeight(mButtonHeight);
    }

    setInterface();

    String question = mCurrentCard.getQuestion(mCurrentSimpleInterface);
    question = typeAnsQuestionFilter(question);

    if (mPrefFixArabic) {
        question = ArabicUtilities.reshapeSentence(question, true);
    }

    Log.i(AnkiDroidApp.TAG, "question: '" + question + "'");

    String displayString = "";

    if (mCurrentSimpleInterface) {
        mCardContent = convertToSimple(question);
        if (mCardContent.length() == 0) {
            SpannableString hint = new SpannableString(
                    getResources().getString(R.string.simple_interface_hint, R.string.card_details_question));
            hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            mCardContent = hint;
        }
    } else {
        // If the user wants to write the answer
        if (typeAnswer()) {
            mAnswerField.setVisibility(View.VISIBLE);

            // Show soft keyboard
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputMethodManager.showSoftInput(mAnswerField, InputMethodManager.SHOW_FORCED);
        }

        displayString = enrichWithQADiv(question, false);

        if (mSpeakText) {
            // ReadText.setLanguageInformation(Model.getModel(DeckManager.getMainDeck(),
            // mCurrentCard.getCardModelId(), false).getId(), mCurrentCard.getCardModelId());
        }

        if (mPrefRecord) {
            Recorder.reset();
            // check for auto record
            try {
                if (mSched.getCol().getDecks().confForDid(mCurrentCard.getDid()).getBoolean("autoRecord")) {
                    Recorder.startRecording();
                }
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
        }

    }

    updateCard(displayString);
    hideEaseButtons();

    // If the user want to show answer automatically
    if (mPrefUseTimer) {
        mTimeoutHandler.removeCallbacks(mShowAnswerTask);
        mTimeoutHandler.postDelayed(mShowAnswerTask, mWaitAnswerSecond * 1000);
    }
}

From source file:com.ichi2.anki2.Reviewer.java

private void displayCardAnswer() {
    Log.i(AnkiDroidApp.TAG, "displayCardAnswer");

    // prevent answering (by e.g. gestures) before card is loaded
    if (mCurrentCard == null) {
        return;/* www.  j a  v  a2  s. c  o  m*/
    }

    sDisplayAnswer = true;
    setFlipCardAnimation();

    String answer = mCurrentCard.getAnswer(mCurrentSimpleInterface);
    answer = typeAnsAnswerFilter(answer);

    String displayString = "";

    if (mCurrentSimpleInterface) {
        mCardContent = convertToSimple(answer);
        if (mCardContent.length() == 0) {
            SpannableString hint = new SpannableString(
                    getResources().getString(R.string.simple_interface_hint, R.string.card_details_answer));
            hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            mCardContent = hint;
        }
    } else {
        Sound.stopSounds();
        Recorder.stopRecording();

        if (mPrefFixArabic) {
            // reshape
            answer = ArabicUtilities.reshapeSentence(answer, true);
        }

        // If the user wrote an answer
        if (typeAnswer()) {
            mAnswerField.setVisibility(View.GONE);
            if (mCurrentCard != null) {
                if (mPrefFixArabic) {
                    // reshape
                    mTypeCorrect = ArabicUtilities.reshapeSentence(mTypeCorrect, true);
                }
                // Obtain the user answer and the correct answer
                String userAnswer = mAnswerField.getText().toString();
                Matcher matcher = sSpanPattern.matcher(Utils.stripHTMLMedia(mTypeCorrect));
                String correctAnswer = matcher.replaceAll("");
                matcher = sBrPattern.matcher(correctAnswer);
                correctAnswer = matcher.replaceAll("\n");
                matcher = Sound.sSoundPattern.matcher(correctAnswer);
                correctAnswer = matcher.replaceAll("");
                Log.i(AnkiDroidApp.TAG, "correct answer = " + correctAnswer);

                // Obtain the diff and send it to updateCard
                DiffEngine diff = new DiffEngine();

                StringBuffer span = new StringBuffer();
                span.append("<span style=\"font-family: '").append(mTypeFont).append("'; font-size: ")
                        .append(mTypeSize).append("px\">");
                span.append(diff.diff_prettyHtml(diff.diff_main(userAnswer, correctAnswer), mNightMode));
                span.append("</span>");
                span.append("<br/>").append(answer);
                displayString = enrichWithQADiv(span.toString(), true);
            }

            // Hide soft keyboard
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(mAnswerField.getWindowToken(), 0);
        } else {
            displayString = enrichWithQADiv(answer, true);
        }
    }

    mIsSelecting = false;
    updateCard(displayString);
    showEaseButtons();

    // If the user want to show next question automatically
    if (mPrefUseTimer) {
        mTimeoutHandler.removeCallbacks(mShowQuestionTask);
        mTimeoutHandler.postDelayed(mShowQuestionTask, mWaitQuestionSecond * 1000);
    }
}

From source file:com.hichinaschool.flashcards.anki.Reviewer.java

private void displayCardQuestion() {
    // show timer, if activated in the deck's preferences
    initTimer();/*from www . jav  a  2 s  . c om*/

    sDisplayAnswer = false;

    if (mButtonHeight == 0 && mRelativeButtonSize != 100) {
        mButtonHeight = mFlipCard.getHeight() * mRelativeButtonSize / 100;
        mFlipCard.setHeight(mButtonHeight);
        mEase1.setHeight(mButtonHeight);
        mEase2.setHeight(mButtonHeight);
        mEase3.setHeight(mButtonHeight);
        mEase4.setHeight(mButtonHeight);
    }

    setInterface();

    String question = mCurrentCard.getQuestion(mCurrentSimpleInterface);
    question = typeAnsQuestionFilter(question);

    if (mPrefFixArabic) {
        question = ArabicUtilities.reshapeSentence(question, true);
    }

    // Log.i(AnkiDroidApp.TAG, "question: '" + question + "'");

    String displayString = "";

    if (mCurrentSimpleInterface) {
        mCardContent = convertToSimple(question);
        if (mCardContent.length() == 0) {
            SpannableString hint = new SpannableString(
                    getResources().getString(R.string.simple_interface_hint, R.string.card_details_question));
            hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            mCardContent = hint;
        }
    } else {
        // If the user wants to write the answer
        if (typeAnswer()) {
            mAnswerField.setVisibility(View.VISIBLE);

            // Show soft keyboard
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputMethodManager.showSoftInput(mAnswerField, InputMethodManager.SHOW_FORCED);
        }

        displayString = enrichWithQADiv(question, false);

        if (mSpeakText) {
            // ReadText.setLanguageInformation(Model.getModel(DeckManager.getMainDeck(),
            // mCurrentCard.getCardModelId(), false).getId(), mCurrentCard.getCardModelId());
        }
    }

    updateCard(displayString);
    hideEaseButtons();

    // If the user want to show answer automatically
    if (mPrefUseTimer) {
        mTimeoutHandler.removeCallbacks(mShowAnswerTask);
        mTimeoutHandler.postDelayed(mShowAnswerTask, mWaitAnswerSecond * 1000);
    }
}

From source file:jmri.enginedriver.throttle.java

void showDirectionIndication(int whichThrottle, int direction) {

    boolean setLeftDirectionButtonEnabled;
    if (direction == 0) { //0=reverse 1=forward
        setLeftDirectionButtonEnabled = directionButtonsAreCurrentlyReversed(whichThrottle);
    } else {//from   ww w  . j  av  a  2  s .c  om
        setLeftDirectionButtonEnabled = !directionButtonsAreCurrentlyReversed(whichThrottle);
    }

    if (!getConsist(whichThrottle).isActive()) {
        bFwds[whichThrottle].setSelected(false);
        bRevs[whichThrottle].setSelected(false);
    } else {
        if (!setLeftDirectionButtonEnabled) {
            bFwds[whichThrottle].setSelected(false);
            bRevs[whichThrottle].setSelected(true);
            bFwds[whichThrottle].setTypeface(null, Typeface.NORMAL);
            bRevs[whichThrottle].setTypeface(null, Typeface.ITALIC + Typeface.BOLD);
            if ((getSpeed(whichThrottle) > 0) && (!dirChangeWhileMoving)) {
                bFwds[whichThrottle].setEnabled(false);
            }
            bRevs[whichThrottle].setEnabled(true);
        } else {
            bFwds[whichThrottle].setSelected(true);
            bRevs[whichThrottle].setSelected(false);
            bFwds[whichThrottle].setTypeface(null, Typeface.ITALIC + Typeface.BOLD);
            bRevs[whichThrottle].setTypeface(null, Typeface.NORMAL);
            bFwds[whichThrottle].setEnabled(true);
            if ((getSpeed(whichThrottle) > 0) && (!dirChangeWhileMoving)) {
                bRevs[whichThrottle].setEnabled(false);
            }
        }
    }

}

From source file:com.hichinaschool.flashcards.anki.Reviewer.java

private void displayCardAnswer() {
    // Log.i(AnkiDroidApp.TAG, "displayCardAnswer");

    // prevent answering (by e.g. gestures) before card is loaded
    if (mCurrentCard == null) {
        return;/*from  w  ww. j av a 2 s. c o m*/
    }

    sDisplayAnswer = true;
    setFlipCardAnimation();

    String answer = mCurrentCard.getAnswer(mCurrentSimpleInterface);
    answer = typeAnsAnswerFilter(answer);

    String displayString = "";

    if (mCurrentSimpleInterface) {
        mCardContent = convertToSimple(answer);
        if (mCardContent.length() == 0) {
            SpannableString hint = new SpannableString(
                    getResources().getString(R.string.simple_interface_hint, R.string.card_details_answer));
            hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            mCardContent = hint;
        }
    } else {
        Sound.stopSounds();

        if (mPrefFixArabic) {
            // reshape
            answer = ArabicUtilities.reshapeSentence(answer, true);
        }

        // If the user wrote an answer
        if (typeAnswer()) {
            mAnswerField.setVisibility(View.GONE);
            if (mCurrentCard != null) {
                if (mPrefFixArabic) {
                    // reshape
                    mTypeCorrect = ArabicUtilities.reshapeSentence(mTypeCorrect, true);
                }
                // Obtain the user answer and the correct answer
                String userAnswer = mAnswerField.getText().toString();
                Matcher matcher = sSpanPattern.matcher(Utils.stripHTMLMedia(mTypeCorrect));
                String correctAnswer = matcher.replaceAll("");
                matcher = sBrPattern.matcher(correctAnswer);
                correctAnswer = matcher.replaceAll("\n");
                matcher = Sound.sSoundPattern.matcher(correctAnswer);
                correctAnswer = matcher.replaceAll("");
                // Log.i(AnkiDroidApp.TAG, "correct answer = " + correctAnswer);

                // Obtain the diff and send it to updateCard
                DiffEngine diff = new DiffEngine();

                StringBuffer span = new StringBuffer();
                span.append("<span style=\"font-family: '").append(mTypeFont).append("'; font-size: ")
                        .append(mTypeSize).append("px\">");
                span.append(diff.diff_prettyHtml(diff.diff_main(userAnswer, correctAnswer), mNightMode));
                span.append("</span>");
                span.append("<br/>").append(answer);
                displayString = enrichWithQADiv(span.toString(), true);
            }

            // Hide soft keyboard
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(mAnswerField.getWindowToken(), 0);
        } else {
            displayString = enrichWithQADiv(answer, true);
        }
    }

    mIsSelecting = false;
    updateCard(displayString);
    showEaseButtons();

    // If the user want to show next question automatically
    if (mPrefUseTimer) {
        mTimeoutHandler.removeCallbacks(mShowQuestionTask);
        mTimeoutHandler.postDelayed(mShowQuestionTask, mWaitQuestionSecond * 1000);
    }
}