From 1ee60d1e5e53c7de7a9ec12b68eba696d5fc8924 Mon Sep 17 00:00:00 2001 From: VanitasVitae Date: Sat, 7 Nov 2015 16:42:24 +0100 Subject: [PATCH] Cleaned code --- CHANGELOG.txt | 2 + app/app.iml | 6 +- app/build.gradle | 2 +- .../integration/android/IntentIntegrator.java | 2 +- .../integration/android/IntentResult.java | 8 +-- .../enigmandroid/MainActivity.java | 5 -- .../enigmandroid/SettingsActivity.java | 13 ++-- .../enigmandroid/enigma/Enigma.java | 38 ++++++------ .../enigmandroid/enigma/Enigma_D.java | 10 +-- .../enigmandroid/enigma/Enigma_G31.java | 10 +-- .../enigmandroid/enigma/Enigma_I.java | 12 ++-- .../enigmandroid/enigma/Enigma_K.java | 10 +-- .../enigmandroid/enigma/Enigma_KD.java | 10 +-- .../enigmandroid/enigma/Enigma_M4.java | 6 +- .../enigmandroid/enigma/Enigma_R.java | 10 +-- .../enigmandroid/enigma/Enigma_T.java | 10 +-- .../enigma/inputPreparer/EditTextAdapter.java | 8 +-- .../enigma/inputPreparer/InputPreparer.java | 2 +- .../enigmandroid/enigma/parts/EntryWheel.java | 18 +++--- .../enigmandroid/enigma/parts/Plugboard.java | 3 +- .../enigmandroid/enigma/parts/Reflector.java | 19 +++--- .../enigmandroid/enigma/parts/Rotor.java | 26 ++++---- .../enigmandroid/layout/LayoutContainer.java | 24 ++++---- .../layout/LayoutContainer_D.java | 8 +-- .../layout/LayoutContainer_G260.java | 1 - .../layout/LayoutContainer_G31.java | 16 ++--- .../layout/LayoutContainer_I.java | 14 ++--- .../layout/LayoutContainer_K.java | 16 ++--- .../layout/LayoutContainer_KD.java | 16 ++--- .../layout/LayoutContainer_K_Swiss.java | 5 -- .../LayoutContainer_K_Swiss_Airforce.java | 5 -- .../layout/LayoutContainer_R.java | 14 ++--- .../layout/LayoutContainer_T.java | 14 ++--- .../layout/PassphraseDialogBuilder.java | 6 +- .../layout/PluggableDialogBuilder.java | 36 +++++------ .../layout/RingSettingsDialogBuilder.java | 6 +- app/src/main/res/menu/main.xml | 61 +++++++++++-------- app/src/main/res/values-de/strings.xml | 2 - .../main/res/values-de/strings_whatsnew.xml | 4 ++ app/src/main/res/values/strings.xml | 9 --- app/src/main/res/values/strings_whatsnew.xml | 13 ++++ 41 files changed, 249 insertions(+), 251 deletions(-) create mode 100644 app/src/main/res/values-de/strings_whatsnew.xml create mode 100644 app/src/main/res/values/strings_whatsnew.xml diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ae5cf45..536185d 100755 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -12,6 +12,8 @@ v1.0.0-not-yet-released< *Added Whats-new-Dialog *New Icon! *Added Script to automatically generate icons +*Reformated code +*TODO: Add tips on long clicks at parts *TODO?: Move KD right below K *TODO?: Add intent filters to recognize and automatically handle shared/copied configuration Strings TODO: These are Strings starting with "EnigmAndroid/" diff --git a/app/app.iml b/app/app.iml index c183b64..6d9ebd4 100644 --- a/app/app.iml +++ b/app/app.iml @@ -71,7 +71,7 @@ - + @@ -89,7 +89,7 @@ - - + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d57b91b..c7dfe9a 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,5 +19,5 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:support-v4:23.0.1' + compile 'com.android.support:support-v4:23.1.0' } diff --git a/app/src/main/java/com/google/zxing/integration/android/IntentIntegrator.java b/app/src/main/java/com/google/zxing/integration/android/IntentIntegrator.java index 231d4d9..2a59e5c 100644 --- a/app/src/main/java/com/google/zxing/integration/android/IntentIntegrator.java +++ b/app/src/main/java/com/google/zxing/integration/android/IntentIntegrator.java @@ -147,7 +147,7 @@ public class IntentIntegrator { private String buttonYes; private String buttonNo; private List targetApplications; - private final Map moreExtras = new HashMap(3); + private final Map moreExtras = new HashMap<>(3); /** * @param activity {@link Activity} invoking the integration diff --git a/app/src/main/java/com/google/zxing/integration/android/IntentResult.java b/app/src/main/java/com/google/zxing/integration/android/IntentResult.java index 2469af9..9e452fb 100644 --- a/app/src/main/java/com/google/zxing/integration/android/IntentResult.java +++ b/app/src/main/java/com/google/zxing/integration/android/IntentResult.java @@ -82,14 +82,8 @@ public final class IntentResult { @Override public String toString() { - StringBuilder dialogText = new StringBuilder(100); - dialogText.append("Format: ").append(formatName).append('\n'); - dialogText.append("Contents: ").append(contents).append('\n'); int rawBytesLength = rawBytes == null ? 0 : rawBytes.length; - dialogText.append("Raw bytes: (").append(rawBytesLength).append(" bytes)\n"); - dialogText.append("Orientation: ").append(orientation).append('\n'); - dialogText.append("EC level: ").append(errorCorrectionLevel).append('\n'); - return dialogText.toString(); + return "Format: "+formatName+'\n'+"Contents: "+contents+'\n'+"Raw bytes: ("+rawBytesLength+" bytes)\n"+"Orientation: "+orientation+'\n'+"EC level: "+errorCorrectionLevel+'\n'; } } diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/MainActivity.java b/app/src/main/java/de/vanitasvitae/enigmandroid/MainActivity.java index a13a52d..1ece87b 100755 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/MainActivity.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/MainActivity.java @@ -104,11 +104,6 @@ public class MainActivity extends Activity } } - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - } - public SecureRandom getSecureRandom() { return this.secureRandom; diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/SettingsActivity.java b/app/src/main/java/de/vanitasvitae/enigmandroid/SettingsActivity.java index 130779f..7ea971b 100755 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/SettingsActivity.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/SettingsActivity.java @@ -42,8 +42,8 @@ public class SettingsActivity extends PreferenceActivity private boolean previousPrefReplaceSpecialCharacters; private String previousPrefSavedEnigmaState; - SharedPreferences prefs; - Resources res; + private SharedPreferences prefs; + private Resources res; @Override protected void onCreate(Bundle savedInstanceState) @@ -106,11 +106,14 @@ public class SettingsActivity extends PreferenceActivity return false; } + /** + * Return whether special characters will be replaced. + * If the SettingsActivity is not fully initialized return false and ignore preference. + * @return boolean + */ public boolean getPrefReplaceSpecialCharacters() { - if (isFullyInitilaized()) - return prefs.getBoolean(PREF_REPLACE_SPECIAL_CHARACTERS, true); - else return false; + return isFullyInitilaized() && prefs.getBoolean(PREF_REPLACE_SPECIAL_CHARACTERS, true); } public void setPrefReplaceSpecialCharacters(boolean replace) diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma.java index 23d1ac1..3f5cfed 100755 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma.java @@ -31,17 +31,17 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor; */ public abstract class Enigma { - protected static String machineType; + static String machineType; - protected boolean doAnomaly = false; //Has the time come to handle an anomaly? + boolean doAnomaly = false; //Has the time come to handle an anomaly? - protected ArrayList availableEntryWheels; - protected ArrayList availableRotors; - protected ArrayList availableReflectors; + ArrayList availableEntryWheels; + ArrayList availableRotors; + ArrayList availableReflectors; - protected Random rand; + Random rand; - public Enigma() + Enigma() { establishAvailableParts(); initialize(); @@ -57,19 +57,19 @@ public abstract class Enigma * Also set the index of the Rotor. * @param r Rotor */ - protected void addAvailableRotor(Rotor r) + void addAvailableRotor(Rotor r) { if(availableRotors == null) availableRotors = new ArrayList<>(); availableRotors.add(availableRotors.size(), r.setIndex(availableRotors.size())); } - protected void addAvailableEntryWheel(EntryWheel e) + void addAvailableEntryWheel(EntryWheel e) { if(availableEntryWheels == null) availableEntryWheels = new ArrayList<>(); availableEntryWheels.add(availableEntryWheels.size(), e.setIndex(availableEntryWheels.size())); } - protected void addAvailableReflector(Reflector r) + void addAvailableReflector(Reflector r) { if(availableReflectors == null) availableReflectors = new ArrayList<>(); availableReflectors.add(availableReflectors.size(), r.setIndex(availableReflectors.size())); @@ -90,30 +90,30 @@ public abstract class Enigma return availableReflectors; } - public EntryWheel getEntryWheel(int index) + EntryWheel getEntryWheel(int index) { if(availableEntryWheels == null || availableEntryWheels.size() == 0) return null; return availableEntryWheels.get(index % availableEntryWheels.size()).getInstance(); } - public Rotor getRotor(int index) + Rotor getRotor(int index) { if(availableRotors == null || availableRotors.size() == 0) return null; return availableRotors.get(index % availableRotors.size()).getInstance(); } - public Rotor getRotor(int index, int rotation, int ringSetting) + Rotor getRotor(int index, int rotation, int ringSetting) { return getRotor(index).setRotation(rotation).setRingSetting(ringSetting); } - public Reflector getReflector(int index) + Reflector getReflector(int index) { if(availableReflectors == null || availableReflectors.size() == 0) return null; return availableReflectors.get(index%availableReflectors.size()).getInstance(); } - public Reflector getReflector(int index, int rotation, int ringSetting) + Reflector getReflector(int index, int rotation, int ringSetting) { return getReflector(index).setRotation(rotation).setRingSetting(ringSetting); } @@ -121,7 +121,7 @@ public abstract class Enigma /** * Set the enigma to an initial state */ - public abstract void initialize(); + protected abstract void initialize(); /** * Encrypt / Decrypt a given String w. @@ -177,7 +177,7 @@ public abstract class Enigma * @param k input char * @return substituted output char */ - public abstract char encryptChar(char k); + protected abstract char encryptChar(char k); /** * Set the state of the enigma @@ -208,9 +208,9 @@ public abstract class Enigma { return getEncodedState(MainActivity.latest_protocol_version); } - public abstract BigInteger getEncodedState(int protocol_version); + protected abstract BigInteger getEncodedState(int protocol_version); - public static String numToMachineType(int n) + private static String numToMachineType(int n) { int m = 13; n = (m+(n+m)%m)%m; //Problem? Trolololo diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_D.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_D.java index 550b93c..bce6a04 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_D.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_D.java @@ -32,11 +32,11 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor; */ public class Enigma_D extends Enigma { - protected EntryWheel entryWheel; - protected Rotor rotor1; - protected Rotor rotor2; - protected Rotor rotor3; - protected Reflector reflector; + private EntryWheel entryWheel; + private Rotor rotor1; + private Rotor rotor2; + private Rotor rotor3; + private Reflector reflector; public Enigma_D() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G31.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G31.java index a210db7..90d8cea 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G31.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_G31.java @@ -30,11 +30,11 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor; */ public class Enigma_G31 extends Enigma { - protected EntryWheel entryWheel; - protected Rotor rotor1; - protected Rotor rotor2; - protected Rotor rotor3; - protected Reflector reflector; + private EntryWheel entryWheel; + Rotor rotor1; + Rotor rotor2; + Rotor rotor3; + Reflector reflector; public Enigma_G31() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_I.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_I.java index bb5a346..6590202 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_I.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_I.java @@ -31,13 +31,13 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor; */ public class Enigma_I extends Enigma { - protected EntryWheel entryWheel; - protected Rotor rotor1; - protected Rotor rotor2; - protected Rotor rotor3; - protected Reflector reflector; + EntryWheel entryWheel; + Rotor rotor1; + Rotor rotor2; + Rotor rotor3; + Reflector reflector; - protected Plugboard plugboard; + Plugboard plugboard; public Enigma_I() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K.java index 04f62cd..d57a953 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_K.java @@ -30,11 +30,11 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor; */ public class Enigma_K extends Enigma { - protected EntryWheel entryWheel; - protected Rotor rotor1; - protected Rotor rotor2; - protected Rotor rotor3; - protected Reflector reflector; + private EntryWheel entryWheel; + Rotor rotor1; + Rotor rotor2; + Rotor rotor3; + Reflector reflector; public Enigma_K() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_KD.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_KD.java index 98f27a3..c491835 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_KD.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_KD.java @@ -32,11 +32,11 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor; */ public class Enigma_KD extends Enigma { - protected EntryWheel entryWheel; - protected Rotor rotor1; - protected Rotor rotor2; - protected Rotor rotor3; - protected Reflector reflector; + private EntryWheel entryWheel; + private Rotor rotor1; + private Rotor rotor2; + private Rotor rotor3; + private Reflector reflector; public Enigma_KD() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_M4.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_M4.java index caf28f3..003a6f1 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_M4.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_M4.java @@ -51,19 +51,19 @@ public class Enigma_M4 extends Enigma Log.d(MainActivity.APP_ID, "Created Enigma M4"); } - protected void addAvailableThinRotor(Rotor r) + private void addAvailableThinRotor(Rotor r) { if(availableThinRotors == null) availableThinRotors = new ArrayList<>(); availableThinRotors.add(availableThinRotors.size(), r.setIndex(availableThinRotors.size())); } - public Rotor getThinRotor(int index) + private Rotor getThinRotor(int index) { if(availableThinRotors == null || availableThinRotors.size() == 0) return null; return availableThinRotors.get(index % availableThinRotors.size()).getInstance(); } - public Rotor getThinRotor(int index, int rotation, int ringSettings) + private Rotor getThinRotor(int index, int rotation, int ringSettings) { Rotor r = getThinRotor(index); if(r == null) return null; diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_R.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_R.java index 634077d..efe00fb 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_R.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_R.java @@ -30,12 +30,12 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor; */ public class Enigma_R extends Enigma { - protected EntryWheel entryWheel; - protected Rotor rotor1; - protected Rotor rotor2; - protected Rotor rotor3; + private EntryWheel entryWheel; + private Rotor rotor1; + private Rotor rotor2; + private Rotor rotor3; - protected Reflector reflector; + private Reflector reflector; public Enigma_R() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_T.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_T.java index e6776a7..b9e3f04 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_T.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/Enigma_T.java @@ -30,11 +30,11 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor; */ public class Enigma_T extends Enigma { - protected EntryWheel entryWheel; - protected Rotor rotor1; - protected Rotor rotor2; - protected Rotor rotor3; - protected Reflector reflector; + private EntryWheel entryWheel; + private Rotor rotor1; + private Rotor rotor2; + private Rotor rotor3; + private Reflector reflector; public Enigma_T() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/inputPreparer/EditTextAdapter.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/inputPreparer/EditTextAdapter.java index 89bf6d1..c530aea 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/inputPreparer/EditTextAdapter.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/inputPreparer/EditTextAdapter.java @@ -8,10 +8,10 @@ import android.widget.EditText; */ public abstract class EditTextAdapter { - protected EditText editText; - protected String content; + EditText editText; + String content; - public EditTextAdapter(EditText editText) + EditTextAdapter(EditText editText) { this.editText = editText; } @@ -79,7 +79,7 @@ public abstract class EditTextAdapter public static class EditTextAdapterGap extends EditTextAdapter { - protected int blockSize; + int blockSize; public EditTextAdapterGap(EditText editText, int blockSize) { super(editText); diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/inputPreparer/InputPreparer.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/inputPreparer/InputPreparer.java index e0d4c52..4cb83d5 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/inputPreparer/InputPreparer.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/inputPreparer/InputPreparer.java @@ -27,7 +27,7 @@ import de.vanitasvitae.enigmandroid.SettingsActivity; * @author vanitasvitae */ public abstract class InputPreparer { - protected InputPreparer child; + InputPreparer child; public String prepareString(String in) { if (child != null) diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/EntryWheel.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/EntryWheel.java index 536d850..0874c9b 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/EntryWheel.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/EntryWheel.java @@ -20,14 +20,14 @@ package de.vanitasvitae.enigmandroid.enigma.parts; */ public class EntryWheel { - protected int type; - protected String name; - protected int index; - protected String summary; - protected Integer[] connections; - protected Integer[] reversedConnections; + private final int type; + private final String name; + private int index; + private final String summary; + private final Integer[] connections; + private final Integer[] reversedConnections; - public EntryWheel(int type, String name, String summary, Integer[] connections, Integer[] reversedConnections) + EntryWheel(int type, String name, String summary, Integer[] connections, Integer[] reversedConnections) { this.type = type; this.name = name; @@ -56,7 +56,7 @@ public class EntryWheel return this.connections[normalize(input)]; } - public int normalize(int input) + private int normalize(int input) { return (input+this.connections.length)%this.connections.length; } @@ -83,7 +83,7 @@ public class EntryWheel return this.reversedConnections[normalize(input)]; } - public EntryWheel createEntryWheel(int type) + private EntryWheel createEntryWheel(int type) { switch(type) { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Plugboard.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Plugboard.java index 70a4d17..3264b6a 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Plugboard.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Plugboard.java @@ -49,6 +49,7 @@ public class Plugboard this.plugs = conf; } + @SuppressWarnings("UnusedReturnValue") public BigInteger setConfiguration(BigInteger b) { String s = ""; @@ -175,7 +176,7 @@ public class Plugboard * @param c array * @return String representation */ - public static String configurationToString(int[] c) + private static String configurationToString(int[] c) { String out = ""; for(int i=0; i ReflectorB * @return Reflector */ - public static Reflector createReflector(int type) + private static Reflector createReflector(int type) { switch (type) { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Rotor.java b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Rotor.java index b864e69..99de65c 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Rotor.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/enigma/parts/Rotor.java @@ -31,31 +31,31 @@ import de.vanitasvitae.enigmandroid.MainActivity; public abstract class Rotor { /** Number of the rotor (used internally to create the Rotor via createRotor() ) */ - protected int type; + private final int type; /** Identifier of the Rotor */ - protected String name; + private final String name; /** Index of the Rotor in the parent machine's selection Spinner */ - protected int index; + private int index; /** Summary of the connections (internal wiring) */ - protected String summary; + private final String summary; /** Wiring of the rotor when the signal passes the first time */ - protected Integer[] connections; + private final Integer[] connections; /** Wiring of the rotor when the signal passes the second time (inverse of the first time) */ - protected Integer[] reversedConnections; + private final Integer[] reversedConnections; /** When the Rotor is at this Position and jumps one over, it also turns the next */ - protected Integer[] turnOverNotches; + private final Integer[] turnOverNotches; /** Offset of the labeled ring of the rotor */ - protected int ringSetting; + private int ringSetting; /** Rotation of the rotor */ - protected int rotation; + private int rotation; /** * This constructor is not accessible from outside this class file. @@ -72,8 +72,8 @@ public abstract class Rotor * @param ringSetting setting of the ring that holds the letters * @param rotation rotation of the rotor */ - protected Rotor(int type, String name, String summary, Integer[] connections, Integer[] reversedConnections, - Integer[] turnOverNotches, int ringSetting, int rotation) + Rotor(int type, String name, String summary, Integer[] connections, Integer[] reversedConnections, + Integer[] turnOverNotches, int ringSetting, int rotation) { this.type = type; this.name = name; @@ -289,7 +289,7 @@ public abstract class Rotor * Returns the positions of the turnover notches in a array * @return turnOverNotches */ - public Integer[] getTurnOverNotches() + private Integer[] getTurnOverNotches() { return this.turnOverNotches; } @@ -309,7 +309,7 @@ public abstract class Rotor * of the rotor * @return size */ - public int getRotorSize() + private int getRotorSize() { return this.connections.length; } diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer.java index 87e4ca3..37a8083 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer.java @@ -1,7 +1,5 @@ package de.vanitasvitae.enigmandroid.layout; -import android.text.Editable; -import android.text.TextWatcher; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.Spinner; @@ -36,19 +34,19 @@ import de.vanitasvitae.enigmandroid.enigma.inputPreparer.InputPreparer; */ public abstract class LayoutContainer { - protected EditText inputView; - protected EditText outputView; + final EditText inputView; + private final EditText outputView; - protected EditTextAdapter input; - protected EditTextAdapter output; + EditTextAdapter input; + EditTextAdapter output; - protected InputPreparer inputPreparer; - protected MainActivity main; + InputPreparer inputPreparer; + final MainActivity main; public abstract Enigma getEnigma(); protected abstract void assembleLayout(); public abstract void resetLayout(); - public abstract void setLayoutState(EnigmaStateBundle state); + protected abstract void setLayoutState(EnigmaStateBundle state); public abstract void syncStateFromLayoutToEnigma(); public void syncStateFromEnigmaToLayout() { @@ -56,7 +54,7 @@ public abstract class LayoutContainer } public abstract void showRingSettingsDialog(); - public LayoutContainer() + LayoutContainer() { main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity(); setEnigmaLayout(); @@ -99,7 +97,7 @@ public abstract class LayoutContainer return createLayoutContainer(SettingsActivity.SettingsSingleton.getInstance().getPrefMachineType()); } - public static LayoutContainer createLayoutContainer(String enigmaType) + private static LayoutContainer createLayoutContainer(String enigmaType) { switch (enigmaType) { case "I": @@ -138,7 +136,7 @@ public abstract class LayoutContainer * @param view Spinner * @param resourceID ID of the referenced array (eg. R.array.rotor_1_8) */ - protected void prepareSpinnerAdapter(Spinner view, int resourceID) { + void prepareSpinnerAdapter(Spinner view, int resourceID) { MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity(); ArrayAdapter adapter = ArrayAdapter.createFromResource(main, resourceID, @@ -152,7 +150,7 @@ public abstract class LayoutContainer * @param view Spinner * @param array Character array */ - protected void prepareSpinnerAdapter(Spinner view, Character[] array) + void prepareSpinnerAdapter(Spinner view, Character[] array) { MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity(); ArrayAdapter adapter = new ArrayAdapter<>(main.getApplicationContext(), diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_D.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_D.java index 2ffb0bd..45a4477 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_D.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_D.java @@ -33,10 +33,10 @@ public class LayoutContainer_D extends LayoutContainer { private Enigma_D enigma; - protected Spinner rotor1PositionView; - protected Spinner rotor2PositionView; - protected Spinner rotor3PositionView; - protected Spinner reflectorPositionView; + private Spinner rotor1PositionView; + private Spinner rotor2PositionView; + private Spinner rotor3PositionView; + private Spinner reflectorPositionView; public LayoutContainer_D() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G260.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G260.java index 8c46664..24c968c 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G260.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G260.java @@ -1,6 +1,5 @@ package de.vanitasvitae.enigmandroid.layout; -import de.vanitasvitae.enigmandroid.R; import de.vanitasvitae.enigmandroid.enigma.Enigma_G260; /** diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G31.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G31.java index a1c49ea..53b7268 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G31.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_G31.java @@ -30,16 +30,16 @@ import de.vanitasvitae.enigmandroid.enigma.Enigma_G31; */ public class LayoutContainer_G31 extends LayoutContainer { - protected Enigma enigma; + Enigma enigma; - protected Spinner rotor1View; - protected Spinner rotor2View; - protected Spinner rotor3View; + private Spinner rotor1View; + private Spinner rotor2View; + private Spinner rotor3View; - protected Spinner rotor1PositionView; - protected Spinner rotor2PositionView; - protected Spinner rotor3PositionView; - protected Spinner reflectorPositionView; + private Spinner rotor1PositionView; + private Spinner rotor2PositionView; + private Spinner rotor3PositionView; + private Spinner reflectorPositionView; public LayoutContainer_G31() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_I.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_I.java index 46f86d3..c7778d5 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_I.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_I.java @@ -33,13 +33,13 @@ public class LayoutContainer_I extends LayoutContainer { private Enigma_I enigma; - protected Spinner rotor1View; - protected Spinner rotor2View; - protected Spinner rotor3View; - protected Spinner reflectorView; - protected Spinner rotor1PositionView; - protected Spinner rotor2PositionView; - protected Spinner rotor3PositionView; + Spinner rotor1View; + Spinner rotor2View; + Spinner rotor3View; + Spinner reflectorView; + Spinner rotor1PositionView; + Spinner rotor2PositionView; + Spinner rotor3PositionView; public LayoutContainer_I() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K.java index f318de4..5ee401d 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K.java @@ -30,16 +30,16 @@ import de.vanitasvitae.enigmandroid.enigma.Enigma_K; */ public class LayoutContainer_K extends LayoutContainer { - protected Enigma enigma; + Enigma enigma; - protected Spinner rotor1View; - protected Spinner rotor2View; - protected Spinner rotor3View; + private Spinner rotor1View; + private Spinner rotor2View; + private Spinner rotor3View; - protected Spinner rotor1PositionView; - protected Spinner rotor2PositionView; - protected Spinner rotor3PositionView; - protected Spinner reflectorPositionView; + private Spinner rotor1PositionView; + private Spinner rotor2PositionView; + private Spinner rotor3PositionView; + private Spinner reflectorPositionView; public LayoutContainer_K() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_KD.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_KD.java index e34407f..022bca7 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_KD.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_KD.java @@ -32,16 +32,16 @@ import de.vanitasvitae.enigmandroid.enigma.Enigma_KD; */ public class LayoutContainer_KD extends LayoutContainer { - protected Enigma enigma; + private Enigma enigma; - protected Spinner rotor1View; - protected Spinner rotor2View; - protected Spinner rotor3View; + private Spinner rotor1View; + private Spinner rotor2View; + private Spinner rotor3View; - protected Spinner rotor1PositionView; - protected Spinner rotor2PositionView; - protected Spinner rotor3PositionView; - protected Spinner reflectorPositionView; + private Spinner rotor1PositionView; + private Spinner rotor2PositionView; + private Spinner rotor3PositionView; + private Spinner reflectorPositionView; public LayoutContainer_KD() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss.java index 77e188f..f4d16a3 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss.java @@ -1,10 +1,5 @@ package de.vanitasvitae.enigmandroid.layout; -import android.widget.Spinner; - -import de.vanitasvitae.enigmandroid.R; -import de.vanitasvitae.enigmandroid.enigma.Enigma; -import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle; import de.vanitasvitae.enigmandroid.enigma.Enigma_K_Swiss_Standard; /** diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss_Airforce.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss_Airforce.java index 14790a7..62a77d4 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss_Airforce.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_K_Swiss_Airforce.java @@ -1,10 +1,5 @@ package de.vanitasvitae.enigmandroid.layout; -import android.widget.Spinner; - -import de.vanitasvitae.enigmandroid.R; -import de.vanitasvitae.enigmandroid.enigma.Enigma; -import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle; import de.vanitasvitae.enigmandroid.enigma.Enigma_K_Swiss_Airforce; /** diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_R.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_R.java index 96ffc6e..adba852 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_R.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_R.java @@ -32,14 +32,14 @@ public class LayoutContainer_R extends LayoutContainer { private Enigma_R enigma; - protected Spinner rotor1View; - protected Spinner rotor2View; - protected Spinner rotor3View; + private Spinner rotor1View; + private Spinner rotor2View; + private Spinner rotor3View; - protected Spinner rotor1PositionView; - protected Spinner rotor2PositionView; - protected Spinner rotor3PositionView; - protected Spinner reflectorPositionView; + private Spinner rotor1PositionView; + private Spinner rotor2PositionView; + private Spinner rotor3PositionView; + private Spinner reflectorPositionView; public LayoutContainer_R() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_T.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_T.java index ca91e3d..8a0f1c1 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_T.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/LayoutContainer_T.java @@ -32,14 +32,14 @@ public class LayoutContainer_T extends LayoutContainer { private Enigma_T enigma; - protected Spinner rotor1View; - protected Spinner rotor2View; - protected Spinner rotor3View; + private Spinner rotor1View; + private Spinner rotor2View; + private Spinner rotor3View; - protected Spinner rotor1PositionView; - protected Spinner rotor2PositionView; - protected Spinner rotor3PositionView; - protected Spinner reflectorPositionView; + private Spinner rotor1PositionView; + private Spinner rotor2PositionView; + private Spinner rotor3PositionView; + private Spinner reflectorPositionView; public LayoutContainer_T() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/PassphraseDialogBuilder.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/PassphraseDialogBuilder.java index cadc9af..59c9bef 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/PassphraseDialogBuilder.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/PassphraseDialogBuilder.java @@ -37,9 +37,9 @@ import de.vanitasvitae.enigmandroid.R; */ public class PassphraseDialogBuilder { - private MainActivity main; - private View passphraseDialogView; - private EditText passphrase; + private final MainActivity main; + private final View passphraseDialogView; + private final EditText passphrase; private Button positive; public PassphraseDialogBuilder() { diff --git a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/PluggableDialogBuilder.java b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/PluggableDialogBuilder.java index d32f504..7685e90 100644 --- a/app/src/main/java/de/vanitasvitae/enigmandroid/layout/PluggableDialogBuilder.java +++ b/app/src/main/java/de/vanitasvitae/enigmandroid/layout/PluggableDialogBuilder.java @@ -37,19 +37,19 @@ import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * @author vanitasvitae */ -public class PluggableDialogBuilder +class PluggableDialogBuilder { - protected ArrayList buttons; - protected View dialogView; - protected MainActivity main; - protected EnigmaStateBundle state; + private ArrayList buttons; + private View dialogView; + private final MainActivity main; + private final EnigmaStateBundle state; - protected boolean allowIncompleteConnections; - protected Button positive; + private boolean allowIncompleteConnections; + private Button positive; - protected HashSet colors; + private HashSet colors; - protected int previouslyPressedButton = -1; + private int previouslyPressedButton = -1; /** * Constructor that prepares layout and buttons. @@ -148,7 +148,7 @@ public class PluggableDialogBuilder /** * Initialize array of buttons, initialize background-color hashset. */ - public void initializeLayout() + private void initializeLayout() { buttons = new ArrayList<>(); dialogView = View.inflate(main, R.layout.dialog_plugs, null); @@ -199,7 +199,7 @@ public class PluggableDialogBuilder /** * Set listeners for all buttons */ - public void setButtonListeners() + private void setButtonListeners() { for(int i=0; i<26; i++) { @@ -219,7 +219,7 @@ public class PluggableDialogBuilder * return false otherwise * @return boolean */ - protected boolean allConnectionsDone() + private boolean allConnectionsDone() { for(int i=0; i( MainActivity.ActivitySingleton.getInstance().getActivity(), @@ -50,7 +50,7 @@ public abstract class RingSettingsDialogBuilder * Creates a ArrayAdapter working over an array of numbers 1 to 26. * @return ArrayAdapter */ - public static ArrayAdapter createAdapter1_26() + private static ArrayAdapter createAdapter1_26() { Integer[] ringArray = new Integer[26]; for(int i=1; i<=26; i++) {ringArray[i-1] = i;} @@ -365,7 +365,7 @@ public abstract class RingSettingsDialogBuilder */ public static abstract class Actions { - protected EnigmaStateBundle stateBundle; + final EnigmaStateBundle stateBundle; public Actions(EnigmaStateBundle bundle) { this.stateBundle = bundle; diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml index f2ddc17..eb29514 100755 --- a/app/src/main/res/menu/main.xml +++ b/app/src/main/res/menu/main.xml @@ -1,46 +1,55 @@ + xmlns:tools="http://schemas.android.com/tools" + tools:context=".MainActivity" + tools:ignore="UnusedAttribute"> - + android:title="@string/action_reset"/> - + android:title="@string/action_send"/> - - - + android:title="@string/action_choose_ring_settings"/> + + - + - + android:title="@string/action_random"/> - + android:showAsAction="ifRoom" + android:title="@string/action_settings"/> - + android:showAsAction="ifRoom" + android:title="@string/title_action_about"/> diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index f9836ca..c2785e3 100755 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -51,6 +51,4 @@ Enigma auf zufällige Konfiguration gesetzt. In Zwischenablage kopiert - Was ist neu? - diff --git a/app/src/main/res/values-de/strings_whatsnew.xml b/app/src/main/res/values-de/strings_whatsnew.xml new file mode 100644 index 0000000..1e07276 --- /dev/null +++ b/app/src/main/res/values-de/strings_whatsnew.xml @@ -0,0 +1,4 @@ + + + Was ist neu? + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0e2b268..3fe3734 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,15 +48,6 @@ Enigma set to random configuration. Copied to clipboard - What\'s new? - %1$s: - - - This splash screen! - \n- Protocol-versioning to ensure compatibility to upcoming releases/new functions\n - Unfortunately we had to break backwards compatibility to older versions :/ - \n- Enigma KD\n - - %1$s:%2$s diff --git a/app/src/main/res/values/strings_whatsnew.xml b/app/src/main/res/values/strings_whatsnew.xml new file mode 100644 index 0000000..a3ea7b5 --- /dev/null +++ b/app/src/main/res/values/strings_whatsnew.xml @@ -0,0 +1,13 @@ + + + What\'s new? + %1$s: + + - This splash screen! + \n- Protocol-versioning to ensure compatibility to upcoming releases/new functions.\n + Unfortunately we had to break backwards compatibility to older versions :/ + \n- Enigma KD! + \n- New Icon! + + + \ No newline at end of file