-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestions.java
More file actions
200 lines (164 loc) · 5.24 KB
/
Copy pathQuestions.java
File metadata and controls
200 lines (164 loc) · 5.24 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package com.testyourself.knowyoursport;
import java.util.ArrayList;
import java.util.Collections;
import com.testyourself.adapter.DBAdapter;
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
import android.media.MediaPlayer;
public class Questions extends Activity {
private static final String TABLE_NAME = "questions";
private static final String ROW_ID = "_id";
private static final String QB_NAME = "canvas";
private static final String QB_FIRST = "first";
private static final String QB_SECOND = "second";
private static final String QB_THIRD = "third";
private static final String QB_FOURTH = "fourth";
private static final String QB_FIFTH = "fifth";
private static final String QB_SIXTH = "sixth";
private static final String QB_SEVENTH = "seventh";
private static final String QB_EIGHTH = "eighth";
private static final String QB_NINTH = "ninth";
private static final String QB_TENTH = "tenth";
private static final String DB_NAME="footballdb";
private static SQLiteDatabase database;
public static TextView textview;
public int q;
private int k;
private String[] first =new String[10];
private String[] second =new String[10];
private String[] extra =new String[2];
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_questions);
mp=MediaPlayer.create(this, R.raw.button);
Bundle bundle = getIntent().getExtras();
DBAdapter dbOpenHelper = new DBAdapter(this, DB_NAME);
database = dbOpenHelper.openDataBase();
textview = (TextView) findViewById(R.id.question);
dbOpenHelper.openDataBase();
q = bundle.getInt("from");
Cursor c = Questions.getQuestion(q);
if (c.moveToFirst()) {
textview.setText(String.valueOf(c.getString(1)));
}
// shuffling the array of the retrieved letters to randomize
for (int h = 2; h < 12; h++) {
if (c.getString(h).toString().equals("!")) {
break;
} else {
k++;
}
}
ArrayList<Integer> numbers = new ArrayList<Integer>();
for (int j = 2; j < k + 2; j++) {
numbers.add(j);
}
Collections.shuffle(numbers);
for (int i = 0; i < k; i++) {
int retval = numbers.get(i);
first[i] = c.getString(retval).toString();
}
for (int i = k; i < 10; i++) {
first[i] = "b";
}
for (int m = 0; m < 8; m++) {
second[m] = c.getString(m + 2).toString();
}
extra[0]=c.getString(k).toString();
extra[1]=c.getString(k+1).toString();
}
public void answer(View v) {
mp.start();
Intent i = new Intent(Questions.this, Answer.class);
Bundle extras = new Bundle();
extras.putString("database", "football");
extras.putInt("category", 1);
extras.putInt("k", k);
extras.putInt("from", q);
extras.putStringArray("first", first);
extras.putStringArray("second", second);
extras.putStringArray("extra", extra);
i.putExtras(extras);
/*Bundle bnaniamtion = ActivityOptions.makeCustomAnimation(
getApplicationContext(), R.anim.rightin, R.anim.rightout)
.toBundle();*/
startActivity(i);
overridePendingTransition(R.anim.rightin, R.anim.rightout);
}
public static Cursor getQuestion(long rowId) throws SQLException {
Cursor mCursor = database.query(true, TABLE_NAME,
new String[] { ROW_ID, QB_NAME, QB_FIRST, QB_SECOND, QB_THIRD,
QB_FOURTH, QB_FIFTH, QB_SIXTH, QB_SEVENTH, QB_EIGHTH,
QB_NINTH, QB_TENTH }, ROW_ID + "=" + rowId, null, null,
null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
/*
protected void onStop()
{
super.onStop();
mp.stop();
}
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
if (mp != null) {
mp.release();
mp = null;
}
}
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
if (mp != null) {
mp.release();
mp= null;
}
}
*/
@Override
protected void onStop()
{
super.onStop();
//Deallocate all memory
if(mp!=null){
if(mp.isPlaying()){
mp.stop();
}
mp.release();
mp=null;
}
}
@Override
public void onBackPressed() {
mp.start();
DBAdapter dbOpenHelper = new DBAdapter(this, DB_NAME);
dbOpenHelper.close();
Intent i = new Intent(Questions.this, Buttons.class);
/*Bundle bnaniamtion = ActivityOptions.makeCustomAnimation(
getApplicationContext(), R.anim.rightin, R.anim.rightout)
.toBundle();*/
startActivity(i);
overridePendingTransition(R.anim.leftin, R.anim.leftout);
}
}