Skip to content

Commit 4627871

Browse files
authored
Merge pull request #4 from CodeDead/release/1.4.2
Release/1.4.2
2 parents 78936ea + 2d8f53d commit 4627871

File tree

26 files changed

+161
-184
lines changed

26 files changed

+161
-184
lines changed

app/build.gradle

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 29
4+
compileSdkVersion 30
55
defaultConfig {
66
applicationId "com.codedead.advancedportchecker"
7-
minSdkVersion 21
8-
targetSdkVersion 29
9-
versionCode 11
10-
versionName '1.4.1'
7+
minSdkVersion 24
8+
targetSdkVersion 30
9+
versionCode 12
10+
versionName '1.4.2'
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
vectorDrawables.useSupportLibrary = true
1313
}
@@ -20,22 +20,22 @@ android {
2020
productFlavors {
2121
}
2222
compileOptions {
23-
sourceCompatibility = 1.8
24-
targetCompatibility = 1.8
23+
sourceCompatibility JavaVersion.VERSION_1_8
24+
targetCompatibility JavaVersion.VERSION_1_8
2525
}
2626
}
2727

2828
dependencies {
2929
implementation fileTree(include: ['*.jar'], dir: 'libs')
30-
implementation 'androidx.core:core:1.1.0'
31-
implementation 'androidx.appcompat:appcompat:1.1.0'
32-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
33-
implementation 'com.google.android.material:material:1.0.0'
30+
implementation 'androidx.core:core:1.6.0'
31+
implementation 'androidx.appcompat:appcompat:1.3.0'
32+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
33+
implementation 'com.google.android.material:material:1.4.0'
3434
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
3535
implementation 'androidx.cardview:cardview:1.0.0'
3636
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
37-
implementation "androidx.preference:preference:1.1.0"
38-
testImplementation 'junit:junit:4.12'
39-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
40-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
37+
implementation "androidx.preference:preference:1.1.1"
38+
testImplementation 'junit:junit:4.13.2'
39+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
40+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
4141
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
tools:ignore="GoogleAppIndexingWarning">
2424
<activity
2525
android:name=".gui.activity.SettingsActivity"
26-
android:label="@string/title_activity_settings"></activity>
26+
android:label="@string/title_activity_settings" />
2727
<activity
2828
android:name=".gui.activity.LoadingActivity"
2929
android:configChanges="orientation|keyboardHidden|screenSize"

app/src/main/java/com/codedead/advancedportchecker/domain/controller/LocaleHelper.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class LocaleHelper {
1919
* @param context The Context object that is attached
2020
* @return The Context object containing correct resource properties
2121
*/
22-
public static Context onAttach(Context context) {
22+
public static Context onAttach(final Context context) {
2323
final String lang = getPersistedData(context, Locale.getDefault().getLanguage());
2424
return setLocale(context, lang);
2525
}
@@ -31,7 +31,7 @@ public static Context onAttach(Context context) {
3131
* @param defaultLanguage The default language code
3232
* @return The Context object containing correct resource properties
3333
*/
34-
public static Context onAttach(Context context, String defaultLanguage) {
34+
public static Context onAttach(final Context context, final String defaultLanguage) {
3535
final String lang = getPersistedData(context, defaultLanguage);
3636
return setLocale(context, lang);
3737
}
@@ -43,7 +43,7 @@ public static Context onAttach(Context context, String defaultLanguage) {
4343
* @param language The language that should be attached
4444
* @return The Context object containing correct resource properties
4545
*/
46-
public static Context setLocale(Context context, String language) {
46+
public static Context setLocale(final Context context, final String language) {
4747
persist(context, language);
4848

4949
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
@@ -60,7 +60,7 @@ public static Context setLocale(Context context, String language) {
6060
* @param defaultLanguage The default language code
6161
* @return The language code that is stored in the shared preferences
6262
*/
63-
private static String getPersistedData(Context context, String defaultLanguage) {
63+
private static String getPersistedData(final Context context, final String defaultLanguage) {
6464
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
6565
return preferences.getString("language", defaultLanguage);
6666
}
@@ -71,9 +71,9 @@ private static String getPersistedData(Context context, String defaultLanguage)
7171
* @param context The Context object that can be used to store preferences
7272
* @param language The language code that should be stored
7373
*/
74-
private static void persist(Context context, String language) {
75-
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
76-
SharedPreferences.Editor editor = preferences.edit();
74+
private static void persist(final Context context, final String language) {
75+
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
76+
final SharedPreferences.Editor editor = preferences.edit();
7777

7878
editor.putString("language", language);
7979
editor.apply();
@@ -87,7 +87,7 @@ private static void persist(Context context, String language) {
8787
* @return The Context object containing correct resource properties
8888
*/
8989
@TargetApi(Build.VERSION_CODES.N)
90-
private static Context updateResources(Context context, String language) {
90+
private static Context updateResources(final Context context, final String language) {
9191
final Locale locale = new Locale(language);
9292
Locale.setDefault(locale);
9393

@@ -104,7 +104,7 @@ private static Context updateResources(Context context, String language) {
104104
* @param language The language code that should be applied to the Context object
105105
* @return The Context object containing correct resource properties
106106
*/
107-
private static Context updateResourcesLegacy(Context context, String language) {
107+
private static Context updateResourcesLegacy(final Context context, final String language) {
108108
final Locale locale = new Locale(language);
109109
Locale.setDefault(locale);
110110

app/src/main/java/com/codedead/advancedportchecker/domain/controller/ScanController.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
public final class ScanController extends AsyncTask<Void, ScanProgress, Void> {
1616

17-
private String host;
18-
private int startPort;
19-
private int endPort;
20-
private int timeOut;
17+
private final String host;
18+
private final int startPort;
19+
private final int endPort;
20+
private final int timeOut;
2121

22-
private AsyncResponse response;
22+
private final AsyncResponse response;
2323

2424
/**
2525
* Initialize a new ScanController
@@ -31,9 +31,9 @@ public final class ScanController extends AsyncTask<Void, ScanProgress, Void> {
3131
* @param timeOut The time it takes before a connection is marked as timed-out
3232
* @param response The AsyncResponse that can be called when a scan has finished or been cancelled
3333
*/
34-
public ScanController(Context context, String host, int startPort,
35-
int endPort, int timeOut,
36-
AsyncResponse response) {
34+
public ScanController(final Context context, String host, final int startPort,
35+
final int endPort, final int timeOut,
36+
final AsyncResponse response) {
3737

3838
if (context == null) throw new NullPointerException("Context cannot be null!");
3939
if (host == null || host.isEmpty() || !UtilController.isValidAddress(host))
@@ -47,7 +47,7 @@ public ScanController(Context context, String host, int startPort,
4747
throw new IllegalArgumentException(context.getString(R.string.string_invalid_endport));
4848
if (endPort < startPort)
4949
throw new IllegalArgumentException(context.getString(R.string.string_endport_larger_than_startport));
50-
if (endPort > 65535 || startPort > 65535)
50+
if (endPort > 65535)
5151
throw new IllegalArgumentException(context.getString(R.string.string_largest_possible_port));
5252

5353
host = host
@@ -63,7 +63,7 @@ public ScanController(Context context, String host, int startPort,
6363
}
6464

6565
@Override
66-
protected Void doInBackground(Void... voids) {
66+
protected Void doInBackground(final Void... voids) {
6767
int currentPort = startPort;
6868
while (currentPort <= endPort) {
6969
if (isCancelled()) {
@@ -76,13 +76,13 @@ protected Void doInBackground(Void... voids) {
7676
}
7777

7878
@Override
79-
protected void onPostExecute(Void aVoid) {
79+
protected void onPostExecute(final Void aVoid) {
8080
response.scanComplete();
8181
super.onPostExecute(aVoid);
8282
}
8383

8484
@Override
85-
protected void onProgressUpdate(ScanProgress... values) {
85+
protected void onProgressUpdate(final ScanProgress... values) {
8686
if (isCancelled()) return;
8787

8888
response.update(values[0]);
@@ -97,16 +97,16 @@ protected void onProgressUpdate(ScanProgress... values) {
9797
* @param timeOut The time it takes before a connection is closed due to a time-out
9898
* @return A ScanProgress object containing the result of the scan
9999
*/
100-
private static ScanProgress scanTcp(String host, int port, int timeOut) {
100+
private static ScanProgress scanTcp(final String host, final int port, final int timeOut) {
101101
final ScanProgress scan = new ScanProgress(host, port);
102102
try {
103-
Socket socket = new Socket();
104-
socket.connect(new InetSocketAddress(host, port), timeOut);
105-
socket.close();
103+
try (final Socket socket = new Socket()) {
104+
socket.connect(new InetSocketAddress(host, port), timeOut);
105+
}
106106
scan.setStatus(ScanStatus.OPEN);
107-
} catch (SocketTimeoutException ce) {
107+
} catch (final SocketTimeoutException ce) {
108108
scan.setStatus(ScanStatus.TIMEOUT);
109-
} catch (Exception ex) {
109+
} catch (final Exception ex) {
110110
scan.setStatus(ScanStatus.CLOSED);
111111
}
112112

app/src/main/java/com/codedead/advancedportchecker/domain/controller/UtilController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public final class UtilController {
1616
* @param context The context that can be used to start the activity
1717
* @param url The URL that should be opened
1818
*/
19-
public static void openWebsite(Context context, String url) {
19+
public static void openWebsite(final Context context, final String url) {
2020
try {
2121
final Uri uri = Uri.parse(url);
2222
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
2323

2424
context.startActivity(intent);
25-
} catch (Exception ex) {
25+
} catch (final Exception ex) {
2626
ex.printStackTrace();
2727
}
2828
}
@@ -33,7 +33,7 @@ public static void openWebsite(Context context, String url) {
3333
* @param context The context that can be used to display the alert
3434
* @param message The message that needs to be displayed to the user
3535
*/
36-
public static void showAlert(Context context, String message) {
36+
public static void showAlert(final Context context, final String message) {
3737
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
3838
builder.setMessage(message);
3939
builder.setCancelable(true);
@@ -42,7 +42,7 @@ public static void showAlert(Context context, String message) {
4242
android.R.string.ok,
4343
(dialog, id) -> dialog.cancel());
4444

45-
AlertDialog alert = builder.create();
45+
final AlertDialog alert = builder.create();
4646
alert.show();
4747
}
4848

app/src/main/java/com/codedead/advancedportchecker/domain/interfaces/AsyncResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ public interface AsyncResponse {
77

88
void scanCancelled();
99

10-
void update(ScanProgress scanProgress);
10+
void update(final ScanProgress scanProgress);
1111
}

app/src/main/java/com/codedead/advancedportchecker/domain/object/NetworkUtils.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33
import android.content.Context;
44
import android.net.ConnectivityManager;
55
import android.net.NetworkCapabilities;
6-
import android.net.NetworkInfo;
76
import android.net.wifi.WifiManager;
8-
import android.os.Build;
97

108
public final class NetworkUtils {
119

12-
private WifiManager wifiManager;
13-
private Context context;
10+
private final WifiManager wifiManager;
11+
private final Context context;
1412

1513
/**
1614
* Initialize a new NetworkUtils
1715
* @param context The context that can be used to access device information
1816
*/
19-
public NetworkUtils(Context context) {
20-
if (context == null) throw new NullPointerException("Context cannot be null!");
17+
public NetworkUtils(final Context context) {
18+
if (context == null)
19+
throw new NullPointerException("Context cannot be null!");
2120

2221
this.context = context;
2322
wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
@@ -30,19 +29,10 @@ public NetworkUtils(Context context) {
3029
public boolean hasNetworkConnection() {
3130
final ConnectivityManager cm = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
3231

33-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
34-
if (cm != null) {
35-
final NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
36-
if (capabilities != null) {
37-
return capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR);
38-
}
39-
}
40-
} else {
41-
if (cm != null) {
42-
final NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
43-
if (activeNetwork != null) {
44-
return activeNetwork.getType() == ConnectivityManager.TYPE_WIFI || activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE;
45-
}
32+
if (cm != null) {
33+
final NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork());
34+
if (capabilities != null) {
35+
return capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR);
4636
}
4737
}
4838
return false;

app/src/main/java/com/codedead/advancedportchecker/domain/object/Runner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public final class Runner extends Application {
1212

1313
@Override
14-
protected void attachBaseContext(Context base) {
14+
protected void attachBaseContext(final Context base) {
1515
final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(base);
1616
super.attachBaseContext(LocaleHelper.onAttach(base, sharedPref.getString("appLanguage", "en")));
1717
}

app/src/main/java/com/codedead/advancedportchecker/domain/object/ScanProgress.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public final class ScanProgress {
1212
* @param host The host that was scanned
1313
* @param port The port that was scanned
1414
*/
15-
public ScanProgress(String host, int port) {
15+
public ScanProgress(final String host, final int port) {
1616
if (host == null || host.isEmpty())
1717
throw new IllegalArgumentException("Host cannot be null or empty!");
1818

@@ -26,8 +26,9 @@ public ScanProgress(String host, int port) {
2626
*
2727
* @param status The status of the scan
2828
*/
29-
public void setStatus(ScanStatus status) {
30-
if (status == null) throw new NullPointerException("Status cannot be null!");
29+
public void setStatus(final ScanStatus status) {
30+
if (status == null)
31+
throw new NullPointerException("Status cannot be null!");
3132
this.status = status;
3233
}
3334

0 commit comments

Comments
 (0)