From 05a8322ce7e4fc10d0d6553f04b3540eca78872e Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sat, 18 Apr 2020 09:27:04 +0200 Subject: [PATCH] Move activity utility classes to separate package --- .../droidfish/gamelogic/PGNFileTest.java | 4 ++-- .../petero/droidfish/tb/ProbeResultTest.java | 1 - .../org/petero/droidfish/tb/ProbeTest.java | 2 -- .../java/org/petero/droidfish/DroidFish.java | 4 ++-- .../droidfish/activities/EditBoard.java | 1 + .../droidfish/activities/EditOptions.java | 1 + .../petero/droidfish/activities/EditPGN.java | 4 +++- .../petero/droidfish/activities/LoadFEN.java | 5 +++-- .../BufferedRandomAccessFileReader.java | 2 +- .../activities/{ => util}/ChessBoardEdit.java | 2 +- .../{ => util}/EditFilePreference.java | 3 ++- .../activities/{ => util}/FENFile.java | 8 ++++---- .../activities/{ => util}/FileBrowseUtil.java | 2 +- .../activities/{ => util}/GameAdapter.java | 6 +++--- .../activities/{ => util}/PGNFile.java | 14 ++++++------- .../{ => util}/SeekBarPreference.java | 2 +- .../src/main/res/layout-land/editboard.xml | 2 +- .../src/main/res/layout/editboard.xml | 2 +- DroidFishApp/src/main/res/xml/preferences.xml | 20 +++++++++---------- 19 files changed, 44 insertions(+), 41 deletions(-) rename DroidFishApp/src/main/java/org/petero/droidfish/activities/{ => util}/BufferedRandomAccessFileReader.java (98%) rename DroidFishApp/src/main/java/org/petero/droidfish/activities/{ => util}/ChessBoardEdit.java (99%) rename DroidFishApp/src/main/java/org/petero/droidfish/activities/{ => util}/EditFilePreference.java (98%) rename DroidFishApp/src/main/java/org/petero/droidfish/activities/{ => util}/FENFile.java (94%) rename DroidFishApp/src/main/java/org/petero/droidfish/activities/{ => util}/FileBrowseUtil.java (98%) rename DroidFishApp/src/main/java/org/petero/droidfish/activities/{ => util}/GameAdapter.java (96%) rename DroidFishApp/src/main/java/org/petero/droidfish/activities/{ => util}/PGNFile.java (97%) rename DroidFishApp/src/main/java/org/petero/droidfish/activities/{ => util}/SeekBarPreference.java (99%) diff --git a/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/PGNFileTest.java b/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/PGNFileTest.java index 155d488..ed3751b 100644 --- a/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/PGNFileTest.java +++ b/DroidFishApp/src/androidTest/java/org/petero/droidfish/gamelogic/PGNFileTest.java @@ -24,8 +24,8 @@ import java.io.IOException; import java.util.ArrayList; import org.petero.droidfish.DroidFishApp; -import org.petero.droidfish.activities.PGNFile; -import org.petero.droidfish.activities.PGNFile.GameInfo; +import org.petero.droidfish.activities.util.PGNFile; +import org.petero.droidfish.activities.util.PGNFile.GameInfo; import junit.framework.TestCase; diff --git a/DroidFishApp/src/androidTest/java/org/petero/droidfish/tb/ProbeResultTest.java b/DroidFishApp/src/androidTest/java/org/petero/droidfish/tb/ProbeResultTest.java index 2763724..854814d 100644 --- a/DroidFishApp/src/androidTest/java/org/petero/droidfish/tb/ProbeResultTest.java +++ b/DroidFishApp/src/androidTest/java/org/petero/droidfish/tb/ProbeResultTest.java @@ -18,7 +18,6 @@ package org.petero.droidfish.tb; -import org.petero.droidfish.tb.ProbeResult; import org.petero.droidfish.tb.ProbeResult.Type; import junit.framework.TestCase; diff --git a/DroidFishApp/src/androidTest/java/org/petero/droidfish/tb/ProbeTest.java b/DroidFishApp/src/androidTest/java/org/petero/droidfish/tb/ProbeTest.java index 4b1812e..dce3342 100644 --- a/DroidFishApp/src/androidTest/java/org/petero/droidfish/tb/ProbeTest.java +++ b/DroidFishApp/src/androidTest/java/org/petero/droidfish/tb/ProbeTest.java @@ -20,8 +20,6 @@ package org.petero.droidfish.tb; import org.petero.droidfish.gamelogic.Position; import org.petero.droidfish.gamelogic.TextIO; -import org.petero.droidfish.tb.Probe; -import org.petero.droidfish.tb.ProbeResult; import android.os.Environment; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/DroidFish.java b/DroidFishApp/src/main/java/org/petero/droidfish/DroidFish.java index aa1c7f7..8506bf6 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/DroidFish.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/DroidFish.java @@ -44,8 +44,8 @@ import org.petero.droidfish.activities.EditPGNLoad; import org.petero.droidfish.activities.EditPGNSave; import org.petero.droidfish.activities.LoadFEN; import org.petero.droidfish.activities.LoadScid; -import org.petero.droidfish.activities.PGNFile; -import org.petero.droidfish.activities.PGNFile.GameInfo; +import org.petero.droidfish.activities.util.PGNFile; +import org.petero.droidfish.activities.util.PGNFile.GameInfo; import org.petero.droidfish.activities.Preferences; import org.petero.droidfish.book.BookOptions; import org.petero.droidfish.engine.EngineUtil; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditBoard.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditBoard.java index 00e104e..0ede006 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditBoard.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditBoard.java @@ -27,6 +27,7 @@ import org.petero.droidfish.FileUtil; import org.petero.droidfish.R; import org.petero.droidfish.Util; import org.petero.droidfish.Util.MaterialDiff; +import org.petero.droidfish.activities.util.ChessBoardEdit; import org.petero.droidfish.gamelogic.ChessParseError; import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.Piece; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditOptions.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditOptions.java index bf73b29..ceee05d 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditOptions.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditOptions.java @@ -42,6 +42,7 @@ import org.petero.droidfish.DroidFishApp; import org.petero.droidfish.FileUtil; import org.petero.droidfish.R; import org.petero.droidfish.Util; +import org.petero.droidfish.activities.util.FileBrowseUtil; import org.petero.droidfish.databinding.EditoptionsBinding; import org.petero.droidfish.databinding.UciOptionButtonBinding; import org.petero.droidfish.databinding.UciOptionCheckBinding; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditPGN.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditPGN.java index 69b7d12..5be86be 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditPGN.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditPGN.java @@ -49,7 +49,9 @@ import org.petero.droidfish.DroidFishApp; import org.petero.droidfish.ObjectCache; import org.petero.droidfish.R; import org.petero.droidfish.Util; -import org.petero.droidfish.activities.PGNFile.GameInfo; +import org.petero.droidfish.activities.util.PGNFile.GameInfo; +import org.petero.droidfish.activities.util.GameAdapter; +import org.petero.droidfish.activities.util.PGNFile; import org.petero.droidfish.databinding.SelectGameBinding; import java.io.File; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/LoadFEN.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/LoadFEN.java index cea5edc..cc00361 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/LoadFEN.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/LoadFEN.java @@ -40,8 +40,9 @@ import org.petero.droidfish.ColorTheme; import org.petero.droidfish.DroidFishApp; import org.petero.droidfish.R; import org.petero.droidfish.Util; -import org.petero.droidfish.activities.FENFile.FenInfo; -import org.petero.droidfish.activities.FENFile.FenInfoResult; +import org.petero.droidfish.activities.util.FENFile; +import org.petero.droidfish.activities.util.FENFile.FenInfo; +import org.petero.droidfish.activities.util.FENFile.FenInfoResult; import org.petero.droidfish.databinding.LoadFenBinding; import org.petero.droidfish.gamelogic.ChessParseError; import org.petero.droidfish.gamelogic.Position; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/BufferedRandomAccessFileReader.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/BufferedRandomAccessFileReader.java similarity index 98% rename from DroidFishApp/src/main/java/org/petero/droidfish/activities/BufferedRandomAccessFileReader.java rename to DroidFishApp/src/main/java/org/petero/droidfish/activities/util/BufferedRandomAccessFileReader.java index 07ebd6d..928ba2f 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/BufferedRandomAccessFileReader.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/BufferedRandomAccessFileReader.java @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -package org.petero.droidfish.activities; +package org.petero.droidfish.activities.util; import java.io.Closeable; import java.io.FileNotFoundException; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/ChessBoardEdit.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/ChessBoardEdit.java similarity index 99% rename from DroidFishApp/src/main/java/org/petero/droidfish/activities/ChessBoardEdit.java rename to DroidFishApp/src/main/java/org/petero/droidfish/activities/util/ChessBoardEdit.java index 01eba1a..4234d40 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/ChessBoardEdit.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/ChessBoardEdit.java @@ -16,7 +16,7 @@ along with this program. If not, see . */ -package org.petero.droidfish.activities; +package org.petero.droidfish.activities.util; import org.petero.droidfish.gamelogic.Move; import org.petero.droidfish.gamelogic.Piece; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditFilePreference.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/EditFilePreference.java similarity index 98% rename from DroidFishApp/src/main/java/org/petero/droidfish/activities/EditFilePreference.java rename to DroidFishApp/src/main/java/org/petero/droidfish/activities/util/EditFilePreference.java index f698e7a..1f536d8 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditFilePreference.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/EditFilePreference.java @@ -16,7 +16,7 @@ along with this program. If not, see . */ -package org.petero.droidfish.activities; +package org.petero.droidfish.activities.util; import android.app.Activity; import android.content.ActivityNotFoundException; @@ -32,6 +32,7 @@ import android.widget.LinearLayout; import org.petero.droidfish.FileUtil; import org.petero.droidfish.R; +import org.petero.droidfish.activities.Preferences; import java.io.File; import java.util.regex.Pattern; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/FENFile.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/FENFile.java similarity index 94% rename from DroidFishApp/src/main/java/org/petero/droidfish/activities/FENFile.java rename to DroidFishApp/src/main/java/org/petero/droidfish/activities/util/FENFile.java index f86b1a9..239bdf4 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/FENFile.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/FENFile.java @@ -16,7 +16,7 @@ along with this program. If not, see . */ -package org.petero.droidfish.activities; +package org.petero.droidfish.activities.util; import android.util.Pair; @@ -35,9 +35,9 @@ public class FENFile { return fileName.getAbsolutePath(); } - static final class FenInfo { - int gameNo; - String fen; + public static final class FenInfo { + public int gameNo; + public String fen; FenInfo(int gameNo, String fen) { this.gameNo = gameNo; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/FileBrowseUtil.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/FileBrowseUtil.java similarity index 98% rename from DroidFishApp/src/main/java/org/petero/droidfish/activities/FileBrowseUtil.java rename to DroidFishApp/src/main/java/org/petero/droidfish/activities/util/FileBrowseUtil.java index 39f3a08..0b1bd09 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/FileBrowseUtil.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/FileBrowseUtil.java @@ -16,7 +16,7 @@ along with this program. If not, see . */ -package org.petero.droidfish.activities; +package org.petero.droidfish.activities.util; import android.content.Intent; import android.content.pm.PackageManager; diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/GameAdapter.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/GameAdapter.java similarity index 96% rename from DroidFishApp/src/main/java/org/petero/droidfish/activities/GameAdapter.java rename to DroidFishApp/src/main/java/org/petero/droidfish/activities/util/GameAdapter.java index a81fe3f..1f741b8 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/GameAdapter.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/GameAdapter.java @@ -16,7 +16,7 @@ along with this program. If not, see . */ -package org.petero.droidfish.activities; +package org.petero.droidfish.activities.util; import android.content.Context; import android.view.LayoutInflater; @@ -117,7 +117,7 @@ public class GameAdapter extends BaseAdapter implements Filterable { } } - interface ItemMatcher { + public interface ItemMatcher { /** Return true if item matches the search criteria. */ boolean matches(U item); } @@ -125,7 +125,7 @@ public class GameAdapter extends BaseAdapter implements Filterable { /** Return an object that determines if an item matches given search criteria. * @param matchStr The match string. * @param useRegExp If true matchStr is interpreted as a regular expression. */ - static ItemMatcher getItemMatcher(String matchStr, boolean useRegExp) { + public static ItemMatcher getItemMatcher(String matchStr, boolean useRegExp) { if (useRegExp) { Pattern tmp; try { diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/PGNFile.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/PGNFile.java similarity index 97% rename from DroidFishApp/src/main/java/org/petero/droidfish/activities/PGNFile.java rename to DroidFishApp/src/main/java/org/petero/droidfish/activities/util/PGNFile.java index 97ac75a..4d68286 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/PGNFile.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/PGNFile.java @@ -16,7 +16,7 @@ along with this program. If not, see . */ -package org.petero.droidfish.activities; +package org.petero.droidfish.activities.util; import java.io.ByteArrayInputStream; import java.io.Closeable; @@ -51,14 +51,14 @@ public class PGNFile { public long startPos; public long endPos; - GameInfo setNull(long currPos) { + public GameInfo setNull(long currPos) { info = null; startPos = currPos; endPos = currPos; return this; } - boolean isNull() { return info == null; } + public boolean isNull() { return info == null; } public String toString() { if (info == null) @@ -410,7 +410,7 @@ public class PGNFile { } /** Read one game defined by gi. Return null on failure. */ - String readOneGame(GameInfo gi) { + public String readOneGame(GameInfo gi) { try (RandomAccessFile f = new RandomAccessFile(fileName, "r")) { byte[] pgnData = new byte[(int) (gi.endPos - gi.startPos)]; f.seek(gi.startPos); @@ -458,7 +458,7 @@ public class PGNFile { } } - boolean deleteGame(GameInfo gi, ArrayList gamesInFile) { + public boolean deleteGame(GameInfo gi, ArrayList gamesInFile) { try { File tmpFile = new File(fileName + ".tmp_delete"); try (RandomAccessFile fileReader = new RandomAccessFile(fileName, "r"); @@ -490,7 +490,7 @@ public class PGNFile { return false; } - void replacePGN(String pgnToSave, GameInfo gi, boolean silent) { + public void replacePGN(String pgnToSave, GameInfo gi, boolean silent) { try { File tmpFile = new File(fileName + ".tmp_delete"); try (RandomAccessFile fileReader = new RandomAccessFile(fileName, "r"); @@ -523,7 +523,7 @@ public class PGNFile { } /** Delete the file. */ - boolean delete() { + public boolean delete() { return fileName.delete(); } } diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/SeekBarPreference.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/SeekBarPreference.java similarity index 99% rename from DroidFishApp/src/main/java/org/petero/droidfish/activities/SeekBarPreference.java rename to DroidFishApp/src/main/java/org/petero/droidfish/activities/util/SeekBarPreference.java index d767c33..b33d64c 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/SeekBarPreference.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/util/SeekBarPreference.java @@ -16,7 +16,7 @@ along with this program. If not, see . */ -package org.petero.droidfish.activities; +package org.petero.droidfish.activities.util; import android.app.AlertDialog; import android.content.Context; diff --git a/DroidFishApp/src/main/res/layout-land/editboard.xml b/DroidFishApp/src/main/res/layout-land/editboard.xml index 0af936d..f5272a3 100644 --- a/DroidFishApp/src/main/res/layout-land/editboard.xml +++ b/DroidFishApp/src/main/res/layout-land/editboard.xml @@ -14,7 +14,7 @@ android:id="@+id/eb_chessboard" android:layout_width="fill_parent" android:layout_height="fill_parent" - class="org.petero.droidfish.activities.ChessBoardEdit" /> + class="org.petero.droidfish.activities.util.ChessBoardEdit" /> diff --git a/DroidFishApp/src/main/res/xml/preferences.xml b/DroidFishApp/src/main/res/xml/preferences.xml index 92192d6..ac9d15f 100644 --- a/DroidFishApp/src/main/res/xml/preferences.xml +++ b/DroidFishApp/src/main/res/xml/preferences.xml @@ -30,12 +30,12 @@ - - + - - - + - + - - + - - +