Skip to content

Commit

Permalink
v1.4: Feature Add - Controlling the slide number text size and indica…
Browse files Browse the repository at this point in the history
…tor scale

Implemented the features of controlling the slide number text size and indicator scale

Added v1.4
  • Loading branch information
sung2063 committed Apr 28, 2021
1 parent 6a88401 commit 959718e
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 49 deletions.
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Sliders/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
versionCode 3
versionName "1.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -22,6 +22,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class CarouselHandler {
private List<ViewGroup> slideList;
private int scrollDirection;
private boolean isShowingIndicator;
private float indicatorScale;
private boolean isShowingSlideNumber;
private int slideNumberTextSize; // in px

// =============================================================================================
// Fields
Expand All @@ -46,11 +48,13 @@ public CarouselHandler() {
// Default Constructor
}

public CarouselHandler(Context context, int scrollDirection, boolean isShowingIndicator, boolean isShowingSlideNumber) {
public CarouselHandler(Context context, int scrollDirection, boolean isShowingIndicator, float indicatorScale, boolean isShowingSlideNumber, int slideNumberTextSize) {
this.context = context;
this.scrollDirection = scrollDirection;
this.isShowingIndicator = isShowingIndicator;
this.indicatorScale = indicatorScale;
this.isShowingSlideNumber = isShowingSlideNumber;
this.slideNumberTextSize = slideNumberTextSize;
}

// =============================================================================================
Expand Down Expand Up @@ -109,6 +113,22 @@ protected void showIndicator(boolean isShowingIndicator) {
this.isShowingIndicator = isShowingIndicator;
}

/**
* Returns the value of indicator scale
* @return indicatorScale returns indicator scale value
*/
protected float getIndicatorScale() {
return indicatorScale;
}

/**
* Set the value of indicator scale
* @param indicatorScale float value for indicator scale
*/
protected void setIndicatorScale(float indicatorScale) {
this.indicatorScale = indicatorScale;
}

/**
* Returns the value of showing slide number
* @return true if showing the slide number, otherwise false
Expand All @@ -125,4 +145,20 @@ public void showSlideNumber(boolean isShowingSlideNumber) {
this.isShowingSlideNumber = isShowingSlideNumber;
}

/**
* Get the value of slide number text size in px
* @return slide number text size in px
*/
public int getSlideNumberTextSize() {
return slideNumberTextSize;
}

/**
* Set the value of slide number text size in px
* @param slideNumberTextSize int value for slide number text size in px
*/
public void setSlideNumberTextSize(int slideNumberTextSize) {
this.slideNumberTextSize = slideNumberTextSize;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import com.google.android.material.tabs.TabLayout;
import com.sung2063.sliders.R;
import com.sung2063.sliders.adapter.SlideAdapter;
import com.sung2063.sliders.exceptions.IllegalArgumentException;
import com.sung2063.sliders.exceptions.SlideNullPointerException;
import com.sung2063.sliders.exceptions.SlideOutOfBoundException;
import com.sung2063.sliders.util.UnitConverter;

import java.util.List;

Expand Down Expand Up @@ -57,7 +59,7 @@ public CarouselView(Context context) {
}

// Create object from XML file
public CarouselView(Context context, @Nullable AttributeSet attrs) {
public CarouselView(Context context, @Nullable AttributeSet attrs) throws IllegalArgumentException {
super(context, attrs);

this.context = context;
Expand All @@ -66,8 +68,21 @@ public CarouselView(Context context, @Nullable AttributeSet attrs) {
try {
int scrollDirection = typedArray.getInt(R.styleable.CarouselView_scrollDirection, CarouselHandler.CAROUSEL_HORIZONTAL_DIRECTION);
boolean isShowingIndicator = typedArray.getBoolean(R.styleable.CarouselView_showIndicator, false);
float indicatorScale = typedArray.getFloat(R.styleable.CarouselView_indicatorScale, 1);
boolean isShowingSlideNumber = typedArray.getBoolean(R.styleable.CarouselView_showSlideNumber, false);
carouselHandler = new CarouselHandler(context, scrollDirection, isShowingIndicator, isShowingSlideNumber);
int slideNumberTextSize = typedArray.getInt(R.styleable.CarouselView_slideNumberTextSize, 45);

// Check illegal exception
if (indicatorScale < 0 || indicatorScale > 1.5) {
throw new IllegalArgumentException(context.getString(R.string.indicator_scale_illegal_error));
}

if (slideNumberTextSize < 0 || slideNumberTextSize > 50) {
throw new IllegalArgumentException(context.getString(R.string.slide_number_text_size_illegal_error));
}

carouselHandler = new CarouselHandler(context, scrollDirection, isShowingIndicator, indicatorScale, isShowingSlideNumber, slideNumberTextSize);

} finally {
typedArray.recycle();
init();
Expand All @@ -89,8 +104,8 @@ protected void init() {

// Setup Layout
setupLayoutDirection(carouselHandler.getScrollDirection());
setupIndicator(carouselHandler.isShowingIndicator());
setupSlideNumber(carouselHandler.isShowingSlideNumber());
setupIndicator(carouselHandler.isShowingIndicator(), carouselHandler.getIndicatorScale());
setupSlideNumber(carouselHandler.isShowingSlideNumber(), carouselHandler.getSlideNumberTextSize());

}

Expand Down Expand Up @@ -147,10 +162,14 @@ private void setupLayoutDirection(int layoutDirection) {
/**
* Setup the tab indicator
* @param isShowingIndicator boolean value for showing the tab indicator
* @param indicatorScale float value for indicator scale
*/
private void setupIndicator(boolean isShowingIndicator) {
private void setupIndicator(boolean isShowingIndicator, float indicatorScale) {
if (isShowingIndicator) {
tabIndicator.setVisibility(VISIBLE); // Show the indicator
tabIndicator.setScaleX(indicatorScale);
tabIndicator.setScaleY(indicatorScale);

} else {
tabIndicator.setVisibility(GONE); // Does not use the indicator
}
Expand All @@ -159,14 +178,19 @@ private void setupIndicator(boolean isShowingIndicator) {
/**
* Setup the slide number view
* @param isShowingSlideNumber boolean value for showing the slide number
* @param slideNumberTextSize text size of slide number
*/
private void setupSlideNumber(boolean isShowingSlideNumber) {
private void setupSlideNumber(boolean isShowingSlideNumber, int slideNumberTextSize) {

if (isShowingSlideNumber) {
// Show the slide number
tvPageNum.setVisibility(VISIBLE);
vpSlider.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

// Convert text size in sp
float slideNumberTextSizeInDP = UnitConverter.convertTextPXToSP(context, slideNumberTextSize);
tvPageNum.setTextSize(slideNumberTextSizeInDP);

vpSlider.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int index) {
super.onPageSelected(index);
Expand All @@ -182,7 +206,7 @@ public void onPageSelected(int index) {
}

// =============================================================================================
// Accessable Methods
// Accessible Methods
// =============================================================================================
public void launch() throws SlideNullPointerException {

Expand All @@ -197,16 +221,14 @@ public void launch() throws SlideNullPointerException {

// Give sometime for loading
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
repositioningVerticalTab();
pbLayoutLoader.setVisibility(GONE);
}
handler.postDelayed(() -> {
repositioningVerticalTab();
pbLayoutLoader.setVisibility(GONE);
}, 250);

} else
} else {
throw new SlideNullPointerException(context.getString(R.string.list_null_error)); // Null Exception
}

}

Expand Down Expand Up @@ -257,7 +279,7 @@ public boolean isShowingIndicator() {
* @param isShowingIndicator boolean value for showing the tab indicator
*/
public void showIndicator(boolean isShowingIndicator) {
setupIndicator(isShowingIndicator);
setupIndicator(isShowingIndicator, carouselHandler.getIndicatorScale());
carouselHandler.showIndicator(isShowingIndicator);
}

Expand All @@ -269,13 +291,31 @@ public boolean isShowingSlideNumber() {
return carouselHandler.isShowingSlideNumber();
}

/**
* Set indicator scale
* @param indicatorScale float value for indicator scale
*/
public void setIndicatorScale(float indicatorScale) {
setupIndicator(carouselHandler.isShowingIndicator(), indicatorScale);
carouselHandler.setIndicatorScale(indicatorScale);
}

/**
* Set the value of slide number
* @param isShowingSlideNumber boolean value for showing the slide number
*/
public void showSlideNumber(boolean isShowingSlideNumber) {
setupSlideNumber(isShowingSlideNumber);
setupSlideNumber(isShowingSlideNumber, carouselHandler.getSlideNumberTextSize());
carouselHandler.showSlideNumber(isShowingSlideNumber);
}

/**
* Set the slide number text size
* @param slideNumberTextSize int value for slide number text size in px
*/
public void setSlideNumberTextSize(int slideNumberTextSize) {
setupSlideNumber(carouselHandler.isShowingSlideNumber(), slideNumberTextSize);
carouselHandler.setSlideNumberTextSize(slideNumberTextSize);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class SlideshowHandler {
private Context context;
private List<ViewGroup> slideList;
private boolean isShowingIndicator;
private float indicatorScale;
private boolean isShowingSlideNumber;
private int slideNumberTextSize; // in px
private int delayTimePeriod;

// =============================================================================================
Expand All @@ -34,10 +36,12 @@ public SlideshowHandler() {
// Default Constructor
}

public SlideshowHandler(Context context, boolean isShowingIndicator, boolean isShowingSlideNumber, int delayTimePeriod) {
public SlideshowHandler(Context context, boolean isShowingIndicator, float indicatorScale, boolean isShowingSlideNumber, int slideNumberTextSize, int delayTimePeriod) {
this.context = context;
this.isShowingIndicator = isShowingIndicator;
this.indicatorScale = indicatorScale;
this.isShowingSlideNumber = isShowingSlideNumber;
this.slideNumberTextSize = slideNumberTextSize;
this.delayTimePeriod = delayTimePeriod;
}

Expand All @@ -59,8 +63,9 @@ protected List<ViewGroup> getSlideList() {
* @throws SlideOutOfBoundException on list size is greater than 10
*/
protected void setSlideList(List<ViewGroup> slideList) throws SlideOutOfBoundException {
if (slideList.size() > 10)
if (slideList.size() > 10) {
throw new SlideOutOfBoundException(context.getString(R.string.exceed_slide_boundary_error));
}
this.slideList = slideList;
}

Expand All @@ -80,6 +85,22 @@ protected void showIndicator(boolean isShowingIndicator) {
this.isShowingIndicator = isShowingIndicator;
}

/**
* Returns the value of indicator scale
* @return indicatorScale returns the indicator scale value
*/
protected float getIndicatorScale() {
return indicatorScale;
}

/**
* Set the value of indicator scale
* @param indicatorScale float value for indicator scale
*/
protected void setIndicatorScale(float indicatorScale) {
this.indicatorScale = indicatorScale;
}

/**
* Returns the value of slide delay time period
* @return slide delay time in second
Expand Down Expand Up @@ -115,4 +136,20 @@ protected boolean showSlideNumber() {
protected void setShowingSlideNumber(boolean isShowingSlideNumber) {
this.isShowingSlideNumber = isShowingSlideNumber;
}

/**
* Get the value of slide number text size in px
* @return slide number text size in px
*/
public int getSlideNumberTextSize() {
return slideNumberTextSize;
}

/**
* Set the value of slide number text size in px
* @param slideNumberTextSize int value for slide number text size in px
*/
public void setSlideNumberTextSize(int slideNumberTextSize) {
this.slideNumberTextSize = slideNumberTextSize;
}
}
Loading

0 comments on commit 959718e

Please sign in to comment.