Skip to content

Commit

Permalink
add zoom level control from #23
Browse files Browse the repository at this point in the history
dependency upgrade
new version 1.3.0
  • Loading branch information
mig35 committed Jan 18, 2021
1 parent 0caf76e commit 69a8c62
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 191 deletions.
2 changes: 1 addition & 1 deletion CarouselLayoutManager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:4.1.1'
}
}

Expand Down
19 changes: 8 additions & 11 deletions CarouselLayoutManager/carousel/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0"
classpath "com.github.dcendents:android-maven-gradle-plugin:2.1"
classpath "com.github.dcendents:android-maven-plugin:1.2"
Expand All @@ -22,7 +22,7 @@ group = "com.azoft.carousellayoutmanager"
final def siteUrl = 'https://github.com/Azoft/CarouselLayoutManager'
final def gitUrl = "https://github.com/Azoft/CarouselLayoutManager.git"
// This is the library version used when deploying the artifact
version = "1.2.4"
version = "1.3.0"

final Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
Expand Down Expand Up @@ -76,14 +76,12 @@ install {
//////////////////////////////// Upload to BinTray ////////////////////////////////

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
buildToolsVersion '27.0.3'
compileSdkVersion 30
resourcePrefix "carousellayoutmanager__"

defaultConfig {
minSdkVersion 11
targetSdkVersion 27
targetSdkVersion 30
versionCode 1
versionName version
}
Expand All @@ -100,11 +98,10 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
def supportVersion = "27.1.1"

implementation "com.android.support:recyclerview-v7:$supportVersion"
javadocDeps "com.android.support:support-annotations:$supportVersion"
javadocDeps "com.android.support:recyclerview-v7:$supportVersion"
implementation 'androidx.recyclerview:recyclerview:1.1.0'
javadocDeps 'androidx.annotation:annotation:1.1.0'
javadocDeps 'androidx.recyclerview:recyclerview:1.1.0'
}

task sourcesJar(type: Jar) {
Expand All @@ -130,6 +127,6 @@ artifacts {
// Excluding aar artifacts from uploading
configurations.archives.artifacts.with { archives ->
for (def iter = archives.iterator(); iter.hasNext();) {
if (iter.next().file =~ 'aar') iter.remove();
if (iter.next().file =~ 'aar') iter.remove()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.azoft.carousellayoutmanager;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

public abstract class CarouselChildSelectionListener {
Expand Down Expand Up @@ -31,12 +31,12 @@ protected CarouselChildSelectionListener(@NonNull final RecyclerView recyclerVie

mRecyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
@Override
public void onChildViewAttachedToWindow(final View view) {
public void onChildViewAttachedToWindow(@NonNull final View view) {
view.setOnClickListener(mOnClickListener);
}

@Override
public void onChildViewDetachedFromWindow(final View view) {
public void onChildViewDetachedFromWindow(@NonNull final View view) {
view.setOnClickListener(null);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.LinearSmoothScroller;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.OrientationHelper;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

Expand All @@ -36,7 +36,6 @@
* So like layout_height is not {@link ViewGroup.LayoutParams#MATCH_PARENT} for {@link CarouselLayoutManager#VERTICAL}<br />
* <br />
*/
@SuppressWarnings({"ClassWithTooManyMethods", "OverlyComplexClass", "unused", "WeakerAccess"})
public class CarouselLayoutManager extends RecyclerView.LayoutManager implements RecyclerView.SmoothScroller.ScrollVectorProvider {

public static final int HORIZONTAL = OrientationHelper.HORIZONTAL;
Expand Down Expand Up @@ -312,7 +311,7 @@ protected int scrollBy(final int diff, @NonNull final RecyclerView.Recycler recy
}

@Override
public void onMeasure(final RecyclerView.Recycler recycler, final RecyclerView.State state, final int widthSpec, final int heightSpec) {
public void onMeasure(@NonNull final RecyclerView.Recycler recycler, @NonNull final RecyclerView.State state, final int widthSpec, final int heightSpec) {
mDecoratedChildSizeInvalid = true;

super.onMeasure(recycler, state, widthSpec, heightSpec);
Expand Down Expand Up @@ -672,12 +671,7 @@ protected int getOffsetForCurrentView(@NonNull final View view) {
final int targetPosition = getPosition(view);
final float directionDistance = getScrollDirection(targetPosition);

final int distance = Math.round(directionDistance * getScrollItemSize());
if (mCircleLayout) {
return distance;
} else {
return distance;
}
return Math.round(directionDistance * getScrollItemSize());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.azoft.carousellayoutmanager;

import android.graphics.PointF;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

/**
* Custom implementation of {@link android.support.v7.widget.RecyclerView.SmoothScroller} that can work only with {@link CarouselLayoutManager}.
* Custom implementation of {@link RecyclerView.SmoothScroller} that can work only with {@link CarouselLayoutManager}.
*
* @see CarouselLayoutManager
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.azoft.carousellayoutmanager;

import android.support.annotation.NonNull;
import androidx.annotation.NonNull;
import android.view.View;

/**
Expand All @@ -10,9 +10,19 @@
*/
public class CarouselZoomPostLayoutListener implements CarouselLayoutManager.PostLayoutListener {

private final float mScaleMultiplier;

public CarouselZoomPostLayoutListener() {
this(0.17f);
}

public CarouselZoomPostLayoutListener(final float scaleMultiplier) {
mScaleMultiplier = scaleMultiplier;
}

@Override
public ItemTransformation transformChild(@NonNull final View child, final float itemPositionToCenterDiff, final int orientation) {
final float scale = (float) (2 * (2 * -StrictMath.atan(Math.abs(itemPositionToCenterDiff) + 1.0) / Math.PI + 1));
final float scale = 1.0f - mScaleMultiplier * Math.abs(itemPositionToCenterDiff);

// because scaling will make view smaller in its center, then we should move this item to the top or bottom to make it visible
final float translateY;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.azoft.carousellayoutmanager;

import android.support.v7.widget.RecyclerView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
* Class for centering items after scroll event.<br />
Expand All @@ -11,7 +12,7 @@ public class CenterScrollListener extends RecyclerView.OnScrollListener {
private boolean mAutoSet = true;

@Override
public void onScrollStateChanged(final RecyclerView recyclerView, final int newState) {
public void onScrollStateChanged(@NonNull final RecyclerView recyclerView, final int newState) {
super.onScrollStateChanged(recyclerView, newState);
final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (!(layoutManager instanceof CarouselLayoutManager)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.azoft.carousellayoutmanager;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

public class DefaultChildSelectionListener extends CarouselChildSelectionListener {
Expand Down
4 changes: 3 additions & 1 deletion CarouselLayoutManager/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 18 08:55:54 NOVT 2018
#Mon Jan 18 09:06:02 NOVT 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
22 changes: 11 additions & 11 deletions CarouselLayoutManager/sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
apply plugin: 'com.android.application'
plugins {
id 'com.android.application'
}

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
compileSdkVersion 30

defaultConfig {
applicationId "com.azoft.carousellayoutmanager.sample"
minSdkVersion 14
targetSdkVersion 27
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
Expand All @@ -17,18 +18,17 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
buildFeatures {
viewBinding true
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
def supportVersion = "27.1.1"

implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
implementation "com.android.support:recyclerview-v7:$supportVersion"
implementation 'com.azoft.carousellayoutmanager:carousel:1.2.4'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.azoft.carousellayoutmanager:carousel:1.3.0'
// implementation project(':carousel')
}
8 changes: 5 additions & 3 deletions CarouselLayoutManager/sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.azoft.carousellayoutmanager.sample"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.azoft.carousellayoutmanager.sample">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="AllowBackup">

<activity
android:name=".CarouselPreviewActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.azoft.carousellayoutmanager.sample;

import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -22,13 +18,18 @@
import java.util.Locale;
import java.util.Random;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

public class CarouselPreviewActivity extends AppCompatActivity {

@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

final ActivityCarouselPreviewBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_carousel_preview);
final ActivityCarouselPreviewBinding binding = ActivityCarouselPreviewBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

setSupportActionBar(binding.toolbar);

Expand Down Expand Up @@ -74,7 +75,7 @@ public void onClick(final View v) {
private void initRecyclerView(final RecyclerView recyclerView, final CarouselLayoutManager layoutManager, final TestAdapter adapter) {
// enable zoom effect. this line can be customized
layoutManager.setPostLayoutListener(new CarouselZoomPostLayoutListener());
layoutManager.setMaxVisibleItems(2);
layoutManager.setMaxVisibleItems(3);

recyclerView.setLayoutManager(layoutManager);
// we expect only fixed sized item for now
Expand Down Expand Up @@ -110,18 +111,17 @@ public void onCenterItemChanged(final int adapterPosition) {

private static final class TestAdapter extends RecyclerView.Adapter<TestViewHolder> {

@SuppressWarnings("UnsecureRandomNumberGeneration")
private final Random mRandom = new Random();
private final int[] mColors;
private final int[] mPosition;
private int mItemsCount = 100;
private final int mItemsCount = 100;

TestAdapter() {
mColors = new int[mItemsCount];
mPosition = new int[mItemsCount];
for (int i = 0; mItemsCount > i; ++i) {
//noinspection MagicNumber
mColors[i] = Color.argb(255, mRandom.nextInt(256), mRandom.nextInt(256), mRandom.nextInt(256));
final Random random = new Random();
mColors[i] = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256));
mPosition[i] = i;
}
}
Expand Down
Loading

0 comments on commit 69a8c62

Please sign in to comment.