2019-01-04 20:40:11 +01:00
|
|
|
/**
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2015-08-27 01:48:33 +02:00
|
|
|
package de.vanitasvitae.enigmandroid.enigma.inputPreparer;
|
2015-08-16 02:59:56 +02:00
|
|
|
|
2015-09-22 21:10:41 +02:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
|
|
|
import de.vanitasvitae.enigmandroid.MainActivity;
|
|
|
|
import de.vanitasvitae.enigmandroid.R;
|
|
|
|
import de.vanitasvitae.enigmandroid.SettingsActivity;
|
|
|
|
|
2015-08-16 02:59:56 +02:00
|
|
|
/**
|
2015-08-27 01:48:33 +02:00
|
|
|
* Preparer class that prepares input text to only consist of [A..Z]
|
2015-08-16 02:59:56 +02:00
|
|
|
* Copyright (C) 2015 Paul Schaub
|
|
|
|
*/
|
2015-09-22 21:10:41 +02:00
|
|
|
public abstract class InputPreparer {
|
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
|
|
|
InputPreparer child;
|
2015-09-22 21:10:41 +02:00
|
|
|
|
|
|
|
public String prepareString(String in) {
|
|
|
|
if (child != null)
|
|
|
|
return child.prepareString(this.prepare(in));
|
|
|
|
else
|
|
|
|
return prepare(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected abstract String prepare(String input);
|
|
|
|
|
|
|
|
public static InputPreparer createInputPreparer()
|
2015-08-16 02:59:56 +02:00
|
|
|
{
|
2015-09-22 21:10:41 +02:00
|
|
|
MainActivity main = (MainActivity) MainActivity.ActivitySingleton.getInstance().getActivity();
|
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(main);
|
2015-08-16 02:59:56 +02:00
|
|
|
|
2015-09-22 21:10:41 +02:00
|
|
|
boolean replaceSpecialChars = sharedPreferences.getBoolean(SettingsActivity.PREF_REPLACE_SPECIAL_CHARACTERS, true);
|
|
|
|
String num_lang = sharedPreferences.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, main.getResources().
|
|
|
|
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]);
|
|
|
|
InputPreparer inPrep = new RemoveIllegalCharacters();
|
|
|
|
if(replaceSpecialChars) inPrep = new ReplaceSpecialCharacters(inPrep);
|
|
|
|
switch (num_lang)
|
2015-08-16 02:59:56 +02:00
|
|
|
{
|
2015-09-22 21:10:41 +02:00
|
|
|
case "de": inPrep = new ReplaceNumbersGerman(inPrep);
|
|
|
|
break;
|
|
|
|
case "en": inPrep = new ReplaceNumbersEnglish(inPrep);
|
|
|
|
break;
|
|
|
|
case "fr": inPrep = new ReplaceNumbersFrench(inPrep);
|
|
|
|
break;
|
2015-10-09 00:57:54 +02:00
|
|
|
case "sp": inPrep = new ReplaceNumbersSpanish(inPrep);
|
|
|
|
break;
|
|
|
|
case "it": inPrep = new ReplaceNumbersItalian(inPrep);
|
|
|
|
break;
|
2015-09-22 21:10:41 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return inPrep;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class ReplaceSpecialCharacters extends InputPreparer {
|
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
|
|
|
// --Commented out by Inspection START (07.11.15 19:47):
|
|
|
|
// public ReplaceSpecialCharacters() {
|
|
|
|
// this.child = null;
|
|
|
|
// }
|
|
|
|
// --Commented out by Inspection STOP (07.11.15 19:47)
|
2015-09-22 21:10:41 +02:00
|
|
|
|
|
|
|
public ReplaceSpecialCharacters(InputPreparer child) {
|
|
|
|
this.child = child;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String prepare(String input) {
|
|
|
|
input = input.toUpperCase();
|
|
|
|
return input.replace("Ä", "AE").replace("Ö", "OE").replace("Ü", "UE").replace("ß", "SS").replace(" ","");
|
2015-08-16 02:59:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-22 21:10:41 +02:00
|
|
|
* Concrete implementation of a german InputPreparer
|
2015-08-16 02:59:56 +02:00
|
|
|
*/
|
2015-09-22 21:10:41 +02:00
|
|
|
public static class ReplaceNumbersGerman extends InputPreparer {
|
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
|
|
|
// --Commented out by Inspection START (07.11.15 19:47):
|
|
|
|
// public ReplaceNumbersGerman() {
|
|
|
|
// this.child = null;
|
|
|
|
// }
|
|
|
|
// --Commented out by Inspection STOP (07.11.15 19:47)
|
2015-09-22 21:10:41 +02:00
|
|
|
|
|
|
|
public ReplaceNumbersGerman(InputPreparer child) {
|
|
|
|
this.child = child;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String prepare(String input) {
|
|
|
|
input = input.replace("0", "NULL")
|
|
|
|
.replace("1", "EINS")
|
|
|
|
.replace("2", "ZWEI")
|
|
|
|
.replace("3", "DREI")
|
|
|
|
.replace("4", "VIER")
|
|
|
|
.replace("5", "FUENF")
|
|
|
|
.replace("6", "SECHS")
|
|
|
|
.replace("7", "SIEBEN")
|
|
|
|
.replace("8", "ACHT")
|
|
|
|
.replace("9", "NEUN");
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
}
|
2015-08-16 02:59:56 +02:00
|
|
|
|
|
|
|
/**
|
2015-09-22 21:10:41 +02:00
|
|
|
* Concrete implementation of a french InputPreparer
|
2015-08-16 02:59:56 +02:00
|
|
|
*/
|
2015-09-22 21:10:41 +02:00
|
|
|
public static class ReplaceNumbersFrench extends InputPreparer {
|
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
|
|
|
// --Commented out by Inspection START (07.11.15 19:47):
|
|
|
|
// public ReplaceNumbersFrench() {
|
|
|
|
// this.child = null;
|
|
|
|
// }
|
|
|
|
// --Commented out by Inspection STOP (07.11.15 19:47)
|
2015-08-16 02:59:56 +02:00
|
|
|
|
2015-09-22 21:10:41 +02:00
|
|
|
public ReplaceNumbersFrench(InputPreparer child) {
|
|
|
|
this.child = child;
|
2015-08-16 02:59:56 +02:00
|
|
|
}
|
|
|
|
|
2015-09-22 21:10:41 +02:00
|
|
|
protected String prepare(String input) {
|
|
|
|
input = input.replace("0", "ZERO")
|
|
|
|
.replace("1", "UN")
|
|
|
|
.replace("2", "DEUX")
|
|
|
|
.replace("3", "TROIS")
|
|
|
|
.replace("4", "QUATRE")
|
|
|
|
.replace("5", "CINQ")
|
|
|
|
.replace("6", "SIX")
|
|
|
|
.replace("7", "SEPT")
|
|
|
|
.replace("8", "HUIT")
|
|
|
|
.replace("9", "NEUF");
|
|
|
|
return input;
|
2015-08-16 02:59:56 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-27 01:48:33 +02:00
|
|
|
|
2015-09-22 21:10:41 +02:00
|
|
|
/**
|
|
|
|
* Concrete implementation of an english InputPreparer
|
|
|
|
*/
|
|
|
|
public static class ReplaceNumbersEnglish extends InputPreparer {
|
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
|
|
|
// --Commented out by Inspection START (07.11.15 19:47):
|
|
|
|
// public ReplaceNumbersEnglish() {
|
|
|
|
// this.child = null;
|
|
|
|
// }
|
|
|
|
// --Commented out by Inspection STOP (07.11.15 19:47)
|
2015-08-27 01:48:33 +02:00
|
|
|
|
2015-09-22 21:10:41 +02:00
|
|
|
public ReplaceNumbersEnglish(InputPreparer child) {
|
|
|
|
this.child = child;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String prepare(String input) {
|
|
|
|
input = input.replace("0", "ZERO")
|
|
|
|
.replace("1", "ONE")
|
|
|
|
.replace("2", "TWO")
|
|
|
|
.replace("3", "THREE")
|
|
|
|
.replace("4", "FOUR")
|
|
|
|
.replace("5", "FIVE")
|
|
|
|
.replace("6", "SIX")
|
|
|
|
.replace("7", "SEVEN")
|
|
|
|
.replace("8", "EIGHT")
|
|
|
|
.replace("9", "NINE");
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-09 00:57:54 +02:00
|
|
|
/**
|
|
|
|
* Concrete implementation of a spanish InputPreparer
|
|
|
|
*/
|
|
|
|
public static class ReplaceNumbersSpanish extends InputPreparer {
|
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
|
|
|
// --Commented out by Inspection START (07.11.15 19:47):
|
|
|
|
// public ReplaceNumbersSpanish() {
|
|
|
|
// this.child = null;
|
|
|
|
// }
|
|
|
|
// --Commented out by Inspection STOP (07.11.15 19:47)
|
2015-10-09 00:57:54 +02:00
|
|
|
|
|
|
|
public ReplaceNumbersSpanish(InputPreparer child) {
|
|
|
|
this.child = child;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String prepare(String input) {
|
|
|
|
input = input.replace("0", "CERO")
|
|
|
|
.replace("1", "UNO")
|
|
|
|
.replace("2", "DOS")
|
|
|
|
.replace("3", "TRES")
|
|
|
|
.replace("4", "CUATRO")
|
|
|
|
.replace("5", "CINCO")
|
|
|
|
.replace("6", "SEIS")
|
|
|
|
.replace("7", "SIETE")
|
|
|
|
.replace("8", "OCHO")
|
|
|
|
.replace("9", "NUEVE");
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Concrete implementation of a spanish InputPreparer
|
|
|
|
*/
|
|
|
|
public static class ReplaceNumbersItalian extends InputPreparer {
|
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
|
|
|
// --Commented out by Inspection START (07.11.15 19:47):
|
|
|
|
// public ReplaceNumbersItalian() {
|
|
|
|
// this.child = null;
|
|
|
|
// }
|
|
|
|
// --Commented out by Inspection STOP (07.11.15 19:47)
|
2015-10-09 00:57:54 +02:00
|
|
|
|
|
|
|
public ReplaceNumbersItalian(InputPreparer child) {
|
|
|
|
this.child = child;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String prepare(String input) {
|
|
|
|
input = input.replace("0", "ZERO")
|
|
|
|
.replace("1", "UNO")
|
|
|
|
.replace("2", "DUE")
|
|
|
|
.replace("3", "TRE")
|
|
|
|
.replace("4", "QUATTRO")
|
|
|
|
.replace("5", "CINQUE")
|
|
|
|
.replace("6", "SEI")
|
|
|
|
.replace("7", "SETTE")
|
|
|
|
.replace("8", "OTTO")
|
|
|
|
.replace("9", "NOVE");
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-22 21:10:41 +02:00
|
|
|
/**
|
|
|
|
* "Final Stage" of Input preparing. This should always be called last
|
|
|
|
* (choose this as the inner most capsule of InputPreparers)
|
2015-10-04 22:51:35 +02:00
|
|
|
* This cant have child InputPreparers.
|
2015-09-22 21:10:41 +02:00
|
|
|
* This Input preparer removes all characters from the string besides A..Z
|
|
|
|
*/
|
|
|
|
public static class RemoveIllegalCharacters extends InputPreparer
|
2015-08-27 01:48:33 +02:00
|
|
|
{
|
2015-09-22 21:10:41 +02:00
|
|
|
public RemoveIllegalCharacters()
|
|
|
|
{
|
|
|
|
this.child = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String prepare(String in)
|
|
|
|
{
|
|
|
|
String out = "";
|
|
|
|
for(char c : in.toUpperCase().toCharArray())
|
|
|
|
{
|
|
|
|
if(c>=65 && c<=90) out = out+c;
|
|
|
|
}
|
|
|
|
return out;
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-16 02:59:56 +02:00
|
|
|
}
|