Sliding animation for activity transitions

This commit is contained in:
Eugen Rochko 2017-03-07 13:05:51 +01:00
parent 03d9701669
commit ce04c7ab2b
10 changed files with 64 additions and 11 deletions

View file

@ -15,6 +15,7 @@
package com.keylesspalace.tusky; package com.keylesspalace.tusky;
import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable; 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 @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
TypedValue value = new TypedValue(); TypedValue value = new TypedValue();

View file

@ -21,13 +21,17 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.SystemClock; import android.os.SystemClock;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.RequiresApi;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.transition.Slide;
import android.transition.TransitionInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;

View file

@ -280,8 +280,14 @@ public class SFragment extends Fragment {
startActivity(intent); 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, protected void openReportPage(String accountId, String accountUsername, String statusId,
Spanned statusContent) { Spanned statusContent) {
Intent intent = new Intent(getContext(), ReportActivity.class); Intent intent = new Intent(getContext(), ReportActivity.class);
intent.putExtra("account_id", accountId); intent.putExtra("account_id", accountId);
intent.putExtra("account_username", accountUsername); intent.putExtra("account_username", accountUsername);

View file

@ -35,7 +35,9 @@ public class ViewThreadActivity extends BaseActivity {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
ActionBar bar = getSupportActionBar(); ActionBar bar = getSupportActionBar();
if (bar != null) { if (bar != null) {
bar.setTitle(R.string.title_thread); bar.setTitle(null);
bar.setDisplayHomeAsUpEnabled(true);
bar.setDisplayShowHomeEnabled(true);
} }
String id = getIntent().getStringExtra("id"); String id = getIntent().getStringExtra("id");
@ -54,10 +56,8 @@ public class ViewThreadActivity extends BaseActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_back: { case android.R.id.home: {
Intent intent = new Intent(this, MainActivity.class); onBackPressed();
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true; return true;
} }
} }

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%p" android:toXDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="300"/>
</set>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="300"/>
</set>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="300"/>
</set>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="300"/>
</set>

View file

@ -3,9 +3,4 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_back"
android:title="@string/action_back"
android:icon="@drawable/ic_back"
app:showAsAction="always" />
</menu> </menu>

View file

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<slide xmlns:android="http://schemas.android.com/apk/res/"
android:duration="1000"/>