blob: 0640282422d9dbf220028e298bbb5db60b87bd60 [file] [log] [blame]
Joe Onorato503007d2010-04-16 09:20:55 -07001/*
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 Onoratofd52b182010-11-10 18:00:52 -080017package com.android.systemui.statusbar.phone;
Joe Onorato503007d2010-04-16 09:20:55 -070018
19import android.content.Context;
20import android.os.Handler;
21import android.util.AttributeSet;
Joe Onoratob77f53b2010-05-28 19:59:51 -040022import android.util.Slog;
Joe Onorato503007d2010-04-16 09:20:55 -070023import android.view.View;
24import android.widget.LinearLayout;
25
Joe Onorato6c01a112010-10-04 17:38:47 -040026import com.android.internal.statusbar.StatusBarIcon;
27
Joe Onoratob77f53b2010-05-28 19:59:51 -040028import com.android.systemui.R;
Joe Onoratofd52b182010-11-10 18:00:52 -080029import com.android.systemui.statusbar.StatusBarIconView;
Joe Onoratob77f53b2010-05-28 19:59:51 -040030
Joe Onorato503007d2010-04-16 09:20:55 -070031public class IconMerger extends LinearLayout {
Joe Onoratob77f53b2010-05-28 19:59:51 -040032 private static final String TAG = "IconMerger";
Daniel Sandler05e24142011-11-10 11:56:49 -050033 private static final boolean DEBUG = false;
Joe Onoratob77f53b2010-05-28 19:59:51 -040034
Joe Onorato6c01a112010-10-04 17:38:47 -040035 private int mIconSize;
Daniel Sandler05e24142011-11-10 11:56:49 -050036 private View mMoreView;
Joe Onorato503007d2010-04-16 09:20:55 -070037
38 public IconMerger(Context context, AttributeSet attrs) {
39 super(context, attrs);
Joe Onorato6c01a112010-10-04 17:38:47 -040040
41 mIconSize = context.getResources().getDimensionPixelSize(
Daniel Sandler05e24142011-11-10 11:56:49 -050042 R.dimen.status_bar_icon_size);
Joe Onorato6c01a112010-10-04 17:38:47 -040043
Daniel Sandler05e24142011-11-10 11:56:49 -050044 if (DEBUG) {
45 setBackgroundColor(0x800099FF);
46 }
Daniel Sandler7c3e39d2011-07-29 16:30:49 -040047 }
48
Daniel Sandler05e24142011-11-10 11:56:49 -050049 public void setOverflowIndicator(View v) {
50 mMoreView = v;
Joe Onorato503007d2010-04-16 09:20:55 -070051 }
52
Daniel Sandler05e24142011-11-10 11:56:49 -050053 @Override
54 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
55 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
56 // we need to constrain this to an integral multiple of our children
57 int width = getMeasuredWidth();
58 setMeasuredDimension(width - (width % mIconSize), getMeasuredHeight());
Joe Onoratob77f53b2010-05-28 19:59:51 -040059 }
60
Joe Onorato503007d2010-04-16 09:20:55 -070061 @Override
62 protected void onLayout(boolean changed, int l, int t, int r, int b) {
63 super.onLayout(changed, l, t, r, b);
Daniel Sandler05e24142011-11-10 11:56:49 -050064 checkOverflow(r - l);
65 }
Joe Onorato503007d2010-04-16 09:20:55 -070066
Daniel Sandler05e24142011-11-10 11:56:49 -050067 private void checkOverflow(int width) {
68 if (mMoreView == null) return;
69
Joe Onorato503007d2010-04-16 09:20:55 -070070 final int N = getChildCount();
Daniel Sandler05e24142011-11-10 11:56:49 -050071 int visibleChildren = 0;
72 for (int i=0; i<N; i++) {
73 if (getChildAt(i).getVisibility() != GONE) visibleChildren++;
Joe Onorato503007d2010-04-16 09:20:55 -070074 }
Daniel Sandler05e24142011-11-10 11:56:49 -050075 final boolean overflowShown = (mMoreView.getVisibility() == View.VISIBLE);
76 // let's assume we have one more slot if the more icon is already showing
77 if (overflowShown) visibleChildren --;
78 final boolean moreRequired = visibleChildren * mIconSize > width;
79 if (moreRequired != overflowShown) {
80 post(new Runnable() {
81 @Override
82 public void run() {
83 mMoreView.setVisibility(moreRequired ? View.VISIBLE : View.GONE);
Joe Onorato503007d2010-04-16 09:20:55 -070084 }
Daniel Sandler05e24142011-11-10 11:56:49 -050085 });
Joe Onorato503007d2010-04-16 09:20:55 -070086 }
Joe Onorato6c01a112010-10-04 17:38:47 -040087 }
Joe Onorato503007d2010-04-16 09:20:55 -070088}