X Tutup
Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ enum RegisterAt {
OnResumeOnPause, //
/**
* Register in the onAttach method, unregister in the onDetach method.
* Except for View which will register in the onAttachedToWindow and
* unregister in the onDetachedFromWindow.
*/
OnAttachOnDetach
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<activity android:name=".innerclasses.ActivityWithInnerEnhancedClasses_" />
<activity android:name=".MultiFindViewActivity_" />
<activity android:name=".receiver.ActivityWithReceiver_" />
<activity android:name=".receiver.EViewAndEViewGroupWithReceiverActivity_" />
<activity android:name=".menu.OptionsMenuActivity_" />
<activity android:name=".menu.OptionsMenuSubActivity_" />
<activity android:name=".menu.InjectMenuActivity_" />
Expand Down
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;

}
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";

}
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;
}
}
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;
}
}
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing new line

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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public JBlock getOnStopBeforeSuperBlock() {

@Override
public JBlock getOnResumeAfterSuperBlock() {
return receiverRegistrationDelegate.getOnAttachAfterSuperBlock();
return receiverRegistrationDelegate.getOnResumeAfterSuperBlock();
}

@Override
Expand Down
Loading
X Tutup