Android Open Source - ABTester A B General Shared Prefs






From Project

Back to project page ABTester.

License

The source code is released under:

MIT License

If you think the Android project ABTester 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 ab.tester.prefs;
/*from w w  w.  ja v a  2 s.c  o  m*/
import java.util.Random;

import android.content.Context;
import android.content.SharedPreferences;

public class ABGeneralSharedPrefs extends ABSharedPrefs {

  public static final String PERCENTILE = "percentile";
  
  public ABGeneralSharedPrefs(Context context) {
    super(context);
  }

  @Override
  protected String getPrefsName() {
    return "ABTester_general";
  }

  public int getPercentile() {
    int random;
    if (prefs.contains(PERCENTILE)) // use old random number
      random = prefs.getInt(PERCENTILE, 0);
    else {
      random = new Random().nextInt(100);
      SharedPreferences.Editor editor = prefs.edit();
      editor.putInt(PERCENTILE, random); // first time, save it
      apply(editor);
    }
    return random;
  }

}




Java Source Code List

ab.tester.ABTest.java
ab.tester.ABTester.java
ab.tester.DefualtLogger.java
ab.tester.LoggerInterface.java
ab.tester.prefs.ABEventsSharedPrefs.java
ab.tester.prefs.ABGeneralSharedPrefs.java
ab.tester.prefs.ABSharedPrefs.java
ab.tester.prefs.ABTestsSharedPrefs.java
com.example.ab_sample.MainActivity.java
com.example.ab_sample.SplashActivity.java