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

Modifying the labeled switch and adding enable text, as well as inver… #29

Open
wants to merge 1 commit into
base: develop
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {

override fun onClick(view: View) {
when (view.id) {
R.id.switch_labeled -> startActivity(Intent(this@MainActivity, LabeledSwitchActivity::class.java))
R.id.switch_labeled -> startActivity(Intent(this@MainActivity, TestActivity::class.java))
R.id.switch_day_night -> startActivity(Intent(this@MainActivity, DayNightActivity::class.java))
}
}
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/res/layout/activity_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@
~ limitations under the License.
-->

<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="#752BE6"
xmlns:app="http://schemas.android.com/apk/res-auto">

<com.github.angads25.toggle.widget.LabeledSwitch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"/>
android:layout_margin="16dp"
android:textSize="10sp"
app:enableText="false"
app:invertColors="false"
app:on="false"
app:colorOff="@color/color_white"
app:colorOn="@color/edit_profile_bottomsheet_bg"
app:colorBorder="@color/color_white"/>

</androidx.appcompat.widget.LinearLayoutCompat>
5 changes: 5 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>


<color name="color_white">#FFFFFF</color>
<color name="edit_profile_bottomsheet_bg">#16283B</color>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ public class ToggleableView extends View {
*/
protected boolean isOn;

/**
* Field to determine whether text is enabled.
*
* @see #isTextEnabled()
* @see #setTextOn(boolean)
*/
protected boolean isTextEnabled;

/**
* Field to determine whether text is enabled.
*
* @see #isColorInverted()
* @see #setColorInverted(boolean)
*/
protected boolean isColorInverted;

/**
* Field to determine whether switch is enabled/disabled.
*
Expand Down Expand Up @@ -110,6 +126,41 @@ public void setOn(boolean on) {
isOn = on;
}

/**
* <p>Returns the boolean state of the text in the Switch.</p>
*
* @return true if the switch is on, false if it is off.
*/
public boolean isTextEnabled() {
return isTextEnabled;
}

/**
* <p>Changes the boolean state of this Switch.</p>
*
* @param on true to turn switch on, false to turn it off.
*/
public void setTextOn(boolean on) {
isTextEnabled = on;
}
/**
* <p>Returns the boolean state of the text in the Switch.</p>
*
* @return true if the switch is on, false if it is off.
*/
public boolean isColorInverted() {
return isColorInverted;
}

/**
* <p>Changes the boolean state of this Switch.</p>
*
* @param on true to turn switch on, false to turn it off.
*/
public void setColorInverted(boolean on) {
isColorInverted = on;
}

/**
* Returns the enabled status for this switch. The interpretation of the
* enabled state varies by subclass.
Expand Down
Loading