Created
October 14, 2012 13:55
-
-
Save kappa7194/3888657 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package it.penpen.android.passphrase_generator; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.List; | |
import android.app.Activity; | |
import android.os.AsyncTask; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.widget.TextView; | |
public class MainActivity extends Activity { | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_load); | |
new DictionaryLoader().execute(); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
getMenuInflater().inflate(R.menu.activity_main, menu); | |
return true; | |
} | |
private class DictionaryLoader extends AsyncTask<Void, Void, List<String>> { | |
@Override | |
protected List<String> doInBackground(Void... params) { | |
String word; | |
List<String> dictionary = new ArrayList<String>(); | |
InputStream inputStream = getResources().openRawResource(R.raw.dictionary); | |
InputStreamReader inputReader = new InputStreamReader(inputStream); | |
BufferedReader bufferedReader = new BufferedReader(inputReader); | |
try { | |
while ((word = bufferedReader.readLine()) != null) { | |
dictionary.add(word); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return dictionary; | |
} | |
@Override | |
protected void onPostExecute(List<String> result) { | |
Integer loadedWords = result.size(); | |
((TextView)findViewById(R.id.words_loaded_number)).setText(loadedWords.toString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment