Skip to content

Commit

Permalink
Merge pull request #114 from Zolon-DOL/master
Browse files Browse the repository at this point in the history
Sprint 4 changes
  • Loading branch information
pbhatt17 authored Jun 17, 2022
2 parents 3287bdf + e99bde6 commit 1e4f18e
Show file tree
Hide file tree
Showing 16 changed files with 847 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ 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),
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")
};
Expand Down
33 changes: 30 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".charts.DataVisualizationActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
Expand Down Expand Up @@ -258,6 +255,36 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="gov.dol.childlabor.MainActivity" />
</activity>
<activity
android:name=".charts.ChartsListActivity"
android:label="Data Visualizations"
android:launchMode="singleTop"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="gov.dol.childlabor.MainActivity" />
</activity>
<activity
android:name=".charts.DataVisualizationActivity"
android:label="Proportional Area Chart"
android:launchMode="singleTop"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="gov.dol.childlabor.MainActivity" />
</activity>
<activity
android:name=".charts.GoodsBySectorChartActivityNew"
android:label="Data Visualizations"
android:launchMode="singleTop"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="gov.dol.childlabor.MainActivity" />
</activity>
</application>

</manifest>
9 changes: 8 additions & 1 deletion app/src/main/java/gov/dol/childlabor/CountryGood.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
114 changes: 114 additions & 0 deletions app/src/main/java/gov/dol/childlabor/GoodXmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ public Good[] getGoodList() {
return goods;
}

public ArrayList<Good> getGoodListNew(String name) {
ArrayList<Good> 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<Good> goods = new ArrayList<Good>(Arrays.asList(getGoodList()));

Expand Down Expand Up @@ -112,6 +133,99 @@ private Good[] parseXML(XmlPullParser parser) throws XmlPullParserException, IOE

}

public ArrayList<Good> parseXMLByRegion(XmlPullParser parser, String region) throws XmlPullParserException, IOException {
ArrayList<Good> 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<CountryGood> countryGoods = new ArrayList<CountryGood>();

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<CountryGood> countryGoods = new ArrayList<CountryGood>();

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/gov/dol/childlabor/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package gov.dol.childlabor.charts;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.MenuItem;
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) {
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);
}
});



}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package gov.dol.childlabor.charts;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.util.Pair;
import android.view.Gravity;
import android.view.MenuItem;


import java.util.ArrayList;
Expand All @@ -25,6 +27,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<String,Pair<Float,Integer>> labels = new HashMap<>();
labels.put("GOLD",new Pair(2.4f,R.color.yellow));
Expand Down Expand Up @@ -60,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);
}
}
}
Loading

0 comments on commit 1e4f18e

Please sign in to comment.