Brighten theme-icons when in Dark mode and add dark color for taskbar

Bug: 217247494
Test: change between dark and light mode and transition in and out of apps
Change-Id: Ia5e38d674a56eb95a48cb1e8c2688586594a69f9
This commit is contained in:
Sebastian Franco
2022-02-02 18:14:07 +00:00
parent f3d81b0a1c
commit 5282efddc9
4 changed files with 65 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ import android.widget.FrameLayout;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.graphics.ColorUtils;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.Insettable;
@@ -35,6 +36,7 @@ import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.icons.ThemedIconDrawable;
import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
@@ -43,14 +45,17 @@ import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.LauncherBindableItemsContainer;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.AllAppsButton;
import com.android.launcher3.views.DoubleShadowBubbleTextView;
/**
* Hosts the Taskbar content such as Hotseat and Recent Apps. Drawn on top of other apps.
*/
public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconParent, Insettable {
private final int[] mTempOutLocation = new int[2];
private static final float TASKBAR_BACKGROUND_LUMINANCE = 0.30f;
public int mThemeIconsBackground;
private final int[] mTempOutLocation = new int[2];
private final Rect mIconLayoutBounds = new Rect();
private final int mIconTouchSize;
private final int mItemMarginLeftRight;
@@ -103,6 +108,8 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
// Needed to draw folder leave-behind when opening one.
setWillNotDraw(false);
mThemeIconsBackground = calculateThemeIconsBackground();
if (FeatureFlags.ENABLE_ALL_APPS_IN_TASKBAR.get()) {
mAllAppsButton = new AllAppsButton(context);
mAllAppsButton.setLayoutParams(
@@ -111,6 +118,21 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
}
}
private int getColorWithGivenLuminance(int color, float luminance) {
float[] colorHSL = new float[3];
ColorUtils.colorToHSL(color, colorHSL);
colorHSL[2] = luminance;
return ColorUtils.HSLToColor(colorHSL);
}
private int calculateThemeIconsBackground() {
int color = ThemedIconDrawable.getColors(mContext)[0];
if (Utilities.isDarkTheme(mContext)) {
return getColorWithGivenLuminance(color, TASKBAR_BACKGROUND_LUMINANCE);
}
return color;
}
protected void init(TaskbarViewController.TaskbarViewCallbacks callbacks) {
mControllerCallbacks = callbacks;
mIconClickListener = mControllerCallbacks.getIconOnClickListener();
@@ -219,6 +241,24 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
int index = Utilities.isRtl(getResources()) ? 0 : getChildCount();
addView(mAllAppsButton, index);
}
mThemeIconsBackground = calculateThemeIconsBackground();
setThemedIconsBackgroundColor(mThemeIconsBackground);
}
/**
* Traverse all the child views and change the background of themeIcons
**/
public void setThemedIconsBackgroundColor(int color) {
for (View icon : getIconViews()) {
if (icon instanceof DoubleShadowBubbleTextView) {
DoubleShadowBubbleTextView textView = ((DoubleShadowBubbleTextView) icon);
if (textView.getIcon() != null
&& textView.getIcon() instanceof ThemedIconDrawable) {
((ThemedIconDrawable) textView.getIcon()).changeBackgroundColor(color);
}
}
}
}
/**