1*f585d8a3SJacky Wang /* 2*f585d8a3SJacky Wang * Copyright (C) 2019 The Dagger Authors. 3*f585d8a3SJacky Wang * 4*f585d8a3SJacky Wang * Licensed under the Apache License, Version 2.0 (the "License"); 5*f585d8a3SJacky Wang * you may not use this file except in compliance with the License. 6*f585d8a3SJacky Wang * You may obtain a copy of the License at 7*f585d8a3SJacky Wang * 8*f585d8a3SJacky Wang * http://www.apache.org/licenses/LICENSE-2.0 9*f585d8a3SJacky Wang * 10*f585d8a3SJacky Wang * Unless required by applicable law or agreed to in writing, software 11*f585d8a3SJacky Wang * distributed under the License is distributed on an "AS IS" BASIS, 12*f585d8a3SJacky Wang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*f585d8a3SJacky Wang * See the License for the specific language governing permissions and 14*f585d8a3SJacky Wang * limitations under the License. 15*f585d8a3SJacky Wang */ 16*f585d8a3SJacky Wang 17*f585d8a3SJacky Wang package dagger.hilt.android; 18*f585d8a3SJacky Wang 19*f585d8a3SJacky Wang import dagger.hilt.GeneratesRootInput; 20*f585d8a3SJacky Wang import java.lang.annotation.ElementType; 21*f585d8a3SJacky Wang import java.lang.annotation.Target; 22*f585d8a3SJacky Wang 23*f585d8a3SJacky Wang /** 24*f585d8a3SJacky Wang * Marks an Android component class to be setup for injection with the standard Hilt Dagger Android 25*f585d8a3SJacky Wang * components. Currently, this supports activities, fragments, views, services, and broadcast 26*f585d8a3SJacky Wang * receivers. 27*f585d8a3SJacky Wang * 28*f585d8a3SJacky Wang * <p>This annotation will generate a base class that the annotated class should extend, either 29*f585d8a3SJacky Wang * directly or via the Hilt Gradle Plugin. This base class will take care of injecting members into 30*f585d8a3SJacky Wang * the Android class as well as handling instantiating the proper Hilt components at the right point 31*f585d8a3SJacky Wang * in the lifecycle. The name of the base class will be "Hilt_<annotated class name>". 32*f585d8a3SJacky Wang * 33*f585d8a3SJacky Wang * <p>Example usage (with the Hilt Gradle Plugin): 34*f585d8a3SJacky Wang * 35*f585d8a3SJacky Wang * <pre><code> 36*f585d8a3SJacky Wang * {@literal @}AndroidEntryPoint 37*f585d8a3SJacky Wang * public final class FooActivity extends FragmentActivity { 38*f585d8a3SJacky Wang * {@literal @}Inject Foo foo; 39*f585d8a3SJacky Wang * 40*f585d8a3SJacky Wang * {@literal @}Override 41*f585d8a3SJacky Wang * public void onCreate(Bundle savedInstanceState) { 42*f585d8a3SJacky Wang * super.onCreate(savedInstanceState); // The foo field is injected in super.onCreate() 43*f585d8a3SJacky Wang * } 44*f585d8a3SJacky Wang * } 45*f585d8a3SJacky Wang * </code></pre> 46*f585d8a3SJacky Wang * 47*f585d8a3SJacky Wang * <p>Example usage (without the Hilt Gradle Plugin): 48*f585d8a3SJacky Wang * 49*f585d8a3SJacky Wang * <pre><code> 50*f585d8a3SJacky Wang * {@literal @}AndroidEntryPoint(FragmentActivity.class) 51*f585d8a3SJacky Wang * public final class FooActivity extends Hilt_FooActivity { 52*f585d8a3SJacky Wang * {@literal @}Inject Foo foo; 53*f585d8a3SJacky Wang * 54*f585d8a3SJacky Wang * {@literal @}Override 55*f585d8a3SJacky Wang * public void onCreate(Bundle savedInstanceState) { 56*f585d8a3SJacky Wang * super.onCreate(savedInstanceState); // The foo field is injected in super.onCreate() 57*f585d8a3SJacky Wang * } 58*f585d8a3SJacky Wang * } 59*f585d8a3SJacky Wang * </code></pre> 60*f585d8a3SJacky Wang * 61*f585d8a3SJacky Wang * @see HiltAndroidApp 62*f585d8a3SJacky Wang */ 63*f585d8a3SJacky Wang @Target({ElementType.TYPE}) 64*f585d8a3SJacky Wang @GeneratesRootInput 65*f585d8a3SJacky Wang public @interface AndroidEntryPoint { 66*f585d8a3SJacky Wang 67*f585d8a3SJacky Wang /** 68*f585d8a3SJacky Wang * The base class for the generated Hilt class. When applying the Hilt Gradle Plugin this value 69*f585d8a3SJacky Wang * is not necessary and will be inferred from the current superclass. 70*f585d8a3SJacky Wang */ value()71*f585d8a3SJacky Wang Class<?> value() default Void.class; 72*f585d8a3SJacky Wang } 73