Skip to content

@BindPreferenceAdapter

xcesco edited this page May 14, 2018 · 2 revisions

This annotation decorates a field to use a particular Shared-Preference Type Adapter to customize persistence on the Shared Preference mechanism. A type adapter must implement the PreferenceTypeAdapter interface. It has two parameter type: the first is the field type, the second is the type that we want to use as replacement and that will be used to store data into the Shared Preference. It implements two methods:

  • toJava: converts data retrieved from a Shared Preference element.
  • toData: converts a field into data to store into a Shared Preference element.

Attributes

  • adapter: Preference Type Adapter class

Usage

@BindSharedPreferences
public class App1Preferences {

  @BindPreference
  public HashSet<String> valueSet;
	
  @BindPreferenceAdapter(adapter=IntTypeAdapter.class)
  @BindPreference
  public int right;		
}

And the associated SQL type adapter:

public class IntTypeAdapter implements PreferenceTypeAdapter<Integer, String> {

  @Override
  public IntegertoJava(byte[] dataValue) {
   ...
  }

  @Override
  public String toData(Integer javaValue) {
    ...
  }
}

This annotation is very useful when you need to persist a class that Kripton does not support directly for persistence.

Table of Contents

Query definition

Features

Relations

Multithread supports

Modularization

Annotations for data convertion

Annotations for SQLite ORM

Annotations for shared preferences

Clone this wiki locally