Skip to content

Commit

Permalink
animation bugs fixed .
Browse files Browse the repository at this point in the history
ability to change animation durations.
indicator listener added.
pager change listener added.
  • Loading branch information
smarteist committed May 31, 2019
1 parent c139bb2 commit d83e60d
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 52 deletions.
22 changes: 18 additions & 4 deletions app/src/main/java/com/smarteist/imageslider/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.smarteist.imageslider;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;

import com.smarteist.autoimageslider.IndicatorAnimations;
import com.smarteist.autoimageslider.IndicatorView.draw.controller.DrawController;
import com.smarteist.autoimageslider.SliderAnimations;
import com.smarteist.autoimageslider.SliderView;

Expand All @@ -18,12 +22,22 @@ protected void onCreate(Bundle savedInstanceState) {

sliderView = findViewById(R.id.imageSlider);

sliderView.setSliderAdapter(new SliderAdapterExample(this));
final SliderAdapterExample adapter = new SliderAdapterExample(this);

sliderView.setSliderAdapter(adapter);

sliderView.setIndicatorAnimation(IndicatorAnimations.SWAP); //set indicator animation by using SliderLayout.IndicatorAnimations. :WORM or THIN_WORM or COLOR or DROP or FILL or NONE or SCALE or SCALE_DOWN or SLIDE and SWAP!!
sliderView.setSliderTransformAnimation(SliderAnimations.DEPTHTRANSFORMATION);
sliderView.setIndicatorAnimation(IndicatorAnimations.COLOR); //set indicator animation by using SliderLayout.IndicatorAnimations. :WORM or THIN_WORM or COLOR or DROP or FILL or NONE or SCALE or SCALE_DOWN or SLIDE and SWAP!!
sliderView.setSliderIndicatorSelectedColor(Color.WHITE);
sliderView.setSliderIndicatorUnselectedColor(Color.GRAY);
sliderView.setSliderTransformAnimation(SliderAnimations.CUBEOUTDEPTHTRANSFORMATION);
sliderView.setScrollTimeInSec(4); //set scroll delay in seconds :
sliderView.startAutoCycle();

sliderView.setOnIndicatorClickListener(new DrawController.ClickListener() {
@Override
public void onIndicatorClicked(int position) {
sliderView.setCurrentPagePosition(position);
}
});


}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.smarteist.imageslider;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.manager.RequestManagerRetriever;
import com.smarteist.autoimageslider.SliderViewAdapter;

public class SliderAdapterExample extends
Expand All @@ -27,28 +31,53 @@ public SliderAdapterVH onCreateViewHolder(ViewGroup parent) {

@Override
public void onBindViewHolder(SliderAdapterVH viewHolder, int position) {
viewHolder.textViewDescription.setText("This is slider item " + position);



switch (position) {
case 0:
viewHolder.textViewDescription.setText("This is slider item " + position);
viewHolder.textViewDescription.setTextSize(16);
viewHolder.textViewDescription.setTextColor(Color.WHITE);
viewHolder.imageGifContainer.setVisibility(View.GONE);
Glide.with(viewHolder.itemView)
.load("https://images.pexels.com/photos/218983/pexels-photo-218983.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260")
.fitCenter()
.into(viewHolder.imageViewBackground);
break;
case 1:
case 2:
viewHolder.textViewDescription.setText("This is slider item " + position);
viewHolder.textViewDescription.setTextSize(16);
viewHolder.textViewDescription.setTextColor(Color.WHITE);
viewHolder.imageGifContainer.setVisibility(View.GONE);
Glide.with(viewHolder.itemView)
.load("https://images.pexels.com/photos/747964/pexels-photo-747964.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260")
.fitCenter()
.into(viewHolder.imageViewBackground);
break;
case 2:
case 4:
viewHolder.textViewDescription.setText("This is slider item " + position);
viewHolder.textViewDescription.setTextSize(16);
viewHolder.textViewDescription.setTextColor(Color.WHITE);
viewHolder.imageGifContainer.setVisibility(View.GONE);
Glide.with(viewHolder.itemView)
.load("https://images.pexels.com/photos/929778/pexels-photo-929778.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260")
.fitCenter()
.into(viewHolder.imageViewBackground);
break;
default:
viewHolder.textViewDescription.setTextSize(29);
viewHolder.textViewDescription.setTextColor(Color.WHITE);
viewHolder.textViewDescription.setText("Ohhhh! look at this!");
viewHolder.imageGifContainer.setVisibility(View.VISIBLE);
Glide.with(viewHolder.itemView)
.load("https://images.pexels.com/photos/218983/pexels-photo-218983.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260")
.load(R.drawable.puma_offer)
.fitCenter()
.into(viewHolder.imageViewBackground);
Glide.with(viewHolder.itemView)
.asGif()
.load(R.drawable.oh_look_at_this)
.into(viewHolder.imageGifContainer);
break;

}
Expand All @@ -65,11 +94,13 @@ class SliderAdapterVH extends SliderViewAdapter.ViewHolder {

View itemView;
ImageView imageViewBackground;
ImageView imageGifContainer;
TextView textViewDescription;

public SliderAdapterVH(View itemView) {
super(itemView);
imageViewBackground = itemView.findViewById(R.id.iv_auto_image_slider);
imageGifContainer = itemView.findViewById(R.id.iv_gif_container);
textViewDescription = itemView.findViewById(R.id.tv_auto_image_slider);
this.itemView = itemView;
}
Expand Down
Binary file added app/src/main/res/drawable/oh_look_at_this.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/puma_offer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 12 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.smarteist.autoimageslider.SliderView
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="@+id/imageSlider"/>
android:layout_margin="16dp"
app:cardCornerRadius="8dp">


<com.smarteist.autoimageslider.SliderView
android:id="@+id/imageSlider"
android:layout_width="match_parent"
android:layout_height="300dp" />
</androidx.cardview.widget.CardView>

</android.widget.RelativeLayout>
16 changes: 13 additions & 3 deletions app/src/main/res/layout/image_slider_layout_item.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
Expand All @@ -8,7 +9,16 @@
android:id="@+id/iv_auto_image_slider"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
android:scaleType="fitXY" />


<ImageView
android:id="@+id/iv_gif_container"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="bottom|start"
android:layout_margin="50dp" />


<FrameLayout
android:id="@+id/fl_shadow_container"
Expand All @@ -20,10 +30,10 @@
android:id="@+id/tv_auto_image_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:textColor="#FFF"
android:layout_marginTop="8dp"
android:layout_marginBottom="25dp"
android:padding="6dp"
android:textColor="#FFF"
android:textSize="18sp" />

</FrameLayout>
Expand Down
10 changes: 3 additions & 7 deletions autoimageslider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ext {
siteUrl = 'https://github.com/smarteist'
gitUrl = 'https://github.com/smarteist/android-image-slider.git'

libraryVersion = '1.3.0'
libraryVersion = '1.3.1'
organization = 'smarteistbintray' // if you push to organization's repository.
developerId = 'smarteist'
developerName = 'Ali Hosseini'
Expand All @@ -33,8 +33,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 3
versionName "1.3"
versionCode 4
versionName "1.3.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand All @@ -58,10 +58,6 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

}

task copyLibs(type: Copy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ void setCurrentPageListener(CurrentPageListener currentPageListener) {
@Override
public void onPageSelected(final int position) {
this.mCurrentPosition = position;
this.currentPageListener.onCurrentPageChanged(mCurrentPosition);
if (this.currentPageListener != null) {
this.currentPageListener.onCurrentPageChanged(position);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.smarteist.autoimageslider;

import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.DecelerateInterpolator;
import android.widget.Scroller;
import androidx.viewpager.widget.ViewPager;
import java.lang.reflect.Field;

public class SliderPager extends ViewPager {

public static final int DEFAULT_SCROLL_DURATION = 250;

public SliderPager (Context context) {
super(context);
}

public SliderPager (Context context, AttributeSet attrs) {
super(context, attrs);
}

public void setScrollDuration(int millis) {
try {
Class<?> viewpager = ViewPager.class;
Field scroller = viewpager.getDeclaredField("mScroller");
scroller.setAccessible(true);
scroller.set(this, new OwnScroller(getContext(), millis));
} catch (Exception e) {
e.printStackTrace();
}
}

class OwnScroller extends Scroller {

private int durationScrollMillis;

OwnScroller(Context context, int durationScroll) {
super(context, new DecelerateInterpolator());
this.durationScrollMillis = durationScroll;
}

@Override
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
super.startScroll(startX, startY, dx, dy, durationScrollMillis);
}
}
}
Loading

0 comments on commit d83e60d

Please sign in to comment.