blob: 117b126409a3e90a6924f71a5db8c3439204bcf3 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2008 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
Joe Onorato79de0c52010-05-26 17:03:26 -040017package com.android.systemui.statusbar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
19import android.content.Context;
Dianne Hackbornd49258f2010-03-26 00:44:29 -070020import android.content.res.Configuration;
21import android.graphics.Canvas;
22import android.os.SystemClock;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.util.AttributeSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.view.MotionEvent;
25import android.view.View;
26import android.view.ViewGroup;
27import android.view.ViewParent;
28import android.widget.FrameLayout;
29
Joe Onorato79de0c52010-05-26 17:03:26 -040030import com.android.systemui.R;
31
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032public class StatusBarView extends FrameLayout {
33 private static final String TAG = "StatusBarView";
34
Dianne Hackbornd49258f2010-03-26 00:44:29 -070035 static final int DIM_ANIM_TIME = 400;
36
Joe Onorato1c95ecb2010-06-28 17:19:12 -040037 StatusBarService mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038 boolean mTracking;
39 int mStartX, mStartY;
40 ViewGroup mNotificationIcons;
41 ViewGroup mStatusIcons;
42 View mDate;
43 FixedSizeDrawable mBackground;
Dianne Hackbornd49258f2010-03-26 00:44:29 -070044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 public StatusBarView(Context context, AttributeSet attrs) {
46 super(context, attrs);
47 }
48
49 @Override
50 protected void onFinishInflate() {
51 super.onFinishInflate();
52 mNotificationIcons = (ViewGroup)findViewById(R.id.notificationIcons);
53 mStatusIcons = (ViewGroup)findViewById(R.id.statusIcons);
54 mDate = findViewById(R.id.date);
55
56 mBackground = new FixedSizeDrawable(mDate.getBackground());
57 mBackground.setFixedBounds(0, 0, 0, 0);
58 mDate.setBackgroundDrawable(mBackground);
59 }
60
61 @Override
62 protected void onAttachedToWindow() {
63 super.onAttachedToWindow();
64 mService.onBarViewAttached();
65 }
Dianne Hackbornd49258f2010-03-26 00:44:29 -070066
67 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
69 super.onSizeChanged(w, h, oldw, oldh);
Joe Onorato1c95ecb2010-06-28 17:19:12 -040070 mService.updateExpandedViewPos(StatusBarService.EXPANDED_LEAVE_ALONE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 }
72
73 @Override
74 protected void onLayout(boolean changed, int l, int t, int r, int b) {
75 super.onLayout(changed, l, t, r, b);
76
77 // put the date date view quantized to the icons
78 int oldDateRight = mDate.getRight();
79 int newDateRight;
80
81 newDateRight = getDateSize(mNotificationIcons, oldDateRight,
82 getViewOffset(mNotificationIcons));
83 if (newDateRight < 0) {
84 int offset = getViewOffset(mStatusIcons);
85 if (oldDateRight < offset) {
86 newDateRight = oldDateRight;
87 } else {
88 newDateRight = getDateSize(mStatusIcons, oldDateRight, offset);
89 if (newDateRight < 0) {
90 newDateRight = r;
91 }
92 }
93 }
94 int max = r - getPaddingRight();
95 if (newDateRight > max) {
96 newDateRight = max;
97 }
98
99 mDate.layout(mDate.getLeft(), mDate.getTop(), newDateRight, mDate.getBottom());
100 mBackground.setFixedBounds(-mDate.getLeft(), -mDate.getTop(), (r-l), (b-t));
101 }
102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 /**
104 * Gets the left position of v in this view. Throws if v is not
105 * a child of this.
106 */
107 private int getViewOffset(View v) {
108 int offset = 0;
109 while (v != this) {
110 offset += v.getLeft();
111 ViewParent p = v.getParent();
112 if (v instanceof View) {
113 v = (View)p;
114 } else {
115 throw new RuntimeException(v + " is not a child of " + this);
116 }
117 }
118 return offset;
119 }
120
121 private int getDateSize(ViewGroup g, int w, int offset) {
122 final int N = g.getChildCount();
123 for (int i=0; i<N; i++) {
124 View v = g.getChildAt(i);
125 int l = v.getLeft() + offset;
126 int r = v.getRight() + offset;
127 if (w >= l && w <= r) {
128 return r;
129 }
130 }
131 return -1;
132 }
133
134 /**
135 * Ensure that, if there is no target under us to receive the touch,
136 * that we process it ourself. This makes sure that onInterceptTouchEvent()
137 * is always called for the entire gesture.
138 */
139 @Override
140 public boolean onTouchEvent(MotionEvent event) {
141 if (event.getAction() != MotionEvent.ACTION_DOWN) {
142 mService.interceptTouchEvent(event);
143 }
144 return true;
145 }
146
147 @Override
148 public boolean onInterceptTouchEvent(MotionEvent event) {
149 return mService.interceptTouchEvent(event)
150 ? true : super.onInterceptTouchEvent(event);
151 }
152}
153