diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2017-06-23 10:36:27 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2017-06-23 10:37:25 -0700 |
commit | 9314b7c01d932093c730dd39b9b9842d1a56efdb (patch) | |
tree | 0180f3d5bd6c901476d85529fe559f69fbceb612 /src/com/android/launcher3/views | |
parent | a9d721df781bf4d195eb52bba1f9a3193f7eaad4 (diff) | |
download | android_packages_apps_Trebuchet-9314b7c01d932093c730dd39b9b9842d1a56efdb.tar.gz android_packages_apps_Trebuchet-9314b7c01d932093c730dd39b9b9842d1a56efdb.tar.bz2 android_packages_apps_Trebuchet-9314b7c01d932093c730dd39b9b9842d1a56efdb.zip |
Separating double shadow logic for BubbleTextView in a separate subclass
This allows better customization and reuse of the double shadow logic and simplified
various attribute management
Change-Id: I5e277d8399756385452d8bb8c0a0107234a76d34
Diffstat (limited to 'src/com/android/launcher3/views')
-rw-r--r-- | src/com/android/launcher3/views/DoubleShadowBubbleTextView.java | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/com/android/launcher3/views/DoubleShadowBubbleTextView.java b/src/com/android/launcher3/views/DoubleShadowBubbleTextView.java new file mode 100644 index 000000000..9c8457afc --- /dev/null +++ b/src/com/android/launcher3/views/DoubleShadowBubbleTextView.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.views; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Region; +import android.util.AttributeSet; + +import com.android.launcher3.BubbleTextView; +import com.android.launcher3.R; + +/** + * Extension of {@link BubbleTextView} which draws two shadows on the text (ambient and key shadows} + */ +public class DoubleShadowBubbleTextView extends BubbleTextView { + + private final ShadowInfo mShadowInfo; + + public DoubleShadowBubbleTextView(Context context) { + this(context, null); + } + + public DoubleShadowBubbleTextView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public DoubleShadowBubbleTextView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + mShadowInfo = new ShadowInfo(context, attrs, defStyle); + setShadowLayer(mShadowInfo.ambientShadowBlur, 0, 0, mShadowInfo.ambientShadowColor); + } + @Override + public void onDraw(Canvas canvas) { + // If text is transparent, don't draw any shadow + if ((getCurrentTextColor() >> 24) == 0) { + getPaint().clearShadowLayer(); + super.onDraw(canvas); + return; + } + + // We enhance the shadow by drawing the shadow twice + getPaint().setShadowLayer( + mShadowInfo.ambientShadowBlur, 0, 0, mShadowInfo.ambientShadowColor); + + drawWithoutBadge(canvas); + canvas.save(Canvas.CLIP_SAVE_FLAG); + canvas.clipRect(getScrollX(), getScrollY() + getExtendedPaddingTop(), + getScrollX() + getWidth(), + getScrollY() + getHeight(), Region.Op.INTERSECT); + + getPaint().setShadowLayer(mShadowInfo.keyShadowBlur, 0.0f, + mShadowInfo.keyShadowOffset, mShadowInfo.keyShadowColor); + drawWithoutBadge(canvas); + canvas.restore(); + + drawBadgeIfNecessary(canvas); + } + + public static class ShadowInfo { + public final float ambientShadowBlur; + public final int ambientShadowColor; + + public final float keyShadowBlur; + public final float keyShadowOffset; + public final int keyShadowColor; + + public ShadowInfo(Context c, AttributeSet attrs, int defStyle) { + + TypedArray a = c.obtainStyledAttributes( + attrs, R.styleable.ShadowInfo, defStyle, 0); + + ambientShadowBlur = a.getDimension(R.styleable.ShadowInfo_ambientShadowBlur, 0); + ambientShadowColor = a.getColor(R.styleable.ShadowInfo_ambientShadowColor, 0); + + keyShadowBlur = a.getDimension(R.styleable.ShadowInfo_keyShadowBlur, 0); + keyShadowOffset = a.getDimension(R.styleable.ShadowInfo_keyShadowOffset, 0); + keyShadowColor = a.getColor(R.styleable.ShadowInfo_keyShadowColor, 0); + a.recycle(); + } + } +} |