mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Automated code cleanup using AndroidStudio.
This commit is contained in:
@@ -42,7 +42,7 @@ public class DescriptionGeneratorTest {
|
||||
private static final long START_TIME = 1288721514000L;
|
||||
private DescriptionGenerator descriptionGenerator;
|
||||
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class SearchEngineTest {
|
||||
private ContentProviderUtils providerUtils;
|
||||
private SearchEngine engine;
|
||||
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
|
||||
|
||||
@Before
|
||||
@@ -66,7 +66,7 @@ public class SearchEngineTest {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
providerUtils.deleteAllTracks(context);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ import de.dennisguse.opentracks.content.data.WaypointsColumns;
|
||||
public class CustomContentProviderTest {
|
||||
|
||||
private CustomContentProvider customContentProvider;
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
+2
-3
@@ -58,7 +58,7 @@ public class CustomContentProviderUtilsTest {
|
||||
private static final String TEST_DESC = "Test Desc!";
|
||||
private static final String TEST_DESC_NEW = "Test Desc new!";
|
||||
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
private ContentProviderUtils contentProviderUtils;
|
||||
|
||||
@Mock
|
||||
@@ -107,7 +107,7 @@ public class CustomContentProviderUtilsTest {
|
||||
testIterator(1, 20000, 2000, false);
|
||||
}
|
||||
|
||||
private List<TrackPoint> testIterator(long trackId, int numPoints, int batchSize, boolean descending) {
|
||||
private void testIterator(long trackId, int numPoints, int batchSize, boolean descending) {
|
||||
long lastPointId = initializeTrack(trackId, numPoints);
|
||||
contentProviderUtils.setDefaultCursorBatchSize(batchSize);
|
||||
List<TrackPoint> locations = new ArrayList<>(numPoints);
|
||||
@@ -122,7 +122,6 @@ public class CustomContentProviderUtilsTest {
|
||||
}
|
||||
Assert.assertEquals(numPoints, locations.size());
|
||||
}
|
||||
return locations;
|
||||
}
|
||||
|
||||
private long initializeTrack(long id, int numPoints) {
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public class CustomSQLiteOpenHelperTest {
|
||||
|
||||
private static final String DATABASE_NAME = "test.db";
|
||||
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
|
||||
/**
|
||||
* Get the SQL create statements for all tables (ordered by name).
|
||||
|
||||
+3
-3
@@ -40,16 +40,16 @@ public class ExportImportTest {
|
||||
|
||||
private static final String TAG = ExportImportTest.class.getSimpleName();
|
||||
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
|
||||
private ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
|
||||
private final ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
|
||||
|
||||
private static final String TRACK_ICON = "the track icon";
|
||||
private static final String TRACK_CATEGORY = "the category";
|
||||
private static final String TRACK_DESCRIPTION = "the description";
|
||||
private final List<Waypoint> waypoints = new ArrayList<>();
|
||||
private long importTrackId;
|
||||
private long trackId = System.currentTimeMillis();
|
||||
private final long trackId = System.currentTimeMillis();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
+2
-2
@@ -73,9 +73,9 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
||||
String longitude = Double.toString(TRACK_LONGITUDE + index);
|
||||
String elevation = Double.toString(TRACK_ELEVATION + index);
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("<trkpt lat=\"" + latitude + "\" lon=\"" + longitude + "\"><ele>" + elevation + "</ele>");
|
||||
buffer.append("<trkpt lat=\"").append(latitude).append("\" lon=\"").append(longitude).append("\"><ele>").append(elevation).append("</ele>");
|
||||
if (time != null) {
|
||||
buffer.append("<time>" + time + "</time>");
|
||||
buffer.append("<time>").append(time).append("</time>");
|
||||
}
|
||||
buffer.append("</trkpt>");
|
||||
return buffer.toString();
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import static org.mockito.Mockito.when;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TrackRecordingServiceNotificationManagerTest {
|
||||
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Mock
|
||||
private TrackPoint locationMock;
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public class TrackRecordingServiceTest {
|
||||
@Rule
|
||||
public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION);
|
||||
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
private ContentProviderUtils contentProviderUtils;
|
||||
|
||||
private final long trackId = Math.abs(new Random().nextLong());
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public class TrackRecordingServiceTestLooper {
|
||||
@Rule
|
||||
public final ServiceTestRule mServiceRule = ServiceTestRule.withTimeout(5, TimeUnit.SECONDS);
|
||||
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
|
||||
private ContentProviderUtils contentProviderUtils;
|
||||
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ import org.junit.runner.RunWith;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class AnnouncementPeriodicTaskFactoryTest {
|
||||
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@BeforeClass
|
||||
public static void preSetUp() {
|
||||
|
||||
@@ -14,7 +14,7 @@ import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class AnnouncementUtilsTest {
|
||||
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Test
|
||||
public void getAnnouncement() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Tests for {@link FileUtils}.
|
||||
@@ -108,9 +109,7 @@ public class FileUtilsTest {
|
||||
File directory = new File("/dir1/dir2/");
|
||||
String suffix = ".gpx";
|
||||
char[] name = new char[FileUtils.MAX_FAT32_PATH_LENGTH];
|
||||
for (int i = 0; i < name.length; i++) {
|
||||
name[i] = 'a';
|
||||
}
|
||||
Arrays.fill(name, 'a');
|
||||
String nameString = new String(name);
|
||||
String truncated = FileUtils.truncateFileName(directory, nameString, suffix);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.TimeZone;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class StringUtilsTest {
|
||||
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
private final Context context = ApplicationProvider.getApplicationContext();
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -88,7 +88,7 @@ public class MarkerEditActivity extends AbstractActivity {
|
||||
|
||||
trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||
markerId = getIntent().getLongExtra(EXTRA_MARKER_ID, -1L);
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(null);
|
||||
|
||||
hasCamera = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
|
||||
|
||||
@@ -254,8 +254,8 @@ public class MarkerEditActivity extends AbstractActivity {
|
||||
private void hideAndShowOptions() {
|
||||
boolean isPhotoSet = (waypoint != null && waypoint.hasPhoto()) || photoUri != null;
|
||||
if (insertPhotoMenuItem != null && insertGalleryImgMenuItem != null) {
|
||||
insertPhotoMenuItem.setVisible(isPhotoSet ? false : true);
|
||||
insertGalleryImgMenuItem.setVisible(isPhotoSet ? false : true);
|
||||
insertPhotoMenuItem.setVisible(!isPhotoSet);
|
||||
insertGalleryImgMenuItem.setVisible(!isPhotoSet);
|
||||
}
|
||||
waypointDeletePhotoBtn.setVisibility(isPhotoSet ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
||||
|
||||
contentProviderUtils = new ContentProviderUtils(this);
|
||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(null);
|
||||
searchEngine = new SearchEngine(contentProviderUtils);
|
||||
|
||||
arrayAdapter = new ArrayAdapter<Map<String, Object>>(this, R.layout.list_item, R.id.list_item_name) {
|
||||
|
||||
@@ -199,7 +199,7 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
||||
|
||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback);
|
||||
trackDataHub = new TrackDataHub(this);
|
||||
|
||||
FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager(), 1) {
|
||||
|
||||
@@ -65,7 +65,7 @@ public class TrackEditActivity extends AbstractActivity implements ChooseActivit
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(null);
|
||||
long trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||
if (trackId == -1L) {
|
||||
Log.e(TAG, "invalid trackId");
|
||||
|
||||
@@ -231,7 +231,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
||||
contentProviderUtils = new ContentProviderUtils(this);
|
||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(bindChangedCallback);
|
||||
trackController = new TrackController(this, trackRecordingServiceConnection, true, recordListener, stopListener);
|
||||
|
||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||
|
||||
@@ -78,8 +78,8 @@ public class TrackDataHub implements DataSourceManager.DataSourceListener, Share
|
||||
|
||||
// Track points sampling state
|
||||
private int numLoadedPoints;
|
||||
private long firstSeenLocationId;
|
||||
private long lastSeenLocationId;
|
||||
private long firstSeenTrackPointId;
|
||||
private long lastSeenTrackPointId;
|
||||
|
||||
public TrackDataHub(Context context) {
|
||||
this(context, new TrackDataManager(), new ContentProviderUtils(context), TARGET_DISPLAYED_TRACK_POINTS);
|
||||
@@ -380,9 +380,9 @@ public class TrackDataHub implements DataSourceManager.DataSourceListener, Share
|
||||
}
|
||||
|
||||
int localNumLoadedPoints = updateSamplingState ? numLoadedPoints : 0;
|
||||
long localFirstSeenLocationId = updateSamplingState ? firstSeenLocationId : -1L;
|
||||
long localLastSeenLocationId = updateSamplingState ? lastSeenLocationId : -1L;
|
||||
long maxPointId = updateSamplingState ? -1L : lastSeenLocationId;
|
||||
long localFirstSeenLocationId = updateSamplingState ? firstSeenTrackPointId : -1L;
|
||||
long localLastSeenLocationId = updateSamplingState ? lastSeenTrackPointId : -1L;
|
||||
long maxPointId = updateSamplingState ? -1L : lastSeenTrackPointId;
|
||||
|
||||
long lastTrackPointId = contentProviderUtils.getLastTrackPointId(selectedTrackId);
|
||||
int samplingFrequency = -1;
|
||||
@@ -431,8 +431,8 @@ public class TrackDataHub implements DataSourceManager.DataSourceListener, Share
|
||||
|
||||
if (updateSamplingState) {
|
||||
numLoadedPoints = localNumLoadedPoints;
|
||||
firstSeenLocationId = localFirstSeenLocationId;
|
||||
lastSeenLocationId = localLastSeenLocationId;
|
||||
firstSeenTrackPointId = localFirstSeenLocationId;
|
||||
lastSeenTrackPointId = localLastSeenLocationId;
|
||||
}
|
||||
|
||||
for (TrackDataListener listener : sampledInListeners) {
|
||||
@@ -445,8 +445,8 @@ public class TrackDataHub implements DataSourceManager.DataSourceListener, Share
|
||||
*/
|
||||
private void resetSamplingState() {
|
||||
numLoadedPoints = 0;
|
||||
firstSeenLocationId = -1L;
|
||||
lastSeenLocationId = -1L;
|
||||
firstSeenTrackPointId = -1L;
|
||||
lastSeenTrackPointId = -1L;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -463,13 +463,4 @@ public class TrackDataHub implements DataSourceManager.DataSourceListener, Share
|
||||
}
|
||||
handler.post(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value selectedTrackId.
|
||||
*
|
||||
* @return the selectedTrackId
|
||||
*/
|
||||
public long getSelectedTrackId() {
|
||||
return selectedTrackId;
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||
*/
|
||||
public class TrackPoint {
|
||||
|
||||
private Location location;
|
||||
private final Location location;
|
||||
|
||||
public TrackPoint() {
|
||||
this.location = new Location("");
|
||||
|
||||
@@ -100,7 +100,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
// A recording track id has been set -> Resumes track and starts timer.
|
||||
resumeTrackDataHub();
|
||||
if (trackRecordingServiceConnection == null) {
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(getContext(), null);
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(null);
|
||||
}
|
||||
trackRecordingServiceConnection.startConnection(getContext());
|
||||
|
||||
@@ -244,7 +244,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
resumeTrackDataHub();
|
||||
PreferencesUtils.register(getContext(), sharedPreferenceChangeListener);
|
||||
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(getContext(), null);
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(null);
|
||||
trackRecordingServiceConnection.startConnection(getContext());
|
||||
|
||||
handlerUpdateUI.post(updateUIeachSecond);
|
||||
|
||||
+1
-2
@@ -54,10 +54,9 @@ public class TrackRecordingServiceConnection implements ServiceConnection, Death
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param context the context
|
||||
* @param callback the callback to invoke when the service binding changes
|
||||
*/
|
||||
public TrackRecordingServiceConnection(Context context, Runnable callback) {
|
||||
public TrackRecordingServiceConnection(Runnable callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public class AnnouncementUtils {
|
||||
} else {
|
||||
//TODO This seems weird; why not use Math.round(d) or Math.ceil()?
|
||||
int count = (int) d;
|
||||
return count < 3 ? 3 : count;
|
||||
return Math.max(count, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
@@ -231,9 +230,8 @@ public class FileUtils {
|
||||
*
|
||||
* @param src source file.
|
||||
* @param dst destination file.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void copy(FileDescriptor src, File dst) throws IOException {
|
||||
*/
|
||||
public static void copy(FileDescriptor src, File dst) {
|
||||
try (FileChannel in = new FileInputStream(src).getChannel();
|
||||
FileChannel out = new FileOutputStream(dst).getChannel()) {
|
||||
in.transferTo(0, in.size(), out);
|
||||
|
||||
Reference in New Issue
Block a user