/* * Copyright (C) 2012 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.systemui.statusbar.phone; import android.app.StatusBarManager; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewRootImpl; import android.widget.FrameLayout; import com.android.systemui.R; import com.android.systemui.statusbar.BaseStatusBar; import com.android.systemui.statusbar.DragDownHelper; import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; public class StatusBarWindowView extends FrameLayout { public static final String TAG = "StatusBarWindowView"; public static final boolean DEBUG = BaseStatusBar.DEBUG; private DragDownHelper mDragDownHelper; private NotificationStackScrollLayout mStackScrollLayout; private NotificationPanelView mNotificationPanel; private View mBrightnessMirror; PhoneStatusBar mService; public StatusBarWindowView(Context context, AttributeSet attrs) { super(context, attrs); setMotionEventSplittingEnabled(false); setWillNotDraw(!DEBUG); } @Override protected boolean fitSystemWindows(Rect insets) { if (getFitsSystemWindows()) { setPadding(insets.left, insets.top, insets.right, 0); insets.left = 0; insets.top = 0; insets.right = 0; } else { setPadding(0, 0, 0, 0); } return false; } @Override protected void onAttachedToWindow () { super.onAttachedToWindow(); mStackScrollLayout = (NotificationStackScrollLayout) findViewById( R.id.notification_stack_scroller); mNotificationPanel = (NotificationPanelView) findViewById(R.id.notification_panel); mDragDownHelper = new DragDownHelper(getContext(), this, mStackScrollLayout, mService); mBrightnessMirror = findViewById(R.id.brightness_mirror); // We really need to be able to animate while window animations are going on // so that activities may be started asynchronously from panel animations final ViewRootImpl root = getViewRootImpl(); if (root != null) { root.setDrawDuringWindowsAnimating(true); } } @Override public boolean dispatchKeyEvent(KeyEvent event) { boolean down = event.getAction() == KeyEvent.ACTION_DOWN; switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: if (!down) { mService.onBackPressed(); } return true; case KeyEvent.KEYCODE_MENU: if (!down) { return mService.onMenuPressed(); } case KeyEvent.KEYCODE_SPACE: if (!down) { return mService.onSpacePressed(); } case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_UP: if (down) { mService.wakeUpIfDozing(event.getEventTime()); } } if (mService.interceptMediaKey(event)) { return true; } return super.dispatchKeyEvent(event); } @Override public boolean dispatchTouchEvent(MotionEvent ev) { if (mBrightnessMirror != null && mBrightnessMirror.getVisibility() == VISIBLE) { // Disallow new pointers while the brightness mirror is visible. This is so that you // can't touch anything other than the brightness slider while the mirror is showing // and the rest of the panel is transparent. if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) { return false; } } return super.dispatchTouchEvent(ev); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { boolean intercept = false; if (mNotificationPanel.isFullyExpanded() && mStackScrollLayout.getVisibility() == View.VISIBLE && mService.getBarState() == StatusBarState.KEYGUARD && !mService.isBouncerShowing()) { intercept = mDragDownHelper.onInterceptTouchEvent(ev); // wake up on a touch down event, if dozing if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) { mService.wakeUpIfDozing(ev.getEventTime()); } } if (!intercept) { super.onInterceptTouchEvent(ev); } if (intercept) { MotionEvent cancellation = MotionEvent.obtain(ev); cancellation.setAction(MotionEvent.ACTION_CANCEL); mStackScrollLayout.onInterceptTouchEvent(cancellation); mNotificationPanel.onInterceptTouchEvent(cancellation); cancellation.recycle(); } return intercept; } @Override public boolean onTouchEvent(MotionEvent ev) { boolean handled = false; if (mService.getBarState() == StatusBarState.KEYGUARD && !mService.isQsExpanded()) { handled = mDragDownHelper.onTouchEvent(ev); } if (!handled) { handled = super.onTouchEvent(ev); } final int action = ev.getAction(); if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) { mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false); } return handled; } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (DEBUG) { Paint pt = new Paint(); pt.setColor(0x80FFFF00); pt.setStrokeWidth(12.0f); pt.setStyle(Paint.Style.STROKE); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt); } } public void cancelExpandHelper() { if (mStackScrollLayout != null) { mStackScrollLayout.cancelExpandHelper(); } } }