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/>.
|
|
|
|
*/
|
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
|
|
|
package de.vanitasvitae.enigmandroid.layout;
|
|
|
|
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.Spinner;
|
|
|
|
|
|
|
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
|
|
|
import de.vanitasvitae.enigmandroid.R;
|
|
|
|
import de.vanitasvitae.enigmandroid.enigma.Enigma;
|
|
|
|
import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
|
|
|
|
import de.vanitasvitae.enigmandroid.enigma.Enigma_KD;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* LayoutContainer for the Enigma Model K
|
|
|
|
* This class contains the layout and controls the layout elements such as spinners and stuff
|
|
|
|
* Copyright (C) 2015 Paul Schaub
|
|
|
|
*/
|
|
|
|
public class LayoutContainer_KD extends LayoutContainer
|
|
|
|
{
|
|
|
|
private Enigma enigma;
|
|
|
|
|
|
|
|
private Spinner rotor1View;
|
|
|
|
private Spinner rotor2View;
|
|
|
|
private Spinner rotor3View;
|
|
|
|
|
|
|
|
private Spinner rotor1PositionView;
|
|
|
|
private Spinner rotor2PositionView;
|
|
|
|
private Spinner rotor3PositionView;
|
|
|
|
private Spinner reflectorPositionView;
|
|
|
|
|
|
|
|
public LayoutContainer_KD()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
main.setTitle("KD - EnigmAndroid");
|
|
|
|
this.resetLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void setEnigmaLayout()
|
|
|
|
{
|
|
|
|
MainActivity.ActivitySingleton.getInstance().getActivity().setContentView(R.layout.activity_main_kd);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Enigma getEnigma() {
|
|
|
|
return this.enigma;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void assembleLayout() {
|
|
|
|
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.reflectorPositionView = (Spinner) main.findViewById(R.id.reflector_position);
|
|
|
|
Button reflectorWiring = (Button) main.findViewById(R.id.button_reflector);
|
|
|
|
reflectorWiring.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
new PluggableDialogBuilder(getEnigma().getState()).showDialogReflector();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Character[] rotorPositionArray = new Character[26];
|
|
|
|
for(int i=0; i<26; i++) {rotorPositionArray[i] = (char) (65+i); /*Fill with A..Z*/}
|
|
|
|
|
|
|
|
prepareSpinnerAdapter(rotor1View, R.array.rotors_1_3);
|
|
|
|
prepareSpinnerAdapter(rotor2View, R.array.rotors_1_3);
|
|
|
|
prepareSpinnerAdapter(rotor3View, R.array.rotors_1_3);
|
|
|
|
|
|
|
|
prepareSpinnerAdapter(rotor1PositionView, rotorPositionArray);
|
|
|
|
prepareSpinnerAdapter(rotor2PositionView, rotorPositionArray);
|
|
|
|
prepareSpinnerAdapter(rotor3PositionView, rotorPositionArray);
|
|
|
|
prepareSpinnerAdapter(reflectorPositionView, rotorPositionArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void resetLayout() {
|
|
|
|
enigma = new Enigma_KD();
|
|
|
|
setLayoutState(enigma.getState());
|
|
|
|
output.setText("");
|
|
|
|
input.setText("");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setLayoutState(EnigmaStateBundle state)
|
|
|
|
{
|
|
|
|
this.rotor1View.setSelection(state.getTypeRotor1());
|
|
|
|
this.rotor2View.setSelection(state.getTypeRotor2());
|
|
|
|
this.rotor3View.setSelection(state.getTypeRotor3());
|
|
|
|
this.rotor1PositionView.setSelection(state.getRotationRotor1());
|
|
|
|
this.rotor2PositionView.setSelection(state.getRotationRotor2());
|
|
|
|
this.rotor3PositionView.setSelection(state.getRotationRotor3());
|
|
|
|
this.reflectorPositionView.setSelection(state.getRotationReflector());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void syncStateFromLayoutToEnigma()
|
|
|
|
{
|
|
|
|
EnigmaStateBundle state = getEnigma().getState();
|
|
|
|
state.setTypeRotor1(rotor1View.getSelectedItemPosition());
|
|
|
|
state.setTypeRotor2(rotor2View.getSelectedItemPosition());
|
|
|
|
state.setTypeRotor3(rotor3View.getSelectedItemPosition());
|
|
|
|
state.setRotationRotor1(rotor1PositionView.getSelectedItemPosition());
|
|
|
|
state.setRotationRotor2(rotor2PositionView.getSelectedItemPosition());
|
|
|
|
state.setRotationRotor3(rotor3PositionView.getSelectedItemPosition());
|
|
|
|
state.setRotationReflector(reflectorPositionView.getSelectedItemPosition());
|
|
|
|
getEnigma().setState(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void showRingSettingsDialog()
|
|
|
|
{
|
|
|
|
new RingSettingsDialogBuilder.RingSettingsDialogBuilderRotRotRotRef().
|
|
|
|
createRingSettingsDialog(getEnigma().getState());
|
|
|
|
}
|
|
|
|
}
|