diff options
author | Chet Haase <chet@google.com> | 2010-10-05 14:30:51 -0700 |
---|---|---|
committer | Chet Haase <chet@google.com> | 2010-10-05 15:13:24 -0700 |
commit | 9ff82bf2b33513052500473d0d6d025a80dcecbf (patch) | |
tree | cc13541088a776d0cda3e02f340de89279dc8d2b /core | |
parent | 10bc36522592179622a0fa7b7f6fffba5907fbf5 (diff) | |
download | frameworks_base-9ff82bf2b33513052500473d0d6d025a80dcecbf.zip frameworks_base-9ff82bf2b33513052500473d0d6d025a80dcecbf.tar.gz frameworks_base-9ff82bf2b33513052500473d0d6d025a80dcecbf.tar.bz2 |
Adding next/prev to fragment animations and to PreferenceActivity
Adding a new concept of "next" and "previous" to fragment.s Previously, fragments would
either be placed onto or taken off of the stack, or would just replace the current
fragment. The new next/prev capability gives the ability to run a transition that is
specific to next/previous operations, such as navigating forward and backward in a list.
New next/prev animations may be associated with a fragment replace operation to get the
next/prev animations built into the system (next animates things up, prev animates them
down).
Change-Id: Ia9f3663bac009376420d845b396ac51b8e4d1647
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/app/FragmentManager.java | 16 | ||||
-rw-r--r-- | core/java/android/app/FragmentTransaction.java | 8 | ||||
-rw-r--r-- | core/java/android/preference/PreferenceActivity.java | 19 | ||||
-rw-r--r-- | core/res/res/anim/fragment_close_enter.xml | 14 | ||||
-rw-r--r-- | core/res/res/anim/fragment_close_exit.xml | 14 | ||||
-rw-r--r-- | core/res/res/anim/fragment_next_enter.xml | 32 | ||||
-rw-r--r-- | core/res/res/anim/fragment_next_exit.xml | 32 | ||||
-rw-r--r-- | core/res/res/anim/fragment_open_enter.xml | 14 | ||||
-rw-r--r-- | core/res/res/anim/fragment_open_exit.xml | 14 | ||||
-rw-r--r-- | core/res/res/anim/fragment_prev_enter.xml | 32 | ||||
-rw-r--r-- | core/res/res/anim/fragment_prev_exit.xml | 32 | ||||
-rwxr-xr-x | core/res/res/values/attrs.xml | 4 | ||||
-rw-r--r-- | core/res/res/values/public.xml | 4 | ||||
-rw-r--r-- | core/res/res/values/styles.xml | 4 |
14 files changed, 176 insertions, 63 deletions
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index da7ba6f..37e7253 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -1380,6 +1380,12 @@ final class FragmentManagerImpl implements FragmentManager { case FragmentTransaction.TRANSIT_FRAGMENT_CLOSE: rev = FragmentTransaction.TRANSIT_FRAGMENT_OPEN; break; + case FragmentTransaction.TRANSIT_FRAGMENT_NEXT: + rev = FragmentTransaction.TRANSIT_FRAGMENT_PREV; + break; + case FragmentTransaction.TRANSIT_FRAGMENT_PREV: + rev = FragmentTransaction.TRANSIT_FRAGMENT_NEXT; + break; } return rev; @@ -1398,6 +1404,16 @@ final class FragmentManagerImpl implements FragmentManager { ? com.android.internal.R.styleable.FragmentAnimation_fragmentCloseEnterAnimation : com.android.internal.R.styleable.FragmentAnimation_fragmentCloseExitAnimation; break; + case FragmentTransaction.TRANSIT_FRAGMENT_NEXT: + animAttr = enter + ? com.android.internal.R.styleable.FragmentAnimation_fragmentNextEnterAnimation + : com.android.internal.R.styleable.FragmentAnimation_fragmentNextExitAnimation; + break; + case FragmentTransaction.TRANSIT_FRAGMENT_PREV: + animAttr = enter + ? com.android.internal.R.styleable.FragmentAnimation_fragmentPrevEnterAnimation + : com.android.internal.R.styleable.FragmentAnimation_fragmentPrevExitAnimation; + break; } return animAttr; } diff --git a/core/java/android/app/FragmentTransaction.java b/core/java/android/app/FragmentTransaction.java index 09d8d26..b00476b 100644 --- a/core/java/android/app/FragmentTransaction.java +++ b/core/java/android/app/FragmentTransaction.java @@ -106,10 +106,14 @@ public interface FragmentTransaction { public final int TRANSIT_UNSET = -1; /** No animation for transition. */ public final int TRANSIT_NONE = 0; - /** Fragment is being added */ + /** Fragment is being added onto the stack */ public final int TRANSIT_FRAGMENT_OPEN = 1 | TRANSIT_ENTER_MASK; - /** Fragment is being removed */ + /** Fragment is being removed from the stack */ public final int TRANSIT_FRAGMENT_CLOSE = 2 | TRANSIT_EXIT_MASK; + /** Fragment is being added in a 'next' operation*/ + public final int TRANSIT_FRAGMENT_NEXT = 3 | TRANSIT_ENTER_MASK; + /** Fragment is being removed in a 'previous' operation */ + public final int TRANSIT_FRAGMENT_PREV = 4 | TRANSIT_EXIT_MASK; /** * Set specific animation resources to run for the fragments that are diff --git a/core/java/android/preference/PreferenceActivity.java b/core/java/android/preference/PreferenceActivity.java index a6c7d9e..a59b2f8 100644 --- a/core/java/android/preference/PreferenceActivity.java +++ b/core/java/android/preference/PreferenceActivity.java @@ -893,11 +893,15 @@ public abstract class PreferenceActivity extends ListActivity implements } } - public void switchToHeaderInner(String fragmentName, Bundle args) { + public void switchToHeaderInner(String fragmentName, Bundle args, boolean next) { getFragmentManager().popBackStack(BACK_STACK_PREFS, POP_BACK_STACK_INCLUSIVE); Fragment f = Fragment.instantiate(this, fragmentName, args); - getFragmentManager().openTransaction().replace( - com.android.internal.R.id.prefs, f).commit(); + FragmentTransaction transaction = getFragmentManager().openTransaction(); + transaction.setTransition(next ? + FragmentTransaction.TRANSIT_FRAGMENT_NEXT : + FragmentTransaction.TRANSIT_FRAGMENT_PREV); + transaction.replace(com.android.internal.R.id.prefs, f); + transaction.commit(); } /** @@ -909,7 +913,7 @@ public abstract class PreferenceActivity extends ListActivity implements */ public void switchToHeader(String fragmentName, Bundle args) { setSelectedHeader(null); - switchToHeaderInner(fragmentName, args); + switchToHeaderInner(fragmentName, args, true); } /** @@ -919,7 +923,8 @@ public abstract class PreferenceActivity extends ListActivity implements * @param header The new header to display. */ public void switchToHeader(Header header) { - switchToHeaderInner(header.fragment, header.fragmentArguments); + switchToHeaderInner(header.fragment, header.fragmentArguments, + mHeaders.indexOf(header) > mHeaders.indexOf(mCurHeader)); setSelectedHeader(header); } @@ -979,7 +984,10 @@ public abstract class PreferenceActivity extends ListActivity implements FragmentTransaction transaction = getFragmentManager().openTransaction(); startPreferenceFragment(fragment, transaction); if (push) { + transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.addToBackStack(BACK_STACK_PREFS); + } else { + transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_NEXT); } transaction.commit(); } @@ -1001,6 +1009,7 @@ public abstract class PreferenceActivity extends ListActivity implements FragmentTransaction transaction = getFragmentManager().openTransaction(); startPreferenceFragment(f, transaction); transaction.setBreadCrumbTitle(pref.getTitle()); + transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.addToBackStack(BACK_STACK_PREFS); transaction.commit(); return true; diff --git a/core/res/res/anim/fragment_close_enter.xml b/core/res/res/anim/fragment_close_enter.xml index 53afa2a..7a9a3b9 100644 --- a/core/res/res/anim/fragment_close_enter.xml +++ b/core/res/res/anim/fragment_close_enter.xml @@ -19,20 +19,6 @@ <set xmlns:android="http://schemas.android.com/apk/res/android"> <objectAnimator android:interpolator="@anim/decelerate_interpolator" - android:valueFrom="2" - android:valueTo="1" - android:valueType="floatType" - android:propertyName="scaleX" - android:duration="@android:integer/config_mediumAnimTime"/> - <objectAnimator - android:interpolator="@anim/decelerate_interpolator" - android:valueFrom="2" - android:valueTo="1" - android:valueType="floatType" - android:propertyName="scaleY" - android:duration="@android:integer/config_mediumAnimTime"/> - <objectAnimator - android:interpolator="@anim/decelerate_interpolator" android:valueFrom="0" android:valueTo="1" android:valueType="floatType" diff --git a/core/res/res/anim/fragment_close_exit.xml b/core/res/res/anim/fragment_close_exit.xml index 1554a4e..0743577 100644 --- a/core/res/res/anim/fragment_close_exit.xml +++ b/core/res/res/anim/fragment_close_exit.xml @@ -20,20 +20,6 @@ <objectAnimator android:interpolator="@anim/accelerate_interpolator" android:valueFrom="1" - android:valueTo=".5" - android:valueType="floatType" - android:propertyName="scaleX" - android:duration="@android:integer/config_mediumAnimTime"/> - <objectAnimator - android:interpolator="@anim/accelerate_interpolator" - android:valueFrom="1" - android:valueTo=".5" - android:valueType="floatType" - android:propertyName="scaleY" - android:duration="@android:integer/config_mediumAnimTime"/> - <objectAnimator - android:interpolator="@anim/accelerate_interpolator" - android:valueFrom="1" android:valueTo="0" android:valueType="floatType" android:propertyName="alpha" diff --git a/core/res/res/anim/fragment_next_enter.xml b/core/res/res/anim/fragment_next_enter.xml new file mode 100644 index 0000000..d2d6ec9 --- /dev/null +++ b/core/res/res/anim/fragment_next_enter.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** Copyright 2010, The Android Open Source Project +** +** 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. +*/ +--> +<set xmlns:android="http://schemas.android.com/apk/res/android"> + <objectAnimator + android:valueFrom="0" + android:valueTo="1" + android:valueType="floatType" + android:propertyName="alpha" + android:duration="@android:integer/config_longAnimTime"/> + <objectAnimator + android:valueFrom="50" + android:valueTo="0" + android:valueType="floatType" + android:propertyName="translationY" + android:duration="@android:integer/config_longAnimTime"/> +</set>
\ No newline at end of file diff --git a/core/res/res/anim/fragment_next_exit.xml b/core/res/res/anim/fragment_next_exit.xml new file mode 100644 index 0000000..fbb82d9 --- /dev/null +++ b/core/res/res/anim/fragment_next_exit.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** Copyright 2010, The Android Open Source Project +** +** 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. +*/ +--> +<set xmlns:android="http://schemas.android.com/apk/res/android"> + <objectAnimator + android:valueFrom="1" + android:valueTo="0" + android:valueType="floatType" + android:propertyName="alpha" + android:duration="@android:integer/config_mediumAnimTime"/> + <objectAnimator + android:valueFrom="0" + android:valueTo="-50" + android:valueType="floatType" + android:propertyName="translationY" + android:duration="@android:integer/config_mediumAnimTime"/> +</set>
\ No newline at end of file diff --git a/core/res/res/anim/fragment_open_enter.xml b/core/res/res/anim/fragment_open_enter.xml index 142f60c..ac60494 100644 --- a/core/res/res/anim/fragment_open_enter.xml +++ b/core/res/res/anim/fragment_open_enter.xml @@ -18,20 +18,6 @@ --> <set xmlns:android="http://schemas.android.com/apk/res/android"> <objectAnimator - android:interpolator="@anim/decelerate_interpolator" - android:valueFrom="2" - android:valueTo="1" - android:valueType="floatType" - android:propertyName="scaleX" - android:duration="@android:integer/config_mediumAnimTime"/> - <objectAnimator - android:interpolator="@anim/decelerate_interpolator" - android:valueFrom="2" - android:valueTo="1" - android:valueType="floatType" - android:propertyName="scaleY" - android:duration="@android:integer/config_mediumAnimTime"/> - <objectAnimator android:valueFrom="0" android:valueTo="1" android:valueType="floatType" diff --git a/core/res/res/anim/fragment_open_exit.xml b/core/res/res/anim/fragment_open_exit.xml index 21260b9..3bf1ad4 100644 --- a/core/res/res/anim/fragment_open_exit.xml +++ b/core/res/res/anim/fragment_open_exit.xml @@ -18,20 +18,6 @@ --> <set xmlns:android="http://schemas.android.com/apk/res/android"> <objectAnimator - android:interpolator="@anim/accelerate_interpolator" - android:valueFrom="1" - android:valueTo="2" - android:valueType="floatType" - android:propertyName="scaleX" - android:duration="@android:integer/config_mediumAnimTime"/> - <objectAnimator - android:interpolator="@anim/accelerate_interpolator" - android:valueFrom="1" - android:valueTo="2" - android:valueType="floatType" - android:propertyName="scaleY" - android:duration="@android:integer/config_mediumAnimTime"/> - <objectAnimator android:valueFrom="1" android:valueTo="0" android:valueType="floatType" diff --git a/core/res/res/anim/fragment_prev_enter.xml b/core/res/res/anim/fragment_prev_enter.xml new file mode 100644 index 0000000..d37afd0 --- /dev/null +++ b/core/res/res/anim/fragment_prev_enter.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** Copyright 2010, The Android Open Source Project +** +** 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. +*/ +--> +<set xmlns:android="http://schemas.android.com/apk/res/android"> + <objectAnimator + android:valueFrom="0" + android:valueTo="1" + android:valueType="floatType" + android:propertyName="alpha" + android:duration="@android:integer/config_longAnimTime"/> + <objectAnimator + android:valueFrom="-50" + android:valueTo="0" + android:valueType="floatType" + android:propertyName="translationY" + android:duration="@android:integer/config_longAnimTime"/> +</set>
\ No newline at end of file diff --git a/core/res/res/anim/fragment_prev_exit.xml b/core/res/res/anim/fragment_prev_exit.xml new file mode 100644 index 0000000..a445a4d --- /dev/null +++ b/core/res/res/anim/fragment_prev_exit.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** Copyright 2010, The Android Open Source Project +** +** 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. +*/ +--> +<set xmlns:android="http://schemas.android.com/apk/res/android"> + <objectAnimator + android:valueFrom="1" + android:valueTo="0" + android:valueType="floatType" + android:propertyName="alpha" + android:duration="@android:integer/config_mediumAnimTime"/> + <objectAnimator + android:valueFrom="0" + android:valueTo="50" + android:valueType="floatType" + android:propertyName="translationY" + android:duration="@android:integer/config_mediumAnimTime"/> +</set>
\ No newline at end of file diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 8e2b762..33d3eeb 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -1088,6 +1088,10 @@ <attr name="fragmentOpenExitAnimation" format="reference" /> <attr name="fragmentCloseEnterAnimation" format="reference" /> <attr name="fragmentCloseExitAnimation" format="reference" /> + <attr name="fragmentNextEnterAnimation" format="reference" /> + <attr name="fragmentNextExitAnimation" format="reference" /> + <attr name="fragmentPrevEnterAnimation" format="reference" /> + <attr name="fragmentPrevExitAnimation" format="reference" /> </declare-styleable> <!-- Window animation class attributes. --> diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 35f8df5..2c3c4fc 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -1332,6 +1332,10 @@ <public type="attr" name="fragmentOpenExitAnimation" /> <public type="attr" name="fragmentCloseEnterAnimation" /> <public type="attr" name="fragmentCloseExitAnimation" /> + <public type="attr" name="fragmentNextEnterAnimation" /> + <public type="attr" name="fragmentNextExitAnimation" /> + <public type="attr" name="fragmentPrevEnterAnimation" /> + <public type="attr" name="fragmentPrevExitAnimation" /> <public type="attr" name="actionBarSize" /> <public type="attr" name="imeSubtypeLocale" /> <public type="attr" name="imeSubtypeMode" /> diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index 3dfaf7f..4b5047e 100644 --- a/core/res/res/values/styles.xml +++ b/core/res/res/values/styles.xml @@ -78,6 +78,10 @@ <item name="fragmentOpenExitAnimation">@anim/fragment_open_exit</item> <item name="fragmentCloseEnterAnimation">@anim/fragment_close_enter</item> <item name="fragmentCloseExitAnimation">@anim/fragment_close_exit</item> + <item name="fragmentNextEnterAnimation">@anim/fragment_next_enter</item> + <item name="fragmentNextExitAnimation">@anim/fragment_next_exit</item> + <item name="fragmentPrevEnterAnimation">@anim/fragment_prev_enter</item> + <item name="fragmentPrevExitAnimation">@anim/fragment_prev_exit</item> </style> <!-- Standard animations for a non-full-screen window or activity. --> |