Code Cleaning

Deleting old classes
This commit is contained in:
Jannik 2016-09-04 17:52:30 +02:00
commit 1d87fc66ec
3 changed files with 0 additions and 438 deletions

View file

@ -42,8 +42,6 @@
android:screenOrientation="portrait"/>
<activity android:name=".AboutActivity"
android:screenOrientation="portrait"/>
<activity android:name=".StatisticsActivity"
android:screenOrientation="portrait"/>
<activity android:name=".HelpActivity"
android:screenOrientation="portrait"/>

View file

@ -1,399 +0,0 @@
package orgprivacy_friendly_apps.secuso.privacyfriendlybreakreminder;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* Created by badri_000 on 26.08.2016.
*/
public class BreakActivity_old extends AppCompatActivity implements View.OnClickListener {
private TextView ct_text;
private CountDownTimer ct;
private String stopTime = "", sideRepetition = "";
String image1, image2;
private boolean isRunning = false;
private List<Exercise> exerciseList;
private SharedPreferences sharedPrefs;
private TextView description, side_repetition, break_exercise_type, execution;
private int currentExercise, breakTime = 0, currentExerciseSection;
private ImageView image;
private String[] exercises;
private DBHandler dbHandler;
private List<List<Exercise>> allAvailableExercises;
private List<Integer> sections;
private Random random;
private boolean exerciseSide = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
currentExercise = 0;
currentExerciseSection = 0;
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
int mins = sharedPrefs.getInt("break_value", 5);
String bufferZeroMinute = "";
if (mins < 10)
bufferZeroMinute = "0";
String[] allProfiles = sharedPrefs.getString("profiles", "").split(";");
String currentProfile = sharedPrefs.getString("name_text", "");
for (int i = 0; i < allProfiles.length; i++) {
if (allProfiles[i].split(",")[0].equals(currentProfile) && !allProfiles[i].split(",")[4].equals("-1")) {
exercises = allProfiles[i].split(",")[4].split("\\.");
}
}
if (exercises == null) {
setContentView(R.layout.activity_break_no_exercises);
Button cancelButton = (Button) findViewById(R.id.button_cancel);
cancelButton.setOnClickListener(this);
ct_text = (TextView) findViewById(R.id.textViewBreak1);
ct_text.setText(bufferZeroMinute + mins + ":00");
ct_text.setOnClickListener(this);
} else {
setContentView(R.layout.activity_break);
Button nextButton = (Button) findViewById(R.id.button_next);
nextButton.setOnClickListener(this);
ct_text = (TextView) findViewById(R.id.textViewBreak);
ct_text.setText(bufferZeroMinute + mins + ":00");
ct_text.setOnClickListener(this);
dbHandler = new DBHandler(this);
random = new Random();
sections = new ArrayList<>();
setRandomExercises();
}
//Keep screen on while on break
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
public void onClick(View v) {
int mins = sharedPrefs.getInt("break_value", 10);
String bufferZeroMinute = "";
String bufferZeroSecond = "";
int time = mins * 60 * 1000;
if (stopTime == "" && !isRunning) {
if (time / 1000 / 60 < 10)
bufferZeroMinute = "0";
ct_text.setText(bufferZeroMinute + time / 1000 / 60 + ":00");
} else if (!isRunning) {
ct_text.setText(stopTime);
String stringTime = (String) ct_text.getText();
String[] timef = stringTime.split(":");
int minute = Integer.parseInt(timef[0]);
int second = Integer.parseInt(timef[1]);
System.out.println("Minute: " + minute + " Second: " + second);
time = (1000 * (minute * 60)) + (1000 * second);
if (minute < 10)
bufferZeroMinute = "0";
if (second < 10)
bufferZeroSecond = "0";
ct_text.setText(bufferZeroMinute + minute + ":" + bufferZeroSecond + second);
}
switch (v.getId()) {
case R.id.textViewBreak1:
case R.id.textViewBreak:
if (isRunning) {
ct.cancel();
stopTime = (String) ct_text.getText();
isRunning = false;
} else {
startTimer(time);
}
break;
case R.id.button_cancel:
if (ct != null)
ct.cancel();
finish();
break;
case R.id.button_next:
// Next Exercise
currentExercise++;
side_repetition.setText(R.string.exercise_break);
if (currentExercise > exerciseList.size() - 1) {
currentExercise = 0;
if (sections.size() == allAvailableExercises.size()) {
System.out.println("Did all exercises, restart!");
sections = new ArrayList<>();
}
while (true) {
currentExerciseSection = random.nextInt(allAvailableExercises.size());
if (!sections.contains(currentExerciseSection)) {
sections.add(currentExerciseSection);
exerciseList = allAvailableExercises.get(currentExerciseSection);
break_exercise_type.setText(exercises[currentExerciseSection]);
System.out.println("Random id for section election: " + currentExerciseSection);
break;
}
}
}
//Set description and execution text of current exercise
description.setText(exerciseList.get(currentExercise).getDescription());
execution.setText(exerciseList.get(currentExercise).getExecution());
//FIXME
setExerciseImage();
//Update Timer
String[] currentTime = ((String) ct_text.getText()).split(":");
int minute = Integer.parseInt(currentTime[0]);
int second = Integer.parseInt(currentTime[1]);
if (second != 0) {
ct.cancel();
breakTime = 0;
if (minute == 0 && second > 0) {
minute = 1;
second = 0;
} else if (minute > 0 && second > 0) {
minute++;
second = 0;
}
if (minute < 10)
bufferZeroMinute = "0";
if (second < 10)
bufferZeroSecond = "0";
System.out.println("New Time: " + bufferZeroMinute + minute + ":" + bufferZeroSecond + second);
if (isRunning) {
time = minute * 60 * 1000;
startTimer(time);
} else {
stopTime = bufferZeroMinute + minute + ":" + bufferZeroSecond + second;
ct_text.setText(stopTime);
}
}
break;
}
}
private void setRandomExercises() {
allAvailableExercises = new ArrayList<>();
System.out.println("Number of sections: " + exercises.length);
for (int i = 0; i < exercises.length; i++) {
List<Exercise> list = dbHandler.getExercisesFromSection(exercises[i]);
allAvailableExercises.add(list);
System.out.println("Section: " + exercises[i] + " and number of ex for it: " + list.size());
}
currentExerciseSection = random.nextInt(allAvailableExercises.size());
System.out.println("Random id for section election: " + currentExerciseSection);
// Set exercise list to current section
exerciseList = allAvailableExercises.get(currentExerciseSection);
sections.add(currentExerciseSection);
description = (TextView) findViewById(R.id.textViewDescription);
description.setText(exerciseList.get(currentExercise).getDescription());
execution = (TextView) findViewById(R.id.textViewExecution);
execution.setText(exerciseList.get(currentExercise).getExecution());
side_repetition = (TextView) findViewById(R.id.textSideRepetition);
side_repetition.setText(R.string.exercise_break);
break_exercise_type = (TextView) findViewById(R.id.break_exercise_type);
break_exercise_type.setText(exerciseList.get(currentExercise).getSection());
//FIXME
setExerciseImage();
}
private void setExerciseImage() {
String imageID = exerciseList.get(currentExercise).getImageID();
image = (ImageView) findViewById(R.id.imageMid);
if (imageID.split(",").length == 1) {
sideRepetition = getResources().getText(R.string.exercise_repetition).toString();
//FIXME Set correct image depending on imageID
image1 = imageID;
//Hardcoded
exerciseSide = false;
int imageResID = getResources().getIdentifier(image1, "drawable", getPackageName());
image.setImageResource(imageResID);
} else {
// There are 2 sides for an exercise
exerciseSide = true;
sideRepetition = getResources().getText(R.string.exercise_side).toString();
image1 = imageID.split(",")[0];
image2 = imageID.split(",")[1];
System.out.println("Id of first image: " + image1 + " , id of second: " + image2);
//image ID from Resource
int imageResID = getResources().getIdentifier(image1, "drawable", getPackageName());
image.setImageResource(imageResID);
}
}
//FIXME Change to the correct picture and whether its side or repetition
private void update() {
//After 10 seconds first side/repetition, then after 20 seconds break for 10 seconds, afterwards second side/repetition and after 20 seconds break and new exercise
breakTime++;
switch (breakTime) {
case 10:
System.out.println("Time for Exercise: Left!");
side_repetition.setText(sideRepetition + " 1");
break;
case 30:
System.out.println("Time for Break between sides!");
side_repetition.setText(R.string.exercise_break);
//If exercise contains 2 images, set ImageView to the second image
if (exerciseSide) {
//image ID from Resource
int imageResID = getResources().getIdentifier(image2, "drawable", getPackageName());
image.setImageResource(imageResID);
}
break;
case 40:
System.out.println("Time for Exercise: Right!");
side_repetition.setText(sideRepetition + " 2");
break;
case 60:
System.out.println("Next Exercise!");
breakTime = 0;
currentExercise++;
if (currentExercise > exerciseList.size() - 1) {
currentExercise = 0;
if (sections.size() == allAvailableExercises.size()) {
System.out.println("Did all exercises, restart!");
sections = new ArrayList<>();
}
while (true) {
currentExerciseSection = random.nextInt(allAvailableExercises.size());
if (!sections.contains(currentExerciseSection)) {
sections.add(currentExerciseSection);
exerciseList = allAvailableExercises.get(currentExerciseSection);
break_exercise_type.setText(exercises[currentExerciseSection]);
System.out.println("Random id for section election: " + currentExerciseSection);
break;
}
}
}
description.setText(exerciseList.get(currentExercise).getDescription());
execution.setText(exerciseList.get(currentExercise).getExecution());
side_repetition.setText(R.string.exercise_break);
//FIXME
setExerciseImage();
break;
}
}
private void startTimer(int time) {
ct = new CountDownTimer(time, 1000) {
boolean timeLeft = false;
public void onTick(long millisUntilFinished) {
String bufferZeroMinute = "";
String bufferZeroSecond = "";
if ((millisUntilFinished / 1000) / 60 < 10)
bufferZeroMinute = "0";
if (millisUntilFinished / 1000 % 60 < 10)
bufferZeroSecond = "0";
ct_text.setText(bufferZeroMinute + (millisUntilFinished / 1000) / 60 + ":" + bufferZeroSecond + millisUntilFinished / 1000 % 60);
// Update image and description of the exercise
update();
// //Show how much time is left
// timeLeft = sharedPrefs.getBoolean("notifications_new_message_timeLeft", false);
// if (timeLeft) {
// Notification notification = new NotificationCompat.Builder(getApplicationContext()).setCategory(Notification.CATEGORY_MESSAGE)
// .setSmallIcon(R.drawable.ic_notifications_black_24dp)
// .setContentTitle("Break Activity Reminder: ")
// .setContentText(((millisUntilFinished / 1000) / 60) + "Minutes and " + (millisUntilFinished / 1000 % 60) + " seconds")
// .setAutoCancel(true)
// .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).build();
// NotificationManager notificationManager =
// (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// notificationManager.notify(999, notification);
// }
}
public void onFinish() {
isRunning = false;
ct_text.setText("00:00");
//Trigger the alarm
String ringPref = sharedPrefs.getString("notifications_new_message_ringtone", "");
if (!ringPref.equals("")) {
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), Uri.parse(ringPref));
r.play();
}
//Vibration
boolean vibrateChecked = sharedPrefs.getBoolean("notifications_new_message_vibrate", false);
if (vibrateChecked) {
// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
// Vibrate for 1500 milliseconds
v.vibrate(1500);
}
}
//Cancel the notification
if (timeLeft) {
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(999);
}
//Remove lag to keep screen on when the break ends
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
//Close database connection
dbHandler.close();
finish();
}
}.start();
isRunning = true;
}
}

View file

@ -1,37 +0,0 @@
package orgprivacy_friendly_apps.secuso.privacyfriendlybreakreminder;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
public class StatisticsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.statistics);
setupActionBar();
}
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(R.string.statistics);
if (actionBar != null) {
// Show the Up button in the action bar.
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}