forked from Zikoz/Greenery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCO2_fragment.java
More file actions
86 lines (68 loc) · 2.8 KB
/
CO2_fragment.java
File metadata and controls
86 lines (68 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.sunshineregiment.greenery;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.support.v4.app.Fragment;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
/**
* Created by Zikoz on 10/03/2017.
*/
public class CO2_fragment extends Fragment {
private BiometricProfile profile;
private Conversions conversion;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_co2, container, false);
}
//private boolean resumeHasRun = false;
@Override
public void onResume() {
super.onResume();
ImageView image = (ImageView) getActivity().findViewById(R.id.img_switcher);
TextView convertToLitres = (TextView) getActivity().findViewById(R.id.conversion_liters);
TextView convertToCo2 = (TextView) getActivity().findViewById(R.id.conversion_co2_grams);
TextView convertToTrees = (TextView) getActivity().findViewById(R.id.conversion_trees);
int n = 3;
image.setScaleX(n);
image.setScaleY(n);
drawTree(image);
showLit(convertToLitres);
showLCo2(convertToCo2);
showTrees(convertToTrees);
//todo: dynamically set these values
profile = new BiometricProfile(20, 70, 1.75, false);//age, weight, height, gender
conversion = new Conversions(2000,profile,true);//steps taken, profile, diesel engine (true = yes)
}
public void showLit(TextView text){
double lit = conversion.getFuel();
text.setText("You have saved " + lit + " litres of fuel");
}
public void showLCo2(TextView text){
int co2 = conversion.getCO2();
text.setText("You have saved " + co2 + " grams of CO2");
}
public void showTrees(TextView text){
double treesSaved = conversion.getTreeDays();
text.setText("You have saved "+ (int) treesSaved + " tree days of CO2");
}
public void drawTree(ImageView image) {
int bronzeT = 100,
silverT = 300,
goldT = 500;
SharedPreferences prefs = getActivity().getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
int steps = prefs.getInt("steps", 0);
if (steps < bronzeT) {
image.setImageResource(R.drawable.tree1);
} else if (steps >= bronzeT && steps < silverT) {
image.setImageResource(R.drawable.tree2);
} else if (steps >= silverT && steps < goldT) {
image.setImageResource(R.drawable.tree3);
} else if (steps >= goldT) {
image.setImageResource(R.drawable.tree4);
}
}
}