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 .ja v a 2s .c o m*/ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; 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.os.Environment; import android.os.Parcelable; import android.app.Activity; import android.app.AlertDialog; import android.content.Intent; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class TimeFlashActivity extends Activity { private Button addVocabB; private Button addVocabListB; private Button reviewVocabB; private Button editListB; //private Long tolerance = (long) 60480000; //# of milliseconds in a week private String defaultDirectory = "/storage"; private static final int REQUEST_PICK_FILE = 1; private String vocabList = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_time_flash); vocabList = getFilesDir().toString() + "/vocabList.txt"; addVocabB = (Button) findViewById(R.id.add_vocab_b); addVocabB.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { Intent addVocabIntent = new Intent(TimeFlashActivity.this, AddVocabActivity.class); startActivity(addVocabIntent); } }); addVocabListB = (Button) findViewById(R.id.add_vocab_list_b); addVocabListB.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // Create a new Intent for the file picker activity Intent addVocabListIntent = new Intent(getBaseContext(), FilePickerActivity.class); addVocabListIntent.putExtra(FilePickerActivity.EXTRA_FILE_PATH, defaultDirectory); // Start the activity startActivityForResult(addVocabListIntent, REQUEST_PICK_FILE); } }); reviewVocabB = (Button) findViewById(R.id.review_vocab_b); reviewVocabB.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // Launch settings menu for running flashcards (date/time) Intent reviewVocabIntent = new Intent(getBaseContext(),FlashCardActivity.class); startActivity(reviewVocabIntent); } }); editListB = (Button) findViewById(R.id.edit_vocab_list_b); editListB.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { Intent editListIntent = new Intent(getBaseContext(), EditListActivity.class); startActivity(editListIntent); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode == RESULT_OK) { switch(requestCode) { case REQUEST_PICK_FILE: if(data.hasExtra(FilePickerActivity.EXTRA_FILE_PATH)) { File f = new File(data.getStringExtra(FilePickerActivity.EXTRA_FILE_PATH)); String filePath = f.getPath(); String fileName = filePath.substring(filePath.lastIndexOf("/")+1, filePath.length()); Log.d("File Returned", fileName); Log.d("File Path Returned", filePath); parseList(filePath); } } } } @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; } public void parseList(String filePath){ File file = new File(vocabList); try { InputStream inputStream = new FileInputStream(filePath); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); FileWriter fileWriter = new FileWriter(file, true); StringBuilder sb = new StringBuilder(); String clue=br.readLine(); String answer=br.readLine(); while((clue!=null)&&(answer!=null)) { sb.append(clue+"\n"); sb.append(answer+"\n"); sb.append(System.currentTimeMillis()+"\n"); clue = br.readLine(); answer = br.readLine(); } Toast.makeText(this, sb, Toast.LENGTH_LONG).show(); fileWriter.append(sb); fileWriter.flush(); fileWriter.close(); br.close(); inputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }