Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Toggle text and color update #32

Open
wants to merge 8 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,55 @@
# Toggle
Android Library for Custom Switches.

### Added feature
1. Added different toggle and text color
- app:colorText="#ffffff"
- app:colorToggle="#ffffff"

2. Added text modification option
- app:textUpperCase
- app:textLowerCase

3. Start toggle animation from touched X position or from the toggle position
- setStartAnimationFromTouchPosition (only from code)

4. Outsourced properties
- setDuration (only from code)
- setInterpolator (only from code)

5. Added option the disable touch during animation
- setInterruptAnimation (only from code)

6. Added Animation listener to track toggle position in percentages
- setOnAnimateListener (only from code)


### Developed by
[Angad Singh](https://www.github.com/angads25) ([@angads25](https://www.twitter.com/angads25))

### Benchmark:
[![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=14) [![Build Status](https://travis-ci.org/Angads25/android-toggle.svg?branch=release)](https://travis-ci.org/Angads25/android-toggle)

### Mentions:
[![Download](https://api.bintray.com/packages/angads25/maven/Toggle/images/download.svg)](https://bintray.com/angads25/maven/Toggle/_latestVersion) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.angads25/toggle/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.angads25/toggle)
[![](https://jitpack.io/v/jozsefmezei/android-toggle.svg)](https://jitpack.io/#jozsefmezei/android-toggle)

### Read all about internal classes and functions in the [wiki](https://github.com/Angads25/android-toggle/wiki).

### Installation

* Library is also Available in MavenCentral, So just put this in your app dependencies to use it:
Add it in your root build.gradle at the end of repositories:
```gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```

* Put this in your app dependencies:
```gradle
implementation 'com.github.angads25:toggle:1.1.0'
implementation 'com.github.jozsefmezei:android-toggle:1.1.1'
```

### Usage
Expand Down Expand Up @@ -51,7 +84,7 @@ Android Library for Custom Switches.

* Labeled Switch | Designed by - [Shweta Gupta](https://dribbble.com/shwetagupta)

![Labeled Switch](https://raw.githubusercontent.com/Angads25/android-toggle/release/screenshots/version%201/LabeledSwitch.png)
![Labeled Switch](https://raw.githubusercontent.com/jozsefmezei/android-toggle/release/screenshots/version%201/LabeledSwitch.png)

* Day Night Switch | Designed by - [Ramakrishna V](https://dribbble.com/RamakrishnaUX)

Expand All @@ -70,4 +103,4 @@ Android Library for Custom Switches.
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.
limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
import android.os.Handler;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.animation.BounceInterpolator;

import com.github.angads25.toggle.interfaces.OnAnimateListener;
import com.github.angads25.toggle.model.ToggleableView;
import com.github.angads25.toggle.widget.LabeledSwitch;

import java.util.Random;
Expand All @@ -36,6 +40,8 @@ public class LabeledSwitchActivity extends AppCompatActivity {
R.id.switch1, R.id.switch2,
R.id.switch4, R.id.switch5,
R.id.switch7, R.id.switch8,
R.id.switch9, R.id.switch10, R.id.switch12,
R.id.switch12, R.id.switch13
};

private LabeledSwitch[] labeledSwitches;
Expand Down Expand Up @@ -76,6 +82,16 @@ public void run() {

labeledSwitches[2].setTypeface(openSansBold);
labeledSwitches[3].setTypeface(openSansBold);
labeledSwitches[10].setDuration(5111);
labeledSwitches[10].setInterpolator(new BounceInterpolator());
labeledSwitches[10].setStartAnimationFromTouchPosition(false);
labeledSwitches[10].setInterruptAnimation(false);
labeledSwitches[10].setOnAnimateListener(new OnAnimateListener() {
@Override
public void onAnimate(ToggleableView toggleableView, float position) {
Log.d("Actual_position_percent", String.valueOf(position));
}
});
}

@Override
Expand Down
74 changes: 74 additions & 0 deletions app/src/main/res/layout/activity_labeled_switch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,78 @@
app:textOff="STOP"
app:colorBorder="@color/colorAccent" />
</android.support.v7.widget.LinearLayoutCompat>

<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">

<com.github.angads25.toggle.widget.LabeledSwitch
android:id="@+id/switch10"
android:layout_width="82dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:textSize="12sp"
app:on="false"
app:textOn="start"
app:textOff="stop"
app:textUpperCase="true"
app:colorBorder="#11111100"
app:colorText="#ffffff"
app:colorToggle="#ffffff"
app:colorOn="@color/colorPrimary"
app:colorOff="#00c4a6"/>

<com.github.angads25.toggle.widget.LabeledSwitch
android:id="@+id/switch11"
android:layout_width="82dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:textSize="12sp"
app:on="true"
app:textOn="start"
app:textOff="stop"
app:textUpperCase="true"
app:colorBorder="#11111100"
app:colorText="#ffffff"
app:colorToggle="#ffffff"
app:colorOn="@color/colorPrimary"
app:colorOff="#00c4a6"/>

<com.github.angads25.toggle.widget.LabeledSwitch
android:id="@+id/switch12"
android:layout_width="82dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:textSize="12sp"
android:enabled="false"
app:on="false"
app:textOn="start"
app:textOff="stop"
app:textUpperCase="true"
app:colorBorder="#11111100"
app:colorText="#ffffff"
app:colorToggle="#ffffff"
app:colorOn="@color/colorPrimary"
app:colorOff="#00c4a6"/>
</android.support.v7.widget.LinearLayoutCompat>

<com.github.angads25.toggle.widget.LabeledSwitch
android:id="@+id/switch13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:textSize="12sp"
app:on="false"
app:textOn="start"
app:textOff="stop"
app:textUpperCase="true"
app:colorBorder="#11111100"
app:colorText="#ffffff"
app:colorToggle="#ffffff"
app:colorOn="@color/colorPrimary"
app:colorOff="#00c4a6"/>

</android.support.v7.widget.LinearLayoutCompat>
Binary file modified screenshots/version 1/LabeledSwitch.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions toggle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext {
siteUrl = 'https://github.com/angads25/android-toggle'
gitUrl = 'https://github.com/angads25/android-toggle.git'

libraryVersion = '1.1.0'
libraryVersion = '1.1.4'

developerId = 'angads25'
developerName = 'Angad Singh'
Expand All @@ -30,8 +30,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.1.0"
versionCode 3
versionName "1.1.4"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.angads25.toggle.interfaces;

import com.github.angads25.toggle.model.ToggleableView;

public interface OnAnimateListener {

void onAnimate(ToggleableView toggleableView, float position);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.view.View;
import android.view.ViewDebug;

import com.github.angads25.toggle.interfaces.OnAnimateListener;
import com.github.angads25.toggle.interfaces.OnStateChangedListener;
import com.github.angads25.toggle.interfaces.OnToggledListener;

Expand Down Expand Up @@ -57,6 +58,13 @@ public class ToggleableView extends View {
*/
protected OnToggledListener onToggledListener;

/**
* Listener to inform user about toggle position. Position are based on percentage between 0 and 1.
*
* @see #setOnAnimateListener(OnToggledListener)
*/
protected OnAnimateListener onAnimateListener;

/**
* Simple constructor to use when creating a switch from code.
* @param context The Context the switch is running in, through which it can
Expand Down Expand Up @@ -142,4 +150,14 @@ public void setOn(boolean on) {
public void setOnToggledListener(OnToggledListener onToggledListener) {
this.onToggledListener = onToggledListener;
}

/**
* Register a callback to be invoked when the toggle animate between start and end position. If this switch is not
* enabled, there won't be any event.
*
* @param onAnimateListener The callback that will run
*/
public void setOnAnimateListener(OnAnimateListener onAnimateListener) {
this.onAnimateListener = onAnimateListener;
}
}
Loading