|
|
@@ -0,0 +1,134 @@
|
|
|
+package hr.tacitus.componentpack.layouts;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.content.res.TypedArray;
|
|
|
+import android.support.constraint.ConstraintLayout;
|
|
|
+import android.support.v4.content.ContextCompat;
|
|
|
+import android.util.AttributeSet;
|
|
|
+import android.util.TypedValue;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import hr.tacitus.componentpack.R;
|
|
|
+import hr.tacitus.componentpack.views.ArcView;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by Bero on 7.7.2017..
|
|
|
+ */
|
|
|
+
|
|
|
+public class StatsBoundsLayout extends ConstraintLayout {
|
|
|
+ private String textMinimum = "Min";
|
|
|
+ private String textMaximum = "Max";
|
|
|
+ private String textAverage = "Average";
|
|
|
+ private float textSize;
|
|
|
+
|
|
|
+ private ConstraintLayout layoutView;
|
|
|
+
|
|
|
+ private TextView tvAverage;
|
|
|
+ private TextView tvMinimum;
|
|
|
+ private TextView tvMaximum;
|
|
|
+
|
|
|
+ private ArcView arcView;
|
|
|
+
|
|
|
+ public StatsBoundsLayout(Context context) {
|
|
|
+ super(context);
|
|
|
+ init(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public StatsBoundsLayout(Context context, AttributeSet attrs) {
|
|
|
+ super(context, attrs);
|
|
|
+ init(attrs);
|
|
|
+ }
|
|
|
+
|
|
|
+ public StatsBoundsLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
+ super(context, attrs, defStyleAttr);
|
|
|
+ init(attrs);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void inflateView() {
|
|
|
+ layoutView = (ConstraintLayout) inflate(getContext(), R.layout.view_stats_bounds, this);
|
|
|
+// LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
+// layoutView = (ConstraintLayout) layoutInflater.inflate(R.layout.view_stats_bounds, this, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getComponents() {
|
|
|
+ arcView = (ArcView) findViewById(R.id.arcView);
|
|
|
+ tvAverage = (TextView) findViewById(R.id.tvAverage);
|
|
|
+ tvMinimum = (TextView) findViewById(R.id.tvMinimum);
|
|
|
+ tvMaximum = (TextView) findViewById(R.id.tvMaximum);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void readParameters(AttributeSet attributeSet) {
|
|
|
+ TypedArray a = getContext().obtainStyledAttributes(attributeSet, R.styleable.StatsBoundsLayout);
|
|
|
+ if (a != null) {
|
|
|
+ try {
|
|
|
+ textAverage = a.getString(R.styleable.StatsBoundsLayout_textAverage);
|
|
|
+ if (textAverage == null)
|
|
|
+ textAverage = "Average";
|
|
|
+
|
|
|
+ textMinimum = a.getString(R.styleable.StatsBoundsLayout_textMinimum);
|
|
|
+ if (textMinimum == null)
|
|
|
+ textMinimum = "Min";
|
|
|
+
|
|
|
+ textMaximum = a.getString(R.styleable.StatsBoundsLayout_textMaximum);
|
|
|
+ if (textMaximum == null)
|
|
|
+ textMaximum = "Max";
|
|
|
+
|
|
|
+ textSize = a.getDimension(R.styleable.StatsBoundsLayout_textSize, 0.f);
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ a.recycle();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onMeasure(int w, int h) {
|
|
|
+ super.onMeasure(w, h);
|
|
|
+
|
|
|
+// int parentWidth = MeasureSpec.getSize(w);
|
|
|
+// int parentHeight = MeasureSpec.getSize(h);
|
|
|
+//
|
|
|
+// measureChildren(MeasureSpec.makeMeasureSpec(parentWidth, MeasureSpec.EXACTLY), h);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initComponents() {
|
|
|
+ if (textSize != 0.f) {
|
|
|
+ TextView[] tvs = {tvAverage, tvMinimum, tvMaximum};
|
|
|
+ for (TextView tv : tvs) {
|
|
|
+ tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tvAverage.setText(textAverage);
|
|
|
+ tvMinimum.setText(textMinimum);
|
|
|
+ tvMaximum.setText(textMaximum);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void init(AttributeSet attributeSet) {
|
|
|
+ inflateView();
|
|
|
+ getComponents();
|
|
|
+
|
|
|
+ if (attributeSet != null)
|
|
|
+ readParameters(attributeSet);
|
|
|
+
|
|
|
+ initComponents();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArcView getArcView() {
|
|
|
+ return arcView;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setAverageText(String text) {
|
|
|
+ tvAverage.setText(text);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setMinimumText(String text) {
|
|
|
+ tvMinimum.setText(text);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setMaximumText(String text) {
|
|
|
+ tvMaximum.setText(text);
|
|
|
+ }
|
|
|
+}
|