[tor-commits] [orbot/master] better cookie dialog

n8fr8 at torproject.org n8fr8 at torproject.org
Thu Mar 2 04:10:21 UTC 2017


commit 8d5df9c9eb12371a7b7c0394a6f7bb6a90e75e4e
Author: arrase <arrase at gmail.com>
Date:   Mon Dec 5 21:14:15 2016 +0100

    better cookie dialog
---
 .../ui/hiddenservices/dialogs/HSActionsDialog.java |  7 +--
 .../ui/hiddenservices/dialogs/HSCookieDialog.java  | 56 ++++++++++++++++++++++
 .../ui/hiddenservices/dialogs/HSDataDialog.java    |  3 ++
 app/src/main/res/layout/layout_hs_cookie.xml       | 25 ++++++++++
 app/src/main/res/values/strings.xml                |  1 +
 5 files changed, 89 insertions(+), 3 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSActionsDialog.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSActionsDialog.java
index 06b650b..ff7f7e1 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSActionsDialog.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSActionsDialog.java
@@ -87,15 +87,16 @@ public class HSActionsDialog extends DialogFragment {
         showAuth.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 String auth_cookie_value = arguments.getString("auth_cookie_value");
+
                 if (arguments.getInt("auth_cookie") == 1) {
                     if (auth_cookie_value == null || auth_cookie_value.length() < 1) {
                         Toast.makeText(
                                 v.getContext(), R.string.please_restart_Orbot_to_enable_the_changes, Toast.LENGTH_LONG
                         ).show();
                     } else {
-                        new AlertDialog.Builder(getActivity())
-                                .setMessage(auth_cookie_value)
-                                .show();
+                        HSCookieDialog dialog = new HSCookieDialog();
+                        dialog.setArguments(arguments);
+                        dialog.show(getFragmentManager(), "HSCookieDialog");
                     }
                 } else {
                     Toast.makeText(
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSCookieDialog.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSCookieDialog.java
new file mode 100644
index 0000000..ff53cec
--- /dev/null
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSCookieDialog.java
@@ -0,0 +1,56 @@
+package org.torproject.android.ui.hiddenservices.dialogs;
+
+import android.app.Dialog;
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v4.app.DialogFragment;
+import android.support.v7.app.AlertDialog;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import org.torproject.android.R;
+
+public class HSCookieDialog extends DialogFragment {
+
+    @NonNull
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        final View dialog_view = getActivity().getLayoutInflater().inflate(R.layout.layout_hs_cookie, null);
+
+        final Bundle arguments = getArguments();
+        final String auth_cookie_value = arguments.getString("auth_cookie_value");
+
+        final AlertDialog cookieDialog = new AlertDialog.Builder(getActivity())
+                .setView(dialog_view)
+                .create();
+
+        TextView cookie = (TextView) dialog_view.findViewById(R.id.hs_cookie);
+        cookie.setText(auth_cookie_value);
+
+        Button clipboard = (Button) dialog_view.findViewById(R.id.hs_cookie_to_clipboard);
+        clipboard.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                Context mContext = v.getContext();
+                ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
+                ClipData clip = ClipData.newPlainText("cookie", auth_cookie_value);
+                clipboard.setPrimaryClip(clip);
+                Toast.makeText(mContext, R.string.done, Toast.LENGTH_LONG).show();
+                cookieDialog.dismiss();
+            }
+        });
+
+        Button cancel = (Button) dialog_view.findViewById(R.id.hs_cookie_cancel);
+        cancel.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                cookieDialog.dismiss();
+            }
+        });
+
+        return cookieDialog;
+    }
+}
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSDataDialog.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSDataDialog.java
index 56c6d3f..9825560 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSDataDialog.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSDataDialog.java
@@ -47,6 +47,9 @@ public class HSDataDialog extends DialogFragment {
 
                 if (checkInput(serverName, localPort, onionPort)) {
                     saveData(serverName, localPort, onionPort, authCookie);
+                    Toast.makeText(
+                            v.getContext(), R.string.please_restart_Orbot_to_enable_the_changes, Toast.LENGTH_LONG
+                    ).show();
                     serviceDataDialog.dismiss();
                 }
             }
diff --git a/app/src/main/res/layout/layout_hs_cookie.xml b/app/src/main/res/layout/layout_hs_cookie.xml
new file mode 100644
index 0000000..398178f
--- /dev/null
+++ b/app/src/main/res/layout/layout_hs_cookie.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical" android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:id="@+id/hs_cookie"
+        android:paddingBottom="5dp"
+        android:paddingLeft="5dp"
+        android:paddingTop="5dp" />
+
+    <Button
+        android:text="@string/copy_cookie_to_clipboard"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:id="@+id/hs_cookie_to_clipboard" />
+
+    <Button
+        android:text="@string/btn_cancel"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:id="@+id/hs_cookie_cancel" />
+</LinearLayout>
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b8192b8..4402608 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -364,6 +364,7 @@
     <string name="click_again_for_backup">Click again for backup</string>
     <string name="service_type">Service type</string>
     <string name="auth_cookie">Auth cookie</string>
+    <string name="copy_cookie_to_clipboard">Copy cookie to clipboard</string>
     <string name="auth_cookie_was_not_configured">Auth cookie was not configured</string>
     <string name="please_restart_Orbot_to_enable_the_changes">Please restart Orbot to enable the changes</string>
 </resources>





More information about the tor-commits mailing list