forked from upstream-mirrors/OpenTracks
Code cleanup using static code analysis (Android Studio).
This commit is contained in:
+12
-48
@@ -233,38 +233,26 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
|
||||
@Override
|
||||
public List<Track> getAllTracks() {
|
||||
ArrayList<Track> tracks = new ArrayList<Track>();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = getTrackCursor(null, null, null, TracksColumns._ID);
|
||||
ArrayList<Track> tracks = new ArrayList<>();
|
||||
try (Cursor cursor = getTrackCursor(null, null, null, TracksColumns._ID)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
tracks.ensureCapacity(cursor.getCount());
|
||||
do {
|
||||
tracks.add(createTrack(cursor));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return tracks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Track getLastTrack() {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
try (Cursor cursor = getTrackCursor(null, null, null,
|
||||
TracksColumns.SHAREDWITHME + " ASC, " + TracksColumns.STARTTIME + " DESC")) {
|
||||
// Using the same order as shown in the track list
|
||||
cursor = getTrackCursor(null, null, null,
|
||||
TracksColumns.SHAREDWITHME + " ASC, " + TracksColumns.STARTTIME + " DESC");
|
||||
if (cursor != null && cursor.moveToNext()) {
|
||||
return createTrack(cursor);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -274,17 +262,11 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
if (trackId < 0) {
|
||||
return null;
|
||||
}
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = getTrackCursor(null, TracksColumns._ID + "=?",
|
||||
new String[] { Long.toString(trackId) }, TracksColumns._ID);
|
||||
try (Cursor cursor = getTrackCursor(null, TracksColumns._ID + "=?",
|
||||
new String[]{Long.toString(trackId)}, TracksColumns._ID)) {
|
||||
if (cursor != null && cursor.moveToNext()) {
|
||||
return createTrack(cursor);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -547,18 +529,12 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
if (trackId < 0) {
|
||||
return -1L;
|
||||
}
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = getWaypointCursor(new String[] { WaypointsColumns._ID },
|
||||
WaypointsColumns.TRACKID + "=?", new String[] { Long.toString(trackId) },
|
||||
WaypointsColumns._ID, 1);
|
||||
try (Cursor cursor = getWaypointCursor(new String[]{WaypointsColumns._ID},
|
||||
WaypointsColumns.TRACKID + "=?", new String[]{Long.toString(trackId)},
|
||||
WaypointsColumns._ID, 1)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return cursor.getLong(cursor.getColumnIndexOrThrow(WaypointsColumns._ID));
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return -1L;
|
||||
}
|
||||
@@ -618,17 +594,11 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
if (waypointId < 0) {
|
||||
return null;
|
||||
}
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = getWaypointCursor(null, WaypointsColumns._ID + "=?",
|
||||
new String[] { Long.toString(waypointId) }, WaypointsColumns._ID, 1);
|
||||
try (Cursor cursor = getWaypointCursor(null, WaypointsColumns._ID + "=?",
|
||||
new String[]{Long.toString(waypointId)}, WaypointsColumns._ID, 1)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return createWaypoint(cursor);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1117,16 +1087,10 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
}
|
||||
|
||||
private Location findTrackPointBy(String selection, String[] selectionArgs) {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = getTrackPointCursor(null, selection, selectionArgs, TrackPointsColumns._ID);
|
||||
try (Cursor cursor = getTrackPointCursor(null, selection, selectionArgs, TrackPointsColumns._ID)) {
|
||||
if (cursor != null && cursor.moveToNext()) {
|
||||
return createTrackPoint(cursor);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class Track implements Parcelable {
|
||||
private TripStatistics tripStatistics = new TripStatistics();
|
||||
|
||||
// Location points (which may not have been loaded)
|
||||
private ArrayList<Location> locations = new ArrayList<Location>();
|
||||
private ArrayList<Location> locations = new ArrayList<>();
|
||||
|
||||
public Track() {}
|
||||
|
||||
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.android.apps.mytracks.lib;
|
||||
|
||||
/**
|
||||
* Constants for the My Tracks common library.
|
||||
* These constants should ideally not be used by third-party applications.
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class MyTracksLibConstants {
|
||||
public static final String TAG = "MyTracksLib";
|
||||
|
||||
private MyTracksLibConstants() {}
|
||||
}
|
||||
@@ -131,10 +131,7 @@ public class FileUtils {
|
||||
* @param components the components
|
||||
*/
|
||||
public static String getPath(String... components) {
|
||||
StringBuilder dirNameBuilder = new StringBuilder();
|
||||
dirNameBuilder.append(Environment.getExternalStorageDirectory());
|
||||
dirNameBuilder.append(getPathDisplayName(components));
|
||||
return dirNameBuilder.toString();
|
||||
return Environment.getExternalStorageDirectory() + getPathDisplayName(components);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,17 +217,17 @@ public class FileUtils {
|
||||
* @param name name
|
||||
*/
|
||||
static String sanitizeFileName(String name) {
|
||||
StringBuffer buffer = new StringBuffer(name.length());
|
||||
StringBuilder builder = new StringBuilder(name.length());
|
||||
for (int i = 0; i < name.length(); i++) {
|
||||
int codePoint = name.codePointAt(i);
|
||||
char character = name.charAt(i);
|
||||
if (Character.isLetterOrDigit(character) || codePoint > 127 || isSpecialFat32(character)) {
|
||||
buffer.appendCodePoint(codePoint);
|
||||
builder.appendCodePoint(codePoint);
|
||||
} else {
|
||||
buffer.append("_");
|
||||
builder.append("_");
|
||||
}
|
||||
}
|
||||
String result = buffer.toString();
|
||||
String result = builder.toString();
|
||||
return result.replaceAll("_+", "_");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user