Skip to content

Commit 8085c52

Browse files
Merge pull request #29 from thirstycoda/master
Add support for vertical orientation and specifying font, style and color for individual items
2 parents c052056 + 15d6559 commit 8085c52

File tree

6 files changed

+333
-91
lines changed

6 files changed

+333
-91
lines changed

app/src/main/java/in/goodiebag/example/MainActivity.java

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package in.goodiebag.example;
22

3-
import androidx.appcompat.app.AppCompatActivity;
4-
import androidx.viewpager.widget.ViewPager;
3+
import android.graphics.Typeface;
54
import android.os.Bundle;
65
import android.widget.TextView;
76

7+
import androidx.appcompat.app.AppCompatActivity;
8+
import androidx.viewpager.widget.ViewPager;
9+
810
import java.util.ArrayList;
911
import java.util.List;
1012

@@ -25,19 +27,26 @@ protected void onCreate(Bundle savedInstanceState) {
2527

2628
List<CarouselPicker.PickerItem> imageItems = new ArrayList<>();
2729
imageItems.add(new CarouselPicker.DrawableItem(R.drawable.i1));
28-
imageItems.add(new CarouselPicker.DrawableItem(R.drawable.i2));
30+
imageItems.add(new CarouselPicker.DrawableItem(R.drawable.i2, getResources().getColor(android.R.color.holo_red_light)));
2931
imageItems.add(new CarouselPicker.DrawableItem(R.drawable.i3));
3032
imageItems.add(new CarouselPicker.DrawableItem(R.drawable.i4));
3133
CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this, imageItems, 0);
3234
imageCarousel.setAdapter(imageAdapter);
3335

3436
List<CarouselPicker.PickerItem> textItems = new ArrayList<>();
35-
textItems.add(new CarouselPicker.TextItem("hi", 20));
36-
textItems.add(new CarouselPicker.TextItem("hi", 20));
37-
textItems.add(new CarouselPicker.TextItem("hi", 20));
37+
textItems.add(new CarouselPicker.TextItem("hi", 20,
38+
getResources().getColor(android.R.color.holo_blue_bright), Typeface.MONOSPACE,
39+
CarouselPicker.TextItem.FontStyle.BOLD_ITALIC));
40+
textItems.add(new CarouselPicker.TextItem("hi, welcome to the carousel picker", 20,
41+
getResources().getColor(android.R.color.holo_red_light),
42+
Typeface.SANS_SERIF, CarouselPicker.TextItem.FontStyle.NORMAL));
43+
textItems.add(new CarouselPicker.TextItem("hi", 20,
44+
Typeface.SERIF, CarouselPicker.TextItem.FontStyle.ITALIC));
3845
textItems.add(new CarouselPicker.TextItem("hi", 20));
3946
CarouselPicker.CarouselViewAdapter textAdapter = new CarouselPicker.CarouselViewAdapter(this, textItems, 0);
4047
textCarousel.setAdapter(textAdapter);
48+
// set default color
49+
textAdapter.setTextColor(getResources().getColor(android.R.color.holo_green_light));
4150

4251
List<CarouselPicker.PickerItem> mixItems = new ArrayList<>();
4352
mixItems.add(new CarouselPicker.DrawableItem(R.drawable.i1));

app/src/main/res/layout/activity_main.xml

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
android:layout_width="match_parent"
1717
android:layout_height="wrap_content"
1818
android:background="#CCC"
19-
app:items_visible="three" />
19+
app:items_visible="three"
20+
app:unselected_item_opacity="0.5"/>
2021

2122
<in.goodiebag.carouselpicker.CarouselPicker
2223
android:id="@+id/textCarousel"
@@ -25,7 +26,10 @@
2526
android:layout_width="match_parent"
2627
android:layout_height="wrap_content"
2728
android:background="#CCC"
28-
app:items_visible="three" />
29+
app:items_visible="three"
30+
app:orientation="vertical"
31+
app:unselected_item_opacity="0.5"
32+
app:text_max_lines="1"/>
2933

3034
<in.goodiebag.carouselpicker.CarouselPicker
3135
android:id="@+id/mixCarousel"

0 commit comments

Comments
 (0)