[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] Hidden Service dialog



commit 3f7435c90e3aa468046b1994938bf6b2b3d821a2
Author: arrase <arrase@xxxxxxxxx>
Date:   Thu Nov 17 02:57:37 2016 +0100

    Hidden Service dialog
---
 .../android/ui/hs/HiddenServicesActivity.java      |  6 +-
 .../android/ui/hs/dialogs/HSDataDialog.java        | 84 ++++++++++++++++++++++
 app/src/main/res/layout/dialog_hs_data.xml         | 63 ++++++++++++++++
 app/src/main/res/values/strings.xml                |  6 ++
 proguard-project.txt                               | 20 ++++++
 project.properties                                 |  2 +-
 6 files changed, 177 insertions(+), 4 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java b/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java
index 85665fb..ebf1ec3 100644
--- a/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java
@@ -5,7 +5,6 @@ import android.database.ContentObserver;
 import android.os.Bundle;
 import android.os.Handler;
 import android.support.design.widget.FloatingActionButton;
-import android.support.design.widget.Snackbar;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
@@ -14,6 +13,7 @@ import android.view.View;
 
 import org.torproject.android.R;
 import org.torproject.android.ui.hs.adapters.HSAdapter;
+import org.torproject.android.ui.hs.dialogs.HSDataDialog;
 import org.torproject.android.ui.hs.providers.HSContentProvider;
 
 public class HiddenServicesActivity extends AppCompatActivity {
@@ -37,8 +37,8 @@ public class HiddenServicesActivity extends AppCompatActivity {
         fab.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
-                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
-                        .setAction("Action", null).show();
+                HSDataDialog dialog = new HSDataDialog();
+                dialog.show(getSupportFragmentManager(), "HSDataDialog");
             }
         });
 
diff --git a/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSDataDialog.java b/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSDataDialog.java
new file mode 100644
index 0000000..e62d2cb
--- /dev/null
+++ b/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSDataDialog.java
@@ -0,0 +1,84 @@
+package org.torproject.android.ui.hs.dialogs;
+
+
+import android.app.Dialog;
+import android.content.ContentResolver;
+import android.content.ContentValues;
+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.EditText;
+import android.widget.Toast;
+
+import org.torproject.android.R;
+import org.torproject.android.ui.hs.providers.HSContentProvider;
+
+public class HSDataDialog extends DialogFragment {
+
+    @NonNull
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        // Get the layout
+        final View dialog_view = getActivity().getLayoutInflater().inflate(R.layout.dialog_hs_data, null);
+
+        // Use the Builder class for convenient dialog construction
+        final AlertDialog serverDataDialog = new AlertDialog.Builder(getActivity())
+                .setView(dialog_view)
+                .setTitle(R.string.hs_dialog_title)
+                .create();
+
+        // Buttons action
+        Button save = (Button) dialog_view.findViewById(R.id.HSDialogSave);
+        save.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                String serverName = ((EditText) dialog_view.findViewById(R.id.hsName)).getText().toString();
+                Integer serverPort = Integer.parseInt(
+                        ((EditText) dialog_view.findViewById(R.id.serverPort)).getText().toString()
+                );
+
+                if (checkInput(serverPort)) {
+                    saveData(serverName, serverPort);
+                    serverDataDialog.dismiss();
+                }
+            }
+        });
+
+        Button cancel = (Button) dialog_view.findViewById(R.id.HSDialogCancel);
+        cancel.setOnClickListener(new View.OnClickListener() {
+            public void onClick(View v) {
+                serverDataDialog.cancel();
+            }
+        });
+
+        return serverDataDialog;
+    }
+
+    private boolean checkInput(Integer port) {
+        boolean is_ok = true;
+        Integer error_msg = 0;
+
+        if (port <= 1 || port > 65535) {
+            error_msg = R.string.invalid_port;
+            is_ok = false;
+        }
+
+        if (!is_ok) {
+            Toast.makeText(getContext(), error_msg, Toast.LENGTH_SHORT).show();
+        }
+
+        return is_ok;
+    }
+
+    private void saveData(String name, Integer port) {
+        ContentValues fields = new ContentValues();
+        fields.put("name", name);
+        fields.put("port", port);
+
+        ContentResolver cr = getContext().getContentResolver();
+
+        cr.insert(HSContentProvider.CONTENT_URI, fields);
+    }
+}
diff --git a/app/src/main/res/layout/dialog_hs_data.xml b/app/src/main/res/layout/dialog_hs_data.xml
new file mode 100644
index 0000000..2f4daa6
--- /dev/null
+++ b/app/src/main/res/layout/dialog_hs_data.xml
@@ -0,0 +1,63 @@
+<?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="wrap_content"
+    android:paddingLeft="5dp"
+    android:paddingRight="5dp"
+    android:paddingTop="5dp"
+    android:paddingBottom="5dp">
+
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:id="@+id/HSNameLabel"
+        android:text="@string/name"
+        android:textAppearance="@style/TextAppearance.AppCompat.Widget.PopupMenu.Small"
+        android:paddingLeft="5dp" />
+
+    <EditText
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:inputType="text"
+        android:ems="10"
+        android:id="@+id/hsName" />
+
+    <TextView
+        android:text="@string/port"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:id="@+id/HSPortLabel"
+        android:textAppearance="@style/TextAppearance.AppCompat.Widget.PopupMenu.Small"
+        android:paddingLeft="5dp" />
+
+    <EditText
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:ems="10"
+        android:id="@+id/serverPort"
+        android:inputType="number" />
+
+    <LinearLayout
+        android:orientation="horizontal"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <Button
+            android:text="@string/cancel"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/HSDialogCancel"
+            android:layout_weight="1"
+            style="@style/Widget.AppCompat.Button.Borderless.Colored" />
+
+        <Button
+            android:text="@string/save"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/HSDialogSave"
+            android:layout_weight="1"
+            style="@style/Widget.AppCompat.Button.Borderless.Colored" />
+    </LinearLayout>
+
+</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 bd93d6d..333ac58 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -331,4 +331,10 @@
 
     <string name="vpn_default_world">World (Location)</string>
     <string name="title_activity_hidden_services">Hidden Services</string>
+    <string name="save">Save</string>
+    <string name="cancel">Cancel</string>
+    <string name="hs_dialog_title">Hidden Service</string>
+    <string name="port">Port</string>
+    <string name="name">Name</string>
+    <string name="invalid_port">Invalid Port</string>
 </resources>
diff --git a/proguard-project.txt b/proguard-project.txt
index e69de29..f2fe155 100644
--- a/proguard-project.txt
+++ b/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
diff --git a/project.properties b/project.properties
index 145c9f2..240497d 100644
--- a/project.properties
+++ b/project.properties
@@ -9,6 +9,6 @@
 #proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt
 
 # Project target.
-target=android-23
+target=android-15
 android.library.reference.1=external/jsocks/jsockslib
 android.library.reference.2=external/appcompat



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits