exit app after import settings
This commit is contained in:
parent
781aa6e657
commit
04ae55ac63
3 changed files with 22 additions and 3 deletions
|
@ -11,6 +11,9 @@ import android.os.Environment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -20,14 +23,17 @@ import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainActivity;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 03.07.2016.
|
* Created by mike on 03.07.2016.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ImportExportPrefs {
|
public class ImportExportPrefs {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(ImportExportPrefs.class);
|
||||||
static File path = new File(Environment.getExternalStorageDirectory().toString());
|
static File path = new File(Environment.getExternalStorageDirectory().toString());
|
||||||
static final File file = new File(path, MainApp.sResources.getString(R.string.app_name) + "Preferences");
|
static final File file = new File(path, MainApp.sResources.getString(R.string.app_name) + "Preferences");
|
||||||
|
|
||||||
|
@ -52,7 +58,7 @@ public class ImportExportPrefs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void exportSharedPreferences(final Context c) {
|
public static void exportSharedPreferences(final MainActivity c) {
|
||||||
|
|
||||||
new AlertDialog.Builder(c)
|
new AlertDialog.Builder(c)
|
||||||
.setMessage(MainApp.sResources.getString(R.string.export_to) + " " + file + " ?")
|
.setMessage(MainApp.sResources.getString(R.string.export_to) + " " + file + " ?")
|
||||||
|
@ -82,7 +88,7 @@ public class ImportExportPrefs {
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void importSharedPreferences(final Context c) {
|
public static void importSharedPreferences(final MainActivity c) {
|
||||||
new AlertDialog.Builder(c)
|
new AlertDialog.Builder(c)
|
||||||
.setMessage(MainApp.sResources.getString(R.string.import_from) + " " + file + " ?")
|
.setMessage(MainApp.sResources.getString(R.string.import_from) + " " + file + " ?")
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||||
|
@ -109,7 +115,18 @@ public class ImportExportPrefs {
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
editor.commit();
|
editor.commit();
|
||||||
ToastUtils.showToastInUiThread(c, MainApp.sResources.getString(R.string.setting_imported));
|
OKDialog.show(c, MainApp.sResources.getString(R.string.setting_imported), MainApp.sResources.getString(R.string.restartingapp), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
log.debug("Exiting");
|
||||||
|
MainApp.instance().stopKeepAliveService();
|
||||||
|
MainApp.bus().post(new EventAppExit());
|
||||||
|
MainApp.closeDbHelper();
|
||||||
|
c.finish();
|
||||||
|
System.runFinalization();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
ToastUtils.showToastInUiThread(c, MainApp.sResources.getString(R.string.filenotfound) + " " + file);
|
ToastUtils.showToastInUiThread(c, MainApp.sResources.getString(R.string.filenotfound) + " " + file);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -532,4 +532,5 @@
|
||||||
<string name="smscommunicator_suspendreplywithcode" formatted="false">K pozastavení smyčky na %d minut odpověz SMS s kódem %s</string>
|
<string name="smscommunicator_suspendreplywithcode" formatted="false">K pozastavení smyčky na %d minut odpověz SMS s kódem %s</string>
|
||||||
<string name="smscommunicator_wrongduration">Chybná doba trvání</string>
|
<string name="smscommunicator_wrongduration">Chybná doba trvání</string>
|
||||||
<string name="ns_logappstartedevent">Logovat spuštění aplikace do NS</string>
|
<string name="ns_logappstartedevent">Logovat spuštění aplikace do NS</string>
|
||||||
|
<string name="restartingapp">Ukončuji aplikaci, aby se nastavení projevilo.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -583,4 +583,5 @@
|
||||||
<string name="treatments_wizard_sb_label">Superbolus</string>
|
<string name="treatments_wizard_sb_label">Superbolus</string>
|
||||||
<string name="ns_logappstartedevent">Log app start to NS</string>
|
<string name="ns_logappstartedevent">Log app start to NS</string>
|
||||||
<string name="key_ns_logappstartedevent" translatable="false">ns_logappstartedevent</string>
|
<string name="key_ns_logappstartedevent" translatable="false">ns_logappstartedevent</string>
|
||||||
|
<string name="restartingapp">Exiting application to apply settings.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue