41 private ImageView arrow;
42 private boolean following =
false;
47 this(context, onPressed,
null);
54 this.onPressedListener = onPressed;
59 private void setupUI() {
60 setBackground(createFollowButtonBackground());
62 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
66 setOnClickListener(v -> followMePressed());
71 arrow =
new ImageView(getContext());
74 arrow.setImageDrawable(icon);
76 arrow.setImageResource(R.drawable.navigine_follow_me);
79 arrow.setImageTintList(ColorStateList.valueOf(tintColor));
81 FrameLayout.LayoutParams labelLp =
new FrameLayout.LayoutParams(
82 ViewGroup.LayoutParams.MATCH_PARENT,
83 ViewGroup.LayoutParams.MATCH_PARENT
85 addView(arrow, labelLp);
86 arrow.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
87 arrow.setAdjustViewBounds(
true);
88 arrow.setPadding(dpToPx(8), dpToPx(8), dpToPx(8), dpToPx(8));
93 private ShapeDrawable createFollowButtonBackground() {
95 int color = c.getButtonBackgroundColor() !=
null ? c.getButtonBackgroundColor() : WidgetStyles.BUTTON_BACKGROUND_COLOR;
96 float radius = dpToPx((
int) WidgetStyles.BORDER_RADIUS);
97 float[] radii =
new float[]{radius, radius, radius, radius, radius, radius, radius, radius};
99 ShapeDrawable drawable =
new ShapeDrawable(
new RoundRectShape(radii,
null,
null));
100 drawable.getPaint().setAntiAlias(
true);
101 drawable.getPaint().setColor(color);
122 private void updateAppearance() {
134 if (activeIcon !=
null) {
135 arrow.setImageDrawable(activeIcon);
137 arrow.setImageTintList(ColorStateList.valueOf(accentColor));
139 GradientDrawable borderDrawable =
new GradientDrawable();
140 borderDrawable.setShape(GradientDrawable.RECTANGLE);
141 borderDrawable.setCornerRadius(dpToPx((
int) WidgetStyles.BORDER_RADIUS));
142 borderDrawable.setColor(WidgetStyles.WHITE_BACKGROUND_COLOR);
143 borderDrawable.setStroke(dpToPx((
int) WidgetStyles.ACTIVE_BORDER_WIDTH), WidgetStyles.BORDER_COLOR);
144 setBackground(borderDrawable);
148 arrow.setImageDrawable(icon);
150 arrow.setImageResource(R.drawable.navigine_follow_me);
152 arrow.setImageTintList(ColorStateList.valueOf(textColor));
154 float radius = dpToPx((
int) WidgetStyles.BORDER_RADIUS);
155 ShapeDrawable background =
new ShapeDrawable(
new RoundRectShape(
156 new float[]{radius, radius, radius, radius, radius, radius, radius, radius},
159 background.getPaint().setAntiAlias(
true);
160 background.getPaint().setColor(bgColor);
161 setBackground(background);
165 private void followMePressed() {
166 following = !following;
169 if (onPressedListener !=
null) {
170 onPressedListener.onPressed(following);
175 protected void onMeasure(
int widthMeasureSpec,
int heightMeasureSpec) {
179 int widthSpec = MeasureSpec.makeMeasureSpec(dpToPx((
int) widthDp), MeasureSpec.EXACTLY);
180 int heightSpec = MeasureSpec.makeMeasureSpec(dpToPx((
int) heightDp), MeasureSpec.EXACTLY);
181 super.onMeasure(widthSpec, heightSpec);
184 private int dpToPx(
int dp) {
185 return (
int) (dp * getResources().getDisplayMetrics().density + 0.5f);