-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFragment.java
More file actions
101 lines (86 loc) · 4.08 KB
/
Copy pathMainFragment.java
File metadata and controls
101 lines (86 loc) · 4.08 KB
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
package edu.neu.madcourse.michellelee.numad18s_michellelee;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.content.Context;
public class MainFragment extends Fragment {
private AlertDialog mDialog;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
// SET UP ABOUT BUTTON
View aboutButton = rootView.findViewById(R.id.about_button);
// determining action when clicked
aboutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// adding custom dialog with image
LayoutInflater inflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogView = inflater.inflate(R.layout.custom_dial, null); // create view for custom dialog
Drawable myShot = getResources().getDrawable(R.drawable.ic_headshot); // make drawable from headshot image
ImageView pic = (ImageView) dialogView.findViewById(R.id.headshot_image); // set imageview ID
pic.setImageDrawable(myShot); // set imageview picture to drawable
builder.setView(dialogView); // set view to custome dialog
builder.setCancelable(false);
builder.setPositiveButton(R.string.ok_label, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// nothing
}
});
mDialog = builder.show();
}
});
// GENERATE ERROR BUTTON
View generateButton = rootView.findViewById(R.id.generate_button); // create button view
generateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) throws RuntimeException {
throw new RuntimeException();
}
});
// DICTIONARY BUTTON
View dictionaryButton = rootView.findViewById(R.id.dictionary_button); // create button view
dictionaryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) throws RuntimeException {
Intent dictionaryIntent = new Intent(getActivity(), TestDictionary.class);
startActivity(dictionaryIntent);
}
});
// NEW GAME BUTTON
View newGameButton = rootView.findViewById(R.id.newgame_button); // create button view
View continueButton = rootView.findViewById(R.id.continue_button);
newGameButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) throws RuntimeException {
Intent newGameIntent = new Intent(getActivity(), GameActivity.class);
startActivity(newGameIntent);
}
});
continueButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), GameActivity.class);
intent.putExtra(GameActivity.KEY_RESTORE, true);
getActivity().startActivity(intent);
}
});
return rootView;
}
@Override
public void onPause() {
super.onPause();
// Get rid of the about dialog if it's still up
if (mDialog != null)
mDialog.dismiss();
}
}