Android Hawk database GitHub open Source project

Source: Internet
Author: User

Android Hawk database GitHub open Source project


Hawk is a very handy database. The operational database requires only one line of code and can store any data type.

GitHub Address: Https://github.com/orhanobut/hawk


Hawk is a simple key-value database.

It uses:

AES encryption

can choose to use sharedpreferences or SQLite

Gson parsing (there is a replacement Fastjson version in simple below the article)

Provide:

Secure data persistence

can store any type


Take a look at the examples that meet the needs of the project and look down

Storage examples:

Hawk.Put "key" , "something" );//Save stringHawk.Put "key" ,true);//Save BooleanHawk.Put "key" ,New Foo());//Save an objectHawk.Put "key" ,list<String>);//Save listHawk.Put "key" ,list<Foo>);//Save listHawk.Put "key" ,map<foo,foo>);//Save mapHawk.Put "key" ,set<Foo>);//Save setHawk.Put "key" ,1234);//Save numbers

Get the example:

StringValue= Hawk.Get (key);intValue= Hawk.Get (key);FooValue= Hawk.Get (key);BooleanValue= Hawk.Get (key);list<String>Value= Hawk.Get (key);list<Foo>Value= Hawk.Get (key);map<String,Foo>Value= Hawk.Get (key);set<Foo>Value= Hawk.Get (key);


(i) Added to the project

Android Studio is configured in Gradle

repositories {  //...  Maven {URL "Https://jitpack.io"}}dependencies {  compile ' com.github.orhanobut:hawk:1.21 '}

Eclipse users please download and import the project

You can refer to the simple below


(ii) initialization of Hawk

Initialization takes only one time to put it in the activity you're starting with, or application.

Hawk.init (This)    . Setencryptionmethod (HawkBuilder.EncryptionMethod.MEDIUM)    . Setstorage ( Hawkbuilder.newsqlitestorage (this))    . Setloglevel (Loglevel.full)    . Build ();

Ability to use high security level initialization may require 36-400ms and require you to provide a password

Hawk.init (This)    . Setencryptionmethod (HawkBuilder.EncryptionMethod.HIGHEST)    . Setstorage ( Hawkbuilder.newsqlitestorage (this))    . Setloglevel (Loglevel.full)    . Build ();


Initialize can choose SQLite or sharepreference

. Setstorage (Hawkbuilder.newsqlitestorage (This))
or
. Setstorage (Hawkbuilder.newsharedprefstorage (This))

(iii) Storage of data

Hawk.put (key, T); Returns the result as Boolean


You can also store multiple items by using the chain feature. Remember to use commit at the end ().
Returns the result as Booleanhawk.chain ()     . Put (Key_list, list<t>).     put (key_another, "test")     . Commit ();


(iv) Data collection

T result = Hawk.get (key);
or

Set the default value when NULL

T result = Hawk.get (key, T);

(v) Removal of data

Hawk.remove (key); Returns the result as Boolean
or

Simultaneously remove multiple

Hawk.remove (Key_list, key_name); Returns the result as Boolean

(vi) Determine if a key is included

Boolean contains = Hawk.contains (key);

(vii) Set password

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 the public      void Onfail ( Exception e) {      }    })    . Build ();



(eight) precautions

Hawk Log Output:

Hawk.init (Context,password, loglevel.full); As default it is NONE

Hawk supports Buildrx's recently very hot Rxjava

If used also please import if do not need Rx function remove the corresponding source code will not affect


Confuse:

#Gson-keep class com.google.gson.** { *; }-keepattributes Signature


(last) Problems encountered

Hawk uses JSON for data storage

I'm using the Gson library provided by Google, but I've got fastjson in my project.

In order to control the size of the package, the Gson resolution is replaced with the eclipse written by Fastjson for your reference


GitHub Address: Https://github.com/orhanobut/hawk

Eclipse Demo: waiting to be mended


  ┏┓┏┓//┏┛┻━━━┛┻┓//┃┃//┃━┃//┃┳┛┗┳┃//┃┃//┃┻┃//┃┃//┗━┓┏━┛//   ┃┃   god of animal protection Woo//   ┃┃   Code no bug!   ┃┗━━━┓//   ┃┣┓//   ┃┏┛//   ┗┓┓┏━┳┓┏┛//     ┃┫┫┃┫┫//     ┗┻┛┗┻┛

Hope to be useful to everyone

Android Hawk database GitHub open Source project

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.