1
0
Fork 0

Error Correction

This commit is contained in:
kauron 2015-02-20 23:36:01 +01:00
parent 0677fbf059
commit 9aeb975ffb
9 changed files with 152 additions and 58 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="" vcs="" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
</component> </component>
</project> </project>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4"> <module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager"> <component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle"> <facet type="java-gradle" name="Java-Gradle">
<configuration> <configuration>
@ -7,7 +7,7 @@
</configuration> </configuration>
</facet> </facet>
</component> </component>
<component name="NewModuleRootManager" inherit-compiler-output="false"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<output url="file://$MODULE_DIR$/build/classes/main" /> <output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" /> <output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output /> <exclude-output />

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4"> <module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="DungeonManager" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager"> <component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle"> <facet type="android-gradle" name="Android-Gradle">
<configuration> <configuration>
@ -9,6 +9,7 @@
<facet type="android" name="Android"> <facet type="android" name="Android">
<configuration> <configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" /> <option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" /> <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" /> <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" /> <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
@ -24,6 +25,7 @@
</component> </component>
<component name="NewModuleRootManager" inherit-compiler-output="false"> <component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" /> <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />

View file

@ -11,7 +11,7 @@ import android.widget.Toast;
public class Introduction extends ActionBarActivity { public class Introduction extends ActionBarActivity {
EditText name, className, raceName, level, maxPg; EditText name, className, raceName, level, maxPg, curativeEfforts, maxCurativeEfforts, pgE;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -23,6 +23,9 @@ public class Introduction extends ActionBarActivity {
raceName = (EditText) findViewById(R.id.editRaceIntro); raceName = (EditText) findViewById(R.id.editRaceIntro);
level = (EditText) findViewById(R.id.editLevelIntro); level = (EditText) findViewById(R.id.editLevelIntro);
maxPg = (EditText) findViewById(R.id.editMaxPgIntro); maxPg = (EditText) findViewById(R.id.editMaxPgIntro);
curativeEfforts = (EditText) findViewById(R.id.editEffortIntro);
maxCurativeEfforts = (EditText) findViewById(R.id.editMaxEffortIntro);
pgE = (EditText) findViewById(R.id.editPgIntro);
} }
@ -61,31 +64,44 @@ public class Introduction extends ActionBarActivity {
private boolean finished() { private boolean finished() {
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE); SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
SharedPreferences.Editor ed = p.edit(); SharedPreferences.Editor ed = p.edit();
String nameString = name.getText().toString(); String nameString = name.getText().toString();
String classString = className.getText().toString(); String classString = className.getText().toString();
String raceString = raceName.getText().toString(); String raceString = raceName.getText().toString();
int levelInt = 0, maxPgInt = 0;
try { int levelInt = 0, maxPgInt = 0, pg = 0, curEff = 0, mCurEff = 0;
if (!level.getText().toString().isEmpty())
levelInt = Integer.parseInt(level.getText().toString()); levelInt = Integer.parseInt(level.getText().toString());
maxPgInt = Integer.parseInt(level.getText().toString()); if (!maxPg.getText().toString().isEmpty())
} catch (Exception e) {} maxPgInt = Integer.parseInt(maxPg.getText().toString());
if (!pgE.getText().toString().isEmpty())
pg = Integer.parseInt(pgE.getText().toString());
if (!curativeEfforts.getText().toString().isEmpty())
curEff = Integer.parseInt(curativeEfforts.getText().toString());
if (!maxCurativeEfforts.getText().toString().isEmpty())
mCurEff = Integer.parseInt(maxCurativeEfforts.getText().toString());
if(getIntent().getExtras().getBoolean("first_time")) { if(getIntent().getExtras().getBoolean("first_time")) {
if (!nameString.isEmpty() && if (
!nameString.isEmpty() &&
!classString.isEmpty() && !classString.isEmpty() &&
!raceString.isEmpty() && !raceString.isEmpty() &&
levelInt != 0 && levelInt != 0 &&
maxPgInt != 0) { maxPgInt != 0 &&
pg != 0 &&
curEff != 0 &&
mCurEff != 0
) {
//first save it all //first save it all
ed.putString("playerName", nameString); ed.putString("playerName", nameString);
ed.putString("className", classString); ed.putString("className", classString);
ed.putString("raceName", raceString); ed.putString("raceName", raceString);
if(p.getInt("pg", Integer.MIN_VALUE) == Integer.MIN_VALUE)
ed.putInt("pg", maxPgInt);
ed.putInt("level", levelInt); ed.putInt("level", levelInt);
ed.putInt("maxPg", maxPgInt); ed.putInt("maxPg", maxPgInt);
ed.putInt("pg", pg);
ed.putInt("maxCurativeEfforts", mCurEff);
ed.putInt("curativeEfforts", curEff);
ed.putBoolean("saved", true); ed.putBoolean("saved", true);
ed.apply();
return true;
} else { } else {
return false; return false;
} }
@ -95,8 +111,11 @@ public class Introduction extends ActionBarActivity {
if (!raceString.isEmpty()) ed.putString("raceName", raceString); if (!raceString.isEmpty()) ed.putString("raceName", raceString);
if (levelInt != 0) ed.putInt("level", levelInt); if (levelInt != 0) ed.putInt("level", levelInt);
if (maxPgInt != 0) ed.putInt("maxPg", maxPgInt); if (maxPgInt != 0) ed.putInt("maxPg", maxPgInt);
if (pg != 0) ed.putInt("pg", pg);
if (mCurEff != 0) ed.putInt("maxCurativeEfforts", mCurEff);
if (curEff != 0) ed.putInt("curativeEfforts", curEff);
}
ed.apply(); ed.apply();
return true; return true;
} }
} }
}

View file

@ -9,6 +9,7 @@ import android.graphics.Color;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -63,6 +64,7 @@ public class MainActivity extends ActionBarActivity
showHealthDialog(); showHealthDialog();
return true; return true;
} else if (id == R.id.action_edit_basics) { } else if (id == R.id.action_edit_basics) {
//TODO: try this startChildActivity()
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE); SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
Intent intent = new Intent(this, Introduction.class); Intent intent = new Intent(this, Introduction.class);
startActivity(intent.putExtra( startActivity(intent.putExtra(
@ -103,6 +105,33 @@ public class MainActivity extends ActionBarActivity
dialog.show(getFragmentManager(), "HealthDialogFragment"); dialog.show(getFragmentManager(), "HealthDialogFragment");
} }
@Override
protected void onPause() {
super.onPause();
Log.e("UTIL", "pause");
}
@Override
protected void onResume() {
super.onResume();
Log.e("UTIL", "resume");
restoreData();
}
@Override
protected void onStop() {
super.onStop();
Log.e("UTIL", "stop");
saveData();
}
@Override
protected void onDestroy() {
super.onDestroy();
saveData();
Log.e("UTIL", "destroy");
}
@Override @Override
public void curativeEffort(DialogFragment dialog, boolean uses) { public void curativeEffort(DialogFragment dialog, boolean uses) {
int hasCured = player.recoverPg(Player.USE_CURATIVE_EFFORT, uses); int hasCured = player.recoverPg(Player.USE_CURATIVE_EFFORT, uses);
@ -182,6 +211,7 @@ public class MainActivity extends ActionBarActivity
private void restoreData(){ private void restoreData(){
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE); SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
//restore state //restore state
if(player == null) {
player = new Player( player = new Player(
p.getString("playerName", getString(R.string.adventurer_name)), p.getString("playerName", getString(R.string.adventurer_name)),
p.getString("className", getString(R.string.class_name)), p.getString("className", getString(R.string.class_name)),
@ -195,6 +225,9 @@ public class MainActivity extends ActionBarActivity
new int[3], new int[3],
new int[18], new int[18],
new Power[4]); new Power[4]);
} else {
}
//set restored values to the respective fields //set restored values to the respective fields
((TextView) findViewById(R.id.nameText)).setText(player.getName()); ((TextView) findViewById(R.id.nameText)).setText(player.getName());
((TextView) findViewById(R.id.raceText)).setText(player.getRaceName()); ((TextView) findViewById(R.id.raceText)).setText(player.getRaceName());
@ -204,6 +237,15 @@ public class MainActivity extends ActionBarActivity
} }
private void saveData() { private void saveData() {
getSharedPreferences("basics", MODE_PRIVATE).edit()
.putString("playerName", player.getName())
.putString("className", player.getClassName())
.putString("raceName", player.getRaceName())
.putInt("level", player.getLevel())
.putInt("maxPg", player.getMaxPg())
.putInt("pg", player.getPg())
.putInt("maxCurativeEfforts", player.getMaxCurativeEfforts())
.putInt("curativeEfforts", player.getCurativeEfforts())
.apply();
} }
} }

View file

@ -60,6 +60,8 @@ public class Player {
} }
public int getMaxCurativeEfforts() {return maxCurativeEfforts;}
public int getCurativeEfforts() {return curativeEfforts;} public int getCurativeEfforts() {return curativeEfforts;}
public void setCurativeEffort(int curativeEfforts) {this.curativeEfforts = curativeEfforts;} public void setCurativeEffort(int curativeEfforts) {this.curativeEfforts = curativeEfforts;}

View file

@ -23,10 +23,10 @@
android:inputType="textPersonName" android:inputType="textPersonName"
android:ems="10" android:ems="10"
android:id="@+id/editRaceIntro" android:id="@+id/editRaceIntro"
android:layout_below="@+id/editClassIntro" android:hint="@string/race_name"
android:layout_alignParentLeft="true" android:layout_below="@+id/editNameIntro"
android:layout_alignParentStart="true" android:layout_toRightOf="@+id/editClassIntro"
android:hint="@string/race_name" /> android:layout_toEndOf="@+id/editClassIntro" />
<EditText <EditText
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -46,12 +46,10 @@
android:ems="10" android:ems="10"
android:id="@+id/editLevelIntro" android:id="@+id/editLevelIntro"
android:hint="@string/level" android:hint="@string/level"
android:width="70dp"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_alignParentRight="true" android:layout_toRightOf="@+id/editNameIntro"
android:layout_alignParentEnd="true" android:layout_alignRight="@+id/editRaceIntro"
android:layout_alignLeft="@+id/editMaxPgIntro" android:layout_alignEnd="@+id/editRaceIntro" />
android:layout_alignStart="@+id/editMaxPgIntro" />
<EditText <EditText
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -59,10 +57,13 @@
android:inputType="number" android:inputType="number"
android:ems="10" android:ems="10"
android:id="@+id/editMaxPgIntro" android:id="@+id/editMaxPgIntro"
android:layout_below="@+id/editLevelIntro"
android:hint="@string/max_pg" android:hint="@string/max_pg"
android:layout_alignLeft="@+id/editMaxEffortIntro" android:width="70dp"
android:layout_alignStart="@+id/editMaxEffortIntro" /> android:layout_below="@+id/editClassIntro"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/editMaxEffortIntro"
android:layout_toStartOf="@+id/editMaxEffortIntro" />
<EditText <EditText
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -70,8 +71,33 @@
android:inputType="number" android:inputType="number"
android:ems="10" android:ems="10"
android:id="@+id/editMaxEffortIntro" android:id="@+id/editMaxEffortIntro"
android:layout_alignTop="@+id/editRaceIntro"
android:layout_toEndOf="@+id/editRaceIntro"
android:hint="@string/max_curative_efforts" android:hint="@string/max_curative_efforts"
android:layout_toRightOf="@+id/editRaceIntro" /> android:layout_below="@+id/editRaceIntro"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editPgIntro"
android:width="70dp"
android:hint="@string/pg"
android:layout_below="@+id/editMaxPgIntro"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/editEffortIntro"
android:layout_toStartOf="@+id/editEffortIntro" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editEffortIntro"
android:layout_below="@+id/editMaxEffortIntro"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="@string/curative_efforts" />
</RelativeLayout> </RelativeLayout>

View file

@ -23,12 +23,13 @@
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/pgCurrent" android:layout_toLeftOf="@+id/pgCurrent"
android:layout_toStartOf="@+id/pgCurrent" android:layout_toStartOf="@+id/pgCurrent"
android:id="@+id/linearLayout"> android:id="@+id/linearLayout"
android:layout_alignBottom="@+id/pgCurrent">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/adventurer_name" android:text="@string/adventurer_name"
android:id="@+id/nameText" android:id="@+id/nameText"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
@ -38,7 +39,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/race_name" android:text="@string/race_name"
android:id="@+id/raceText" android:id="@+id/raceText"
android:layout_alignTop="@+id/classText" android:layout_alignTop="@+id/classText"
@ -49,7 +50,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/class_name" android:text="@string/class_name"
android:id="@+id/classText" android:id="@+id/classText"
android:layout_below="@+id/nameText" android:layout_below="@+id/nameText"
@ -59,7 +60,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/level" android:text="@string/level"
android:id="@+id/lvlText" android:id="@+id/lvlText"
android:layout_alignParentBottom="false" android:layout_alignParentBottom="false"
@ -71,7 +72,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/lvl" android:id="@+id/lvl"
android:layout_alignParentBottom="false" android:layout_alignParentBottom="false"
android:layout_toRightOf="@+id/lvlText" android:layout_toRightOf="@+id/lvlText"

View file

@ -4,6 +4,8 @@
<string name="app_name" translatable="false">DungeonManager</string> <string name="app_name" translatable="false">DungeonManager</string>
<string name="action_cure">Cure</string> <string name="action_cure">Cure</string>
<string name="action_undo">Undo</string> <string name="action_undo">Undo</string>
<string name="pg">PG</string>
<string name="curative_efforts">Curative efforts</string>
<string name="dungeons_and_dragons">Dungeons and Dragons</string> <string name="dungeons_and_dragons">Dungeons and Dragons</string>
<string name="action_save">Save</string> <string name="action_save">Save</string>
<string name="action_calendar_activity">Create event</string> <string name="action_calendar_activity">Create event</string>
@ -26,7 +28,7 @@
<string name="action_finish">Done</string> <string name="action_finish">Done</string>
<string name="level">Level</string> <string name="level">Level</string>
<string name="max_curative_efforts">Curative efforts</string> <string name="max_curative_efforts">Max curative efforts</string>
<string name="max_pg">Max PG</string> <string name="max_pg">Max PG</string>
<string name="missing_info_error">You need to fill all the information</string> <string name="missing_info_error">You need to fill all the information</string>
<string name="no_curative_efforts_error">You don\'t have any curative efforts left!</string> <string name="no_curative_efforts_error">You don\'t have any curative efforts left!</string>