Skip to content

Instantly share code, notes, and snippets.

Avatar
Coffee coffee

Jaewoong Eum skydoves

Coffee coffee
View GitHub Profile
View Profile.java
@PreferenceEntity(name = "UserProfile")
public class Profile {
protected final boolean login = false;
@KeyName(name = "nickname") protected final String userNickName = null;
@KeyName(name = "visits") protected final int visitCount = 1;
@KeyName(name = "userPet")
@TypeConverter(converter = PetConverter.class)
protected Pet userPetInfo;
View PreferenceRoomActivity.java
Preference_UserProfile userProfile = Preference_UserProfile.getInstance(this);
userProfile.putNickname("my nickname"); // puts a SharedPreference in NickName key.
userProfile.getNickname(); // gets a SharedPreference value in NickName key.
userProfile.containsNickname(); // checks nickname key value is exist in SharedPreference.
userProfile.removeNickname(); // removes nickname key's value in SharedPreference.
userProfile.nicknameKeyName(); // returns nickname fields's key name.
userProfile.getEntityName(); // returns UserProfile entity's name;
userProfile.getkeyNameList(); // returns UserProfile entity's KeyName list of fields.
View PetConverter.java
public class PetConverter extends PreferenceTypeConverter<Pet> {
private final Gson gson;
/**
* default constructor will be called by PreferenceRoom
*/
public PetConverter() {
this.gson = new Gson();
}
View Converter_Example.java
@KeyName(name = "userPet")
@TypeConverter(converter = PetConverter.class)
protected Pet userPetInfo;
View PrivateInfoConverter.java
public class PrivateInfoConverter extends PreferenceTypeConverter<PrivateInfo> {
@Override
public String convertObject(PrivateInfo privateInfo) {
return privateInfo.getName() + "," + privateInfo.getAge();
}
@Override
public PrivateInfo convertType(String string) {
if(string == null) return new PrivateInfo("null",0);
View Preference_UserProfile.java
Preference_UserProfile.getInstance(this).putNickname("my nickname");
View PreferenceFunction_Example.java
@PreferenceFunction(keyname = "nickname")
public String putUserNickFunction(String nickname) {
return "Hello, " + nickname;
}
@PreferenceFunction(keyname = "nickname")
public String getUserNickFunction(String nickname) {
return nickname + "!!!";
}
View PreferenceFunction_Example2.java
@PreferenceFunction(keyname = "visits")
public int putVisitCountFunction(int count) {
return ++count;
}
View PreferenceFunction_Example3.java
component.UserProfile().putVisits(component.UserProfile().getVisits());
View PreferenceFunction_Example4.java
@PreferenceFunction(keyname = "uuid")
public String putUuidFunction(String uuid) {
return SecurityUtils.encrypt(uuid);
}
@PreferenceFunction(keyname = "uuid")
public String getUuidFunction(String uuid) {
return SecurityUtils.decrypt(uuid);
}