Skip to content

Commit

Permalink
Merge pull request #56 from orhanobut/oo/hawk-v2
Browse files Browse the repository at this point in the history
Huge refactoring
  • Loading branch information
orhanobut committed Jul 18, 2015
2 parents 4bd7528 + dd6b001 commit af0b7e2
Show file tree
Hide file tree
Showing 26 changed files with 709 additions and 1,520 deletions.
61 changes: 44 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,65 @@ Hawk provides:

###Add dependency
```groovy
compile 'com.orhanobut:hawk:1.16'
compile 'com.orhanobut:hawk:1.17'
```

If you want to have Rx features, make sure to add Rx dependency

#### Initialize the hawk
```java
Hawk.init(context, PASSWORD); // might take 36-400ms depends on device
Hawk.init(this)
.setEncryptionMethod(HawkBuilder.EncryptionMethod.MEDIUM)
.setStorage(HawkBuilder.newSqliteStorage(this))
.setLogLevel(LogLevel.FULL)
.build();
```
if you don't put any password, it will use another approach, it is faster but less secure.

You can use highest secure crypto approach, init might take 36-400ms. You also need to provide password
```java
Hawk.init(context); // might take 36-60ms
Hawk.init(this)
.setEncryptionMethod(HawkBuilder.EncryptionMethod.HIGHEST)
.setStorage(HawkBuilder.newSqliteStorage(this))
.setLogLevel(LogLevel.FULL)
.build();
```
. You may want to use async solution for init. Add a callback to init and it will work asynchronous.

You can use no-crypto mode if you don't want encryption. This mode will be automatically used if the device does not
support AES, PBE algorithm.
```java
Hawk.init(context, PASSWORD, new Hawk.Callback() {
@Override
public void onSuccess() {
}
Hawk.init(context)
.setEncryptionMethod(HawkBuilder.EncryptionMethod.NO_ENCRYPTION)
.build();
```

@Override
public void onFail(Exception e) {
}
}
);
Select the storage, you can either use sharedpreferences or sqlite to store data
```java
.setStorage(HawkBuilder.newSqliteStorage(this))
```
or
```java
.setStorage(HawkBuilder.newSharedPrefStorage(this))
```

You can use no-crypto mode if you don't want encryption. This mode will be automatically used if the device does not
support AES, PBE algorithm.
You may want to use async solution for init. Add a callback to init and it will work asynchronous.
```java
Hawk.initWithoutEncryption(context);
Hawk.init(this)
.setEncryptionMethod(HawkBuilder.EncryptionMethod.HIGHEST)
.setPassword("password")
.setStorage(HawkBuilder.newSqliteStorage(this))
.setLogLevel(LogLevel.FULL)
.setCallback(new HawkBuilder.Callback() {
@Override
public void onSuccess() {

}

@Override
public void onFail(Exception e) {

}
})
.build();
```

#### Save
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ dependencies {
compile 'com.android.support:appcompat-v7:21.0.3'

compile project(":hawk")
compile 'net.danlew:android.joda:2.8.1'
}
25 changes: 24 additions & 1 deletion app/src/main/java/com/orhanobut/hawksample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
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;
Expand Down Expand Up @@ -67,8 +71,27 @@ protected void onCreate(Bundle savedInstanceState) {
//
// benchmarkDelete();

Hawk.init(this);
Hawk.init(this)
.setEncryptionMethod(HawkBuilder.EncryptionMethod.HIGHEST)
.setPassword("password")
.setStorage(HawkBuilder.newSharedPrefStorage(this))
.setLogLevel(LogLevel.FULL)
.setCallback(new HawkBuilder.Callback() {
@Override
public void onSuccess() {

}

@Override
public void onFail(Exception e) {

}
})
.build();
testRx();

Hawk.put("joda", new DateTime());
DateTime dateTime = Hawk.get("joda");
}

private void testRx() {
Expand Down
13 changes: 0 additions & 13 deletions hawk/src/androidTest/java/com/orhanobut/hawk/ApplicationTest.java

This file was deleted.

50 changes: 1 addition & 49 deletions hawk/src/androidTest/java/com/orhanobut/hawk/DataHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,9 @@ protected void tearDown() throws Exception {
context = null;
}

public void testGetDataInfoShouldReturnNull_null() {
try {
DataHelper.getDataInfo(null);
assertTrue(false);
} catch (Exception e) {
assertTrue(true);
}
}

public void testGetDataInfoShouldThrowException_NotContainDelimiter() {
try {
DataHelper.getDataInfo("324234");
assertTrue(false);
} catch (Exception e) {
assertTrue(true);
}
}

public void testGetDataInfoShouldReturnNotNull() {
DataInfo info = DataHelper.getDataInfo("String11@asdfjasdf");
assertNotNull(info);
}

public void testGetDataInfoShouldBeSerializable() {
DataInfo info = DataHelper.getDataInfo("String11@asdfjasdf");
assertTrue(info.isSerializable());
}

public void testGetDataInfoShouldNotBeSerializable() {
DataInfo info = DataHelper.getDataInfo("String10@asdfjasdf");
assertFalse(info.isSerializable());
}

public void testGetDataInfoShouldBeList() {
DataInfo info = DataHelper.getDataInfo("String11@asdfjasdf");
assertTrue(info.isSerializable());
}

public void testGetDataInfoShouldNotBeList() {
DataInfo info = DataHelper.getDataInfo("String00@asdfjasdf");
assertFalse(info.isSerializable());
}

public void testNewVersionCheck() {
DataInfo info = DataHelper.getDataInfo("String#String#00V@asdfjasdf");
DataInfo info = DataHelper.getDataInfo("java.lang.String##00V@asdfjasdf");
assertTrue(info.isNewVersion());
}

public void testOldVersionCheck() {
DataInfo info = DataHelper.getDataInfo("String#String#00@asdfjasdf");
assertTrue(!info.isNewVersion());
}

}

This file was deleted.

39 changes: 0 additions & 39 deletions hawk/src/androidTest/java/com/orhanobut/hawk/FooParcelable.java

This file was deleted.

This file was deleted.

Loading

0 comments on commit af0b7e2

Please sign in to comment.