Example usage for android.graphics Typeface create

List of usage examples for android.graphics Typeface create

Introduction

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

Prototype

public static Typeface create(Typeface family, @Style int style) 

Source Link

Document

Create a typeface object that best matches the specified existing typeface and the specified Style.

Usage

From source file:com.lyue.aw_jitpack_aar.app.zxing.zxing.view.ViewfinderView.java

@Override
public void onDraw(Canvas canvas) {
    //CameraManager
    Rect frame = CameraManager.get().getFramingRect();
    if (frame == null) {
        return;// www .  j a v  a 2  s .  co  m
    }

    //
    if (!isFirst) {
        isFirst = true;
        slideTop = frame.top;
        slideBottom = frame.bottom;
    }

    //
    int width = canvas.getWidth();
    int height = canvas.getHeight();

    paint.setColor(resultBitmap != null ? resultColor : maskColor);

    //
    //
    canvas.drawRect(0, 0, width, frame.top, paint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);
    canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);
    canvas.drawRect(0, frame.bottom + 1, width, height, paint);

    if (resultBitmap != null) {
        // Draw the opaque result bitmap over the scanning rectangle
        paint.setAlpha(OPAQUE);
        canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);
    } else {

        //8
        paint.setColor(Color.GREEN);
        canvas.drawRect(frame.left, frame.top, frame.left + ScreenRate, frame.top + CORNER_WIDTH, paint);
        canvas.drawRect(frame.left, frame.top, frame.left + CORNER_WIDTH, frame.top + ScreenRate, paint);
        canvas.drawRect(frame.right - ScreenRate, frame.top, frame.right, frame.top + CORNER_WIDTH, paint);
        canvas.drawRect(frame.right - CORNER_WIDTH, frame.top, frame.right, frame.top + ScreenRate, paint);
        canvas.drawRect(frame.left, frame.bottom - CORNER_WIDTH, frame.left + ScreenRate, frame.bottom, paint);
        canvas.drawRect(frame.left, frame.bottom - ScreenRate, frame.left + CORNER_WIDTH, frame.bottom, paint);
        canvas.drawRect(frame.right - ScreenRate, frame.bottom - CORNER_WIDTH, frame.right, frame.bottom,
                paint);
        canvas.drawRect(frame.right - CORNER_WIDTH, frame.bottom - ScreenRate, frame.right, frame.bottom,
                paint);

        //,SPEEN_DISTANCE

        slideTop += SPEEN_DISTANCE;
        if (slideTop >= frame.bottom) {
            slideTop = frame.top;
        }
        Rect lineRect = new Rect();
        lineRect.left = frame.left;
        lineRect.right = frame.right;
        lineRect.top = slideTop;
        lineRect.bottom = slideTop + 18;
        canvas.drawBitmap(
                ((BitmapDrawable) (getResources().getDrawable(R.drawable.aar_qrcode_scan_line))).getBitmap(),
                null, lineRect, paint);

        //
        paint.setColor(Color.WHITE);
        paint.setTextSize(TEXT_SIZE * density);
        paint.setAlpha(0x40);
        paint.setTypeface(Typeface.create("System", Typeface.BOLD));
        String text = getResources().getString(R.string.scan_text);
        float textWidth = paint.measureText(text);

        canvas.drawText(text, (width - textWidth) / 2,
                (float) (frame.bottom + (float) TEXT_PADDING_TOP * density), paint);

        Collection<ResultPoint> currentPossible = possibleResultPoints;
        Collection<ResultPoint> currentLast = lastPossibleResultPoints;
        if (currentPossible.isEmpty()) {
            lastPossibleResultPoints = null;
        } else {
            possibleResultPoints = new HashSet<ResultPoint>(5);
            lastPossibleResultPoints = currentPossible;
            paint.setAlpha(OPAQUE);
            paint.setColor(resultPointColor);
            for (ResultPoint point : currentPossible) {
                canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint);
            }
        }
        if (currentLast != null) {
            paint.setAlpha(OPAQUE / 2);
            paint.setColor(resultPointColor);
            for (ResultPoint point : currentLast) {
                canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, paint);
            }
        }

        //
        postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom);

    }
}

From source file:color.kidpaint.com.kidpaintcolor.tools.implementation.TextTool.java

public void updateTypeface() {
    int style;//from   ww  w.  j a va  2 s. co  m
    if (mItalic) {
        style = Typeface.ITALIC;
    } else {
        style = Typeface.NORMAL;
    }

    if (mFont.equals("Sans Serif")) {
        mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, style));
    } else if (mFont.equals("Serif")) {
        mTextPaint.setTypeface(Typeface.create(Typeface.SERIF, style));
    } else if (mFont.equals("Monospace")) {
        mTextPaint.setTypeface(Typeface.create(Typeface.MONOSPACE, style));
    }

    if (Build.VERSION.SDK_INT < 21) {
        mTextPaint.setTextSkewX(0.0f);
        if (mFont.equals("Monospace")) {
            mTextPaint.setTypeface(Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL));
            if (style == Typeface.ITALIC) {
                mTextPaint.setTextSkewX(-0.25f);
            }
        }
    }
}

From source file:com.android.argb.edhlc.Utils.java

public static void createRecordListElement(Activity parent, Record currentRecord,
        String highlightedPlayerName) {
    TextView textDateRecordCard = (TextView) parent.findViewById(R.id.textDateRecordCard);
    LinearLayout linearFirstLineRecordCard = (LinearLayout) parent.findViewById(R.id.linearFirstLineRecordCard);
    TextView textFirstIndicatorRecordCard = (TextView) parent.findViewById(R.id.textFirstIndicatorRecordCard);
    TextView textFirstPlayerRecordCard = (TextView) parent.findViewById(R.id.textFirstPlayerRecordCard);
    TextView textFirstDeckRecordCard = (TextView) parent.findViewById(R.id.textFirstDeckRecordCard);

    View divider1RecordCard = parent.findViewById(R.id.divider1RecordCard);

    LinearLayout linearSecondLineRecordCard = (LinearLayout) parent
            .findViewById(R.id.linearSecondLineRecordCard);
    TextView textSecondIndicatorRecordCard = (TextView) parent.findViewById(R.id.textSecondIndicatorRecordCard);
    TextView textSecondPlayerRecordCard = (TextView) parent.findViewById(R.id.textSecondPlayerRecordCard);
    TextView textSecondDeckRecordCard = (TextView) parent.findViewById(R.id.textSecondDeckRecordCard);

    View divider2RecordCard = parent.findViewById(R.id.divider2RecordCard);

    LinearLayout linearThirdLineRecordCard = (LinearLayout) parent.findViewById(R.id.linearThirdLineRecordCard);
    TextView textThirdIndicatorRecordCard = (TextView) parent.findViewById(R.id.textThirdIndicatorRecordCard);
    TextView textThirdPlayerRecordCard = (TextView) parent.findViewById(R.id.textThirdPlayerRecordCard);
    TextView textThirdDeckRecordCard = (TextView) parent.findViewById(R.id.textThirdDeckRecordCard);

    View divider3RecordCard = parent.findViewById(R.id.divider3RecordCard);

    LinearLayout linearFourthLineRecordCard = (LinearLayout) parent
            .findViewById(R.id.linearFourthLineRecordCard);
    TextView textFourthIndicatorRecordCard = (TextView) parent.findViewById(R.id.textFourthIndicatorRecordCard);
    TextView textFourthPlayerRecordCard = (TextView) parent.findViewById(R.id.textFourthPlayerRecordCard);
    TextView textFourthDeckRecordCard = (TextView) parent.findViewById(R.id.textFourthDeckRecordCard);

    Typeface typefaceMedium = Typeface.create("sans-serif-medium", Typeface.NORMAL);
    Typeface typefaceNormal = Typeface.create("sans-serif", Typeface.NORMAL);
    int colorAccent = ContextCompat.getColor(parent, R.color.accent_color);
    int colorSecondary = ContextCompat.getColor(parent, R.color.secondary_text);

    textDateRecordCard.setText(String.format("Played on %s", currentRecord.getDate()));

    switch (currentRecord.getTotalPlayers()) {
    case 2:/*from  w ww  .  ja v a 2s  . c om*/
        linearFirstLineRecordCard.setVisibility(View.VISIBLE);
        linearSecondLineRecordCard.setVisibility(View.VISIBLE);
        linearThirdLineRecordCard.setVisibility(View.GONE);
        linearFourthLineRecordCard.setVisibility(View.GONE);

        divider1RecordCard.setVisibility(View.VISIBLE);
        divider2RecordCard.setVisibility(View.GONE);
        divider3RecordCard.setVisibility(View.GONE);

        textFirstDeckRecordCard.setText(currentRecord.getFirstPlace().getDeckName());
        textFirstPlayerRecordCard.setText(currentRecord.getFirstPlace().getDeckOwnerName());

        textSecondDeckRecordCard.setText(currentRecord.getSecondPlace().getDeckName());
        textSecondPlayerRecordCard.setText(currentRecord.getSecondPlace().getDeckOwnerName());

        if (highlightedPlayerName != null) {
            textFirstDeckRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFirstPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textFirstPlayerRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFirstPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textFirstIndicatorRecordCard.setTextColor(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFirstPlace().getDeckOwnerName())
                            ? colorAccent
                            : colorSecondary);
            textFirstIndicatorRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFirstPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);

            textSecondDeckRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getSecondPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textSecondPlayerRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getSecondPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textSecondIndicatorRecordCard.setTextColor(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getSecondPlace().getDeckOwnerName())
                            ? colorAccent
                            : colorSecondary);
            textSecondIndicatorRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getSecondPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
        }
        break;

    case 3:
        linearFirstLineRecordCard.setVisibility(View.VISIBLE);
        linearSecondLineRecordCard.setVisibility(View.VISIBLE);
        linearThirdLineRecordCard.setVisibility(View.VISIBLE);
        linearFourthLineRecordCard.setVisibility(View.GONE);

        divider1RecordCard.setVisibility(View.VISIBLE);
        divider2RecordCard.setVisibility(View.VISIBLE);
        divider3RecordCard.setVisibility(View.GONE);

        textFirstDeckRecordCard.setText(currentRecord.getFirstPlace().getDeckName());
        textFirstPlayerRecordCard.setText(currentRecord.getFirstPlace().getDeckOwnerName());

        textSecondDeckRecordCard.setText(currentRecord.getSecondPlace().getDeckName());
        textSecondPlayerRecordCard.setText(currentRecord.getSecondPlace().getDeckOwnerName());

        textThirdDeckRecordCard.setText(currentRecord.getThirdPlace().getDeckName());
        textThirdPlayerRecordCard.setText(currentRecord.getThirdPlace().getDeckOwnerName());

        if (highlightedPlayerName != null) {
            textFirstDeckRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFirstPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textFirstPlayerRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFirstPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textFirstIndicatorRecordCard.setTextColor(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFirstPlace().getDeckOwnerName())
                            ? colorAccent
                            : colorSecondary);
            textFirstIndicatorRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFirstPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);

            textSecondDeckRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getSecondPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textSecondPlayerRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getSecondPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textSecondIndicatorRecordCard.setTextColor(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getSecondPlace().getDeckOwnerName())
                            ? colorAccent
                            : colorSecondary);
            textSecondIndicatorRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getSecondPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);

            textThirdDeckRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getThirdPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textThirdPlayerRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getThirdPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textThirdIndicatorRecordCard.setTextColor(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getThirdPlace().getDeckOwnerName())
                            ? colorAccent
                            : colorSecondary);
            textThirdIndicatorRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getThirdPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
        }
        break;

    case 4:
        linearFirstLineRecordCard.setVisibility(View.VISIBLE);
        linearSecondLineRecordCard.setVisibility(View.VISIBLE);
        linearThirdLineRecordCard.setVisibility(View.VISIBLE);
        linearFourthLineRecordCard.setVisibility(View.VISIBLE);

        divider1RecordCard.setVisibility(View.VISIBLE);
        divider2RecordCard.setVisibility(View.VISIBLE);
        divider3RecordCard.setVisibility(View.VISIBLE);

        textFirstDeckRecordCard.setText(currentRecord.getFirstPlace().getDeckName());
        textFirstPlayerRecordCard.setText(currentRecord.getFirstPlace().getDeckOwnerName());

        textSecondDeckRecordCard.setText(currentRecord.getSecondPlace().getDeckName());
        textSecondPlayerRecordCard.setText(currentRecord.getSecondPlace().getDeckOwnerName());

        textThirdDeckRecordCard.setText(currentRecord.getThirdPlace().getDeckName());
        textThirdPlayerRecordCard.setText(currentRecord.getThirdPlace().getDeckOwnerName());

        textFourthDeckRecordCard.setText(currentRecord.getFourthPlace().getDeckName());
        textFourthPlayerRecordCard.setText(currentRecord.getFourthPlace().getDeckOwnerName());

        if (highlightedPlayerName != null) {
            textFirstDeckRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFirstPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textFirstPlayerRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFirstPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textFirstIndicatorRecordCard.setTextColor(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFirstPlace().getDeckOwnerName())
                            ? colorAccent
                            : colorSecondary);
            textFirstIndicatorRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFirstPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);

            textSecondDeckRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getSecondPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textSecondPlayerRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getSecondPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textSecondIndicatorRecordCard.setTextColor(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getSecondPlace().getDeckOwnerName())
                            ? colorAccent
                            : colorSecondary);
            textSecondIndicatorRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getSecondPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);

            textThirdDeckRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getThirdPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textThirdPlayerRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getThirdPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textThirdIndicatorRecordCard.setTextColor(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getThirdPlace().getDeckOwnerName())
                            ? colorAccent
                            : colorSecondary);
            textThirdIndicatorRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getThirdPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);

            textFourthDeckRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFourthPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textFourthPlayerRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFourthPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
            textFourthIndicatorRecordCard.setTextColor(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFourthPlace().getDeckOwnerName())
                            ? colorAccent
                            : colorSecondary);
            textFourthIndicatorRecordCard.setTypeface(
                    highlightedPlayerName.equalsIgnoreCase(currentRecord.getFourthPlace().getDeckOwnerName())
                            ? typefaceMedium
                            : typefaceNormal);
        }
        break;
    }
}

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Get paint for text use//from www .j  a  va 2 s .  c  o m
 * @return red paint object
 */
public static Paint getTextPaint(final float fontSize, final Paint.Align align) {
    Paint paint = getPaint();
    paint.setTextSize(fontSize);
    paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
    paint.setTextAlign(align);
    return (paint);
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossDeviceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.view_zenoss_device_fragment, container, false);

    Typeface titlesTypeFace = Typeface.create("sans-serif-light", Typeface.BOLD);

    deviceTitle = (TextView) rootView.findViewById(R.id.DeviceTitle);
    deviceTitle.setTypeface(titlesTypeFace);

    loadAverageGraphView = (ImageView) rootView.findViewById(R.id.loadAverageGraph);
    CPUGraphView = (ImageView) rootView.findViewById(R.id.CPUGraph);
    MemoryGraphView = (ImageView) rootView.findViewById(R.id.MemoryGraph);

    snmpAgent = (TextView) rootView.findViewById(R.id.snmpAgent);
    snmpAgent.setTypeface(titlesTypeFace);
    snmpContact = (TextView) rootView.findViewById(R.id.snmpContact);
    snmpContact.setTypeface(titlesTypeFace);
    snmpLocation = (TextView) rootView.findViewById(R.id.snmpLocation);
    snmpLocation.setTypeface(titlesTypeFace);
    Uptime = (TextView) rootView.findViewById(R.id.uptime);
    Uptime.setTypeface(titlesTypeFace);// www.j a  v a 2  s  . c  o  m
    MemoryRAM = (TextView) rootView.findViewById(R.id.memory_ram);
    MemoryRAM.setTypeface(titlesTypeFace);
    MemorySwap = (TextView) rootView.findViewById(R.id.memory_swap);
    MemorySwap.setTypeface(titlesTypeFace);
    LastCollected = (TextView) rootView.findViewById(R.id.lastCollected);
    LastCollected.setTypeface(titlesTypeFace);

    hsv = (HorizontalScrollView) rootView.findViewById(R.id.horizontalScrollView);

    try {
        ImageView deviceRepImg = ((ImageView) rootView.findViewById(R.id.deviceRepImg));
        deviceRepImg.setScaleType(ImageView.ScaleType.CENTER_CROP);
        Random r = new Random();
        deviceRepImg.setImageResource(mThumbIds[r.nextInt(mThumbIds.length)]);
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("ViewZenossDeviceFragment", "ImageRand", e);
    }

    return rootView;
}

From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java

/**
 * Applies the specified text appearance resource to a paint, returning the
 * text color if one is set in the text appearance.
 *
 * @param p the paint to modify/*from   w w w  .  j  a v a2s .c  om*/
 * @param resId the resource ID of the text appearance
 * @return the text color, if available
 */
private ColorStateList applyTextAppearance(Paint p, int resId) {
    final TypedArray ta = getContext().obtainStyledAttributes(null, R.styleable.TextAppearance, 0, resId);

    final String fontFamily = ta.getString(R.styleable.TextAppearance_android_fontFamily);
    if (fontFamily != null) {
        p.setTypeface(Typeface.create(fontFamily, 0));
    }

    p.setTextSize(ta.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, (int) p.getTextSize()));

    final ColorStateList textColor = ta.getColorStateList(R.styleable.TextAppearance_android_textColor);
    if (textColor != null) {
        final int enabledColor = textColor.getColorForState(ENABLED_STATE_SET, 0);
        p.setColor(enabledColor);
    }

    ta.recycle();

    return textColor;
}

From source file:com.xbm.android.matisse.internal.ui.widget.CheckView.java

private void initTextPaint() {
    if (mTextPaint == null) {
        mTextPaint = new TextPaint();
        mTextPaint.setAntiAlias(true);/* w w w. j  av  a2  s.  c o  m*/
        mTextPaint.setColor(Color.WHITE);
        mTextPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
        mTextPaint.setTextSize(12.0f * mDensity);
    }
}

From source file:za.jamie.soundstage.widgets.PagerSlidingTabStrip.java

private void setTypefaceFromAttrs(String familyName, int typefaceIndex, int styleIndex) {
    Typeface tf = null;//from   ww w  .j a  v a2s  .com
    if (familyName != null) {
        tf = Typeface.create(familyName, styleIndex);
        if (tf != null) {
            setTypeface(tf);
            return;
        }
    }
    switch (typefaceIndex) {
    case SANS:
        tf = Typeface.SANS_SERIF;
        break;

    case SERIF:
        tf = Typeface.SERIF;
        break;

    case MONOSPACE:
        tf = Typeface.MONOSPACE;
        break;
    }
    setTypeface(tf, styleIndex);
}

From source file:me.futuretechnology.util.ui.TitlePageIndicator.java

public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) {
        return;/*from ww  w .  j a  v  a  2  s .c  om*/
    }

    // TODO clean this up
    // Load defaults from resources
    Resources res = getResources();
    int defaultFooterColor = res.getColor(R.color.default_title_indicator_footer_color);
    float defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height);
    float defaultFooterIndicatorHeight = res
            .getDimension(R.dimen.default_title_indicator_footer_indicator_height);
    float defaultFooterIndicatorUnderlinePadding = res
            .getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding);
    float defaultFooterPadding = res.getDimension(R.dimen.default_title_indicator_footer_padding);
    int defaultSelectedColor = res.getColor(R.color.default_title_indicator_selected_color);
    boolean defaultSelectedBold = res.getBoolean(R.bool.default_title_indicator_selected_bold);
    int defaultTextColor = res.getColor(R.color.default_title_indicator_text_color);
    float defaultTextSize = res.getDimension(R.dimen.default_title_indicator_text_size);
    float defaultTitlePadding = res.getDimension(R.dimen.default_title_indicator_title_padding);
    float defaultClipPadding = res.getDimension(R.dimen.default_title_indicator_clip_padding);
    float defaultTopPadding = res.getDimension(R.dimen.default_title_indicator_top_padding);

    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TitlePageIndicator, defStyle, 0);

    // Retrieve the colors to be used for this view and apply them.
    mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight,
            defaultFooterLineHeight);
    mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight,
            defaultFooterIndicatorHeight);
    mFooterIndicatorUnderlinePadding = a.getDimension(
            R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding,
            defaultFooterIndicatorUnderlinePadding);
    mFooterPadding = a.getDimension(R.styleable.TitlePageIndicator_footerPadding, defaultFooterPadding);
    mTopPadding = a.getDimension(R.styleable.TitlePageIndicator_topPadding, defaultTopPadding);
    mTitlePadding = a.getDimension(R.styleable.TitlePageIndicator_titlePadding, defaultTitlePadding);
    mClipPadding = a.getDimension(R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding);
    mColorSelected = a.getColor(R.styleable.TitlePageIndicator_selectedColor, defaultSelectedColor);
    mColorText = a.getColor(R.styleable.TitlePageIndicator_textColor, defaultTextColor);
    mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold, defaultSelectedBold);

    float textSize = a.getDimension(R.styleable.TitlePageIndicator_textSize, defaultTextSize);
    int footerColor = a.getColor(R.styleable.TitlePageIndicator_footerColor, defaultFooterColor);
    mPaintText.setTextSize(textSize);
    mPaintText.setAntiAlias(true);
    mPaintText.setDither(true);
    mPaintText.setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL));
    mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE);
    // noinspection SuspiciousNameCombination
    mPaintFooterLine.setStrokeWidth(mFooterLineHeight);
    mPaintFooterLine.setColor(footerColor);
    mPaintFooterIndicator.setDither(true);

    // http://code.google.com/p/android/issues/detail?id=24873
    // bug when enabling hardware acceleration

    // workaround #1: disable hw acceleration => the drawing will be rough
    // setLayerType(View.LAYER_TYPE_SOFTWARE, mPaintFooterIndicator);

    // workaround #2: avoid using 0 as stroke width => the drawing will be smooth as butter
    mPaintFooterIndicator.setStrokeWidth(1);

    mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterIndicator.setColor(footerColor);

    a.recycle();

    ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.cssn.samplesdk.MainActivity.java

/**
 *
 *//*from w  w w .j  a  v  a 2 s .  c o  m*/
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if (Util.LOG_ENABLED) {
        Utils.appendLog(TAG, "protected void onCreate(Bundle savedInstanceState)");
    }

    // load the model
    if (savedInstanceState == null) {
        if (Util.LOG_ENABLED) {
            Utils.appendLog(TAG, "if (savedInstanceState == null)");
        }
        mainActivityModel = new MainActivityModel();
    } else {
        if (Util.LOG_ENABLED) {
            Utils.appendLog(TAG, "if (savedInstanceState != null)");
        }
        mainActivityModel = DataContext.getInstance().getMainActivityModel();
        // if coming from background and kill the app, restart the model
        if (mainActivityModel == null) {
            mainActivityModel = new MainActivityModel();
        }
    }
    DataContext.getInstance().setContext(getApplicationContext());

    String licenseKey = DataContext.getInstance().getLicenseKey();

    // load the controller instance
    acuantAndroidMobileSdkControllerInstance = AcuantAndroidMobileSDKController.getInstance(this, licenseKey);
    if (!Util.isTablet(this)) {
        acuantAndroidMobileSdkControllerInstance
                .setPdf417BarcodeImageDrawable(getResources().getDrawable(R.drawable.barcode));
    }

    acuantAndroidMobileSdkControllerInstance.setWebServiceListener(this);
    acuantAndroidMobileSdkControllerInstance.setCloudUrl("cssnwebservices.com");
    acuantAndroidMobileSdkControllerInstance.setWatermarkText("Powered By Acuant", 0, 0, 30, 0);
    DisplayMetrics metrics = this.getResources().getDisplayMetrics();

    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int height = displaymetrics.heightPixels;
    int width = displaymetrics.widthPixels;
    int minLength = (int) (Math.min(width, height) * 0.9);
    int maxLength = (int) (minLength * 1.5);
    int left = minLength / 2 - 50;
    int top = maxLength / 2 - 100;
    Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    Typeface currentTypeFace = textPaint.getTypeface();
    Typeface bold = Typeface.create(currentTypeFace, Typeface.BOLD);
    textPaint.setColor(Color.WHITE);
    textPaint.setTextSize(50);
    textPaint.setTextAlign(Paint.Align.LEFT);
    textPaint.setTypeface(bold);
    Paint.FontMetrics metric = textPaint.getFontMetrics();
    acuantAndroidMobileSdkControllerInstance.setInstructionText("Blink Slowly", left, top, textPaint);
    //acuantAndroidMobileSdkControllerInstance.setShowActionBar(false);
    //acuantAndroidMobileSdkControllerInstance.setShowStatusBar(false);
    acuantAndroidMobileSdkControllerInstance.setFlashlight(false);
    //acuantAndroidMobileSdkControllerInstance.setFlashlight(0,0,50,0);
    //acuantAndroidMobileSdkControllerInstance.setFlashlightImageDrawable(getResources().getDrawable(R.drawable.lighton), getResources().getDrawable(R.drawable.lightoff));
    //acuantAndroidMobileSdkControllerInstance.setShowInitialMessage(true);
    //acuantAndroidMobileSdkControllerInstance.setCropBarcode(true);
    //acuantAndroidMobileSdkControllerInstance.setPdf417BarcodeDialogWaitingBarcode("AcuantAndroidMobileSampleSDK","ALIGN AND TAP", 10, "Try Again", "Yes");
    acuantAndroidMobileSdkControllerInstance.setCanShowBracketsOnTablet(true);
    // load several member variables
    setContentView(R.layout.activity_main);

    layoutCards = (LinearLayout) findViewById(R.id.cardImagesLayout);
    layoutBackImage = (RelativeLayout) findViewById(R.id.relativeLayoutBackImage);
    layoutFrontImage = (RelativeLayout) findViewById(R.id.relativeLayoutFrontImage);

    frontImageView = (ImageView) findViewById(R.id.frontImageView);
    backImageView = (ImageView) findViewById(R.id.backImageView);

    editTextLicense = (EditText) findViewById(R.id.editTextLicenceKey);
    editTextLicense.setText(DataContext.getInstance().getLicenseKey());

    txtTapToCaptureFront = (TextView) findViewById(R.id.txtTapToCaptureFront);
    txtTapToCaptureBack = (TextView) findViewById(R.id.txtTapToCaptureBack);

    activateLicenseButton = (Button) findViewById(R.id.activateLicenseButton);

    processCardButton = (Button) findViewById(R.id.processCardButton);
    processCardButton.setVisibility(View.INVISIBLE);

    editTextLicense.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            validateLicenseKey(editTextLicense.getText().toString());
            DataContext.getInstance().setLicenseKey(editTextLicense.getText().toString());
            return true;
        }
    });

    // it is necessary to use a post UI call, because of the previous set text on 'editTextLicense'
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            editTextLicense.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    mainActivityModel.setState(State.NO_VALIDATED);
                    updateActivateLicenseButtonFromModel();
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }
            });
        }
    });

    editTextLicense.setOnFocusChangeListener(new OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                hideVirtualKeyboard();
            }
        }
    });

    // update the UI from the model
    updateUI();
    acuantAndroidMobileSdkControllerInstance.setCardCroppingListener(this);
    acuantAndroidMobileSdkControllerInstance.setAcuantErrorListener(this);
    if (Utils.LOG_ENABLED) {
        Utils.appendLog(TAG, "getScreenOrientation()=" + Util.getScreenOrientation(this));
    }
}