2015-02-04 20:51:31 +01:00
|
|
|
package de.vanitasvitae.enigmandroid;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2015-02-18 21:51:40 +01:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.DialogInterface;
|
2015-02-24 22:04:02 +01:00
|
|
|
import android.content.Intent;
|
2015-02-24 23:36:24 +01:00
|
|
|
import android.content.SharedPreferences;
|
2015-08-27 01:48:33 +02:00
|
|
|
import android.content.res.Configuration;
|
2015-03-14 00:29:43 +01:00
|
|
|
import android.net.Uri;
|
2015-02-04 20:51:31 +01:00
|
|
|
import android.os.Bundle;
|
2015-02-24 23:36:24 +01:00
|
|
|
import android.preference.PreferenceManager;
|
2015-09-15 02:06:47 +02:00
|
|
|
import android.util.Log;
|
2015-02-04 20:51:31 +01:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2015-08-27 01:48:33 +02:00
|
|
|
import android.view.View;
|
2015-02-04 20:51:31 +01:00
|
|
|
import android.widget.Toast;
|
2015-08-27 01:48:33 +02:00
|
|
|
|
2015-09-15 02:06:47 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2015-08-27 01:48:33 +02:00
|
|
|
import de.vanitasvitae.enigmandroid.enigma.inputPreparer.InputPreparer;
|
|
|
|
import de.vanitasvitae.enigmandroid.layout.LayoutContainer;
|
|
|
|
|
2015-08-16 02:59:56 +02:00
|
|
|
/**
|
|
|
|
* Main Android Activity of the app
|
|
|
|
* Copyright (C) 2015 Paul Schaub
|
|
|
|
|
|
|
|
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 2 of the License, or
|
|
|
|
(at your option) 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.
|
2015-02-04 20:51:31 +01:00
|
|
|
|
2015-08-16 02:59:56 +02:00
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
* @author vanitasvitae
|
|
|
|
*/
|
2015-02-04 20:51:31 +01:00
|
|
|
public class MainActivity extends Activity
|
|
|
|
{
|
2015-02-24 23:36:24 +01:00
|
|
|
private static final int RESULT_SETTINGS = 1;
|
2015-08-27 01:48:33 +02:00
|
|
|
private static final String URI_CHANGELOG =
|
|
|
|
"https://github.com/vanitasvitae/EnigmAndroid/blob/master/CHANGELOG.txt";
|
2015-02-24 23:36:24 +01:00
|
|
|
|
2015-08-27 01:48:33 +02:00
|
|
|
LayoutContainer layoutContainer;
|
|
|
|
protected String prefMachineType;
|
|
|
|
protected boolean prefAnomaly;
|
|
|
|
protected String prefNumericLanguage;
|
2015-09-10 02:56:48 +02:00
|
|
|
protected String prefMessageFormatting;
|
2015-02-18 21:51:40 +01:00
|
|
|
|
2015-02-04 20:51:31 +01:00
|
|
|
@Override
|
2015-02-18 21:51:40 +01:00
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
2015-02-04 20:51:31 +01:00
|
|
|
super.onCreate(savedInstanceState);
|
2015-09-15 02:06:47 +02:00
|
|
|
Log.d("Activity","OnCreate!");
|
2015-08-16 02:59:56 +02:00
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
2015-09-22 21:10:41 +02:00
|
|
|
this.prefMachineType = sharedPreferences.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources().
|
|
|
|
getStringArray(R.array.pref_alias_machine_type)[0]);
|
2015-08-15 03:53:02 +02:00
|
|
|
ActivitySingleton singleton = ActivitySingleton.getInstance();
|
|
|
|
singleton.setActivity(this);
|
2015-08-27 01:48:33 +02:00
|
|
|
updateContentView();
|
|
|
|
layoutContainer = LayoutContainer.createLayoutContainer(prefMachineType);
|
|
|
|
updatePreferenceValues();
|
2015-08-15 03:53:02 +02:00
|
|
|
//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)
|
|
|
|
{
|
2015-09-10 02:56:48 +02:00
|
|
|
layoutContainer.getInput().setRawText(sharedText);
|
2015-08-15 03:53:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-04 20:51:31 +01:00
|
|
|
}
|
|
|
|
|
2015-09-15 02:06:47 +02:00
|
|
|
/**
|
|
|
|
* Unfortunately we have to overwrite this, because on orientation changes the LayoutContainer
|
|
|
|
* will reset and we would lose information about plugboard, reflector-wiring and ring settings.
|
|
|
|
* These info are we saving here.
|
|
|
|
* TODO: Find more elegant solution
|
|
|
|
* @param outState state
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState (Bundle outState)
|
|
|
|
{
|
|
|
|
ArrayList<Integer> plugboard = new ArrayList<>();
|
|
|
|
if(layoutContainer.getState().getConfigurationPlugboard() != null) {
|
|
|
|
for (int i : layoutContainer.getState().getConfigurationPlugboard()) plugboard.add(i);
|
|
|
|
}
|
|
|
|
outState.putIntegerArrayList("plugboard",plugboard);
|
|
|
|
|
|
|
|
ArrayList<Integer> reflector = new ArrayList<>();
|
|
|
|
if(layoutContainer.getState().getConfigurationReflector() != null) {
|
|
|
|
for (int i : layoutContainer.getState().getConfigurationReflector()) reflector.add(i);
|
|
|
|
}
|
|
|
|
outState.putIntegerArrayList("reflector", reflector);
|
|
|
|
|
|
|
|
outState.putInt("ring1", layoutContainer.getState().getRingSettingRotor1());
|
|
|
|
outState.putInt("ring2", layoutContainer.getState().getRingSettingRotor2());
|
|
|
|
outState.putInt("ring3", layoutContainer.getState().getRingSettingRotor3());
|
|
|
|
outState.putInt("ring4", layoutContainer.getState().getRingSettingRotor4());
|
|
|
|
outState.putInt("ringR", layoutContainer.getState().getRingSettingReflector());
|
|
|
|
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Here we get back values previously saved int onSaveInstanceState
|
|
|
|
* @param savedInstanceState state
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onRestoreInstanceState (Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
ArrayList<Integer> plugboard = savedInstanceState.getIntegerArrayList("plugboard");
|
|
|
|
if(plugboard != null && plugboard.size() != 0) {
|
|
|
|
int[] p = new int[plugboard.size()];
|
|
|
|
for (int i = 0; i < plugboard.size(); i++) p[i] = plugboard.get(i);
|
|
|
|
layoutContainer.getState().setConfigurationPlugboard(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayList<Integer> reflector = savedInstanceState.getIntegerArrayList("reflector");
|
|
|
|
if(reflector != null && reflector.size() != 0) {
|
|
|
|
int[] r = new int[reflector.size()];
|
|
|
|
for (int i = 0; i < reflector.size(); i++) r[i] = reflector.get(i);
|
|
|
|
layoutContainer.getState().setConfigurationReflector(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
layoutContainer.getState().setRingSettingRotor1(savedInstanceState.getInt("ring1"));
|
|
|
|
layoutContainer.getState().setRingSettingRotor2(savedInstanceState.getInt("ring2"));
|
|
|
|
layoutContainer.getState().setRingSettingRotor3(savedInstanceState.getInt("ring3"));
|
|
|
|
layoutContainer.getState().setRingSettingRotor4(savedInstanceState.getInt("ring4"));
|
|
|
|
layoutContainer.getState().setRingSettingReflector(savedInstanceState.getInt("ringR"));
|
|
|
|
}
|
|
|
|
|
2015-08-27 01:48:33 +02:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
2015-09-15 02:06:47 +02:00
|
|
|
this.updateContentView();
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateContentView()
|
|
|
|
{
|
|
|
|
switch (prefMachineType)
|
|
|
|
{
|
2015-09-10 02:56:48 +02:00
|
|
|
case "I":
|
|
|
|
this.setContentView(R.layout.activity_main_i_m3);
|
2015-08-27 01:48:33 +02:00
|
|
|
break;
|
|
|
|
case "M3":
|
|
|
|
this.setContentView(R.layout.activity_main_i_m3);
|
|
|
|
break;
|
2015-09-10 02:56:48 +02:00
|
|
|
case "M4":
|
|
|
|
this.setContentView(R.layout.activity_main_m4);
|
|
|
|
break;
|
|
|
|
case "D":
|
|
|
|
this.setContentView(R.layout.activity_main_d);
|
|
|
|
break;
|
2015-09-12 00:04:58 +02:00
|
|
|
case "K":
|
2015-09-16 14:38:46 +02:00
|
|
|
case "KS":
|
|
|
|
case "KSA":
|
2015-09-15 02:06:47 +02:00
|
|
|
case "T":
|
2015-09-16 14:38:46 +02:00
|
|
|
case "R":
|
|
|
|
case "G31":
|
|
|
|
case "G312":
|
|
|
|
case "G260":
|
|
|
|
this.setContentView(R.layout.activity_main_g_k_t);
|
2015-09-12 00:04:58 +02:00
|
|
|
break;
|
2015-08-27 01:48:33 +02:00
|
|
|
default:
|
|
|
|
this.setContentView(R.layout.activity_main_i_m3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updatePreferenceValues()
|
|
|
|
{
|
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
2015-09-22 21:10:41 +02:00
|
|
|
this.setPrefMachineType(sharedPreferences.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources().
|
|
|
|
getStringArray(R.array.pref_alias_machine_type)[0]));
|
|
|
|
this.setPrefAnomaly(sharedPreferences.getBoolean(SettingsActivity.PREF_ANOMALY, true));
|
|
|
|
this.setPrefNumericLanguage(sharedPreferences.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, getResources().
|
2015-08-27 01:48:33 +02:00
|
|
|
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]));
|
2015-09-22 21:10:41 +02:00
|
|
|
this.setPrefMessageFormatting(sharedPreferences.getString(SettingsActivity.PREF_MESSAGE_FORMATTING, getResources().
|
2015-09-10 02:56:48 +02:00
|
|
|
getStringArray(R.array.pref_alias_message_formatting)[0]));
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setPrefMachineType(String type)
|
|
|
|
{
|
|
|
|
if(prefMachineType == null || !prefMachineType.equals(type))
|
|
|
|
{
|
|
|
|
prefMachineType = type;
|
|
|
|
String savedInput = "";
|
|
|
|
if(layoutContainer != null)
|
|
|
|
{
|
2015-09-10 02:56:48 +02:00
|
|
|
savedInput = layoutContainer.getInput().getText();
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
updateContentView();
|
|
|
|
layoutContainer = LayoutContainer.createLayoutContainer(prefMachineType);
|
2015-09-22 21:10:41 +02:00
|
|
|
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
|
2015-09-10 02:56:48 +02:00
|
|
|
layoutContainer.getInput().setText(savedInput);
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPrefMachineType()
|
|
|
|
{
|
|
|
|
if(prefMachineType != null) return prefMachineType;
|
2015-09-10 02:56:48 +02:00
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
2015-09-22 21:10:41 +02:00
|
|
|
this.prefMachineType = sharedPreferences.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources().
|
|
|
|
getStringArray(R.array.pref_alias_machine_type)[0]);
|
2015-09-10 02:56:48 +02:00
|
|
|
return prefMachineType;
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setPrefAnomaly(boolean anomaly)
|
|
|
|
{
|
|
|
|
if(prefAnomaly !=anomaly)
|
|
|
|
{
|
|
|
|
prefAnomaly = anomaly;
|
2015-09-16 14:38:46 +02:00
|
|
|
if(layoutContainer != null && layoutContainer.getEnigma() != null) layoutContainer.getEnigma().setPrefAnomaly(anomaly);
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getPrefAnomaly()
|
|
|
|
{
|
|
|
|
return prefAnomaly;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPrefNumericLanguage(String lang)
|
|
|
|
{
|
|
|
|
if(prefNumericLanguage == null || !prefNumericLanguage.equals(lang))
|
|
|
|
{
|
|
|
|
prefNumericLanguage = lang;
|
2015-09-22 21:10:41 +02:00
|
|
|
layoutContainer.setInputPreparer(InputPreparer.createInputPreparer());
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPrefNumericLanguage()
|
|
|
|
{
|
|
|
|
if(prefNumericLanguage != null) return prefNumericLanguage;
|
2015-09-10 02:56:48 +02:00
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
2015-09-22 21:10:41 +02:00
|
|
|
this.prefNumericLanguage = sharedPreferences.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, getResources().
|
2015-09-10 02:56:48 +02:00
|
|
|
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]);
|
|
|
|
return prefNumericLanguage;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPrefMessageFormatting(String messageFormatting)
|
|
|
|
{
|
|
|
|
if(prefMessageFormatting == null || !prefMessageFormatting.equals(messageFormatting))
|
2015-08-27 01:48:33 +02:00
|
|
|
{
|
2015-09-10 02:56:48 +02:00
|
|
|
prefMessageFormatting = messageFormatting;
|
|
|
|
layoutContainer.setEditTextAdapter(messageFormatting);
|
2015-08-27 01:48:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-10 02:56:48 +02:00
|
|
|
public String getPrefMessageFormatting()
|
|
|
|
{
|
|
|
|
if(prefMessageFormatting != null) return prefMessageFormatting;
|
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
2015-09-22 21:10:41 +02:00
|
|
|
this.prefMessageFormatting = sharedPreferences.getString(SettingsActivity.PREF_MESSAGE_FORMATTING, getResources().
|
2015-09-10 02:56:48 +02:00
|
|
|
getStringArray(R.array.pref_alias_message_formatting)[0]);
|
|
|
|
return prefMessageFormatting;
|
|
|
|
}
|
|
|
|
|
2015-02-04 20:51:31 +01:00
|
|
|
@Override
|
2015-02-18 21:51:40 +01:00
|
|
|
public boolean onCreateOptionsMenu(Menu menu)
|
|
|
|
{
|
2015-02-11 20:56:43 +01:00
|
|
|
this.getMenuInflater().inflate(R.menu.main, menu);
|
2015-02-04 20:51:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-02-18 21:51:40 +01:00
|
|
|
/**
|
|
|
|
* Handle Options menu clicks
|
|
|
|
*/
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item)
|
|
|
|
{
|
2015-02-04 20:51:31 +01:00
|
|
|
int id = item.getItemId();
|
2015-03-14 00:29:43 +01:00
|
|
|
if (id == R.id.action_reset)
|
2015-02-04 20:51:31 +01:00
|
|
|
{
|
2015-09-10 02:56:48 +02:00
|
|
|
layoutContainer.resetLayout();
|
2015-02-18 21:51:40 +01:00
|
|
|
Toast.makeText(getApplicationContext(), R.string.message_reset,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-26 16:04:02 +02:00
|
|
|
else if (id == R.id.action_random_configuration)
|
|
|
|
{
|
|
|
|
layoutContainer.getEnigma().randomState();
|
|
|
|
layoutContainer.setLayoutState(layoutContainer.getEnigma().getState());
|
|
|
|
Toast.makeText(getApplicationContext(), R.string.message_random,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-18 21:51:40 +01:00
|
|
|
else if (id == R.id.action_choose_ringstellung)
|
|
|
|
{
|
2015-08-27 01:48:33 +02:00
|
|
|
layoutContainer.showRingSettingsDialog();
|
2015-02-18 21:51:40 +01:00
|
|
|
return true;
|
2015-02-04 20:51:31 +01:00
|
|
|
}
|
2015-02-24 22:04:02 +01:00
|
|
|
else if (id == R.id.action_settings)
|
|
|
|
{
|
|
|
|
Intent i = new Intent(this, SettingsActivity.class);
|
2015-02-24 23:36:24 +01:00
|
|
|
startActivityForResult(i, RESULT_SETTINGS);
|
2015-02-24 22:04:02 +01:00
|
|
|
}
|
2015-03-14 00:29:43 +01:00
|
|
|
else if (id == R.id.action_about)
|
|
|
|
{
|
|
|
|
showAboutDialog();
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-15 03:53:02 +02:00
|
|
|
else if (id == R.id.action_send)
|
|
|
|
{
|
2015-09-10 02:56:48 +02:00
|
|
|
if(layoutContainer.getOutput().getText().length() == 0)
|
2015-08-15 03:53:02 +02:00
|
|
|
{
|
2015-08-16 02:59:56 +02:00
|
|
|
Toast.makeText(this, R.string.error_no_text_to_send, Toast.LENGTH_SHORT).show();
|
2015-08-15 03:53:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Intent sendIntent = new Intent();
|
|
|
|
sendIntent.setAction(Intent.ACTION_SEND);
|
2015-09-10 02:56:48 +02:00
|
|
|
sendIntent.putExtra(Intent.EXTRA_TEXT, layoutContainer.getOutput().getModifiedText());
|
2015-08-15 03:53:02 +02:00
|
|
|
sendIntent.setType("text/plain");
|
|
|
|
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
|
|
|
|
}
|
|
|
|
}
|
2015-02-04 20:51:31 +01:00
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
2015-02-18 21:51:40 +01:00
|
|
|
/**
|
2015-08-15 03:53:02 +02:00
|
|
|
* Set the chosen Configuration to the enigma, get the input string from the input textbox and
|
|
|
|
* prepare it, set the input to the prepared text, encrypt the prepared input and set the
|
|
|
|
* encrypted string to the output textbox and update the spinners to their new positions.
|
2015-02-18 21:51:40 +01:00
|
|
|
* @param v View
|
|
|
|
*/
|
|
|
|
public void doCrypto(View v)
|
2015-02-04 20:51:31 +01:00
|
|
|
{
|
2015-09-10 02:56:48 +02:00
|
|
|
layoutContainer.doCrypto();
|
2015-02-04 20:51:31 +01:00
|
|
|
}
|
|
|
|
|
2015-02-18 21:51:40 +01:00
|
|
|
/**
|
2015-08-27 01:48:33 +02:00
|
|
|
* Show a Dialog containing information about the app, license, usage, author and a link
|
|
|
|
* to the changelog
|
2015-02-18 21:51:40 +01:00
|
|
|
*/
|
2015-03-14 00:29:43 +01:00
|
|
|
public void showAboutDialog()
|
|
|
|
{
|
|
|
|
final View aboutView = View.inflate(this, R.layout.dialog_about, null);
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(R.string.title_about_dialog);
|
|
|
|
builder.setView(aboutView)
|
|
|
|
.setCancelable(true)
|
|
|
|
.setPositiveButton(R.string.dialog_positiv, 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();
|
|
|
|
openWebPage(URI_CHANGELOG);
|
|
|
|
}
|
|
|
|
}).show();
|
|
|
|
}
|
|
|
|
|
2015-08-27 01:48:33 +02:00
|
|
|
/**
|
|
|
|
* Handle preference changes
|
|
|
|
* @param requestCode requestCode
|
|
|
|
* @param resultCode resultCode (RESULT_SETTINGS is defined at the top)
|
|
|
|
* @param data data (not important here)
|
|
|
|
*/
|
2015-02-24 23:36:24 +01:00
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
|
|
|
switch (requestCode) {
|
|
|
|
case RESULT_SETTINGS:
|
|
|
|
{
|
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
2015-09-22 21:10:41 +02:00
|
|
|
this.setPrefMachineType(sharedPrefs.getString(SettingsActivity.PREF_MACHINE_TYPE, getResources()
|
|
|
|
.getStringArray(R.array.pref_alias_machine_type)[0]));
|
|
|
|
this.setPrefAnomaly(sharedPrefs.getBoolean(SettingsActivity.PREF_ANOMALY, true));
|
|
|
|
this.setPrefNumericLanguage(sharedPrefs.getString(SettingsActivity.PREF_NUMERIC_LANGUAGE, getResources().
|
2015-08-27 01:48:33 +02:00
|
|
|
getStringArray(R.array.pref_alias_numeric_spelling_language)[0]));
|
2015-09-22 21:10:41 +02:00
|
|
|
this.setPrefMessageFormatting(sharedPrefs.getString(SettingsActivity.PREF_MESSAGE_FORMATTING,
|
2015-09-10 02:56:48 +02:00
|
|
|
getResources().getStringArray(R.array.pref_alias_message_formatting)[0]));
|
2015-02-24 23:36:24 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-08-16 02:59:56 +02:00
|
|
|
|
2015-02-24 23:36:24 +01:00
|
|
|
}
|
|
|
|
}
|
2015-03-14 00:29:43 +01:00
|
|
|
|
2015-08-27 01:48:33 +02:00
|
|
|
/**
|
|
|
|
* Open the web page with the URL url
|
|
|
|
* @param url URL of the website
|
|
|
|
*/
|
2015-03-14 00:29:43 +01:00
|
|
|
public void openWebPage(String url) {
|
2015-08-27 01:48:33 +02:00
|
|
|
Uri webPage = Uri.parse(url);
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, webPage);
|
2015-03-14 00:29:43 +01:00
|
|
|
if (intent.resolveActivity(getPackageManager()) != null) {
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
2015-08-15 03:53:02 +02:00
|
|
|
|
2015-08-27 01:48:33 +02:00
|
|
|
/**
|
|
|
|
* Singleton that grants access to an Activity from anywhere within the app
|
|
|
|
*/
|
|
|
|
public static class ActivitySingleton
|
|
|
|
{
|
|
|
|
private static ActivitySingleton instance = null;
|
|
|
|
private Activity activity;
|
2015-08-15 03:53:02 +02:00
|
|
|
|
2015-08-27 01:48:33 +02:00
|
|
|
//private constructor
|
|
|
|
private ActivitySingleton(){}
|
|
|
|
//Singleton method
|
|
|
|
public static ActivitySingleton getInstance()
|
|
|
|
{
|
|
|
|
if(instance == null) instance = new ActivitySingleton();
|
|
|
|
return instance;
|
|
|
|
}
|
2015-08-15 03:53:02 +02:00
|
|
|
|
2015-08-27 01:48:33 +02:00
|
|
|
/**
|
|
|
|
* Set an Activity that the Singleton returns
|
|
|
|
* @param activity activity that's stored
|
|
|
|
*/
|
|
|
|
public void setActivity(Activity activity)
|
|
|
|
{
|
|
|
|
this.activity = activity;
|
|
|
|
}
|
2015-08-15 03:53:02 +02:00
|
|
|
|
2015-08-27 01:48:33 +02:00
|
|
|
/**
|
|
|
|
* Returns the stored Activity
|
|
|
|
* @return stored Activity
|
|
|
|
*/
|
|
|
|
public Activity getActivity()
|
|
|
|
{
|
|
|
|
return activity;
|
2015-08-15 03:53:02 +02:00
|
|
|
}
|
2015-08-27 01:48:33 +02:00
|
|
|
|
|
|
|
}
|
2015-02-04 20:51:31 +01:00
|
|
|
}
|