2 * SaveMySugar - Exchange messages using the distance between phone calls
4 * Copyright (C) 2015 Antonio Ospite <ao2@ao2.it>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * adouble with this program. If not, see <http://www.gnu.org/licenses/>.
20 package it.ao2.savemysugar;
22 import android.app.Application;
23 import android.content.SharedPreferences;
24 import android.preference.PreferenceManager;
25 import android.util.Log;
27 import it.ao2.util.morse.MorseDistanceModulator;
28 import it.ao2.util.morse.MorseTranslator;
30 public class SaveMySugarApplication extends Application {
32 private static final String TAG = "SaveMySugar";
33 private MorseDistanceModulator mModulator;
34 private MorseTranslator mTranslator;
37 public void onCreate() {
40 mModulator = new MorseDistanceModulator();
41 updateModulatorParams();
43 mTranslator = new MorseTranslator();
46 public void updateModulatorParams() {
47 String defaultCallSetupTimeMin = Double.toString(mModulator.DEFAULT_PERIOD_MIN);
48 String defaultCallSetupTimeMax = Double.toString(mModulator.DEFAULT_PERIOD_MAX);
49 String defaultRingTimeMin = Double.toString(mModulator.DEFAULT_PULSE_MIN);
50 String defaultRingTimeMax = Double.toString(mModulator.DEFAULT_PULSE_MAX);
52 SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
53 double newCallSetupTimeMin = Double.parseDouble(sharedPrefs.getString("call_setup_time_min", defaultCallSetupTimeMin));
54 double newCallSetupTimeMax = Double.parseDouble(sharedPrefs.getString("call_setup_time_max", defaultCallSetupTimeMax));
55 double newRingTimeMin = Double.parseDouble(sharedPrefs.getString("ring_time_min", defaultRingTimeMin));
56 double newRingTimeMax = Double.parseDouble(sharedPrefs.getString("ring_time_max", defaultRingTimeMax));
58 Log.d(TAG, "Call setup time min: " + newCallSetupTimeMin + "\n");
59 Log.d(TAG, "Call setup time max: " + newCallSetupTimeMax + "\n");
60 Log.d(TAG, "Ring time min: " + newRingTimeMin + "\n");
61 Log.d(TAG, "Ring time max: " + newRingTimeMax + "\n");
63 // Analog modems don't like to dial a new call immediately after they
64 // hung up the previous one; an extra delay of about one ring time
65 // makes them happy: use newRingTimeMax as the interSymbolDistance.
66 double interSymbolDistance = newRingTimeMax;
68 mModulator.setParameters(newCallSetupTimeMin, newCallSetupTimeMax,
69 newRingTimeMin, newRingTimeMax,
73 public MorseDistanceModulator getModulator() {
77 public MorseTranslator getTranslator() {