Android Open Source - MathApp Score






From Project

Back to project page MathApp.

License

The source code is released under:

MIT License

If you think the Android project MathApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ie.lc.mathApp;
/*from   ww w  .j a v  a 2 s. c o m*/
import java.io.File;
import java.io.IOException;
import android.os.Environment;





public class Score
{
  private static     ScoreData data;
  private static final String     FILE = "/mathApp/score.blob";
  
  
  
  
  
  public static int getSuccesses() {
    return data.successes;
  }





  public static int getAttempts() {
    return data.attempts;
  }
  
  
  
  
  
  public static int getSuccessPercent() {
    if (data.attempts > 0)
       return (int) Geo.roundArith( (data.successes / (double) data.attempts) * 100.0 );
    else return 0;
  }
  
  
  
  
  
  public static void reset() {
    data.attempts  = 0;
    data.successes = 0;
    save();
  }
  
  
  
  
  
  public static void onCorrectAnswer() {
    load();
    data.attempts ++;
    data.successes++;
    save();
  }
  
  
  
  
  
  public static void onWrongAnswer() {
    load();
    data.attempts++;
    save();
  }
  
  
  
  
  
  public static void load() {
    ioCommon( false );
  }
  
  
  
  
  
  public static void save() {
    ioCommon( true );
  }
  
  
  
  
  
  private static void ioCommon( boolean write ) {
    File    dir   = Environment.getExternalStorageDirectory();
    String  state = Environment.getExternalStorageState();
    boolean ready = Environment.MEDIA_MOUNTED.equals( state );
    String  file  = dir.getAbsolutePath() + FILE;
    
    if (ready)
    if (! write) {
      if (Storage.exists( file ))
         data = Storage.read( file, ScoreData.class );
      else data = new ScoreData();
    }
    else {
      new File(file).getParentFile().mkdirs();
      Storage.write( file, data );
    }
  }
}




Java Source Code List

ie.lc.mathApp.ActivityArithmetic.java
ie.lc.mathApp.ActivityCommonMenu.java
ie.lc.mathApp.ActivityGameBase.java
ie.lc.mathApp.ActivityScore.java
ie.lc.mathApp.ActivitySqrt.java
ie.lc.mathApp.ActivityWave.java
ie.lc.mathApp.CallbackThread.java
ie.lc.mathApp.Callback.java
ie.lc.mathApp.Geo.java
ie.lc.mathApp.Operator.java
ie.lc.mathApp.ScoreData.java
ie.lc.mathApp.Score.java
ie.lc.mathApp.SeekBarAdapter.java
ie.lc.mathApp.Storage.java
ie.lc.mathApp.TextWatcherAdapter.java
ie.lc.mathApp.Util.java
ie.lc.mathApp.Wave.java