Skip to content
Snippets Groups Projects
Commit 76209379 authored by Peter Joseph De Jonckheere CESM2014's avatar Peter Joseph De Jonckheere CESM2014
Browse files

Changed graph

parent d15545f6
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,8 @@ import com.notificationFramework.stimulus.Stimulus; ...@@ -21,6 +21,8 @@ import com.notificationFramework.stimulus.Stimulus;
import com.notificationFramework.stimulusStrategy.Accelerometer; import com.notificationFramework.stimulusStrategy.Accelerometer;
import com.notificationFramework.stimulusStrategy.SigMotionDetect; import com.notificationFramework.stimulusStrategy.SigMotionDetect;
import java.util.List;
/** /**
* Created by Peter De Jonckheere 21/11/2017 * Created by Peter De Jonckheere 21/11/2017
* <p> * <p>
...@@ -83,16 +85,22 @@ public class MainActivity extends AppCompatActivity { ...@@ -83,16 +85,22 @@ public class MainActivity extends AppCompatActivity {
private void setUpGraph(){ private void setUpGraph(){
GraphView graph = (GraphView) findViewById(R.id.graph); GraphView graph = (GraphView) findViewById(R.id.graph);
List<Integer> acks = SaveFile.getWeeklyAcks(this.getApplicationContext());
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[] { DataPoint[] dataPoints = new DataPoint[7];
new DataPoint(0, 1), int j = 0;
new DataPoint(1, 5), for(int i = 0; i < acks.size(); i =+ 2){
new DataPoint(2, 3), DataPoint dp = new DataPoint(acks.get(i), acks.get(i+1));
new DataPoint(3, 2), dataPoints[j] = dp;
new DataPoint(4, 6) j++;
}); }
for(int i = 0; i < 7; i++){
if(dataPoints[i] == null){
dataPoints[i] = new DataPoint(0, 0);
}
}
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(dataPoints);
graph.addSeries(series); graph.addSeries(series);
graph.setTitle(getString(R.string.your_progress));
} }
/** /**
* Creates the stimulus object which initiates the background processes of the application. Uses * Creates the stimulus object which initiates the background processes of the application. Uses
......
...@@ -617,6 +617,37 @@ public class SaveFile { ...@@ -617,6 +617,37 @@ public class SaveFile {
} }
} }
static List<Integer> getWeeklyAcks(Context context) {
List<Integer> acks = new ArrayList<>();
String line = "";
List<String> contents = new ArrayList<>();
if (isExternalStorageMounted()) {
File dir = getDirectory(context);
File file = new File(dir, "ACKLOG.txt");
//Creates a new file if one doesn't already exist
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
Log.e("FILE_ERROR", "COULDN'T CREATE NEW FILE");
}
}
//Reads the current contents of the log file
try {
if (file.isFile() && file.canRead()) {
BufferedReader br = new BufferedReader(new FileReader(file));
while ((line = br.readLine()) != null) {
String items[] = line.split(" ");
acks.add(Integer.parseInt(items[0]));
acks.add(Integer.parseInt(items[1]));
}
}
} catch (IOException | NumberFormatException e) {
}
}
return acks;
}
/** /**
* Checks if external storage is available on the device. * Checks if external storage is available on the device.
* *
......
...@@ -59,4 +59,5 @@ ...@@ -59,4 +59,5 @@
<string name="place_ack_total">Last Place Acknowledgement Total</string> <string name="place_ack_total">Last Place Acknowledgement Total</string>
<string name="current_week">Current Week</string> <string name="current_week">Current Week</string>
<string name="prev_ack_total">Previous Acknowledgement Count</string> <string name="prev_ack_total">Previous Acknowledgement Count</string>
<string name="your_progress">Your Progress</string>
</resources> </resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment