forked from YifengWong/TastySnake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelpDialog.java
67 lines (61 loc) · 2.24 KB
/
HelpDialog.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
package com.example.stevennl.tastysnake.widget;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import com.example.stevennl.tastysnake.Config;
import com.example.stevennl.tastysnake.R;
/**
* A dialog showing game help information.
*/
public class HelpDialog extends Dialog {
private static final String TAG = "HelpDialog";
private Context context;
private DialogInterface.OnCancelListener cancelListener;
/**
* Initialize a dialog to show help information.
*
* @param context The context
* @param cancelListener_ Called when the dialog is closed
*/
public HelpDialog(Context context, @Nullable DialogInterface.OnCancelListener cancelListener_) {
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.context = context;
this.cancelListener = cancelListener_;
setOnCancelListener(cancelListener);
init();
}
private void init() {
View v = LayoutInflater.from(context).inflate(R.layout.dialog_help, null);
initInfoTxt(v);
Window window = getWindow();
if (window != null) {
window.setContentView(v);
window.setWindowAnimations(R.style.DialogAnim);
WindowManager.LayoutParams lp = window.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
}
}
private void initInfoTxt(View v) {
TextView infoTxt = (TextView) v.findViewById(R.id.dialog_help_infoTxt);
infoTxt.setText(context.getString(R.string.help_info, Config.DURATION_ATTACK));
infoTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
HelpDialog.this.dismiss();
if (cancelListener != null) {
cancelListener.onCancel(HelpDialog.this);
}
}
});
}
}