From 2f8895ff1702dc3e0c13b8d809ca7e3b7b7d9241 Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Thu, 16 Jul 2015 09:57:29 +0200 Subject: [PATCH] PowerEditor: added confirmation for back press --- .../kauron/dungeonmanager/PowerEditor.java | 26 ++++++++++++++++++- app/src/main/res/values-es/strings.xml | 10 ++++++- app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java b/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java index c54a0f0..c5855db 100644 --- a/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java +++ b/app/src/main/java/com/kauron/dungeonmanager/PowerEditor.java @@ -1,9 +1,11 @@ package com.kauron.dungeonmanager; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.SharedPreferences; import android.graphics.drawable.Drawable; -import android.support.v7.app.ActionBarActivity; import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.ArrayAdapter; @@ -24,6 +26,28 @@ public class PowerEditor extends ActionBarActivity { private SharedPreferences p; private Drawable background; + @Override + public void onBackPressed() { + AlertDialog.Builder alert = new AlertDialog.Builder(this); + alert.setTitle(R.string.sure); + alert.setMessage(R.string.progress_lost); + + alert.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + PowerEditor.super.onBackPressed(); + } + }); + + alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + // Canceled. + } + }); + + alert.show(); + + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 6aa8c48..abdef25 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -153,7 +153,7 @@ - Race + Raza Dracónidos Eladrines Elfos @@ -181,4 +181,12 @@ Usar No tienes poderes, añade uno Mostrar ataque/defensa + Ajustes + Hello world! + Display + Sección 1 + Sección 2 + Sección 3 + Tus cambios se perderán + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5f45f8b..6654223 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -200,5 +200,7 @@ Hello world! Settings + Your changes will be lost + Yes