/* * Copyright (C) 2010 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.tablet; import java.util.Arrays; import android.animation.LayoutTransition; import android.app.Notification; import android.app.PendingIntent; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.PixelFormat; import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.util.Slog; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.view.WindowManagerImpl; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.FrameLayout; import android.widget.TextView; import com.android.internal.statusbar.StatusBarIcon; import com.android.internal.statusbar.StatusBarNotification; import com.android.systemui.R; import com.android.systemui.statusbar.StatusBarIconView; public class TabletTicker extends Handler implements LayoutTransition.TransitionListener { private static final String TAG = "StatusBar.TabletTicker"; private static final boolean CLICKABLE_TICKER = true; // 3 is enough to let us see most cases, but not get so far behind that it's too annoying. private static final int QUEUE_LENGTH = 3; private static final int MSG_ADVANCE = 1; private static final int ADVANCE_DELAY = 5000; // 5 seconds private Context mContext; private ViewGroup mWindow; private IBinder mCurrentKey; private StatusBarNotification mCurrentNotification; private View mCurrentView; private IBinder[] mKeys = new IBinder[QUEUE_LENGTH]; private StatusBarNotification[] mQueue = new StatusBarNotification[QUEUE_LENGTH]; private int mQueuePos; private final int mLargeIconHeight; private TabletStatusBar mBar; private LayoutTransition mLayoutTransition; private boolean mWindowShouldClose; public TabletTicker(TabletStatusBar bar) { mBar = bar; mContext = bar.getContext(); final Resources res = mContext.getResources(); mLargeIconHeight = res.getDimensionPixelSize( android.R.dimen.notification_large_icon_height); } public void add(IBinder key, StatusBarNotification notification) { if (false) { Slog.d(TAG, "add 1 mCurrentNotification=" + mCurrentNotification + " mQueuePos=" + mQueuePos + " mQueue=" + Arrays.toString(mQueue)); } // If it's already in here, remove whatever's in there and put the new one at the end. remove(key, false); mKeys[mQueuePos] = key; mQueue[mQueuePos] = notification; // If nothing is running now, start the next one. if (mQueuePos == 0 && mCurrentNotification == null) { sendEmptyMessage(MSG_ADVANCE); } if (mQueuePos < QUEUE_LENGTH - 1) { mQueuePos++; } } public void remove(IBinder key) { remove(key, true); } public void remove(IBinder key, boolean advance) { if (mCurrentKey == key) { // Showing now if (advance) { removeMessages(MSG_ADVANCE); sendEmptyMessage(MSG_ADVANCE); } } else { // In the queue for (int i=0; i 0) { mQueuePos--; } break; } } } } public void halt() { removeMessages(MSG_ADVANCE); if (mCurrentView != null || mQueuePos != 0) { for (int i=0; i