diff --git a/android/res/layout/subscription_button.xml b/android/res/layout/subscription_button.xml new file mode 100644 index 0000000000..34216c828b --- /dev/null +++ b/android/res/layout/subscription_button.xml @@ -0,0 +1,63 @@ + + + + + + + + diff --git a/android/res/values/attrs.xml b/android/res/values/attrs.xml index 03f5cb033b..e2f86c2583 100644 --- a/android/res/values/attrs.xml +++ b/android/res/values/attrs.xml @@ -98,4 +98,10 @@ + + + + + + diff --git a/android/src/com/mapswithme/maps/widget/SubscriptionButton.java b/android/src/com/mapswithme/maps/widget/SubscriptionButton.java new file mode 100644 index 0000000000..5309d75e57 --- /dev/null +++ b/android/src/com/mapswithme/maps/widget/SubscriptionButton.java @@ -0,0 +1,111 @@ +package com.mapswithme.maps.widget; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.TextView; + +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; +import com.mapswithme.maps.R; + +public class SubscriptionButton extends FrameLayout +{ + @Nullable + private Drawable mButtonBackground; + @ColorInt + private int mButtonTextColor; + @Nullable + private Drawable mSaleBackground; + @ColorInt + private int mSaleTextColor; + @SuppressWarnings("NullableProblems") + @NonNull + private TextView mSaleView; + @SuppressWarnings("NullableProblems") + @NonNull + private TextView mNameView; + @SuppressWarnings("NullableProblems") + @NonNull + private TextView mPriceView; + + public SubscriptionButton(@NonNull Context context) + { + super(context); + } + + public SubscriptionButton(@NonNull Context context, @Nullable AttributeSet attrs) + { + super(context, attrs); + init(attrs); + } + + public SubscriptionButton(@NonNull Context context, @Nullable AttributeSet attrs, + int defStyleAttr) + { + super(context, attrs, defStyleAttr); + init(attrs); + } + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + public SubscriptionButton(@NonNull Context context, @Nullable AttributeSet attrs, + int defStyleAttr, int defStyleRes) + { + super(context, attrs, defStyleAttr, defStyleRes); + init(attrs); + } + + private void init(@Nullable AttributeSet attrs) + { + TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SubscriptionButton); + try + { + mButtonBackground = a.getDrawable(R.styleable.SubscriptionButton_buttonBackground); + mButtonTextColor = a.getColor(R.styleable.SubscriptionButton_buttonTextColor, 0); + mSaleBackground = a.getDrawable(R.styleable.SubscriptionButton_saleBackground); + mSaleTextColor = a.getColor(R.styleable.SubscriptionButton_saleTextColor, 0); + LayoutInflater.from(getContext()).inflate(R.layout.subscription_button, this, true); + } + finally + { + a.recycle(); + } + } + + @Override + protected void onFinishInflate() + { + super.onFinishInflate(); + View buttonContainer = findViewById(R.id.button_container); + buttonContainer.setBackground(mButtonBackground); + mNameView = buttonContainer.findViewById(R.id.name); + mNameView.setTextColor(mButtonTextColor); + mPriceView = buttonContainer.findViewById(R.id.price); + mPriceView.setTextColor(mButtonTextColor); + mSaleView = findViewById(R.id.sale); + mSaleView.setBackground(mSaleBackground); + mSaleView.setTextColor(mSaleTextColor); + } + + public void setName(@NonNull String name) + { + mNameView.setText(name); + } + + public void setPrice(@NonNull String price) + { + mPriceView.setText(price); + } + + public void setSale(@NonNull String sale) + { + mSaleView.setText(sale); + } +}