2019-01-04 20:40:11 +01:00
|
|
|
/**
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2015-08-27 01:48:33 +02:00
|
|
|
package de.vanitasvitae.enigmandroid.layout;
|
|
|
|
|
2015-09-15 02:06:47 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
2015-09-10 02:56:48 +02:00
|
|
|
import android.widget.Spinner;
|
2015-08-27 01:48:33 +02:00
|
|
|
|
|
|
|
import de.vanitasvitae.enigmandroid.R;
|
2015-09-10 02:56:48 +02:00
|
|
|
import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
|
2015-08-27 01:48:33 +02:00
|
|
|
import de.vanitasvitae.enigmandroid.enigma.Enigma_M3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Concrete LayoutContainer for the M3 layout.
|
|
|
|
* This class contains the layout and controls the layout elements such as spinners and stuff
|
|
|
|
* Copyright (C) 2015 Paul Schaub
|
|
|
|
*/
|
|
|
|
public class LayoutContainer_M3 extends LayoutContainer_I
|
|
|
|
{
|
2015-09-10 02:56:48 +02:00
|
|
|
private Enigma_M3 enigma;
|
|
|
|
|
2015-08-27 01:48:33 +02:00
|
|
|
public LayoutContainer_M3()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
main.setTitle("M3 - EnigmAndroid");
|
2015-09-10 02:56:48 +02:00
|
|
|
this.resetLayout();
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
Started new Iteration of MainActivity as Main2, moved getters and setters of preferences to SettingsActivity
Added Enigma KD, Added protocol version to ensure compatibility with upcoming releases, Added options to share configuration as string, organized sharing/receiving of configuration, moved preference-management to SettingsActivity, Added whats-New-Dialog that informs user about latest changes
Translated some strings, commented some methods in MainActivity
New Icon!
Added comment and removed unused import, peanuts if you ask me
Added Script to automatically render icon in all dimensions
Reformated code and moved Plugboard, EntryWheel, Reflector, Rotor to new package parts
Cleaned repository
Merge branch 'development'
2017-05-05 16:49:30 +02:00
|
|
|
protected void assembleLayout()
|
2015-08-27 01:48:33 +02:00
|
|
|
{
|
2015-09-10 02:56:48 +02:00
|
|
|
this.rotor1View = (Spinner) main.findViewById(R.id.rotor1);
|
|
|
|
this.rotor2View = (Spinner) main.findViewById(R.id.rotor2);
|
|
|
|
this.rotor3View = (Spinner) main.findViewById(R.id.rotor3);
|
|
|
|
this.rotor1PositionView = (Spinner) main.findViewById(R.id.rotor1position);
|
|
|
|
this.rotor2PositionView = (Spinner) main.findViewById(R.id.rotor2position);
|
|
|
|
this.rotor3PositionView = (Spinner) main.findViewById(R.id.rotor3position);
|
|
|
|
this.reflectorView = (Spinner) main.findViewById(R.id.reflector);
|
2015-09-15 02:06:47 +02:00
|
|
|
Button setPlugboardButton = (Button) main.findViewById(R.id.button_plugboard);
|
|
|
|
setPlugboardButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-09-30 14:25:49 +02:00
|
|
|
new PluggableDialogBuilder(getEnigma().getState()).showDialogPlugboard();
|
2015-09-15 02:06:47 +02:00
|
|
|
}
|
|
|
|
});
|
2015-09-10 02:56:48 +02:00
|
|
|
|
2015-08-27 01:48:33 +02:00
|
|
|
Character[] rotorPositionArray = new Character[26];
|
2015-09-26 16:51:19 +02:00
|
|
|
for(int i=0; i<26; i++) {rotorPositionArray[i] = (char) (65+i); /*Fill with A..Z*/}
|
2015-08-27 01:48:33 +02:00
|
|
|
|
2015-09-26 16:51:19 +02:00
|
|
|
prepareSpinnerAdapter(rotor1View, R.array.rotors_1_8);
|
|
|
|
prepareSpinnerAdapter(rotor2View, R.array.rotors_1_8);
|
|
|
|
prepareSpinnerAdapter(rotor3View, R.array.rotors_1_8);
|
|
|
|
prepareSpinnerAdapter(reflectorView, R.array.reflectors_b_c);
|
|
|
|
prepareSpinnerAdapter(rotor1PositionView, rotorPositionArray);
|
|
|
|
prepareSpinnerAdapter(rotor2PositionView, rotorPositionArray);
|
|
|
|
prepareSpinnerAdapter(rotor3PositionView, rotorPositionArray);
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-10 02:56:48 +02:00
|
|
|
public void resetLayout()
|
|
|
|
{
|
|
|
|
enigma = new Enigma_M3();
|
|
|
|
setLayoutState(enigma.getState());
|
2015-09-12 00:04:58 +02:00
|
|
|
output.setText("");
|
|
|
|
input.setText("");
|
2015-09-10 02:56:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-26 16:04:02 +02:00
|
|
|
public void setLayoutState(EnigmaStateBundle state)
|
2015-09-10 02:56:48 +02:00
|
|
|
{
|
2015-10-04 22:51:35 +02:00
|
|
|
this.rotor1View.setSelection(state.getTypeRotor1());
|
|
|
|
this.rotor2View.setSelection(state.getTypeRotor2());
|
|
|
|
this.rotor3View.setSelection(state.getTypeRotor3());
|
|
|
|
this.reflectorView.setSelection(state.getTypeReflector());
|
2015-09-10 02:56:48 +02:00
|
|
|
this.rotor1PositionView.setSelection(state.getRotationRotor1());
|
|
|
|
this.rotor2PositionView.setSelection(state.getRotationRotor2());
|
|
|
|
this.rotor3PositionView.setSelection(state.getRotationRotor3());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-30 14:25:49 +02:00
|
|
|
public void syncStateFromLayoutToEnigma()
|
2015-08-27 01:48:33 +02:00
|
|
|
{
|
2015-09-30 14:25:49 +02:00
|
|
|
EnigmaStateBundle state = getEnigma().getState();
|
2015-10-04 22:51:35 +02:00
|
|
|
state.setTypeRotor1(rotor1View.getSelectedItemPosition());
|
|
|
|
state.setTypeRotor2(rotor2View.getSelectedItemPosition());
|
|
|
|
state.setTypeRotor3(rotor3View.getSelectedItemPosition());
|
|
|
|
state.setTypeReflector(reflectorView.getSelectedItemPosition());
|
2015-09-10 02:56:48 +02:00
|
|
|
state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
|
|
|
|
state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
|
|
|
|
state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());
|
2015-09-30 14:25:49 +02:00
|
|
|
getEnigma().setState(state);
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-10 02:56:48 +02:00
|
|
|
public Enigma_M3 getEnigma()
|
2015-08-27 01:48:33 +02:00
|
|
|
{
|
2015-09-10 02:56:48 +02:00
|
|
|
return this.enigma;
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
}
|