Search in sources :

Example 11 with SystemServicesProxy

use of com.android.systemui.recents.misc.SystemServicesProxy in project android_frameworks_base by ResurrectionRemix.

the class RecentsTvView method launchTaskFomRecents.

/**
     * Launch the given task from recents with animation. If the task is not focused, this will
     * attempt to scroll to focus the task before launching.
     * @param task
     */
private void launchTaskFomRecents(final Task task, boolean animate) {
    if (!animate) {
        SystemServicesProxy ssp = Recents.getSystemServices();
        ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
        return;
    }
    mTaskStackHorizontalView.requestFocus();
    Task focusedTask = mTaskStackHorizontalView.getFocusedTask();
    if (focusedTask != null && task != focusedTask) {
        if (mScrollListener != null) {
            mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
        }
        mScrollListener = new OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    TaskCardView cardView = mTaskStackHorizontalView.getChildViewForTask(task);
                    if (cardView != null) {
                        mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, cardView, null, INVALID_STACK_ID);
                    } else {
                        // This should not happen normally. If this happens then the data in
                        // the grid view was altered during the scroll. Log error and launch
                        // task with no animation.
                        Log.e(TAG, "Card view for task : " + task + ", returned null.");
                        SystemServicesProxy ssp = Recents.getSystemServices();
                        ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
                    }
                    mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
                }
            }
        };
        mTaskStackHorizontalView.addOnScrollListener(mScrollListener);
        mTaskStackHorizontalView.setSelectedPositionSmooth(((TaskStackHorizontalViewAdapter) mTaskStackHorizontalView.getAdapter()).getPositionOfTask(task));
    } else {
        mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, mTaskStackHorizontalView.getChildViewForTask(task), null, INVALID_STACK_ID);
    }
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) Task(com.android.systemui.recents.model.Task) OnScrollListener(android.support.v7.widget.RecyclerView.OnScrollListener) RecyclerView(android.support.v7.widget.RecyclerView)

Example 12 with SystemServicesProxy

use of com.android.systemui.recents.misc.SystemServicesProxy in project android_frameworks_base by ResurrectionRemix.

the class RecentsTaskLoader method getAndUpdateActivityTitle.

/**
     * Returns the cached task label if the task key is not expired, updating the cache if it is.
     */
String getAndUpdateActivityTitle(Task.TaskKey taskKey, ActivityManager.TaskDescription td) {
    SystemServicesProxy ssp = Recents.getSystemServices();
    // Return the task description label if it exists
    if (td != null && td.getLabel() != null) {
        return td.getLabel();
    }
    // Return the cached activity label if it exists
    String label = mActivityLabelCache.getAndInvalidateIfModified(taskKey);
    if (label != null) {
        return label;
    }
    // All short paths failed, load the label from the activity info and cache it
    ActivityInfo activityInfo = getAndUpdateActivityInfo(taskKey);
    if (activityInfo != null) {
        label = ssp.getBadgedActivityLabel(activityInfo, taskKey.userId);
        mActivityLabelCache.put(taskKey, label);
        return label;
    }
    // but do not cache it
    return "";
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) ActivityInfo(android.content.pm.ActivityInfo)

Example 13 with SystemServicesProxy

use of com.android.systemui.recents.misc.SystemServicesProxy in project android_frameworks_base by ResurrectionRemix.

the class RecentsTaskLoader method getAndUpdateActivityIcon.

/**
     * Returns the cached task icon if the task key is not expired, updating the cache if it is.
     */
Drawable getAndUpdateActivityIcon(Task.TaskKey taskKey, ActivityManager.TaskDescription td, Resources res, boolean loadIfNotCached) {
    SystemServicesProxy ssp = Recents.getSystemServices();
    // Return the cached activity icon if it exists
    Drawable icon = mIconCache.getAndInvalidateIfModified(taskKey);
    if (icon != null) {
        return icon;
    }
    if (loadIfNotCached) {
        // Return and cache the task description icon if it exists
        icon = ssp.getBadgedTaskDescriptionIcon(td, taskKey.userId, res);
        if (icon != null) {
            mIconCache.put(taskKey, icon);
            return icon;
        }
        // Load the icon from the activity info and cache it
        ActivityInfo activityInfo = getAndUpdateActivityInfo(taskKey);
        if (activityInfo != null) {
            icon = ssp.getBadgedActivityIcon(activityInfo, taskKey.userId);
            if (icon != null) {
                mIconCache.put(taskKey, icon);
                return icon;
            }
        }
    }
    // We couldn't load any icon
    return null;
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) ActivityInfo(android.content.pm.ActivityInfo) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable)

Example 14 with SystemServicesProxy

use of com.android.systemui.recents.misc.SystemServicesProxy in project android_frameworks_base by ResurrectionRemix.

the class RecentsTaskLoader method run.

@Override
public void run() {
    while (true) {
        if (mCancelled) {
            // We have to unset the context here, since the background thread may be using it
            // when we call stop()
            mContext = null;
            // If we are cancelled, then wait until we are started again
            synchronized (mLoadThread) {
                try {
                    mLoadThread.wait();
                } catch (InterruptedException ie) {
                    ie.printStackTrace();
                }
            }
        } else {
            RecentsConfiguration config = Recents.getConfiguration();
            SystemServicesProxy ssp = Recents.getSystemServices();
            // the load thread
            if (ssp != null) {
                // Load the next item from the queue
                final Task t = mLoadQueue.nextTask();
                if (t != null) {
                    Drawable cachedIcon = mIconCache.get(t.key);
                    ThumbnailData cachedThumbnailData = mThumbnailCache.get(t.key);
                    // Load the icon if it is stale or we haven't cached one yet
                    if (cachedIcon == null) {
                        cachedIcon = ssp.getBadgedTaskDescriptionIcon(t.taskDescription, t.key.userId, mContext.getResources());
                        if (cachedIcon == null) {
                            ActivityInfo info = ssp.getActivityInfo(t.key.getComponent(), t.key.userId);
                            if (info != null) {
                                if (DEBUG)
                                    Log.d(TAG, "Loading icon: " + t.key);
                                cachedIcon = ssp.getBadgedActivityIcon(info, t.key.userId);
                            }
                        }
                        if (cachedIcon == null) {
                            cachedIcon = mDefaultIcon;
                        }
                        // At this point, even if we can't load the icon, we will set the
                        // default icon.
                        mIconCache.put(t.key, cachedIcon);
                    }
                    // Load the thumbnail if it is stale or we haven't cached one yet
                    if (cachedThumbnailData == null) {
                        if (config.svelteLevel < RecentsConfiguration.SVELTE_DISABLE_LOADING) {
                            if (DEBUG)
                                Log.d(TAG, "Loading thumbnail: " + t.key);
                            cachedThumbnailData = ssp.getTaskThumbnail(t.key.id);
                        }
                        if (cachedThumbnailData.thumbnail == null) {
                            cachedThumbnailData.thumbnail = mDefaultThumbnail;
                        } else {
                            // Kick off an early upload of the bitmap to GL so
                            // that this won't jank the first frame it's drawn in.
                            cachedThumbnailData.thumbnail.prepareToDraw();
                        }
                        // them from scratch each time)
                        if (config.svelteLevel < RecentsConfiguration.SVELTE_LIMIT_CACHE) {
                            mThumbnailCache.put(t.key, cachedThumbnailData);
                        }
                    }
                    if (!mCancelled) {
                        // Notify that the task data has changed
                        final Drawable newIcon = cachedIcon;
                        final ThumbnailData newThumbnailData = cachedThumbnailData;
                        mMainThreadHandler.post(new Runnable() {

                            @Override
                            public void run() {
                                t.notifyTaskDataLoaded(newThumbnailData.thumbnail, newIcon, newThumbnailData.thumbnailInfo);
                            }
                        });
                    }
                }
            }
            // If there are no other items in the list, then just wait until something is added
            if (!mCancelled && mLoadQueue.isEmpty()) {
                synchronized (mLoadQueue) {
                    try {
                        mWaitingOnLoadQueue = true;
                        while (mLoadQueue.isEmpty()) {
                            mLoadQueue.wait();
                        }
                        mWaitingOnLoadQueue = false;
                    } catch (InterruptedException ie) {
                        ie.printStackTrace();
                    }
                }
            }
        }
    }
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) ActivityInfo(android.content.pm.ActivityInfo) RecentsConfiguration(com.android.systemui.recents.RecentsConfiguration) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable)

Example 15 with SystemServicesProxy

use of com.android.systemui.recents.misc.SystemServicesProxy in project android_frameworks_base by ResurrectionRemix.

the class RecentsTvTransitionHelper method startTaskActivity.

private void startTaskActivity(TaskStack stack, Task task, @Nullable TaskCardView taskView, ActivityOptions opts, final ActivityOptions.OnAnimationStartedListener animStartedListener) {
    SystemServicesProxy ssp = Recents.getSystemServices();
    if (ssp.startActivityFromRecents(mContext, task.key, task.title, opts)) {
        // Keep track of the index of the task launch
        int taskIndexFromFront = 0;
        int taskIndex = stack.indexOfStackTask(task);
        if (taskIndex > -1) {
            taskIndexFromFront = stack.getTaskCount() - taskIndex - 1;
        }
        EventBus.getDefault().send(new LaunchTaskSucceededEvent(taskIndexFromFront));
    } else {
        // Keep track of failed launches
        EventBus.getDefault().send(new LaunchTaskFailedEvent());
    }
    Rect taskRect = taskView.getFocusedThumbnailRect();
    // we do not override the transition.
    if (taskRect == null || task.thumbnail == null) {
        return;
    }
    IRemoteCallback.Stub callback = null;
    if (animStartedListener != null) {
        callback = new IRemoteCallback.Stub() {

            @Override
            public void sendResult(Bundle data) throws RemoteException {
                mHandler.post(new Runnable() {

                    @Override
                    public void run() {
                        if (animStartedListener != null) {
                            animStartedListener.onAnimationStarted();
                        }
                    }
                });
            }
        };
    }
    try {
        Bitmap thumbnail = Bitmap.createScaledBitmap(task.thumbnail, taskRect.width(), taskRect.height(), false);
        WindowManagerGlobal.getWindowManagerService().overridePendingAppTransitionAspectScaledThumb(thumbnail, taskRect.left, taskRect.top, taskRect.width(), taskRect.height(), callback, true);
    } catch (RemoteException e) {
        Log.w(TAG, "Failed to override transition: " + e);
    }
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) IRemoteCallback(android.os.IRemoteCallback) Bundle(android.os.Bundle) RemoteException(android.os.RemoteException)

Aggregations

SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)243 Rect (android.graphics.Rect)45 ActivityManager (android.app.ActivityManager)35 ActivityInfo (android.content.pm.ActivityInfo)34 RecentsTaskLoader (com.android.systemui.recents.model.RecentsTaskLoader)30 TaskStack (com.android.systemui.recents.model.TaskStack)30 Task (com.android.systemui.recents.model.Task)25 Drawable (android.graphics.drawable.Drawable)19 Point (android.graphics.Point)16 ActivityOptions (android.app.ActivityOptions)15 ComponentName (android.content.ComponentName)15 RemoteException (android.os.RemoteException)15 MutableBoolean (android.util.MutableBoolean)15 RecentsActivityLaunchState (com.android.systemui.recents.RecentsActivityLaunchState)15 RecentsConfiguration (com.android.systemui.recents.RecentsConfiguration)15 Bitmap (android.graphics.Bitmap)14 ArrayList (java.util.ArrayList)14 BitmapDrawable (android.graphics.drawable.BitmapDrawable)12 ActivityNotFoundException (android.content.ActivityNotFoundException)10 Intent (android.content.Intent)10