Main menu

Pages

[Easy] How to make slide exit activity like telegram in sketchware.

[Easy] How to make slide exit activity like telegram in sketchware.

1. Create new project / enter in your old project.


2. Add / insert H linear in SK virtual screen.


2. Create or add an activity that you want to apply slide exit activity.

//Note : Because if you do not create or add an activity and you insert slide exit activity on Mainactivity, when you slide to exit activity, it will exit the app perfectly.
So it is very important to add or create an activity and apply the slide exit activity on that activity.


3. On the activity you want to apply the slide exit activity, you need or must have a main linear that has or will be insert or inserted in SK virtual screen firstly, like this : 👇





And make sure that the main linear has background color such us red, white, black, yellow or any other colors Except Transparent Color, do not use none or transparent color.


4. On the activity you want to apply the slide exit activity, create a normal moreblock with these codes below in the pic.



• First ASD - getWindow().getDecorView().setBackgroundResource(android.R.color.transparent);
MIN_DISTANCE = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, this.getResources().getDisplayMetrics());
rootView = (ViewGroup) ((ViewGroup) this .findViewById(android.R.id.content)).getChildAt(0);
rootView.post(new Runnable() { @Override public void run() {

rootWidth = rootView.getWidth();
} });
}
// Custom Variables
ViewGroup rootView ;
int rootWidth;
boolean enableSwipe= false;
boolean lockSwipe = false;
float downX;
float downY;
float MIN_DISTANCE ;
// Detect touch Events
@Override public boolean dispatchTouchEvent(MotionEvent event) { 
switch(event.getAction()) { 
case MotionEvent.ACTION_DOWN: 
downX = event.getRawX();
downY =event.getRawY();
enableSwipe = false;
lockSwipe = false;
//convert activity to transparent

try { java.lang.reflect.Method getActivityOptions = Activity.class.getDeclaredMethod("getActivityOptions"); getActivityOptions.setAccessible(true); Object options = getActivityOptions.invoke(this); Class<?>[] classes = Activity.class.getDeclaredClasses(); Class<?> translucentConversionListenerClazz = null; for (Class clazz : classes) { if (clazz.getSimpleName().contains("TranslucentConversionListener")) { translucentConversionListenerClazz = clazz; } } 
java.lang.reflect.Method convertToTranslucent = Activity.class.getDeclaredMethod("convertToTranslucent", translucentConversionListenerClazz, ActivityOptions.class); convertToTranslucent.setAccessible(true); convertToTranslucent.invoke(this, null, options); } catch (Throwable t) {
}
break; 
case MotionEvent.ACTION_MOVE: 
if (!lockSwipe){
if(enableSwipe){
float translation = event.getRawX() -downX - MIN_DISTANCE;
if (translation >= rootWidth || translation<= 0){
rootView.setTranslationX(0);
}else{
rootView.setTranslationX(translation);
}
}else{

• Second ASD - float translation = event.getRawX() -downX;
if(Math.abs(event.getRawY() - downY) >= MIN_DISTANCE){
enableSwipe = false;
lockSwipe = true;
}else{
enableSwipe = event.getRawX() -downX >= MIN_DISTANCE;
}
}
}
break; 
case MotionEvent.ACTION_UP: 
if(rootView.getTranslationX() > rootWidth / 5){
rootView.animate() 
.translationX(rootWidth)
.setListener(
new AnimatorListenerAdapter() { 
@Override public void onAnimationEnd(Animator animation) { 

super.onAnimationEnd(animation);
finish();
overridePendingTransition(0, 0);

} });
}else{
rootView.animate() 
.translationX(0)
.setListener(
new AnimatorListenerAdapter() { 
@Override public void onAnimationEnd(Animator animation) { 
super.onAnimationEnd(animation);

// convert activity back to normal

try {
            java.lang.reflect.Method method = Activity.class.getDeclaredMethod("convertFromTranslucent");
            method.setAccessible(true);
            method.invoke(this);
        } catch (Throwable t) {
        }
} });

• Third ASD - enableSwipe =false;
lockSwipe = false;
}
break; 
default:
enableSwipe =false;
lockSwipe = false;
break; 
}
if (enableSwipe){
// Event will not be passed to next views
return true;
}
else{
// Event will be passed to next views
return super.dispatchTouchEvent(event); 
}
}
{

Or download the moreblock ==>>
Please the moreblock available on Universal SketchCode Apk link : 👇


4. Insert that moreblock you have created on Oncreate of the activity you want to apply the slide exit activity.


5. Save and run the project.....

Thanks for you read thus tutorial words.



reactions

Comments