Merge pull request #482 from zod/checkstyle-android

Enable checkstyle for brouter-routing-app
This commit is contained in:
afischerdev 2022-11-10 10:56:35 +01:00 committed by GitHub
commit 31e10c5475
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 153 additions and 116 deletions

View file

@ -3,6 +3,7 @@ root = true
[*] [*]
end_of_line = lf end_of_line = lf
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true
[*.java] [*.java]
indent_style = space indent_style = space

View file

@ -11,7 +11,6 @@ import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import btools.router.OsmNogoPolygon.Point;
import btools.util.CheapRuler; import btools.util.CheapRuler;
public class OsmNogoPolygonTest { public class OsmNogoPolygonTest {
@ -77,9 +76,9 @@ public class OsmNogoPolygonTest {
@Test @Test
public void testIsWithin() { public void testIsWithin() {
double[] plons = {0.0, 0.5, 1.0, -1.5, -0.5, 1.0, 1.0, 0.5, 0.5, 0.5,}; double[] plons = {0.0, 0.5, 1.0, -1.5, -0.5, 1.0, 1.0, 0.5, 0.5, 0.5};
double[] plats = {0.0, 1.5, 0.0, 0.5, -1.5, -1.0, -0.1, -0.1, 0.0, 0.1,}; double[] plats = {0.0, 1.5, 0.0, 0.5, -1.5, -1.0, -0.1, -0.1, 0.0, 0.1};
boolean[] within = {true, false, false, false, false, true, true, true, true, true,}; boolean[] within = {true, false, false, false, false, true, true, true, true, true};
for (int i = 0; i < plons.length; i++) { for (int i = 0; i < plons.length; i++) {
assertEquals("(" + plons[i] + "," + plats[i] + ")", within[i], polygon.isWithin(toOsmLon(plons[i], OFFSET_X), toOsmLat(plats[i], OFFSET_Y))); assertEquals("(" + plons[i] + "," + plats[i] + ")", within[i], polygon.isWithin(toOsmLon(plons[i], OFFSET_X), toOsmLat(plats[i], OFFSET_Y)));

View file

@ -101,6 +101,16 @@ dependencies {
androidTestImplementation 'androidx.work:work-testing:2.7.1' androidTestImplementation 'androidx.work:work-testing:2.7.1'
} }
check.dependsOn 'checkstyle'
task checkstyle(type: Checkstyle) {
source 'src'
include '**/*.java'
exclude '**/gen/**'
classpath = files()
}
task generateProfiles(type: Exec) { task generateProfiles(type: Exec) {
commandLine = "../misc/scripts/generate_profile_variants.sh" commandLine = "../misc/scripts/generate_profile_variants.sh"
} }

View file

@ -96,77 +96,80 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
return builder.create(); return builder.create();
case DIALOG_MAINACTION_ID: case DIALOG_MAINACTION_ID:
builder.setTitle("Select Main Action"); builder.setTitle("Select Main Action");
builder builder.setItems(
.setItems(new String[] new String[] { "Download Manager", "BRouter App" },
{"Download Manager", "BRouter App"}, new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) { public void onClick(DialogInterface dialog, int item) {
if (item == 0) if (item == 0)
startDownloadManager(); startDownloadManager();
else else
showDialog(DIALOG_SELECTPROFILE_ID); showDialog(DIALOG_SELECTPROFILE_ID);
} }
} })
) .setNegativeButton("Close", new DialogInterface.OnClickListener() {
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
finish(); finish();
} }
} });
);
return builder.create(); return builder.create();
case DIALOG_SHOW_DM_INFO_ID: case DIALOG_SHOW_DM_INFO_ID:
builder builder
.setTitle("BRouter Download Manager") .setTitle("BRouter Download Manager")
.setMessage( .setMessage(
"*** Attention: ***\n\n" + "The Download Manager is used to download routing-data " "*** Attention: ***\n\n" + "The Download Manager is used to download routing-data "
+ "files which can be up to 170MB each. Do not start the Download Manager " + "on a cellular data connection without a data plan! " + "files which can be up to 170MB each. Do not start the Download Manager "
+ "Download speed is restricted to 16 MBit/s.").setPositiveButton("I know", new DialogInterface.OnClickListener() { + "on a cellular data connection without a data plan! "
public void onClick(DialogInterface dialog, int id) { + "Download speed is restricted to 16 MBit/s.")
Intent intent = new Intent(BRouterActivity.this, BInstallerActivity.class); .setPositiveButton("I know", new DialogInterface.OnClickListener() {
startActivity(intent); public void onClick(DialogInterface dialog, int id) {
showNewDialog(DIALOG_MAINACTION_ID); Intent intent = new Intent(BRouterActivity.this, BInstallerActivity.class);
} startActivity(intent);
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { showNewDialog(DIALOG_MAINACTION_ID);
public void onClick(DialogInterface dialog, int id) { }
finish(); }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
} public void onClick(DialogInterface dialog, int id) {
}); finish();
}
});
return builder.create(); return builder.create();
case DIALOG_SHOW_REPEAT_TIMEOUT_HELP_ID: case DIALOG_SHOW_REPEAT_TIMEOUT_HELP_ID:
builder builder
.setTitle("Successfully prepared a timeout-free calculation") .setTitle("Successfully prepared a timeout-free calculation")
.setMessage( .setMessage(
"You successfully repeated a calculation that previously run into a timeout " "You successfully repeated a calculation that previously run into a timeout "
+ "when started from your map-tool. If you repeat the same request from your " + "when started from your map-tool. If you repeat the same request from your "
+ "maptool, with the exact same destination point and a close-by starting point, " + "maptool, with the exact same destination point and a close-by starting point, "
+ "this request is guaranteed not to time out.").setNegativeButton("Exit", new DialogInterface.OnClickListener() { + "this request is guaranteed not to time out.")
public void onClick(DialogInterface dialog, int id) { .setNegativeButton("Exit", new DialogInterface.OnClickListener() {
finish(); public void onClick(DialogInterface dialog, int id) {
} finish();
}); }
});
return builder.create(); return builder.create();
case DIALOG_OLDDATAHINT_ID: case DIALOG_OLDDATAHINT_ID:
builder builder
.setTitle("Local setup needs reset") .setTitle("Local setup needs reset")
.setMessage( .setMessage(
"You are currently using an old version of the lookup-table " + "together with routing data made for this old table. " "You are currently using an old version of the lookup-table "
+ "Before downloading new datafiles made for the new table, " + "together with routing data made for this old table. "
+ "you have to reset your local setup by 'moving away' (or deleting) " + "Before downloading new datafiles made for the new table, "
+ "your <basedir>/brouter directory and start a new setup by calling the " + "BRouter App again.") + "you have to reset your local setup by 'moving away' (or deleting) "
.setPositiveButton("OK", new DialogInterface.OnClickListener() { + "your <basedir>/brouter directory and start a new setup by calling the " + "BRouter App again.")
public void onClick(DialogInterface dialog, int id) { .setPositiveButton("OK", new DialogInterface.OnClickListener() {
finish(); public void onClick(DialogInterface dialog, int id) {
} finish();
}); }
});
return builder.create(); return builder.create();
case DIALOG_ROUTINGMODES_ID: case DIALOG_ROUTINGMODES_ID:
builder.setTitle(message); builder.setTitle(message);
builder.setMultiChoiceItems(routingModes, routingModesChecked, new DialogInterface.OnMultiChoiceClickListener() { builder.setMultiChoiceItems(routingModes, routingModesChecked,
@Override new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which, boolean isChecked) { @Override
routingModesChecked[which] = isChecked; public void onClick(DialogInterface dialog, int which, boolean isChecked) {
} routingModesChecked[which] = isChecked;
}); }
});
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) { public void onClick(DialogInterface dialog, int whichButton) {
mBRouterView.configureService(routingModes, routingModesChecked); mBRouterView.configureService(routingModes, routingModesChecked);
@ -174,11 +177,15 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
}); });
return builder.create(); return builder.create();
case DIALOG_EXCEPTION_ID: case DIALOG_EXCEPTION_ID:
builder.setTitle("An Error occured").setMessage(errorMessage).setPositiveButton("OK", new DialogInterface.OnClickListener() { builder
public void onClick(DialogInterface dialog, int id) { .setTitle("An Error occured")
mBRouterView.continueProcessing(); .setMessage(errorMessage)
} .setPositiveButton("OK",
}); new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mBRouterView.continueProcessing();
}
});
return builder.create(); return builder.create();
case DIALOG_TEXTENTRY_ID: case DIALOG_TEXTENTRY_ID:
builder.setTitle("Enter SDCARD base dir:"); builder.setTitle("Enter SDCARD base dir:");
@ -214,16 +221,17 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
return builder.create(); return builder.create();
case DIALOG_VIASELECT_ID: case DIALOG_VIASELECT_ID:
builder.setTitle("Check VIA Selection:"); builder.setTitle("Check VIA Selection:");
builder.setMultiChoiceItems(availableVias, getCheckedBooleanArray(availableVias.length), new DialogInterface.OnMultiChoiceClickListener() { builder.setMultiChoiceItems(availableVias, getCheckedBooleanArray(availableVias.length),
@Override new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which, boolean isChecked) { @Override
if (isChecked) { public void onClick(DialogInterface dialog, int which, boolean isChecked) {
selectedVias.add(availableVias[which]); if (isChecked) {
} else { selectedVias.add(availableVias[which]);
selectedVias.remove(availableVias[which]); } else {
} selectedVias.remove(availableVias[which]);
} }
}); }
});
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) { public void onClick(DialogInterface dialog, int whichButton) {
mBRouterView.updateViaList(selectedVias); mBRouterView.updateViaList(selectedVias);
@ -237,12 +245,13 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
for (int i = 0; i < nogoList.size(); i++) for (int i = 0; i < nogoList.size(); i++)
nogoNames[i] = nogoList.get(i).name; nogoNames[i] = nogoList.get(i).name;
final boolean[] nogoEnabled = getCheckedBooleanArray(nogoList.size()); final boolean[] nogoEnabled = getCheckedBooleanArray(nogoList.size());
builder.setMultiChoiceItems(nogoNames, getCheckedBooleanArray(nogoNames.length), new DialogInterface.OnMultiChoiceClickListener() { builder.setMultiChoiceItems(nogoNames, getCheckedBooleanArray(nogoNames.length),
@Override new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which, boolean isChecked) { @Override
nogoEnabled[which] = isChecked; public void onClick(DialogInterface dialog, int which, boolean isChecked) {
} nogoEnabled[which] = isChecked;
}); }
});
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) { public void onClick(DialogInterface dialog, int whichButton) {
mBRouterView.updateNogoList(nogoEnabled); mBRouterView.updateNogoList(nogoEnabled);
@ -293,11 +302,15 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
return builder.create(); return builder.create();
case DIALOG_MODECONFIGOVERVIEW_ID: case DIALOG_MODECONFIGOVERVIEW_ID:
builder.setTitle("Success").setMessage(message).setPositiveButton("Exit", new DialogInterface.OnClickListener() { builder
public void onClick(DialogInterface dialog, int id) { .setTitle("Success")
finish(); .setMessage(message)
} .setPositiveButton("Exit",
}); new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
return builder.create(); return builder.create();
case DIALOG_PICKWAYPOINT_ID: case DIALOG_PICKWAYPOINT_ID:
builder.setTitle(wpCount > 0 ? "Select to/via" : "Select from"); builder.setTitle(wpCount > 0 ? "Select to/via" : "Select from");
@ -345,7 +358,8 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
try { try {
StatFs stat = new StatFs(f.getAbsolutePath()); StatFs stat = new StatFs(f.getAbsolutePath());
size = (long) stat.getAvailableBlocks() * stat.getBlockSize(); size = (long) stat.getAvailableBlocks() * stat.getBlockSize();
} catch (Exception e) { /* ignore */ } } catch (Exception e) {
/* ignore */ }
dirFreeSizes.add(size); dirFreeSizes.add(size);
} }
@ -358,7 +372,8 @@ public class BRouterActivity extends AppCompatActivity implements ActivityCompat
int bdidx = 0; int bdidx = 0;
DecimalFormat df = new DecimalFormat("###0.00"); DecimalFormat df = new DecimalFormat("###0.00");
for (int idx = 0; idx < availableBasedirs.size(); idx++) { for (int idx = 0; idx < availableBasedirs.size(); idx++) {
basedirOptions[bdidx++] = availableBasedirs.get(idx) + " (" + df.format(dirFreeSizes.get(idx) / 1024. / 1024. / 1024.) + " GB free)"; basedirOptions[bdidx++] = availableBasedirs.get(idx) + " ("
+ df.format(dirFreeSizes.get(idx) / 1024. / 1024. / 1024.) + " GB free)";
} }
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
basedirOptions[bdidx] = "Enter path manually"; basedirOptions[bdidx] = "Enter path manually";

View file

@ -1,6 +1,5 @@
package btools.routingapp; package btools.routingapp;
import android.app.Service; import android.app.Service;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@ -49,10 +48,11 @@ public class BRouterService extends Service {
baseDir = br.readLine(); baseDir = br.readLine();
} catch (Exception e) { } catch (Exception e) {
} finally { } finally {
if (configInput != null) try { if (configInput != null)
configInput.close(); try {
} catch (Exception ee) { configInput.close();
} } catch (Exception ee) {
}
} }
worker.baseDir = baseDir; worker.baseDir = baseDir;
worker.segmentDir = new File(baseDir, "brouter/segments4"); worker.segmentDir = new File(baseDir, "brouter/segments4");
@ -94,7 +94,7 @@ public class BRouterService extends Service {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write("z64".getBytes(Charset.forName("UTF-8"))); // marker prefix baos.write("z64".getBytes(Charset.forName("UTF-8"))); // marker prefix
OutputStream os = new GZIPOutputStream(baos); OutputStream os = new GZIPOutputStream(baos);
byte[] ab = gpxMessage.getBytes(Charset.forName("UTF-8")); //StandardCharsets.UTF_8 byte[] ab = gpxMessage.getBytes(Charset.forName("UTF-8")); // StandardCharsets.UTF_8
gpxMessage = null; gpxMessage = null;
os.write(ab); os.write(ab);
ab = null; ab = null;
@ -119,7 +119,7 @@ public class BRouterService extends Service {
try { try {
String modesFile = baseDir + "/brouter/modes/serviceconfig.dat"; String modesFile = baseDir + "/brouter/modes/serviceconfig.dat";
br = new BufferedReader(new FileReader(modesFile)); br = new BufferedReader(new FileReader(modesFile));
for (; ; ) { for (;;) {
String line = br.readLine(); String line = br.readLine();
if (line == null) if (line == null)
break; break;
@ -137,10 +137,11 @@ public class BRouterService extends Service {
} catch (Exception e) { } catch (Exception e) {
return "no brouter service config found, mode " + mode_key; return "no brouter service config found, mode " + mode_key;
} finally { } finally {
if (br != null) try { if (br != null)
br.close(); try {
} catch (Exception ee) { br.close();
} } catch (Exception ee) {
}
} }
return "no brouter service config found for mode " + mode_key; return "no brouter service config found for mode " + mode_key;
} }
@ -163,10 +164,11 @@ public class BRouterService extends Service {
os = new FileOutputStream(profileFile); os = new FileOutputStream(profileFile);
os.write(profileBytes); os.write(profileBytes);
} finally { } finally {
if (os != null) try { if (os != null)
os.close(); try {
} catch (IOException io) { os.close();
} } catch (IOException io) {
}
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -182,7 +184,6 @@ public class BRouterService extends Service {
worker.nogoPolygonsList = new ArrayList<OsmNodeNamed>(); worker.nogoPolygonsList = new ArrayList<OsmNodeNamed>();
} }
private boolean fileEqual(byte[] fileBytes, File file) throws Exception { private boolean fileEqual(byte[] fileBytes, File file) throws Exception {
if (!file.exists()) { if (!file.exists()) {
return false; return false;
@ -196,8 +197,10 @@ public class BRouterService extends Service {
is = new FileInputStream(file); is = new FileInputStream(file);
while (pos < nbytes) { while (pos < nbytes) {
int len = is.read(buf, 0, blen); int len = is.read(buf, 0, blen);
if (len <= 0) return false; if (len <= 0)
if (pos + len > nbytes) return false; return false;
if (pos + len > nbytes)
return false;
for (int j = 0; j < len; j++) { for (int j = 0; j < len; j++) {
if (fileBytes[pos++] != buf[j]) { if (fileBytes[pos++] != buf[j]) {
return false; return false;
@ -206,21 +209,23 @@ public class BRouterService extends Service {
} }
return true; return true;
} finally { } finally {
if (is != null) try { if (is != null)
is.close(); try {
} catch (IOException io) { is.close();
} } catch (IOException io) {
}
} }
} }
private String checkForTestDummy(String baseDir) { private String checkForTestDummy(String baseDir) {
File testdummy = new File(baseDir + "/brouter/profiles2/remotetestdummy.brf"); File testdummy = new File(baseDir + "/brouter/profiles2/remotetestdummy.brf");
if (!testdummy.exists()) return null; if (!testdummy.exists())
return null;
BufferedReader br = null; BufferedReader br = null;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
try { try {
br = new BufferedReader(new FileReader(testdummy)); br = new BufferedReader(new FileReader(testdummy));
for (; ; ) { for (;;) {
String line = br.readLine(); String line = br.readLine();
if (line == null) if (line == null)
break; break;
@ -230,10 +235,11 @@ public class BRouterService extends Service {
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("error reading " + testdummy); throw new RuntimeException("error reading " + testdummy);
} finally { } finally {
if (br != null) try { if (br != null)
br.close(); try {
} catch (Exception ee) { br.close();
} } catch (Exception ee) {
}
} }
} }
@ -261,9 +267,8 @@ public class BRouterService extends Service {
Log.d(getClass().getSimpleName(), "onDestroy()"); Log.d(getClass().getSimpleName(), "onDestroy()");
} }
// This is the old onStart method that will be called on the pre-2.0 // This is the old onStart method that will be called on the pre-2.0
// platform. On 2.0 or later we override onStartCommand() so this // platform. On 2.0 or later we override onStartCommand() so this
// method will not be called. // method will not be called.
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

View file

@ -12,10 +12,17 @@
<module name="TreeWalker"> <module name="TreeWalker">
<module name="Indentation"> <module name="Indentation">
<property name="basicOffset" value="2"/> <property name="basicOffset" value="2" />
<property name="caseIndent" value="2"/> <property name="caseIndent" value="2" />
<property name="throwsIndent" value="2"/> <property name="throwsIndent" value="2" />
<property name="lineWrappingIndentation" value="2"/> <property name="lineWrappingIndentation" value="2" />
</module> </module>
<module name="ParenPad" />
<module name="NoWhitespaceBefore">
<property name="allowLineBreaks" value="true" />
</module>
<module name="WhitespaceAfter" />
</module> </module>
</module> </module>