diff --git a/res/drawable/ic_plus.xml b/res/drawable/ic_plus.xml index 3ab926aade..d004f429ca 100644 --- a/res/drawable/ic_plus.xml +++ b/res/drawable/ic_plus.xml @@ -14,7 +14,7 @@ limitations under the License. --> diff --git a/res/layout/widget_cell_content.xml b/res/layout/widget_cell_content.xml index f4bfebd59a..462bb52aab 100644 --- a/res/layout/widget_cell_content.xml +++ b/res/layout/widget_cell_content.xml @@ -104,8 +104,9 @@ android:gravity="center" android:visibility="gone" android:drawableStart="@drawable/ic_plus" - android:drawablePadding="8dp" + android:drawablePadding="@dimen/widget_cell_add_button_drawable_padding" android:drawableTint="?attr/widgetPickerAddButtonTextColor" + android:maxLines="1" android:background="@drawable/widget_cell_add_button_background" /> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 50a0aa1618..4e5ef12c1b 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -192,11 +192,14 @@ 8dp 48dp 8dp + 16dp 16dp 24dp 14sp 500 20sp + 8dp + 19dp 4dp 16dp diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java index 6dcaf757b4..5dacfb0b23 100644 --- a/src/com/android/launcher3/widget/WidgetCell.java +++ b/src/com/android/launcher3/widget/WidgetCell.java @@ -29,6 +29,7 @@ import android.animation.ObjectAnimator; import android.animation.TimeInterpolator; import android.content.Context; import android.graphics.Bitmap; +import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.text.TextUtils; import android.util.AttributeSet; @@ -544,11 +545,46 @@ public class WidgetCell extends LinearLayout { if (mIsShowingAddButton) return; mIsShowingAddButton = true; + setupIconOrTextButton(); mWidgetAddButton.setOnClickListener(callback); fadeThrough(/* hide= */ mWidgetTextContainer, /* show= */ mWidgetAddButton, ADD_BUTTON_FADE_DURATION_MS, Interpolators.LINEAR); } + /** + * Depending on the width of the cell, set up the add button to be icon-only or icon+text. + */ + private void setupIconOrTextButton() { + String addText = getResources().getString(R.string.widget_add_button_label); + Rect textSize = new Rect(); + mWidgetAddButton.getPaint().getTextBounds(addText, 0, addText.length(), textSize); + int startPadding = getResources() + .getDimensionPixelSize(R.dimen.widget_cell_add_button_start_padding); + int endPadding = getResources() + .getDimensionPixelSize(R.dimen.widget_cell_add_button_end_padding); + int drawableWidth = getResources() + .getDimensionPixelSize(R.dimen.widget_cell_add_button_drawable_width); + int drawablePadding = getResources() + .getDimensionPixelSize(R.dimen.widget_cell_add_button_drawable_padding); + int textButtonWidth = textSize.width() + startPadding + endPadding + drawableWidth + + drawablePadding; + if (textButtonWidth > getMeasuredWidth()) { + // Setup icon-only button + mWidgetAddButton.setText(null); + int startIconPadding = getResources() + .getDimensionPixelSize(R.dimen.widget_cell_add_icon_button_start_padding); + mWidgetAddButton.setPaddingRelative(/* start= */ startIconPadding, /* top= */ 0, + /* end= */ endPadding, /* bottom= */ 0); + mWidgetAddButton.setCompoundDrawablePadding(0); + } else { + // Setup icon + text button + mWidgetAddButton.setText(addText); + mWidgetAddButton.setPaddingRelative(/* start= */ startPadding, /* top= */ 0, + /* end= */ endPadding, /* bottom= */ 0); + mWidgetAddButton.setCompoundDrawablePadding(drawablePadding); + } + } + /** * Hide tap to add button. */