com.activeandroid.serializer.TypeSerializer Java Examples

The following examples show how to use com.activeandroid.serializer.TypeSerializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Configuration.java    From clear-todolist with GNU General Public License v3.0 6 votes vote down vote up
private List<Class<? extends TypeSerializer>> loadSerializerList(String[] serializers) {
	final List<Class<? extends TypeSerializer>> typeSerializers = new ArrayList<Class<? extends TypeSerializer>>();
	final ClassLoader classLoader = mContext.getClass().getClassLoader();
	for (String serializer : serializers) {
		try {
			Class serializerClass = Class.forName(serializer.trim(), false, classLoader);
			if (ReflectionUtils.isTypeSerializer(serializerClass)) {
				typeSerializers.add(serializerClass);
			}
		}
		catch (ClassNotFoundException e) {
			Log.e("Couldn't create class.", e);
		}
	}

	return typeSerializers;
}
 
Example #2
Source File: Configuration.java    From mobile-android-survey-app with MIT License 6 votes vote down vote up
private List<Class<? extends TypeSerializer>> loadSerializerList(String[] serializers) {
	final List<Class<? extends TypeSerializer>> typeSerializers = new ArrayList<Class<? extends TypeSerializer>>();
	final ClassLoader classLoader = mContext.getClass().getClassLoader();
	for (String serializer : serializers) {
		try {
			Class serializerClass = Class.forName(serializer.trim(), false, classLoader);
			if (ReflectionUtils.isTypeSerializer(serializerClass)) {
				typeSerializers.add(serializerClass);
			}
		}
		catch (ClassNotFoundException e) {
			Log.e("Couldn't create class.", e);
		}
	}

	return typeSerializers;
}
 
Example #3
Source File: Configuration.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
public Builder addTypeSerializer(Class<? extends TypeSerializer> typeSerializer) {
	if (mTypeSerializers == null) {
		mTypeSerializers = new ArrayList<Class<? extends TypeSerializer>>();
	}

	mTypeSerializers.add(typeSerializer);
	return this;
}
 
Example #4
Source File: Configuration.java    From clear-todolist with GNU General Public License v3.0 5 votes vote down vote up
public Builder addTypeSerializers(Class<? extends TypeSerializer>... typeSerializers) {
	if (mTypeSerializers == null) {
		mTypeSerializers = new ArrayList<Class<? extends TypeSerializer>>();
	}

	mTypeSerializers.addAll(Arrays.asList(typeSerializers));
	return this;
}
 
Example #5
Source File: Configuration.java    From mobile-android-survey-app with MIT License 5 votes vote down vote up
public Builder addTypeSerializers(Class<? extends TypeSerializer>... typeSerializers) {
	if (mTypeSerializers == null) {
		mTypeSerializers = new ArrayList<Class<? extends TypeSerializer>>();
	}

	mTypeSerializers.addAll(Arrays.asList(typeSerializers));
	return this;
}
 
Example #6
Source File: Configuration.java    From mobile-android-survey-app with MIT License 5 votes vote down vote up
public Builder addTypeSerializer(Class<? extends TypeSerializer> typeSerializer) {
	if (mTypeSerializers == null) {
		mTypeSerializers = new ArrayList<Class<? extends TypeSerializer>>();
	}

	mTypeSerializers.add(typeSerializer);
	return this;
}
 
Example #7
Source File: Cache.java    From mobile-android-survey-app with MIT License 4 votes vote down vote up
public static synchronized TypeSerializer getParserForType(Class<?> type) {
	return sModelInfo.getTypeSerializer(type);
}
 
Example #8
Source File: SQLiteUtils.java    From mobile-android-survey-app with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static String createColumnDefinition(TableInfo tableInfo, Field field) {
	StringBuilder definition = new StringBuilder();

	Class<?> type = field.getType();
	final String name = tableInfo.getColumnName(field);
	final TypeSerializer typeSerializer = Cache.getParserForType(field.getType());
	final Column column = field.getAnnotation(Column.class);

	if (typeSerializer != null) {
		type = typeSerializer.getSerializedType();
	}

	if (TYPE_MAP.containsKey(type)) {
		definition.append(name);
		definition.append(" ");
		definition.append(TYPE_MAP.get(type).toString());
	}
	else if (ReflectionUtils.isModel(type)) {
		definition.append(name);
		definition.append(" ");
		definition.append(SQLiteType.INTEGER.toString());
	}
	else if (ReflectionUtils.isSubclassOf(type, Enum.class)) {
		definition.append(name);
		definition.append(" ");
		definition.append(SQLiteType.TEXT.toString());
	}

	if (!TextUtils.isEmpty(definition)) {

		if (name.equals(tableInfo.getIdName())) {
			definition.append(" PRIMARY KEY AUTOINCREMENT");
		}else if(column!=null){
			if (column.length() > -1) {
				definition.append("(");
				definition.append(column.length());
				definition.append(")");
			}

			if (column.notNull()) {
				definition.append(" NOT NULL ON CONFLICT ");
				definition.append(column.onNullConflict().toString());
			}

			if (column.unique()) {
				definition.append(" UNIQUE ON CONFLICT ");
				definition.append(column.onUniqueConflict().toString());
			}
		}

		if (FOREIGN_KEYS_SUPPORTED && ReflectionUtils.isModel(type)) {
			definition.append(" REFERENCES ");
			definition.append(Cache.getTableInfo((Class<? extends Model>) type).getTableName());
			definition.append("("+tableInfo.getIdName()+")");
			definition.append(" ON DELETE ");
			definition.append(column.onDelete().toString().replace("_", " "));
			definition.append(" ON UPDATE ");
			definition.append(column.onUpdate().toString().replace("_", " "));
		}
	}
	else {
		Log.e("No type mapping for: " + type.toString());
	}

	return definition.toString();
}
 
Example #9
Source File: ReflectionUtils.java    From mobile-android-survey-app with MIT License 4 votes vote down vote up
public static boolean isTypeSerializer(Class<?> type) {
	return isSubclassOf(type, TypeSerializer.class);
}
 
Example #10
Source File: ModelInfo.java    From mobile-android-survey-app with MIT License 4 votes vote down vote up
public TypeSerializer getTypeSerializer(Class<?> type) {
	return mTypeSerializers.get(type);
}
 
Example #11
Source File: Configuration.java    From mobile-android-survey-app with MIT License 4 votes vote down vote up
public Builder setTypeSerializers(Class<? extends TypeSerializer>... typeSerializers) {
	mTypeSerializers = Arrays.asList(typeSerializers);
	return this;
}
 
Example #12
Source File: Configuration.java    From mobile-android-survey-app with MIT License 4 votes vote down vote up
public List<Class<? extends TypeSerializer>> getTypeSerializers() {
	return mTypeSerializers;
}
 
Example #13
Source File: Cache.java    From clear-todolist with GNU General Public License v3.0 4 votes vote down vote up
public static synchronized TypeSerializer getParserForType(Class<?> type) {
	return sModelInfo.getTypeSerializer(type);
}
 
Example #14
Source File: SQLiteUtils.java    From clear-todolist with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static String createColumnDefinition(TableInfo tableInfo, Field field) {
	StringBuilder definition = new StringBuilder();

	Class<?> type = field.getType();
	final String name = tableInfo.getColumnName(field);
	final TypeSerializer typeSerializer = Cache.getParserForType(field.getType());
	final Column column = field.getAnnotation(Column.class);

	if (typeSerializer != null) {
		type = typeSerializer.getSerializedType();
	}

	if (TYPE_MAP.containsKey(type)) {
		definition.append(name);
		definition.append(" ");
		definition.append(TYPE_MAP.get(type).toString());
	}
	else if (ReflectionUtils.isModel(type)) {
		definition.append(name);
		definition.append(" ");
		definition.append(SQLiteType.INTEGER.toString());
	}
	else if (ReflectionUtils.isSubclassOf(type, Enum.class)) {
		definition.append(name);
		definition.append(" ");
		definition.append(SQLiteType.TEXT.toString());
	}

	if (!TextUtils.isEmpty(definition)) {

		if (name.equals(tableInfo.getIdName())) {
			definition.append(" PRIMARY KEY AUTOINCREMENT");
		}else if(column!=null){
			if (column.length() > -1) {
				definition.append("(");
				definition.append(column.length());
				definition.append(")");
			}

			if (column.notNull()) {
				definition.append(" NOT NULL ON CONFLICT ");
				definition.append(column.onNullConflict().toString());
			}

			if (column.unique()) {
				definition.append(" UNIQUE ON CONFLICT ");
				definition.append(column.onUniqueConflict().toString());
			}
		}

		if (FOREIGN_KEYS_SUPPORTED && ReflectionUtils.isModel(type)) {
			definition.append(" REFERENCES ");
			definition.append(Cache.getTableInfo((Class<? extends Model>) type).getTableName());
			definition.append("("+tableInfo.getIdName()+")");
			definition.append(" ON DELETE ");
			definition.append(column.onDelete().toString().replace("_", " "));
			definition.append(" ON UPDATE ");
			definition.append(column.onUpdate().toString().replace("_", " "));
		}
	}
	else {
		Log.e("No type mapping for: " + type.toString());
	}

	return definition.toString();
}
 
Example #15
Source File: ReflectionUtils.java    From clear-todolist with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isTypeSerializer(Class<?> type) {
	return isSubclassOf(type, TypeSerializer.class);
}
 
Example #16
Source File: ModelInfo.java    From clear-todolist with GNU General Public License v3.0 4 votes vote down vote up
public TypeSerializer getTypeSerializer(Class<?> type) {
	return mTypeSerializers.get(type);
}
 
Example #17
Source File: Configuration.java    From clear-todolist with GNU General Public License v3.0 4 votes vote down vote up
public Builder setTypeSerializers(Class<? extends TypeSerializer>... typeSerializers) {
	mTypeSerializers = Arrays.asList(typeSerializers);
	return this;
}
 
Example #18
Source File: Configuration.java    From clear-todolist with GNU General Public License v3.0 4 votes vote down vote up
public List<Class<? extends TypeSerializer>> getTypeSerializers() {
	return mTypeSerializers;
}