/* * Copyright (C) 2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.eugene.fithealthmaingit; import android.app.Application; import android.content.Context; import com.eugene.fithealthmaingit.Databases_Adapters_ListViews.FoodManual.LogManual; import com.eugene.fithealthmaingit.Databases_Adapters_ListViews.LogFood.LogMeal; import com.eugene.fithealthmaingit.Databases_Adapters_ListViews.LogQuickSearchData.LogQuickSearch; import com.eugene.fithealthmaingit.Databases_Adapters_ListViews.LogRecipes.LogRecipeHolder; import com.eugene.fithealthmaingit.Databases_Adapters_ListViews.LogRecipes.LogRecipeItems; import com.eugene.fithealthmaingit.Databases_Adapters_ListViews.LogWeight.WeightLog; import com.orm.androrm.DatabaseAdapter; import com.orm.androrm.Model; import java.util.ArrayList; import java.util.List; /** * Used androrm to handle database */ public class AppActivity extends Application { private static AppActivity appContext; public void onCreate() { super.onCreate(); appContext = this; initializeDatabase(); } /** * An accessor method to make it easier to access the app context from * classes that are not activities * * @return Context the application context */ public static Context context() { return appContext; } private void initializeDatabase() { // setup the database List<Class<? extends Model>> models = new ArrayList<>(0); models.add(LogQuickSearch.class); models.add(LogMeal.class); models.add(LogManual.class); models.add(WeightLog.class); models.add(LogRecipeHolder.class); models.add(LogRecipeItems.class); String dbName = this.getResources().getString(R.string.database_name); DatabaseAdapter.setDatabaseName(dbName); DatabaseAdapter adapter = new DatabaseAdapter(appContext); adapter.setModels(models); } }