Initial commit of 3 button work

Home, Back and Recents basic functionality working

Fixes: 180046394
Change-Id: Ifc5c767e35e88183500d14d14736eb40df436369
This commit is contained in:
Vinit Nayak
2021-03-25 12:31:23 -07:00
parent 13e4618b57
commit 16fd85629d
10 changed files with 339 additions and 10 deletions

View File

@@ -15,6 +15,13 @@
*/
package com.android.launcher3.taskbar;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_BACK;
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_HOME;
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_RECENTS;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.LayoutTransition;
@@ -24,11 +31,14 @@ import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.SystemProperties;
import android.util.AttributeSet;
import android.view.DragEvent;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.LayoutRes;
@@ -45,12 +55,17 @@ import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.views.ActivityContext;
import com.android.quickstep.SysUINavigationMode;
/**
* Hosts the Taskbar content such as Hotseat and Recent Apps. Drawn on top of other apps.
*/
public class TaskbarView extends LinearLayout implements FolderIcon.FolderIconParent, Insettable {
private static final boolean ENABLE_THREE_BUTTON_TASKBAR =
SystemProperties.getBoolean("persist.debug.taskbar_three_button", false);
private final int mIconTouchSize;
private final boolean mIsRtl;
private final int mTouchSlop;
@@ -69,6 +84,8 @@ public class TaskbarView extends LinearLayout implements FolderIcon.FolderIconPa
private int mHotseatStartIndex;
private int mHotseatEndIndex;
private LinearLayout mButtonRegion;
// Delegate touches to the closest view if within mIconTouchSize.
private boolean mDelegateTargeted;
private View mDelegateView;
@@ -77,6 +94,8 @@ public class TaskbarView extends LinearLayout implements FolderIcon.FolderIconPa
// Only non-null when the corresponding Folder is open.
private @Nullable FolderIcon mLeaveBehindFolderIcon;
private int mNavButtonStartIndex;
public TaskbarView(@NonNull Context context) {
this(context, null);
}
@@ -107,8 +126,18 @@ public class TaskbarView extends LinearLayout implements FolderIcon.FolderIconPa
mItemMarginLeftRight = Math.round(mItemMarginLeftRight * mNonIconScale);
}
protected void init(int numHotseatIcons) {
mHotseatStartIndex = 0;
protected void init(int numHotseatIcons, SysUINavigationMode.Mode newMode) {
// TODO: check if buttons on left
if (newMode == SysUINavigationMode.Mode.THREE_BUTTONS && ENABLE_THREE_BUTTON_TASKBAR) {
// 3 button
mNavButtonStartIndex = 0;
createNavButtons();
} else {
mNavButtonStartIndex = -1;
removeNavButtons();
}
mHotseatStartIndex = mNavButtonStartIndex + 1;
mHotseatEndIndex = mHotseatStartIndex + numHotseatIcons - 1;
updateHotseatItems(new ItemInfo[numHotseatIcons]);
@@ -185,11 +214,11 @@ public class TaskbarView extends LinearLayout implements FolderIcon.FolderIconPa
if (hotseatView == null || hotseatView.getSourceLayoutResId() != expectedLayoutResId
|| needsReinflate) {
removeView(hotseatView);
ActivityContext activityContext = ActivityContext.lookupContext(getContext());
ActivityContext activityContext = getActivityContext();
if (isFolder) {
FolderInfo folderInfo = (FolderInfo) hotseatItemInfo;
FolderIcon folderIcon = FolderIcon.inflateFolderAndIcon(expectedLayoutResId,
ActivityContext.lookupContext(getContext()), this, folderInfo);
getActivityContext(), this, folderInfo);
folderIcon.setTextVisible(false);
hotseatView = folderIcon;
} else {
@@ -335,12 +364,71 @@ public class TaskbarView extends LinearLayout implements FolderIcon.FolderIconPa
return findDelegateView(xInOurCoordinates, yInOurCoorindates) != null;
}
private void removeNavButtons() {
if (mButtonRegion != null) {
mButtonRegion.removeAllViews();
removeView(mButtonRegion);
} // else We've never been in 3 button. Woah Scoob!
}
/**
* Add back/home/recents buttons into a single ViewGroup that will be inserted at
* {@param navButtonStartIndex}
*/
private void createNavButtons() {
ActivityContext context = getActivityContext();
if (mButtonRegion == null) {
mButtonRegion = new LinearLayout(getContext());
} else {
mButtonRegion.removeAllViews();
}
mButtonRegion.setVisibility(VISIBLE);
LayoutParams regionParams = new LayoutParams(WRAP_CONTENT, MATCH_PARENT);
regionParams.gravity = Gravity.START; // check left/right preference
regionParams.setMargins(mItemMarginLeftRight, 0, mItemMarginLeftRight, 0);
LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(
context.getDeviceProfile().iconSizePx,
context.getDeviceProfile().iconSizePx
);
buttonParams.gravity = Gravity.CENTER;
// Back button
ImageView backButton = new ImageView(getContext());
backButton.setImageResource(R.drawable.ic_sysbar_back);
backButton.setBackgroundResource(R.drawable.taskbar_icon_click_feedback_roundrect);
backButton.setPadding(mItemMarginLeftRight, 0, mItemMarginLeftRight, 0);
backButton.setOnClickListener(view -> mControllerCallbacks.onNavigationButtonClick(
BUTTON_BACK));
mButtonRegion.addView(backButton, buttonParams);
// Home button
ImageView homeButton = new ImageView(getContext());
homeButton.setImageResource(R.drawable.ic_sysbar_home);
homeButton.setBackgroundResource(R.drawable.taskbar_icon_click_feedback_roundrect);
homeButton.setPadding(mItemMarginLeftRight, 0, mItemMarginLeftRight, 0);
homeButton.setOnClickListener(view -> mControllerCallbacks.onNavigationButtonClick(
BUTTON_HOME));
mButtonRegion.addView(homeButton, buttonParams);
// Recents button
ImageView recentsButton = new ImageView(getContext());
recentsButton.setImageResource(R.drawable.ic_sysbar_recent);
recentsButton.setBackgroundResource(R.drawable.taskbar_icon_click_feedback_roundrect);
recentsButton.setPadding(mItemMarginLeftRight, 0, mItemMarginLeftRight, 0);
recentsButton.setOnClickListener(view -> mControllerCallbacks.onNavigationButtonClick(
BUTTON_RECENTS));
mButtonRegion.addView(recentsButton, buttonParams);
addView(mButtonRegion, mNavButtonStartIndex);
}
@Override
public boolean onDragEvent(DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
mIsDraggingItem = true;
AbstractFloatingView.closeAllOpenViews(ActivityContext.lookupContext(getContext()));
AbstractFloatingView.closeAllOpenViews(getActivityContext());
return true;
case DragEvent.ACTION_DRAG_ENDED:
mIsDraggingItem = false;
@@ -407,12 +495,15 @@ public class TaskbarView extends LinearLayout implements FolderIcon.FolderIconPa
}
private View inflate(@LayoutRes int layoutResId) {
return ActivityContext.lookupContext(getContext()).getLayoutInflater()
.inflate(layoutResId, this, false);
return getActivityContext().getLayoutInflater().inflate(layoutResId, this, false);
}
@Override
public void setInsets(Rect insets) {
// Ignore, we just implement Insettable to draw behind system insets.
}
private <T extends Context & ActivityContext> T getActivityContext() {
return ActivityContext.lookupContext(getContext());
}
}