Home | History | Annotate | Download | only in activitygraphs
      1 /*
      2  * Copyright (C) 2013 Square, Inc.
      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 package com.example.dagger.activitygraphs;
     17 
     18 import android.app.Application;
     19 import android.location.LocationManager;
     20 import dagger.Module;
     21 import dagger.Provides;
     22 import javax.inject.Singleton;
     23 
     24 import static android.content.Context.LOCATION_SERVICE;
     25 
     26 /**
     27  * A module for Android-specific dependencies which require a {@link Context} or
     28  * {@link android.app.Application} to create.
     29  */
     30 @Module
     31 public class DemoApplicationModule {
     32   private final Application application;
     33 
     34   public DemoApplicationModule(Application application) {
     35     this.application = application;
     36   }
     37 
     38   /**
     39    * Expose the application to the graph.
     40    */
     41   @Provides @Singleton Application application() {
     42     return application;
     43   }
     44 
     45   @Provides @Singleton LocationManager provideLocationManager() {
     46     return (LocationManager) application.getSystemService(LOCATION_SERVICE);
     47   }
     48 }
     49