emotionhero/app/src/main/java/com/rubenvandeven/emotionhero/StoryDialogFragment.java

55 lines
2.0 KiB
Java

package com.rubenvandeven.emotionhero;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatDialogFragment;
/**
* Created by ruben on 07/09/16.
*/
public class StoryDialogFragment extends AppCompatDialogFragment {
GamingActivity activity;
// Override the Fragment.onAttach() method to instantiate the NoticeDialogListener
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// Verify that the host activity implements the callback interface
try {
// Instantiate the NoticeDialogListener so we can send events to the host
this.activity = (GamingActivity) activity;
} catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(activity.toString()
+ " must implement StoryDialogFragmentListener");
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(activity.currentScenario.getDescription()).setTitle(activity.currentScenario.toString())
.setNeutralButton("Start!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
activity.startGame();
}
}).setCancelable(false).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
activity.startGame();
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}