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;
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();

View File

@ -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;

View File

@ -280,6 +280,12 @@ 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) {
Intent intent = new Intent(getContext(), ReportActivity.class);

View File

@ -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;
}
}

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: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>

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"/>