Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3ce0b7cd authored by Jim Miller's avatar Jim Miller Committed by Android (Google) Code Review
Browse files

Merge "Fix 3117937: Add simplified "recent apps"."

parents bac9c294 44c66fe2
Loading
Loading
Loading
Loading
+10.8 KiB
Loading image diff...
+1 −1
Original line number Diff line number Diff line
@@ -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"
+49 −0
Original line number Diff line number Diff line
<?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>
+167 −0
Original line number Diff line number Diff line
/*
 * 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();
    }
}
+66 −16
Original line number Diff line number Diff line
@@ -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;

@@ -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));

        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);
@@ -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;
            }
        }
@@ -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) {
@@ -687,11 +727,21 @@ public class TabletStatusBarService extends StatusBarService {

    public void onClickRecentButton() {
        if (DEBUG) Slog.d(TAG, "clicked recent apps");
        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 {
Loading