-
Notifications
You must be signed in to change notification settings - Fork 24
/
RateMeMaybeFragment.java
105 lines (84 loc) · 2.55 KB
/
RateMeMaybeFragment.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.kopfgeldjaeger.ratememaybe;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
public class RateMeMaybeFragment extends DialogFragment implements
OnClickListener, OnCancelListener {
private RMMFragInterface mInterface;
private String title;
private String message;
private int customIcon;
private String positiveBtn;
private String neutralBtn;
private String negativeBtn;
public interface RMMFragInterface {
void _handlePositiveChoice();
void _handleNeutralChoice();
void _handleNegativeChoice();
void _handleCancel();
}
public void setData(int customIcon, String title, String message,
String positiveBtn, String neutralBtn, String negativeBtn,
RMMFragInterface myInterface) {
this.customIcon = customIcon;
this.title = title;
this.message = message;
this.positiveBtn = positiveBtn;
this.neutralBtn = neutralBtn;
this.negativeBtn = negativeBtn;
this.mInterface = myInterface;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Fragment including variables will survive orientation changes
this.setRetainInstance(true);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
if (customIcon != 0) {
builder.setIcon(customIcon);
}
builder.setTitle(title);
builder.setMessage(message);
builder.setPositiveButton(positiveBtn, this);
builder.setNeutralButton(neutralBtn, this);
builder.setNegativeButton(negativeBtn, this);
builder.setOnCancelListener(this);
AlertDialog alert = builder.create();
return alert;
}
@Override
public void onCancel(DialogInterface dialog) {
mInterface._handleCancel();
}
@Override
public void onClick(DialogInterface dialog, int choice) {
switch (choice) {
case DialogInterface.BUTTON_POSITIVE:
mInterface._handlePositiveChoice();
break;
case DialogInterface.BUTTON_NEUTRAL:
mInterface._handleNeutralChoice();
break;
case DialogInterface.BUTTON_NEGATIVE:
mInterface._handleNegativeChoice();
break;
}
}
@Override
public void onDestroyView() {
// Work around bug:
// http://code.google.com/p/android/issues/detail?id=17423
Dialog dialog = getDialog();
if ((dialog != null) && getRetainInstance()) {
dialog.setDismissMessage(null);
}
super.onDestroyView();
}
}