PanelBar.java revision 08d05e3d1d6ade6924266296033981a96b47d5fb
1package com.android.systemui.statusbar.phone; 2 3import java.util.ArrayList; 4 5import android.content.Context; 6import android.util.AttributeSet; 7import android.util.Slog; 8import android.view.MotionEvent; 9import android.widget.FrameLayout; 10 11public class PanelBar extends FrameLayout { 12 public static final boolean DEBUG = true; 13 public static final String TAG = PanelView.class.getSimpleName(); 14 public static final void LOG(String fmt, Object... args) { 15 if (!DEBUG) return; 16 Slog.v(TAG, String.format(fmt, args)); 17 } 18 19 private PanelHolder mPanelHolder; 20 private ArrayList<PanelView> mPanels = new ArrayList<PanelView>(); 21 private PanelView mTouchingPanel; 22 23 public PanelBar(Context context, AttributeSet attrs) { 24 super(context, attrs); 25 } 26 27 @Override 28 protected void onFinishInflate() { 29 super.onFinishInflate(); 30 } 31 32 public void addPanel(PanelView pv) { 33 mPanels.add(pv); 34 pv.setBar(this); 35 } 36 37 public void setPanelHolder(PanelHolder ph) { 38 if (ph == null) { 39 Slog.e(TAG, "setPanelHolder: null PanelHolder", new Throwable()); 40 return; 41 } 42 ph.setBar(this); 43 mPanelHolder = ph; 44 final int N = ph.getChildCount(); 45 for (int i=0; i<N; i++) { 46 final PanelView v = (PanelView) ph.getChildAt(i); 47 if (v != null) { 48 addPanel(v); 49 } 50 } 51 } 52 53 public float getBarHeight() { 54 return getMeasuredHeight(); 55 } 56 57 @Override 58 public boolean onTouchEvent(MotionEvent event) { 59 // figure out which panel needs to be talked to here 60 if (event.getAction() == MotionEvent.ACTION_DOWN) { 61 final int N = mPanels.size(); 62 final int i = (int)(N * event.getX() / getMeasuredWidth()); 63 mTouchingPanel = mPanels.get(i); 64 mPanelHolder.setSelectedPanel(mTouchingPanel); 65 LOG("PanelBar.onTouch: ACTION_DOWN: panel %d", i); 66 onPanelPeeked(); 67 } 68 final boolean result = mTouchingPanel.getHandle().dispatchTouchEvent(event); 69 return result; 70 } 71 72 public void panelExpansionChanged(PanelView panel, float frac) { 73 boolean fullyClosed = true; 74 boolean fullyOpened = false; 75 for (PanelView pv : mPanels) { 76 if (pv.getExpandedHeight() > 0f) { 77 fullyClosed = false; 78 final float thisFrac = pv.getExpandedFraction(); 79 LOG("panel %s: f=%.1f", pv, thisFrac); 80 if (panel == pv) { 81 if (thisFrac == 1f) fullyOpened = true; 82 } else { 83 pv.setExpandedFraction(1f-frac); 84 } 85 } 86 } 87 if (fullyOpened) onPanelFullyOpened(); 88 if (fullyClosed) onAllPanelsCollapsed(); 89 else onPanelPeeked(); 90 91 LOG("panelExpansionChanged: [%s%s ]", fullyOpened?" fullyOpened":"", fullyClosed?" fullyClosed":""); 92 } 93 94 public void collapseAllPanels(boolean animate) { 95 for (PanelView pv : mPanels) { 96 if (animate && pv == mTouchingPanel) { 97 mTouchingPanel.collapse(); 98 } else { 99 pv.setExpandedFraction(0); // just in case 100 } 101 } 102 } 103 104 public void onPanelPeeked() { 105 LOG("onPanelPeeked"); 106 } 107 108 public void onAllPanelsCollapsed() { 109 LOG("onAllPanelsCollapsed"); 110 } 111 112 public void onPanelFullyOpened() { 113 LOG("onPanelFullyOpened"); 114 } 115} 116