しばらく前に、ページ遷移を伴うウィザードを実装する必要がありました。そして、ActivityGroup アプローチを使用しました。Wizard
( から継承AcitivtyGroup
) とWizardPage
( から継承)がありActivity
ました。 WizardPage
アニメーションを処理するコードを持っていましたがWizard
、適切なタイミングでそれらのアニメーションを呼び出す責任がありました。
WizardPage
クラス:
/**
* Called to animate appearance of this activity
* as if somebody clicked next on previous activity
* and ended up to this activity.
*
* Animation: <----
*/
void onAnimateOpenAsNext()
{
animateTransition(android.R.attr.activityOpenEnterAnimation);
}
/**
* Called to animate appearance of this activity
* as if somebody clicked back on previous activity
* and ended up to this activity.
*
* Animation: ---->
*/
void onAnimateOpenAsPrev()
{
animateTransition(android.R.attr.activityCloseEnterAnimation);
}
/**
* Called to animate disappearance of this acitivity
* when "next" button was clicked
*
* Animation: <--
*/
void onAnimateCloseOnNext()
{
animateTransition(android.R.attr.activityOpenExitAnimation);
}
/**
* Called to animate disappearance of this activity
* when "prev" button was clicked
*
* Animation: -->
*/
void onAnimateCloseOnPrev()
{
animateTransition(android.R.attr.activityCloseExitAnimation);
}
private void animateTransition(int animAttributeId)
{
TypedValue animations = new TypedValue();
Theme theme = this.getTheme();
theme.resolveAttribute(android.R.attr.windowAnimationStyle, animations, true);
TypedArray animationArray = obtainStyledAttributes(animations.resourceId,
new int[] {animAttributeId});
int animResId = animationArray.getResourceId(0, 0);
animationArray.recycle();
if(animResId != 0)
{
try
{
Animation anim = AnimationUtils.loadAnimation(this, animResId);
getWindow().getDecorView().startAnimation(anim);
}
catch(Resources.NotFoundException ex)
{
//didn't find animation resource, ignore error
}
}
}
Wizard
startPage
実際のアクティビティ遷移を行うために呼び出されたメソッドがありました:
public void startPage(int i)
{
int prevIndex = getCurrentPageIndex();
m_pageIndex = i;
WizardPage currentPage = getCurrentPage();
if(currentPage != null)
{
if(prevIndex <= i)
{
currentPage.onAnimateCloseOnNext();
}
else
{
currentPage.onAnimateCloseOnPrev();
}
}
LocalActivityManager manager = getLocalActivityManager();
m_startingActivity = true;
Window activityWindow = manager.startActivity(Integer.toString(i), m_pageIntens.get(i));
m_startingActivity = false;
setContentView(activityWindow.getDecorView());
currentPage = getCurrentPage();
if(currentPage != null)
{
if(prevIndex <= i)
{
getCurrentPage().onAnimateOpenAsNext();
}
else
{
getCurrentPage().onAnimateOpenAsPrev();
}
}
}