Java 类android.util.TypedValue 实例源码

项目:weex-3d-map    文件:AbstractEditComponent.java   
/**
 * Process view after created.
 *
 * @param editText
 */
protected void appleStyleAfterCreated(WXEditText editText) {
  String alignStr = (String) getDomObject().getStyles().get(Constants.Name.TEXT_ALIGN);
  int textAlign = getTextAlign(alignStr);
  if (textAlign <= 0) {
    textAlign = Gravity.LEFT;
  }
  editText.setGravity(textAlign | Gravity.CENTER_VERTICAL);
  int colorInt = WXResourceUtils.getColor("#999999");
  if (colorInt != Integer.MIN_VALUE) {
    editText.setHintTextColor(colorInt);
  }

  editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, WXStyle.getFontSize(getDomObject().getStyles()));
  editText.setText(getDomObject().getAttrs().optString(Constants.Name.VALUE));
}
项目:PagerTabIndicator    文件:PagerTabsIndicator.java   
private View createTextView(String text) {

        final TextView textView = new TextView(getContext());
        textView.setText(text);
        textView.setGravity(Gravity.CENTER);
        textView.setSingleLine();
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        textView.setTextColor(textColor);


        return new TabView(PagerTabsIndicator.this.getContext(), textView) {
            @Override
            public void onOffset(float offset) {
                super.onOffset(offset);
                if (highlightText) {
                    ((TextView) getChildAt(0)).setTextColor(Util.mixTwoColors(highlightTextColor, textColor, offset));
                }
            }
        };
    }
项目:AdPlayBanner    文件:PointView.java   
private void setDefault(float size) {
    setGravity(Gravity.CENTER);
    setTextColor(Color.WHITE);

    DisplayMetrics metrics = getResources().getDisplayMetrics();
    if (size <= 0) {
        mSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, metrics);
    } else {
        mSize = size;
    }

    if (metrics.density <= 1.5) {
        setTextSize(TypedValue.COMPLEX_UNIT_DIP, 9);
    } else {
        setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
    }

    int paddingLeft = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, metrics);
    int paddingRight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, metrics);

    setPadding(paddingLeft, 0, paddingRight, 0);

    change();
}
项目:Nird2    文件:AuthorView.java   
public void setBlogLink(final GroupId groupId) {
    setClickable(true);
    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(
            android.R.attr.selectableItemBackground, outValue, true);
    setBackgroundResource(outValue.resourceId);
    setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(getContext(), BlogActivity.class);
            i.putExtra(GROUP_ID, groupId.getBytes());
            i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
            getContext().startActivity(i);
        }
    });
}
项目:dynamic-toasts    文件:AboutDialogFragment.java   
@Override
protected @NonNull DynamicDialog onCustomiseDialog(@NonNull DynamicDialog alertDialog,
                                                   @Nullable Bundle savedInstanceState) {
    View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_about,
            new LinearLayout(getContext()), false);
    TextView message = view.findViewById(R.id.dialog_about_text);

    message.setText(Html.fromHtml(getString(R.string.about_content)
            .replace("\n", "<br/>")));
    message.setTextSize(TypedValue.COMPLEX_UNIT_SP, TEXT_SIZE);
    message.setLineSpacing(0f, 1.2f);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    message.setLinkTextColor(ContextCompat.getColor(getContext(), R.color.colorPrimary));

    alertDialog.setView(view);
    return alertDialog;
}
项目:StyleableToast    文件:StyleableToast.java   
private void makeTextView() {
    loadTextViewStyleAttributes();
    textView.setText(text);
    if (textColor != 0) {
        textView.setTextColor(textColor);
    }

    if (textSize > 0) {
        textView.setTextSize(isTextSizeFromStyle ? 0 : TypedValue.COMPLEX_UNIT_SP, textSize);
    }

    if (textBold && typeface == null) {
        textView.setTypeface(Typeface.create(context.getString(R.string.default_font), Typeface.BOLD));
    } else if (textBold) {
        textView.setTypeface(Typeface.create(typeface, Typeface.BOLD));
    } else if (typeface != null) {
        textView.setTypeface(typeface);
        //TODO THIS CHECK IS DEPRECATED AND WILL BE DELETED SOON
    } else if (fontId > 0) {
        textView.setTypeface(ResourcesCompat.getFont(context, fontId));
    }
}
项目:AggregationNews    文件:SizeUtils.java   
/**
 * 各种单位转换
 * <p>该方法存在于TypedValue</p>
 *
 * @param unit    单位
 * @param value   值
 * @param metrics DisplayMetrics
 * @return 转换结果
 */
public static float applyDimension(int unit, float value, DisplayMetrics metrics) {
    switch (unit) {
        case TypedValue.COMPLEX_UNIT_PX:
            return value;
        case TypedValue.COMPLEX_UNIT_DIP:
            return value * metrics.density;
        case TypedValue.COMPLEX_UNIT_SP:
            return value * metrics.scaledDensity;
        case TypedValue.COMPLEX_UNIT_PT:
            return value * metrics.xdpi * (1.0f / 72);
        case TypedValue.COMPLEX_UNIT_IN:
            return value * metrics.xdpi;
        case TypedValue.COMPLEX_UNIT_MM:
            return value * metrics.xdpi * (1.0f / 25.4f);
    }
    return 0;
}
项目:adyen-android    文件:GiropayFragment.java   
private void selectedBank(final GiroPayIssuer bank) {
    editText.removeTextChangedListener(giroPayTextWatcher);
    editText.setText(bank.getBankName());
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
    editText.setSingleLine(false);
    editText.clearFocus();
    editText.setEnabled(false);
    editText.setCancelDrawable(AppCompatResources.getDrawable(getContext(), R.drawable.clear_icon),
            new GiroPayEditText.OnDrawableClickListener() {
        @Override
        public void onDrawableClick() {
            unSelectedBank();
        }
    });

    issuerListAdapter.clearData();
    issuerListAdapter.notifyDataSetChanged();

    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(editText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

    payButton.setEnabled(true);
}
项目:FinalProject    文件:MessageHolders.java   
@Override
public final void applyStyle(MessagesListStyle style) {
    super.applyStyle(style);
    if (bubble != null) {
        bubble.setPadding(style.getOutcomingDefaultBubblePaddingLeft(),
                style.getOutcomingDefaultBubblePaddingTop(),
                style.getOutcomingDefaultBubblePaddingRight(),
                style.getOutcomingDefaultBubblePaddingBottom());
        ViewCompat.setBackground(bubble, style.getOutcomingBubbleDrawable());
    }

    if (text != null) {
        text.setTextColor(style.getOutcomingTextColor());
        text.setTextSize(TypedValue.COMPLEX_UNIT_PX, style.getOutcomingTextSize());
        text.setTypeface(text.getTypeface(), style.getOutcomingTextStyle());
        text.setAutoLinkMask(style.getTextAutoLinkMask());
        text.setLinkTextColor(style.getOutcomingTextLinkColor());
        configureLinksBehavior(text);
    }
}
项目:proSwipeButton    文件:ProSwipeButton.java   
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    contentContainer = view.findViewById(R.id.relativeLayout_swipeBtn_contentContainer);
    arrowHintContainer = view.findViewById(R.id.linearLayout_swipeBtn_hintContainer);
    contentTv = view.findViewById(R.id.tv_btnText);
    arrow1 = view.findViewById(R.id.iv_arrow1);
    arrow2 = view.findViewById(R.id.iv_arrow2);

    tintArrowHint();
    contentTv.setText(btnText);
    contentTv.setTextColor(textColorInt);
    contentTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    gradientDrawable = new GradientDrawable();
    gradientDrawable.setShape(GradientDrawable.RECTANGLE);
    gradientDrawable.setCornerRadius(btnRadius);
    setBackgroundColor(bgColorInt);
    updateBackground();
    setupTouchListener();
}
项目:ht-viewpagerwithindicator    文件:SlidingTabLayout.java   
/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
                outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}
项目:qmui    文件:QMUITopBar.java   
/**
 * 生成一个文本按钮,并设置文字
 *
 * @param text 按钮的文字
 * @return
 */
private Button generateTopBarTextButton(String text) {
    Button button = new Button(getContext());
    button.setBackgroundResource(0);
    button.setMinWidth(0);
    button.setMinHeight(0);
    button.setMinimumWidth(0);
    button.setMinimumHeight(0);
    int paddingHorizontal = getTopBarTextBtnPaddingHorizontal();
    button.setPadding(paddingHorizontal, 0, paddingHorizontal, 0);
    button.setTextColor(QMUIResHelper.getAttrColorStateList(getContext(), R.attr.qmui_topbar_text_btn_color_state_list));
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, QMUIResHelper.getAttrDimen(getContext(), R.attr.qmui_topbar_text_btn_text_size));
    button.setGravity(Gravity.CENTER);
    button.setText(text);
    return button;
}
项目:wallpaperboard    文件:WallpaperBoardSplashActivity.java   
private void initBottomText() {
    TextView splashTitle = findViewById(R.id.splash_title);
    if (splashTitle != null) {
        splashTitle.setText(mConfig.getBottomText());

        if (mConfig.getBottomTextColor() != -1) {
            splashTitle.setTextColor(mConfig.getBottomTextColor());
        } else {
            int color = ContextCompat.getColor(this, R.color.splashColor);
            splashTitle.setTextColor(ColorHelper.getBodyTextColor(color));
        }

        splashTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, mConfig.getBottomTextSize());
        splashTitle.setTypeface(mConfig.getBottomTextFont(this));
    }
}
项目:QMark    文件:MagicBoardView.java   
private void init(Context context, int drawableId, String text, int textColor, String typefacePath) {
    reset();
    if (drawableId > 0) setMagicSrc(drawableId);

    mTextView = mEditMode ? new EditText(context) : new TextView(context);
    //不要用LayoutParams.WRAP_CONTENT,否则每次设置文本都会引发requestLayout()
    addView(mTextView, new LayoutParams(0, 0));
    mTextView.addTextChangedListener(mTextWatcher);
    mTextView.setBackgroundResource(0);
    mTextView.setPadding(0, 0, 0, 0);   //paddings会导致文本的遮盖,对于EditText, 即使将背景置为null, 也还会有padding
    mTextView.setTextColor(textColor);
    mTextView.setGravity(Gravity.CENTER);
    if (typefacePath != null) setTextFont(typefacePath.startsWith("asset:"), typefacePath);

    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    //DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    //mUnitInPx = (int)(displayMetrics.density * 2 + 0.5f);
    //if (!mEditMode) mUnitInPx *= 2;
    if (mMinTextSize <= 0) mMinTextSize = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 9, displayMetrics);
    if (mMaxTextSize <= 0) mMaxTextSize = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 80, displayMetrics);
    if (mMinTextSize > mMaxTextSize) throw new IllegalArgumentException("字号范围设置错误:[" + mMinTextSize + ", " + mMaxTextSize + "]");
    scaleTextSize(1);
    mTextSize = mMinTextSizeScaled;
    setTextSize(mTextSize);
    setText(text);
}
项目:GitHub    文件:TextSizeTransition.java   
@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }

    Float startSize = (Float) startValues.values.get(PROPNAME_TEXT_SIZE);
    Float endSize = (Float) endValues.values.get(PROPNAME_TEXT_SIZE);
    if (startSize == null || endSize == null || startSize.floatValue() == endSize.floatValue()) {
        return null;
    }

    TextView view = (TextView) endValues.view;
    view.setTextSize(TypedValue.COMPLEX_UNIT_PX, startSize);
    return ObjectAnimator.ofFloat(view, TEXT_SIZE_PROPERTY, startSize, endSize);
}
项目:Android-skin-support    文件:SkinMaterialNavigationView.java   
private ColorStateList createDefaultColorStateList(int baseColorThemeAttr) {
    final TypedValue value = new TypedValue();
    if (!getContext().getTheme().resolveAttribute(baseColorThemeAttr, value, true)) {
        return null;
    }
    ColorStateList baseColor = SkinCompatResources.getColorStateList(getContext(), value.resourceId);

    int colorPrimary = SkinCompatResources.getColor(getContext(), mDefaultTintResId);
    int defaultColor = baseColor.getDefaultColor();
    return new ColorStateList(new int[][]{
            DISABLED_STATE_SET,
            CHECKED_STATE_SET,
            EMPTY_STATE_SET
    }, new int[]{
            baseColor.getColorForState(DISABLED_STATE_SET, defaultColor),
            colorPrimary,
            defaultColor
    });
}
项目:PlusGram    文件:MentionCell.java   
public MentionCell(Context context) {
    super(context);

    setOrientation(HORIZONTAL);

    setBackgroundResource(R.drawable.list_selector);

    avatarDrawable = new AvatarDrawable();
    avatarDrawable.setSmallStyle(true);

    imageView = new BackupImageView(context);
    imageView.setRoundRadius(AndroidUtilities.dp(14));
    addView(imageView, LayoutHelper.createLinear(28, 28, 12, 4, 0, 0));

    nameTextView = new TextView(context);
    nameTextView.setTextColor(0xff000000);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    nameTextView.setSingleLine(true);
    nameTextView.setGravity(Gravity.LEFT);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    addView(nameTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 12, 0, 0, 0));

    usernameTextView = new TextView(context);
    usernameTextView.setTextColor(0xff999999);
    usernameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    usernameTextView.setSingleLine(true);
    usernameTextView.setGravity(Gravity.LEFT);
    usernameTextView.setEllipsize(TextUtils.TruncateAt.END);
    addView(usernameTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 12, 0, 8, 0));
}
项目:BBSSDK-for-Android    文件:Theme0StyleModifier.java   
public static void setTextSize(TextView textview, String strdimen) {
    if (textview == null || StringUtils.isEmpty(strdimen)) {
        throw new IllegalArgumentException("Illegal argument to setTextSize()!");
    }
    Context context = textview.getContext();
    int tvTitleSize = context.getResources().getDimensionPixelSize(ResHelper.getResId(context, "dimen", "bbs_title_txt_size"));
    textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvTitleSize);
}
项目:RLibrary    文件:ItemInfoLayout.java   
private void initLayout() {
    mTextView = new RTextView(getContext());
    mDarkTextView = new RTextView(getContext());
    mImageView = new ImageView(getContext());
    mLineView = new View(getContext());
    mLineView.setVisibility(showLine ? View.VISIBLE : View.GONE);
    mLineView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.base_chat_bg_color));

    mTextView.setTag(itemTag);
    mTextView.setText(itemText);
    mTextView.setTextColor(itemTextColor);
    mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, itemTextSize);
    mTextView.setCompoundDrawablePadding(leftDrawPadding);
    mTextView.setGravity(Gravity.CENTER_VERTICAL);
    setLeftDrawableRes(leftDrawableRes);

    mDarkTextView.setId(itemDarkId);
    mDarkTextView.setTag(itemDarkTag);
    mDarkTextView.setText(itemDarkText);
    mDarkTextView.setTextColor(itemDarkTextColor);
    mDarkTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, itemDarkTextSize);
    mDarkTextView.setCompoundDrawablePadding(rightDrawPadding);
    mDarkTextView.setGravity(Gravity.CENTER_VERTICAL);
    mDarkTextView.setMaxLines(1);
    mDarkTextView.setSingleLine(true);
    mDarkTextView.setEllipsize(TextUtils.TruncateAt.END);
    mDarkTextView.setMaxLength(20);
    mDarkTextView.setMaxWidth((int) (getResources().getDisplayMetrics().density * 260));

    setRightDrawableRes(rightDrawableRes);
    setDarkDrawableRes(darkDrawableRes);

    LayoutParams params = new LayoutParams(-2, -2);
    params.addRule(RelativeLayout.CENTER_VERTICAL);

    LayoutParams paramsDark = new LayoutParams(-2, -2);
    paramsDark.addRule(RelativeLayout.CENTER_VERTICAL);
    paramsDark.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

    int size = (int) dpToPx(darkImageSize);
    LayoutParams imageParam = new LayoutParams(size, size);
    imageParam.addRule(RelativeLayout.CENTER_VERTICAL);
    imageParam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    if (isRedDotMode) {
        imageParam.setMargins(0, 0, (int) dpToPx(20), 0);
    } else {
        int padding = (int) dpToPx(2);
        imageParam.setMargins(0, 0, -padding, 0);
        mImageView.setPadding(0, padding, 0, padding);
    }
    //mImageView.setBackgroundColor(Color.RED);

    LayoutParams lineParam = new LayoutParams(-1, getResources().getDimensionPixelOffset(R.dimen.base_line));
    lineParam.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

    addView(mTextView, params);
    addView(mDarkTextView, paramsDark);
    addView(mImageView, imageParam);
    addView(mLineView, lineParam);
}
项目:aos-MediaLib    文件:ActionBarSubmenu.java   
/*******************************************************************
** ActionBarSubmenu API
*******************************************************************/

public ActionBarSubmenu(Context context, LayoutInflater inflater, View anchor) {
    mContext = context;

    mItemList = new ArrayList<SubmenuItemData>();
    mSelectedPosition = 0;   // default value
    mSubmenuItemTitleMaxWidth = 0;

    mAdapter = new ActionBarSubmenuAdapter(inflater);

    mPopupWindow = new ListPopupWindow(context, null);
    mPopupWindow.setAdapter(mAdapter);
    mPopupWindow.setModal(true);
    mPopupWindow.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(context,R.color.primary_material_dark)));
    mPopupWindow.setAnchorView(anchor);
    mPopupWindow.setOnItemClickListener(this);

    // Get the size of the font used to display the submenu items
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.textAppearanceLarge, typedValue, true);
    int[] attribute = new int[] { android.R.attr.textSize };
    TypedArray array = context.obtainStyledAttributes(typedValue.resourceId, attribute);
    mSubmenuFontSize = array.getDimensionPixelSize(0, -1);
    array.recycle();

    // Get the size of the radio button bitmap
    mRadioButtonWidth = context.getResources().getDimensionPixelSize(R.dimen.radio_button_width);
}
项目:LibScout    文件:AXMLPrinter.java   
public static String getAttributeValue(AXmlResourceParser parser,int index) {
    int type=parser.getAttributeValueType(index);
    int data=parser.getAttributeValueData(index);
    if (type==TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type==TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X",getPackage(data),data);
    }
    if (type==TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X",getPackage(data),data);
    }
    if (type==TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type==TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X",data);
    }
    if (type==TypedValue.TYPE_INT_BOOLEAN) {
        return data!=0?"true":"false";
    }
    if (type==TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data))+
            DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type==TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data))+
            FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type>=TypedValue.TYPE_FIRST_COLOR_INT && type<=TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X",data);
    }
    if (type>=TypedValue.TYPE_FIRST_INT && type<=TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>",data,type);
}
项目:DarkCalculator    文件:AutofitHelper.java   
/**
 * Creates a new instance of {@code AutofitHelper} that wraps a {@link TextView} and enables
 * automatically sizing the text to fit.
 */
public static AutofitHelper create(TextView view, AttributeSet attrs, int defStyle) {
    AutofitHelper helper = new AutofitHelper(view);
    boolean sizeToFit = true;
    if (attrs != null) {
        Context context = view.getContext();
        int minTextSize = (int) helper.getMinTextSize();
        float precision = helper.getPrecision();

        TypedArray ta = context.obtainStyledAttributes(
                attrs,
                R.styleable.AutofitTextView,
                defStyle,
                0);
        sizeToFit = ta.getBoolean(R.styleable.AutofitTextView_sizeToFit, sizeToFit);
        minTextSize = ta.getDimensionPixelSize(R.styleable.AutofitTextView_minTextSize,
                minTextSize);
        precision = ta.getFloat(R.styleable.AutofitTextView_precision, precision);
        ta.recycle();

        helper.setMinTextSize(TypedValue.COMPLEX_UNIT_PX, minTextSize)
                .setPrecision(precision);
    }
    helper.setEnabled(sizeToFit);

    return helper;
}
项目:Pocket-Plays-for-Twitch    文件:FontFitTextView.java   
/**
 * Reset the text to the original size
 */
public void resetTextSize() {
    if (mTextSize > 0) {
        super.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
        mMaxTextSize = mTextSize;
    }
}
项目:StarrySkyDemo    文件:StarrySkyView.java   
public StarrySkyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    //初始化三种星球移动速度
    mFloatTransLowSpeed = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.5f,
            getResources().getDisplayMetrics());
    mFloatTransMidSpeed = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.75f,
            getResources().getDisplayMetrics());
    mFloatTransFastSpeed = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1f,
            getResources().getDisplayMetrics());

    mTotalWidth = getResources().getDisplayMetrics().widthPixels;
    mTotalHeight = getResources().getDisplayMetrics().heightPixels;

    initBitmapInfo();

    paint = new Paint();

    screenRect = new Rect(0, 0, mTotalWidth, mTotalHeight);

    valueAnimator = ValueAnimator.ofInt(0, 100);
    valueAnimator.setDuration(10000);
    valueAnimator.setInterpolator(new AccelerateInterpolator());
    valueAnimator.setRepeatMode(ValueAnimator.RESTART);
    valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
    valueAnimator.addUpdateListener(new AnimatorUpdateListener());

}
项目:PlusGram    文件:SharedMediaSectionCell.java   
public SharedMediaSectionCell(Context context) {
    super(context);

    textView = new TextView(getContext());
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setTextColor(0xff212121);
    textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 13, 0, 13, 0));
}
项目:BBSSDK-for-Android    文件:Theme1StyleModifier.java   
public static void setTextSize(TextView textview, String strdimen) {
    if (textview == null || StringUtils.isEmpty(strdimen)) {
        throw new IllegalArgumentException("Illegal argument to setTextSize()!");
    }
    Context context = textview.getContext();
    int tvTitleSize = context.getResources().getDimensionPixelSize(ResHelper.getResId(context, "dimen", "bbs_title_txt_size"));
    textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvTitleSize);
}
项目:GracefulMovies    文件:BoxOfficeActivity.java   
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_box_office);
    ButterKnife.bind(this);

    initializeToolbar();

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mAdapter.getData() != null && !mAdapter.getData().isEmpty())
                mRecyclerView.smoothScrollToPosition(0);
        }
    });

    mSwipeRefreshLayout.setColorSchemeColors(
            ContextCompat.getColor(this, Colorful.getThemeDelegate().getAccentColor().getColorRes()),
            ContextCompat.getColor(this, Colorful.getThemeDelegate().getPrimaryColor().getColorRes())
    );
    mSwipeRefreshLayout.setProgressViewEndTarget(false, (int) TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, 80, Resources.getSystem().getDisplayMetrics()));
    mSwipeRefreshLayout.setRefreshing(true);
    mSwipeRefreshLayout.setOnRefreshListener(this);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mAdapter = new BoxOfficeListAdapter();
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setItemAnimator(null);

    mPresenter = new BoxOfficeActivityPresenterImpl();
    mPresenter.register(this);
    mPresenter.loadData();
}
项目:FabulousFilter    文件:ViewPagerBottomSheetDialog.java   
private static int getThemeResId(Context context, int themeId) {
    if (themeId == 0) {
        // If the provided theme is 0, then retrieve the dialogTheme from our theme
        TypedValue outValue = new TypedValue();
        if (context.getTheme().resolveAttribute(
                R.attr.bottomSheetDialogTheme, outValue, true)) {
            themeId = outValue.resourceId;
        } else {
            // bottomSheetDialogTheme is not provided; we default to our light theme
            themeId = R.style.Theme_Design_Light_BottomSheetDialog;
        }
    }
    return themeId;
}
项目:yyox    文件:EditPageLand.java   
private void initBody(RelativeLayout rlBody, float ratio) {
    svContent = new ScrollView(activity);
    rlBody.addView(svContent, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    LinearLayout llContent = new LinearLayout(activity);
    llContent.setOrientation(LinearLayout.HORIZONTAL);
    svContent.addView(llContent, new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    etContent = new EditText(activity);
    int padding = (int) (DESIGN_LEFT_PADDING * ratio);
    etContent.setPadding(padding, padding, padding, padding);
    etContent.setBackgroundDrawable(null);
    etContent.setTextColor(0xff3b3b3b);
    etContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
    etContent.setText(sp.getText());
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT);
    lp.weight = 1;
    llContent.addView(etContent, lp);
    etContent.addTextChangedListener(this);

    rlThumb = new RelativeLayout(activity);
    rlThumb.setBackgroundColor(0xff313131);
    int thumbWidth = (int) (DESIGN_THUMB_HEIGHT_L * ratio);
    int xWidth = (int) (DESIGN_REMOVE_THUMB_HEIGHT_L * ratio);
    lp = new LinearLayout.LayoutParams(thumbWidth, thumbWidth);
    lp.rightMargin = lp.bottomMargin = lp.topMargin = padding;
    llContent.addView(rlThumb, lp);

    aivThumb = new AsyncImageView(activity) {
        public void onImageGot(String url, Bitmap bm) {
            thumb = bm;
            super.onImageGot(url, bm);
        }
    };
    aivThumb.setScaleToCropCenter(true);
    RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(thumbWidth, thumbWidth);
    rlThumb.addView(aivThumb, rllp);
    aivThumb.setOnClickListener(this);
    initThumb(aivThumb);

    xvRemove = new XView(activity);
    xvRemove.setRatio(ratio);
    rllp = new RelativeLayout.LayoutParams(xWidth, xWidth);
    rllp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    rllp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    rlThumb.addView(xvRemove, rllp);
    xvRemove.setOnClickListener(this);
}
项目:GeekZone    文件:BaseActivity.java   
private void initView(View view) {
    mRootLayout = new FrameLayout(this);
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);
    mRootLayout.setLayoutParams(layoutParams);
    mRootLayout.addView(view);

    TypedValue tv = new TypedValue();
    int actionBarHeight = 0;
    if (mIsLoadingMargin && getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                getResources().getDisplayMetrics());
    }
    FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    flp.topMargin = actionBarHeight;

    mErrorView = LayoutInflater.from(this).inflate(R.layout.load_failed, null);
    mErrorView.setVisibility(View.GONE);
    mErrorView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            retryLoading();
        }
    });
    mRootLayout.addView(mErrorView, flp);

    mLoadingView = LayoutInflater.from(this).inflate(R.layout.loading, null);
    mLoadingView.setLayoutParams(layoutParams);
    mLoadingView.setVisibility(View.GONE);
    mRootLayout.addView(mLoadingView, flp);

    mFloatLoadingView = LayoutInflater.from(this).inflate(R.layout.float_loading, null);
    mFloatLoadingView.setVisibility(View.GONE);
    mRootLayout.addView(mFloatLoadingView, flp);

    setContentView(mRootLayout);
}
项目:ywApplication    文件:FollowListPage.java   
public PRTHeader(Context context) {
    super(context);
    setOrientation(VERTICAL);

    LinearLayout llInner = new LinearLayout(context);
    LayoutParams lpInner = new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lpInner.gravity = Gravity.CENTER_HORIZONTAL;
    addView(llInner, lpInner);

    ivArrow = new RotateImageView(context);
    int resId = getBitmapRes(context, "ssdk_oks_ptr_ptr");
    if (resId > 0) {
        ivArrow.setImageResource(resId);
    }
    int dp_32 = dipToPx(context, 32);
    LayoutParams lpIv = new LayoutParams(dp_32, dp_32);
    lpIv.gravity = Gravity.CENTER_VERTICAL;
    llInner.addView(ivArrow, lpIv);

    pbRefreshing = new ProgressBar(context);
    llInner.addView(pbRefreshing, lpIv);
    pbRefreshing.setVisibility(View.GONE);

    tvHeader = new TextView(getContext());
    tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    tvHeader.setGravity(Gravity.CENTER);
    int dp_10 = com.mob.tools.utils.R.dipToPx(getContext(), 10);
    tvHeader.setPadding(dp_10, dp_10, dp_10, dp_10);
    tvHeader.setTextColor(0xff000000);
    LayoutParams lpTv = new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lpTv.gravity = Gravity.CENTER_VERTICAL;
    llInner.addView(tvHeader, lpTv);
}
项目:TextEmoji    文件:FriendListItem.java   
public FriendListItem(Context context, float ratio) {
    super(context);
    int itemPadding = (int) (ratio * DESIGN_ITEM_PADDING);
    setPadding(itemPadding, 0, itemPadding, 0);
    setMinimumHeight((int) (ratio * DESIGN_ITEM_HEIGHT));
    setBackgroundColor(0xffffffff);

    ivCheck = new ImageView(context);
    LayoutParams lp = new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER_VERTICAL;
    addView(ivCheck, lp);

    aivIcon = new AsyncImageView(context);
    int avatarWidth = (int) (ratio * DESIGN_AVATAR_WIDTH);
    lp = new LayoutParams(avatarWidth, avatarWidth);
    lp.gravity = Gravity.CENTER_VERTICAL;
    int avatarMargin = (int) (ratio * DESIGN_AVATAR_PADDING);
    lp.setMargins(avatarMargin, 0, avatarMargin, 0);
    addView(aivIcon, lp);

    tvName = new TextView(context);
    tvName.setTextColor(0xff000000);
    tvName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    tvName.setSingleLine();
    lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER_VERTICAL;
    lp.weight = 1;
    addView(tvName, lp);

    int resId = ResHelper.getBitmapRes(context, "ssdk_oks_classic_check_checked");
    if (resId > 0) {
        bmChd = BitmapFactory.decodeResource(context.getResources(), resId);
    }
    resId = ResHelper.getBitmapRes(getContext(), "ssdk_oks_classic_check_default");
    if (resId > 0) {
        bmUnch = BitmapFactory.decodeResource(context.getResources(), resId);
    }
}
项目:Rxjava2.0Demo    文件:NineGridImageView.java   
public NineGridImageView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    //转换成dp
    gridSpace = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, gridSpace, dm);
    imageViews = new ArrayList<>();
}
项目:GravityBox    文件:ProgressBarView.java   
public ProgressBarView(ContainerType containerType, ViewGroup container,
        XSharedPreferences prefs, ProgressBarController ctrl) {
    super(container.getContext());

    mContainerType = containerType;
    mCtrl = ctrl;

    mAnimated = prefs.getBoolean(GravityBoxSettings.PREF_KEY_STATUSBAR_DOWNLOAD_PROGRESS_ANIMATED, true);
    mCentered = prefs.getBoolean(GravityBoxSettings.PREF_KEY_STATUSBAR_DOWNLOAD_PROGRESS_CENTERED, false);
    mHeightPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            prefs.getInt(GravityBoxSettings.PREF_KEY_STATUSBAR_DOWNLOAD_PROGRESS_THICKNESS, 1),
            getResources().getDisplayMetrics());
    mEdgeMarginPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            prefs.getInt(GravityBoxSettings.PREF_KEY_STATUSBAR_DOWNLOAD_PROGRESS_MARGIN, 0),
            getResources().getDisplayMetrics());

    setScaleX(0f);
    setBackgroundColor(Color.WHITE);
    setVisibility(View.GONE);
    container.addView(this);

    mAnimator = new ObjectAnimator();
    mAnimator.setTarget(this);
    mAnimator.setInterpolator(new DecelerateInterpolator());
    mAnimator.setDuration(ANIM_DURATION);
    mAnimator.setRepeatCount(0);
}
项目:HLOLI    文件:DividerDecoration.java   
/**
 * 构造方法传入布局方向,不可不传
 *
 * @param context
 * @param orientation
 */
public DividerDecoration(Context context, int orientation) {
    this.mOrientation = orientation;
    if (orientation != LinearLayoutManager.VERTICAL && orientation != LinearLayoutManager.HORIZONTAL) {
        throw new IllegalArgumentException("请传入正确的参数");
    }
    mItemSize = (int) TypedValue.applyDimension(mItemSize, TypedValue.COMPLEX_UNIT_DIP, context.getResources().getDisplayMetrics());
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(context.getResources().getColor(R.color.divider));
     /*设置填充*/
    mPaint.setStyle(Paint.Style.FILL);
}
项目:GxIconAndroid    文件:ExtraUtil.java   
public static int fetchColor(@NonNull Context context, int attrId) {
    TypedValue typedValue = new TypedValue();
    TypedArray a = context.obtainStyledAttributes(typedValue.data,
            new int[] { attrId });
    int color = a.getColor(0, 0);
    a.recycle();
    return color;
}
项目:EatLoading    文件:EatLoading.java   
@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int resultWidth;
        int resultHeight;

        //测量宽高
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);

        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = MeasureSpec.getSize(heightMeasureSpec);

        //确定高
        if (heightMode == MeasureSpec.EXACTLY){
            resultHeight = height;
        }else {
            float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());
            resultHeight = (int) px;

            if (widthMode == MeasureSpec.AT_MOST){
                resultHeight = Math.min(resultHeight, height);
            }
        }

        //确定宽
        if (widthMode == MeasureSpec.EXACTLY){
            resultWidth = width;
        }else {
            resultWidth = resultHeight * 4;

            if (widthMode == MeasureSpec.AT_MOST){
                resultWidth = Math.min(resultWidth, width);
            }
        }

        setMeasuredDimension(resultWidth, resultHeight);
    }
项目:GravityBox    文件:StatusbarBatteryPercentage.java   
public void setTextSize(int size) {
    if (size == 0) {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, mDefaultSizePx);
    } else {
        setTextSize(TypedValue.COMPLEX_UNIT_DIP, size);
    }
}
项目:PicKing    文件:ScreenUtil.java   
/**
 * 获取actionbar的像素高度,默认使用android官方兼容包做actionbar兼容
 *
 * @return
 */
public static int getActionBarHeight(Context context) {
    int actionBarHeight = 0;
    if (context instanceof AppCompatActivity && ((AppCompatActivity) context).getSupportActionBar() != null) {
        Log.d("isAppCompatActivity", "==AppCompatActivity");
        actionBarHeight = ((AppCompatActivity) context).getSupportActionBar().getHeight();
    } else if (context instanceof Activity && ((Activity) context).getActionBar() != null) {
        Log.d("isActivity", "==Activity");
        actionBarHeight = ((Activity) context).getActionBar().getHeight();
    } else if (context instanceof ActivityGroup) {
        Log.d("ActivityGroup", "==ActivityGroup");
        if (((ActivityGroup) context).getCurrentActivity() instanceof AppCompatActivity && ((AppCompatActivity) ((ActivityGroup) context).getCurrentActivity()).getSupportActionBar() != null) {
            actionBarHeight = ((AppCompatActivity) ((ActivityGroup) context).getCurrentActivity()).getSupportActionBar().getHeight();
        } else if (((ActivityGroup) context).getCurrentActivity() instanceof Activity && ((Activity) ((ActivityGroup) context).getCurrentActivity()).getActionBar() != null) {
            actionBarHeight = ((Activity) ((ActivityGroup) context).getCurrentActivity()).getActionBar().getHeight();
        }
    }
    if (actionBarHeight != 0)
        return actionBarHeight;
    final TypedValue tv = new TypedValue();
    if (context.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, tv, true)) {
        if (context.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, tv, true))
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    } else {
        if (context.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, tv, true))
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }
    Log.d("actionBarHeight", "====" + actionBarHeight);
    return actionBarHeight;
}
项目:FinalProject    文件:MessageHolders.java   
@Override
public void applyStyle(MessagesListStyle style) {
    if (time != null) {
        time.setTextColor(style.getOutcomingTimeTextColor());
        time.setTextSize(TypedValue.COMPLEX_UNIT_PX, style.getOutcomingTimeTextSize());
        time.setTypeface(time.getTypeface(), style.getOutcomingTimeTextStyle());
    }
}