|
| 1 | +/** |
| 2 | + * Copyright (C) 2010-2013 eBusiness Information, Excilys Group |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * 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, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | +package org.androidannotations.annotations; |
| 17 | + |
| 18 | + |
| 19 | +import java.lang.annotation.ElementType; |
| 20 | +import java.lang.annotation.Retention; |
| 21 | +import java.lang.annotation.RetentionPolicy; |
| 22 | +import java.lang.annotation.Target; |
| 23 | + |
| 24 | +/** |
| 25 | + * This annotation is intended to be used on methods of an {@link EActivity}, {@link EFragment} or {@link EService}. |
| 26 | + * When this annotation is used, a {@link android.content.BroadcastReceiver} |
| 27 | + * will be created to receive the Intent corresponding to the given actions |
| 28 | + * and it will call the annotated method. |
| 29 | + * <p/> |
| 30 | + * The annotated method MUST return void and MAY have one parameter: |
| 31 | + * <ul> |
| 32 | + * <li>An {@link android.content.Intent}</li> |
| 33 | + * </ul> |
| 34 | + * <p/> |
| 35 | + * The annotation has two parameters: |
| 36 | + * <ul> |
| 37 | + * <li> |
| 38 | + * {@link #actions()}: One or several {@link java.lang.String} indicating the actions which will spark the method. |
| 39 | + * This parameter is MANDATORY |
| 40 | + * </li> |
| 41 | + * <li> |
| 42 | + * {@link #registerAt()}: The moment when the {@link android.content.BroadcastReceiver} |
| 43 | + * will be registered and unregistered. By default : OnCreate/OnDestroy. |
| 44 | + * The available values depend on the enclosing enhanced component. |
| 45 | + * |
| 46 | + * </li> |
| 47 | + * </ul> |
| 48 | + * <p/> |
| 49 | + * <blockquote> |
| 50 | + * |
| 51 | + * Example : |
| 52 | + * |
| 53 | + * <pre> |
| 54 | + * @EActivity |
| 55 | + * public class MyActivity { |
| 56 | + * |
| 57 | + * @Receiver(actions={{@link android.net.wifi.WifiManager.WIFI_STATE_CHANGED_ACTION}} |
| 58 | + * public void onWifiStateChanged(Intent intent); |
| 59 | + * |
| 60 | + * @Receiver(actions={{@link android.net.wifi.WifiManager.WIFI_STATE_CHANGED_ACTION}, registerAt=RegisterAt.OnResumeOnPause} |
| 61 | + * public void onWifiStateChangedWithoutIntent(); |
| 62 | + * |
| 63 | + * } |
| 64 | + * </pre> |
| 65 | + * |
| 66 | + */ |
| 67 | +@Retention(RetentionPolicy.CLASS) |
| 68 | +@Target(ElementType.METHOD) |
| 69 | +public @interface Receiver { |
| 70 | + |
| 71 | + String[] actions(); |
| 72 | + |
| 73 | + RegisterAt registerAt() default RegisterAt.OnCreateOnDestroy; |
| 74 | + |
| 75 | + public enum RegisterAt { |
| 76 | + OnCreateOnDestroy, |
| 77 | + OnStartOnStop, |
| 78 | + OnResumeOnPause, |
| 79 | + OnAttachOnDetach |
| 80 | + } |
| 81 | +} |
0 commit comments