Repository: RobertApikyan/SegmentedControl
Branch: master
Commit: 574281e85338
Files: 48
Total size: 125.7 KB
Directory structure:
gitextract_p17z464c/
├── .gitignore
├── .idea/
│ ├── caches/
│ │ ├── build_file_checksums.ser
│ │ └── gradle_models.ser
│ ├── encodings.xml
│ ├── gradle.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ └── vcs.xml
├── LICENSE
├── README.md
├── build.gradle
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── segmentedcontrolmodule/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ └── main/
│ ├── AndroidManifest.xml
│ ├── java/
│ │ └── segmented_control/
│ │ └── widget/
│ │ └── custom/
│ │ └── android/
│ │ └── com/
│ │ └── segmentedcontrol/
│ │ ├── Assert.java
│ │ ├── Configs.java
│ │ ├── Consumer.java
│ │ ├── Notifier.java
│ │ ├── SegmentConsumer.java
│ │ ├── SegmentedControl.java
│ │ ├── SegmentedControlControllerComponent.java
│ │ ├── SegmentedControlViewComponent.java
│ │ ├── custom_segment/
│ │ │ ├── SegmentAdapterImpl.java
│ │ │ └── SegmentViewHolderImpl.java
│ │ ├── item_row/
│ │ │ ├── SegmentRowAdapter.java
│ │ │ └── SegmentRowViewHolder.java
│ │ ├── item_row_column/
│ │ │ ├── SegmentAdapter.java
│ │ │ ├── SegmentBackgroundType.java
│ │ │ ├── SegmentData.java
│ │ │ ├── SegmentDecoration.java
│ │ │ └── SegmentViewHolder.java
│ │ ├── listeners/
│ │ │ ├── OnSegmentClickListener.java
│ │ │ ├── OnSegmentSelectRequestListener.java
│ │ │ └── OnSegmentSelectedListener.java
│ │ └── utils/
│ │ ├── ArgbEvaluator.java
│ │ └── Utils.java
│ └── res/
│ ├── layout/
│ │ └── item_segment_impl.xml
│ └── values/
│ ├── attr.xml
│ ├── colors.xml
│ └── strings.xml
└── settings.gradle
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
/app
================================================
FILE: .idea/encodings.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
================================================
FILE: .idea/gradle.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/segmentedcontrolmodule" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
================================================
FILE: .idea/misc.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="10">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="9">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
================================================
FILE: .idea/modules.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/SegmentedControl_.iml" filepath="$PROJECT_DIR$/SegmentedControl_.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/segmentedControl.iml" filepath="$PROJECT_DIR$/segmentedControl.iml" />
<module fileurl="file://$PROJECT_DIR$/segmentedcontrolmodule/segmentedcontrolmodule.iml" filepath="$PROJECT_DIR$/segmentedcontrolmodule/segmentedcontrolmodule.iml" />
</modules>
</component>
</project>
================================================
FILE: .idea/runConfigurations.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
================================================
FILE: .idea/vcs.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: README.md
================================================
# Android SegmentedControl + multi row support + multi selection
### minSdk API 14+

[Demo App, Play store link](https://play.google.com/store/apps/details?id=segmented_control.widget.custom.android.com.segmentedcontrolexample&hl=en)
[Or try demo App online !](https://appetize.io/app/y4e91xhxgp47956bf73da4z4yg)
[](https://jitpack.io/#RobertApikyan/SegmentedControl)
[](https://opensource.org/licenses/Apache-2.0)
## Segmented control for Android, with a lot of customization properties
<img src="https://raw.githubusercontent.com/RobertApikyan/SegmentedControl/release_v0.1/docs/intro.gif.gif" width="300" height="525" />
## ScreenShots
<img src="https://raw.githubusercontent.com/RobertApikyan/SegmentedControl/intro/intro/ezgif.com-optimize.gif" width="400" />
<img src="https://raw.githubusercontent.com/RobertApikyan/SegmentedControl/release_v0.1/docs/device-2017-09-14-133621.png" width="400" />
<img src="https://raw.githubusercontent.com/RobertApikyan/SegmentedControl/release_v0.1/docs/device-2017-09-14-133711.png" width="400" />
<img src="https://raw.githubusercontent.com/RobertApikyan/SegmentedControl/release_v0.1/docs/device-2017-09-14-133736.png" width="400" />
<img src="https://raw.githubusercontent.com/RobertApikyan/SegmentedControl/release_v0.1/docs/device-2017-09-14-133907.png" width="400" />
<img src="https://raw.githubusercontent.com/RobertApikyan/SegmentedControl/release_v0.1/docs/device-2017-09-14-134003.png" width="400" />
<img src="https://raw.githubusercontent.com/RobertApikyan/SegmentedControl/release_v0.1/docs/device-2017-09-14-202249.png" width="400" />
## Download
### Gradle
Add to project level build.gradle
```groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Add dependency to app module level build.gradle
```groovy
dependencies {
implementation 'com.github.RobertApikyan:SegmentedControl:1.2.0'
}
```
### Maven
```xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
```
Add dependency
```xml
<dependency>
<groupId>com.github.RobertApikyan</groupId>
<artifactId>SegmentedControl</artifactId>
<version>1.1.3</version>
</dependency>
```
### Done.
## Simple usage in XML
```xml
<segmented_control.widget.custom.android.com.segmentedcontrol.SegmentedControl
android:id="@+id/segmented_control"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
app:columnCount="3"
app:distributeEvenly="true"
app:textVerticalPadding="6dp"
app:radius="12dp"
app:segments="@array/your_array_data" />
```
Attributes
```xml
<attr name="supportedSelectionsCount" format="boolean" /> setSupportedSelectionsCount(int)
<attr name="reselectionEnabled" format="boolean" /> setDistributeEvenly(boolean)
<attr name="distributeEvenly" format="boolean" /> setDistributeEvenly(boolean)
<attr name="columnCount" format="integer" /> setColumnCount(int)
<attr name="segments" format="reference" /> addSegments(Object[]), addSegments(List)
<attr name="selectedStrokeColor" format="color" /> setSelectedStrokeColor(int)
<attr name="unSelectedStrokeColor" format="color" /> setUnSelectedStrokeColor(int)
<attr name="strokeWidth" format="dimension" / setStrokeWidth(int)
<attr name="selectedBackgroundColor" format="color" /> setSelectedBackgroundColor(int)
<attr name="unSelectedBackgroundColor" format="color" /> setUnSelectedBackgroundColor(int)
<attr name="selectedTextColor" format="color"/> setSelectedTextColor(int)
<attr name="unSelectedTextColor" format="color"/> setUnSelectedTextColor(int)
<attr name="textSize" format="dimension"/> setTextSize(int)
<attr name="selectionAnimationDuration" format="integer"/>
<attr name="focusedBackgroundColor" format="color"/>
<attr name="textHorizontalPadding" format="dimension"/> setTextHorizontalPadding(int)
<attr name="textVerticalPadding" format="dimension"/> setTextVerticalPadding(int)
<attr name="segmentVerticalMargin" format="dimension"/> setSegmentVerticalMargin(int)
<attr name="segmentHorizontalMargin" format="dimension"/> setSegmentHorizontalMargin(int)
<attr name="radius" format="dimension"/> setRadius(int)
<attr name="topLeftRadius" format="dimension"/> setTopLeftRadius(int)
<attr name="topRightRadius" format="dimension"/> setTopRightRadius(int)
<attr name="bottomRightRadius" format="dimension"/> setBottomRightRadius(int)
<attr name="bottomLeftRadius" format="dimension"/> setBottomLeftRadius(int)
<attr name="radiusForEverySegment" format="boolean"/> setRadiusForEverySegment(boolean)
<attr name="fontAssetPath" format="string"/> setTypeFace(TypeFace)
```
**Note:** After every configuration change call segmentedControl.notifyConfigIsChanged() method
# Example
```java
segmentedControl.setStrokeWidth(width.intValue());
segmentedControl.setColumnCount(columnCount);
segmentedControl.notifyConfigIsChanged();
```
> SegmentedControl uses SegmentAdapter and SegmentViewHolder for displaying segments. There are allready exist a default implementations for SegmentAdapter (SegmentAdapterImpl) and SegmentViewHolder (SegmentViewHolderImpl), but if you want to make your custom implementation... well here is the steps
1. Define `segment_item.xml` inside `layouts` folder
```xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="2dp"
android:background="@color/colorPrimary"
android:gravity="center"
android:textColor="@color/colorAccent"
android:textSize="14sp" />
</LinearLayout>
```
2. Create a `SegmentViewHolder` instance (`AppSegmentViewHolder`) (here I define the segment generic data type as a String)
```java
public class AppSegmentViewHolder extends SegmentViewHolder<String> {
TextView textView;
public AppSegmentViewHolder(@NonNull View sectionView) {
super(sectionView);
textView = (TextView) sectionView.findViewById(R.id.text_view);
}
@Override
protected void onSegmentBind(String segmentData) {
textView.setText(segmentData);
}
}
```
3. Create a `SegmentAdapter` instance
```java
public class AppSegmentAdapter extends SegmentAdapter<String, AppSegmentViewHolder> {
@NonNull
@Override
protected AppSegmentViewHolder onCreateViewHolder(@NonNull LayoutInflater layoutInflater, ViewGroup viewGroup, int i) {
return new AppSegmentViewHolder(layoutInflater.inflate(R.layout.item_segment, null));
}
}
```
4. Pass the adapter to the segmentedControl
```java
segmentedControl = (SegmentedControl) findViewById(R.id.segmented_control);
segmentedControl.setAdapter(new AppSegmentAdapter());
```
5. Finally add segments data.
```java
segmentedControl.addSegments(getResources().getStringArray(R.array.segments));
```
That's it :)
For custom implementation use `SegmentedControlUtils` helper class in order to define segment background type and background radius.
[](https://www.linkedin.com/in/robert-apikyan-24b915130/)
License
-------
Copyright 2017 Robert Apikyan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Fri Apr 19 11:27:29 AMT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
================================================
FILE: gradle.properties
================================================
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
================================================
FILE: gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: segmentedcontrolmodule/.gitignore
================================================
/build
================================================
FILE: segmentedcontrolmodule/build.gradle
================================================
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
api 'com.github.RobertApikyan:ViewComponent:1.0.3'
api 'com.github.RobertApikyan:SecLayout:1.0.3'
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
================================================
FILE: segmentedcontrolmodule/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: segmentedcontrolmodule/src/main/AndroidManifest.xml
================================================
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="segmented_control.widget.custom.android.com.segmented_control">
<application android:label="@string/app_name" />
</manifest>
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Assert.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol;
import section_layout.widget.custom.android.com.sectionlayout.SectionLayout;
/**
* Created by Robert Apikyan on 9/7/2017.
*/
class Assert {
static void adapter(SectionLayout.Adapter adapter) {
throwIf(adapter == null, new IllegalArgumentException("SegmentedControl#setAdapter -> adapter can't be null"));
}
static void columnCount(int columnCount) {
throwIf(columnCount < Configs.DEFAULT_COLUMN_COUNT,
new IllegalArgumentException("SegmentedControl#setColumnCount -> columnCounts value is invalid:" + " " + "columnCount = " + columnCount));
}
static void outOfBounds(int position, int size, String methodName) {
throwIf(position > size, new IndexOutOfBoundsException(methodName + " -> " + "position = " + position + " " + "size = " + size));
}
private static void throwIf(boolean willThrow, Exception exception) {
if (willThrow) {
try {
throw exception;
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void supportedSelectionsCount(int supportedSelectionsCount) {
throwIf(supportedSelectionsCount < Configs.DEFAULT_SUPPORTED_SELECTIONS_COUNT,
new IllegalStateException("SegmentedControl#setSupportedSelectionsCount -> supportedSelectionsCount value is invalid: " +
" " + "supportedSelectionsCount= "+supportedSelectionsCount));
}
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Configs.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentDecoration;
/**
* Created by Robert Apikyan on 9/7/2017.
*/
class Configs {
static final int DEFAULT_COLUMN_COUNT = 2;
static final int DEFAULT_SUPPORTED_SELECTIONS_COUNT = 1;
boolean willDistributeEvenly;
boolean reselectionEnabled;
int columnCount;
int supportedSelectionsCount;
SegmentDecoration segmentDecoration = new SegmentDecoration();
static Configs getDefault() {
Configs configs = new Configs();
configs.reselectionEnabled = true;
configs.willDistributeEvenly = false;
configs.columnCount = DEFAULT_COLUMN_COUNT;
configs.supportedSelectionsCount = DEFAULT_SUPPORTED_SELECTIONS_COUNT;
return configs;
}
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Consumer.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol;
/**
* Created by Robert Apikyan on 9/8/2017.
*/
interface Consumer<T> {
void apply(T t);
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Notifier.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol;
import java.util.ArrayList;
import java.util.List;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentViewHolder;
import segmented_control.widget.custom.android.com.segmentedcontrol.listeners.OnSegmentClickListener;
import segmented_control.widget.custom.android.com.segmentedcontrol.listeners.OnSegmentSelectRequestListener;
import segmented_control.widget.custom.android.com.segmentedcontrol.listeners.OnSegmentSelectedListener;
import static segmented_control.widget.custom.android.com.segmentedcontrol.utils.Utils.lazy;
/**
* Created by Robert Apikyan on 9/8/2017.
*/
class Notifier<D> implements OnSegmentClickListener<D>, OnSegmentSelectedListener<D>, OnSegmentSelectRequestListener<D> {
private List<OnSegmentClickListener<D>> onSegmentClickListeners;
private List<OnSegmentSelectedListener<D>> onSegmentSelectedListeners;
@SuppressWarnings("unchecked")
private OnSegmentSelectRequestListener<D> onSegmentSelectRequestListener;
@Override
public void onSegmentClick(final SegmentViewHolder<D> segmentViewHolder) {
onEvent(onSegmentClickListeners, new Consumer<OnSegmentClickListener<D>>() {
@Override
public void apply(OnSegmentClickListener<D> onSegmentClickListener) {
onSegmentClickListener.onSegmentClick(segmentViewHolder);
}
});
}
@Override
public void onSegmentSelected(final SegmentViewHolder<D> segmentViewHolder, final boolean isSelected, final boolean isReselected) {
onEvent(onSegmentSelectedListeners, new Consumer<OnSegmentSelectedListener<D>>() {
@Override
public void apply(OnSegmentSelectedListener<D> onSegmentSelectedListener) {
onSegmentSelectedListener.onSegmentSelected(segmentViewHolder, isSelected, isReselected);
}
});
}
@Override
public boolean onSegmentSelectRequest(final SegmentViewHolder<D> segmentViewHolder) {
return onSegmentSelectRequestListener == null || onSegmentSelectRequestListener.onSegmentSelectRequest(segmentViewHolder);
}
void addOnSegmentClickListener(OnSegmentClickListener<D> onSegmentClickListener) {
onSegmentClickListeners = lazy(onSegmentClickListeners, new ArrayList<OnSegmentClickListener<D>>());
onSegmentClickListeners.add(onSegmentClickListener);
}
void removeOnSegmentClickListener(OnSegmentClickListener<D> onSegmentClickListener) {
onSegmentClickListeners = lazy(onSegmentClickListeners, new ArrayList<OnSegmentClickListener<D>>());
onSegmentClickListeners.remove(onSegmentClickListener);
}
void addOnSegmentSelectListener(OnSegmentSelectedListener<D> onSegmentSelectedListener) {
onSegmentSelectedListeners = lazy(onSegmentSelectedListeners, new ArrayList<OnSegmentSelectedListener<D>>());
onSegmentSelectedListeners.add(onSegmentSelectedListener);
}
void removeOnSegmentSelectListener(OnSegmentSelectedListener<D> onSegmentSelectedListener) {
onSegmentSelectedListeners = lazy(onSegmentSelectedListeners, new ArrayList<OnSegmentSelectedListener<D>>());
onSegmentSelectedListeners.remove(onSegmentSelectedListener);
}
void setOnSegmentSelectRequestListener(OnSegmentSelectRequestListener<D> onSegmentSelectRequestListener) {
this.onSegmentSelectRequestListener = onSegmentSelectRequestListener;
}
private <T> void onEvent(List<T> eventListeners, Consumer<T> listenerConsumer) {
if (eventListeners != null && eventListeners.size() != 0) {
for (T t : eventListeners) {
listenerConsumer.apply(t);
}
}
}
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentConsumer.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentViewHolder;
public interface SegmentConsumer<D> {
void apply(SegmentViewHolder<D> segmentViewHolder);
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControl.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import java.util.List;
import section_layout.widget.custom.android.com.sectionlayout.SectionLayout;
import segmented_control.widget.custom.android.com.segmented_control.R;
import segmented_control.widget.custom.android.com.segmentedcontrol.custom_segment.SegmentAdapterImpl;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentAdapter;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentViewHolder;
import segmented_control.widget.custom.android.com.segmentedcontrol.listeners.OnSegmentClickListener;
import segmented_control.widget.custom.android.com.segmentedcontrol.listeners.OnSegmentSelectRequestListener;
import segmented_control.widget.custom.android.com.segmentedcontrol.listeners.OnSegmentSelectedListener;
import view_component.lib_android.com.view_component.base_view.layouts.ComponentFrameLayout;
import static segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentDecoration.DEFAULT_SELECTION_ANIMATION_DURATION;
/**
* Created by Robert Apikyan on 8/18/2017.
* /* Attributes
* <attr name="distributeEvenly" format="boolean" /> {@link #setDistributeEvenly(boolean)}
* <attr name="reselectionEnabled" format="boolean" /> {@link #setReselectionEnabled(boolean)}
* <attr name="columnCount" format="integer" /> {@link #setColumnCount(int)}
* <attr name="segments" format="reference" /> {@link #addSegments(Object[])} {@link #addSegments(List)}
* <attr name="supportedSegmentsCount" format="reference"/> {@link #setSupportedSelectionsCount(int)}
* <attr name="selectedStrokeColor" format="color" /> {@link #setSelectedStrokeColor(int)}
* <attr name="unSelectedStrokeColor" format="color" /> {@link #setUnSelectedStrokeColor(int)}
* <attr name="strokeWidth" format="dimension" />{@link #setStrokeWidth(int)}
* <attr name="selectedBackgroundColor" format="color" /> {@link #setSelectedBackgroundColor(int)}
* <attr name="unSelectedBackgroundColor" format="color" /> {@link #setUnSelectedBackgroundColor(int)}
* <attr name="selectedTextColor" format="color"/> {@link #setSelectedTextColor(int)}
* <attr name="unSelectedTextColor" format="color"/> {@link #setUnSelectedTextColor(int)}
* <attr name="textSize" format="dimension"/> {@link #setTextSize(int)}
* <attr name="textHorizontalPadding" format="dimension"/> {@link #setTextHorizontalPadding(int)}
* <attr name="textVerticalPadding" format="dimension"/> {@link #setTextVerticalPadding(int)}
* <attr name="segmentVerticalMargin" format="dimension"/> {@link #setSegmentVerticalMargin(int)}
* <attr name="segmentHorizontalMargin" format="dimension"/> {@link #setSegmentHorizontalMargin(int)}
* <attr name="radius" format="dimension"/> {@link #setRadius(int)}
* <attr name="topLeftRadius" format="dimension"/> {@link #setTopLeftRadius(int)}
* <attr name="topRightRadius" format="dimension"/> {@link #setTopRightRadius(int)}
* <attr name="bottomRightRadius" format="dimension"/> {@link #setBottomRightRadius(int)}
* <attr name="bottomLeftRadius" format="dimension"/> {@link #setBottomLeftRadius(int)}
* <attr name="radiusForEverySegment" format="boolean"/> {@link #setRadiusForEverySegment(boolean)}
*
* @param <D>
*/
public class SegmentedControl<D> extends ComponentFrameLayout<SegmentedControlViewComponent<D>,
SegmentedControlControllerComponent<D>> {
public SegmentedControl(Context context) {
this(context, null);
}
public SegmentedControl(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SegmentedControl(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initAttr(attrs, defStyle);
}
private void initAttr(AttributeSet attrs, int defStyle) {
TypedArray typedArray = getContext().obtainStyledAttributes(attrs,
R.styleable.SegmentedControl,
defStyle, 0);
fetchAccentColor();
try {
attrDistributeEvenly(typedArray);
attrReselectionEnabled(typedArray);
attrColumnCount(typedArray);
attrSupportedSelectionsCount(typedArray);
attrSelectedStrokeColor(typedArray);
attrUnSelectedStrokeColor(typedArray);
attrStrokeWidth(typedArray);
attrSelectedBackgroundColor(typedArray);
attrFocusedBackgroundColor(typedArray);
attrSelectionAnimationDuration(typedArray);
attrUnSelectedBackgroundColor(typedArray);
attrSelectedTextColor(typedArray);
attrUnSelectedTextColor(typedArray);
attrTextSize(typedArray);
attrFontAssetPath(typedArray);
attrTextVerticalPadding(typedArray);
attrTextHorizontalPadding(typedArray);
attrSegmentHorizontalMargin(typedArray);
attrSegmentVerticalMargin(typedArray);
attrTopLeftRadius(typedArray);
attrTopRightRadius(typedArray);
attrBottomRightRadius(typedArray);
attrBottomLeftRadius(typedArray);
attrRadius(typedArray);
attrRadiusForEverySegment(typedArray);
attrSegments(typedArray);
} finally {
typedArray.recycle();
}
}
private void fetchAccentColor() {
TypedValue tv = new TypedValue();
TypedArray typedArray = getContext().obtainStyledAttributes(tv.data, new int[]{R.attr.colorAccent});
try {
getControllerComponent().setAccentColor(typedArray.getColor(0, 0));
} finally {
typedArray.recycle();
}
}
private void attrSelectedStrokeColor(TypedArray typedArray) {
obtainColorAttr(typedArray, R.styleable.SegmentedControl_selectedStrokeColor, new Consumer<Integer>() {
@Override
public void apply(Integer color) {
getControllerComponent().setSelectedStrokeColor(color);
}
});
}
private void attrUnSelectedStrokeColor(TypedArray typedArray) {
obtainColorAttr(typedArray, R.styleable.SegmentedControl_unSelectedStrokeColor, new Consumer<Integer>() {
@Override
public void apply(Integer color) {
getControllerComponent().setUnSelectedStrokeColor(color);
}
});
}
private void attrStrokeWidth(TypedArray typedArray) {
obtainDimensionAttr(typedArray, R.styleable.SegmentedControl_strokeWidth, new Consumer<Integer>() {
@Override
public void apply(Integer width) {
getControllerComponent().setStrokeWidth(width);
}
});
}
private void attrSelectedBackgroundColor(TypedArray typedArray) {
obtainColorAttr(typedArray, R.styleable.SegmentedControl_selectedBackgroundColor, new Consumer<Integer>() {
@Override
public void apply(Integer color) {
getControllerComponent().setSelectedBackgroundColor(color);
}
});
}
private void attrUnSelectedBackgroundColor(TypedArray typedArray) {
obtainColorAttr(typedArray, R.styleable.SegmentedControl_unSelectedBackgroundColor, new Consumer<Integer>() {
@Override
public void apply(Integer color) {
getControllerComponent().setUnSelectedBackgroundColor(color);
}
});
}
private void attrFocusedBackgroundColor(TypedArray typedArray) {
obtainColorAttr(typedArray, R.styleable.SegmentedControl_focusedBackgroundColor, new Consumer<Integer>() {
@Override
public void apply(Integer color) {
getControllerComponent().setFocusedBackgroundColor(color);
}
});
}
private void attrSelectionAnimationDuration(TypedArray typedArray) {
getControllerComponent().setSelectionAnimationDuration(
typedArray.getInt(R.styleable.SegmentedControl_selectionAnimationDuration,
DEFAULT_SELECTION_ANIMATION_DURATION));
}
private void attrSelectedTextColor(TypedArray typedArray) {
obtainColorAttr(typedArray, R.styleable.SegmentedControl_selectedTextColor, new Consumer<Integer>() {
@Override
public void apply(Integer color) {
getControllerComponent().setSelectedTextColor(color);
}
});
}
private void attrUnSelectedTextColor(TypedArray typedArray) {
obtainColorAttr(typedArray, R.styleable.SegmentedControl_unSelectedTextColor, new Consumer<Integer>() {
@Override
public void apply(Integer color) {
getControllerComponent().setUnSelectedTextColor(color);
}
});
}
private void attrTextSize(TypedArray typedArray) {
int textSize = typedArray.getDimensionPixelSize(R.styleable.SegmentedControl_textSize,
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 14,
getResources().getDisplayMetrics()));
if (textSize > 0) {
getControllerComponent().setTextSize(textSize);
}
}
private void attrFontAssetPath(TypedArray typedArray) {
String fontPath = typedArray.getString(R.styleable.SegmentedControl_fontAssetPath);
if (fontPath != null && !fontPath.isEmpty()) {
getControllerComponent().setTypeFace(Typeface.createFromAsset(getContext().getAssets(), fontPath));
}
}
private void attrTextVerticalPadding(TypedArray typedArray) {
obtainDimensionAttr(typedArray, R.styleable.SegmentedControl_textVerticalPadding, new Consumer<Integer>() {
@Override
public void apply(Integer dimen) {
getControllerComponent().setTextVerticalPadding(dimen);
}
});
}
private void attrTextHorizontalPadding(TypedArray typedArray) {
obtainDimensionAttr(typedArray, R.styleable.SegmentedControl_textHorizontalPadding, new Consumer<Integer>() {
@Override
public void apply(Integer dimen) {
getControllerComponent().setTextHorizontalPadding(dimen);
}
});
}
private void attrSegmentVerticalMargin(TypedArray typedArray) {
obtainDimensionAttr(typedArray, R.styleable.SegmentedControl_segmentVerticalMargin, new Consumer<Integer>() {
@Override
public void apply(Integer dimen) {
getControllerComponent().setSegmentVerticalMargin(dimen);
}
});
}
private void attrSegmentHorizontalMargin(TypedArray typedArray) {
obtainDimensionAttr(typedArray, R.styleable.SegmentedControl_segmentHorizontalMargin, new Consumer<Integer>() {
@Override
public void apply(Integer dimen) {
getControllerComponent().setSegmentHorizontalMargin(dimen);
}
});
}
private void attrRadius(TypedArray typedArray) {
obtainDimensionAttr(typedArray, R.styleable.SegmentedControl_radius, new Consumer<Integer>() {
@Override
public void apply(Integer dimen) {
getControllerComponent().setRadius(dimen);
}
});
}
private void attrTopLeftRadius(TypedArray typedArray) {
obtainDimensionAttr(typedArray, R.styleable.SegmentedControl_topLeftRadius, new Consumer<Integer>() {
@Override
public void apply(Integer dimen) {
getControllerComponent().setTopLeftRadius(dimen);
}
});
}
private void attrTopRightRadius(TypedArray typedArray) {
obtainDimensionAttr(typedArray, R.styleable.SegmentedControl_topRightRadius, new Consumer<Integer>() {
@Override
public void apply(Integer dimen) {
getControllerComponent().setTopRightRadius(dimen);
}
});
}
private void attrBottomRightRadius(TypedArray typedArray) {
obtainDimensionAttr(typedArray, R.styleable.SegmentedControl_bottomRightRadius, new Consumer<Integer>() {
@Override
public void apply(Integer dimen) {
getControllerComponent().setBottomRightRadius(dimen);
}
});
}
private void attrBottomLeftRadius(TypedArray typedArray) {
obtainDimensionAttr(typedArray, R.styleable.SegmentedControl_bottomLeftRadius, new Consumer<Integer>() {
@Override
public void apply(Integer dimen) {
getControllerComponent().setBottomLeftRadius(dimen);
}
});
}
private void attrRadiusForEverySegment(TypedArray typedArray) {
boolean radiusForEverySegment = typedArray.getBoolean(R.styleable.SegmentedControl_radiusForEverySegment, false);
getControllerComponent().setRadiusForEverySegment(radiusForEverySegment);
}
private void attrSegments(TypedArray typedArray) {
CharSequence[] items = typedArray.getTextArray(R.styleable.SegmentedControl_segments);
useDefaultAdapter();
//noinspection unchecked
getControllerComponent().addSegments((D[]) items);
}
private void attrColumnCount(TypedArray typedArray) {
int columnCount = typedArray.getInteger(R.styleable.SegmentedControl_columnCount, Configs.DEFAULT_COLUMN_COUNT);
getControllerComponent().setColumnCount(columnCount);
notifyConfigIsChanged();
}
private void attrSupportedSelectionsCount(TypedArray typedArray) {
int supportedSelectionsCount = typedArray.getInteger(R.styleable.SegmentedControl_supportedSelectionsCount, Configs.DEFAULT_SUPPORTED_SELECTIONS_COUNT);
if (supportedSelectionsCount > 0) {
getControllerComponent().setSupportedSelectionsCount(supportedSelectionsCount);
}
}
private void attrDistributeEvenly(TypedArray typedArray) {
boolean willDistribute = typedArray.getBoolean(R.styleable.SegmentedControl_distributeEvenly, false);
getControllerComponent().setDistributeEvenly(willDistribute);
getControllerComponent().notifyConfigIsChanged();
}
private void attrReselectionEnabled(TypedArray typedArray) {
boolean reselectionEnabled = typedArray.getBoolean(R.styleable.SegmentedControl_reselectionEnabled, true);
getControllerComponent().setReselectionEnabled(reselectionEnabled);
}
private void obtainColorAttr(TypedArray typedArray, int attr, Consumer<Integer> colorConsumer) {
int color = typedArray.getColor(attr, -2); // -1 is white
if (color != -2) {
colorConsumer.apply(color);
}
}
private void obtainDimensionAttr(TypedArray typedArray, int attr, Consumer<Integer> dimensionConsumer) {
int dimensionPixelSize = typedArray.getDimensionPixelSize(attr, -1);
if (dimensionPixelSize != -1) {
dimensionConsumer.apply(dimensionPixelSize);
}
}
@NonNull
@Override
public SegmentedControlViewComponent<D> createViewComponent(@NonNull LayoutInflater layoutInflater) {
addView(new SectionLayout<D>(getContext()), 0);
return new SegmentedControlViewComponent<>(this);
}
@NonNull
@Override
public SegmentedControlControllerComponent<D> createControllerComponent() {
return new SegmentedControlControllerComponent<>();
}
/**
* Will enabled multy selection, default value is 1, only one item can be selected at the time
* @param supportedSelectionsCount specifies the count of selected segments at the same time,
* if the selection count is reached the elder selection
* will be unselected
*/
public void setSupportedSelectionsCount(int supportedSelectionsCount) {
Assert.supportedSelectionsCount(supportedSelectionsCount);
getControllerComponent().setSupportedSelectionsCount(supportedSelectionsCount);
}
/**
* @param columnCount The column count for SegmentedControl
*/
public void setColumnCount(int columnCount) {
Assert.columnCount(columnCount);
getControllerComponent().setColumnCount(columnCount);
}
/**
* @param adapter, NonNull adapter (extended from {@link SegmentAdapter})
*/
public void setAdapter(@NonNull SegmentAdapter adapter) {
Assert.adapter(adapter);
getControllerComponent().setAdapter(adapter);
}
/**
* set the adapter {@link SegmentAdapter} with {@link segmented_control.widget.custom.android.com.segmentedcontrol.custom_segment.SegmentViewHolderImpl} view holder
* where data D data type is String. use segmentedControl.addSegments(String[] segmentDataArray) or segmentedControl.addSegments(List<String> segmentDataList) methods
*/
public void useDefaultAdapter() {
setAdapter(new SegmentAdapterImpl());
}
/**
* Add segments to segmentController
*
* @param segmentData, specified array Data type
*/
public void addSegments(D[] segmentData) {
getControllerComponent().addSegments(segmentData);
}
/**
* Add segments to segmentController
*
* @param segmentData, specified list Data type
*/
public void addSegments(List<D> segmentData) {
getControllerComponent().addSegments(segmentData);
}
/**
* @param willDistributeEvenly, true each section width with will be equal to each other,
* false each section width will be measured depending on its content width;
*/
public void setDistributeEvenly(boolean willDistributeEvenly) {
getControllerComponent().setDistributeEvenly(willDistributeEvenly);
}
/**
* @param isEnabled if true second click to segment will not turn it from selected to unselected state,
* if false the second click will turn it from selected to un selected state,
* default value is true
*/
public void setReselectionEnabled(boolean isEnabled) {
getControllerComponent().setReselectionEnabled(isEnabled);
}
/**
* @param onSegmentClickListener, every time click event will be notified,
* even if the segment is already selected
*/
public void addOnSegmentClickListener(OnSegmentClickListener<D> onSegmentClickListener) {
getControllerComponent().addOnSegmentClickListener(onSegmentClickListener);
}
/**
* @param onSegmentClickListener, every time click event will be notified,
* even if the segment is already selected
* <p>
* Remove listener
*/
public void removeOnSegmentClickListener(OnSegmentClickListener<D> onSegmentClickListener) {
getControllerComponent().removeOnSegmentClickListener(onSegmentClickListener);
}
/**
* @param onSegmentSelectedListener, event will be notified, when segment is selected and unSelected and reselected,
* for more info check out {@link OnSegmentSelectedListener} class
*/
public void addOnSegmentSelectListener(OnSegmentSelectedListener<D> onSegmentSelectedListener) {
getControllerComponent().addOnSegmentSelectListener(onSegmentSelectedListener);
}
/**
* @param onSegmentSelectedListener, event will be notified, when segment is selected and unSelected and reselected,
* for more info check out {@link OnSegmentSelectedListener} class
* <p>
* Remove listener
*/
public void removeOnSegmentSelectListener(OnSegmentSelectedListener<D> onSegmentSelectedListener) {
getControllerComponent().removeOnSegmentSelectListener(onSegmentSelectedListener);
}
/**
* @param onSegmentSelectRequestListener, event will be triggered after click event and before selection event
* for more info click out {@link OnSegmentSelectRequestListener} class
*/
public void setOnSegmentSelectRequestListener(OnSegmentSelectRequestListener<D> onSegmentSelectRequestListener) {
getControllerComponent().setOnSegmentSelectRequestListener(onSegmentSelectRequestListener);
}
/**
* Removes all segments
*/
public void removeAllSegments() {
getControllerComponent().removeAllSegments();
}
/**
* find the segment view holder with the segment absolute position
*
* @param position, the segment position
* @return SegmentViewHolder instance for specified position
*/
public SegmentViewHolder<D> findSegmentByAbsolutePosition(int position) {
Assert.outOfBounds(position, size(), "SegmentedControl#findSegmentByAbsolutePosition");
return getControllerComponent().findSegmentByAbsolutePosition(position);
}
/**
* find the segment with column number and row position
*
* @param column, Segment column number
* @param row, Segment row position
* @return SegmentViewHolder instance for specified column and row numbers
*/
public SegmentViewHolder<D> findSegmentByColumnAndRow(int column, int row) {
Assert.outOfBounds(getControllerComponent().getAbsolutePosition(column, row), size(), "SegmentedControl#setSelectedSegment");
return getControllerComponent().findSegmentByColumnAndRow(column, row);
}
/**
* Select the selected position
*
* @param position, Segment position
*/
public void setSelectedSegment(int position) {
Assert.outOfBounds(position, size(), "SegmentedControl#setSelectedSegment");
getControllerComponent().setSelectedSegment(position);
}
/**
* Select the segment with specified column number and row position
*
* @param column, Segment column number
* @param row, Segment row position
*/
public void setSelectedSegment(int column, int row) {
Assert.outOfBounds(getControllerComponent().getAbsolutePosition(column, row), size(), "SegmentedControl#setSelectedSegment");
getControllerComponent().setSelectedSegment(column, row);
}
/**
* Iterate on segments, and pass the view holders as an argument for {@link SegmentConsumer}
*
* @param segmentConsumer, Segment consumer
*/
public void forEachSegment(SegmentConsumer<D> segmentConsumer) {
getControllerComponent().forEachSegment(segmentConsumer);
}
public void setSelectedStrokeColor(int color) {
getControllerComponent().setSelectedStrokeColor(color);
}
public void setUnSelectedStrokeColor(int color) {
getControllerComponent().setUnSelectedStrokeColor(color);
}
public void setFocusedBackgroundColor(int color) {
getControllerComponent().setFocusedBackgroundColor(color);
}
/**
* Set segments selection animation duration value
*
* @param duration in milliseconds
*/
public void setSelectionAnimationDuration(int duration) {
getControllerComponent().setSelectionAnimationDuration(duration);
}
public void setStrokeWidth(int width) {
getControllerComponent().setStrokeWidth(width);
}
public void setSelectedBackgroundColor(int color) {
getControllerComponent().setSelectedBackgroundColor(color);
}
public void setUnSelectedBackgroundColor(int color) {
getControllerComponent().setUnSelectedBackgroundColor(color);
}
public void setSelectedTextColor(int color) {
getControllerComponent().setSelectedTextColor(color);
}
public void setUnSelectedTextColor(int color) {
getControllerComponent().setUnSelectedTextColor(color);
}
public void setTextSize(int textSize) {
getControllerComponent().setTextSize(textSize);
}
public void setTypeFace(Typeface typeFace) {
getControllerComponent().setTypeFace(typeFace);
}
public void setTextVerticalPadding(int padding) {
getControllerComponent().setTextVerticalPadding(padding);
}
public void setTextHorizontalPadding(int padding) {
getControllerComponent().setTextHorizontalPadding(padding);
}
public void setSegmentVerticalMargin(int margin) {
getControllerComponent().setSegmentVerticalMargin(margin);
}
public void setSegmentHorizontalMargin(int margin) {
getControllerComponent().setSegmentHorizontalMargin(margin);
}
public void setRadius(int radius) {
getControllerComponent().setRadius(radius);
}
public void setTopLeftRadius(int radius) {
getControllerComponent().setTopLeftRadius(radius);
}
public void setTopRightRadius(int radius) {
getControllerComponent().setTopRightRadius(radius);
}
public void setBottomRightRadius(int radius) {
getControllerComponent().setBottomRightRadius(radius);
}
public void setBottomLeftRadius(int radius) {
getControllerComponent().setBottomLeftRadius(radius);
}
/**
* @param radiusForEverySegment, true every segment corners will be rounded, false only top left,top right, bottom right and bottom left corners will be rounded
*/
public void setRadiusForEverySegment(boolean radiusForEverySegment) {
getControllerComponent().setRadiusForEverySegment(radiusForEverySegment);
}
/**
* Removes the last selected segment selection, SegmentViewHolder's onSegmentSelected method will be called
* with isSelected = false, isReselected = false
*/
public void clearSelection() {
getControllerComponent().clearSelection(false);
}
/**
* Removes the last selected segment selection, SegmentViewHolder's onSegmentSelected method will be called
* with isSelected = false, isReselected = false.
*
* @param notifySegmentSelectedListener if true SegmentSelectedListeners will be notified.
*/
public void clearSelection(boolean notifySegmentSelectedListener) {
getControllerComponent().clearSelection(notifySegmentSelectedListener);
}
/**
* Call this method after every configuration change
* setColumnCount, setRadius et...
*/
public void notifyConfigIsChanged() {
getControllerComponent().notifyConfigIsChanged();
}
public int size() {
return getControllerComponent().size();
}
// public SegmentViewHolder<D> getSelectedViewHolder() {
// return getControllerComponent().getSelectedViewHolder();
// }
/**
* @return int[]{column,row} Section column and row numbers
*/
public int[] getLastSelectedColumnAndRow() {
return getControllerComponent().getLastSelectedColumnAndRow();
}
public int getLastSelectedAbsolutePosition() {
return getControllerComponent().getLastSelectedAbsolutePosition();
}
public boolean hasSelectedSegment() {
return getControllerComponent().isSelected();
}
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlControllerComponent.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol;
import android.graphics.Typeface;
import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import section_layout.widget.custom.android.com.sectionlayout.SectionLayout;
import section_layout.widget.custom.android.com.sectionlayout.distributive_section_layout.DistributiveSectionLayout;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row.SegmentRowAdapter;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row.SegmentRowViewHolder;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentAdapter;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentData;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentDecoration;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentViewHolder;
import segmented_control.widget.custom.android.com.segmentedcontrol.listeners.OnSegmentClickListener;
import segmented_control.widget.custom.android.com.segmentedcontrol.listeners.OnSegmentSelectRequestListener;
import segmented_control.widget.custom.android.com.segmentedcontrol.listeners.OnSegmentSelectedListener;
import view_component.lib_android.com.view_component.base_view.ControllerComponent;
/**
* Created by Robert Apikyan on 9/5/2017.
*/
class SegmentedControlControllerComponent<D> extends ControllerComponent<SegmentedControlViewComponent<D>> {
private final Configs configs = Configs.getDefault();
// private SegmentViewHolder<D> lastClickedSegmentViewHolder;
private LinkedList<SegmentViewHolder<D>> selectedSegments = new LinkedList<>();
private final Notifier<D> notifier = new Notifier<>();
private final List<D> dataList = new ArrayList<>();
// private final OnSegmentClickListener<D> _onSegmentClickListener = new OnSegmentClickListener<D>() {
// @Override
// public void onSegmentClick(SegmentViewHolder<D> segmentViewHolder) {
// notifier.onSegmentClick(segmentViewHolder);
//
// if (segmentViewHolder.equals(lastClickedSegmentViewHolder)) {
// // on section reselected
// segmentViewHolder.setSelected(true);
// notifier.onSegmentSelected(segmentViewHolder, true, true);
// } else if (notifier.onSegmentSelectRequest(segmentViewHolder)) {
// // on section selected
// // unSelect the last one
// if (lastClickedSegmentViewHolder != null) {
// lastClickedSegmentViewHolder.setSelected(false);
// notifier.onSegmentSelected(lastClickedSegmentViewHolder, false, false);
// }
// // select the current
// lastClickedSegmentViewHolder = segmentViewHolder;
// segmentViewHolder.setSelected(true);
// notifier.onSegmentSelected(segmentViewHolder, true, false);
// }
// }
// };
private final OnSegmentClickListener<D> onSegmentClickListener = new OnSegmentClickListener<D>() {
@Override
public void onSegmentClick(SegmentViewHolder<D> segmentViewHolder) {
notifier.onSegmentClick(segmentViewHolder);
int index = selectedSegments.indexOf(segmentViewHolder);
boolean contains = index != -1;
if (contains) {
// on section reselected
SegmentViewHolder<D> viewHolder = selectedSegments.get(index);
if (configs.reselectionEnabled){
viewHolder.setSelected(true);
notifier.onSegmentSelected(segmentViewHolder, true, true);
}else{
selectedSegments.remove(index);
viewHolder.setSelected(false);
notifier.onSegmentSelected(segmentViewHolder, false, false);
}
} else if (notifier.onSegmentSelectRequest(segmentViewHolder)) {
// on section selected
// unSelect the last one
SegmentViewHolder<D> lastSelected = addSelectedSegmentViewHolder(segmentViewHolder);
if (lastSelected != null) {
lastSelected.setSelected(false);
notifier.onSegmentSelected(lastSelected, false, false);
}
// select the current
segmentViewHolder.setSelected(true);
notifier.onSegmentSelected(segmentViewHolder, true, false);
}
}
};
/**
* 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<D> addSelectedSegmentViewHolder(SegmentViewHolder<D> segmentViewHolder) {
selectedSegments.add(segmentViewHolder);
if (selectedSegments.size() > configs.supportedSelectionsCount) {
return selectedSegments.remove(0);
}
return null;
}
private SegmentViewHolder<D> getLastSelectedViewHolder() {
return selectedSegments.size() > 0 ? selectedSegments.getLast() : null;
}
private void addSegment(D segmentData) {
if (getVerticalSectionLayout().size() == 0 || !canAddToLastRow()) {
addNewRow();
}
addSegmentToLastRow(segmentData);
}
// removeLastSelected = true
// private void removeAllSegments(boolean removeLastSelected) {
// for (int row = 0; row < getVerticalSectionLayout().size(); row++) {
// getHorizontalSectionLayout(row).removeAllSections();
// }
// getVerticalSectionLayout().removeAllSections();
// dataList.clear();
//
// if (removeLastSelected) {
// lastClickedSegmentViewHolder = null;
// }
// }
private void removeAllSegments(boolean removeLastSelected) {
for (int row = 0; row < getVerticalSectionLayout().size(); row++) {
getHorizontalSectionLayout(row).removeAllSections();
}
getVerticalSectionLayout().removeAllSections();
dataList.clear();
if (removeLastSelected) {
selectedSegments.clear();
}
}
private void addSegmentToLastRow(D segmentData) {
DistributiveSectionLayout<SegmentData<D>> horizontalSectionLayout = getHorizontalSectionLayout(getLastRowIndex());
horizontalSectionLayout
.addSection(SegmentData.create(segmentData, onSegmentClickListener, getAbsolutePosition(getLastHorizontalSectionLayout().size(),
getVerticalSectionLayout().size() - 1), getLastRowIndex(), horizontalSectionLayout.size(), size(), configs.columnCount, configs.segmentDecoration));
horizontalSectionLayout.requestLayout();
}
private int[] getRowAndColumnWithAbsolutePosition(int position) {
int smallDiff = position % configs.columnCount;
int diff = position - smallDiff;
int row = (diff / configs.columnCount) + (smallDiff == configs.columnCount ? 1 : 0);
int column = position % configs.columnCount;
return new int[]{row, column};
}
void notifyConfigIsChanged() {
recreate(false);
}
// public void clearSelection(boolean notifySegmentSelectedListener) {
// if (lastClickedSegmentViewHolder != null) {
// lastClickedSegmentViewHolder.setSelected(false);
//
// if (notifySegmentSelectedListener) {
// notifier.onSegmentSelected(lastClickedSegmentViewHolder, false, false);
// }
//
// lastClickedSegmentViewHolder = null;
// }
// }
public void clearSelection(boolean notifySegmentSelectedListener) {
if (!selectedSegments.isEmpty()) {
for (SegmentViewHolder<D> selectedSegment : selectedSegments) {
selectedSegment.setSelected(false);
if (notifySegmentSelectedListener) {
notifier.onSegmentSelected(selectedSegment, false, false);
}
}
selectedSegments.clear();
}
}
// private void recreate(boolean removeLastSelected) {
// if (dataList.size() == 0) return;
// List<D> itemsData = new ArrayList<>(dataList);
// removeAllSegments(removeLastSelected);
// addSegments(itemsData);
// if (lastClickedSegmentViewHolder != null) {
// setSelectedSegment(lastClickedSegmentViewHolder.getAbsolutePosition());
// }
// }
private void recreate(boolean removeLastSelected) {
if (dataList.size() == 0) return;
List<D> itemsData = new ArrayList<>(dataList);
removeAllSegments(removeLastSelected);
addSegments(itemsData);
SegmentViewHolder<D> lastSelection = getLastSelectedViewHolder();
if (lastSelection != null) {
setSelectedSegment(lastSelection.getAbsolutePosition());
}
}
private boolean canAddToLastRow() {
return getHorizontalSectionLayout(getLastRowIndex()).size() < configs.columnCount;
}
private void addNewRow() {
//noinspection unchecked
getVerticalSectionLayout().addSection(configs.willDistributeEvenly);
}
private SectionLayout getVerticalSectionLayout() {
//noinspection ConstantConditions
return getViewComponent().verticalSectionLayout;
}
private DistributiveSectionLayout<SegmentData<D>> getHorizontalSectionLayout(int row) {
//noinspection unchecked
SegmentRowViewHolder<D> segmentedViewHolder = (SegmentRowViewHolder<D>) getVerticalSectionLayout().getViewHolderForAdapterPosition(row);
return segmentedViewHolder.getDistributiveSectionLayout();
}
private DistributiveSectionLayout<SegmentData<D>> getLastHorizontalSectionLayout() {
return getHorizontalSectionLayout(getLastRowIndex());
}
private int getLastRowIndex() {
return getVerticalSectionLayout().size() - 1;
}
SegmentViewHolder<D> findSegmentByAbsolutePosition(int position) {
int[] point = getRowAndColumnWithAbsolutePosition(position);
return findSegmentByColumnAndRow(point[0], point[1]);
}
SegmentViewHolder<D> findSegmentByColumnAndRow(int column, int row) {
return (SegmentViewHolder<D>) getHorizontalSectionLayout(column).getViewHolderForAdapterPosition(row);
}
void forEachSegment(SegmentConsumer<D> segmentConsumer) {
for (int row = 0; row < getVerticalSectionLayout().size(); row++) {
DistributiveSectionLayout<SegmentData<D>> horizontalSectionLayout = getHorizontalSectionLayout(row);
for (int column = 0; column < horizontalSectionLayout.size(); column++) {
segmentConsumer.apply(findSegmentByColumnAndRow(row, column));
}
}
}
void setAccentColor(int color) {
configs.segmentDecoration = SegmentDecoration.createDefault(getContext(), color);
}
void setSelectedStrokeColor(int color) {
configs.segmentDecoration.selectedStrokeColor = color;
}
void setUnSelectedStrokeColor(int color) {
configs.segmentDecoration.unSelectedStrokeColor = color;
}
void setStrokeWidth(int width) {
configs.segmentDecoration.strokeWidth = width;
}
void setSelectedBackgroundColor(int color) {
configs.segmentDecoration.selectBackgroundColor = color;
}
void setUnSelectedBackgroundColor(int color) {
configs.segmentDecoration.unSelectedBackgroundColor = color;
}
void setFocusedBackgroundColor(int color) {
configs.segmentDecoration.focusedBackgroundColor = color;
}
void setReselectionEnabled(boolean isEnabled){
configs.reselectionEnabled = isEnabled;
}
void setSelectionAnimationDuration(int duration) {
configs.segmentDecoration.selectionAnimationDuration = duration;
}
void setSelectedTextColor(int color) {
configs.segmentDecoration.selectedTextColor = color;
}
void setUnSelectedTextColor(int color) {
configs.segmentDecoration.unSelectedTextColor = color;
}
void setTextSize(int textSize) {
configs.segmentDecoration.textSize = textSize;
}
void setTypeFace(Typeface typeFace) {
configs.segmentDecoration.typeface = typeFace;
}
void setTextVerticalPadding(int padding) {
configs.segmentDecoration.textVerticalPadding = padding;
}
void setTextHorizontalPadding(int padding) {
configs.segmentDecoration.textHorizontalPadding = padding;
}
void setSegmentVerticalMargin(int margin) {
configs.segmentDecoration.segmentVerticalMargin = margin;
}
void setSegmentHorizontalMargin(int margin) {
configs.segmentDecoration.segmentHorizontalMargin = margin;
}
void setRadius(int radius) {
setTopLeftRadius(radius);
setTopRightRadius(radius);
setBottomRightRadius(radius);
setBottomLeftRadius(radius);
}
void setTopLeftRadius(int radius) {
configs.segmentDecoration.topLeftRadius = radius;
}
void setTopRightRadius(int radius) {
configs.segmentDecoration.topRightRadius = radius;
}
void setBottomRightRadius(int radius) {
configs.segmentDecoration.bottomRightRadius = radius;
}
void setBottomLeftRadius(int radius) {
configs.segmentDecoration.bottomLeftRadius = radius;
}
void setRadiusForEverySegment(boolean radiusForEverySegment) {
configs.segmentDecoration.radiusForEverySegment = radiusForEverySegment;
}
void setAdapter(SegmentAdapter adapter) {
//noinspection ConstantConditions, setAdapter will be called from SegmentedControl
getViewComponent().verticalSectionLayout.withAdapter(new SegmentRowAdapter(adapter));
}
void addSegments(D[] segmentDataArray) {
if (segmentDataArray == null || segmentDataArray.length == 0) return;
addSegments(new ArrayList<>(Arrays.asList(segmentDataArray)));
}
void addSegments(List<D> segmentDataList) {
if (segmentDataList == null || segmentDataList.size() == 0) return;
dataList.addAll(new ArrayList<>(segmentDataList));
for (D segmentData : dataList) {
addSegment(segmentData);
}
}
void removeAllSegments() {
removeAllSegments(true);
}
void setDistributeEvenly(boolean willDistributeEvenly) {
configs.willDistributeEvenly = willDistributeEvenly;
}
void setSupportedSelectionsCount(int supportedSelectionsCount) {
configs.supportedSelectionsCount = supportedSelectionsCount;
}
void setColumnCount(int columnCount) {
configs.columnCount = columnCount;
}
void addOnSegmentClickListener(OnSegmentClickListener<D> onSegmentClickListener) {
notifier.addOnSegmentClickListener(onSegmentClickListener);
}
void removeOnSegmentClickListener(OnSegmentClickListener<D> onSegmentClickListener) {
notifier.removeOnSegmentClickListener(onSegmentClickListener);
}
void addOnSegmentSelectListener(OnSegmentSelectedListener<D> onSegmentSelectedListener) {
notifier.addOnSegmentSelectListener(onSegmentSelectedListener);
}
void removeOnSegmentSelectListener(OnSegmentSelectedListener<D> onSegmentSelectedListener) {
notifier.removeOnSegmentSelectListener(onSegmentSelectedListener);
}
void setOnSegmentSelectRequestListener(OnSegmentSelectRequestListener<D> onSegmentSelectRequestListener) {
notifier.setOnSegmentSelectRequestListener(onSegmentSelectRequestListener);
}
void setSelectedSegment(int absolutePosition) {
int[] point = getRowAndColumnWithAbsolutePosition(absolutePosition);
setSelectedSegment(point[0], point[1]);
}
void setSelectedSegment(int column, int row) {
onSegmentClickListener.onSegmentClick(findSegmentByColumnAndRow(column, row));
}
// SegmentViewHolder<D> getSelectedViewHolder() {
// return lastClickedSegmentViewHolder;
// }
List<SegmentViewHolder<D>> getSelectedViewHolders() {
return selectedSegments;
}
int[] getLastSelectedColumnAndRow() {
SegmentViewHolder<D> lastSelection = getLastSelectedViewHolder();
if (lastSelection != null) {
return new int[]{lastSelection.getColumn(), lastSelection.getRow()};
} else {
return new int[]{-1, -1};
}
}
//
int getLastSelectedAbsolutePosition() {
SegmentViewHolder<D> lastSelection = getLastSelectedViewHolder();
if (lastSelection != null) {
return lastSelection.getAbsolutePosition();
} else {
return -1;
}
}
// boolean isSelected() {
// return lastClickedSegmentViewHolder != null;
// }
boolean isSelected() {
return !selectedSegments.isEmpty();
}
int size() {
return dataList.size();
}
int getAbsolutePosition(int column, int row) {
return row * configs.columnCount + column;
}
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlViewComponent.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.LinearLayout;
import section_layout.widget.custom.android.com.sectionlayout.SectionLayout;
import view_component.lib_android.com.view_component.base_view.ViewComponent;
/**
* Created by Robert Apikyan on 9/5/2017.
*/
class SegmentedControlViewComponent<D> extends ViewComponent {
final SectionLayout<D> verticalSectionLayout;
SegmentedControlViewComponent(@NonNull View rootView) {
super(rootView);
//noinspection unchecked
verticalSectionLayout = (SectionLayout<D>) getRootViewGroup().getChildAt(0);
verticalSectionLayout.setOrientation(LinearLayout.VERTICAL);
}
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/custom_segment/SegmentAdapterImpl.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.custom_segment;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import segmented_control.widget.custom.android.com.segmented_control.R;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentAdapter;
/**
* Created by Robert Apikyan on 9/8/2017.
*/
public class SegmentAdapterImpl extends SegmentAdapter<CharSequence, SegmentViewHolderImpl> {
@NonNull
@Override
protected SegmentViewHolderImpl onCreateViewHolder(@NonNull LayoutInflater layoutInflater, ViewGroup viewGroup, int i) {
return new SegmentViewHolderImpl(layoutInflater.inflate(R.layout.item_segment_impl, null));
}
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/custom_segment/SegmentViewHolderImpl.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.custom_segment;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import segmented_control.widget.custom.android.com.segmented_control.R;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentViewHolder;
import static segmented_control.widget.custom.android.com.segmentedcontrol.utils.Utils.createBackgroundAnimation;
import static segmented_control.widget.custom.android.com.segmentedcontrol.utils.Utils.createRadius;
import static segmented_control.widget.custom.android.com.segmentedcontrol.utils.Utils.defineRadiusForPosition;
import static segmented_control.widget.custom.android.com.segmentedcontrol.utils.Utils.getBackground;
import static segmented_control.widget.custom.android.com.segmentedcontrol.utils.Utils.isInBounds;
/**
* Created by Robert Apikyan on 9/8/2017.
*/
public class SegmentViewHolderImpl extends SegmentViewHolder<CharSequence> {
private TextView itemTV;
private float[] radius;
private ValueAnimator va;
private int[] windowLocation;
private final ValueAnimator.AnimatorUpdateListener bgAnimListener = new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int colorArgb = (int) animation.getAnimatedValue();
Drawable bg = getBackground(getStrokeWidth(), isSelected() ? getSelectedStrokeColor() : getUnSelectedStrokeColor(), colorArgb, radius);
setBackground(bg);
}
};
@SuppressWarnings("FieldCanBeLocal")
private final View.OnTouchListener segmentTouchListener = new View.OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {
if (isSelected()) {
return false;
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
setBackground(getFocusedBackground());
} else if (event.getAction() == MotionEvent.ACTION_UP ||
event.getAction() == MotionEvent.ACTION_CANCEL ||
event.getAction() == MotionEvent.ACTION_POINTER_UP ||
event.getAction() == MotionEvent.ACTION_OUTSIDE) {
if (!isInBounds(event.getX(), event.getY(), windowLocation[0], windowLocation[1],
getSectionView().getMeasuredWidth(), getSectionView().getMeasuredHeight())) {
setBackground(isSelected() ? getSelectedBackground() : getUnSelectedBackground());
}
}
return false;
}
};
public SegmentViewHolderImpl(@NonNull View sectionView) {
super(sectionView);
itemTV = sectionView.findViewById(R.id.item_segment_tv);
sectionView.setOnTouchListener(segmentTouchListener);
}
@Override
protected void onSegmentBind(CharSequence segmentData) {
initScreenLocation();
itemTV.setText(segmentData);
if (isRadiusForEverySegment()) {
radius = createRadius(getTopLeftRadius(), getTopRightRadius(), getBottomRightRadius(), getBottomLeftRadius());
} else {
radius = defineRadiusForPosition(getAbsolutePosition(), getColumnCount(), getCurrentSize(), getTopLeftRadius(), getTopRightRadius(), getBottomRightRadius(), getBottomLeftRadius());
}
setSectionDecorationSelected(false, false);
itemTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, getTextSize());
if (getTypeFace() != null) {
itemTV.setTypeface(getTypeFace());
}
itemTV.setPadding(getTextHorizontalPadding(), getTextVerticalPadding(), getTextHorizontalPadding(), getTextVerticalPadding());
((ViewGroup.MarginLayoutParams) itemTV.getLayoutParams()).setMargins(getSegmentHorizontalMargin(), getSegmentVerticalMargin(), getSegmentHorizontalMargin(), getSegmentVerticalMargin());
}
private void initScreenLocation() {
windowLocation = new int[2];
getSectionView().getLocationOnScreen(windowLocation);
}
@Override
public void onSegmentSelected(boolean isSelected, boolean isReselected) {
super.onSegmentSelected(isSelected, isReselected);
setSectionDecorationSelected(isSelected, isReselected);
}
private Drawable getSelectedBackground() {
return getBackground(getStrokeWidth(), getSelectedStrokeColor(), getSelectBackgroundColor(), radius);
}
private Drawable getUnSelectedBackground() {
return getBackground(getStrokeWidth(), getUnSelectedStrokeColor(), getUnSelectedBackgroundColor(), radius);
}
private Drawable getFocusedBackground() {
return getBackground(getStrokeWidth(), isSelected() ? getSelectedStrokeColor() : getUnSelectedStrokeColor(), getFocusedBackgroundColor(), radius);
}
private void setSectionDecorationSelected(boolean isSelected, boolean isReselected) {
if (isReselected)
return;
if (hasBackground()) {
animateNewBackground(isSelected);
} else {
setBackground(isSelected ? getSelectedBackground() : getUnSelectedBackground());
}
itemTV.setTextColor(isSelected ? getSelectedTextColor() : getUnSelectedTextColor());
}
private void animateNewBackground(boolean isSelected) {
if (va != null) {
va.end();
va.removeUpdateListener(bgAnimListener);
}
// animate
int startColor = isSelected ? getFocusedBackgroundColor() : getSelectBackgroundColor();
int endColor = isSelected ? getSelectBackgroundColor() : getUnSelectedBackgroundColor();
va = createBackgroundAnimation(startColor, endColor);
va.addUpdateListener(bgAnimListener);
va.setDuration(getSelectionAnimationDuration());
va.start();
}
private void setBackground(Drawable drawable) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
itemTV.setBackground(drawable);
} else {
//noinspection deprecation
itemTV.setBackgroundDrawable(drawable);
}
}
private boolean hasBackground() {
return itemTV.getBackground() != null;
}
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row/SegmentRowAdapter.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.item_row;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import section_layout.widget.custom.android.com.sectionlayout.SectionLayout;
import section_layout.widget.custom.android.com.sectionlayout.distributive_section_layout.DistributiveSectionLayout;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentAdapter;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentData;
/**
* Created by Robert Apikyan on 9/7/2017.
*/
public class SegmentRowAdapter<D> extends SectionLayout.Adapter<Boolean, SegmentRowViewHolder<SegmentData<D>>> {
private final SegmentAdapter segmentAdapter;
public SegmentRowAdapter(SegmentAdapter segmentAdapter) {
this.segmentAdapter = segmentAdapter;
}
@NonNull
@Override
protected SegmentRowViewHolder<SegmentData<D>> onCreateViewHolder(@NonNull LayoutInflater layoutInflater, ViewGroup viewGroup, int i) {
return new SegmentRowViewHolder<>(new DistributiveSectionLayout<SegmentData<D>>(layoutInflater.getContext()), segmentAdapter);
}
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row/SegmentRowViewHolder.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.item_row;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.LinearLayout;
import section_layout.widget.custom.android.com.sectionlayout.SectionLayout;
import section_layout.widget.custom.android.com.sectionlayout.distributive_section_layout.DistributiveSectionLayout;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentAdapter;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentData;
/**
* Created by Robert Apikyan on 9/7/2017.
*/
public class SegmentRowViewHolder<D> extends SectionLayout.ViewHolder<Boolean> {
private final DistributiveSectionLayout<SegmentData<D>> distributiveSectionLayout;
SegmentRowViewHolder(@NonNull View sectionView, SegmentAdapter segmentAdapter) {
super(sectionView);
//noinspection unchecked
distributiveSectionLayout = (DistributiveSectionLayout<SegmentData<D>>) sectionView;
distributiveSectionLayout.setOrientation(LinearLayout.HORIZONTAL);
distributiveSectionLayout.withAdapter(segmentAdapter);
}
@Override
protected void onBind(Boolean willDistributeEvenly) {
distributiveSectionLayout.distributeEvenly(willDistributeEvenly);
}
public DistributiveSectionLayout<SegmentData<D>> getDistributiveSectionLayout() {
return distributiveSectionLayout;
}
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentAdapter.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column;
import section_layout.widget.custom.android.com.sectionlayout.distributive_section_layout.DistributiveSectionLayout;
/**
* Created by Robert Apikyan on 9/7/2017.
*/
public abstract class SegmentAdapter<D, VH extends SegmentViewHolder<D>> extends DistributiveSectionLayout.Adapter<SegmentData<D>, VH> {
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentBackgroundType.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column;
import android.support.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import static segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentBackgroundType.BOTTOM_LEFT_BG;
import static segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentBackgroundType.BOTTOM_RIGHT_BG;
import static segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentBackgroundType.BOTTOM_SINGLE_BG;
import static segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentBackgroundType.MIDDLE_BG;
import static segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentBackgroundType.SINGLE_BG;
import static segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentBackgroundType.TOP_LEFT_BG;
import static segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentBackgroundType.TOP_LEFT_SINGLE_BG;
import static segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentBackgroundType.TOP_RIGHT_BG;
import static segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentBackgroundType.TOP_RIGHT_SINGLE_BG;
import static segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentBackgroundType.TOP_SINGLE_BG;
/**
* Created by Robert Apikyan on 9/12/2017.
*/
@IntDef(value = {SINGLE_BG,
TOP_SINGLE_BG,
TOP_LEFT_BG,
TOP_LEFT_SINGLE_BG,
TOP_RIGHT_SINGLE_BG,
TOP_RIGHT_BG,
MIDDLE_BG,
BOTTOM_SINGLE_BG,
BOTTOM_LEFT_BG,
BOTTOM_RIGHT_BG})
@Retention(RetentionPolicy.SOURCE)
public @interface SegmentBackgroundType {
int SINGLE_BG = 0;
int TOP_SINGLE_BG = 1;
int TOP_LEFT_BG = 2;
int TOP_LEFT_SINGLE_BG = 3;
int TOP_RIGHT_SINGLE_BG = 4;
int TOP_RIGHT_BG = 5;
int MIDDLE_BG = 6;
int BOTTOM_SINGLE_BG = 7;
int BOTTOM_LEFT_BG = 8;
int BOTTOM_RIGHT_BG = 9;
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentData.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column;
import android.graphics.Typeface;
import segmented_control.widget.custom.android.com.segmentedcontrol.listeners.OnSegmentClickListener;
/**
* Created by Robert Apikyan on 9/7/2017.
*/
public class SegmentData<D> {
boolean isSelected;
int absolutePosition;
private int row;
private int column;
private D segmentData;
private OnSegmentClickListener<D> onSegmentClickListener;
private SegmentDecoration segmentDecoration;
private int currentSize;
private int columnCount;
public static <D> SegmentData<D> create(D segmentData, OnSegmentClickListener<D> onSegmentClickListener, int absolutePosition, int row, int column, int currentSize, int columnCount, SegmentDecoration segmentDecoration) {
SegmentData<D> sd = new SegmentData<>();
sd.segmentData = segmentData;
sd.absolutePosition = absolutePosition;
sd.row = row;
sd.column = column;
sd.currentSize = currentSize;
sd.columnCount = columnCount;
sd.segmentDecoration = segmentDecoration;
sd.onSegmentClickListener = onSegmentClickListener;
return sd;
}
public boolean isSelected() {
return isSelected;
}
public int getAbsolutePosition() {
return absolutePosition;
}
public int getRow() {
return row;
}
public int getColumn() {
return column;
}
public D getSegmentData() {
return segmentData;
}
public OnSegmentClickListener<D> getOnSegmentClickListener() {
return onSegmentClickListener;
}
public int getSelectedStrokeColor() {
return segmentDecoration.getSelectedStrokeColor();
}
public int getUnSelectedStrokeColor() {
return segmentDecoration.getUnSelectedStrokeColor();
}
public int getStrokeWidth() {
return segmentDecoration.getStrokeWidth();
}
public int getSelectBackgroundColor() {
return segmentDecoration.getSelectBackgroundColor();
}
public int getUnSelectedBackgroundColor() {
return segmentDecoration.getUnSelectedBackgroundColor();
}
public int getFocusedBackgroundColor(){
return segmentDecoration.getFocusedBackgroundColor();
}
public int getSelectionAnimationDuration(){
return segmentDecoration.getSelectionAnimationDuration();
}
public int getSelectedTextColor() {
return segmentDecoration.getSelectedTextColor();
}
public int getUnSelectedTextColor() {
return segmentDecoration.getUnSelectedTextColor();
}
public int getTextSize() {
return segmentDecoration.getTextSize();
}
public Typeface getTypeFace(){
return segmentDecoration.getTypeface();
}
public int getTextHorizontalPadding() {
return segmentDecoration.getTextHorizontalPadding();
}
public int getTextVerticalPadding() {
return segmentDecoration.getTextVerticalPadding();
}
public int getSegmentVerticalMargin() {
return segmentDecoration.getSegmentVerticalMargin();
}
public int getSegmentHorizontalMargin() {
return segmentDecoration.getSegmentHorizontalMargin();
}
public int getTopLeftRadius() {
return segmentDecoration.getTopLeftRadius();
}
public int getTopRightRadius() {
return segmentDecoration.getTopRightRadius();
}
public int getBottomRightRadius() {
return segmentDecoration.getBottomRightRadius();
}
public int getBottomLeftRadius() {
return segmentDecoration.getBottomLeftRadius();
}
public boolean isRadiusForEverySegment() {
return segmentDecoration.isRadiusForEverySegment();
}
public int getCurrentSize() {
return currentSize;
}
public int getColumnCount() {
return columnCount;
}
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentDecoration.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.annotation.ColorInt;
import android.support.v4.content.ContextCompat;
/**
* Created by Robert Apikyan on 9/11/2017.
*/
public class SegmentDecoration {
public static final int DEFAULT_FOCUSED_BACKGROUND_ALPHA = 36;
public static final int DEFAULT_SELECTION_ANIMATION_DURATION = 196;
// segment decoration
// stroke
@ColorInt
public int selectedStrokeColor;
@ColorInt
public int unSelectedStrokeColor;
public int strokeWidth;
// background
@ColorInt
public int selectBackgroundColor;
@ColorInt
public int unSelectedBackgroundColor;
// focused segment background
public int focusedBackgroundColor;
// selection Animation Duration
public int selectionAnimationDuration;
// text
@ColorInt
public int selectedTextColor;
@ColorInt
public int unSelectedTextColor;
public int textSize;
// text padding
public int textHorizontalPadding;
public int textVerticalPadding;
// segment margins
public int segmentVerticalMargin;
public int segmentHorizontalMargin;
// segment font type
public Typeface typeface;
// radius
public int topLeftRadius;
public int topRightRadius;
public int bottomRightRadius;
public int bottomLeftRadius;
public boolean radiusForEverySegment = false; // def. value
public static SegmentDecoration createDefault(Context context, int accentColor) {
SegmentDecoration sd = new SegmentDecoration();
sd.selectedStrokeColor = accentColor;
sd.unSelectedStrokeColor = accentColor;
sd.selectBackgroundColor = accentColor;
sd.unSelectedBackgroundColor = ContextCompat.getColor(context, android.R.color.transparent);
sd.focusedBackgroundColor = Color.argb(DEFAULT_FOCUSED_BACKGROUND_ALPHA,
Color.red(accentColor),
Color.green(accentColor),
Color.blue(accentColor));
sd.selectionAnimationDuration = DEFAULT_SELECTION_ANIMATION_DURATION;
sd.selectedTextColor = ContextCompat.getColor(context, android.R.color.white);
sd.unSelectedTextColor = accentColor;
sd.strokeWidth = 1;
sd.typeface = null;
return sd;
}
public int getSelectedStrokeColor() {
return selectedStrokeColor;
}
public int getUnSelectedStrokeColor() {
return unSelectedStrokeColor;
}
public int getStrokeWidth() {
return strokeWidth;
}
public int getSelectBackgroundColor() {
return selectBackgroundColor;
}
public int getUnSelectedBackgroundColor() {
return unSelectedBackgroundColor;
}
public int getFocusedBackgroundColor() {
return focusedBackgroundColor;
}
public int getSelectionAnimationDuration() {
return selectionAnimationDuration;
}
public int getSelectedTextColor() {
return selectedTextColor;
}
public int getUnSelectedTextColor() {
return unSelectedTextColor;
}
public int getTextSize() {
return textSize;
}
public int getTextHorizontalPadding() {
return textHorizontalPadding;
}
public int getTextVerticalPadding() {
return textVerticalPadding;
}
public int getSegmentVerticalMargin() {
return segmentVerticalMargin;
}
public int getSegmentHorizontalMargin() {
return segmentHorizontalMargin;
}
public int getTopLeftRadius() {
return topLeftRadius;
}
public int getTopRightRadius() {
return topRightRadius;
}
public int getBottomRightRadius() {
return bottomRightRadius;
}
public int getBottomLeftRadius() {
return bottomLeftRadius;
}
public boolean isRadiusForEverySegment() {
return radiusForEverySegment;
}
public Typeface getTypeface() {
return typeface;
}
;
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentViewHolder.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.view.View;
import section_layout.widget.custom.android.com.sectionlayout.distributive_section_layout.DistributiveSectionLayout;
/**
* Created by Robert Apikyan on 9/7/2017.
*/
public abstract class SegmentViewHolder<D> extends DistributiveSectionLayout.ViewHolder<SegmentData<D>> {
private SegmentData<D> segmentData;
private final View.OnClickListener onSectionViewClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (segmentData != null)
segmentData.getOnSegmentClickListener().onSegmentClick(SegmentViewHolder.this);
}
};
public SegmentViewHolder(@NonNull View sectionView) {
super(sectionView);
}
@Override
protected final void onBind(SegmentData<D> segmentData) {
this.segmentData = segmentData;
getSectionView().setOnClickListener(onSectionViewClickListener);
onSegmentBind(segmentData.getSegmentData());
}
public final void setSelected(boolean isSelected) {
if (segmentData.isSelected() && isSelected) {
segmentData.isSelected = true;
onSegmentSelected(true, true);
} else if (isSelected) {
segmentData.isSelected = true;
onSegmentSelected(true, false);
} else {
segmentData.isSelected = false;
onSegmentSelected(false, false);
}
}
/**
* Override this method in order to define, performed action, selected, unselected, reselected
*
* @param isSelected, represent selected state
* @param isReselected, represent reselected state
*/
public void onSegmentSelected(boolean isSelected, boolean isReselected) {
}
public int getAbsolutePosition() {
return segmentData.absolutePosition;
}
public boolean isSelected() {
return segmentData.isSelected;
}
public int getRow() {
return segmentData.getRow();
}
public int getColumn() {
return segmentData.getColumn();
}
public D getSegmentData() {
return segmentData.getSegmentData();
}
public int getSelectedStrokeColor() {
return segmentData.getSelectedStrokeColor();
}
public int getUnSelectedStrokeColor() {
return segmentData.getUnSelectedStrokeColor();
}
public int getStrokeWidth() {
return segmentData.getStrokeWidth();
}
public int getSelectBackgroundColor() {
return segmentData.getSelectBackgroundColor();
}
public int getUnSelectedBackgroundColor() {
return segmentData.getUnSelectedBackgroundColor();
}
public int getFocusedBackgroundColor(){
return segmentData.getFocusedBackgroundColor();
}
public int getSelectionAnimationDuration(){
return segmentData.getSelectionAnimationDuration();
}
public int getSelectedTextColor() {
return segmentData.getSelectedTextColor();
}
public int getUnSelectedTextColor() {
return segmentData.getUnSelectedTextColor();
}
public int getTextSize() {
return segmentData.getTextSize();
}
public Typeface getTypeFace(){return segmentData.getTypeFace();}
public int getCurrentSize() {
return segmentData.getCurrentSize();
}
public int getColumnCount() {
return segmentData.getColumnCount();
}
public int getTextHorizontalPadding() {
return segmentData.getTextHorizontalPadding();
}
public int getTextVerticalPadding() {
return segmentData.getTextVerticalPadding();
}
public int getSegmentVerticalMargin() {
return segmentData.getSegmentVerticalMargin();
}
public int getSegmentHorizontalMargin() {
return segmentData.getSegmentHorizontalMargin();
}
public int getTopLeftRadius() {
return segmentData.getTopLeftRadius();
}
public int getTopRightRadius() {
return segmentData.getTopRightRadius();
}
public int getBottomRightRadius() {
return segmentData.getBottomRightRadius();
}
public int getBottomLeftRadius() {
return segmentData.getBottomLeftRadius();
}
public boolean isRadiusForEverySegment() {
return segmentData.isRadiusForEverySegment();
}
protected abstract void onSegmentBind(D segmentData);
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/listeners/OnSegmentClickListener.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.listeners;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentViewHolder;
/**
* Created by Robert Apikyan on 9/7/2017.
*/
public interface OnSegmentClickListener<D> {
/**
* @param segmentViewHolder, the clicked segment view holder instance
*/
void onSegmentClick(SegmentViewHolder<D> segmentViewHolder);
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/listeners/OnSegmentSelectRequestListener.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.listeners;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentViewHolder;
/**
* Created by Robert Apikyan on 9/12/2017.
*/
public interface OnSegmentSelectRequestListener<D> {
/**
* The event will be triggered before perform segment selection,and after segment click event
*
* @param segmentViewHolder, clicked segment view holder
* @return false segment selection will be ignored, true segment selection will be performed
*/
boolean onSegmentSelectRequest(SegmentViewHolder<D> segmentViewHolder);
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/listeners/OnSegmentSelectedListener.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.listeners;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentViewHolder;
/**
* Created by Robert Apikyan on 9/7/2017.
*/
public interface OnSegmentSelectedListener<D> {
/**
* The Event will be triggered: if the segment is selected, reselected and unSelected
* 1. Segment is selected for first time: isSelected = true ,isReselected = false
* 2. Segment is reselected: isSelected = true ,isReselected = true
* 3. Segment is unSelected: isSelected = false ,isReselected = false
*
* @param segmentViewHolder event related segmentViewHolder
* @param isSelected, true segment is selected
* @param isReselected, true segment is reselected
*/
void onSegmentSelected(SegmentViewHolder<D> segmentViewHolder, boolean isSelected, boolean isReselected);
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/utils/ArgbEvaluator.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.utils;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
public class ArgbEvaluator implements TypeEvaluator {
private static final android.animation.ArgbEvaluator sInstance = new android.animation.ArgbEvaluator();
/**
* Returns an instance of <code>ArgbEvaluator</code> that may be used in
* {@link ValueAnimator#setEvaluator(TypeEvaluator)}. The same instance may
* be used in multiple <code>Animator</code>s because it holds no state.
* @return An instance of <code>ArgbEvalutor</code>.
*
* @hide
*/
public static android.animation.ArgbEvaluator getInstance() {
return sInstance;
}
/**
* This function returns the calculated in-between value for a color
* given integers that represent the start and end values in the four
* bytes of the 32-bit int. Each channel is separately linearly interpolated
* and the resulting calculated values are recombined into the return value.
*
* @param fraction The fraction from the starting to the ending values
* @param startValue A 32-bit int value representing colors in the
* separate bytes of the parameter
* @param endValue A 32-bit int value representing colors in the
* separate bytes of the parameter
* @return A value that is calculated to be the linearly interpolated
* result, derived by separating the start and end values into separate
* color channels and interpolating each one separately, recombining the
* resulting values in the same way.
*/
public Object evaluate(float fraction, Object startValue, Object endValue) {
int startInt = (Integer) startValue;
float startA = ((startInt >> 24) & 0xff) / 255.0f;
float startR = ((startInt >> 16) & 0xff) / 255.0f;
float startG = ((startInt >> 8) & 0xff) / 255.0f;
float startB = ( startInt & 0xff) / 255.0f;
int endInt = (Integer) endValue;
float endA = ((endInt >> 24) & 0xff) / 255.0f;
float endR = ((endInt >> 16) & 0xff) / 255.0f;
float endG = ((endInt >> 8) & 0xff) / 255.0f;
float endB = ( endInt & 0xff) / 255.0f;
// convert from sRGB to linear
startR = (float) Math.pow(startR, 2.2);
startG = (float) Math.pow(startG, 2.2);
startB = (float) Math.pow(startB, 2.2);
endR = (float) Math.pow(endR, 2.2);
endG = (float) Math.pow(endG, 2.2);
endB = (float) Math.pow(endB, 2.2);
// compute the interpolated color in linear space
float a = startA + fraction * (endA - startA);
float r = startR + fraction * (endR - startR);
float g = startG + fraction * (endG - startG);
float b = startB + fraction * (endB - startB);
// convert back to sRGB in the [0..255] range
a = a * 255.0f;
r = (float) Math.pow(r, 1.0 / 2.2) * 255.0f;
g = (float) Math.pow(g, 1.0 / 2.2) * 255.0f;
b = (float) Math.pow(b, 1.0 / 2.2) * 255.0f;
return Math.round(a) << 24 | Math.round(r) << 16 | Math.round(g) << 8 | Math.round(b);
}
}
================================================
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/utils/Utils.java
================================================
package segmented_control.widget.custom.android.com.segmentedcontrol.utils;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.support.annotation.IntRange;
import android.view.View;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentBackgroundType;
import segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column.SegmentViewHolder;
/**
* Created by Robert Apikyan on 9/8/2017.
*/
public class Utils {
public static <T> T lazy(T nullable, T nonNull) {
if (nullable == null) {
nullable = nonNull;
}
return nullable;
}
/**
* Utility method, use to define segment background type
*
* @param absolutePosition, Segment absolute position from {@link SegmentViewHolder#getAbsolutePosition()}
* @param columnCount, from {@link SegmentViewHolder#getColumnCount()}
* @param size, from {@link SegmentViewHolder#getCurrentSize()}
* @return {@link SegmentBackgroundType}
*/
@SegmentBackgroundType
public static int defineSegmentBackground(@IntRange(from = 0) int absolutePosition, @IntRange(from = 1) int columnCount, @IntRange(from = 1) int size) {
// if only one item
if (size == 1) {
return SegmentBackgroundType.SINGLE_BG;
}
// if one column
if (columnCount == 1) {
// for first
if (absolutePosition == 0) {
return SegmentBackgroundType.TOP_SINGLE_BG;
}
// for last
if (absolutePosition == size - 1) {
return SegmentBackgroundType.BOTTOM_SINGLE_BG;
}
}
// if not one column, but one row
if (size <= columnCount) {
if (absolutePosition == 0) {
return SegmentBackgroundType.TOP_LEFT_SINGLE_BG;
}
if (absolutePosition == size - 1) {
return SegmentBackgroundType.TOP_RIGHT_SINGLE_BG;
}
}
// if not one column and multi row
if (absolutePosition == 0) {
return SegmentBackgroundType.TOP_LEFT_BG;
}
if (absolutePosition == columnCount - 1) {
return SegmentBackgroundType.TOP_RIGHT_BG;
}
int notCompletedRowItemsCount = size % columnCount;
int completeRowsItemsCount = size - notCompletedRowItemsCount;
if (notCompletedRowItemsCount == 1 && absolutePosition == completeRowsItemsCount) {
return SegmentBackgroundType.BOTTOM_SINGLE_BG;
}
if (notCompletedRowItemsCount == 0) {
if (absolutePosition == size - columnCount) {
return SegmentBackgroundType.BOTTOM_LEFT_BG;
}
if (absolutePosition == size - 1) {
return SegmentBackgroundType.BOTTOM_RIGHT_BG;
}
} else if (notCompletedRowItemsCount > 0) {
if (absolutePosition == size - notCompletedRowItemsCount) {
return SegmentBackgroundType.BOTTOM_LEFT_BG;
}
if (absolutePosition == size - 1) {
return SegmentBackgroundType.BOTTOM_RIGHT_BG;
}
}
return SegmentBackgroundType.MIDDLE_BG;
}
/**
* Use to define segment corner radius
*
* @param absolutePosition, Segment absolute position from {@link SegmentViewHolder#getAbsolutePosition()}
* @param columnCount, from {@link SegmentViewHolder#getColumnCount()}
* @param size, from {@link SegmentViewHolder#getCurrentSize()}
* @param topLeftRadius, from {@link SegmentViewHolder#getTopLeftRadius()}
* @param topRightRadius, from {@link SegmentViewHolder#getTopRightRadius()} ()}
* @param bottomRightRadius, from {@link SegmentViewHolder#getBottomRightRadius()}
* @param bottomLeftRadius, from {@link SegmentViewHolder#getBottomLeftRadius()}
* @return, float[] corners radius,
*/
public static float[] defineRadiusForPosition(@IntRange(from = 0) int absolutePosition, @IntRange(from = 1) int columnCount, @IntRange(from = 1) int size,
int topLeftRadius, int topRightRadius, int bottomRightRadius, int bottomLeftRadius) {
@SegmentBackgroundType
int bgType = defineSegmentBackground(absolutePosition, columnCount, size);
switch (bgType) {
case SegmentBackgroundType.BOTTOM_LEFT_BG:
return createRadius(0, 0, 0, bottomLeftRadius);
case SegmentBackgroundType.BOTTOM_RIGHT_BG:
return createRadius(0, 0, bottomRightRadius, 0);
case SegmentBackgroundType.BOTTOM_SINGLE_BG:
return createRadius(0, 0, bottomRightRadius, bottomLeftRadius);
case SegmentBackgroundType.MIDDLE_BG:
return createRadius(0, 0, 0, 0);
case SegmentBackgroundType.SINGLE_BG:
return createRadius(topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius);
case SegmentBackgroundType.TOP_LEFT_BG:
return createRadius(topLeftRadius, 0, 0, 0);
case SegmentBackgroundType.TOP_LEFT_SINGLE_BG:
return createRadius(topLeftRadius, 0, 0, bottomLeftRadius);
case SegmentBackgroundType.TOP_RIGHT_BG:
return createRadius(0, topRightRadius, 0, 0);
case SegmentBackgroundType.TOP_RIGHT_SINGLE_BG:
return createRadius(0, topRightRadius, bottomRightRadius, 0);
case SegmentBackgroundType.TOP_SINGLE_BG:
return createRadius(topLeftRadius, topRightRadius, 0, 0);
default:
return createRadius(0, 0, 0, 0);
}
}
public static float[] createRadius(float topLeft, float topRight, float bottomRight, float bottomLeft) {
return new float[]{topLeft, topLeft, topRight, topRight, bottomRight, bottomRight, bottomLeft, bottomLeft};
}
/**
* @param strokeWidth, stroke width
* @param strokeColor, stroke color
* @param argb, background color
* @param radii, use {@link #defineRadiusForPosition(int, int, int, int, int, int, int)} method to define radii
* @return background drawable
*/
public static Drawable getBackground(int strokeWidth, int strokeColor, int argb, float[] radii) {
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(GradientDrawable.RECTANGLE);
drawable.setStroke(strokeWidth, strokeColor);
drawable.setCornerRadii(radii);
drawable.setColor(argb);
return drawable;
}
public static ValueAnimator createBackgroundAnimation(int argbStart, int argbEnd) {
return ValueAnimator.ofObject(ArgbEvaluator.getInstance(), argbStart, argbEnd);
}
public static boolean isInBounds(float touchX, float touchY, float viewX, float viewY, float viewW, float viewH) {
return touchX >= viewX && touchX <= viewX + viewW && // in x bounds
touchY >= viewY && touchY <= viewY + viewH;
}
}
================================================
FILE: segmentedcontrolmodule/src/main/res/layout/item_segment_impl.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/item_segment_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</FrameLayout>
================================================
FILE: segmentedcontrolmodule/src/main/res/values/attr.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SegmentedControl">
<attr name="reselectionEnabled" format="boolean"/>
<attr name="distributeEvenly" format="boolean" />
<attr name="supportedSelectionsCount" format="integer"/>
<attr name="columnCount" format="integer" />
<attr name="segments" format="reference" />
<attr name="selectedStrokeColor" format="color" />
<attr name="unSelectedStrokeColor" format="color" />
<attr name="strokeWidth" format="dimension" />
<attr name="selectedBackgroundColor" format="color" />
<attr name="unSelectedBackgroundColor" format="color" />
<attr name="selectionAnimationDuration" format="integer"/>
<attr name="focusedBackgroundColor" format="color"/>
<attr name="selectedTextColor" format="color"/>
<attr name="unSelectedTextColor" format="color"/>
<attr name="textSize" format="dimension"/>
<attr name="textHorizontalPadding" format="dimension"/>
<attr name="textVerticalPadding" format="dimension"/>
<attr name="segmentVerticalMargin" format="dimension"/>
<attr name="segmentHorizontalMargin" format="dimension"/>
<attr name="radius" format="dimension"/>
<attr name="topLeftRadius" format="dimension"/>
<attr name="topRightRadius" format="dimension"/>
<attr name="bottomRightRadius" format="dimension"/>
<attr name="bottomLeftRadius" format="dimension"/>
<attr name="radiusForEverySegment" format="boolean"/>
<attr name="fontAssetPath" format="string"/>
</declare-styleable>
</resources>
================================================
FILE: segmentedcontrolmodule/src/main/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
================================================
FILE: segmentedcontrolmodule/src/main/res/values/strings.xml
================================================
<resources>
<string name="app_name">SegmentedControl</string>
</resources>
================================================
FILE: settings.gradle
================================================
include ':app', ':segmentedcontrolmodule'
gitextract_p17z464c/ ├── .gitignore ├── .idea/ │ ├── caches/ │ │ ├── build_file_checksums.ser │ │ └── gradle_models.ser │ ├── encodings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ ├── runConfigurations.xml │ └── vcs.xml ├── LICENSE ├── README.md ├── build.gradle ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── segmentedcontrolmodule/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── segmented_control/ │ │ └── widget/ │ │ └── custom/ │ │ └── android/ │ │ └── com/ │ │ └── segmentedcontrol/ │ │ ├── Assert.java │ │ ├── Configs.java │ │ ├── Consumer.java │ │ ├── Notifier.java │ │ ├── SegmentConsumer.java │ │ ├── SegmentedControl.java │ │ ├── SegmentedControlControllerComponent.java │ │ ├── SegmentedControlViewComponent.java │ │ ├── custom_segment/ │ │ │ ├── SegmentAdapterImpl.java │ │ │ └── SegmentViewHolderImpl.java │ │ ├── item_row/ │ │ │ ├── SegmentRowAdapter.java │ │ │ └── SegmentRowViewHolder.java │ │ ├── item_row_column/ │ │ │ ├── SegmentAdapter.java │ │ │ ├── SegmentBackgroundType.java │ │ │ ├── SegmentData.java │ │ │ ├── SegmentDecoration.java │ │ │ └── SegmentViewHolder.java │ │ ├── listeners/ │ │ │ ├── OnSegmentClickListener.java │ │ │ ├── OnSegmentSelectRequestListener.java │ │ │ └── OnSegmentSelectedListener.java │ │ └── utils/ │ │ ├── ArgbEvaluator.java │ │ └── Utils.java │ └── res/ │ ├── layout/ │ │ └── item_segment_impl.xml │ └── values/ │ ├── attr.xml │ ├── colors.xml │ └── strings.xml └── settings.gradle
SYMBOL INDEX (297 symbols across 21 files)
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Assert.java
class Assert (line 9) | class Assert {
method adapter (line 11) | static void adapter(SectionLayout.Adapter adapter) {
method columnCount (line 15) | static void columnCount(int columnCount) {
method outOfBounds (line 20) | static void outOfBounds(int position, int size, String methodName) {
method throwIf (line 24) | private static void throwIf(boolean willThrow, Exception exception) {
method supportedSelectionsCount (line 34) | public static void supportedSelectionsCount(int supportedSelectionsCou...
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Configs.java
class Configs (line 9) | class Configs {
method getDefault (line 21) | static Configs getDefault() {
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Consumer.java
type Consumer (line 7) | interface Consumer<T> {
method apply (line 8) | void apply(T t);
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Notifier.java
class Notifier (line 18) | class Notifier<D> implements OnSegmentClickListener<D>, OnSegmentSelecte...
method onSegmentClick (line 24) | @Override
method onSegmentSelected (line 34) | @Override
method onSegmentSelectRequest (line 44) | @Override
method addOnSegmentClickListener (line 49) | void addOnSegmentClickListener(OnSegmentClickListener<D> onSegmentClic...
method removeOnSegmentClickListener (line 54) | void removeOnSegmentClickListener(OnSegmentClickListener<D> onSegmentC...
method addOnSegmentSelectListener (line 59) | void addOnSegmentSelectListener(OnSegmentSelectedListener<D> onSegment...
method removeOnSegmentSelectListener (line 64) | void removeOnSegmentSelectListener(OnSegmentSelectedListener<D> onSegm...
method setOnSegmentSelectRequestListener (line 69) | void setOnSegmentSelectRequestListener(OnSegmentSelectRequestListener<...
method onEvent (line 74) | private <T> void onEvent(List<T> eventListeners, Consumer<T> listenerC...
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentConsumer.java
type SegmentConsumer (line 5) | public interface SegmentConsumer<D> {
method apply (line 6) | void apply(SegmentViewHolder<D> segmentViewHolder);
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControl.java
class SegmentedControl (line 54) | public class SegmentedControl<D> extends ComponentFrameLayout<SegmentedC...
method SegmentedControl (line 56) | public SegmentedControl(Context context) {
method SegmentedControl (line 60) | public SegmentedControl(Context context, AttributeSet attrs) {
method SegmentedControl (line 64) | public SegmentedControl(Context context, AttributeSet attrs, int defSt...
method initAttr (line 69) | private void initAttr(AttributeSet attrs, int defStyle) {
method fetchAccentColor (line 106) | private void fetchAccentColor() {
method attrSelectedStrokeColor (line 116) | private void attrSelectedStrokeColor(TypedArray typedArray) {
method attrUnSelectedStrokeColor (line 125) | private void attrUnSelectedStrokeColor(TypedArray typedArray) {
method attrStrokeWidth (line 134) | private void attrStrokeWidth(TypedArray typedArray) {
method attrSelectedBackgroundColor (line 143) | private void attrSelectedBackgroundColor(TypedArray typedArray) {
method attrUnSelectedBackgroundColor (line 152) | private void attrUnSelectedBackgroundColor(TypedArray typedArray) {
method attrFocusedBackgroundColor (line 161) | private void attrFocusedBackgroundColor(TypedArray typedArray) {
method attrSelectionAnimationDuration (line 170) | private void attrSelectionAnimationDuration(TypedArray typedArray) {
method attrSelectedTextColor (line 176) | private void attrSelectedTextColor(TypedArray typedArray) {
method attrUnSelectedTextColor (line 185) | private void attrUnSelectedTextColor(TypedArray typedArray) {
method attrTextSize (line 194) | private void attrTextSize(TypedArray typedArray) {
method attrFontAssetPath (line 203) | private void attrFontAssetPath(TypedArray typedArray) {
method attrTextVerticalPadding (line 210) | private void attrTextVerticalPadding(TypedArray typedArray) {
method attrTextHorizontalPadding (line 219) | private void attrTextHorizontalPadding(TypedArray typedArray) {
method attrSegmentVerticalMargin (line 228) | private void attrSegmentVerticalMargin(TypedArray typedArray) {
method attrSegmentHorizontalMargin (line 237) | private void attrSegmentHorizontalMargin(TypedArray typedArray) {
method attrRadius (line 246) | private void attrRadius(TypedArray typedArray) {
method attrTopLeftRadius (line 255) | private void attrTopLeftRadius(TypedArray typedArray) {
method attrTopRightRadius (line 264) | private void attrTopRightRadius(TypedArray typedArray) {
method attrBottomRightRadius (line 273) | private void attrBottomRightRadius(TypedArray typedArray) {
method attrBottomLeftRadius (line 282) | private void attrBottomLeftRadius(TypedArray typedArray) {
method attrRadiusForEverySegment (line 291) | private void attrRadiusForEverySegment(TypedArray typedArray) {
method attrSegments (line 296) | private void attrSegments(TypedArray typedArray) {
method attrColumnCount (line 303) | private void attrColumnCount(TypedArray typedArray) {
method attrSupportedSelectionsCount (line 309) | private void attrSupportedSelectionsCount(TypedArray typedArray) {
method attrDistributeEvenly (line 316) | private void attrDistributeEvenly(TypedArray typedArray) {
method attrReselectionEnabled (line 322) | private void attrReselectionEnabled(TypedArray typedArray) {
method obtainColorAttr (line 327) | private void obtainColorAttr(TypedArray typedArray, int attr, Consumer...
method obtainDimensionAttr (line 334) | private void obtainDimensionAttr(TypedArray typedArray, int attr, Cons...
method createViewComponent (line 341) | @NonNull
method createControllerComponent (line 348) | @NonNull
method setSupportedSelectionsCount (line 360) | public void setSupportedSelectionsCount(int supportedSelectionsCount) {
method setColumnCount (line 368) | public void setColumnCount(int columnCount) {
method setAdapter (line 376) | public void setAdapter(@NonNull SegmentAdapter adapter) {
method useDefaultAdapter (line 385) | public void useDefaultAdapter() {
method addSegments (line 394) | public void addSegments(D[] segmentData) {
method addSegments (line 403) | public void addSegments(List<D> segmentData) {
method setDistributeEvenly (line 411) | public void setDistributeEvenly(boolean willDistributeEvenly) {
method setReselectionEnabled (line 420) | public void setReselectionEnabled(boolean isEnabled) {
method addOnSegmentClickListener (line 428) | public void addOnSegmentClickListener(OnSegmentClickListener<D> onSegm...
method removeOnSegmentClickListener (line 438) | public void removeOnSegmentClickListener(OnSegmentClickListener<D> onS...
method addOnSegmentSelectListener (line 446) | public void addOnSegmentSelectListener(OnSegmentSelectedListener<D> on...
method removeOnSegmentSelectListener (line 456) | public void removeOnSegmentSelectListener(OnSegmentSelectedListener<D>...
method setOnSegmentSelectRequestListener (line 464) | public void setOnSegmentSelectRequestListener(OnSegmentSelectRequestLi...
method removeAllSegments (line 471) | public void removeAllSegments() {
method findSegmentByAbsolutePosition (line 481) | public SegmentViewHolder<D> findSegmentByAbsolutePosition(int position) {
method findSegmentByColumnAndRow (line 493) | public SegmentViewHolder<D> findSegmentByColumnAndRow(int column, int ...
method setSelectedSegment (line 503) | public void setSelectedSegment(int position) {
method setSelectedSegment (line 514) | public void setSelectedSegment(int column, int row) {
method forEachSegment (line 524) | public void forEachSegment(SegmentConsumer<D> segmentConsumer) {
method setSelectedStrokeColor (line 528) | public void setSelectedStrokeColor(int color) {
method setUnSelectedStrokeColor (line 532) | public void setUnSelectedStrokeColor(int color) {
method setFocusedBackgroundColor (line 536) | public void setFocusedBackgroundColor(int color) {
method setSelectionAnimationDuration (line 545) | public void setSelectionAnimationDuration(int duration) {
method setStrokeWidth (line 549) | public void setStrokeWidth(int width) {
method setSelectedBackgroundColor (line 553) | public void setSelectedBackgroundColor(int color) {
method setUnSelectedBackgroundColor (line 557) | public void setUnSelectedBackgroundColor(int color) {
method setSelectedTextColor (line 561) | public void setSelectedTextColor(int color) {
method setUnSelectedTextColor (line 565) | public void setUnSelectedTextColor(int color) {
method setTextSize (line 569) | public void setTextSize(int textSize) {
method setTypeFace (line 573) | public void setTypeFace(Typeface typeFace) {
method setTextVerticalPadding (line 577) | public void setTextVerticalPadding(int padding) {
method setTextHorizontalPadding (line 581) | public void setTextHorizontalPadding(int padding) {
method setSegmentVerticalMargin (line 585) | public void setSegmentVerticalMargin(int margin) {
method setSegmentHorizontalMargin (line 589) | public void setSegmentHorizontalMargin(int margin) {
method setRadius (line 593) | public void setRadius(int radius) {
method setTopLeftRadius (line 597) | public void setTopLeftRadius(int radius) {
method setTopRightRadius (line 601) | public void setTopRightRadius(int radius) {
method setBottomRightRadius (line 605) | public void setBottomRightRadius(int radius) {
method setBottomLeftRadius (line 609) | public void setBottomLeftRadius(int radius) {
method setRadiusForEverySegment (line 616) | public void setRadiusForEverySegment(boolean radiusForEverySegment) {
method clearSelection (line 624) | public void clearSelection() {
method clearSelection (line 634) | public void clearSelection(boolean notifySegmentSelectedListener) {
method notifyConfigIsChanged (line 642) | public void notifyConfigIsChanged() {
method size (line 646) | public int size() {
method getLastSelectedColumnAndRow (line 657) | public int[] getLastSelectedColumnAndRow() {
method getLastSelectedAbsolutePosition (line 661) | public int getLastSelectedAbsolutePosition() {
method hasSelectedSegment (line 665) | public boolean hasSelectedSegment() {
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlControllerComponent.java
class SegmentedControlControllerComponent (line 29) | class SegmentedControlControllerComponent<D> extends ControllerComponent...
method onSegmentClick (line 61) | @Override
method addSelectedSegmentViewHolder (line 101) | @Nullable
method getLastSelectedViewHolder (line 110) | private SegmentViewHolder<D> getLastSelectedViewHolder() {
method addSegment (line 114) | private void addSegment(D segmentData) {
method removeAllSegments (line 135) | private void removeAllSegments(boolean removeLastSelected) {
method addSegmentToLastRow (line 147) | private void addSegmentToLastRow(D segmentData) {
method getRowAndColumnWithAbsolutePosition (line 155) | private int[] getRowAndColumnWithAbsolutePosition(int position) {
method notifyConfigIsChanged (line 163) | void notifyConfigIsChanged() {
method clearSelection (line 179) | public void clearSelection(boolean notifySegmentSelectedListener) {
method recreate (line 203) | private void recreate(boolean removeLastSelected) {
method canAddToLastRow (line 215) | private boolean canAddToLastRow() {
method addNewRow (line 219) | private void addNewRow() {
method getVerticalSectionLayout (line 224) | private SectionLayout getVerticalSectionLayout() {
method getHorizontalSectionLayout (line 229) | private DistributiveSectionLayout<SegmentData<D>> getHorizontalSection...
method getLastHorizontalSectionLayout (line 235) | private DistributiveSectionLayout<SegmentData<D>> getLastHorizontalSec...
method getLastRowIndex (line 239) | private int getLastRowIndex() {
method findSegmentByAbsolutePosition (line 243) | SegmentViewHolder<D> findSegmentByAbsolutePosition(int position) {
method findSegmentByColumnAndRow (line 248) | SegmentViewHolder<D> findSegmentByColumnAndRow(int column, int row) {
method forEachSegment (line 252) | void forEachSegment(SegmentConsumer<D> segmentConsumer) {
method setAccentColor (line 261) | void setAccentColor(int color) {
method setSelectedStrokeColor (line 265) | void setSelectedStrokeColor(int color) {
method setUnSelectedStrokeColor (line 269) | void setUnSelectedStrokeColor(int color) {
method setStrokeWidth (line 273) | void setStrokeWidth(int width) {
method setSelectedBackgroundColor (line 277) | void setSelectedBackgroundColor(int color) {
method setUnSelectedBackgroundColor (line 281) | void setUnSelectedBackgroundColor(int color) {
method setFocusedBackgroundColor (line 285) | void setFocusedBackgroundColor(int color) {
method setReselectionEnabled (line 289) | void setReselectionEnabled(boolean isEnabled){
method setSelectionAnimationDuration (line 293) | void setSelectionAnimationDuration(int duration) {
method setSelectedTextColor (line 297) | void setSelectedTextColor(int color) {
method setUnSelectedTextColor (line 301) | void setUnSelectedTextColor(int color) {
method setTextSize (line 305) | void setTextSize(int textSize) {
method setTypeFace (line 309) | void setTypeFace(Typeface typeFace) {
method setTextVerticalPadding (line 313) | void setTextVerticalPadding(int padding) {
method setTextHorizontalPadding (line 317) | void setTextHorizontalPadding(int padding) {
method setSegmentVerticalMargin (line 321) | void setSegmentVerticalMargin(int margin) {
method setSegmentHorizontalMargin (line 325) | void setSegmentHorizontalMargin(int margin) {
method setRadius (line 329) | void setRadius(int radius) {
method setTopLeftRadius (line 336) | void setTopLeftRadius(int radius) {
method setTopRightRadius (line 340) | void setTopRightRadius(int radius) {
method setBottomRightRadius (line 344) | void setBottomRightRadius(int radius) {
method setBottomLeftRadius (line 348) | void setBottomLeftRadius(int radius) {
method setRadiusForEverySegment (line 352) | void setRadiusForEverySegment(boolean radiusForEverySegment) {
method setAdapter (line 356) | void setAdapter(SegmentAdapter adapter) {
method addSegments (line 361) | void addSegments(D[] segmentDataArray) {
method addSegments (line 366) | void addSegments(List<D> segmentDataList) {
method removeAllSegments (line 376) | void removeAllSegments() {
method setDistributeEvenly (line 380) | void setDistributeEvenly(boolean willDistributeEvenly) {
method setSupportedSelectionsCount (line 384) | void setSupportedSelectionsCount(int supportedSelectionsCount) {
method setColumnCount (line 388) | void setColumnCount(int columnCount) {
method addOnSegmentClickListener (line 392) | void addOnSegmentClickListener(OnSegmentClickListener<D> onSegmentClic...
method removeOnSegmentClickListener (line 396) | void removeOnSegmentClickListener(OnSegmentClickListener<D> onSegmentC...
method addOnSegmentSelectListener (line 400) | void addOnSegmentSelectListener(OnSegmentSelectedListener<D> onSegment...
method removeOnSegmentSelectListener (line 404) | void removeOnSegmentSelectListener(OnSegmentSelectedListener<D> onSegm...
method setOnSegmentSelectRequestListener (line 408) | void setOnSegmentSelectRequestListener(OnSegmentSelectRequestListener<...
method setSelectedSegment (line 412) | void setSelectedSegment(int absolutePosition) {
method setSelectedSegment (line 417) | void setSelectedSegment(int column, int row) {
method getSelectedViewHolders (line 425) | List<SegmentViewHolder<D>> getSelectedViewHolders() {
method getLastSelectedColumnAndRow (line 429) | int[] getLastSelectedColumnAndRow() {
method getLastSelectedAbsolutePosition (line 439) | int getLastSelectedAbsolutePosition() {
method isSelected (line 452) | boolean isSelected() {
method size (line 456) | int size() {
method getAbsolutePosition (line 460) | int getAbsolutePosition(int column, int row) {
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlViewComponent.java
class SegmentedControlViewComponent (line 14) | class SegmentedControlViewComponent<D> extends ViewComponent {
method SegmentedControlViewComponent (line 17) | SegmentedControlViewComponent(@NonNull View rootView) {
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/custom_segment/SegmentAdapterImpl.java
class SegmentAdapterImpl (line 14) | public class SegmentAdapterImpl extends SegmentAdapter<CharSequence, Seg...
method onCreateViewHolder (line 16) | @NonNull
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/custom_segment/SegmentViewHolderImpl.java
class SegmentViewHolderImpl (line 27) | public class SegmentViewHolderImpl extends SegmentViewHolder<CharSequenc...
method onAnimationUpdate (line 35) | @Override
method onTouch (line 45) | @SuppressLint("ClickableViewAccessibility")
method SegmentViewHolderImpl (line 69) | public SegmentViewHolderImpl(@NonNull View sectionView) {
method onSegmentBind (line 75) | @Override
method initScreenLocation (line 93) | private void initScreenLocation() {
method onSegmentSelected (line 98) | @Override
method getSelectedBackground (line 104) | private Drawable getSelectedBackground() {
method getUnSelectedBackground (line 108) | private Drawable getUnSelectedBackground() {
method getFocusedBackground (line 112) | private Drawable getFocusedBackground() {
method setSectionDecorationSelected (line 116) | private void setSectionDecorationSelected(boolean isSelected, boolean ...
method animateNewBackground (line 129) | private void animateNewBackground(boolean isSelected) {
method setBackground (line 149) | private void setBackground(Drawable drawable) {
method hasBackground (line 158) | private boolean hasBackground() {
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row/SegmentRowAdapter.java
class SegmentRowAdapter (line 16) | public class SegmentRowAdapter<D> extends SectionLayout.Adapter<Boolean,...
method SegmentRowAdapter (line 20) | public SegmentRowAdapter(SegmentAdapter segmentAdapter) {
method onCreateViewHolder (line 24) | @NonNull
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row/SegmentRowViewHolder.java
class SegmentRowViewHolder (line 16) | public class SegmentRowViewHolder<D> extends SectionLayout.ViewHolder<Bo...
method SegmentRowViewHolder (line 19) | SegmentRowViewHolder(@NonNull View sectionView, SegmentAdapter segment...
method onBind (line 27) | @Override
method getDistributiveSectionLayout (line 32) | public DistributiveSectionLayout<SegmentData<D>> getDistributiveSectio...
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentAdapter.java
class SegmentAdapter (line 9) | public abstract class SegmentAdapter<D, VH extends SegmentViewHolder<D>>...
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentData.java
class SegmentData (line 11) | public class SegmentData<D> {
method create (line 25) | public static <D> SegmentData<D> create(D segmentData, OnSegmentClickL...
method isSelected (line 38) | public boolean isSelected() {
method getAbsolutePosition (line 42) | public int getAbsolutePosition() {
method getRow (line 46) | public int getRow() {
method getColumn (line 50) | public int getColumn() {
method getSegmentData (line 54) | public D getSegmentData() {
method getOnSegmentClickListener (line 58) | public OnSegmentClickListener<D> getOnSegmentClickListener() {
method getSelectedStrokeColor (line 62) | public int getSelectedStrokeColor() {
method getUnSelectedStrokeColor (line 66) | public int getUnSelectedStrokeColor() {
method getStrokeWidth (line 70) | public int getStrokeWidth() {
method getSelectBackgroundColor (line 74) | public int getSelectBackgroundColor() {
method getUnSelectedBackgroundColor (line 78) | public int getUnSelectedBackgroundColor() {
method getFocusedBackgroundColor (line 82) | public int getFocusedBackgroundColor(){
method getSelectionAnimationDuration (line 86) | public int getSelectionAnimationDuration(){
method getSelectedTextColor (line 90) | public int getSelectedTextColor() {
method getUnSelectedTextColor (line 94) | public int getUnSelectedTextColor() {
method getTextSize (line 98) | public int getTextSize() {
method getTypeFace (line 102) | public Typeface getTypeFace(){
method getTextHorizontalPadding (line 106) | public int getTextHorizontalPadding() {
method getTextVerticalPadding (line 110) | public int getTextVerticalPadding() {
method getSegmentVerticalMargin (line 114) | public int getSegmentVerticalMargin() {
method getSegmentHorizontalMargin (line 118) | public int getSegmentHorizontalMargin() {
method getTopLeftRadius (line 122) | public int getTopLeftRadius() {
method getTopRightRadius (line 126) | public int getTopRightRadius() {
method getBottomRightRadius (line 130) | public int getBottomRightRadius() {
method getBottomLeftRadius (line 134) | public int getBottomLeftRadius() {
method isRadiusForEverySegment (line 138) | public boolean isRadiusForEverySegment() {
method getCurrentSize (line 142) | public int getCurrentSize() {
method getColumnCount (line 146) | public int getColumnCount() {
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentDecoration.java
class SegmentDecoration (line 13) | public class SegmentDecoration {
method createDefault (line 57) | public static SegmentDecoration createDefault(Context context, int acc...
method getSelectedStrokeColor (line 75) | public int getSelectedStrokeColor() {
method getUnSelectedStrokeColor (line 79) | public int getUnSelectedStrokeColor() {
method getStrokeWidth (line 83) | public int getStrokeWidth() {
method getSelectBackgroundColor (line 87) | public int getSelectBackgroundColor() {
method getUnSelectedBackgroundColor (line 91) | public int getUnSelectedBackgroundColor() {
method getFocusedBackgroundColor (line 95) | public int getFocusedBackgroundColor() {
method getSelectionAnimationDuration (line 99) | public int getSelectionAnimationDuration() {
method getSelectedTextColor (line 103) | public int getSelectedTextColor() {
method getUnSelectedTextColor (line 107) | public int getUnSelectedTextColor() {
method getTextSize (line 111) | public int getTextSize() {
method getTextHorizontalPadding (line 115) | public int getTextHorizontalPadding() {
method getTextVerticalPadding (line 119) | public int getTextVerticalPadding() {
method getSegmentVerticalMargin (line 123) | public int getSegmentVerticalMargin() {
method getSegmentHorizontalMargin (line 127) | public int getSegmentHorizontalMargin() {
method getTopLeftRadius (line 131) | public int getTopLeftRadius() {
method getTopRightRadius (line 135) | public int getTopRightRadius() {
method getBottomRightRadius (line 139) | public int getBottomRightRadius() {
method getBottomLeftRadius (line 143) | public int getBottomLeftRadius() {
method isRadiusForEverySegment (line 147) | public boolean isRadiusForEverySegment() {
method getTypeface (line 151) | public Typeface getTypeface() {
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentViewHolder.java
class SegmentViewHolder (line 13) | public abstract class SegmentViewHolder<D> extends DistributiveSectionLa...
method onClick (line 17) | @Override
method SegmentViewHolder (line 24) | public SegmentViewHolder(@NonNull View sectionView) {
method onBind (line 28) | @Override
method setSelected (line 35) | public final void setSelected(boolean isSelected) {
method onSegmentSelected (line 54) | public void onSegmentSelected(boolean isSelected, boolean isReselected) {
method getAbsolutePosition (line 58) | public int getAbsolutePosition() {
method isSelected (line 62) | public boolean isSelected() {
method getRow (line 66) | public int getRow() {
method getColumn (line 70) | public int getColumn() {
method getSegmentData (line 74) | public D getSegmentData() {
method getSelectedStrokeColor (line 78) | public int getSelectedStrokeColor() {
method getUnSelectedStrokeColor (line 82) | public int getUnSelectedStrokeColor() {
method getStrokeWidth (line 86) | public int getStrokeWidth() {
method getSelectBackgroundColor (line 90) | public int getSelectBackgroundColor() {
method getUnSelectedBackgroundColor (line 94) | public int getUnSelectedBackgroundColor() {
method getFocusedBackgroundColor (line 98) | public int getFocusedBackgroundColor(){
method getSelectionAnimationDuration (line 102) | public int getSelectionAnimationDuration(){
method getSelectedTextColor (line 106) | public int getSelectedTextColor() {
method getUnSelectedTextColor (line 110) | public int getUnSelectedTextColor() {
method getTextSize (line 114) | public int getTextSize() {
method getTypeFace (line 118) | public Typeface getTypeFace(){return segmentData.getTypeFace();}
method getCurrentSize (line 120) | public int getCurrentSize() {
method getColumnCount (line 124) | public int getColumnCount() {
method getTextHorizontalPadding (line 128) | public int getTextHorizontalPadding() {
method getTextVerticalPadding (line 132) | public int getTextVerticalPadding() {
method getSegmentVerticalMargin (line 136) | public int getSegmentVerticalMargin() {
method getSegmentHorizontalMargin (line 140) | public int getSegmentHorizontalMargin() {
method getTopLeftRadius (line 144) | public int getTopLeftRadius() {
method getTopRightRadius (line 148) | public int getTopRightRadius() {
method getBottomRightRadius (line 152) | public int getBottomRightRadius() {
method getBottomLeftRadius (line 156) | public int getBottomLeftRadius() {
method isRadiusForEverySegment (line 160) | public boolean isRadiusForEverySegment() {
method onSegmentBind (line 164) | protected abstract void onSegmentBind(D segmentData);
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/listeners/OnSegmentClickListener.java
type OnSegmentClickListener (line 9) | public interface OnSegmentClickListener<D> {
method onSegmentClick (line 13) | void onSegmentClick(SegmentViewHolder<D> segmentViewHolder);
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/listeners/OnSegmentSelectRequestListener.java
type OnSegmentSelectRequestListener (line 9) | public interface OnSegmentSelectRequestListener<D> {
method onSegmentSelectRequest (line 16) | boolean onSegmentSelectRequest(SegmentViewHolder<D> segmentViewHolder);
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/listeners/OnSegmentSelectedListener.java
type OnSegmentSelectedListener (line 9) | public interface OnSegmentSelectedListener<D> {
method onSegmentSelected (line 20) | void onSegmentSelected(SegmentViewHolder<D> segmentViewHolder, boolean...
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/utils/ArgbEvaluator.java
class ArgbEvaluator (line 6) | public class ArgbEvaluator implements TypeEvaluator {
method getInstance (line 17) | public static android.animation.ArgbEvaluator getInstance() {
method evaluate (line 37) | public Object evaluate(float fraction, Object startValue, Object endVa...
FILE: segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/utils/Utils.java
class Utils (line 17) | public class Utils {
method lazy (line 18) | public static <T> T lazy(T nullable, T nonNull) {
method defineSegmentBackground (line 33) | @SegmentBackgroundType
method defineRadiusForPosition (line 113) | public static float[] defineRadiusForPosition(@IntRange(from = 0) int ...
method createRadius (line 155) | public static float[] createRadius(float topLeft, float topRight, floa...
method getBackground (line 166) | public static Drawable getBackground(int strokeWidth, int strokeColor,...
method createBackgroundAnimation (line 175) | public static ValueAnimator createBackgroundAnimation(int argbStart, i...
method isInBounds (line 179) | public static boolean isInBounds(float touchX, float touchY, float vie...
Condensed preview — 48 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (138K chars).
[
{
"path": ".gitignore",
"chars": 123,
"preview": "*.iml\n.gradle\n/local.properties\n/.idea/workspace.xml\n/.idea/libraries\n.DS_Store\n/build\n/captures\n.externalNativeBuild\n/a"
},
{
"path": ".idea/encodings.xml",
"chars": 135,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"Encoding\" addBOMForNewFiles=\"with NO BOM"
},
{
"path": ".idea/gradle.xml",
"chars": 825,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"GradleSettings\">\n <option name=\"linke"
},
{
"path": ".idea/misc.xml",
"chars": 2847,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"NullableNotNullManager\">\n <option nam"
},
{
"path": ".idea/modules.xml",
"chars": 659,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"ProjectModuleManager\">\n <modules>\n "
},
{
"path": ".idea/runConfigurations.xml",
"chars": 564,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"RunConfigurationProducerService\">\n <o"
},
{
"path": ".idea/vcs.xml",
"chars": 167,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"VcsDirectoryMappings\">\n <mapping dire"
},
{
"path": "LICENSE",
"chars": 11357,
"preview": " Apache License\n Version 2.0, January 2004\n "
},
{
"path": "README.md",
"chars": 8769,
"preview": "# Android SegmentedControl + multi row support + multi selection\n### minSdk API 14+\n\n users:\n# Gradle settings configured through the IDE *will o"
},
{
"path": "gradlew",
"chars": 4971,
"preview": "#!/usr/bin/env bash\n\n##############################################################################\n##\n## Gradle start "
},
{
"path": "gradlew.bat",
"chars": 2314,
"preview": "@if \"%DEBUG%\" == \"\" @echo off\n@rem ##########################################################################\n@rem\n@rem "
},
{
"path": "segmentedcontrolmodule/.gitignore",
"chars": 7,
"preview": "/build\n"
},
{
"path": "segmentedcontrolmodule/build.gradle",
"chars": 857,
"preview": "apply plugin: 'com.android.library'\n\nandroid {\n compileSdkVersion 28\n\n defaultConfig {\n minSdkVersion 14\n "
},
{
"path": "segmentedcontrolmodule/proguard-rules.pro",
"chars": 908,
"preview": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in D:"
},
{
"path": "segmentedcontrolmodule/src/main/AndroidManifest.xml",
"chars": 214,
"preview": "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n\n package=\"segmented_control.widget.custom.andro"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Assert.java",
"chars": 1542,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol;\n\nimport section_layout.widget.custom.android.com.s"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Configs.java",
"chars": 869,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol;\n\nimport segmented_control.widget.custom.android.co"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Consumer.java",
"chars": 169,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol;\n\n/**\n * Created by Robert Apikyan on 9/8/2017.\n */"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/Notifier.java",
"chars": 3769,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol;\n\nimport java.util.ArrayList;\nimport java.util.List"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentConsumer.java",
"chars": 270,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol;\n\nimport segmented_control.widget.custom.android.co"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControl.java",
"chars": 27507,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol;\n\nimport android.content.Context;\nimport android.co"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlControllerComponent.java",
"chars": 17421,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol;\n\nimport android.graphics.Typeface;\nimport android."
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/SegmentedControlViewComponent.java",
"chars": 778,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol;\n\nimport android.support.annotation.NonNull;\nimport"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/custom_segment/SegmentAdapterImpl.java",
"chars": 776,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.custom_segment;\n\nimport android.support.annotation."
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/custom_segment/SegmentViewHolderImpl.java",
"chars": 6588,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.custom_segment;\n\nimport android.animation.ValueAnim"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row/SegmentRowAdapter.java",
"chars": 1223,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.item_row;\n\nimport android.support.annotation.NonNul"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row/SegmentRowViewHolder.java",
"chars": 1471,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.item_row;\n\nimport android.support.annotation.NonNul"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentAdapter.java",
"chars": 396,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column;\n\nimport section_layout.widget.cust"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentBackgroundType.java",
"chars": 2154,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column;\n\nimport android.support.annotation"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentData.java",
"chars": 3929,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column;\n\nimport android.graphics.Typeface;"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentDecoration.java",
"chars": 4109,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column;\n\nimport android.content.Context;\ni"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/item_row_column/SegmentViewHolder.java",
"chars": 4535,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.item_row_column;\n\nimport android.graphics.Typeface;"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/listeners/OnSegmentClickListener.java",
"chars": 438,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.listeners;\n\nimport segmented_control.widget.custom."
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/listeners/OnSegmentSelectRequestListener.java",
"chars": 647,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.listeners;\n\nimport segmented_control.widget.custom."
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/listeners/OnSegmentSelectedListener.java",
"chars": 922,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.listeners;\n\nimport segmented_control.widget.custom."
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/utils/ArgbEvaluator.java",
"chars": 3201,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.utils;\n\nimport android.animation.TypeEvaluator;\nimp"
},
{
"path": "segmentedcontrolmodule/src/main/java/segmented_control/widget/custom/android/com/segmentedcontrol/utils/Utils.java",
"chars": 7281,
"preview": "package segmented_control.widget.custom.android.com.segmentedcontrol.utils;\n\nimport android.animation.ObjectAnimator;\nim"
},
{
"path": "segmentedcontrolmodule/src/main/res/layout/item_segment_impl.xml",
"chars": 393,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<FrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n andro"
},
{
"path": "segmentedcontrolmodule/src/main/res/values/attr.xml",
"chars": 1671,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <declare-styleable name=\"SegmentedControl\">\n <attr name=\"r"
},
{
"path": "segmentedcontrolmodule/src/main/res/values/colors.xml",
"chars": 207,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <color name=\"colorPrimary\">#3F51B5</color>\n <color name=\"color"
},
{
"path": "segmentedcontrolmodule/src/main/res/values/strings.xml",
"chars": 79,
"preview": "<resources>\n <string name=\"app_name\">SegmentedControl</string>\n</resources>\n"
},
{
"path": "settings.gradle",
"chars": 42,
"preview": "include ':app', ':segmentedcontrolmodule'\n"
}
]
// ... and 3 more files (download for full content)
About this extraction
This page contains the full source code of the RobertApikyan/SegmentedControl GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 48 files (125.7 KB), approximately 29.3k tokens, and a symbol index with 297 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.