Cleaned code

This commit is contained in:
VanitasVitae 2015-11-07 16:42:24 +01:00
parent c938b745bc
commit 1ee60d1e5e
41 changed files with 249 additions and 251 deletions

View file

@ -12,6 +12,8 @@ v1.0.0-not-yet-released<
*Added Whats-new-Dialog *Added Whats-new-Dialog
*New Icon! *New Icon!
*Added Script to automatically generate icons *Added Script to automatically generate icons
*Reformated code
*TODO: Add tips on long clicks at parts
*TODO?: Move KD right below K *TODO?: Move KD right below K
*TODO?: Add intent filters to recognize and automatically handle shared/copied configuration Strings *TODO?: Add intent filters to recognize and automatically handle shared/copied configuration Strings
TODO: These are Strings starting with "EnigmAndroid/" TODO: These are Strings starting with "EnigmAndroid/"

View file

@ -71,7 +71,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
@ -89,7 +89,7 @@
</content> </content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" /> <orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" /> <orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" /> <orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" />
</component> </component>
</module> </module>

View file

@ -19,5 +19,5 @@ android {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:23.0.1' compile 'com.android.support:support-v4:23.1.0'
} }

View file

@ -147,7 +147,7 @@ public class IntentIntegrator {
private String buttonYes; private String buttonYes;
private String buttonNo; private String buttonNo;
private List<String> targetApplications; private List<String> targetApplications;
private final Map<String,Object> moreExtras = new HashMap<String,Object>(3); private final Map<String,Object> moreExtras = new HashMap<>(3);
/** /**
* @param activity {@link Activity} invoking the integration * @param activity {@link Activity} invoking the integration

View file

@ -82,14 +82,8 @@ public final class IntentResult {
@Override @Override
public String toString() { 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; int rawBytesLength = rawBytes == null ? 0 : rawBytes.length;
dialogText.append("Raw bytes: (").append(rawBytesLength).append(" bytes)\n"); return "Format: "+formatName+'\n'+"Contents: "+contents+'\n'+"Raw bytes: ("+rawBytesLength+" bytes)\n"+"Orientation: "+orientation+'\n'+"EC level: "+errorCorrectionLevel+'\n';
dialogText.append("Orientation: ").append(orientation).append('\n');
dialogText.append("EC level: ").append(errorCorrectionLevel).append('\n');
return dialogText.toString();
} }
} }

View file

@ -104,11 +104,6 @@ public class MainActivity extends Activity
} }
} }
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
public SecureRandom getSecureRandom() public SecureRandom getSecureRandom()
{ {
return this.secureRandom; return this.secureRandom;

View file

@ -42,8 +42,8 @@ public class SettingsActivity extends PreferenceActivity
private boolean previousPrefReplaceSpecialCharacters; private boolean previousPrefReplaceSpecialCharacters;
private String previousPrefSavedEnigmaState; private String previousPrefSavedEnigmaState;
SharedPreferences prefs; private SharedPreferences prefs;
Resources res; private Resources res;
@Override @Override
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
@ -106,11 +106,14 @@ public class SettingsActivity extends PreferenceActivity
return false; 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() public boolean getPrefReplaceSpecialCharacters()
{ {
if (isFullyInitilaized()) return isFullyInitilaized() && prefs.getBoolean(PREF_REPLACE_SPECIAL_CHARACTERS, true);
return prefs.getBoolean(PREF_REPLACE_SPECIAL_CHARACTERS, true);
else return false;
} }
public void setPrefReplaceSpecialCharacters(boolean replace) public void setPrefReplaceSpecialCharacters(boolean replace)

View file

@ -31,17 +31,17 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
*/ */
public abstract class Enigma 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<EntryWheel> availableEntryWheels; ArrayList<EntryWheel> availableEntryWheels;
protected ArrayList<Rotor> availableRotors; ArrayList<Rotor> availableRotors;
protected ArrayList<Reflector> availableReflectors; ArrayList<Reflector> availableReflectors;
protected Random rand; Random rand;
public Enigma() Enigma()
{ {
establishAvailableParts(); establishAvailableParts();
initialize(); initialize();
@ -57,19 +57,19 @@ public abstract class Enigma
* Also set the index of the Rotor. * Also set the index of the Rotor.
* @param r Rotor * @param r Rotor
*/ */
protected void addAvailableRotor(Rotor r) void addAvailableRotor(Rotor r)
{ {
if(availableRotors == null) availableRotors = new ArrayList<>(); if(availableRotors == null) availableRotors = new ArrayList<>();
availableRotors.add(availableRotors.size(), r.setIndex(availableRotors.size())); availableRotors.add(availableRotors.size(), r.setIndex(availableRotors.size()));
} }
protected void addAvailableEntryWheel(EntryWheel e) void addAvailableEntryWheel(EntryWheel e)
{ {
if(availableEntryWheels == null) availableEntryWheels = new ArrayList<>(); if(availableEntryWheels == null) availableEntryWheels = new ArrayList<>();
availableEntryWheels.add(availableEntryWheels.size(), e.setIndex(availableEntryWheels.size())); availableEntryWheels.add(availableEntryWheels.size(), e.setIndex(availableEntryWheels.size()));
} }
protected void addAvailableReflector(Reflector r) void addAvailableReflector(Reflector r)
{ {
if(availableReflectors == null) availableReflectors = new ArrayList<>(); if(availableReflectors == null) availableReflectors = new ArrayList<>();
availableReflectors.add(availableReflectors.size(), r.setIndex(availableReflectors.size())); availableReflectors.add(availableReflectors.size(), r.setIndex(availableReflectors.size()));
@ -90,30 +90,30 @@ public abstract class Enigma
return availableReflectors; return availableReflectors;
} }
public EntryWheel getEntryWheel(int index) EntryWheel getEntryWheel(int index)
{ {
if(availableEntryWheels == null || availableEntryWheels.size() == 0) return null; if(availableEntryWheels == null || availableEntryWheels.size() == 0) return null;
return availableEntryWheels.get(index % availableEntryWheels.size()).getInstance(); return availableEntryWheels.get(index % availableEntryWheels.size()).getInstance();
} }
public Rotor getRotor(int index) Rotor getRotor(int index)
{ {
if(availableRotors == null || availableRotors.size() == 0) return null; if(availableRotors == null || availableRotors.size() == 0) return null;
return availableRotors.get(index % availableRotors.size()).getInstance(); 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); return getRotor(index).setRotation(rotation).setRingSetting(ringSetting);
} }
public Reflector getReflector(int index) Reflector getReflector(int index)
{ {
if(availableReflectors == null || availableReflectors.size() == 0) return null; if(availableReflectors == null || availableReflectors.size() == 0) return null;
return availableReflectors.get(index%availableReflectors.size()).getInstance(); 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); return getReflector(index).setRotation(rotation).setRingSetting(ringSetting);
} }
@ -121,7 +121,7 @@ public abstract class Enigma
/** /**
* Set the enigma to an initial state * Set the enigma to an initial state
*/ */
public abstract void initialize(); protected abstract void initialize();
/** /**
* Encrypt / Decrypt a given String w. * Encrypt / Decrypt a given String w.
@ -177,7 +177,7 @@ public abstract class Enigma
* @param k input char * @param k input char
* @return substituted output char * @return substituted output char
*/ */
public abstract char encryptChar(char k); protected abstract char encryptChar(char k);
/** /**
* Set the state of the enigma * Set the state of the enigma
@ -208,9 +208,9 @@ public abstract class Enigma
{ {
return getEncodedState(MainActivity.latest_protocol_version); 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; int m = 13;
n = (m+(n+m)%m)%m; //Problem? Trolololo n = (m+(n+m)%m)%m; //Problem? Trolololo

View file

@ -32,11 +32,11 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
*/ */
public class Enigma_D extends Enigma { public class Enigma_D extends Enigma {
protected EntryWheel entryWheel; private EntryWheel entryWheel;
protected Rotor rotor1; private Rotor rotor1;
protected Rotor rotor2; private Rotor rotor2;
protected Rotor rotor3; private Rotor rotor3;
protected Reflector reflector; private Reflector reflector;
public Enigma_D() public Enigma_D()
{ {

View file

@ -30,11 +30,11 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
*/ */
public class Enigma_G31 extends Enigma public class Enigma_G31 extends Enigma
{ {
protected EntryWheel entryWheel; private EntryWheel entryWheel;
protected Rotor rotor1; Rotor rotor1;
protected Rotor rotor2; Rotor rotor2;
protected Rotor rotor3; Rotor rotor3;
protected Reflector reflector; Reflector reflector;
public Enigma_G31() public Enigma_G31()
{ {

View file

@ -31,13 +31,13 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
*/ */
public class Enigma_I extends Enigma public class Enigma_I extends Enigma
{ {
protected EntryWheel entryWheel; EntryWheel entryWheel;
protected Rotor rotor1; Rotor rotor1;
protected Rotor rotor2; Rotor rotor2;
protected Rotor rotor3; Rotor rotor3;
protected Reflector reflector; Reflector reflector;
protected Plugboard plugboard; Plugboard plugboard;
public Enigma_I() public Enigma_I()
{ {

View file

@ -30,11 +30,11 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
*/ */
public class Enigma_K extends Enigma public class Enigma_K extends Enigma
{ {
protected EntryWheel entryWheel; private EntryWheel entryWheel;
protected Rotor rotor1; Rotor rotor1;
protected Rotor rotor2; Rotor rotor2;
protected Rotor rotor3; Rotor rotor3;
protected Reflector reflector; Reflector reflector;
public Enigma_K() public Enigma_K()
{ {

View file

@ -32,11 +32,11 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
*/ */
public class Enigma_KD extends Enigma { public class Enigma_KD extends Enigma {
protected EntryWheel entryWheel; private EntryWheel entryWheel;
protected Rotor rotor1; private Rotor rotor1;
protected Rotor rotor2; private Rotor rotor2;
protected Rotor rotor3; private Rotor rotor3;
protected Reflector reflector; private Reflector reflector;
public Enigma_KD() public Enigma_KD()
{ {

View file

@ -51,19 +51,19 @@ public class Enigma_M4 extends Enigma
Log.d(MainActivity.APP_ID, "Created Enigma M4"); Log.d(MainActivity.APP_ID, "Created Enigma M4");
} }
protected void addAvailableThinRotor(Rotor r) private void addAvailableThinRotor(Rotor r)
{ {
if(availableThinRotors == null) availableThinRotors = new ArrayList<>(); if(availableThinRotors == null) availableThinRotors = new ArrayList<>();
availableThinRotors.add(availableThinRotors.size(), r.setIndex(availableThinRotors.size())); 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; if(availableThinRotors == null || availableThinRotors.size() == 0) return null;
return availableThinRotors.get(index % availableThinRotors.size()).getInstance(); 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); Rotor r = getThinRotor(index);
if(r == null) return null; if(r == null) return null;

View file

@ -30,12 +30,12 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
*/ */
public class Enigma_R extends Enigma public class Enigma_R extends Enigma
{ {
protected EntryWheel entryWheel; private EntryWheel entryWheel;
protected Rotor rotor1; private Rotor rotor1;
protected Rotor rotor2; private Rotor rotor2;
protected Rotor rotor3; private Rotor rotor3;
protected Reflector reflector; private Reflector reflector;
public Enigma_R() public Enigma_R()
{ {

View file

@ -30,11 +30,11 @@ import de.vanitasvitae.enigmandroid.enigma.parts.Rotor;
*/ */
public class Enigma_T extends Enigma public class Enigma_T extends Enigma
{ {
protected EntryWheel entryWheel; private EntryWheel entryWheel;
protected Rotor rotor1; private Rotor rotor1;
protected Rotor rotor2; private Rotor rotor2;
protected Rotor rotor3; private Rotor rotor3;
protected Reflector reflector; private Reflector reflector;
public Enigma_T() public Enigma_T()
{ {

View file

@ -8,10 +8,10 @@ import android.widget.EditText;
*/ */
public abstract class EditTextAdapter public abstract class EditTextAdapter
{ {
protected EditText editText; EditText editText;
protected String content; String content;
public EditTextAdapter(EditText editText) EditTextAdapter(EditText editText)
{ {
this.editText = editText; this.editText = editText;
} }
@ -79,7 +79,7 @@ public abstract class EditTextAdapter
public static class EditTextAdapterGap extends EditTextAdapter public static class EditTextAdapterGap extends EditTextAdapter
{ {
protected int blockSize; int blockSize;
public EditTextAdapterGap(EditText editText, int blockSize) public EditTextAdapterGap(EditText editText, int blockSize)
{ {
super(editText); super(editText);

View file

@ -27,7 +27,7 @@ import de.vanitasvitae.enigmandroid.SettingsActivity;
* @author vanitasvitae * @author vanitasvitae
*/ */
public abstract class InputPreparer { public abstract class InputPreparer {
protected InputPreparer child; InputPreparer child;
public String prepareString(String in) { public String prepareString(String in) {
if (child != null) if (child != null)

View file

@ -20,14 +20,14 @@ package de.vanitasvitae.enigmandroid.enigma.parts;
*/ */
public class EntryWheel public class EntryWheel
{ {
protected int type; private final int type;
protected String name; private final String name;
protected int index; private int index;
protected String summary; private final String summary;
protected Integer[] connections; private final Integer[] connections;
protected Integer[] reversedConnections; 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.type = type;
this.name = name; this.name = name;
@ -56,7 +56,7 @@ public class EntryWheel
return this.connections[normalize(input)]; return this.connections[normalize(input)];
} }
public int normalize(int input) private int normalize(int input)
{ {
return (input+this.connections.length)%this.connections.length; return (input+this.connections.length)%this.connections.length;
} }
@ -83,7 +83,7 @@ public class EntryWheel
return this.reversedConnections[normalize(input)]; return this.reversedConnections[normalize(input)];
} }
public EntryWheel createEntryWheel(int type) private EntryWheel createEntryWheel(int type)
{ {
switch(type) switch(type)
{ {

View file

@ -49,6 +49,7 @@ public class Plugboard
this.plugs = conf; this.plugs = conf;
} }
@SuppressWarnings("UnusedReturnValue")
public BigInteger setConfiguration(BigInteger b) public BigInteger setConfiguration(BigInteger b)
{ {
String s = ""; String s = "";
@ -175,7 +176,7 @@ public class Plugboard
* @param c array * @param c array
* @return String representation * @return String representation
*/ */
public static String configurationToString(int[] c) private static String configurationToString(int[] c)
{ {
String out = ""; String out = "";
for(int i=0; i<c.length; i++) // c.length = 26 (mostly) for(int i=0; i<c.length; i++) // c.length = 26 (mostly)

View file

@ -31,13 +31,13 @@ import de.vanitasvitae.enigmandroid.enigma.Enigma;
*/ */
public class Reflector public class Reflector
{ {
protected int type; private final int type;
protected String name; private final String name;
protected int index; private int index;
protected String summary; private final String summary;
protected int[] connections; private int[] connections;
protected int rotation; private int rotation;
protected int ringSetting; private int ringSetting;
/** /**
* This constructor is not accessible from outside this class file. * This constructor is not accessible from outside this class file.
@ -46,7 +46,7 @@ public class Reflector
* @param type name indicator of the reflector * @param type name indicator of the reflector
* @param connections wiring of the reflector as Integer array * @param connections wiring of the reflector as Integer array
*/ */
protected Reflector(int type, String name, String summary, int[] connections) Reflector(int type, String name, String summary, int[] connections)
{ {
this.type = type; this.type = type;
this.name = name; this.name = name;
@ -106,6 +106,7 @@ public class Reflector
return this; return this;
} }
@SuppressWarnings("UnusedReturnValue")
public BigInteger setConfiguration(BigInteger b) public BigInteger setConfiguration(BigInteger b)
{ {
String s = ""; String s = "";
@ -143,7 +144,7 @@ public class Reflector
* default -> ReflectorB * default -> ReflectorB
* @return Reflector * @return Reflector
*/ */
public static Reflector createReflector(int type) private static Reflector createReflector(int type)
{ {
switch (type) switch (type)
{ {

View file

@ -31,31 +31,31 @@ import de.vanitasvitae.enigmandroid.MainActivity;
public abstract class Rotor public abstract class Rotor
{ {
/** Number of the rotor (used internally to create the Rotor via createRotor() ) */ /** Number of the rotor (used internally to create the Rotor via createRotor() ) */
protected int type; private final int type;
/** Identifier of the Rotor */ /** Identifier of the Rotor */
protected String name; private final String name;
/** Index of the Rotor in the parent machine's selection Spinner */ /** Index of the Rotor in the parent machine's selection Spinner */
protected int index; private int index;
/** Summary of the connections (internal wiring) */ /** Summary of the connections (internal wiring) */
protected String summary; private final String summary;
/** Wiring of the rotor when the signal passes the first time */ /** 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) */ /** 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 */ /** 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 */ /** Offset of the labeled ring of the rotor */
protected int ringSetting; private int ringSetting;
/** Rotation of the rotor */ /** Rotation of the rotor */
protected int rotation; private int rotation;
/** /**
* This constructor is not accessible from outside this class file. * 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 ringSetting setting of the ring that holds the letters
* @param rotation rotation of the rotor * @param rotation rotation of the rotor
*/ */
protected Rotor(int type, String name, String summary, Integer[] connections, Integer[] reversedConnections, Rotor(int type, String name, String summary, Integer[] connections, Integer[] reversedConnections,
Integer[] turnOverNotches, int ringSetting, int rotation) Integer[] turnOverNotches, int ringSetting, int rotation)
{ {
this.type = type; this.type = type;
this.name = name; this.name = name;
@ -289,7 +289,7 @@ public abstract class Rotor
* Returns the positions of the turnover notches in a array * Returns the positions of the turnover notches in a array
* @return turnOverNotches * @return turnOverNotches
*/ */
public Integer[] getTurnOverNotches() private Integer[] getTurnOverNotches()
{ {
return this.turnOverNotches; return this.turnOverNotches;
} }
@ -309,7 +309,7 @@ public abstract class Rotor
* of the rotor * of the rotor
* @return size * @return size
*/ */
public int getRotorSize() private int getRotorSize()
{ {
return this.connections.length; return this.connections.length;
} }

View file

@ -1,7 +1,5 @@
package de.vanitasvitae.enigmandroid.layout; package de.vanitasvitae.enigmandroid.layout;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
@ -36,19 +34,19 @@ import de.vanitasvitae.enigmandroid.enigma.inputPreparer.InputPreparer;
*/ */
public abstract class LayoutContainer public abstract class LayoutContainer
{ {
protected EditText inputView; final EditText inputView;
protected EditText outputView; private final EditText outputView;
protected EditTextAdapter input; EditTextAdapter input;
protected EditTextAdapter output; EditTextAdapter output;
protected InputPreparer inputPreparer; InputPreparer inputPreparer;
protected MainActivity main; final MainActivity main;
public abstract Enigma getEnigma(); public abstract Enigma getEnigma();
protected abstract void assembleLayout(); protected abstract void assembleLayout();
public abstract void resetLayout(); public abstract void resetLayout();
public abstract void setLayoutState(EnigmaStateBundle state); protected abstract void setLayoutState(EnigmaStateBundle state);
public abstract void syncStateFromLayoutToEnigma(); public abstract void syncStateFromLayoutToEnigma();
public void syncStateFromEnigmaToLayout() public void syncStateFromEnigmaToLayout()
{ {
@ -56,7 +54,7 @@ public abstract class LayoutContainer
} }
public abstract void showRingSettingsDialog(); public abstract void showRingSettingsDialog();
public LayoutContainer() LayoutContainer()
{ {
main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity(); main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
setEnigmaLayout(); setEnigmaLayout();
@ -99,7 +97,7 @@ public abstract class LayoutContainer
return createLayoutContainer(SettingsActivity.SettingsSingleton.getInstance().getPrefMachineType()); return createLayoutContainer(SettingsActivity.SettingsSingleton.getInstance().getPrefMachineType());
} }
public static LayoutContainer createLayoutContainer(String enigmaType) private static LayoutContainer createLayoutContainer(String enigmaType)
{ {
switch (enigmaType) { switch (enigmaType) {
case "I": case "I":
@ -138,7 +136,7 @@ public abstract class LayoutContainer
* @param view Spinner * @param view Spinner
* @param resourceID ID of the referenced array (eg. R.array.rotor_1_8) * @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(); MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(main, resourceID, ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(main, resourceID,
@ -152,7 +150,7 @@ public abstract class LayoutContainer
* @param view Spinner * @param view Spinner
* @param array Character array * @param array Character array
*/ */
protected void prepareSpinnerAdapter(Spinner view, Character[] array) void prepareSpinnerAdapter(Spinner view, Character[] array)
{ {
MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity(); MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
ArrayAdapter<Character> adapter = new ArrayAdapter<>(main.getApplicationContext(), ArrayAdapter<Character> adapter = new ArrayAdapter<>(main.getApplicationContext(),

View file

@ -33,10 +33,10 @@ public class LayoutContainer_D extends LayoutContainer
{ {
private Enigma_D enigma; private Enigma_D enigma;
protected Spinner rotor1PositionView; private Spinner rotor1PositionView;
protected Spinner rotor2PositionView; private Spinner rotor2PositionView;
protected Spinner rotor3PositionView; private Spinner rotor3PositionView;
protected Spinner reflectorPositionView; private Spinner reflectorPositionView;
public LayoutContainer_D() public LayoutContainer_D()
{ {

View file

@ -1,6 +1,5 @@
package de.vanitasvitae.enigmandroid.layout; package de.vanitasvitae.enigmandroid.layout;
import de.vanitasvitae.enigmandroid.R;
import de.vanitasvitae.enigmandroid.enigma.Enigma_G260; import de.vanitasvitae.enigmandroid.enigma.Enigma_G260;
/** /**

View file

@ -30,16 +30,16 @@ import de.vanitasvitae.enigmandroid.enigma.Enigma_G31;
*/ */
public class LayoutContainer_G31 extends LayoutContainer public class LayoutContainer_G31 extends LayoutContainer
{ {
protected Enigma enigma; Enigma enigma;
protected Spinner rotor1View; private Spinner rotor1View;
protected Spinner rotor2View; private Spinner rotor2View;
protected Spinner rotor3View; private Spinner rotor3View;
protected Spinner rotor1PositionView; private Spinner rotor1PositionView;
protected Spinner rotor2PositionView; private Spinner rotor2PositionView;
protected Spinner rotor3PositionView; private Spinner rotor3PositionView;
protected Spinner reflectorPositionView; private Spinner reflectorPositionView;
public LayoutContainer_G31() public LayoutContainer_G31()
{ {

View file

@ -33,13 +33,13 @@ public class LayoutContainer_I extends LayoutContainer
{ {
private Enigma_I enigma; private Enigma_I enigma;
protected Spinner rotor1View; Spinner rotor1View;
protected Spinner rotor2View; Spinner rotor2View;
protected Spinner rotor3View; Spinner rotor3View;
protected Spinner reflectorView; Spinner reflectorView;
protected Spinner rotor1PositionView; Spinner rotor1PositionView;
protected Spinner rotor2PositionView; Spinner rotor2PositionView;
protected Spinner rotor3PositionView; Spinner rotor3PositionView;
public LayoutContainer_I() public LayoutContainer_I()
{ {

View file

@ -30,16 +30,16 @@ import de.vanitasvitae.enigmandroid.enigma.Enigma_K;
*/ */
public class LayoutContainer_K extends LayoutContainer public class LayoutContainer_K extends LayoutContainer
{ {
protected Enigma enigma; Enigma enigma;
protected Spinner rotor1View; private Spinner rotor1View;
protected Spinner rotor2View; private Spinner rotor2View;
protected Spinner rotor3View; private Spinner rotor3View;
protected Spinner rotor1PositionView; private Spinner rotor1PositionView;
protected Spinner rotor2PositionView; private Spinner rotor2PositionView;
protected Spinner rotor3PositionView; private Spinner rotor3PositionView;
protected Spinner reflectorPositionView; private Spinner reflectorPositionView;
public LayoutContainer_K() public LayoutContainer_K()
{ {

View file

@ -32,16 +32,16 @@ import de.vanitasvitae.enigmandroid.enigma.Enigma_KD;
*/ */
public class LayoutContainer_KD extends LayoutContainer public class LayoutContainer_KD extends LayoutContainer
{ {
protected Enigma enigma; private Enigma enigma;
protected Spinner rotor1View; private Spinner rotor1View;
protected Spinner rotor2View; private Spinner rotor2View;
protected Spinner rotor3View; private Spinner rotor3View;
protected Spinner rotor1PositionView; private Spinner rotor1PositionView;
protected Spinner rotor2PositionView; private Spinner rotor2PositionView;
protected Spinner rotor3PositionView; private Spinner rotor3PositionView;
protected Spinner reflectorPositionView; private Spinner reflectorPositionView;
public LayoutContainer_KD() public LayoutContainer_KD()
{ {

View file

@ -1,10 +1,5 @@
package de.vanitasvitae.enigmandroid.layout; 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; import de.vanitasvitae.enigmandroid.enigma.Enigma_K_Swiss_Standard;
/** /**

View file

@ -1,10 +1,5 @@
package de.vanitasvitae.enigmandroid.layout; 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; import de.vanitasvitae.enigmandroid.enigma.Enigma_K_Swiss_Airforce;
/** /**

View file

@ -32,14 +32,14 @@ public class LayoutContainer_R extends LayoutContainer
{ {
private Enigma_R enigma; private Enigma_R enigma;
protected Spinner rotor1View; private Spinner rotor1View;
protected Spinner rotor2View; private Spinner rotor2View;
protected Spinner rotor3View; private Spinner rotor3View;
protected Spinner rotor1PositionView; private Spinner rotor1PositionView;
protected Spinner rotor2PositionView; private Spinner rotor2PositionView;
protected Spinner rotor3PositionView; private Spinner rotor3PositionView;
protected Spinner reflectorPositionView; private Spinner reflectorPositionView;
public LayoutContainer_R() public LayoutContainer_R()
{ {

View file

@ -32,14 +32,14 @@ public class LayoutContainer_T extends LayoutContainer
{ {
private Enigma_T enigma; private Enigma_T enigma;
protected Spinner rotor1View; private Spinner rotor1View;
protected Spinner rotor2View; private Spinner rotor2View;
protected Spinner rotor3View; private Spinner rotor3View;
protected Spinner rotor1PositionView; private Spinner rotor1PositionView;
protected Spinner rotor2PositionView; private Spinner rotor2PositionView;
protected Spinner rotor3PositionView; private Spinner rotor3PositionView;
protected Spinner reflectorPositionView; private Spinner reflectorPositionView;
public LayoutContainer_T() public LayoutContainer_T()
{ {

View file

@ -37,9 +37,9 @@ import de.vanitasvitae.enigmandroid.R;
*/ */
public class PassphraseDialogBuilder public class PassphraseDialogBuilder
{ {
private MainActivity main; private final MainActivity main;
private View passphraseDialogView; private final View passphraseDialogView;
private EditText passphrase; private final EditText passphrase;
private Button positive; private Button positive;
public PassphraseDialogBuilder() public PassphraseDialogBuilder()
{ {

View file

@ -37,19 +37,19 @@ import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* @author vanitasvitae * @author vanitasvitae
*/ */
public class PluggableDialogBuilder class PluggableDialogBuilder
{ {
protected ArrayList<ButtonWrapper> buttons; private ArrayList<ButtonWrapper> buttons;
protected View dialogView; private View dialogView;
protected MainActivity main; private final MainActivity main;
protected EnigmaStateBundle state; private final EnigmaStateBundle state;
protected boolean allowIncompleteConnections; private boolean allowIncompleteConnections;
protected Button positive; private Button positive;
protected HashSet<Integer> colors; private HashSet<Integer> colors;
protected int previouslyPressedButton = -1; private int previouslyPressedButton = -1;
/** /**
* Constructor that prepares layout and buttons. * Constructor that prepares layout and buttons.
@ -148,7 +148,7 @@ public class PluggableDialogBuilder
/** /**
* Initialize array of buttons, initialize background-color hashset. * Initialize array of buttons, initialize background-color hashset.
*/ */
public void initializeLayout() private void initializeLayout()
{ {
buttons = new ArrayList<>(); buttons = new ArrayList<>();
dialogView = View.inflate(main, R.layout.dialog_plugs, null); dialogView = View.inflate(main, R.layout.dialog_plugs, null);
@ -199,7 +199,7 @@ public class PluggableDialogBuilder
/** /**
* Set listeners for all buttons * Set listeners for all buttons
*/ */
public void setButtonListeners() private void setButtonListeners()
{ {
for(int i=0; i<26; i++) for(int i=0; i<26; i++)
{ {
@ -219,7 +219,7 @@ public class PluggableDialogBuilder
* return false otherwise * return false otherwise
* @return boolean * @return boolean
*/ */
protected boolean allConnectionsDone() private boolean allConnectionsDone()
{ {
for(int i=0; i<buttons.size(); i++) for(int i=0; i<buttons.size(); i++)
{ {
@ -232,7 +232,7 @@ public class PluggableDialogBuilder
/** /**
* restore the connections according to the plugboard * restore the connections according to the plugboard
*/ */
protected void restoreConfigurationPlugboard() private void restoreConfigurationPlugboard()
{ {
restoreConfiguration(state.getConfigurationPlugboard()); restoreConfiguration(state.getConfigurationPlugboard());
} }
@ -240,7 +240,7 @@ public class PluggableDialogBuilder
/** /**
* restore the connections according to the reflector * restore the connections according to the reflector
*/ */
protected void restoreConfigurationReflector() private void restoreConfigurationReflector()
{ {
restoreConfiguration(state.getConfigurationReflector()); restoreConfiguration(state.getConfigurationReflector());
} }
@ -249,7 +249,7 @@ public class PluggableDialogBuilder
* Connect all the buttons according to c. * Connect all the buttons according to c.
* @param c array of connections * @param c array of connections
*/ */
protected void restoreConfiguration(int[] c) private void restoreConfiguration(int[] c)
{ {
for(int i=0; i<26; i++) for(int i=0; i<26; i++)
{ {
@ -265,7 +265,7 @@ public class PluggableDialogBuilder
* @param button1 first and * @param button1 first and
* @param button2 second button * @param button2 second button
*/ */
public void setPlug(int button1, int button2) private void setPlug(int button1, int button2)
{ {
if(button1 == button2) if(button1 == button2)
{ {
@ -303,7 +303,7 @@ public class PluggableDialogBuilder
* Update state of positive button. Check, if all connections are done and if so, enable positive * Update state of positive button. Check, if all connections are done and if so, enable positive
* button. Otherwise disable it. * button. Otherwise disable it.
*/ */
protected void updatePositiveButton() private void updatePositiveButton()
{ {
if(!allowIncompleteConnections && positive != null) if(!allowIncompleteConnections && positive != null)
{ {
@ -331,7 +331,7 @@ public class PluggableDialogBuilder
* Handle button pressed events. * Handle button pressed events.
* @param button button that got pressed * @param button button that got pressed
*/ */
public void buttonPressed(int button) private void buttonPressed(int button)
{ {
if(previouslyPressedButton != -1) if(previouslyPressedButton != -1)
{ {

View file

@ -37,7 +37,7 @@ public abstract class RingSettingsDialogBuilder
protected abstract void showDialog(EnigmaStateBundle stateBundle, ArrayAdapter[] adapters, int[] rIDs, Actions actions); protected abstract void showDialog(EnigmaStateBundle stateBundle, ArrayAdapter[] adapters, int[] rIDs, Actions actions);
public abstract void createRingSettingsDialog(EnigmaStateBundle stateBundle); public abstract void createRingSettingsDialog(EnigmaStateBundle stateBundle);
public static ArrayAdapter createAdapter(Integer[] array) private static ArrayAdapter createAdapter(Integer[] array)
{ {
ArrayAdapter adapter = new ArrayAdapter<>( ArrayAdapter adapter = new ArrayAdapter<>(
MainActivity.ActivitySingleton.getInstance().getActivity(), MainActivity.ActivitySingleton.getInstance().getActivity(),
@ -50,7 +50,7 @@ public abstract class RingSettingsDialogBuilder
* Creates a ArrayAdapter working over an array of numbers 1 to 26. * Creates a ArrayAdapter working over an array of numbers 1 to 26.
* @return ArrayAdapter * @return ArrayAdapter
*/ */
public static ArrayAdapter createAdapter1_26() private static ArrayAdapter createAdapter1_26()
{ {
Integer[] ringArray = new Integer[26]; Integer[] ringArray = new Integer[26];
for(int i=1; i<=26; i++) {ringArray[i-1] = i;} for(int i=1; i<=26; i++) {ringArray[i-1] = i;}
@ -365,7 +365,7 @@ public abstract class RingSettingsDialogBuilder
*/ */
public static abstract class Actions public static abstract class Actions
{ {
protected EnigmaStateBundle stateBundle; final EnigmaStateBundle stateBundle;
public Actions(EnigmaStateBundle bundle) public Actions(EnigmaStateBundle bundle)
{ {
this.stateBundle = bundle; this.stateBundle = bundle;

View file

@ -1,46 +1,55 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" > tools:context=".MainActivity"
tools:ignore="UnusedAttribute">
<!-- RESET --> <!-- RESET -->
<item android:id="@+id/action_reset" <item
android:id="@+id/action_reset"
android:orderInCategory="96" android:orderInCategory="96"
android:showAsAction="ifRoom" android:showAsAction="ifRoom"
android:title="@string/action_reset" /> android:title="@string/action_reset"/>
<!-- SEND --> <!-- SEND -->
<item android:id="@+id/action_send_message" <item
android:id="@+id/action_send_message"
android:icon="@drawable/ic_send_white_48dp"
android:orderInCategory="97" android:orderInCategory="97"
android:showAsAction="always" android:showAsAction="always"
android:title="@string/action_send" android:title="@string/action_send"/>
android:icon="@drawable/ic_send_white_48dp"/>
<!-- RINGSETTING --> <!-- RINGSETTING -->
<item android:id="@+id/action_choose_ringsetting" <item
android:title="@string/action_choose_ring_settings" android:id="@+id/action_choose_ringsetting"
android:orderInCategory="98" android:orderInCategory="98"
android:showAsAction="ifRoom" />
<!-- SHARE CONFIGURATION -->
<item android:id="@+id/action_share_configuration"
android:title="@string/action_share_configuration"
android:showAsAction="ifRoom" android:showAsAction="ifRoom"
android:orderInCategory="99" /> android:title="@string/action_choose_ring_settings"/>
<!-- SHARE CONFIGURATION -->
<item
android:id="@+id/action_share_configuration"
android:orderInCategory="99"
android:showAsAction="ifRoom"
android:title="@string/action_share_configuration"/>
<!-- RESTORE CONFIGURATION FROM QR OR ENTER SEED--> <!-- RESTORE CONFIGURATION FROM QR OR ENTER SEED-->
<item android:id="@+id/action_restore_configuration" <item
android:title="@string/action_restore_configuration" android:id="@+id/action_restore_configuration"
android:showAsAction="ifRoom" android:orderInCategory="100"
android:orderInCategory="100" /> android:showAsAction="ifRoom"
android:title="@string/action_restore_configuration"/>
<!-- RANDOM --> <!-- RANDOM -->
<item android:id="@+id/action_random_configuration" <item
android:id="@+id/action_random_configuration"
android:orderInCategory="101" android:orderInCategory="101"
android:showAsAction="ifRoom" android:showAsAction="ifRoom"
android:title="@string/action_random" /> android:title="@string/action_random"/>
<!-- SETTINGS --> <!-- SETTINGS -->
<item android:id="@+id/action_settings" <item
android:title="@string/action_settings" android:id="@+id/action_settings"
android:orderInCategory="102" android:orderInCategory="102"
android:showAsAction="ifRoom" /> android:showAsAction="ifRoom"
android:title="@string/action_settings"/>
<!-- ABOUT --> <!-- ABOUT -->
<item android:id="@+id/action_about" <item
android:title="@string/title_action_about" android:id="@+id/action_about"
android:orderInCategory="103" android:orderInCategory="103"
android:showAsAction="ifRoom" /> android:showAsAction="ifRoom"
android:title="@string/title_action_about"/>
</menu> </menu>

View file

@ -51,6 +51,4 @@
<string name="message_random">Enigma auf zufällige Konfiguration gesetzt.</string> <string name="message_random">Enigma auf zufällige Konfiguration gesetzt.</string>
<string name="message_clipboard">In Zwischenablage kopiert</string> <string name="message_clipboard">In Zwischenablage kopiert</string>
<string name="dialog_whats_new_title">Was ist neu?</string>
</resources> </resources>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="dialog_whats_new_title">Was ist neu?</string>
</resources>

View file

@ -48,15 +48,6 @@
<string name="message_random">Enigma set to random configuration.</string> <string name="message_random">Enigma set to random configuration.</string>
<string name="message_clipboard">Copied to clipboard</string> <string name="message_clipboard">Copied to clipboard</string>
<string name="dialog_whats_new_title">What\'s new?</string>
<string name="dialog_whats_new_header" translatable="false">%1$s:</string> <!--Version-->
<string name="dialog_whats_new_content" translatable="false">
- 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
</string>
<string translatable="false" name="button_plug_title">%1$s:%2$s</string> <string translatable="false" name="button_plug_title">%1$s:%2$s</string>
<string-array translatable="false" name="rotors_1_3"> <string-array translatable="false" name="rotors_1_3">

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="dialog_whats_new_title">What\'s new?</string>
<string translatable="false" name="dialog_whats_new_header">%1$s:</string> <!--Version-->
<string translatable="false" name="dialog_whats_new_content">
- 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!
</string>
</resources>