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 @@ -62,12 +62,13 @@ public ActivityIntentBuilder(Context context, Intent intent) {
}

@Override
public final void start() {
public final PostActivityStarter start() {
startForResult(-1);
return new PostActivityStarter(context);
}

@Override
public abstract void startForResult(int requestCode);
public abstract PostActivityStarter startForResult(int requestCode);

/**
* Adds additional options {@link Bundle} to the start method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public interface ActivityStarter {
* objects. It also passes the given extras, the options
* {@link android.os.Bundle Bundle}, if new methods are available which
* accept that.
*
* @return a {@link PostActivityStarter} object to optionally chain
* additional actions.
*/
void start();
PostActivityStarter start();

/**
* Starts the {@link android.app.Activity Activity} for result, by calling
Expand All @@ -43,6 +46,9 @@ public interface ActivityStarter {
* @param requestCode
* this code will be returned in onActivityResult() when the
* activity exits.
*
* @return a {@link PostActivityStarter} object to optionally chain
* additional actions.
*/
void startForResult(int requestCode);
PostActivityStarter startForResult(int requestCode);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* 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.api.builder;

import android.app.Activity;
import android.content.Context;

/**
* Provides additional actions to be added to a start of an {@link Activity}.
*/
public final class PostActivityStarter {

private Context context;

/**
* Creates a new instance.
*
* @param context
* the current {@link Context} which is used to start the
* {@link Activity}
*/
public PostActivityStarter(Context context) {
this.context = context;
}

/**
* Call this to specify an explicit transition animation to perform next.
*
* The implementation of this method simply calls
* {@link Activity#overridePendingTransition}, if the current context is an
* {@link Activity}.
*
* @param enterAnim
* A resource ID of the animation resource to use for the
* incoming activity. Use 0 for no animation.
* @param exitAnim
* A resource ID of the animation resource to use for the
* outgoing activity. Use 0 for no animation.
*/
void withAnimation(int enterAnim, int exitAnim) {
if (context instanceof Activity) {
((Activity) context).overridePendingTransition(enterAnim, exitAnim);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.lang.model.element.VariableElement;
import javax.lang.model.util.ElementFilter;

import org.androidannotations.api.builder.PostActivityStarter;
import org.androidannotations.helper.AndroidManifest;
import org.androidannotations.helper.CanonicalNameConstants;
import org.androidannotations.holder.HasIntentBuilder;
Expand Down Expand Up @@ -116,7 +117,9 @@ private JFieldVar addFragmentConstructor(JClass fragmentClass, String fieldName)
}

private void overrideStartForResultMethod() {
JMethod method = holder.getIntentBuilderClass().method(PUBLIC, environment.getCodeModel().VOID, "startForResult");
JClass postActivityStarterClass = environment.getJClass(PostActivityStarter.class);

JMethod method = holder.getIntentBuilderClass().method(PUBLIC, postActivityStarterClass, "startForResult");
method.annotate(Override.class);
JVar requestCode = method.param(environment.getCodeModel().INT, "requestCode");
JBlock body = method.body();
Expand Down Expand Up @@ -188,6 +191,8 @@ private void overrideStartForResultMethod() {
} else {
activityCondition._else().invoke(contextField, "startActivity").arg(intentField);
}

body._return(_new(postActivityStarterClass).arg(contextField));
}

private JBlock createCallWithIfGuard(JVar requestCode, JBlock thenBlock, JExpression invocationTarget) {
Expand Down
X Tutup