Add Hotseat items to Taskbar

- Currently supports WorkspaceItemInfo (e.g. normal app icons
  including hotseat predictions and pinned deep shortcuts).
- Currently doesn't support Folders, Notification dots, or
  long press.

Some technical details:
- Always allow HotseatPredictionController updates given the
  Hotseat is always showing even when Launcher is stopped.
- Represent Taskbar Hotseat items as BubbleTextViews, to
  allow for normal click handling etc. When the hotseat is
  updated, we reuse the same BubbleTextViews that were
  initially inflated, and just reapply the new info.
- Add new BubbleTextView iconDisplay for Taskbar, to allow
  for different treatment such as icon size.

Bug: 171917176
Change-Id: I325eb39051f2dc69228b39b5c40ed0cbdad8e200
This commit is contained in:
Tony Wickham
2021-01-11 14:54:23 -06:00
parent 5f7f4cb35d
commit 794fe4f58e
17 changed files with 323 additions and 10 deletions

View File

@@ -16,19 +16,35 @@
package com.android.launcher3.taskbar;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.R;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
/**
* Hosts the Taskbar content such as Hotseat and Recent Apps. Drawn on top of other apps.
*/
public class TaskbarView extends LinearLayout {
private final ColorDrawable mBackgroundDrawable;
private final int mItemMarginLeftRight;
// Initialized in init().
private int mHotseatStartIndex;
private int mHotseatEndIndex;
private TaskbarController.TaskbarViewCallbacks mControllerCallbacks;
public TaskbarView(@NonNull Context context) {
this(context, null);
@@ -46,7 +62,24 @@ public class TaskbarView extends LinearLayout {
public TaskbarView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
Resources resources = getResources();
mBackgroundDrawable = (ColorDrawable) getBackground();
mItemMarginLeftRight = resources.getDimensionPixelSize(R.dimen.taskbar_icon_spacing);
}
protected void setCallbacks(TaskbarController.TaskbarViewCallbacks taskbarViewCallbacks) {
mControllerCallbacks = taskbarViewCallbacks;
}
protected void init(int numHotseatIcons) {
mHotseatStartIndex = 0;
mHotseatEndIndex = mHotseatStartIndex + numHotseatIcons - 1;
updateHotseatItems(new ItemInfo[numHotseatIcons]);
}
protected void cleanup() {
removeAllViews();
}
/**
@@ -56,4 +89,47 @@ public class TaskbarView extends LinearLayout {
public void setBackgroundAlpha(float alpha) {
mBackgroundDrawable.setAlpha((int) (alpha * 255));
}
/**
* Inflates/binds the Hotseat views to show in the Taskbar given their ItemInfos.
*/
protected void updateHotseatItems(ItemInfo[] hotseatItemInfos) {
for (int i = 0; i < hotseatItemInfos.length; i++) {
ItemInfo hotseatItemInfo = hotseatItemInfos[i];
int hotseatIndex = mHotseatStartIndex + i;
View hotseatView = getChildAt(hotseatIndex);
// Replace any Hotseat views with the appropriate type if it's not already that type.
final int expectedLayoutResId;
if (hotseatItemInfo != null && hotseatItemInfo.isPredictedItem()) {
expectedLayoutResId = R.layout.taskbar_predicted_app_icon;
} else {
expectedLayoutResId = R.layout.taskbar_app_icon;
}
if (hotseatView == null || hotseatView.getSourceLayoutResId() != expectedLayoutResId) {
removeView(hotseatView);
BubbleTextView btv = (BubbleTextView) inflate(expectedLayoutResId);
LayoutParams lp = new LayoutParams(btv.getIconSize(), btv.getIconSize());
lp.setMargins(mItemMarginLeftRight, 0, mItemMarginLeftRight, 0);
hotseatView = btv;
addView(hotseatView, hotseatIndex, lp);
}
// Apply the Hotseat ItemInfos, or hide the view if there is none for a given index.
if (hotseatView instanceof BubbleTextView
&& hotseatItemInfo instanceof WorkspaceItemInfo) {
((BubbleTextView) hotseatView).applyFromWorkspaceItem(
(WorkspaceItemInfo) hotseatItemInfo);
hotseatView.setVisibility(VISIBLE);
hotseatView.setOnClickListener(mControllerCallbacks.getItemOnClickListener());
} else {
hotseatView.setVisibility(GONE);
hotseatView.setOnClickListener(null);
}
}
}
private View inflate(@LayoutRes int layoutResId) {
return LayoutInflater.from(getContext()).inflate(layoutResId, this, false);
}
}