diff --git a/.github/workflows/android-test.yml b/.github/workflows/android-test.yml
new file mode 100644
index 0000000..e499e2f
--- /dev/null
+++ b/.github/workflows/android-test.yml
@@ -0,0 +1,99 @@
+name: Android Emulator Tests
+on: [ push, pull_request ]
+
+jobs:
+ check-if-tests-exist:
+ runs-on: ubuntu-latest
+ outputs:
+ status: ${{ steps.check-androidTest.outputs.NOT_EMPTY }}
+ min-sdk-version: ${{ steps.get-sdk-version.outputs.MIN_SDK_VERSION }}
+ target-sdk-version: ${{ steps.get-sdk-version.outputs.TARGET_SDK_VERSION }}
+ app-id: ${{ steps.get-app-id.outputs.APP_ID }}
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ with:
+ submodules: "recursive"
+ - name: Check if androidTest folder is not empty
+ run: |
+ echo "NOT_EMPTY=$([ "$(ls -A app/src/androidTest)" ] && echo 'true' || echo 'false')"
+ echo "NOT_EMPTY=$([ "$(ls -A app/src/androidTest)" ] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
+ id: check-androidTest
+ - name: Get min and target sdk
+ if: steps.check-androidTest.outputs.NOT_EMPTY == 'true'
+ id: get-sdk-version
+ run: |
+ echo "MIN_SDK_VERSION=$(cat app/build.gradle | grep minSdkVersion | rev | cut -d' ' -f 1 | rev)" >> $GITHUB_OUTPUT
+ echo "TARGET_SDK_VERSION=$(cat app/build.gradle | grep targetSdkVersion | rev | cut -d' ' -f 1 | rev)" >> $GITHUB_OUTPUT
+ - name: Get app ID
+ id: get-app-id
+ run: |
+ echo "APP_ID=$(cat app/build.gradle | grep applicationId | rev | cut -d' ' -f 1 | rev | tr -d '"')" >> $GITHUB_OUTPUT
+
+ test:
+ needs: check-if-tests-exist
+ if: needs.check-if-tests-exist.outputs.status == 'true'
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ api-level: [34, "${{ needs.check-if-tests-exist.outputs.min-sdk-version }}", "${{ needs.check-if-tests-exist.outputs.target-sdk-version }}"]
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ with:
+ submodules: 'recursive'
+
+ - name: Enable KVM group perms
+ run: |
+ echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
+ sudo udevadm control --reload-rules
+ sudo udevadm trigger --name-match=kvm
+
+ - name: Gradle cache
+ uses: gradle/gradle-build-action@v3
+
+ - name: AVD cache
+ uses: actions/cache@v4
+ id: avd-cache
+ with:
+ path: |
+ ~/.android/avd/*
+ ~/.android/adb*
+ key: avd-${{ matrix.api-level }}
+
+ - name: Set up JDK environment
+ uses: actions/setup-java@v3
+ with:
+ distribution: 'zulu'
+ java-version: 17
+
+ - name: create AVD and generate snapshot for caching
+ if: steps.avd-cache.outputs.cache-hit != 'true'
+ uses: reactivecircus/android-emulator-runner@v2
+ with:
+ api-level: ${{ matrix.api-level }}
+ target: ${{ matrix.api-level >= 30 && 'google_apis' || 'default' }}
+ arch: ${{ matrix.api-level < 21 && 'x86' || 'x86_64' }}
+ force-avd-creation: false
+ emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
+ disable-animations: false
+ script: echo "Generated AVD snapshot for caching."
+
+ - name: Run connected tests
+ uses: ReactiveCircus/android-emulator-runner@v2
+ with:
+ api-level: ${{ matrix.api-level }}
+ target: ${{ matrix.api-level >= 30 && 'google_apis' || 'default' }}
+ arch: ${{ matrix.api-level < 21 && 'x86' || 'x86_64' }}
+ force-avd-creation: false
+ emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
+ disable-animations: true
+ script: |
+ adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}} || true
+ adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.test || true
+ adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.androidTest || true
+ chmod +x gradlew
+ ./gradlew :app:connectedCheck --stacktrace
+ adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}} || true
+ adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.test || true
+ adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.androidTest || true
diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml
index ad4099a..6e50db1 100644
--- a/.github/workflows/changelog.yml
+++ b/.github/workflows/changelog.yml
@@ -2,7 +2,7 @@ name: Changelog Generation
on:
release:
- types: [published, released]
+ types: [published]
workflow_dispatch:
jobs:
@@ -16,6 +16,7 @@ jobs:
- uses: rhysd/changelog-from-release/action@v3
with:
file: CHANGELOG.md
+ pull_request: true
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_summary_template: 'update changelog for %s changes'
args: -l 2
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 99f0199..fe5b0a9 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -45,5 +45,23 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
+ - name: Run lint check
+ run: bash ./gradlew lint
+
+ - name: Upload lint result
+ uses: actions/upload-artifact@v4
+ with:
+ name: lint-results-debug
+ path: app/build/reports/lint-results-debug.html
+
- name: Build the app
- run: bash ./gradlew build --stacktrace
\ No newline at end of file
+ run: bash ./gradlew build --stacktrace
+
+ - name: Build debug apk
+ run: bash ./gradlew assembleDebug
+
+ - name: Upload debug apk
+ uses: actions/upload-artifact@v4
+ with:
+ name: debug-apk
+ path: app/build/outputs/apk/debug/*.apk
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 26585d3..1b5f058 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -12,8 +12,8 @@ android {
minSdkVersion 21
targetSdkVersion 34
compileSdk 34
- versionCode 7
- versionName "1.3.1"
+ versionCode 8
+ versionName "1.4.0"
}
buildTypes {
release {
@@ -36,7 +36,7 @@ android {
}
android.applicationVariants.configureEach { variant ->
- variant.outputs.all {
+ variant.outputs.configureEach {
def appName = "pfa-2048"
outputFileName = appName + "-${variant.name}-v${variant.versionName}.apk"
}
@@ -56,15 +56,15 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
- implementation 'androidx.appcompat:appcompat:1.6.1'
- implementation 'com.google.android.material:material:1.11.0'
+ implementation 'androidx.appcompat:appcompat:1.7.0'
+ implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
// Backup
implementation project(path: ':backup-api')
- def work_version = "2.9.0"
+ def work_version = "2.9.1"
implementation "androidx.work:work-runtime:$work_version"
implementation "androidx.work:work-runtime-ktx:$work_version"
androidTestImplementation "androidx.work:work-testing:$work_version"
diff --git a/app/src/androidTest/java/org/secuso/privacyfriendly2048/ApplicationTest.java b/app/src/androidTest/java/org/secuso/privacyfriendly2048/ApplicationTest.java
deleted file mode 100644
index 0f42b49..0000000
--- a/app/src/androidTest/java/org/secuso/privacyfriendly2048/ApplicationTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.secuso.privacyfriendly2048;
-
-import android.app.Application;
-import android.test.ApplicationTestCase;
-
-/**
- * Testing Fundamentals
- */
-public class ApplicationTest extends ApplicationTestCase {
- public ApplicationTest() {
- super(Application.class);
- }
-}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 2d40793..5fee9ec 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -72,9 +72,16 @@
android:value="org.secuso.privacyfriendly2048.activities.MainActivity" />
+
+
+
+
diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/activities/Element.java b/app/src/main/java/org/secuso/privacyfriendly2048/activities/Element.java
index ed11fe2..56a8a1e 100644
--- a/app/src/main/java/org/secuso/privacyfriendly2048/activities/Element.java
+++ b/app/src/main/java/org/secuso/privacyfriendly2048/activities/Element.java
@@ -22,11 +22,13 @@
import static org.secuso.privacyfriendly2048.helpers.ThemeResolverKt.GetColorInt;
import static org.secuso.privacyfriendly2048.helpers.ThemeResolverKt.GetColorRes;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ShapeDrawable;
+import android.util.TypedValue;
import android.view.View;
import org.secuso.privacyfriendly2048.R;
@@ -50,18 +52,22 @@ public class Element extends androidx.appcompat.widget.AppCompatButton {
public int dPosY = 0;
public boolean activated;
public boolean animateMoving = false;
- public float textSize = 24;
Context context;
int color;
+ @SuppressLint("RestrictedApi")
public Element(Context c) {
super(c);
context = c;
setAllCaps(false);
- setTextSize(textSize);
setBackgroundResource(R.drawable.game_brick);
setColor(GetColorRes(context, R.attr.buttonEmpty));
+ setMaxLines(1);
+ setAutoSizeTextTypeUniformWithConfiguration(1,
+ 100,
+ 1,
+ TypedValue.COMPLEX_UNIT_SP);
}
public void drawItem() {
@@ -136,14 +142,10 @@ public void drawItem() {
case 16384:
setColor(GetColorRes(context, R.attr.button16384));
setTextColor(GetColorInt(context, R.attr.button16384Text));
- textSize = textSize * 0.8f;
- setTextSize(textSize);
break;
case 32768:
setColor(GetColorRes(context, R.attr.button32768));
setTextColor(GetColorInt(context, R.attr.button32768Text));
- textSize = textSize * 0.8f;
- setTextSize(textSize);
break;
}
}
@@ -197,11 +199,6 @@ public int getPosY() {
return posY;
}
- public void updateFontSize() {
- textSize = (float) (getLayoutParams().width / 7.0);
- setTextSize(textSize);
- }
-
public Element copy() {
Element temp = new Element(context);
temp.number = number;
@@ -212,9 +209,7 @@ public Element copy() {
temp.dPosY = dPosY;
temp.activated = activated;
temp.animateMoving = animateMoving;
- temp.textSize = textSize;
temp.color = color;
- temp.setTextSize(textSize);
//temp.setBackgroundResource(backGroundResource);
temp.setColor(color);
temp.setVisibility(getVisibility());
diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/activities/GameActivity.java b/app/src/main/java/org/secuso/privacyfriendly2048/activities/GameActivity.java
index caa3855..0190ecd 100644
--- a/app/src/main/java/org/secuso/privacyfriendly2048/activities/GameActivity.java
+++ b/app/src/main/java/org/secuso/privacyfriendly2048/activities/GameActivity.java
@@ -30,6 +30,7 @@
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.util.Log;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -164,7 +165,36 @@ protected void onCreate(Bundle savedInstanceState) {
}
-
+ private void handleUndo() {
+ undoButton.setVisibility(View.INVISIBLE);
+ if (undo && last_elements != null) {
+ gameStatistics.undo();
+ elements = last_elements;
+ points = last_points;
+ number_field.removeAllViews();
+ //number_field_background.removeAllViews();
+ points = last_points;
+ textFieldPoints.setText("" + points);
+ setDPositions(false);
+ for (Element[] i : elements) {
+ for (Element j : i) {
+ j.setVisibility(View.INVISIBLE);
+ number_field.addView(j);
+ j.drawItem();
+ }
+ }
+ for (int i = 0; i < elements.length; i++) {
+ for (int j = 0; j < elements[i].length; j++) {
+ elements[i][j].setOnTouchListener(swipeListener);
+ backgroundElements[i][j].setOnTouchListener(swipeListener);
+ }
+ }
+ updateGameState();
+ drawAllElements(elements);
+ number_field.refreshDrawableState();
+ }
+ undo = false;
+ }
public void initResources() {
number_field = (RelativeLayout) findViewById(R.id.number_field);
number_field_background = (RelativeLayout) findViewById(R.id.number_field_background);
@@ -180,37 +210,11 @@ public void onClick(View v) {
}
});
undoButton = (ImageButton) findViewById(R.id.undoButton);
+
undoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- undoButton.setVisibility(View.INVISIBLE);
- if (undo && last_elements != null) {
- gameStatistics.undo();
- elements = last_elements;
- points = last_points;
- number_field.removeAllViews();
- //number_field_background.removeAllViews();
- points = last_points;
- textFieldPoints.setText("" + points);
- setDPositions(false);
- for (Element[] i : elements) {
- for (Element j : i) {
- j.setVisibility(View.INVISIBLE);
- number_field.addView(j);
- j.drawItem();
- }
- }
- for (int i = 0; i < elements.length; i++) {
- for (int j = 0; j < elements[i].length; j++) {
- elements[i][j].setOnTouchListener(swipeListener);
- backgroundElements[i][j].setOnTouchListener(swipeListener);
- }
- }
- updateGameState();
- drawAllElements(elements);
- number_field.refreshDrawableState();
- }
- undo = false;
+ handleUndo();
}
});
@@ -362,7 +366,6 @@ record = gameStatistics.getRecord();
elements[i][j].setDPosition(lp.getMarginStart(), lp.topMargin);
elements[i][j].setLayoutParams(lp);
backgroundElements[i][j].setLayoutParams(lp);
- elements[i][j].updateFontSize();
backgroundElements[i][j].setLayoutParams(lp);
backgroundElements[i][j].setOnTouchListener(swipeListener);
elements[i][j].setOnTouchListener(swipeListener);
@@ -409,331 +412,371 @@ public Element[][] deepCopy(Element[][] e) {
return r;
}
- public void setListener() {
- swipeListener = new Gestures(this) {
- public boolean onSwipeTop() {
- Element[][] temp = deepCopy(elements);
- int temp_points = points;
- moved = false;
- Element s = new Element(myActivity);
-
- for (int i = 0; i < elements.length; i++) {
- s.number = elements[0][i].number;
- s.posX = 0;
- s.posY = i;
-
-
- for (int j = 1; j < elements[i].length; j++) {
- if (elements[j][i].number != 0 && (s.number == 0 || s.number == elements[j][i].number)) {
- moved = true;
- elements[j][i].setNumber(s.number + elements[j][i].number);
- elements[s.posX][s.posY].setNumber(0);
- switchElementPositions(elements[j][i], elements[s.posX][s.posY]);
- Element z = elements[j][i];
- elements[j][i] = elements[s.posX][s.posY];
- elements[s.posX][s.posY] = z;
- if (s.number != 0)
- points += elements[s.posX][s.posY].number;
- if (s.number != 0)
- s.posX++;
- j = s.posX;
- s.number = elements[j][i].number;
-
- } else if (elements[j][i].number != 0) {
- s.number = elements[j][i].number;
- s.posX = j;
- s.posY = i;
- }
- }
+ private boolean handleSwipeTop() {
+ Element[][] temp = deepCopy(elements);
+ int temp_points = points;
+ moved = false;
+ Element s = new Element(myActivity);
- }
- for (int i = 0; i < elements.length; i++) {
- s.number = elements[0][i].number;
- s.posX = 0;
+ for (int i = 0; i < elements.length; i++) {
+ s.number = elements[0][i].number;
+ s.posX = 0;
+ s.posY = i;
+
+
+ for (int j = 1; j < elements[i].length; j++) {
+ if (elements[j][i].number != 0 && (s.number == 0 || s.number == elements[j][i].number)) {
+ moved = true;
+ elements[j][i].setNumber(s.number + elements[j][i].number);
+ elements[s.posX][s.posY].setNumber(0);
+ switchElementPositions(elements[j][i], elements[s.posX][s.posY]);
+ Element z = elements[j][i];
+ elements[j][i] = elements[s.posX][s.posY];
+ elements[s.posX][s.posY] = z;
+ if (s.number != 0)
+ points += elements[s.posX][s.posY].number;
+ if (s.number != 0)
+ s.posX++;
+ j = s.posX;
+ s.number = elements[j][i].number;
+
+ } else if (elements[j][i].number != 0) {
+ s.number = elements[j][i].number;
+ s.posX = j;
s.posY = i;
-
-
- for (int j = 1; j < elements[i].length; j++) {
- if (elements[j][i].number != 0 && s.number == 0) {
- moved = true;
- elements[j][i].setNumber(s.number + elements[j][i].number);
- elements[s.posX][s.posY].setNumber(0);
- switchElementPositions(elements[j][i], elements[s.posX][s.posY]);
- Element z = elements[j][i];
- elements[j][i] = elements[s.posX][s.posY];
- elements[s.posX][s.posY] = z;
- if (s.number != 0)
- s.posX++;
- j = s.posX;
- s.number = elements[j][i].number;
-
- } else if (s.number != 0) {
- s.number = elements[j][i].number;
- s.posX = j;
- s.posY = i;
- }
- }
-
}
- if (moved) {
- gameStatistics.addMoves(1);
- last_points = temp_points;
- last_elements = temp;
- undoButton.setVisibility(View.VISIBLE);
- undo = true;
+ }
+
+ }
+ for (int i = 0; i < elements.length; i++) {
+ s.number = elements[0][i].number;
+ s.posX = 0;
+ s.posY = i;
+
+
+ for (int j = 1; j < elements[i].length; j++) {
+ if (elements[j][i].number != 0 && s.number == 0) {
+ moved = true;
+ elements[j][i].setNumber(s.number + elements[j][i].number);
+ elements[s.posX][s.posY].setNumber(0);
+ switchElementPositions(elements[j][i], elements[s.posX][s.posY]);
+ Element z = elements[j][i];
+ elements[j][i] = elements[s.posX][s.posY];
+ elements[s.posX][s.posY] = z;
+ if (s.number != 0)
+ s.posX++;
+ j = s.posX;
+ s.number = elements[j][i].number;
+
+ } else if (s.number != 0) {
+ s.number = elements[j][i].number;
+ s.posX = j;
+ s.posY = i;
}
- if (moved)
- gameStatistics.moveT();
- addNumber();
- setDPositions(animationActivated);
- updateGameState();
- //es wurde nach oben gewischt, hier den Code einfügen
- return false;
}
- public boolean onSwipeRight() {
- Element[][] temp = deepCopy(elements);
- int temp_points = points;
- moved = false;
- Element s = new Element(myActivity);
- for (int i = 0; i < elements.length; i++) {
- s.number = elements[i][elements[i].length - 1].number;
- s.posX = i;
- s.posY = elements[i].length - 1;
-
-
- for (int j = elements[i].length - 2; j >= 0; j--) {
- if (elements[i][j].number != 0 && (s.number == 0 || s.number == elements[i][j].number)) {
- moved = true;
-
- elements[i][j].setNumber(s.number + elements[i][j].number);
- elements[s.posX][s.posY].setNumber(0);
- switchElementPositions(elements[i][j], elements[s.posX][s.posY]);
- Element z = elements[i][j];
- elements[i][j] = elements[s.posX][s.posY];
- elements[s.posX][s.posY] = z;
-
- if (s.number != 0)
- points += elements[s.posX][s.posY].number;
- if (s.number != 0)
- s.posY--;
- j = s.posY;
- s.number = elements[i][j].number;
- } else if (elements[i][j].number != 0) {
- s.number = elements[i][j].number;
- s.posX = i;
- s.posY = j;
- }
- }
+ }
+ if (moved) {
+ gameStatistics.addMoves(1);
+ last_points = temp_points;
+ last_elements = temp;
+ undoButton.setVisibility(View.VISIBLE);
+ undo = true;
+ }
+ if (moved)
+ gameStatistics.moveT();
+ addNumber();
+ setDPositions(animationActivated);
+ updateGameState();
+ //es wurde nach oben gewischt, hier den Code einfügen
+ return false;
+ }
- }
- for (int i = 0; i < elements.length; i++) {
- s.number = elements[i][elements[i].length - 1].number;
+ private boolean handleSwipeRight() {
+ Element[][] temp = deepCopy(elements);
+ int temp_points = points;
+ moved = false;
+ Element s = new Element(myActivity);
+ for (int i = 0; i < elements.length; i++) {
+ s.number = elements[i][elements[i].length - 1].number;
+ s.posX = i;
+ s.posY = elements[i].length - 1;
+
+
+ for (int j = elements[i].length - 2; j >= 0; j--) {
+ if (elements[i][j].number != 0 && (s.number == 0 || s.number == elements[i][j].number)) {
+ moved = true;
+
+ elements[i][j].setNumber(s.number + elements[i][j].number);
+ elements[s.posX][s.posY].setNumber(0);
+ switchElementPositions(elements[i][j], elements[s.posX][s.posY]);
+ Element z = elements[i][j];
+ elements[i][j] = elements[s.posX][s.posY];
+ elements[s.posX][s.posY] = z;
+
+ if (s.number != 0)
+ points += elements[s.posX][s.posY].number;
+ if (s.number != 0)
+ s.posY--;
+ j = s.posY;
+ s.number = elements[i][j].number;
+ } else if (elements[i][j].number != 0) {
+ s.number = elements[i][j].number;
s.posX = i;
- s.posY = elements[i].length - 1;
+ s.posY = j;
+ }
+ }
+ }
+ for (int i = 0; i < elements.length; i++) {
+ s.number = elements[i][elements[i].length - 1].number;
+ s.posX = i;
+ s.posY = elements[i].length - 1;
- for (int j = elements[i].length - 2; j >= 0; j--) {
- if (elements[i][j].number != 0 && s.number == 0) {
- moved = true;
- elements[i][j].setNumber(s.number + elements[i][j].number);
- elements[s.posX][s.posY].setNumber(0);
- switchElementPositions(elements[i][j], elements[s.posX][s.posY]);
- Element z = elements[i][j];
- elements[i][j] = elements[s.posX][s.posY];
- elements[s.posX][s.posY] = z;
+ for (int j = elements[i].length - 2; j >= 0; j--) {
+ if (elements[i][j].number != 0 && s.number == 0) {
+ moved = true;
+ elements[i][j].setNumber(s.number + elements[i][j].number);
+ elements[s.posX][s.posY].setNumber(0);
+ switchElementPositions(elements[i][j], elements[s.posX][s.posY]);
+ Element z = elements[i][j];
+ elements[i][j] = elements[s.posX][s.posY];
+ elements[s.posX][s.posY] = z;
- if (s.number != 0)
- s.posY--;
- j = s.posY;
- s.number = elements[i][j].number;
- } else if (s.number != 0) {
- s.number = elements[i][j].number;
- s.posX = i;
- s.posY = j;
- }
- }
+ if (s.number != 0)
+ s.posY--;
+ j = s.posY;
+ s.number = elements[i][j].number;
+ } else if (s.number != 0) {
+ s.number = elements[i][j].number;
+ s.posX = i;
+ s.posY = j;
}
- if (moved) {
- gameStatistics.addMoves(1);
- last_points = temp_points;
- last_elements = temp;
- undoButton.setVisibility(View.VISIBLE);
- undo = true;
- }
- if (moved)
- gameStatistics.moveR();
- addNumber();
- setDPositions(animationActivated);
- updateGameState();
-
- //es wurde nach rechts gewischt, hier den Code einfügen
- return false;
}
- public boolean onSwipeLeft() {
- Element[][] temp = deepCopy(elements);
- int temp_points = points;
- moved = false;
- Element s = new Element(myActivity);
- for (int i = 0; i < elements.length; i++) {
- s.number = elements[i][0].number;
- s.posX = i;
- s.posY = 0;
-
-
- for (int j = 1; j < elements[i].length; j++) {
- if (elements[i][j].number != 0 && (s.number == 0 || s.number == elements[i][j].number)) {
- moved = true;
-
-
- elements[i][j].setNumber(s.number + elements[i][j].number);
- elements[s.posX][s.posY].setNumber(0);
- switchElementPositions(elements[i][j], elements[s.posX][s.posY]);
- Element z = elements[i][j];
- elements[i][j] = elements[s.posX][s.posY];
- elements[s.posX][s.posY] = z;
-
- if (s.number != 0)
- points += elements[s.posX][s.posY].number;
- if (s.number != 0)
- s.posY++;
- j = s.posY;
- s.number = elements[i][j].number;
- } else if (elements[i][j].number != 0) {
- s.number = elements[i][j].number;
- s.posX = i;
- s.posY = j;
- }
- }
+ }
+ if (moved) {
+ gameStatistics.addMoves(1);
+ last_points = temp_points;
+ last_elements = temp;
+ undoButton.setVisibility(View.VISIBLE);
+ undo = true;
+ }
+ if (moved)
+ gameStatistics.moveR();
+ addNumber();
+ setDPositions(animationActivated);
+ updateGameState();
- }
- for (int i = 0; i < elements.length; i++) {
- s.number = elements[i][0].number;
- s.posX = i;
- s.posY = 0;
-
- for (int j = 1; j < elements[i].length; j++) {
- if (elements[i][j].number != 0 && s.number == 0) {
- moved = true;
-
- elements[i][j].setNumber(s.number + elements[i][j].number);
- elements[s.posX][s.posY].setNumber(0);
- switchElementPositions(elements[i][j], elements[s.posX][s.posY]);
- Element z = elements[i][j];
- elements[i][j] = elements[s.posX][s.posY];
- elements[s.posX][s.posY] = z;
-
- if (s.number != 0)
- s.posY++;
- j = s.posY;
- s.number = elements[i][j].number;
- } else if (s.number != 0) {
- s.number = elements[i][j].number;
- s.posX = i;
- s.posY = j;
- }
- }
+ //es wurde nach rechts gewischt, hier den Code einfügen
+ return false;
+ }
+ private boolean handleSwipeLeft() {
+ Element[][] temp = deepCopy(elements);
+ int temp_points = points;
+ moved = false;
+ Element s = new Element(myActivity);
+ for (int i = 0; i < elements.length; i++) {
+ s.number = elements[i][0].number;
+ s.posX = i;
+ s.posY = 0;
+
+
+ for (int j = 1; j < elements[i].length; j++) {
+ if (elements[i][j].number != 0 && (s.number == 0 || s.number == elements[i][j].number)) {
+ moved = true;
+
+
+ elements[i][j].setNumber(s.number + elements[i][j].number);
+ elements[s.posX][s.posY].setNumber(0);
+ switchElementPositions(elements[i][j], elements[s.posX][s.posY]);
+ Element z = elements[i][j];
+ elements[i][j] = elements[s.posX][s.posY];
+ elements[s.posX][s.posY] = z;
+
+ if (s.number != 0)
+ points += elements[s.posX][s.posY].number;
+ if (s.number != 0)
+ s.posY++;
+ j = s.posY;
+ s.number = elements[i][j].number;
+ } else if (elements[i][j].number != 0) {
+ s.number = elements[i][j].number;
+ s.posX = i;
+ s.posY = j;
}
- if (moved) {
- gameStatistics.addMoves(1);
- last_points = temp_points;
- last_elements = temp;
- undoButton.setVisibility(View.VISIBLE);
- undo = true;
+ }
+
+ }
+ for (int i = 0; i < elements.length; i++) {
+ s.number = elements[i][0].number;
+ s.posX = i;
+ s.posY = 0;
+
+ for (int j = 1; j < elements[i].length; j++) {
+ if (elements[i][j].number != 0 && s.number == 0) {
+ moved = true;
+
+ elements[i][j].setNumber(s.number + elements[i][j].number);
+ elements[s.posX][s.posY].setNumber(0);
+ switchElementPositions(elements[i][j], elements[s.posX][s.posY]);
+ Element z = elements[i][j];
+ elements[i][j] = elements[s.posX][s.posY];
+ elements[s.posX][s.posY] = z;
+
+ if (s.number != 0)
+ s.posY++;
+ j = s.posY;
+ s.number = elements[i][j].number;
+ } else if (s.number != 0) {
+ s.number = elements[i][j].number;
+ s.posX = i;
+ s.posY = j;
}
- if (moved)
- gameStatistics.moveL();
- addNumber();
- setDPositions(animationActivated);
- updateGameState();
- //es wurde nach links gewischt, hier den Code einfügen
- return false;
}
- public boolean onSwipeBottom() {
- Element[][] temp = deepCopy(elements);
- int temp_points = points;
- moved = false;
- Element s = new Element(myActivity);
- for (int i = 0; i < elements.length; i++) {
- s.number = elements[elements[i].length - 1][i].number;
- s.posX = elements[i].length - 1;
+ }
+ if (moved) {
+ gameStatistics.addMoves(1);
+ last_points = temp_points;
+ last_elements = temp;
+ undoButton.setVisibility(View.VISIBLE);
+ undo = true;
+ }
+ if (moved)
+ gameStatistics.moveL();
+ addNumber();
+ setDPositions(animationActivated);
+ updateGameState();
+ //es wurde nach links gewischt, hier den Code einfügen
+ return false;
+ }
+
+ private boolean handleSwipeBottom() {
+ Element[][] temp = deepCopy(elements);
+ int temp_points = points;
+ moved = false;
+ Element s = new Element(myActivity);
+ for (int i = 0; i < elements.length; i++) {
+ s.number = elements[elements[i].length - 1][i].number;
+ s.posX = elements[i].length - 1;
+ s.posY = i;
+
+
+ for (int j = elements[i].length - 2; j >= 0; j--) {
+ if (elements[j][i].number != 0 && (s.number == 0 || s.number == elements[j][i].number)) {
+ moved = true;
+
+ elements[j][i].setNumber(s.number + elements[j][i].number);
+ elements[s.posX][s.posY].setNumber(0);
+ switchElementPositions(elements[j][i], elements[s.posX][s.posY]);
+ Element z = elements[j][i];
+ elements[j][i] = elements[s.posX][s.posY];
+ elements[s.posX][s.posY] = z;
+
+ if (s.number != 0)
+ points += elements[s.posX][s.posY].number;
+ if (s.number != 0)
+ s.posX--;
+ j = s.posX;
+ s.number = elements[j][i].number;
+ } else if (elements[j][i].number != 0) {
+ s.number = elements[j][i].number;
+ s.posX = j;
s.posY = i;
+ }
+ }
+ }
+ for (int i = 0; i < elements.length; i++) {
+ s.number = elements[elements[i].length - 1][i].number;
+ s.posX = elements[i].length - 1;
+ s.posY = i;
+
+
+ for (int j = elements[i].length - 2; j >= 0; j--) {
+ if (elements[j][i].number != 0 && s.number == 0) {
+ moved = true;
+
+ elements[j][i].setNumber(s.number + elements[j][i].number);
+ elements[s.posX][s.posY].setNumber(0);
+ switchElementPositions(elements[j][i], elements[s.posX][s.posY]);
+ Element z = elements[j][i];
+ elements[j][i] = elements[s.posX][s.posY];
+ elements[s.posX][s.posY] = z;
+
+ if (s.number != 0)
+ s.posX--;
+ j = s.posX;
+ s.number = elements[j][i].number;
+ } else if (s.number != 0) {
+ s.number = elements[j][i].number;
+ s.posX = j;
+ s.posY = i;
+ }
+ }
- for (int j = elements[i].length - 2; j >= 0; j--) {
- if (elements[j][i].number != 0 && (s.number == 0 || s.number == elements[j][i].number)) {
- moved = true;
-
- elements[j][i].setNumber(s.number + elements[j][i].number);
- elements[s.posX][s.posY].setNumber(0);
- switchElementPositions(elements[j][i], elements[s.posX][s.posY]);
- Element z = elements[j][i];
- elements[j][i] = elements[s.posX][s.posY];
- elements[s.posX][s.posY] = z;
-
- if (s.number != 0)
- points += elements[s.posX][s.posY].number;
- if (s.number != 0)
- s.posX--;
- j = s.posX;
- s.number = elements[j][i].number;
- } else if (elements[j][i].number != 0) {
- s.number = elements[j][i].number;
- s.posX = j;
- s.posY = i;
- }
- }
+ }
+ if (moved) {
+ gameStatistics.addMoves(1);
+ last_points = temp_points;
+ last_elements = temp;
+ undoButton.setVisibility(View.VISIBLE);
+ undo = true;
+ }
+ if (moved)
+ gameStatistics.moveD();
+ addNumber();
+ setDPositions(animationActivated);
+ updateGameState();
+ //es wurde nach unten gewischt, hier den Code einfügen
+ return false;
+ }
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_DPAD_UP:
+ handleSwipeTop();
+ return true;
+ case KeyEvent.KEYCODE_DPAD_RIGHT:
+ handleSwipeRight();
+ return true;
+ case KeyEvent.KEYCODE_DPAD_LEFT:
+ handleSwipeLeft();
+ return true;
+ case KeyEvent.KEYCODE_DPAD_DOWN:
+ handleSwipeBottom();
+ return true;
+ case KeyEvent.KEYCODE_Z:
+ if (event.isCtrlPressed()) {
+ handleUndo();
}
- for (int i = 0; i < elements.length; i++) {
- s.number = elements[elements[i].length - 1][i].number;
- s.posX = elements[i].length - 1;
- s.posY = i;
+ return true;
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+ public void setListener() {
+ swipeListener = new Gestures(this) {
+ public boolean onSwipeTop() {
+ return handleSwipeTop();
+ }
- for (int j = elements[i].length - 2; j >= 0; j--) {
- if (elements[j][i].number != 0 && s.number == 0) {
- moved = true;
-
- elements[j][i].setNumber(s.number + elements[j][i].number);
- elements[s.posX][s.posY].setNumber(0);
- switchElementPositions(elements[j][i], elements[s.posX][s.posY]);
- Element z = elements[j][i];
- elements[j][i] = elements[s.posX][s.posY];
- elements[s.posX][s.posY] = z;
-
- if (s.number != 0)
- s.posX--;
- j = s.posX;
- s.number = elements[j][i].number;
- } else if (s.number != 0) {
- s.number = elements[j][i].number;
- s.posX = j;
- s.posY = i;
- }
- }
+ public boolean onSwipeRight() {
+ return handleSwipeRight();
+ }
- }
- if (moved) {
- gameStatistics.addMoves(1);
- last_points = temp_points;
- last_elements = temp;
- undoButton.setVisibility(View.VISIBLE);
- undo = true;
- }
- if (moved)
- gameStatistics.moveD();
- addNumber();
- setDPositions(animationActivated);
- updateGameState();
- //es wurde nach unten gewischt, hier den Code einfügen
- return false;
+ public boolean onSwipeLeft() {
+ return handleSwipeLeft();
+ }
+
+ public boolean onSwipeBottom() {
+ return handleSwipeBottom();
}
public boolean nichts() {
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 dfc144d..db23755 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,6 +20,7 @@
import android.os.Bundle;
import android.os.Handler;
+import android.view.KeyEvent;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
@@ -78,4 +79,9 @@ protected void onPostCreate(Bundle savedInstanceState) {
}
}
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ return super.onKeyDown(keyCode, event);
+ }
+
}
diff --git a/app/src/main/res/drawable/layout4x4_o.jpg b/app/src/main/res/drawable/layout4x4_o.jpg
deleted file mode 100644
index 7071527..0000000
Binary files a/app/src/main/res/drawable/layout4x4_o.jpg and /dev/null differ
diff --git a/app/src/main/res/drawable/layout4x4_o.png b/app/src/main/res/drawable/layout4x4_o.png
new file mode 100644
index 0000000..03fe8b3
Binary files /dev/null and b/app/src/main/res/drawable/layout4x4_o.png differ
diff --git a/app/src/main/res/drawable/layout4x4_s.jpg b/app/src/main/res/drawable/layout4x4_s.jpg
deleted file mode 100644
index 2c49e1d..0000000
Binary files a/app/src/main/res/drawable/layout4x4_s.jpg and /dev/null differ
diff --git a/app/src/main/res/drawable/layout4x4_s.png b/app/src/main/res/drawable/layout4x4_s.png
new file mode 100644
index 0000000..bc1081d
Binary files /dev/null and b/app/src/main/res/drawable/layout4x4_s.png differ
diff --git a/app/src/main/res/drawable/layout5x5_o.jpg b/app/src/main/res/drawable/layout5x5_o.jpg
deleted file mode 100644
index 0099874..0000000
Binary files a/app/src/main/res/drawable/layout5x5_o.jpg and /dev/null differ
diff --git a/app/src/main/res/drawable/layout5x5_o.png b/app/src/main/res/drawable/layout5x5_o.png
new file mode 100644
index 0000000..ac310c3
Binary files /dev/null and b/app/src/main/res/drawable/layout5x5_o.png differ
diff --git a/app/src/main/res/drawable/layout5x5_s.jpg b/app/src/main/res/drawable/layout5x5_s.jpg
deleted file mode 100644
index d564105..0000000
Binary files a/app/src/main/res/drawable/layout5x5_s.jpg and /dev/null differ
diff --git a/app/src/main/res/drawable/layout5x5_s.png b/app/src/main/res/drawable/layout5x5_s.png
new file mode 100644
index 0000000..ce02f72
Binary files /dev/null and b/app/src/main/res/drawable/layout5x5_s.png differ
diff --git a/app/src/main/res/drawable/layout6x6_o.jpg b/app/src/main/res/drawable/layout6x6_o.jpg
deleted file mode 100644
index abfb311..0000000
Binary files a/app/src/main/res/drawable/layout6x6_o.jpg and /dev/null differ
diff --git a/app/src/main/res/drawable/layout6x6_o.png b/app/src/main/res/drawable/layout6x6_o.png
new file mode 100644
index 0000000..654478f
Binary files /dev/null and b/app/src/main/res/drawable/layout6x6_o.png differ
diff --git a/app/src/main/res/drawable/layout6x6_s.jpg b/app/src/main/res/drawable/layout6x6_s.jpg
deleted file mode 100644
index f09708c..0000000
Binary files a/app/src/main/res/drawable/layout6x6_s.jpg and /dev/null differ
diff --git a/app/src/main/res/drawable/layout6x6_s.png b/app/src/main/res/drawable/layout6x6_s.png
new file mode 100644
index 0000000..26c5a4b
Binary files /dev/null and b/app/src/main/res/drawable/layout6x6_s.png differ
diff --git a/app/src/main/res/drawable/layout7x7_o.jpg b/app/src/main/res/drawable/layout7x7_o.jpg
deleted file mode 100644
index 475cf16..0000000
Binary files a/app/src/main/res/drawable/layout7x7_o.jpg and /dev/null differ
diff --git a/app/src/main/res/drawable/layout7x7_o.png b/app/src/main/res/drawable/layout7x7_o.png
new file mode 100644
index 0000000..dd2ac17
Binary files /dev/null and b/app/src/main/res/drawable/layout7x7_o.png differ
diff --git a/app/src/main/res/drawable/layout7x7_s.jpg b/app/src/main/res/drawable/layout7x7_s.jpg
deleted file mode 100644
index b8fc596..0000000
Binary files a/app/src/main/res/drawable/layout7x7_s.jpg and /dev/null differ
diff --git a/app/src/main/res/drawable/layout7x7_s.png b/app/src/main/res/drawable/layout7x7_s.png
new file mode 100644
index 0000000..b0c83a4
Binary files /dev/null and b/app/src/main/res/drawable/layout7x7_s.png differ
diff --git a/app/src/main/res/layout-land/choose_slide1.xml b/app/src/main/res/layout-land/choose_slide1.xml
index 4c1892c..af65a4c 100644
--- a/app/src/main/res/layout-land/choose_slide1.xml
+++ b/app/src/main/res/layout-land/choose_slide1.xml
@@ -25,7 +25,6 @@
android:paddingRight="@dimen/desc_padding"
android:text="4x4"
android:textAlignment="center"
- android:textColor="@android:color/black"
android:textSize="@dimen/slide_desc" />
diff --git a/app/src/main/res/layout-land/choose_slide2.xml b/app/src/main/res/layout-land/choose_slide2.xml
index 7093965..2969c1d 100644
--- a/app/src/main/res/layout-land/choose_slide2.xml
+++ b/app/src/main/res/layout-land/choose_slide2.xml
@@ -25,7 +25,6 @@
android:paddingRight="@dimen/desc_padding"
android:text="5x5"
android:textAlignment="center"
- android:textColor="@android:color/black"
android:textSize="@dimen/slide_desc" />
diff --git a/app/src/main/res/layout-land/choose_slide3.xml b/app/src/main/res/layout-land/choose_slide3.xml
index e293ebc..b6af73f 100644
--- a/app/src/main/res/layout-land/choose_slide3.xml
+++ b/app/src/main/res/layout-land/choose_slide3.xml
@@ -25,7 +25,6 @@
android:paddingRight="@dimen/desc_padding"
android:text="6x6"
android:textAlignment="center"
- android:textColor="@android:color/black"
android:textSize="@dimen/slide_desc" />
diff --git a/app/src/main/res/layout-land/choose_slide4.xml b/app/src/main/res/layout-land/choose_slide4.xml
index 0dd0e6d..b7f638a 100644
--- a/app/src/main/res/layout-land/choose_slide4.xml
+++ b/app/src/main/res/layout-land/choose_slide4.xml
@@ -25,7 +25,6 @@
android:paddingRight="@dimen/desc_padding"
android:text="7x7"
android:textAlignment="center"
- android:textColor="@android:color/black"
android:textSize="@dimen/slide_desc" />
diff --git a/app/src/main/res/layout/choose_slide1.xml b/app/src/main/res/layout/choose_slide1.xml
index e76f95b..43e4da6 100644
--- a/app/src/main/res/layout/choose_slide1.xml
+++ b/app/src/main/res/layout/choose_slide1.xml
@@ -27,7 +27,6 @@
android:paddingRight="@dimen/desc_padding"
android:text="4x4"
android:textAlignment="center"
- android:textColor="@android:color/black"
android:textSize="@dimen/slide_desc" />
diff --git a/app/src/main/res/layout/choose_slide2.xml b/app/src/main/res/layout/choose_slide2.xml
index 7093965..2969c1d 100644
--- a/app/src/main/res/layout/choose_slide2.xml
+++ b/app/src/main/res/layout/choose_slide2.xml
@@ -25,7 +25,6 @@
android:paddingRight="@dimen/desc_padding"
android:text="5x5"
android:textAlignment="center"
- android:textColor="@android:color/black"
android:textSize="@dimen/slide_desc" />
diff --git a/app/src/main/res/layout/choose_slide3.xml b/app/src/main/res/layout/choose_slide3.xml
index e293ebc..b6af73f 100644
--- a/app/src/main/res/layout/choose_slide3.xml
+++ b/app/src/main/res/layout/choose_slide3.xml
@@ -25,7 +25,6 @@
android:paddingRight="@dimen/desc_padding"
android:text="6x6"
android:textAlignment="center"
- android:textColor="@android:color/black"
android:textSize="@dimen/slide_desc" />
diff --git a/app/src/main/res/layout/choose_slide4.xml b/app/src/main/res/layout/choose_slide4.xml
index 0dd0e6d..b7f638a 100644
--- a/app/src/main/res/layout/choose_slide4.xml
+++ b/app/src/main/res/layout/choose_slide4.xml
@@ -25,7 +25,6 @@
android:paddingRight="@dimen/desc_padding"
android:text="7x7"
android:textAlignment="center"
- android:textColor="@android:color/black"
android:textSize="@dimen/slide_desc" />
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 5a4a9e6..9c48cf1 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -105,4 +105,11 @@
Zeit pro Wischer
Statistik zurücksetzem
+
+ Streiche Oben
+ Streiche Unten
+ Streiche Links
+ Streiche Rechts
+ Rückgängig
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7fa3230..64f867f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -104,5 +104,11 @@
Time per Swipe
Reset Statistics
+
+ Swipe Up
+ Swipe Down
+ Swipe Left
+ Swipe Right
+ Undo
diff --git a/app/src/main/res/xml/air_actions.xml b/app/src/main/res/xml/air_actions.xml
new file mode 100644
index 0000000..f68526a
--- /dev/null
+++ b/app/src/main/res/xml/air_actions.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+