package foo.bar;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;
import android.content.SharedPreferences; import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
public class SharedPrefsTest extends Activity {
    // OK 1
    public void onCreate1(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("foo", "bar");
        editor.putInt("bar", 42);
        editor.commit();
    }

    // OK 2
    public void onCreate2(Bundle savedInstanceState, boolean apply) {
        super.onCreate(savedInstanceState);
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("foo", "bar");
        editor.putInt("bar", 42);
        if (apply) {
            editor.apply();
        }
    }

    // OK 3
    public boolean test1(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("foo", "bar");
        editor.putInt("bar", 42);
        editor.apply(); return true;
    }

    // Not a bug
    public void test(Foo foo) {
        Bar bar1 = foo.edit();
        Bar bar2 = Foo.edit();
        Bar bar3 = edit();


    }

    // Bug
    public void bug1(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("foo", "bar");
        editor.putInt("bar", 42);
    }

    // Constructor test
    public SharedPrefsTest(Context context) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("foo", "bar");
    }

    private Bar edit() {
        return null;
    }

    private static class Foo {
        static Bar edit() { return null; }
    }

    private static class Bar {

    }
 }

