Compare commits
10 Commits
b9dddacbaa
...
ef00bc0657
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef00bc0657 | ||
|
|
a00b1f6412 | ||
|
|
e4f0f805c5 | ||
|
|
362e387d26 | ||
|
|
976d74676c | ||
|
|
fcb1ca3aa0 | ||
|
|
ef78bff9be | ||
|
|
cff541d58e | ||
|
|
4d2a472686 | ||
|
|
23073a8841 |
7
.idea/dictionaries/Sebastian.xml
generated
Normal file
7
.idea/dictionaries/Sebastian.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="Sebastian">
|
||||
<words>
|
||||
<w>postgrachelor</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
3
.idea/gradle.xml
generated
3
.idea/gradle.xml
generated
@@ -3,9 +3,8 @@
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="LOCAL" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.14.1" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
||||
17
.idea/misc.xml
generated
17
.idea/misc.xml
generated
@@ -1,7 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
<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">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
@@ -27,17 +30,7 @@
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||
<OptionsSetting value="true" id="Add" />
|
||||
<OptionsSetting value="true" id="Remove" />
|
||||
<OptionsSetting value="true" id="Checkout" />
|
||||
<OptionsSetting value="true" id="Update" />
|
||||
<OptionsSetting value="true" id="Status" />
|
||||
<OptionsSetting value="true" id="Edit" />
|
||||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
1
app/.gitignore
vendored
1
app/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/build
|
||||
@@ -1,6 +1,14 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
signingConfigs {
|
||||
config {
|
||||
keyAlias 'PostGrachelor'
|
||||
keyPassword '9ApoTheke'
|
||||
storeFile file('D:/nextcloud/Documents/Konfigurationen/JavaKeystore/android.jks')
|
||||
storePassword '9ApoTheke'
|
||||
}
|
||||
}
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.2"
|
||||
defaultConfig {
|
||||
@@ -15,16 +23,23 @@ android {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
signingConfig signingConfigs.config
|
||||
}
|
||||
debug {
|
||||
signingConfig signingConfigs.config
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
compile 'com.android.support:appcompat-v7:25.2.0'
|
||||
compile 'com.android.support:design:25.2.0'
|
||||
compile 'com.android.support:gridlayout-v7:25.3.1'
|
||||
compile 'com.android.support:appcompat-v7:25.3.1'
|
||||
compile 'com.android.support:design:25.3.1'
|
||||
compile 'com.android.support:support-v4:25.3.1'
|
||||
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
<?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" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:allowBackup="false"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
@@ -11,12 +14,36 @@
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
android:launchMode="singleTask"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
<data
|
||||
android:host="postgrachelor"
|
||||
android:scheme="postgrachelor" />
|
||||
</intent-filter>
|
||||
</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>
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Exceptions;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 25.03.17.
|
||||
* Exception to indicate a not instantiated service
|
||||
*/
|
||||
|
||||
public class NoCurrentQuestionException extends Exception {
|
||||
private static final long serialVersionUID = 1997753363232807010L;
|
||||
|
||||
public NoCurrentQuestionException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public NoCurrentQuestionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NoCurrentQuestionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public NoCurrentQuestionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Exceptions;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 25.03.17.
|
||||
* Exception to indicate a not instantiated service
|
||||
*/
|
||||
|
||||
public class NotInitializedException extends Exception {
|
||||
private static final long serialVersionUID = 1997753363232807009L;
|
||||
|
||||
public NotInitializedException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public NotInitializedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NotInitializedException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public NotInitializedException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Exceptions;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 25.03.17.
|
||||
* Exception to indicate a not instantiated service
|
||||
*/
|
||||
|
||||
public class NotLoggedInException extends Exception {
|
||||
private static final long serialVersionUID = 1997753363232807010L;
|
||||
|
||||
public NotLoggedInException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public NotLoggedInException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NotLoggedInException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public NotLoggedInException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package de.hwr_berlin.it14.postgrachelor;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
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.Utils.Conversion;
|
||||
import de.hwr_berlin.it14.postgrachelor.Utils.HighscoreAdapter;
|
||||
|
||||
public class HighscoreActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
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);
|
||||
} else if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
// Get the Intent that started this activity and extract the string
|
||||
Intent intent = getIntent();
|
||||
String categoryID = intent.getStringExtra("CategoryID");
|
||||
String categoryName = intent.getStringExtra("CategoryName");
|
||||
String categoryCount = intent.getStringExtra("CategoryCount");
|
||||
|
||||
ListView listView = (ListView) findViewById(R.id.category_listview);
|
||||
HighscoreAdapter adapter = new HighscoreAdapter(Conversion.strToInt(categoryCount, 2), Conversion.strToInt(categoryID, -1), getApplicationContext());
|
||||
listView.setAdapter(adapter);
|
||||
|
||||
setTitle(categoryName);
|
||||
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
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;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInitializedException;
|
||||
import de.hwr_berlin.it14.postgrachelor.Services.LoginService;
|
||||
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link LoginFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class LoginFragment extends Fragment {
|
||||
public static final String NAME = "LOGIN_FRAGMENT";
|
||||
|
||||
public LoginFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @return A new instance of fragment LoginFragment.
|
||||
*/
|
||||
public static LoginFragment newInstance() {
|
||||
LoginFragment fragment = new LoginFragment();
|
||||
Bundle args = new Bundle();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
View layout = inflater.inflate(R.layout.fragment_login, container, false);
|
||||
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
|
||||
public void onClick(View v) {
|
||||
Log.d(NAME, "Button click: "+login_edit.getText().toString());
|
||||
|
||||
try {
|
||||
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));
|
||||
}
|
||||
});
|
||||
login_edit.setText("");
|
||||
|
||||
return layout;
|
||||
}
|
||||
}
|
||||
@@ -1,64 +1,219 @@
|
||||
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.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.view.View;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
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;
|
||||
|
||||
public class MainActivity extends AppCompatActivity
|
||||
implements NavigationView.OnNavigationItemSelectedListener {
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInitializedException;
|
||||
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 final HashMap<String, ProgressDialog> dialogs = new HashMap<>();
|
||||
private Menu menu;
|
||||
private boolean isSaved = true;
|
||||
private final SparseBooleanArray menuStates = new SparseBooleanArray();
|
||||
|
||||
@Override
|
||||
public String showDialog() {
|
||||
ProgressDialog pDialog = new ProgressDialog(this);
|
||||
pDialog.setMessage(this.getString(R.string.please_wait));
|
||||
pDialog.setCancelable(false);
|
||||
if (!this.isFinishing())
|
||||
pDialog.show();
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
this.dialogs.put(uuid, pDialog);
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void errorJsonParsing() {
|
||||
Toast.makeText(this.getApplicationContext(),
|
||||
"Couldn't get json from server. Check LogCat for possible errors!",
|
||||
Toast.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void errorJsonLoadingFailed(String message) {
|
||||
Toast.makeText(this.getApplicationContext(),
|
||||
"Json parsing error: " + message,
|
||||
Toast.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideDialog(String uuid) {
|
||||
if (dialogs.containsKey(uuid)) {
|
||||
ProgressDialog dialog = dialogs.get(uuid);
|
||||
if (dialog != null && dialog.isShowing()) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class FragmentState {
|
||||
private static final int LOGIN = 0x1;
|
||||
private static final int MAIN = 0x2;
|
||||
private static final int QUESTION_END = 0x4;
|
||||
private static final int QUESTION = 0x8;
|
||||
}
|
||||
|
||||
private static final String NAME = "MainActivity";
|
||||
private int fragmentState = 0;
|
||||
private FragmentManager myFragmentManager;
|
||||
private MainFragment mainFragment;
|
||||
private LoginFragment loginFragment;
|
||||
private QuestionEndFragment questionEndFragment;
|
||||
private QuestionFragment questionFragment;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.isSaved = false;
|
||||
|
||||
Log.d(NAME, "create");
|
||||
setContentView(R.layout.activity_main);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
}
|
||||
});
|
||||
// content
|
||||
myFragmentManager = getFragmentManager();
|
||||
mainFragment = MainFragment.newInstance();
|
||||
loginFragment = LoginFragment.newInstance();
|
||||
questionEndFragment = QuestionEndFragment.newInstance();
|
||||
questionFragment = QuestionFragment.newInstance();
|
||||
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
drawer.setDrawerListener(toggle);
|
||||
toggle.syncState();
|
||||
|
||||
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
if (savedInstanceState != null) {
|
||||
this.selectFragment(savedInstanceState.getInt("selected fragment"));
|
||||
}
|
||||
|
||||
HighscoreService.initialize(this);
|
||||
LoginService.initialize(this);
|
||||
GameService.initialize(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
final MainActivity that = this;
|
||||
LoginService.addLoginEventListener(NAME, new LoginService.OnLoginEventListener() {
|
||||
@Override
|
||||
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(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(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) {
|
||||
that.selectFragment(FragmentState.QUESTION_END);
|
||||
} else if (state == StoredStates.PAUSED || state == StoredStates.END) {
|
||||
that.selectFragment(FragmentState.MAIN);
|
||||
}
|
||||
updateOptionMenu();
|
||||
}
|
||||
});
|
||||
|
||||
//this.selectFragment(this.fragmentState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
boolean success;
|
||||
try {
|
||||
success = GameService.pauseGame();
|
||||
} catch (NotInitializedException e) {
|
||||
success = false;
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!success)
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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
|
||||
@@ -68,34 +223,183 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@SuppressWarnings("StatementWithEmptyBody")
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem item) {
|
||||
// Handle navigation view item clicks here.
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.nav_camera) {
|
||||
// Handle the camera action
|
||||
} else if (id == R.id.nav_gallery) {
|
||||
|
||||
} else if (id == R.id.nav_slideshow) {
|
||||
|
||||
} else if (id == R.id.nav_manage) {
|
||||
|
||||
} else if (id == R.id.nav_share) {
|
||||
|
||||
} else if (id == R.id.nav_send) {
|
||||
private void selectFragment(int item) {
|
||||
if (this.isSaved)
|
||||
return;
|
||||
|
||||
boolean isLoggedIn = LoginService.isLoggedIn();
|
||||
if (!isLoggedIn) {
|
||||
item = FragmentState.LOGIN;
|
||||
} else if (item == FragmentState.LOGIN) {
|
||||
item = FragmentState.MAIN;
|
||||
}
|
||||
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
return true;
|
||||
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) {
|
||||
// Handle the camera action
|
||||
LoginFragment fragment = (LoginFragment) myFragmentManager.findFragmentByTag(LoginFragment.NAME);
|
||||
if (fragment == null) {
|
||||
FragmentTransaction fragmentTransaction = myFragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.relative_content, loginFragment, LoginFragment.NAME);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
} else if (item == FragmentState.MAIN) {
|
||||
MainFragment fragment = (MainFragment) myFragmentManager.findFragmentByTag(MainFragment.NAME);
|
||||
if (fragment == null) {
|
||||
FragmentTransaction fragmentTransaction = myFragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.relative_content, mainFragment, MainFragment.NAME);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
if (change) {
|
||||
try {
|
||||
HighscoreService.updateHighscores();
|
||||
} catch (NotInitializedException | NotLoggedInException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else if (item == FragmentState.QUESTION_END) {
|
||||
QuestionEndFragment fragment = (QuestionEndFragment) myFragmentManager.findFragmentByTag(QuestionEndFragment.NAME);
|
||||
if (fragment == null) {
|
||||
FragmentTransaction fragmentTransaction = myFragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.relative_content, questionEndFragment, QuestionEndFragment.NAME);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
} else if (item == FragmentState.QUESTION) {
|
||||
QuestionFragment fragment = (QuestionFragment) myFragmentManager.findFragmentByTag(QuestionFragment.NAME);
|
||||
if (fragment == null) {
|
||||
FragmentTransaction fragmentTransaction = myFragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.relative_content, questionFragment, QuestionFragment.NAME);
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Set<String> keys = dialogs.keySet();
|
||||
for (String key: keys) {
|
||||
ProgressDialog dialog = dialogs.get(key);
|
||||
if (dialog != null && dialog.isShowing()) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
//dialogs.put(key, null);
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
package de.hwr_berlin.it14.postgrachelor;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.GridLayout;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInitializedException;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link MainFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class MainFragment extends Fragment {
|
||||
public static final String NAME = "MAIN_FRAGMENT";
|
||||
private boolean listenersRegistered;
|
||||
|
||||
public MainFragment() {
|
||||
// Required empty public constructor
|
||||
this.listenersRegistered = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @return A new instance of fragment MainFragment.
|
||||
*/
|
||||
public static MainFragment newInstance() {
|
||||
Log.d(NAME, "newInstance");
|
||||
MainFragment fragment = new MainFragment();
|
||||
Bundle args = new Bundle();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
Log.d(NAME, "onCreateView "+this.listenersRegistered);
|
||||
final View view = inflater.inflate(R.layout.fragment_main, container, false);
|
||||
final View.OnClickListener categoryClick= new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getActivity(), HighscoreActivity.class);
|
||||
intent.putExtra("CategoryID", v.getTag(R.id.category_id).toString());
|
||||
intent.putExtra("CategoryName", v.getTag(R.id.category_name).toString());
|
||||
intent.putExtra("CategoryCount", v.getTag(R.id.category_count).toString());
|
||||
startActivity(intent);
|
||||
}
|
||||
};
|
||||
LoginService.addLoginEventListener(NAME, new LoginService.OnLoginEventListener() {
|
||||
@Override
|
||||
public void onLoginEvent(Login login) {
|
||||
TextView textView = (TextView) view.findViewById(R.id.fragment_main_status).findViewById(R.id.fragment_user_name);
|
||||
textView.setText(login.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogoutEvent(int status, String message) {
|
||||
}
|
||||
});
|
||||
HighscoreService.addHighscoreUpdateEventListener(new HighscoreService.OnHighscoreUpdateEventListener() {
|
||||
@Override
|
||||
public void onHighscoreUpdateEvent(Highscores scores) {
|
||||
|
||||
Log.d(NAME, "onHighscoreUpdate");
|
||||
TextView userStatusTextViewScore = (TextView) view.findViewById(R.id.fragment_main_status).findViewById(R.id.fragment_user_score);
|
||||
ProgressBar userStatusProgressBar = (ProgressBar) view.findViewById(R.id.fragment_main_status).findViewById(R.id.progressBarStatus);
|
||||
GridLayout gridLayoutCategories = (GridLayout) view.findViewById(R.id.fragment_main_categories);
|
||||
|
||||
|
||||
View categoryView;
|
||||
GridLayout.LayoutParams param;
|
||||
|
||||
gridLayoutCategories.removeAllViews();
|
||||
|
||||
if (scores == null) {
|
||||
userStatusTextViewScore.setText("0");
|
||||
userStatusProgressBar.setMax(1);
|
||||
userStatusProgressBar.setProgress(0);
|
||||
|
||||
TextView textView;
|
||||
textView = new TextView(view.getContext());
|
||||
textView.setText(R.string.no_highscores_available);
|
||||
textView.setTextColor(ContextCompat.getColor(view.getContext(), R.color.colorPrimaryDark));
|
||||
|
||||
gridLayoutCategories.addView(textView);
|
||||
param = new GridLayout.LayoutParams(GridLayout.spec(GridLayout.UNDEFINED, 1f), GridLayout.spec(GridLayout.UNDEFINED, 1f));
|
||||
param.width = 0;
|
||||
textView.setLayoutParams(param);
|
||||
|
||||
} else {
|
||||
Iterator<HighscoresCategories> iterator = scores.getCategoryIterator();
|
||||
ProgressBar catProgress;
|
||||
TextView textView;
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
HighscoresCategories category = iterator.next();
|
||||
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());
|
||||
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);
|
||||
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);
|
||||
catProgress.setMax(scores.getAll());
|
||||
catProgress.setProgress(scores.getAll() - category.getPlace() + 1);
|
||||
|
||||
gridLayoutCategories.addView(categoryView);
|
||||
param = new GridLayout.LayoutParams(GridLayout.spec(GridLayout.UNDEFINED, 1f), GridLayout.spec(GridLayout.UNDEFINED, 1f));
|
||||
param.width = 0;
|
||||
categoryView.setLayoutParams(param);
|
||||
}
|
||||
|
||||
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);
|
||||
userStatusProgressBar.setTag(R.id.category_name, view.getResources().getString(R.string.app_name));
|
||||
userStatusProgressBar.setTag(R.id.category_count, scores.getAll());
|
||||
userStatusProgressBar.setOnClickListener(categoryClick);
|
||||
}
|
||||
}
|
||||
});
|
||||
GameService.addGameStateChangeEventListener(NAME, new GameService.OnGameStateChangeEventListener() {
|
||||
@Override
|
||||
public void onGameStateChangeEvent(int previous, int state) {
|
||||
Log.d(NAME, "onGameStateChangeEvent");
|
||||
|
||||
View userGameBackground = view.findViewById(R.id.fragment_main_game).findViewById(R.id.background);
|
||||
TextView userGameTextView = (TextView) view.findViewById(R.id.fragment_main_game).findViewById(R.id.title);
|
||||
ImageButton userStatusImage = (ImageButton) view.findViewById(R.id.fragment_main_game).findViewById(R.id.image_btn);
|
||||
if (state == StoredStates.END || state == StoredStates.UNINITIALIZED) {
|
||||
userGameBackground.setBackgroundResource(android.R.color.holo_green_dark);
|
||||
userGameTextView.setText(R.string.start_test);
|
||||
userStatusImage.setImageResource(android.R.drawable.ic_media_play);
|
||||
} else {
|
||||
userGameBackground.setBackgroundResource(android.R.color.holo_orange_dark);
|
||||
userGameTextView.setText(R.string.resume_test);
|
||||
userStatusImage.setImageResource(android.R.drawable.ic_media_pause);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.listenersRegistered = true;
|
||||
// Inflate the layout for this fragment
|
||||
|
||||
View fragmentMainGameView = view.findViewById(R.id.fragment_main_game);
|
||||
fragmentMainGameView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
try {
|
||||
int state = GameService.getState().getState();
|
||||
Log.d(NAME, "Game click: "+state);
|
||||
if (state == StoredStates.END || state == StoredStates.UNINITIALIZED) {
|
||||
GameService.startGame();
|
||||
} else {
|
||||
GameService.resumeGame();
|
||||
}
|
||||
} catch (NotInitializedException | NotLoggedInException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Lookup the swipe container view
|
||||
final SwipeRefreshLayout swipeContainer = (SwipeRefreshLayout) view.findViewById(R.id.swipeContainer);
|
||||
// Setup refresh listener which triggers new data loading
|
||||
swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
try {
|
||||
HighscoreService.updateHighscores(new JsonRequestPG.AsyncResponse() {
|
||||
@Override
|
||||
public void processFinish(JSONObject data) {
|
||||
swipeContainer.setRefreshing(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processError(int status, String message) {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (NotInitializedException ignored) {
|
||||
} catch (NotLoggedInException e) {
|
||||
try {
|
||||
LoginService.doLogout(15999, "Not logged in");
|
||||
} catch (NotInitializedException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// Configure the refreshing colors
|
||||
swipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
|
||||
android.R.color.holo_green_light,
|
||||
android.R.color.holo_orange_light,
|
||||
android.R.color.holo_red_light);
|
||||
|
||||
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package de.hwr_berlin.it14.postgrachelor;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
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.Utils.Conversion;
|
||||
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link QuestionEndFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class QuestionEndFragment extends Fragment {
|
||||
public static final String NAME = "QUESTION_END_FRAGMENT";
|
||||
|
||||
public QuestionEndFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
* @return A new instance of fragment QuestionEndFragment.
|
||||
*/
|
||||
public static QuestionEndFragment newInstance() {
|
||||
QuestionEndFragment fragment = new QuestionEndFragment();
|
||||
Bundle args = new Bundle();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
final View view = inflater.inflate(R.layout.fragment_question_end, container, false);
|
||||
|
||||
Button btn = (Button) view.findViewById(R.id.returnBtn);
|
||||
btn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
try {
|
||||
GameService.endGame();
|
||||
} catch (NotInitializedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
GameService.addGameEndEventListener(NAME, new GameService.OnGameEndEventListener() {
|
||||
@Override
|
||||
public void onGameEndEvent(Scores scores) {
|
||||
Log.d(NAME, "onGameEndEvent" + scores);
|
||||
if (scores != null) {
|
||||
TextView textView = (TextView) view.findViewById(R.id.textViewScore);
|
||||
textView.setText(String.format(Locale.getDefault(), "%1$d", scores.getScore()));
|
||||
|
||||
textView = (TextView) view.findViewById(R.id.textViewTime);
|
||||
textView.setText(Conversion.millisToTime(scores.getTime()));
|
||||
} else {
|
||||
TextView textView = (TextView) view.findViewById(R.id.textViewScore);
|
||||
textView.setText(R.string.no_score);
|
||||
|
||||
textView = (TextView) view.findViewById(R.id.textViewTime);
|
||||
textView.setText(R.string.no_time);
|
||||
}
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package de.hwr_berlin.it14.postgrachelor;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import de.hwr_berlin.it14.postgrachelor.Exceptions.NoCurrentQuestionException;
|
||||
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInitializedException;
|
||||
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotLoggedInException;
|
||||
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.Timings;
|
||||
import de.hwr_berlin.it14.postgrachelor.Utils.Conversion;
|
||||
import de.hwr_berlin.it14.postgrachelor.Utils.ReverseInterpolator;
|
||||
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link QuestionFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class QuestionFragment extends Fragment {
|
||||
public static final String NAME = "QUESTION_FRAGMENT";
|
||||
|
||||
public QuestionFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @return A new instance of fragment QuestionFragment.
|
||||
*/
|
||||
public static QuestionFragment newInstance() {
|
||||
QuestionFragment fragment = new QuestionFragment();
|
||||
Bundle args = new Bundle();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
Log.d(NAME, "onCreateView");
|
||||
final View view = inflater.inflate(R.layout.fragment_question, container, false);
|
||||
View layout = view.findViewById(R.id.layout_fragment_question);
|
||||
|
||||
final TextView questionTitleView = (TextView) view.findViewById(R.id.questionTitle);
|
||||
final TextView questionCategoryView = (TextView) view.findViewById(R.id.questionCategory);
|
||||
|
||||
final TextView totalView = (TextView) view.findViewById(R.id.questionTotal);
|
||||
final TextView timeView = (TextView) view.findViewById(R.id.questionTime);
|
||||
final TextView scoreView = (TextView) view.findViewById(R.id.questionScore);
|
||||
|
||||
final Button[] questionAnswerViews = {
|
||||
(Button) view.findViewById(R.id.questionAnswer0),
|
||||
(Button) view.findViewById(R.id.questionAnswer1),
|
||||
(Button) view.findViewById(R.id.questionAnswer2),
|
||||
(Button) view.findViewById(R.id.questionAnswer3)
|
||||
};
|
||||
// Inflate the layout for this fragment
|
||||
layout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (GameService.isNextNeeded())
|
||||
try {
|
||||
GameService.runNext();
|
||||
} catch (NotInitializedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
questionAnswerViews[i].setTag(i);
|
||||
questionAnswerViews[i].setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (GameService.isNextNeeded()) {
|
||||
try {
|
||||
GameService.runNext();
|
||||
} catch (NotInitializedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (GameService.getState().getState() != StoredStates.ON_HOLD_RESULT) {
|
||||
try {
|
||||
GameService.answer((int) v.getTag());
|
||||
} catch (NotInitializedException | NotLoggedInException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoCurrentQuestionException e) {
|
||||
GameService.haltGame();
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
GameService.haltGame();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Context context = getActivity().getApplicationContext();
|
||||
final int colorBgFalse = ContextCompat.getColor(context, android.R.color.holo_red_dark);
|
||||
final int colorBgClicked = ContextCompat.getColor(context, android.R.color.holo_orange_dark);
|
||||
final int colorBg = ContextCompat.getColor(context, android.R.color.holo_green_dark);
|
||||
final int colorText = ContextCompat.getColor(context, android.R.color.black);
|
||||
final Animation animation = AnimationUtils.loadAnimation(context, R.anim.scale_up);
|
||||
|
||||
GameService.addTickEventListener(NAME, new GameService.OnTickEventListener() {
|
||||
@Override
|
||||
public void onTickEvent(Timings timings) {
|
||||
if (timings != null) {
|
||||
timeView.setText(Conversion.millisToTime(timings.getTimeDiff()));
|
||||
scoreView.setText(String.format(Locale.getDefault(), "%1d", timings.getScore()));
|
||||
}
|
||||
}
|
||||
});
|
||||
GameService.addQuestionUpdateEventListener(NAME, new GameService.OnQuestionUpdateEventListener() {
|
||||
@Override
|
||||
public void onQuestionUpdateEvent(Question question, int answer, Result result) {
|
||||
Log.d(NAME, "onQuestionUpdateEvent - question: " + question);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
questionAnswerViews[i].setBackgroundColor(
|
||||
ContextCompat.getColor(view.getContext(), R.color.colorPrimary)
|
||||
);
|
||||
questionAnswerViews[i].setTextColor(
|
||||
ContextCompat.getColor(view.getContext(), android.R.color.white)
|
||||
);
|
||||
}
|
||||
|
||||
if (question != null) {
|
||||
questionTitleView.setText(question.getQuestion());
|
||||
questionCategoryView.setText(view.getContext().getResources().getString(R.string.category, question.getCategory()));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
questionAnswerViews[i].setText(question.getAnswers()[i]);
|
||||
}
|
||||
} else {
|
||||
questionTitleView.setText("");
|
||||
questionCategoryView.setText(R.string.no_question_available);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
questionAnswerViews[i].setText("");
|
||||
}
|
||||
}
|
||||
|
||||
if (answer != -1 && result != null) {
|
||||
questionAnswerViews[answer].setBackgroundColor(colorBgFalse);
|
||||
} else if (answer != -1) {
|
||||
questionAnswerViews[answer].setBackgroundColor(colorBgClicked);
|
||||
}
|
||||
|
||||
if (result != null && result.getCorrectPos()>=0 && result.getCorrectPos()<=3) {
|
||||
questionAnswerViews[result.getCorrectPos()].setBackgroundColor(colorBg);
|
||||
questionAnswerViews[result.getCorrectPos()].setTextColor(colorText);
|
||||
totalView.setText(Conversion.intToStr(result.getTotal()));
|
||||
scoreView.setText(Conversion.intToStr(result.getScore()));
|
||||
|
||||
if (result.isCorrect()) {
|
||||
animation.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator()));
|
||||
totalView.startAnimation(animation);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
GameService.addGameStateChangeEventListener(NAME, new GameService.OnGameStateChangeEventListener() {
|
||||
@Override
|
||||
public void onGameStateChangeEvent(int previous, int state) {
|
||||
Log.d(NAME, Conversion.intToStr(previous, 5)+Conversion.intToStr(state,5));
|
||||
if (previous != StoredStates.ON_HOLD_RESULT && state == StoredStates.RUNNING)
|
||||
totalView.setText(R.string._0);
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,538 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Services;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import de.hwr_berlin.it14.postgrachelor.Exceptions.NoCurrentQuestionException;
|
||||
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInitializedException;
|
||||
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotLoggedInException;
|
||||
import de.hwr_berlin.it14.postgrachelor.Types.Scores;
|
||||
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;
|
||||
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.JsonRequestPG;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 27.03.2017.
|
||||
* Game service controls game flow
|
||||
*/
|
||||
|
||||
public class GameService {
|
||||
private static final int GAME_TICK_INTERVAL = 100;
|
||||
private static final String NAME = "SERVICE_GAME";
|
||||
private static final String PREFS_NAME = "PrefsGame";
|
||||
|
||||
|
||||
private static StoredStates states = null;
|
||||
private static StoredTimings timings = null;
|
||||
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 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<>();
|
||||
private static final HashMap<String, OnPrefsUpdateEventListener> prefsUpdateEventListeners = new HashMap<>();
|
||||
|
||||
public interface OnGameStateChangeEventListener {
|
||||
void onGameStateChangeEvent(int previous, int state);
|
||||
}
|
||||
public interface OnQuestionUpdateEventListener {
|
||||
void onQuestionUpdateEvent(Question question, int answer, Result result);
|
||||
}
|
||||
public interface OnGameEndEventListener {
|
||||
void onGameEndEvent(Scores scores);
|
||||
}
|
||||
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;
|
||||
SharedPreferences settings = activity.getSharedPreferences(GameService.PREFS_NAME, 0);
|
||||
GameService.initialized = true;
|
||||
|
||||
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();
|
||||
|
||||
emitTickEvent();
|
||||
emitQuestionUpdateEvent();
|
||||
emitGameEndEvent();
|
||||
emitGameStateChangeEvent();
|
||||
emitPrefsUpdateEvent();
|
||||
}
|
||||
|
||||
public static void addGameStateChangeEventListener(String key, OnGameStateChangeEventListener listener) {
|
||||
gameStateChangeEventListeners.put(key, listener);
|
||||
if (GameService.initialized) {
|
||||
States states = GameService.getState();
|
||||
listener.onGameStateChangeEvent(states.getPrevious(), states.getState());
|
||||
}
|
||||
}
|
||||
|
||||
private static void emitGameStateChangeEvent() {
|
||||
if (GameService.initialized) {
|
||||
States states = GameService.getState();
|
||||
for (OnGameStateChangeEventListener listener: gameStateChangeEventListeners.values()) {
|
||||
listener.onGameStateChangeEvent(states.getPrevious(), states.getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addQuestionUpdateEventListener(String key, OnQuestionUpdateEventListener listener) {
|
||||
questionUpdateEventListeners.put(key, listener);
|
||||
if (GameService.initialized)
|
||||
listener.onQuestionUpdateEvent(GameService.getQuestion(), GameService.getAnswer(), GameService.getResult());
|
||||
}
|
||||
|
||||
private static void emitQuestionUpdateEvent() {
|
||||
for (OnQuestionUpdateEventListener listener: questionUpdateEventListeners.values()) {
|
||||
listener.onQuestionUpdateEvent(GameService.getQuestion(), GameService.getAnswer(), GameService.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
public static void addGameEndEventListener(String key, OnGameEndEventListener onGameEndEventListener) {
|
||||
gameEndEventListeners.put(key, onGameEndEventListener);
|
||||
if (GameService.initialized)
|
||||
onGameEndEventListener.onGameEndEvent(GameService.getScores());
|
||||
}
|
||||
|
||||
private static void emitGameEndEvent() {
|
||||
for (OnGameEndEventListener listener: gameEndEventListeners.values()) {
|
||||
listener.onGameEndEvent(GameService.getScores());
|
||||
}
|
||||
}
|
||||
|
||||
public static void addTickEventListener(String key, OnTickEventListener onTickEventListener) {
|
||||
gameTickEventListeners.put(key, onTickEventListener);
|
||||
onTickEventListener.onTickEvent(GameService.getTimings());
|
||||
}
|
||||
|
||||
private static void emitTickEvent() {
|
||||
for (OnTickEventListener listener: gameTickEventListeners.values()) {
|
||||
listener.onTickEvent(GameService.getTimings());
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
GameService.timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
GameService.activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
emitTickEvent();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 0, GameService.GAME_TICK_INTERVAL);
|
||||
}
|
||||
|
||||
private static void stopTimer() {
|
||||
if (GameService.timer != null) {
|
||||
GameService.timer.cancel();
|
||||
GameService.timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
// GETTER
|
||||
|
||||
private static Timings getTimings() {
|
||||
return GameService.timings.get();
|
||||
}
|
||||
|
||||
private static Scores getScores() {
|
||||
return GameService.scores.get();
|
||||
}
|
||||
|
||||
public static States getState() {
|
||||
if (!GameService.initialized)
|
||||
return new States(StoredStates.END, StoredStates.END);
|
||||
return GameService.states.get();
|
||||
}
|
||||
|
||||
private static Question getQuestion() {
|
||||
return GameService.question.getQuestion();
|
||||
}
|
||||
|
||||
private static Result getResult() {
|
||||
return GameService.question.getResult();
|
||||
}
|
||||
|
||||
private static int getAnswer() {
|
||||
return GameService.question.getAnswer();
|
||||
}
|
||||
|
||||
private static Question getNeededNext() {
|
||||
return GameService.next.getNext();
|
||||
}
|
||||
|
||||
private static Scores getNeededEnd() {
|
||||
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() {
|
||||
GameService.timings.start();
|
||||
}
|
||||
|
||||
private static void stopTimings() {
|
||||
GameService.timings.stop();
|
||||
}
|
||||
|
||||
private static void setNeededNext(Question question) {
|
||||
GameService.next.setNext(question);
|
||||
}
|
||||
|
||||
private static void setNeededEnd(Scores scores) {
|
||||
GameService.next.setEnd(scores);
|
||||
}
|
||||
|
||||
// REMOVERS
|
||||
|
||||
private static void resetTimings() {
|
||||
GameService.timings.reset();
|
||||
}
|
||||
|
||||
private static void unsetQuestion() {
|
||||
GameService.question.remove();
|
||||
}
|
||||
|
||||
private static void unsetScores() {
|
||||
GameService.scores.remove();
|
||||
}
|
||||
|
||||
private static void unsetNext() {
|
||||
GameService.next.remove();
|
||||
}
|
||||
|
||||
//END
|
||||
|
||||
public static boolean pauseGame() throws NotInitializedException {
|
||||
if (!GameService.initialized)
|
||||
throw new NotInitializedException();
|
||||
|
||||
int state = GameService.getState().getState();
|
||||
if (state == StoredStates.RUNNING || state == StoredStates.ON_HOLD_LOADING || state == StoredStates.ON_HOLD_RESULT) {
|
||||
GameService.setState(StoredStates.PAUSED);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void resumeGame() throws NotInitializedException {
|
||||
if (!GameService.initialized)
|
||||
throw new NotInitializedException();
|
||||
|
||||
int state = GameService.getState().getState();
|
||||
if (state == StoredStates.PAUSED)
|
||||
GameService.setState(GameService.getState().getPrevious());
|
||||
}
|
||||
|
||||
public static void endGame() throws NotInitializedException {
|
||||
if (!GameService.initialized)
|
||||
throw new NotInitializedException();
|
||||
|
||||
GameService.setState(StoredStates.END);
|
||||
GameService.unsetQuestion();
|
||||
GameService.unsetScores();
|
||||
GameService.unsetNext();
|
||||
GameService.resetTimings();
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
throw new NoCurrentQuestionException();
|
||||
}
|
||||
|
||||
GameService.stopTimings();
|
||||
GameService.setAnswer(id);
|
||||
GameService.setState(StoredStates.ON_HOLD_LOADING);
|
||||
|
||||
if (GameService.getAnswer()==-1)
|
||||
throw new NoCurrentQuestionException();
|
||||
|
||||
final String currentToken = GameService.getQuestion().getToken();
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("answer", Conversion.intToStr(GameService.getAnswer()));
|
||||
params.put("uid", LoginService.getLogin().getUID());
|
||||
params.put("token", currentToken);
|
||||
params.put("time", String.valueOf(GameService.getTimings().getTimeDiff()));
|
||||
Log.d("GameServiceFragment", "answer/processFinish - before");
|
||||
JsonRequestPG requester = new JsonRequestPG("answer.php", params, /*activity*/null, new JsonRequestPG.AsyncResponse() {
|
||||
@Override
|
||||
public void processFinish(final JSONObject data) {
|
||||
Log.d("GameServiceFragment", "answer/processFinish - " + data.toString());
|
||||
JSONObject data_result = data.optJSONObject("results");
|
||||
if (data_result == null) {
|
||||
if (GameService.getState().getState()==StoredStates.ON_HOLD_LOADING && GameService.getQuestion()!=null && GameService.getQuestion().getToken().equals(currentToken))
|
||||
try {
|
||||
GameService.endGame();
|
||||
} catch (NotInitializedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return; // token already used -> ignore
|
||||
}
|
||||
|
||||
Result result = new Result(
|
||||
data_result.optBoolean("correct", false),
|
||||
data_result.optInt("score", 0),
|
||||
data_result.optInt("correctPos", 0),
|
||||
data_result.optInt("total", 0)
|
||||
);
|
||||
GameService.setResult(result);
|
||||
|
||||
JSONObject data_next = data.optJSONObject("next");
|
||||
if (data_next != null) {
|
||||
Question question = parseQuestion(data_next);
|
||||
GameService.setNeededNext(question);
|
||||
}
|
||||
|
||||
JSONObject data_end = data.optJSONObject("end");
|
||||
if (data_end != null) {
|
||||
Scores scores = parseScores(data_end);
|
||||
GameService.setNeededEnd(scores);
|
||||
}
|
||||
|
||||
GameService.setState(StoredStates.ON_HOLD_RESULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processError(int status, String message) {
|
||||
Log.d("GameServiceFragment", "answer/processError "+status+" "+message);
|
||||
if (status==13104 || status==13102)
|
||||
try {
|
||||
GameService.endGame();
|
||||
} catch (NotInitializedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
requester.execute();
|
||||
}
|
||||
|
||||
public static void startGame() throws NotInitializedException, NotLoggedInException {
|
||||
if (!GameService.initialized)
|
||||
throw new NotInitializedException();
|
||||
if (!LoginService.isLoggedIn())
|
||||
throw new NotLoggedInException();
|
||||
|
||||
GameService.unsetNext();
|
||||
GameService.unsetScores();
|
||||
GameService.unsetQuestion();
|
||||
GameService.resetTimings();
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
String uid;
|
||||
uid = LoginService.getLogin().getUID();
|
||||
params.put("uid", uid);
|
||||
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) {
|
||||
JSONObject data_next = data.optJSONObject("next");
|
||||
if (data_next != null) {
|
||||
Question question = GameService.parseQuestion(data_next);
|
||||
GameService.setQuestion(question);
|
||||
} else {
|
||||
GameService.setState(StoredStates.END);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processError(int status, String message) {
|
||||
GameService.setState(StoredStates.END);
|
||||
if (status==12104) { // user uid not found
|
||||
try {
|
||||
LoginService.doLogout(status, message);
|
||||
} catch (NotInitializedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
requester.execute();
|
||||
}
|
||||
|
||||
public static void runNext() throws IllegalStateException, NotInitializedException {
|
||||
if (!GameService.initialized)
|
||||
throw new NotInitializedException();
|
||||
if (!GameService.isNextNeeded())
|
||||
GameService.endGame();
|
||||
|
||||
Question question = GameService.getNeededNext();
|
||||
Scores scores = GameService.getNeededEnd();
|
||||
if (question != null) {
|
||||
GameService.setQuestion(question);
|
||||
} else if (scores != null) {
|
||||
GameService.setScores(scores);
|
||||
} else {
|
||||
GameService.haltGame();
|
||||
}
|
||||
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);
|
||||
GameService.startTimings();
|
||||
GameService.setState(StoredStates.RUNNING);
|
||||
GameService.emitQuestionUpdateEvent();
|
||||
}
|
||||
|
||||
private static void setState(int state) {
|
||||
GameService.states.nextState(state);
|
||||
|
||||
if (GameService.getState().getState() != StoredStates.RUNNING)
|
||||
GameService.stopTimer();
|
||||
GameService.emitGameStateChangeEvent();
|
||||
if (GameService.getState().getState() == StoredStates.RUNNING)
|
||||
GameService.startTimer();
|
||||
}
|
||||
|
||||
private static void setResult(Result result) {
|
||||
GameService.question.setResult(result);
|
||||
GameService.emitQuestionUpdateEvent();
|
||||
}
|
||||
|
||||
private static void setScores(Scores scores) {
|
||||
GameService.scores.set(scores);
|
||||
GameService.setState(StoredStates.END);
|
||||
GameService.emitGameEndEvent();
|
||||
}
|
||||
|
||||
private static void setAnswer(int id) {
|
||||
GameService.question.setAnswer(id);
|
||||
GameService.emitQuestionUpdateEvent();
|
||||
}
|
||||
|
||||
private static Question parseQuestion(JSONObject data_next) {
|
||||
JSONArray data_next_arr = data_next.optJSONArray("answers");
|
||||
return new Question(
|
||||
data_next.optString("categoryName", ""),
|
||||
data_next.optInt("categoryID", 0),
|
||||
data_next.optString("token", ""),
|
||||
data_next.optString("question", ""),
|
||||
new String[]{
|
||||
data_next_arr.optString(0, ""),
|
||||
data_next_arr.optString(1, ""),
|
||||
data_next_arr.optString(2, ""),
|
||||
data_next_arr.optString(3, "")
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private static Scores parseScores(JSONObject data_end) {
|
||||
return new Scores(
|
||||
data_end.optInt("score", 0),
|
||||
data_end.optInt("time", 0)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Services;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.Highscores;
|
||||
import de.hwr_berlin.it14.postgrachelor.Types.HighscoresUser;
|
||||
import de.hwr_berlin.it14.postgrachelor.Utils.Conversion;
|
||||
import de.hwr_berlin.it14.postgrachelor.Utils.JsonRequestPG;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 25.03.17.
|
||||
* Login service
|
||||
*/
|
||||
|
||||
public class HighscoreService {
|
||||
private static final String NAME = "HighscoreService";
|
||||
private static final long MIN_REFRESH_RATE = 1000;
|
||||
private static Highscores latestScores = null;
|
||||
private static boolean instantiated = false;
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static Activity activity = null;
|
||||
private static final ArrayList<OnHighscoreUpdateEventListener> highscoreUpdateEventListeners = new ArrayList<>();
|
||||
private static long lastUpdate = 0;
|
||||
|
||||
public interface OnHighscoreUpdateEventListener {
|
||||
void onHighscoreUpdateEvent(Highscores scores);
|
||||
}
|
||||
|
||||
public static void addHighscoreUpdateEventListener(OnHighscoreUpdateEventListener onLoginEventListener) {
|
||||
highscoreUpdateEventListeners.add(onLoginEventListener);
|
||||
onLoginEventListener.onHighscoreUpdateEvent(getLatestScores());
|
||||
}
|
||||
|
||||
private static void emitHighscoreUpdateEvent() {
|
||||
for (OnHighscoreUpdateEventListener listener: highscoreUpdateEventListeners) {
|
||||
listener.onHighscoreUpdateEvent(getLatestScores());
|
||||
}
|
||||
}
|
||||
|
||||
public static void initialize(Activity activity) {
|
||||
HighscoreService.activity = activity;
|
||||
instantiated = true;
|
||||
}
|
||||
|
||||
private static boolean available() {
|
||||
return (HighscoreService.latestScores != null);
|
||||
}
|
||||
|
||||
private static Highscores getLatestScores() {
|
||||
return HighscoreService.latestScores;
|
||||
}
|
||||
|
||||
private static void setLatestScores(Highscores scores) {
|
||||
latestScores = scores;
|
||||
emitHighscoreUpdateEvent();
|
||||
}
|
||||
|
||||
public static void updateHighscores() throws NotInitializedException, NotLoggedInException {
|
||||
HighscoreService.updateHighscores(null);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("uid", LoginService.getLogin().getUID());
|
||||
JsonRequestPG requester = new JsonRequestPG("highscores.php", params, /*activity*/null, new JsonRequestPG.AsyncResponse() {
|
||||
@Override
|
||||
public void processFinish(JSONObject output) {
|
||||
// never reached if not instantiated
|
||||
Highscores result = new Highscores(
|
||||
output.optInt("score", 0),
|
||||
output.optInt("place", 0),
|
||||
output.optInt("all", 1)
|
||||
);
|
||||
JSONArray array = output.optJSONArray("categories");
|
||||
if (array != null) {
|
||||
int max = array.length();
|
||||
for (int i = 0; i < max; i++) {
|
||||
try {
|
||||
JSONObject category = array.getJSONObject(i);
|
||||
result.addCategory(
|
||||
category.optInt("id", 0),
|
||||
category.optString("name", ""),
|
||||
category.optInt("score", 0),
|
||||
category.optInt("place", 0)
|
||||
);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
setLatestScores(result);
|
||||
|
||||
if (asyncResponse != null) {
|
||||
asyncResponse.processFinish(output);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processError(int status, String message) {
|
||||
setLatestScores(null);
|
||||
if (status==15102) { // user uid not found
|
||||
try {
|
||||
LoginService.doLogout(status, message);
|
||||
} catch (NotInitializedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (asyncResponse != null) {
|
||||
asyncResponse.processError(status, message);
|
||||
}
|
||||
}
|
||||
});
|
||||
requester.execute();
|
||||
}
|
||||
|
||||
public static ArrayList<HighscoresUser> getHighscoreDetailsSync(final int limit, int offset, int category, final JsonRequestPG.AsyncResponse asyncResponse) {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
if (limit >= 0)
|
||||
params.put("limit", Conversion.intToStr(limit));
|
||||
if (offset >= 0)
|
||||
params.put("offset", Conversion.intToStr(offset));
|
||||
if (category >= 0)
|
||||
params.put("category", Conversion.intToStr(category));
|
||||
final ArrayList<HighscoresUser> highscoresUsers = new ArrayList<>();
|
||||
JsonRequestPG requester = new JsonRequestPG("allhighscores.php", params, activity, new JsonRequestPG.AsyncResponse() {
|
||||
@Override
|
||||
public void processFinish(JSONObject output) {
|
||||
if (output != null) {
|
||||
JSONArray array = output.optJSONArray("array");
|
||||
if (array != null) {
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
JSONObject objectItem = array.optJSONObject(i);
|
||||
if (objectItem != null) {
|
||||
highscoresUsers.add(new HighscoresUser(
|
||||
objectItem.optString("name", "A Random User"),
|
||||
objectItem.optInt("score"),
|
||||
objectItem.optInt("place")
|
||||
));
|
||||
} else {
|
||||
highscoresUsers.add(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (asyncResponse != null) {
|
||||
asyncResponse.processFinish(output);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processError(int status, String message) {
|
||||
if (asyncResponse != null) {
|
||||
asyncResponse.processError(status, message);
|
||||
}
|
||||
}
|
||||
});
|
||||
requester.executeSync();
|
||||
return highscoresUsers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Services;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import de.hwr_berlin.it14.postgrachelor.Exceptions.NotInitializedException;
|
||||
import de.hwr_berlin.it14.postgrachelor.Types.Login;
|
||||
import de.hwr_berlin.it14.postgrachelor.Types.StoredLogin;
|
||||
import de.hwr_berlin.it14.postgrachelor.Utils.JsonRequestPG;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 25.03.17.
|
||||
* Login service
|
||||
*/
|
||||
|
||||
public class LoginService {
|
||||
private static final String PREFS_NAME = "PrefsLogin";
|
||||
private static final String NAME = "SERVICE_LOGIN";
|
||||
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<>();
|
||||
private static long lastStateChange = 0;
|
||||
|
||||
public interface OnLoginEventListener {
|
||||
void onLoginEvent(Login login);
|
||||
void onLogoutEvent(int status, String message);
|
||||
}
|
||||
|
||||
public static void addLoginEventListener(String key, OnLoginEventListener onLoginEventListener) {
|
||||
loginEventListeners.put(key, onLoginEventListener);
|
||||
if (isLoggedIn()) {
|
||||
onLoginEventListener.onLoginEvent(getLogin());
|
||||
}
|
||||
}
|
||||
|
||||
private static void emitLoginEvent() {
|
||||
for (OnLoginEventListener listener: loginEventListeners.values()) {
|
||||
listener.onLoginEvent(getLogin());
|
||||
}
|
||||
}
|
||||
|
||||
private static void emitLogoutEvent(int status, String message) {
|
||||
for (OnLoginEventListener listener: loginEventListeners.values()) {
|
||||
listener.onLogoutEvent(status, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initialize(Activity activity) {
|
||||
SharedPreferences settings = activity.getSharedPreferences(PREFS_NAME, 0);
|
||||
LoginService.activity = activity;
|
||||
instantiated = true;
|
||||
|
||||
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() {
|
||||
return login != null && login.isLoaded();
|
||||
}
|
||||
|
||||
public static Login getLogin() {
|
||||
return login.get();
|
||||
}
|
||||
|
||||
private static void setLogin(Login user) {
|
||||
login.login(user);
|
||||
emitLoginEvent();
|
||||
}
|
||||
|
||||
private static void setLogout(int status, String message) {
|
||||
login.logout();
|
||||
emitLogoutEvent(status, message);
|
||||
}
|
||||
|
||||
public static void doRegister(String name) throws NotInitializedException {
|
||||
if (!instantiated)
|
||||
throw new NotInitializedException();
|
||||
|
||||
LoginService.lastStateChange = System.currentTimeMillis();
|
||||
final long time = LoginService.lastStateChange;
|
||||
|
||||
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) {
|
||||
if (time != LoginService.lastStateChange)
|
||||
return;
|
||||
|
||||
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) {
|
||||
if (time != LoginService.lastStateChange)
|
||||
return;
|
||||
|
||||
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();
|
||||
|
||||
LoginService.lastStateChange = System.currentTimeMillis();
|
||||
final long time = LoginService.lastStateChange;
|
||||
|
||||
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) {
|
||||
if (time != LoginService.lastStateChange)
|
||||
return;
|
||||
|
||||
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) {
|
||||
if (time != LoginService.lastStateChange)
|
||||
return;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
LoginService.lastStateChange = System.currentTimeMillis();
|
||||
|
||||
GameService.endGame();
|
||||
GameService.endGame();
|
||||
LoginService.setLogout(status, message);
|
||||
}
|
||||
|
||||
public static void doRename(String name) throws NotInitializedException {
|
||||
if (!instantiated)
|
||||
throw new NotInitializedException();
|
||||
|
||||
LoginService.lastStateChange = System.currentTimeMillis();
|
||||
final long time = LoginService.lastStateChange;
|
||||
|
||||
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) {
|
||||
if (time != LoginService.lastStateChange)
|
||||
return;
|
||||
|
||||
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) {
|
||||
if (time != LoginService.lastStateChange)
|
||||
return;
|
||||
|
||||
Log.d(NAME, "error");
|
||||
Log.d(NAME, "status: "+status+" - message: "+message);
|
||||
// never reached if not instantiated
|
||||
}
|
||||
});
|
||||
requester.execute();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 27.03.2017.
|
||||
* Contains all highscores
|
||||
*/
|
||||
|
||||
public class Highscores {
|
||||
private int score = 0;
|
||||
private int place = 0;
|
||||
private int all = 0;
|
||||
private final ArrayList<HighscoresCategories> categories;
|
||||
|
||||
public Highscores(int score, int place, int all) {
|
||||
this.score = score;
|
||||
this.place = place;
|
||||
this.all = all;
|
||||
this.categories = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addCategory(int id, String name, int score, int place) {
|
||||
this.categories.add(new HighscoresCategories(id, name, score, place));
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return this.score;
|
||||
}
|
||||
|
||||
public int getPlace() {
|
||||
return this.place;
|
||||
}
|
||||
|
||||
public int getAll() {
|
||||
return this.all;
|
||||
}
|
||||
|
||||
public Iterator<HighscoresCategories> getCategoryIterator() {
|
||||
return this.categories.iterator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 27.03.2017.
|
||||
* Statistics of a single category
|
||||
*/
|
||||
|
||||
public class HighscoresCategories {
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final int score;
|
||||
private final int place;
|
||||
|
||||
HighscoresCategories(int id, String name, int score, int place) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.score = score;
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return this.score;
|
||||
}
|
||||
|
||||
public int getPlace() {
|
||||
return this.place;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 11.04.2017.
|
||||
*/
|
||||
|
||||
public class HighscoresUser extends Requestable {
|
||||
private final String name;
|
||||
private final int score;
|
||||
private final int place;
|
||||
|
||||
public HighscoresUser(String name, int score, int place) {
|
||||
this.name = name;
|
||||
this.score = score;
|
||||
this.place = place;
|
||||
this.unrequested();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public int getPlace() {
|
||||
return place;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 30.03.2017.
|
||||
* Contains all data related to a question (question, answer, category)
|
||||
*/
|
||||
|
||||
public class Question {
|
||||
private final String category;
|
||||
private final int categoryID;
|
||||
private final String token;
|
||||
private final String question;
|
||||
private final String[] answers;
|
||||
|
||||
public Question(String category, int categoryID, String token, String question, String[] answers) {
|
||||
this.category = category;
|
||||
this.categoryID = categoryID;
|
||||
this.token = token;
|
||||
this.question = question;
|
||||
this.answers = answers;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
int getCategoryID() {
|
||||
return categoryID;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public String getQuestion() {
|
||||
return question;
|
||||
}
|
||||
|
||||
public String[] getAnswers() {
|
||||
return answers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 20.04.2017.
|
||||
*/
|
||||
|
||||
public interface RequestActivityInterface {
|
||||
String showDialog();
|
||||
void errorJsonParsing();
|
||||
void errorJsonLoadingFailed(String message);
|
||||
void hideDialog(String uuid);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 12.04.2017.
|
||||
*/
|
||||
|
||||
public class Requestable {
|
||||
private long requested;
|
||||
|
||||
public Requestable() {
|
||||
this.requested();
|
||||
}
|
||||
|
||||
public boolean isRequested() {
|
||||
return this.requested != 0;
|
||||
}
|
||||
|
||||
void unrequested() {
|
||||
this.requested = 0;
|
||||
}
|
||||
|
||||
private void requested() {
|
||||
this.requested = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 30.03.2017.
|
||||
* Contains statistics of answering the last question
|
||||
*/
|
||||
|
||||
public class Result {
|
||||
private final int score;
|
||||
private final int correctPos;
|
||||
private final int total;
|
||||
private final boolean correct;
|
||||
|
||||
public Result(boolean correct, int score, int correctPos, int total) {
|
||||
this.correct = correct;
|
||||
this.score = score;
|
||||
this.correctPos = correctPos;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public boolean isCorrect() {
|
||||
return correct;
|
||||
}
|
||||
|
||||
public int getCorrectPos() {
|
||||
return correctPos;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 22.04.2017.
|
||||
* Scores of a game
|
||||
*/
|
||||
|
||||
public class Scores {
|
||||
private final int score;
|
||||
private final int time;
|
||||
|
||||
public Scores(int score, int time) {
|
||||
this.score = score;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 23.04.2017.
|
||||
* Current and previous game state
|
||||
*/
|
||||
|
||||
public class States {
|
||||
private final int previous;
|
||||
private final int state;
|
||||
|
||||
public States(int previous, int state) {
|
||||
|
||||
this.previous = previous;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public int getPrevious() {
|
||||
return previous;
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 22.04.2017.
|
||||
* Stored next entity
|
||||
*/
|
||||
|
||||
public class StoredNextEntity extends StoredObject {
|
||||
private class Next extends StoredObject {
|
||||
|
||||
private static final String STR_CATEGORY = "category";
|
||||
private String category;
|
||||
private static final String STR_CATEGORY_ID = "categoryID";
|
||||
private int categoryID;
|
||||
private static final String STR_TOKEN = "token";
|
||||
private String token;
|
||||
private static final String STR_QUESTION = "question";
|
||||
private String question;
|
||||
private static final String STR_ANSWER0 = "answer0";
|
||||
private String answer0;
|
||||
private static final String STR_ANSWER1 = "answer1";
|
||||
private String answer1;
|
||||
private static final String STR_ANSWER2 = "answer2";
|
||||
private String answer2;
|
||||
private static final String STR_ANSWER3 = "answer3";
|
||||
private String answer3;
|
||||
|
||||
private Next(SharedPreferences prefs, String prefix) {
|
||||
super(prefs, prefix+".next");
|
||||
this.category = this.loadFromPref(STR_CATEGORY, "");
|
||||
this.categoryID = this.loadFromPref(STR_CATEGORY_ID, -1);
|
||||
this.token = this.loadFromPref(STR_TOKEN, "");
|
||||
this.question = this.loadFromPref(STR_QUESTION, "");
|
||||
this.answer0 = this.loadFromPref(STR_ANSWER0, "");
|
||||
this.answer1 = this.loadFromPref(STR_ANSWER1, "");
|
||||
this.answer2 = this.loadFromPref(STR_ANSWER2, "");
|
||||
this.answer3 = this.loadFromPref(STR_ANSWER3, "");
|
||||
}
|
||||
|
||||
private void set(Question question) {
|
||||
this.category = question.getCategory();
|
||||
this.saveToPref(STR_CATEGORY, this.category);
|
||||
this.categoryID = question.getCategoryID();
|
||||
this.saveToPref(STR_CATEGORY_ID, this.categoryID);
|
||||
this.token = question.getToken();
|
||||
this.saveToPref(STR_TOKEN, this.token);
|
||||
this.question = question.getQuestion();
|
||||
this.saveToPref(STR_QUESTION, this.question);
|
||||
this.answer0 = question.getAnswers()[0];
|
||||
this.saveToPref(STR_ANSWER0, this.answer0);
|
||||
this.answer1 = question.getAnswers()[1];
|
||||
this.saveToPref(STR_ANSWER1, this.answer1);
|
||||
this.answer2 = question.getAnswers()[2];
|
||||
this.saveToPref(STR_ANSWER2, this.answer2);
|
||||
this.answer3 = question.getAnswers()[3];
|
||||
this.saveToPref(STR_ANSWER3, this.answer3);
|
||||
this.unremove();
|
||||
}
|
||||
|
||||
public Question get() {
|
||||
if (!this.isLoaded())
|
||||
return null;
|
||||
return new Question(this.category, this.categoryID, this.token, this.question, new String[]{
|
||||
this.answer0,
|
||||
this.answer1,
|
||||
this.answer2,
|
||||
this.answer3
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private class End extends StoredObject {
|
||||
private static final String STR_SCORE = "score";
|
||||
private int score;
|
||||
private static final String STR_TIME = "time";
|
||||
private int time;
|
||||
|
||||
private End(SharedPreferences prefs, String prefix) {
|
||||
super(prefs, prefix+".end");
|
||||
this.score = this.loadFromPref(STR_SCORE, 0);
|
||||
this.time = this.loadFromPref(STR_TIME, 0);
|
||||
}
|
||||
|
||||
private void set(Scores scores) {
|
||||
this.score = scores.getScore();
|
||||
this.saveToPref(STR_SCORE, this.score);
|
||||
this.time = scores.getTime();
|
||||
this.saveToPref(STR_TIME, this.time);
|
||||
this.unremove();
|
||||
}
|
||||
|
||||
private Scores get() {
|
||||
if (!this.isLoaded())
|
||||
return null;
|
||||
return new Scores(this.score, this.time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
}
|
||||
}
|
||||
|
||||
private final Next next;
|
||||
private final End end;
|
||||
|
||||
public StoredNextEntity(SharedPreferences prefs, String prefix) {
|
||||
super(prefs, prefix+".nextEntity");
|
||||
this.next = new Next(prefs, prefix+".nextEntity");
|
||||
this.end = new End(prefs, prefix+".nextEntity");
|
||||
}
|
||||
|
||||
public void setNext(Question question) {
|
||||
this.next.set(question);
|
||||
this.end.remove();
|
||||
this.unremove();
|
||||
}
|
||||
|
||||
public void setEnd(Scores scores) {
|
||||
this.end.set(scores);
|
||||
this.next.remove();
|
||||
this.unremove();
|
||||
}
|
||||
|
||||
public Question getNext() {
|
||||
Log.d("getNext", String.valueOf(this.next.get() != null));
|
||||
return this.next.get();
|
||||
}
|
||||
|
||||
public Scores getEnd() {
|
||||
Log.d("getEnd", String.valueOf(this.end.get() != null));
|
||||
return this.end.get();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
super.remove();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 18.04.2017.
|
||||
* Stored object
|
||||
*/
|
||||
|
||||
abstract class StoredObject {
|
||||
private final SharedPreferences prefs;
|
||||
private final String prefix;
|
||||
|
||||
StoredObject(SharedPreferences prefs, String prefix){
|
||||
this.prefs = prefs;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
void remove() {
|
||||
SharedPreferences.Editor editor = this.prefs.edit();
|
||||
editor.putBoolean("L"+this.prefix, false);
|
||||
editor.apply();
|
||||
Log.d("StoredObject-remove", "L"+this.prefix);
|
||||
}
|
||||
|
||||
void unremove() {
|
||||
SharedPreferences.Editor editor = this.prefs.edit();
|
||||
editor.putBoolean("L"+this.prefix, true);
|
||||
editor.apply();
|
||||
Log.d("StoredObject-unremove", "L"+this.prefix);
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return this.prefs.getBoolean("L"+this.prefix, false);
|
||||
}
|
||||
|
||||
void saveToPref(String name, String value) {
|
||||
SharedPreferences.Editor editor = this.prefs.edit();
|
||||
editor.putString(this.prefix+"."+name, value);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
void saveToPref(String name, int value) {
|
||||
SharedPreferences.Editor editor = this.prefs.edit();
|
||||
editor.putInt(this.prefix+"."+name, value);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
void saveToPref(String name, long value) {
|
||||
SharedPreferences.Editor editor = this.prefs.edit();
|
||||
editor.putLong(this.prefix+"."+name, value);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
void saveToPref(String name, boolean value) {
|
||||
SharedPreferences.Editor editor = this.prefs.edit();
|
||||
editor.putBoolean(this.prefix+"."+name, value);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
||||
|
||||
String loadFromPref(String name, String defValue) {
|
||||
if (!this.isLoaded())
|
||||
return defValue;
|
||||
return this.prefs.getString(this.prefix+"."+name, defValue);
|
||||
}
|
||||
|
||||
int loadFromPref(String name, int defValue) {
|
||||
if (!this.isLoaded())
|
||||
return defValue;
|
||||
return this.prefs.getInt(this.prefix+"."+name, defValue);
|
||||
}
|
||||
|
||||
long loadFromPref(String name, long defValue) {
|
||||
if (!this.isLoaded())
|
||||
return defValue;
|
||||
return this.prefs.getLong(this.prefix+"."+name, defValue);
|
||||
}
|
||||
|
||||
boolean loadFromPref(String name, boolean defValue) {
|
||||
if (!this.isLoaded())
|
||||
return defValue;
|
||||
return this.prefs.getBoolean(this.prefix+"."+name, defValue);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 22.04.2017.
|
||||
* Stored question object
|
||||
*/
|
||||
|
||||
public class StoredQuestion extends StoredObject {
|
||||
private class Question extends StoredObject {
|
||||
|
||||
private static final String STR_CATEGORY = "category";
|
||||
private String category;
|
||||
private static final String STR_CATEGORY_ID = "categoryID";
|
||||
private int categoryID;
|
||||
private static final String STR_TOKEN = "token";
|
||||
private String token;
|
||||
private static final String STR_QUESTION = "question";
|
||||
private String question;
|
||||
private static final String STR_ANSWER0 = "answer0";
|
||||
private String answer0;
|
||||
private static final String STR_ANSWER1 = "answer1";
|
||||
private String answer1;
|
||||
private static final String STR_ANSWER2 = "answer2";
|
||||
private String answer2;
|
||||
private static final String STR_ANSWER3 = "answer3";
|
||||
private String answer3;
|
||||
|
||||
private Question(SharedPreferences prefs, String prefix) {
|
||||
super(prefs, prefix+".question");
|
||||
this.category = this.loadFromPref(STR_CATEGORY, "");
|
||||
this.categoryID = this.loadFromPref(STR_CATEGORY_ID, -1);
|
||||
this.token = this.loadFromPref(STR_TOKEN, "");
|
||||
this.question = this.loadFromPref(STR_QUESTION, "");
|
||||
this.answer0 = this.loadFromPref(STR_ANSWER0, "");
|
||||
this.answer1 = this.loadFromPref(STR_ANSWER1, "");
|
||||
this.answer2 = this.loadFromPref(STR_ANSWER2, "");
|
||||
this.answer3 = this.loadFromPref(STR_ANSWER3, "");
|
||||
}
|
||||
|
||||
private void set(de.hwr_berlin.it14.postgrachelor.Types.Question question) {
|
||||
this.category = question.getCategory();
|
||||
this.saveToPref(STR_CATEGORY, this.category);
|
||||
this.categoryID = question.getCategoryID();
|
||||
this.saveToPref(STR_CATEGORY_ID, this.categoryID);
|
||||
this.token = question.getToken();
|
||||
this.saveToPref(STR_TOKEN, this.token);
|
||||
this.question = question.getQuestion();
|
||||
this.saveToPref(STR_QUESTION, this.question);
|
||||
this.answer0 = question.getAnswers()[0];
|
||||
this.saveToPref(STR_ANSWER0, this.answer0);
|
||||
this.answer1 = question.getAnswers()[1];
|
||||
this.saveToPref(STR_ANSWER1, this.answer1);
|
||||
this.answer2 = question.getAnswers()[2];
|
||||
this.saveToPref(STR_ANSWER2, this.answer2);
|
||||
this.answer3 = question.getAnswers()[3];
|
||||
this.saveToPref(STR_ANSWER3, this.answer3);
|
||||
this.unremove();
|
||||
}
|
||||
|
||||
public de.hwr_berlin.it14.postgrachelor.Types.Question get() {
|
||||
if (!this.isLoaded())
|
||||
return null;
|
||||
return new de.hwr_berlin.it14.postgrachelor.Types.Question(this.category, this.categoryID, this.token, this.question, new String[]{
|
||||
this.answer0,
|
||||
this.answer1,
|
||||
this.answer2,
|
||||
this.answer3
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private class Answer extends StoredObject {
|
||||
private static final String STR_ANSWER = "answer";
|
||||
private int answer;
|
||||
|
||||
private Answer(SharedPreferences prefs, String prefix) {
|
||||
super(prefs, prefix+".answer");
|
||||
this.answer = this.loadFromPref(STR_ANSWER, -1);
|
||||
}
|
||||
|
||||
private void set(int answer) {
|
||||
if (this.isLoaded())
|
||||
return;
|
||||
this.answer = answer;
|
||||
this.saveToPref(STR_ANSWER, this.answer);
|
||||
this.unremove();
|
||||
}
|
||||
|
||||
private int get() {
|
||||
if (this.isLoaded())
|
||||
return this.answer;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
}
|
||||
}
|
||||
|
||||
private class Result extends StoredObject {
|
||||
|
||||
private static final String STR_SCORE = "score";
|
||||
private int score;
|
||||
private static final String STR_CORRECT_POS = "correctPos";
|
||||
private int correctPos;
|
||||
private static final String STR_TOTAL = "total";
|
||||
private int total;
|
||||
private static final String STR_IS_CORRECT = "isCorrect";
|
||||
private boolean isCorrect;
|
||||
|
||||
private Result(SharedPreferences prefs, String prefix) {
|
||||
super(prefs, prefix + ".result");
|
||||
this.score = this.loadFromPref(STR_SCORE, 0);
|
||||
this.correctPos = this.loadFromPref(STR_CORRECT_POS, 0);
|
||||
this.total = this.loadFromPref(STR_TOTAL, 0);
|
||||
this.isCorrect = this.loadFromPref(STR_IS_CORRECT, false);
|
||||
}
|
||||
|
||||
private void set(de.hwr_berlin.it14.postgrachelor.Types.Result result) {
|
||||
this.isCorrect = result.isCorrect();
|
||||
this.saveToPref(STR_IS_CORRECT, this.isCorrect);
|
||||
this.score = result.getScore();
|
||||
this.saveToPref(STR_SCORE, this.score);
|
||||
this.correctPos = result.getCorrectPos();
|
||||
this.saveToPref(STR_CORRECT_POS, this.correctPos);
|
||||
this.total = result.getTotal();
|
||||
this.saveToPref(STR_TOTAL, this.total);
|
||||
this.unremove();
|
||||
}
|
||||
|
||||
private de.hwr_berlin.it14.postgrachelor.Types.Result get() {
|
||||
if (!this.isLoaded())
|
||||
return null;
|
||||
return new de.hwr_berlin.it14.postgrachelor.Types.Result(
|
||||
this.isCorrect,
|
||||
this.score,
|
||||
this.correctPos,
|
||||
this.total
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private final Question question;
|
||||
private final Answer answer;
|
||||
private final Result result;
|
||||
|
||||
public StoredQuestion(SharedPreferences prefs, String prefix) {
|
||||
super(prefs, prefix+".question");
|
||||
this.question = new Question(prefs, prefix+".question");
|
||||
this.answer = new Answer(prefs, prefix+".question");
|
||||
this.result = new Result(prefs, prefix+".question");
|
||||
if (this.question.isLoaded())
|
||||
this.unremove();
|
||||
else
|
||||
this.remove();
|
||||
}
|
||||
|
||||
public void setQuestion(de.hwr_berlin.it14.postgrachelor.Types.Question question) {
|
||||
this.question.set(question);
|
||||
this.answer.remove();
|
||||
this.result.remove();
|
||||
this.unremove();
|
||||
}
|
||||
|
||||
public void setAnswer(int answer) {
|
||||
this.answer.set(answer);
|
||||
}
|
||||
|
||||
public void setResult(de.hwr_berlin.it14.postgrachelor.Types.Result result) {
|
||||
this.result.set(result);
|
||||
}
|
||||
|
||||
public de.hwr_berlin.it14.postgrachelor.Types.Question getQuestion() {
|
||||
return this.question.get();
|
||||
}
|
||||
|
||||
public int getAnswer() {
|
||||
return this.answer.get();
|
||||
}
|
||||
|
||||
public de.hwr_berlin.it14.postgrachelor.Types.Result getResult() {
|
||||
return this.result.get();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
super.remove();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 30.03.2017.
|
||||
* Games scores on game end
|
||||
*/
|
||||
|
||||
public class StoredScores extends StoredObject {
|
||||
|
||||
private int score;
|
||||
private static final String STR_SCORE = "score";
|
||||
private int time;
|
||||
private static final String STR_TIME = "time";
|
||||
|
||||
public StoredScores(SharedPreferences prefs, String prefix) {
|
||||
super(prefs, prefix+".scores");
|
||||
this.score = this.loadFromPref(STR_SCORE, -1);
|
||||
this.time = this.loadFromPref(STR_TIME, -1);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
super.remove();
|
||||
}
|
||||
|
||||
public void set(Scores scores) {
|
||||
this.score = scores.getScore();
|
||||
this.saveToPref(STR_SCORE, this.score);
|
||||
this.time = scores.getTime();
|
||||
this.saveToPref(STR_TIME, this.time);
|
||||
this.unremove();
|
||||
}
|
||||
|
||||
public Scores get() {
|
||||
if (!this.isLoaded())
|
||||
return null;
|
||||
return new Scores(this.score, this.time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 21.04.2017.
|
||||
* Stored game state object
|
||||
*/
|
||||
public final class StoredStates extends StoredObject {
|
||||
|
||||
public static final int UNINITIALIZED = 1;
|
||||
public static final int END = 2;
|
||||
public static final int ON_HOLD_LOADING = 4;
|
||||
public static final int ON_HOLD_RESULT = 8;
|
||||
public static final int RUNNING = 16;
|
||||
public static final int PAUSED = 32;
|
||||
|
||||
|
||||
private int state;
|
||||
private static final String STR_STATE = "state";
|
||||
private int previous;
|
||||
private static final String STR_PREVIOUS = "previous";
|
||||
|
||||
public StoredStates(SharedPreferences prefs, String prefix) {
|
||||
super(prefs, prefix+".states");
|
||||
this.previous = this.loadFromPref(STR_PREVIOUS, END);
|
||||
this.state = this.loadFromPref(STR_STATE, END);
|
||||
this.unremove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public States get() {
|
||||
return new States(this.previous, this.state);
|
||||
}
|
||||
|
||||
public void nextState(int state) {
|
||||
this.previous = this.state;
|
||||
this.state = state;
|
||||
this.saveToPref(STR_PREVIOUS, this.previous);
|
||||
this.saveToPref(STR_STATE, this.state);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
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 StoredTimings extends StoredObject {
|
||||
private static final int M = 1000;
|
||||
private static final int N = 100;
|
||||
private static final int R = 30;
|
||||
private static final int S = 0;
|
||||
private static final int T = 100;
|
||||
|
||||
private long startTime;
|
||||
private static final String STR_START_TIME = "startTime";
|
||||
private long endTime;
|
||||
private static final String STR_END_TIME = "endTime";
|
||||
|
||||
public StoredTimings(SharedPreferences prefs, String prefix) {
|
||||
super(prefs, prefix+".timings");
|
||||
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
|
||||
this.unremove();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.startTime = System.currentTimeMillis();
|
||||
this.saveToPref(STR_START_TIME, this.startTime);
|
||||
this.endTime = -1;
|
||||
this.saveToPref(STR_END_TIME, this.endTime);
|
||||
this.unremove();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (this.endTime != -1)
|
||||
return;
|
||||
this.endTime = System.currentTimeMillis();
|
||||
this.saveToPref(STR_END_TIME, this.endTime);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.remove();
|
||||
}
|
||||
|
||||
public Timings get() {
|
||||
return new Timings(this.getTimeDiff(), this.getScore());
|
||||
}
|
||||
|
||||
private long getTimeDiff() {
|
||||
if (!this.isLoaded())
|
||||
return 0;
|
||||
else if (this.endTime != -1)
|
||||
return this.endTime-this.startTime;
|
||||
else
|
||||
return System.currentTimeMillis()-this.startTime;
|
||||
}
|
||||
|
||||
private int getScore() {
|
||||
//this.score = Math.max((int) Math.floor(1025 - 5*Math.sqrt(2*timeDiff-3975)), 10);
|
||||
//this.score = (int) Math.max(N, M-(R*Math.sqrt(T*(-8*S+T+8*this.timeDiff))-T)/2/T);
|
||||
|
||||
// simplified
|
||||
return (int) Math.max(N, M-(R*Math.sqrt(T*(T + 8 * this.getTimeDiff()))-T)/2/T);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Types;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 23.04.2017.
|
||||
* Time and score measurement
|
||||
*/
|
||||
|
||||
public class Timings {
|
||||
private final long timeDiff;
|
||||
private final int score;
|
||||
|
||||
Timings(long timeDiff, int score) {
|
||||
this.timeDiff = timeDiff;
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public long getTimeDiff() {
|
||||
return timeDiff;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Utils;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.hwr_berlin.it14.postgrachelor.Types.Requestable;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 10.04.2017.
|
||||
*/
|
||||
|
||||
abstract class AsyncAdapter<T extends Requestable> extends BaseAdapter {
|
||||
|
||||
private int count;
|
||||
private ArrayList<Requestable> items;
|
||||
|
||||
private AsyncAdapter() {}
|
||||
|
||||
AsyncAdapter(int count) {
|
||||
super();
|
||||
items = new ArrayList<>();
|
||||
this.setCount(count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (convertView == null)
|
||||
convertView = this.inflateView(position, parent);
|
||||
convertView = this.clearView(position, convertView);
|
||||
this.loadView(position, convertView, parent);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@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);
|
||||
request.execute();
|
||||
} else if (!this.items.get(position).isRequested()) {
|
||||
this.fillView((T) this.items.get(position), position, convertView);
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
abstract ListSequence<T> getAsyncListSequence(int position);
|
||||
|
||||
private void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
protected abstract int getRequestedLength(int position);
|
||||
|
||||
|
||||
|
||||
|
||||
private class AsyncRequest extends AsyncTask<Void, Void, ListSequence<Requestable>> {
|
||||
|
||||
private final int position;
|
||||
private final View convertView;
|
||||
|
||||
AsyncRequest(int position, View convertView) {
|
||||
this.position = position;
|
||||
this.convertView = convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
for (int i = items.size(); i < this.position; i++) {
|
||||
items.add(null);
|
||||
}
|
||||
for (int i = this.position; i < this.position+getRequestedLength(this.position); i++) {
|
||||
if (i < items.size())
|
||||
items.set(i, new Requestable());
|
||||
else
|
||||
items.add(new Requestable());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
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
|
||||
protected void onPostExecute(ListSequence<Requestable> result) {
|
||||
super.onPostExecute(result);
|
||||
int start = result.getStart();
|
||||
ArrayList<Requestable> list = result.getItems();
|
||||
for (int i = items.size(); i < start; i++) {
|
||||
items.add(null);
|
||||
}
|
||||
while (list.size() > 0) {
|
||||
if (start < items.size())
|
||||
items.set(start, list.remove(0));
|
||||
else
|
||||
items.add(list.remove(0));
|
||||
start++;
|
||||
}
|
||||
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<R> {
|
||||
private final int start;
|
||||
private final ArrayList<R> items;
|
||||
|
||||
ListSequence(int start, ArrayList<R> items) {
|
||||
this.start = start;
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
|
||||
public int getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
ArrayList<R> getItems() {
|
||||
return items;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Utils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 06.04.2017.
|
||||
* Convert between data types
|
||||
*/
|
||||
|
||||
public class Conversion {
|
||||
|
||||
public static String millisToTime(long millis) {
|
||||
int seconds = (int) (millis/1000) % 60;
|
||||
int minutes = (int) (millis/1000/60) % 60;
|
||||
int hours = (int) (millis/1000/60/60) % 24;
|
||||
int days = (int) millis/1000/60/60/24;
|
||||
String result = intToStr(minutes, 2, '0')+":"+intToStr(seconds, 2, '0');
|
||||
if (hours > 0)
|
||||
result = intToStr(hours)+":"+result;
|
||||
if (days > 0)
|
||||
result = intToStr(days)+" days "+result;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String intToStr(int i) {
|
||||
return String.format(Locale.getDefault(), "%1d", i);
|
||||
}
|
||||
|
||||
public static String intToStr(int i, int padding) {
|
||||
return String.format(Locale.getDefault(), "%"+Conversion.intToStr(padding)+"s", i);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static String intToStr(int i, int padding, char padChar) {
|
||||
return Conversion.intToStr(i, padding).replace(' ', padChar);
|
||||
}
|
||||
|
||||
public static int strToInt(String string, int defValue) {
|
||||
try{
|
||||
return Integer.parseInt(string);
|
||||
}catch(NumberFormatException e){
|
||||
return defValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.hwr_berlin.it14.postgrachelor.R;
|
||||
import de.hwr_berlin.it14.postgrachelor.Services.HighscoreService;
|
||||
import de.hwr_berlin.it14.postgrachelor.Types.HighscoresUser;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 11.04.2017.
|
||||
* Async highscore adapter for list view
|
||||
*/
|
||||
|
||||
public class HighscoreAdapter extends AsyncAdapter<HighscoresUser> {
|
||||
private final Context context;
|
||||
private final int category;
|
||||
|
||||
public HighscoreAdapter(int count, int category, Context context) {
|
||||
super(count);
|
||||
this.category = category;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
void fillView(HighscoresUser item, int position, View convertView) {
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
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)
|
||||
userNameView.setText(item.getName());
|
||||
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)
|
||||
userScoreView.setText(Conversion.intToStr(score));
|
||||
else
|
||||
userScoreView.setText(convertView.getContext().getResources().getString(R.string.no_score));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
View inflateView(int position, ViewGroup parent) {
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
return inflater.inflate(R.layout.adapter_highscore_details, parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
View clearView(int position, View convertView) {
|
||||
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) {
|
||||
userNameView.setText(R.string.loading);
|
||||
}
|
||||
if (userPlaceView != null) {
|
||||
userPlaceView.setText(convertView.getContext().getResources().getString(R.string.place, Conversion.intToStr(position+1)));
|
||||
}
|
||||
if (userScoreView != null) {
|
||||
userScoreView.setText("");
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
ListSequence<HighscoresUser> getAsyncListSequence(int position) {
|
||||
int limit = this.getRequestedLength(position);
|
||||
ArrayList<HighscoresUser> items = HighscoreService.getHighscoreDetailsSync(limit, position, this.category, null);
|
||||
return new ListSequence<>(position, items);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRequestedLength(int position) {
|
||||
return Math.min(10, getCount()-position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
import de.hwr_berlin.it14.postgrachelor.Types.RequestActivityInterface;
|
||||
|
||||
import static android.content.ContentValues.TAG;
|
||||
|
||||
abstract class JsonRequest extends AsyncTask<Void, Void, JSONObject> {
|
||||
private final String connectionURL;
|
||||
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.requestInterface = ((RequestActivityInterface) this.activity);
|
||||
} else {
|
||||
this.requestInterface = null;
|
||||
}
|
||||
Log.d("JSONRequest create", connectionURL+path);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SameReturnValue")
|
||||
protected abstract String getConnectionURL();
|
||||
|
||||
JSONObject executeSync() {
|
||||
JSONObject result = this.doInBackground();
|
||||
Log.d("JSONRequest excecute", result.toString());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
Log.d("fragment, JSONRequest", "onPre1");
|
||||
// Showing progress dialog
|
||||
if (this.requestInterface != null)
|
||||
this.uuid = this.requestInterface.showDialog();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected JSONObject doInBackground(Void... arg0) {
|
||||
URL url = null;
|
||||
String jsonText = "";
|
||||
JSONObject jsonObj = null;
|
||||
try {
|
||||
url = new URL(parseURL(this.connectionURL+this.path, this.params));
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HttpURLConnection urlConnection = null;
|
||||
if (url == null)
|
||||
return new JSONObject();
|
||||
try {
|
||||
Log.d("JSONRequest url", url.toString());
|
||||
urlConnection = (HttpURLConnection) url.openConnection();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (urlConnection == null)
|
||||
return new JSONObject();
|
||||
try {
|
||||
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
|
||||
Scanner s = new Scanner(in).useDelimiter("\\A");
|
||||
jsonText = s.hasNext() ? s.next() : "";
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
urlConnection.disconnect();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!jsonText.equals("")) {
|
||||
jsonText = jsonText.substring(jsonText.indexOf("{"), jsonText.lastIndexOf("}")+1);
|
||||
|
||||
try {
|
||||
jsonObj = new JSONObject(jsonText);
|
||||
} catch (final JSONException e) {
|
||||
Log.e(TAG, "Json parsing error: " + e.getMessage());
|
||||
if (this.requestInterface != null) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
requestInterface.errorJsonLoadingFailed(e.getMessage());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Couldn't get json from server.");
|
||||
if (this.requestInterface != null) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
requestInterface.errorJsonParsing();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return jsonObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(JSONObject result) {
|
||||
super.onPostExecute(result);
|
||||
if (this.requestInterface != null)
|
||||
requestInterface.hideDialog(this.uuid);
|
||||
}
|
||||
|
||||
private String parseURL(String url, Map<String, String> params)
|
||||
{
|
||||
Uri.Builder builder = Uri.parse(url).buildUpon();
|
||||
if (params != null) {
|
||||
for (String key : params.keySet()) {
|
||||
builder.appendQueryParameter(key, params.get(key));
|
||||
}
|
||||
}
|
||||
return builder.build().toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 19.03.17.
|
||||
* Implementation of JsonRequest
|
||||
*/
|
||||
|
||||
public class JsonRequestPG extends JsonRequest {
|
||||
|
||||
private final ArrayList<AsyncResponse> delegates;
|
||||
|
||||
public interface AsyncResponse {
|
||||
void processFinish(JSONObject data);
|
||||
void processError(int status, String message);
|
||||
}
|
||||
|
||||
public JsonRequestPG(String path, HashMap<String, String> params, Activity activity, AsyncResponse delegate) {
|
||||
super(path, params, activity);
|
||||
this.delegates = new ArrayList<>();
|
||||
this.delegates.add(delegate);
|
||||
}
|
||||
|
||||
private void processError(int status, String message) {
|
||||
for (AsyncResponse delegate: delegates) {
|
||||
delegate.processError(status, message);
|
||||
}
|
||||
}
|
||||
|
||||
private void processFinish(JSONObject data) {
|
||||
for (AsyncResponse delegate: delegates) {
|
||||
delegate.processFinish(data);
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject executeSync() {
|
||||
JSONObject result = super.executeSync();
|
||||
if (result == null) {
|
||||
this.processError(-1, "Internal error occurred!");
|
||||
return null;
|
||||
}
|
||||
JSONObject meta = result.optJSONObject("meta");
|
||||
if (meta==null) {
|
||||
this.processError(-2, "Invalid JSON: Meta tag not found!");
|
||||
return null;
|
||||
}
|
||||
int status = meta.optInt("status", -3);
|
||||
String message = meta.optString("message", "");
|
||||
if (status != 0) {
|
||||
this.processError(status, message);
|
||||
return null;
|
||||
}
|
||||
JSONArray array = result.optJSONArray("data");
|
||||
JSONObject data;
|
||||
if (array != null) {
|
||||
data = new JSONObject();
|
||||
try {
|
||||
data.put("array", array);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
data = result.optJSONObject("data");
|
||||
}
|
||||
this.processFinish(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConnectionURL() {
|
||||
return "http://leander.sebse.de/";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(JSONObject result) {
|
||||
super.onPostExecute(result);
|
||||
if (result == null) {
|
||||
this.processError(-1, "Internal error occurred!");
|
||||
return;
|
||||
}
|
||||
JSONObject meta = result.optJSONObject("meta");
|
||||
if (meta==null) {
|
||||
this.processError(-2, "Invalid JSON: Meta tag not found!");
|
||||
return;
|
||||
}
|
||||
int status = meta.optInt("status", -3);
|
||||
String message = meta.optString("message", "");
|
||||
if (status != 0) {
|
||||
if (this.activity != null)
|
||||
new AlertDialog.Builder(this.activity)
|
||||
.setTitle("Error "+status)
|
||||
.setMessage(message)
|
||||
.setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// do nothing
|
||||
}
|
||||
})
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.show();
|
||||
this.processError(status, message);
|
||||
return;
|
||||
}
|
||||
JSONArray array = result.optJSONArray("data");
|
||||
JSONObject data;
|
||||
if (array != null) {
|
||||
data = new JSONObject();
|
||||
try {
|
||||
data.put("array", array);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
data = result.optJSONObject("data");
|
||||
}
|
||||
this.processFinish(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package de.hwr_berlin.it14.postgrachelor.Utils;
|
||||
|
||||
import android.view.animation.Interpolator;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 08.04.2017.
|
||||
*/
|
||||
|
||||
public class ReverseInterpolator implements Interpolator {
|
||||
private final Interpolator delegate;
|
||||
|
||||
public ReverseInterpolator(Interpolator delegate){
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public ReverseInterpolator(){
|
||||
this(new LinearInterpolator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getInterpolation(float input) {
|
||||
return this.delegate.getInterpolation(this.reverseInput(input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Map value so 0-0.5 = 0-1 and 0.5-1 = 1-0
|
||||
*/
|
||||
private float reverseInput(float input){
|
||||
if(input <= 0.5)
|
||||
return input*2;
|
||||
else
|
||||
return Math.abs(input-1)*2;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
15
app/src/main/res/anim/scale_up.xml
Normal file
15
app/src/main/res/anim/scale_up.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<scale
|
||||
android:duration="500"
|
||||
android:fromXScale="1.0"
|
||||
android:fromYScale="1.0"
|
||||
android:toXScale="2.0"
|
||||
android:toYScale="2.0"
|
||||
android:pivotX="100%"
|
||||
android:pivotY="100%" >
|
||||
|
||||
</scale>
|
||||
|
||||
</set>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@android:id/background">
|
||||
<shape>
|
||||
<solid android:color="@color/colorPrimary" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:id="@android:id/secondaryProgress">
|
||||
<clip>
|
||||
<shape>
|
||||
<solid android:color="@color/colorPrimary" />
|
||||
</shape>
|
||||
</clip>
|
||||
</item>
|
||||
<item android:id="@android:id/progress">
|
||||
<clip>
|
||||
<shape>
|
||||
<solid android:color="@color/colorPrimaryDark" />
|
||||
</shape>
|
||||
</clip>
|
||||
</item>
|
||||
</layer-list>
|
||||
@@ -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>
|
||||
14
app/src/main/res/layout/activity_highscore.xml
Normal file
14
app/src/main/res/layout/activity_highscore.xml
Normal 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.HighscoreActivity">
|
||||
|
||||
|
||||
<ListView
|
||||
android:id="@+id/category_listview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:listitem="@layout/adapter_highscore_details" />
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
@@ -1,25 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:openDrawer="start">
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<include
|
||||
layout="@layout/app_bar_main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<android.support.design.widget.NavigationView
|
||||
<!--<android.support.design.widget.NavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
android:fitsSystemWindows="true"
|
||||
app:headerLayout="@layout/nav_header_main"
|
||||
app:menu="@menu/activity_main_drawer" />
|
||||
app:menu="@menu/activity_main_drawer" />-->
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
|
||||
14
app/src/main/res/layout/activity_settings.xml
Normal file
14
app/src/main/res/layout/activity_settings.xml
Normal 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>
|
||||
42
app/src/main/res/layout/adapter_highscore_details.xml
Normal file
42
app/src/main/res/layout/adapter_highscore_details.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/tvPlace"
|
||||
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"
|
||||
tools:text="0000"
|
||||
tools:ignore="RtlSymmetry" />
|
||||
<TextView
|
||||
android:id="@+id/tvName"
|
||||
style="@style/TextAppearance.AppCompat.Body1"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:padding="20dp"
|
||||
android:layout_marginLeft="70sp"
|
||||
android:layout_marginStart="70sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/start_test" />
|
||||
<TextView
|
||||
android:id="@+id/tvScore"
|
||||
style="@style/TextAppearance.AppCompat.Body1"
|
||||
android:textColor="@android:color/primary_text_light"
|
||||
android:padding="20dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
tools:ignore="RelativeOverlap"
|
||||
android:text="@string/_1337" />
|
||||
</RelativeLayout>
|
||||
21
app/src/main/res/layout/adapter_setting.xml
Normal file
21
app/src/main/res/layout/adapter_setting.xml
Normal 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>
|
||||
@@ -21,7 +21,23 @@
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_main" />
|
||||
<RelativeLayout 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:id="@+id/relative_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context="de.hwr_berlin.it14.postgrachelor.MainActivity"
|
||||
tools:showIn="@layout/app_bar_main">
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
@@ -29,6 +45,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
app:srcCompat="@android:drawable/ic_dialog_email" />
|
||||
app:srcCompat="@android:drawable/ic_dialog_email" />-->
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout 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:id="@+id/content_main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context="de.hwr_berlin.it14.postgrachelor.MainActivity"
|
||||
tools:showIn="@layout/app_bar_main">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!" />
|
||||
</RelativeLayout>
|
||||
62
app/src/main/res/layout/fragment_login.xml
Normal file
62
app/src/main/res/layout/fragment_login.xml
Normal file
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView 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"
|
||||
android:gravity="center"
|
||||
android:scrollbarStyle="outsideOverlay"
|
||||
tools:context="de.hwr_berlin.it14.postgrachelor.LoginFragment">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:paddingTop="50dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="100dp"
|
||||
android:src="@mipmap/ic_launcher"
|
||||
android:contentDescription="@string/launcher_icon"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="40dp"
|
||||
android:textSize="40sp"
|
||||
android:text="@string/app_name" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_margin="20dp"
|
||||
android:text="@string/welcome_text" />
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:layout_margin="10dp"
|
||||
android:hint="@string/enter_user_name"
|
||||
android:id="@+id/login_edit"
|
||||
android:maxLines="1"
|
||||
android:inputType="textFilter|textNoSuggestions"
|
||||
android:background="@android:color/background_light" />
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
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>
|
||||
|
||||
</ScrollView>
|
||||
63
app/src/main/res/layout/fragment_main.xml
Normal file
63
app/src/main/res/layout/fragment_main.xml
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/swipeContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="de.hwr_berlin.it14.postgrachelor.MainFragment">
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbarStyle="outsideOverlay">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/fragment_main_game"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/fragment_main_game"/>
|
||||
|
||||
<include layout="@layout/fragment_main_status"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/fragment_main_status"/>
|
||||
|
||||
<android.support.v7.widget.GridLayout
|
||||
xmlns:grid="http://schemas.android.com/apk/res-auto"
|
||||
|
||||
android:id="@+id/fragment_main_categories"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4dp"
|
||||
|
||||
grid:alignmentMode="alignBounds"
|
||||
grid:columnCount="2"
|
||||
grid:rowOrderPreserved="false"
|
||||
grid:useDefaultMargins="true"
|
||||
tools:listitem="@layout/fragment_main_category">
|
||||
<include layout="@layout/fragment_main_category"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
grid:layout_columnWeight="1"
|
||||
grid:layout_gravity="fill"
|
||||
/>
|
||||
<include layout="@layout/fragment_main_category"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
grid:layout_columnWeight="1"
|
||||
grid:layout_gravity="fill"
|
||||
/>
|
||||
<include layout="@layout/fragment_main_category"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
grid:layout_columnWeight="1"
|
||||
grid:layout_gravity="fill"
|
||||
/>
|
||||
</android.support.v7.widget.GridLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
36
app/src/main/res/layout/fragment_main_category.xml
Normal file
36
app/src/main/res/layout/fragment_main_category.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:background="#FF33B5E6"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:gravity="start"
|
||||
android:padding="5dp"
|
||||
tools:ignore="Overdraw">
|
||||
<TextView
|
||||
android:id="@+id/textViewCategory"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="100dp"
|
||||
android:text="@string/category" />
|
||||
<ProgressBar
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:id="@+id/progressBarCategory"
|
||||
android:progressDrawable="@drawable/horizontal_progress_drawable_red"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="false"
|
||||
android:max="900"
|
||||
android:progress="300"
|
||||
android:layout_alignParentBottom="true"/>
|
||||
<TextView
|
||||
android:id="@+id/textViewScore"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:paddingTop="10dp"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:text="@string/_1337"/>
|
||||
</RelativeLayout>
|
||||
49
app/src/main/res/layout/fragment_main_game.xml
Normal file
49
app/src/main/res/layout/fragment_main_game.xml
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout 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="match_parent"
|
||||
tools:showIn="@layout/fragment_main"
|
||||
android:clickable="true"
|
||||
android:padding="5dp">
|
||||
|
||||
<View
|
||||
android:id="@+id/background"
|
||||
android:background="@android:color/holo_orange_dark"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="90dp"
|
||||
android:max="100"
|
||||
android:minHeight="90dp"
|
||||
android:maxHeight="90dp"
|
||||
android:progress="20"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:textAppearance="@style/Base.TextAppearance.AppCompat.Title"
|
||||
android:textColor="@android:color/white"
|
||||
android:padding="10dp"
|
||||
android:paddingBottom="0dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="@string/start_test"
|
||||
tools:ignore="RelativeOverlap" />
|
||||
|
||||
<ImageButton
|
||||
android:contentDescription="@string/play_a_game"
|
||||
android:id="@+id/image_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@android:drawable/ic_media_play"
|
||||
android:background="@android:color/transparent"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:paddingEnd="50dp"
|
||||
android:paddingStart="50dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingRight="50dp"
|
||||
android:paddingLeft="50dp"
|
||||
android:clickable="false" />
|
||||
|
||||
</RelativeLayout>
|
||||
41
app/src/main/res/layout/fragment_main_status.xml
Normal file
41
app/src/main/res/layout/fragment_main_status.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout 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="match_parent"
|
||||
tools:showIn="@layout/fragment_main"
|
||||
android:padding="5dp">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBarStatus"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:progressDrawable="@drawable/horizontal_progress_drawable_red"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="90dp"
|
||||
android:indeterminate="false"
|
||||
android:max="100"
|
||||
android:minHeight="90dp"
|
||||
android:maxHeight="90dp"
|
||||
android:progress="20"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fragment_user_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/Base.TextAppearance.AppCompat.Title"
|
||||
android:textColor="@android:color/white"
|
||||
android:padding="10dp"
|
||||
android:text="@string/app_name" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fragment_user_score"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:textAppearance="@style/Base.TextAppearance.AppCompat.Title"
|
||||
android:textColor="@android:color/white"
|
||||
android:padding="20dp"
|
||||
android:textSize="55sp"
|
||||
android:text="@string/_1337" />
|
||||
</RelativeLayout>
|
||||
107
app/src/main/res/layout/fragment_question.xml
Normal file
107
app/src/main/res/layout/fragment_question.xml
Normal file
@@ -0,0 +1,107 @@
|
||||
<RelativeLayout 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"
|
||||
android:clickable="true"
|
||||
android:id="@+id/layout_fragment_question"
|
||||
tools:context="de.hwr_berlin.it14.postgrachelor.QuestionFragment">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_margin="20dp"
|
||||
android:id="@+id/questionCategory"
|
||||
android:text="@string/android_studio_email" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_margin="20dp"
|
||||
android:layout_alignTop="@id/questionCategory"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Title"
|
||||
android:id="@+id/questionTitle"
|
||||
android:text="@string/welcome_text" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/questionTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/_02_15"
|
||||
android:layout_marginBottom="320sp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
android:layout_alignParentBottom="true"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/questionScore"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/_1337"
|
||||
android:layout_marginBottom="320sp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/questionTotal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="320sp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
tools:ignore="RelativeOverlap"
|
||||
android:layout_alignParentRight="true" />
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="245sp"
|
||||
android:height="75sp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:background="@color/colorPrimary"
|
||||
android:textColor="@android:color/white"
|
||||
android:id="@+id/questionAnswer0"
|
||||
android:text="@string/welcome_text"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="165sp"
|
||||
android:height="75sp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:background="@color/colorPrimary"
|
||||
android:textColor="@android:color/white"
|
||||
android:id="@+id/questionAnswer1"
|
||||
android:text="@string/welcome_text"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="85sp"
|
||||
android:height="75sp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:background="@color/colorPrimary"
|
||||
android:textColor="@android:color/white"
|
||||
android:id="@+id/questionAnswer2"
|
||||
android:text="@string/welcome_text"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="5sp"
|
||||
android:height="75sp"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:background="@color/colorPrimary"
|
||||
android:textColor="@android:color/white"
|
||||
android:id="@+id/questionAnswer3"
|
||||
android:text="@string/welcome_text"/>
|
||||
|
||||
</RelativeLayout>
|
||||
45
app/src/main/res/layout/fragment_question_end.xml
Normal file
45
app/src/main/res/layout/fragment_question_end.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<LinearLayout 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.QuestionEndFragment"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="40dp"
|
||||
android:textSize="40sp"
|
||||
android:text="@string/test_completed" />
|
||||
<TextView
|
||||
android:id="@+id/textViewScore"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textSize="80sp"
|
||||
android:text="@string/_1337"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/colorPrimaryDark"
|
||||
android:textStyle="bold"/>
|
||||
<TextView
|
||||
android:id="@+id/textViewTime"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="40dp"
|
||||
android:textSize="25sp"
|
||||
android:text="@string/_02_15"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/colorPrimaryDark"
|
||||
android:textStyle="bold"/>
|
||||
<Button
|
||||
android:id="@+id/returnBtn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/colorPrimary"
|
||||
android:textColor="@android:color/white"
|
||||
android:text="@string/return_btn"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,35 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/nav_header_height"
|
||||
android:background="@drawable/side_nav_bar"
|
||||
android:gravity="bottom"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/nav_header_vertical_spacing"
|
||||
app:srcCompat="@android:drawable/sym_def_app_icon" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/nav_header_vertical_spacing"
|
||||
android:text="Android Studio"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="android.studio@android.com" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<group android:checkableBehavior="single">
|
||||
<item
|
||||
android:id="@+id/nav_camera"
|
||||
android:icon="@drawable/ic_menu_camera"
|
||||
android:title="Import" />
|
||||
<item
|
||||
android:id="@+id/nav_gallery"
|
||||
android:icon="@drawable/ic_menu_gallery"
|
||||
android:title="Gallery" />
|
||||
<item
|
||||
android:id="@+id/nav_slideshow"
|
||||
android:icon="@drawable/ic_menu_slideshow"
|
||||
android:title="Slideshow" />
|
||||
<item
|
||||
android:id="@+id/nav_manage"
|
||||
android:icon="@drawable/ic_menu_manage"
|
||||
android:title="Tools" />
|
||||
</group>
|
||||
|
||||
<item android:title="Communicate">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/nav_share"
|
||||
android:icon="@drawable/ic_menu_share"
|
||||
android:title="Share" />
|
||||
<item
|
||||
android:id="@+id/nav_send"
|
||||
android:icon="@drawable/ic_menu_send"
|
||||
android:title="Send" />
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
</menu>
|
||||
@@ -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>
|
||||
|
||||
7
app/src/main/res/values-de/plurals.xml
Normal file
7
app/src/main/res/values-de/plurals.xml
Normal 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>
|
||||
40
app/src/main/res/values-de/strings.xml
Normal file
40
app/src/main/res/values-de/strings.xml
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="action_settings">Einstellungen</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! 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>
|
||||
<string name="category">Kategorie: %1$s</string>
|
||||
<string name="no_question_available">Keine Fragen verfügbar!</string>
|
||||
<string name="play_a_game">Spiele ein Spiel!</string>
|
||||
<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 6–20 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>
|
||||
@@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#3F51B5</color>
|
||||
<color name="colorPrimaryDark">#303F9F</color>
|
||||
<!--<color name="colorPrimary">#3F51B5</color>-->
|
||||
<color name="colorPrimary">#5262BC</color>
|
||||
<!--<color name="colorPrimaryDark">#303F9F</color>-->
|
||||
<color name="colorPrimaryDark">#2B388F</color>
|
||||
<color name="colorAccent">#FF4081</color>
|
||||
</resources>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1,8 +1 @@
|
||||
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<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 />
|
||||
|
||||
6
app/src/main/res/values/ids.xml
Normal file
6
app/src/main/res/values/ids.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<item name="category_name" type="id" />
|
||||
<item name="category_id" type="id" />
|
||||
<item name="category_count" type="id" />
|
||||
</resources>
|
||||
7
app/src/main/res/values/plurals.xml
Normal file
7
app/src/main/res/values/plurals.xml
Normal 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>
|
||||
@@ -1,8 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">PostGrachelor</string>
|
||||
|
||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||
|
||||
<string name="app_name" translatable="false">PostGrachelor</string>
|
||||
<string name="action_settings">Settings</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>
|
||||
<string name="test_completed">Test completed!</string>
|
||||
<string name="_1337" translatable="false">1337</string>
|
||||
<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! 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>
|
||||
<string name="no_time">No Time</string>
|
||||
<string name="category">Category: %1$s</string>
|
||||
<string name="no_question_available">No question available!</string>
|
||||
<string name="_0" translatable="false">0</string>
|
||||
<string name="play_a_game">Play a Game!</string>
|
||||
<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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">
|
||||
<svg width="83cm" height="24cm" viewBox="39 -1 1642 462" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg width="83cm" height="24cm" viewBox="39 -1 1642 462" xmlns="http://www.w3.org/2000/svg">
|
||||
<g>
|
||||
<rect style="fill: #ffffff" x="40" y="0" width="45.05" height="36"/>
|
||||
<rect style="fill: none; fill-opacity:0; stroke-width: 2; stroke: #000000" x="40" y="0" width="45.05" height="36"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
@@ -5,7 +5,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.2.3'
|
||||
classpath 'com.android.tools.build:gradle:2.3.1'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
#Mon Dec 28 10:00:20 PST 2015
|
||||
#Fri Mar 03 08:16:04 CET 2017
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
|
||||
|
||||
Reference in New Issue
Block a user