diff --git a/app/build.gradle b/app/build.gradle index 610c2fb..d95714c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,7 +25,7 @@ task createVersionXML { versionFile.println( '' << version << '' ) versionFile.println( '' << githash << '' ) versionFile.println( '' << builddate << '' ) - versionFile.println( '0x00010001' ) + versionFile.println( '0x00010002' ) versionFile.println( '' ) versionFile.close() } diff --git a/app/src/main/AndroidManifest-debug.xml b/app/src/main/AndroidManifest-debug.xml index 530122f..9582ee7 100644 --- a/app/src/main/AndroidManifest-debug.xml +++ b/app/src/main/AndroidManifest-debug.xml @@ -1,7 +1,7 @@ diff --git a/app/src/main/art/build.gradle b/app/src/main/art/build.gradle new file mode 100644 index 0000000..432c2b3 --- /dev/null +++ b/app/src/main/art/build.gradle @@ -0,0 +1,107 @@ +//apply plugin: 'com.android.application' + +class svg2png extends DefaultTask { + + String input + String output + int width + int hight + def layers + + def layerOnOff( def layer ) { + def t = '-u "//*/svg:g[@inkscape:label=\\"'+layer.key+'\\"]/@style"' + if ( layer.value ) + return t + ' -v display:inline' + else + return t + ' -v display:none' + } + + def configSVG( def svg, def layers ) { + def cfg = 'xmlstarlet ed -P -N svg=http://www.w3.org/2000/svg ' + for ( layer in layers ) { + cfg += layerOnOff( layer ) + ' ' + } + return cfg + svg + } + + def configPNG( def png, def h, def w ) { + def cfg = 'imagemagick -background none -resize '+w+'x'+h+' - ' + png + } + + def exportPNG( def svg, def svgLayerCfg, def png, def h, def w ) { + def svgProc = configSVG( svg, svgLayerCfg ).execute() + def pngProc = + configPNG( png, h, w ). + execute() + svgProc.pipeTo( pngProc ) + + pngProc.consumeProcessOutput() + pngProc.waitForOrKill(10000) + + if ( svgProc.exitValue() ) + throw new GradleException("Failed to generate svg.") + if ( pngProc.exitValue() ) + throw new GradleException("Failed to generate png.") + } + + +} + +sourceSet { + +} + +// +// Creates version.xml +// +task buildIcon { + + //from(file('srcDir')) + //into(buildDir) + + doLast { + + def sizes = [ 'ldpi':[36,36], + 'mdpi':[48,48], + 'hdpi':[72,72], + 'xhdpi':[96,96] ] + + def sizes2= [ 'ldpi':[22,36], + 'mdpi':[29,48], + 'hdpi':[43,72], + 'xhdpi':[58,96] ] + + def sizes3= [ '':[500,500] ] + +/* + def files = [ + ( "icon.svg", "icon.png", [ 'Debug':false ], sizes ), + ( "icon.svg", "icon_debug.png", [ 'Debug':true ], sizes ), + + ( "buttons.svg", "reset.png", [ 'Reset Smooth':true ], sizes ), + ( "buttons.svg", "undo.png", [ 'Undo Smooth':true ], sizes ), + ( "buttons.svg", "next.png", [ 'Next Smooth':true ], sizes2 ), + ( "buttons.svg", "prev.png", [ 'Prev Smooth':true ], sizes2 ), + + ( "lock.svg", "lock.png", [ 'lock':true ], sizes2 ), + ( "lock.svg", "unlock.png", [ 'unlock':true ], sizes2 ), + ( "lock.svg", "unlocking.png", [ 'locking':true ], sizes2 ), + + ( "bingo.svg", "bingo.png", [], sizes3 ), + ( "box.svg", "box.png", [], sizes3 ), + ( "floor.svg", "floor.png", [ 'Goal':false ], sizes3 ), + ( "floor.svg", "goal.png", [ 'Goal':true ], sizes3 ), + ( "wall.svg", "wall.png", [], sizes3 ), + ( "worker.svg", "worker.png", [ 'Hands':false ], sizes3 ), + ( "worker.svg", "worker_select.png", [ 'Hands':true ], sizes3 ), + + ( "splash.svg", "splash.png", [], ['':[500:800]] ) + ] +*/ +// for ( s in sizes ) { +// exportPNG( "icon.svg",icon,s.key+"_icon.png",s.value[0],s.value[1]) +// } + } +} + + diff --git a/app/src/main/java/org/vostan/sokoban/App.java b/app/src/main/java/org/vostan/sokoban/App.java index 1021be3..0366510 100644 --- a/app/src/main/java/org/vostan/sokoban/App.java +++ b/app/src/main/java/org/vostan/sokoban/App.java @@ -32,6 +32,7 @@ public class App extends Application max_level = pc.getCount(); current_level = prefs.getInt("current_level", MIN_LEVEL); achieved_level = prefs.getInt("achieved_level", MIN_LEVEL+10); + prefsEdit.apply(); } // // This is a singleton object. diff --git a/app/src/main/java/org/vostan/sokoban/play/PlayActivity.java b/app/src/main/java/org/vostan/sokoban/play/PlayActivity.java index 8a85e3e..0c18ca3 100644 --- a/app/src/main/java/org/vostan/sokoban/play/PlayActivity.java +++ b/app/src/main/java/org/vostan/sokoban/play/PlayActivity.java @@ -130,12 +130,12 @@ public class PlayActivity extends FragmentActivity title_view.setVisibility(View.INVISIBLE); } - public boolean onReset( View v ) + public void onReset( View v ) { while ( puzzle.isUndoable() ) puzzle.restore(); puzzle_view.invalidate(); - return true; + //return true; } // // Go to previouse puzzle. @@ -175,16 +175,16 @@ public class PlayActivity extends FragmentActivity // // Undo last action. // - public boolean onUndo( View v ) + public void onUndo( View v ) { if ( puzzle.isUndoable() ) { puzzle.restore(); puzzle_view.invalidate(); - return true; + // return true; } - else - return false; + //else + // return false; } private void loadCurrentPuzzle() diff --git a/app/src/main/res/layout/puzzle_view_title.xml b/app/src/main/res/layout/puzzle_view_title.xml index 6e7ff20..59d5c90 100644 --- a/app/src/main/res/layout/puzzle_view_title.xml +++ b/app/src/main/res/layout/puzzle_view_title.xml @@ -22,7 +22,7 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="0" - android:textSize="40dp" + android:textSize="40sp" android:paddingLeft="5dp" android:textScaleX="1" android:textColor="#FFE680" diff --git a/app/src/tests/java/org/vostan/sokoban/menu/MainActivityTest.java b/app/src/tests/java/org/vostan/sokoban/menu/MainActivityTest.java new file mode 100644 index 0000000..467a0e8 --- /dev/null +++ b/app/src/tests/java/org/vostan/sokoban/menu/MainActivityTest.java @@ -0,0 +1,115 @@ +package org.vostan.sokoban.menu; + +import android.app.Activity; +import android.test.ActivityInstrumentationTestCase2; +import android.widget.Spinner; + +import org.vostan.sokoban.menu.MainActivity; +import org.vostan.sokoban.R; + +/** + * This is a simple framework for a test of an Application. See + * {@link android.test.ApplicationTestCase ApplicationTestCase} for more information on + * how to write and extend Application tests. + * + *

To run this test, you can type: + * adb shell am instrument -w \ + * -e class com.example.android.activityinstrumentation.MainActivityTest \ + * quux.tests/android.test.InstrumentationTestRunner + * + *

Individual tests are defined as any method beginning with 'test'. + * + *

ActivityInstrumentationTestCase2 allows these tests to run alongside a running + * copy of the application under inspection. Calling getActivity() will return a + * handle to this activity (launching it if needed). + */ +public class MainActivityTest + extends ActivityInstrumentationTestCase2 { + + MainActivity mActivity; + + public MainActivityTest() { + super("org.vostan.sokoban.menu.MainActivity", MainActivity.class); + } + + protected void setUp() throws Exception { + mActivity = getActivity(); + } + + /** + * Test to make sure that spinner values are persisted across activity restarts. + * + *

Launches the main activity, sets a spinner value, closes the activity, then relaunches + * that activity. Checks to make sure that the spinner values match what we set them to. + */ + // BEGIN_INCLUDE (test_name) + public void testSpinnerValuePersistedBetweenLaunches() { +/* + // END_INCLUDE (test_name) + final int TEST_SPINNER_POSITION_1 = MainActivity.WEATHER_PARTLY_CLOUDY; + + // BEGIN_INCLUDE (launch_activity) + // Launch the activity + Activity activity = getActivity(); + // END_INCLUDE (launch_activity) + + // BEGIN_INCLUDE (write_to_ui) + // Set spinner to test position 1 + final Spinner spinner1 = (Spinner) activity.findViewById(R.id.spinner); + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + // Attempts to manipulate the UI must be performed on a UI thread. + // Calling this outside runOnUiThread() will cause an exception. + // + // You could also use @UiThreadTest, but activity lifecycle methods + // cannot be called if this annotation is used. + spinner1.requestFocus(); + spinner1.setSelection(TEST_SPINNER_POSITION_1); + } + }); + // END_INCLUDE (write_to_ui) + + // BEGIN_INCLUDE (relaunch_activity) + // Close the activity + activity.finish(); + setActivity(null); // Required to force creation of a new activity + + // Relaunch the activity + activity = this.getActivity(); + // END_INCLUDE (relaunch_activity) + + // BEGIN_INCLUDE (check_results) + // Verify that the spinner was saved at position 1 + final Spinner spinner2 = (Spinner) activity.findViewById(R.id.spinner); + int currentPosition = spinner2.getSelectedItemPosition(); + assertEquals(TEST_SPINNER_POSITION_1, currentPosition); + // END_INCLUDE (check_results) + + // Since this is a stateful test, we need to make sure that the activity isn't simply + // echoing a previously-stored value that (coincidently) matches position 1 + final int TEST_SPINNER_POSITION_2 = MainActivity.WEATHER_SNOW; + + // Set spinner to test position 2 + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + spinner2.requestFocus(); + spinner2.setSelection(TEST_SPINNER_POSITION_2); + } + }); + + // Close the activity + activity.finish(); + setActivity(null); + + // Relaunch the activity + activity = this.getActivity(); + + // Verify that the spinner was saved at position 2 + final Spinner spinner3 = (Spinner) activity.findViewById(R.id.spinner); + currentPosition = spinner3.getSelectedItemPosition(); + assertEquals(TEST_SPINNER_POSITION_2, currentPosition); +*/ + } +}