Settings and help implemented; login via UID, rename, auto-name refresh on change

This commit is contained in:
Caesar2011
2017-04-28 18:03:54 +02:00
parent e4f0f805c5
commit a00b1f6412
55 changed files with 1073 additions and 374 deletions

1
.idea/misc.xml generated
View File

@@ -3,6 +3,7 @@
<component name="EntryPointsManager">
<entry_points version="2.0">
<entry_point TYPE="method" FQNAME="de.hwr_berlin.it14.postgrachelor.Types.HighscoresCategories int getId()" />
<entry_point TYPE="field" FQNAME="de.hwr_berlin.it14.postgrachelor.Types.StoredTimings S" />
</entry_points>
</component>
<component name="NullableNotNullManager">

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="de.hwr_berlin.it14.postgrachelor">
<uses-permission android:name="android.permission.INTERNET" />
@@ -13,7 +14,7 @@
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize">
@@ -30,7 +31,20 @@
android:scheme="postgrachelor" />
</intent-filter>
</activity>
<activity android:name=".HighscoreActivity"></activity>
<activity android:name=".HighscoreActivity"
android:parentActivityName=".MainActivity"
tools:ignore="UnusedAttribute">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".SettingActivity"
android:parentActivityName=".MainActivity"
tools:ignore="UnusedAttribute">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
</manifest>

View File

@@ -4,8 +4,10 @@ import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;
import de.hwr_berlin.it14.postgrachelor.Services.GameService;
import de.hwr_berlin.it14.postgrachelor.Services.HighscoreService;
import de.hwr_berlin.it14.postgrachelor.Services.LoginService;
import de.hwr_berlin.it14.postgrachelor.Utils.Conversion;
import de.hwr_berlin.it14.postgrachelor.Utils.HighscoreAdapter;
@@ -16,6 +18,10 @@ public class HighscoreActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_highscore);
HighscoreService.initialize(this);
LoginService.initialize(this);
GameService.initialize(this);
if (getActionBar() != null) {
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(true);
@@ -51,6 +57,15 @@ public class HighscoreActivity extends AppCompatActivity {
return true;
}
@Override
protected void onResume() {
super.onResume();
HighscoreService.initialize(this);
LoginService.initialize(this);
GameService.initialize(this);
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);

View File

@@ -3,6 +3,8 @@ package de.hwr_berlin.it14.postgrachelor;
import android.content.Context;
import android.os.Bundle;
import android.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -45,7 +47,7 @@ public class LoginFragment extends Fragment {
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View layout = inflater.inflate(R.layout.fragment_login, container, false);
Button login_btn = (Button) layout.findViewById(R.id.login_btn);
final Button login_btn = (Button) layout.findViewById(R.id.login_btn);
final EditText login_edit = (EditText) layout.findViewById(R.id.login_edit);
login_btn.setOnClickListener(new View.OnClickListener() {
@Override
@@ -53,15 +55,31 @@ public class LoginFragment extends Fragment {
Log.d(NAME, "Button click: "+login_edit.getText().toString());
try {
LoginService.doLogin(login_edit.getText().toString());
String value = login_edit.getText().toString();
if (value.length()==32)
LoginService.doLogin(value);
else
LoginService.doRegister(value);
} catch (NotInitializedException e) {
e.printStackTrace();
}
InputMethodManager mgr = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
});
login_edit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
if (s.length()==32)
login_btn.setText(login_btn.getResources().getString(R.string.login_user_btn));
else
login_btn.setText(login_btn.getResources().getString(R.string.register_btn));
}
});

View File

@@ -3,10 +3,15 @@ package de.hwr_berlin.it14.postgrachelor;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.view.ContextThemeWrapper;
import android.util.Log;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.SparseBooleanArray;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
@@ -20,12 +25,16 @@ import de.hwr_berlin.it14.postgrachelor.Exceptions.NotLoggedInException;
import de.hwr_berlin.it14.postgrachelor.Services.GameService;
import de.hwr_berlin.it14.postgrachelor.Services.HighscoreService;
import de.hwr_berlin.it14.postgrachelor.Services.LoginService;
import de.hwr_berlin.it14.postgrachelor.Types.Login;
import de.hwr_berlin.it14.postgrachelor.Types.RequestActivityInterface;
import de.hwr_berlin.it14.postgrachelor.Types.StoredStates;
public class MainActivity extends AppCompatActivity implements RequestActivityInterface {
private HashMap<String, ProgressDialog> dialogs = new HashMap<>();
private final HashMap<String, ProgressDialog> dialogs = new HashMap<>();
private Menu menu;
private boolean isSaved = true;
private final SparseBooleanArray menuStates = new SparseBooleanArray();
@Override
public String showDialog() {
@@ -83,8 +92,9 @@ public class MainActivity extends AppCompatActivity implements RequestActivityIn
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.isSaved = false;
Log.d("Activity fragment", "create");
Log.d(NAME, "create");
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
@@ -100,6 +110,10 @@ public class MainActivity extends AppCompatActivity implements RequestActivityIn
if (savedInstanceState != null) {
this.selectFragment(savedInstanceState.getInt("selected fragment"));
}
HighscoreService.initialize(this);
LoginService.initialize(this);
GameService.initialize(this);
}
@Override
@@ -109,21 +123,21 @@ public class MainActivity extends AppCompatActivity implements RequestActivityIn
final MainActivity that = this;
LoginService.addLoginEventListener(NAME, new LoginService.OnLoginEventListener() {
@Override
public void onLoginEvent(String name, String uid) {
Log.d("Activity fragment", "onLogin - name: " + name + " - uid: " + uid);
public void onLoginEvent(Login login) {
Log.d(NAME, "onLogin - name: " + LoginService.getLogin().getName() + " - uid: " + LoginService.getLogin().getUID());
that.selectFragment(FragmentState.MAIN);
}
@Override
public void onLogoutEvent(int status, String message) {
Log.d("Activity fragment", "onLogout - name: " + status + " - uid: " + message);
Log.d(NAME, "onLogout - name: " + status + " - uid: " + message);
that.selectFragment(FragmentState.LOGIN);
}
});
GameService.addGameStateChangeEventListener(NAME, new GameService.OnGameStateChangeEventListener() {
@Override
public void onGameStateChangeEvent(int previous, int state) {
Log.d("Activity fragment", "onGameStateChange - previous: " + previous + " - state: " + state);
Log.d(NAME, "onGameStateChange - previous: " + previous + " - state: " + state);
if (state == StoredStates.RUNNING || state == StoredStates.ON_HOLD_LOADING || state == StoredStates.ON_HOLD_RESULT)
that.selectFragment(FragmentState.QUESTION);
else if (previous == StoredStates.ON_HOLD_RESULT && state == StoredStates.END) {
@@ -131,11 +145,9 @@ public class MainActivity extends AppCompatActivity implements RequestActivityIn
} else if (state == StoredStates.PAUSED || state == StoredStates.END) {
that.selectFragment(FragmentState.MAIN);
}
updateOptionMenu();
}
});
HighscoreService.instantiate(this);
LoginService.instantiate(this);
GameService.initialize(this);
//this.selectFragment(this.fragmentState);
}
@@ -157,6 +169,12 @@ public class MainActivity extends AppCompatActivity implements RequestActivityIn
@Override
protected void onResume() {
super.onResume();
this.isSaved = false;
HighscoreService.initialize(this);
LoginService.initialize(this);
GameService.initialize(this);
Log.d(NAME, "Resuming");
selectFragment(this.fragmentState);
}
@@ -164,10 +182,38 @@ public class MainActivity extends AppCompatActivity implements RequestActivityIn
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
this.menu = menu;
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
this.updateOptionMenu();
for (int i = 0; i < menuStates.size(); i++) {
int key = menuStates.keyAt(i);
if (menuStates.get(key))
this.showOption(key);
else
this.hideOption(key);
}
menuStates.clear();
return super.onPrepareOptionsMenu(menu);
}
private void updateOptionMenu() {
if (GameService.isFinished()) {
this.setOptionIcon(R.id.action_gameState, android.R.drawable.ic_media_play);
this.setOptionTitle(R.id.action_gameState, this.getResources().getString(R.string.start_test));
} else if (GameService.isRunning()) {
this.setOptionIcon(R.id.action_gameState, android.R.drawable.ic_media_pause);
this.setOptionTitle(R.id.action_gameState, this.getResources().getString(R.string.pause_test));
} else if (GameService.isPaused()) {
this.setOptionIcon(R.id.action_gameState, android.R.drawable.ic_media_pause);
this.setOptionTitle(R.id.action_gameState, this.getResources().getString(R.string.resume_test));
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
@@ -177,6 +223,61 @@ public class MainActivity extends AppCompatActivity implements RequestActivityIn
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Intent intent = new Intent(this, SettingActivity.class);
startActivity(intent);
return true;
} else if (id == R.id.action_gameState) {
if (GameService.isRunning()) {
try {
GameService.pauseGame();
} catch (NotInitializedException e) {
e.printStackTrace();
}
} else if (GameService.isPaused()) {
try {
GameService.resumeGame();
} catch (NotInitializedException e) {
e.printStackTrace();
}
} else if (GameService.isFinished()) {
try {
GameService.startGame();
} catch (NotInitializedException | NotLoggedInException e) {
e.printStackTrace();
}
}
return true;
} else if (id == R.id.action_help) {
int text = 0;
switch (this.fragmentState) {
case FragmentState.LOGIN:
text = R.string.help_login;
break;
case FragmentState.MAIN:
text = R.string.help_main;
break;
case FragmentState.QUESTION:
text = R.string.help_question;
break;
case FragmentState.QUESTION_END:
text = R.string.help_question_end;
break;
}
if (text != 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.DialogTheme));
builder.setTitle(builder.getContext().getResources().getString(R.string.help));
builder.setMessage(builder.getContext().getResources().getString(text));
builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
return true;
}
@@ -184,19 +285,24 @@ public class MainActivity extends AppCompatActivity implements RequestActivityIn
}
private void selectFragment(int item) {
boolean change = this.fragmentState != item;
this.fragmentState = item;
// Handle navigation view item clicks here.
try {
boolean isLoggedIn = LoginService.isLoggedIn();
if (!isLoggedIn && (item != FragmentState.LOGIN)) {
return;
} else if (isLoggedIn && (item == FragmentState.LOGIN)) {
return;
}
} catch (NotInitializedException e) {
e.printStackTrace();
if (this.isSaved)
return;
boolean isLoggedIn = LoginService.isLoggedIn();
if (!isLoggedIn) {
item = FragmentState.LOGIN;
} else if (item == FragmentState.LOGIN) {
item = FragmentState.MAIN;
}
boolean change = this.fragmentState != item;
if (item == FragmentState.LOGIN) {
this.hideOption(R.id.action_gameState);
this.hideOption(R.id.action_settings);
} else if (this.fragmentState == FragmentState.LOGIN) {
this.showOption(R.id.action_gameState);
this.showOption(R.id.action_settings);
}
if (item == FragmentState.LOGIN) {
@@ -236,11 +342,51 @@ public class MainActivity extends AppCompatActivity implements RequestActivityIn
fragmentTransaction.commit();
}
}
this.fragmentState = item;
}
private void hideOption(int id)
{
if (this.menu!=null) {
MenuItem item = this.menu.findItem(id);
item.setVisible(false);
} else {
menuStates.put(id, false);
}
}
private void showOption(int id)
{
if (this.menu!=null) {
MenuItem item = this.menu.findItem(id);
item.setVisible(true);
} else {
menuStates.put(id, true);
}
}
private void setOptionTitle(int id, String title)
{
if (this.menu!=null) {
MenuItem item = this.menu.findItem(id);
item.setTitle(title);
}
}
private void setOptionIcon(int id, int iconRes)
{
if (this.menu!=null) {
MenuItem item = this.menu.findItem(id);
item.setIcon(iconRes);
}
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putInt("selected fragment", this.fragmentState);
this.isSaved = true;
super.onSaveInstanceState(savedInstanceState);
}

View File

@@ -26,6 +26,7 @@ import de.hwr_berlin.it14.postgrachelor.Services.HighscoreService;
import de.hwr_berlin.it14.postgrachelor.Services.LoginService;
import de.hwr_berlin.it14.postgrachelor.Types.Highscores;
import de.hwr_berlin.it14.postgrachelor.Types.HighscoresCategories;
import de.hwr_berlin.it14.postgrachelor.Types.Login;
import de.hwr_berlin.it14.postgrachelor.Types.StoredStates;
import de.hwr_berlin.it14.postgrachelor.Utils.JsonRequestPG;
@@ -74,9 +75,9 @@ public class MainFragment extends Fragment {
};
LoginService.addLoginEventListener(NAME, new LoginService.OnLoginEventListener() {
@Override
public void onLoginEvent(String name, String uid) {
public void onLoginEvent(Login login) {
TextView textView = (TextView) view.findViewById(R.id.fragment_main_status).findViewById(R.id.fragment_user_name);
textView.setText(name);
textView.setText(login.getName());
}
@Override
@@ -123,14 +124,16 @@ public class MainFragment extends Fragment {
categoryView = inflater.inflate(R.layout.fragment_main_category, gridLayoutCategories, false);
categoryView.setTag(R.id.category_id, category.getId());
categoryView.setTag(R.id.category_name, category.getName());
// TODO automated count
categoryView.setTag(R.id.category_count, scores.getAll());
categoryView.setOnClickListener(categoryClick);
textView = (TextView) categoryView.findViewById(R.id.textViewCategory);
textView.setText(category.getName());
textView = (TextView) categoryView.findViewById(R.id.textViewScore);
textView.setText(String.format(Locale.getDefault(), "%1$d", category.getScore()));
if (category.getScore() != -1)
textView.setText(String.format(Locale.getDefault(), "%1$d", category.getScore()));
else
textView.setText(view.getResources().getString(R.string.no_score));
catProgress = (ProgressBar) categoryView.findViewById(R.id.progressBarCategory);
catProgress.setProgress(0);
@@ -143,7 +146,11 @@ public class MainFragment extends Fragment {
categoryView.setLayoutParams(param);
}
userStatusTextViewScore.setText(String.format(Locale.getDefault(), "%1$d", scores.getScore()));
if (scores.getScore() != -1)
userStatusTextViewScore.setText(String.format(Locale.getDefault(), "%1$d", scores.getScore()));
else
userStatusTextViewScore.setText(view.getResources().getString(R.string.no_score));
userStatusProgressBar.setMax(scores.getAll());
userStatusProgressBar.setProgress(scores.getAll() - scores.getPlace() + 1);
userStatusProgressBar.setTag(R.id.category_id, -1);
@@ -219,7 +226,7 @@ public class MainFragment extends Fragment {
} catch (NotInitializedException ignored) {
} catch (NotLoggedInException e) {
try {
LoginService.setLogout(15999, "Not logged in");
LoginService.doLogout(15999, "Not logged in");
} catch (NotInitializedException ignored) {
}
}

View File

@@ -14,7 +14,6 @@ import java.util.Locale;
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInitializedException;
import de.hwr_berlin.it14.postgrachelor.Services.GameService;
import de.hwr_berlin.it14.postgrachelor.Types.Scores;
import de.hwr_berlin.it14.postgrachelor.Types.StoredScores;
import de.hwr_berlin.it14.postgrachelor.Utils.Conversion;

View File

@@ -23,7 +23,6 @@ import de.hwr_berlin.it14.postgrachelor.Services.GameService;
import de.hwr_berlin.it14.postgrachelor.Types.Question;
import de.hwr_berlin.it14.postgrachelor.Types.Result;
import de.hwr_berlin.it14.postgrachelor.Types.StoredStates;
import de.hwr_berlin.it14.postgrachelor.Types.StoredTimings;
import de.hwr_berlin.it14.postgrachelor.Types.Timings;
import de.hwr_berlin.it14.postgrachelor.Utils.Conversion;
import de.hwr_berlin.it14.postgrachelor.Utils.ReverseInterpolator;
@@ -101,7 +100,10 @@ public class QuestionFragment extends Fragment {
} else if (GameService.getState().getState() != StoredStates.ON_HOLD_RESULT) {
try {
GameService.answer((int) v.getTag());
} catch (NotInitializedException | NotLoggedInException | NoCurrentQuestionException e) {
} catch (NotInitializedException | NotLoggedInException e) {
e.printStackTrace();
} catch (NoCurrentQuestionException e) {
GameService.haltGame();
e.printStackTrace();
}
} else {

View File

@@ -20,6 +20,8 @@ import de.hwr_berlin.it14.postgrachelor.Types.States;
import de.hwr_berlin.it14.postgrachelor.Types.StoredNextEntity;
import de.hwr_berlin.it14.postgrachelor.Types.StoredQuestion;
import de.hwr_berlin.it14.postgrachelor.Types.StoredScores;
import de.hwr_berlin.it14.postgrachelor.Types.StoredPrefs;
import de.hwr_berlin.it14.postgrachelor.Types.Prefs;
import de.hwr_berlin.it14.postgrachelor.Types.Question;
import de.hwr_berlin.it14.postgrachelor.Types.Result;
import de.hwr_berlin.it14.postgrachelor.Types.StoredStates;
@@ -35,7 +37,6 @@ import de.hwr_berlin.it14.postgrachelor.Utils.JsonRequestPG;
public class GameService {
private static final int GAME_TICK_INTERVAL = 100;
private static final int QUESTION_COUNT = 10;
private static final String NAME = "SERVICE_GAME";
private static final String PREFS_NAME = "PrefsGame";
@@ -45,25 +46,17 @@ public class GameService {
private static StoredScores scores = null;
private static StoredNextEntity next = null;
private static StoredQuestion question = null;
private static StoredPrefs prefs = null;
private static boolean initialized = false;
@SuppressLint("StaticFieldLeak")
private static Activity activity = null;
private static SharedPreferences settings = null;
private static Timer timer = null;
private static final HashMap<String, OnGameStateChangeEventListener> gameStateChangeEventListeners = new HashMap<>();
private static final HashMap<String, OnQuestionUpdateEventListener> questionUpdateEventListeners = new HashMap<>();
private static final HashMap<String, OnGameEndEventListener> gameEndEventListeners = new HashMap<>();
private static final HashMap<String, OnTickEventListener> gameTickEventListeners = new HashMap<>();
public static void haltGame() {
Log.d(NAME, "Halt game!", new Throwable("HAlt game!"));
try {
GameService.endGame();
} catch (NotInitializedException e) {
e.printStackTrace();
}
}
private static final HashMap<String, OnPrefsUpdateEventListener> prefsUpdateEventListeners = new HashMap<>();
public interface OnGameStateChangeEventListener {
void onGameStateChangeEvent(int previous, int state);
@@ -77,19 +70,23 @@ public class GameService {
public interface OnTickEventListener {
void onTickEvent(Timings timings);
}
public interface OnPrefsUpdateEventListener {
void onPrefsUpdateEvent(Prefs prefs);
}
private GameService() {}
public static void initialize(Activity activity) {
GameService.activity = activity;
GameService.settings = activity.getSharedPreferences(GameService.PREFS_NAME, 0);
SharedPreferences settings = activity.getSharedPreferences(GameService.PREFS_NAME, 0);
GameService.initialized = true;
GameService.states = new StoredStates(GameService.settings, "");
GameService.timings = new StoredTimings(GameService.settings, "");
GameService.scores = new StoredScores(GameService.settings, "");
GameService.next = new StoredNextEntity(GameService.settings, "");
GameService.question = new StoredQuestion(GameService.settings, "");
GameService.states = new StoredStates(settings, "");
GameService.timings = new StoredTimings(settings, "");
GameService.scores = new StoredScores(settings, "");
GameService.next = new StoredNextEntity(settings, "");
GameService.question = new StoredQuestion(settings, "");
GameService.prefs = new StoredPrefs(settings, "");
if (GameService.getState().getState()==StoredStates.RUNNING)
GameService.startTimer();
@@ -98,6 +95,7 @@ public class GameService {
emitQuestionUpdateEvent();
emitGameEndEvent();
emitGameStateChangeEvent();
emitPrefsUpdateEvent();
}
public static void addGameStateChangeEventListener(String key, OnGameStateChangeEventListener listener) {
@@ -152,6 +150,17 @@ public class GameService {
}
}
public static void addPrefsUpdateEventListener(String key, OnPrefsUpdateEventListener onPrefsUpdateEventListener) {
prefsUpdateEventListeners.put(key, onPrefsUpdateEventListener);
onPrefsUpdateEventListener.onPrefsUpdateEvent(GameService.getPrefs());
}
private static void emitPrefsUpdateEvent() {
for (OnPrefsUpdateEventListener listener: prefsUpdateEventListeners.values()) {
listener.onPrefsUpdateEvent(GameService.getPrefs());
}
}
private static void startTimer() {
if (GameService.timer==null)
GameService.timer = new Timer();
@@ -211,6 +220,38 @@ public class GameService {
return GameService.next.getEnd();
}
private static Prefs getPrefs() {
return GameService.prefs.get();
}
public static boolean isRunning() {
if (GameService.initialized) {
int state = GameService.getState().getState();
return state==StoredStates.RUNNING || state==StoredStates.ON_HOLD_LOADING || state==StoredStates.ON_HOLD_RESULT;
}
return false;
}
public static boolean isPaused() {
if (GameService.initialized) {
int state = GameService.getState().getState();
return state==StoredStates.PAUSED;
}
return false;
}
public static boolean isFinished() {
if (GameService.initialized) {
int state = GameService.getState().getState();
return state==StoredStates.END || state==StoredStates.UNINITIALIZED;
}
return false;
}
public static boolean isNextNeeded() {
return GameService.initialized && GameService.next.isLoaded();
}
// SETTER
private static void startTimings() {
@@ -229,7 +270,7 @@ public class GameService {
GameService.next.setEnd(scores);
}
// UNSETTER
// REMOVERS
private static void resetTimings() {
GameService.timings.reset();
@@ -262,17 +303,13 @@ public class GameService {
}
}
public static boolean resumeGame() throws NotInitializedException {
public static void resumeGame() throws NotInitializedException {
if (!GameService.initialized)
throw new NotInitializedException();
int state = GameService.getState().getState();
if (state == StoredStates.PAUSED) {
if (state == StoredStates.PAUSED)
GameService.setState(GameService.getState().getPrevious());
return true;
} else {
return false;
}
}
public static void endGame() throws NotInitializedException {
@@ -287,26 +324,35 @@ public class GameService {
}
public static void haltGame() {
Log.d(NAME, "Halt game!", new Throwable("Halt game!"));
try {
GameService.endGame();
} catch (NotInitializedException e) {
e.printStackTrace();
}
}
public static void answer(int id) throws NotInitializedException, NotLoggedInException, NoCurrentQuestionException {
if (!GameService.initialized)
throw new NotInitializedException();
if (GameService.isNextNeeded())
throw new IllegalStateException();
if (!LoginService.isLoggedIn())
throw new NotLoggedInException();
if (GameService.getQuestion()==null || GameService.getAnswer()==-1) {
throw new NoCurrentQuestionException();
}
GameService.stopTimings();
GameService.setAnswer(id);
GameService.setState(StoredStates.ON_HOLD_LOADING);
if (GameService.getQuestion()==null || GameService.getAnswer()==-1) {
GameService.haltGame();
return;
}
final String currentToken = GameService.getQuestion().getToken();
HashMap<String, String> params = new HashMap<>();
params.put("answer", Conversion.intToStr(GameService.getAnswer()));
params.put("uid", LoginService.getLoginUID());
params.put("uid", LoginService.getLogin().getUID());
params.put("token", currentToken);
params.put("time", String.valueOf(GameService.getTimings().getTimeDiff()));
Log.d("GameServiceFragment", "answer/processFinish - before");
@@ -365,6 +411,8 @@ public class GameService {
public static void startGame() throws NotInitializedException, NotLoggedInException {
if (!GameService.initialized)
throw new NotInitializedException();
if (!LoginService.isLoggedIn())
throw new NotLoggedInException();
GameService.unsetNext();
GameService.unsetScores();
@@ -373,9 +421,9 @@ public class GameService {
HashMap<String, String> params = new HashMap<>();
String uid;
uid = LoginService.getLoginUID();
uid = LoginService.getLogin().getUID();
params.put("uid", uid);
params.put("length", Conversion.intToStr(GameService.QUESTION_COUNT));
params.put("length", Conversion.intToStr(GameService.getPrefs().getGameLength()));
JsonRequestPG requester = new JsonRequestPG("start.php", params, GameService.activity, new JsonRequestPG.AsyncResponse() {
@Override
public void processFinish(JSONObject data) {
@@ -393,7 +441,7 @@ public class GameService {
GameService.setState(StoredStates.END);
if (status==12104) { // user uid not found
try {
LoginService.setLogout(status, message);
LoginService.doLogout(status, message);
} catch (NotInitializedException e) {
e.printStackTrace();
}
@@ -403,10 +451,6 @@ public class GameService {
requester.execute();
}
public static boolean isNextNeeded() {
return GameService.initialized && GameService.next.isLoaded();
}
public static void runNext() throws IllegalStateException, NotInitializedException {
if (!GameService.initialized)
throw new NotInitializedException();
@@ -425,6 +469,13 @@ public class GameService {
GameService.unsetNext();
}
public static void setGameLength(int length) throws NotInitializedException {
if (!GameService.initialized)
throw new NotInitializedException();
GameService.prefs.setGameLength(length);
GameService.emitPrefsUpdateEvent();
}
private static void setQuestion(Question question) {
Log.d(NAME, "token: "+question.getToken());
GameService.question.setQuestion(question);

View File

@@ -2,7 +2,6 @@ package de.hwr_berlin.it14.postgrachelor.Services;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
@@ -26,8 +25,6 @@ import de.hwr_berlin.it14.postgrachelor.Utils.JsonRequestPG;
public class HighscoreService {
private static final String NAME = "HighscoreService";
private static final long MIN_REFRESH_RATE = 1000;
//private static final String PREFS_NAME = "PrefsHighscore";
//private static SharedPreferences settings = null;
private static Highscores latestScores = null;
private static boolean instantiated = false;
@SuppressLint("StaticFieldLeak")
@@ -50,8 +47,7 @@ public class HighscoreService {
}
}
public static void instantiate(Activity activity) {
//settings = activity.getSharedPreferences(PREFS_NAME, 0);
public static void initialize(Activity activity) {
HighscoreService.activity = activity;
instantiated = true;
}
@@ -74,18 +70,19 @@ public class HighscoreService {
}
public static void updateHighscores(final JsonRequestPG.AsyncResponse asyncResponse) throws NotInitializedException, NotLoggedInException {
if (!instantiated)
throw new NotInitializedException();
if (!LoginService.isLoggedIn())
throw new NotLoggedInException();
if (lastUpdate >= System.currentTimeMillis()-MIN_REFRESH_RATE && available()) {
emitHighscoreUpdateEvent();
return;
}
lastUpdate = System.currentTimeMillis();
if (!instantiated)
throw new NotInitializedException();
HashMap<String, String> params = new HashMap<>();
String uid = LoginService.getLoginUID();
Log.d(NAME, uid);
params.put("uid", LoginService.getLoginUID());
params.put("uid", LoginService.getLogin().getUID());
JsonRequestPG requester = new JsonRequestPG("highscores.php", params, /*activity*/null, new JsonRequestPG.AsyncResponse() {
@Override
public void processFinish(JSONObject output) {
@@ -124,7 +121,7 @@ public class HighscoreService {
setLatestScores(null);
if (status==15102) { // user uid not found
try {
LoginService.setLogout(status, message);
LoginService.doLogout(status, message);
} catch (NotInitializedException e) {
e.printStackTrace();
}

View File

@@ -10,7 +10,8 @@ import org.json.JSONObject;
import java.util.HashMap;
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInitializedException;
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotLoggedInException;
import de.hwr_berlin.it14.postgrachelor.Types.Login;
import de.hwr_berlin.it14.postgrachelor.Types.StoredLogin;
import de.hwr_berlin.it14.postgrachelor.Utils.JsonRequestPG;
/**
@@ -20,31 +21,28 @@ import de.hwr_berlin.it14.postgrachelor.Utils.JsonRequestPG;
public class LoginService {
private static final String PREFS_NAME = "PrefsLogin";
private static SharedPreferences settings = null;
private static final String NAME = "SERVICE_GAME";
private static boolean instantiated = false;
@SuppressLint("StaticFieldLeak")
private static Activity activity = null;
private static StoredLogin login = null;
private static final HashMap<String, OnLoginEventListener> loginEventListeners = new HashMap<>();
public interface OnLoginEventListener {
void onLoginEvent(String name, String uid);
void onLoginEvent(Login login);
void onLogoutEvent(int status, String message);
}
public static void addLoginEventListener(String key, OnLoginEventListener onLoginEventListener) {
loginEventListeners.put(key, onLoginEventListener);
if (isLoggedInSave()) {
try {
onLoginEventListener.onLoginEvent(getLoginName(), getLoginUID());
} catch (NotInitializedException | NotLoggedInException e) {
e.printStackTrace();
}
if (isLoggedIn()) {
onLoginEventListener.onLoginEvent(getLogin());
}
}
private static void emitLoginEvent(String name, String uid) {
private static void emitLoginEvent() {
for (OnLoginEventListener listener: loginEventListeners.values()) {
listener.onLoginEvent(name, uid);
listener.onLoginEvent(getLogin());
}
}
@@ -54,112 +52,136 @@ public class LoginService {
}
}
public static void instantiate(Activity activity) {
settings = activity.getSharedPreferences(PREFS_NAME, 0);
public static void initialize(Activity activity) {
SharedPreferences settings = activity.getSharedPreferences(PREFS_NAME, 0);
LoginService.activity = activity;
instantiated = true;
String name = null;
String uid = null;
try {
name = getLoginName();
uid = getLoginUIDSave();
} catch (NotInitializedException e) {
e.printStackTrace();
}
if (isLoggedInSave()) {
emitLoginEvent(name, uid);
login = new StoredLogin(settings, "");
if (LoginService.isLoggedIn()) {
emitLoginEvent();
try {
LoginService.doLogin(LoginService.getLogin().getUID());
} catch (NotInitializedException e) {
e.printStackTrace();
}
} else {
emitLogoutEvent(-5, null);
}
}
public static boolean isLoggedIn() throws NotInitializedException {
if (!instantiated)
throw new NotInitializedException();
return settings.getBoolean("isLoggedIn", false);
public static boolean isLoggedIn() {
return login != null && login.isLoaded();
}
private static boolean isLoggedInSave() {
try {
return isLoggedIn();
} catch (NotInitializedException e) {
return false;
}
public static Login getLogin() {
return login.get();
}
private static String getLoginName() throws NotInitializedException {
if (!LoginService.isLoggedIn())
return "";
return settings.getString("loginName", "");
private static void setLogin(Login user) {
login.login(user);
emitLoginEvent();
}
static String getLoginUID() throws NotInitializedException, NotLoggedInException {
if (!LoginService.isLoggedIn())
throw new NotLoggedInException();
return settings.getString("loginUID", "");
}
private static String getLoginUIDSave() throws NotInitializedException {
if (!LoginService.isLoggedIn())
return "";
return settings.getString("loginUID", "");
}
private static void setLogin(String name, String uid) throws NotInitializedException {
if (!instantiated)
throw new NotInitializedException();
SharedPreferences.Editor editor = settings.edit();
editor.putString("loginName", name);
editor.putString("loginUID", uid);
editor.putBoolean("isLoggedIn", true);
editor.apply();
emitLoginEvent(name, uid);
}
public static void setLogout(int status, String message) throws NotInitializedException {
if (!instantiated)
throw new NotInitializedException();
SharedPreferences.Editor editor = settings.edit();
editor.clear();
editor.apply();
private static void setLogout(int status, String message) {
login.logout();
emitLogoutEvent(status, message);
}
private static void setLoginSave(String name, String uid) {
try {
setLogin(name, uid);
} catch (NotInitializedException ignored) {
}
}
private static void setLogoutSave(int status, String message) {
try {
setLogout(status, message);
} catch (NotInitializedException ignored) {
}
}
public static void doLogin(String name) throws NotInitializedException {
public static void doRegister(String name) throws NotInitializedException {
if (!instantiated)
throw new NotInitializedException();
HashMap<String, String> params = new HashMap<>();
params.put("name", name);
JsonRequestPG requester = new JsonRequestPG("register.php", params, activity, new JsonRequestPG.AsyncResponse() {
@Override
public void processFinish(JSONObject output) {
Log.d("Activity fragment", "output");
Log.d("Activity fragment", output.toString());
Log.d(NAME, "output");
Log.d(NAME, output.toString());
// never reached if not instantiated
LoginService.setLoginSave(output.optString("name", ""), output.optString("uid", ""));
LoginService.setLogin(new Login(
output.optString("name", ""),
output.optString("uid", "")
));
}
@Override
public void processError(int status, String message) {
Log.d("Activity fragment", "error");
Log.d("Activity fragment", "status: "+status+" - message: "+message);
Log.d(NAME, "error");
Log.d(NAME, "status: "+status+" - message: "+message);
// never reached if not instantiated
LoginService.setLogout(status, message);
}
});
requester.execute();
}
public static void doLogin(String uid) throws NotInitializedException {
if (!instantiated)
throw new NotInitializedException();
HashMap<String, String> params = new HashMap<>();
params.put("uid", uid);
JsonRequestPG requester = new JsonRequestPG("login.php", params, activity, new JsonRequestPG.AsyncResponse() {
@Override
public void processFinish(JSONObject output) {
Log.d(NAME, "output");
Log.d(NAME, output.toString());
// never reached if not instantiated
LoginService.setLogin(new Login(
output.optString("name", ""),
output.optString("uid", "")
));
}
@Override
public void processError(int status, String message) {
Log.d(NAME, "error");
Log.d(NAME, "status: "+status+" - message: "+message);
}
});
requester.execute();
}
public static void doLogout(int status, String message) throws NotInitializedException {
if (!LoginService.instantiated) {
throw new NotInitializedException();
}
GameService.endGame();
GameService.endGame();
LoginService.setLogout(status, message);
}
public static void doRename(String name) throws NotInitializedException {
if (!instantiated)
throw new NotInitializedException();
HashMap<String, String> params = new HashMap<>();
params.put("name", name);
params.put("uid", LoginService.getLogin().getUID());
JsonRequestPG requester = new JsonRequestPG("rename.php", params, activity, new JsonRequestPG.AsyncResponse() {
@Override
public void processFinish(JSONObject output) {
Log.d(NAME, "output");
Log.d(NAME, output.toString());
// never reached if not instantiated
LoginService.setLogin(new Login(
output.optString("name", ""),
output.optString("uid", "")
));
}
@Override
public void processError(int status, String message) {
Log.d(NAME, "error");
Log.d(NAME, "status: "+status+" - message: "+message);
// never reached if not instantiated
LoginService.setLogoutSave(status, message);
}
});
requester.execute();

View File

@@ -0,0 +1,82 @@
package de.hwr_berlin.it14.postgrachelor;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import de.hwr_berlin.it14.postgrachelor.Services.GameService;
import de.hwr_berlin.it14.postgrachelor.Services.HighscoreService;
import de.hwr_berlin.it14.postgrachelor.Services.LoginService;
import de.hwr_berlin.it14.postgrachelor.Types.Login;
import de.hwr_berlin.it14.postgrachelor.Utils.SettingAdapter;
/**
* Created by Sebastian on 24.04.2017.
*/
public class SettingActivity extends AppCompatActivity {
private static final String NAME = "SettingActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
if (getActionBar() != null) {
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(true);
} else if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
ListView listView = (ListView) findViewById(R.id.setting_listview);
SettingAdapter adapter = new SettingAdapter(this);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
GameService.initialize(this);
LoginService.initialize(this);
HighscoreService.initialize(this);
LoginService.addLoginEventListener(NAME, new LoginService.OnLoginEventListener() {
@Override
public void onLoginEvent(Login login) {
}
@Override
public void onLogoutEvent(int status, String message) {
SettingActivity.this.finish();
}
});
}
@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}
@Override
public boolean onNavigateUp() {
onBackPressed();
return true;
}
@Override
protected void onResume() {
super.onResume();
HighscoreService.initialize(this);
LoginService.initialize(this);
GameService.initialize(this);
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
}
}

View File

@@ -16,13 +16,6 @@ public class HighscoresUser extends Requestable {
this.unrequested();
}
public HighscoresUser() {
super();
this.name = "";
this.score = 0;
this.place = 0;
}
public String getName() {
return name;
}

View File

@@ -0,0 +1,23 @@
package de.hwr_berlin.it14.postgrachelor.Types;
/**
* Created by Sebastian on 24.04.2017.
*/
public class Login {
private final String name;
private final String uid;
public Login(String name, String uid) {
this.name = name;
this.uid = uid;
}
public String getName() {
return name;
}
public String getUID() {
return uid;
}
}

View File

@@ -0,0 +1,18 @@
package de.hwr_berlin.it14.postgrachelor.Types;
/**
* Created by Sebastian on 23.04.2017.
* Time and score measurement
*/
public class Prefs {
private final int gameLength;
Prefs(int gameLength) {
this.gameLength = gameLength;
}
public int getGameLength() {
return gameLength;
}
}

View File

@@ -15,11 +15,11 @@ public class Requestable {
return this.requested != 0;
}
protected void unrequested() {
void unrequested() {
this.requested = 0;
}
protected void requested() {
private void requested() {
this.requested = System.currentTimeMillis();
}
}

View File

@@ -0,0 +1,53 @@
package de.hwr_berlin.it14.postgrachelor.Types;
import android.view.View;
/**
* Created by Sebastian on 24.04.2017.
*/
public class SettingItem {
private final String title;
private String name;
private final View.OnClickListener onClickListener;
private final String message;
private String value;
public SettingItem(String title, String message, View.OnClickListener onClickListener) {
this.title = title;
this.name = "";
this.message = message;
this.value = "";
this.onClickListener = onClickListener;
}
public String getTitle() {
return title;
}
public View.OnClickListener getOnClickListener() {
return onClickListener;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMessage() {
return message;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@@ -0,0 +1,38 @@
package de.hwr_berlin.it14.postgrachelor.Types;
import android.content.SharedPreferences;
/**
* Created by Sebastian on 24.04.2017.
*/
public class StoredLogin extends StoredObject {
private static final String STR_NAME = "name";
private String name;
private static final String STR_UID = "uid";
private String uid;
public StoredLogin(SharedPreferences prefs, String prefix) {
super(prefs, prefix+".login");
this.name = this.loadFromPref(STR_NAME, "");
this.uid = this.loadFromPref(STR_UID, "");
}
public void login(Login login) {
this.name = login.getName();
this.saveToPref(STR_NAME, this.name);
this.uid = login.getUID();
this.saveToPref(STR_UID, this.uid);
this.unremove();
}
public void logout() {
this.remove();
}
public Login get() {
if (!this.isLoaded())
return null;
return new Login(this.name, this.uid);
}
}

View File

@@ -70,10 +70,6 @@ public class StoredNextEntity extends StoredObject {
this.answer3
});
}
protected void remove() {
super.remove();
}
}
private class End extends StoredObject {
@@ -139,14 +135,6 @@ public class StoredNextEntity extends StoredObject {
return this.end.get();
}
public boolean isNext() {
return this.next.isLoaded();
}
public boolean isEnd() {
return this.end.isLoaded();
}
public void remove() {
super.remove();
}

View File

@@ -2,9 +2,6 @@ package de.hwr_berlin.it14.postgrachelor.Types;
import android.content.SharedPreferences;
import android.util.Log;
import android.util.NoSuchPropertyException;
import java.util.NoSuchElementException;
/**
* Created by Sebastian on 18.04.2017.
@@ -12,15 +9,15 @@ import java.util.NoSuchElementException;
*/
abstract class StoredObject {
private SharedPreferences prefs;
private String prefix;
private final SharedPreferences prefs;
private final String prefix;
StoredObject(SharedPreferences prefs, String prefix){
this.prefs = prefs;
this.prefix = prefix;
}
protected void remove() {
void remove() {
SharedPreferences.Editor editor = this.prefs.edit();
editor.putBoolean("L"+this.prefix, false);
editor.apply();

View File

@@ -0,0 +1,33 @@
package de.hwr_berlin.it14.postgrachelor.Types;
import android.content.SharedPreferences;
/**
* Created by Sebastian on 06.04.2017.
* Timing results on each tick, when game is running
*/
public class StoredPrefs extends StoredObject {
private static final int DEFAULT_GAME_LENGTH = 10;
private int gameLength;
private static final String STR_GAME_LENGTH = "gameLength";
public StoredPrefs(SharedPreferences prefs, String prefix) {
super(prefs, prefix+".gameLength");
this.gameLength = this.loadFromPref(STR_GAME_LENGTH, DEFAULT_GAME_LENGTH);
this.unremove();
}
public void setGameLength(int gameLength) {
if (gameLength > 0)
this.gameLength = gameLength;
else
this.gameLength = DEFAULT_GAME_LENGTH;
this.saveToPref(STR_GAME_LENGTH, this.gameLength);
}
public Prefs get() {
return new Prefs(this.gameLength);
}
}

View File

@@ -69,10 +69,6 @@ public class StoredQuestion extends StoredObject {
this.answer3
});
}
protected void remove() {
super.remove();
}
}
private class Answer extends StoredObject {
@@ -189,18 +185,6 @@ public class StoredQuestion extends StoredObject {
return this.result.get();
}
public boolean isQuestion() {
return this.question.isLoaded();
}
public boolean isAnswer() {
return this.answer.isLoaded();
}
public boolean isResult() {
return this.result.isLoaded();
}
public void remove() {
super.remove();
}

View File

@@ -2,8 +2,6 @@ package de.hwr_berlin.it14.postgrachelor.Types;
import android.content.SharedPreferences;
import java.util.NoSuchElementException;
/**
* Created by Sebastian on 21.04.2017.
* Stored game state object

View File

@@ -1,7 +1,6 @@
package de.hwr_berlin.it14.postgrachelor.Types;
import android.content.SharedPreferences;
import android.provider.Settings;
/**
* Created by Sebastian on 06.04.2017.
@@ -15,14 +14,14 @@ public class StoredTimings extends StoredObject {
private static final int T = 100;
private long startTime;
private static final String STR_STARTTIME = "startTime";
private static final String STR_START_TIME = "startTime";
private long endTime;
private static final String STR_ENDTIME = "endTime";
private static final String STR_END_TIME = "endTime";
public StoredTimings(SharedPreferences prefs, String prefix) {
super(prefs, prefix+".timings");
this.startTime = this.loadFromPref(STR_STARTTIME, (long) -1);
this.endTime = this.loadFromPref(STR_ENDTIME, (long) -1);
this.startTime = this.loadFromPref(STR_START_TIME, (long) -1);
this.endTime = this.loadFromPref(STR_END_TIME, (long) -1);
if (this.startTime == -1)
this.remove();
else
@@ -31,9 +30,9 @@ public class StoredTimings extends StoredObject {
public void start() {
this.startTime = System.currentTimeMillis();
this.saveToPref(STR_STARTTIME, this.startTime);
this.saveToPref(STR_START_TIME, this.startTime);
this.endTime = -1;
this.saveToPref(STR_ENDTIME, this.endTime);
this.saveToPref(STR_END_TIME, this.endTime);
this.unremove();
}
@@ -41,7 +40,7 @@ public class StoredTimings extends StoredObject {
if (this.endTime != -1)
return;
this.endTime = System.currentTimeMillis();
this.saveToPref(STR_ENDTIME, this.endTime);
this.saveToPref(STR_END_TIME, this.endTime);
}
public void reset() {

View File

@@ -1,7 +1,6 @@
package de.hwr_berlin.it14.postgrachelor.Utils;
import android.os.AsyncTask;
import android.test.suitebuilder.annotation.Suppress;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
@@ -14,14 +13,14 @@ import de.hwr_berlin.it14.postgrachelor.Types.Requestable;
* Created by Sebastian on 10.04.2017.
*/
public abstract class AsyncAdapter<T extends Requestable> extends BaseAdapter {
abstract class AsyncAdapter<T extends Requestable> extends BaseAdapter {
private int count;
private ArrayList<Requestable> items;
private AsyncAdapter() {}
public AsyncAdapter(int count) {
AsyncAdapter(int count) {
super();
items = new ArrayList<>();
this.setCount(count);
@@ -51,7 +50,7 @@ public abstract class AsyncAdapter<T extends Requestable> extends BaseAdapter {
return convertView;
}
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "UnusedParameters"})
private void loadView(int position, View convertView, ViewGroup parent) {
if (position >= this.items.size() || this.items.get(position) == null) {
AsyncRequest request = new AsyncRequest(position, convertView);
@@ -61,8 +60,10 @@ public abstract class AsyncAdapter<T extends Requestable> extends BaseAdapter {
}
}
@SuppressWarnings("UnusedParameters")
abstract void fillView(T item, int position, View convertView);
@SuppressWarnings("UnusedParameters")
abstract View inflateView(int position, ViewGroup parent);
abstract View clearView(int position, View convertView);
@@ -78,10 +79,10 @@ public abstract class AsyncAdapter<T extends Requestable> extends BaseAdapter {
class AsyncRequest extends AsyncTask<Void, Void, ListSequence<T>> {
private class AsyncRequest extends AsyncTask<Void, Void, ListSequence<Requestable>> {
private final int position;
private View convertView;
private final View convertView;
AsyncRequest(int position, View convertView) {
this.position = position;
@@ -104,16 +105,21 @@ public abstract class AsyncAdapter<T extends Requestable> extends BaseAdapter {
@Override
protected ListSequence<T> doInBackground(Void... arg0) {
return getAsyncListSequence(position);
protected ListSequence<Requestable> doInBackground(Void... arg0) {
ListSequence<T> list = getAsyncListSequence(position);
ArrayList<T> items = list.getItems();
ArrayList<Requestable> requestables = new ArrayList<>(items.size());
for (T item: items) {
requestables.add(item);
}
return new ListSequence<>(list.getStart(), requestables);
}
@Override
@SuppressWarnings("unchecked")
protected void onPostExecute(ListSequence<T> result) {
protected void onPostExecute(ListSequence<Requestable> result) {
super.onPostExecute(result);
int start = result.getStart();
ArrayList<T> list = result.getItems();
ArrayList<Requestable> list = result.getItems();
for (int i = items.size(); i < start; i++) {
items.add(null);
}
@@ -124,17 +130,25 @@ public abstract class AsyncAdapter<T extends Requestable> extends BaseAdapter {
items.add(list.remove(0));
start++;
}
if (position < items.size())
fillView((T) items.get(position), position, convertView);
if (position < items.size()) {
try {
T item;
//noinspection unchecked
item = (T) items.get(position);
fillView(item, position, convertView);
} catch (ClassCastException e) {
fillView(null, position, convertView);
}
}
notifyDataSetChanged();
}
}
class ListSequence<T> {
class ListSequence<R> {
private final int start;
private final ArrayList<T> items;
private final ArrayList<R> items;
public ListSequence(int start, int end, ArrayList<T> items) {
ListSequence(int start, ArrayList<R> items) {
this.start = start;
this.items = items;
}
@@ -144,7 +158,7 @@ public abstract class AsyncAdapter<T extends Requestable> extends BaseAdapter {
return start;
}
public ArrayList<T> getItems() {
ArrayList<R> getItems() {
return items;
}
}

View File

@@ -18,8 +18,8 @@ import de.hwr_berlin.it14.postgrachelor.Types.HighscoresUser;
*/
public class HighscoreAdapter extends AsyncAdapter<HighscoresUser> {
private Context context;
private int category;
private final Context context;
private final int category;
public HighscoreAdapter(int count, int category, Context context) {
super(count);
@@ -35,12 +35,10 @@ public class HighscoreAdapter extends AsyncAdapter<HighscoresUser> {
TextView userNameView = (TextView) convertView.findViewById(R.id.tvName);
TextView userPlaceView = (TextView) convertView.findViewById(R.id.tvPlace);
TextView userScoreView = (TextView) convertView.findViewById(R.id.tvScore);
if (userNameView != null) {
if (userNameView != null)
userNameView.setText(item.getName());
}
if (userPlaceView != null) {
if (userPlaceView != null)
userPlaceView.setText(convertView.getContext().getResources().getString(R.string.place, Conversion.intToStr(item.getPlace())));
}
if (userScoreView != null) {
int score = item.getScore();
if (score != -1)
@@ -77,7 +75,7 @@ public class HighscoreAdapter extends AsyncAdapter<HighscoresUser> {
ListSequence<HighscoresUser> getAsyncListSequence(int position) {
int limit = this.getRequestedLength(position);
ArrayList<HighscoresUser> items = HighscoreService.getHighscoreDetailsSync(limit, position, this.category, null);
return new ListSequence<>(position, position+items.size()-1, items);
return new ListSequence<>(position, items);
}
@Override

View File

@@ -1,11 +1,9 @@
package de.hwr_berlin.it14.postgrachelor.Utils;
import android.app.Activity;
import android.app.ProgressDialog;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
@@ -20,9 +18,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import de.hwr_berlin.it14.postgrachelor.R;
import de.hwr_berlin.it14.postgrachelor.Types.RequestActivityInterface;
import de.hwr_berlin.it14.postgrachelor.Types.Requestable;
import static android.content.ContentValues.TAG;
@@ -31,16 +27,18 @@ abstract class JsonRequest extends AsyncTask<Void, Void, JSONObject> {
private final String path;
private final HashMap<String, String> params;
final Activity activity;
private final RequestActivityInterface requestInterface;
private String uuid;
JsonRequest(String path, HashMap<String, String> params, Activity activity) {
this.connectionURL = getConnectionURL();
this.path = path;
this.params = params;
this.activity = activity;
if (activity instanceof RequestActivityInterface) {
this.activity = activity;
this.requestInterface = ((RequestActivityInterface) this.activity);
} else {
this.activity = null;
this.requestInterface = null;
}
Log.d("JSONRequest create", connectionURL+path);
}
@@ -48,7 +46,7 @@ abstract class JsonRequest extends AsyncTask<Void, Void, JSONObject> {
@SuppressWarnings("SameReturnValue")
protected abstract String getConnectionURL();
public JSONObject executeSync() {
JSONObject executeSync() {
JSONObject result = this.doInBackground();
Log.d("JSONRequest excecute", result.toString());
return result;
@@ -59,8 +57,8 @@ abstract class JsonRequest extends AsyncTask<Void, Void, JSONObject> {
super.onPreExecute();
Log.d("fragment, JSONRequest", "onPre1");
// Showing progress dialog
if (this.activity != null)
this.uuid = ((RequestActivityInterface) this.activity).showDialog();
if (this.requestInterface != null)
this.uuid = this.requestInterface.showDialog();
}
@@ -104,11 +102,11 @@ abstract class JsonRequest extends AsyncTask<Void, Void, JSONObject> {
jsonObj = new JSONObject(jsonText);
} catch (final JSONException e) {
Log.e(TAG, "Json parsing error: " + e.getMessage());
if (this.activity != null) {
if (this.requestInterface != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
((RequestActivityInterface) activity).errorJsonLoadingFailed(e.getMessage());
requestInterface.errorJsonLoadingFailed(e.getMessage());
}
});
@@ -116,11 +114,11 @@ abstract class JsonRequest extends AsyncTask<Void, Void, JSONObject> {
}
} else {
Log.e(TAG, "Couldn't get json from server.");
if (this.activity != null) {
if (this.requestInterface != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
((RequestActivityInterface) activity).errorJsonParsing();
requestInterface.errorJsonParsing();
}
});
@@ -134,8 +132,8 @@ abstract class JsonRequest extends AsyncTask<Void, Void, JSONObject> {
@Override
protected void onPostExecute(JSONObject result) {
super.onPostExecute(result);
if (this.activity != null)
((RequestActivityInterface) activity).hideDialog(this.uuid);
if (this.requestInterface != null)
requestInterface.hideDialog(this.uuid);
}
private String parseURL(String url, Map<String, String> params)

View File

@@ -3,7 +3,6 @@ package de.hwr_berlin.it14.postgrachelor.Utils;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;

View File

@@ -14,6 +14,7 @@ public class ReverseInterpolator implements Interpolator {
this.delegate = delegate;
}
@SuppressWarnings("unused")
public ReverseInterpolator(){
this(new LinearInterpolator());
}

View File

@@ -0,0 +1,194 @@
package de.hwr_berlin.it14.postgrachelor.Utils;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.view.ContextThemeWrapper;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInitializedException;
import de.hwr_berlin.it14.postgrachelor.R;
import de.hwr_berlin.it14.postgrachelor.Services.GameService;
import de.hwr_berlin.it14.postgrachelor.Services.LoginService;
import de.hwr_berlin.it14.postgrachelor.Types.Login;
import de.hwr_berlin.it14.postgrachelor.Types.Prefs;
import de.hwr_berlin.it14.postgrachelor.Types.SettingItem;
/**
* Created by Sebastian on 24.04.2017.
*/
public class SettingAdapter extends BaseAdapter {
private static final String NAME = "SettingAdapter";
private final Activity activity;
private final Context context;
private final SettingItem[] items;
public SettingAdapter(final Activity activity) {
super();
this.context = activity.getApplicationContext();
this.activity = activity;
this.items = new SettingItem[] {
new SettingItem(context.getString(R.string.game_length),
context.getString(R.string.game_length_msg),
new View.OnClickListener() {
@Override
public void onClick(View v) {
final EditText input = getInputView();
input.setInputType(InputType.TYPE_CLASS_NUMBER);
getInsertBox((SettingItem) v.getTag(), input, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int len = Conversion.strToInt(input.getText().toString(), 0);
try {
GameService.setGameLength(len);
} catch (NotInitializedException e) {
e.printStackTrace();
}
}
}).show();
}
}),
new SettingItem(context.getString(R.string.change_user_name),
context.getString(R.string.change_user_name_msg), new View.OnClickListener() {
@Override
public void onClick(View v) {
final EditText input = getInputView();
getInsertBox((SettingItem) v.getTag(), input, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
LoginService.doRename(input.getText().toString());
} catch (NotInitializedException e) {
e.printStackTrace();
}
}
}).show();
}
}),
new SettingItem(context.getString(R.string.copy_uid),
context.getString(R.string.copy_uid_msg), new View.OnClickListener() {
@Override
public void onClick(View v) {
final EditText input = getInputView();
input.setSelectAllOnFocus(true);
getInsertBox((SettingItem) v.getTag(), input, null).show();
}
}),
new SettingItem(context.getString(R.string.logout_user),
context.getString(R.string.logout_user_msg), new View.OnClickListener() {
@Override
public void onClick(View v) {
getInsertBox((SettingItem) v.getTag(), null, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
LoginService.doLogout(-7, "User desired logout!");
} catch (NotInitializedException e) {
e.printStackTrace();
}
}
}).show();
}
})
};
items[3].setName(context.getString(R.string.logout_user_value));
GameService.addPrefsUpdateEventListener(NAME, new GameService.OnPrefsUpdateEventListener() {
@Override
public void onPrefsUpdateEvent(Prefs prefs) {
items[0].setName(context.getResources().getQuantityString(R.plurals.current_length, prefs.getGameLength(), prefs.getGameLength()));
items[0].setValue(Conversion.intToStr(prefs.getGameLength()));
notifyDataSetChanged();
}
});
LoginService.addLoginEventListener(NAME, new LoginService.OnLoginEventListener() {
@Override
public void onLoginEvent(Login login) {
items[1].setName(context.getString(R.string.current_name, login.getName()));
items[1].setValue(login.getName());
items[2].setName(context.getString(R.string.current_uid, login.getUID()));
items[2].setValue(login.getUID());
notifyDataSetChanged();
}
@Override
public void onLogoutEvent(int status, String message) {
items[1].setName(context.getString(R.string.not_logged_in));
items[1].setValue("");
items[2].setName(context.getString(R.string.not_logged_in));
items[2].setValue("");
notifyDataSetChanged();
}
});
}
@Override
public int getCount() {
return items.length;
}
@Override
public SettingItem getItem(int position) {
return this.items[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.adapter_setting, parent, false);
}
SettingItem item = getItem(position);
TextView textView = (TextView) convertView.findViewById(R.id.svTitle);
textView.setText(item.getTitle());
textView = (TextView) convertView.findViewById(R.id.svName);
textView.setText(item.getName());
convertView.setOnClickListener(item.getOnClickListener());
convertView.setTag(item);
return convertView;
}
private EditText getInputView() {
final EditText input = new EditText(context);
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
return input;
}
private AlertDialog.Builder getInsertBox(SettingItem item, EditText input, DialogInterface.OnClickListener onPositive) {
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.DialogTheme));
builder.setTitle(item.getTitle());
builder.setMessage(item.getMessage());
// Set up the input
if (input != null) {
input.setText(item.getValue());
builder.setView(input);
}
// Set up the buttons
if (onPositive != null)
builder.setPositiveButton("OK", onPositive);
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
return builder;
}
}

View File

@@ -1,12 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0" />
<path
android:fillColor="#FF000000"
android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />
</vector>

View File

@@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M22,16V4c0,-1.1 -0.9,-2 -2,-2H8c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2zm-11,-4l2.03,2.71L16,11l4,5H8l3,-4zM2,6v14c0,1.1 0.9,2 2,2h14v-2H4V6H2z" />
</vector>

View File

@@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M22.7,19l-9.1,-9.1c0.9,-2.3 0.4,-5 -1.5,-6.9 -2,-2 -5,-2.4 -7.4,-1.3L9,6 6,9 1.6,4.7C0.4,7.1 0.9,10.1 2.9,12.1c1.9,1.9 4.6,2.4 6.9,1.5l9.1,9.1c0.4,0.4 1,0.4 1.4,0l2.3,-2.3c0.5,-0.4 0.5,-1.1 0.1,-1.4z" />
</vector>

View File

@@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z" />
</vector>

View File

@@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z" />
</vector>

View File

@@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M4,6H2v14c0,1.1 0.9,2 2,2h14v-2H4V6zm16,-4H8c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V4c0,-1.1 -0.9,-2 -2,-2zm-8,12.5v-9l6,4.5 -6,4.5z" />
</vector>

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="6"
android:shape="ring"
android:thickness="10dp" >
<solid android:color="@color/colorPrimaryDark" />
</shape>

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FFFF"
android:pathData="M8 5v14l11-7z" />
</vector>

View File

@@ -1,9 +0,0 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="135"
android:centerColor="#4CAF50"
android:endColor="#2E7D32"
android:startColor="#81C784"
android:type="linear" />
</shape>

View File

@@ -1,6 +1,5 @@
<?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"

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="de.hwr_berlin.it14.postgrachelor.SettingActivity">
<ListView
android:id="@+id/setting_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/adapter_setting" />
</android.support.constraint.ConstraintLayout>

View File

@@ -9,12 +9,15 @@
style="@style/TextAppearance.AppCompat.Body1"
android:textColor="@android:color/primary_text_light"
android:padding="20dp"
android:paddingStart="0dp"
android:paddingLeft="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end"
android:width="70sp"
android:maxWidth="70sp"
android:text="@string/_0" />
tools:text="0000"
tools:ignore="RtlSymmetry" />
<TextView
android:id="@+id/tvName"
style="@style/TextAppearance.AppCompat.Body1"

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<TextView
android:id="@+id/svTitle"
style="@style/TextAppearance.AppCompat.Body2"
android:textColor="@android:color/primary_text_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Title is important" />
<TextView
android:id="@+id/svName"
android:textColor="@android:color/secondary_text_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Current setting: here" />
</LinearLayout>

View File

@@ -47,6 +47,15 @@
android:layout_height="wrap_content"
android:id="@+id/login_btn"
android:text="@string/register_btn"/>
<!--<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/already_registered"
android:clickable="true"
android:textColor="@color/colorPrimaryDark"
android:paddingTop="5dp"
android:textStyle="italic"
android:text="@string/already_registered"/>-->
</LinearLayout>

View File

@@ -37,7 +37,8 @@
grid:alignmentMode="alignBounds"
grid:columnCount="2"
grid:rowOrderPreserved="false"
grid:useDefaultMargins="true">
grid:useDefaultMargins="true"
tools:listitem="@layout/fragment_main_category">
<include layout="@layout/fragment_main_category"
android:layout_width="0dp"
android:layout_height="wrap_content"

View File

@@ -2,7 +2,6 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="@layout/fragment_main"
android:background="#FF33B5E6"
android:layout_width="0dp"
android:layout_height="0dp"

View File

@@ -1,9 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_gameState"
android:orderInCategory="100"
android:icon="@android:drawable/ic_media_play"
android:title="@string/start_test"
app:showAsAction="ifRoom|withText" />
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
android:icon="@android:drawable/ic_menu_preferences"
app:showAsAction="never|withText" />
<item
android:id="@+id/action_help"
android:orderInCategory="100"
android:title="@string/help"
android:icon="@android:drawable/ic_menu_help"
app:showAsAction="never|withText" />
</menu>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<plurals name="current_length">
<item quantity="one">eine Frage</item>
<item quantity="other">%d Fragen</item>
</plurals>
</resources>

View File

@@ -1,17 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="action_settings">Einstellungen</string>
<string name="enter_user_name">Benutzername eingeben…</string>
<string name="enter_user_name">Benutzername oder UID eingeben…</string>
<string name="welcome_text">Willkommen zu unserer sinnlosen App! Beweise, dass du schlauer bist als wir und beantworte unsere Fragen!</string>
<string name="register_btn">Registrieren</string>
<string name="start_test">Test starten!</string>
<string name="test_completed">Test beendet!</string>
<string name="return_btn">Zurück</string>
<string name="android_studio_email">android.studio@android.com</string>
<string name="no_highscores_available">Highscores konnten nicht geladen werden!</string>
<string name="no_highscores_available">Highscores konnten nicht geladen werden! Herunterziehen zum aktualisieren…</string>
<string name="resume_test">Test wiederaufnehmen!</string>
<string name="no_score">Keine Punkte</string>
<string name="no_time">Keine Zeit</string>
@@ -21,4 +18,23 @@
<string name="please_wait">Bitte warten…</string>
<string name="loading">Lädt…</string>
<string name="place">%1$s.</string>
<string name="help">Hilfe</string>
<string name="pause_test">Test pausieren!</string>
<string name="change_user_name">Benutzernamen ändern</string>
<string name="change_user_name_msg">Gib Deinen neuen Benutzernamen ein:</string>
<string name="copy_uid">Klicke, um deine UID zu kopieren</string>
<string name="copy_uid_msg">Kopiere deine UID und stelle dein Account auf einem anderen Account wieder her!</string>
<string name="current_name">Aktueller Benutzername: %s</string>
<string name="current_uid">Aktuelle UID: %s</string>
<string name="game_length">Spiellänge</string>
<string name="game_length_msg">Gib die Anzahl der Fragen in einem Test an:</string>
<string name="not_logged_in">Du bist gar nicht eingeloggt, Junge!</string>
<string name="logout_user_value">Melde dich aus deinem Account aus!</string>
<string name="logout_user_msg">Möchtest du dich wirklich ausloggen? Stelle sicher, dass du deine UID extern GESICHERT hast!</string>
<string name="logout_user">Abmelden</string>
<string name="login_user_btn">Login mit deiner UID</string>
<string name="help_login">Registriere Dich mit einem eindeutigen Namen mit 620 Zeichen. Falls du schon ein Account hast, kannst du auch deine 32 Zeichen lange UID eintragen, die du innerhalb der App in den Einstellungen findest.</string>
<string name="help_main">Hier siehst Du Deine Highscores! Unter dem \"Spiel starten\"-Button findest Du sowohl deine Gesamt-Highscore als auch für die einzelnen Kategorien. Der Fortschrittsbalken zeigt live Deine Position zu anderen Spielern. Die angegebenen Punkte entsprechen gewichteten Durchschnittspunkten pro Frage.</string>
<string name="help_question">Schnell! Je schneller du antwortest, desto mehr Punkte bekommst du! Für jede korrekte Antwort erhälst du mindestens 100 Punkte. Falsche Antworten werden mit 0 Punkten gewertet!</string>
<string name="help_question_end">Herzlichen Glückwunsch! Du hast deinen Test erfolgreich beendet und deine Gesamtpunkte und deine für den Test benötigte Zeit werden nun angezeigt.</string>
</resources>

View File

@@ -1,9 +1,6 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="nav_header_vertical_spacing">16dp</dimen>
<dimen name="nav_header_height">160dp</dimen>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>

View File

@@ -1,8 +1 @@
<resources>
<item name="ic_menu_camera" type="drawable">@android:drawable/ic_menu_camera</item>
<item name="ic_menu_gallery" type="drawable">@android:drawable/ic_menu_gallery</item>
<item name="ic_menu_slideshow" type="drawable">@android:drawable/ic_menu_slideshow</item>
<item name="ic_menu_manage" type="drawable">@android:drawable/ic_menu_manage</item>
<item name="ic_menu_share" type="drawable">@android:drawable/ic_menu_share</item>
<item name="ic_menu_send" type="drawable">@android:drawable/ic_menu_send</item>
</resources>
<resources />

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<plurals name="current_length">
<item quantity="one">1 question</item>
<item quantity="other">%d questions</item>
</plurals>
</resources>

View File

@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name" translatable="false">PostGrachelor</string>
<string name="action_settings">Settings</string>
<string name="enter_user_name">Enter User Name…</string>
<string name="enter_user_name">Enter User Name or UID…</string>
<string name="welcome_text">Welcome to our stupid app. Prove that you are smarter than we are and answer our questions!</string>
<string name="register_btn">Register</string>
<string name="start_test">Start Test!</string>
@@ -14,7 +11,7 @@
<string name="return_btn">Return</string>
<string name="launcher_icon" translatable="false">Launcher Icon</string>
<string name="android_studio_email">android.studio@android.com</string>
<string name="no_highscores_available">Highscores could not be loaded!</string>
<string name="no_highscores_available">Highscores could not be loaded! Pull down to refresh…</string>
<string name="resume_test">Resume Test!</string>
<string name="_02_15" translatable="false">02:15</string>
<string name="no_score">No Score</string>
@@ -26,4 +23,23 @@
<string name="please_wait">Please wait…</string>
<string name="loading">Loading…</string>
<string name="place">#%1$s</string>
<string name="help">Help</string>
<string name="pause_test">Pause Test!</string>
<string name="current_name">Current Name: %s</string>
<string name="not_logged_in">You are not logged in, dude!</string>
<string name="game_length">Game Length</string>
<string name="change_user_name">Change User Name</string>
<string name="copy_uid">Click to copy your UID</string>
<string name="current_uid">Current UID: %s</string>
<string name="game_length_msg">Enter how many questions a game should contain:</string>
<string name="change_user_name_msg">Enter your new user name:</string>
<string name="copy_uid_msg">Copy your UID to restore your account on a different device!</string>
<string name="logout_user">Logout</string>
<string name="logout_user_msg">Log out from your account! Be sure to COPY your UID externally before!</string>
<string name="logout_user_value">Log out from your account!</string>
<string name="login_user_btn">Login with your UID</string>
<string name="help_login">Register yourself with a unique name with 6 to 20 characters. If you already have an account enter your 32 character long UID. You can find it in your settings screen inside the app.</string>
<string name="help_main">This page shows your highscores! Underneath the test start button you can find your general highscore and your scores per category. The progress bar indicates your live place relative to other players. Points are valued average points per question.</string>
<string name="help_question">Hurry up! The faster you answer your question, the more points you get! For any correct answer you receive at least 100 point. Wrong answers are rewarded with 0 points!</string>
<string name="help_question_end">Congratulations! You finished your test successfully and your total score and total time of all questions are shown.</string>
</resources>

View File

@@ -17,4 +17,10 @@
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="DialogTheme" parent="Theme.AppCompat.Dialog">
<!--<item name="android:windowNoTitle">true</item>-->
<!--<item name="android:textColorPrimary">@android:color/background_light</item>
<item name="android:textColor">@android:color/background_light</item>-->
</style>
</resources>