Cleanup using AndroidStudio analyze.

This commit is contained in:
Dennis Guse
2024-07-11 07:38:45 +02:00
parent f5190aef06
commit d8eed2ccc9
11 changed files with 19 additions and 29 deletions
@@ -7,7 +7,6 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
@@ -40,17 +39,12 @@ public class ShowErrorActivity extends AbstractActivity {
private void reportBug() {
Uri uriUrl;
try {
uriUrl = Uri.parse(
String.format(
getString(R.string.report_issue_link),
URLEncoder.encode(viewBinding.textViewError.getText().toString(), StandardCharsets.UTF_8.toString())
)
);
} catch (final UnsupportedEncodingException ignored) {
// can't happen as UTF-8 is always available
return;
}
uriUrl = Uri.parse(
String.format(
getString(R.string.report_issue_link),
URLEncoder.encode(viewBinding.textViewError.getText().toString(), StandardCharsets.UTF_8)
)
);
Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(intent);
}
@@ -41,9 +41,9 @@ import androidx.core.view.GestureDetectorCompat;
import java.text.NumberFormat;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Iterator;
import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.data.models.Marker;
@@ -679,12 +679,13 @@ public class ChartView extends View {
private record TitlePosition(
int line, // line number (starts at 1, top to bottom numbering)
int xPos // x position in points (starts at 0, left to right indexing)
) {};
) {}
private record TitleDimensions(
int lineCount, // number of lines the titles will take
int lineHeight, // height of a line (all lines have the same height)
List<TitlePosition> titlePositions // positions of visible titles (the order corresponds to seriesList)
) {};
) {}
/**
* Draws series titles.
@@ -711,7 +712,7 @@ public class ChartView extends View {
private TitleDimensions getTitleDimensions() {
int lineCnt = 1;
int lineHeight = 0;
List<TitlePosition> tps = new ArrayList<TitlePosition>();
List<TitlePosition> tps = new ArrayList<>();
int xPosInLine = spacer;
for (ChartValueSeries chartValueSeries : seriesList) {
if (chartValueSeries.isEnabled() && chartValueSeries.hasData() || allowIfEmpty(chartValueSeries)) {
@@ -263,7 +263,7 @@ public final class Marker {
}
public boolean hasPhoto() {
return photoUrl != null && !"".equals(photoUrl);
return photoUrl != null && !photoUrl.isEmpty();
}
public record Id(long id) implements Parcelable {
@@ -310,7 +310,7 @@ public class GPXTrackExporter implements TrackExporter {
}
public Distance writeTrackPoint(ZoneOffset zoneOffset, TrackPoint trackPoint, List<TrackPoint> sensorPoints, Distance trackDistance) {
Distance cumulativeDistance = null;
Distance cumulativeDistance;
printWriter.println("<trkpt " + formatLocation(trackPoint.getLatitude(), trackPoint.getLongitude()) + ">");
@@ -498,7 +498,7 @@ public class KMLTrackExporter implements TrackExporter {
}
private void writeTypeLocalized(String localizedValue) {
if (localizedValue == null || localizedValue.equals("")) {
if (localizedValue == null || localizedValue.isEmpty()) {
return;
}
printWriter.println("<ExtendedData>");
@@ -414,7 +414,7 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
Float value = null;
if (content != null) {
content = content.trim();
if (!"".equals(content)) {
if (!content.isEmpty()) {
try {
value = Float.parseFloat(content);
} catch (NumberFormatException e) {
@@ -20,9 +20,7 @@ public class GainManager implements SensorConnector {
private final SensorManager.SensorDataChangedObserver listener;
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (sharedPreferences, key) -> {
connect();
};
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = (sharedPreferences, key) -> connect();
private Context context;
private Handler handler;
@@ -55,7 +55,7 @@ public abstract class Aggregator<Input, Output> {
/**
* Reset long term aggregated values (more than derived from previous SensorData). e.g. overall distance.
*/
public void reset() {};
public void reset() {}
/**
* Is the data recent considering the current time.
@@ -229,7 +229,7 @@ public class PreferencesUtils {
//TODO Check if actually needed or can be superseeded by a flexible default in getUnit()
public static void applyDefaultUnit() {
if (getString(R.string.stats_units_key, "").equals("")) {
if (getString(R.string.stats_units_key, "").isEmpty()) {
if (!Locale.US.equals(Locale.getDefault())) {
setUnit(UnitSystem.METRIC);
} else {
@@ -114,9 +114,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
setSupportActionBar(viewBinding.bottomAppBarLayout.bottomAppBar);
setSupportActionBar(viewBinding.markerListToolbar);
viewBinding.bottomAppBarLayout.bottomAppBar.setNavigationOnClickListener(item -> {
finish();
});
viewBinding.bottomAppBarLayout.bottomAppBar.setNavigationOnClickListener(item -> finish());
}
@Override