* The default NavigationDrawer functionality is implemented in this class. If you wish to inherit * the default behaviour, make sure the content view has a NavigationDrawer with the id 'nav_view', * the header should point to 'nav_header_main' and the menu should be loaded from 'main_drawer'. - * + *
* Also the main layout that holds the content of the activity should have the id 'main_content'. * This way it will automatically fade in and out every time a transition is happening. - * */ public abstract class BaseActivity extends AppCompatActivity implements OnNavigationItemSelectedListener { @@ -69,7 +69,7 @@ public abstract class BaseActivity extends AppCompatActivity implements OnNaviga public static final int MAIN_CONTENT_FADEIN_DURATION = 250; // Navigation drawer: - public DrawerLayout mDrawerLayout; + public DrawerLayout mDrawerLayout; private NavigationView mNavigationView; // Helper @@ -106,10 +106,9 @@ public boolean onNavigationItemSelected(MenuItem item) { } - protected boolean goToNavigationItem(final int itemId) { - if(itemId == getNavigationDrawerID()) { + if (itemId == getNavigationDrawerID()) { // just close drawer because we are already in this activity mDrawerLayout.closeDrawer(GravityCompat.START); return true; @@ -137,7 +136,7 @@ public void run() { // set active navigation item private void selectNavigationItem(int itemId) { - for(int i = 0 ; i < mNavigationView.getMenu().size(); i++) { + for (int i = 0; i < mNavigationView.getMenu().size(); i++) { boolean b = itemId == mNavigationView.getMenu().getItem(i).getItemId(); mNavigationView.getMenu().getItem(i).setChecked(b); } @@ -146,6 +145,7 @@ private void selectNavigationItem(int itemId) { /** * Enables back navigation for activities that are launched from the NavBar. See * {@code AndroidManifest.xml} to find out the parent activity names for each activity. + * * @param intent */ private void createBackStack(Intent intent) { @@ -162,12 +162,13 @@ private void createBackStack(Intent intent) { /** * This method manages the behaviour of the navigation drawer * Add your menu items (ids) to res/menu/activity_main_drawer.xml + * * @param itemId Item that has been clicked by the user */ private void callDrawerItem(final int itemId) { Intent intent; - switch(itemId) { + switch (itemId) { case R.id.nav_example: intent = new Intent(this, MainActivity.class); @@ -187,13 +188,13 @@ private void callDrawerItem(final int itemId) { createBackStack(intent); break; case R.id.nav_statistics: - intent = new Intent(this,StatsActivity.class); + intent = new Intent(this, StatsActivity.class); createBackStack(intent); break; case R.id.nav_settings: intent = new Intent(this, SettingsActivity.class); - intent.putExtra( PreferenceActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.GeneralPreferenceFragment.class.getName() ); - intent.putExtra( PreferenceActivity.EXTRA_NO_HEADERS, true ); + intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.GeneralPreferenceFragment.class.getName()); + intent.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true); createBackStack(intent); break; default: @@ -205,7 +206,7 @@ protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - if(getSupportActionBar() == null) { + if (getSupportActionBar() == null) { setSupportActionBar(toolbar); } diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/BaseActivityWithoutNavBar.java b/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/BaseActivityWithoutNavBar.java index 919128a..dfc144d 100644 --- a/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/BaseActivityWithoutNavBar.java +++ b/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/BaseActivityWithoutNavBar.java @@ -20,15 +20,9 @@ import android.os.Bundle; import android.os.Handler; +import android.view.View; -import com.google.android.material.navigation.NavigationView.OnNavigationItemSelectedListener; -import androidx.core.app.TaskStackBuilder; -import androidx.core.view.GravityCompat; -import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; - -import android.view.View; import org.secuso.privacyfriendly2048.R; @@ -37,14 +31,13 @@ * @version 20171017 * This class is a parent class of all activities that can be accessed from the * Navigation Drawer (example see MainActivity.java) - * + *
* The default NavigationDrawer functionality is implemented in this class. If you wish to inherit * the default behaviour, make sure the content view has a NavigationDrawer with the id 'nav_view', * the header should point to 'nav_header_main' and the menu should be loaded from 'main_drawer'. - * + *
* Also the main layout that holds the content of the activity should have the id 'main_content'. * This way it will automatically fade in and out every time a transition is happening. - * */ public abstract class BaseActivityWithoutNavBar extends AppCompatActivity { diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/GameState.java b/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/GameState.java index bee8e3a..3de5a90 100644 --- a/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/GameState.java +++ b/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/GameState.java @@ -20,14 +20,11 @@ package org.secuso.privacyfriendly2048.activities.helper; -import android.util.Log; - import org.secuso.privacyfriendly2048.activities.Element; import java.io.Serializable; /** - * * @author Julian Wadephul and Saskia Jacob * @version 20180807 */ @@ -37,86 +34,75 @@ public class GameState implements Serializable { public int[] last_numbers; public int points = 0; public int last_points = 0; - public boolean undo=false; + public boolean undo = false; - public GameState(int size) - { - numbers = new int[size*size]; + public GameState(int size) { + numbers = new int[size * size]; } - public GameState(int [][] e) - { + + public GameState(int[][] e) { int length = 1; - for(int i = 0; i < e.length; i++) - { - if(e[i].length > length) + for (int i = 0; i < e.length; i++) { + if (e[i].length > length) length = e[i].length; } this.n = e.length; - numbers = new int[e.length*e.length]; + numbers = new int[e.length * e.length]; int c = 0; - for(int i = 0; i < e.length;i++) - { - for(int j = 0; j < e[i].length;j++){ + for (int i = 0; i < e.length; i++) { + for (int j = 0; j < e[i].length; j++) { numbers[c++] = e[i][j]; } } last_numbers = numbers; } - public GameState(Element[][] e, Element[][] e2) - { + + public GameState(Element[][] e, Element[][] e2) { int length = 1; - for(int i = 0; i < e.length; i++) - { - if(e[i].length > length) + for (int i = 0; i < e.length; i++) { + if (e[i].length > length) length = e[i].length; } this.n = e.length; - numbers = new int[e.length*e.length]; + numbers = new int[e.length * e.length]; int c = 0; - for(int i = 0; i < e.length;i++) - { - for(int j = 0; j < e[i].length;j++){ + for (int i = 0; i < e.length; i++) { + for (int j = 0; j < e[i].length; j++) { numbers[c++] = e[i][j].number; } } length = 1; - for(int i = 0; i < e2.length; i++) - { - if(e2[i].length > length) + for (int i = 0; i < e2.length; i++) { + if (e2[i].length > length) length = e2[i].length; } - last_numbers = new int[e2.length*e2.length]; + last_numbers = new int[e2.length * e2.length]; c = 0; - for(int i = 0; i < e2.length;i++) - { - for(int j = 0; j < e2[i].length;j++){ + for (int i = 0; i < e2.length; i++) { + for (int j = 0; j < e2[i].length; j++) { last_numbers[c++] = e2[i][j].number; } } } - public int getNumber(int i, int j) - { + + public int getNumber(int i, int j) { try { - return numbers[i*n+j]; - } - catch(ArrayIndexOutOfBoundsException e) - { + return numbers[i * n + j]; + } catch (ArrayIndexOutOfBoundsException e) { e.printStackTrace(); } return 0; } - public int getLastNumber(int i, int j) - { + + public int getLastNumber(int i, int j) { try { - return last_numbers[i*n+j]; - } - catch(ArrayIndexOutOfBoundsException e) - { + return last_numbers[i * n + j]; + } catch (ArrayIndexOutOfBoundsException e) { e.printStackTrace(); } @@ -124,11 +110,10 @@ public int getLastNumber(int i, int j) } - @Override public String toString() { String result = "numbers: "; - for (int i:numbers) { + for (int i : numbers) { result += i + " "; } result += ", n: " + n; diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/GameStatistics.java b/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/GameStatistics.java index 3347c17..84fbb43 100644 --- a/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/GameStatistics.java +++ b/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/GameStatistics.java @@ -39,11 +39,10 @@ private long record = 0; private int undo = 0; private int moves_l = 0; private int moves_r = 0; - private int moves_t= 0; + private int moves_t = 0; private int moves_d = 0; - public GameStatistics(int n) - { + public GameStatistics(int n) { this.n = n; filename = "statistics" + n + ".txt"; } @@ -54,8 +53,8 @@ public long getHighestNumber() { } public void setHighestNumber(long highestNumber) { - if(this.highestNumber < highestNumber) - this.highestNumber = highestNumber; + if (this.highestNumber < highestNumber) + this.highestNumber = highestNumber; } public long getTimePlayed() { @@ -66,8 +65,7 @@ public void addTimePlayed(long timePlayed) { this.timePlayed += timePlayed; } - public boolean resetTimePlayed() - { + public boolean resetTimePlayed() { this.timePlayed = 0; return true; } @@ -92,36 +90,34 @@ public void setRecord(long record) { this.record = record; } - public void undo() - { + public void undo() { undo++; } - public void moveL() - { + + public void moveL() { moves_l++; } - public void moveR() - { + + public void moveR() { moves_r++; } - public void moveT() - { + + public void moveT() { moves_t++; } - public void moveD() - { + + public void moveD() { moves_d++; } - public int getUndo() - { + public int getUndo() { return undo; } @Override public String toString() { return "moves " + moves + - " timePlayed " + timePlayed/1000.0f + + " timePlayed " + timePlayed / 1000.0f + " highest Number " + highestNumber + " record" + record; } diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/Gestures.java b/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/Gestures.java index 10ad66e..8b9da6a 100644 --- a/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/Gestures.java +++ b/app/src/main/java/org/secuso/privacyfriendly2048/activities/helper/Gestures.java @@ -20,13 +20,13 @@ package org.secuso.privacyfriendly2048.activities.helper; import android.content.Context; -import android.util.Log; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; /** * This class implements the Gestures Listener for swiping in the game + * * @author Julian Wadephul and Saskia Jacob * @version 20180807 */ @@ -57,7 +57,7 @@ public boolean onDown(MotionEvent e) { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - + boolean result = false; try { float diffY = e2.getY() - e1.getY(); @@ -69,7 +69,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve } else { result = onSwipeLeft(); } - }else{ + } else { result = nichts(); } } else { @@ -79,7 +79,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve } else { result = onSwipeTop(); } - }else{ + } else { result = nichts(); } } @@ -98,7 +98,7 @@ public boolean onSwipeLeft() { return false; } - public boolean nichts(){ + public boolean nichts() { return false; } diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/backup/BackupCreator.kt b/app/src/main/java/org/secuso/privacyfriendly2048/backup/BackupCreator.kt index 8c75900..0e0bc8c 100644 --- a/app/src/main/java/org/secuso/privacyfriendly2048/backup/BackupCreator.kt +++ b/app/src/main/java/org/secuso/privacyfriendly2048/backup/BackupCreator.kt @@ -5,11 +5,11 @@ import android.content.Context import android.preference.PreferenceManager import android.util.JsonWriter import android.util.Log +import org.secuso.privacyfriendly2048.database.PFASQLiteHelper import org.secuso.privacyfriendlybackup.api.backup.DatabaseUtil.getSupportSQLiteOpenHelper import org.secuso.privacyfriendlybackup.api.backup.DatabaseUtil.writeDatabase import org.secuso.privacyfriendlybackup.api.backup.PreferenceUtil.writePreferences import org.secuso.privacyfriendlybackup.api.pfa.IBackupCreator -import org.secuso.privacyfriendly2048.database.PFASQLiteHelper import java.io.OutputStream import java.io.OutputStreamWriter diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/backup/BackupRestorer.kt b/app/src/main/java/org/secuso/privacyfriendly2048/backup/BackupRestorer.kt index 88db518..7ad5098 100644 --- a/app/src/main/java/org/secuso/privacyfriendly2048/backup/BackupRestorer.kt +++ b/app/src/main/java/org/secuso/privacyfriendly2048/backup/BackupRestorer.kt @@ -5,11 +5,10 @@ import android.content.SharedPreferences import android.preference.PreferenceManager import android.util.JsonReader import android.util.Log -import androidx.annotation.NonNull +import org.secuso.privacyfriendly2048.database.PFASQLiteHelper import org.secuso.privacyfriendlybackup.api.backup.DatabaseUtil import org.secuso.privacyfriendlybackup.api.backup.FileUtil import org.secuso.privacyfriendlybackup.api.pfa.IBackupRestorer -import org.secuso.privacyfriendly2048.database.PFASQLiteHelper import java.io.IOException import java.io.InputStream import java.io.InputStreamReader @@ -75,17 +74,20 @@ class BackupRestorer : IBackupRestorer { when (name) { "switch_preference_1", "pref_animationActivated" -> preferences.putBoolean(name, reader.nextBoolean()) + "pref_color" -> preferences.putString(name, reader.nextString()) "FirstLaunchManager.PREF_PICKER_SECONDS", "FirstLaunchManager.PREF_PICKER_MINUTES", "FirstLaunchManager.PREF_BREAK_PICKER_SECONDS", "FirstLaunchManager.PREF_PICKER_HOURS", "FirstLaunchManager.PREF_BREAK_PICKER_MINUTES" -> preferences.putInt(name, reader.nextInt()) + "pref_schedule_exercise_days" -> preferences.putStringSet(name, readPreferenceSet(reader)) "WORK_TIME", "PAUSE TIME", "pref_schedule_exercise_time", "DEFAULT_EXERCISE_SET" -> preferences.putLong(name, reader.nextLong()) + else -> throw RuntimeException("Unknown preference $name") } } diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/database/DatabaseExporter.java b/app/src/main/java/org/secuso/privacyfriendly2048/database/DatabaseExporter.java index 26fbde8..c391038 100644 --- a/app/src/main/java/org/secuso/privacyfriendly2048/database/DatabaseExporter.java +++ b/app/src/main/java/org/secuso/privacyfriendly2048/database/DatabaseExporter.java @@ -31,10 +31,10 @@ /** * @author Karola Marky * @version 20161225 - * Structure based on http://tech.sarathdr.com/android-app/convert-database-cursor-result-to-json-array-android-app-development/ - * accessed at 25th December 2016 - *
- * This class turns a database into a JSON string + * Structure based on http://tech.sarathdr.com/android-app/convert-database-cursor-result-to-json-array-android-app-development/ + * accessed at 25th December 2016 + *
+ * This class turns a database into a JSON string
*/
public class DatabaseExporter {
@@ -51,6 +51,7 @@ public DatabaseExporter(String DB_PATH, String DB_NAME) {
/**
* Turns a single DB table into a JSON string
+ *
* @return JSON string of the table
*/
public JSONArray tableToJSON(String TABLE_NAME) {
@@ -123,7 +124,6 @@ public ArrayList
* This class defines the structure of our database.
*/
@@ -90,6 +89,7 @@ public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVers
* Adds a single sampleData to our Table
* As no ID is provided and KEY_ID is autoincremented (see line 50)
* the last available key of the table is taken and incremented by 1
+ *
* @param sampleData data that will be added
*/
public void addSampleData(PFASampleDataType sampleData) {
@@ -109,8 +109,9 @@ public void addSampleData(PFASampleDataType sampleData) {
* Adds a single sampleData to our Table
* This method can be used for re-insertion for example an undo-action
* Therefore, the key of the sampleData will also be written into the database
+ *
* @param sampleData data that will be added
- * Only use this for undo options and re-insertions
+ * Only use this for undo options and re-insertions
*/
public void addSampleDataWithID(PFASampleDataType sampleData) {
SQLiteDatabase database = this.getWritableDatabase();
@@ -131,6 +132,7 @@ public void addSampleDataWithID(PFASampleDataType sampleData) {
/**
* This method gets a single sampleData entry based on its ID
+ *
* @param id of the sampleData that is requested, could be get by the get-method
* @return the sampleData that is requested.
*/
@@ -145,7 +147,7 @@ public PFASampleDataType getSampleData(int id) {
PFASampleDataType sampleData = new PFASampleDataType();
- if( cursor != null && cursor.moveToFirst() ){
+ if (cursor != null && cursor.moveToFirst()) {
sampleData.setID(Integer.parseInt(cursor.getString(0)));
sampleData.setDOMAIN(cursor.getString(1));
sampleData.setUSERNAME(cursor.getString(2));
@@ -163,6 +165,7 @@ public PFASampleDataType getSampleData(int id) {
/**
* This method returns all data from the DB as a list
* This could be used for instance to fill a recyclerView
+ *
* @return A list of all available sampleData in the Database
*/
public List
* This class holds the "data type" that will be stored in the database
* Each column of the database will be a private variable in this class.
* For each data type one class is required.
* In our example we only use one data type, which is sampleData
- *
*/
public class PFASampleDataType {
@@ -38,22 +36,24 @@ public class PFASampleDataType {
private String USERNAME;
private int LENGTH;
- public PFASampleDataType() { }
+ public PFASampleDataType() {
+ }
/**
* Always use this constructor to generate data with values.
- * @param ID The primary key for the database (will be automatically set by the DB)
- * @param DOMAIN Some sample String that could be in the DB
+ *
+ * @param ID The primary key for the database (will be automatically set by the DB)
+ * @param DOMAIN Some sample String that could be in the DB
* @param USERNAME Some sample String that could be in the DB
- * @param LENGTH Some sample int that could be in the DB
+ * @param LENGTH Some sample int that could be in the DB
*/
public PFASampleDataType(int ID, String DOMAIN, String USERNAME, int LENGTH) {
- this.ID=ID;
- this.DOMAIN=DOMAIN;
- this.USERNAME=USERNAME;
- this.LENGTH=LENGTH;
+ this.ID = ID;
+ this.DOMAIN = DOMAIN;
+ this.USERNAME = USERNAME;
+ this.LENGTH = LENGTH;
}
/**
diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/helpers/FirstLaunchManager.java b/app/src/main/java/org/secuso/privacyfriendly2048/helpers/FirstLaunchManager.java
index aa4b221..950ac92 100644
--- a/app/src/main/java/org/secuso/privacyfriendly2048/helpers/FirstLaunchManager.java
+++ b/app/src/main/java/org/secuso/privacyfriendly2048/helpers/FirstLaunchManager.java
@@ -57,7 +57,7 @@ public boolean isFirstTimeLaunch() {
}
public void initFirstTimeLaunch() {
- if(pref.getBoolean(IS_FIRST_TIME_LAUNCH, true)) {
+ if (pref.getBoolean(IS_FIRST_TIME_LAUNCH, true)) {
// First time setup in here
}
}
diff --git a/app/src/main/res/drawable/game_brick.xml b/app/src/main/res/drawable/game_brick.xml
index 8f4ba23..29aed91 100644
--- a/app/src/main/res/drawable/game_brick.xml
+++ b/app/src/main/res/drawable/game_brick.xml
@@ -1,10 +1,8 @@
-