/** * Set the text that this SnackBar is to display. * @param text The text is displayed. * @return This SnackBar for chaining methods. */ public SnackBar text(CharSequence text){ mText.setText(text); return this; }
private android.widget.TextView getLabelView(){ if(mLabelView == null){ mLabelView = new TextView(getContext()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) mLabelView.setTextDirection(mIsRtl ? TEXT_DIRECTION_RTL : TEXT_DIRECTION_LTR); mLabelView.setSingleLine(true); mLabelView.setDuplicateParentStateEnabled(true); } return mLabelView; }
public void applyStyle(int resId){ ViewUtil.applyStyle(this, resId); applyStyle(getContext(), null, 0, resId); }
/** * Set the title of this Dialog. * @param title The title text. * @return The Dialog for chaining methods. */ public Dialog title(CharSequence title){ mTitle.setText(title); mTitle.setVisibility(TextUtils.isEmpty(title) ? View.GONE : View.VISIBLE); return this; }
private void initMessageView(){ mMessage = new TextView(getContext()); mMessage.setTextAppearance(getContext(), mMessageTextAppearanceId); mMessage.setTextColor(mMessageTextColor); mMessage.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); }
int padding = mIsRtl ? mText.getPaddingLeft() : mText.getPaddingRight(); mText.measure(MeasureSpec.makeMeasureSpec(widthSize - (mAction.getMeasuredWidth() - padding), widthMode), heightMeasureSpec); width = mText.getMeasuredWidth() + mAction.getMeasuredWidth() - padding; mText.measure(MeasureSpec.makeMeasureSpec(widthSize, widthMode), heightMeasureSpec); width = mText.getMeasuredWidth(); height = Math.max(mText.getMeasuredHeight(), mAction.getMeasuredHeight());
if(mLabelView != null && mLabelView.getLayoutParams() != null){ int size = widthMode == MeasureSpec.UNSPECIFIED ? 0 : (widthSize - paddingHorizontal); int ws = MeasureSpec.makeMeasureSpec(size, widthMode); int hs = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); mLabelView.measure(ws, hs); labelWidth = mLabelView.getMeasuredWidth(); labelHeight = mLabelView.getMeasuredHeight(); ViewGroup.LayoutParams params = v.getLayoutParams(); int ws = getSpec(widthSize - paddingHorizontal, params.width); int hs = getSpec(heightSize - paddingVertical - mLabelView.getMeasuredHeight(), params.height);
int titleHeight = 0; if(mTitle.getVisibility() == View.VISIBLE){ widthMs = View.MeasureSpec.makeMeasureSpec(width == ViewGroup.LayoutParams.WRAP_CONTENT ? maxWidth : width, View.MeasureSpec.AT_MOST); heightMs = View.MeasureSpec.makeMeasureSpec(maxHeight, View.MeasureSpec.AT_MOST); mTitle.measure(widthMs, heightMs); titleWidth = mTitle.getMeasuredWidth(); titleHeight = mTitle.getMeasuredHeight();
childBottom -= getPaddingBottom(); if(mTitle.getVisibility() == View.VISIBLE) { if(mIsRtl) mTitle.layout(childRight - mTitle.getMeasuredWidth(), childTop, childRight, childTop + mTitle.getMeasuredHeight()); else mTitle.layout(childLeft, childTop, childLeft + mTitle.getMeasuredWidth(), childTop + mTitle.getMeasuredHeight()); childTop += mTitle.getMeasuredHeight();
mTitle = new TextView(context); mPositiveAction = new Button(context); mNegativeAction = new Button(context); mCardView.setUseCompatPadding(true); mTitle.setId(TITLE); mTitle.setGravity(Gravity.START); mTitle.setPadding(mContentPadding, mContentPadding, mContentPadding, mContentPadding - mActionPadding); mPositiveAction.setId(ACTION_POSITIVE); mPositiveAction.setPadding(mActionPadding, 0, mActionPadding, 0);
/** * Set the horizontal padding between this SnackBar and it's text and button. * @param padding * @return This SnackBar for chaining methods. */ public SnackBar horizontalPadding(int padding){ mText.setPadding(padding, mText.getPaddingTop(), padding, mText.getPaddingBottom()); mAction.setPadding(padding, mAction.getPaddingTop(), padding, mAction.getPaddingBottom()); return this; }
/** * Set the vertical padding between this SnackBar and it's text and button. * @param padding * @return This SnackBar for chaining methods. */ public SnackBar verticalPadding(int padding){ mText.setPadding(mText.getPaddingLeft(), padding, mText.getPaddingRight(), padding); mAction.setPadding(mAction.getPaddingLeft(), padding, mAction.getPaddingRight(), padding); return this; }
@Override protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ mWidth = MATCH_PARENT; mHeight = WRAP_CONTENT; mDuration = -1; mIsRtl = false; mText = new TextView(context); mText.setSingleLine(true); mText.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); addView(mText, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mAction = new Button(context); mAction.setBackgroundResource(0); mAction.setGravity(Gravity.CENTER); mAction.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mActionClickListener != null) mActionClickListener.onActionClick(SnackBar.this, mActionId); dismiss(); } }); addView(mAction, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mBackground = new BackgroundDrawable(); mBackground.setColor(0xFF323232); ViewUtil.setBackground(this, mBackground); setClickable(true); super.init(context, attrs, defStyleAttr, defStyleRes); }
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int childLeft = getPaddingLeft(); int childRight = r - l - getPaddingRight(); int childTop = getPaddingTop(); int childBottom = b - t - getPaddingBottom(); if(mAction.getVisibility() == View.VISIBLE){ if(mIsRtl) { mAction.layout(childLeft, childTop, childLeft + mAction.getMeasuredWidth(), childBottom); childLeft += mAction.getMeasuredWidth() - mText.getPaddingLeft(); } else { mAction.layout(childRight - mAction.getMeasuredWidth(), childTop, childRight, childBottom); childRight -= mAction.getMeasuredWidth() - mText.getPaddingRight(); } } mText.layout(childLeft, childTop, childRight, childBottom); }
int top = getPaddingTop() + (mLabelView == null ? 0 : mLabelView.getMeasuredHeight()); int bottom = h - getDividerDrawableHeight() - getPaddingBottom(); if(mIsRtl) mLabelView.layout(childRight - mLabelView.getMeasuredWidth(), childTop, childRight, childTop + mLabelView.getMeasuredHeight()); else mLabelView.layout(childLeft, childTop, childLeft + mLabelView.getMeasuredWidth(), childTop + mLabelView.getMeasuredHeight()); childTop += mLabelView.getMeasuredHeight();
protected void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ ViewUtil.applyFont(this, attrs, defStyleAttr, defStyleRes); applyStyle(context, attrs, defStyleAttr, defStyleRes); if(!isInEditMode()) mStyleId = ThemeManager.getStyleId(context, attrs, defStyleAttr, defStyleRes); }
padding(horizontalPadding >= 0 ? horizontalPadding : mText.getPaddingLeft(), verticalPadding >= 0 ? verticalPadding : mText.getPaddingTop());
@Override public void onThemeChanged(ThemeManager.OnThemeChangedEvent event) { int style = ThemeManager.getInstance().getCurrentStyle(mStyleId); if(mCurrentStyle != style){ mCurrentStyle = style; applyStyle(mCurrentStyle); } }
@Override public void setBackgroundDrawable(Drawable drawable) { Drawable background = getBackground(); if(background instanceof RippleDrawable && !(drawable instanceof RippleDrawable)) ((RippleDrawable) background).setBackgroundDrawable(drawable); else super.setBackgroundDrawable(drawable); }