-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
218 lines (172 loc) · 7.7 KB
/
MainActivity.java
File metadata and controls
218 lines (172 loc) · 7.7 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package com.slouchieteam.slouchie;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.support.v7.widget.SwitchCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ToggleButton;
public class MainActivity extends ActionBarActivity {
public static ToggleButton servicetogglebutton;
int countdown = 0;
public static boolean trackingservicerunning;
Intent postureserviceintent;
ToggleButton.OnCheckedChangeListener changeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
beginPostureTracking();
} else {
stopService(postureserviceintent);
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
servicetogglebutton = (ToggleButton) findViewById(R.id.servicetogglebutton);
if (trackingservicerunning) {
servicetogglebutton.setChecked(true);
} else {
servicetogglebutton.setChecked(false);
}
servicetogglebutton.setOnCheckedChangeListener(changeListener);
View scrollview = findViewById(R.id.scrollView);
scrollview.setVisibility(View.INVISIBLE);
scrollview.post(new Runnable() {
@Override
public void run() {
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slidein);
View scrollview = findViewById(R.id.scrollView);
scrollview.startAnimation(anim);
scrollview.setVisibility(View.VISIBLE);
}
});
postureserviceintent = new Intent(this, PostureService.class);
postureserviceintent.putExtra(PostureService.PACKAGE_NAME + ".myaction", PostureService.intentstartid);
makecardshideable();
int angle = getSharedPreferences(getPackageName(), MODE_PRIVATE).getInt("angle", 12);
getSharedPreferences(getPackageName(), MODE_PRIVATE).edit().putInt("angle", angle).commit();
boolean strongvibration = getSharedPreferences(getPackageName(), MODE_PRIVATE).getBoolean("strongvibration", false);
getSharedPreferences(getPackageName(), MODE_PRIVATE).edit().putBoolean("strongvibration", strongvibration).commit();
((TextView) findViewById(R.id.seektext)).setText(String.valueOf(angle));
SeekBar bar = ((SeekBar) findViewById(R.id.seekbar));
bar.setOnSeekBarChangeListener(seekbarlistener);
bar.setProgress(angle);
SwitchCompat vibrationswitch = (SwitchCompat) findViewById(R.id.vibrationswitch);
vibrationswitch.setChecked(strongvibration);
vibrationswitch.setOnCheckedChangeListener(vibrationswitchchangedlistener);
LinearLayout vibrationswitchlayout = (LinearLayout) findViewById(R.id.vibrationswitchlayout);
vibrationswitchlayout.setOnClickListener(switchlayoutlistener);
}
public void makecardshideable() {
LinearLayout Cardslayout = (LinearLayout) findViewById(R.id.cardslayout);
if (Cardslayout != null) {
int count = Cardslayout.getChildCount();
for (int i = 0; i <= count; i++) {
View v = Cardslayout.getChildAt(i);
if (v instanceof CardView) {
v.setOnClickListener(hidecardslistener);
}
}
}
}
public static void servicestopped() {
servicetogglebutton.setChecked(false);
}
void beginPostureTracking() {
// stopService(postureserviceintent);
startService(postureserviceintent);
}
View.OnClickListener switchlayoutlistener = new View.OnClickListener() {
@Override
public void onClick(View v) {
SwitchCompat vibrationswitch = (SwitchCompat) findViewById(R.id.vibrationswitch);
vibrationswitch.setChecked(!vibrationswitch.isChecked());
getSharedPreferences(getPackageName(), MODE_PRIVATE).edit().putBoolean("strongvibration", vibrationswitch.isChecked()).commit();
}
};
SwitchCompat.OnCheckedChangeListener vibrationswitchchangedlistener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
getSharedPreferences(getPackageName(), MODE_PRIVATE).edit().putBoolean("strongvibration", isChecked).commit();
}
};
SeekBar.OnSeekBarChangeListener seekbarlistener = new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
((TextView) findViewById(R.id.seektext)).setText(String.valueOf(progress) + "°");
getSharedPreferences(getPackageName(), MODE_PRIVATE).edit().putInt("angle", progress).commit();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
};
View.OnClickListener hidecardslistener = new View.OnClickListener() {
@Override
public void onClick(View v) {
final View tobehidden = v.findViewWithTag("hideable");
if (tobehidden != null) {
if (tobehidden.getVisibility() == View.GONE) {
tobehidden.post(new Runnable() {
@Override
public void run() {
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.appear);
tobehidden.startAnimation(anim);
tobehidden.setVisibility(View.VISIBLE);
}
});
} else {
tobehidden.post(new Runnable() {
@Override
public void run() {
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.disappear);
tobehidden.startAnimation(anim);
}
});
tobehidden.postDelayed(new Runnable() {
@Override
public void run() {
tobehidden.setVisibility(View.GONE);
}
}, 300);
}
}
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onDestroy() {
// vibratehandler.removeCallbacks(vibraterunnable);
super.onDestroy();
}
}