From 3e1b8d4cb7b279009b71f842238f805a822f47ab Mon Sep 17 00:00:00 2001 From: Sergej A Date: Thu, 25 Aug 2016 18:55:11 +0200 Subject: [PATCH] Major changes Added german language, some additions to Help layout, fixed a bug in DBHandler, changed BreakActivity and layout for it, cleaned code in BreakReminder, fixed bug in ExerciseListPreference, cleaned code in ProfileActivity, --- .../BreakActivity.java | 316 ++++++++------ .../BreakReminder.java | 185 ++++---- .../DBHandler.java | 40 +- .../ExerciseListPreference.java | 38 +- .../ProfileActivity.java | 11 +- app/src/main/res/layout/activity_break.xml | 68 ++- .../layout/activity_break_no_exercises.xml | 48 ++ app/src/main/res/layout/app_widget2x1.xml | 2 +- app/src/main/res/layout/app_widget2x2.xml | 2 +- app/src/main/res/layout/app_widget3x3.xml | 2 +- app/src/main/res/layout/app_widget4x4.xml | 2 +- app/src/main/res/layout/help.xml | 413 +++++++++--------- app/src/main/res/layout/new_profile.xml | 8 +- app/src/main/res/values-de/strings.xml | 89 ++++ app/src/main/res/values/strings.xml | 105 ++--- app/src/main/res/xml/pref_general.xml | 13 +- 16 files changed, 727 insertions(+), 615 deletions(-) create mode 100644 app/src/main/res/layout/activity_break_no_exercises.xml create mode 100644 app/src/main/res/values-de/strings.xml diff --git a/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/BreakActivity.java b/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/BreakActivity.java index 03e9211..55c42d3 100644 --- a/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/BreakActivity.java +++ b/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/BreakActivity.java @@ -14,6 +14,7 @@ import android.support.v4.app.NotificationCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; +import android.view.WindowManager; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; @@ -28,14 +29,14 @@ public class BreakActivity extends AppCompatActivity implements View.OnClickList private boolean isRunning = false; private List exerciseList; private SharedPreferences sharedPrefs; - private TextView description, side_repetition, break_exercise_type; + private TextView description, side_repetition, break_exercise_type, execution; private int currentExercise, breakTime = 0; - private ImageView image, image_mid, image_right; + private ImageView image; + private String[] exercises; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_break); currentExercise = 0; sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -46,56 +47,61 @@ public class BreakActivity extends AppCompatActivity implements View.OnClickList bufferZeroMinute = "0"; ct_text = (TextView) findViewById(R.id.textViewBreak); - ct_text.setText(bufferZeroMinute + mins + ":00"); - - Button skipButton = (Button) findViewById(R.id.button_next); - skipButton.setOnClickListener(this); - ct_text.setOnClickListener(this); - - -// LinearLayout ll = (LinearLayout) findViewById(R.id.layout_break); -// // TODO Do it dynamically -// for (int i = 0; i < 20; i++) { -// ImageView image = new ImageView(this); -// image.setLayoutParams(new android.view.ViewGroup.LayoutParams(80, 60)); -// image.setImageResource(R.drawable.statistic_logo); -// ll.addView(image); -// } DBHandler dbHandler = new DBHandler(this); String[] allProfiles = sharedPrefs.getString("profiles", "").split(";"); String currentProfile = sharedPrefs.getString("name_text", ""); - String[] exercises = new String[8]; + for (int i = 0; i < allProfiles.length; i++) { - if (allProfiles[i].split(",")[0].equals(currentProfile)) { - System.out.println("Hi: " + allProfiles[i].split(",")[4]); + if (allProfiles[i].split(",")[0].equals(currentProfile) && !allProfiles[i].split(",")[4].equals("-1")) { exercises = allProfiles[i].split(",")[4].split("\\."); } } - exerciseList = dbHandler.getExercisesFromSection(exercises[currentExercise]); - description = (TextView) findViewById(R.id.textViewDescription); - description.setText(exerciseList.get(currentExercise).getDescription()); - side_repetition = (TextView) findViewById(R.id.textSideRepetition); - side_repetition.setText("Break"); + 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); - break_exercise_type = (TextView) findViewById(R.id.break_exercise_type); - break_exercise_type.setText(exerciseList.get(currentExercise).getSection()); + 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); - image = (ImageView) findViewById(R.id.imageView); - image_mid = (ImageView) findViewById(R.id.imageMid); - image_right = (ImageView) findViewById(R.id.imageRight); - image.setImageResource(R.drawable.train_left); - image_right.setImageResource(R.drawable.train_right); + + //TODO Iterate over all + exerciseList = dbHandler.getExercisesFromSection(exercises[currentExercise]); + 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()); + + image = (ImageView) findViewById(R.id.imageMid); + image.setImageResource(R.drawable.train_left); + } + + //Keep screen on while on break + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } public void onClick(View v) { - final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); int mins = sharedPrefs.getInt("break_value", 10); String bufferZeroMinute = ""; String bufferZeroSecond = ""; int time = mins * 60 * 1000; - int oldTime = time; if (stopTime == "" && !isRunning) { if (time / 1000 / 60 < 10) @@ -126,148 +132,172 @@ public class BreakActivity extends AppCompatActivity implements View.OnClickList switch (v.getId()) { + case R.id.textViewBreak1: case R.id.textViewBreak: if (isRunning) { ct.cancel(); stopTime = (String) ct_text.getText(); isRunning = false; } else { - 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); - - //FIXME 10 Sec break -> 10 + 10 exercise -> 10 sec break - 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", ""); - System.out.println("Sound: " + ringPref); - if (!ringPref.equals("")) { - System.out.println("-----------------PLAY NOTIFICATION SOUND----------------"); - Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), Uri.parse(ringPref)); - r.play(); - } - - //FIXME Test Vibration - boolean vibrateChecked = sharedPrefs.getBoolean("notifications_new_message_vibrate", false); - System.out.println("Vibrate is : " + vibrateChecked); - if (vibrateChecked) { - // Get instance of Vibrator from current Context - Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); - - if (v == null) { - System.out.println("No vibrator! :D"); - } else { - // Vibrate for 3000 milliseconds - System.out.println("Vibrate for 3000 ms"); - v.vibrate(3000); - } - } - - //Cancel the notification - if (timeLeft) { - NotificationManager notificationManager = - (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - notificationManager.cancel(999); - } - finish(); - //startBreak(); - } - }.start(); - isRunning = true; + startTimer(time); } break; + + case R.id.button_cancel: + if (ct != null) + ct.cancel(); + finish(); + break; + case R.id.button_next: - //TODO Update Timer + + // Next Exercise currentExercise++; - System.out.println("Current Ex#: " + currentExercise + " , All Ex#: " + exerciseList.size()); - side_repetition.setText("Break"); + side_repetition.setText(R.string.exercise_break); if (currentExercise > exerciseList.size() - 1) currentExercise = 0; + description.setText(exerciseList.get(currentExercise).getDescription()); + execution.setText(exerciseList.get(currentExercise).getExecution()); - switch (currentExercise % 3) { - case 0: - image.setImageResource(R.drawable.train_left); - image_mid.setImageResource(android.R.color.transparent); - image_right.setImageResource(R.drawable.train_right); - break; + //Update Timer + String[] currentTime = ((String) ct_text.getText()).split(":"); - case 1: - image.setImageResource(android.R.color.transparent); - image_mid.setImageResource(R.drawable.train_left); - image_right.setImageResource(android.R.color.transparent); - break; + int minute = Integer.parseInt(currentTime[0]); + int second = Integer.parseInt(currentTime[1]); + System.out.println("Current Minute: " + minute + " and current second: " + second); - case 2: - image.setImageResource(android.R.color.transparent); - image_mid.setImageResource(R.drawable.train_right); - image_right.setImageResource(android.R.color.transparent); - break; + 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); + } } - description.setText(exerciseList.get(currentExercise).getDescription()); - - //finish(); break; } } private void update() { - breakTime++; + //FIXME Change to the correct picture and whether its side or repetetion + breakTime++; switch (breakTime) { case 10: System.out.println("Time for Exercise: Left!"); - image_mid.setImageResource(R.drawable.train_left); - image_right.setImageResource(android.R.color.transparent); - image.setImageResource(android.R.color.transparent); - side_repetition.setText("Side/Repetition 1"); - break; - case 20: - System.out.println("Time for Exercise: Right!"); - image_mid.setImageResource(R.drawable.train_right); - side_repetition.setText("Side/Repetition 2"); + side_repetition.setText(R.string.exercise_repetition + " 1"); break; case 30: + System.out.println("Time for Break between sides!"); + side_repetition.setText(R.string.exercise_break); + image.setImageResource(R.drawable.train_middle); + break; + case 40: + System.out.println("Time for Exercise: Right!"); + side_repetition.setText(R.string.exercise_repetition + " 2"); + break; + case 60: System.out.println("Next Exercise!"); - image.setImageResource(R.drawable.train_left); - image_mid.setImageResource(android.R.color.transparent); - image_right.setImageResource(R.drawable.train_right); + image.setImageResource(R.drawable.train_right); breakTime = 0; currentExercise++; + if (currentExercise > exerciseList.size() - 1) + currentExercise = 0; description.setText(exerciseList.get(currentExercise).getDescription()); + execution.setText(exerciseList.get(currentExercise).getExecution()); side_repetition.setText("Break"); - + 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); + finish(); + } + }.start(); + isRunning = true; + } } diff --git a/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/BreakReminder.java b/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/BreakReminder.java index caf8027..5c5cebf 100644 --- a/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/BreakReminder.java +++ b/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/BreakReminder.java @@ -72,8 +72,7 @@ public class BreakReminder extends AppCompatActivity String allProfiles = sharedPrefs.getString("profiles", ""); if (allProfiles.equals("")) { - System.out.println("Es gibt noch keine Profile!!"); - allProfiles = "Random,90,5,false,Arms.Legs.Head.Neck.Pelvis.Spinal Column.Trunk.;Upper-Body,90,15,true,Arms.Neck.Head.;Torso,30,5,true,Spinal Column.Trunk.;Under-Body,30,5,true,Legs.Pelvis.;"; + allProfiles = this.getResources().getText(R.string.standard_profile).toString(); editor.putString("profiles", allProfiles); editor.apply(); @@ -81,9 +80,7 @@ public class BreakReminder extends AppCompatActivity welcomeDialog.show(getFragmentManager(), "WelcomeDialog"); } - - - System.out.println("Alle Profile: " + sharedPrefs.getString("profiles", "FAIL")); + System.out.println("Alle Profile: " + sharedPrefs.getString("profiles", "-1")); // If chosen, set screen to "stay on" boolean stayOn = sharedPrefs.getBoolean("notifications_stayOn", false); @@ -116,9 +113,8 @@ public class BreakReminder extends AppCompatActivity String[] fillProfileNames = allProfiles.split(";"); for (int i = 0; i < profileNames.length - 1; i++) { profileNames[i] = fillProfileNames[i].split(",")[0]; - System.out.println("Profile name:" + profileNames[i]); } - profileNames[profileNames.length - 1] = "New Profile..."; + profileNames[profileNames.length - 1] = this.getResources().getText(R.string.new_profile).toString(); ArrayAdapter adapter = new ArrayAdapter(this, R.layout.spinner_layout, profileNames); profileSpinner.setAdapter(adapter); @@ -128,7 +124,6 @@ public class BreakReminder extends AppCompatActivity public void onItemSelected(AdapterView parent, View view, int position, long id) { String profileSelected = (String) parent.getItemAtPosition(position); - if (profileSelected.equals("New Profile...")) { createNewProfile(); } else { updatePreference(profileSelected); @@ -145,11 +140,9 @@ public class BreakReminder extends AppCompatActivity String allProfiles = sharedPrefs.getString("profiles", ""); - String currentProfile = sharedPrefs.getString("name_text", "") + "," + sharedPrefs.getInt("work_value", -1) + "," + sharedPrefs.getInt("break_value", -1) + "," + sharedPrefs.getBoolean("cont_value", false)+ "," + sharedPrefs.getString("exercise_value", "-1"); + String currentProfile = sharedPrefs.getString("name_text", "") + "," + sharedPrefs.getInt("work_value", -1) + "," + sharedPrefs.getInt("break_value", -1) + "," + sharedPrefs.getBoolean("cont_value", false) + "," + sharedPrefs.getString("exercise_value", "-1"); - if (allProfiles.contains(currentProfile) && profileSelected.equals(sharedPrefs.getString("name_text", ""))) { - System.out.println("Profile didn´t change"); - } else { + if (!allProfiles.contains(currentProfile) && profileSelected.equals(sharedPrefs.getString("name_text", ""))) { if (ct != null) { ct.cancel(); isRunning = false; @@ -201,7 +194,6 @@ public class BreakReminder extends AppCompatActivity for (int i = 0; i < profileNames.length - 1; i++) { profileNames[i] = fillProfileNames[i].split(",")[0]; } - profileNames[profileNames.length - 1] = "New Profile..."; ArrayAdapter adapter = new ArrayAdapter(this, R.layout.spinner_layout, profileNames); profileSpinner.setAdapter(adapter); @@ -224,7 +216,6 @@ public class BreakReminder extends AppCompatActivity profileSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView parent, View view, int position, long id) { String profileSelected = (String) parent.getItemAtPosition(position); - if (profileSelected.equals("New Profile...")) { createNewProfile(); } else { updatePreference(profileSelected); @@ -249,16 +240,11 @@ public class BreakReminder extends AppCompatActivity else getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - System.out.println("Activity resumed!!"); - //FIXME Add flag if New Profile or Resume if (sharedPrefs.getBoolean("change_profiles", false)) { System.out.println("Change Profiles is true!"); fillProfiles(); - //profileSpinner = (Spinner) findViewById(R.id.spinner); - - SharedPreferences.Editor editor = sharedPrefs.edit(); editor.putBoolean("change_profiles", false); editor.apply(); @@ -344,85 +330,7 @@ public class BreakReminder extends AppCompatActivity stopTime = (String) ct_text.getText(); isRunning = false; } else { - 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); - - updateWidgets(bufferZeroMinute + (millisUntilFinished / 1000) / 60 + ":" + bufferZeroSecond + millisUntilFinished / 1000 % 60); - - //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 Reminder: ") - .setContentText("Take a break in " + ((millisUntilFinished / 1000) / 60) + " minutes and " + ((millisUntilFinished / 1000) % 60) + " seconds") - .setAutoCancel(true) - .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).build(); - NotificationManager notificationManager = - (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - notificationManager.notify(1000, notification); - } - } - - public void onFinish() { - isRunning = false; - ct_text.setText("00:00"); - - updateWidgets("00:00"); - - //trigger the alarm - String ringPref = sharedPrefs.getString("notifications_new_message_ringtone", ""); - - if (!ringPref.equals("")) { - // Get the current ringtone - Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), Uri.parse(ringPref)); - - // Play ringtone - r.play(); - } - - 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) { - System.out.println("No vibrator! :D"); - } else { - // Vibrate for 1500 milliseconds - v.vibrate(1500); - } - } - - //Cancel the notification - if (timeLeft) { - NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - notificationManager.cancel(1000); - } - startBreak(); - - String workTime = "" + sharedPrefs.getInt("work_value", 0); - if(workTime.length() == 1) - workTime = "0" + workTime; - - ct_text.setText(workTime + ":00"); - updateWidgets(workTime + ":00"); - } - }.start(); - isRunning = true; + startTimer(time); } break; @@ -457,6 +365,87 @@ public class BreakReminder extends AppCompatActivity } } + + 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); + + updateWidgets(bufferZeroMinute + (millisUntilFinished / 1000) / 60 + ":" + bufferZeroSecond + millisUntilFinished / 1000 % 60); + + //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 Reminder: ") + .setContentText("Take a break in " + ((millisUntilFinished / 1000) / 60) + " minutes and " + ((millisUntilFinished / 1000) % 60) + " seconds") + .setAutoCancel(true) + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).build(); + NotificationManager notificationManager = + (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + notificationManager.notify(1000, notification); + } + } + + public void onFinish() { + isRunning = false; + ct_text.setText("00:00"); + + updateWidgets("00:00"); + + //trigger the alarm + String ringPref = sharedPrefs.getString("notifications_new_message_ringtone", ""); + + if (!ringPref.equals("")) { + // Get the current ringtone + Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), Uri.parse(ringPref)); + + // Play ringtone + r.play(); + } + + 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(1000); + } + startBreak(); + + String workTime = "" + sharedPrefs.getInt("work_value", 0); + if (workTime.length() == 1) + workTime = "0" + workTime; + + ct_text.setText(workTime + ":00"); + updateWidgets(workTime + ":00"); + } + }.start(); + isRunning = true; + } + private void createNewProfile() { SharedPreferences.Editor editor = sharedPrefs.edit(); editor.putBoolean("change_profiles", true); diff --git a/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/DBHandler.java b/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/DBHandler.java index b3a405a..c4031fb 100644 --- a/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/DBHandler.java +++ b/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/DBHandler.java @@ -9,6 +9,7 @@ import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; +import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -38,20 +39,22 @@ public class DBHandler extends SQLiteOpenHelper { DEVICE_LANGUAGE = Locale.getDefault().getLanguage(); + if(!DEVICE_LANGUAGE.equals("de") && !DEVICE_LANGUAGE.equals("fr") && !DEVICE_LANGUAGE.equals("ru")) + DEVICE_LANGUAGE = "en"; System.out.println("Current Language: " + DEVICE_LANGUAGE); - //If Database exists open - if (checkDataBase()) { - openDataBase(); - } else { + + //Check if database exists + File databaseFile = mContext.getDatabasePath(DATABASE_NAME); + if (false == databaseFile.exists()) { + this.getReadableDatabase(); try { - this.getReadableDatabase(); copyDataBase(); this.close(); - openDataBase(); - } catch (IOException e) { - e.printStackTrace(); + } catch (Exception e) { + Log.v("db log", "Copying data didn´t work!!"); } } + } @Override @@ -83,8 +86,6 @@ public class DBHandler extends SQLiteOpenHelper { Exercise exercise; List exerciseList = new ArrayList<>(); dataBase = this.getReadableDatabase(); - if (DEVICE_LANGUAGE.equals("de")) - section = "nacken"; Cursor res = dataBase.rawQuery("SELECT * FROM EXERCISES_" + DEVICE_LANGUAGE + " WHERE " + EXERCISES_SECTION + " LIKE " + "\"%" + section + "%\"", null); res.moveToFirst(); @@ -98,25 +99,6 @@ public class DBHandler extends SQLiteOpenHelper { return exerciseList; } - - private boolean checkDataBase() { - dataBase = null; - boolean exist = false; - try { - String dbPath = DATABASE_PATH + DATABASE_NAME; - dataBase = SQLiteDatabase.openDatabase(dbPath, null, - SQLiteDatabase.OPEN_READONLY); - } catch (SQLiteException e) { - Log.v("db log", "Database doesn't exist!!"); - } - - if (dataBase != null) { - exist = true; - closeDataBase(); - } - return exist; - } - public void openDataBase() throws SQLException { String dbPath = DATABASE_PATH + DATABASE_NAME; dataBase = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE); diff --git a/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/ExerciseListPreference.java b/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/ExerciseListPreference.java index 2fc2c45..b50065e 100644 --- a/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/ExerciseListPreference.java +++ b/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/ExerciseListPreference.java @@ -27,11 +27,6 @@ public class ExerciseListPreference extends ListPreference implements DialogInte mClickedDialogEntryIndices = new boolean[getEntries().length]; } - public ExerciseListPreference(Context context) { - this(context, null); - mClickedDialogEntryIndices = new boolean[getEntries().length]; - } - @Override protected View onCreateDialogView() { @@ -51,7 +46,7 @@ public class ExerciseListPreference extends ListPreference implements DialogInte CharSequence[] entries = getEntries(); CharSequence[] entryValues = getEntryValues(); - if (entries == null || entryValues == null || entries.length != entryValues.length ) { + if (entries == null || entryValues == null || entries.length != entryValues.length) { throw new IllegalStateException( "ListPreference requires an entries array and an entryValues array which are both the same length"); } @@ -67,18 +62,17 @@ public class ExerciseListPreference extends ListPreference implements DialogInte private void restoreCheckedEntries() { CharSequence[] entryValues = getEntries(); - System.out.println("VALUE-CHECK" + getValue()); - for ( int j=0; j 0 ) - // exs = exs.substring(0, exs.length()); - // setValue(exs); - //} } + if (exs.equals("")) + exs = "-1"; + SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("exercise_value", exs); editor.apply(); diff --git a/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/ProfileActivity.java b/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/ProfileActivity.java index 3592ef8..383e37b 100644 --- a/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/ProfileActivity.java +++ b/app/src/main/java/orgprivacy_friendly_apps/secuso/privacyfriendlybreakreminder/ProfileActivity.java @@ -28,7 +28,7 @@ public class ProfileActivity extends AppCompatActivity implements View.OnClickLi setContentView(R.layout.new_profile); sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); - oldExerciseValue = sharedPrefs.getString("exercise_value","-1"); + oldExerciseValue = sharedPrefs.getString("exercise_value", "-1"); SharedPreferences.Editor editor = sharedPrefs.edit(); editor.putString("exercise_value", "-1"); @@ -40,14 +40,14 @@ public class ProfileActivity extends AppCompatActivity implements View.OnClickLi break_seekbar.setProgress(1); interval_text = (TextView) findViewById(R.id.interval_text); - interval_text.setText("1 Minutes"); + interval_text.setText("1 " + getResources().getText(R.string.settings_unit)); break_text = (TextView) findViewById(R.id.break_text); - break_text.setText("1 Minutes"); + break_text.setText("1 " + getResources().getText(R.string.settings_unit)); interval_seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - interval_text.setText(progress + " Minutes"); + interval_text.setText(progress + " " + getResources().getText(R.string.settings_unit)); } @Override @@ -62,7 +62,7 @@ public class ProfileActivity extends AppCompatActivity implements View.OnClickLi break_seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - break_text.setText(progress + " Minutes"); + break_text.setText(progress + " " + getResources().getText(R.string.settings_unit)); } @Override @@ -147,7 +147,6 @@ public class ProfileActivity extends AppCompatActivity implements View.OnClickLi private void createExerciseType() { Intent intent = new Intent(this, ExerciseTypeActivity.class); this.startActivity(intent); - System.out.println("Exercise Type Activity!"); } } diff --git a/app/src/main/res/layout/activity_break.xml b/app/src/main/res/layout/activity_break.xml index 2f7d576..a8d39d9 100644 --- a/app/src/main/res/layout/activity_break.xml +++ b/app/src/main/res/layout/activity_break.xml @@ -17,7 +17,7 @@ android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:text="@string/exercise_type" - android:textAppearance="?android:attr/textAppearanceMedium" /> + android:textAppearance="?android:attr/textAppearanceLarge" /> - - + android:text="@string/exercise_break" + android:textAppearance="?android:attr/textAppearanceLarge" + android:textColor="@color/yellow" + android:textStyle="bold" /> - - + android:layout_below="@+id/textSideRepetition" />