This repository was archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
@Receiver support for @EView and @EViewGroup #1830
Merged
WonderCsabo
merged 5 commits into
androidannotations:develop
from
simopete:1656_EView_EViewGroup_Receiver
Aug 4, 2016
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5dee44d
Fix EServiceHolder receiver delegation method call
simopete d83422b
Add Receiver support to EView/EViewGroup
simopete faa9e8c
Update javadoc for Receiver
simopete 031f229
Compile tests for @Receiver in @EView
simopete f892b64
Functional tests for @Receiver in @EView and @EViewGroup
simopete File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ain/java/org/androidannotations/test/receiver/EViewAndEViewGroupWithReceiverActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * Copyright (C) 2010-2016 eBusiness Information, Excilys Group | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed To in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package org.androidannotations.test.receiver; | ||
|
|
||
| import org.androidannotations.annotations.EActivity; | ||
| import org.androidannotations.annotations.ViewById; | ||
| import org.androidannotations.test.R; | ||
|
|
||
| import android.app.Activity; | ||
|
|
||
| @EActivity(R.layout.activity_eview_eviewgroup_receiver) | ||
| public class EViewAndEViewGroupWithReceiverActivity extends Activity { | ||
|
|
||
| @ViewById | ||
| ViewWithReceiver viewWithReceiver; | ||
|
|
||
| @ViewById | ||
| ViewGroupWithReceiver viewGroupWithReceiver; | ||
|
|
||
| } |
24 changes: 24 additions & 0 deletions
24
...dannotations-test/src/main/java/org/androidannotations/test/receiver/ReceiverActions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /** | ||
| * Copyright (C) 2010-2016 eBusiness Information, Excilys Group | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed To in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package org.androidannotations.test.receiver; | ||
|
|
||
| public abstract class ReceiverActions { | ||
|
|
||
| public static final String ACTION_0 = "org.androidannotations.ACTION_0"; | ||
| public static final String ACTION_1 = "org.androidannotations.ACTION_1"; | ||
| public static final String ACTION_2 = "org.androidannotations.ACTION_2"; | ||
|
|
||
| } |
59 changes: 59 additions & 0 deletions
59
...ations-test/src/main/java/org/androidannotations/test/receiver/ViewGroupWithReceiver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * Copyright (C) 2010-2016 eBusiness Information, Excilys Group | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed To in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package org.androidannotations.test.receiver; | ||
|
|
||
| import org.androidannotations.annotations.EViewGroup; | ||
| import org.androidannotations.annotations.Receiver; | ||
|
|
||
| import android.content.Context; | ||
| import android.content.Intent; | ||
| import android.util.AttributeSet; | ||
| import android.widget.LinearLayout; | ||
|
|
||
| @EViewGroup | ||
| public class ViewGroupWithReceiver extends LinearLayout { | ||
|
|
||
| public boolean action0Received = false; | ||
| public boolean action1Received = false; | ||
| public String action1Extra; | ||
| public boolean action2Received = false; | ||
| public Intent action2Extra; | ||
|
|
||
| public ViewGroupWithReceiver(Context context) { | ||
| super(context); | ||
| } | ||
|
|
||
| public ViewGroupWithReceiver(Context context, AttributeSet attrs) { | ||
| super(context, attrs); | ||
| } | ||
|
|
||
| @Receiver(actions = ReceiverActions.ACTION_0, registerAt = Receiver.RegisterAt.OnAttachOnDetach) | ||
| void receive0() { | ||
| action0Received = true; | ||
| } | ||
|
|
||
| @Receiver(actions = ReceiverActions.ACTION_1, registerAt = Receiver.RegisterAt.OnAttachOnDetach) | ||
| void receive1(@Receiver.Extra("extra") String extra) { | ||
| action1Received = true; | ||
| action1Extra = extra; | ||
| } | ||
|
|
||
| @Receiver(actions = ReceiverActions.ACTION_2, local = true, registerAt = Receiver.RegisterAt.OnAttachOnDetach) | ||
| protected void receive2(@Receiver.Extra Intent extra) { | ||
| action2Received = true; | ||
| action2Extra = extra; | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
...annotations-test/src/main/java/org/androidannotations/test/receiver/ViewWithReceiver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * Copyright (C) 2010-2016 eBusiness Information, Excilys Group | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed To in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package org.androidannotations.test.receiver; | ||
|
|
||
| import org.androidannotations.annotations.EView; | ||
| import org.androidannotations.annotations.Receiver; | ||
|
|
||
| import android.content.Context; | ||
| import android.content.Intent; | ||
| import android.util.AttributeSet; | ||
| import android.view.View; | ||
|
|
||
| @EView | ||
| public class ViewWithReceiver extends View { | ||
|
|
||
| public boolean action0Received = false; | ||
| public boolean action1Received = false; | ||
| public String action1Extra; | ||
| public boolean action2Received = false; | ||
| public Intent action2Extra; | ||
|
|
||
| public ViewWithReceiver(Context context) { | ||
| super(context); | ||
| } | ||
|
|
||
| public ViewWithReceiver(Context context, AttributeSet attrs) { | ||
| super(context, attrs); | ||
| } | ||
|
|
||
| @Receiver(actions = ReceiverActions.ACTION_0, registerAt = Receiver.RegisterAt.OnAttachOnDetach) | ||
| void receive0() { | ||
| action0Received = true; | ||
| } | ||
|
|
||
| @Receiver(actions = ReceiverActions.ACTION_1, registerAt = Receiver.RegisterAt.OnAttachOnDetach) | ||
| void receive1(@Receiver.Extra("extra") String extra) { | ||
| action1Received = true; | ||
| action1Extra = extra; | ||
| } | ||
|
|
||
| @Receiver(actions = ReceiverActions.ACTION_2, local = true, registerAt = Receiver.RegisterAt.OnAttachOnDetach) | ||
| protected void receive2(@Receiver.Extra Intent extra) { | ||
| action2Received = true; | ||
| action2Extra = extra; | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
...s-core/androidannotations-test/src/main/res/layout/activity_eview_eviewgroup_receiver.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
|
|
||
| Copyright (C) 2010-2016 eBusiness Information, Excilys Group | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| use this file except in compliance with the License. You may obtain a copy of | ||
| the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed To in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| License for the specific language governing permissions and limitations under | ||
| the License. | ||
|
|
||
| --> | ||
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="fill_parent" | ||
| android:orientation="vertical"> | ||
|
|
||
| <org.androidannotations.test.receiver.ViewWithReceiver_ | ||
| android:id="@+id/viewWithReceiver" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="wrap_content"/> | ||
|
|
||
| <org.androidannotations.test.receiver.ViewGroupWithReceiver_ | ||
| android:id="@+id/viewGroupWithReceiver" | ||
| android:layout_width="fill_parent" | ||
| android:layout_height="wrap_content"/> | ||
|
|
||
| </LinearLayout> | ||
75 changes: 75 additions & 0 deletions
75
...rc/test/java/org/androidannotations/test/receiver/EViewAndEViewGroupWithReceiverTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /** | ||
| * Copyright (C) 2010-2016 eBusiness Information, Excilys Group | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed To in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package org.androidannotations.test.receiver; | ||
|
|
||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.robolectric.Robolectric; | ||
| import org.robolectric.RobolectricTestRunner; | ||
|
|
||
| import android.content.Intent; | ||
| import android.support.v4.content.LocalBroadcastManager; | ||
|
|
||
| @RunWith(RobolectricTestRunner.class) | ||
| public class EViewAndEViewGroupWithReceiverTest { | ||
|
|
||
| private EViewAndEViewGroupWithReceiverActivity_ activity; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| activity = Robolectric.setupActivity(EViewAndEViewGroupWithReceiverActivity_.class); | ||
| } | ||
|
|
||
| @Test | ||
| public void eViewAndEViewGroupReceivedAction0Test() { | ||
| Intent intent = new Intent(ReceiverActions.ACTION_0); | ||
| activity.sendBroadcast(intent); | ||
|
|
||
| assertTrue(activity.viewWithReceiver.action0Received); | ||
| assertTrue(activity.viewGroupWithReceiver.action0Received); | ||
| } | ||
|
|
||
| @Test | ||
| public void eViewAndEViewGroupReceivedAction1WithExtraTest() { | ||
| String extraContent = "extraContent"; | ||
| Intent intent = new Intent(ReceiverActions.ACTION_1); | ||
| intent.putExtra("extra", extraContent); | ||
| activity.sendBroadcast(intent); | ||
|
|
||
| assertTrue(activity.viewWithReceiver.action1Received); | ||
| assertTrue(activity.viewWithReceiver.action1Extra.equals(extraContent)); | ||
| assertTrue(activity.viewGroupWithReceiver.action1Received); | ||
| assertTrue(activity.viewGroupWithReceiver.action1Extra.equals(extraContent)); | ||
| } | ||
|
|
||
| @Test | ||
| public void eViewAndEViewGroupReceivedAction2WithExtraTest() { | ||
| Intent intent = new Intent(ReceiverActions.ACTION_2); | ||
| Intent extraIntent = new Intent("someAction"); | ||
| intent.putExtra("extra", extraIntent); | ||
|
|
||
| LocalBroadcastManager.getInstance(Robolectric.application).sendBroadcast(intent); | ||
|
|
||
| assertTrue(activity.viewWithReceiver.action2Received); | ||
| assertTrue(activity.viewWithReceiver.action2Extra.equals(extraIntent)); | ||
| assertTrue(activity.viewGroupWithReceiver.action2Received); | ||
| assertTrue(activity.viewGroupWithReceiver.action2Extra.equals(extraIntent)); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,8 @@ | |
| import org.androidannotations.annotations.EIntentService; | ||
| import org.androidannotations.annotations.EReceiver; | ||
| import org.androidannotations.annotations.EService; | ||
| import org.androidannotations.annotations.EView; | ||
| import org.androidannotations.annotations.EViewGroup; | ||
| import org.androidannotations.annotations.Trace; | ||
| import org.androidannotations.annotations.ViewById; | ||
| import org.androidannotations.internal.core.model.AndroidSystemServices; | ||
|
|
@@ -168,8 +170,8 @@ public void enclosingElementHasEActivityOrEFragment(Element element, ElementVali | |
| enclosingElementHasOneOfAnnotations(element, validAnnotations, valid); | ||
| } | ||
|
|
||
| public void enclosingElementHasEActivityOrEFragmentOrEServiceOrEIntentService(Element element, ElementValidation valid) { | ||
| List<Class<? extends Annotation>> validAnnotations = asList(EActivity.class, EFragment.class, EService.class, EIntentService.class); | ||
| public void enclosingElementHasEActivityOrEFragmentOrEServiceOrEIntentServiceOrEViewOrEViewGroup(Element element, ElementValidation valid) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have you checked that this method is not used somehwere else to not break validation in other processors?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay... just realized that all places where this is called are necessarily part of this PR and that it is only used in one place. ignore this comment :D |
||
| List<Class<? extends Annotation>> validAnnotations = asList(EActivity.class, EFragment.class, EService.class, EIntentService.class, EView.class, EViewGroup.class); | ||
| enclosingElementHasOneOfAnnotations(element, validAnnotations, valid); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing new line