From cb73e6352c4f92915aa29ccd9134dc222b9833f4 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Thu, 14 May 2015 10:00:11 +1000 Subject: [PATCH] Cleaned up some lint errors, i18n some strings. --- F-Droid/res/values/strings.xml | 7 +++++-- .../fdroid/fdroid/net/BluetoothDownloader.java | 12 +++--------- .../fdroid/fdroid/net/WifiStateChangeService.java | 1 + .../fdroid/net/bluetooth/BluetoothClient.java | 3 ++- .../fdroid/net/bluetooth/BluetoothConnection.java | 2 +- .../fdroid/net/bluetooth/BluetoothServer.java | 15 ++++++++++----- .../fdroid/net/bluetooth/httpish/Request.java | 14 +++++++++----- .../fdroid/net/bluetooth/httpish/Response.java | 2 +- .../views/swap/BluetoothDeviceListFragment.java | 6 +++--- .../fdroid/fdroid/views/swap/SwapActivity.java | 3 ++- 10 files changed, 37 insertions(+), 28 deletions(-) diff --git a/F-Droid/res/values/strings.xml b/F-Droid/res/values/strings.xml index fb94347b9..77aebe2fe 100644 --- a/F-Droid/res/values/strings.xml +++ b/F-Droid/res/values/strings.xml @@ -329,6 +329,9 @@ May work Promising Best bet - Your device is - Select from devices below, or press \"Scan\" from the menu to find more devices. + Your device is + Select from devices below, or press \"Scan\" from the menu to find more devices. + Bonded + Currently bonding... + Unknown device diff --git a/F-Droid/src/org/fdroid/fdroid/net/BluetoothDownloader.java b/F-Droid/src/org/fdroid/fdroid/net/BluetoothDownloader.java index 5dcf02758..a860e2aa2 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/BluetoothDownloader.java +++ b/F-Droid/src/org/fdroid/fdroid/net/BluetoothDownloader.java @@ -17,18 +17,12 @@ import java.net.MalformedURLException; public class BluetoothDownloader extends Downloader { - private static final String TAG = "org.fdroid.fdroid.net.BluetoothDownloader"; + private static final String TAG = "BluetoothDownloader"; private final BluetoothConnection connection; private FileDetails fileDetails; private final String sourcePath; - public BluetoothDownloader(BluetoothConnection connection, String sourcePath, String destFile, Context ctx) throws FileNotFoundException, MalformedURLException { - super(destFile, ctx); - this.connection = connection; - this.sourcePath = sourcePath; - } - public BluetoothDownloader(BluetoothConnection connection, String sourcePath, Context ctx) throws IOException { super(ctx); this.connection = connection; @@ -54,7 +48,7 @@ public class BluetoothDownloader extends Downloader { // TODO: Manage the dependency which includes this class better? // Right now, I only needed the one class from apache commons. - // There are countless classes online which provide this functionaligy, + // There are countless classes online which provide this functionality, // including some which are available from the Android SDK - the only // problem is that they have a funky API which doesn't just wrap a // plain old InputStream (the class is ContentLengthInputStream - @@ -67,7 +61,7 @@ public class BluetoothDownloader extends Downloader { /** * May return null if an error occurred while getting file details. - * TODO: Should we throw an exception? Everywhere else in this blue package throws IO exceptions weely neely. + * TODO: Should we throw an exception? Everywhere else in this blue package throws IO exceptions weelx`x`xy-neely. * Will probably require some thought as to how the API looks, with regards to all of the public methods * and their signatures. */ diff --git a/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java b/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java index 8277daa3a..8ec1527af 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java +++ b/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java @@ -151,6 +151,7 @@ public class WifiStateChangeService extends Service { Intent intent = new Intent(BROADCAST); LocalBroadcastManager.getInstance(WifiStateChangeService.this).sendBroadcast(intent); WifiStateChangeService.this.stopSelf(); + FDroidApp.localRepoWifi.restartIfRunning(); } } diff --git a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothClient.java b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothClient.java index 886b215f6..fe45b8ee3 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothClient.java +++ b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothClient.java @@ -7,7 +7,8 @@ import java.io.IOException; public class BluetoothClient { - private static final String TAG = "org.fdroid.fdroid.net.bluetooth.BluetoothClient"; + @SuppressWarnings("unused") + private static final String TAG = "BluetoothClient"; private BluetoothDevice device; diff --git a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothConnection.java b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothConnection.java index 43ba63d8d..c74f1e3cd 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothConnection.java +++ b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothConnection.java @@ -12,7 +12,7 @@ import java.io.OutputStream; public class BluetoothConnection { - private static final String TAG = "org.fdroid.fdroid.net.bluetooth.BluetoothConnection"; + private static final String TAG = "BluetoothConnection"; private InputStream input = null; private OutputStream output = null; diff --git a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java index 111ec3f78..493cc47be 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java +++ b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java @@ -4,6 +4,7 @@ import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothServerSocket; import android.bluetooth.BluetoothSocket; import android.content.Context; +import android.os.Build; import android.util.Log; import org.fdroid.fdroid.FDroidApp; import org.fdroid.fdroid.Utils; @@ -21,10 +22,10 @@ import java.util.List; */ public class BluetoothServer extends Thread { - private static final String TAG = "org.fdroid.fdroid.net.bluetooth.BluetoothServer"; + private static final String TAG = "BluetoothServer"; private BluetoothServerSocket serverSocket; - private List clients = new ArrayList(); + private List clients = new ArrayList<>(); private final Context context; @@ -75,8 +76,6 @@ public class BluetoothServer extends Thread { private static class Connection extends Thread { - private static final String TAG = "org.fdroid.fdroid.net.bluetooth.BluetoothServer.Connection"; - private final Context context; private final BluetoothSocket socket; @@ -139,7 +138,13 @@ public class BluetoothServer extends Thread { .build(); } catch (IOException e) { - throw new IOException("Error getting file " + request.getPath() + " from local repo proxy - " + e.getMessage(), e); + if (Build.VERSION.SDK_INT <= 9) { + // Would like to use the specific IOException below with a "cause", but it is + // only supported on SDK 9, so I guess this is the next most useful thing. + throw e; + } else { + throw new IOException("Error getting file " + request.getPath() + " from local repo proxy - " + e.getMessage(), e); + } } } diff --git a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Request.java b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Request.java index be10cd4e3..f78c981c4 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Request.java +++ b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Request.java @@ -15,11 +15,11 @@ import java.util.Map; public class Request { - private static final String TAG = "org.fdroid.fdroid.net.bluetooth.httpish.Request"; + private static final String TAG = "bluetooth.Request"; - public static interface Methods { - public static final String HEAD = "HEAD"; - public static final String GET = "GET"; + public interface Methods { + String HEAD = "HEAD"; + String GET = "GET"; } private String method; @@ -48,6 +48,10 @@ public class Request { return new Request(Methods.GET, path, connection); } + public String getHeaderValue(String header) { + return headers.containsKey(header) ? headers.get(header) : null; + } + public Response send() throws IOException { Log.d(TAG, "Sending request to server (" + path + ")"); @@ -141,7 +145,7 @@ public class Request { * our HTTP-ish implementation. */ private Map readHeaders() throws IOException { - Map headers = new HashMap(); + Map headers = new HashMap<>(); String responseLine = input.readLine(); while (responseLine != null && responseLine.length() > 0) { diff --git a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Response.java b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Response.java index e98e81a94..3e5b274b3 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Response.java +++ b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Response.java @@ -16,7 +16,7 @@ import java.util.Map; public class Response { - private static final String TAG = "org.fdroid.fdroid.net.bluetooth.httpish.Response"; + private static final String TAG = "bluetooth.Response"; private int statusCode; private Map headers; diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/BluetoothDeviceListFragment.java b/F-Droid/src/org/fdroid/fdroid/views/swap/BluetoothDeviceListFragment.java index 7719767b0..a13d69c08 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/BluetoothDeviceListFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/BluetoothDeviceListFragment.java @@ -304,12 +304,12 @@ public class BluetoothDeviceListFragment extends ThemeableListFragment { // TODO: Is the term "Bonded device" common parlance among phone users? // It sounds a bit technical to me, maybe something more lay like "Previously connected". // Although it is technically not as accurate, it would make sense to more people... - return "Bonded"; + return getString(R.string.swap_bluetooth_bonded_device); } else if (deviceBondState == BluetoothDevice.BOND_BONDING) { - return "Currently bonding..."; + return getString(R.string.swap_bluetooth_bonding_device); } else { // TODO: Might be a little bit harsh, makes it sound more malicious than it should. - return "Unknown device"; + return getString(R.string.swap_bluetooth_unknown_device); } } } diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapActivity.java b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapActivity.java index 47429edf4..d9499b0fd 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapActivity.java @@ -40,7 +40,7 @@ public class SwapActivity extends ActionBarActivity implements SwapProcessManage private static final int REQUEST_BLUETOOTH_ENABLE = 1; private static final int REQUEST_BLUETOOTH_DISCOVERABLE = 2; - private static final String TAG = "org.fdroid.fdroid.views.swap.SwapActivity"; + private static final String TAG = "SwapActivity"; private Timer shutdownLocalRepoTimer; private UpdateAsyncTask updateSwappableAppsTask = null; @@ -241,6 +241,7 @@ public class SwapActivity extends ActionBarActivity implements SwapProcessManage Log.d(TAG, "Initiating Bluetooth swap instead of wifi."); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); + // TODO: May be null (e.g. on an emulator). if (adapter.isEnabled()) { Log.d(TAG, "Bluetooth enabled, will pair with device."); ensureBluetoothDiscoverable();