Skip to content

Commit

Permalink
chore: Cleanup the code a little bit (#518)
Browse files Browse the repository at this point in the history
1 - cleaned up the autoboxing.. valueOf() returns an Object type where parseXXX() returns a primitive type.
Several places primitive types are used instead of Objects.
2 - A couple of places just simply use the diamond operator.
3 - A couple of places lambda is treated as a statement.. Really minor semantics

Expected behavior
A few less warnings will be emitted by the Android Studio..
  • Loading branch information
BradWalker authored Jun 3, 2021
1 parent cbbe607 commit 9f294a4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,11 @@ public void setOnMapClickListener(OnMapClickListener listener) {
private void checkMapPreferences() {
SharedPreferences settings = Application.getPrefs();
if (mMap != null && mMapController.getMode().equals(MODE_MAP)) {
if (mMap.getMapType() != Integer.valueOf(
if (mMap.getMapType() != Integer.parseInt(
settings.getString(getString(R.string.pref_key_map_type),
String.valueOf(GoogleMap.MAP_TYPE_NORMAL))
)) {
mMap.setMapType(Integer.valueOf(
mMap.setMapType(Integer.parseInt(
settings.getString(getString(R.string.pref_key_map_type),
String.valueOf(GoogleMap.MAP_TYPE_NORMAL))
));
Expand Down
20 changes: 9 additions & 11 deletions GPSTest/src/main/java/com/android/gpstest/GpsTestActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public class GpsTestActivity extends AppCompatActivity
private GnssAntennaInfo.Listener gnssAntennaInfoListener;

// Listeners for Fragments
private List<GpsTestListener> mGpsTestListeners = new ArrayList<GpsTestListener>();
private List<GpsTestListener> mGpsTestListeners = new ArrayList<>();

private Location mLastLocation;

Expand Down Expand Up @@ -619,12 +619,12 @@ private void setupStartState(Bundle savedInstanceState) {
// Apply start state settings from preferences
SharedPreferences settings = Application.getPrefs();

double tempMinTime = Double.valueOf(
double tempMinTime = Double.parseDouble(
settings.getString(getString(R.string.pref_key_gps_min_time),
getString(R.string.pref_gps_min_time_default_sec))
);
minTime = (long) (tempMinTime * SECONDS_TO_MILLISECONDS);
minDistance = Float.valueOf(
minDistance = Float.parseFloat(
settings.getString(getString(R.string.pref_key_gps_min_distance),
getString(R.string.pref_gps_min_distance_default_meters))
);
Expand Down Expand Up @@ -980,10 +980,10 @@ private synchronized void gpsStart() {
showProgressBar();

// Show Toast only if the user has set minTime or minDistance to something other than default values
if (minTime != (long) (Double.valueOf(getString(R.string.pref_gps_min_time_default_sec))
if (minTime != (long) (Double.parseDouble(getString(R.string.pref_gps_min_time_default_sec))
* SECONDS_TO_MILLISECONDS) ||
minDistance != Float
.valueOf(getString(R.string.pref_gps_min_distance_default_meters))) {
.parseFloat(getString(R.string.pref_gps_min_distance_default_meters))) {
Toast.makeText(this, String.format(getString(R.string.gps_set_location_listener),
String.valueOf((double) minTime / SECONDS_TO_MILLISECONDS),
String.valueOf(minDistance)), Toast.LENGTH_SHORT).show();
Expand Down Expand Up @@ -1232,9 +1232,7 @@ public void onStatusChanged(int status) {
if (UIUtils.canManageDialog(GpsTestActivity.this) &&
(mWriteRawMeasurementToAndroidMonitor || mWriteRawMeasurementsToFile)) {
new Handler(Looper.getMainLooper()).postDelayed(
() -> runOnUiThread(() -> {
Toast.makeText(GpsTestActivity.this, statusMessage, Toast.LENGTH_SHORT).show();
}), 3000);
() -> runOnUiThread(() -> Toast.makeText(GpsTestActivity.this, statusMessage, Toast.LENGTH_SHORT).show()), 3000);
}
}
};
Expand Down Expand Up @@ -1455,15 +1453,15 @@ private void promptEnableGps() {
@SuppressLint("MissingPermission")
private void checkTimeAndDistance(SharedPreferences settings) {
double tempMinTimeDouble = Double
.valueOf(settings.getString(getString(R.string.pref_key_gps_min_time), "1"));
.parseDouble(settings.getString(getString(R.string.pref_key_gps_min_time), "1"));
long minTimeLong = (long) (tempMinTimeDouble * SECONDS_TO_MILLISECONDS);

if (minTime != minTimeLong ||
minDistance != Float.valueOf(
minDistance != Float.parseFloat(
settings.getString(getString(R.string.pref_key_gps_min_distance), "0"))) {
// User changed preference values, get the new ones
minTime = minTimeLong;
minDistance = Float.valueOf(
minDistance = Float.parseFloat(
settings.getString(getString(R.string.pref_key_gps_min_distance), "0"));
// If the GPS is started, reset the location listener with the new values
if (mStarted && mProvider != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public class NavigationDrawerFragment extends Fragment {
};

// list of navdrawer items that were actually added to the navdrawer, in order
private List<Integer> mNavDrawerItems = new ArrayList<Integer>();
private List<Integer> mNavDrawerItems = new ArrayList<>();

// views that correspond to each navdrawer item, null if not yet created
private View[] mNavDrawerItemViews = null;
Expand Down
8 changes: 4 additions & 4 deletions GPSTest/src/main/java/com/android/gpstest/util/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ public static Location getLocationFromGeoUri(String geoUri) {

String[] noPrefix = geoUri.split(":");
String[] coords = noPrefix[1].split(",");
if (isValidLatitude(Double.valueOf(coords[0])) && isValidLongitude(Double.valueOf(coords[1]))) {
if (isValidLatitude(Double.parseDouble(coords[0])) && isValidLongitude(Double.parseDouble(coords[1]))) {
l = new Location("Geo URI");
l.setLatitude(Double.valueOf(coords[0]));
l.setLongitude(Double.valueOf(coords[1]));
l.setLatitude(Double.parseDouble(coords[0]));
l.setLongitude(Double.parseDouble(coords[1]));
if (coords.length == 3) {
l.setAltitude(Double.valueOf(coords[2]));
l.setAltitude(Double.parseDouble(coords[2]));
}
}

Expand Down
4 changes: 2 additions & 2 deletions GPSTest/src/main/java/com/android/gpstest/util/NmeaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public static DilutionOfPrecision getDop(String nmeaSentence) {
if (!TextUtils.isEmpty(pdop) && !TextUtils.isEmpty(hdop) && !TextUtils.isEmpty(vdop)) {
DilutionOfPrecision dop = null;
try {
dop = new DilutionOfPrecision(Double.valueOf(pdop), Double.valueOf(hdop),
Double.valueOf(vdop));
dop = new DilutionOfPrecision(Double.parseDouble(pdop), Double.parseDouble(hdop),
Double.parseDouble(vdop));
} catch (NumberFormatException e) {
// See https://github.com/barbeau/gpstest/issues/71#issuecomment-263169174
Log.e(TAG, "Invalid DOP values in NMEA: " + nmeaSentence);
Expand Down
4 changes: 1 addition & 3 deletions GPSTest/src/main/java/com/android/gpstest/util/UIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,7 @@ public static Dialog createQrCodeDialog(AppCompatActivity activity) {
.setCancelable(false)
.setView(view)
.setPositiveButton(R.string.ok,
(dialog, which) -> {
IOUtils.openQrCodeReader(activity);
}
(dialog, which) -> IOUtils.openQrCodeReader(activity)
).setNegativeButton(R.string.not_now,
(dialog, which) -> {
// No op
Expand Down

0 comments on commit 9f294a4

Please sign in to comment.