Skip to content

Commit

Permalink
Merge pull request #3431 from billdawson/timob-10302
Browse files Browse the repository at this point in the history
TIMOB-10302 Android: Allow window.open() animations for heavyweight windows via activity transitions.
  • Loading branch information
ayeung committed Nov 16, 2012
2 parents cd1cf1c + b6efc66 commit add69f4
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.appcelerator.titanium.proxy.TiWindowProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiFileHelper;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiCompositeLayout;
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutArrangement;
import org.appcelerator.titanium.view.TiUIView;
Expand Down Expand Up @@ -106,12 +105,15 @@ public TiUIActivityWindow(ActivityWindowProxy proxy, TiBaseActivity activity, Me
handleBooted();
}

protected void createNewActivity(HashMap options)
protected void createNewActivity(HashMap<String, Object> options)
{
Activity activity = proxy.getActivity();
Intent intent = createIntent(activity);

Object animated = options.get(TiC.PROPERTY_ANIMATED);
Object enterAnim = options.get(TiC.PROPERTY_ACTIVITY_ENTER_ANIMATION);
Object exitAnim = options.get(TiC.PROPERTY_ACTIVITY_EXIT_ANIMATION);

if (animated != null) {
animate = TiConvert.toBoolean(animated);
}
Expand All @@ -120,9 +122,17 @@ protected void createNewActivity(HashMap options)
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.putExtra(TiC.PROPERTY_ANIMATE, false);
activity.startActivity(intent);
TiUIHelper.overridePendingTransition(activity);
activity.overridePendingTransition(0, 0); // Suppress default transition.

} else {
if (enterAnim != null) {
intent.putExtra(TiC.INTENT_PROPERTY_ENTER_ANIMATION, TiConvert.toInt(enterAnim));
}

if (exitAnim != null) {
intent.putExtra(TiC.INTENT_PROPERTY_EXIT_ANIMATION, TiConvert.toInt(exitAnim));
}

activity.startActivity(intent);
}
}
Expand Down Expand Up @@ -226,7 +236,7 @@ public void close(KrollDict options)
if (windowActivity != null) {
if (!animateOnClose) {
windowActivity.finish();
TiUIHelper.overridePendingTransition(windowActivity);
windowActivity.overridePendingTransition(0, 0); // Suppress default transition.

} else {
windowActivity.finish();
Expand Down Expand Up @@ -430,8 +440,9 @@ public void processProperties(KrollDict d)
if (d.containsKey(TiC.PROPERTY_ACTIVITY)) {
Object activityObject = d.get(TiC.PROPERTY_ACTIVITY);
ActivityProxy activityProxy = getProxy().getActivityProxy();
if (activityObject instanceof HashMap && activityProxy != null) {
KrollDict options = new KrollDict((HashMap) activityObject);
if (activityObject instanceof HashMap<?, ?> && activityProxy != null) {
@SuppressWarnings("unchecked")
KrollDict options = new KrollDict((HashMap<String, Object>) activityObject);
activityProxy.handleCreationDict(options);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@

public class TiActivity extends TiBaseActivity
{
private static final String TAG = "TiActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,26 @@ protected void onCreate(Bundle savedInstanceState)

Intent intent = getIntent();
if (intent != null) {

// Activity transition
final int NO_VAL = -1;
int enterAnim = intent.getIntExtra(TiC.INTENT_PROPERTY_ENTER_ANIMATION, NO_VAL);
int exitAnim = intent.getIntExtra(TiC.INTENT_PROPERTY_EXIT_ANIMATION, NO_VAL);

if (enterAnim != NO_VAL || exitAnim != NO_VAL) {
// If one of them is set, set both of them since
// overridePendingTransition requires both.
if (enterAnim == NO_VAL) {
enterAnim = 0;
}

if (exitAnim == NO_VAL) {
exitAnim = 0;
}

this.overridePendingTransition(enterAnim, exitAnim);
}

if (intent.hasExtra(TiC.INTENT_PROPERTY_MESSENGER)) {
messenger = (Messenger) intent.getParcelableExtra(TiC.INTENT_PROPERTY_MESSENGER);
msgActivityCreatedId = intent.getIntExtra(TiC.INTENT_PROPERTY_MSG_ACTIVITY_CREATED_ID, -1);
Expand Down Expand Up @@ -1180,7 +1200,7 @@ public void finish()
}

if (!animate) {
TiUIHelper.overridePendingTransition(this);
this.overridePendingTransition(0, 0); // Suppress default transition.
}
}

Expand Down
12 changes: 12 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ public class TiC
* @module.api
*/
public static final String EVENT_UNFOCUSED = "unfocused";
public static final String INTENT_PROPERTY_ENTER_ANIMATION = "enterAnimation";
public static final String INTENT_PROPERTY_EXIT_ANIMATION = "exitAnimation";
public static final String INTENT_PROPERTY_FINISH_ROOT = "finishRoot";
public static final String INTENT_PROPERTY_IS_TAB = "isTab";
public static final String INTENT_PROPERTY_LAYOUT = "layout";
Expand Down Expand Up @@ -520,6 +522,16 @@ public class TiC
*/
public static final String PROPERTY_ACTIVITY = "activity";

/**
* @module.api
*/
public static final String PROPERTY_ACTIVITY_ENTER_ANIMATION = "activityEnterAnimation";

/**
* @module.api
*/
public static final String PROPERTY_ACTIVITY_EXIT_ANIMATION = "activityExitAnimation";

/**
* @module.api
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public void open(@Kroll.argument(optional = true) Object arg)
if (arg instanceof KrollDict) {
options = (KrollDict) arg;

} else if (arg instanceof HashMap) {
options = new KrollDict((HashMap) arg);
} else if (arg instanceof HashMap<?, ?>) {
options = new KrollDict((HashMap<String, Object>) arg);

} else if (arg instanceof TiAnimation) {
options = new KrollDict();
Expand All @@ -146,6 +146,7 @@ public void open(@Kroll.argument(optional = true) Object arg)
opening = false;
}

@SuppressWarnings("unchecked")
@Kroll.method
public void close(@Kroll.argument(optional = true) Object arg)
{
Expand All @@ -154,8 +155,8 @@ public void close(@Kroll.argument(optional = true) Object arg)
TiAnimation animation = null;

if (arg != null) {
if (arg instanceof HashMap) {
options = new KrollDict((HashMap) arg);
if (arg instanceof HashMap<?, ?>) {
options = new KrollDict((HashMap<String, Object>) arg);

} else if (arg instanceof TiAnimation) {
options = new KrollDict();
Expand Down Expand Up @@ -384,7 +385,7 @@ public int[] getOrientationModes()
return orientationModes;
}


// Expose the method and property here, instead of in KrollProxy
@Kroll.method(name = "getActivity") @Kroll.getProperty(name = "_internalActivity")
public ActivityProxy getActivityProxy()
Expand Down
80 changes: 76 additions & 4 deletions apidoc/Titanium/UI/Window.yml
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,9 @@ description: |
#### Animations
Windows can be animated like any normal [View](Titanium.UI.View). To transition between
2 windows, you can use the `transition` property on an animation. For example, to flip
right-to-left between two windows, you could do the following:
Windows can be animated like any normal [View](Titanium.UI.View). To transition between
2 windows, you can use the `transition` property on an animation (not supported on Android).
For example, to flip right-to-left between two windows, you could do the following:
var window2 = Titanium.UI.createWindow({url:'foo.js'});
var t = Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT;
Expand Down Expand Up @@ -724,6 +724,10 @@ description: |
w.animate({transform:t2, duration:200});
});
Note that to animate an Android heavyweight window while you open it, you need
to follow a specific procedure which is explained below in "Heavyweight
Window Transitions in Android".
#### iPad Modal Windows
For iPad, iPhone SDK 3.2 and Titanium 1.2 introduced several new ways of presenting
Expand Down Expand Up @@ -774,6 +778,44 @@ description: |
A heavyweight window is always created when you open a new window from inside a
[TabGroup](Titanium.UI.TabGroup).
#### Heavyweight Window Transitions in Android
As explained above, heavyweight windows are their own Android Activity. The only way
to animate the opening of an Activity in Android is to apply an animation _resource_ to
it. Passing a <Titanium.UI.Animation> object as a parameter to <Titanium.UI.Window.open>
will have no effect if the window being opened is heavyweight and thus opens its own Activity.
Instead, in the parameter dictionary you pass to <Titanium.UI.Window.open>, you should set the
[activityEnterAnimation](openWindowParams.activityEnterAnimation) and
[activityExitAnimation](openWindowParams.activityExitAnimation) keys to
animation resources. `activityEnterAnimation` should be set to the animation you want to run
on the new window (activity), while `activityExitAnimation` should be set to the animation you
want to run on the window (activity) that you are leaving as you open the new heavyweight window
above it.
Animation resources are available through the `R` object. Use either <Titanium.Android.R> for
built-in resources or <Titanium.App.Android.R> for resources that you package in your application.
As an example, you may wish for the window that you are opening to fade in while the window
you are leaving should fade out:
var win2 = Ti.UI.createWindow({
fullscreen: false // Makes it heavyweight
});
win2.open({
activityEnterAnimation: Ti.Android.R.anim.fade_in,
activityExitAnimation: Ti.Android.R.anim.fade_out
});
See the official Android [R.anim](http://developer.android.com/reference/android/R.anim.html) documentation
for information about built-in animations.
For information on creating your own animation resource XML files, see "[View Animation](http://developer.android.com/guide/topics/resources/animation-resource.html#View)"
in Android's Resources documentation. After creating an animation resource file, you can place it under
`platform/android/res/anim` in your Titanium project folder and it will be packaged in your app's APK
and then available via <Titanium.App.Android.R>.
#### Android "root" Windows
In Android, you may wish to specify that a window which you create (such as the first
Expand Down Expand Up @@ -823,7 +865,9 @@ properties:
description: |
On Android, this property supports animated transitions on heavyweight windows
except for modal windows (`modal:true`). See "Android Heavyweight and Lightweight
Windows" in the main description of Titanium.UI.Window for more information.
Windows" in the main description of Titanium.UI.Window for more information. The
transitions are on by default, but you can set this to `false` to stop them
if you wish.
On iOS, only use this property to disable animated transitions on modal windows.
This property has unintended side effects on non-modal windows if it is defined.
Expand Down Expand Up @@ -933,3 +977,31 @@ properties:
of Titanium.UI.Window for more information.
type: [Number,String]

- name: activityEnterAnimation
summary: Animation resource to run on the activity (heavyweight window) being opened.
description: |
See "Heavyweight Window Transitions in Android" in the main description of Titanium.UI.Window
for more information.
type: Number
platforms: [android]
since: "3.1.0"
examples:
- title: Sliding in a new Window
example: |
var win2 = Ti.UI.createWindow({fullscreen:false});
win2.open({
activityEnterAnimation: Ti.Android.R.anim.slide_in_left,
activityExitAnimation: Ti.Android.R.anim.slide_out_right
});
- name: activityExitAnimation
summary: Animation resource to run on the activity that is being put in background
as a heavyweight window is being opened above it.
description: |
See "Heavyweight Window Transitions in Android" in the main description of Titanium.UI.Window
for more information.
type: Number
platforms: [android]
since: "3.1.0"

0 comments on commit add69f4

Please sign in to comment.