Skip to content

Commit

Permalink
Feature/blur effect (#1)
Browse files Browse the repository at this point in the history
* add blur effect

* remove unnecessery libs
  • Loading branch information
williaanlopes authored Dec 21, 2019
1 parent 27c3975 commit 4d952eb
Show file tree
Hide file tree
Showing 13 changed files with 698 additions and 36 deletions.
24 changes: 23 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ android {
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -17,13 +18,34 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

packagingOptions {//加上这些代码
pickFirst 'lib/armeabi-v7a/libRSSupport.so'
pickFirst 'lib/arm64-v8a/libRSSupport.so'
pickFirst 'lib/x86_64/libRSSupport.so'
pickFirst 'lib/x86/libRSSupport.so'
pickFirst 'lib/arm64-v8a/librsjni.so'
pickFirst 'lib/x86/librsjni.so'
pickFirst 'lib/x86_64/librsjni.so'
pickFirst 'lib/armeabi-v7a/librsjni.so'
pickFirst 'lib/x86_64/librsjni_androidx.so'
pickFirst 'lib/armeabi-v7a/librsjni_androidx.so'
pickFirst 'lib/x86/librsjni_androidx.so'
pickFirst 'lib/arm64-v8a/librsjni_androidx.so'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

implementation project(':library')

implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gurpster.slidingpanel">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:hardwareAccelerated="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/gurpster/slidingpanel/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.gurpster.slidingpanel;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatImageView;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.bumptech.glide.Glide;
import com.gurpster.library.SlidingPanelLayout;

public class MainActivity extends AppCompatActivity {

Expand All @@ -11,6 +17,22 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

SlidingPanelLayout slidingPanel = findViewById(R.id.sliding_layout);
slidingPanel.addPanelSlideListener(new SlidingPanelLayout.PanelSlideListener() {
@Override
public void onPanelSlide(View panel, float slideOffset, float inverseSlideOffset) {
Log.d("", inverseSlideOffset+"");
}

@Override
public void onPanelStateChanged(View panel, SlidingPanelLayout.PanelState previousState, SlidingPanelLayout.PanelState newState) {

}
});

AppCompatImageView imageView = findViewById(R.id.imageView);
Glide.with(this)
.load("https://biografieonline.it/img/bio/Scarlett_Johansson_3.jpg")
.into(imageView);
}
}
88 changes: 77 additions & 11 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<com.gurpster.library.SlidingPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
app:blurBackground="true"
app:initialState="collapsed"
app:shadowHeight="15dp"
app:panelHeight="68dp"
app:parallaxOffset="100dp"
app:dragView="@+id/dragView"
app:overlay="true"
app:scrollableView="@+id/list"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- MAIN CONTENT -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<androidx.appcompat.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>

</FrameLayout>

<!-- SLIDING LAYOUT -->
<LinearLayout
android:id="@+id/dragView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:clickable="true"
android:focusable="false"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal">

<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textSize="14sp" />

<Button
android:id="@+id/follow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical|right"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="14sp" />

</LinearLayout>

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>

</LinearLayout>
<!--/ SLIDING LAYOUT -->

</androidx.constraintlayout.widget.ConstraintLayout>
</com.gurpster.library.SlidingPanelLayout>
28 changes: 21 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
apply plugin: 'com.android.library'

repositories {
maven { url 'http://Manabu-GT.github.com/GlassView/mvn-repo' }
mavenCentral()
}

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"


defaultConfig {
minSdkVersion 15
targetSdkVersion 29
Expand All @@ -18,6 +12,10 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'

targetSdkVersion 29
renderscriptTargetApi 21
renderscriptSupportModeEnabled true
}

buildTypes {
Expand All @@ -27,6 +25,21 @@ android {
}
}

packagingOptions {//加上这些代码
pickFirst 'lib/armeabi-v7a/libRSSupport.so'
pickFirst 'lib/arm64-v8a/libRSSupport.so'
pickFirst 'lib/x86_64/libRSSupport.so'
pickFirst 'lib/x86/libRSSupport.so'
pickFirst 'lib/arm64-v8a/librsjni.so'
pickFirst 'lib/x86/librsjni.so'
pickFirst 'lib/x86_64/librsjni.so'
pickFirst 'lib/armeabi-v7a/librsjni.so'
pickFirst 'lib/x86_64/librsjni_androidx.so'
pickFirst 'lib/armeabi-v7a/librsjni_androidx.so'
pickFirst 'lib/x86/librsjni_androidx.so'
pickFirst 'lib/arm64-v8a/librsjni_androidx.so'
}

}

dependencies {
Expand All @@ -35,7 +48,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'

implementation 'com.ms.square:glassview:0.1.0'
implementation 'com.daimajia.easing:library:2.0@aar'
implementation 'com.daimajia.androidanimations:library:2.3@aar'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
Expand Down
50 changes: 38 additions & 12 deletions library/src/main/java/com/gurpster/library/SlidingPanelLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
Expand All @@ -25,10 +23,9 @@
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;

import androidx.core.view.MotionEventCompat;
import androidx.core.view.ViewCompat;

import com.ms.square.android.glassview.GlassView;
import com.gurpster.library.blur.GlassView;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
Expand Down Expand Up @@ -230,6 +227,7 @@ public enum PanelState {
* range [0, 1] where 0 = collapsed, 1 = expanded.
*/
private float mSlideOffset;
private float mReverseSlideOffset;

/**
* How far in pixels the slideable panel may move.
Expand All @@ -254,7 +252,7 @@ public enum PanelState {

private float mPrevMotionX;
private float mPrevMotionY;
// private float mPrevMotionLocation;
// private float mPrevMotionLocation;
private float mInitialMotionX;
private float mInitialMotionY;
private boolean mIsScrollableViewHandlingTouch = false;
Expand All @@ -264,6 +262,7 @@ public enum PanelState {

private final ViewDragHelper mDragHelper;

// private ViewGroup mRootBlurView;
private GlassView mBlurView;

/**
Expand Down Expand Up @@ -334,7 +333,6 @@ public SlidingPanelLayout(Context context, AttributeSet attrs, int defStyle) {
setGravity(gravity);
defAttrs.recycle();


TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingPanelLayout);

mPanelHeight = ta.getDimensionPixelSize(R.styleable.SlidingPanelLayout_panelHeight, -1);
Expand Down Expand Up @@ -746,8 +744,7 @@ public boolean isClipPanel() {
void dispatchOnPanelSlide(View panel) {
synchronized (mPanelSlideListeners) {
for (PanelSlideListener l : mPanelSlideListeners) {
float mInverseSlideOffset = (mSlideOffset);
l.onPanelSlide(panel, mSlideOffset, mInverseSlideOffset);
l.onPanelSlide(panel, mSlideOffset, mReverseSlideOffset);
}
}
}
Expand Down Expand Up @@ -1194,6 +1191,17 @@ private float computeSlideOffset(int topPosition) {
: (float) (topPosition - topBoundCollapsed) / mSlideRange);
}

private float computeReverseSlideOffset(int topPosition) {
// Compute the panel top position if the panel is collapsed (offset 0)
final int topBoundCollapsed = computePanelTopPosition(0);

// Determine the new slide offset based on the collapsed top position and the new required
// top position
return (mIsSlidingUp
? (float) (topPosition - topBoundCollapsed) / mSlideRange
: (float) (topBoundCollapsed - topPosition) / mSlideRange);
}

/**
* Returns the current state of the panel as an enum.
*
Expand All @@ -1211,7 +1219,7 @@ public PanelState getPanelState() {
public void setPanelState(PanelState state) {

// Abort any running animation, to allow state change
if(mDragHelper.getViewDragState() == ViewDragHelper.STATE_SETTLING){
if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_SETTLING) {
// Log.d(TAG, "View is settling. Aborting animation.");
mDragHelper.abort();
}
Expand Down Expand Up @@ -1302,7 +1310,7 @@ private void setPanelStateInternal(PanelState state) {
private void applyParallaxForCurrentSlideOffset() {
if (mParallaxOffset > 0) {
int mainViewOffset = getCurrentParallaxOffset();
ViewCompat.setTranslationY(mMainView, mainViewOffset);
mMainView.setTranslationY(mainViewOffset);
}
}

Expand Down Expand Up @@ -1366,10 +1374,28 @@ protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
}

if (mBlurBackground && mSlideOffset > 0) {
mBlurView.setVisibility(View.VISIBLE);
// if (mBlurView.getVisibility() != View.VISIBLE) {
// mBlurView.setVisibility(View.VISIBLE);
// YoYo.with(Techniques.FadeIn)
// .duration(150)
// .playOn(mBlurView);
// }
mBlurView.setAlpha(mSlideOffset * 5);
mBlurView.setBlurRadius(mSlideOffset * 25);
} else if (mBlurView != null) {
mBlurView.setVisibility(View.INVISIBLE);
mBlurView.setAlpha(mSlideOffset * 5);
// if (mBlurView.getVisibility() == View.VISIBLE) {
// mBlurView.setVisibility(View.VISIBLE);
// YoYo.with(Techniques.FadeOut)
// .duration(150)
// .onEnd(new YoYo.AnimatorCallback() {
// @Override
// public void call(Animator animator) {
// mBlurView.setVisibility(View.INVISIBLE);
// }
// })
// .playOn(mBlurView);
// }
}
} else {
result = super.drawChild(canvas, child, drawingTime);
Expand Down
Loading

0 comments on commit 4d952eb

Please sign in to comment.