From 5aa538bbe87f61efead264c64dfad7efb0a98b7d Mon Sep 17 00:00:00 2001 From: misaochan Date: Thu, 28 Jul 2016 16:25:40 +1200 Subject: [PATCH] Add dialog --- .../category/CategorizationFragment.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java b/app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java index 1297426e4..063a68e9a 100644 --- a/app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java @@ -3,6 +3,7 @@ package fr.free.nrw.commons.category; import android.app.Activity; import android.content.ContentProviderClient; import android.content.Context; +import android.content.DialogInterface; import android.database.Cursor; import android.os.AsyncTask; import android.os.Bundle; @@ -10,6 +11,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.RemoteException; import android.support.v4.app.Fragment; +import android.support.v7.app.AlertDialog; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; @@ -463,14 +465,37 @@ public class CategorizationFragment extends Fragment { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { // handle back button's click listener Toast.makeText(getActivity(), "Back press", Toast.LENGTH_SHORT).show(); + backButtonDialog(); return true; + } else { + return false; } - return false; } }); } } + private void backButtonDialog() { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + + builder.setMessage("Are you sure you want to leave? The image will not have any categories saved.") + .setTitle("Warning"); + + builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // User clicked OK button + } + }); + builder.setNegativeButton("No", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // User cancelled the dialog + } + }); + + AlertDialog dialog = builder.create(); + dialog.show(); + } + @Override public void onDestroy() { super.onDestroy();