[tor-commits] [orbot/master] Final linting round:

n8fr8 at torproject.org n8fr8 at torproject.org
Wed Oct 7 12:37:35 UTC 2020


commit e436df06d9616faebf01fdb1e08a5e5fe5bf80a7
Author: bim <dsnake at protonmail.com>
Date:   Tue Sep 15 23:30:15 2020 -0400

    Final linting round:
    - replaced deprecated Switch with androidx SwitchCompat
    - Made the country dropdown centered on the main activity UI
    - Removed XML attributes that do nothing
---
 .../org/torproject/android/OrbotMainActivity.java  |  5 +-
 .../adapters/ClientCookiesAdapter.java             | 13 ++---
 .../hiddenservices/adapters/OnionListAdapter.java  |  5 +-
 app/src/main/res/layout/layout_about.xml           |  2 +-
 app/src/main/res/layout/layout_apps.xml            |  1 -
 .../res/layout/layout_client_cookie_list_item.xml  |  2 +-
 app/src/main/res/layout/layout_hs_list_item.xml    |  8 ++--
 app/src/main/res/layout/layout_main.xml            | 56 +++++-----------------
 8 files changed, 29 insertions(+), 63 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
index f336e8bf..8c898fce 100644
--- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java
+++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java
@@ -45,6 +45,7 @@ import androidx.annotation.RequiresApi;
 import androidx.appcompat.app.AppCompatActivity;
 import androidx.appcompat.widget.SwitchCompat;
 import androidx.appcompat.widget.Toolbar;
+import androidx.core.content.res.ResourcesCompat;
 import androidx.core.view.GravityCompat;
 import androidx.drawerlayout.widget.DrawerLayout;
 import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@@ -316,8 +317,6 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan
 
         Intent intent = new Intent(OrbotMainActivity.this, OrbotService.class);
         stopService(intent);
-
-
     }
 
     private void doLayout() {
@@ -1204,7 +1203,7 @@ public class OrbotMainActivity extends AppCompatActivity implements OrbotConstan
         LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
         params.setMargins(3, 3, 3, 3);
         iv.setLayoutParams(params);
-        iv.setImageDrawable(getResources().getDrawable(R.drawable.ic_settings_white_24dp));
+        iv.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_settings_white_24dp, null));
         llBoxShortcuts.addView(iv);
         iv.setOnClickListener(v -> startActivityForResult(new Intent(OrbotMainActivity.this, AppManagerActivity.class), REQUEST_VPN_APPS_SELECT));
     }
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/adapters/ClientCookiesAdapter.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/adapters/ClientCookiesAdapter.java
index f61958cd..e7123522 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/adapters/ClientCookiesAdapter.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/adapters/ClientCookiesAdapter.java
@@ -4,11 +4,12 @@ import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
+
+import androidx.appcompat.widget.SwitchCompat;
 import androidx.cursoradapter.widget.CursorAdapter;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.Switch;
 import android.widget.TextView;
 import android.widget.Toast;
 import org.torproject.android.R;
@@ -33,7 +34,7 @@ public class ClientCookiesAdapter extends CursorAdapter {
         TextView domain = view.findViewById(R.id.cookie_onion);
         domain.setText(cursor.getString(cursor.getColumnIndex(CookieContentProvider.ClientCookie.DOMAIN)));
 
-        Switch enabled = view.findViewById(R.id.cookie_switch);
+        SwitchCompat enabled = view.findViewById(R.id.cookie_switch);
         enabled.setChecked(
                 cursor.getInt(cursor.getColumnIndex(CookieContentProvider.ClientCookie.ENABLED)) == 1
         );
@@ -42,13 +43,9 @@ public class ClientCookiesAdapter extends CursorAdapter {
             ContentResolver resolver = mContext.getContentResolver();
             ContentValues fields = new ContentValues();
             fields.put(CookieContentProvider.ClientCookie.ENABLED, isChecked);
-            resolver.update(
-                    CookieContentProvider.CONTENT_URI, fields, where, null
-            );
+            resolver.update(CookieContentProvider.CONTENT_URI, fields, where, null);
 
-            Toast.makeText(
-                    mContext, R.string.please_restart_Orbot_to_enable_the_changes, Toast.LENGTH_LONG
-            ).show();
+            Toast.makeText(mContext, R.string.please_restart_Orbot_to_enable_the_changes, Toast.LENGTH_LONG).show();
         });
     }
 
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/adapters/OnionListAdapter.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/adapters/OnionListAdapter.java
index 895f2779..0d06ce3e 100644
--- a/app/src/main/java/org/torproject/android/ui/hiddenservices/adapters/OnionListAdapter.java
+++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/adapters/OnionListAdapter.java
@@ -4,11 +4,12 @@ import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
+
+import androidx.appcompat.widget.SwitchCompat;
 import androidx.cursoradapter.widget.CursorAdapter;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.Switch;
 import android.widget.TextView;
 import android.widget.Toast;
 import org.torproject.android.R;
@@ -37,7 +38,7 @@ public class OnionListAdapter extends CursorAdapter {
         TextView domain = view.findViewById(R.id.hs_onion);
         domain.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.DOMAIN)));
 
-        Switch enabled = view.findViewById(R.id.hs_switch);
+        SwitchCompat enabled = view.findViewById(R.id.hs_switch);
         enabled.setChecked(
                 cursor.getInt(cursor.getColumnIndex(HSContentProvider.HiddenService.ENABLED)) == 1
         );
diff --git a/app/src/main/res/layout/layout_about.xml b/app/src/main/res/layout/layout_about.xml
index dca409c9..6f338ec7 100644
--- a/app/src/main/res/layout/layout_about.xml
+++ b/app/src/main/res/layout/layout_about.xml
@@ -12,7 +12,7 @@
 
         <LinearLayout
             android:layout_width="fill_parent"
-            android:layout_height="fill_parent"
+            android:layout_height="wrap_content"
             android:orientation="vertical">
 
             <TextView
diff --git a/app/src/main/res/layout/layout_apps.xml b/app/src/main/res/layout/layout_apps.xml
index bc35af99..49215fe8 100644
--- a/app/src/main/res/layout/layout_apps.xml
+++ b/app/src/main/res/layout/layout_apps.xml
@@ -15,7 +15,6 @@
         android:id="@+id/applistview"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_alignParentTop="true"
         android:gravity="center"
         android:horizontalSpacing="5dp"
         android:numColumns="4"
diff --git a/app/src/main/res/layout/layout_client_cookie_list_item.xml b/app/src/main/res/layout/layout_client_cookie_list_item.xml
index 1d5d1ccb..213ba6cb 100644
--- a/app/src/main/res/layout/layout_client_cookie_list_item.xml
+++ b/app/src/main/res/layout/layout_client_cookie_list_item.xml
@@ -12,7 +12,7 @@
         android:textSize="18sp"
         android:layout_weight="1" />
 
-    <Switch
+    <androidx.appcompat.widget.SwitchCompat
         android:id="@+id/cookie_switch"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
diff --git a/app/src/main/res/layout/layout_hs_list_item.xml b/app/src/main/res/layout/layout_hs_list_item.xml
index e83b8747..8f603bd9 100644
--- a/app/src/main/res/layout/layout_hs_list_item.xml
+++ b/app/src/main/res/layout/layout_hs_list_item.xml
@@ -18,8 +18,8 @@
             android:id="@+id/hs_port"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            android:paddingRight="10dp"
             android:paddingTop="10dp"
+            android:paddingRight="10dp"
             android:textSize="35sp" />
 
         <LinearLayout
@@ -32,21 +32,21 @@
                 android:id="@+id/hs_name"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:paddingBottom="10dp"
                 android:paddingLeft="10dp"
+                android:paddingBottom="10dp"
                 android:textSize="24sp" />
 
             <TextView
                 android:id="@+id/hs_onion"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:paddingBottom="10dp"
                 android:paddingLeft="10dp"
+                android:paddingBottom="10dp"
                 android:textSize="18sp" />
 
         </LinearLayout>
 
-        <Switch
+        <androidx.appcompat.widget.SwitchCompat
             android:id="@+id/hs_switch"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
diff --git a/app/src/main/res/layout/layout_main.xml b/app/src/main/res/layout/layout_main.xml
index ce70f957..7ff57108 100644
--- a/app/src/main/res/layout/layout_main.xml
+++ b/app/src/main/res/layout/layout_main.xml
@@ -26,7 +26,7 @@
 
             <RelativeLayout
                 android:layout_width="match_parent"
-                android:layout_height="match_parent">
+                android:layout_height="wrap_content">
 
                 <FrameLayout
                     android:id="@+id/frameMain"
@@ -107,9 +107,7 @@
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_below="@+id/lblPorts"
-                    android:orientation="horizontal"
-
-                    >
+                    android:orientation="horizontal">
 
                     <LinearLayout
                         android:layout_width="170dp"
@@ -119,21 +117,14 @@
                         android:layout_weight="1"
                         android:background="#11CCCCCC"
                         android:orientation="vertical">
-                        <!--
-                <TextView
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:text="Select Region"
-                    android:layout_margin="12dp"
 
-                    />-->
                         <Spinner
                             android:id="@+id/spinnerCountry"
                             android:layout_width="165dp"
                             android:layout_height="wrap_content"
+                            android:layout_gravity="center"
                             android:layout_margin="9dp"
-
-                            />
+                            android:padding="3dp" />
 
                     </LinearLayout>
 
@@ -145,9 +136,7 @@
                         android:layout_margin="3dp"
                         android:layout_weight="1"
                         android:background="#11CCCCCC"
-                        android:orientation="vertical"
-
-                        >
+                        android:orientation="vertical">
 
                         <androidx.appcompat.widget.SwitchCompat
                             android:id="@+id/btnVPN"
@@ -156,9 +145,7 @@
                             android:layout_gravity="center"
                             android:layout_margin="9dp"
                             android:text="@string/apps_mode"
-                            app:switchPadding="3dp"
-
-                            />
+                            app:switchPadding="3dp" />
                     </LinearLayout>
 
                 </LinearLayout>
@@ -169,9 +156,7 @@
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_below="@+id/controls"
-                    android:orientation="horizontal"
-
-                    >
+                    android:orientation="horizontal">
 
                     <LinearLayout
                         android:layout_width="170dp"
@@ -188,9 +173,7 @@
                             android:fontFamily="sans-serif-light"
                             android:gravity="center"
                             android:lines="1"
-                            android:text="@string/main_layout_download"
-
-                            />
+                            android:text="@string/main_layout_download" />
 
 
                         <TextView
@@ -201,9 +184,7 @@
                             android:fontFamily="sans-serif-light"
                             android:gravity="center_vertical"
                             android:lines="1"
-                            android:text="0kbps"
-
-                            />
+                            android:text="0kbps" />
                     </LinearLayout>
 
 
@@ -213,9 +194,7 @@
                         android:layout_gravity="center"
                         android:layout_margin="3dp"
                         android:layout_weight="1"
-                        android:orientation="horizontal"
-
-                        >
+                        android:orientation="horizontal">
 
                         <TextView
                             android:layout_width="wrap_content"
@@ -233,9 +212,7 @@
                             android:fontFamily="sans-serif-light"
                             android:gravity="center_vertical"
                             android:lines="1"
-                            android:text="0kbps"
-
-                            />
+                            android:text="0kbps" />
 
                     </LinearLayout>
 
@@ -247,7 +224,6 @@
                     android:layout_height="40dp"
                     android:layout_below="@+id/traffic"
                     android:layout_margin="3dp"
-                    android:layout_weight="1"
                     android:background="#11CCCCCC"
                     android:gravity="center_horizontal"
                     android:orientation="horizontal">
@@ -259,16 +235,12 @@
                         android:fontFamily="sans-serif-light"
                         android:gravity="center_vertical"
                         android:lines="1"
-                        android:text="@string/trouble_connecting"
-
-                        />
+                        android:text="@string/trouble_connecting" />
 
                     <androidx.appcompat.widget.SwitchCompat
                         android:id="@+id/btnBridges"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
-                        android:layout_centerHorizontal="true"
-                        android:layout_centerVertical="true"
                         android:layout_margin="3dp"
                         android:layout_marginTop="10dp"
                         android:text="@string/use_bridges"
@@ -281,7 +253,6 @@
                     android:layout_height="80dp"
                     android:layout_below="@+id/row_bridges"
                     android:layout_margin="3dp"
-                    android:layout_weight="1"
                     android:background="#55CCCCCC"
                     android:gravity="center_horizontal"
                     android:orientation="vertical">
@@ -301,7 +272,7 @@
                         android:layout_height="wrap_content"
                         android:gravity="center"
                         android:orientation="horizontal"
-                        android:padding="3dp"/>
+                        android:padding="3dp" />
                 </LinearLayout>
 
 
@@ -327,7 +298,6 @@
                 android:id="@+id/orbotLog"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
-                android:layout_alignParentLeft="true"
                 android:layout_marginTop="10dp"
                 android:fontFamily="monospace"
                 android:gravity="start"





More information about the tor-commits mailing list