[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [snowflake-mobile/master] Created a workable UI and created a service class
commit 49c4d5c62078d3831d66bb159d9b164fad2e90ff
Author: Hashik Donthineni <HashikDonthineni@xxxxxxxxx>
Date: Wed Jun 3 20:23:45 2020 +0530
Created a workable UI and created a service class
---
.idea/misc.xml | 2 +-
.../org/torproject/snowflake/MainActivity.java | 30 ++++++++++++++++++++++
.../torproject/snowflake/MyPersistentService.java | 16 ++++++++++++
app/src/main/res/layout/activity_main.xml | 10 ++++----
4 files changed, 52 insertions(+), 6 deletions(-)
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 7bfef59..37a7509 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
diff --git a/app/src/main/java/org/torproject/snowflake/MainActivity.java b/app/src/main/java/org/torproject/snowflake/MainActivity.java
index 31b77ff..240e285 100644
--- a/app/src/main/java/org/torproject/snowflake/MainActivity.java
+++ b/app/src/main/java/org/torproject/snowflake/MainActivity.java
@@ -2,7 +2,11 @@ package org.torproject.snowflake;
import androidx.appcompat.app.AppCompatActivity;
+import android.app.ActivityManager;
+import android.content.Context;
import android.os.Bundle;
+import android.widget.Button;
+import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@@ -10,5 +14,31 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+
+ Button startButton = findViewById(R.id.start_button);
+
+ startButton.setOnClickListener(v -> {
+ if (isServiceRunning()){ //Toggling the service.
+ //TODO: Start service
+ }
+ else{
+ //TODO: Stop service
+ }
+ });
+ if (BuildConfig.DEBUG)
+ startButton.performClick(); //To perform an automatic click in testing environment.
+ }
+
+ //Test to see if the service is already running.
+ private boolean isServiceRunning() {
+ ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+ if (manager != null) {
+ for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+ if (MyPersistentService.class.getName().equals(service.service.getClassName())) {
+ return true;
+ }
+ }
+ }
+ return false;
}
}
diff --git a/app/src/main/java/org/torproject/snowflake/MyPersistentService.java b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
new file mode 100644
index 0000000..cc4806d
--- /dev/null
+++ b/app/src/main/java/org/torproject/snowflake/MyPersistentService.java
@@ -0,0 +1,16 @@
+package org.torproject.snowflake;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+
+import androidx.annotation.Nullable;
+
+//Main foreground service to handle network calls and to relay the data in the back ground.
+public class MyPersistentService extends Service {
+ @Nullable
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 4fc2444..1c42128 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -6,13 +6,13 @@
android:layout_height="match_parent"
tools:context=".MainActivity">
- <TextView
+ <Button
+ android:id="@+id/start_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="Hello World!"
+ android:text="Service Toggle"
app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintRight_toRightOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
-
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits