Berislav před 9 roky
rodič
revize
2fbd5c4b5c

+ 2 - 1
app/build.gradle

@@ -4,7 +4,7 @@ apply plugin: 'maven-publish'
 
 def libraryGroupId = 'hr.tacitus.components'
 def libraryArtifactId = 'tankers-components'
-def libraryVersion = '0.0.1'
+def libraryVersion = '0.0.4'
 
 android {
     compileSdkVersion 25
@@ -25,6 +25,7 @@ android {
 }
 
 dependencies {
+    compile 'com.android.support.constraint:constraint-layout:1.0.2'
     compile fileTree(dir: 'libs', include: ['*.jar'])
     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
         exclude group: 'com.android.support', module: 'support-annotations'

+ 18 - 0
app/src/main/java/hr/tacitus/componentpack/Utils.java

@@ -0,0 +1,18 @@
+package hr.tacitus.componentpack;
+
+import android.content.res.Resources;
+import android.util.TypedValue;
+import android.view.WindowManager;
+
+/**
+ * Created by Bero on 7.7.2017..
+ */
+
+public class Utils {
+
+    public static float dipToPixels(float dips) {
+        Resources r = Resources.getSystem();
+        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dips, r.getDisplayMetrics());
+    }
+
+}

+ 134 - 0
app/src/main/java/hr/tacitus/componentpack/layouts/StatsBoundsLayout.java

@@ -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);
+    }
+}

+ 43 - 1
app/src/main/java/hr/tacitus/componentpack/ArcView.java → app/src/main/java/hr/tacitus/componentpack/views/ArcView.java

@@ -1,4 +1,4 @@
-package hr.tacitus.componentpack;
+package hr.tacitus.componentpack.views;
 
 import android.content.Context;
 import android.content.pm.PackageManager;
@@ -13,6 +13,11 @@ import android.util.AttributeSet;
 import android.view.View;
 import android.view.ViewTreeObserver;
 
+import java.io.UTFDataFormatException;
+
+import hr.tacitus.componentpack.R;
+import hr.tacitus.componentpack.Utils;
+
 /**
  * Created by Bero on 6.7.2017..
  */
@@ -24,6 +29,9 @@ public class ArcView extends View {
     private int backgroundColor = Color.BLACK;
     private float arcWidthInPixels = 32;
 
+    private int intrinsicWidth = (int)Utils.dipToPixels(180);
+    private int intrinsicHeight = (int)Utils.dipToPixels(90);
+
     private Paint arcPaint;
     private Paint canvasPaint;
     private RectF arcRect, subArcRect;
@@ -95,6 +103,40 @@ public class ArcView extends View {
         });
     }
 
+    @Override
+    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
+        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
+        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
+        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
+
+        int width, height;
+
+        switch (widthMode) {
+            case MeasureSpec.EXACTLY:
+                width = widthSize;
+                break;
+            case MeasureSpec.AT_MOST:
+                width = Math.min(intrinsicWidth, widthSize);
+                break;
+            default:
+                width = intrinsicWidth;
+        }
+
+        switch (heightMode) {
+            case MeasureSpec.EXACTLY:
+                height = heightSize;
+                break;
+            case MeasureSpec.AT_MOST:
+                height = Math.min(intrinsicHeight, heightSize);
+                break;
+            default:
+                height = intrinsicHeight;
+        }
+
+        setMeasuredDimension(width, height);
+    }
+
     @Override
     public void onDraw(Canvas canvas) {
         canvas.drawPaint(canvasPaint);

+ 62 - 0
app/src/main/res/layout/view_stats_bounds.xml

@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    tools:layout_editor_absoluteX="0dp"
+    tools:layout_editor_absoluteY="81dp">
+
+    <TextView
+        android:id="@+id/tvAverage"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="8dp"
+        android:layout_marginStart="8dp"
+        android:text="TextView"
+        app:layout_constraintTop_toTopOf="parent"
+        android:layout_marginTop="0dp"
+        android:layout_marginRight="8dp"
+        app:layout_constraintRight_toRightOf="parent"
+        android:layout_marginLeft="8dp"
+        app:layout_constraintLeft_toLeftOf="parent" />
+
+    <hr.tacitus.componentpack.views.ArcView
+        tools:layout_width="180dp"
+        tools:layout_height="60dp"
+        android:id="@+id/arcView"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        app:backgroundColor="?android:colorBackground"
+        android:layout_marginTop="0dp"
+        app:layout_constraintTop_toBottomOf="@+id/tvAverage"
+        android:layout_marginLeft="8dp"
+        app:layout_constraintLeft_toLeftOf="parent"
+        android:layout_marginRight="8dp"
+        app:layout_constraintRight_toRightOf="parent" />
+
+    <TextView
+        android:id="@+id/tvMinimum"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="TextView"
+        android:layout_marginTop="0dp"
+        app:layout_constraintTop_toBottomOf="@+id/arcView"
+        android:layout_marginLeft="0dp"
+        app:layout_constraintLeft_toLeftOf="@+id/arcView"
+        app:layout_constraintRight_toLeftOf="@+id/arcView"
+        android:layout_marginRight="0dp" />
+
+    <TextView
+        android:id="@+id/tvMaximum"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="TextView"
+        android:layout_marginTop="0dp"
+        app:layout_constraintTop_toBottomOf="@+id/arcView"
+        android:layout_marginRight="0dp"
+        app:layout_constraintRight_toRightOf="@+id/arcView"
+        app:layout_constraintLeft_toRightOf="@+id/arcView"
+        android:layout_marginLeft="0dp" />
+
+</android.support.constraint.ConstraintLayout>

+ 7 - 0
app/src/main/res/values/attrs.xml

@@ -5,4 +5,11 @@
         <attr name="arcWidth" format="dimension" />
         <attr name="backgroundColor" format="color" />
     </declare-styleable>
+
+    <declare-styleable name="StatsBoundsLayout">
+        <attr name="textAverage" format="string" />
+        <attr name="textMinimum" format="string" />
+        <attr name="textMaximum" format="string" />
+        <attr name="textSize" format="dimension" />
+    </declare-styleable>
 </resources>

+ 3 - 3
componentsactivity/build.gradle

@@ -1,13 +1,13 @@
 apply plugin: 'com.android.application'
 
 android {
-    compileSdkVersion 26
+    compileSdkVersion 25
     buildToolsVersion "25.0.3"
 
     defaultConfig {
         applicationId "hr.tacitus.componentsactivity"
         minSdkVersion 19
-        targetSdkVersion 26
+        targetSdkVersion 25
         versionCode 1
         versionName "1.0"
 
@@ -27,7 +27,7 @@ dependencies {
     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
         exclude group: 'com.android.support', module: 'support-annotations'
     })
-    compile 'com.android.support:appcompat-v7:26.+'
+    compile 'com.android.support:appcompat-v7:25.+'
     compile 'com.android.support.constraint:constraint-layout:1.0.2'
     testCompile 'junit:junit:4.12'
     compile project(':app')

+ 7 - 0
componentsactivity/src/main/java/hr/tacitus/componentsactivity/MainActivity.java

@@ -3,11 +3,18 @@ package hr.tacitus.componentsactivity;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 
+import hr.tacitus.componentpack.layouts.StatsBoundsLayout;
+
 public class MainActivity extends AppCompatActivity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
+
+        StatsBoundsLayout layout = (StatsBoundsLayout) findViewById(R.id.statsBounds);
+        layout.setAverageText("Avg: 5.68 L/100km");
+        layout.setMaximumText("Max: 7.45 L/100km");
+        layout.setMinimumText("Min: 4.84 L/100km");
     }
 }

+ 31 - 15
componentsactivity/src/main/res/layout/activity_main.xml

@@ -1,24 +1,40 @@
 <?xml version="1.0" encoding="utf-8"?>
-<android.support.constraint.ConstraintLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
-    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
-    android:layout_height="match_parent" tools:context="hr.tacitus.componentsactivity.MainActivity">
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context="hr.tacitus.componentsactivity.MainActivity">
 
-    <hr.tacitus.componentpack.ArcView
-        android:paddingTop="6dp"
-        android:paddingStart="10dp"
-        android:paddingEnd="10dp"
+    <hr.tacitus.componentpack.views.ArcView
+        android:id="@+id/arcView2"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="8dp"
+        android:layout_marginLeft="8dp"
+        android:layout_marginRight="8dp"
+        android:layout_marginStart="8dp"
+        android:layout_marginTop="40dp"
         android:paddingBottom="6dp"
-        android:layout_width="150dp"
-        android:layout_height="80dp"
-        app:layout_constraintTop_toTopOf="parent"
-        app:backgroundColor="?android:colorBackground"
+        android:paddingEnd="10dp"
+        android:paddingStart="10dp"
+        android:paddingTop="6dp"
         app:arcWidth="8dp"
-        android:layout_marginTop="37dp"
-        android:layout_marginRight="8dp"
+        app:backgroundColor="?android:colorBackground"
+        app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <hr.tacitus.componentpack.layouts.StatsBoundsLayout
+        android:id="@+id/statsBounds"
+        android:layout_width="wrap_content"
+        android:layout_height="60dp"
         android:layout_marginLeft="8dp"
-        app:layout_constraintLeft_toLeftOf="parent" />
+        android:layout_marginRight="8dp"
+        android:layout_marginTop="89dp"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/arcView2"
+        app:textSize="10sp" />
 
 </android.support.constraint.ConstraintLayout>