FloatingActionButtonImpl.java revision be48ed9161c09c4b2178ab6dbe28638222809fc7
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 SHOW_HIDE_ANIM_DURATION = 200;
30
31    static final int[] PRESSED_ENABLED_STATE_SET = {android.R.attr.state_pressed,
32            android.R.attr.state_enabled};
33    static final int[] FOCUSED_ENABLED_STATE_SET = {android.R.attr.state_focused,
34            android.R.attr.state_enabled};
35    static final int[] EMPTY_STATE_SET = new int[0];
36
37    final View mView;
38    final ShadowViewDelegate mShadowViewDelegate;
39
40    FloatingActionButtonImpl(View view, ShadowViewDelegate shadowViewDelegate) {
41        mView = view;
42        mShadowViewDelegate = shadowViewDelegate;
43    }
44
45    abstract void setBackgroundDrawable(Drawable originalBackground, ColorStateList backgroundTint,
46            PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth);
47
48    abstract void setBackgroundTintList(ColorStateList tint);
49
50    abstract void setBackgroundTintMode(PorterDuff.Mode tintMode);
51
52    abstract void setRippleColor(int rippleColor);
53
54    abstract void setElevation(float elevation);
55
56    abstract void setPressedTranslationZ(float translationZ);
57
58    abstract void onDrawableStateChanged(int[] state);
59
60    abstract void jumpDrawableToCurrentState();
61
62    abstract void hide();
63
64    abstract void show();
65
66    Drawable createBorderDrawable(int borderWidth, ColorStateList backgroundTint) {
67        final Resources resources = mView.getResources();
68        CircularBorderDrawable borderDrawable = newCircularDrawable();
69        borderDrawable.setGradientColors(
70                resources.getColor(R.color.fab_stroke_top_outer_color),
71                resources.getColor(R.color.fab_stroke_top_inner_color),
72                resources.getColor(R.color.fab_stroke_end_inner_color),
73                resources.getColor(R.color.fab_stroke_end_outer_color));
74        borderDrawable.setBorderWidth(borderWidth);
75        borderDrawable.setTintColor(backgroundTint.getDefaultColor());
76        return borderDrawable;
77    }
78
79    CircularBorderDrawable newCircularDrawable() {
80        return new CircularBorderDrawable();
81    }
82}
83