mirror of
https://github.com/vanitasvitae/EnigmAndroid.git
synced 2024-12-23 03:18:00 +01:00
Started new Iteration of MainActivity as Main2, moved getters and setters of preferences to SettingsActivity
This commit is contained in:
parent
d1d3211cca
commit
ba4a0f590f
13 changed files with 890 additions and 531 deletions
336
app/src/main/java/de/vanitasvitae/enigmandroid/Main2.java
Normal file
336
app/src/main/java/de/vanitasvitae/enigmandroid/Main2.java
Normal file
|
@ -0,0 +1,336 @@
|
||||||
|
package de.vanitasvitae.enigmandroid;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.zxing.integration.android.IntentIntegrator;
|
||||||
|
import com.google.zxing.integration.android.IntentResult;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
|
import de.vanitasvitae.enigmandroid.enigma.Enigma;
|
||||||
|
import de.vanitasvitae.enigmandroid.layout.LayoutContainer;
|
||||||
|
import de.vanitasvitae.enigmandroid.layout.PassphraseDialogBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reimplementation of MainActivity
|
||||||
|
* Created by vanitas on 11.10.15.
|
||||||
|
*/
|
||||||
|
public class Main2 extends Activity
|
||||||
|
{
|
||||||
|
private static final int RESULT_SETTINGS = 1;
|
||||||
|
private static final String URI_CHANGELOG =
|
||||||
|
"https://github.com/vanitasvitae/EnigmAndroid/blob/master/CHANGELOG.txt";
|
||||||
|
public static final String APP_ID = "EnigmAndroid";
|
||||||
|
|
||||||
|
private LayoutContainer layoutContainer;
|
||||||
|
private SecureRandom numberGenerator;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
this.numberGenerator = new SecureRandom();
|
||||||
|
MainActivity.ActivitySingleton singleton = MainActivity.ActivitySingleton.getInstance();
|
||||||
|
singleton.setActivity(this);
|
||||||
|
numberGenerator = new SecureRandom();
|
||||||
|
restoreEnigmaModelAndState();
|
||||||
|
|
||||||
|
//Handle shared text
|
||||||
|
Intent intent = getIntent();
|
||||||
|
String action = intent.getAction();
|
||||||
|
String type = intent.getType();
|
||||||
|
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||||
|
if ("text/plain".equals(type))
|
||||||
|
{
|
||||||
|
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||||
|
if (sharedText != null)
|
||||||
|
{
|
||||||
|
layoutContainer.getInput().setRawText(sharedText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu)
|
||||||
|
{
|
||||||
|
this.getMenuInflater().inflate(R.menu.main, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
/**
|
||||||
|
* Handle Options menu clicks
|
||||||
|
*/
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
|
{
|
||||||
|
int id = item.getItemId();
|
||||||
|
if (id == R.id.action_reset)
|
||||||
|
{
|
||||||
|
layoutContainer.resetLayout();
|
||||||
|
Toast.makeText(getApplicationContext(), R.string.message_reset,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (id == R.id.action_send)
|
||||||
|
{
|
||||||
|
actionShareMessage();
|
||||||
|
}
|
||||||
|
else if (id == R.id.action_choose_ringsetting)
|
||||||
|
{
|
||||||
|
layoutContainer.showRingSettingsDialog();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(id == R.id.action_enter_seed)
|
||||||
|
{
|
||||||
|
new PassphraseDialogBuilder().showDialog();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (id == R.id.action_receive_scan)
|
||||||
|
{
|
||||||
|
IntentIntegrator integrator = new IntentIntegrator(this);
|
||||||
|
integrator.initiateScan();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(id == R.id.action_share_scan)
|
||||||
|
{
|
||||||
|
actionShareConfiguration();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (id == R.id.action_random_configuration)
|
||||||
|
{
|
||||||
|
actionRandomConfiguration();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (id == R.id.action_settings)
|
||||||
|
{
|
||||||
|
Intent i = new Intent(this, SettingsActivity.class);
|
||||||
|
startActivityForResult(i, RESULT_SETTINGS);
|
||||||
|
}
|
||||||
|
else if (id == R.id.action_about)
|
||||||
|
{
|
||||||
|
actionAbout();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle preference changes
|
||||||
|
* @param requestCode requestCode
|
||||||
|
* @param resultCode resultCode (RESULT_SETTINGS is defined at the top)
|
||||||
|
* @param data data (not important here)
|
||||||
|
*/
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
|
switch (requestCode) {
|
||||||
|
//Settings
|
||||||
|
case RESULT_SETTINGS:
|
||||||
|
{
|
||||||
|
restoreEnigmaModelAndState();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//QR_Scanner
|
||||||
|
case IntentIntegrator.REQUEST_CODE:
|
||||||
|
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||||
|
if (scanResult != null) {
|
||||||
|
String content = scanResult.getContents();
|
||||||
|
if(content == null) Log.e(APP_ID, "Error! Received nothing from QR-Code!");
|
||||||
|
else {
|
||||||
|
Log.d(APP_ID, "Received " + content + " from QR-Code!");
|
||||||
|
restoreEnigmaModelAndState(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause()
|
||||||
|
{
|
||||||
|
super.onPause();
|
||||||
|
//TODO: Save state
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean restoreEnigmaModelAndState()
|
||||||
|
{
|
||||||
|
String savedState = SettingsActivity.SettingsSingleton.getInstance().getPrefSavedEnigmaState();
|
||||||
|
if (savedState.equals("-1") || SettingsActivity.SettingsSingleton.getInstance().prefSavedEnigmaStateChanged())
|
||||||
|
{
|
||||||
|
layoutContainer = LayoutContainer.createLayoutContainer(
|
||||||
|
SettingsActivity.SettingsSingleton.getInstance().getPrefMachineType());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//No changes
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean restoreEnigmaModelAndState(BigInteger savedState)
|
||||||
|
{
|
||||||
|
SettingsActivity.SettingsSingleton.getInstance().setPrefMachineType(
|
||||||
|
Enigma.chooseEnigmaFromSave(savedState));
|
||||||
|
String savedInput = "";
|
||||||
|
if(layoutContainer != null) savedInput = layoutContainer.getInput().getText();
|
||||||
|
layoutContainer = LayoutContainer.createLayoutContainer(
|
||||||
|
SettingsActivity.SettingsSingleton.getInstance().getPrefMachineType());
|
||||||
|
layoutContainer.getEnigma().restoreState(Enigma.removeDigit(savedState, 20));
|
||||||
|
layoutContainer.syncStateFromEnigmaToLayout();
|
||||||
|
layoutContainer.getInput().setText(savedInput);
|
||||||
|
layoutContainer.getOutput().setText("");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore Enigma state from String. String has to start with "EnigmAndroid/"
|
||||||
|
* @param savedState String
|
||||||
|
* @return success
|
||||||
|
*/
|
||||||
|
private boolean restoreEnigmaModelAndState(String savedState)
|
||||||
|
{
|
||||||
|
if(!savedState.startsWith(APP_ID+"/"))
|
||||||
|
{
|
||||||
|
Toast.makeText(this, R.string.error_no_valid_qr, Toast.LENGTH_LONG).show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
savedState = savedState.substring((APP_ID+"/").length());
|
||||||
|
BigInteger s = new BigInteger(savedState, 16);
|
||||||
|
return restoreEnigmaModelAndState(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set EnigmAndroid into a state calculated from the seed.
|
||||||
|
* @param seed seed
|
||||||
|
*/
|
||||||
|
public void createStateFromSeed(String seed)
|
||||||
|
{
|
||||||
|
String savedInput = "";
|
||||||
|
if(layoutContainer != null) savedInput = layoutContainer.getInput().getText();
|
||||||
|
SettingsActivity.SettingsSingleton.getInstance().setPrefMachineType(
|
||||||
|
Enigma.chooseEnigmaFromSeed(seed));
|
||||||
|
layoutContainer = LayoutContainer.createLayoutContainer();
|
||||||
|
layoutContainer.getEnigma().setStateFromSeed(seed);
|
||||||
|
layoutContainer.syncStateFromEnigmaToLayout();
|
||||||
|
layoutContainer.getInput().setText(savedInput);
|
||||||
|
layoutContainer.getOutput().setText("");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the chosen Configuration to the enigma, get the input string from the input text box and
|
||||||
|
* prepare it, set the input to the prepared text, encrypt the prepared input and set the
|
||||||
|
* encrypted string to the output text box and update the spinners to their new positions.
|
||||||
|
* @param v View
|
||||||
|
*/
|
||||||
|
public void doCrypto(View v)
|
||||||
|
{
|
||||||
|
layoutContainer.doCrypto();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If there is any message inside the right text field, share it via intent.
|
||||||
|
* Otherwise show a Toast.
|
||||||
|
*/
|
||||||
|
private void actionShareMessage()
|
||||||
|
{
|
||||||
|
if(layoutContainer.getOutput().getText().length() == 0)
|
||||||
|
{
|
||||||
|
Toast.makeText(this, R.string.error_no_text_to_send, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Intent sendIntent = new Intent();
|
||||||
|
sendIntent.setAction(Intent.ACTION_SEND);
|
||||||
|
sendIntent.putExtra(Intent.EXTRA_TEXT, layoutContainer.getOutput().getModifiedText());
|
||||||
|
sendIntent.setType("text/plain");
|
||||||
|
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Share current enigma configuration via QR-Code
|
||||||
|
*/
|
||||||
|
private void actionShareConfiguration()
|
||||||
|
{
|
||||||
|
IntentIntegrator QRIntegrator = new IntentIntegrator(this);
|
||||||
|
layoutContainer.syncStateFromLayoutToEnigma();
|
||||||
|
Log.d(APP_ID,
|
||||||
|
"Sharing configuration to QR: "+layoutContainer.getEnigma().stateToString());
|
||||||
|
QRIntegrator.shareText(APP_ID+"/"+layoutContainer.getEnigma().stateToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the enigma to a random state.
|
||||||
|
* Do not change enigma model.
|
||||||
|
*/
|
||||||
|
private void actionRandomConfiguration()
|
||||||
|
{
|
||||||
|
layoutContainer.getEnigma().randomState();
|
||||||
|
layoutContainer.syncStateFromEnigmaToLayout();
|
||||||
|
Toast.makeText(getApplicationContext(), R.string.message_random,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
layoutContainer.getOutput().setText("");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the credits dialog of the app
|
||||||
|
*/
|
||||||
|
private void actionAbout()
|
||||||
|
{
|
||||||
|
final View aboutView = View.inflate(this, R.layout.dialog_about, null);
|
||||||
|
//Get and set Version code
|
||||||
|
PackageInfo pInfo = null;
|
||||||
|
try{ pInfo = getPackageManager().getPackageInfo(this.getPackageName(), 0);}
|
||||||
|
catch (PackageManager.NameNotFoundException e){ e.printStackTrace();}
|
||||||
|
assert pInfo != null;
|
||||||
|
String version = pInfo.versionName+ " ("+pInfo.versionCode+")";
|
||||||
|
TextView versionText = (TextView) aboutView.findViewById(R.id.about_version_section);
|
||||||
|
versionText.setText(version);
|
||||||
|
|
||||||
|
//Build and show dialog
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
builder.setTitle(R.string.title_about_dialog);
|
||||||
|
builder.setView(aboutView)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
public void onClick(DialogInterface dialog, int id)
|
||||||
|
{
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.button_show_changelog, new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
public void onClick(DialogInterface dialog, int id)
|
||||||
|
{
|
||||||
|
dialog.cancel();
|
||||||
|
Uri webPage = Uri.parse(URI_CHANGELOG);
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW, webPage);
|
||||||
|
if (intent.resolveActivity(getPackageManager()) != null) {
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SecureRandom getNumberGenerator()
|
||||||
|
{
|
||||||
|
return this.numberGenerator;
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,418 +51,427 @@ import de.vanitasvitae.enigmandroid.layout.PassphraseDialogBuilder;
|
||||||
*/
|
*/
|
||||||
public class MainActivity extends Activity
|
public class MainActivity extends Activity
|
||||||
{
|
{
|
||||||
private static final int RESULT_SETTINGS = 1;
|
private static final int RESULT_SETTINGS = 1;
|
||||||
private static final String URI_CHANGELOG =
|
private static final String URI_CHANGELOG =
|
||||||
"https://github.com/vanitasvitae/EnigmAndroid/blob/master/CHANGELOG.txt";
|
"https://github.com/vanitasvitae/EnigmAndroid/blob/master/CHANGELOG.txt";
|
||||||
public static final String APP_ID = "EnigmAndroid";
|
public static final String APP_ID = "EnigmAndroid";
|
||||||
|
|
||||||
private LayoutContainer layoutContainer;
|
private LayoutContainer layoutContainer;
|
||||||
private String prefMachineType;
|
private String prefMachineType;
|
||||||
private String prefNumericLanguage;
|
private String prefNumericLanguage;
|
||||||
private String prefMessageFormatting;
|
private String prefMessageFormatting;
|
||||||
|
|
||||||
private SecureRandom secureRandom;
|
private SecureRandom secureRandom;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState)
|
public void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
secureRandom = new SecureRandom();
|
secureRandom = new SecureRandom();
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
ActivitySingleton singleton = ActivitySingleton.getInstance();
|
||||||
this.prefMachineType = sharedPreferences.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources().
|
singleton.setActivity(this);
|
||||||
getStringArray(R.array.pref_alias_machine_type)[0]);
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
ActivitySingleton singleton = ActivitySingleton.getInstance();
|
this.prefMachineType = sharedPreferences.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources().
|
||||||
singleton.setActivity(this);
|
getStringArray(R.array.pref_alias_machine_type)[0]);
|
||||||
updateContentView();
|
|
||||||
layoutContainer = LayoutContainer.createLayoutContainer(prefMachineType);
|
|
||||||
updatePreferenceValues();
|
|
||||||
//Handle shared text
|
|
||||||
Intent intent = getIntent();
|
|
||||||
String action = intent.getAction();
|
|
||||||
String type = intent.getType();
|
|
||||||
|
|
||||||
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
updateContentView();
|
||||||
if ("text/plain".equals(type))
|
layoutContainer = LayoutContainer.createLayoutContainer(prefMachineType);
|
||||||
{
|
updatePreferenceValues();
|
||||||
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
|
|
||||||
if (sharedText != null)
|
|
||||||
{
|
|
||||||
layoutContainer.getInput().setRawText(sharedText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
//Handle shared text
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
Intent intent = getIntent();
|
||||||
super.onConfigurationChanged(newConfig);
|
String action = intent.getAction();
|
||||||
this.updateContentView();
|
String type = intent.getType();
|
||||||
}
|
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||||
|
if ("text/plain".equals(type))
|
||||||
|
{
|
||||||
|
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||||
|
if (sharedText != null)
|
||||||
|
{
|
||||||
|
layoutContainer.getInput().setRawText(sharedText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateContentView()
|
@Override
|
||||||
{
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
switch (prefMachineType)
|
super.onConfigurationChanged(newConfig);
|
||||||
{
|
this.updateContentView();
|
||||||
case "I":
|
}
|
||||||
setContentView(R.layout.activity_main_i_m3);
|
|
||||||
break;
|
|
||||||
case "M3":
|
|
||||||
this.setContentView(R.layout.activity_main_i_m3);
|
|
||||||
break;
|
|
||||||
case "M4":
|
|
||||||
this.setContentView(R.layout.activity_main_m4);
|
|
||||||
break;
|
|
||||||
case "D":
|
|
||||||
this.setContentView(R.layout.activity_main_d);
|
|
||||||
break;
|
|
||||||
case "K":
|
|
||||||
case "KS":
|
|
||||||
case "KSA":
|
|
||||||
case "T":
|
|
||||||
case "R":
|
|
||||||
case "G31":
|
|
||||||
case "G312":
|
|
||||||
case "G260":
|
|
||||||
this.setContentView(R.layout.activity_main_g_k_r_t);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
this.setContentView(R.layout.activity_main_i_m3);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updatePreferenceValues()
|
private void updateContentView()
|
||||||
{
|
{
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
switch (prefMachineType)
|
||||||
this.setPrefMachineType(sharedPreferences.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources().
|
{
|
||||||
getStringArray(R.array.pref_alias_machine_type)[0]));
|
case "I":
|
||||||
this.setPrefNumericLanguage(sharedPreferences.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, getResources().
|
setContentView(R.layout.activity_main_i_m3);
|
||||||
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]));
|
break;
|
||||||
this.setPrefMessageFormatting(sharedPreferences.getString(SettingsActivity.PREF_MESSAGE_FORMATTING, getResources().
|
case "M3":
|
||||||
getStringArray(R.array.pref_alias_message_formatting)[0]));
|
this.setContentView(R.layout.activity_main_i_m3);
|
||||||
}
|
break;
|
||||||
|
case "M4":
|
||||||
|
this.setContentView(R.layout.activity_main_m4);
|
||||||
|
break;
|
||||||
|
case "D":
|
||||||
|
this.setContentView(R.layout.activity_main_d);
|
||||||
|
break;
|
||||||
|
case "K":
|
||||||
|
case "KS":
|
||||||
|
case "KSA":
|
||||||
|
case "T":
|
||||||
|
case "R":
|
||||||
|
case "G31":
|
||||||
|
case "G312":
|
||||||
|
case "G260":
|
||||||
|
this.setContentView(R.layout.activity_main_g_k_r_t);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.setContentView(R.layout.activity_main_i_m3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setPrefMachineType(String type)
|
private void updatePreferenceValues()
|
||||||
{
|
{
|
||||||
if(prefMachineType == null || !prefMachineType.equals(type))
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
{
|
this.setPrefMachineType(sharedPreferences.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources().
|
||||||
prefMachineType = type;
|
getStringArray(R.array.pref_alias_machine_type)[0]));
|
||||||
String savedInput = "";
|
this.setPrefNumericLanguage(sharedPreferences.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, getResources().
|
||||||
if(layoutContainer != null)
|
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]));
|
||||||
{
|
this.setPrefMessageFormatting(sharedPreferences.getString(SettingsActivity.PREF_MESSAGE_FORMATTING, getResources().
|
||||||
savedInput = layoutContainer.getInput().getText();
|
getStringArray(R.array.pref_alias_message_formatting)[0]));
|
||||||
}
|
}
|
||||||
updateContentView();
|
|
||||||
layoutContainer = LayoutContainer.createLayoutContainer(prefMachineType);
|
|
||||||
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
|
|
||||||
layoutContainer.getInput().setText(savedInput);
|
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
sharedPreferences.edit().putString(SettingsActivity.PREF_MACHINE_TYPE, type).apply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPrefMachineType()
|
private void setPrefMachineType(String type)
|
||||||
{
|
{
|
||||||
if(prefMachineType != null) return prefMachineType;
|
if(prefMachineType == null || !prefMachineType.equals(type))
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
{
|
||||||
this.prefMachineType = sharedPreferences.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources().
|
prefMachineType = type;
|
||||||
getStringArray(R.array.pref_alias_machine_type)[0]);
|
String savedInput = "";
|
||||||
return prefMachineType;
|
if(layoutContainer != null)
|
||||||
}
|
{
|
||||||
|
savedInput = layoutContainer.getInput().getText();
|
||||||
|
}
|
||||||
|
updateContentView();
|
||||||
|
layoutContainer = LayoutContainer.createLayoutContainer(prefMachineType);
|
||||||
|
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
|
||||||
|
layoutContainer.getInput().setText(savedInput);
|
||||||
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
sharedPreferences.edit().putString(SettingsActivity.PREF_MACHINE_TYPE, type).apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setPrefNumericLanguage(String lang)
|
public String getPrefMachineType()
|
||||||
{
|
{
|
||||||
if(prefNumericLanguage == null || !prefNumericLanguage.equals(lang))
|
if(prefMachineType != null) return prefMachineType;
|
||||||
{
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
prefNumericLanguage = lang;
|
this.prefMachineType = sharedPreferences.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources().
|
||||||
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
|
getStringArray(R.array.pref_alias_machine_type)[0]);
|
||||||
}
|
return prefMachineType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrefNumericLanguage()
|
public void setPrefNumericLanguage(String lang)
|
||||||
{
|
{
|
||||||
if(prefNumericLanguage != null) return prefNumericLanguage;
|
if(prefNumericLanguage == null || !prefNumericLanguage.equals(lang))
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
{
|
||||||
this.prefNumericLanguage = sharedPreferences.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, getResources().
|
prefNumericLanguage = lang;
|
||||||
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]);
|
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
|
||||||
return prefNumericLanguage;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrefMessageFormatting(String messageFormatting)
|
public String getPrefNumericLanguage()
|
||||||
{
|
{
|
||||||
if(prefMessageFormatting == null || !prefMessageFormatting.equals(messageFormatting))
|
if(prefNumericLanguage != null) return prefNumericLanguage;
|
||||||
{
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
prefMessageFormatting = messageFormatting;
|
this.prefNumericLanguage = sharedPreferences.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, getResources().
|
||||||
layoutContainer.setEditTextAdapter(messageFormatting);
|
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]);
|
||||||
}
|
return prefNumericLanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrefMessageFormatting()
|
public void setPrefMessageFormatting(String messageFormatting)
|
||||||
{
|
{
|
||||||
if(prefMessageFormatting != null) return prefMessageFormatting;
|
if(prefMessageFormatting == null || !prefMessageFormatting.equals(messageFormatting))
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
{
|
||||||
this.prefMessageFormatting = sharedPreferences.getString(SettingsActivity.PREF_MESSAGE_FORMATTING, getResources().
|
prefMessageFormatting = messageFormatting;
|
||||||
getStringArray(R.array.pref_alias_message_formatting)[0]);
|
layoutContainer.setEditTextAdapter(messageFormatting);
|
||||||
return prefMessageFormatting;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecureRandom getSecureRandom()
|
public String getPrefMessageFormatting()
|
||||||
{
|
{
|
||||||
return this.secureRandom;
|
if(prefMessageFormatting != null) return prefMessageFormatting;
|
||||||
}
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
this.prefMessageFormatting = sharedPreferences.getString(SettingsActivity.PREF_MESSAGE_FORMATTING, getResources().
|
||||||
|
getStringArray(R.array.pref_alias_message_formatting)[0]);
|
||||||
|
return prefMessageFormatting;
|
||||||
|
}
|
||||||
|
|
||||||
public void onDialogFinished(EnigmaStateBundle state)
|
public SecureRandom getSecureRandom()
|
||||||
{
|
{
|
||||||
layoutContainer.getEnigma().setState(state);
|
return this.secureRandom;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void onDialogFinished(EnigmaStateBundle state)
|
||||||
public boolean onCreateOptionsMenu(Menu menu)
|
{
|
||||||
{
|
layoutContainer.getEnigma().setState(state);
|
||||||
this.getMenuInflater().inflate(R.menu.main, menu);
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/**
|
public boolean onCreateOptionsMenu(Menu menu)
|
||||||
* Handle Options menu clicks
|
{
|
||||||
*/
|
this.getMenuInflater().inflate(R.menu.main, menu);
|
||||||
public boolean onOptionsItemSelected(MenuItem item)
|
return true;
|
||||||
{
|
}
|
||||||
int id = item.getItemId();
|
|
||||||
if (id == R.id.action_reset)
|
|
||||||
{
|
|
||||||
layoutContainer.resetLayout();
|
|
||||||
Toast.makeText(getApplicationContext(), R.string.message_reset,
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (id == R.id.action_random_configuration)
|
|
||||||
{
|
|
||||||
layoutContainer.getEnigma().randomState();
|
|
||||||
layoutContainer.syncStateFromEnigmaToLayout();
|
|
||||||
Toast.makeText(getApplicationContext(), R.string.message_random,
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (id == R.id.action_choose_ringsetting)
|
|
||||||
{
|
|
||||||
layoutContainer.showRingSettingsDialog();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (id == R.id.action_settings)
|
|
||||||
{
|
|
||||||
Intent i = new Intent(this, SettingsActivity.class);
|
|
||||||
startActivityForResult(i, RESULT_SETTINGS);
|
|
||||||
}
|
|
||||||
else if (id == R.id.action_about)
|
|
||||||
{
|
|
||||||
showAboutDialog();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (id == R.id.action_send)
|
|
||||||
{
|
|
||||||
if(layoutContainer.getOutput().getText().length() == 0)
|
|
||||||
{
|
|
||||||
Toast.makeText(this, R.string.error_no_text_to_send, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Intent sendIntent = new Intent();
|
|
||||||
sendIntent.setAction(Intent.ACTION_SEND);
|
|
||||||
sendIntent.putExtra(Intent.EXTRA_TEXT, layoutContainer.getOutput().getModifiedText());
|
|
||||||
sendIntent.setType("text/plain");
|
|
||||||
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (id == R.id.action_receive_scan)
|
|
||||||
{
|
|
||||||
IntentIntegrator integrator = new IntentIntegrator(this);
|
|
||||||
integrator.initiateScan();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(id == R.id.action_share_scan)
|
|
||||||
{
|
|
||||||
IntentIntegrator QRIntegrator = new IntentIntegrator(this);
|
|
||||||
layoutContainer.syncStateFromLayoutToEnigma();
|
|
||||||
Log.d(APP_ID, "Sharing configuration to QR: " + layoutContainer.getEnigma().stateToString());
|
|
||||||
QRIntegrator.shareText(APP_ID+"/"+layoutContainer.getEnigma().stateToString());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(id == R.id.action_enter_seed)
|
|
||||||
{
|
|
||||||
new PassphraseDialogBuilder().showDialog();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Set the chosen Configuration to the enigma, get the input string from the input text box and
|
/**
|
||||||
* prepare it, set the input to the prepared text, encrypt the prepared input and set the
|
* Handle Options menu clicks
|
||||||
* encrypted string to the output text box and update the spinners to their new positions.
|
*/
|
||||||
* @param v View
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
*/
|
{
|
||||||
public void doCrypto(View v)
|
int id = item.getItemId();
|
||||||
{
|
if (id == R.id.action_reset)
|
||||||
layoutContainer.doCrypto();
|
{
|
||||||
}
|
layoutContainer.resetLayout();
|
||||||
|
Toast.makeText(getApplicationContext(), R.string.message_reset,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (id == R.id.action_random_configuration)
|
||||||
|
{
|
||||||
|
layoutContainer.getEnigma().randomState();
|
||||||
|
layoutContainer.syncStateFromEnigmaToLayout();
|
||||||
|
Toast.makeText(getApplicationContext(), R.string.message_random,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
layoutContainer.getOutput().setText("");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (id == R.id.action_choose_ringsetting)
|
||||||
|
{
|
||||||
|
layoutContainer.showRingSettingsDialog();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (id == R.id.action_settings)
|
||||||
|
{
|
||||||
|
Intent i = new Intent(this, SettingsActivity.class);
|
||||||
|
startActivityForResult(i, RESULT_SETTINGS);
|
||||||
|
}
|
||||||
|
else if (id == R.id.action_about)
|
||||||
|
{
|
||||||
|
showAboutDialog();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (id == R.id.action_send)
|
||||||
|
{
|
||||||
|
if(layoutContainer.getOutput().getText().length() == 0)
|
||||||
|
{
|
||||||
|
Toast.makeText(this, R.string.error_no_text_to_send, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Intent sendIntent = new Intent();
|
||||||
|
sendIntent.setAction(Intent.ACTION_SEND);
|
||||||
|
sendIntent.putExtra(Intent.EXTRA_TEXT, layoutContainer.getOutput().getModifiedText());
|
||||||
|
sendIntent.setType("text/plain");
|
||||||
|
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (id == R.id.action_receive_scan)
|
||||||
|
{
|
||||||
|
IntentIntegrator integrator = new IntentIntegrator(this);
|
||||||
|
integrator.initiateScan();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(id == R.id.action_share_scan)
|
||||||
|
{
|
||||||
|
IntentIntegrator QRIntegrator = new IntentIntegrator(this);
|
||||||
|
layoutContainer.syncStateFromLayoutToEnigma();
|
||||||
|
Log.d(APP_ID, "Sharing configuration to QR: " + layoutContainer.getEnigma().stateToString());
|
||||||
|
QRIntegrator.shareText(APP_ID+"/"+layoutContainer.getEnigma().stateToString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(id == R.id.action_enter_seed)
|
||||||
|
{
|
||||||
|
new PassphraseDialogBuilder().showDialog();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a Dialog containing information about the app, license, usage, author and a link
|
* Set the chosen Configuration to the enigma, get the input string from the input text box and
|
||||||
* to the changelog
|
* prepare it, set the input to the prepared text, encrypt the prepared input and set the
|
||||||
*/
|
* encrypted string to the output text box and update the spinners to their new positions.
|
||||||
private void showAboutDialog()
|
* @param v View
|
||||||
{
|
*/
|
||||||
final View aboutView = View.inflate(this, R.layout.dialog_about, null);
|
public void doCrypto(View v)
|
||||||
|
{
|
||||||
|
layoutContainer.doCrypto();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show a Dialog containing information about the app, license, usage, author and a link
|
||||||
|
* to the changelog
|
||||||
|
*/
|
||||||
|
private void showAboutDialog()
|
||||||
|
{
|
||||||
|
final View aboutView = View.inflate(this, R.layout.dialog_about, null);
|
||||||
//Get and set Version code
|
//Get and set Version code
|
||||||
PackageInfo pInfo = null;
|
PackageInfo pInfo = null;
|
||||||
try{ pInfo = getPackageManager().getPackageInfo(this.getPackageName(), 0);}
|
try{ pInfo = getPackageManager().getPackageInfo(this.getPackageName(), 0);}
|
||||||
catch (PackageManager.NameNotFoundException e){ e.printStackTrace();}
|
catch (PackageManager.NameNotFoundException e){ e.printStackTrace();}
|
||||||
String version = pInfo.versionName+ " ("+pInfo.versionCode+")";
|
assert pInfo != null;
|
||||||
TextView versionText = (TextView) aboutView.findViewById(R.id.about_version_section);
|
String version = pInfo.versionName+ " ("+pInfo.versionCode+")";
|
||||||
versionText.setText(version);
|
TextView versionText = (TextView) aboutView.findViewById(R.id.about_version_section);
|
||||||
|
versionText.setText(version);
|
||||||
|
|
||||||
//Build and show dialog
|
//Build and show dialog
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle(R.string.title_about_dialog);
|
builder.setTitle(R.string.title_about_dialog);
|
||||||
builder.setView(aboutView)
|
builder.setView(aboutView)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener()
|
.setPositiveButton(R.string.dialog_positive, new DialogInterface.OnClickListener()
|
||||||
{
|
{
|
||||||
public void onClick(DialogInterface dialog, int id)
|
public void onClick(DialogInterface dialog, int id)
|
||||||
{
|
{
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.button_show_changelog, new DialogInterface.OnClickListener()
|
.setNegativeButton(R.string.button_show_changelog, new DialogInterface.OnClickListener()
|
||||||
{
|
{
|
||||||
public void onClick(DialogInterface dialog, int id)
|
public void onClick(DialogInterface dialog, int id)
|
||||||
{
|
{
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
openWebPage(URI_CHANGELOG);
|
openWebPage(URI_CHANGELOG);
|
||||||
}
|
}
|
||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle preference changes
|
* Handle preference changes
|
||||||
* @param requestCode requestCode
|
* @param requestCode requestCode
|
||||||
* @param resultCode resultCode (RESULT_SETTINGS is defined at the top)
|
* @param resultCode resultCode (RESULT_SETTINGS is defined at the top)
|
||||||
* @param data data (not important here)
|
* @param data data (not important here)
|
||||||
*/
|
*/
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case RESULT_SETTINGS:
|
case RESULT_SETTINGS:
|
||||||
{
|
{
|
||||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
this.setPrefMachineType(sharedPrefs.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources()
|
this.setPrefMachineType(sharedPrefs.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources()
|
||||||
.getStringArray(R.array.pref_alias_machine_type)[0]));
|
.getStringArray(R.array.pref_alias_machine_type)[0]));
|
||||||
this.setPrefNumericLanguage(sharedPrefs.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, getResources().
|
this.setPrefNumericLanguage(sharedPrefs.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, getResources().
|
||||||
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]));
|
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]));
|
||||||
this.setPrefMessageFormatting(sharedPrefs.getString(SettingsActivity.PREF_MESSAGE_FORMATTING,
|
this.setPrefMessageFormatting(sharedPrefs.getString(SettingsActivity.PREF_MESSAGE_FORMATTING,
|
||||||
getResources().getStringArray(R.array.pref_alias_message_formatting)[0]));
|
getResources().getStringArray(R.array.pref_alias_message_formatting)[0]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IntentIntegrator.REQUEST_CODE:
|
case IntentIntegrator.REQUEST_CODE:
|
||||||
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||||
if (scanResult != null) {
|
if (scanResult != null) {
|
||||||
String content = scanResult.getContents();
|
String content = scanResult.getContents();
|
||||||
if(content == null) Log.e(APP_ID, "Error! Received nothing from QR-Code!");
|
if(content == null) Log.e(APP_ID, "Error! Received nothing from QR-Code!");
|
||||||
else {
|
else {
|
||||||
Log.d(APP_ID, "Received " + content + " from QR-Code!");
|
Log.d(APP_ID, "Received " + content + " from QR-Code!");
|
||||||
restoreStateFromCode(content);
|
restoreStateFromCode(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set EnigmAndroid into a certain state as described in the QR-Code
|
* Set EnigmAndroid into a certain state as described in the QR-Code
|
||||||
* @param mem content of the QR-Code
|
* @param mem content of the QR-Code
|
||||||
*/
|
*/
|
||||||
public void restoreStateFromCode(String mem)
|
public void restoreStateFromCode(String mem)
|
||||||
{
|
{
|
||||||
if(!mem.startsWith(APP_ID+"/"))
|
if(!mem.startsWith(APP_ID+"/"))
|
||||||
{
|
{
|
||||||
Toast.makeText(this, R.string.error_no_valid_qr, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.error_no_valid_qr, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mem = mem.substring((APP_ID+"/").length());
|
String inputString = layoutContainer.getInput().getText();
|
||||||
BigInteger s = new BigInteger(mem, 16);
|
mem = mem.substring((APP_ID+"/").length());
|
||||||
Log.d(APP_ID, "Try to restore configuration from BigInteger value "+ s.toString());
|
BigInteger s = new BigInteger(mem, 16);
|
||||||
setPrefMachineType(Enigma.chooseEnigmaFromSave(s));
|
Log.d(APP_ID, "Try to restore configuration from BigInteger value "+ s.toString());
|
||||||
updateContentView();
|
setPrefMachineType(Enigma.chooseEnigmaFromSave(s));
|
||||||
layoutContainer = LayoutContainer.createLayoutContainer(getPrefMachineType());
|
updateContentView();
|
||||||
layoutContainer.getEnigma().restoreState(Enigma.removeDigit(s,20));
|
layoutContainer = LayoutContainer.createLayoutContainer(getPrefMachineType());
|
||||||
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
|
layoutContainer.getEnigma().restoreState(Enigma.removeDigit(s,20));
|
||||||
layoutContainer.syncStateFromEnigmaToLayout();
|
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
|
||||||
}
|
layoutContainer.syncStateFromEnigmaToLayout();
|
||||||
}
|
layoutContainer.getInput().setText(inputString);
|
||||||
|
layoutContainer.getOutput().setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set EnigmAndroid into a state calculated from the seed.
|
* Set EnigmAndroid into a state calculated from the seed.
|
||||||
* @param seed seed
|
* @param seed seed
|
||||||
*/
|
*/
|
||||||
public void createStateFromSeed(String seed)
|
public void createStateFromSeed(String seed)
|
||||||
{
|
{
|
||||||
setPrefMachineType(Enigma.chooseEnigmaFromSeed(seed));
|
String inputString = layoutContainer.getInput().getText();
|
||||||
updateContentView();
|
setPrefMachineType(Enigma.chooseEnigmaFromSeed(seed));
|
||||||
layoutContainer = LayoutContainer.createLayoutContainer(getPrefMachineType());
|
updateContentView();
|
||||||
layoutContainer.getEnigma().setStateFromSeed(seed);
|
layoutContainer = LayoutContainer.createLayoutContainer(getPrefMachineType());
|
||||||
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
|
layoutContainer.getEnigma().setStateFromSeed(seed);
|
||||||
layoutContainer.syncStateFromEnigmaToLayout();
|
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
|
||||||
}
|
layoutContainer.syncStateFromEnigmaToLayout();
|
||||||
|
layoutContainer.getInput().setText(inputString);
|
||||||
|
layoutContainer.getOutput().setText("");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the web page with the URL url
|
* Open the web page with the URL url
|
||||||
* @param url URL of the website
|
* @param url URL of the website
|
||||||
*/
|
*/
|
||||||
private void openWebPage(String url) {
|
private void openWebPage(String url) {
|
||||||
Uri webPage = Uri.parse(url);
|
Uri webPage = Uri.parse(url);
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, webPage);
|
Intent intent = new Intent(Intent.ACTION_VIEW, webPage);
|
||||||
if (intent.resolveActivity(getPackageManager()) != null) {
|
if (intent.resolveActivity(getPackageManager()) != null) {
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton that grants access to an Activity from anywhere within the app
|
* Singleton that grants access to an Activity from anywhere within the app
|
||||||
*/
|
*/
|
||||||
public static class ActivitySingleton
|
public static class ActivitySingleton
|
||||||
{
|
{
|
||||||
private static ActivitySingleton instance = null;
|
private static ActivitySingleton instance = null;
|
||||||
private Activity activity;
|
private Activity activity;
|
||||||
|
|
||||||
//private constructor
|
//private constructor
|
||||||
private ActivitySingleton(){}
|
private ActivitySingleton(){}
|
||||||
//Singleton method
|
//Singleton method
|
||||||
public static ActivitySingleton getInstance()
|
public static ActivitySingleton getInstance()
|
||||||
{
|
{
|
||||||
if(instance == null) instance = new ActivitySingleton();
|
if(instance == null) instance = new ActivitySingleton();
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set an Activity that the Singleton returns
|
* Set an Activity that the Singleton returns
|
||||||
* @param activity activity that's stored
|
* @param activity activity that's stored
|
||||||
*/
|
*/
|
||||||
public void setActivity(Activity activity)
|
public void setActivity(Activity activity)
|
||||||
{
|
{
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the stored Activity
|
* Returns the stored Activity
|
||||||
* @return stored Activity
|
* @return stored Activity
|
||||||
*/
|
*/
|
||||||
public Activity getActivity()
|
public Activity getActivity()
|
||||||
{
|
{
|
||||||
return activity;
|
return activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package de.vanitasvitae.enigmandroid;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that represents the settings activity.
|
* Class that represents the settings activity.
|
||||||
|
@ -26,10 +27,15 @@ public class SettingsActivity extends PreferenceActivity
|
||||||
{
|
{
|
||||||
public static final String PREF_NUMERIC_LANGUAGE = "prefNumericLanguage";
|
public static final String PREF_NUMERIC_LANGUAGE = "prefNumericLanguage";
|
||||||
public static final String PREF_MACHINE_TYPE = "prefMachineType";
|
public static final String PREF_MACHINE_TYPE = "prefMachineType";
|
||||||
public static final String PREF_ANOMALY = "prefAnomaly";
|
|
||||||
public static final String PREF_MESSAGE_FORMATTING = "prefMessageFormatting";
|
public static final String PREF_MESSAGE_FORMATTING = "prefMessageFormatting";
|
||||||
public static final String PREF_REPLACE_SPECIAL_CHARACTERS = "prefReplaceSpecialCharacters";
|
public static final String PREF_REPLACE_SPECIAL_CHARACTERS = "prefReplaceSpecialCharacters";
|
||||||
public static final String PREF_REPLACE_SPACES = "prefReplaceSpaces";
|
public static final String PREF_SAVED_ENIGMA_STATE = "prefSavedEnigmaState";
|
||||||
|
|
||||||
|
private String previousPrefNumericLanguage;
|
||||||
|
private String previousPrefMachineType;
|
||||||
|
private String previousPrefMessageFormatting;
|
||||||
|
private boolean previousPrefReplaceSpecialCharacters;
|
||||||
|
private String previousPrefSavedEnigmaState;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
|
@ -37,5 +43,143 @@ public class SettingsActivity extends PreferenceActivity
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
addPreferencesFromResource(R.xml.pref_page);
|
addPreferencesFromResource(R.xml.pref_page);
|
||||||
|
this.previousPrefMachineType = getPrefMachineType();
|
||||||
|
this.previousPrefSavedEnigmaState = getPrefSavedEnigmaState();
|
||||||
|
this.previousPrefMessageFormatting = getPrefMessageFormatting();
|
||||||
|
this.previousPrefNumericLanguage = getPrefNumericLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPrefNumericLanguage()
|
||||||
|
{
|
||||||
|
return PreferenceManager.getDefaultSharedPreferences(this).getString(
|
||||||
|
PREF_NUMERIC_LANGUAGE,
|
||||||
|
getResources().getStringArray(R.array.pref_alias_message_formatting)[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrefNumericLanguage(String lang)
|
||||||
|
{
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||||
|
.putString(PREF_NUMERIC_LANGUAGE, lang).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean prefNumericLanguageChanged()
|
||||||
|
{
|
||||||
|
if(this.previousPrefNumericLanguage == null || !this.previousPrefNumericLanguage.equals(getPrefNumericLanguage()))
|
||||||
|
{
|
||||||
|
this.previousPrefNumericLanguage = this.getPrefNumericLanguage();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getPrefReplaceSpecialCharacters()
|
||||||
|
{
|
||||||
|
return PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
|
||||||
|
PREF_REPLACE_SPECIAL_CHARACTERS, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrefReplaceSpecialCharacters(boolean replace)
|
||||||
|
{
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||||
|
.putBoolean(PREF_REPLACE_SPECIAL_CHARACTERS, replace).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean prefReplaceSpecialCharactersChanged()
|
||||||
|
{
|
||||||
|
boolean changed = previousPrefReplaceSpecialCharacters != getPrefReplaceSpecialCharacters();
|
||||||
|
if(changed)
|
||||||
|
{
|
||||||
|
previousPrefReplaceSpecialCharacters = getPrefReplaceSpecialCharacters();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrefMachineType()
|
||||||
|
{
|
||||||
|
return PreferenceManager.getDefaultSharedPreferences(this).getString(
|
||||||
|
PREF_MACHINE_TYPE,
|
||||||
|
getResources().getStringArray(R.array.pref_alias_machine_type)[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrefMachineType(String pref)
|
||||||
|
{
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||||
|
.putString(PREF_MACHINE_TYPE, pref).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean prefMachineTypeChanged()
|
||||||
|
{
|
||||||
|
if(this.previousPrefMachineType == null || !this.previousPrefMachineType.equals(getPrefMachineType()))
|
||||||
|
{
|
||||||
|
this.previousPrefMachineType = this.getPrefMachineType();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrefSavedEnigmaState()
|
||||||
|
{
|
||||||
|
return PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
.getString(PREF_SAVED_ENIGMA_STATE, "-1");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param state HEX
|
||||||
|
*/
|
||||||
|
public void setPrefSavedEnigmaState(String state)
|
||||||
|
{
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||||
|
.putString(PREF_SAVED_ENIGMA_STATE, state).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean prefSavedEnigmaStateChanged()
|
||||||
|
{
|
||||||
|
if(this.previousPrefSavedEnigmaState == null || !this.previousPrefSavedEnigmaState
|
||||||
|
.equals(getPrefSavedEnigmaState()))
|
||||||
|
{
|
||||||
|
this.previousPrefSavedEnigmaState = this.getPrefSavedEnigmaState();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrefMessageFormatting()
|
||||||
|
{
|
||||||
|
return PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
.getString(SettingsActivity.PREF_MESSAGE_FORMATTING, getResources().
|
||||||
|
getStringArray(R.array.pref_alias_message_formatting)[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrefMessageFormatting(String format)
|
||||||
|
{
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(this).edit()
|
||||||
|
.putString(PREF_MESSAGE_FORMATTING, format).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean prefMessageFormattingChanged()
|
||||||
|
{
|
||||||
|
if(this.previousPrefMessageFormatting == null || !this.previousPrefMessageFormatting
|
||||||
|
.equals(getPrefMessageFormatting()))
|
||||||
|
{
|
||||||
|
this.previousPrefMessageFormatting = this.getPrefMessageFormatting();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SettingsSingleton extends SettingsActivity
|
||||||
|
{
|
||||||
|
private static SettingsActivity instance;
|
||||||
|
private SettingsSingleton()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SettingsActivity getInstance()
|
||||||
|
{
|
||||||
|
if(instance == null) instance = new SettingsActivity();
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.widget.Spinner;
|
||||||
|
|
||||||
import de.vanitasvitae.enigmandroid.MainActivity;
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
||||||
import de.vanitasvitae.enigmandroid.R;
|
import de.vanitasvitae.enigmandroid.R;
|
||||||
|
import de.vanitasvitae.enigmandroid.SettingsActivity;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.Enigma;
|
import de.vanitasvitae.enigmandroid.enigma.Enigma;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
|
import de.vanitasvitae.enigmandroid.enigma.EnigmaStateBundle;
|
||||||
import de.vanitasvitae.enigmandroid.enigma.inputPreparer.EditTextAdapter;
|
import de.vanitasvitae.enigmandroid.enigma.inputPreparer.EditTextAdapter;
|
||||||
|
@ -60,6 +61,7 @@ public abstract class LayoutContainer
|
||||||
this.outputView = (EditText) main.findViewById(R.id.output);
|
this.outputView = (EditText) main.findViewById(R.id.output);
|
||||||
input = EditTextAdapter.createEditTextAdapter(inputView, main.getPrefMessageFormatting());
|
input = EditTextAdapter.createEditTextAdapter(inputView, main.getPrefMessageFormatting());
|
||||||
output = EditTextAdapter.createEditTextAdapter(outputView, main.getPrefMessageFormatting());
|
output = EditTextAdapter.createEditTextAdapter(outputView, main.getPrefMessageFormatting());
|
||||||
|
inputPreparer = InputPreparer.createInputPreparer();
|
||||||
initializeLayout();
|
initializeLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +88,11 @@ public abstract class LayoutContainer
|
||||||
return this.output;
|
return this.output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LayoutContainer createLayoutContainer()
|
||||||
|
{
|
||||||
|
return createLayoutContainer(SettingsActivity.SettingsSingleton.getInstance().getPrefMachineType());
|
||||||
|
}
|
||||||
|
|
||||||
public static LayoutContainer createLayoutContainer(String enigmaType)
|
public static LayoutContainer createLayoutContainer(String enigmaType)
|
||||||
{
|
{
|
||||||
switch (enigmaType) {
|
switch (enigmaType) {
|
||||||
|
|
|
@ -40,6 +40,7 @@ public class LayoutContainer_D extends LayoutContainer
|
||||||
public LayoutContainer_D()
|
public LayoutContainer_D()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
main.setContentView(R.layout.activity_main_d);
|
||||||
main.setTitle("D - EnigmAndroid");
|
main.setTitle("D - EnigmAndroid");
|
||||||
this.resetLayout();
|
this.resetLayout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class LayoutContainer_G31 extends LayoutContainer
|
||||||
public LayoutContainer_G31()
|
public LayoutContainer_G31()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
main.setContentView(R.layout.activity_main_g_k_r_t);
|
||||||
main.setTitle("G31 - EnigmAndroid");
|
main.setTitle("G31 - EnigmAndroid");
|
||||||
this.resetLayout();
|
this.resetLayout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class LayoutContainer_I extends LayoutContainer
|
||||||
public LayoutContainer_I()
|
public LayoutContainer_I()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
main.setContentView(R.layout.activity_main_i_m3);
|
||||||
main.setTitle("I - EnigmAndroid");
|
main.setTitle("I - EnigmAndroid");
|
||||||
this.resetLayout();
|
this.resetLayout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import de.vanitasvitae.enigmandroid.enigma.Enigma_K;
|
||||||
*/
|
*/
|
||||||
public class LayoutContainer_K extends LayoutContainer
|
public class LayoutContainer_K extends LayoutContainer
|
||||||
{
|
{
|
||||||
private Enigma_K enigma;
|
protected Enigma enigma;
|
||||||
|
|
||||||
protected Spinner rotor1View;
|
protected Spinner rotor1View;
|
||||||
protected Spinner rotor2View;
|
protected Spinner rotor2View;
|
||||||
|
@ -43,6 +43,7 @@ public class LayoutContainer_K extends LayoutContainer
|
||||||
public LayoutContainer_K()
|
public LayoutContainer_K()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
main.setContentView(R.layout.activity_main_g_k_r_t);
|
||||||
main.setTitle("K - EnigmAndroid");
|
main.setTitle("K - EnigmAndroid");
|
||||||
this.resetLayout();
|
this.resetLayout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,19 +27,8 @@ import de.vanitasvitae.enigmandroid.enigma.Enigma_K_Swiss_Standard;
|
||||||
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 LayoutContainer_K_Swiss extends LayoutContainer
|
public class LayoutContainer_K_Swiss extends LayoutContainer_K
|
||||||
{
|
{
|
||||||
private Enigma_K_Swiss_Standard enigma;
|
|
||||||
|
|
||||||
protected Spinner rotor1View;
|
|
||||||
protected Spinner rotor2View;
|
|
||||||
protected Spinner rotor3View;
|
|
||||||
|
|
||||||
protected Spinner rotor1PositionView;
|
|
||||||
protected Spinner rotor2PositionView;
|
|
||||||
protected Spinner rotor3PositionView;
|
|
||||||
protected Spinner reflectorPositionView;
|
|
||||||
|
|
||||||
public LayoutContainer_K_Swiss()
|
public LayoutContainer_K_Swiss()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
@ -47,34 +36,6 @@ public class LayoutContainer_K_Swiss extends LayoutContainer
|
||||||
this.resetLayout();
|
this.resetLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Enigma getEnigma() {
|
|
||||||
return this.enigma;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initializeLayout() {
|
|
||||||
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);
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public void resetLayout() {
|
public void resetLayout() {
|
||||||
enigma = new Enigma_K_Swiss_Standard();
|
enigma = new Enigma_K_Swiss_Standard();
|
||||||
|
@ -82,37 +43,4 @@ public class LayoutContainer_K_Swiss extends LayoutContainer
|
||||||
output.setText("");
|
output.setText("");
|
||||||
input.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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,19 +27,8 @@ import de.vanitasvitae.enigmandroid.enigma.Enigma_K_Swiss_Airforce;
|
||||||
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 LayoutContainer_K_Swiss_Airforce extends LayoutContainer
|
public class LayoutContainer_K_Swiss_Airforce extends LayoutContainer_K
|
||||||
{
|
{
|
||||||
private Enigma_K_Swiss_Airforce enigma;
|
|
||||||
|
|
||||||
protected Spinner rotor1View;
|
|
||||||
protected Spinner rotor2View;
|
|
||||||
protected Spinner rotor3View;
|
|
||||||
|
|
||||||
protected Spinner rotor1PositionView;
|
|
||||||
protected Spinner rotor2PositionView;
|
|
||||||
protected Spinner rotor3PositionView;
|
|
||||||
protected Spinner reflectorPositionView;
|
|
||||||
|
|
||||||
public LayoutContainer_K_Swiss_Airforce()
|
public LayoutContainer_K_Swiss_Airforce()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
@ -47,34 +36,6 @@ public class LayoutContainer_K_Swiss_Airforce extends LayoutContainer
|
||||||
this.resetLayout();
|
this.resetLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Enigma getEnigma() {
|
|
||||||
return this.enigma;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initializeLayout() {
|
|
||||||
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);
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public void resetLayout() {
|
public void resetLayout() {
|
||||||
enigma = new Enigma_K_Swiss_Airforce();
|
enigma = new Enigma_K_Swiss_Airforce();
|
||||||
|
@ -82,37 +43,4 @@ public class LayoutContainer_K_Swiss_Airforce extends LayoutContainer
|
||||||
output.setText("");
|
output.setText("");
|
||||||
input.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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ public class LayoutContainer_M4 extends LayoutContainer
|
||||||
public LayoutContainer_M4()
|
public LayoutContainer_M4()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
main.setContentView(R.layout.activity_main_m4);
|
||||||
main.setTitle("M4 - EnigmAndroid");
|
main.setTitle("M4 - EnigmAndroid");
|
||||||
this.resetLayout();
|
this.resetLayout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class LayoutContainer_R extends LayoutContainer
|
||||||
public LayoutContainer_R()
|
public LayoutContainer_R()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
main.setContentView(R.layout.activity_main_g_k_r_t);
|
||||||
main.setTitle("R - EnigmAndroid");
|
main.setTitle("R - EnigmAndroid");
|
||||||
this.resetLayout();
|
this.resetLayout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class LayoutContainer_T extends LayoutContainer
|
||||||
public LayoutContainer_T()
|
public LayoutContainer_T()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
main.setContentView(R.layout.activity_main_g_k_r_t);
|
||||||
main.setTitle("T - EnigmAndroid");
|
main.setTitle("T - EnigmAndroid");
|
||||||
this.resetLayout();
|
this.resetLayout();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue