diff --git a/README.md b/README.md index b65d0d2..192a601 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Carousel Picker -![alt downloads](https://img.shields.io/jitpack/dm/github/GoodieBag/CarouselPicker.svg) +[![Download](https://jitpack.io/v/Husseinhj/KotlinCarouselPicker.svg)](https://jitpack.io/#Husseinhj/KotlinCarouselPicker) + A Carousel picker library for android which supports both text and icons . :pouting_cat: @@ -12,19 +13,17 @@ Add this in your root build.gradle file at the end of repositories: ```java allprojects { - repositories { - ... - maven { url 'https://jitpack.io' } - } + repositories { + ... + maven { url 'https://jitpack.io' } } +} ``` Add the dependency : ```java dependencies { - implementation 'com.github.GoodieBag:CarouselPicker:v1.2' - // v1.2 is the latest release with vertical orientation and font styling options. - // For the previous stable release use v1.1 - } + implementation 'com.github.Husseinhj:KotlinCarouselPicker:2.0.2' +} ``` Sync the gradle and that's it! :+1: @@ -38,7 +37,7 @@ Sync the gradle and that's it! :+1: ### XML : ```xml - mixItems = new ArrayList<>(); mixItems.add(new CarouselPicker.DrawableItem(R.drawable.i1)); @@ -89,23 +91,18 @@ carouselPicker.setAdapter(mixAdapter); - Text color for text items can be set using ```adapter.setTextColor(colorInt)``` ## Listeners : -```java -carouselPicker.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - //position of the selected item - } +```kotlin +carouselPicker.addOnPageChangeListener(object: ViewPager.OnPageChangeListener { + override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { + } - @Override - public void onPageScrollStateChanged(int state) { + override fun onPageSelected(position: Int) { + //position of the selected item + } - } - }); + override fun onPageScrollStateChanged(state: Int) { + } +}) ``` ## LICENSE : diff --git a/app/build.gradle b/app/build.gradle index e177f06..59c8cbd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,11 +1,13 @@ apply plugin: 'com.android.application' +apply plugin: 'org.jetbrains.kotlin.android' android { - compileSdkVersion 29 + compileSdk 34 + namespace "in.goodiebag.example" defaultConfig { applicationId "in.goodiebag.example" minSdkVersion 15 - targetSdkVersion 29 + targetSdk 34 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -17,15 +19,18 @@ android { } } compileOptions { - sourceCompatibility = 1.7 - targetCompatibility = 1.7 + sourceCompatibility = 11 + targetCompatibility = 11 + } + kotlinOptions { + jvmTarget = '11' } - buildToolsVersion = '29.0.2' } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'androidx.appcompat:appcompat:1.1.0' - testImplementation 'junit:junit:4.12' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'androidx.core:core-ktx:1.12.0' + testImplementation 'junit:junit:4.13.2' implementation project(':carouselpicker') } diff --git a/app/src/androidTest/java/in/goodiebag/example/ExampleInstrumentedTest.java b/app/src/androidTest/java/in/goodiebag/example/ExampleInstrumentedTest.java deleted file mode 100644 index 555e667..0000000 --- a/app/src/androidTest/java/in/goodiebag/example/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package in.goodiebag.example; - -import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumentation test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() throws Exception { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("in.goodiebag.example.carouselview", appContext.getPackageName()); - } -} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 479e57c..db1f91c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + - + diff --git a/app/src/main/java/in/goodiebag/example/MainActivity.java b/app/src/main/java/in/goodiebag/example/MainActivity.java deleted file mode 100644 index 8cbf09d..0000000 --- a/app/src/main/java/in/goodiebag/example/MainActivity.java +++ /dev/null @@ -1,112 +0,0 @@ -package in.goodiebag.example; - -import android.graphics.Typeface; -import android.os.Bundle; -import android.widget.TextView; - -import androidx.appcompat.app.AppCompatActivity; -import androidx.viewpager.widget.ViewPager; - -import java.util.ArrayList; -import java.util.List; - -import in.goodiebag.carouselpicker.CarouselPicker; - -public class MainActivity extends AppCompatActivity { - CarouselPicker imageCarousel, textCarousel, mixCarousel; - TextView tvSelected; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - imageCarousel = findViewById(R.id.imageCarousel); - textCarousel = findViewById(R.id.textCarousel); - mixCarousel = findViewById(R.id.mixCarousel); - tvSelected = findViewById(R.id.tvSelectedItem); - - List imageItems = new ArrayList<>(); - imageItems.add(new CarouselPicker.DrawableItem(R.drawable.i1)); - imageItems.add(new CarouselPicker.DrawableItem(R.drawable.i2, getResources().getColor(android.R.color.holo_red_light))); - imageItems.add(new CarouselPicker.DrawableItem(R.drawable.i3)); - imageItems.add(new CarouselPicker.DrawableItem(R.drawable.i4)); - CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this, imageItems, 0); - imageCarousel.setAdapter(imageAdapter); - - List textItems = new ArrayList<>(); - textItems.add(new CarouselPicker.TextItem("hi", 20, - getResources().getColor(android.R.color.holo_blue_bright), Typeface.MONOSPACE, - CarouselPicker.TextItem.FontStyle.BOLD_ITALIC)); - textItems.add(new CarouselPicker.TextItem("hi, welcome to the carousel picker", 20, - getResources().getColor(android.R.color.holo_red_light), - Typeface.SANS_SERIF, CarouselPicker.TextItem.FontStyle.NORMAL)); - textItems.add(new CarouselPicker.TextItem("hi", 20, - Typeface.SERIF, CarouselPicker.TextItem.FontStyle.ITALIC)); - textItems.add(new CarouselPicker.TextItem("hi", 20)); - CarouselPicker.CarouselViewAdapter textAdapter = new CarouselPicker.CarouselViewAdapter(this, textItems, 0); - textCarousel.setAdapter(textAdapter); - // set default color - textAdapter.setTextColor(getResources().getColor(android.R.color.holo_green_light)); - - List mixItems = new ArrayList<>(); - mixItems.add(new CarouselPicker.DrawableItem(R.drawable.i1)); - mixItems.add(new CarouselPicker.TextItem("hi", 20)); - mixItems.add(new CarouselPicker.DrawableItem(R.drawable.i2)); - mixItems.add(new CarouselPicker.TextItem("hi", 20)); - - CarouselPicker.CarouselViewAdapter mixAdapter = new CarouselPicker.CarouselViewAdapter(this, mixItems, 0); - mixAdapter.setTextColor(getResources().getColor(R.color.colorPrimary)); - mixCarousel.setAdapter(mixAdapter); - - imageCarousel.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - tvSelected.setText("Selected item in image carousel is : "+position); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - - textCarousel.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - tvSelected.setText("Selected item in text carousel is : "+position); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - - mixCarousel.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - - } - - @Override - public void onPageSelected(int position) { - tvSelected.setText("Selected item in mix carousel is : "+position); - } - - @Override - public void onPageScrollStateChanged(int state) { - - } - }); - } -} diff --git a/app/src/main/java/in/goodiebag/example/MainActivity.kt b/app/src/main/java/in/goodiebag/example/MainActivity.kt new file mode 100644 index 0000000..5b795dd --- /dev/null +++ b/app/src/main/java/in/goodiebag/example/MainActivity.kt @@ -0,0 +1,131 @@ +package `in`.goodiebag.example + +import android.graphics.Color +import android.os.Bundle +import android.widget.TextView +import android.graphics.Typeface +import android.os.Build +import android.widget.Button +import androidx.appcompat.app.AppCompatActivity +import com.goodiebag.carouselpicker.CarouselPicker +import androidx.viewpager.widget.ViewPager.OnPageChangeListener + +class MainActivity : AppCompatActivity() { + + private lateinit var tvSelected: TextView + private lateinit var mixCarousel: CarouselPicker + private lateinit var imageCarousel: CarouselPicker + private lateinit var textCarousel: CarouselPicker + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + imageCarousel = findViewById(R.id.imageCarousel) + textCarousel = findViewById(R.id.textCarousel) + mixCarousel = findViewById(R.id.mixCarousel) + tvSelected = findViewById(R.id.tvSelectedItem) + + val imageItems: MutableList = ArrayList() + imageItems.add(CarouselPicker.DrawableItem(R.drawable.i1)) + imageItems.add( + CarouselPicker.DrawableItem( + R.drawable.i2, + getResources().getColor(android.R.color.holo_red_light) + ) + ) + + imageItems.add(CarouselPicker.DrawableItem(R.drawable.i3)) + imageItems.add(CarouselPicker.DrawableItem(R.drawable.i4)) + + val imageAdapter = CarouselPicker.CarouselViewAdapter(imageItems, 0) + imageCarousel.setAdapter(imageAdapter) + val textItems: MutableList = ArrayList() + textItems.add( + CarouselPicker.TextItem( + "hi", 20, + getResources().getColor(android.R.color.holo_blue_bright), Typeface.MONOSPACE, + CarouselPicker.TextItem.FontStyle.BOLD_ITALIC + ) + ) + textItems.add( + CarouselPicker.TextItem( + "hi, welcome to the carousel picker", 20, + getResources().getColor(android.R.color.holo_red_light), + Typeface.SANS_SERIF, CarouselPicker.TextItem.FontStyle.NORMAL + ) + ) + textItems.add( + CarouselPicker.TextItem( + "hi", 20, + Typeface.SERIF, CarouselPicker.TextItem.FontStyle.ITALIC + ) + ) + textItems.add(CarouselPicker.TextItem("hi", 20)) + val textAdapter = CarouselPicker.CarouselViewAdapter(textItems, 0) + textCarousel.setAdapter(textAdapter) + // set default color + textAdapter.textColor = getResources().getColor(android.R.color.holo_green_light) + textAdapter.selectedItemTextColor = Color.GREEN + textAdapter.selectedIndex = 1 + + val mixItems: MutableList = ArrayList() + mixItems.add(CarouselPicker.DrawableItem(R.drawable.i1)) + mixItems.add(CarouselPicker.TextItem("hi", 20)) + mixItems.add(CarouselPicker.DrawableItem(R.drawable.i2)) + mixItems.add(CarouselPicker.TextItem("hi", 20)) + val mixAdapter = CarouselPicker.CarouselViewAdapter(mixItems, 0) + mixAdapter.textColor = getResources().getColor(R.color.colorPrimary) + mixAdapter.selectedItemTextColor = getResources().getColor(R.color.colorAccent) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + mixAdapter.selectedItemTintColor = getResources().getColor(R.color.colorAccent) + } + mixCarousel.setAdapter(mixAdapter) + imageCarousel.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int, + ) { + } + + override fun onPageSelected(position: Int) { + tvSelected.setText("Selected item in image carousel is : $position") + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + textCarousel.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int, + ) { + } + + override fun onPageSelected(position: Int) { + tvSelected.setText("Selected item in text carousel is : $position") + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + mixCarousel.addOnPageChangeListener(object : OnPageChangeListener { + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int, + ) { + } + + override fun onPageSelected(position: Int) { + tvSelected.setText("Selected item in mix carousel is : $position") + } + + override fun onPageScrollStateChanged(state: Int) {} + }) + + findViewById