This repository has been archived by the owner on Jul 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into feature/cleanup-about
- Loading branch information
Showing
13 changed files
with
277 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/info/hebbeker/david/memorex/DisplayHighScore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package info.hebbeker.david.memorex; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.text.Html; | ||
import android.widget.TextView; | ||
|
||
import java.io.Serializable; | ||
|
||
public class DisplayHighScore extends AppCompatActivity | ||
{ | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) | ||
{ | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_display_high_score); | ||
final Serializable currentHighScore = getIntent().getSerializableExtra(MainActivity.HIGH_SCORE_DATA); | ||
final String aboutText = getResources().getString(R.string.high_score_display, currentHighScore.toString()); | ||
final TextView textView = findViewById(R.id.textViewHighScore); | ||
textView.setText(Html.fromHtml(aboutText)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/main/java/info/hebbeker/david/memorex/HighScoreContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package info.hebbeker.david.memorex; | ||
|
||
import android.content.SharedPreferences; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonSyntaxException; | ||
|
||
import java.io.IOException; | ||
|
||
class HighScoreContainer | ||
{ | ||
final private SharedPreferences sharedPref; | ||
final private String highScorePreferenceKey = "HighScoreStorage"; | ||
final private Gson gson = new Gson(); | ||
private Score currentHighScore; | ||
|
||
HighScoreContainer(final SharedPreferences sharedPref) | ||
{ | ||
this.sharedPref = sharedPref; | ||
loadHighScore(); | ||
} | ||
|
||
private void loadHighScore() | ||
{ | ||
try | ||
{ | ||
String highScoreSerializedObject = this.sharedPref.getString(highScorePreferenceKey, ""); | ||
currentHighScore = gson.fromJson(highScoreSerializedObject, Score.class); | ||
if (currentHighScore == null) // this may be overcautious | ||
{ | ||
throw new IOException("Getting stored high score failed!"); | ||
} | ||
} | ||
catch (JsonSyntaxException|IOException e) | ||
{ | ||
e.printStackTrace(); | ||
currentHighScore = new Score(0); | ||
saveHighScore(); | ||
} | ||
} | ||
|
||
boolean setNewHighScore(final Score newScore) | ||
{ | ||
final boolean isNewHighScore = newScore.isGreaterThan(currentHighScore); | ||
if (isNewHighScore) | ||
{ | ||
currentHighScore = newScore; | ||
saveHighScore(); | ||
} | ||
return isNewHighScore; | ||
} | ||
|
||
private void saveHighScore() | ||
{ | ||
SharedPreferences.Editor editor = sharedPref.edit(); | ||
String highScoreSerializedObject = gson.toJson(currentHighScore); | ||
editor.putString(highScorePreferenceKey, highScoreSerializedObject); | ||
editor.apply(); | ||
} | ||
|
||
public Score getCurrentHighScore() | ||
{ | ||
return currentHighScore; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package info.hebbeker.david.memorex; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Does contain information about a score. | ||
* \todo Add the following attributes: username, speed, date, points | ||
*/ | ||
class Score implements Serializable | ||
{ | ||
/** | ||
* Completed level. | ||
* <p> | ||
* If the player fails at level 2, the completed level is 1. If he fails at level 1, the | ||
* completed level is 0. | ||
*/ | ||
private final int level; | ||
|
||
Score(final int level) | ||
{ | ||
this.level = level; | ||
} | ||
|
||
/** | ||
* @return true if this score is greater than other score | ||
*/ | ||
boolean isGreaterThan(final Score otherScore) | ||
{ | ||
return this.level > otherScore.level; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "Level=" + level; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="info.hebbeker.david.memorex.DisplayHighScore"> | ||
|
||
<TextView | ||
android:id="@+id/textViewHighScore" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
android:layout_marginBottom="8dp" | ||
android:layout_marginLeft="11dp" | ||
android:layout_marginRight="11dp" | ||
android:layout_marginTop="8dp" | ||
android:autoLink="web|email|map" | ||
android:text="@string/high_score_display" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
# This script shall print a string to stdout that can directly be used as a tag name for versioning. | ||
|
||
echo "INFO: Call this script like this: $0 4 3 2 alpha" | ||
|
||
# read arguments | ||
majorOffset=$1 | ||
minorOffset=$2 | ||
patchOffset=$3 | ||
masterPostfix=$4 | ||
|
||
gitInfo=`git describe --tags --always --match "v[[:digit:]]*"` | ||
rawBranchName=`git symbolic-ref --short HEAD` | ||
branchName="${rawBranchName/\//-}" | ||
|
||
# truncate leading `v` | ||
oldVersionString=${gitInfo:1} | ||
|
||
# separate version information | ||
IFS=- # delimit on _ | ||
set -f # disable the glob part | ||
oldVersionInfo=(${oldVersionString}) # invoke the split+glob operator | ||
IFS= | ||
|
||
commits=${oldVersionInfo[1]} | ||
object=${oldVersionInfo[2]} | ||
|
||
# separate version numbers | ||
IFS=. # delimit on _ | ||
set -f # disable the glob part | ||
oldVersionNumbers=(${oldVersionInfo[0]}) # invoke the split+glob operator | ||
IFS= | ||
|
||
major=$((${oldVersionNumbers[0]}+$majorOffset)) | ||
minor=$((${oldVersionNumbers[1]}+$minorOffset)) | ||
patch=$((${oldVersionNumbers[2]}+$patchOffset)) | ||
|
||
if [ "$branchName" == "master" ]; then | ||
if [ "$masterPostfix" == "" ]; then | ||
postfix="" | ||
else | ||
postfix="-$masterPostfix" | ||
fi | ||
else | ||
postfix="-0.develop+$branchName.$commits.$object" | ||
fi | ||
|
||
version="$major.$minor.$patch$postfix" | ||
|
||
# Tags which point to defined versions shall use the version name prefixed with a `v` as this is [common practice](https://github.com/semver/semver/issues/235#issuecomment-346477428) on GitHub. | ||
tag="v$version" | ||
echo ${tag} |