Skip to content

Commit

Permalink
Cleanup: use Java 17's instanceof.
Browse files Browse the repository at this point in the history
Fixes #1757.
  • Loading branch information
dennisguse committed Nov 6, 2023
1 parent cd4d297 commit 062457f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/main/java/de/dennisguse/opentracks/TrackListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ private void updateGpsMenuItem(boolean isGpsStarted, boolean isRecording) {
startGpsMenuItem.setVisibility(!isRecording ? View.VISIBLE : View.INVISIBLE);
if (!isRecording) {
startGpsMenuItem.setIcon(AppCompatResources.getDrawable(this, isGpsStarted ? gpsStatusValue.icon : R.drawable.ic_gps_off_24dp));
if (startGpsMenuItem.getIcon() instanceof AnimatedVectorDrawable) {
((AnimatedVectorDrawable) startGpsMenuItem.getIcon()).start();
if (startGpsMenuItem.getIcon() instanceof AnimatedVectorDrawable animatedVectorDrawable) {
animatedVectorDrawable.start();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public void onDialogClosed(boolean positiveResult) {
Toast.makeText(activity, R.string.settings_layout_reset_done, Toast.LENGTH_SHORT).show();
}

if (activity instanceof ResetCallback) {
((ResetCallback) activity).onReset();
if (activity instanceof ResetCallback resetCallback) {
resetCallback.onReset();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public void onDisplayPreferenceDialog(Preference preference) {
private void setWheelCircumferenceInputFilter() {
EditTextPreference wheelPreference = findPreference(getString(R.string.settings_sensor_bluetooth_cycling_speed_wheel_circumference_key));
wheelPreference.setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue instanceof String) {
if (newValue instanceof String newValueString) {
try {
int newValueInt = Integer.parseInt((String) newValue);
int newValueInt = Integer.parseInt(newValueString);
return newValueInt >= 100 && newValueInt < 4000;
} catch (NumberFormatException e) {
Log.w(TAG, "Entered string is no number.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ protected void onCreate(Bundle bundle) {

Object bundleMarkerId = getIntent().getExtras().get(EXTRA_MARKER_ID);
Marker.Id markerId = null;
if (bundleMarkerId instanceof Marker.Id) {
markerId = (Marker.Id) bundleMarkerId;
if (bundleMarkerId instanceof Marker.Id cast) {
markerId = cast;
}
if (bundleMarkerId instanceof Long) {
if (bundleMarkerId instanceof Long cast) {
//Incoming Intent via Dashboard API.
markerId = new Marker.Id((Long) bundleMarkerId);
markerId = new Marker.Id(cast);
}
if (markerId == null) {
Log.d(TAG, "invalid marker id");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/de/dennisguse/opentracks/ui/util/ViewUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public static void makeClickableLinks(ViewGroup view) {

for (int i = 0; i < view.getChildCount(); i++) {
final View child = view.getChildAt(i);
if (child instanceof ViewGroup) {
makeClickableLinks((ViewGroup) child);
} else if (child instanceof TextView) {
((TextView) child).setMovementMethod(LinkMovementMethod.getInstance());
if (child instanceof ViewGroup childVg) {
makeClickableLinks(childVg);
} else if (child instanceof TextView childTv) {
childTv.setMovementMethod(LinkMovementMethod.getInstance());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/dennisguse/opentracks/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ public static String formatCData(String text) {
public static OffsetDateTime parseTime(String xmlDateTime) {
try {
TemporalAccessor t = DateTimeFormatter.ISO_DATE_TIME.parseBest(xmlDateTime, ZonedDateTime::from, LocalDateTime::from);
if (t instanceof LocalDateTime) {
if (t instanceof LocalDateTime localDateTime) {
Log.w(TAG, "Date does not contain timezone information: using UTC.");
t = ((LocalDateTime) t).atZone(ZoneOffset.UTC);
t = localDateTime.atZone(ZoneOffset.UTC);
}
return OffsetDateTime.from(t);
} catch (Exception e) {
Expand Down

0 comments on commit 062457f

Please sign in to comment.