Treasure


Source link: https://github.com/baoyongzhang/Treasure

Treasure

English document

Treasure???Android????? SharePreferences?????????????????????????? Serializable? Parcelable????0????????????????????????

????

1?????

Gradle

compile 'com.baoyz.treasure:treasure:0.7.4' annotationProcessor 'com.baoyz.treasure:treasure-compiler:0.7.4'

Gradle Plugin

???? Module ????? Treasure???? Multiple dex files define Lcom/baoyz/treasure/PreferencesFinder ????? Treasure Gradle Plugin ?????????

? buildscript ?????

dependencies {

  classpath 'com.baoyz.treasure:treasure-gradle:0.7.4' 
}

?????? Application Module ? apply ???Library Module ????

apply plugin: 'com.baoyz.treasure'

????? Module ???? Treasure ??????????????

2?????
@Preferences public interface SimplePreferences {

String getUsername();

void setUsername(String username);
  
}
 

??????? interface????? @Preferences????????????????? get? set????????????????????? key??? getUsername()? setUsername()? key?? username?????? setUsername()??? value???? getUsername()????????? key?????

3????
SimplePreferences preferences = Treasure.get(context, SimplePreferences.class);
 preferences.setUsername("Hello Treasure!");
 preferences.getUsername();
 // return "Hello Treasure!"

?? Treasure.get()????????? Preferences????????? set??????????? get??????

????

???

????? Preferences?????????????????????? Preferences?

Treasure.get(context, SimplePreferences.class, "id_one");
 Treasure.get(context, SimplePreferences.class, "id_two");

Treasure???????? get????????? String???ID???ID??? Preferences???????????????????? zzz40500??????

???

@Default?????? get???????

@Default("Hello Treasure!") String getUsername();
  @Default("false") boolean isLogin();
  // default is 1 hour @Default("1000 * 60 * 60") long getTimeout();
  @Default({
"hello", "world", "!"
}
) Set<String> getStringSet();

?????? @Default?????????

????? ???
int 0
float 0f
long 0l
boolean false
String null
Set<String> null

????

??????????? edit().apply()?????? edit().commit()??????

1???
@Preferences(edit = Preferences.Edit.COMMIT) public interface SimplePreferences

?????????????? set????? commit()???????

2???????
@Commit void setUsername(String username);

?? @Commit???????????

3??????? boolean
boolean setUsername(String username);

???????????????? set??????? boolean?????????? commit()????????? commit()????

????

@Remove void removeUsername();
  @Remove void deleteTimeout();

?? @Remove??????????????? key????

????

@Clear void clear();

??????????? @Clear??????????????????? Preferences????

???

???? @Expired???????????????????? set???? @Expired????? getter? setter?? ??????

// 10????? @Expired(value = 10, unit = Expired.UNIT_SECONDS) String getTestExpired();

@Expired?????????????????????????? setter?????????

// second?????????????UNIT_MINUTES???? void setTestExpired(String value, @Expired(unit = Expired.UNIT_MINUTES) int second);

@Expired? unit?????? UNIT_MILLISECONDS???

?????

?? interface?????????? SharePreferences???????????? Treasure???? Serializable? Parcelable????

// Serializable or Parcelable class User implements Serializable {
...
}
  // Preferences Interface void setUser(User user);
 User getUser();

????????????? Gson???? JSON??????

public class GsonConverterFactory implements Converter.Factory {

@Override
  public <F> Converter<F, String> fromType(Type fromType) {

return new Converter<F, String>() {

 @Override

 public String convert(F value) {

  return new Gson().toJson(value);

 
}

}
;
  
}

@Override
  public <T> Converter<String, T> toType(final Type toType) {

return new Converter<String, T>() {

 @Override

 public T convert(String value) {

  return new Gson().fromJson(value, toType);

 
}

}
;
  
}
 
}

?????????? Treasure.setConverterFactory()?????????????

Treasure.setConverterFactory(new GsonConverterFactory());

?? SharedPreferences ??

@Prototype SharedPreferences getSharedPreferences();

?? @Prototype ??????? SharedPreferences ??????????????? SharedPreferences ???

??? Key

@Key("custom_key") String getValue();
 @Key("custom_key") void setValue(String value);

?????

?????? get? set? put? is? remove? delete???????????????????? key??????????????????????? key?

Proguard

Treasure???0???????? Proguard???

??

Favor??????

javapoet

License

The MIT License (MIT)  Copyright (c) 2015 baoyongzhang <[email protected]> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

Resources

This is a Android Button with a progress bar over it. This is useful when you do something that takes a while like networking, etc.

AndroidQuery is an Android SQLite and ContentProvider ORM powered by an annotation preprocessor. It focus on easy of use without sacrificing performances.

Built-in support for:

  • RxJava2 / Android loaders
  • custom migration
  • custom type converters
  • joins
  • default models for Android ContentProviders (like Contacts, BlockedNumbers, ...)

An android lib for enhancing BottomNavigationView.

The library came out as an effort to reduce the boilerplate required for getting runtime permissions for Android devices running OS 6.0 and above.

The developer can now focus on handling the granted and denied state of the permission rather than dealing with the permission flow and dialogues.

A custom reusable circular slider control for Android application.

MP3 audio recording component.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes