From d498795a4cfeb3c93f4034e1b982bdd0a2fafc1f Mon Sep 17 00:00:00 2001 From: daimajia Date: Fri, 20 Jun 2014 16:17:34 +0800 Subject: [PATCH] add setScaleType method --- .../daimajia/slider/demo/MainActivity.java | 1 + gradle.properties | 4 +-- library/build.gradle | 4 +-- .../library/SliderTypes/BaseSliderView.java | 33 ++++++++++++++++++- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/demo/src/main/java/com/daimajia/slider/demo/MainActivity.java b/demo/src/main/java/com/daimajia/slider/demo/MainActivity.java index 08e4724..c150044 100644 --- a/demo/src/main/java/com/daimajia/slider/demo/MainActivity.java +++ b/demo/src/main/java/com/daimajia/slider/demo/MainActivity.java @@ -50,6 +50,7 @@ protected void onCreate(Bundle savedInstanceState) { textSliderView .description(name) .image(file_maps.get(name)) + .setScaleType(BaseSliderView.ScaleType.Fit) .setOnSliderClickListener(this); //add your extra information diff --git a/gradle.properties b/gradle.properties index b8616c3..61f72a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,8 +18,8 @@ # org.gradle.parallel=true -VERSION_NAME=1.0.6 -VERSION_CODE=7 +VERSION_NAME=1.0.7 +VERSION_CODE=8 GROUP=com.daimajia.slider POM_DESCRIPTION=An amazing and convenient Android image slider. diff --git a/library/build.gradle b/library/build.gradle index 737b066..ca1b164 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 7 - versionName "1.0.6" + versionCode 8 + versionName "1.0.7" } buildTypes { release { diff --git a/library/src/main/java/com/daimajia/slider/library/SliderTypes/BaseSliderView.java b/library/src/main/java/com/daimajia/slider/library/SliderTypes/BaseSliderView.java index 1ec2dde..b3feb6d 100644 --- a/library/src/main/java/com/daimajia/slider/library/SliderTypes/BaseSliderView.java +++ b/library/src/main/java/com/daimajia/slider/library/SliderTypes/BaseSliderView.java @@ -47,6 +47,15 @@ public abstract class BaseSliderView { private String mDescription; + /** + * Scale type of the image. + */ + private ScaleType mScaleType = ScaleType.Fit; + + public enum ScaleType{ + CenterCrop, CenterInside, Fit, FitCenterCrop + } + protected BaseSliderView(Context context) { mContext = context; this.mBundle = new Bundle(); @@ -195,7 +204,18 @@ protected void loadImage(ImageView targetImageView){ if(getError() != 0){ rq.error(getError()); } - rq.fit(); + + switch (mScaleType){ + case Fit: + rq.fit(); + break; + case CenterCrop: + rq.fit().centerCrop(); + break; + case CenterInside: + rq.fit().centerInside(); + break; + } rq.into(targetImageView,new Callback() { @Override @@ -213,6 +233,17 @@ public void onError() { }); } + + + public BaseSliderView setScaleType(ScaleType type){ + mScaleType = type; + return this; + } + + public ScaleType getScaleType(){ + return mScaleType; + } + private View progressBar = null; /** * when you want to extends this class, you must call this method to bind click event to your view.