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

Commit

Permalink
docs: Added javadoc of library methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Angad Singh committed Sep 26, 2018
1 parent 5a5841e commit 3e9cf07
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 255 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
compileSdkVersion 28
buildToolsVersion '28.0.2'
defaultConfig {
applicationId "com.github.angads25.toggledemo"
minSdkVersion 14
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -28,7 +28,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':toggle')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ 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_day_night -> {
startActivity(Intent(this@MainActivity, DayNightActivity::class.java))
}
R.id.switch_labeled -> startActivity(Intent(this@MainActivity, LabeledSwitchActivity::class.java))
R.id.switch_day_night -> startActivity(Intent(this@MainActivity, DayNightActivity::class.java))
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_labeled_switch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:textSize="14sp"
app:on="true"
app:on="false"
app:colorBorder="@color/colorAccent"/>

<com.github.angads25.toggle.widget.LabeledSwitch
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.51'
ext.kotlin_version = '1.2.71'

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Jul 12 21:05:10 IST 2018
#Thu Sep 27 01:45:09 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
2 changes: 1 addition & 1 deletion toggle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext {

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
buildToolsVersion '28.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@
* <p>
* Created by Angad Singh on 25/2/18.
* </p>
*
* Interface definition for a callback to be invoked when state of switch is changed.
*
* <p>This is a <a href="package-summary.html">event listener</a>
* whose event method is {@link #onStateChanged(View, int)}.
*
* @since 1.1.0
*/

public interface OnStateChangedListener {

/**
* Called when a view changes it's state.
*
* @param view The view whose state was changed.
* @param state The state of the view.
*/
void onStateChanged(View view, int state);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,22 @@
* <p>
* Created by Angad Singh on 28/1/18.
* </p>
*
* Interface definition for a callback to be invoked when a digital switch is either on/off.
*
* <p>This is a <a href="package-summary.html">event listener</a>
* whose event method is {@link #onSwitched(ToggleableView, boolean)}.
*
* @since 1.1.0
*/

public interface OnToggledListener {

/**
* Called when a view changes it's state.
*
* @param toggleableView The view which either is on/off.
* @param isOn The on/off state of switch, true when switch turns on.
*/
void onSwitched(ToggleableView toggleableView, boolean isOn);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewDebug;

import com.github.angads25.toggle.interfaces.OnStateChangedListener;
import com.github.angads25.toggle.interfaces.OnToggledListener;
Expand All @@ -33,51 +34,112 @@ public class ToggleableView extends View {
protected int width;
protected int height;

protected int state;

/**
* Field to determine whether switch is on/off.
*
* @see #isOn()
* @see #setOn(boolean)
*/
protected boolean isOn;

/**
* Field to determine whether switch is enabled/disabled.
*
* @see #isEnabled()
* @see #setEnabled(boolean)
*/
protected boolean enabled;

/**
* Listener used to dispatch switch events.
*
* @see #setOnToggledListener(OnToggledListener)
*/
protected OnToggledListener onToggledListener;
protected OnStateChangedListener onStateChangedListener;

/**
* Simple constructor to use when creating a switch from code.
* @param context The Context the switch is running in, through which it can
* access the current theme, resources, etc.
*/
public ToggleableView(Context context) {
super(context);
}

/**
* Constructor that is called when inflating a switch from XML.
*
* @param context The Context the switch is running in, through which it can
* access the current theme, resources, etc.
* @param attrs The attributes of the XML tag that is inflating the switch.
*/
public ToggleableView(Context context, AttributeSet attrs) {
super(context, attrs);
}

/**
* Perform inflation from XML and apply a class-specific base style from a
* theme attribute.
*
* @param context The Context the switch is running in, through which it can
* access the current theme, resources, etc.
* @param attrs The attributes of the XML tag that is inflating the switch.
* @param defStyleAttr An attribute in the current theme that contains a
* reference to a style resource that supplies default values for
* the switch. Can be 0 to not look for defaults.
*/
public ToggleableView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public int getState() {
return state;
}

public void setState(int state) {
this.state = state;
}

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

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

/**
* Returns the enabled status for this switch. The interpretation of the
* enabled state varies by subclass.
*
* @return True if this switch is enabled, false otherwise.
*/
@ViewDebug.ExportedProperty
@Override public boolean isEnabled() {
return enabled;
}

public void setOnToggledListener(OnToggledListener onToggledListener) {
this.onToggledListener = onToggledListener;
/**
* Set the enabled state of this switch. The interpretation of the enabled
* state varies by subclass.
*
* @param enabled True if this view is enabled, false otherwise.
*/
@Override public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

private void setOnStateChangedListener(OnStateChangedListener onStateChangedListener) {
this.onStateChangedListener = onStateChangedListener;
/**
* Register a callback to be invoked when the boolean state of switch is changed. If this switch is not
* enabled, there won't be any event.
*
* @param onToggledListener The callback that will run
*
* @see #setEnabled(boolean)
*/
public void setOnToggledListener(OnToggledListener onToggledListener) {
this.onToggledListener = onToggledListener;
}
}
Loading

0 comments on commit 3e9cf07

Please sign in to comment.