1 /*
2  * Copyright (C) 2017 The Dagger Authors.
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 dagger.android.support;
18 
19 import android.os.Bundle;
20 import androidx.annotation.ContentView;
21 import androidx.annotation.LayoutRes;
22 import androidx.annotation.Nullable;
23 import androidx.appcompat.app.AppCompatActivity;
24 import dagger.android.AndroidInjection;
25 import dagger.android.AndroidInjector;
26 import dagger.android.DispatchingAndroidInjector;
27 import dagger.android.HasAndroidInjector;
28 import dagger.internal.Beta;
29 import javax.inject.Inject;
30 
31 /**
32  * An {@link AppCompatActivity} that injects its members in {@link #onCreate(Bundle)} and can be
33  * used to inject {@code Fragment}s attached to it.
34  */
35 @Beta
36 public abstract class DaggerAppCompatActivity extends AppCompatActivity
37     implements HasAndroidInjector {
38 
39   @Inject DispatchingAndroidInjector<Object> androidInjector;
40 
DaggerAppCompatActivity()41   public DaggerAppCompatActivity() {
42     super();
43   }
44 
45   @ContentView
DaggerAppCompatActivity(@ayoutRes int contentLayoutId)46   public DaggerAppCompatActivity(@LayoutRes int contentLayoutId) {
47     super(contentLayoutId);
48   }
49 
50   @Override
onCreate(@ullable Bundle savedInstanceState)51   protected void onCreate(@Nullable Bundle savedInstanceState) {
52     AndroidInjection.inject(this);
53     super.onCreate(savedInstanceState);
54   }
55 
56   @Override
androidInjector()57   public AndroidInjector<Object> androidInjector() {
58     return androidInjector;
59   }
60 }
61