StatusBarHeaderView.java revision d7daab7b9e33cd56f2692b9ebea87ef21290c1ea
1/* 2 * Copyright (C) 2014 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 com.android.systemui.statusbar.phone; 18 19import android.content.Context; 20import android.util.AttributeSet; 21import android.view.View; 22import android.view.ViewGroup; 23import android.widget.LinearLayout; 24import android.widget.RelativeLayout; 25 26import com.android.systemui.R; 27 28/** 29 * The view to manage the header area in the expanded status bar. 30 */ 31public class StatusBarHeaderView extends RelativeLayout { 32 33 private boolean mExpanded; 34 private View mBackground; 35 private View mFlipper; 36 37 private int mCollapsedHeight; 38 private int mExpandedHeight; 39 40 public StatusBarHeaderView(Context context, AttributeSet attrs) { 41 super(context, attrs); 42 } 43 44 @Override 45 protected void onFinishInflate() { 46 super.onFinishInflate(); 47 mBackground = findViewById(R.id.background); 48 mFlipper = findViewById(R.id.header_flipper); 49 loadDimens(); 50 } 51 52 private void loadDimens() { 53 mCollapsedHeight = getResources().getDimensionPixelSize( 54 R.dimen.status_bar_header_height); 55 mExpandedHeight = getResources().getDimensionPixelSize( 56 R.dimen.status_bar_header_height_expanded); 57 } 58 59 public int getCollapsedHeight() { 60 return mCollapsedHeight; 61 } 62 63 public int getExpandedHeight() { 64 return mExpandedHeight; 65 } 66 67 public void setExpanded(boolean expanded) { 68 if (expanded != mExpanded) { 69 ViewGroup.LayoutParams lp = getLayoutParams(); 70 lp.height = expanded ? mExpandedHeight : mCollapsedHeight; 71 setLayoutParams(lp); 72 mExpanded = expanded; 73 } 74 } 75 76 public void setExpansionEnabled(boolean enabled) { 77 mFlipper.setVisibility(enabled ? View.VISIBLE : View.GONE); 78 } 79 80 public void setExpansion(float height) { 81 if (height < mCollapsedHeight) { 82 height = mCollapsedHeight; 83 } 84 if (height > mExpandedHeight) { 85 height = mExpandedHeight; 86 } 87 if (mExpanded) { 88 mBackground.setTranslationY(-(mExpandedHeight - height)); 89 } else { 90 mBackground.setTranslationY(0); 91 } 92 } 93 94 public View getBackgroundView() { 95 return mBackground; 96 } 97} 98