diff --git a/app/.gitignore b/app/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 6900d5e..0000000 --- a/app/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 21 - buildToolsVersion "21.1.2" - - defaultConfig { - applicationId "com.orhanobut.hawksample" - minSdkVersion 10 - targetSdkVersion 21 - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - - lintOptions { - abortOnError false - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:21.0.3' - - compile project(":hawk") - compile 'net.danlew:android.joda:2.8.1' -} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro deleted file mode 100644 index 90281a6..0000000 --- a/app/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/oobut/dev/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/app/src/androidTest/java/com/orhanobut/hawksample/ApplicationTest.java b/app/src/androidTest/java/com/orhanobut/hawksample/ApplicationTest.java deleted file mode 100644 index c7a1f41..0000000 --- a/app/src/androidTest/java/com/orhanobut/hawksample/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.orhanobut.hawksample; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml deleted file mode 100644 index ffaf73c..0000000 --- a/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - diff --git a/app/src/main/java/com/orhanobut/hawksample/Foo.java b/app/src/main/java/com/orhanobut/hawksample/Foo.java deleted file mode 100644 index 1be61f5..0000000 --- a/app/src/main/java/com/orhanobut/hawksample/Foo.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.orhanobut.hawksample; - -/** - * @author Orhan Obut - */ -public class Foo { - int a = 1; - int b = 3; - String c = "asdfasdf"; - - void test() { - - } - - @Override - public String toString() { - return "Foo{" + - "a=" + a + - ", b=" + b + - ", c='" + c + '\'' + - '}'; - } -} diff --git a/app/src/main/java/com/orhanobut/hawksample/MainActivity.java b/app/src/main/java/com/orhanobut/hawksample/MainActivity.java deleted file mode 100644 index 065921a..0000000 --- a/app/src/main/java/com/orhanobut/hawksample/MainActivity.java +++ /dev/null @@ -1,516 +0,0 @@ -package com.orhanobut.hawksample; - -import android.app.Activity; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.util.Log; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.orhanobut.hawk.Hawk; -import com.orhanobut.hawk.HawkBuilder; -import com.orhanobut.hawk.LogLevel; - -import org.joda.time.DateTime; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import rx.Subscriber; -import rx.android.schedulers.AndroidSchedulers; -import rx.schedulers.Schedulers; - - -public class MainActivity extends Activity { - - private static final String TAG = MainActivity.class.getSimpleName(); - - private SharedPreferences.Editor editor; - private SharedPreferences prefs; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - // long start = System.nanoTime(); - // Hawk.initWithoutEncryption(this, LogLevel.FULL); - // long end = System.nanoTime(); - // - // double resultHawk = getTime(start, end); - // log("Hawk init with password : " + resultHawk); - // - // start = System.nanoTime(); - // prefs = getSharedPreferences("BENCHARMK", MODE_PRIVATE); - // editor = prefs.edit(); - // end = System.nanoTime(); - // double resultPref = getTime(start, end); - // log("init: Prefs: " + resultPref + " Hawk : " + resultHawk); - // - // - // benchmarkPrimitivePut(); - // benchmarkStringPut(); - // benchmarkListObjectPut(); - // benchmarkListStringPut(); - // benchmarkObjectPut(); - // benchmarkMapPut(); - // benchmarkSetPut(); - // - // benchmarkPrimitiveGet(); - // benchmarkStringGet(); - // benchmarkListObjectGet(); - // benchmarkListStringGet(); - // benchmarkObjectGet(); - // benchmarkMapGet(); - // benchmarkSetGet(); - // - // benchmarkDelete(); - - Hawk.init(this) - .setEncryptionMethod(HawkBuilder.EncryptionMethod.HIGHEST) - .setPassword("password") - .setStorage(HawkBuilder.newSharedPrefStorage(this)) - .setLogLevel(LogLevel.FULL) - .setCallback(new HawkBuilder.Callback() { - @Override - public void onSuccess() { - testRx(); - - Hawk.put("joda", new DateTime()); - DateTime dateTime = Hawk.get("joda"); - } - - @Override - public void onFail(Exception e) { - - } - }) - .build(); - } - - private void testRx() { - Hawk.putObservable(KEY, new Foo()) - .observeOn(Schedulers.io()) - .subscribeOn(AndroidSchedulers.mainThread()) - .subscribe(new Subscriber() { - @Override - public void onCompleted() { - } - - @Override - public void onError(Throwable e) { - } - - @Override - public void onNext(Boolean s) { - } - }); - - Hawk.getObservable(KEY) - .observeOn(Schedulers.io()) - .subscribeOn(AndroidSchedulers.mainThread()) - .subscribe(new Subscriber() { - @Override - public void onCompleted() { - Log.d("rxtest", "completed"); - } - - @Override - public void onError(Throwable e) { - Log.d("rxtest", "error"); - } - - @Override - public void onNext(Foo s) { - Log.d("rxtest", s.toString()); - } - }); - - } - - private void testHawkInitWithoutPassword() { - Hawk.init(this); - Hawk.put("test123", "test"); - Hawk.init(this); - Hawk.get("test123"); - } - - private static final String KEY = "KEY"; - - private void benchmarkPrimitivePut() { - int value = 13423; - - editor.clear().commit(); - long start = System.nanoTime(); - editor.putInt(KEY, value).commit(); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - start = System.nanoTime(); - Hawk.put(KEY, value); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("int put : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkStringPut() { - String value = "something"; - - editor.clear().commit(); - long start = System.nanoTime(); - editor.putString(KEY, value).commit(); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - start = System.nanoTime(); - Hawk.put(KEY, value); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("String put : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkObjectPut() { - Foo foo = new Foo(); - - Gson gson = new Gson(); - editor.clear().commit(); - long start = System.nanoTime(); - String value = gson.toJson(foo); - editor.putString(KEY, value).commit(); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - start = System.nanoTime(); - Hawk.put(KEY, foo); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("T put : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkListStringPut() { - List list = new ArrayList<>(); - for (int i = 0; i < 100; i++) { - list.add("asdfasdfdsf"); - } - - Gson gson = new Gson(); - editor.clear().commit(); - long start = System.nanoTime(); - String value = gson.toJson(list); - editor.putString(KEY, value).commit(); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - start = System.nanoTime(); - Hawk.put(KEY, list); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("List put : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkMapPut() { - Map map = new HashMap<>(); - for (int i = 0; i < 100; i++) { - map.put("key", "value"); - } - - Gson gson = new Gson(); - editor.clear().commit(); - long start = System.nanoTime(); - String value = gson.toJson(map); - editor.putString(KEY, value).commit(); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - start = System.nanoTime(); - Hawk.put(KEY, map); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("Map put : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkSetPut() { - Set set = new HashSet<>(); - for (int i = 0; i < 100; i++) { - set.add("key"); - } - - Gson gson = new Gson(); - editor.clear().commit(); - long start = System.nanoTime(); - String value = gson.toJson(set); - editor.putString(KEY, value).commit(); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - start = System.nanoTime(); - Hawk.put(KEY, set); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("Set put : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkListObjectPut() { - List list = new ArrayList<>(); - for (int i = 0; i < 100; i++) { - list.add(new Foo()); - } - - Gson gson = new Gson(); - editor.clear().commit(); - long start = System.nanoTime(); - String value = gson.toJson(list); - editor.putString(KEY, value).commit(); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - start = System.nanoTime(); - Hawk.put(KEY, list); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("List put : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkPrimitiveGet() { - int value = 13423; - - editor.clear().commit(); - editor.putInt(KEY, value).commit(); - - long start = System.nanoTime(); - prefs.getInt(KEY, 0); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - Hawk.put(KEY, value); - start = System.nanoTime(); - Hawk.get(KEY); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("int get : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkStringGet() { - String value = "something"; - - editor.clear().commit(); - editor.putString(KEY, value).commit(); - - long start = System.nanoTime(); - prefs.getString(KEY, null); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - Hawk.put(KEY, value); - start = System.nanoTime(); - Hawk.get(KEY); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("String get : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkListStringGet() { - List list = new ArrayList<>(); - for (int i = 0; i < 100; i++) { - list.add("asdfasdfdsf"); - } - - Gson gson = new Gson(); - editor.clear().commit(); - String value = gson.toJson(list); - editor.putString(KEY, value).commit(); - long start = System.nanoTime(); - String json = prefs.getString(KEY, null); - Type type = new TypeToken>() { - }.getType(); - gson.fromJson(json, type); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - Hawk.put(KEY, list); - start = System.nanoTime(); - Hawk.get(KEY); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("List get : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkMapGet() { - Map map = new HashMap<>(); - for (int i = 0; i < 100; i++) { - map.put("key", "value"); - } - - Gson gson = new Gson(); - editor.clear().commit(); - String value = gson.toJson(map); - editor.putString(KEY, value).commit(); - long start = System.nanoTime(); - String json = prefs.getString(KEY, null); - Type type = new TypeToken>() { - }.getType(); - gson.fromJson(json, type); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - Hawk.put(KEY, map); - start = System.nanoTime(); - Hawk.get(KEY); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("Map get : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkSetGet() { - Set map = new HashSet<>(); - for (int i = 0; i < 100; i++) { - map.add("key"); - } - - Gson gson = new Gson(); - editor.clear().commit(); - String value = gson.toJson(map); - editor.putString(KEY, value).commit(); - long start = System.nanoTime(); - String json = prefs.getString(KEY, null); - Type type = new TypeToken>() { - }.getType(); - gson.fromJson(json, type); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - Hawk.put(KEY, map); - start = System.nanoTime(); - Hawk.get(KEY); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("Set get : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkListObjectGet() { - List list = new ArrayList<>(); - for (int i = 0; i < 100; i++) { - list.add(new Foo()); - } - - Gson gson = new Gson(); - editor.clear().commit(); - String value = gson.toJson(list); - editor.putString(KEY, value).commit(); - long start = System.nanoTime(); - String json = prefs.getString(KEY, null); - Type type = new TypeToken>() { - }.getType(); - gson.fromJson(json, type); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - Hawk.put(KEY, list); - start = System.nanoTime(); - Hawk.get(KEY); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("List get : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - - private void benchmarkObjectGet() { - Foo foo = new Foo(); - - Gson gson = new Gson(); - editor.clear().commit(); - String value = gson.toJson(foo); - editor.putString(KEY, value).commit(); - long start = System.nanoTime(); - String json = prefs.getString(KEY, null); - gson.fromJson(json, Foo.class); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - Hawk.put(KEY, foo); - start = System.nanoTime(); - Hawk.get(KEY); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("Object get : Pref : " + resultPref + " -- Hawk : " + resultHawk); - - } - - private void benchmarkDelete() { - int value = 13423; - - editor.clear().commit(); - editor.putInt(KEY, value).commit(); - - long start = System.nanoTime(); - editor.remove(KEY); - long end = System.nanoTime(); - double resultPref = getTime(start, end); - - Hawk.clear(); - Hawk.put(KEY, value); - start = System.nanoTime(); - Hawk.remove(KEY); - end = System.nanoTime(); - double resultHawk = getTime(start, end); - - log("int remove : Pref : " + resultPref + " -- Hawk : " + resultHawk); - } - - - private double getTime(long start, long end) { - return (end - start) / 1e6d; - } - - private void log(String message) { - Log.d(TAG + " ---- BENCHMARK : ", message); - } - - -} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 53ce557..0000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml deleted file mode 100644 index a459e0a..0000000 --- a/app/src/main/res/menu/menu_main.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100644 index cde69bc..0000000 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100644 index c133a0c..0000000 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100644 index bfa42f0..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100644 index 324e72c..0000000 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml deleted file mode 100644 index 63fc816..0000000 --- a/app/src/main/res/values-w820dp/dimens.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - 64dp - diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml deleted file mode 100644 index 47c8224..0000000 --- a/app/src/main/res/values/dimens.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - 16dp - 16dp - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml deleted file mode 100644 index 5cf38e0..0000000 --- a/app/src/main/res/values/strings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - HawkSample - - Hello world! - Settings - diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml deleted file mode 100644 index 766ab99..0000000 --- a/app/src/main/res/values/styles.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/hawk/src/main/java/com/orhanobut/hawk/GsonParser.java b/hawk/src/main/java/com/orhanobut/hawk/GsonParser.java index 0ced1eb..8d14e7a 100644 --- a/hawk/src/main/java/com/orhanobut/hawk/GsonParser.java +++ b/hawk/src/main/java/com/orhanobut/hawk/GsonParser.java @@ -7,7 +7,7 @@ import java.lang.reflect.Type; -final class GsonParser implements Parser { +public final class GsonParser implements Parser { private final Gson gson; diff --git a/hawk/src/main/java/com/orhanobut/hawk/Parser.java b/hawk/src/main/java/com/orhanobut/hawk/Parser.java index 5b6e16e..99cdc02 100644 --- a/hawk/src/main/java/com/orhanobut/hawk/Parser.java +++ b/hawk/src/main/java/com/orhanobut/hawk/Parser.java @@ -2,7 +2,7 @@ import java.lang.reflect.Type; -interface Parser { +public interface Parser { T fromJson(String content, Type type) throws Exception; diff --git a/settings.gradle b/settings.gradle index 6f95567..12666e2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':hawk' +include ':hawk'