Skip to main content

GRE5000

After finishing some GRE quizzes that I downloaded a while ago, I wanted to have those with me so that I could review them again. Hence, this app. The app randomly chooses 1 of 50 quizzes. From that quiz, it chooses 1 of 100 questions. The app uses random number generators, Jsoup parser, AsyncTask and javascript.



 Code:

onCreate
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  webViewCanvas = (WebView) findViewById(R.id.webView1);
  webViewCanvas.getSettings().setJavaScriptEnabled(true);
  button = (Button) findViewById(R.id.button1);
  loadingScreen = (ImageView) findViewById(R.id.imageView1);
  AsyncTaskRunner shuffleForNewWord = new AsyncTaskRunner();
  shuffleForNewWord.execute();
 }


AsyncTask

 private class AsyncTaskRunner extends AsyncTask<String, String, String> {

  private String word, answer, options;
  private String result;

  @Override
  protected String doInBackground(String... params) {
   String file = "words_college_gre_words-quiz-" + randomQuiz()+ ".htm";
   InputStream greFiles = null;

   try {
    greFiles = getAssets().open(file);
    Document doc = Jsoup.parse(greFiles, "UTF-8","http://example.com/");
    Element selectedQuizQuestion = (doc.select("tr").get(randomQuestion()));
    String raw = selectedQuizQuestion.toString();
    
    //...............Editing raw to get result.......................//
    //.......Adding html, javascript, and pretty printing............//
    result = //getting result from above described process 
    //sending word to publishProgress to print it as Button label
    //doInBackground should have nothing to do with controlling UI/main thread
    publishProgress(word);
    
   } catch (IOException e) {
    e.printStackTrace();
   }

   finally {
    if (greFiles != null)
     try {
      greFiles.close();
     } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
   }
   return result;
  }

  @Override
  protected void onPostExecute(String result) {
   //changing to transparent image once the result is ready
   loadingScreen.setImageResource(R.drawable.transparent);
   webViewCanvas.loadData(result, "text/html", "UTF-8");
  }

  @Override
  protected void onPreExecute() {
   button.setText("SHUFFLING");
   //making the webview color consistent 
   webViewCanvas.loadData("<html><body bgcolor=\"#8cdfff\"></html></body>","text/html", "UTF-8");
   loadingScreen.setImageResource(R.drawable.nottransparent);
  }

  @Override
  protected void onProgressUpdate(String... text) {
   button.setText(word);
  }

 }

Screenshots:





Popular posts from this blog

SalsaNight

Zorgania

The Zorganian Republic has some very strange customs. Couples only wish to have female children as only females can inherit the family's wealth, so if they have a male child they keep having more children until they have a girl. If they have a girl, they stop having children. What is the ratio of girls to boys in Zorgania?
The ratio of girls to boys in Zorgania is 1:1. This might be a little counter-intuitive at first. Here are some ways of tackling this problem. 1. Monte Carlo Simulation: Although, Monte Carlo simulation does not necessarily show why the result is 1:1, it is appropriate because of the very counter-intuitive nature of the problem. At the very least, it helps us see that the result is indeed 1:1. Therefore, this is a good start.
The following R code estimates the probability of a child being a boy in Zorgania. 
couples <-100000 boycount <-0for (i in1:couples){ # 0: boywhile (sample(c(0,1),1) ==0) { boycount=boycount+1 } } probability <- boycount/(co…

Simple Launcher

A simple minimal launcher application for Android devices that shows battery percentage using lzyzsd's CirclProgress library (ArchProgress used in this case) and BroadcastReciever for battery state, Android's clock widgets, a built-in flash light switch and an app list view that can be toggled. Currently, the toggle simply filters all the app that I am working on at present. Future implementation can allow users to select their favorite apps or populate second toggle based on the most used applications.