Skip to content

Commit

Permalink
update to v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rgocal committed Apr 20, 2019
1 parent acabad3 commit 4c89c49
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 33 deletions.
Binary file added .idea/caches/gradle_models.ser
Binary file not shown.
10 changes: 3 additions & 7 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
versionName "1.1"
}
buildTypes {
release {
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/com/gocalsd/switchbar/GoogleTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public GoogleTextView(Context context) {
public GoogleTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setFont();

}

private void setFont() {
Expand All @@ -25,10 +24,8 @@ private void setFont() {
public GoogleTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setFont();

}


@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if(focused)
Expand Down
23 changes: 15 additions & 8 deletions app/src/main/java/com/gocalsd/switchbar/SwitchBar.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.gocalsd.switchbar;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.content.ContextCompat;
Expand All @@ -28,13 +34,13 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
private ToggleSwitch mSwitch;
private TextView mTextView;
private String switchOn, switchOff;
private int mSwitchColor;
private int mBackgroundSwitchColor;
private Drawable switchbarBackground, wrappedBackground, wrappedBackgroundTwo;

private ArrayList<OnSwitchChangeListener> mSwitchChangeListeners =
new ArrayList<OnSwitchChangeListener>();
new ArrayList<>();

public static interface OnSwitchChangeListener {
public interface OnSwitchChangeListener {
/**
* Called when the checked state of the Switch has changed.
*
Expand All @@ -56,23 +62,23 @@ public SwitchBar(Context context, AttributeSet attrs, int defStyleAttr) {
}

public void setSwitchbarOnBackground(int backgroundColor){
this.mSwitchColor = ContextCompat.getColor(getContext(), backgroundColor);
this.mBackgroundSwitchColor = ContextCompat.getColor(getContext(), backgroundColor);

switchbarBackground = ContextCompat.getDrawable(getContext(), R.drawable.switchbar_bkg);
assert switchbarBackground != null;
wrappedBackground = DrawableCompat.wrap(switchbarBackground);
DrawableCompat.setTint(wrappedBackground, mSwitchColor);
DrawableCompat.setTint(wrappedBackground, mBackgroundSwitchColor);
wrappedBackground.invalidateSelf();
wrappedBackground.mutate();
}

public void setSwitchbarOffBackground(int backgroundColor){
this.mSwitchColor = ContextCompat.getColor(getContext(), backgroundColor);
this.mBackgroundSwitchColor = ContextCompat.getColor(getContext(), backgroundColor);

switchbarBackground = ContextCompat.getDrawable(getContext(), R.drawable.switchbar_bkg);
assert switchbarBackground != null;
wrappedBackgroundTwo = DrawableCompat.wrap(switchbarBackground);
DrawableCompat.setTint(wrappedBackgroundTwo, mSwitchColor);
DrawableCompat.setTint(wrappedBackgroundTwo, mBackgroundSwitchColor);
wrappedBackgroundTwo.invalidateSelf();
wrappedBackgroundTwo.mutate();
}
Expand All @@ -89,7 +95,7 @@ public SwitchBar(Context context, AttributeSet attrs, int defStyleAttr, int defS
switchOff = String.valueOf(R.string.switch_off_text);
switchOn = String.valueOf(R.string.switch_on_text);

mSwitch = (ToggleSwitch) findViewById(R.id.switch_widget);
mSwitch = findViewById(R.id.switch_widget);
// Prevent onSaveInstanceState() to be called as we are managing the state of the Switch
// on our own
mSwitch.setSaveEnabled(false);
Expand Down Expand Up @@ -198,6 +204,7 @@ static class SavedState extends BaseSavedState {
SavedState(Parcelable superState) {
super(superState);
}

/**
* Constructor called from {@link #CREATOR}
*/
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/gocalsd/switchbar/ToggleSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ public class ToggleSwitch extends Switch {

private ToggleSwitch.OnBeforeCheckedChangeListener mOnBeforeListener;

public static interface OnBeforeCheckedChangeListener {

public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked);
public interface OnBeforeCheckedChangeListener { boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked);
}

public ToggleSwitch(Context context) {
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/res/layout/switchbar_layout.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">

<com.gocalsd.switchbar.GoogleTextView
android:id="@+id/switch_text"
android:text="Switchbar"
Expand All @@ -9,14 +8,13 @@
android:layout_weight="1"
android:layout_marginStart="56dp"
android:layout_gravity="center_vertical|start"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Title" />
style="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" />

<com.gocalsd.switchbar.ToggleSwitch
android:id="@+id/switch_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="28dp"
android:background="@null" />

android:theme="@style/ToggleSwitchTheme"
android:layout_marginEnd="28dp" />
</merge>
7 changes: 7 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<resources>

<style name="ToggleSwitchTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="colorAccent">@color/colorPrimaryDark</item>
</style>

</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.2'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Fri Apr 19 12:55:24 EDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gocalsd.switchbarexample;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
Expand Down Expand Up @@ -35,9 +36,9 @@ protected void onCreate(Bundle savedInstanceState) {
//Set the on and off Messages
switchBar.setOnMessage(posMessage);
switchBar.setOffMessage(negMessage);

//Set the on and off Background Colors
//It's suggested to use the Primary and DarkPrimary colors of your application
//as the switch uses the Accent Color
//If you want to theme the Switch, override the style
switchBar.setSwitchbarOnBackground(R.color.colorPrimary);
switchBar.setSwitchbarOffBackground(R.color.colorPrimaryDark);

Expand Down

0 comments on commit 4c89c49

Please sign in to comment.