From ce04c7ab2b2fddd930e3f94ff8924e8c7d57b51c Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 7 Mar 2017 13:05:51 +0100 Subject: [PATCH] Sliding animation for activity transitions --- .../com/keylesspalace/tusky/BaseActivity.java | 21 +++++++++++++++++++ .../com/keylesspalace/tusky/MainActivity.java | 4 ++++ .../com/keylesspalace/tusky/SFragment.java | 8 ++++++- .../tusky/ViewThreadActivity.java | 10 ++++----- app/src/main/res/anim/slide_from_left.xml | 6 ++++++ app/src/main/res/anim/slide_from_right.xml | 6 ++++++ app/src/main/res/anim/slide_to_left.xml | 6 ++++++ app/src/main/res/anim/slide_to_right.xml | 6 ++++++ app/src/main/res/menu/view_thread_toolbar.xml | 5 ----- .../main/res/transition/activity_slide.xml | 3 +++ 10 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 app/src/main/res/anim/slide_from_left.xml create mode 100644 app/src/main/res/anim/slide_from_right.xml create mode 100644 app/src/main/res/anim/slide_to_left.xml create mode 100644 app/src/main/res/anim/slide_to_right.xml create mode 100644 app/src/main/res/transition/activity_slide.xml diff --git a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java index 28e523a2..bb3a4fb5 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java @@ -15,6 +15,7 @@ package com.keylesspalace.tusky; +import android.content.Intent; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; @@ -38,6 +39,26 @@ public class BaseActivity extends AppCompatActivity { } } + @Override + public void finish() { + super.finish(); + overridePendingTransitionExit(); + } + + @Override + public void startActivity(Intent intent) { + super.startActivity(intent); + overridePendingTransitionEnter(); + } + + private void overridePendingTransitionEnter() { + overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); + } + + private void overridePendingTransitionExit() { + overridePendingTransition(R.anim.slide_from_left, R.anim.slide_to_right); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { TypedValue value = new TypedValue(); diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index acaf77da..3fb5b338 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -21,13 +21,17 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.SystemClock; import android.preference.PreferenceManager; +import android.support.annotation.RequiresApi; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.TabLayout; import android.support.v4.view.ViewPager; import android.os.Bundle; import android.support.v7.widget.Toolbar; +import android.transition.Slide; +import android.transition.TransitionInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; diff --git a/app/src/main/java/com/keylesspalace/tusky/SFragment.java b/app/src/main/java/com/keylesspalace/tusky/SFragment.java index 112fdae1..ba1fea6e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/SFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/SFragment.java @@ -280,8 +280,14 @@ public class SFragment extends Fragment { startActivity(intent); } + @Override + public void startActivity(Intent intent) { + super.startActivity(intent); + getActivity().overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); + } + protected void openReportPage(String accountId, String accountUsername, String statusId, - Spanned statusContent) { + Spanned statusContent) { Intent intent = new Intent(getContext(), ReportActivity.class); intent.putExtra("account_id", accountId); intent.putExtra("account_username", accountUsername); diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java b/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java index 3250d50e..e9e0485e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewThreadActivity.java @@ -35,7 +35,9 @@ public class ViewThreadActivity extends BaseActivity { setSupportActionBar(toolbar); ActionBar bar = getSupportActionBar(); if (bar != null) { - bar.setTitle(R.string.title_thread); + bar.setTitle(null); + bar.setDisplayHomeAsUpEnabled(true); + bar.setDisplayShowHomeEnabled(true); } String id = getIntent().getStringExtra("id"); @@ -54,10 +56,8 @@ public class ViewThreadActivity extends BaseActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case R.id.action_back: { - Intent intent = new Intent(this, MainActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(intent); + case android.R.id.home: { + onBackPressed(); return true; } } diff --git a/app/src/main/res/anim/slide_from_left.xml b/app/src/main/res/anim/slide_from_left.xml new file mode 100644 index 00000000..5c7fe522 --- /dev/null +++ b/app/src/main/res/anim/slide_from_left.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/slide_from_right.xml b/app/src/main/res/anim/slide_from_right.xml new file mode 100644 index 00000000..3c595d04 --- /dev/null +++ b/app/src/main/res/anim/slide_from_right.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/slide_to_left.xml b/app/src/main/res/anim/slide_to_left.xml new file mode 100644 index 00000000..21688e2c --- /dev/null +++ b/app/src/main/res/anim/slide_to_left.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/slide_to_right.xml b/app/src/main/res/anim/slide_to_right.xml new file mode 100644 index 00000000..8ded764f --- /dev/null +++ b/app/src/main/res/anim/slide_to_right.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/view_thread_toolbar.xml b/app/src/main/res/menu/view_thread_toolbar.xml index 0f352f24..cd09d76f 100644 --- a/app/src/main/res/menu/view_thread_toolbar.xml +++ b/app/src/main/res/menu/view_thread_toolbar.xml @@ -3,9 +3,4 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> - - \ No newline at end of file diff --git a/app/src/main/res/transition/activity_slide.xml b/app/src/main/res/transition/activity_slide.xml new file mode 100644 index 00000000..cd343707 --- /dev/null +++ b/app/src/main/res/transition/activity_slide.xml @@ -0,0 +1,3 @@ + + \ No newline at end of file