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-09-15 02:06:47 +02:00
|
|
|
package de.vanitasvitae.enigmandroid.layout;
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.DialogInterface;
|
2015-10-09 00:57:54 +02:00
|
|
|
import android.content.res.Resources;
|
2015-09-15 02:06:47 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2015-09-20 00:55:43 +02:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
2015-09-15 02:06:47 +02:00
|
|
|
|
|
|
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
|
|
|
import de.vanitasvitae.enigmandroid.R;
|
|
|
|
import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
|
|
|
|
|
|
|
|
/**
|
2015-10-01 00:39:17 +02:00
|
|
|
* Builder for the dialog that is used to plug the plugboard/wire the
|
|
|
|
* rewirable reflector.
|
2015-09-15 02:06:47 +02:00
|
|
|
* Copyright (C) 2015 Paul Schaub
|
|
|
|
*/
|
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
|
|
|
class PluggableDialogBuilder
|
2015-09-15 02:06:47 +02:00
|
|
|
{
|
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
|
|
|
private ArrayList<ButtonWrapper> buttons;
|
|
|
|
private View dialogView;
|
|
|
|
private final MainActivity main;
|
|
|
|
private final EnigmaStateBundle state;
|
2015-09-20 00:55:43 +02:00
|
|
|
|
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
|
|
|
private boolean allowIncompleteConnections;
|
|
|
|
private Button positive;
|
2015-09-30 14:25:49 +02:00
|
|
|
|
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
|
|
|
private HashSet<Integer> colors;
|
2015-09-15 02:06:47 +02:00
|
|
|
|
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
|
|
|
private int previouslyPressedButton = -1;
|
2015-09-15 02:06:47 +02:00
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Constructor that prepares layout and buttons.
|
|
|
|
* @param state EnigmaStateBundle from which dialog gets restored and which gets manipulated
|
|
|
|
*/
|
2015-09-15 02:06:47 +02:00
|
|
|
public PluggableDialogBuilder(EnigmaStateBundle state)
|
|
|
|
{
|
|
|
|
this.state = state;
|
|
|
|
main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
|
|
|
|
initializeLayout();
|
|
|
|
setButtonListeners();
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Show dialog for the plugboard
|
|
|
|
*/
|
2015-09-15 02:06:47 +02:00
|
|
|
public void showDialogPlugboard()
|
|
|
|
{
|
2015-09-30 14:25:49 +02:00
|
|
|
allowIncompleteConnections = true;
|
2015-09-15 02:06:47 +02:00
|
|
|
restoreConfigurationPlugboard();
|
|
|
|
AlertDialog.Builder adb = new AlertDialog.Builder(main);
|
|
|
|
adb.setTitle(R.string.title_plugboard_dialog);
|
|
|
|
Dialog d = adb.setView(dialogView)
|
|
|
|
.setCancelable(true)
|
2015-10-09 00:57:54 +02:00
|
|
|
.setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener() {
|
2015-09-15 02:06:47 +02:00
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
|
|
int[] plugs = new int[26];
|
|
|
|
for (int i = 0; i < 26; i++) {
|
2015-09-20 00:55:43 +02:00
|
|
|
plugs[i] = buttons.get(i).getConnectedButton();
|
2015-09-15 02:06:47 +02:00
|
|
|
}
|
|
|
|
state.setConfigurationPlugboard(plugs);
|
2015-09-30 14:25:49 +02:00
|
|
|
main.onDialogFinished(state);
|
2015-09-15 02:06:47 +02:00
|
|
|
Toast.makeText(main.getApplication(), R.string.dialog_plugboard_set, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
})
|
2015-10-09 00:57:54 +02:00
|
|
|
.setNegativeButton(R.string.dialog_negative, new DialogInterface.OnClickListener() {
|
2015-09-15 02:06:47 +02:00
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
|
|
dialog.cancel();
|
|
|
|
Toast.makeText(main, R.string.dialog_abort,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}).create();
|
|
|
|
|
|
|
|
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
|
|
|
|
lp.copyFrom(d.getWindow().getAttributes());
|
|
|
|
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
|
|
|
|
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
|
d.show();
|
|
|
|
d.getWindow().setAttributes(lp);
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Show the dialog for the reflector. This can only be positively closed when all
|
|
|
|
* connections are made.
|
|
|
|
*/
|
2015-09-15 02:06:47 +02:00
|
|
|
public void showDialogReflector()
|
|
|
|
{
|
2015-09-30 14:25:49 +02:00
|
|
|
allowIncompleteConnections = false;
|
2015-09-15 02:06:47 +02:00
|
|
|
restoreConfigurationReflector();
|
|
|
|
AlertDialog.Builder adb = new AlertDialog.Builder(main);
|
|
|
|
adb.setTitle(R.string.title_reflector_dialog);
|
|
|
|
Dialog d = adb.setView(dialogView)
|
|
|
|
.setCancelable(true)
|
2015-10-09 00:57:54 +02:00
|
|
|
.setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener() {
|
2015-09-15 02:06:47 +02:00
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
|
|
int[] plugs = new int[26];
|
|
|
|
for (int i = 0; i < 26; i++) {
|
2015-09-20 00:55:43 +02:00
|
|
|
plugs[i] = buttons.get(i).getConnectedButton();
|
2015-09-15 02:06:47 +02:00
|
|
|
}
|
|
|
|
state.setConfigurationReflector(plugs);
|
2015-09-30 14:25:49 +02:00
|
|
|
main.onDialogFinished(state);
|
2015-09-15 02:06:47 +02:00
|
|
|
Toast.makeText(main.getApplication(), R.string.dialog_reflector_set, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
})
|
2015-10-09 00:57:54 +02:00
|
|
|
.setNegativeButton(R.string.dialog_negative, new DialogInterface.OnClickListener() {
|
2015-09-15 02:06:47 +02:00
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
|
|
dialog.cancel();
|
|
|
|
Toast.makeText(main, R.string.dialog_abort,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}).create();
|
|
|
|
|
|
|
|
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
|
|
|
|
lp.copyFrom(d.getWindow().getAttributes());
|
|
|
|
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
|
|
|
|
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
|
|
|
d.show();
|
2015-09-30 14:25:49 +02:00
|
|
|
positive = ((AlertDialog)d).getButton(AlertDialog.BUTTON_POSITIVE);
|
|
|
|
if(!allConnectionsDone())
|
|
|
|
{
|
|
|
|
positive.setEnabled(false);
|
|
|
|
}
|
2015-09-15 02:06:47 +02:00
|
|
|
d.getWindow().setAttributes(lp);
|
|
|
|
}
|
2015-10-01 00:39:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize array of buttons, initialize background-color hashset.
|
|
|
|
*/
|
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
|
|
|
private void initializeLayout()
|
2015-09-15 02:06:47 +02:00
|
|
|
{
|
|
|
|
buttons = new ArrayList<>();
|
|
|
|
dialogView = View.inflate(main, R.layout.dialog_plugs, null);
|
|
|
|
|
2015-09-20 00:55:43 +02:00
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.A),0));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.B),1));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.C),2));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.D),3));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.E),4));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.F),5));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.G),6));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.H),7));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.I),8));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.J),9));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.K),10));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.L),11));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.M),12));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.N),13));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.O),14));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.P),15));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.Q),16));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.R),17));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.S),18));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.T),19));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.U),20));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.V),21));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.W),22));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.X),23));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.Y),24));
|
|
|
|
buttons.add(new ButtonWrapper((Button) dialogView.findViewById(R.id.Z),25));
|
|
|
|
|
|
|
|
colors = new HashSet<>();
|
|
|
|
colors.add(R.drawable.button_orange);
|
|
|
|
colors.add(R.drawable.button_olive);
|
|
|
|
colors.add(R.drawable.button_blue);
|
|
|
|
colors.add(R.drawable.button_red);
|
|
|
|
colors.add(R.drawable.button_yellow);
|
|
|
|
colors.add(R.drawable.button_purple);
|
|
|
|
colors.add(R.drawable.button_green);
|
|
|
|
colors.add(R.drawable.button_cyan);
|
|
|
|
colors.add(R.drawable.button_berry);
|
|
|
|
colors.add(R.drawable.button_brown);
|
|
|
|
colors.add(R.drawable.button_pink);
|
|
|
|
colors.add(R.drawable.button_elder);
|
|
|
|
colors.add(R.drawable.button_black);
|
2015-09-15 02:06:47 +02:00
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Set listeners for all buttons
|
|
|
|
*/
|
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
|
|
|
private void setButtonListeners()
|
2015-09-15 02:06:47 +02:00
|
|
|
{
|
|
|
|
for(int i=0; i<26; i++)
|
|
|
|
{
|
2015-09-20 00:55:43 +02:00
|
|
|
Button b = buttons.get(i).getButton();
|
2015-09-15 02:06:47 +02:00
|
|
|
final int id = i;
|
|
|
|
b.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
buttonPressed(id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Check, whether all connections are done. If so, return true.
|
|
|
|
* return false otherwise
|
|
|
|
* @return boolean
|
|
|
|
*/
|
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
|
|
|
private boolean allConnectionsDone()
|
2015-09-30 14:25:49 +02:00
|
|
|
{
|
|
|
|
for(int i=0; i<buttons.size(); i++)
|
|
|
|
{
|
|
|
|
ButtonWrapper b = buttons.get(i);
|
|
|
|
if(b.getConnectedButton() == i || b.getConnectedButton() == -1) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* restore the connections according to the plugboard
|
|
|
|
*/
|
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
|
|
|
private void restoreConfigurationPlugboard()
|
2015-09-15 02:06:47 +02:00
|
|
|
{
|
|
|
|
restoreConfiguration(state.getConfigurationPlugboard());
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* restore the connections according to the reflector
|
|
|
|
*/
|
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
|
|
|
private void restoreConfigurationReflector()
|
2015-09-15 02:06:47 +02:00
|
|
|
{
|
|
|
|
restoreConfiguration(state.getConfigurationReflector());
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Connect all the buttons according to c.
|
|
|
|
* @param c array of connections
|
|
|
|
*/
|
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
|
|
|
private void restoreConfiguration(int[] c)
|
2015-09-15 02:06:47 +02:00
|
|
|
{
|
|
|
|
for(int i=0; i<26; i++)
|
|
|
|
{
|
2015-09-20 00:55:43 +02:00
|
|
|
setPlug(i, c[i]);
|
2015-09-15 02:06:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Connect button1 and button2. If two buttons got pressed afterwards and they are not the same
|
|
|
|
* they get connected. If one or both of them was connected beforehand, these connections get
|
|
|
|
* resolved. If both events come from the same button, the buttons connections (if any) get
|
|
|
|
* resolved.
|
|
|
|
* @param button1 first and
|
|
|
|
* @param button2 second button
|
|
|
|
*/
|
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
|
|
|
private void setPlug(int button1, int button2)
|
2015-09-15 02:06:47 +02:00
|
|
|
{
|
2015-09-20 00:55:43 +02:00
|
|
|
if(button1 == button2)
|
2015-09-15 02:06:47 +02:00
|
|
|
{
|
2015-09-20 00:55:43 +02:00
|
|
|
setButtonFree(buttons.get(button1).getConnectedButton());
|
|
|
|
setButtonFree(button1);
|
2015-09-15 02:06:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-20 00:55:43 +02:00
|
|
|
ButtonWrapper b1 = buttons.get(button1);
|
|
|
|
ButtonWrapper b2 = buttons.get(button2);
|
|
|
|
|
|
|
|
if (b1.getConnectedButton() != button1) {
|
|
|
|
setButtonFree(b1.getConnectedButton());
|
|
|
|
}
|
|
|
|
if (b2.getConnectedButton() != button2) {
|
|
|
|
setButtonFree(b2.getConnectedButton());
|
|
|
|
}
|
|
|
|
|
|
|
|
b1.setConnectedButton(button2);
|
|
|
|
b2.setConnectedButton(button1);
|
|
|
|
|
|
|
|
int res;
|
|
|
|
Iterator<Integer> it = colors.iterator();
|
|
|
|
res = it.next();
|
|
|
|
if(res == 0) res = it.next();
|
|
|
|
colors.remove(res);
|
|
|
|
|
|
|
|
b1.setResourceID(res);
|
|
|
|
b2.setResourceID(res);
|
2015-09-15 02:06:47 +02:00
|
|
|
}
|
2015-09-30 14:25:49 +02:00
|
|
|
updatePositiveButton();
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Update state of positive button. Check, if all connections are done and if so, enable positive
|
|
|
|
* button. Otherwise disable it.
|
|
|
|
*/
|
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
|
|
|
private void updatePositiveButton()
|
2015-09-30 14:25:49 +02:00
|
|
|
{
|
|
|
|
if(!allowIncompleteConnections && positive != null)
|
|
|
|
{
|
|
|
|
if(allConnectionsDone()) positive.setEnabled(true);
|
|
|
|
else positive.setEnabled(false);
|
|
|
|
}
|
2015-09-15 02:06:47 +02:00
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Set buttons to not connected. That includes changing background to grey, set connection to
|
|
|
|
* itself.
|
2015-10-04 22:51:35 +02:00
|
|
|
* @param b index of button
|
2015-10-01 00:39:17 +02:00
|
|
|
*/
|
2015-09-20 00:55:43 +02:00
|
|
|
private void setButtonFree(int b)
|
2015-09-15 02:06:47 +02:00
|
|
|
{
|
2015-09-20 00:55:43 +02:00
|
|
|
ButtonWrapper button = buttons.get(b);
|
|
|
|
int res = button.getResourceID();
|
|
|
|
if(res != R.drawable.button_grey)
|
|
|
|
colors.add(button.getResourceID());
|
|
|
|
button.setResourceID(R.drawable.button_grey);
|
|
|
|
button.setConnectedButton(b);
|
2015-09-15 02:06:47 +02:00
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Handle button pressed events.
|
|
|
|
* @param button button that got pressed
|
|
|
|
*/
|
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
|
|
|
private void buttonPressed(int button)
|
2015-09-15 02:06:47 +02:00
|
|
|
{
|
2015-09-20 00:55:43 +02:00
|
|
|
if(previouslyPressedButton != -1)
|
2015-09-15 02:06:47 +02:00
|
|
|
{
|
2015-09-20 00:55:43 +02:00
|
|
|
setPlug(previouslyPressedButton, button);
|
|
|
|
previouslyPressedButton = -1;
|
2015-09-15 02:06:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-20 00:55:43 +02:00
|
|
|
previouslyPressedButton = button;
|
|
|
|
buttons.get(button).setWaiting();
|
2015-09-15 02:06:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Wrapper class for Buttons, that also stores the index of both, the connected button, as well
|
|
|
|
* as the button itself and resourceID of used material.
|
|
|
|
*/
|
2015-09-20 00:55:43 +02:00
|
|
|
private static class ButtonWrapper
|
2015-09-15 02:06:47 +02:00
|
|
|
{
|
2015-09-20 00:55:43 +02:00
|
|
|
private Button button;
|
|
|
|
private int connectedButton;
|
|
|
|
private int resourceID;
|
|
|
|
private int index;
|
2015-10-01 00:39:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create ButtonWrapper
|
|
|
|
* @param button underlying Button
|
|
|
|
* @param index index of the button in the buttons array
|
|
|
|
*/
|
2015-09-20 00:55:43 +02:00
|
|
|
public ButtonWrapper(Button button, int index)
|
|
|
|
{
|
|
|
|
this.button = button;
|
|
|
|
this.index = index;
|
|
|
|
this.connectedButton = index;
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* set the index of the connected button and update buttons text
|
|
|
|
* @param other index
|
|
|
|
*/
|
2015-09-20 00:55:43 +02:00
|
|
|
public void setConnectedButton(int other)
|
|
|
|
{
|
|
|
|
this.connectedButton = other;
|
2015-10-09 00:57:54 +02:00
|
|
|
Resources res = MainActivity.ActivitySingleton.getInstance().getActivity().getResources();
|
|
|
|
this.getButton().setText(String.format(
|
|
|
|
res.getText(R.string.button_plug_title).toString(),
|
|
|
|
""+(char) (index+65),
|
|
|
|
""+(char) (connectedButton+65)));
|
2015-09-20 00:55:43 +02:00
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* return index of the connected button
|
|
|
|
* @return index of connected button
|
|
|
|
*/
|
2015-09-20 00:55:43 +02:00
|
|
|
public int getConnectedButton()
|
|
|
|
{
|
|
|
|
return this.connectedButton;
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Indicate, that this button is waiting for another button to connect to.
|
|
|
|
*/
|
2015-09-20 00:55:43 +02:00
|
|
|
public void setWaiting()
|
|
|
|
{
|
2015-10-09 00:57:54 +02:00
|
|
|
Resources res = MainActivity.ActivitySingleton.getInstance().getActivity().getResources();
|
|
|
|
this.getButton().setText(String.format(
|
|
|
|
res.getText(R.string.button_plug_title).toString(),
|
|
|
|
""+(char) (index+65)," "));
|
2015-09-20 00:55:43 +02:00
|
|
|
}
|
2015-09-15 02:06:47 +02:00
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Set buttons background and store value in resourceID
|
|
|
|
* @param r resourceID of background material
|
|
|
|
*/
|
2015-09-20 00:55:43 +02:00
|
|
|
public void setResourceID(int r)
|
|
|
|
{
|
|
|
|
button.setBackgroundResource(r);
|
|
|
|
this.resourceID = r;
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* get resourceID of buttons background as store in resourceID
|
|
|
|
* @return resourceID
|
|
|
|
*/
|
2015-09-20 00:55:43 +02:00
|
|
|
public int getResourceID()
|
|
|
|
{
|
|
|
|
return this.resourceID;
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:39:17 +02:00
|
|
|
/**
|
|
|
|
* Return stored button object
|
|
|
|
* @return button
|
|
|
|
*/
|
2015-09-20 00:55:43 +02:00
|
|
|
public Button getButton()
|
|
|
|
{
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
}
|
2015-09-15 02:06:47 +02:00
|
|
|
}
|