Skip to content

Commit

Permalink
更新部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Xxj-star committed Aug 18, 2019
1 parent beb7bef commit fc2ef73
Show file tree
Hide file tree
Showing 8 changed files with 450 additions and 15 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ dependencies {
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':permissionlib')
implementation 'pub.devrel:easypermissions:1.2.0'
implementation 'com.android.support:recyclerview-v7:29.0.0'
//动画
implementation 'com.facebook.rebound:rebound:0.3.8'
}
34 changes: 21 additions & 13 deletions app/src/main/java/com/skl/permissiontool/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@
import android.Manifest;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.skl.permissionlib.PermissionUtil;
import com.skl.permissionlib.PermissionsInterface;
import com.skl.permissiontool.springyanimator.SpringAnimationType;
import com.skl.permissiontool.springyanimator.SpringyAnimator;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


//可以传数组,还可以传单个多个
String[] array = new String[]{
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.READ_PHONE_STATE};

/**
* @param savedInstanceState
*/
Expand All @@ -22,18 +30,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//可以传数组,还可以传单个多个
String[] array = new String[]{
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.READ_PHONE_STATE};

//可以传list集合
List<String> list = new ArrayList<>();
list.add(Manifest.permission.ACCESS_COARSE_LOCATION);
list.add(Manifest.permission.ACCESS_COARSE_LOCATION);
list.add(Manifest.permission.ACCESS_COARSE_LOCATION);
}

public void helloClick(View view) {
PermissionUtil.builder(this).addPermissions(array).addPerName("定位").execute(new PermissionsInterface() {
@Override
public void allAgree() {
Expand All @@ -60,6 +59,15 @@ public void refusAndNotPrompt(String permission) {
Log.e("yyy", "-----------被拒绝且选择了不再提示的权限---------->" + permission);
}
});
}

/**
* 点击缩放动画
*/
public static void animateView(View view) {
SpringyAnimator springHelper = new SpringyAnimator(SpringAnimationType.SCALEXY, 500, 4, 0, 1);
springHelper.startSpring(view);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.skl.permissiontool.springyanimator;

/**
* Created by salman on 21/11/16.
*/

public enum SpringAnimationType {
TRANSLATEX,
TRANSLATEY,
ROTATEX,
ROTATEY,
SCALEXY,
SCALEX,
SCALEY,
ALPHA,
ROTATION
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.skl.permissiontool.springyanimator;

/**
* Created by Zach on 7/1/2017.
*/

public enum SpringyAdapterAnimationType {
SLIDE_FROM_BOTTOM,
SLIDE_FROM_RIGHT,
SLIDE_FROM_LEFT,
SCALE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package com.skl.permissiontool.springyanimator;


import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.facebook.rebound.SimpleSpringListener;
import com.facebook.rebound.Spring;
import com.facebook.rebound.SpringConfig;
import com.facebook.rebound.SpringSystem;
import com.facebook.rebound.SpringUtil;


/**
* Created by Zach on 6/30/2017.
*/

public class SpringyAdapterAnimator {

private static final int INIT_DELAY = 100;

private static final int INIT_TENSION = 200;
private static final int INIT_FRICTION = 20;

private int tension;
private int fraction ;


private static final int PER_ITEM_GAPE = 100;

private int parentHeight;
private int parentWidth;
private RecyclerView parent;
private SpringSystem mSpringSystem;
private SpringyAdapterAnimationType animationType;
private boolean mFirstViewInit = true;
private int mLastPosition = -1;
private int mStartDelay;

public SpringyAdapterAnimator(RecyclerView recyclerView) {
parent = recyclerView;
mSpringSystem = SpringSystem.create();
animationType = SpringyAdapterAnimationType.SLIDE_FROM_BOTTOM;
parentHeight = parent.getResources().getDisplayMetrics().heightPixels;
parentWidth = parent.getResources().getDisplayMetrics().widthPixels;
mStartDelay = INIT_DELAY;
tension = INIT_TENSION;
fraction= INIT_FRICTION;
}
/*
* setInitDelay @param initDelay for set delay at screen creation
* */
public void setInitDelay(int initDelay){
mStartDelay = initDelay;
}

public void setSpringAnimationType(SpringyAdapterAnimationType type){
animationType = type;
}


public void addConfig(int tension,int fraction){
this.tension = tension;
this.fraction = fraction;
}

/**
* onSpringyItemCreate call in Adapter's Constructor method
* @param item itemView instance from RecyclerView's OnCreateView method
* **/
public void onSpringItemCreate(View item) {

if (mFirstViewInit) {
setAnimation(item, mStartDelay, tension, fraction);
mStartDelay += PER_ITEM_GAPE;
}
}


/**
* * onSpringyItemBind call in RecyclerView's onBind for scroll effects
* @param item itemView instance from RecyclerView's onBind method
* @param position from RecyclerView's onBind method
* **/
public void onSpringItemBind(View item, int position) {

if (!mFirstViewInit && position > mLastPosition) {
setAnimation(item, 0, tension - tension/4, fraction);
mLastPosition = position;
}
}


private void setAnimation(final View item, final int delay,
final int tension, final int friction) {
setInitValue(item);
Runnable startAnimation = new Runnable() {
@Override
public void run() {
SpringConfig config = new SpringConfig(tension, friction);
Spring spring = mSpringSystem.createSpring();
spring.setSpringConfig(config);
spring.addListener(new SimpleSpringListener() {
@Override
public void onSpringUpdate(Spring spring) {
switch (animationType) {
case SLIDE_FROM_BOTTOM:
item.setTranslationY(getMappedValue(spring));
break;
case SLIDE_FROM_LEFT:
item.setTranslationX(getMappedValue(spring));
break;
case SLIDE_FROM_RIGHT:
item.setTranslationX(getMappedValue(spring));
break;
case SCALE:
item.setScaleX(getMappedValue(spring));
item.setScaleY(getMappedValue(spring));
break;
}

}

@Override
public void onSpringEndStateChange(Spring spring) {
mFirstViewInit = false;
}
});
spring.setEndValue(1);

}
};

parent.postDelayed(startAnimation, delay);
}

private void setInitValue(View item) {

switch (animationType) {
case SLIDE_FROM_BOTTOM:
item.setTranslationY(parentHeight);
break;
case SLIDE_FROM_LEFT:
item.setTranslationX(-parentWidth);
break;
case SLIDE_FROM_RIGHT:
item.setTranslationX(parentWidth);
break;
case SCALE:
item.setScaleX(0);
item.setScaleY(0);
break;
default:
item.setTranslationY(parentHeight);
break;
}
}

private float getMappedValue(Spring spring) {

float value;
switch (animationType) {
case SLIDE_FROM_BOTTOM:
value = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, parentHeight, 0);
break;
case SLIDE_FROM_LEFT:
value = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, -parentWidth, 0);
break;
case SLIDE_FROM_RIGHT:
value = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, parentWidth, 0);
break;
case SCALE:
value = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 0, 1);
break;
default:
value = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, parentHeight, 0);
break;
}
return value;
}

}
Loading

0 comments on commit fc2ef73

Please sign in to comment.