[tor-commits] [snowflake-mobile/master] Changed Snowflake Button to Switch

cohosh at torproject.org cohosh at torproject.org
Mon Aug 10 16:49:27 UTC 2020


commit aaea63a1e19fdc3b744215eaebd888cab6e3c21c
Author: Hashik Donthineni <HashikDonthineni at gmail.com>
Date:   Wed Aug 5 15:38:12 2020 +0530

    Changed Snowflake Button to Switch
---
 .../org/torproject/snowflake/fragments/MainFragment.java   | 14 ++++++++------
 app/src/main/res/layout/fragment_main.xml                  | 11 +++++++----
 app/src/main/res/values/strings.xml                        |  2 ++
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/app/src/main/java/org/torproject/snowflake/fragments/MainFragment.java b/app/src/main/java/org/torproject/snowflake/fragments/MainFragment.java
index 7638b1c..45ce672 100644
--- a/app/src/main/java/org/torproject/snowflake/fragments/MainFragment.java
+++ b/app/src/main/java/org/torproject/snowflake/fragments/MainFragment.java
@@ -6,7 +6,7 @@ import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.Button;
+import android.widget.Switch;
 import android.widget.TextView;
 
 import androidx.annotation.NonNull;
@@ -52,15 +52,17 @@ public class MainFragment extends Fragment {
                              Bundle savedInstanceState) {
         View rootView = inflater.inflate(R.layout.fragment_main, container, false);
         usersServedTV = rootView.findViewById(R.id.users_served);
-        Button startButton = rootView.findViewById(R.id.start_button);
+        Switch startButton = rootView.findViewById(R.id.start_button);
 
-        startButton.setOnClickListener(v -> {
-            if (callback.isServiceRunning()) //Toggling the service.
+        startButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
+            if (callback.isServiceRunning() && !isChecked) { //Toggling the service.
+                startButton.setText(getString(R.string.Snowflake_Off));
                 callback.serviceToggle(ForegroundServiceConstants.ACTION_STOP);
-            else
+            } else {
+                startButton.setText(getString(R.string.Snowflake_On));
                 callback.serviceToggle(ForegroundServiceConstants.ACTION_START);
+            }
         });
-
         showServed(callback.getServed());
 
         // Inflate the layout for this fragment
diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml
index f6b4c4d..6e59640 100644
--- a/app/src/main/res/layout/fragment_main.xml
+++ b/app/src/main/res/layout/fragment_main.xml
@@ -6,13 +6,16 @@
     tools:context=".fragments.MainFragment">
 
 
-    <Button
+    <Switch
         android:id="@+id/start_button"
-        android:layout_width="wrap_content"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_centerInParent="true"
-        android:foreground="?android:attr/selectableItemBackground"
-        android:text="Service Toggle" />
+        android:layout_margin="20dp"
+        android:text="@string/Snowflake_Off"
+        android:textAlignment="textStart"
+        android:textColor="@color/colorText"
+        android:textSize="20sp" />
 
     <TextView
         android:id="@+id/users_served"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 856c648..876b7f6 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -3,4 +3,6 @@
     <string name="not_channel_desc">This Channel should not be muted. The Android system will consider Snowflake not import and will kill the service if it\'s muted.</string>
     <string name="not_channel_name">Snowflake Service</string>
     <string name="users_served_text">Users you have helped circumvent censorship in the past day \n</string>
+    <string name="Snowflake_Off">Snowflake is Off</string>
+    <string name="Snowflake_On">Snowflake is On</string>
 </resources>





More information about the tor-commits mailing list