Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 685b8b2

Browse files
authored
Solve lint issues, reduce baseline (#9627)
* [android] - fix lint issues SDK
1 parent ba7574e commit 685b8b2

File tree

88 files changed

+599
-3335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+599
-3335
lines changed

platform/android/MapboxGLAndroidSDK/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ android {
116116
}
117117

118118
lintOptions {
119-
baseline file("lint-baseline.xml")
119+
baseline file("lint-baseline-local.xml")
120120
checkAllWarnings true
121121
warningsAsErrors true
122122
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<issues format="4" by="lint 2.3.1">
3+
4+
<issue
5+
id="MissingTranslation"
6+
message="&quot;`mapbox_attributionErrorNoBrowser`&quot; is not translated in &quot;ca&quot; (Catalan), &quot;es&quot; (Spanish), &quot;lt&quot; (Lithuanian), &quot;nl&quot; (Dutch), &quot;sv&quot; (Swedish), &quot;vi&quot; (Vietnamese)"
7+
errorLine1=" &lt;string name=&quot;mapbox_attributionErrorNoBrowser&quot;>No web browser installed on device, can\&apos;t open web page.&lt;/string>"
8+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
9+
<location
10+
file="src/main/res/values/strings.xml"
11+
line="13"
12+
column="13"/>
13+
</issue>
14+
15+
<issue
16+
id="MissingTranslation"
17+
message="&quot;`mapbox_telemetrySettings`&quot; is not translated in &quot;ca&quot; (Catalan), &quot;es&quot; (Spanish), &quot;lt&quot; (Lithuanian), &quot;nl&quot; (Dutch), &quot;sv&quot; (Swedish), &quot;vi&quot; (Vietnamese)"
18+
errorLine1=" &lt;string name=&quot;mapbox_telemetrySettings&quot;>Telemetry Settings&lt;/string>"
19+
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
20+
<location
21+
file="src/main/res/values/strings.xml"
22+
line="15"
23+
column="13"/>
24+
</issue>
25+
26+
<issue
27+
id="TypographyQuotes"
28+
message="Replace straight quotes (&apos;&apos;) with directional quotes (‘’, &amp;#8216; and &amp;#8217;) ?"
29+
errorLine1=" &lt;string name=&quot;mapbox_attributionTelemetryMessage&quot;>Estàs ajudant a millorar els mapes d\&apos;OpenStreetMap i de Mapbox aportant dades d\&apos;ús anònimes.&lt;/string>"
30+
errorLine2=" ^">
31+
<location
32+
file="src/main/res/values-ca/strings.xml"
33+
line="9"
34+
column="55"/>
35+
</issue>
36+
37+
</issues>

platform/android/MapboxGLAndroidSDK/lint/lint-baseline-ci.xml

+1-586
Large diffs are not rendered by default.

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mapbox.mapboxsdk;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Context;
45
import android.net.ConnectivityManager;
56
import android.net.NetworkInfo;
@@ -26,6 +27,7 @@
2627
@UiThread
2728
public final class Mapbox {
2829

30+
@SuppressLint("StaticFieldLeak")
2931
private static Mapbox INSTANCE;
3032
private Context context;
3133
private String accessToken;

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mapbox.mapboxsdk.annotations;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Context;
45
import android.graphics.Bitmap;
56
import android.graphics.BitmapFactory;
@@ -35,6 +36,7 @@ public final class IconFactory {
3536
public static final String ICON_MARKERVIEW_ID = ICON_ID_PREFIX + "marker_view";
3637

3738
private Context context;
39+
@SuppressLint("StaticFieldLeak")
3840
private static IconFactory instance;
3941
private Icon defaultMarker;
4042
private Icon defaultMarkerView;

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,11 @@ public void cancel() {
109109
@Override
110110
public void onResponse(Call call, Response response) throws IOException {
111111
if (response.isSuccessful()) {
112-
Timber.v(String.format("[HTTP] Request was successful (code = %d).", response.code()));
112+
Timber.v("[HTTP] Request was successful (code = %s).", response.code());
113113
} else {
114114
// We don't want to call this unsuccessful because a 304 isn't really an error
115115
String message = !TextUtils.isEmpty(response.message()) ? response.message() : "No additional information";
116-
Timber.d(String.format(
117-
"[HTTP] Request with response code = %d: %s",
118-
response.code(), message));
116+
Timber.d("[HTTP] Request with response code = %s: %s", response.code(), message);
119117
}
120118

121119
byte[] body;
@@ -160,15 +158,12 @@ private void onFailure(Exception e) {
160158
String errorMessage = e.getMessage() != null ? e.getMessage() : "Error processing the request";
161159

162160
if (type == TEMPORARY_ERROR) {
163-
Timber.d(String.format(MapboxConstants.MAPBOX_LOCALE,
164-
"Request failed due to a temporary error: %s", errorMessage));
161+
Timber.d("Request failed due to a temporary error: %s", errorMessage);
165162
} else if (type == CONNECTION_ERROR) {
166-
Timber.i(String.format(MapboxConstants.MAPBOX_LOCALE,
167-
"Request failed due to a connection error: %s", errorMessage));
163+
Timber.i("Request failed due to a connection error: %s", errorMessage);
168164
} else {
169165
// PERMANENT_ERROR
170-
Timber.w(String.format(MapboxConstants.MAPBOX_LOCALE,
171-
"Request failed due to a permanent error: %s", errorMessage));
166+
Timber.w("Request failed due to a permanent error: %s", errorMessage);
172167
}
173168

174169
mLock.lock();

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ public void setPrefetchesTiles(boolean enable) {
272272
* Check whether tile pre-fetching is enabled or not.
273273
*
274274
* @return true if enabled
275-
*
276275
* @see MapboxMap#setPrefetchesTiles(boolean)
277276
*/
278277
@UiThread
@@ -316,7 +315,7 @@ public <T extends Layer> T getLayerAs(@NonNull String layerId) {
316315
// noinspection unchecked
317316
return (T) nativeMapView.getLayer(layerId);
318317
} catch (ClassCastException exception) {
319-
Timber.e(String.format("Layer: %s is a different type: %s", layerId, exception));
318+
Timber.e(exception, "Layer: %s is a different type: ", layerId);
320319
return null;
321320
}
322321
}
@@ -437,7 +436,7 @@ public <T extends Source> T getSourceAs(@NonNull String sourceId) {
437436
// noinspection unchecked
438437
return (T) nativeMapView.getSource(sourceId);
439438
} catch (ClassCastException exception) {
440-
Timber.e(String.format("Source: %s is a different type: %s", sourceId, exception));
439+
Timber.e(exception, "Source: %s is a different type: ", sourceId);
441440
return null;
442441
}
443442
}

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.mapbox.mapboxsdk.annotations.Polygon;
1818
import com.mapbox.mapboxsdk.annotations.Polyline;
1919
import com.mapbox.mapboxsdk.camera.CameraPosition;
20-
import com.mapbox.mapboxsdk.constants.MapboxConstants;
2120
import com.mapbox.mapboxsdk.geometry.LatLng;
2221
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
2322
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
@@ -84,9 +83,10 @@ public NativeMapView(MapView mapView) {
8483

8584
private boolean isDestroyedOn(String callingMethod) {
8685
if (destroyed && !TextUtils.isEmpty(callingMethod)) {
87-
Timber.e(String.format(MapboxConstants.MAPBOX_LOCALE,
86+
Timber.e(
8887
"You're calling `%s` after the `MapView` was destroyed, were you invoking it after `onDestroy()`?",
89-
callingMethod));
88+
callingMethod
89+
);
9090
}
9191
return destroyed;
9292
}
@@ -143,14 +143,14 @@ public void resizeView(int width, int height) {
143143
if (width > 65535) {
144144
// we have seen edge cases where devices return incorrect values #6111
145145
Timber.e("Device returned an out of range width size, "
146-
+ "capping value at 65535 instead of " + width);
146+
+ "capping value at 65535 instead of %s", width);
147147
width = 65535;
148148
}
149149

150150
if (height > 65535) {
151151
// we have seen edge cases where devices return incorrect values #6111
152152
Timber.e("Device returned an out of range height size, "
153-
+ "capping value at 65535 instead of " + height);
153+
+ "capping value at 65535 instead of %s", height);
154154
height = 65535;
155155
}
156156
nativeResizeView(width, height);

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public void onMapChanged(int change) {
346346

347347
void setMinZoom(double minZoom) {
348348
if ((minZoom < MapboxConstants.MINIMUM_ZOOM) || (minZoom > MapboxConstants.MAXIMUM_ZOOM)) {
349-
Timber.e("Not setting minZoomPreference, value is in unsupported range: " + minZoom);
349+
Timber.e("Not setting minZoomPreference, value is in unsupported range: %s", minZoom);
350350
return;
351351
}
352352
mapView.setMinZoom(minZoom);
@@ -358,7 +358,7 @@ void setMinZoom(double minZoom) {
358358

359359
void setMaxZoom(double maxZoom) {
360360
if ((maxZoom < MapboxConstants.MINIMUM_ZOOM) || (maxZoom > MapboxConstants.MAXIMUM_ZOOM)) {
361-
Timber.e("Not setting maxZoomPreference, value is in unsupported range: " + maxZoom);
361+
Timber.e("Not setting maxZoomPreference, value is in unsupported range: %s", maxZoom);
362362
return;
363363
}
364364
mapView.setMaxZoom(maxZoom);

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mapbox.mapboxsdk.maps.widgets;
22

33
import android.animation.ValueAnimator;
4+
import android.annotation.SuppressLint;
45
import android.content.Context;
56
import android.graphics.Camera;
67
import android.graphics.Canvas;
@@ -775,6 +776,7 @@ private static class GpsLocationListener implements LocationEngineListener {
775776
locationSource = new WeakReference<>(locationEngine);
776777
}
777778

779+
@SuppressLint("MissingPermission")
778780
@Override
779781
public void onConnected() {
780782
MyLocationView locationView = userLocationView.get();

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mapbox.mapboxsdk.net;
22

3+
import android.annotation.SuppressLint;
34
import android.content.BroadcastReceiver;
45
import android.content.Context;
56
import android.content.Intent;
@@ -21,6 +22,7 @@
2122
* Not public api.
2223
*/
2324
public class ConnectivityReceiver extends BroadcastReceiver {
25+
@SuppressLint("StaticFieldLeak")
2426
private static ConnectivityReceiver INSTANCE;
2527

2628
/**
@@ -82,7 +84,7 @@ public void deactivate() {
8284
@Override
8385
public void onReceive(Context context, Intent intent) {
8486
boolean connected = isConnected(context);
85-
Timber.v("Connected: " + connected);
87+
Timber.v("Connected: %s", connected);
8688

8789
// Loop over listeners
8890
for (ConnectivityListener listener : listeners) {

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mapbox.mapboxsdk.offline;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Context;
45
import android.os.Handler;
56
import android.os.Looper;
@@ -40,6 +41,7 @@ public class OfflineManager {
4041
private Handler handler;
4142

4243
// This object is implemented as a singleton
44+
@SuppressLint("StaticFieldLeak")
4345
private static OfflineManager instance;
4446

4547
// The application context
@@ -90,11 +92,11 @@ public interface CreateOfflineRegionCallback {
9092
*/
9193
private OfflineManager(Context context) {
9294
this.context = context.getApplicationContext();
93-
this.fileSource = FileSource.getInstance(context);
95+
this.fileSource = FileSource.getInstance(this.context);
9496
initialize(fileSource);
9597

9698
// Delete any existing previous ambient cache database
97-
deleteAmbientDatabase(context);
99+
deleteAmbientDatabase(this.context);
98100
}
99101

100102
private void deleteAmbientDatabase(final Context context) {
@@ -107,10 +109,10 @@ public void run() {
107109
File file = new File(path);
108110
if (file.exists()) {
109111
file.delete();
110-
Timber.d("Old ambient cache database deleted to save space: " + path);
112+
Timber.d("Old ambient cache database deleted to save space: %s", path);
111113
}
112114
} catch (Exception exception) {
113-
Timber.e("Failed to delete old ambient cache database: ", exception);
115+
Timber.e(exception, "Failed to delete old ambient cache database: ");
114116
}
115117
}
116118
}).start();

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ public static String getCachePath(Context context) {
7272
MapboxConstants.KEY_META_DATA_SET_STORAGE_EXTERNAL,
7373
MapboxConstants.DEFAULT_SET_STORAGE_EXTERNAL);
7474
} catch (PackageManager.NameNotFoundException exception) {
75-
Timber.e("Failed to read the package metadata: ", exception);
75+
Timber.e(exception,"Failed to read the package metadata: ");
7676
} catch (Exception exception) {
77-
Timber.e("Failed to read the storage key: ", exception);
77+
Timber.e(exception, "Failed to read the storage key: ");
7878
}
7979

8080
String cachePath = null;
@@ -83,7 +83,7 @@ public static String getCachePath(Context context) {
8383
// Try getting the external storage path
8484
cachePath = context.getExternalFilesDir(null).getAbsolutePath();
8585
} catch (NullPointerException exception) {
86-
Timber.e("Failed to obtain the external storage path: ", exception);
86+
Timber.e(exception, "Failed to obtain the external storage path: ");
8787
}
8888
}
8989

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public <S extends Stops> S getStopsAs() {
279279
// noinspection unchecked
280280
return (S) stops;
281281
} catch (ClassCastException exception) {
282-
Timber.e(String.format("Stops: %s is a different type: %s", stops.getClass(), exception));
282+
Timber.e(exception, "Stops: %s is a different type: ", stops.getClass());
283283
return null;
284284
}
285285
}

platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@
8383

8484
<!-- Exposed styles -->
8585
<public name="mapbox_style_mapbox_streets" type="string" />
86-
<public name="mapbox_style_emerald" type="string" />
86+
<public name="mapbox_style_outdoors" type="string" />
8787
<public name="mapbox_style_light" type="string" />
8888
<public name="mapbox_style_dark" type="string" />
8989
<public name="mapbox_style_satellite" type="string" />
9090
<public name="mapbox_style_satellite_streets" type="string" />
91+
<public name="mapbox_style_traffic_day" type="string" />
92+
<public name="mapbox_style_traffic_night" type="string" />
9193

9294
<!-- Exposed strings -->
9395
<public name="mapbox_compassContentDescription" type="string" />

platform/android/MapboxGLAndroidSDK/src/main/res/color/mapbox_material_bg_selector.xml

-5
This file was deleted.

platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_attribution_list_item.xml

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
android:paddingLeft="24dp"
1010
android:paddingRight="24dp"
1111
android:textAllCaps="true"
12+
android:textIsSelectable="true"
1213
android:textAppearance="?android:attr/textAppearanceButton"
1314
android:textColor="@color/mapbox_blue"/>

platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
android:layout_width="wrap_content"
2424
android:layout_height="wrap_content"
2525
android:layout_marginBottom="2dp"
26+
android:textIsSelectable="true"
2627
android:maxEms="17"
2728
android:textColor="@android:color/black"
2829
android:textSize="18sp"
@@ -34,13 +35,13 @@
3435
android:layout_height="wrap_content"
3536
android:layout_marginBottom="2dp"
3637
android:layout_marginTop="2dp"
38+
android:textIsSelectable="true"
3739
android:lineSpacingExtra="1dp"
3840
android:maxEms="17"
3941
android:textColor="@color/mapbox_gray"
4042
android:textSize="14sp"/>
4143

4244
<TextView
43-
android:id="@+id/infowindow_subdescription"
4445
android:layout_width="wrap_content"
4546
android:layout_height="wrap_content"
4647
android:maxEms="17"
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:id="@+id/image"
4-
android:layout_width="wrap_content"
5-
android:layout_height="wrap_content" />
3+
android:id="@+id/image"
4+
android:layout_width="wrap_content"
5+
android:layout_height="wrap_content"
6+
android:contentDescription="@null"/>

platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
<color name="mapbox_gray">#7D7F80</color>
44
<color name="mapbox_gray_light">#EEEEEE</color>
55
<color name="mapbox_blue">#1E8CAB</color>
6-
<color name="mapbox_my_location_ring">@color/mapbox_blue</color>
76
</resources>

platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml

-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@
22
<resources>
33
<dimen name="mapbox_infowindow_tipview_width">8dp</dimen>
44
<dimen name="mapbox_infowindow_margin">8dp</dimen>
5-
<dimen name="mapbox_infowindow_offset">-2dp</dimen>
6-
<dimen name="mapbox_infowindow_line_width">1.5dp</dimen>
7-
<dimen name="mapbox_attribution_icon_left_padding">@dimen/mapbox_two_dp</dimen>
8-
<dimen name="mapbox_attribution_icon_top_padding">@dimen/mapbox_two_dp</dimen>
9-
<dimen name="mapbox_attribution_icon_right_padding">@dimen/mapbox_two_dp</dimen>
10-
<dimen name="mapbox_attribution_icon_bottom_padding">@dimen/mapbox_two_dp</dimen>
11-
<dimen name="mapbox_two_dp">2dp</dimen>
125
<dimen name="mapbox_four_dp">4dp</dimen>
136
<dimen name="mapbox_eight_dp">8dp</dimen>
14-
<dimen name="mapbox_ten_dp">10dp</dimen>
15-
<dimen name="mapbox_sixteen_dp">16dp</dimen>
167
<dimen name="mapbox_ninety_two_dp">92dp</dimen>
178
<dimen name="mapbox_my_locationview_outer_circle">18dp</dimen>
189
</resources>

0 commit comments

Comments
 (0)