Example usage for android.graphics Typeface BOLD

List of usage examples for android.graphics Typeface BOLD

Introduction

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

Prototype

int BOLD

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

Click Source Link

Usage

From source file:com.android.mms.transaction.MessagingNotification.java

protected static CharSequence buildTickerMessage(Context context, String address, String subject, String body) {
    String displayAddress = Contact.get(address, true).getName();

    StringBuilder buf = new StringBuilder(
            displayAddress == null ? "" : displayAddress.replace('\n', ' ').replace('\r', ' '));
    if (!TextUtils.isEmpty(subject) && !TextUtils.isEmpty(body)) {
        buf.append(':').append(' ');
    }/*from  w ww  . ja  va  2  s  .c om*/

    int offset = buf.length();
    if (!TextUtils.isEmpty(subject)) {
        subject = subject.replace('\n', ' ').replace('\r', ' ');
        buf.append(subject);
        buf.append(' ');
    }

    if (!TextUtils.isEmpty(body)) {
        body = body.replace('\n', ' ').replace('\r', ' ');
        buf.append(body);
    }

    SpannableString spanText = new SpannableString(buf.toString());
    spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, offset, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spanText;
}

From source file:ru.valle.btc.MainActivity.java

private void tryToGenerateSpendingTransaction() {
    final ArrayList<UnspentOutputInfo> unspentOutputs = verifiedUnspentOutputsForTx;
    final String outputAddress = verifiedRecipientAddressForTx;
    final long requestedAmountToSend = verifiedAmountToSendForTx;
    final KeyPair keyPair = verifiedKeyPairForTx;
    final boolean inputsComesFromJson = verifiedUnspentOutputsComesFromJson;
    final int predefinedConfirmationsCount = verifiedConfirmationsCount;

    spendTxDescriptionView.setVisibility(View.GONE);
    spendTxWarningView.setVisibility(View.GONE);
    spendTxEdit.setText("");
    spendTxEdit.setVisibility(View.GONE);
    sendTxInBrowserButton.setVisibility(View.GONE);
    findViewById(R.id.spend_tx_required_age_for_free_tx).setVisibility(View.GONE);
    //        https://blockchain.info/pushtx

    if (unspentOutputs != null && !unspentOutputs.isEmpty() && !TextUtils.isEmpty(outputAddress)
            && keyPair != null && requestedAmountToSend >= SEND_MAX && requestedAmountToSend != 0
            && !TextUtils.isEmpty(keyPair.address)) {
        cancelAllRunningTasks();//from ww  w.  j  av a2 s  . c om
        generateTransactionTask = new AsyncTask<Void, Void, GenerateTransactionResult>() {

            @Override
            protected GenerateTransactionResult doInBackground(Void... voids) {
                final Transaction spendTx;
                try {
                    long availableAmount = 0;
                    for (UnspentOutputInfo unspentOutputInfo : unspentOutputs) {
                        availableAmount += unspentOutputInfo.value;
                    }
                    long amount;
                    if (availableAmount == requestedAmountToSend || requestedAmountToSend == SEND_MAX) {
                        //transfer maximum possible amount
                        amount = -1;
                    } else {
                        amount = requestedAmountToSend;
                    }
                    long extraFee;
                    SharedPreferences preferences = PreferenceManager
                            .getDefaultSharedPreferences(MainActivity.this);
                    try {
                        extraFee = preferences.getLong(PreferencesActivity.PREF_EXTRA_FEE,
                                FeePreference.PREF_EXTRA_FEE_DEFAULT);
                    } catch (ClassCastException e) {
                        preferences.edit().remove(PreferencesActivity.PREF_EXTRA_FEE)
                                .putLong(PreferencesActivity.PREF_EXTRA_FEE,
                                        FeePreference.PREF_EXTRA_FEE_DEFAULT)
                                .commit();
                        extraFee = FeePreference.PREF_EXTRA_FEE_DEFAULT;
                    }
                    spendTx = BTCUtils.createTransaction(unspentOutputs, outputAddress, keyPair.address, amount,
                            extraFee, keyPair.publicKey, keyPair.privateKey);

                    //6. double check that generated transaction is valid
                    Transaction.Script[] relatedScripts = new Transaction.Script[spendTx.inputs.length];
                    for (int i = 0; i < spendTx.inputs.length; i++) {
                        Transaction.Input input = spendTx.inputs[i];
                        for (UnspentOutputInfo unspentOutput : unspentOutputs) {
                            if (Arrays.equals(unspentOutput.txHash, input.outPoint.hash)
                                    && unspentOutput.outputIndex == input.outPoint.index) {
                                relatedScripts[i] = unspentOutput.script;
                                break;
                            }
                        }
                    }
                    BTCUtils.verify(relatedScripts, spendTx);
                } catch (BitcoinException e) {
                    switch (e.errorCode) {
                    case BitcoinException.ERR_INSUFFICIENT_FUNDS:
                        return new GenerateTransactionResult(getString(R.string.error_not_enough_funds),
                                GenerateTransactionResult.ERROR_SOURCE_AMOUNT_FIELD);
                    case BitcoinException.ERR_FEE_IS_TOO_BIG:
                        return new GenerateTransactionResult(getString(R.string.generated_tx_have_too_big_fee),
                                GenerateTransactionResult.ERROR_SOURCE_INPUT_TX_FIELD);
                    case BitcoinException.ERR_MEANINGLESS_OPERATION://input, output and change addresses are same.
                        return new GenerateTransactionResult(getString(R.string.output_address_same_as_input),
                                GenerateTransactionResult.ERROR_SOURCE_ADDRESS_FIELD);
                    //                            case BitcoinException.ERR_INCORRECT_PASSWORD
                    //                            case BitcoinException.ERR_WRONG_TYPE:
                    //                            case BitcoinException.ERR_FEE_IS_LESS_THEN_ZERO
                    //                            case BitcoinException.ERR_CHANGE_IS_LESS_THEN_ZERO
                    //                            case BitcoinException.ERR_AMOUNT_TO_SEND_IS_LESS_THEN_ZERO
                    default:
                        return new GenerateTransactionResult(
                                getString(R.string.error_failed_to_create_transaction) + ": " + e.getMessage(),
                                GenerateTransactionResult.ERROR_SOURCE_UNKNOWN);
                    }
                } catch (Exception e) {
                    return new GenerateTransactionResult(
                            getString(R.string.error_failed_to_create_transaction) + ": " + e,
                            GenerateTransactionResult.ERROR_SOURCE_UNKNOWN);
                }

                long inValue = 0;
                for (Transaction.Input input : spendTx.inputs) {
                    for (UnspentOutputInfo unspentOutput : unspentOutputs) {
                        if (Arrays.equals(unspentOutput.txHash, input.outPoint.hash)
                                && unspentOutput.outputIndex == input.outPoint.index) {
                            inValue += unspentOutput.value;
                        }
                    }
                }
                long outValue = 0;
                for (Transaction.Output output : spendTx.outputs) {
                    outValue += output.value;
                }
                long fee = inValue - outValue;
                return new GenerateTransactionResult(spendTx, fee);
            }

            @Override
            protected void onPostExecute(GenerateTransactionResult result) {
                super.onPostExecute(result);
                generateTransactionTask = null;
                if (result != null) {
                    final TextView rawTxToSpendErr = (TextView) findViewById(R.id.err_raw_tx);
                    if (result.tx != null) {
                        String amountStr = null;
                        Transaction.Script out = null;
                        try {
                            out = Transaction.Script.buildOutput(outputAddress);
                        } catch (BitcoinException ignore) {
                        }
                        if (result.tx.outputs[0].script.equals(out)) {
                            amountStr = BTCUtils.formatValue(result.tx.outputs[0].value);
                        }
                        if (amountStr == null) {
                            rawTxToSpendErr.setText(R.string.error_unknown);
                        } else {
                            String descStr;
                            String feeStr = BTCUtils.formatValue(result.fee);
                            String changeStr;
                            if (result.tx.outputs.length == 1) {
                                changeStr = null;
                                descStr = getString(R.string.spend_tx_description, amountStr, keyPair.address,
                                        outputAddress, feeStr);
                            } else if (result.tx.outputs.length == 2) {
                                changeStr = BTCUtils.formatValue(result.tx.outputs[1].value);
                                descStr = getString(R.string.spend_tx_with_change_description, amountStr,
                                        keyPair.address, outputAddress, feeStr, changeStr);
                            } else {
                                throw new RuntimeException();
                            }
                            SpannableStringBuilder descBuilder = new SpannableStringBuilder(descStr);

                            int spanBegin = descStr.indexOf(keyPair.address);
                            if (spanBegin >= 0) {//from
                                ForegroundColorSpan addressColorSpan = new ForegroundColorSpan(
                                        getColor(MainActivity.this, R.color.dark_orange));
                                descBuilder.setSpan(addressColorSpan, spanBegin,
                                        spanBegin + keyPair.address.length(),
                                        SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
                            }
                            if (spanBegin >= 0) {
                                spanBegin = descStr.indexOf(keyPair.address, spanBegin + 1);
                                if (spanBegin >= 0) {//change
                                    ForegroundColorSpan addressColorSpan = new ForegroundColorSpan(
                                            getColor(MainActivity.this, R.color.dark_orange));
                                    descBuilder.setSpan(addressColorSpan, spanBegin,
                                            spanBegin + keyPair.address.length(),
                                            SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
                                }
                            }
                            spanBegin = descStr.indexOf(outputAddress);
                            if (spanBegin >= 0) {//dest
                                ForegroundColorSpan addressColorSpan = new ForegroundColorSpan(
                                        getColor(MainActivity.this, R.color.dark_green));
                                descBuilder.setSpan(addressColorSpan, spanBegin,
                                        spanBegin + outputAddress.length(),
                                        SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
                            }
                            final String nbspBtc = "\u00a0BTC";
                            spanBegin = descStr.indexOf(amountStr + nbspBtc);
                            if (spanBegin >= 0) {
                                descBuilder.setSpan(new StyleSpan(Typeface.BOLD), spanBegin,
                                        spanBegin + amountStr.length() + nbspBtc.length(),
                                        SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
                            }
                            spanBegin = descStr.indexOf(feeStr + nbspBtc, spanBegin);
                            if (spanBegin >= 0) {
                                descBuilder.setSpan(new StyleSpan(Typeface.BOLD), spanBegin,
                                        spanBegin + feeStr.length() + nbspBtc.length(),
                                        SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
                            }
                            if (changeStr != null) {
                                spanBegin = descStr.indexOf(changeStr + nbspBtc, spanBegin);
                                if (spanBegin >= 0) {
                                    descBuilder.setSpan(new StyleSpan(Typeface.BOLD), spanBegin,
                                            spanBegin + changeStr.length() + nbspBtc.length(),
                                            SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
                                }
                            }
                            spendTxDescriptionView.setText(descBuilder);
                            spendTxDescriptionView.setVisibility(View.VISIBLE);
                            spendTxWarningView.setVisibility(View.VISIBLE);
                            spendTxEdit.setText(BTCUtils.toHex(result.tx.getBytes()));
                            spendTxEdit.setVisibility(View.VISIBLE);
                            sendTxInBrowserButton.setVisibility(View.VISIBLE);

                            TextView maxAgeView = (TextView) findViewById(
                                    R.id.spend_tx_required_age_for_free_tx);
                            CheckBox maxAgeCheckBox = (CheckBox) findViewById(
                                    R.id.spend_tx_required_age_for_free_tx_checkbox);
                            if (!inputsComesFromJson) {
                                if (!showNotEligibleForNoFeeBecauseOfBasicConstrains(maxAgeView, result.tx)) {
                                    final int confirmations = (int) (BTCUtils.MIN_PRIORITY_FOR_NO_FEE
                                            * result.tx.getBytes().length / unspentOutputs.get(0).value);
                                    float daysFloat = confirmations / BTCUtils.EXPECTED_BLOCKS_PER_DAY;
                                    String timePeriodStr;
                                    if (daysFloat <= 1) {
                                        int hours = (int) Math.round(Math.ceil(daysFloat / 24));
                                        timePeriodStr = getResources().getQuantityString(R.plurals.hours, hours,
                                                hours);
                                    } else {
                                        int days = (int) Math.round(Math.ceil(daysFloat));
                                        timePeriodStr = getResources().getQuantityString(R.plurals.days, days,
                                                days);
                                    }
                                    maxAgeCheckBox.setText(getString(R.string.input_tx_is_old_enough,
                                            getResources().getQuantityString(R.plurals.confirmations,
                                                    confirmations, confirmations),
                                            timePeriodStr));
                                    maxAgeCheckBox.setVisibility(View.VISIBLE);
                                    maxAgeCheckBox.setOnCheckedChangeListener(null);
                                    maxAgeCheckBox.setChecked(predefinedConfirmationsCount > 0);
                                    maxAgeCheckBox.setOnCheckedChangeListener(
                                            new CompoundButton.OnCheckedChangeListener() {
                                                @Override
                                                public void onCheckedChanged(CompoundButton buttonView,
                                                        boolean isChecked) {
                                                    verifiedConfirmationsCount = isChecked ? confirmations : -1;
                                                    onUnspentOutputsInfoChanged();
                                                }
                                            });
                                } else {
                                    maxAgeCheckBox.setVisibility(View.GONE);
                                }
                            } else {
                                showNotEligibleForNoFeeBecauseOfBasicConstrains(maxAgeView, result.tx);
                            }
                        }
                    } else if (result.errorSource == GenerateTransactionResult.ERROR_SOURCE_INPUT_TX_FIELD) {
                        rawTxToSpendErr.setText(result.errorMessage);
                    } else if (result.errorSource == GenerateTransactionResult.ERROR_SOURCE_ADDRESS_FIELD
                            || result.errorSource == GenerateTransactionResult.HINT_FOR_ADDRESS_FIELD) {
                        ((TextView) findViewById(R.id.err_recipient_address)).setText(result.errorMessage);
                    } else if (!TextUtils.isEmpty(result.errorMessage)
                            && result.errorSource == GenerateTransactionResult.ERROR_SOURCE_UNKNOWN) {
                        new AlertDialog.Builder(MainActivity.this).setMessage(result.errorMessage)
                                .setPositiveButton(android.R.string.ok, null).show();
                    }

                    ((TextView) findViewById(R.id.err_amount))
                            .setText(result.errorSource == GenerateTransactionResult.ERROR_SOURCE_AMOUNT_FIELD
                                    ? result.errorMessage
                                    : "");
                }
            }

            private boolean showNotEligibleForNoFeeBecauseOfBasicConstrains(TextView maxAgeView,
                    Transaction tx) {
                long minOutput = Long.MAX_VALUE;
                for (Transaction.Output output : tx.outputs) {
                    minOutput = Math.min(output.value, minOutput);
                }
                int txLen = tx.getBytes().length;
                if (txLen >= BTCUtils.MAX_TX_LEN_FOR_NO_FEE) {
                    maxAgeView.setText(
                            getResources().getQuantityText(R.plurals.tx_size_too_big_to_be_free, txLen));
                    maxAgeView.setVisibility(View.VISIBLE);
                    return true;
                } else if (minOutput < BTCUtils.MIN_MIN_OUTPUT_VALUE_FOR_NO_FEE) {
                    maxAgeView
                            .setText(getString(R.string.tx_output_is_too_small, BTCUtils.formatValue(minOutput),
                                    BTCUtils.formatValue(BTCUtils.MIN_MIN_OUTPUT_VALUE_FOR_NO_FEE)));
                    maxAgeView.setVisibility(View.VISIBLE);
                    return true;
                }
                maxAgeView.setVisibility(View.GONE);
                return false;
            }
        }.execute();
    }
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

/**
 * Return the layout for a numbered event. Create it if not already existing
 *///ww w. java 2s .  c o  m
private StaticLayout getEventLayout(StaticLayout[] layouts, int i, Event event, Paint paint, Rect r) {
    if (i < 0 || i >= layouts.length) {
        return null;
    }

    StaticLayout layout = layouts[i];
    // Check if we have already initialized the StaticLayout and that
    // the width hasn't changed (due to vertical resizing which causes
    // re-layout of events at min height)
    if (layout == null || r.width() != layout.getWidth()) {
        SpannableStringBuilder bob = new SpannableStringBuilder();
        if (event.title != null) {
            // MAX - 1 since we add a space
            bob.append(drawTextSanitizer(event.title.toString(), MAX_EVENT_TEXT_LEN - 1));
            bob.setSpan(new StyleSpan(Typeface.BOLD), 0, bob.length(), 0);
            bob.append(' ');
        }
        if (event.location != null) {
            bob.append(drawTextSanitizer(event.location.toString(), MAX_EVENT_TEXT_LEN - bob.length()));
        }

        paint.setColor(mEventTextColor);

        // Leave a one pixel boundary on the left and right of the rectangle for the event
        layout = new StaticLayout(bob, 0, bob.length(), new TextPaint(paint), r.width(), Alignment.ALIGN_NORMAL,
                1.0f, 0.0f, true, null, r.width());

        layouts[i] = layout;
    }
    layout.getPaint().setAlpha(mEventsAlpha);
    return layout;
}

From source file:plugin.google.maps.GoogleMaps.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override//w  w w  .j  a v  a 2 s .c  o m
public View getInfoContents(Marker marker) {
    String title = marker.getTitle();
    String snippet = marker.getSnippet();
    if ((title == null) && (snippet == null)) {
        return null;
    }

    JSONObject properties = null;
    JSONObject styles = null;
    String propertyId = "marker_property_" + marker.getId();
    PluginEntry pluginEntry = this.plugins.get("Marker");
    PluginMarker pluginMarker = (PluginMarker) pluginEntry.plugin;
    if (pluginMarker.objects.containsKey(propertyId)) {
        properties = (JSONObject) pluginMarker.objects.get(propertyId);

        if (properties.has("styles")) {
            try {
                styles = (JSONObject) properties.getJSONObject("styles");
            } catch (JSONException e) {
            }
        }
    }

    // Linear layout
    LinearLayout windowLayer = new LinearLayout(activity);
    windowLayer.setPadding(3, 3, 3, 3);
    windowLayer.setOrientation(LinearLayout.VERTICAL);
    LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER;
    windowLayer.setLayoutParams(layoutParams);

    //----------------------------------------
    // text-align = left | center | right
    //----------------------------------------
    int gravity = Gravity.LEFT;
    int textAlignment = View.TEXT_ALIGNMENT_GRAVITY;

    if (styles != null) {
        try {
            String textAlignValue = styles.getString("text-align");

            switch (TEXT_STYLE_ALIGNMENTS.valueOf(textAlignValue)) {
            case left:
                gravity = Gravity.LEFT;
                textAlignment = View.TEXT_ALIGNMENT_GRAVITY;
                break;
            case center:
                gravity = Gravity.CENTER;
                textAlignment = View.TEXT_ALIGNMENT_CENTER;
                break;
            case right:
                gravity = Gravity.RIGHT;
                textAlignment = View.TEXT_ALIGNMENT_VIEW_END;
                break;
            }

        } catch (Exception e) {
        }
    }

    if (title != null) {
        if (title.indexOf("data:image/") > -1 && title.indexOf(";base64,") > -1) {
            String[] tmp = title.split(",");
            Bitmap image = PluginUtil.getBitmapFromBase64encodedImage(tmp[1]);
            image = PluginUtil.scaleBitmapForDevice(image);
            ImageView imageView = new ImageView(this.cordova.getActivity());
            imageView.setImageBitmap(image);
            windowLayer.addView(imageView);
        } else {
            TextView textView = new TextView(this.cordova.getActivity());
            textView.setText(title);
            textView.setSingleLine(false);

            int titleColor = Color.BLACK;
            if (styles != null && styles.has("color")) {
                try {
                    titleColor = PluginUtil.parsePluginColor(styles.getJSONArray("color"));
                } catch (JSONException e) {
                }
            }
            textView.setTextColor(titleColor);
            textView.setGravity(gravity);
            if (VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                textView.setTextAlignment(textAlignment);
            }

            //----------------------------------------
            // font-style = normal | italic
            // font-weight = normal | bold
            //----------------------------------------
            int fontStyle = Typeface.NORMAL;
            if (styles != null) {
                try {
                    if ("italic".equals(styles.getString("font-style"))) {
                        fontStyle = Typeface.ITALIC;
                    }
                } catch (JSONException e) {
                }
                try {
                    if ("bold".equals(styles.getString("font-weight"))) {
                        fontStyle = fontStyle | Typeface.BOLD;
                    }
                } catch (JSONException e) {
                }
            }
            textView.setTypeface(Typeface.DEFAULT, fontStyle);

            windowLayer.addView(textView);
        }
    }
    if (snippet != null) {
        //snippet = snippet.replaceAll("\n", "");
        TextView textView2 = new TextView(this.cordova.getActivity());
        textView2.setText(snippet);
        textView2.setTextColor(Color.GRAY);
        textView2.setTextSize((textView2.getTextSize() / 6 * 5) / density);
        textView2.setGravity(gravity);
        if (VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            textView2.setTextAlignment(textAlignment);
        }

        windowLayer.addView(textView2);
    }
    return windowLayer;
}

From source file:com.forrestguice.suntimeswidget.SuntimesActivity.java

public void highlightTimeField(SolarEvents.SolarEventField highlightField) {
    int nextCardOffset = 0;
    int currentCard = this.card_flipper.getDisplayedChild();

    for (SolarEvents.SolarEventField field : timeFields.keySet()) {
        TextView txtField = timeFields.get(field);
        if (txtField != null) {
            if (field.equals(highlightField)) {
                txtField.setTypeface(txtField.getTypeface(), Typeface.BOLD);
                txtField.setPaintFlags(txtField.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

                if (currentCard == 0 && field.tomorrow) {
                    nextCardOffset = 1;//w  ww . j a v a 2 s .  c  o m

                } else if (currentCard == 1 && !field.tomorrow) {
                    nextCardOffset = -1;
                }

            } else {
                txtField.setTypeface(Typeface.create(txtField.getTypeface(), Typeface.NORMAL), Typeface.NORMAL);
                txtField.setPaintFlags(txtField.getPaintFlags() & (~Paint.UNDERLINE_TEXT_FLAG));
            }
        }
    }

    if (!userSwappedCard) {
        //Log.d("DEBUG", "Swapping card to show highlighted :: userSwappedCard " + userSwappedCard);
        if (nextCardOffset > 0) {
            showNextCard();

        } else if (nextCardOffset < 0) {
            showPreviousCard();
        }
    }
}

From source file:com.hichinaschool.flashcards.libanki.Sched.java

/**
 * Deck finished state ******************************************************
 * *****************************************
 *///from  w  w  w  .  j a v a2s.c om

public CharSequence finishedMsg(Context context) {
    SpannableStringBuilder sb = new SpannableStringBuilder();
    sb.append(context.getString(R.string.studyoptions_congrats_finished));
    StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
    sb.setSpan(boldSpan, 0, sb.length(), 0);
    sb.append(_nextDueMsg(context));
    // sb.append("\n\n");
    // sb.append(_tomorrowDueMsg(context));
    return sb;
}

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

private Typeface fontToRoboto(String fontName) {
    if ("native:MainThin".equals(fontName)) {
        return Typeface.create("sans-serif-thin", Typeface.NORMAL);
    }/*from ww  w  .  j ava 2s .  c  o  m*/
    if ("native:MainLight".equals(fontName)) {
        return Typeface.create("sans-serif-light", Typeface.NORMAL);
    }
    if ("native:MainRegular".equals(fontName)) {
        return Typeface.create("sans-serif", Typeface.NORMAL);
    }

    if ("native:MainBold".equals(fontName)) {
        return Typeface.create("sans-serif-condensed", Typeface.BOLD);
    }

    if ("native:MainBlack".equals(fontName)) {
        return Typeface.create("sans-serif-black", Typeface.BOLD);
    }

    if ("native:ItalicThin".equals(fontName)) {
        return Typeface.create("sans-serif-thin", Typeface.ITALIC);
    }

    if ("native:ItalicLight".equals(fontName)) {
        return Typeface.create("sans-serif-thin", Typeface.ITALIC);
    }

    if ("native:ItalicRegular".equals(fontName)) {
        return Typeface.create("sans-serif", Typeface.ITALIC);
    }

    if ("native:ItalicBold".equals(fontName)) {
        return Typeface.create("sans-serif-condensed", Typeface.BOLD_ITALIC);
    }

    if ("native:ItalicBlack".equals(fontName)) {
        return Typeface.create("sans-serif-black", Typeface.BOLD_ITALIC);
    }

    throw new IllegalArgumentException("Unsupported native font type: " + fontName);
}

From source file:com.skytree.epubtest.BookViewActivity.java

public void makeFontBox() {
    int boxColor = Color.rgb(241, 238, 229);
    int innerBoxColor = Color.rgb(246, 244, 239);
    int inlineColor = Color.rgb(133, 105, 75);

    int width = 450;
    int height = 500;
    fontBox = new SkyBox(this);
    fontBox.setBoxColor(boxColor);//from  ww w  .  j  a v  a  2s  .co m
    fontBox.setArrowHeight(ps(25));
    fontBox.setArrowDirection(false);
    setFrame(fontBox, ps(50), ps(200), ps(width), ps(height));

    ScrollView fontBoxScrollView = new ScrollView(this);
    this.setFrame(fontBoxScrollView, ps(5), ps(10), ps(440), ps(height - 50));
    fontBox.contentView.addView(fontBoxScrollView); // NEW

    SkyLayout contentLayout = new SkyLayout(this);
    fontBoxScrollView.addView(contentLayout,
            new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    // #1 first make brightness controller
    // brView is the box containing the bright slider. 
    int FY = 10;
    View brView = new View(this);
    RoundRectShape rrs = new RoundRectShape(
            new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
    SkyDrawable srd = new SkyDrawable(rrs, innerBoxColor, inlineColor, 1);
    brView.setBackgroundDrawable(srd);
    setFrame(brView, ps(20), ps(FY), ps(width - 40), ps(53));
    contentLayout.addView(brView);
    // darker and brighter icons
    int SBS = 60;
    ImageButton sbb = this.makeImageButton(9005, R.drawable.brightness2x, ps(SBS), ps(SBS));
    setFrame(sbb, ps(50), ps(FY), ps(SBS), ps(SBS));
    sbb.setAlpha(200);
    int BBS = 70;
    ImageButton bbb = this.makeImageButton(9006, R.drawable.brightness2x, ps(BBS), ps(BBS));
    setFrame(bbb, ps(width - 110), ps(FY - 5), ps(BBS), ps(BBS));
    bbb.setAlpha(200);
    contentLayout.addView(sbb);
    contentLayout.addView(bbb);
    // making bright slider      
    brightBar = new SeekBar(this);
    brightBar.setMax(999);
    brightBar.setId(997);
    brightBar.setBackgroundColor(Color.TRANSPARENT);
    brightBar.setOnSeekBarChangeListener(new SeekBarDelegate());
    brightBar.setProgressDrawable(new LineDrawable(Color.rgb(160, 160, 160), ps(10)));
    brightBar.setThumbOffset(-1);
    setFrame(brightBar, ps(100), ps(FY + 4), ps(width - 210), ps(50));
    contentLayout.addView(brightBar);

    // #2 second make decrese/increse font size buttons
    // decrease font size Button
    int FBY = 80;
    decreaseButton = new Button(this);
    setFrame(decreaseButton, ps(20), ps(FBY), ps(width - 40 - 20) / 2, ps(60));
    decreaseButton.setText(getString(R.string.chara));
    decreaseButton.setGravity(Gravity.CENTER);
    decreaseButton.setTextSize(14);
    decreaseButton.setId(5000);
    RoundRectShape drs = new RoundRectShape(
            new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
    SkyDrawable drd = new SkyDrawable(drs, innerBoxColor, inlineColor, 1);
    decreaseButton.setBackgroundDrawable(drd);
    decreaseButton.setOnClickListener(listener);
    decreaseButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(decreaseButton));
    contentLayout.addView(decreaseButton);
    // inccrease font size Button
    increaseButton = new Button(this);
    setFrame(increaseButton, ps(10 + width / 2), ps(FBY), ps(width - 40 - 20) / 2, ps(60));
    increaseButton.setText(getString(R.string.chara));
    increaseButton.setTextSize(18);
    increaseButton.setGravity(Gravity.CENTER);
    increaseButton.setId(5001);
    RoundRectShape irs = new RoundRectShape(
            new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
    SkyDrawable ird = new SkyDrawable(irs, innerBoxColor, inlineColor, 1);
    increaseButton.setBackgroundDrawable(ird);
    increaseButton.setOnClickListener(listener);
    increaseButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(increaseButton));
    contentLayout.addView(increaseButton);

    // # 3 make the button to increase/decrese line spacing. 
    int LBY = 145;
    // deccrease line space Button
    decreaseLineSpaceButton = this.makeImageButton(9005, R.drawable.decline2x, ps(30), ps(30));
    setFrame(decreaseLineSpaceButton, ps(20), ps(LBY), ps(width - 40 - 20) / 2, ps(60));
    decreaseLineSpaceButton.setId(4000);
    drs = new RoundRectShape(new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null,
            null);
    drd = new SkyDrawable(drs, innerBoxColor, inlineColor, 1);
    decreaseLineSpaceButton.setBackgroundDrawable(drd);
    decreaseLineSpaceButton.setOnClickListener(listener);
    decreaseLineSpaceButton
            .setOnTouchListener(new ImageButtonHighlighterOnTouchListener(decreaseLineSpaceButton));
    contentLayout.addView(decreaseLineSpaceButton);
    // inccrease line space Button        
    increaseLineSpaceButton = this.makeImageButton(9005, R.drawable.incline2x, ps(30), ps(30));
    setFrame(increaseLineSpaceButton, ps(10 + width / 2), ps(LBY), ps(width - 40 - 20) / 2, ps(60));
    increaseLineSpaceButton.setId(4001);
    irs = new RoundRectShape(new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null,
            null);
    ird = new SkyDrawable(irs, innerBoxColor, inlineColor, 1);
    increaseLineSpaceButton.setBackgroundDrawable(ird);
    increaseLineSpaceButton.setOnClickListener(listener);
    increaseLineSpaceButton
            .setOnTouchListener(new ImageButtonHighlighterOnTouchListener(increaseLineSpaceButton));
    contentLayout.addView(increaseLineSpaceButton);

    // #4 make themes selector.  
    int TY = 220;
    int TH = 70;
    int TW = (width - 40 - 20) / 3;

    HorizontalScrollView themeScrollView = new HorizontalScrollView(this);
    themesView = new LinearLayout(this);
    themesView.setOrientation(LinearLayout.HORIZONTAL);

    themeScrollView.addView(themesView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    for (int i = 0; i < this.themes.size(); i++) {
        Theme theme = themes.get(i);
        Button themeButton = new Button(this);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ps(TW), ps(TH));
        layoutParams.setMargins(0, 0, 24, 0);
        themesView.addView(themeButton, layoutParams);
        RoundRectShape rs = new RoundRectShape(
                new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
        SkyDrawable brd = new SkyDrawable(rs, theme.backgroundColor, Color.BLACK, 1);
        themeButton.setBackgroundDrawable(brd);
        themeButton.setText(theme.name);
        themeButton.setTextColor(theme.foregroundColor);
        themeButton.setId(7000 + i);
        themeButton.setOnClickListener(listener);
    }

    this.setFrame(themeScrollView, ps(20), ps(TY), ps(width - 40), ps(90));
    contentLayout.addView(themeScrollView);

    // #5 font list box
    int SY = 310;
    int fontButtonHeight = 80;
    int fontListHeight;
    fontListHeight = fontButtonHeight * fonts.size();
    fontListView = new LinearLayout(this);
    fontListView.setOrientation(LinearLayout.VERTICAL);
    contentLayout.addView(fontListView);
    this.setFrame(fontListView, ps(20), ps(SY), ps(width - 40), ps(fontListHeight));
    int inlineColor2 = Color.argb(140, 133, 105, 75);

    for (int i = 0; i < fonts.size(); i++) {
        CustomFont customFont = fonts.get(i);
        Button fontButton = new Button(this);
        fontButton.setText(customFont.fontFaceName);
        fontButton.setTextSize(20);
        Typeface tf = null;
        if (customFont.fontFileName == null || customFont.fontFileName.isEmpty()) {
            tf = this.getTypeface(customFont.fontFaceName, Typeface.BOLD);
        } else {
            tf = Typeface.createFromAsset(getAssets(), "fonts/" + customFont.fontFileName);
        }
        if (tf != null)
            fontButton.setTypeface(tf);
        fontButton.setId(5100 + i);
        RoundRectShape rs = new RoundRectShape(
                new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
        SkyDrawable brd = new SkyDrawable(rs, innerBoxColor, inlineColor2, 1);
        fontButton.setBackgroundDrawable(brd);
        this.setFrame(fontButton, ps(0), ps(0), ps(width - 40), ps(fontButtonHeight));
        fontListView.addView(fontButton);
        fontButton.setOnClickListener(listener);
        fontButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(fontButton));
    }

    this.ePubView.addView(fontBox);
    this.hideFontBox();
}

From source file:ru.valle.btc.MainActivity.java

private CharSequence getPrivateKeyTypeLabel(final KeyPair keyPair) {
    int typeWithCompression = keyPair.privateKey.type == BTCUtils.PrivateKeyInfo.TYPE_BRAIN_WALLET
            && keyPair.privateKey.isPublicKeyCompressed ? keyPair.privateKey.type + 1 : keyPair.privateKey.type;
    CharSequence keyType = getResources().getTextArray(R.array.private_keys_types)[typeWithCompression];
    SpannableString keyTypeLabel = new SpannableString(getString(R.string.private_key_type, keyType));
    int keyTypeStart = keyTypeLabel.toString().indexOf(keyType.toString());
    keyTypeLabel.setSpan(new StyleSpan(Typeface.BOLD), keyTypeStart, keyTypeStart + keyType.length(),
            SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
    if (keyPair.privateKey.type == BTCUtils.PrivateKeyInfo.TYPE_BRAIN_WALLET) {
        String compressionStrToSpan = keyType.toString().substring(keyType.toString().indexOf(',') + 2);
        int start = keyTypeLabel.toString().indexOf(compressionStrToSpan);
        if (start >= 0) {

            ClickableSpan switchPublicKeyCompressionSpan = new ClickableSpan() {
                @Override//from w  w w.  j  a v a2 s  .co m
                public void onClick(View widget) {
                    cancelAllRunningTasks();
                    switchingCompressionTypeTask = new AsyncTask<Void, Void, KeyPair>() {

                        @Override
                        protected KeyPair doInBackground(Void... params) {
                            return new KeyPair(new BTCUtils.PrivateKeyInfo(keyPair.privateKey.type,
                                    keyPair.privateKey.privateKeyEncoded, keyPair.privateKey.privateKeyDecoded,
                                    !keyPair.privateKey.isPublicKeyCompressed));
                        }

                        @Override
                        protected void onPostExecute(KeyPair keyPair) {
                            switchingCompressionTypeTask = null;
                            onKeyPairModify(false, keyPair);
                        }
                    };
                    switchingCompressionTypeTask.execute();
                }
            };
            keyTypeLabel.setSpan(switchPublicKeyCompressionSpan, start, start + compressionStrToSpan.length(),
                    SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
        }
    }
    return keyTypeLabel;
}

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. ja v a 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;
}