FloatingActionButtonImpl.java revision 092f4b4fc5610ed1a2c4f5108066726ee59d8f16
1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.support.design.widget; 18 19import android.content.res.ColorStateList; 20import android.content.res.Resources; 21import android.graphics.PorterDuff; 22import android.graphics.drawable.Drawable; 23import android.support.design.R; 24import android.support.v4.graphics.drawable.DrawableCompat; 25import android.view.View; 26 27abstract class FloatingActionButtonImpl { 28 29 static final int[] PRESSED_ENABLED_STATE_SET = {android.R.attr.state_pressed, 30 android.R.attr.state_enabled}; 31 static final int[] FOCUSED_ENABLED_STATE_SET = {android.R.attr.state_focused, 32 android.R.attr.state_enabled}; 33 static final int[] EMPTY_STATE_SET = new int[0]; 34 35 final View mView; 36 final ShadowViewDelegate mShadowViewDelegate; 37 38 FloatingActionButtonImpl(View view, ShadowViewDelegate shadowViewDelegate) { 39 mView = view; 40 mShadowViewDelegate = shadowViewDelegate; 41 } 42 43 abstract void setBackgroundDrawable(Drawable originalBackground, ColorStateList backgroundTint, 44 PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth); 45 46 abstract void setBackgroundTintList(ColorStateList tint); 47 48 abstract void setBackgroundTintMode(PorterDuff.Mode tintMode); 49 50 abstract void setRippleColor(int rippleColor); 51 52 abstract void setElevation(float elevation); 53 54 abstract void setPressedTranslationZ(float translationZ); 55 56 abstract void onDrawableStateChanged(int[] state); 57 58 abstract void jumpDrawableToCurrentState(); 59 60 Drawable createBorderDrawable(int borderWidth, ColorStateList backgroundTint) { 61 final Resources resources = mView.getResources(); 62 CircularBorderDrawable borderDrawable = newCircularDrawable(); 63 borderDrawable.setGradientColors( 64 resources.getColor(R.color.fab_stroke_top_outer_color), 65 resources.getColor(R.color.fab_stroke_top_inner_color), 66 resources.getColor(R.color.fab_stroke_end_inner_color), 67 resources.getColor(R.color.fab_stroke_end_outer_color)); 68 borderDrawable.setBorderWidth(borderWidth); 69 borderDrawable.setTintColor(backgroundTint.getDefaultColor()); 70 return borderDrawable; 71 } 72 73 CircularBorderDrawable newCircularDrawable() { 74 return new CircularBorderDrawable(); 75 } 76} 77