Example usage for android.graphics Typeface NORMAL

List of usage examples for android.graphics Typeface NORMAL

Introduction

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

Prototype

int NORMAL

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

Click Source Link

Usage

From source file:de.egore911.drilog.adapter.ShowDataAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Object o = getItem(position);
    boolean isUser = o instanceof User;

    ViewGroup row;/*from  ww w  .j  a  va  2s . c  o m*/
    if (null == convertView) {
        // Create a new view for the user or comment
        if (isUser) {
            row = (RelativeLayout) layoutInflater.inflate(R.layout.line_name, null);
            UserViewHolder holder = new UserViewHolder();
            holder.nameField = (TextView) row.findViewById(R.id.name);
            holder.avatarField = (ImageView) row.findViewById(R.id.avatar);
            holder.user = (User) o;
            row.setTag(holder);
        } else {
            row = (RelativeLayout) layoutInflater.inflate(R.layout.line_comment, null);
            CommentViewHolder holder = new CommentViewHolder();
            holder.commentField = (TextView) row.findViewById(R.id.comment);
            holder.dateField = (TextView) row.findViewById(R.id.date);
            holder.comment = (Comment) o;
            row.setTag(holder);
        }
    } else {
        // Recycle a previous view if possible
        row = (ViewGroup) convertView;
        if (isUser) {
            UserViewHolder holder = (UserViewHolder) row.getTag();
            holder.user = (User) o;
        } else {
            CommentViewHolder holder = (CommentViewHolder) row.getTag();
            holder.comment = (Comment) o;
        }
    }

    if (isUser) {
        User user = (User) o;

        setDefaultCellBackground(position, row, false);

        // Render a user
        UserViewHolder holder = (UserViewHolder) row.getTag();
        if (watchList != null && watchList.contains(user.nick)) {
            holder.nameField.setTypeface(null, Typeface.BOLD);
        } else {
            holder.nameField.setTypeface(null, Typeface.NORMAL);
        }
        holder.nameField.setText(user.name);
        Picasso.with(activity).load(user.image).placeholder(R.drawable.ic_launcher).into(holder.avatarField);
    } else {
        Comment comment = (Comment) o;

        setDefaultCellBackground(position, row, anchor == comment);

        // Render a comment
        CommentViewHolder holder = (CommentViewHolder) row.getTag();
        holder.commentField.setText(comment.content);
        holder.dateField.setText(comment.time);
    }

    return row;
}

From source file:com.bei.test.view.tab.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);//from   ww  w . j av a  2  s.  c o  m
    setWillNotDraw(false);
    mTabsContainer = new LinearLayout(context);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(mTabsContainer);

    mRectPaint = new Paint();
    mRectPaint.setAntiAlias(true);
    mRectPaint.setStyle(Style.FILL);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabNormalTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabNormalTextSize, dm);
    mTabSelectTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabSelectTextSize, dm);

    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    // get system attrs for container
    TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black));
    mUnderlineColor = textPrimaryColor;
    mDividerColor = textPrimaryColor;
    mIndicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    String tabTextTypefaceName = "sans-serif";
    // Use Roboto Medium as the default typeface from API 21 onwards
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tabTextTypefaceName = "sans-serif-medium";
        mTabTextTypefaceStyle = Typeface.NORMAL;
    }

    // get custom attrs for tabs and container
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    mIndicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, mIndicatorColor);
    mIndicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            mIndicatorHeight);
    mUnderlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, mUnderlineColor);
    mUnderlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            mUnderlineHeight);
    mDividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, mDividerColor);
    mDividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, mDividerWidth);
    mDividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            mDividerPadding);
    isExpandTabs = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, isExpandTabs);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, mScrollOffset);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle);
    mTabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight,
            mTabPadding);
    mTabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            mTabBackgroundResId);
    mTabNormalTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabNormalTextSize,
            mTabNormalTextSize);
    mTabSelectTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabSelectTextSize,
            mTabSelectTextSize);

    mTabTextColor = a.hasValue(R.styleable.PagerSlidingTabStrip_pstsTabTextColor)
            ? a.getColorStateList(R.styleable.PagerSlidingTabStrip_pstsTabTextColor)
            : null;
    mTabTextTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextStyle, mTabTextTypefaceStyle);
    isTabTextAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTabTextAllCaps, isTabTextAllCaps);
    int tabTextAlpha = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextAlpha, DEF_VALUE_TAB_TEXT_ALPHA);
    String fontFamily = a.getString(R.styleable.PagerSlidingTabStrip_pstsTabTextFontFamily);
    a.recycle();

    //Tab text color selector
    if (mTabTextColor == null) {
        mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha,
                Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor)));
    }

    //Tab text typeface and style
    if (fontFamily != null) {
        tabTextTypefaceName = fontFamily;
    }
    mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle);

    //Bottom padding for the tabs container parent view to show indicator and underline
    setTabsContainerParentViewPaddings();

    //Configure tab's container LayoutParams for either equal divided space or just wrap tabs
    mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
            : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
}

From source file:yjbo.yy.ynewsrecycle.mainutil.PSFirst.java

public PSFirst(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mcontext = context;/*from   ww  w . j  a  v a 2  s  . c o  m*/
    setFillViewport(true);
    setWillNotDraw(false);
    mTabsContainer = new LinearLayout(context);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(mTabsContainer);

    mRectPaint = new Paint();
    mRectPaint.setAntiAlias(true);
    mRectPaint.setStyle(Style.FILL);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabTextSize, dm);

    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    // get system attrs for container
    TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black));
    mUnderlineColor = textPrimaryColor;
    mDividerColor = textPrimaryColor;
    mIndicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    String tabTextTypefaceName = "sans-serif";
    // Use Roboto Medium as the default typeface from API 21 onwards
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tabTextTypefaceName = "sans-serif-medium";
        mTabTextTypefaceStyle = Typeface.NORMAL;
    }

    // get custom attrs for tabs and container
    a = context.obtainStyledAttributes(attrs, R.styleable.PSFirst);
    mIndicatorColor = a.getColor(R.styleable.PSFirst_pstsIndicatorColor2, mIndicatorColor);
    mIndicatorHeight = a.getDimensionPixelSize(R.styleable.PSFirst_pstsIndicatorHeight2, mIndicatorHeight);
    mUnderlineColor = a.getColor(R.styleable.PSFirst_pstsUnderlineColor2, mUnderlineColor);
    mUnderlineHeight = a.getDimensionPixelSize(R.styleable.PSFirst_pstsUnderlineHeight2, mUnderlineHeight);
    mDividerColor = a.getColor(R.styleable.PSFirst_pstsDividerColor2, mDividerColor);
    mDividerWidth = a.getDimensionPixelSize(R.styleable.PSFirst_pstsDividerWidth2, mDividerWidth);
    mDividerPadding = a.getDimensionPixelSize(R.styleable.PSFirst_pstsDividerPadding2, mDividerPadding);
    isExpandTabs = a.getBoolean(R.styleable.PSFirst_pstsShouldExpand2, isExpandTabs);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.PSFirst_pstsScrollOffset2, mScrollOffset);
    isPaddingMiddle = a.getBoolean(R.styleable.PSFirst_pstsPaddingMiddle2, isPaddingMiddle);
    mTabPadding = a.getDimensionPixelSize(R.styleable.PSFirst_pstsTabPaddingLeftRight2, mTabPadding);
    //        mTabBackgroundResId = a.getResourceId(R.styleable.PSFirst_pstsTabBackground2, mTabBackgroundResId);
    mTabTextSize = a.getDimensionPixelSize(R.styleable.PSFirst_pstsTabTextSize2, mTabTextSize);
    mTabTextColor = a.hasValue(R.styleable.PSFirst_pstsTabTextColor2)
            ? a.getColorStateList(R.styleable.PSFirst_pstsTabTextColor2)
            : null;
    mTabTextTypefaceStyle = a.getInt(R.styleable.PSFirst_pstsTabTextStyle2, mTabTextTypefaceStyle);
    isTabTextAllCaps = a.getBoolean(R.styleable.PSFirst_pstsTabTextAllCaps2, isTabTextAllCaps);
    int tabTextAlpha = a.getInt(R.styleable.PSFirst_pstsTabTextAlpha2, DEF_VALUE_TAB_TEXT_ALPHA);
    String fontFamily = a.getString(R.styleable.PSFirst_pstsTabTextFontFamily2);
    a.recycle();

    //Tab text color selector
    if (mTabTextColor == null) {
        mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha,
                Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor)));
    }

    //Tab text typeface and style
    if (fontFamily != null) {
        tabTextTypefaceName = fontFamily;
    }
    mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle);

    //Bottom padding for the tabs container parent view to show indicator and underline
    setTabsContainerParentViewPaddings();

    //Configure tab's container LayoutParams for either equal divided space or just wrap tabs
    mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
            : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
}

From source file:com.github.shareme.gwspagerslidingtabstrip.library.PagerSlidingTabStrip.java

@SuppressWarnings("deprecation")
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);//  w  w w.  j a  v a2s. c  o m
    setWillNotDraw(false);
    mTabsContainer = new LinearLayout(context);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(mTabsContainer);

    mRectPaint = new Paint();
    mRectPaint.setAntiAlias(true);
    mRectPaint.setStyle(Style.FILL);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabTextSize, dm);

    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    // get system attrs for container
    TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS);
    //TODO: getColor(int) depreciated fix
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black));
    mUnderlineColor = textPrimaryColor;
    mDividerColor = textPrimaryColor;
    mIndicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    String tabTextTypefaceName = "sans-serif";
    // Use Roboto Medium as the default typeface from API 21 onwards
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tabTextTypefaceName = "sans-serif-medium";
        mTabTextTypefaceStyle = Typeface.NORMAL;
    }

    // get custom attrs for tabs and container
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    mIndicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, mIndicatorColor);
    mIndicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            mIndicatorHeight);
    mUnderlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, mUnderlineColor);
    mUnderlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            mUnderlineHeight);
    mDividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, mDividerColor);
    mDividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, mDividerWidth);
    mDividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            mDividerPadding);
    isExpandTabs = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, isExpandTabs);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, mScrollOffset);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle);
    mTabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight,
            mTabPadding);
    mTabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            mTabBackgroundResId);
    mTabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabTextSize, mTabTextSize);
    mTabTextColor = a.hasValue(R.styleable.PagerSlidingTabStrip_pstsTabTextColor)
            ? a.getColorStateList(R.styleable.PagerSlidingTabStrip_pstsTabTextColor)
            : null;
    mTabTextTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextStyle, mTabTextTypefaceStyle);
    isTabTextAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTabTextAllCaps, isTabTextAllCaps);
    int tabTextAlpha = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextAlpha, DEF_VALUE_TAB_TEXT_ALPHA);
    String fontFamily = a.getString(R.styleable.PagerSlidingTabStrip_pstsTabTextFontFamily);
    a.recycle();

    //Tab text color selector
    if (mTabTextColor == null) {
        mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha,
                Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor)));
    }

    //Tab text typeface and style
    if (fontFamily != null) {
        tabTextTypefaceName = fontFamily;
    }
    mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle);

    //Bottom padding for the tabs container parent view to show indicator and underline
    setTabsContainerParentViewPaddings();

    //Configure tab's container LayoutParams for either equal divided space or just wrap tabs
    mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
            : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
}

From source file:net.kourlas.voipms_sms.adapters.ConversationsRecyclerViewAdapter.java

@Override
public void onBindViewHolder(ConversationViewHolder conversationViewHolder, int position) {
    Message message = messages.get(position);

    ViewSwitcher viewSwitcher = conversationViewHolder.getViewSwitcher();
    viewSwitcher.setDisplayedChild(isItemChecked(position) ? 1 : 0);

    QuickContactBadge contactBadge = conversationViewHolder.getContactBadge();
    contactBadge.assignContactFromPhone(message.getContact(), true);

    String photoUri = Utils.getContactPhotoUri(applicationContext, message.getContact());
    if (photoUri != null) {
        contactBadge.setImageURI(Uri.parse(photoUri));
    } else {//from   w  w w . j ava  2s . c  om
        contactBadge.setImageToDefault();
    }

    TextView contactTextView = conversationViewHolder.getContactTextView();
    String contactName = Utils.getContactName(applicationContext, message.getContact());
    SpannableStringBuilder contactTextBuilder = new SpannableStringBuilder();
    if (contactName != null) {
        contactTextBuilder.append(contactName);
    } else {
        contactTextBuilder.append(Utils.getFormattedPhoneNumber(message.getContact()));
    }
    if (!filterConstraint.equals("")) {
        int index = contactTextBuilder.toString().toLowerCase().indexOf(filterConstraint.toLowerCase());
        if (index != -1) {
            contactTextBuilder.setSpan(
                    new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)),
                    index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);
        }
    }
    contactTextView.setText(contactTextBuilder);

    final TextView messageTextView = conversationViewHolder.getMessageTextView();
    SpannableStringBuilder messageTextBuilder = new SpannableStringBuilder();

    int index = message.getText().toLowerCase().indexOf(filterConstraint.toLowerCase());
    if (!filterConstraint.equals("") && index != -1) {
        int nonMessageOffset = index;
        if (message.getType() == Message.Type.OUTGOING) {
            messageTextBuilder.insert(0,
                    applicationContext.getString(R.string.conversations_message_you) + " ");
            nonMessageOffset += 5;
        }

        int substringOffset = index - 20;
        if (substringOffset > 0) {
            messageTextBuilder.append("...");
            nonMessageOffset += 3;

            while (message.getText().charAt(substringOffset) != ' ' && substringOffset < index - 1) {
                substringOffset += 1;
            }
            substringOffset += 1;
        } else {
            substringOffset = 0;
        }

        messageTextBuilder.append(message.getText().substring(substringOffset));
        messageTextBuilder.setSpan(
                new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)),
                nonMessageOffset - substringOffset,
                nonMessageOffset - substringOffset + filterConstraint.length(),
                SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);
    } else {
        if (message.getType() == Message.Type.OUTGOING) {
            messageTextBuilder.append(applicationContext.getString(R.string.conversations_message_you));
            messageTextBuilder.append(" ");
        }
        messageTextBuilder.append(message.getText());
    }
    messageTextView.setText(messageTextBuilder);

    if (message.isUnread()) {
        contactTextView.setTypeface(null, Typeface.BOLD);
        messageTextView.setTypeface(null, Typeface.BOLD);
    } else {
        contactTextView.setTypeface(null, Typeface.NORMAL);
        messageTextView.setTypeface(null, Typeface.NORMAL);
    }

    // Set date line
    TextView dateTextView = conversationViewHolder.getDateTextView();
    if (message.isDraft()) {
        SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder();
        dateTextBuilder.append(applicationContext.getString(R.string.conversations_message_draft));
        dateTextBuilder.setSpan(new StyleSpan(Typeface.ITALIC), 0, dateTextBuilder.length(),
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        dateTextView.setText(dateTextBuilder);
    } else if (!message.isDelivered()) {
        if (!message.isDeliveryInProgress()) {
            SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder();
            dateTextBuilder.append(applicationContext.getString(R.string.conversations_message_not_sent));
            dateTextBuilder.setSpan(
                    new ForegroundColorSpan(
                            ContextCompat.getColor(applicationContext, android.R.color.holo_red_dark)),
                    0, dateTextBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            dateTextView.setText(dateTextBuilder);
        } else {
            dateTextView.setText(applicationContext.getString(R.string.conversations_message_sending));
        }
    } else {
        dateTextView.setText(Utils.getFormattedDate(applicationContext, message.getDate(), true));
    }
}

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  w  w .  jav  a  2 s . co m
        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.qingsongchou.library.widget.tab.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/*from w  w w  .  j av a2 s .c  om*/
    setWillNotDraw(false);
    mTabsContainer = new LinearLayout(context);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(mTabsContainer);

    mRectPaint = new Paint();
    mRectPaint.setAntiAlias(true);
    mRectPaint.setStyle(Style.FILL);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabNormalTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabNormalTextSize, dm);
    mTabSelectTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabSelectTextSize, dm);

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    screenWidth = dm.widthPixels;

    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    // get system attrs for container
    TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black));
    mUnderlineColor = textPrimaryColor;
    mDividerColor = textPrimaryColor;
    mIndicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    String tabTextTypefaceName = "sans-serif";
    // Use Roboto Medium as the default typeface from API 21 onwards
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tabTextTypefaceName = "sans-serif-medium";
        mTabTextTypefaceStyle = Typeface.NORMAL;
    }

    // get custom attrs for tabs and container
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    mIndicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsQscIndicatorColor, mIndicatorColor);
    mIndicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscIndicatorHeight,
            mIndicatorHeight);
    mUnderlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsQscUnderlineColor, mUnderlineColor);
    mUnderlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscUnderlineHeight,
            mUnderlineHeight);
    mDividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsQscDividerColor, mDividerColor);
    mDividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscDividerWidth,
            mDividerWidth);
    mDividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscDividerPadding,
            mDividerPadding);
    isExpandTabs = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsQscShouldExpand, isExpandTabs);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscScrollOffset,
            mScrollOffset);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsQscPaddingMiddle, isPaddingMiddle);
    mTabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscTabPaddingLeftRight,
            mTabPadding);
    mTabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsQscTabBackground,
            mTabBackgroundResId);
    mTabNormalTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscTabNormalTextSize,
            mTabNormalTextSize);
    mTabSelectTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscTabSelectTextSize,
            mTabSelectTextSize);

    mTabTextColor = a.hasValue(R.styleable.PagerSlidingTabStrip_pstsQscTabTextColor)
            ? a.getColorStateList(R.styleable.PagerSlidingTabStrip_pstsQscTabTextColor)
            : null;
    mTabTextTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsQscTabTextStyle,
            mTabTextTypefaceStyle);
    isTabTextAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsQscTabTextAllCaps, isTabTextAllCaps);
    int tabTextAlpha = a.getInt(R.styleable.PagerSlidingTabStrip_pstsQscTabTextAlpha, DEF_VALUE_TAB_TEXT_ALPHA);
    String fontFamily = a.getString(R.styleable.PagerSlidingTabStrip_pstsQscTabTextFontFamily);
    a.recycle();

    //Tab text color selector
    if (mTabTextColor == null) {
        mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha,
                Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor)));
    }

    //Tab text typeface and style
    if (fontFamily != null) {
        tabTextTypefaceName = fontFamily;
    }
    mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle);

    //Bottom padding for the tabs container parent view to show indicator and underline
    setTabsContainerParentViewPaddings();

    //Configure tab's container LayoutParams for either equal divided space or just wrap tabs
    mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
            : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
}

From source file:net.yaly.ViewPagerDoubleIndicator.java

public ViewPagerDoubleIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);//from  w ww  .  ja  v  a 2 s  . c  o  m
    setWillNotDraw(false);
    mTabsContainer = new LinearLayout(context);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(mTabsContainer);

    mRectPaint = new Paint();
    mRectPaint.setAntiAlias(true);
    mRectPaint.setStyle(Style.FILL);
    mPaintLine = new Paint();
    mPaintLine.setStyle(Style.FILL);
    mPaintLine.setAntiAlias(true);

    //
    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabTextSize, dm);
    // ?
    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    // get system attrs for container?
    TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black));
    mUnderlineColor = textPrimaryColor;
    mDividerColor = textPrimaryColor;
    mBaseLineColor = textPrimaryColor;
    mIndicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    String tabTextTypefaceName = "sans-serif";
    // Use Roboto Medium as the default typeface from API 21 onwards
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tabTextTypefaceName = "sans-serif-medium";
        mTabTextTypefaceStyle = Typeface.NORMAL;
    }

    // get custom attrs for tabs and container ?attr?
    a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerDoubleIndicator);
    mBaseLineColor = a.getColor(R.styleable.ViewPagerDoubleIndicator_vpdiBaseLineColor, mBaseLineColor);
    mIndicatorColor = a.getColor(R.styleable.ViewPagerDoubleIndicator_vpdiIndicatorColor, mIndicatorColor);
    mIndicatorHeight = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiIndicatorHeight,
            mIndicatorHeight);
    mUnderlineColor = a.getColor(R.styleable.ViewPagerDoubleIndicator_vpdiUnderlineColor, mUnderlineColor);
    mUnderlineHeight = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiUnderlineHeight,
            mUnderlineHeight);
    mDividerColor = a.getColor(R.styleable.ViewPagerDoubleIndicator_vpdiDividerColor, mDividerColor);
    mDividerWidth = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiDividerWidth,
            mDividerWidth);
    mDividerPadding = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiDividerPadding,
            mDividerPadding);
    isExpandTabs = a.getBoolean(R.styleable.ViewPagerDoubleIndicator_vpdiShouldExpand, isExpandTabs);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiScrollOffset,
            mScrollOffset);
    isPaddingMiddle = a.getBoolean(R.styleable.ViewPagerDoubleIndicator_vpdiPaddingMiddle, isPaddingMiddle);
    isHorizontalSplit = a.getBoolean(R.styleable.ViewPagerDoubleIndicator_vpdiHorizontalSplit,
            isHorizontalSplit);
    mTabPadding = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiTabPaddingLeftRight,
            mTabPadding);
    mTabBackgroundResId = a.getResourceId(R.styleable.ViewPagerDoubleIndicator_vpdiTabBackground,
            mTabBackgroundResId);
    mTabTextSize = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextSize, mTabTextSize);
    mTabTextColor = a.hasValue(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextColor)
            ? a.getColorStateList(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextColor)
            : null;
    mTabTextColorUnSelected = a.hasValue(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextColorUnSelected)
            ? a.getColorStateList(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextColorUnSelected)
            : null;
    mTabTextTypefaceStyle = a.getInt(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextStyle,
            mTabTextTypefaceStyle);
    isTabTextAllCaps = a.getBoolean(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextAllCaps, isTabTextAllCaps);
    int tabTextAlpha = a.getInt(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextAlpha,
            DEF_VALUE_TAB_TEXT_ALPHA);
    String fontFamily = a.getString(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextFontFamily);
    a.recycle();

    //Tab text color selector
    if (mTabTextColor == null) {
        mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha,
                Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor)));
    }

    //Tab text typeface and style
    if (fontFamily != null) {
        tabTextTypefaceName = fontFamily;
    }
    mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle);

    //Bottom padding for the tabs container parent view to show indicator and underline
    setTabsContainerParentViewPaddings();

    //Configure tab's container LayoutParams for either equal divided space or just wrap tabs
    //?Viewlayout? TODO
    if (isHorizontalSplit) {
        mTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
                1f);//?view
    } else {
        mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
                : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);//?view
    }
}

From source file:com.facebook.react.views.textinput.ReactTextInputManager.java

@ReactProp(name = ViewProps.FONT_FAMILY)
public void setFontFamily(ReactEditText view, String fontFamily) {
    int style = Typeface.NORMAL;
    if (view.getTypeface() != null) {
        style = view.getTypeface().getStyle();
    }// w ww .  j a  v a  2  s. c o m
    Typeface newTypeface = ReactFontManager.getInstance().getTypeface(fontFamily, style,
            view.getContext().getAssets());
    view.setTypeface(newTypeface);
}

From source file:com.ekuater.labelchat.ui.widget.PagerSlidingTabStrip.java

private int indexToTextStyle(int index, int defaultStyle) {
    int style;//w w  w. j  a  v a  2 s . c  o m

    switch (index) {
    case 0:
        style = Typeface.NORMAL;
        break;
    case 1:
        style = Typeface.BOLD;
        break;
    case 2:
        style = Typeface.ITALIC;
        break;
    case 3:
        style = Typeface.BOLD_ITALIC;
        break;
    default:
        style = defaultStyle;
        break;

    }
    return style;
}