9 İşlemeler ae52ec5430 ... 2fc9aa8826

Yazar SHA1 Mesaj Tarih
  Berislav 2fc9aa8826 Fixed bug for PieChart colorProvider adapterChange() 9 yıl önce
  Berislav ab517c3b1e Support for multiline legend 9 yıl önce
  Berislav b564d82df8 Pie Chart updates 9 yıl önce
  Berislav deec1fd95b Centering legend 9 yıl önce
  Berislav 092501b6d7 Added pie chart adapter and color provider 9 yıl önce
  Berislav e251f998c3 Adjusted chart padding 9 yıl önce
  Berislav e8a3eccf33 Update chart calculation 9 yıl önce
  Berislav 0f310c2c4b Legend updates in PieChart 9 yıl önce
  Berislav 50e979cadf Updated library version 9 yıl önce

+ 1 - 1
.idea/misc.xml

@@ -37,7 +37,7 @@
     <ConfirmationsSetting value="0" id="Add" />
     <ConfirmationsSetting value="0" id="Remove" />
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">

+ 4 - 4
app/build.gradle

@@ -4,14 +4,14 @@ apply plugin: 'maven-publish'
 
 def libraryGroupId = 'hr.tacitus.graphs'
 def libraryArtifactId = 'android-graphs'
-def libraryVersion = '0.0.5'
+def libraryVersion = '0.0.12'
 
 android {
-    compileSdkVersion 26
+    compileSdkVersion 25
     buildToolsVersion "25.0.3"
     defaultConfig {
         minSdkVersion 19
-        targetSdkVersion 26
+        targetSdkVersion 25
         versionCode 1
         versionName libraryVersion
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -29,7 +29,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.+'
     testCompile 'junit:junit:4.12'
 }
 

+ 13 - 0
app/src/main/java/hr/tacitus/graphs/PieChartAdapter.java

@@ -0,0 +1,13 @@
+package hr.tacitus.graphs;
+
+/**
+ * Created by Bero on 9.7.2017..
+ */
+
+public interface PieChartAdapter {
+    int getCount();
+
+    String getDescription(int position);
+    float getValue(int position);
+    String getValueDescription(int position);
+}

+ 9 - 0
app/src/main/java/hr/tacitus/graphs/PieChartColorProvider.java

@@ -0,0 +1,9 @@
+package hr.tacitus.graphs;
+
+/**
+ * Created by Bero on 9.7.2017..
+ */
+
+public interface PieChartColorProvider {
+    int getColor(int position);
+}

+ 483 - 0
app/src/main/java/hr/tacitus/graphs/PieChartView.java

@@ -0,0 +1,483 @@
+package hr.tacitus.graphs;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.RectF;
+import android.support.annotation.Nullable;
+import android.text.Layout;
+import android.text.StaticLayout;
+import android.text.TextPaint;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.View;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static android.R.attr.ellipsize;
+import static android.R.attr.value;
+
+/**
+ * Created by Bero on 7.7.2017..
+ */
+
+public class PieChartView extends View {
+
+    class PieChartItem {
+        float value;
+        // color for this pie chart item
+        Paint paint;
+        // text
+        String description;
+
+        // cached value
+        int descriptionWidth;
+        StaticLayout descriptionLayout;
+
+        String valueDescription;
+        int valueDescriptionWidth;
+        int valueDescriptionHeight;
+
+        float getAngle() {
+            return value * 3.6f;
+        }
+    }
+
+    private static float MAX_LEGEND_WIDTH_PERCENTAGE = 35f;
+    private static float MAX_LEGEND_WIDTH_PX = 300;
+    private static float LEGEND_PADDING_HORIZONTAL = 20f;
+    private static float LEGEND_PADDING_TOP = 20f;
+
+    private float titleTextSizeSp = 16.f;
+
+    private boolean showLegend = true;
+    private float legendTextSizeSp = 10.f;
+    private float legendSquareSize = 20f;
+    private float legendWidth;
+    private float legendMaxTextWidth;
+
+    private float CHART_PADDING_DP = 24.f;
+    private float chartTextSizeSp = 10.f;
+    private float chartPaddingPx;
+
+    private PieChartAdapter adapter;
+    private PieChartColorProvider colorProvider;
+
+    private String title;
+
+    private List<Integer> colors;
+
+    private int textColor;
+
+    private TextPaint titlePaint;
+    private TextPaint valuePaint;
+    private TextPaint legendDescriptionPaint;
+    private StaticLayout titleTextLayout;
+
+    private RectF titleRect;
+    private RectF legendRect;
+    private RectF pieChartRect;
+
+    private List<PieChartItem> items = new ArrayList<>();
+
+    private boolean readyToDraw = false;
+
+    public PieChartView(Context context) {
+        super(context);
+        init(null);
+    }
+
+    public PieChartView(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        init(attrs);
+    }
+
+    public PieChartView(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        init(attrs);
+    }
+
+    private void readAttributes(AttributeSet attributeSet) {
+        TypedArray a = getContext().obtainStyledAttributes(attributeSet, R.styleable.PieChartView);
+        if (a != null) {
+            try {
+                title = a.getString(R.styleable.PieChartView_title);
+                showLegend = a.getBoolean(R.styleable.PieChartView_showLegend, true);
+                textColor = a.getColor(R.styleable.PieChartView_textColor, Color.BLACK);
+            } finally {
+                a.recycle();
+            }
+        }
+    }
+
+    private float getLegendHeight() {
+        if (!showLegend) {
+            return 0;
+        }
+
+        float height = 0;
+        for (PieChartItem item : items) {
+            height += item.descriptionLayout.getHeight();
+            Log.d("SL-HEIGHT-2", String.format("%d", item.descriptionLayout.getHeight()));
+        }
+        return height;
+    }
+
+    @Nullable
+    private RectF getLegendRect() {
+        if (showLegend) {
+            float legendHeight = getLegendHeight() + 2 * LEGEND_PADDING_TOP;
+
+            float left = getRight() - legendWidth;
+            float right = getRight(); // titleRect.right;
+            float top = titleRect != null ? titleRect.bottom : 0;
+            float bottom = getHeight() - top;
+
+            RectF rect = new RectF(left, top, right, bottom);
+            float centerY = rect.centerY();
+
+            rect.top = centerY - legendHeight / 2;
+            if (rect.top <= LEGEND_PADDING_TOP) {
+                rect.top = LEGEND_PADDING_TOP;
+            }
+
+            rect.bottom = centerY + legendHeight / 2;
+            if (rect.bottom >= getHeight() - top - LEGEND_PADDING_TOP) {
+                rect.bottom = getHeight() - top - LEGEND_PADDING_TOP;
+            }
+
+            return rect;
+        }
+        return null;
+    }
+
+    private RectF getPieChartRect() {
+        // Pie chart max rectangle
+        float left = getPaddingLeft() + chartPaddingPx;
+        float top = (titleRect != null ? titleRect.bottom : 0) + chartPaddingPx;
+        float right = getWidth() - getPaddingRight() - chartPaddingPx;
+        if (showLegend)
+            right -= legendRect.width();
+        float bottom = getHeight() - getPaddingBottom() - chartPaddingPx;
+        RectF rectF = new RectF(left, top, right, bottom);
+        // width must be equal to height
+        if (rectF.width() != rectF.height()) {
+            float width = Math.min(rectF.width(), rectF.height());
+            left = rectF.centerX() - width / 2;
+            right = left + width;
+            top = rectF.centerY() - width / 2;
+            bottom = top + width;
+
+            rectF = new RectF(left, top, right, bottom);
+        }
+
+        return rectF;
+    }
+
+    private RectF getTitleRect() {
+        if (title != null)
+            return new RectF(getPaddingLeft(), getPaddingTop(),
+                    getWidth() - getPaddingRight(), 32.f);
+        return null;
+    }
+
+    private void initTitleText() {
+        // int width = (int) titlePaint.measureText(title);
+        if (titleRect != null) {
+            titleTextLayout = new StaticLayout(title, titlePaint, (int) titleRect.width(),
+                    Layout.Alignment.ALIGN_CENTER, 1.0f, 0, false);
+        }
+        else {
+            titleTextLayout = null;
+        }
+    }
+
+    private void init(AttributeSet attributeSet) {
+        chartPaddingPx = Utils.dipsToPixels(CHART_PADDING_DP, getResources());
+
+        if (attributeSet != null)
+            readAttributes(attributeSet);
+
+        titlePaint = new TextPaint();
+        titlePaint.setAntiAlias(true);
+        titlePaint.setTextSize(Utils.spsToPixels(titleTextSizeSp, getResources()));
+        titlePaint.setColor(textColor);
+
+        valuePaint = new TextPaint();
+        valuePaint.setAntiAlias(true);
+        valuePaint.setTextSize(Utils.spsToPixels(chartTextSizeSp, getResources()));
+        valuePaint.setColor(textColor);
+
+        legendDescriptionPaint = new TextPaint();
+        legendDescriptionPaint.setAntiAlias(true);
+        legendDescriptionPaint.setTextSize(Utils.spsToPixels(legendTextSizeSp, getResources()));
+        legendDescriptionPaint.setColor(textColor);
+    }
+
+    private void initRectangles() {
+        titleRect = getTitleRect();
+        if (showLegend) {
+            updateLegendWidth();
+        }
+        legendRect = getLegendRect();
+        pieChartRect = getPieChartRect();
+    }
+
+    private void drawTitle(Canvas canvas) {
+        if (titleTextLayout != null)
+            titleTextLayout.draw(canvas);
+    }
+
+    private void drawChart(Canvas canvas) {
+//        Paint p = new Paint();
+//        p.setColor(Color.CYAN);
+//        canvas.drawRect(pieChartRect, p);
+
+        if (items.size() == 0) {
+            int width = titleRect != null ? (int)titleRect.width() : getWidth();
+
+            StaticLayout staticLayout = new StaticLayout("No data available", valuePaint, width, Layout.Alignment.ALIGN_CENTER,
+                    0, 0, false);
+
+            canvas.save();
+            canvas.translate(0, pieChartRect.top);
+
+            staticLayout.draw(canvas);
+
+            canvas.restore();
+            return;
+        }
+
+        float startAngle = -90.f;
+        for (PieChartItem item : items) {
+            canvas.drawArc(pieChartRect, startAngle, item.getAngle(), true, item.paint);
+            startAngle += item.getAngle();
+        }
+
+        startAngle = 90.f;
+        for (PieChartItem item : items) {
+            if (item.valueDescription == null)
+                continue;
+
+            float angleMiddle = startAngle - item.getAngle() / 2;
+            float r = pieChartRect.width() / 2;
+            float x = (float) Math.cos(Math.toRadians(angleMiddle)) * r;
+            float y = (float) Math.sin(Math.toRadians(angleMiddle)) * r;
+
+            float left = x + pieChartRect.centerX();
+            float top = pieChartRect.centerY() - y;
+
+            // Adjust text position based on quadrant.
+            // negative x have left shift by valueDescriptionWidth
+            float modAngle = (angleMiddle + 360) % 360;
+            if (modAngle > 90 && modAngle < 270) {
+                left -= item.valueDescriptionWidth;
+            }
+
+            // TODO: left padding?
+            if (left < 0)
+                left = 0;
+
+            // negative y have top shift by text height
+            if ((angleMiddle + 360) % 360 > 180) {
+                top += item.valueDescriptionHeight;
+            }
+
+            canvas.drawText(item.valueDescription, left, top, valuePaint);
+
+            startAngle -= item.getAngle();
+        }
+    }
+
+    private void drawLegend(Canvas canvas) {
+//        Paint p = new Paint();
+//        p.setColor(Color.RED);
+//        canvas.drawRect(legendRect, p);
+
+        float left = legendRect.left + LEGEND_PADDING_HORIZONTAL;
+        float top = legendRect.top + LEGEND_PADDING_TOP;
+
+        // Draw color explanations
+        for (int i = 0; i < items.size(); ++i) {
+            PieChartItem item = items.get(i);
+
+            canvas.drawRect(new RectF(left, top, left + legendSquareSize, top + legendSquareSize), item.paint);
+
+//            StaticLayout staticLayout = new StaticLayout(item.description,
+//                    0, item.description.length(),
+//                    legendDescriptionPaint, item.descriptionWidth,
+//                    Layout.Alignment.ALIGN_NORMAL, 0, 0, false, TextUtils.TruncateAt.END, (int)legendMaxTextWidth);
+
+//            StaticLayout staticLayout = new StaticLayout(item.description, legendDescriptionPaint,
+//                    (int)legendMaxTextWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false);
+//
+//            Log.d("SL-HEIGHT", String.format("%d", staticLayout.getHeight()));
+
+            canvas.save();
+            canvas.translate(left + (legendSquareSize * 1.5f), top);
+            item.descriptionLayout.draw(canvas);
+
+            // staticLayout.draw(canvas);
+
+            canvas.restore();
+
+            top += item.descriptionLayout.getHeight();
+        }
+    }
+
+    @Override
+    public void onDraw(Canvas canvas) {
+        if (!readyToDraw)
+            return;
+
+        drawTitle(canvas);
+        drawChart(canvas);
+        if (showLegend)
+            drawLegend(canvas);
+    }
+
+    @Override
+    public void onSizeChanged(int xNew, int yNew, int xOld, int yOld) {
+        super.onSizeChanged(xNew, yNew, xOld, yOld);
+
+        adapterChanged();
+//        initRectangles();
+//        initTitleText();
+
+        readyToDraw = true;
+    }
+
+    private void initColors() {
+        colors = new ArrayList<>();
+        int count = adapter.getCount();
+        if (colorProvider != null) {
+            for (int i = 0; i < adapter.getCount(); ++i) {
+                colors.add(colorProvider.getColor(i));
+            }
+        }
+        else {
+            // 3 sets of 2 main colors - rb, rg, bg
+            int maxValue = 220;
+            int perSetGain = (int) (maxValue / (Math.ceil(count / 6.) + 1));
+
+            float r = maxValue, g = 0, b = 0;
+            for (int i = 0; i < count; ++i) {
+                int color = Color.rgb((int) r, (int) g, (int) b);
+                colors.add(color);
+
+                r = Color.green(color);
+                g = Color.blue(color);
+                b = Color.red(color);
+
+                if (i != 0 && (i + 1) % 3 == 0) {
+                    if (i == 2) {
+                        g = maxValue;
+                    } else {
+                        r -= perSetGain;
+                    }
+                }
+            }
+        }
+    }
+
+    private void createItems() {
+        for (int i = 0; i < adapter.getCount(); ++i) {
+            PieChartItem pieChartItem = new PieChartItem();
+            pieChartItem.value = adapter.getValue(i);
+            pieChartItem.paint = new Paint(Paint.ANTI_ALIAS_FLAG);
+            pieChartItem.paint.setColor(colors.get(i));
+            pieChartItem.description = adapter.getDescription(i);
+            pieChartItem.valueDescription = adapter.getValueDescription(i);
+
+            if (pieChartItem.description != null) {
+                pieChartItem.descriptionWidth = Utils.textWidth(pieChartItem.description, legendDescriptionPaint, true);
+            }
+            if (pieChartItem.valueDescription != null) {
+                pieChartItem.valueDescriptionWidth = Utils.textWidth(pieChartItem.valueDescription, valuePaint, true);
+                pieChartItem.valueDescriptionHeight = Utils.textHeight(pieChartItem.valueDescription, valuePaint);
+            }
+
+            items.add(pieChartItem);
+        }
+    }
+
+    private float getMaxLegendWidth() {
+        float width = getWidth();
+        float maxPercWidth = width * MAX_LEGEND_WIDTH_PERCENTAGE;
+        return Math.min(maxPercWidth, MAX_LEGEND_WIDTH_PX);
+    }
+
+    /**
+     * Calculates required legend width.
+     */
+    private void updateLegendWidth() {
+        float maxWidth = getMaxLegendWidth();
+
+        legendWidth = 0;
+        for (PieChartItem item : items) {
+            float width = item.descriptionWidth + 2 * LEGEND_PADDING_HORIZONTAL + legendSquareSize * 1.5f;
+            if (width > legendWidth)
+                legendWidth = width;
+
+            if (legendWidth >= maxWidth) {
+                legendWidth = maxWidth;
+                break;
+            }
+        }
+
+        if (legendWidth > 0) {
+            legendMaxTextWidth = legendWidth - 2 * LEGEND_PADDING_HORIZONTAL - legendSquareSize * 1.5f;
+        }
+
+        for (PieChartItem item : items) {
+            item.descriptionLayout = new StaticLayout(item.description, legendDescriptionPaint,
+                    (int)legendMaxTextWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false);
+        }
+    }
+
+    public PieChartAdapter getAdapter() {
+        return adapter;
+    }
+
+    public void setAdapter(PieChartAdapter adapter) {
+        this.adapter = adapter;
+
+        adapterChanged();
+    }
+
+    public void setColorProvider(PieChartColorProvider colorProvider) {
+        this.colorProvider = colorProvider;
+    }
+
+    private void adapterChanged() {
+        items.clear();
+
+        if (adapter != null) {
+            initColors();
+            createItems();
+        }
+
+        initRectangles();
+        initTitleText();
+
+        invalidate();
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+
+        adapterChanged();
+    }
+
+    public void notifyDatasetChanged() {
+        adapterChanged();
+    }
+}

+ 54 - 0
app/src/main/java/hr/tacitus/graphs/Utils.java

@@ -0,0 +1,54 @@
+package hr.tacitus.graphs;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.util.TypedValue;
+
+/**
+ * Created by Bero on 8.7.2017..
+ */
+
+public class Utils {
+
+    public static float dipsToPixels(float dips) {
+        return dipsToPixels(dips, Resources.getSystem());
+    }
+
+    public static float dipsToPixels(float dips, Resources resources) {
+        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dips, resources.getDisplayMetrics());
+    }
+
+    public static float spsToPixels(float sps, Resources resources) {
+        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sps, resources.getDisplayMetrics());
+    }
+
+    public static Rect textBounds(String text, Paint paint) {
+        Rect bounds = new Rect();
+        paint.getTextBounds(text, 0, text.length(), bounds);
+        return bounds;
+    }
+
+    public static int textHeight(String text, Paint paint) {
+        return textBounds(text, paint).height();
+    }
+
+    /**
+     *
+     * https://stackoverflow.com/questions/7549182/android-paint-measuretext-vs-gettextbounds
+     *
+     * @param text content
+     * @param paint text paint
+     * @param useMeasureText measureText returns slightly different result, including so called
+     *                       Glyphs's AdvanceX value. So measureText() >(=?) getTextBounds' width().
+     * @return text width
+     */
+    public static int textWidth(String text, Paint paint, boolean useMeasureText) {
+        if (useMeasureText)
+            return (int)Math.ceil(paint.measureText(text));
+        return textBounds(text, paint).width();
+    }
+
+}

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

@@ -10,4 +10,10 @@
         <attr name="showHorizontalValues" format="boolean" />
         <attr name="noDataText" format="string" />
     </declare-styleable>
+
+    <declare-styleable name="PieChartView">
+        <attr name="title" format="string" />
+        <attr name="textColor" format="color" />
+        <attr name="showLegend" format="boolean" />
+    </declare-styleable>
 </resources>

+ 3 - 3
graphsapp/build.gradle

@@ -1,13 +1,13 @@
 apply plugin: 'com.android.application'
 
 android {
-    compileSdkVersion 26
+    compileSdkVersion 25
     buildToolsVersion "25.0.3"
 
     defaultConfig {
         applicationId "hr.tacitus.graphsapp"
         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')

+ 51 - 2
graphsapp/src/main/java/hr/tacitus/graphsapp/MainActivity.java

@@ -1,23 +1,40 @@
 package hr.tacitus.graphsapp;
 
+import android.graphics.Color;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.view.View;
 
 import hr.tacitus.graphs.BarGraphAdapter;
 import hr.tacitus.graphs.BarGraphView;
+import hr.tacitus.graphs.PieChartAdapter;
+import hr.tacitus.graphs.PieChartColorProvider;
+import hr.tacitus.graphs.PieChartView;
+
 import java.text.DecimalFormat;
 
 public class MainActivity extends AppCompatActivity {
 
     private BarGraphView bgv;
+    private PieChartView pieChartView;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
 
-        bgv = (BarGraphView) findViewById(R.id.bgvGraf);
+//        bgv = (BarGraphView) findViewById(R.id.bgvGraf);
+//        updateAdapter();
+
+        // float[] values = {12.5f, 50.0f, 25f, 12.5f};
+        pieChartView = (PieChartView) findViewById(R.id.pieChart);
+        pieChartView.setColorProvider(new PieChartColorProvider() {
+            int[] colors = {Color.RED, Color.YELLOW, Color.parseColor("#f47142")};
+            @Override
+            public int getColor(int position) {
+                return colors[position];
+            }
+        });
         updateAdapter();
     }
 
@@ -59,7 +76,39 @@ public class MainActivity extends AppCompatActivity {
         };
     }
 
+    private PieChartAdapter createPieChartAdapter() {
+        return new PieChartAdapter() {
+            // float[] values = {10f, 5f, 15f, 10f, 10f, 5f, 15f, 5f, 5f, 5f, 5f, 5f, 5f, };
+            float[] values = {23.5f, 27.5f, 49f};
+            String[] descriptions = {"Fuel 110234 HRK but promising!", "Regular Expenses 53200 HRK", "Irregular Expenses 12500 HRK"};
+
+            @Override
+            public int getCount() {
+                return values.length;
+            }
+
+            @Override
+            public String getDescription(int position) {
+                return descriptions[position];
+            }
+
+            @Override
+            public float getValue(int position) {
+                return values[position];
+            }
+
+            @Override
+            public String getValueDescription(int position) {
+                return Float.toString(values[position]) + " %";
+            }
+        };
+    }
+
     private void updateAdapter() {
-        bgv.setAdapter(bgv.getAdapter() == null ? createSampleAdapter() : null);
+        if (bgv != null)
+            bgv.setAdapter(bgv.getAdapter() == null ? createSampleAdapter() : null);
+        if (pieChartView != null) {
+            pieChartView.setAdapter(pieChartView.getAdapter() == null ? createPieChartAdapter() : null);
+        }
     }
 }

+ 17 - 11
graphsapp/src/main/res/layout/activity_main.xml

@@ -19,19 +19,25 @@
             android:text="Toggle Adapter" />
     </LinearLayout>
 
-
-    <hr.tacitus.graphs.BarGraphView
+    <hr.tacitus.graphs.PieChartView
         android:layout_below="@id/toolbar"
-        android:id="@+id/bgvGraf"
-        android:layout_width="fill_parent"
-        android:layout_height="fill_parent"
-        android:paddingTop="42dp"
-        android:paddingLeft="6dp"
-        android:paddingBottom="6dp"
-        android:paddingRight="6dp"
-
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:id="@+id/pieChart"
+        app:title="Some testing"
+        app:textColor="#ffffff"
+        />
 
 
-        />
+    <!--<hr.tacitus.graphs.BarGraphView-->
+        <!--android:layout_below="@id/toolbar"-->
+        <!--android:id="@+id/bgvGraf"-->
+        <!--android:layout_width="0dp"-->
+        <!--android:layout_height="0dp"-->
+        <!--android:paddingTop="42dp"-->
+        <!--android:paddingLeft="6dp"-->
+        <!--android:paddingBottom="6dp"-->
+        <!--android:paddingRight="6dp"-->
+        <!--/>-->
 
 </RelativeLayout>

+ 1 - 1
graphsapp/src/main/res/values/styles.xml

@@ -1,7 +1,7 @@
 <resources>
 
     <!-- Base application theme. -->
-    <style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
+    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
         <!-- Customize your theme here. -->
         <item name="colorPrimary">@color/colorPrimary</item>
         <item name="colorPrimaryDark">@color/colorPrimaryDark</item>