1024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek/* 2024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * Copyright (C) 2014 The Android Open Source Project 3024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * 4024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * Licensed under the Apache License, Version 2.0 (the "License"); 5024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * you may not use this file except in compliance with the License. 6024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * You may obtain a copy of the License at 7024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * 8024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * http://www.apache.org/licenses/LICENSE-2.0 9024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * 10024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * Unless required by applicable law or agreed to in writing, software 11024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * distributed under the License is distributed on an "AS IS" BASIS, 12024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * See the License for the specific language governing permissions and 14024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * limitations under the License 15024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek */ 16024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 17024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinekpackage com.android.systemui.statusbar; 18024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 19024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinekimport android.content.Context; 20024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinekimport android.graphics.Canvas; 21024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinekimport android.graphics.drawable.Drawable; 22024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinekimport android.util.AttributeSet; 23024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinekimport android.widget.FrameLayout; 24024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinekimport com.android.systemui.R; 25024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 26024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek/** 27024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek * The guts of a notification revealed when performing a long press. 28024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek */ 29024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinekpublic class NotificationGuts extends FrameLayout { 30024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 31024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek private Drawable mBackground; 32024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek private int mClipTopAmount; 33024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek private int mActualHeight; 34024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 35024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek public NotificationGuts(Context context, AttributeSet attrs) { 36024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek super(context, attrs); 37024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek setWillNotDraw(false); 38024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 39024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 40024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek @Override 41024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek protected void onDraw(Canvas canvas) { 42024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek draw(canvas, mBackground); 43024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 44024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 45024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek private void draw(Canvas canvas, Drawable drawable) { 46024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek if (drawable != null) { 47024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek drawable.setBounds(0, mClipTopAmount, getWidth(), mActualHeight); 48024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek drawable.draw(canvas); 49024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 50024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 51024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 52024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek @Override 53024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek protected void onFinishInflate() { 54024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek super.onFinishInflate(); 55024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek mBackground = mContext.getDrawable(R.drawable.notification_guts_bg); 56024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek if (mBackground != null) { 57024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek mBackground.setCallback(this); 58024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 59024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 60024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 61024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek @Override 62024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek protected boolean verifyDrawable(Drawable who) { 63024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek return super.verifyDrawable(who) || who == mBackground; 64024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 65024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 66024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek @Override 67024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek protected void drawableStateChanged() { 68024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek drawableStateChanged(mBackground); 69024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 70024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 71024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek private void drawableStateChanged(Drawable d) { 72024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek if (d != null && d.isStateful()) { 73024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek d.setState(getDrawableState()); 74024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 75024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 76024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 77024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek @Override 78024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek public void drawableHotspotChanged(float x, float y) { 79024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek if (mBackground != null) { 80024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek mBackground.setHotspot(x, y); 81024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 82024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 83024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 84024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek public void setActualHeight(int actualHeight) { 85024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek mActualHeight = actualHeight; 86024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek invalidate(); 87024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 88024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 89024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek public int getActualHeight() { 90024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek return mActualHeight; 91024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 92024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 93024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek public void setClipTopAmount(int clipTopAmount) { 94024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek mClipTopAmount = clipTopAmount; 95024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek invalidate(); 96024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 97024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 98024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek @Override 99024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek public boolean hasOverlappingRendering() { 100024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek 101024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek // Prevents this view from creating a layer when alpha is animating. 102024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek return false; 103024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek } 104024ca598dd4b38b389251c138f4ef9882d4b68b0Selim Cinek} 105