diff --git a/.idea/modules.xml b/.idea/modules.xml
index b4e1e38..1ac92af 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -4,11 +4,9 @@
-
-
\ No newline at end of file
diff --git a/preveiwapp/src/main/java/com/example/preveiwapp/MainActivity.java b/preveiwapp/src/main/java/com/example/preveiwapp/MainActivity.java
index af4dc03..847519f 100644
--- a/preveiwapp/src/main/java/com/example/preveiwapp/MainActivity.java
+++ b/preveiwapp/src/main/java/com/example/preveiwapp/MainActivity.java
@@ -18,7 +18,12 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
sc = findViewById(R.id.sc);
- sc.setSupportedSelectionsCount(6);
+
+ sc.addSegments(getResources().getStringArray(R.array.segments));
+
+ sc.setColumnCount(3);
+ sc.notifyConfigIsChanged();
+
sc.addOnSegmentSelectListener(new OnSegmentSelectedListener() {
@Override
public void onSegmentSelected(SegmentViewHolder segmentViewHolder, boolean isSelected, boolean isReselected) {
@@ -32,5 +37,6 @@ public void onSegmentClick(SegmentViewHolder segmentViewHolder) {
Log.d("Segment Click",segmentViewHolder.getSegmentData());
}
});
+
}
}
diff --git a/preveiwapp/src/main/res/layout/activity_main.xml b/preveiwapp/src/main/res/layout/activity_main.xml
index e418967..1d63d08 100644
--- a/preveiwapp/src/main/res/layout/activity_main.xml
+++ b/preveiwapp/src/main/res/layout/activity_main.xml
@@ -12,10 +12,8 @@
android:layout_height="wrap_content"
app:supportedSelectionsCount="3"
app:distributeEvenly="true"
- app:selectionAnimationDuration="5000"
android:layout_margin="16dp"
app:radius="16dp"
- app:textVerticalPadding="4dp"
- app:segments="@array/segments"/>
+ app:textVerticalPadding="4dp"/>
\ No newline at end of file
diff --git a/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlControllerComponent.java b/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlControllerComponent.java
index 3ecdff9..154cc9e 100644
--- a/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlControllerComponent.java
+++ b/segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlControllerComponent.java
@@ -28,7 +28,7 @@
class SegmentedControlControllerComponent extends ControllerComponent> {
private final Configs configs = Configs.getDefault();
-// private SegmentViewHolder lastClickedSegmentViewHolder;
+ // private SegmentViewHolder lastClickedSegmentViewHolder;
private LinkedList> selectedSegments = new LinkedList<>();
private final Notifier notifier = new Notifier<>();
private final List dataList = new ArrayList<>();
@@ -64,22 +64,22 @@ public void onSegmentClick(SegmentViewHolder segmentViewHolder) {
int index = selectedSegments.indexOf(segmentViewHolder);
boolean contains = index != -1;
- if (contains){
+ if (contains) {
// on section reselected
SegmentViewHolder viewHolder = selectedSegments.get(index);
viewHolder.setSelected(true);
- notifier.onSegmentSelected(segmentViewHolder,true,true);
- } else if (notifier.onSegmentSelectRequest(segmentViewHolder)){
+ notifier.onSegmentSelected(segmentViewHolder, true, true);
+ } else if (notifier.onSegmentSelectRequest(segmentViewHolder)) {
// on section selected
// unSelect the last one
SegmentViewHolder lastSelected = addSelectedSegmentViewHolder(segmentViewHolder);
- if (lastSelected!=null){
+ if (lastSelected != null) {
lastSelected.setSelected(false);
- notifier.onSegmentSelected(lastSelected,false,false);
+ notifier.onSegmentSelected(lastSelected, false, false);
}
// select the current
segmentViewHolder.setSelected(true);
- notifier.onSegmentSelected(segmentViewHolder,true,false);
+ notifier.onSegmentSelected(segmentViewHolder, true, false);
}
}
};
@@ -87,20 +87,21 @@ public void onSegmentClick(SegmentViewHolder segmentViewHolder) {
/**
* Watch the supported selections count, if limit is reached the oldest segment will be removed from
* selections list and returned back to method caller
+ *
* @param segmentViewHolder new selected segment;
* @return oldest selection
*/
@Nullable
- private SegmentViewHolder addSelectedSegmentViewHolder(SegmentViewHolder segmentViewHolder){
+ private SegmentViewHolder addSelectedSegmentViewHolder(SegmentViewHolder segmentViewHolder) {
selectedSegments.add(segmentViewHolder);
- if (selectedSegments.size() > configs.supportedSelectionsCount){
+ if (selectedSegments.size() > configs.supportedSelectionsCount) {
return selectedSegments.remove(0);
}
return null;
}
- private SegmentViewHolder getLastSelectedViewHolder(){
- return selectedSegments.getLast();
+ private SegmentViewHolder getLastSelectedViewHolder() {
+ return selectedSegments.size() > 0 ? selectedSegments.getLast() : null;
}
private void addSegment(D segmentData) {
@@ -169,12 +170,12 @@ void notifyConfigIsChanged() {
// }
public void clearSelection(boolean notifySegmentSelectedListener) {
- if (!selectedSegments.isEmpty()){
+ if (!selectedSegments.isEmpty()) {
for (SegmentViewHolder selectedSegment : selectedSegments) {
selectedSegment.setSelected(false);
- if (notifySegmentSelectedListener){
- notifier.onSegmentSelected(selectedSegment,false,false);
+ if (notifySegmentSelectedListener) {
+ notifier.onSegmentSelected(selectedSegment, false, false);
}
}
@@ -274,11 +275,11 @@ void setUnSelectedBackgroundColor(int color) {
configs.segmentDecoration.unSelectedBackgroundColor = color;
}
- void setFocusedBackgroundColor(int color){
+ void setFocusedBackgroundColor(int color) {
configs.segmentDecoration.focusedBackgroundColor = color;
}
- void setSelectionAnimationDuration(int duration){
+ void setSelectionAnimationDuration(int duration) {
configs.segmentDecoration.selectionAnimationDuration = duration;
}
@@ -369,7 +370,7 @@ void setDistributeEvenly(boolean willDistributeEvenly) {
configs.willDistributeEvenly = willDistributeEvenly;
}
- void setSupportedSelectionsCount(int supportedSelectionsCount){
+ void setSupportedSelectionsCount(int supportedSelectionsCount) {
configs.supportedSelectionsCount = supportedSelectionsCount;
}
@@ -410,24 +411,25 @@ void setSelectedSegment(int column, int row) {
// return lastClickedSegmentViewHolder;
// }
- List> getSelectedViewHolders(){
+ List> getSelectedViewHolders() {
return selectedSegments;
}
int[] getLastSelectedColumnAndRow() {
SegmentViewHolder lastSelection = getLastSelectedViewHolder();
- if (lastSelection!=null){
- return new int[]{lastSelection.getColumn(),lastSelection.getRow()};
- }else{
- return new int[]{-1,-1};
+ if (lastSelection != null) {
+ return new int[]{lastSelection.getColumn(), lastSelection.getRow()};
+ } else {
+ return new int[]{-1, -1};
}
}
-//
+
+ //
int getLastSelectedAbsolutePosition() {
SegmentViewHolder lastSelection = getLastSelectedViewHolder();
- if (lastSelection!=null){
+ if (lastSelection != null) {
return lastSelection.getAbsolutePosition();
- }else{
+ } else {
return -1;
}
}
@@ -436,7 +438,7 @@ int getLastSelectedAbsolutePosition() {
// return lastClickedSegmentViewHolder != null;
// }
- boolean isSelected(){
+ boolean isSelected() {
return !selectedSegments.isEmpty();
}