Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
Fixed a conflicting issue with color tinting
Added a better example gui
  • Loading branch information
rgocal committed Mar 6, 2020
1 parent c73aa89 commit 7520bb6
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 23
targetSdkVersion 29
versionCode 3
versionName "2.00"
versionCode 4
versionName "2.10"
}
buildTypes {
release {
Expand Down
13 changes: 5 additions & 8 deletions app/src/main/java/com/gocalsd/switchbar/SwitchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,16 @@ public interface OnSwitchChangeListener {
}

public void setSwitchbarOnBackground(int backgroundColor){
int newColor = ContextCompat.getColor(getContext(), backgroundColor);
this.onColor = newColor;
this.mBackgroundSwitchColor = newColor;
backgroundDrawableOn.setTint(newColor);
this.mBackgroundSwitchColor = backgroundColor;
backgroundDrawableOn.setTint(backgroundColor);
backgroundDrawableOn.setElevation(8);
backgroundDrawableOn.setCornerSize(0);
}

public void setSwitchbarOffBackground(int backgroundColor){
int newColor = ContextCompat.getColor(getContext(), backgroundColor);
this.offColor = newColor;
this.mBackgroundSwitchColor = newColor;
backgroundDrawableOff.setTint(newColor);
this.offColor = backgroundColor;
this.mBackgroundSwitchColor = backgroundColor;
backgroundDrawableOff.setTint(backgroundColor);
backgroundDrawableOff.setElevation(8);
backgroundDrawableOff.setCornerSize(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;

import com.gocalsd.switchbar.SwitchBar;
import com.gocalsd.switchbar.ToggleSwitch;

public class MainActivity extends AppCompatActivity {

SwitchBar switchBar;
String posMessage, negMessage;

@Override
Expand All @@ -19,19 +20,20 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final AppCompatImageView imageView = findViewById(R.id.cast_background);
SwitchBar switchBar = findViewById(R.id.switchBar);

switchBar = new SwitchBar(this);
setSupportActionBar(toolbar);

posMessage = getString(R.string.switch_on_string);
negMessage = getString(R.string.switch_off_string);

switchBar = findViewById(R.id.switchBar);
imageView.setBackgroundResource(R.drawable.cast_connected);

//Set the on and off Background Colors
//Set the on and off Background Colors using Context
//If you want to theme the Switch, override the style
switchBar.setSwitchbarOnBackground(R.color.colorPrimary);
switchBar.setSwitchbarOffBackground(R.color.colorAccent);
switchBar.setSwitchbarOnBackground(ContextCompat.getColor(getBaseContext(), R.color.colorPrimary));
switchBar.setSwitchbarOffBackground(ContextCompat.getColor(getBaseContext(), R.color.colorAccent));

//Set the defaults
switchBar.setOnMessage(posMessage);
Expand All @@ -40,13 +42,19 @@ protected void onCreate(Bundle savedInstanceState) {
switchBar.setChecked(true);
switchBar.setTextViewLabel(true);

//Set the addOnSwitchChangeListener
switchBar.addOnSwitchChangeListener(new SwitchBar.OnSwitchChangeListener() {
//Set the add the Listener
switchBar.getSwitch().setOnBeforeCheckedChangeListener(new ToggleSwitch.OnBeforeCheckedChangeListener() {
@Override
public void onSwitchChanged(ToggleSwitch switchView, boolean isChecked) {

public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
if(checked) {
imageView.setBackgroundResource(R.drawable.cast_connected);
}else{
imageView.setBackgroundResource(R.drawable.cast_off);
}
return false;
}
});

}

}
8 changes: 8 additions & 0 deletions switchbarExample/src/main/res/drawable/cast_connected.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- drawable/cast_connected.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M21,3H3C1.89,3 1,3.89 1,5V8H3V5H21V19H14V21H21A2,2 0 0,0 23,19V5C23,3.89 22.1,3 21,3M1,10V12A9,9 0 0,1 10,21H12C12,14.92 7.07,10 1,10M19,7H5V8.63C8.96,9.91 12.09,13.04 13.37,17H19M1,14V16A5,5 0 0,1 6,21H8A7,7 0 0,0 1,14M1,18V21H4A3,3 0 0,0 1,18Z" />
</vector>
8 changes: 8 additions & 0 deletions switchbarExample/src/main/res/drawable/cast_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- drawable/cast_off.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M1.6,1.27L0.25,2.75L1.41,3.8C1.16,4.13 1,4.55 1,5V8H3V5.23L18.2,19H14V21H20.41L22.31,22.72L23.65,21.24M6.5,3L8.7,5H21V16.14L23,17.95V5C23,3.89 22.1,3 21,3M1,10V12A9,9 0 0,1 10,21H12C12,14.92 7.08,10 1,10M1,14V16A5,5 0 0,1 6,21H8A7,7 0 0,0 1,14M1,18V21H4A3,3 0 0,0 1,18Z" />
</vector>
22 changes: 22 additions & 0 deletions switchbarExample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4"
tools:context=".MainActivity">

<androidx.appcompat.widget.Toolbar
Expand All @@ -19,4 +20,25 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>

<com.gocalsd.switchbar.GoogleTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:gravity="center"
android:text="@string/action_details"/>

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:layout_margin="16dp"
app:cardUseCompatPadding="true"
android:elevation="4dp">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/cast_background"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</androidx.cardview.widget.CardView>

</androidx.appcompat.widget.LinearLayoutCompat>
5 changes: 3 additions & 2 deletions switchbarExample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<string name="app_name">SwitchbarExample</string>
<string name="action_settings">Settings</string>

<string name="switch_on_string">Switchbar On</string>
<string name="switch_off_string">Switchbar Off</string>
<string name="switch_on_string">Wireless Cast On</string>
<string name="switch_off_string">Wireless Cast Off</string>
<string name="action_details">Connect to a wireless device on your network to mirrow your mobile device display. While connected, this may impact the speed of your internet data connection to other devices.</string>
</resources>

0 comments on commit 7520bb6

Please sign in to comment.