Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alex11111115 committed Oct 7, 2024
1 parent 7532a14 commit 75aa5bc
Show file tree
Hide file tree
Showing 10 changed files with 456 additions and 71 deletions.
44 changes: 7 additions & 37 deletions .androidide/editor/openedFiles.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,17 @@
"file": "/storage/emulated/0/AndroidIDEProjects/AnimationPro/app/src/main/java/com/example/anim/MainActivity.java",
"selection": {
"end": {
"column": 0,
"index": 0,
"line": 0
"column": 26,
"index": 2992,
"line": 83
},
"start": {
"column": 0,
"index": 0,
"line": 0
}
}
},
{
"file": "/storage/emulated/0/AndroidIDEProjects/AnimationPro/app/src/main/java/com/example/anim/PageActivity.java",
"selection": {
"end": {
"column": 47,
"index": 2446,
"line": 74
},
"start": {
"column": 47,
"index": 2446,
"line": 74
}
}
},
{
"file": "/storage/emulated/0/AndroidIDEProjects/AnimationPro/AnimationPro/src/main/java/com/kilobyte/ActivityTransitionManager.java",
"selection": {
"end": {
"column": 40,
"index": 5440,
"line": 133
},
"start": {
"column": 40,
"index": 5440,
"line": 133
"column": 26,
"index": 2992,
"line": 83
}
}
}
],
"selectedFile": "/storage/emulated/0/AndroidIDEProjects/AnimationPro/AnimationPro/src/main/java/com/kilobyte/ActivityTransitionManager.java"
"selectedFile": "/storage/emulated/0/AndroidIDEProjects/AnimationPro/app/src/main/java/com/example/anim/MainActivity.java"
}
3 changes: 3 additions & 0 deletions AnimationPro/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ android {
}

dependencies {

implementation 'androidx.recyclerview:recyclerview:1.3.2'

// Dynamic Animation library
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'

Expand Down
10 changes: 5 additions & 5 deletions AnimationPro/src/main/java/com/kilobyte/AnimationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

public class AnimationManager {

private static final int ANIMATION_STAGGER_DELAY = 50;
private static final int ANIMATION_BASE_DURATION = 500;
private static final int ANIMATION_STAGGER_DELAY = 20;
private static final int ANIMATION_BASE_DURATION = 250;

public static class SmoothAnimationCreator {

Expand Down Expand Up @@ -87,12 +87,12 @@ public static void startFadeOutAnimation(View targetView) {
}

public static void startGradualScaleAnimation(View targetView) {
ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(targetView, "scaleX", 1f, 1.2f, 1f);
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(targetView, "scaleY", 1f, 1.2f, 1f);
ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(targetView, "scaleX", 1f, 1.07f, 1f);
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(targetView, "scaleY", 1f, 1.07f, 1f);

AnimatorSet scaleAnimationSet = new AnimatorSet();
scaleAnimationSet.playTogether(scaleXAnimator, scaleYAnimator);
scaleAnimationSet.setDuration(1500);
scaleAnimationSet.setDuration(750);
scaleAnimationSet.setInterpolator(new OvershootInterpolator());
scaleAnimationSet.start();
}
Expand Down
103 changes: 103 additions & 0 deletions AnimationPro/src/main/java/com/kilobyte/CustomTransition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.kilobyte;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator; // إضافة المروِّج البديل

public class CustomTransition {
private View sourceView;
private View targetView;
private ViewGroup rootView;
private long duration = 300; // مدة الانتقال بالميللي ثانية

public CustomTransition(View sourceView, View targetView, ViewGroup rootView) {
this.sourceView = sourceView;
this.targetView = targetView;
this.rootView = rootView;
}

public void startTransition() {
// حفظ الموقع الأصلي للعناصر
final float startX = sourceView.getX();
final float startY = sourceView.getY();
final float startWidth = sourceView.getWidth();
final float startHeight = sourceView.getHeight();

// حساب الموقع النهائي
int[] targetLocation = new int[2];
targetView.getLocationInWindow(targetLocation);
final float endX = targetLocation[0];
final float endY = targetLocation[1];
final float endWidth = targetView.getWidth();
final float endHeight = targetView.getHeight();

// إنشاء نسخة مؤقتة من العنصر للانتقال
final View transitionView = createTransitionView(sourceView);
rootView.addView(transitionView);

// إنشاء الأنيميشن
ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
animator.setDuration(duration);
animator.setInterpolator(new AccelerateDecelerateInterpolator()); // استخدام المروِّج الجديد

animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float fraction = animation.getAnimatedFraction();

// حساب القيم الحالية باستخدام التداخل
float currentX = lerp(startX, endX, fraction);
float currentY = lerp(startY, endY, fraction);
float currentWidth = lerp(startWidth, endWidth, fraction);
float currentHeight = lerp(startHeight, endHeight, fraction);

// تحديث موقع وحجم العنصر المؤقت
transitionView.setX(currentX);
transitionView.setY(currentY);
transitionView.getLayoutParams().width = (int) currentWidth;
transitionView.getLayoutParams().height = (int) currentHeight;
transitionView.requestLayout();
}
});

animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// إزالة العنصر المؤقت بعد انتهاء الانتقال
rootView.removeView(transitionView);
targetView.setVisibility(View.VISIBLE);
}
});

// إخفاء العنصر الهدف أثناء الانتقال
targetView.setVisibility(View.INVISIBLE);
animator.start();
}

// دالة مساعدة لإنشاء نسخة من العنصر للانتقال
private View createTransitionView(View source) {
// إنشاء نسخة من العنصر المصدر
View transitionView = new View(source.getContext());
transitionView.setLayoutParams(new ViewGroup.LayoutParams(
source.getWidth(),
source.getHeight()
));
transitionView.setX(source.getX());
transitionView.setY(source.getY());
transitionView.setBackground(source.getBackground());
return transitionView;
}

// دالة مساعدة للتداخل الخطي
private float lerp(float start, float end, float fraction) {
return start + (end - start) * fraction;
}

// تعيين مدة الانتقال
public void setDuration(long duration) {
this.duration = duration;
}
}
Loading

0 comments on commit 75aa5bc

Please sign in to comment.