aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app/src/main/java/com/wireguard/android/ProfileActivity.java
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-08-04 12:24:18 -0500
committerSamuel Holland <samuel@sholland.org>2017-08-04 12:24:18 -0500
commit81ab643d2bf17b7ac5c70efa6f33e0737969cf85 (patch)
treeac1c1c04bf6011e2d8f41e8519d212288bfe902a /app/src/main/java/com/wireguard/android/ProfileActivity.java
parentProfileList: remove generated config from UI (diff)
downloadwireguard-android-81ab643d2bf17b7ac5c70efa6f33e0737969cf85.tar.xz
wireguard-android-81ab643d2bf17b7ac5c70efa6f33e0737969cf85.zip
ProfileList: Convert to a fragment
This is required for a future two-fragment tablet layout, and simplifies the code a bit since the profile detail (view/edit) will be implemented as fragments anyway. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/ProfileActivity.java')
-rw-r--r--app/src/main/java/com/wireguard/android/ProfileActivity.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/ProfileActivity.java b/app/src/main/java/com/wireguard/android/ProfileActivity.java
new file mode 100644
index 00000000..5daaf54c
--- /dev/null
+++ b/app/src/main/java/com/wireguard/android/ProfileActivity.java
@@ -0,0 +1,96 @@
+package com.wireguard.android;
+
+import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import com.wireguard.config.Profile;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Activity that allows creating/viewing/editing/deleting WireGuard profiles.
+ */
+
+public class ProfileActivity extends Activity {
+ private final ServiceConnection connection = new ProfileServiceConnection();
+ private final List<ServiceConnectionListener> listeners = new ArrayList<>();
+ private ProfileServiceInterface service;
+
+ public void addServiceConnectionListener(ServiceConnectionListener listener) {
+ listeners.add(listener);
+ }
+
+ public ProfileServiceInterface getService() {
+ return service;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.profile_activity);
+ // Ensure the long-running service is started. This only needs to happen once.
+ Intent intent = new Intent(this, ProfileService.class);
+ startService(intent);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.main, menu);
+ return true;
+ }
+
+ public void onMenuSettings(MenuItem item) {
+
+ }
+
+ public void onProfileSelected(Profile profile) {
+
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ Intent intent = new Intent(this, ProfileService.class);
+ bindService(intent, connection, Context.BIND_AUTO_CREATE);
+ }
+
+ @Override
+ public void onStop() {
+ super.onStop();
+ if (service != null) {
+ unbindService(connection);
+ for (ServiceConnectionListener listener : listeners)
+ listener.onServiceDisconnected();
+ service = null;
+ }
+ }
+
+ public void removeServiceConnectionListener(ServiceConnectionListener listener) {
+ listeners.remove(listener);
+ }
+
+ private class ProfileServiceConnection implements ServiceConnection {
+ @Override
+ public void onServiceConnected(ComponentName component, IBinder binder) {
+ service = (ProfileServiceInterface) binder;
+ for (ServiceConnectionListener listener : listeners)
+ listener.onServiceConnected(service);
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName component) {
+ // This function is only called when the service crashes or goes away unexpectedly.
+ for (ServiceConnectionListener listener : listeners)
+ listener.onServiceDisconnected();
+ service = null;
+ }
+ }
+}