Permalink
Browse files

added intro animations for toolbar, fab and feed items

  • Loading branch information...
frogermcs committed Nov 10, 2014
1 parent 1095d5f commit 4e838861c5f858711b1072777cae2325ce12ee21
@@ -16,9 +16,11 @@
* Created by froger_mcs on 05.11.14.
*/
public class FeedAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int ANIMATED_ITEMS_COUNT = 2;
private Context context;
private int itemsCount = 10;
private int lastAnimatedPosition = -1;
private int itemsCount = 0;
public FeedAdapter(Context context) {
this.context = context;
@@ -30,8 +32,25 @@ public FeedAdapter(Context context) {
return new CellFeedViewHolder(view);
}
private void runEnterAnimation(View view, int position) {
if (position >= ANIMATED_ITEMS_COUNT - 1) {
return;
}
if (position > lastAnimatedPosition) {
lastAnimatedPosition = position;
view.setTranslationY(Utils.getScreenHeight(context));
view.animate()
.translationY(0)
.setInterpolator(new DecelerateInterpolator(3.f))
.setDuration(700)
.start();
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
runEnterAnimation(viewHolder.itemView, position);
CellFeedViewHolder holder = (CellFeedViewHolder) viewHolder;
if (position % 2 == 0) {
holder.ivFeedCenter.setImageResource(R.drawable.img_feed_center_1);
@@ -58,4 +77,9 @@ public CellFeedViewHolder(View view) {
ButterKnife.inject(this, view);
}
}
public void updateItems() {
itemsCount = 10;
notifyDataSetChanged();
}
}
@@ -20,14 +20,23 @@
public class MainActivity extends ActionBarActivity {
private static final int ANIM_DURATION_TOOLBAR = 300;
private static final int ANIM_DURATION_FAB = 400;
@InjectView(R.id.toolbar)
Toolbar toolbar;
@InjectView(R.id.ivLogo)
ImageView ivLogo;
@InjectView(R.id.rvFeed)
RecyclerView rvFeed;
@InjectView(R.id.btnCreate)
ImageButton btnCreate;
private MenuItem inboxMenuItem;
private FeedAdapter feedAdapter;
private boolean pendingIntroAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -36,6 +45,10 @@ protected void onCreate(Bundle savedInstanceState) {
setupToolbar();
setupFeed();
if (savedInstanceState == null) {
pendingIntroAnimation = true;
}
}
private void setupToolbar() {
@@ -55,6 +68,49 @@ public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
inboxMenuItem = menu.findItem(R.id.action_inbox);
inboxMenuItem.setActionView(R.layout.menu_item_view);
if (pendingIntroAnimation) {
pendingIntroAnimation = false;
startIntroAnimation();
}
return true;
}
private void startIntroAnimation() {
btnCreate.setTranslationY(2 * getResources().getDimensionPixelOffset(R.dimen.btn_fab_size));
int actionbarSize = Utils.dpToPx(56);
toolbar.setTranslationY(-actionbarSize);
ivLogo.setTranslationY(-actionbarSize);
inboxMenuItem.getActionView().setTranslationY(-actionbarSize);
toolbar.animate()
.translationY(0)
.setDuration(ANIM_DURATION_TOOLBAR)
.setStartDelay(300);
ivLogo.animate()
.translationY(0)
.setDuration(ANIM_DURATION_TOOLBAR)
.setStartDelay(400);
inboxMenuItem.getActionView().animate()
.translationY(0)
.setDuration(ANIM_DURATION_TOOLBAR)
.setStartDelay(500)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
startContentAnimation();
}
})
.start();
}
private void startContentAnimation() {
btnCreate.animate()
.translationY(0)
.setInterpolator(new OvershootInterpolator(1.f))
.setStartDelay(300)
.setDuration(ANIM_DURATION_FAB)
.start();
feedAdapter.updateItems();
}
}

0 comments on commit 4e83886

Please sign in to comment.