style: unify native top action buttons

This commit is contained in:
kris
2026-03-29 19:10:20 +08:00
parent 32960f8ecc
commit e94e91a0f7
4 changed files with 101 additions and 30 deletions

View File

@@ -0,0 +1,55 @@
package com.hyzq.boss;
import static org.junit.Assert.assertEquals;
import android.content.Context;
import android.util.TypedValue;
import android.widget.Button;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
@Config(sdk = 34)
public class BossUiTopActionStyleTest {
@Test
public void applyCompactTopActionStyle_usesWechatLikeIconSizing() {
Context context = RuntimeEnvironment.getApplication();
Button button = new Button(context);
BossUi.applyTopActionButtonStyle(context, button, BossUi.TopActionButtonStyle.COMPACT_ICON);
assertEquals(context.getColor(R.color.boss_text_primary), button.getCurrentTextColor());
assertEquals(BossUi.dp(context, 38), button.getMinWidth());
assertEquals(BossUi.dp(context, 36), button.getMinHeight());
assertEquals(BossUi.dp(context, 12), button.getPaddingLeft());
assertEquals(BossUi.dp(context, 6), button.getPaddingTop());
assertEquals(
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20, context.getResources().getDisplayMetrics()),
button.getTextSize(),
0.01f
);
}
@Test
public void applySecondaryTopActionStyle_usesDarkTextAndTightPadding() {
Context context = RuntimeEnvironment.getApplication();
Button button = new Button(context);
BossUi.applyTopActionButtonStyle(context, button, BossUi.TopActionButtonStyle.SECONDARY_TEXT);
assertEquals(context.getColor(R.color.boss_text_primary), button.getCurrentTextColor());
assertEquals(0, button.getMinWidth());
assertEquals(0, button.getMinHeight());
assertEquals(BossUi.dp(context, 12), button.getPaddingLeft());
assertEquals(BossUi.dp(context, 8), button.getPaddingTop());
assertEquals(
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 14, context.getResources().getDisplayMetrics()),
button.getTextSize(),
0.01f
);
}
}