Back to project page ActiveAndroidDemo.
The source code is released under:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...
If you think the Android project ActiveAndroidDemo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.gannon.activeandroiddemo.helpers; /* w w w .ja va 2 s . com*/ import android.content.Context; import com.gannon.activeandroiddemo.ActiveAndroidDemo; import com.gannon.activeandroiddemo.R; import com.gannon.activeandroiddemo.models.Category; import com.gannon.activeandroiddemo.models.Product; /** * Model helper methods */ public class ModelHelper { protected static Context context; static { context = ActiveAndroidDemo.getContext(); } /** * Seed default categories */ public static void seedCategories() { String[] names = context.getResources().getStringArray(R.array.seed_categories); Category.deleteAll(); for (String name : names) { Category category = new Category(); category.name = name; category.save(); } } /** * Seed default products */ public static void seedProducts() { String[] valueSets = context.getResources().getStringArray(R.array.seed_products); Product.deleteAll(); for (String set : valueSets) { Product product = new Product(); String[] values = set.split(",\\s*"); product.title = values[0]; product.description = values[1]; product.price = Double.parseDouble(values[2]); product.category = Category.load(Category.class, Long.parseLong(values[3])); product.save(); } } public static Category getPlaceholderCategory() { Category placeholder = new Category(); placeholder.name = "(None)"; return placeholder; } }