-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
203 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
rigger/src/main/java/com/jkb/fragment/swiper/SwipeActivityManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.jkb.fragment.swiper; | ||
|
||
import android.app.Activity; | ||
import android.support.annotation.NonNull; | ||
|
||
import java.util.Stack; | ||
|
||
/** | ||
* This class is used to manage {@link android.app.Activity} and only used by {@link SwipeLayout}. | ||
* | ||
* @author JingYeoh | ||
* <a href="mailto:[email protected]">Email me</a> | ||
* <a href="https://github.com/justkiddingbaby">Github</a> | ||
* <a href="http://blog.justkiddingbaby.com">Blog</a> | ||
* @since Aug 1,2018 | ||
*/ | ||
class SwipeActivityManager { | ||
|
||
private Stack<Activity> mActivityStack; | ||
|
||
private static volatile SwipeActivityManager sInstance = null; | ||
|
||
private SwipeActivityManager() { | ||
mActivityStack = new Stack<>(); | ||
} | ||
|
||
/** | ||
* Returns the instance of SwipeManager. | ||
*/ | ||
static SwipeActivityManager getInstance() { | ||
if (sInstance == null) { | ||
synchronized (SwipeActivityManager.class) { | ||
if (sInstance == null) { | ||
sInstance = new SwipeActivityManager(); | ||
} | ||
} | ||
} | ||
return sInstance; | ||
} | ||
|
||
private void addToStack(@NonNull Activity activity) { | ||
mActivityStack.add(activity); | ||
} | ||
|
||
private void removeFromStack(@NonNull Activity activity) { | ||
mActivityStack.remove(activity); | ||
} | ||
|
||
@NonNull | ||
Stack<Activity> getActivityStack() { | ||
return mActivityStack; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
rigger/src/main/java/com/jkb/fragment/swiper/aop/SwipeInjection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.jkb.fragment.swiper.aop; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* Using AspectJ tools reach AOP. this class is used to inject | ||
* {@link com.jkb.fragment.rigger.rigger.Rigger} to Activity's lifecycle and other methods. | ||
* | ||
* @author JingYeoh | ||
* <a href="mailto:[email protected]">Email me</a> | ||
* <a href="https://github.com/justkiddingbaby">Github</a> | ||
* <a href="http://blog.justkiddingbaby.com">Blog</a> | ||
* @since Nov 19,2017 | ||
*/ | ||
@Aspect | ||
public class SwipeInjection { | ||
|
||
//****************PointCut*********************************** | ||
|
||
/** | ||
* PointCut method.find all classes that is marked by | ||
* {@link com.jkb.fragment.swiper.annotation.Swiper} Annotation. | ||
*/ | ||
@Pointcut("@target(com.jkb.fragment.swiper.annotation.Swiper)") | ||
public void annotatedWithSwiper() { | ||
} | ||
|
||
/** | ||
* PointCut method.find all classes that is marked by | ||
* {@link com.jkb.fragment.rigger.annotation.Puppet} Annotation. | ||
*/ | ||
@Pointcut("@target(com.jkb.fragment.rigger.annotation.Puppet)") | ||
public void annotatedWithPuppet() { | ||
} | ||
|
||
//****************Helper************************************ && annotatedWithPuppet() && annotatedWithSwiper() | ||
|
||
@Pointcut("execution(* android.support.v4.app.FragmentActivity+.onCreate(..))") | ||
public void onCreate() { | ||
} | ||
|
||
@Pointcut("execution(* android.support.v4.app.FragmentActivity+.onDestroy(..))") | ||
public void onDestroy() { | ||
} | ||
|
||
//****************Process*********************************** | ||
|
||
@Around("onCreate()") | ||
public Object onCreateProcess(ProceedingJoinPoint joinPoint) throws Throwable { | ||
Object result = joinPoint.proceed(); | ||
Object puppet = joinPoint.getTarget(); | ||
//Only inject the class that marked by Puppet annotation. | ||
|
||
Method onCreate = invokeSwiperMethod("addToStack", Activity.class); | ||
onCreate.invoke(getSwiperInstance(), puppet); | ||
return result; | ||
} | ||
|
||
@Around("onDestroy()") | ||
public Object onDestroyProcess(ProceedingJoinPoint joinPoint) throws Throwable { | ||
Object result = joinPoint.proceed(); | ||
Object puppet = joinPoint.getTarget(); | ||
//Only inject the class that marked by Puppet annotation. | ||
|
||
Method onDestroy = invokeSwiperMethod("removeFromStack", Activity.class); | ||
onDestroy.invoke(getSwiperInstance(), puppet); | ||
return result; | ||
} | ||
|
||
/** | ||
* Returns the instance of SwiperActivityManager class by reflect. | ||
*/ | ||
Object getSwiperInstance() throws Exception { | ||
Class<?> riggerClazz = Class.forName("com.jkb.fragment.swiper.SwipeActivityManager"); | ||
Method getInstance = riggerClazz.getDeclaredMethod("getInstance"); | ||
getInstance.setAccessible(true); | ||
return getInstance.invoke(null); | ||
} | ||
|
||
/** | ||
* Returns the method object of SwiperActivityManager by reflect. | ||
*/ | ||
Method invokeSwiperMethod(String methodName, Class<?>... params) throws Exception { | ||
Object object = getSwiperInstance(); | ||
Class<?> clazz = object.getClass(); | ||
Method method = clazz.getDeclaredMethod(methodName, params); | ||
method.setAccessible(true); | ||
return method; | ||
} | ||
} |