Skip to content

Commit

Permalink
🚧 Add shadow and scrim for SwipeLayout.
Browse files Browse the repository at this point in the history
  • Loading branch information
JingYeoh committed Aug 2, 2018
1 parent de767e9 commit ed57713
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility rootProject.ext.android.targetCompatibilityVersion
targetCompatibility rootProject.ext.android.targetCompatibilityVersion
}

signingConfigs {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/yj/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class MainActivity extends BaseActivity {
@Override
protected void init(Bundle savedInstanceState) {
Rigger.enableDebugLogging(true);
Rigger.getRigger(this).getSwipeLayout().setShadowDrawable(new int[]{
R.drawable.swiper_shadow_left, R.drawable.swiper_shadow_right,
R.drawable.swiper_shadow_top, R.drawable.swiper_shadow_bottom
});
if (savedInstanceState == null) {
Rigger.getRigger(this).startFragment(TestFragment.newInstance());
}
Expand Down
14 changes: 11 additions & 3 deletions app/src/main/java/com/yj/app/test/start/StartFragment.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.yj.app.test.start;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.jkb.fragment.rigger.annotation.Animator;
import com.jkb.fragment.rigger.annotation.Puppet;
import com.jkb.fragment.rigger.rigger.Rigger;
import com.jkb.fragment.swiper.annotation.SwipeEdge;
import com.jkb.fragment.swiper.annotation.Swiper;
import com.yj.app.R;
import com.yj.app.base.BaseFragment;

import java.util.UUID;

/**
Expand All @@ -24,7 +23,7 @@
* <a href="http://blog.justkiddingbaby.com">Blog</a>
* @since Nov 21,2017
*/
@Swiper(edgeSide = {SwipeEdge.LEFT, SwipeEdge.RIGHT})
@Swiper(edgeSide = SwipeEdge.ALL)
@Animator(enter = R.anim.push_left_in_no_alpha, exit = R.anim.push_right_out_no_alpha,
popEnter = R.anim.push_right_in_no_alpha, popExit = R.anim.push_left_out_no_alpha)
@Puppet(containerViewId = R.id.firstContent)
Expand All @@ -38,6 +37,15 @@ public static StartFragment newInstance(int count) {
return fragment;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Rigger.getRigger(this).getSwipeLayout().setShadowDrawable(new int[]{
R.drawable.swiper_shadow_left, R.drawable.swiper_shadow_right,
R.drawable.swiper_shadow_top, R.drawable.swiper_shadow_bottom
});
}

//data
private int mCount;

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/swiper_shadow_bottom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="225"
android:endColor="@android:color/transparent"
android:startColor="@android:color/black"/>
</shape>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/swiper_shadow_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="@android:color/black"
android:startColor="@android:color/transparent"/>
</shape>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/swiper_shadow_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="@android:color/black"
android:endColor="@android:color/transparent"/>
</shape>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/swiper_shadow_top.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:endColor="@android:color/transparent"
android:startColor="@android:color/black"/>
</shape>
4 changes: 2 additions & 2 deletions rigger/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
sourceCompatibility rootProject.ext.android.targetCompatibilityVersion
targetCompatibility rootProject.ext.android.targetCompatibilityVersion
}

buildTypes {
Expand Down
24 changes: 14 additions & 10 deletions rigger/src/main/java/com/jkb/fragment/rigger/rigger/_Rigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import com.jkb.fragment.rigger.exception.UnSupportException;
import com.jkb.fragment.rigger.helper.FragmentStackManager;
import com.jkb.fragment.rigger.utils.Logger;
import com.jkb.fragment.swiper.annotation.Swiper;
import com.jkb.fragment.swiper.SwipeLayout;
import com.jkb.fragment.swiper.annotation.Swiper;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -62,7 +62,7 @@ static _Rigger create(@NonNull Object object) {
return new _FragmentRigger((Fragment) object);
} else {
throw new RiggerException(
"Puppet Annotation class can only used on android.app.Activity or android.support.v4.app.Fragment");
"Puppet Annotation class can only used on android.app.Activity or android.support.v4.app.Fragment");
}
}

Expand Down Expand Up @@ -160,7 +160,7 @@ void onCreate(Bundle savedInstanceState) {
* @return Return the View for the fragment's UI, or null.
*/
View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState, @Nullable View view) {
@Nullable Bundle savedInstanceState, @Nullable View view) {
return view;
}

Expand Down Expand Up @@ -329,7 +329,7 @@ public void startFragment(@NonNull Fragment fragment) {
}
if (getContainerViewId() <= 0) {
throwException(
new UnSupportException("ContainerViewId must be effective in class " + mPuppetTarget.getClass()));
new UnSupportException("ContainerViewId must be effective in class " + mPuppetTarget.getClass()));
}
addFragmentWithAnim(fragment, mContainerViewId);
mRiggerTransaction.hide(getVisibleFragmentTags(getContainerViewId()));
Expand Down Expand Up @@ -428,7 +428,7 @@ public void hideFragment(@NonNull Fragment fragment) {
String fragmentTAG = rigger.getFragmentTAG();
mRiggerTransaction.setCustomAnimations(rigger.mPopEnterAnim, rigger.mExitAnim);
mRiggerTransaction.hide(fragmentTAG)
.commit();
.commit();
}

@Override
Expand All @@ -444,8 +444,8 @@ public void replaceFragment(@NonNull Fragment fragment, @IdRes int containerView
String fragmentTAG = Rigger.getRigger(fragment).getFragmentTAG();
addFragmentWithAnim(fragment, containerViewId);
mRiggerTransaction.remove(mStackManager.getFragmentTags(containerViewId))
.show(fragmentTAG)
.commit();
.show(fragmentTAG)
.commit();
mStackManager.remove(containerViewId);
mStackManager.add(fragmentTAG, containerViewId);
}
Expand Down Expand Up @@ -573,7 +573,7 @@ private String[] getVisibleFragmentTags(@IdRes int containerViewId) {
for (String tag : fragmentTags) {
Fragment fragment = mRiggerTransaction.find(tag);
if (fragment != null && !fragment.isHidden() &&
fragment.getView() != null && fragment.getView().getVisibility() == View.VISIBLE) {
fragment.getView() != null && fragment.getView().getVisibility() == View.VISIBLE) {
result.add(tag);
}
}
Expand All @@ -590,6 +590,10 @@ SwipeLayout buildSwipeLayout() {
mSwipeLayout.setParallaxOffset(mSwiper.parallaxOffset());
mSwipeLayout.setSwipeEdgeSide(mSwiper.edgeSide());
mSwipeLayout.setStickyWithHost(mStickyStack);
mSwipeLayout.setScrimColor(mSwiper.scrimColor());
mSwipeLayout.setScrimMaxAlpha(mSwiper.scrimMaxAlpha());
mSwipeLayout.setShadowDrawable(mSwiper.shadowDrawable());
mSwipeLayout.setShadowWidth(mSwiper.shadowWidth());

LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
mSwipeLayout.setLayoutParams(params);
Expand All @@ -615,8 +619,8 @@ void setHWLayerAnimListenerIfAlpha(View v, Animation anim) {

static boolean shouldRunOnHWLayer(View v, Animation anim) {
return v.getLayerType() == View.LAYER_TYPE_NONE
&& ViewCompat.hasOverlappingRendering(v)
&& modifiesAlpha(anim);
&& ViewCompat.hasOverlappingRendering(v)
&& modifiesAlpha(anim);
}

private static boolean modifiesAlpha(Animation anim) {
Expand Down
Loading

0 comments on commit ed57713

Please sign in to comment.