Merge "Folder polish" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-05-19 18:00:18 +00:00
committed by Android (Google) Code Review
6 changed files with 44 additions and 39 deletions

View File

@@ -28,6 +28,9 @@
<color name="workspace_text_color_light">@android:color/system_neutral1_0</color>
<color name="workspace_text_color_dark">@android:color/system_neutral1_1000</color>
<color name="folder_hint_text_color_light">@android:color/system_neutral1_50</color>
<color name="folder_hint_text_color_dark">@android:color/system_neutral2_700</color>
<color name="text_color_primary_dark">@android:color/system_neutral1_50</color>
<color name="text_color_secondary_dark">@android:color/system_neutral2_200</color>
<color name="text_color_tertiary_dark">@android:color/system_neutral2_400</color>

View File

@@ -52,6 +52,9 @@
<color name="workspace_text_color_light">#FFF</color>
<color name="workspace_text_color_dark">#FF000000</color>
<color name="folder_hint_text_color_light">#FFF</color>
<color name="folder_hint_text_color_dark">#FF000000</color>
<color name="text_color_primary_dark">#FFFFFFFF</color>
<color name="text_color_secondary_dark">#FFFFFFFF</color>
<color name="text_color_tertiary_dark">#CCFFFFFF</color>

View File

@@ -51,7 +51,7 @@
<item name="folderIconBorderColor">?android:attr/colorPrimary</item>
<item name="folderTextColor">?android:attr/textColorPrimary</item>
<item name="isFolderDarkText">true</item>
<item name="folderHintColor">#89616161</item>
<item name="folderHintColor">@color/folder_hint_text_color_dark</item>
<item name="loadingIconColor">#CCFFFFFF</item>
<item name="iconOnlyShortcutColor">?android:attr/textColorSecondary</item>
<item name="workProfileOverlayTextColor">#FF212121</item>
@@ -73,6 +73,7 @@
<item name="folderFillColor">#FF3C4043</item> <!-- 100% GM2 800 -->
<item name="folderTextColor">?attr/workspaceTextColor</item>
<item name="isFolderDarkText">?attr/isWorkspaceDarkText</item>
<item name="folderHintColor">@color/folder_hint_text_color_dark</item>
<item name="disabledIconAlpha">.254</item>
</style>
@@ -89,6 +90,7 @@
<item name="folderIconBorderColor">#FF80868B</item>
<item name="folderTextColor">?attr/workspaceTextColor</item>
<item name="isFolderDarkText">true</item>
<item name="folderHintColor">@color/folder_hint_text_color_dark</item>
</style>
<style name="LauncherTheme.Dark" parent="@style/LauncherTheme">
@@ -110,7 +112,7 @@
<item name="folderIconBorderColor">?android:attr/colorPrimary</item>
<item name="folderTextColor">?android:attr/textColorPrimary</item>
<item name="isFolderDarkText">false</item>
<item name="folderHintColor">#89CCCCCC</item>
<item name="folderHintColor">@color/folder_hint_text_color_light</item>
<item name="isMainColorDark">true</item>
<item name="loadingIconColor">#99FFFFFF</item>
<item name="iconOnlyShortcutColor">#B3FFFFFF</item>
@@ -123,6 +125,7 @@
<item name="folderFillColor">#FF3C4043</item> <!-- 100% GM2 800 -->
<item name="folderTextColor">@android:color/white</item>
<item name="isFolderDarkText">false</item>
<item name="folderHintColor">@color/folder_hint_text_color_light</item>
<item name="disabledIconAlpha">.54</item>
</style>
@@ -131,6 +134,7 @@
<item name="folderFillColor">#CDFFFFFF</item>
<item name="folderTextColor">?attr/workspaceTextColor</item>
<item name="isFolderDarkText">?attr/isWorkspaceDarkText</item>
<item name="folderHintColor">@color/folder_hint_text_color_dark</item>
<item name="workspaceTextColor">@color/workspace_text_color_dark</item>
<item name="workspaceShadowColor">@android:color/transparent</item>
<item name="workspaceAmbientShadowColor">@android:color/transparent</item>

View File

@@ -39,7 +39,6 @@ import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.util.TouchController;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.BaseDragLayer;
import com.android.launcher3.widget.LocalColorExtractor;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -112,21 +111,12 @@ public abstract class AbstractFloatingView extends LinearLayout implements Touch
protected boolean mIsOpen;
// Index used to get background color when using local wallpaper color extraction.
protected int mColorExtractionIndex;
public AbstractFloatingView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public AbstractFloatingView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
mColorExtractionIndex = LocalColorExtractor.getColorIndex(context);
}
/**

View File

@@ -32,8 +32,10 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.appwidget.AppWidgetHostView;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.Insets;
import android.graphics.Path;
@@ -65,6 +67,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.graphics.ColorUtils;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.Alarm;
@@ -157,13 +160,18 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
private static final float ICON_OVERSCROLL_WIDTH_FACTOR = 0.45f;
private static final int FOLDER_NAME_ANIMATION_DURATION = 633;
private static final int FOLDER_COLOR_ANIMATION_DURATION = 150;
private static final int FOLDER_COLOR_ANIMATION_DURATION = 200;
private static final int REORDER_DELAY = 250;
private static final int ON_EXIT_CLOSE_DELAY = 400;
private static final Rect sTempRect = new Rect();
private static final int MIN_FOLDERS_FOR_HARDWARE_OPTIMIZATION = 10;
// Index used to get background color when using local wallpaper color extraction,
private static final int DARK_COLOR_EXTRACTION_INDEX = android.R.color.system_neutral1_900;
private static final int LIGHT_COLOR_EXTRACTION_INDEX = android.R.color.system_neutral2_500;
private static final int LIGHT_COLOR_L_STAR = 98;
private final Alarm mReorderAlarm = new Alarm();
private final Alarm mOnExitAlarm = new Alarm();
private final Alarm mOnScrollHintAlarm = new Alarm();
@@ -296,8 +304,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
}
if (Utilities.ATLEAST_S) {
mColorExtractionIndex = LocalColorExtractor.getColorIndex(
!Themes.getAttrBoolean(getContext(), R.attr.isFolderDarkText));
boolean isFolderDarkText = Themes.getAttrBoolean(getContext(), R.attr.isFolderDarkText);
mColorExtractor = LocalColorExtractor.newInstance(getContext());
mColorListener = (RectF rect, SparseIntArray extractedColors) -> {
mColorChangeRunnable = () -> {
@@ -313,11 +320,14 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
mOpenAnimationColorChangeAnimator = null;
}
// Start a new animator to the extracted color.
int newColor = extractedColors.get(mColorExtractionIndex);
// Start a new animator to the extracted color. Clamp down on the alpha
// to prevent folder from being transparent for too long.
GradientDrawable bg = (GradientDrawable) getBackground();
mColorChangeAnimator = ObjectAnimator.ofArgb(bg, "color",
bg.getColor().getDefaultColor(), newColor).setDuration(duration);
int currentColor = ColorUtils.setAlphaComponent(bg.getColor().getDefaultColor(),
255);
int newColor = getExtractedColor(extractedColors, isFolderDarkText);
mColorChangeAnimator = ObjectAnimator.ofArgb(bg, "color", currentColor,
newColor).setDuration(duration);
mColorChangeAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
@@ -337,6 +347,21 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
}
}
/**
* Returns an index used to query the color of interest from the list of extracted colors.
* @param hasDarkText True when dark index is wanted, False when light index is wanted.
*/
@TargetApi(Build.VERSION_CODES.S)
private int getExtractedColor(SparseIntArray colors, boolean hasDarkText) {
int color = colors.get(hasDarkText
? LIGHT_COLOR_EXTRACTION_INDEX
: DARK_COLOR_EXTRACTION_INDEX);
if (hasDarkText) {
color = ColorStateList.valueOf(color).withLStar(LIGHT_COLOR_L_STAR).getDefaultColor();
}
return color;
}
public boolean onLongClick(View v) {
// Return if global dragging is not enabled
if (!mLauncherDelegate.isDraggingEnabled()) return true;

View File

@@ -28,7 +28,6 @@ import androidx.annotation.Nullable;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.ResourceBasedOverride;
import java.util.List;
@@ -36,10 +35,6 @@ import java.util.List;
/** Extracts the colors we need from the wallpaper at given locations. */
public class LocalColorExtractor implements ResourceBasedOverride {
// Index used to get background color when using local wallpaper color extraction,
private static final int LIGHT_COLOR_EXTRACTION_INDEX = android.R.color.system_accent2_50;
private static final int DARK_COLOR_EXTRACTION_INDEX = android.R.color.system_accent2_800;
/** Listener for color changes on a screen location. */
public interface Listener {
/**
@@ -108,19 +103,4 @@ public class LocalColorExtractor implements ResourceBasedOverride {
RectF colorExtractionRectOut) {
// no-op
}
/**
* Returns an index used to query the color of interest from the list of extracted colors.
*/
public static int getColorIndex(Context context) {
return getColorIndex(Utilities.isDarkTheme(context));
}
/**
* Returns an index used to query the color of interest from the list of extracted colors.
* @param getDarkIndex True when dark index is wanted, False when light index is wanted.
*/
public static int getColorIndex(boolean getDarkIndex) {
return getDarkIndex ? DARK_COLOR_EXTRACTION_INDEX : LIGHT_COLOR_EXTRACTION_INDEX;
}
}