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 @@ -24,7 +24,11 @@
* <p>
* Use on any native, {@link android.os.Parcelable Parcelable} or
* {@link java.io.Serializable Serializable} field in an {@link EActivity}
* annotated class to bind it with Android's extra.
* annotated class to bind it with Android's arguments.
* If <a href="http://parceler.org">Parceler</a> is on the classpath, extras
* annotated with &#064;Parcel, or collections supported by Parceler will be
* automatically marshaled using a {@link android.os.Parcelable Parcelable}
* through the Parcels utility class.
* </p>
* <p>
* The annotation value is the key used for extra. If not set, the field name
Expand All @@ -43,7 +47,7 @@
* Activity#setIntent(Intent)} will automatically update the annotated extras.
* </p>
* <blockquote>
*
*
* Example :
*
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
* Use on any native, {@link android.os.Parcelable Parcelable} or
* {@link java.io.Serializable Serializable} field in an {@link EFragment}
* annotated class to bind it with Android's arguments.
* If <a href="http://parceler.org">Parceler</a> is on the classpath, extras
* annotated with &#064;Parcel, or collections supported by Parceler will be
* automatically marshaled using a {@link android.os.Parcelable Parcelable}
* through the Parcels utility class.
* </p>
* <p>
* The annotation value is the key used for argument. If not set, the field name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
* Use on activity fields to save and restore their values when the system calls
* <code>onSaveInstanceState(Bundle)</code> and <code>onCreate(Bundle)</code>.
* </p>
* <p>
* Use on any native, {@link android.os.Parcelable Parcelable} or
* {@link java.io.Serializable Serializable} field in an {@link EActivity}
* annotated class to bind it with Android's arguments.
* If <a href="http://parceler.org">Parceler</a> is on the classpath, extras
* annotated with &#064;Parcel, or collections supported by Parceler will be
* automatically marshaled using a {@link android.os.Parcelable Parcelable}
* through the Parcels utility class.
* </p>
*
* <blockquote>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
* Use on any native, {@link android.os.Parcelable} or
* {@link java.io.Serializable} parameter of an {@link OnActivityResult}
* annotated method to bind it with the value from the Intent.
* If <a href="http://parceler.org">Parceler</a> is on the classpath, extras
* annotated with &#064;Parcel, or collections supported by Parceler will be
* automatically marshaled using a {@link android.os.Parcelable Parcelable}
* through the Parcels utility class.
* </p>
* <p>
* The annotation value is the key used for the result data. If not set, the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ enum RegisterAt {
* {@code void onReceive(Context context, Intent intent)}. The key of this
* extra is the value of the annotation {@link ReceiverAction.Extra} if it
* is set or the name of the parameter.
* If <a href="http://parceler.org">Parceler</a> is on the classpath, extras
* annotated with &#064;Parcel, or collections supported by Parceler will be
* automatically marshaled using a {@link android.os.Parcelable Parcelable}
* through the Parcels utility class.
* </p>
*/
@Retention(RetentionPolicy.CLASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
* {@code void onReceive(Context context, Intent intent)}. The key of this
* extra is the value of the annotation {@link ReceiverAction.Extra} if it
* is set or the name of the parameter.
* If <a href="http://parceler.org">Parceler</a> is on the classpath, extras
* annotated with &#064;Parcel, or collections supported by Parceler will be
* automatically marshaled using a {@link android.os.Parcelable Parcelable}
* through the Parcels utility class.
* </p>
*/
@Retention(RetentionPolicy.CLASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@
* AbstractIntentService} class, which implements that method, so you do not
* have to do in your actual class if you derive it.
* </p>
* <p>
* Use on any native, {@link android.os.Parcelable Parcelable} or
* {@link java.io.Serializable Serializable} field in an {@link EService}
* annotated class to bind it with Android's arguments.
* If <a href="http://parceler.org">Parceler</a> is on the classpath, extras
* annotated with &#064;Parcel, or collections supported by Parceler will be
* automatically marshaled using a {@link android.os.Parcelable Parcelable}
* through the Parcels utility class.
* </p>
*
* @see EIntentService
* @see org.androidannotations.api.support.app.AbstractIntentService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<main.basedir>${project.parent.parent.basedir}</main.basedir>
<android-rome-version>1.0.0-r2</android-rome-version>
<checkstyle.excludes>**/R.java,**/BuildConfig.java,</checkstyle.excludes>
<parceler.version>1.0.3</parceler.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -82,6 +83,17 @@
<version>140</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.parceler</groupId>
<artifactId>parceler</artifactId>
<version>${parceler.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.parceler</groupId>
<artifactId>parceler-api</artifactId>
<version>${parceler.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
package org.androidannotations.test;

import java.util.ArrayList;
import java.util.List;

import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.test.parceler.ParcelerBean;

import android.app.Activity;
import android.content.Intent;
Expand All @@ -41,6 +43,12 @@ public class ExtraInjectedActivity extends Activity {
@Extra("byteArrayExtra")
byte[] byteArrayExtra;

@Extra("parcelerExtra")
ParcelerBean parcelerExample;

@Extra("parcelerExtraCollection")
List<ParcelerBean> parcelerExampleCollection;

@Extra
String extraWithoutValue;

Expand All @@ -57,6 +65,12 @@ void intentWithExtras() {
ExtraInjectedActivity_.intent(this).intExtra(42).get();
ExtraInjectedActivity_.intent(this).stringExtra("hello")
.startForResult(42);
ExtraInjectedActivity_.intent(this)
.parcelerExample(new ParcelerBean("Andy", 42));
List<ParcelerBean> parcelerBeans = new ArrayList<ParcelerBean>();
parcelerBeans.add(new ParcelerBean("Duke", 1337));
ExtraInjectedActivity_.intent(this)
.parcelerExampleCollection(parcelerBeans);
ExtraInjectedActivity_.intent(this)
.parcelableSerializableData(new ParcelableSerializableData())
.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.InstanceState;
import org.androidannotations.test.R;
import org.androidannotations.test.parceler.ParcelerBean;

import android.app.Activity;
import android.os.Bundle;
Expand Down Expand Up @@ -180,4 +181,6 @@ public class SaveInstanceStateActivity extends Activity {
@InstanceState
Bundle bundle;

@InstanceState
ParcelerBean parcelerBean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (C) 2010-2015 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.parceler;

import org.parceler.Parcel;
import org.parceler.ParcelConstructor;


@Parcel
public class ParcelerBean {

String name;
int age;

public ParcelerBean() {
}

@ParcelConstructor
public ParcelerBean(String name, int age) {
this.name = name;
this.age = age;
}

public String getName() {
return name;
}

public int getAge() {
return age;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import static org.fest.assertions.api.Assertions.assertThat;

import java.util.ArrayList;
import java.util.List;

import org.androidannotations.test.parceler.ParcelerBean;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -93,4 +95,22 @@ public void extraWithoutValueInjected() {
assertThat(activity.extraWithoutValue).isEqualTo("Hello!");
}

@Test
public void parcelerExtraInjected() {
controller.withIntent(ExtraInjectedActivity_.intent(context).parcelerExample(new ParcelerBean("Andy", 42)).get()).create();
assertThat(activity.parcelerExample.getName()).isEqualTo("Andy");
assertThat(activity.parcelerExample.getAge()).isEqualTo(42);
}

@Test
public void parcelerExtraCollectionInjected() {
List<ParcelerBean> parcelerBeans = new ArrayList<ParcelerBean>();
parcelerBeans.add(new ParcelerBean("Duke", 1337));
controller.withIntent(ExtraInjectedActivity_.intent(context).parcelerExampleCollection(parcelerBeans).get()).create();
assertThat(activity.parcelerExampleCollection.size()).isEqualTo(1);
ParcelerBean bean = activity.parcelerExampleCollection.iterator().next();
assertThat(bean.getName()).isEqualTo("Duke");
assertThat(bean.getAge()).isEqualTo(1337);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ public TypeElement typeElementFromQualifiedName(String qualifiedName) {
return getElementUtils().getTypeElement(qualifiedName);
}

public boolean isAnnotatedWith(Element element, String qualifiedName) {
for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
if (annotationMirror.getAnnotationType().toString().equals(qualifiedName)) {
return true;
}
}
return false;
}

public String generatedClassQualifiedNameFromQualifiedName(String qualifiedName) {
TypeElement type = typeElementFromQualifiedName(qualifiedName);
if (type.getNestingKind() == NestingKind.MEMBER) {
Expand Down Expand Up @@ -443,5 +452,4 @@ public boolean hasOneOfClassAnnotations(Element element, List<Class<? extends An
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import com.helger.jcodemodel.AbstractJClass;
import com.helger.jcodemodel.IJExpression;
import com.helger.jcodemodel.IJStatement;
import com.helger.jcodemodel.JExpr;
import com.helger.jcodemodel.JMethod;

Expand Down Expand Up @@ -77,12 +78,14 @@ public class BundleHelper {

private AndroidAnnotationsEnvironment environment;
private AnnotationHelper annotationHelper;
private ParcelerHelper parcelerHelper;
private APTCodeModelHelper codeModelHelper;

private TypeMirror element;

private boolean restoreCallNeedCastStatement = false;
private boolean restoreCallNeedsSuppressWarning = false;
private boolean parcelerBean = false;

private String methodNameToSave;
private String methodNameToRestore;
Expand All @@ -93,6 +96,7 @@ public BundleHelper(AndroidAnnotationsEnvironment environment, TypeMirror elemen
this.environment = environment;
annotationHelper = new AnnotationHelper(environment);
codeModelHelper = new APTCodeModelHelper(environment);
parcelerHelper = new ParcelerHelper(environment);
this.element = element;

String typeString = element.toString();
Expand Down Expand Up @@ -172,6 +176,10 @@ public BundleHelper(AndroidAnnotationsEnvironment environment, TypeMirror elemen
if (isTypeParcelable(type)) {
methodNameToSave = "put" + "Parcelable";
methodNameToRestore = "get" + "Parcelable";
} else if (parcelerHelper.isParcelType(type)) {
methodNameToSave = "put" + "Parcelable";
methodNameToRestore = "get" + "Parcelable";
parcelerBean = true;
} else {
methodNameToSave = "put" + "Serializable";
methodNameToRestore = "get" + "Serializable";
Expand Down Expand Up @@ -225,6 +233,10 @@ public IJExpression getExpressionToRestoreFromBundle(AbstractJClass variableClas
expressionToRestore = JExpr.invoke(bundle, methodNameToRestore).arg(extraKey);
}

if (parcelerBean) {
expressionToRestore = environment.getCodeModel().ref(CanonicalNameConstants.PARCELS_UTILITY_CLASS).staticInvoke("unwrap").arg(expressionToRestore);
}

if (restoreCallNeedCastStatement) {
expressionToRestore = JExpr.cast(variableClass, expressionToRestore);

Expand All @@ -234,4 +246,12 @@ public IJExpression getExpressionToRestoreFromBundle(AbstractJClass variableClas
}
return expressionToRestore;
}

public IJStatement getExpressionToSaveFromField(IJExpression saveStateBundleParam, IJExpression fieldName, IJExpression variableRef) {
IJExpression refExpression = variableRef;
if (parcelerBean) {
refExpression = environment.getCodeModel().ref(CanonicalNameConstants.PARCELS_UTILITY_CLASS).staticInvoke("wrap").arg(refExpression);
}
return JExpr.invoke(saveStateBundleParam, methodNameToSave).arg(fieldName).arg(refExpression);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public final class CanonicalNameConstants {
public static final String INTENT_FILTER = "android.content.IntentFilter";
public static final String COMPONENT_NAME = "android.content.ComponentName";
public static final String BUNDLE = "android.os.Bundle";
public static final String IBINDER = "android.os.IBinder";
public static final String SPARSE_ARRAY = "android.util.SparseArray";
public static final String SPARSE_BOOLEAN_ARRAY = "android.util.SparseBooleanArray";
public static final String APPLICATION = "android.app.Application";
public static final String ACTIVITY = "android.app.Activity";
public static final String EDITABLE = "android.text.Editable";
Expand Down Expand Up @@ -148,6 +151,12 @@ public final class CanonicalNameConstants {
public static final String SCHEME_REGISTRY = "org.apache.http.conn.scheme.SchemeRegistry";
public static final String SINGLE_CLIENT_CONN_MANAGER = "org.apache.http.impl.conn.SingleClientConnManager";

/*
* Parceler
*/
public static final String PARCEL_ANNOTATION = "org.parceler.Parcel";
public static final String PARCELS_UTILITY_CLASS = "org.parceler.Parcels";

private CanonicalNameConstants() {
}

Expand Down
Loading
X Tutup