-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFlashActivity.java
More file actions
213 lines (167 loc) · 5.61 KB
/
FlashActivity.java
File metadata and controls
213 lines (167 loc) · 5.61 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
201
202
203
204
205
206
207
208
209
210
211
212
213
package com.buildmlearnstore.activities;
import java.io.IOException;
import java.util.ArrayList;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockActivity;
import com.buildmlearnstore.model.Card;
import com.buildmlearnstore.model.FlashModel;
public class FlashActivity extends SherlockActivity implements
AnimationListener {
View answerView, questionView;
Button flipButton;
Button preButton;
Button nextButton;
boolean isFlipped = false;
int iQuestionIndex = 0;
String flashCardanswer;
ImageView questionImage;
TextView flashCardText, flashcardNumber;
TextView questionText;
private Animation animation1;
private Animation animation2;
private View currentView;
private FlashModel mFlashModel;
private ArrayList<Card> mCardList;
private Drawable d;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flashcards);
mFlashModel = FlashModel.getInstance();
mCardList = mFlashModel.getList();
animation1 = AnimationUtils.loadAnimation(this, R.anim.to_middle);
animation1.setAnimationListener(this);
animation2 = AnimationUtils.loadAnimation(this, R.anim.from_middle);
animation2.setAnimationListener(this);
questionView = (View) findViewById(R.id.questionInMain);
answerView = (View) findViewById(R.id.answerInMain);
questionView.setVisibility(View.VISIBLE);
answerView.setVisibility(View.GONE);
iQuestionIndex = 0;
questionImage = (ImageView) findViewById(R.id.questionImage);
flashCardText = (TextView) findViewById(R.id.flashCardText);
questionText = (TextView) findViewById(R.id.questionhint);
flashcardNumber = (TextView) findViewById(R.id.flashCardNumber);
flipButton = (Button) findViewById(R.id.flip_button);
preButton = (Button) findViewById(R.id.pre_button);
nextButton = (Button) findViewById(R.id.next_button);
populateQuestion(iQuestionIndex);
currentView = questionView;
flipButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
currentView.clearAnimation();
currentView.setAnimation(animation1);
currentView.startAnimation(animation1);
}
});
preButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (iQuestionIndex != 0) {
isFlipped = false;
iQuestionIndex--;
questionView.setVisibility(View.VISIBLE);
answerView.setVisibility(View.GONE);
currentView = questionView;
populateQuestion(iQuestionIndex);
}
}
});
nextButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (iQuestionIndex < mCardList.size()-1) {
isFlipped = false;
iQuestionIndex++;
questionView.setVisibility(View.VISIBLE);
answerView.setVisibility(View.GONE);
currentView = questionView;
populateQuestion(iQuestionIndex);
} else {
finish();
/*Intent myIntent = new Intent(FlashActivity.this,
ScoreActivity.class);
startActivity(myIntent);
finish();
*/ }
}
});
}
public void populateQuestion(int index) {
if (index == 0) {
preButton.setEnabled(false);
} else
preButton.setEnabled(true);
int cardNum = index + 1;
flashcardNumber.setText("Card #" + cardNum + " of " + mCardList.size());
if (mCardList.get(index).getImagePath() != null) {
questionImage.setVisibility(View.VISIBLE);
try {
d = Drawable.createFromStream(
getAssets().open(mCardList.get(index).getImagePath()),
null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
questionImage.setImageDrawable(d);
// questionImage.setImageBitmap(mBitmap);
} else {
questionImage.setVisibility(View.GONE);
}
flashCardanswer = mCardList.get(index).getAnswer();
flashCardText.setText(mCardList.get(index).getHint());
questionText.setVisibility(View.GONE);
if (mCardList.get(index).getQuestion() != null) {
questionText.setVisibility(View.VISIBLE);
questionText.setText(mCardList.get(index).getQuestion());
}
}
@Override
public void onAnimationEnd(Animation animation) {
if (animation == animation1) {
TextView answerText = (TextView) findViewById(R.id.answerText);
if (!isFlipped) {
answerView.setVisibility(View.VISIBLE);
questionView.setVisibility(View.GONE);
isFlipped = true;
answerText.setText(flashCardanswer);
currentView = answerView;
} else {
isFlipped = false;
answerText.setText("");
questionView.setVisibility(View.VISIBLE);
answerView.setVisibility(View.GONE);
currentView = questionView;
}
currentView.clearAnimation();
currentView.setAnimation(animation2);
currentView.startAnimation(animation2);
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}