1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.example.android.asymmetricfingerprintdialog; 18 19 import android.app.Application; 20 import android.util.Log; 21 22 import dagger.ObjectGraph; 23 24 /** 25 * The Application class of the sample which holds the ObjectGraph in Dagger and enables 26 * dependency injection. 27 */ 28 public class InjectedApplication extends Application { 29 30 private static final String TAG = InjectedApplication.class.getSimpleName(); 31 32 private ObjectGraph mObjectGraph; 33 34 @Override onCreate()35 public void onCreate() { 36 super.onCreate(); 37 38 initObjectGraph(new FingerprintModule(this)); 39 } 40 41 /** 42 * Initialize the Dagger module. Passing null or mock modules can be used for testing. 43 * 44 * @param module for Dagger 45 */ initObjectGraph(Object module)46 public void initObjectGraph(Object module) { 47 mObjectGraph = module != null ? ObjectGraph.create(module) : null; 48 } 49 inject(Object object)50 public void inject(Object object) { 51 if (mObjectGraph == null) { 52 // This usually happens during tests. 53 Log.i(TAG, "Object graph is not initialized."); 54 return; 55 } 56 mObjectGraph.inject(object); 57 } 58 59 } 60