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.ui; 17 18 import android.location.LocationManager; 19 import android.os.Bundle; 20 import android.support.v4.app.FragmentActivity; 21 import com.example.dagger.activitygraphs.ActivityModule; 22 import com.example.dagger.activitygraphs.DemoApplication; 23 import javax.inject.Inject; 24 25 public class HomeActivity extends FragmentActivity { 26 @Inject LocationManager locationManager; 27 private HomeComponent component; 28 29 HomeComponent component() { 30 if (component == null) { 31 component = DaggerHomeComponent.builder() 32 .applicationComponent(((DemoApplication) getApplication()).component()) 33 .activityModule(new ActivityModule(this)) 34 .build(); 35 } 36 return component; 37 } 38 39 @Override protected void onCreate(Bundle savedInstanceState) { 40 super.onCreate(savedInstanceState); 41 component().inject(this); 42 43 if (savedInstanceState == null) { 44 getSupportFragmentManager().beginTransaction() 45 .add(android.R.id.content, new HomeFragment()) 46 .commit(); 47 } 48 49 // TODO do something with the injected dependencies here! 50 } 51 } 52