13322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek/* 23322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * Copyright (C) 2016 The Android Open Source Project 33322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * 43322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * Licensed under the Apache License, Version 2.0 (the "License"); 53322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * you may not use this file except in compliance with the License. 63322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * You may obtain a copy of the License at 73322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * 83322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * http://www.apache.org/licenses/LICENSE-2.0 93322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * 103322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * Unless required by applicable law or agreed to in writing, software 113322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * distributed under the License is distributed on an "AS IS" BASIS, 123322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * See the License for the specific language governing permissions and 143322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * limitations under the License 153322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek */ 163322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek 173322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinekpackage com.android.systemui.statusbar.notification; 183322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek 193322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinekimport android.annotation.Nullable; 203322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinekimport android.content.Context; 213322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinekimport android.graphics.Outline; 223322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinekimport android.util.AttributeSet; 233322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinekimport android.view.View; 243322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinekimport android.view.ViewGroup; 253322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinekimport android.view.ViewOutlineProvider; 263322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinekimport android.widget.LinearLayout; 273322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek 28e4367d60fce814a4d238fc066919693f3852bc09Selim Cinekimport com.android.systemui.R; 293322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinekimport com.android.systemui.statusbar.AlphaOptimizedFrameLayout; 303322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek 313322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek/** 323322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek * A view used to cast a shadow of a certain size on another view 333322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek */ 343322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinekpublic class FakeShadowView extends AlphaOptimizedFrameLayout { 353322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek public static final float SHADOW_SIBLING_TRESHOLD = 0.1f; 36e4367d60fce814a4d238fc066919693f3852bc09Selim Cinek private final int mShadowMinHeight; 373322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek 383322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek private View mFakeShadow; 393322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek private float mOutlineAlpha; 403322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek 413322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek public FakeShadowView(Context context) { 423322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek this(context, null); 433322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek } 443322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek 453322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek public FakeShadowView(Context context, @Nullable AttributeSet attrs) { 463322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek this(context, attrs, 0); 473322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek } 483322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek 493322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek public FakeShadowView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 503322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek this(context, attrs, defStyleAttr, 0); 513322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek } 523322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek 533322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek public FakeShadowView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, 543322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek int defStyleRes) { 553322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek super(context, attrs, defStyleAttr, defStyleRes); 563322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek mFakeShadow = new View(context); 573322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek mFakeShadow.setVisibility(INVISIBLE); 583322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek mFakeShadow.setLayoutParams(new LinearLayout.LayoutParams( 593322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek ViewGroup.LayoutParams.MATCH_PARENT, 603322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek (int) (48 * getResources().getDisplayMetrics().density))); 613322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek mFakeShadow.setOutlineProvider(new ViewOutlineProvider() { 623322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek @Override 633322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek public void getOutline(View view, Outline outline) { 643322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek outline.setRect(0, 0, getWidth(), mFakeShadow.getHeight()); 653322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek outline.setAlpha(mOutlineAlpha); 663322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek } 673322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek }); 683322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek addView(mFakeShadow); 69e4367d60fce814a4d238fc066919693f3852bc09Selim Cinek mShadowMinHeight = Math.max(1, context.getResources() 70e4367d60fce814a4d238fc066919693f3852bc09Selim Cinek .getDimensionPixelSize(R.dimen.notification_divider_height)); 713322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek } 723322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek 733322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek public void setFakeShadowTranslationZ(float fakeShadowTranslationZ, float outlineAlpha, 743322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek int shadowYEnd, int outlineTranslation) { 753322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek if (fakeShadowTranslationZ == 0.0f) { 763322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek mFakeShadow.setVisibility(INVISIBLE); 773322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek } else { 783322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek mFakeShadow.setVisibility(VISIBLE); 79e4367d60fce814a4d238fc066919693f3852bc09Selim Cinek fakeShadowTranslationZ = Math.max(mShadowMinHeight, fakeShadowTranslationZ); 803322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek mFakeShadow.setTranslationZ(fakeShadowTranslationZ); 813322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek mFakeShadow.setTranslationX(outlineTranslation); 823322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek mFakeShadow.setTranslationY(shadowYEnd - mFakeShadow.getHeight()); 833322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek if (outlineAlpha != mOutlineAlpha) { 843322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek mOutlineAlpha = outlineAlpha; 853322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek mFakeShadow.invalidateOutline(); 863322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek } 873322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek } 883322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek } 893322357b5045fdcc3e3b04c65219d39ce1ae441fSelim Cinek} 90