From 7daa8db5f6cf87a1ffbbd0d182c6772b4e9797ef Mon Sep 17 00:00:00 2001 From: "Mwaura E.N" Date: Tue, 18 Feb 2020 14:15:46 +0300 Subject: [PATCH 1/5] Initial Update Of the README.MD file to accomodate for kotlin --- README.md | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 82991fd..1776c1b 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,23 @@ A simple yet flexible library to add carousel view in your android application. Download + +Downloading and configuring the Carousel View Does Not Vary whether you are using kotlin or Java as +your primary programming language -------- -### Gradle: +### Gradle: Configure CarouselView for Gradle + +add below dependency in the app-level build.gradle file ```groovy compile 'com.synnapps:carouselview:0.1.5' ``` -### Maven: +if your gradle plugin complains with a warning like +Configuration 'compile' is obsolete and has been replaced with 'implementation', replace the compile + word with implementations as indicated below + ```groovy + implementation 'com.synnapps:carouselview:0.1.5' + ``` +### Maven: Configure CarouselView for Maven ```xml com.synnapps @@ -29,6 +40,9 @@ compile 'com.synnapps:carouselview:0.1.5' Usage -------- +Whether you are using Java Or kotlin as your primary language, the layout implementation does not +change + ### Include following code in your layout: ```xml @@ -44,6 +58,9 @@ Usage app:strokeWidth="1dp"/> ``` ### Include following code in your activity: + +###Java + ```java public class SampleCarouselViewActivity extends AppCompatActivity { @@ -71,6 +88,26 @@ public class SampleCarouselViewActivity extends AppCompatActivity { } ``` +###Kotlin +```kotlin + +class MainActivity : AppCompatActivity() { + + private lateinit var carouselView: CarouselView + private var sampleImages = intArrayOf(R.drawable.image_1, R.drawable.image_2, R.drawable + .image_3, R.drawable.image_4, R.drawable.image_5) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + carouselView = (CarouselView) findViewById(R.id.carouselView) + carouselView.setPageCount(sampleImages.length) + + carouselView.setImageListener(imageListener) +} + } +``` ### If you want to add custom view, implement ```ViewListener```. ```java From ef06f69c3f125fd6e111bf9f5b44651d61c277c9 Mon Sep 17 00:00:00 2001 From: "Mwaura E.N" Date: Tue, 18 Feb 2020 14:36:14 +0300 Subject: [PATCH 2/5] Initial Update Of the README.MD file to accomodate for kotlin --- README.md | 115 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 1776c1b..8c8896a 100644 --- a/README.md +++ b/README.md @@ -11,23 +11,15 @@ A simple yet flexible library to add carousel view in your android application. Download - -Downloading and configuring the Carousel View Does Not Vary whether you are using kotlin or Java as -your primary programming language -------- -### Gradle: Configure CarouselView for Gradle +Downloading and configuring the CarouselView does not vary whether you are using kotlin or Java as +your primary programming language -add below dependency in the app-level build.gradle file +### Gradle: ```groovy compile 'com.synnapps:carouselview:0.1.5' ``` -if your gradle plugin complains with a warning like -Configuration 'compile' is obsolete and has been replaced with 'implementation', replace the compile - word with implementations as indicated below - ```groovy - implementation 'com.synnapps:carouselview:0.1.5' - ``` -### Maven: Configure CarouselView for Maven +### Maven: ```xml com.synnapps @@ -40,11 +32,10 @@ Configuration 'compile' is obsolete and has been replaced with 'implementation', Usage -------- -Whether you are using Java Or kotlin as your primary language, the layout implementation does not -change - ### Include following code in your layout: +The layout implementation is same regardless of whether you are using Java Or kotlin + ```xml ``` -### Include following code in your activity: -###Java +Java +-------- +### Include following code in your activity: ```java public class SampleCarouselViewActivity extends AppCompatActivity { @@ -88,26 +80,6 @@ public class SampleCarouselViewActivity extends AppCompatActivity { } ``` -###Kotlin -```kotlin - -class MainActivity : AppCompatActivity() { - - private lateinit var carouselView: CarouselView - private var sampleImages = intArrayOf(R.drawable.image_1, R.drawable.image_2, R.drawable - .image_3, R.drawable.image_4, R.drawable.image_5) - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - - carouselView = (CarouselView) findViewById(R.id.carouselView) - carouselView.setPageCount(sampleImages.length) - - carouselView.setImageListener(imageListener) -} - } -``` ### If you want to add custom view, implement ```ViewListener```. ```java @@ -152,6 +124,75 @@ customCarouselView.setImageClickListener(new ImageClickListener() { }); ``` +Kotlin +-------- + +### Include following code in your activity: + +```kotlin +class MainActivity : AppCompatActivity() { + + private lateinit var carouselView: CarouselView + private var sampleImages = intArrayOf( + R.drawable.image_1, R.drawable.image_2, R.drawable + .image_3, R.drawable.image_4, R.drawable.image_5 + ) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + carouselView = (CarouselView) findViewById (R.id.carouselView) + carouselView.setPageCount(sampleImages.length) + + carouselView.setImageListener(imageListener) + } +} + +``` + +### If you want to add custom view, implement ```ViewListener```. +```kotlin + +class SampleCarouselViewActivity : AppCompatActivity() { + internal var customCarouselView: CarouselView + internal var NUMBER_OF_PAGES = 5 + internal var viewListener: ViewListener = object : ViewListener() { + fun setViewForPosition(position: Int): View { + val customView = getLayoutInflater().inflate(R.layout.view_custom, null) + //set view attributes here + + return customView + } + } + + protected fun onCreate(savedInstanceState: Bundle) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_sample_carousel_view) + customCarouselView = findViewById(R.id.customCarouselView) as CarouselView + customCarouselView.setPageCount(NUMBER_OF_PAGES) + // set ViewListener for custom view + customCarouselView.setViewListener(viewListener) + } +} + +``` + +### If you'd like to receive touch events for each image + +```kotlin +customCarouselView.setImageClickListener(object : ImageClickListener() { + fun onClick(position: Int) { + Toast.makeText( + this@SampleCarouselViewActivity, + "Clicked item: " + position, + Toast.LENGTH_SHORT + ).show() + } + }) + +``` + ### If using ProGuard add this line to your proguard-rules.pro: ``` From 89599cde25a7e3dab4395697a8dfc2fd82c91a0f Mon Sep 17 00:00:00 2001 From: "Mwaura E.N" Date: Tue, 18 Feb 2020 14:46:08 +0300 Subject: [PATCH 3/5] Second Update Of the README.MD file to accomodate for kotlin --- README.md | 83 +++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 8c8896a..6c38787 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Usage ### Include following code in your layout: -The layout implementation is same regardless of whether you are using Java Or kotlin +The layout is same regardless of whether you are using Java Or kotlin ```xml ``` -Java --------- - ### Include following code in your activity: + +####Java Implementation ```java public class SampleCarouselViewActivity extends AppCompatActivity { @@ -81,7 +80,32 @@ public class SampleCarouselViewActivity extends AppCompatActivity { } ``` +####Kotlin Implementation +```kotlin +class MainActivity : AppCompatActivity() { + + private lateinit var carouselView: CarouselView + private var sampleImages = intArrayOf( + R.drawable.image_1, R.drawable.image_2, R.drawable + .image_3, R.drawable.image_4, R.drawable.image_5 + ) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + carouselView = (CarouselView) findViewById (R.id.carouselView) + carouselView.setPageCount(sampleImages.length) + + carouselView.setImageListener(imageListener) + } +} + +``` + ### If you want to add custom view, implement ```ViewListener```. + +####Java Implementation ```java public class SampleCarouselViewActivity extends AppCompatActivity { @@ -110,48 +134,10 @@ public class SampleCarouselViewActivity extends AppCompatActivity { return customView; } }; - -``` - -### If you'd like to receive touch events for each image - -```java -customCarouselView.setImageClickListener(new ImageClickListener() { - @Override - public void onClick(int position) { - Toast.makeText(SampleCarouselViewActivity.this, "Clicked item: "+ position, Toast.LENGTH_SHORT).show(); - } - }); -``` - -Kotlin --------- - -### Include following code in your activity: - -```kotlin -class MainActivity : AppCompatActivity() { - - private lateinit var carouselView: CarouselView - private var sampleImages = intArrayOf( - R.drawable.image_1, R.drawable.image_2, R.drawable - .image_3, R.drawable.image_4, R.drawable.image_5 - ) - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - - carouselView = (CarouselView) findViewById (R.id.carouselView) - carouselView.setPageCount(sampleImages.length) - - carouselView.setImageListener(imageListener) - } } - ``` -### If you want to add custom view, implement ```ViewListener```. +####Kotlin Implementation ```kotlin class SampleCarouselViewActivity : AppCompatActivity() { @@ -180,6 +166,17 @@ class SampleCarouselViewActivity : AppCompatActivity() { ### If you'd like to receive touch events for each image +####Java Implementation +```java +customCarouselView.setImageClickListener(new ImageClickListener() { + @Override + public void onClick(int position) { + Toast.makeText(SampleCarouselViewActivity.this, "Clicked item: "+ position, Toast.LENGTH_SHORT).show(); + } + }); +``` + +####Kotlin Implementation ```kotlin customCarouselView.setImageClickListener(object : ImageClickListener() { fun onClick(position: Int) { From 8c30016ff560eb8073c220dc0bdac5ab508b8b7f Mon Sep 17 00:00:00 2001 From: "Mwaura E.N" Date: Tue, 18 Feb 2020 14:58:11 +0300 Subject: [PATCH 4/5] Commit After Renaming Branch --- README.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6c38787..7d86038 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ The layout is same regardless of whether you are using Java Or kotlin ### Include following code in your activity: -####Java Implementation +**Java** ```java public class SampleCarouselViewActivity extends AppCompatActivity { @@ -79,8 +79,7 @@ public class SampleCarouselViewActivity extends AppCompatActivity { } ``` - -####Kotlin Implementation +**Kotlin ** ```kotlin class MainActivity : AppCompatActivity() { @@ -105,7 +104,7 @@ class MainActivity : AppCompatActivity() { ### If you want to add custom view, implement ```ViewListener```. -####Java Implementation +**Java ** ```java public class SampleCarouselViewActivity extends AppCompatActivity { @@ -136,8 +135,7 @@ public class SampleCarouselViewActivity extends AppCompatActivity { }; } ``` - -####Kotlin Implementation +**Kotlin ** ```kotlin class SampleCarouselViewActivity : AppCompatActivity() { @@ -166,7 +164,7 @@ class SampleCarouselViewActivity : AppCompatActivity() { ### If you'd like to receive touch events for each image -####Java Implementation +**Java ** ```java customCarouselView.setImageClickListener(new ImageClickListener() { @Override @@ -175,8 +173,7 @@ customCarouselView.setImageClickListener(new ImageClickListener() { } }); ``` - -####Kotlin Implementation +**Kotlin ** ```kotlin customCarouselView.setImageClickListener(object : ImageClickListener() { fun onClick(position: Int) { From 90019dcc1e92afdefdcf47bd7a07542470b4ece0 Mon Sep 17 00:00:00 2001 From: "Mwaura E.N" Date: Tue, 18 Feb 2020 15:06:25 +0300 Subject: [PATCH 5/5] Commit After Doing Some Changes to the Doccumentation --- README.md | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7d86038..e3da984 100644 --- a/README.md +++ b/README.md @@ -78,12 +78,14 @@ public class SampleCarouselViewActivity extends AppCompatActivity { }; } + ``` -**Kotlin ** +**Kotlin** ```kotlin class MainActivity : AppCompatActivity() { private lateinit var carouselView: CarouselView + private var sampleImages = intArrayOf( R.drawable.image_1, R.drawable.image_2, R.drawable .image_3, R.drawable.image_4, R.drawable.image_5 @@ -93,10 +95,11 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - carouselView = (CarouselView) findViewById (R.id.carouselView) - carouselView.setPageCount(sampleImages.length) - - carouselView.setImageListener(imageListener) + carouselView = findViewById(R.id.carouselView) + carouselView.apply{ + setPageCount(sampleImages.length) + setImageListener(imageListener) + } } } @@ -104,9 +107,8 @@ class MainActivity : AppCompatActivity() { ### If you want to add custom view, implement ```ViewListener```. -**Java ** +**Java** ```java - public class SampleCarouselViewActivity extends AppCompatActivity { CarouselView customCarouselView; @@ -134,11 +136,12 @@ public class SampleCarouselViewActivity extends AppCompatActivity { } }; } + ``` -**Kotlin ** +**Kotlin** ```kotlin - class SampleCarouselViewActivity : AppCompatActivity() { + internal var customCarouselView: CarouselView internal var NUMBER_OF_PAGES = 5 internal var viewListener: ViewListener = object : ViewListener() { @@ -164,7 +167,7 @@ class SampleCarouselViewActivity : AppCompatActivity() { ### If you'd like to receive touch events for each image -**Java ** +**Java** ```java customCarouselView.setImageClickListener(new ImageClickListener() { @Override @@ -172,8 +175,9 @@ customCarouselView.setImageClickListener(new ImageClickListener() { Toast.makeText(SampleCarouselViewActivity.this, "Clicked item: "+ position, Toast.LENGTH_SHORT).show(); } }); + ``` -**Kotlin ** +**Kotlin** ```kotlin customCarouselView.setImageClickListener(object : ImageClickListener() { fun onClick(position: Int) {