[tor-commits] [orbot/master] About dialog remains open on rotation. Added an android:id to its

n8fr8 at torproject.org n8fr8 at torproject.org
Mon Aug 24 21:02:51 UTC 2020


commit 872b52481a6292fcb18d2e3af51b548c4e9603ec
Author: bim <dsnake at protonmail.com>
Date:   Sun May 10 18:25:15 2020 -0400

    About dialog remains open on rotation. Added an android:id to its
    ScrollView so its position is retained too.
---
 .../org/torproject/android/OrbotMainActivity.java  |  66 +-----
 .../android/ui/dialog/AboutDialogFragment.java     |  90 +++++++
 app/src/main/res/layout/layout_about.xml           | 258 ++++++++++++---------
 3 files changed, 239 insertions(+), 175 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index 7c4528d5..837d7e60 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -6,6 +6,7 @@ package org.torproject.android;
 import android.app.ActivityManager;
 import android.app.ActivityManager.RunningServiceInfo;
 import android.app.AlertDialog;
+
 import android.content.BroadcastReceiver;
 import android.content.ContentResolver;
 import android.content.ContentValues;
@@ -17,14 +18,12 @@ import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
 import android.database.Cursor;
 import android.net.Uri;
 import android.net.VpnService;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
-import android.text.Html;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.Menu;
@@ -66,6 +65,7 @@ import org.torproject.android.settings.LocaleHelper;
 import org.torproject.android.settings.SettingsPreferences;
 import org.torproject.android.ui.AppManagerActivity;
 import org.torproject.android.ui.Rotate3dAnimation;
+import org.torproject.android.ui.dialog.AboutDialogFragment;
 import org.torproject.android.ui.hiddenservices.ClientCookiesActivity;
 import org.torproject.android.ui.hiddenservices.HiddenServicesActivity;
 import org.torproject.android.ui.hiddenservices.backup.BackupUtils;
@@ -74,10 +74,7 @@ import org.torproject.android.ui.hiddenservices.providers.HSContentProvider;
 import org.torproject.android.ui.onboarding.BridgeWizardActivity;
 import org.torproject.android.ui.onboarding.OnboardingActivity;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
@@ -466,8 +463,7 @@ public class OrbotMainActivity extends AppCompatActivity
             doExit();
 
         } else if (item.getItemId() == R.id.menu_about) {
-            showAbout();
-
+            new AboutDialogFragment().show(getSupportFragmentManager(), AboutDialogFragment.TAG);
         } else if (item.getItemId() == R.id.menu_scan) {
             IntentIntegrator integrator = new IntentIntegrator(OrbotMainActivity.this);
             integrator.initiateScan();
@@ -496,51 +492,6 @@ public class OrbotMainActivity extends AppCompatActivity
         return super.onOptionsItemSelected(item);
     }
 
-    private void showAbout() {
-        View view = getLayoutInflater().inflate(R.layout.layout_about, null);
-        String version;
-
-        try {
-            version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName + " (Tor " + OrbotService.BINARY_TOR_VERSION + ")";
-        } catch (NameNotFoundException e) {
-            version = "Version Not Found";
-        }
-
-        TextView versionName = view.findViewById(R.id.versionName);
-        versionName.setText(version);
-
-        TextView aboutOther = view.findViewById(R.id.aboutother);
-
-        try {
-            String aboutText = readFromAssets(this, "LICENSE");
-            aboutText = aboutText.replace("\n", "<br/>");
-            aboutOther.setText(Html.fromHtml(aboutText));
-        } catch (IOException e) {
-        }
-
-
-        new AlertDialog.Builder(this)
-                .setTitle(getString(R.string.button_about))
-                .setView(view)
-                .show();
-    }
-
-    @SuppressWarnings("SameParameterValue")
-    private static String readFromAssets(Context context, String filename) throws IOException {
-        BufferedReader reader = new BufferedReader(new InputStreamReader(context.getAssets().open(filename)));
-
-        // do reading, usually loop until end of file reading
-        StringBuilder sb = new StringBuilder();
-        String mLine = reader.readLine();
-        while (mLine != null) {
-            sb.append(mLine).append('\n'); // process line
-            mLine = reader.readLine();
-        }
-        reader.close();
-        return sb.toString();
-    }
-
-
     /**
      * This is our attempt to REALLY exit Orbot, and stop the background service
      * However, Android doesn't like people "quitting" apps, and/or our code may
@@ -589,14 +540,13 @@ public class OrbotMainActivity extends AppCompatActivity
 
             Intent intentVPN = VpnService.prepare(this);
             if (intentVPN != null)
-                startActivityForResult(intentVPN,REQUEST_VPN);
+                startActivityForResult(intentVPN, REQUEST_VPN);
             else {
                 sendIntentToService(ACTION_START);
                 sendIntentToService(ACTION_START_VPN);
             }
 
-        } else
-        {
+        } else {
             //stop the VPN here
             sendIntentToService(ACTION_STOP_VPN);
         }
@@ -879,11 +829,9 @@ public class OrbotMainActivity extends AppCompatActivity
                     torStatus.equals(TorServiceConstants.STATUS_ON))
                 refreshVPNApps();
 
-        }
-        else if (request == REQUEST_VPN && response == RESULT_OK) {
+        } else if (request == REQUEST_VPN && response == RESULT_OK) {
             sendIntentToService(ACTION_START_VPN);
-        }
-        else if (request == REQUEST_VPN && response == RESULT_CANCELED) {
+        } else if (request == REQUEST_VPN && response == RESULT_CANCELED) {
             mBtnVPN.setChecked(false);
             Prefs.putUseVpn(false);
         }
diff --git a/app/src/main/java/org/torproject/android/ui/dialog/AboutDialogFragment.java b/app/src/main/java/org/torproject/android/ui/dialog/AboutDialogFragment.java
new file mode 100644
index 00000000..38b9821a
--- /dev/null
+++ b/app/src/main/java/org/torproject/android/ui/dialog/AboutDialogFragment.java
@@ -0,0 +1,90 @@
+package org.torproject.android.ui.dialog;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.text.Html;
+import android.view.View;
+import android.widget.TextView;
+
+import androidx.fragment.app.DialogFragment;
+
+import org.torproject.android.R;
+import org.torproject.android.service.OrbotService;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+public class AboutDialogFragment extends DialogFragment {
+
+    public static final String TAG = AboutDialogFragment.class.getSimpleName();
+
+    private TextView tvAbout;
+    private static final String BUNDLE_KEY_TV_ABOUT_TEXT = "about_tv_txt";
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        View view = getActivity().getLayoutInflater().inflate(R.layout.layout_about, null);
+        String version;
+
+        try {
+            version = getContext().getPackageManager().getPackageInfo(
+                    getContext().getPackageName(), 0).versionName + " (Tor " +
+                    OrbotService.BINARY_TOR_VERSION + ")";
+        } catch (PackageManager.NameNotFoundException e) {
+            version = "Version Not Found";
+        }
+
+        TextView versionName = view.findViewById(R.id.versionName);
+        versionName.setText(version);
+
+        tvAbout = view.findViewById(R.id.aboutother);
+
+        boolean buildAboutText = true;
+
+        if (savedInstanceState != null) {
+            String tvAboutText = savedInstanceState.getParcelable(BUNDLE_KEY_TV_ABOUT_TEXT);
+            if (tvAboutText != null) {
+                buildAboutText = false;
+                tvAbout.setText(tvAboutText);
+            }
+        }
+
+        if (buildAboutText) {
+            try {
+                String aboutText = readFromAssets(getContext(), "LICENSE");
+                aboutText = aboutText.replace("\n", "<br/>");
+                tvAbout.setText(Html.fromHtml(aboutText));
+            } catch (IOException e) {
+            }
+        }
+        return new AlertDialog.Builder(getContext())
+                .setTitle(getString(R.string.button_about))
+                .setView(view)
+                .create();
+    }
+
+    @SuppressWarnings("SameParameterValue")
+    private static String readFromAssets(Context context, String filename) throws IOException {
+        BufferedReader reader = new BufferedReader(new InputStreamReader(context.getAssets().open(filename)));
+
+        // do reading, usually loop until end of file reading
+        StringBuilder sb = new StringBuilder();
+        String mLine = reader.readLine();
+        while (mLine != null) {
+            sb.append(mLine).append('\n'); // process line
+            mLine = reader.readLine();
+        }
+        reader.close();
+        return sb.toString();
+    }
+
+    @Override
+    public void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putString(BUNDLE_KEY_TV_ABOUT_TEXT, tvAbout.getText().toString());
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/layout_about.xml b/app/src/main/res/layout/layout_about.xml
index 9d01498b..ce1792b3 100644
--- a/app/src/main/res/layout/layout_about.xml
+++ b/app/src/main/res/layout/layout_about.xml
@@ -1,117 +1,143 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
-    android:layout_width="fill_parent"
-    android:layout_height="fill_parent">
-	<ScrollView
-        android:orientation="vertical"
-		android:layout_width="fill_parent" 
-		android:layout_height="fill_parent">    
-		<LinearLayout
-		    android:orientation="vertical"
-		    android:layout_width="fill_parent"
-		    android:layout_height="fill_parent">
-		    <TextView android:text="@string/wizard_details"
-				android:layout_width="fill_parent" 
-				android:layout_height="wrap_content"		
-				android:paddingTop="15px"
-				android:paddingLeft="15px"
-				android:textStyle="bold"
-				android:textColor="#00ff00" />	
-			<TextView android:text="@string/wizard_details_msg"
-				android:layout_width="fill_parent" 
-				android:layout_height="wrap_content"
-				android:autoLink="web"
-				android:textColorLink="#ffffff"
-				android:paddingLeft="15px"		
-				android:textColor="#ffffff" />
-				
-			<TextView android:text="Version: "
-				android:layout_width="fill_parent" 
-				android:layout_height="wrap_content"
-				android:paddingTop="15px"
-				android:paddingLeft="15px"
-				android:textStyle="bold"
-				android:textColor="#00ff00" />
-			<TextView android:text="- Unknown -"
-				android:id="@+id/versionName"
-				android:layout_width="fill_parent" 
-				android:layout_height="wrap_content"
-				android:paddingLeft="15px"		
-				android:layout_gravity="center_vertical"
-				android:textColor="#ffffff" />	
-			<TextView android:text="@string/project_home"
-				android:layout_width="fill_parent" 
-				android:layout_height="wrap_content"		
-				android:paddingTop="15px"
-				android:paddingLeft="15px"
-				android:textStyle="bold"
-				android:textColor="#00ff00" />
-			<TextView android:text="@string/project_urls"
-				android:layout_width="fill_parent" 
-				android:layout_height="wrap_content"
-				android:autoLink="web"
-				android:textColorLink="#ffffff"
-				android:paddingLeft="15px"		
-				android:textColor="#ffffff" />
-			<TextView android:text="@string/third_party_software"
-				android:layout_width="fill_parent" 
-				android:layout_height="wrap_content"		
-				android:paddingTop="15px"
-				android:paddingLeft="15px"
-				android:textStyle="bold"
-				android:textColor="#00ff00" />	
-			<TextView android:text="@string/tor_version"
-				android:layout_width="fill_parent" 
-				android:layout_height="wrap_content"
-				android:autoLink="web"
-				android:textColorLink="#ffffff"
-				android:paddingLeft="15px"
-				android:textColor="#ffffff" />				
-			<TextView android:text="@string/libevent_version"
-				android:layout_width="fill_parent" 
-				android:layout_height="wrap_content"
-				android:autoLink="web"
-				android:textColorLink="#ffffff"
-				android:paddingLeft="15px"	
-				android:textColor="#ffffff" />	
-			<TextView android:text="@string/polipo_version"
-				android:layout_width="fill_parent" 
-				android:layout_height="wrap_content"
-				android:autoLink="web"
-				android:textColorLink="#ffffff"
-				android:paddingLeft="15px"	
-				android:textColor="#ffffff" />	
-			<TextView android:text="@string/obfsproxy_version"
-				android:layout_width="fill_parent" 
-				android:layout_height="wrap_content"
-				android:autoLink="web"
-				android:textColorLink="#ffffff"
-				android:paddingLeft="15px"
-				android:textColor="#ffffff"/>
-			<TextView android:text="@string/openssl_version"
-				android:layout_width="fill_parent" 
-				android:layout_height="wrap_content"
-				android:autoLink="web"
-				android:textColorLink="#ffffff"
-				android:paddingLeft="15px"	
-				android:textColor="#ffffff" />
-
-			<TextView android:text="License: "
-				android:layout_width="fill_parent"
-				android:layout_height="wrap_content"
-				android:paddingTop="15px"
-				android:paddingLeft="15px"
-				android:textStyle="bold"
-				android:textColor="#00ff00" />
-			<TextView
-				android:id="@+id/aboutother"
-				android:layout_width="fill_parent"
-				android:layout_height="wrap_content"
-				android:autoLink="web"
-				android:textColorLink="#ffffff"
-				android:paddingLeft="15px"
-				android:textColor="#ffffff" />
-		</LinearLayout>
-		</ScrollView>			
+<?xml version="1.0" encoding="utf-8"?>)
+            archivesBaseName = "Orbot-$versionName"
+    android:orientation="vertical">
+
+    <ScrollView
+		android:id="@+id/scrollView"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:orientation="vertical">
+
+        <LinearLayout
+            android:layout_width="fill_parent"
+            android:layout_height="fill_parent"
+            android:orientation="vertical">
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:paddingLeft="15px"
+                android:paddingTop="15px"
+                android:text="@string/wizard_details"
+                android:textColor="#00ff00"
+                android:textStyle="bold" />
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:autoLink="web"
+                android:paddingLeft="15px"
+                android:text="@string/wizard_details_msg"
+                android:textColor="#ffffff"
+                android:textColorLink="#ffffff" />
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:paddingLeft="15px"
+                android:paddingTop="15px"
+                android:text="Version: "
+                android:textColor="#00ff00"
+                android:textStyle="bold" />
+
+            <TextView
+                android:id="@+id/versionName"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center_vertical"
+                android:paddingLeft="15px"
+                android:text="- Unknown -"
+                android:textColor="#ffffff" />
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:paddingLeft="15px"
+                android:paddingTop="15px"
+                android:text="@string/project_home"
+                android:textColor="#00ff00"
+                android:textStyle="bold" />
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:autoLink="web"
+                android:paddingLeft="15px"
+                android:text="@string/project_urls"
+                android:textColor="#ffffff"
+                android:textColorLink="#ffffff" />
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:paddingLeft="15px"
+                android:paddingTop="15px"
+                android:text="@string/third_party_software"
+                android:textColor="#00ff00"
+                android:textStyle="bold" />
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:autoLink="web"
+                android:paddingLeft="15px"
+                android:text="@string/tor_version"
+                android:textColor="#ffffff"
+                android:textColorLink="#ffffff" />
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:autoLink="web"
+                android:paddingLeft="15px"
+                android:text="@string/libevent_version"
+                android:textColor="#ffffff"
+                android:textColorLink="#ffffff" />
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:autoLink="web"
+                android:paddingLeft="15px"
+                android:text="@string/polipo_version"
+                android:textColor="#ffffff"
+                android:textColorLink="#ffffff" />
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:autoLink="web"
+                android:paddingLeft="15px"
+                android:text="@string/obfsproxy_version"
+                android:textColor="#ffffff"
+                android:textColorLink="#ffffff" />
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:autoLink="web"
+                android:paddingLeft="15px"
+                android:text="@string/openssl_version"
+                android:textColor="#ffffff"
+                android:textColorLink="#ffffff" />
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:paddingLeft="15px"
+                android:paddingTop="15px"
+                android:text="License: "
+                android:textColor="#00ff00"
+                android:textStyle="bold" />
+
+            <TextView
+                android:id="@+id/aboutother"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:autoLink="web"
+                android:paddingLeft="15px"
+                android:textColor="#ffffff"
+                android:textColorLink="#ffffff" />
+        </LinearLayout>
+    </ScrollView>
 </LinearLayout>





More information about the tor-commits mailing list