1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

Add animation when switching from message list to message view

This commit is contained in:
cketti 2013-02-02 02:21:20 +01:00
parent a7b90feb83
commit b02e338b49
8 changed files with 178 additions and 30 deletions

View File

@ -0,0 +1,13 @@
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="200"
android:fromXDelta="-50%p"
android:toXDelta="0" />
<alpha
android:duration="200"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>

View File

@ -0,0 +1,13 @@
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="200"
android:fromXDelta="50%p"
android:toXDelta="0" />
<alpha
android:duration="200"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>

View File

@ -0,0 +1,13 @@
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="200"
android:fromXDelta="0"
android:toXDelta="-50%p" />
<alpha
android:duration="200"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>

View File

@ -0,0 +1,13 @@
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="200"
android:fromXDelta="0"
android:toXDelta="50%p" />
<alpha
android:duration="200"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<com.fsck.k9.view.ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="@+id/message_list_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<FrameLayout
android:id="@+id/message_view_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</com.fsck.k9.view.ViewSwitcher>

View File

@ -18,7 +18,6 @@
android:layout_width="1px" android:layout_width="1px"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="?attr/messageListDividerColor" android:background="?attr/messageListDividerColor"
android:visibility="gone"
tools:ignore="PxUsage" /> tools:ignore="PxUsage" />
<FrameLayout <FrameLayout

View File

@ -19,6 +19,7 @@ import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -29,6 +30,7 @@ import com.actionbarsherlock.view.MenuItem;
import com.fsck.k9.Account; import com.fsck.k9.Account;
import com.fsck.k9.Account.SortType; import com.fsck.k9.Account.SortType;
import com.fsck.k9.K9; import com.fsck.k9.K9;
import com.fsck.k9.K9.SplitViewMode;
import com.fsck.k9.Preferences; import com.fsck.k9.Preferences;
import com.fsck.k9.R; import com.fsck.k9.R;
import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener; import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener;
@ -50,6 +52,7 @@ import com.fsck.k9.search.SearchSpecification.Searchfield;
import com.fsck.k9.search.SearchSpecification.SearchCondition; import com.fsck.k9.search.SearchSpecification.SearchCondition;
import com.fsck.k9.view.MessageHeader; import com.fsck.k9.view.MessageHeader;
import com.fsck.k9.view.MessageTitleView; import com.fsck.k9.view.MessageTitleView;
import com.fsck.k9.view.ViewSwitcher;
import de.cketti.library.changelog.ChangeLog; import de.cketti.library.changelog.ChangeLog;
@ -148,7 +151,6 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
private TextView mActionBarUnread; private TextView mActionBarUnread;
private Menu mMenu; private Menu mMenu;
private ViewGroup mMessageListContainer;
private ViewGroup mMessageViewContainer; private ViewGroup mMessageViewContainer;
private View mMessageViewPlaceHolder; private View mMessageViewPlaceHolder;
@ -180,6 +182,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
* finish the activity. * finish the activity.
*/ */
private boolean mMessageListWasDisplayed = false; private boolean mMessageListWasDisplayed = false;
private ViewSwitcher mViewSwitcher;
@Override @Override
@ -191,7 +194,17 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
return; return;
} }
setContentView(R.layout.split_message_list); if (useSplitView()) {
setContentView(R.layout.split_message_list);
} else {
setContentView(R.layout.message_list);
mViewSwitcher = (ViewSwitcher) findViewById(R.id.container);
mViewSwitcher.setAnimateFirstView(false);
mViewSwitcher.setFirstInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_left));
mViewSwitcher.setFirstOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_right));
mViewSwitcher.setSecondInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_right));
mViewSwitcher.setSecondOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_left));
}
initializeActionBar(); initializeActionBar();
@ -284,32 +297,23 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
mDisplayMode = (displayMessage) ? DisplayMode.MESSAGE_VIEW : DisplayMode.MESSAGE_LIST; mDisplayMode = (displayMessage) ? DisplayMode.MESSAGE_VIEW : DisplayMode.MESSAGE_LIST;
} }
switch (K9.getSplitViewMode()) { if (useSplitView()) {
case ALWAYS: { mDisplayMode = DisplayMode.SPLIT_VIEW;
mDisplayMode = DisplayMode.SPLIT_VIEW; } else if (mMessageViewFragment != null || mDisplayMode == DisplayMode.MESSAGE_VIEW) {
break; mDisplayMode = DisplayMode.MESSAGE_VIEW;
}
case NEVER: {
// Use the value set at the beginning of this method.
break;
}
case WHEN_IN_LANDSCAPE: {
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
mDisplayMode = DisplayMode.SPLIT_VIEW;
} else if (mMessageViewFragment != null ||
mDisplayMode == DisplayMode.MESSAGE_VIEW) {
mDisplayMode = DisplayMode.MESSAGE_VIEW;
} else {
mDisplayMode = DisplayMode.MESSAGE_LIST;
}
break;
}
} }
} }
private boolean useSplitView() {
SplitViewMode splitViewMode = K9.getSplitViewMode();
int orientation = getResources().getConfiguration().orientation;
return (splitViewMode == SplitViewMode.ALWAYS ||
(splitViewMode == SplitViewMode.WHEN_IN_LANDSCAPE &&
orientation == Configuration.ORIENTATION_LANDSCAPE));
}
private void initializeLayout() { private void initializeLayout() {
mMessageListContainer = (ViewGroup) findViewById(R.id.message_list_container);
mMessageViewContainer = (ViewGroup) findViewById(R.id.message_view_container); mMessageViewContainer = (ViewGroup) findViewById(R.id.message_view_container);
mMessageViewPlaceHolder = getLayoutInflater().inflate(R.layout.empty_message_view, null); mMessageViewPlaceHolder = getLayoutInflater().inflate(R.layout.empty_message_view, null);
} }
@ -326,7 +330,6 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
} }
case SPLIT_VIEW: { case SPLIT_VIEW: {
mMessageListWasDisplayed = true; mMessageListWasDisplayed = true;
findViewById(R.id.message_list_divider).setVisibility(View.VISIBLE);
if (mMessageViewFragment == null) { if (mMessageViewFragment == null) {
showMessageViewPlaceHolder(); showMessageViewPlaceHolder();
} else { } else {
@ -1319,8 +1322,8 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
mMessageListWasDisplayed = true; mMessageListWasDisplayed = true;
mDisplayMode = DisplayMode.MESSAGE_LIST; mDisplayMode = DisplayMode.MESSAGE_LIST;
mMessageViewContainer.setVisibility(View.GONE); mViewSwitcher.showFirstView();
mMessageListContainer.setVisibility(View.VISIBLE);
removeMessageViewFragment(); removeMessageViewFragment();
mMessageListFragment.setActiveMessage(null); mMessageListFragment.setActiveMessage(null);
@ -1330,8 +1333,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
private void showMessageView() { private void showMessageView() {
mDisplayMode = DisplayMode.MESSAGE_VIEW; mDisplayMode = DisplayMode.MESSAGE_VIEW;
mMessageListContainer.setVisibility(View.GONE); mViewSwitcher.showSecondView();
mMessageViewContainer.setVisibility(View.VISIBLE);
showMessageTitleView(); showMessageTitleView();
} }

View File

@ -0,0 +1,78 @@
package com.fsck.k9.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.widget.ViewAnimator;
/**
* A {@link ViewAnimator} that animates between two child views using different animations
* depending on which view is displayed.
*/
public class ViewSwitcher extends ViewAnimator {
private Animation mFirstInAnimation;
private Animation mFirstOutAnimation;
private Animation mSecondInAnimation;
private Animation mSecondOutAnimation;
public ViewSwitcher(Context context) {
super(context);
}
public ViewSwitcher(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void showFirstView() {
if (getDisplayedChild() == 0) {
return;
}
setInAnimation(mFirstInAnimation);
setOutAnimation(mFirstOutAnimation);
setDisplayedChild(0);
}
public void showSecondView() {
if (getDisplayedChild() == 1) {
return;
}
setInAnimation(mSecondInAnimation);
setOutAnimation(mSecondOutAnimation);
setDisplayedChild(1);
}
public Animation getFirstInAnimation() {
return mFirstInAnimation;
}
public void setFirstInAnimation(Animation inAnimation) {
this.mFirstInAnimation = inAnimation;
}
public Animation getmFirstOutAnimation() {
return mFirstOutAnimation;
}
public void setFirstOutAnimation(Animation outAnimation) {
mFirstOutAnimation = outAnimation;
}
public Animation getSecondInAnimation() {
return mSecondInAnimation;
}
public void setSecondInAnimation(Animation inAnimation) {
mSecondInAnimation = inAnimation;
}
public Animation getSecondOutAnimation() {
return mSecondOutAnimation;
}
public void setSecondOutAnimation(Animation outAnimation) {
mSecondOutAnimation = outAnimation;
}
}