private void init(Context context, AttributeSet attrs, int defStyleAttr) { TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, 0); mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, 0xFFDA4336); mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, 0xFFE75043); mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, 0xFFAAAAAA); mColorRipple = attr.getColor(R.styleable.FloatingActionButton_fab_colorRipple, 0x99FFFFFF); mShowShadow = attr.getBoolean(R.styleable.FloatingActionButton_fab_showShadow, true); mShadowColor = attr.getColor(R.styleable.FloatingActionButton_fab_shadowColor, 0x66000000); mShadowRadius = attr.getDimensionPixelSize( R.styleable.FloatingActionButton_fab_shadowRadius, mShadowRadius); mShadowXOffset = attr.getDimensionPixelSize( R.styleable.FloatingActionButton_fab_shadowXOffset, mShadowXOffset); mShadowYOffset = attr.getDimensionPixelSize( R.styleable.FloatingActionButton_fab_shadowYOffset, mShadowYOffset); mFabSize = attr.getInt(R.styleable.FloatingActionButton_fab_size, SIZE_NORMAL); mLabelText = attr.getString(R.styleable.FloatingActionButton_fab_label); mShouldProgressIndeterminate = attr.getBoolean(R.styleable.FloatingActionButton_fab_progress_indeterminate, false); mProgressColor = attr.getColor(R.styleable.FloatingActionButton_fab_progress_color, 0xFF009688); mProgressBackgroundColor = attr.getColor(R.styleable.FloatingActionButton_fab_progress_backgroundColor, 0x4D000000); mProgressMax = attr.getInt(R.styleable.FloatingActionButton_fab_progress_max, mProgressMax); mShowProgressBackground = attr.getBoolean(R.styleable.FloatingActionButton_fab_progress_showBackground, true); if (attr.hasValue(R.styleable.FloatingActionButton_fab_progress)) { mProgress = attr.getInt(R.styleable.FloatingActionButton_fab_progress, 0); mShouldSetProgress = true; } if (attr.hasValue(R.styleable.FloatingActionButton_fab_elevationCompat)) { float elevation = attr.getDimensionPixelOffset(R.styleable.FloatingActionButton_fab_elevationCompat, 0); if (isInEditMode()) { setElevation(elevation); } else { setElevationCompat(elevation); } } initShowAnimation(attr); initHideAnimation(attr); attr.recycle(); if (isInEditMode()) { if (mShouldProgressIndeterminate) { setIndeterminate(true); } else if (mShouldSetProgress) { saveButtonOriginalPosition(); setProgress(mProgress, false); } } // updateBackground(); setClickable(true); }
/** * Change the indeterminate mode for the progress bar. In indeterminate mode, the progress is * ignored and the progress bar shows an infinite animation instead. * * @param indeterminate true to enable the indeterminate mode */ public synchronized void setIndeterminate(boolean indeterminate) { if (!indeterminate) { mCurrentProgress = 0.0f; } mProgressBarEnabled = indeterminate; mShouldUpdateButtonPosition = true; mProgressIndeterminate = indeterminate; mLastTimeAnimated = SystemClock.uptimeMillis(); setupProgressBounds(); saveButtonOriginalPosition(); updateBackground(); }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { saveButtonOriginalPosition(); if (mShouldProgressIndeterminate) { setIndeterminate(true); mShouldProgressIndeterminate = false; } else if (mShouldSetProgress) { setProgress(mProgress, mAnimateProgress); mShouldSetProgress = false; } else if (mShouldUpdateButtonPosition) { updateButtonPosition(); mShouldUpdateButtonPosition = false; } super.onSizeChanged(w, h, oldw, oldh); setupProgressBounds(); setupProgressBarPaints(); updateBackground(); }
public synchronized void setProgress(int progress, boolean animate) { if (mProgressIndeterminate) return; mProgress = progress; mAnimateProgress = animate; if (!mButtonPositionSaved) { mShouldSetProgress = true; return; } mProgressBarEnabled = true; mShouldUpdateButtonPosition = true; setupProgressBounds(); saveButtonOriginalPosition(); updateBackground(); if (progress < 0) { progress = 0; } else if (progress > mProgressMax) { progress = mProgressMax; } if (progress == mTargetProgress) { return; } mTargetProgress = mProgressMax > 0 ? (progress / (float) mProgressMax) * 360 : 0; mLastTimeAnimated = SystemClock.uptimeMillis(); if (!animate) { mCurrentProgress = mTargetProgress; } invalidate(); }