Github address: 0 intrusion sideslip return

use

Class in Application

SwipeBackHelper.init(this); // This is the first stepCopy the code

This article is not going to be a long explanation of the principle, just to tell you my thinking. The author’s project also has a sideshow return function. Like many sideshow open source projects, we need to inherit the swipeBackActivity base class to realize the control of the sideshow return method. I find it rather tedious. And many sideslip frameworks require the transparent theme true(default false)

<item name="android:windowIsTranslucent">true</item>
Copy the code

In practice, this property is purely problematic. It can cause a series of animation problems, such as front and back animation, Activity back animation, etc. It is also worth noting that when the interface jumps, the Activity that initiates the jump only executes onPause, not onStop.

Therefore, I decided to change this situation. In this process, I had three considerations: dedication to the project, adaptation of the highland version of the phone, and theme compatibility. We should focus on these three points. This is my goal. Let me elaborate on these three directions

In sex

Can you make the Activity sideslip without changing it? The answer is yes. Here I use the ActivityLifeCallbacks technology, need API 14+ in the onActivityCreated function dynamically into the top layer of the layout, instead of the previous initialization of the slide code in the Activity way. And dynamically determine if the Activity is the second to be pushed and if it is a reload. This is because the first Activity launched does not need to be sideslip, as in our home screen.

fitment

In terms of suitability, I hope that the sideslip effect is the same in high and low versions of the phone, and there will be no flash

When reworking swipeBack, I encountered a chance to flash at the end of swiping on older phones, which gave me a headache but had to be fixed. So I found other skid banks to try, I found that some have the same problem, some do not. So I took a closer look at the sideslip libraries that didn’t flash and found that they all had one thing in common: they had to use transparent themes. This kind of mandatory requirement is not acceptable to me, AND I must solve this pain point. Why did it flash? This is easy because the Activity Finish will have an exit animation at the end of the sideslip, so you’ll see the scene flash. Let’s make the exit animation “cancel”, so I set the exit animation to the following:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:interpolator/decelerate_quad">
</set"> < p style =" max-width: 100%; clear: both; min-height: 1emCopy the code

After making the above changes, it is not completely solved, although the chance of flash is greatly reduced. I think I’m going to do it the other way. I draw the DecorView from the previous activity interface onto the canvas of the current activity in dispatchDraw, because the dispatchDraw() method executes first, It then draws the DecorView from Activity A onto the current Activity B interface. B enters onPause, and the content of B is still displayed on the interface. Next, enter A onStart, the system prepares the interface of A, and redraws the DecorView in A to the current interface of A. Enter A onResume, and the interface of A will be displayed on the screen while the interface of B will be hidden. Because the contents of interface A and interface B are the same, there is no switching effect in the display of the screen

compatibility

In terms of compatibility, I want to be compatible with both transparent and opaque themes.

Because these two options are not fixed and uniform in every project. Don’t change SwipeBack just because you use it. It’s not friendly. We should treat them better and be compatible with them. To deal with this, I used reflection technology. The ConvertFromAlways method of the Reflection Activity always turns a transparent theme into an opaque one, compatible with both.

conclusion

The above is the Android sideslip Lib that I share with you today, which has been used in my project. Also welcome to have a try, if you think good, please star for me!

Github address: 0 intrusion sideslip return