From 66636542ce8fcfd44d85f5371bea9afc874106c4 Mon Sep 17 00:00:00 2001 From: Gnanendra18 Date: Fri, 3 Jun 2022 17:39:03 +0530 Subject: [PATCH 1/8] Goods By Sector Chart In progress. --- .../charting/utils/ColorTemplate.java | 4 + app/src/main/AndroidManifest.xml | 33 ++- .../java/gov/dol/childlabor/CountryGood.java | 9 +- .../gov/dol/childlabor/GoodXmlParser.java | 114 ++++++++++ .../java/gov/dol/childlabor/MainActivity.java | 3 +- .../childlabor/charts/ChartsListActivity.java | 40 ++++ .../charts/DataVisualizationActivity.java | 4 + .../charts/GoodsBySectorChartActivityNew.java | 203 ++++++++++++++++++ .../childlabor/charts/PieChartActivity.java | 2 +- .../ic_baseline_keyboard_arrow_right_24.xml | 11 + .../main/res/layout/activity_charts_list.xml | 65 ++++++ .../main/res/layout/goods_by_sector_chart.xml | 65 ++++++ .../res/layout/proportional_area_chart.xml | 23 +- 13 files changed, 567 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/gov/dol/childlabor/charts/ChartsListActivity.java create mode 100644 app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java create mode 100644 app/src/main/res/drawable/ic_baseline_keyboard_arrow_right_24.xml create mode 100644 app/src/main/res/layout/activity_charts_list.xml create mode 100644 app/src/main/res/layout/goods_by_sector_chart.xml diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/utils/ColorTemplate.java b/MPChartLib/src/main/java/com/github/mikephil/charting/utils/ColorTemplate.java index 4d9c1de..e6e3b43 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/utils/ColorTemplate.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/utils/ColorTemplate.java @@ -51,6 +51,10 @@ public class ColorTemplate { Color.rgb(192, 255, 140), Color.rgb(255, 247, 140), Color.rgb(255, 208, 140), Color.rgb(140, 234, 255), Color.rgb(255, 140, 157) }; + public static final int[] ORANGE = { + Color.rgb(192, 255, 140), Color.rgb(255, 247, 140), Color.rgb(255, 208, 140), + Color.rgb(140, 234, 255), Color.rgb(255, 140, 157) + }; public static final int[] MATERIAL_COLORS = { rgb("#2ecc71"), rgb("#f1c40f"), rgb("#e74c3c"), rgb("#3498db") }; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 97d2058..d5adc1a 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,9 +15,6 @@ android:largeHeap="true" android:supportsRtl="true" android:theme="@style/AppTheme"> - @@ -258,6 +255,36 @@ android:name="android.support.PARENT_ACTIVITY" android:value="gov.dol.childlabor.MainActivity" /> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/gov/dol/childlabor/CountryGood.java b/app/src/main/java/gov/dol/childlabor/CountryGood.java index 3fd149f..3819010 100755 --- a/app/src/main/java/gov/dol/childlabor/CountryGood.java +++ b/app/src/main/java/gov/dol/childlabor/CountryGood.java @@ -7,7 +7,7 @@ */ public class CountryGood implements Serializable { - private String goodName, countryName; + private String goodName, countryName,countryRegion; private Boolean hasChildLabor, hasForcedLabor, hasForcedChildLabor; public CountryGood() { @@ -54,4 +54,11 @@ public void setForcedChildLabor(Boolean hasForcedChildLabor) { this.hasForcedChildLabor = hasForcedChildLabor; } + public String getCountryRegion() { + return countryRegion; + } + + public void setCountryRegion(String countryRegion) { + this.countryRegion = countryRegion; + } } diff --git a/app/src/main/java/gov/dol/childlabor/GoodXmlParser.java b/app/src/main/java/gov/dol/childlabor/GoodXmlParser.java index 7149786..93f308f 100755 --- a/app/src/main/java/gov/dol/childlabor/GoodXmlParser.java +++ b/app/src/main/java/gov/dol/childlabor/GoodXmlParser.java @@ -56,6 +56,27 @@ public Good[] getGoodList() { return goods; } + public ArrayList getGoodListNew(String name) { + ArrayList goods = null; + try { + XmlPullParserFactory pullParserFactory; + pullParserFactory = XmlPullParserFactory.newInstance(); + XmlPullParser parser = pullParserFactory.newPullParser(); + + parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); + parser.setInput(stream, null); + goods = parseXMLByRegion(parser,name); + } + catch(XmlPullParserException e) { + e.printStackTrace(); + } + catch(IOException e) { + e.printStackTrace(); + } + + return goods; + } + public Good[] getGoodListBySector() { ArrayList goods = new ArrayList(Arrays.asList(getGoodList())); @@ -112,6 +133,99 @@ private Good[] parseXML(XmlPullParser parser) throws XmlPullParserException, IOE } + public ArrayList parseXMLByRegion(XmlPullParser parser, String region) throws XmlPullParserException, IOException { + ArrayList goods = null; + int eventType = parser.getEventType(); + Good currentGood = null; + + while(eventType != XmlPullParser.END_DOCUMENT) { + String name = null; + switch(eventType) { + case XmlPullParser.START_DOCUMENT: + goods = new ArrayList(); + break; + case XmlPullParser.START_TAG: + name = parser.getName(); + if (name.equals("Good")) { + currentGood = new Good("Good"); + } else if (currentGood != null) { + switch(name) { + case "Good_Name": + currentGood.setName(parser.nextText()); + break; + case "Good_Sector": + currentGood.setSector(parser.nextText()); + break; + case "Countries": + currentGood.setCountries(parseCountriesByRegion(parser, currentGood.getName())); + break; + default: + skip(parser); + } + } + break; + case XmlPullParser.END_TAG: + name = parser.getName(); + if (name.equals("Good") && currentGood != null && currentGood.getCountries().length > 0) { + goods.add(currentGood); + } + } + eventType = parser.next(); + } + + return goods; + + } + + private CountryGood[] parseCountriesByRegion(XmlPullParser parser, String goodName) throws XmlPullParserException, IOException { + ArrayList countryGoods = new ArrayList(); + + int eventType = parser.getEventType(); + CountryGood currentCountryGood = null; + + while(!(eventType == XmlPullParser.END_TAG && parser.getName().equals("Countries"))) { + String name = null; + switch(eventType) { + case XmlPullParser.START_TAG: + name = parser.getName(); + if (name.equals("Country")) { + currentCountryGood = new CountryGood(); + currentCountryGood.setGoodName(goodName); + } else if (currentCountryGood != null) { + switch(name) { + case "Country_Name": + currentCountryGood.setCountryName(parser.nextText()); + break; + case "Country_Region": + currentCountryGood.setCountryRegion(parser.nextText()); + break; + case "Child_Labor": + currentCountryGood.setChildLabor(parser.nextText().equals("Yes")); + break; + case "Forced_Labor": + currentCountryGood.setForcedLabor(parser.nextText().equals("Yes")); + break; + case "Forced_Child_Labor": + currentCountryGood.setForcedChildLabor(parser.nextText().equals("Yes")); + break; + default: + skip(parser); + } + } + break; + case XmlPullParser.END_TAG: + name = parser.getName(); + if (name.equals("Country") && currentCountryGood != null) { + countryGoods.add(currentCountryGood); + } + } + eventType = parser.next(); + } + + return countryGoods.toArray(new CountryGood[countryGoods.size()]); + } + + private CountryGood[] parseCountries(XmlPullParser parser, String goodName) throws XmlPullParserException, IOException { ArrayList countryGoods = new ArrayList(); diff --git a/app/src/main/java/gov/dol/childlabor/MainActivity.java b/app/src/main/java/gov/dol/childlabor/MainActivity.java index cdcd927..f37f56c 100755 --- a/app/src/main/java/gov/dol/childlabor/MainActivity.java +++ b/app/src/main/java/gov/dol/childlabor/MainActivity.java @@ -21,6 +21,7 @@ import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; +import gov.dol.childlabor.charts.ChartsListActivity; import gov.dol.childlabor.charts.DataVisualizationActivity; public class MainActivity extends AppCompatActivity { @@ -88,7 +89,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) intent = new Intent(getApplicationContext(), ExploitationTypeListSpinnerActivity.class); break; case "Data Visualizations": - intent = new Intent(getApplicationContext(), DataVisualizationActivity.class); + intent = new Intent(getApplicationContext(), ChartsListActivity.class); break; } diff --git a/app/src/main/java/gov/dol/childlabor/charts/ChartsListActivity.java b/app/src/main/java/gov/dol/childlabor/charts/ChartsListActivity.java new file mode 100644 index 0000000..03ca936 --- /dev/null +++ b/app/src/main/java/gov/dol/childlabor/charts/ChartsListActivity.java @@ -0,0 +1,40 @@ +package gov.dol.childlabor.charts; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.util.AttributeSet; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import gov.dol.childlabor.R; + +public class ChartsListActivity extends AppCompatActivity { + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_charts_list); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + findViewById(R.id.proportional_chart).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + startActivity(new Intent(ChartsListActivity.this,DataVisualizationActivity.class)); + } + }); + findViewById(R.id.piechart).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + startActivity(new Intent(ChartsListActivity.this,GoodsBySectorChartActivityNew.class)); + } + }); + + + + } +} diff --git a/app/src/main/java/gov/dol/childlabor/charts/DataVisualizationActivity.java b/app/src/main/java/gov/dol/childlabor/charts/DataVisualizationActivity.java index 167fd2f..c414da1 100644 --- a/app/src/main/java/gov/dol/childlabor/charts/DataVisualizationActivity.java +++ b/app/src/main/java/gov/dol/childlabor/charts/DataVisualizationActivity.java @@ -1,6 +1,7 @@ package gov.dol.childlabor.charts; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import android.graphics.Color; import android.os.Bundle; @@ -25,6 +26,9 @@ public class DataVisualizationActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.proportional_area_chart); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); BubbleLayout layout = findViewById(R.id.bubble_layout); Map> labels = new HashMap<>(); labels.put("GOLD",new Pair(2.4f,R.color.yellow)); diff --git a/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java b/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java new file mode 100644 index 0000000..7dcd481 --- /dev/null +++ b/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java @@ -0,0 +1,203 @@ +package gov.dol.childlabor.charts; + +import android.graphics.Color; +import android.graphics.Typeface; +import android.os.Bundle; +import android.text.SpannableString; +import android.text.style.RelativeSizeSpan; +import android.text.style.StyleSpan; +import android.util.Log; +import android.view.WindowManager; + +import androidx.appcompat.app.AppCompatActivity; + +import com.github.mikephil.charting.animation.Easing; +import com.github.mikephil.charting.charts.PieChart; +import com.github.mikephil.charting.components.Legend; +import com.github.mikephil.charting.data.Entry; +import com.github.mikephil.charting.data.PieData; +import com.github.mikephil.charting.data.PieDataSet; +import com.github.mikephil.charting.data.PieEntry; +import com.github.mikephil.charting.formatter.PercentFormatter; +import com.github.mikephil.charting.highlight.Highlight; +import com.github.mikephil.charting.listener.OnChartValueSelectedListener; +import com.github.mikephil.charting.utils.ColorTemplate; +import com.github.mikephil.charting.utils.MPPointF; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import gov.dol.childlabor.CountryGood; +import gov.dol.childlabor.Good; +import gov.dol.childlabor.GoodXmlParser; +import gov.dol.childlabor.R; + +public class GoodsBySectorChartActivityNew extends AppCompatActivity implements + OnChartValueSelectedListener { + + private PieChart chart; + String country = "Country"; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + // WindowManager.LayoutParams.FLAG_FULLSCREEN); + setContentView(R.layout.activity_piechart_half); + + setTitle("Goods By Sector"); + country = "Agriculture"; + chart = findViewById(R.id.chart1); + chart.setUsePercentValues(true); + chart.getDescription().setEnabled(false); + chart.setExtraOffsets(5, 10, 5, 5); + + chart.setDragDecelerationFrictionCoef(0.95f); + + chart.setCenterText(generateCenterSpannableText()); + + chart.setDrawHoleEnabled(true); + chart.setHoleColor(Color.WHITE); + + chart.setTransparentCircleColor(Color.WHITE); + chart.setTransparentCircleAlpha(110); + + chart.setHoleRadius(58f); + chart.setTransparentCircleRadius(61f); + + chart.setDrawCenterText(true); + + chart.setRotationAngle(0); + // enable rotation of the chart by touch + chart.setRotationEnabled(true); + chart.setHighlightPerTapEnabled(true); + + // chart.setUnit(" €"); + // chart.setDrawUnitsInChart(true); + + // add a selection listener + chart.setOnChartValueSelectedListener(this); + + + chart.animateY(1400, Easing.EaseInOutQuad); + // chart.spin(2000, 0, 360); + + Legend l = chart.getLegend(); + l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); + l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); + l.setOrientation(Legend.LegendOrientation.VERTICAL); + l.setDrawInside(false); + l.setXEntrySpace(7f); + l.setYEntrySpace(0f); + l.setYOffset(0f); + + // entry label styling + chart.setEntryLabelColor(Color.WHITE); + chart.setEntryLabelTextSize(12f); + setData(); + } + + private void setData() { + //ArrayList entries = new ArrayList<>(); + + // NOTE: The order of the entries when being added to the entries array determines their position around the center of + // the chart. + GoodXmlParser gParser = GoodXmlParser.fromContext(this); + Map map = new HashMap<>(); + ArrayList goodListBySector = gParser.getGoodListNew(""); + for (Good good : + goodListBySector) { + if (good.getSector().equals("Agriculture")) { + for(CountryGood country: good.getCountries()){ + //Log.e("Region",country.getCountryRegion()); + if(map.containsKey(country.getCountryRegion())){ + map.put(country.getCountryRegion(),map.get(country.getCountryRegion())+1); + }else{ + map.put(country.getCountryRegion(),1); + } + } + } + } + ArrayList values = new ArrayList<>(); + map.remove(""); + for (String key : + map.keySet()) { + values.add(new PieEntry(map.get(key), key)); + } + + + PieDataSet dataSet = new PieDataSet(values, "Agriculture By Region"); + + dataSet.setDrawIcons(false); + + dataSet.setSliceSpace(3f); + dataSet.setIconsOffset(new MPPointF(0, 40)); + dataSet.setSelectionShift(5f); + + // add a lot of colors + + ArrayList colors = new ArrayList<>(); + + /*for (int c : ColorTemplate.VORDIPLOM_COLORS) + colors.add(c);*/ + + /*for (int c : ColorTemplate.JOYFUL_COLORS) + colors.add(c);*/ + + for (int c : ColorTemplate.COLORFUL_COLORS) + colors.add(c); + + /*for (int c : ColorTemplate.LIBERTY_COLORS) + colors.add(c); + + for (int c : ColorTemplate.PASTEL_COLORS) + colors.add(c);*/ + + colors.add(ColorTemplate.getHoloBlue()); + + dataSet.setColors(colors); + //dataSet.setSelectionShift(0f); + + PieData data = new PieData(dataSet); + data.setValueFormatter(new PercentFormatter()); + data.setValueTextSize(11f); + data.setValueTextColor(Color.WHITE); + chart.setData(data); + + // undo all highlights + chart.highlightValues(null); + + chart.invalidate(); + } + + + + + private SpannableString generateCenterSpannableText() { + + SpannableString s = new SpannableString(country+"\nBy Region"); + s.setSpan(new RelativeSizeSpan(1.7f), 0, country.length(), 0); + s.setSpan(new StyleSpan(Typeface.NORMAL), country.length(), s.length() - country.length()+1, 0); + //s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0); + //s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0); + //s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0); + //s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0); + return s; + } + + @Override + public void onValueSelected(Entry e, Highlight h) { + + if (e == null) + return; + Log.i("VAL SELECTED", + "Value: " + e.getY() + ", index: " + h.getX() + + ", DataSet index: " + h.getDataSetIndex()); + } + + @Override + public void onNothingSelected() { + Log.i("PieChart", "nothing selected"); + } + +} diff --git a/app/src/main/java/gov/dol/childlabor/charts/PieChartActivity.java b/app/src/main/java/gov/dol/childlabor/charts/PieChartActivity.java index 1f2a202..924d63b 100644 --- a/app/src/main/java/gov/dol/childlabor/charts/PieChartActivity.java +++ b/app/src/main/java/gov/dol/childlabor/charts/PieChartActivity.java @@ -130,7 +130,7 @@ private void setData() { values.add(new PieEntry(se*100, "Services")); values.add(new PieEntry(in*100, "Industry")); - PieDataSet dataSet = new PieDataSet(values, "Election Results"); + PieDataSet dataSet = new PieDataSet(values, "Results"); dataSet.setDrawIcons(false); diff --git a/app/src/main/res/drawable/ic_baseline_keyboard_arrow_right_24.xml b/app/src/main/res/drawable/ic_baseline_keyboard_arrow_right_24.xml new file mode 100644 index 0000000..7f7b33e --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_keyboard_arrow_right_24.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/layout/activity_charts_list.xml b/app/src/main/res/layout/activity_charts_list.xml new file mode 100644 index 0000000..b71fa6a --- /dev/null +++ b/app/src/main/res/layout/activity_charts_list.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/goods_by_sector_chart.xml b/app/src/main/res/layout/goods_by_sector_chart.xml new file mode 100644 index 0000000..b71fa6a --- /dev/null +++ b/app/src/main/res/layout/goods_by_sector_chart.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/proportional_area_chart.xml b/app/src/main/res/layout/proportional_area_chart.xml index f650075..b183c41 100644 --- a/app/src/main/res/layout/proportional_area_chart.xml +++ b/app/src/main/res/layout/proportional_area_chart.xml @@ -1,10 +1,27 @@ - + android:divider="?android:attr/dividerHorizontal" + android:orientation="vertical" + android:showDividers="middle"> + + + + + - \ No newline at end of file + From b8efb696402ba4f3751b385327dcbb27438b3f70 Mon Sep 17 00:00:00 2001 From: Gnanendra18 Date: Mon, 6 Jun 2022 20:12:03 +0530 Subject: [PATCH 2/8] Goods By Sector Chart. --- .../charts/GoodsBySectorChartActivityNew.java | 57 +++++++++++-- .../main/res/layout/activity_charts_list.xml | 2 +- .../res/layout/activity_goods_by_sector.xml | 85 +++++++++++++++++++ app/src/main/res/values/colors.xml | 1 + 4 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/layout/activity_goods_by_sector.xml diff --git a/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java b/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java index 7dcd481..7a92830 100644 --- a/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java +++ b/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java @@ -7,9 +7,12 @@ import android.text.style.RelativeSizeSpan; import android.text.style.StyleSpan; import android.util.Log; +import android.view.View; import android.view.WindowManager; +import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import com.github.mikephil.charting.animation.Easing; import com.github.mikephil.charting.charts.PieChart; @@ -38,12 +41,49 @@ public class GoodsBySectorChartActivityNew extends AppCompatActivity implements private PieChart chart; String country = "Country"; + TextView agriculture,manufacturing,mining,other; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, // WindowManager.LayoutParams.FLAG_FULLSCREEN); - setContentView(R.layout.activity_piechart_half); + setContentView(R.layout.activity_goods_by_sector); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + agriculture = findViewById(R.id.agri); + manufacturing = findViewById(R.id.manufacture); + mining = findViewById(R.id.mining); + other = findViewById(R.id.other); + agriculture.setOnClickListener(view -> { + resetColors(); + agriculture.setBackgroundColor(getResources().getColor(R.color.orange)); + setData("Agriculture"); + country = "Agriculture"; + chart.setCenterText(generateCenterSpannableText()); + }); + mining.setOnClickListener(view -> { + resetColors(); + mining.setBackgroundColor(getResources().getColor(R.color.orange)); + setData("Mining"); + country = "Mining"; + chart.setCenterText(generateCenterSpannableText()); + }); + manufacturing.setOnClickListener(view -> { + resetColors(); + manufacturing.setBackgroundColor(getResources().getColor(R.color.orange)); + setData("Manufacturing"); + country = "Manufacturing"; + chart.setCenterText(generateCenterSpannableText()); + }); + other.setOnClickListener(view -> { + resetColors(); + other.setBackgroundColor(getResources().getColor(R.color.orange)); + setData("Other"); + country = "Other"; + chart.setCenterText(generateCenterSpannableText()); + }); setTitle("Goods By Sector"); country = "Agriculture"; @@ -94,10 +134,17 @@ protected void onCreate(Bundle savedInstanceState) { // entry label styling chart.setEntryLabelColor(Color.WHITE); chart.setEntryLabelTextSize(12f); - setData(); + setData("Agriculture"); + } + + private void resetColors() { + agriculture.setBackground(null); + mining.setBackground(null); + other.setBackground(null); + manufacturing.setBackground(null); } - private void setData() { + private void setData(String sector) { //ArrayList entries = new ArrayList<>(); // NOTE: The order of the entries when being added to the entries array determines their position around the center of @@ -107,7 +154,7 @@ private void setData() { ArrayList goodListBySector = gParser.getGoodListNew(""); for (Good good : goodListBySector) { - if (good.getSector().equals("Agriculture")) { + if (good.getSector().equals(sector)) { for(CountryGood country: good.getCountries()){ //Log.e("Region",country.getCountryRegion()); if(map.containsKey(country.getCountryRegion())){ @@ -177,7 +224,7 @@ private SpannableString generateCenterSpannableText() { SpannableString s = new SpannableString(country+"\nBy Region"); s.setSpan(new RelativeSizeSpan(1.7f), 0, country.length(), 0); - s.setSpan(new StyleSpan(Typeface.NORMAL), country.length(), s.length() - country.length()+1, 0); + s.setSpan(new StyleSpan(Typeface.NORMAL), country.length(), s.length() - country.length()+5, 0); //s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0); //s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0); //s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0); diff --git a/app/src/main/res/layout/activity_charts_list.xml b/app/src/main/res/layout/activity_charts_list.xml index b71fa6a..fb4ec33 100644 --- a/app/src/main/res/layout/activity_charts_list.xml +++ b/app/src/main/res/layout/activity_charts_list.xml @@ -52,7 +52,7 @@ android:id="@+id/piechart" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="Pie chart" + android:text="Goods By Sector" android:drawableRight="@drawable/ic_baseline_keyboard_arrow_right_24" app:drawableEndCompat="@drawable/ic_baseline_keyboard_arrow_right_24" /> diff --git a/app/src/main/res/layout/activity_goods_by_sector.xml b/app/src/main/res/layout/activity_goods_by_sector.xml new file mode 100644 index 0000000..3e56014 --- /dev/null +++ b/app/src/main/res/layout/activity_goods_by_sector.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index fcd0971..71a8197 100755 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -22,6 +22,7 @@ #CAF1DE #FFE7C7 #F7F7F7 + #EE920E From 8273cedf1bfed32d68bffea13f50a5819027b45c Mon Sep 17 00:00:00 2001 From: Gnanendra18 Date: Mon, 13 Jun 2022 18:55:56 +0530 Subject: [PATCH 3/8] Goods By Region Chart --- .../childlabor/charts/ChartsListActivity.java | 12 +++++- .../charts/GoodsBySectorChartActivityNew.java | 37 +++++++++++++++---- .../main/res/layout/activity_charts_list.xml | 9 +++++ 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/gov/dol/childlabor/charts/ChartsListActivity.java b/app/src/main/java/gov/dol/childlabor/charts/ChartsListActivity.java index 03ca936..ea389a4 100644 --- a/app/src/main/java/gov/dol/childlabor/charts/ChartsListActivity.java +++ b/app/src/main/java/gov/dol/childlabor/charts/ChartsListActivity.java @@ -30,7 +30,17 @@ public void onClick(View view) { findViewById(R.id.piechart).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - startActivity(new Intent(ChartsListActivity.this,GoodsBySectorChartActivityNew.class)); + Intent intent = new Intent(ChartsListActivity.this, GoodsBySectorChartActivityNew.class); + intent.putExtra("IS_GOODS_BY_REGION",false); + startActivity(intent); + } + }); + findViewById(R.id.goods_by_region).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(ChartsListActivity.this, GoodsBySectorChartActivityNew.class); + intent.putExtra("IS_GOODS_BY_REGION",true); + startActivity(intent); } }); diff --git a/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java b/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java index 7a92830..4ccae4d 100644 --- a/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java +++ b/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java @@ -42,6 +42,7 @@ public class GoodsBySectorChartActivityNew extends AppCompatActivity implements private PieChart chart; String country = "Country"; TextView agriculture,manufacturing,mining,other; + boolean isGoodsByRegion = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -52,6 +53,10 @@ protected void onCreate(Bundle savedInstanceState) { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); + isGoodsByRegion = getIntent().getBooleanExtra("IS_GOODS_BY_REGION",false); + if(isGoodsByRegion){ + findViewById(R.id.sector_group).setVisibility(View.GONE); + } agriculture = findViewById(R.id.agri); manufacturing = findViewById(R.id.manufacture); mining = findViewById(R.id.mining); @@ -85,8 +90,13 @@ protected void onCreate(Bundle savedInstanceState) { chart.setCenterText(generateCenterSpannableText()); }); - setTitle("Goods By Sector"); - country = "Agriculture"; + if(isGoodsByRegion){ + setTitle("Goods By Region"); + country = "All Categories"; + }else { + setTitle("Goods By Sector"); + country = "Agriculture"; + } chart = findViewById(R.id.chart1); chart.setUsePercentValues(true); chart.getDescription().setEnabled(false); @@ -154,13 +164,24 @@ private void setData(String sector) { ArrayList goodListBySector = gParser.getGoodListNew(""); for (Good good : goodListBySector) { - if (good.getSector().equals(sector)) { - for(CountryGood country: good.getCountries()){ + if(isGoodsByRegion){ + for (CountryGood country : good.getCountries()) { //Log.e("Region",country.getCountryRegion()); - if(map.containsKey(country.getCountryRegion())){ - map.put(country.getCountryRegion(),map.get(country.getCountryRegion())+1); - }else{ - map.put(country.getCountryRegion(),1); + if (map.containsKey(country.getCountryRegion())) { + map.put(country.getCountryRegion(), map.get(country.getCountryRegion()) + 1); + } else { + map.put(country.getCountryRegion(), 1); + } + } + }else { + if (good.getSector().equals(sector)) { + for (CountryGood country : good.getCountries()) { + //Log.e("Region",country.getCountryRegion()); + if (map.containsKey(country.getCountryRegion())) { + map.put(country.getCountryRegion(), map.get(country.getCountryRegion()) + 1); + } else { + map.put(country.getCountryRegion(), 1); + } } } } diff --git a/app/src/main/res/layout/activity_charts_list.xml b/app/src/main/res/layout/activity_charts_list.xml index fb4ec33..484c94e 100644 --- a/app/src/main/res/layout/activity_charts_list.xml +++ b/app/src/main/res/layout/activity_charts_list.xml @@ -56,6 +56,15 @@ android:drawableRight="@drawable/ic_baseline_keyboard_arrow_right_24" app:drawableEndCompat="@drawable/ic_baseline_keyboard_arrow_right_24" /> + + From 9a482c96dd092100c5d5464a2843a96275cb7ace Mon Sep 17 00:00:00 2001 From: Gnanendra18 Date: Mon, 13 Jun 2022 19:06:59 +0530 Subject: [PATCH 4/8] Title modified to Most common goods produced with exploited labor --- app/src/main/res/layout/activity_charts_list.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/layout/activity_charts_list.xml b/app/src/main/res/layout/activity_charts_list.xml index 484c94e..4143931 100644 --- a/app/src/main/res/layout/activity_charts_list.xml +++ b/app/src/main/res/layout/activity_charts_list.xml @@ -44,7 +44,7 @@ android:id="@+id/proportional_chart" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="Proportional area chart" + android:text="Most common goods produced with exploited labor" android:drawableRight="@drawable/ic_baseline_keyboard_arrow_right_24" app:drawableEndCompat="@drawable/ic_baseline_keyboard_arrow_right_24" /> Date: Mon, 13 Jun 2022 19:54:42 +0530 Subject: [PATCH 5/8] No Data available for statistics and back button handling. --- .../childlabor/charts/ChartsListActivity.java | 11 ++++++ .../charts/DataVisualizationActivity.java | 11 ++++++ .../charts/GoodsBySectorChartActivityNew.java | 12 +++++++ .../childlabor/charts/PieChartActivity.java | 31 +++++++++++++++-- .../res/layout/activity_piechart_half.xml | 34 +++++++++++++++++++ 5 files changed, 96 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/gov/dol/childlabor/charts/ChartsListActivity.java b/app/src/main/java/gov/dol/childlabor/charts/ChartsListActivity.java index ea389a4..4346527 100644 --- a/app/src/main/java/gov/dol/childlabor/charts/ChartsListActivity.java +++ b/app/src/main/java/gov/dol/childlabor/charts/ChartsListActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.os.Bundle; import android.util.AttributeSet; +import android.view.MenuItem; import android.view.View; import androidx.annotation.NonNull; @@ -46,5 +47,15 @@ public void onClick(View view) { + } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } } } diff --git a/app/src/main/java/gov/dol/childlabor/charts/DataVisualizationActivity.java b/app/src/main/java/gov/dol/childlabor/charts/DataVisualizationActivity.java index c414da1..a8214a3 100644 --- a/app/src/main/java/gov/dol/childlabor/charts/DataVisualizationActivity.java +++ b/app/src/main/java/gov/dol/childlabor/charts/DataVisualizationActivity.java @@ -9,6 +9,7 @@ import android.util.DisplayMetrics; import android.util.Pair; import android.view.Gravity; +import android.view.MenuItem; import java.util.ArrayList; @@ -64,4 +65,14 @@ protected void onCreate(Bundle savedInstanceState) { } } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } } \ No newline at end of file diff --git a/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java b/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java index 4ccae4d..c76fcc9 100644 --- a/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java +++ b/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java @@ -7,6 +7,7 @@ import android.text.style.RelativeSizeSpan; import android.text.style.StyleSpan; import android.util.Log; +import android.view.MenuItem; import android.view.View; import android.view.WindowManager; import android.widget.TextView; @@ -268,4 +269,15 @@ public void onNothingSelected() { Log.i("PieChart", "nothing selected"); } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + } diff --git a/app/src/main/java/gov/dol/childlabor/charts/PieChartActivity.java b/app/src/main/java/gov/dol/childlabor/charts/PieChartActivity.java index 924d63b..baf7cef 100644 --- a/app/src/main/java/gov/dol/childlabor/charts/PieChartActivity.java +++ b/app/src/main/java/gov/dol/childlabor/charts/PieChartActivity.java @@ -9,6 +9,7 @@ import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; @@ -17,6 +18,7 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; +import android.view.View; import android.view.WindowManager; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; @@ -52,13 +54,24 @@ protected void onCreate(Bundle savedInstanceState) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_piechart_half); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); - setTitle("PieChartActivity"); + setTitle("Working Statistics"); country = getIntent().getStringExtra("Country"); String agriculture = getIntent().getStringExtra("Agriculture"); String services = getIntent().getStringExtra("Services"); String industry = getIntent().getStringExtra("Industry"); + findViewById(R.id.back).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + finish(); + } + }); + + chart = findViewById(R.id.chart1); try { ag = Float.parseFloat(agriculture); se = Float.parseFloat(services); @@ -68,9 +81,12 @@ protected void onCreate(Bundle savedInstanceState) { ag = .333f; se = .333f; in = .333f; + findViewById(R.id.toolbar_head).setVisibility(View.GONE); + chart.setVisibility(View.GONE); + findViewById(R.id.text).setVisibility(View.VISIBLE); + findViewById(R.id.back).setVisibility(View.VISIBLE); } - chart = findViewById(R.id.chart1); chart.setUsePercentValues(true); chart.getDescription().setEnabled(false); chart.setExtraOffsets(5, 10, 5, 5); @@ -203,5 +219,14 @@ public void onValueSelected(Entry e, Highlight h) { public void onNothingSelected() { Log.i("PieChart", "nothing selected"); } - + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } } diff --git a/app/src/main/res/layout/activity_piechart_half.xml b/app/src/main/res/layout/activity_piechart_half.xml index 9d58c85..c82dbbe 100644 --- a/app/src/main/res/layout/activity_piechart_half.xml +++ b/app/src/main/res/layout/activity_piechart_half.xml @@ -1,11 +1,31 @@ + + + + + + From a559952cb30bd68aa68f0109ff7e0a5c98c90992 Mon Sep 17 00:00:00 2001 From: Gnanendra18 Date: Mon, 13 Jun 2022 20:40:55 +0530 Subject: [PATCH 6/8] Percentage Data to Normal data conversion --- .../charts/GoodsBySectorChartActivityNew.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java b/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java index c76fcc9..3b4ae84 100644 --- a/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java +++ b/app/src/main/java/gov/dol/childlabor/charts/GoodsBySectorChartActivityNew.java @@ -22,6 +22,7 @@ import com.github.mikephil.charting.data.PieData; import com.github.mikephil.charting.data.PieDataSet; import com.github.mikephil.charting.data.PieEntry; +import com.github.mikephil.charting.formatter.DefaultValueFormatter; import com.github.mikephil.charting.formatter.PercentFormatter; import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.listener.OnChartValueSelectedListener; @@ -99,7 +100,7 @@ protected void onCreate(Bundle savedInstanceState) { country = "Agriculture"; } chart = findViewById(R.id.chart1); - chart.setUsePercentValues(true); + chart.setUsePercentValues(false); chart.getDescription().setEnabled(false); chart.setExtraOffsets(5, 10, 5, 5); @@ -113,8 +114,8 @@ protected void onCreate(Bundle savedInstanceState) { chart.setTransparentCircleColor(Color.WHITE); chart.setTransparentCircleAlpha(110); - chart.setHoleRadius(58f); - chart.setTransparentCircleRadius(61f); + chart.setHoleRadius(50f); + chart.setTransparentCircleRadius(0f); chart.setDrawCenterText(true); @@ -144,7 +145,8 @@ protected void onCreate(Bundle savedInstanceState) { // entry label styling chart.setEntryLabelColor(Color.WHITE); - chart.setEntryLabelTextSize(12f); + chart.setEntryLabelTextSize(16f); + chart.setDrawEntryLabels(false); setData("Agriculture"); } @@ -195,7 +197,7 @@ private void setData(String sector) { } - PieDataSet dataSet = new PieDataSet(values, "Agriculture By Region"); + PieDataSet dataSet = new PieDataSet(values, country+" By Region"); dataSet.setDrawIcons(false); @@ -228,8 +230,8 @@ private void setData(String sector) { //dataSet.setSelectionShift(0f); PieData data = new PieData(dataSet); - data.setValueFormatter(new PercentFormatter()); - data.setValueTextSize(11f); + data.setValueFormatter(new DefaultValueFormatter(0)); + data.setValueTextSize(14f); data.setValueTextColor(Color.WHITE); chart.setData(data); From 06a8d3cd8b4f4528cd9d6fd39e414715d92cbcc6 Mon Sep 17 00:00:00 2001 From: Gnanendra18 Date: Thu, 16 Jun 2022 08:48:25 +0530 Subject: [PATCH 7/8] Changed title --- app/src/main/AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d5adc1a..c0a3dcc 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -257,7 +257,7 @@ @@ -277,7 +277,7 @@ From 33098f17c4b92da9c3d794cb8d848c8dc7d2e0ad Mon Sep 17 00:00:00 2001 From: Gnanendra18 Date: Thu, 16 Jun 2022 19:59:03 +0530 Subject: [PATCH 8/8] Color changes and title removed from pie chart --- .../mikephil/charting/utils/ColorTemplate.java | 4 ++-- .../dol/childlabor/charts/PieChartActivity.java | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/utils/ColorTemplate.java b/MPChartLib/src/main/java/com/github/mikephil/charting/utils/ColorTemplate.java index e6e3b43..00cd273 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/utils/ColorTemplate.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/utils/ColorTemplate.java @@ -44,8 +44,8 @@ public class ColorTemplate { Color.rgb(191, 134, 134), Color.rgb(179, 48, 80) }; public static final int[] COLORFUL_COLORS = { - Color.rgb(193, 37, 82), Color.rgb(255, 102, 0), Color.rgb(245, 199, 0), - Color.rgb(106, 150, 31), Color.rgb(179, 100, 53) + Color.rgb(57,89,122), Color.rgb(108,128,80), Color.rgb(245, 199, 0), + Color.rgb(218,141,58), Color.rgb(179, 100, 53) }; public static final int[] VORDIPLOM_COLORS = { Color.rgb(192, 255, 140), Color.rgb(255, 247, 140), Color.rgb(255, 208, 140), diff --git a/app/src/main/java/gov/dol/childlabor/charts/PieChartActivity.java b/app/src/main/java/gov/dol/childlabor/charts/PieChartActivity.java index baf7cef..342065b 100644 --- a/app/src/main/java/gov/dol/childlabor/charts/PieChartActivity.java +++ b/app/src/main/java/gov/dol/childlabor/charts/PieChartActivity.java @@ -101,8 +101,8 @@ public void onClick(View view) { chart.setTransparentCircleColor(Color.WHITE); chart.setTransparentCircleAlpha(110); - chart.setHoleRadius(58f); - chart.setTransparentCircleRadius(61f); + chart.setHoleRadius(50f); + chart.setTransparentCircleRadius(0f); chart.setDrawCenterText(true); @@ -133,6 +133,7 @@ public void onClick(View view) { // entry label styling chart.setEntryLabelColor(Color.WHITE); chart.setEntryLabelTextSize(12f); + chart.setDrawEntryLabels(false); setData(); } @@ -146,7 +147,7 @@ private void setData() { values.add(new PieEntry(se*100, "Services")); values.add(new PieEntry(in*100, "Industry")); - PieDataSet dataSet = new PieDataSet(values, "Results"); + PieDataSet dataSet = new PieDataSet(values, ""); dataSet.setDrawIcons(false); @@ -158,20 +159,20 @@ private void setData() { ArrayList colors = new ArrayList<>(); - for (int c : ColorTemplate.VORDIPLOM_COLORS) + /*for (int c : ColorTemplate.VORDIPLOM_COLORS) colors.add(c); for (int c : ColorTemplate.JOYFUL_COLORS) - colors.add(c); + colors.add(c);*/ for (int c : ColorTemplate.COLORFUL_COLORS) colors.add(c); - for (int c : ColorTemplate.LIBERTY_COLORS) + /*for (int c : ColorTemplate.LIBERTY_COLORS) colors.add(c); for (int c : ColorTemplate.PASTEL_COLORS) - colors.add(c); + colors.add(c);*/ colors.add(ColorTemplate.getHoloBlue());