diff options
6 files changed, 289 insertions, 21 deletions
diff --git a/packages/SystemUI/res/drawable-mdpi/sysbar_panel_recents_bg.9.png b/packages/SystemUI/res/drawable-mdpi/sysbar_panel_recents_bg.9.png Binary files differnew file mode 100644 index 0000000..85726d2 --- /dev/null +++ b/packages/SystemUI/res/drawable-mdpi/sysbar_panel_recents_bg.9.png diff --git a/packages/SystemUI/res/layout-xlarge/status_bar.xml b/packages/SystemUI/res/layout-xlarge/status_bar.xml index 429fdf2..dbe4167 100644 --- a/packages/SystemUI/res/layout-xlarge/status_bar.xml +++ b/packages/SystemUI/res/layout-xlarge/status_bar.xml @@ -146,7 +146,7 @@ android:background="@drawable/ic_sysbar_icon_bg" systemui:keyCode="3" /> - <ImageButton android:id="@+id/recent" + <ImageButton android:id="@+id/recent_apps" android:layout_width="wrap_content" android:layout_height="match_parent" android:src="@drawable/ic_sysbar_recent" diff --git a/packages/SystemUI/res/layout-xlarge/sysbar_panel_recent.xml b/packages/SystemUI/res/layout-xlarge/sysbar_panel_recent.xml new file mode 100644 index 0000000..2f9e0d7 --- /dev/null +++ b/packages/SystemUI/res/layout-xlarge/sysbar_panel_recent.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* apps/common/assets/default/default/skins/StatusBar.xml +** +** Copyright 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. +*/ +--> + +<com.android.systemui.statusbar.tablet.RecentAppsPanel + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:background="@drawable/sysbar_panel_recents_bg" + android:orientation="vertical"> + + <TextView android:id="@+id/recents_no_recents" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:text="@string/recent_tasks_empty" + android:gravity="center_horizontal|center_vertical" + android:visibility="gone"> + </TextView> + + <HorizontalScrollView android:id="@+id/scroll_view" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + + <LinearLayout android:id="@+id/recents_container" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:gravity="right" + android:orientation="horizontal" + /> + + </HorizontalScrollView> + +</com.android.systemui.statusbar.tablet.RecentAppsPanel> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/RecentAppsPanel.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/RecentAppsPanel.java new file mode 100644 index 0000000..6797958 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/RecentAppsPanel.java @@ -0,0 +1,167 @@ +/* + * 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.ArrayList; +import java.util.List; + +import android.app.ActivityManager; +import android.bluetooth.BluetoothAdapter; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.content.res.TypedArray; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.media.AudioManager; +import android.net.wifi.WifiManager; +import android.util.AttributeSet; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.view.View.OnClickListener; +import android.widget.BaseAdapter; +import android.widget.Gallery; +import android.widget.HorizontalScrollView; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import com.android.systemui.R; + +public class RecentAppsPanel extends LinearLayout implements StatusBarPanel, OnClickListener { + private static final String TAG = "RecentAppsPanel"; + private static final boolean DEBUG = TabletStatusBarService.DEBUG; + private static final int MAX_RECENT_TASKS = 20; + private static final float ITEM_WIDTH = 75; + private static final float ITEM_HEIGHT = 75; + private TabletStatusBarService mBar; + private TextView mNoRecents; + private LinearLayout mRecentsContainer; + private float mDensity; + private HorizontalScrollView mScrollView; + + public boolean isInContentArea(int x, int y) { + final int l = getPaddingLeft(); + final int r = getWidth() - getPaddingRight(); + final int t = getPaddingTop(); + final int b = getHeight() - getPaddingBottom(); + return x >= l && x < r && y >= t && y < b; + } + + public void setBar(TabletStatusBarService bar) { + mBar = bar; + } + + public RecentAppsPanel(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public RecentAppsPanel(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + mDensity = getResources().getDisplayMetrics().density; + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + mNoRecents = (TextView) findViewById(R.id.recents_no_recents); + mRecentsContainer = (LinearLayout) findViewById(R.id.recents_container); + mScrollView = (HorizontalScrollView) findViewById(R.id.scroll_view); + mScrollView.setHorizontalFadingEdgeEnabled(true); + } + + @Override + protected void onVisibilityChanged(View changedView, int visibility) { + super.onVisibilityChanged(changedView, visibility); + Log.v(TAG, "onVisibilityChanged(" + changedView + ", " + visibility + ")"); + if (visibility == View.VISIBLE && changedView == this) { + refreshIcons(); + mRecentsContainer.setScrollbarFadingEnabled(true); + mRecentsContainer.scrollTo(0, 0); + } + } + + private void refreshIcons() { + mRecentsContainer.removeAllViews(); + final Context context = getContext(); + final PackageManager pm = context.getPackageManager(); + final ActivityManager am = (ActivityManager) + context.getSystemService(Context.ACTIVITY_SERVICE); + final List<ActivityManager.RecentTaskInfo> recentTasks = + am.getRecentTasks(MAX_RECENT_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE); + + ActivityInfo homeInfo = new Intent(Intent.ACTION_MAIN) + .addCategory(Intent.CATEGORY_HOME) + .resolveActivityInfo(pm, 0); + + int numTasks = recentTasks.size(); + final int width = (int) (mDensity * ITEM_WIDTH + 0.5f); + final int height = (int) (mDensity * ITEM_HEIGHT + 0.5f); + ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(width, height); + for (int i = 0; i < numTasks; ++i) { + final ActivityManager.RecentTaskInfo info = recentTasks.get(i); + + Intent intent = new Intent(info.baseIntent); + if (info.origActivity != null) { + intent.setComponent(info.origActivity); + } + + // Exclude home activity. + if (homeInfo != null + && homeInfo.packageName.equals(intent.getComponent().getPackageName()) + && homeInfo.name.equals(intent.getComponent().getClassName())) { + continue; + } + + intent.setFlags((intent.getFlags()&~Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) + | Intent.FLAG_ACTIVITY_NEW_TASK); + final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0); + if (resolveInfo != null) { + final ActivityInfo activityInfo = resolveInfo.activityInfo; + final String title = activityInfo.loadLabel(pm).toString(); + Drawable icon = activityInfo.loadIcon(pm); + + if (title != null && title.length() > 0 && icon != null) { + ImageView imageView = new ImageView(mContext); + imageView.setScaleType(ImageView.ScaleType.FIT_XY); + imageView.setLayoutParams(layoutParams); + imageView.setOnClickListener(this); + imageView.setTag(intent); + imageView.setImageDrawable(icon); + mRecentsContainer.addView(imageView); + } + } + } + + int views = mRecentsContainer.getChildCount(); + mNoRecents.setVisibility(views == 0 ? View.VISIBLE : View.GONE); + mRecentsContainer.setVisibility(views > 0 ? View.VISIBLE : View.GONE); + } + + public void onClick(View v) { + Intent intent = (Intent) v.getTag(); + if (DEBUG) Log.v(TAG, "Starting activity " + intent); + getContext().startActivity(intent); + mBar.animateCollapse(); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarService.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarService.java index 9fb29ac..7234557 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarService.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarService.java @@ -67,8 +67,11 @@ public class TabletStatusBarService extends StatusBarService { public static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001; public static final int MSG_OPEN_SYSTEM_PANEL = 1010; public static final int MSG_CLOSE_SYSTEM_PANEL = 1011; - + public static final int MSG_OPEN_RECENTS_PANEL = 1020; + public static final int MSG_CLOSE_RECENTS_PANEL = 1021; + private static final int MAX_IMAGE_LEVEL = 10000; + private static final boolean USE_2D_RECENTS = true; int mIconSize; @@ -76,7 +79,7 @@ public class TabletStatusBarService extends StatusBarService { // tracking all current notifications private NotificationData mNotns = new NotificationData(); - + TabletStatusBarView mStatusBarView; ImageView mNotificationTrigger; NotificationIconArea mNotificationIconArea; @@ -110,6 +113,7 @@ public class TabletStatusBarService extends StatusBarService { int mDisabled = 0; boolean mNotificationsOn = true; + private RecentAppsPanel mRecentsPanel; protected void addPanelWindows() { final Context context = mContext; @@ -118,6 +122,7 @@ public class TabletStatusBarService extends StatusBarService { final int barHeight= res.getDimensionPixelSize( com.android.internal.R.dimen.status_bar_height); + // Notification Panel mNotificationPanel = (NotificationPanel)View.inflate(context, R.layout.sysbar_panel_notifications, null); mNotificationPanel.setVisibility(View.GONE); @@ -139,11 +144,11 @@ public class TabletStatusBarService extends StatusBarService { WindowManagerImpl.getDefault().addView(mNotificationPanel, lp); + // System Panel mSystemPanel = (SystemPanel) View.inflate(context, R.layout.sysbar_panel_system, null); mSystemPanel.setVisibility(View.GONE); mSystemPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_SYSTEM_PANEL, - mSystemPanel)); - + mSystemPanel)); mStatusBarView.setIgnoreChildren(1, mSystemInfo, mSystemPanel); lp = new WindowManager.LayoutParams( @@ -159,6 +164,31 @@ public class TabletStatusBarService extends StatusBarService { WindowManagerImpl.getDefault().addView(mSystemPanel, lp); mSystemPanel.setBar(this); + + + // Recents Panel + if (USE_2D_RECENTS) { + mRecentsPanel = (RecentAppsPanel) View.inflate(context, R.layout.sysbar_panel_recent, + null); + mRecentsPanel.setVisibility(View.GONE); + mRecentsPanel.setOnTouchListener(new TouchOutsideListener(MSG_CLOSE_RECENTS_PANEL, + mRecentsPanel)); + mStatusBarView.setIgnoreChildren(2, mRecentButton, mRecentsPanel); + + lp = new WindowManager.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, + WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN + | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, + PixelFormat.TRANSLUCENT); + lp.gravity = Gravity.BOTTOM | Gravity.LEFT; + lp.setTitle("RecentsPanel"); + lp.windowAnimations = com.android.internal.R.style.Animation_SlidingCard; + + WindowManagerImpl.getDefault().addView(mRecentsPanel, lp); + mRecentsPanel.setBar(this); + } } @Override @@ -181,12 +211,13 @@ public class TabletStatusBarService extends StatusBarService { mBarContents = sb.findViewById(R.id.bar_contents); mCurtains = sb.findViewById(R.id.lights_out); mSystemInfo = sb.findViewById(R.id.systemInfo); + mRecentButton = sb.findViewById(R.id.recent_apps); // mSystemInfo.setOnClickListener(mOnClickListener); mSystemInfo.setOnLongClickListener(new SetLightsOnListener(false)); mSystemInfo.setOnTouchListener(new ClockTouchListener()); - mRecentButton = sb.findViewById(R.id.recent); + mRecentButton = sb.findViewById(R.id.recent_apps); mRecentButton.setOnClickListener(mOnClickListener); SetLightsOnListener on = new SetLightsOnListener(true); @@ -231,7 +262,7 @@ public class TabletStatusBarService extends StatusBarService { mPile = (ViewGroup)mNotificationPanel.findViewById(R.id.content); mPile.removeAllViews(); - + ScrollView scroller = (ScrollView)mPile.getParent(); scroller.setFillViewport(true); @@ -277,6 +308,13 @@ public class TabletStatusBarService extends StatusBarService { case MSG_CLOSE_SYSTEM_PANEL: if (DEBUG) Slog.d(TAG, "closing system panel"); mSystemPanel.setVisibility(View.GONE); + case MSG_OPEN_RECENTS_PANEL: + if (DEBUG) Slog.d(TAG, "opening recents panel"); + if (mRecentsPanel != null) mRecentsPanel.setVisibility(View.VISIBLE); + break; + case MSG_CLOSE_RECENTS_PANEL: + if (DEBUG) Slog.d(TAG, "closing recents panel"); + if (mRecentsPanel != null) mRecentsPanel.setVisibility(View.GONE); break; } } @@ -315,7 +353,7 @@ public class TabletStatusBarService extends StatusBarService { mSignalMeter.setImageResource(R.drawable.sysbar_wifimini); // adjust to permyriad mSignalMeter.setImageLevel(level * (MAX_IMAGE_LEVEL / 100)); - mSignalIcon.setImageResource(isWifi ? R.drawable.ic_sysbar_wifi_mini + mSignalIcon.setImageResource(isWifi ? R.drawable.ic_sysbar_wifi_mini : R.drawable.ic_sysbar_wifi_mini); // XXX } } @@ -362,7 +400,7 @@ public class TabletStatusBarService extends StatusBarService { public void updateNotification(IBinder key, StatusBarNotification notification) { if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ") // TODO"); - + final NotificationData.Entry oldEntry = mNotns.findByKey(key); if (oldEntry == null) { Slog.w(TAG, "updateNotification for unknown key: " + key); @@ -527,6 +565,8 @@ public class TabletStatusBarService extends StatusBarService { mHandler.sendEmptyMessage(MSG_CLOSE_NOTIFICATION_PANEL); mHandler.removeMessages(MSG_CLOSE_SYSTEM_PANEL); mHandler.sendEmptyMessage(MSG_CLOSE_SYSTEM_PANEL); + mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL); + mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL); } public void setLightsOn(boolean on) { @@ -665,7 +705,7 @@ public class TabletStatusBarService extends StatusBarService { mIconLayout.setVisibility(View.VISIBLE); // TODO: animation refreshNotificationTrigger(); } else { - int msg = (mNotificationPanel.getVisibility() == View.GONE) + int msg = (mNotificationPanel.getVisibility() == View.GONE) ? MSG_OPEN_NOTIFICATION_PANEL : MSG_CLOSE_NOTIFICATION_PANEL; mHandler.removeMessages(msg); @@ -677,7 +717,7 @@ public class TabletStatusBarService extends StatusBarService { public void onClickSystemInfo() { if (DEBUG) Slog.d(TAG, "clicked system info"); if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { - int msg = (mSystemPanel.getVisibility() == View.GONE) + int msg = (mSystemPanel.getVisibility() == View.GONE) ? MSG_OPEN_SYSTEM_PANEL : MSG_CLOSE_SYSTEM_PANEL; mHandler.removeMessages(msg); @@ -687,11 +727,21 @@ public class TabletStatusBarService extends StatusBarService { public void onClickRecentButton() { if (DEBUG) Slog.d(TAG, "clicked recent apps"); - Intent intent = new Intent(); - intent.setClass(mContext, RecentApplicationsActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); - mContext.startActivity(intent); + if (mRecentsPanel == null) { + Intent intent = new Intent(); + intent.setClass(mContext, RecentApplicationsActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + mContext.startActivity(intent); + } else { + if ((mDisabled & StatusBarManager.DISABLE_EXPAND) == 0) { + int msg = (mRecentsPanel.getVisibility() == View.GONE) + ? MSG_OPEN_RECENTS_PANEL + : MSG_CLOSE_RECENTS_PANEL; + mHandler.removeMessages(msg); + mHandler.sendEmptyMessage(msg); + } + } } private class NotificationClicker implements View.OnClickListener { @@ -835,7 +885,7 @@ public class TabletStatusBarService extends StatusBarService { final String _pkg = sbn.pkg; final String _tag = sbn.tag; final int _id = sbn.id; - vetoButton.setOnClickListener(new View.OnClickListener() { + vetoButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { mBarService.onNotificationClear(_pkg, _tag, _id); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarView.java index d836e4a..15866fe 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarView.java @@ -26,8 +26,8 @@ import android.widget.FrameLayout; public class TabletStatusBarView extends FrameLayout { private Handler mHandler; - private View[] mIgnoreChildren = new View[2]; - private View[] mPanels = new View[2]; + private View[] mIgnoreChildren = new View[3]; + private View[] mPanels = new View[3]; private int[] mPos = new int[2]; public TabletStatusBarView(Context context) { @@ -44,9 +44,11 @@ public class TabletStatusBarView extends FrameLayout { mHandler.sendEmptyMessage(TabletStatusBarService.MSG_CLOSE_NOTIFICATION_PANEL); mHandler.removeMessages(TabletStatusBarService.MSG_CLOSE_SYSTEM_PANEL); mHandler.sendEmptyMessage(TabletStatusBarService.MSG_CLOSE_SYSTEM_PANEL); + mHandler.removeMessages(TabletStatusBarService.MSG_CLOSE_RECENTS_PANEL); + mHandler.sendEmptyMessage(TabletStatusBarService.MSG_CLOSE_RECENTS_PANEL); - for (int i=0; i<mPanels.length; i++) { - if (mPanels[i].getVisibility() == View.VISIBLE) { + for (int i=0; i < mPanels.length; i++) { + if (mPanels[i] != null && mPanels[i].getVisibility() == View.VISIBLE) { if (eventInside(mIgnoreChildren[i], ev)) { return true; } |