Skip to content

Commit

Permalink
Finished
Browse files Browse the repository at this point in the history
  • Loading branch information
unf-sdc-2017 committed Jul 10, 2017
1 parent c23441b commit d252bdc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void statisticsActivity(View view){
public void createNotification (){
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle("TimeTracker")
.setContentText("What are you doing");
.setContentText("What are you doing?");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, MainActivity.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private void setReferences(){

void updateView(){
ArrayList<String> valuesToRead = new ArrayList<>();
valuesToRead.add("catagory");

// Find the values to read.
for (Action a : Action.actionList) {
Expand All @@ -85,7 +86,7 @@ void updateView(){
// Convert the list back to an array.
String[] valuesToSend = valuesToRead.toArray(new String[0]);
Log.e("Test", "" + valuesToSend.length);
ArrayAdapter<String> adapter = new StatisticsArrayAdapter(this, valuesToSend);
ArrayAdapter<String> adapter = new StatisticsArrayAdapter(this, valuesToSend, classificationString);
statListView.setAdapter(adapter);
}

Expand Down Expand Up @@ -120,17 +121,52 @@ public void onNothingSelected(AdapterView<?> adapterView) { }
class StatisticsArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
private final String category;

public StatisticsArrayAdapter(Context context, String[] values) {
public StatisticsArrayAdapter(Context context, String[] values, String category) {
super(context, -1, values);
this.context = context;
this.values = values;
this.category = category;
}

@Override @NonNull
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
String name = values[position];

if(name.equals("catagory")){
// If it is the first line, make a pieChart.

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.activity_statistics_pie_row, parent, false);
TextView nameText = (TextView) convertView.findViewById(R.id.nameOfPieChart);
PieChart chart = (PieChart) convertView.findViewById(R.id.chart);

nameText.setText(category);

ArrayList<String> labels = new ArrayList<>();
for (Action a : Action.actionList) {
if(labels.contains(a.getName())){
continue;
}
if(a.getClassification().getName().equals(category)){
labels.add(a.getName());
}
}

ArrayList<Integer> amounts = new ArrayList<>();
for (String s : labels) {
amounts.add(Action.getAmount(s));
}

makePieChart(category, labels, amounts, chart);



return convertView;

}

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.activity_statistics_row, parent, false);
TextView nameText = (TextView) convertView.findViewById(R.id.nameOfChart);
Expand Down Expand Up @@ -185,5 +221,14 @@ private void makeLineChart(String title, ArrayList<Integer> amounts, LineChart l
Charts.getXAxisData(labels, lineChart);
}

// If there is a reference to a chart, this will set all the values.
private void makePieChart(String title, ArrayList<String> names, ArrayList<Integer> amounts, PieChart pieChart) {
int[] colors = new int[] { R.color.neonpink, R.color.green, R.color.blue, R.color.lightgreen, R.color.red, R.color.yellow, R.color.lightblue, R.color.magenza, R.color.orange, R.color.turqoise, R.color.pumpkin, R.color.palepink, R.color.svump, R.color.darkpurple }, getApplicationContext;
PieDataSet dataSet = new PieDataSet(Charts.createEntries(names, amounts), title);
dataSet.setColors(colors, context);
PieData data = new PieData(dataSet);
pieChart.setData(data);
pieChart.invalidate(); // refresh
}

}
23 changes: 23 additions & 0 deletions app/src/main/res/layout/activity_statistics_pie_row.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/nameOfPieChart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Category name"
android:textAlignment="center"
android:textSize="24sp" />

<com.github.mikephil.charting.charts.PieChart
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true" />

</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/lightblue</item>
<item name="colorPrimaryDark">@color/blue</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

Expand Down

0 comments on commit d252bdc

Please sign in to comment.