Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 08c7cd56 authored by Tony Wickham's avatar Tony Wickham
Browse files

Update undo snackbar visuals

- Use accent color for action
- Update font-family to use TextTitle style
- Reduce elevation to 3dp
- Inset snackbar left/right margins more, unless we need to increase the
  width to fit the text
- For largest display/font size, fallback to 2 lines and smaller font if
  necessary to not cut off the label
- Remove top/bottom padding on action (b/114084048)
- Allow up to 20 char for the action (b/114317987)

Change-Id: I833c102aaac3ba3db2283997c142926c3830336d
parent 447036d0
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -25,17 +25,23 @@
        android:gravity="center_vertical"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:textSize="14sp"
        android:textColor="?android:attr/textColorPrimary"/>
        android:lines="1"
        android:ellipsize="end"
        android:textSize="@dimen/snackbar_max_text_size"
        android:textColor="?android:attr/textColorPrimary"
        android:theme="@style/TextTitle"/>
    <TextView
        android:id="@+id/action"
        android:layout_height="@dimen/snackbar_content_height"
        android:layout_width="wrap_content"
        android:layout_weight="0"
        android:gravity="center"
        android:padding="8dp"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:background="?android:attr/selectableItemBackground"
        android:textStyle="bold"
        android:textColor="?android:attr/textColorPrimary"
        android:textAllCaps="true"/>
        android:textSize="@dimen/snackbar_max_text_size"
        android:textColor="?android:attr/colorAccent"
        android:theme="@style/TextTitle"
        android:capitalize="sentences"/>
</merge>
 No newline at end of file
+6 −1
Original line number Diff line number Diff line
@@ -230,5 +230,10 @@
    <dimen name="snackbar_height">48dp</dimen>
    <dimen name="snackbar_content_height">32dp</dimen>
    <dimen name="snackbar_padding">8dp</dimen>
    <dimen name="snackbar_margin">16dp</dimen>
    <dimen name="snackbar_min_margin_left_right">6dp</dimen>
    <dimen name="snackbar_max_margin_left_right">72dp</dimen>
    <dimen name="snackbar_margin_bottom">30dp</dimen>
    <dimen name="snackbar_elevation">3dp</dimen>
    <dimen name="snackbar_min_text_size">12sp</dimen>
    <dimen name="snackbar_max_text_size">14sp</dimen>
</resources>
+1 −1
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@
    <!-- Accessibility confirmation for item removed. [CHAR_LIMIT=50]-->
    <string name="item_removed">Item removed</string>

    <!-- Action shown in snackbar to undo item removal. [CHAR_LIMIT=15] -->
    <!-- Action shown in snackbar to undo item removal. [CHAR_LIMIT=20] -->
    <string name="undo">Undo</string>

    <!-- Accessibility action to move an item on the workspace. [CHAR_LIMIT=30] -->
+40 −8
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.widget.TextView;
@@ -60,7 +61,7 @@ public class Snackbar extends AbstractFloatingView {
        snackbar.setOrientation(HORIZONTAL);
        snackbar.setGravity(Gravity.CENTER_VERTICAL);
        Resources res = launcher.getResources();
        snackbar.setElevation(res.getDimension(R.dimen.deep_shortcuts_elevation));
        snackbar.setElevation(res.getDimension(R.dimen.snackbar_elevation));
        int padding = res.getDimensionPixelSize(R.dimen.snackbar_padding);
        snackbar.setPadding(padding, padding, padding, padding);
        snackbar.setBackgroundResource(R.drawable.round_rect_primary);
@@ -72,14 +73,45 @@ public class Snackbar extends AbstractFloatingView {
        DragLayer.LayoutParams params = (DragLayer.LayoutParams) snackbar.getLayoutParams();
        params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
        params.height = res.getDimensionPixelSize(R.dimen.snackbar_height);
        int margin = res.getDimensionPixelSize(R.dimen.snackbar_margin);
        int maxMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_max_margin_left_right);
        int minMarginLeftRight = res.getDimensionPixelSize(R.dimen.snackbar_min_margin_left_right);
        int marginBottom = res.getDimensionPixelSize(R.dimen.snackbar_margin_bottom);
        Rect insets = launcher.getDeviceProfile().getInsets();
        params.width = dragLayer.getWidth() - margin * 2 -  insets.left - insets.right;
        params.setMargins(0, margin + insets.top, 0, margin + insets.bottom);

        ((TextView) snackbar.findViewById(R.id.label)).setText(labelStringResId);
        ((TextView) snackbar.findViewById(R.id.action)).setText(actionStringResId);
        snackbar.findViewById(R.id.action).setOnClickListener(v -> {
        int maxWidth = dragLayer.getWidth() - minMarginLeftRight * 2 - insets.left - insets.right;
        int minWidth = dragLayer.getWidth() - maxMarginLeftRight * 2 - insets.left - insets.right;
        params.width = minWidth;
        params.setMargins(0, 0, 0, marginBottom + insets.bottom);

        TextView labelView = snackbar.findViewById(R.id.label);
        TextView actionView = snackbar.findViewById(R.id.action);
        String labelText = res.getString(labelStringResId);
        String actionText = res.getString(actionStringResId);
        int totalContentWidth = (int) (labelView.getPaint().measureText(labelText)
                + actionView.getPaint().measureText(actionText))
                + labelView.getPaddingRight() + labelView.getPaddingLeft()
                + actionView.getPaddingRight() + actionView.getPaddingLeft()
                + padding * 2;
        if (totalContentWidth > params.width) {
            // The text doesn't fit in our standard width so update width to accommodate.
            if (totalContentWidth <= maxWidth) {
                params.width = totalContentWidth;
            } else {
                // One line will be cut off, fallback to 2 lines and smaller font. (This should only
                // happen in some languages if system display and font size are set to largest.)
                int textHeight = res.getDimensionPixelSize(R.dimen.snackbar_content_height);
                float textSizePx = res.getDimension(R.dimen.snackbar_min_text_size);
                labelView.setLines(2);
                labelView.getLayoutParams().height = textHeight * 2;
                actionView.getLayoutParams().height = textHeight * 2;
                labelView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
                actionView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSizePx);
                params.height += textHeight;
                params.width = maxWidth;
            }
        }
        labelView.setText(labelText);
        actionView.setText(actionText);
        actionView.setOnClickListener(v -> {
            if (onActionClicked != null) {
                onActionClicked.run();
            }