Back to project page timeflash.
The source code is released under:
Apache License
If you think the Android project timeflash listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.derlethtully.timeflash; //from w w w .j a v a 2 s. c o m import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.util.TypedValue; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class FlashCardActivity extends Activity { private List<FlashCardEntry> currentVocab = new ArrayList<FlashCardEntry>(); private List<FlashCardEntry> oldVocab = new ArrayList<FlashCardEntry>(); private String vocabList = null; private String answerText = null; private Button nextEntryB; private Button prevEntryB; private Button revealAnswerB; private TextView clueView; private TextView answerView; private TextView indexView; private int flashCardIndex = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_flash_card); View view = this.getWindow().getDecorView(); view.setBackgroundColor(0xFFCCCCCC); //Setup textviews and buttons clueView = (TextView) findViewById(R.id.clue); clueView.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { float fontSize = clueView.getTextSize() + 10; Log.d("Font Size",Float.toString(clueView.getTextSize())); if(fontSize>=150)fontSize=32; clueView.setTextSize(TypedValue.COMPLEX_UNIT_DIP,fontSize); } }); answerView = (TextView) findViewById(R.id.answer); indexView = (TextView) findViewById(R.id.index); //Button to go backwards in vocab list prevEntryB = (Button) findViewById(R.id.prev_entry_b); prevEntryB.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { //Decrement the index, ensure index is within bounds, and then update flashcard flashCardIndex--; if(flashCardIndex == -1) flashCardIndex = currentVocab.size()-1; updateFlashCardEntry(flashCardIndex); } }); //Button to go forwards in vocab list nextEntryB = (Button) findViewById(R.id.next_entry_b); nextEntryB.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { //Increment index, ensure index is within bounds, and then update flashcard flashCardIndex++; if(flashCardIndex==currentVocab.size()) flashCardIndex = 0; updateFlashCardEntry(flashCardIndex); } }); //Button to show the current flashcard's answer revealAnswerB = (Button) findViewById(R.id.reveal_answer_b); revealAnswerB.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { answerView.setText(answerText); } }); //Get location of vocabulary file vocabList = getFilesDir().toString() + "/vocabList.txt"; //Open the file if possible and generate the current flashcard list try { InputStream inputStream = new FileInputStream(vocabList); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); String clue=br.readLine(); String answer=br.readLine(); String time = br.readLine(); while((clue!=null)&&(answer!=null)&&(time!=null)){ FlashCardEntry flashCard = new FlashCardEntry(clue,answer,time); currentVocab.add(flashCard); clue = br.readLine(); answer = br.readLine(); time = br.readLine(); } updateFlashCardEntry(flashCardIndex); br.close(); inputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.flash_card, menu); return true; } //Takes the current index and updates the flashcard information accordingly public void updateFlashCardEntry(int index){ try{ FlashCardEntry flashCard = currentVocab.get(index); clueView.setText(flashCard.getClue()); answerText = flashCard.getAnswer(); answerView.setText(""); indexView.setText(Integer.toString(index+1)+" of " +Integer.toString(currentVocab.size())); }catch(IndexOutOfBoundsException e){ Toast.makeText(this, "No Words in List", Toast.LENGTH_SHORT).show(); finish(); } } }