diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils')
14 files changed, 0 insertions, 875 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FileUtils.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FileUtils.kt deleted file mode 100644 index e0c1ca4207..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FileUtils.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils - -import android.content.Context -import android.os.AsyncTask -import java.io.File -import java.io.FileOutputStream -import java.lang.ref.WeakReference - -class FileUtils { - - /** - * Task that copies a file from the assets directory to a provided directory. - * The asset's name is going to be kept in the new directory. - */ - class CopyFileFromAssetsTask(context: Context, listener: OnFileCopiedFromAssetsListener) : AsyncTask<String, Void, Boolean>() { - private val contextWeakReference: WeakReference<Context> = WeakReference(context) - private val listenerWeakReference: WeakReference<OnFileCopiedFromAssetsListener> = WeakReference(listener) - - override fun doInBackground(vararg strings: String): Boolean? { - val assetName = strings[0] - val destinationPath = strings[1] - contextWeakReference.get()?.let { - try { - copyAsset(it, assetName, destinationPath) - } catch (ex: Exception) { - return false - } - } - - return true - } - - override fun onCancelled() { - listenerWeakReference.get()?.onError() - } - - override fun onPostExecute(result: Boolean) { - if (result) { - listenerWeakReference.get()?.onFileCopiedFromAssets() - } else { - listenerWeakReference.get()?.onError() - } - } - - private fun copyAsset(context: Context, assetName: String, destinationPath: String) { - val bufferSize = 1024 - val assetManager = context.assets - val inputStream = assetManager.open(assetName) - val outputStream = FileOutputStream(File(destinationPath, assetName)) - try { - inputStream.copyTo(outputStream, bufferSize) - } finally { - inputStream.close() - outputStream.flush() - outputStream.close() - } - } - } - - interface OnFileCopiedFromAssetsListener { - fun onFileCopiedFromAssets() - fun onError() - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FontCache.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FontCache.java deleted file mode 100644 index a4352d0b1c..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/FontCache.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - -import android.content.Context; -import android.graphics.Typeface; - -import java.util.Hashtable; - -import timber.log.Timber; - -public class FontCache { - - private static Hashtable<String, Typeface> fontCache = new Hashtable<>(); - - public static Typeface get(String name, Context context) { - Typeface tf = fontCache.get(name); - if (tf == null) { - try { - tf = Typeface.createFromAsset(context.getAssets(), name); - fontCache.put(name, tf); - } catch (Exception exception) { - Timber.e("Font not found"); - } - } - return tf; - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java deleted file mode 100644 index c21e479659..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/GeoParseUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - -import android.content.Context; -import android.text.TextUtils; - -import com.mapbox.geojson.Feature; -import com.mapbox.geojson.FeatureCollection; -import com.mapbox.geojson.Point; -import com.mapbox.mapboxsdk.geometry.LatLng; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -public class GeoParseUtil { - - public static String loadStringFromAssets(final Context context, final String fileName) throws IOException { - if (TextUtils.isEmpty(fileName)) { - throw new NullPointerException("No GeoJSON File Name passed in."); - } - InputStream is = context.getAssets().open(fileName); - BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); - return readAll(rd); - } - - public static List<LatLng> parseGeoJsonCoordinates(String geojsonStr) { - List<LatLng> latLngs = new ArrayList<>(); - FeatureCollection featureCollection = FeatureCollection.fromJson(geojsonStr); - for (Feature feature : featureCollection.features()) { - if (feature.geometry() instanceof Point) { - Point point = (Point) feature.geometry(); - latLngs.add(new LatLng(point.latitude(), point.longitude())); - } - } - return latLngs; - } - - private static String readAll(Reader rd) throws IOException { - StringBuilder sb = new StringBuilder(); - int cp; - while ((cp = rd.read()) != -1) { - sb.append((char) cp); - } - return sb.toString(); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/IconUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/IconUtils.java deleted file mode 100644 index b6768a91a3..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/IconUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.DrawableRes; -import android.support.annotation.NonNull; -import android.support.v4.content.res.ResourcesCompat; -import android.support.v4.graphics.drawable.DrawableCompat; - -import com.mapbox.mapboxsdk.annotations.Icon; -import com.mapbox.mapboxsdk.annotations.IconFactory; - -public class IconUtils { - - /** - * Demonstrates converting any Drawable to an Icon, for use as a marker icon. - */ - public static Icon drawableToIcon(@NonNull Context context, @DrawableRes int id, @ColorInt int colorRes) { - Drawable vectorDrawable = ResourcesCompat.getDrawable(context.getResources(), id, context.getTheme()); - Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(), - vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); - DrawableCompat.setTint(vectorDrawable, colorRes); - vectorDrawable.draw(canvas); - return IconFactory.getInstance(context).fromBitmap(bitmap); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/IdleZoomListener.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/IdleZoomListener.java deleted file mode 100644 index 80f17ab58e..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/IdleZoomListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - -import android.content.Context; -import android.widget.TextView; -import com.mapbox.mapboxsdk.camera.CameraPosition; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.testapp.R; - -public class IdleZoomListener implements MapboxMap.OnCameraIdleListener { - - private MapboxMap mapboxMap; - private TextView textView; - - public IdleZoomListener(MapboxMap mapboxMap, TextView textView) { - this.mapboxMap = mapboxMap; - this.textView = textView; - } - - @Override - public void onCameraIdle() { - Context context = textView.getContext(); - CameraPosition position = mapboxMap.getCameraPosition(); - textView.setText(String.format(context.getString(R.string.debug_zoom), position.zoom)); - } -}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/ItemClickSupport.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/ItemClickSupport.java deleted file mode 100644 index 0939181ef4..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/ItemClickSupport.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - -import android.support.v7.widget.RecyclerView; -import android.view.View; - -import com.mapbox.mapboxsdk.testapp.R; - -public class ItemClickSupport { - private final RecyclerView recyclerView; - private OnItemClickListener onItemClickListener; - private OnItemLongClickListener onItemLongClickListener; - private View.OnClickListener onClickListener = new View.OnClickListener() { - @Override - public void onClick(View view) { - if (onItemClickListener != null) { - RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(view); - onItemClickListener.onItemClicked(recyclerView, holder.getAdapterPosition(), view); - } - } - }; - private View.OnLongClickListener onLongClickListener = new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - if (onItemLongClickListener != null) { - RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(view); - return onItemLongClickListener.onItemLongClicked(recyclerView, holder.getAdapterPosition(), view); - } - return false; - } - }; - private RecyclerView.OnChildAttachStateChangeListener attachListener - = new RecyclerView.OnChildAttachStateChangeListener() { - @Override - public void onChildViewAttachedToWindow(View view) { - if (onItemClickListener != null) { - view.setOnClickListener(onClickListener); - } - if (onItemLongClickListener != null) { - view.setOnLongClickListener(onLongClickListener); - } - } - - @Override - public void onChildViewDetachedFromWindow(View view) { - - } - }; - - private ItemClickSupport(RecyclerView recyclerView) { - this.recyclerView = recyclerView; - this.recyclerView.setTag(R.id.item_click_support, this); - this.recyclerView.addOnChildAttachStateChangeListener(attachListener); - } - - public static ItemClickSupport addTo(RecyclerView view) { - ItemClickSupport support = (ItemClickSupport) view.getTag(R.id.item_click_support); - if (support == null) { - support = new ItemClickSupport(view); - } - return support; - } - - public static ItemClickSupport removeFrom(RecyclerView view) { - ItemClickSupport support = (ItemClickSupport) view.getTag(R.id.item_click_support); - if (support != null) { - support.detach(view); - } - return support; - } - - public ItemClickSupport setOnItemClickListener(OnItemClickListener listener) { - onItemClickListener = listener; - return this; - } - - public ItemClickSupport setOnItemLongClickListener(OnItemLongClickListener listener) { - onItemLongClickListener = listener; - return this; - } - - private void detach(RecyclerView view) { - view.removeOnChildAttachStateChangeListener(attachListener); - view.setTag(R.id.item_click_support, null); - } - - public interface OnItemClickListener { - - void onItemClicked(RecyclerView recyclerView, int position, View view); - } - - public interface OnItemLongClickListener { - - boolean onItemLongClicked(RecyclerView recyclerView, int position, View view); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/NavUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/NavUtils.java deleted file mode 100644 index f59e80e921..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/NavUtils.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - -import android.app.Activity; -import android.content.Intent; -import android.support.annotation.NonNull; -import com.mapbox.mapboxsdk.testapp.activity.FeatureOverviewActivity; - -public class NavUtils { - - public static void navigateHome(@NonNull Activity context) { - context.startActivity(new Intent(context, FeatureOverviewActivity.class)); - context.finish(); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/OfflineUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/OfflineUtils.java deleted file mode 100644 index 7a6e6ac063..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/OfflineUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - -import android.support.annotation.NonNull; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.testapp.activity.offline.OfflineActivity.JSON_CHARSET; -import static com.mapbox.mapboxsdk.testapp.activity.offline.OfflineActivity.JSON_FIELD_REGION_NAME; - -public class OfflineUtils { - - public static String convertRegionName(@NonNull byte[] metadata) { - try { - String json = new String(metadata, JSON_CHARSET); - JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class); - String name = jsonObject.get(JSON_FIELD_REGION_NAME).getAsString(); - return name != null ? name : ""; - } catch (Exception exception) { - return ""; - } - } - - public static byte[] convertRegionName(String regionName) { - try { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty(JSON_FIELD_REGION_NAME, regionName); - return jsonObject.toString().getBytes(JSON_CHARSET); - } catch (Exception exception) { - Timber.e(exception, "Failed to encode metadata: "); - } - return null; - } - -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/ResourceUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/ResourceUtils.java deleted file mode 100644 index 6b522ac210..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/ResourceUtils.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - -import android.content.Context; -import android.support.annotation.RawRes; -import android.util.TypedValue; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringWriter; -import java.io.Writer; - -public class ResourceUtils { - - public static String readRawResource(Context context, @RawRes int rawResource) throws IOException { - String json = ""; - if (context != null) { - Writer writer = new StringWriter(); - char[] buffer = new char[1024]; - try (InputStream is = context.getResources().openRawResource(rawResource)) { - Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); - int numRead; - while ((numRead = reader.read(buffer)) != -1) { - writer.write(buffer, 0, numRead); - } - } - json = writer.toString(); - } - return json; - } - - public static float convertDpToPx(Context context, float dp) { - return TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); - } -} - diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/TileLoadingMeasurementUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/TileLoadingMeasurementUtils.java deleted file mode 100644 index c8af9aee21..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/TileLoadingMeasurementUtils.java +++ /dev/null @@ -1,217 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - -import android.app.ActivityManager; -import android.content.Context; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.net.ConnectivityManager; -import android.net.NetworkCapabilities; -import android.net.NetworkInfo; -import android.os.Build; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.StringDef; -import android.util.DisplayMetrics; -import android.view.Display; -import android.view.WindowManager; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.mapbox.mapboxsdk.MapStrictMode; -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.mapboxsdk.module.http.HttpRequestUtil; - -import java.io.IOException; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import okhttp3.Interceptor; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.constants.MapboxConstants.DEFAULT_MEASURE_TILE_DOWNLOAD_ON; -import static com.mapbox.mapboxsdk.constants.MapboxConstants.KEY_META_DATA_MEASURE_TILE_DOWNLOAD_ON; - -public class TileLoadingMeasurementUtils { - - private static final String ATTRIBUTE_REQUEST_URL = "requestUrl"; - - - public static void setUpTileLoadingMeasurement() { - if (isTileLoadingMeasurementOn()) { - OkHttpClient okHttpClient = new OkHttpClient.Builder() - .addNetworkInterceptor(new TileLoadingInterceptor()) - .build(); - HttpRequestUtil.setOkHttpClient(okHttpClient); - } - } - - private static boolean isTileLoadingMeasurementOn() { - return isBooleanMetaDataValueOn(KEY_META_DATA_MEASURE_TILE_DOWNLOAD_ON, - DEFAULT_MEASURE_TILE_DOWNLOAD_ON); - } - - private static boolean isBooleanMetaDataValueOn(@NonNull String propKey, boolean defaultValue) { - - try { - // Try getting a custom value from the app Manifest - Context context = Mapbox.getApplicationContext(); - ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), - PackageManager.GET_META_DATA); - if (appInfo.metaData != null) { - return appInfo.metaData.getBoolean(propKey, defaultValue); - } - } catch (PackageManager.NameNotFoundException exception) { - Timber.e("Failed to read the package metadata: " + exception); - MapStrictMode.strictModeViolation(exception); - } catch (Exception exception) { - Timber.e("Failed to read key: " + propKey + " " + exception); - MapStrictMode.strictModeViolation(exception); - } - return defaultValue; - } - - - /** - * This Interceptor allows to measure time spent getting a response object over network. - * The following data will be collected: - * responseCode, elapsedMS - * requestUrl (request string till the question mark), - * and device metadata. - */ - static class TileLoadingInterceptor implements Interceptor { - - private static String metadata = null; - - @StringDef( {CONNECTION_NONE, CONNECTION_CELLULAR, CONNECTION_WIFI}) - @Retention(RetentionPolicy.SOURCE) - @interface ConnectionState { - } - private static final String CONNECTION_NONE = "none"; - private static final String CONNECTION_CELLULAR = "cellular"; - private static final String CONNECTION_WIFI = "wifi"; - - @Override - public Response intercept(Chain chain) throws IOException { - Request request = chain.request(); - long elapsed = System.nanoTime(); - - Response response = chain.proceed(request); - elapsed = System.nanoTime() - elapsed; - - triggerPerformanceEvent(response, elapsed / 1000000); - - return response; - } - - private void triggerPerformanceEvent(Response response, long elapsedMs) { - List<Attribute<String>> attributes = new ArrayList<>(); - String request = getUrl(response.request()); - attributes.add(new Attribute<>("requestUrl", request)); - attributes.add(new Attribute<>("responseCode", String.valueOf(response.code()))); - attributes.add( - new Attribute<>("connectionState", getConnectionState())); - - List<Attribute<Long>> counters = new ArrayList(); - counters.add(new Attribute<>("elapsedMS", elapsedMs)); - - Bundle bundle = new Bundle(); - Gson gson = new Gson(); - bundle.putString("attributes", gson.toJson(attributes)); - bundle.putString("counters", gson.toJson(counters)); - bundle.putString("metadata", getMetadata()); - - Mapbox.getTelemetry().onPerformanceEvent(bundle); - } - - private static String getUrl(Request request) { - String url = request.url().toString(); - return url.substring(0, url.indexOf('?')); - } - - private static String getMetadata() { - if (metadata == null) { - JsonObject metaData = new JsonObject(); - metaData.addProperty("os", "android"); - metaData.addProperty("manufacturer", Build.MANUFACTURER); - metaData.addProperty("brand", Build.BRAND); - metaData.addProperty("device", Build.MODEL); - metaData.addProperty("version", Build.VERSION.RELEASE); - metaData.addProperty("abi", Build.CPU_ABI); - metaData.addProperty("country", Locale.getDefault().getISO3Country()); - metaData.addProperty("ram", getRam()); - metaData.addProperty("screenSize", getWindowSize()); - - metadata = metaData.toString(); - } - return metadata; - } - - private static String getRam() { - ActivityManager actManager = - (ActivityManager) Mapbox.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); - ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo(); - actManager.getMemoryInfo(memInfo); - return String.valueOf(memInfo.totalMem); - } - - private static String getWindowSize() { - WindowManager windowManager = - (WindowManager) Mapbox.getApplicationContext().getSystemService(Context.WINDOW_SERVICE); - Display display = windowManager.getDefaultDisplay(); - DisplayMetrics metrics = new DisplayMetrics(); - display.getMetrics(metrics); - int width = metrics.widthPixels; - int height = metrics.heightPixels; - return "{" + width + "," + height + "}"; - } - - @ConnectionState - private static String getConnectionState() { - Context appContext = Mapbox.getApplicationContext(); - ConnectivityManager connectivityManager = - (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (connectivityManager != null) { - NetworkCapabilities capabilities = - connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork()); - if (capabilities != null) { - if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { - return CONNECTION_WIFI; - } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { - return CONNECTION_CELLULAR; - } - } - } - } else { - if (connectivityManager != null) { - NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); - if (activeNetwork != null) { - if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) { - return CONNECTION_WIFI; - } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { - return CONNECTION_CELLULAR; - } - } - } - } - return CONNECTION_NONE; - } - } - - private static class Attribute<T> { - private String name; - private T value; - - Attribute(String name, T value) { - this.name = name; - this.value = value; - } - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/TimberLogger.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/TimberLogger.java deleted file mode 100644 index 369e25a012..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/TimberLogger.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - -import com.mapbox.mapboxsdk.log.LoggerDefinition; -import timber.log.Timber; - -public class TimberLogger implements LoggerDefinition { - - @Override - public void v(String tag, String msg) { - Timber.tag(tag).v(msg); - } - - @Override - public void v(String tag, String msg, Throwable tr) { - Timber.tag(tag).v(tr, msg); - } - - @Override - public void d(String tag, String msg) { - Timber.tag(tag).d(msg); - } - - @Override - public void d(String tag, String msg, Throwable tr) { - Timber.tag(tag).d(tr, msg); - } - - @Override - public void i(String tag, String msg) { - Timber.tag(tag).i(msg); - } - - @Override - public void i(String tag, String msg, Throwable tr) { - Timber.tag(tag).i(tr, msg); - } - - @Override - public void w(String tag, String msg) { - Timber.tag(tag).w(msg); - } - - @Override - public void w(String tag, String msg, Throwable tr) { - Timber.tag(tag).w(tr, msg); - } - - @Override - public void e(String tag, String msg) { - Timber.tag(tag).e(msg); - } - - @Override - public void e(String tag, String msg, Throwable tr) { - Timber.tag(tag).e(tr, msg); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/TimingLogger.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/TimingLogger.java deleted file mode 100644 index 235fd8233b..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/TimingLogger.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; -/* - * Copyright (C) 2007 The Android Open Source Project - * - * 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. - */ - -import android.os.SystemClock; - -import java.util.ArrayList; - -import timber.log.Timber; - -/** - * A utility class to help log timings splits throughout a method call. - * Typical usage is: - * <p> - * <pre> - * TimingLogger timings = new TimingLogger(TAG, "methodA"); - * // ... do some work A ... - * timings.addSplit("work A"); - * // ... do some work B ... - * timings.addSplit("work B"); - * // ... do some work C ... - * timings.addSplit("work C"); - * timings.dumpToLog(); - * </pre> - * <p> - * <p>The dumpToLog call would add the following to the log:</p> - * <p> - * <pre> - * D/TAG ( 3459): methodA: begin - * D/TAG ( 3459): methodA: 9 ms, work A - * D/TAG ( 3459): methodA: 1 ms, work B - * D/TAG ( 3459): methodA: 6 ms, work C - * D/TAG ( 3459): methodA: end, 16 ms - * </pre> - */ -public class TimingLogger { - /** - * The Log tag to use for checking Log.isLoggable and for - * logging the timings. - */ - private String tag; - /** - * A label to be included in every log. - */ - private String label; - /** - * Used to track whether Log.isLoggable was enabled at reset time. - */ - private boolean disabled; - /** - * Stores the time of each split. - */ - private ArrayList<Long> splits; - /** - * Stores the labels for each split. - */ - private ArrayList<String> splitLabels; - - /** - * Create and initialize a TimingLogger object that will log using - * the specific tag. If the Log.isLoggable is not enabled to at - * least the Log.VERBOSE level for that tag at creation time then - * the addSplit and dumpToLog call will do nothing. - * - * @param tag the log tag to use while logging the timings - * @param label a string to be displayed with each log - */ - public TimingLogger(String tag, String label) { - reset(tag, label); - } - - /** - * Clear and initialize a TimingLogger object that will log using - * the specific tag. If the Log.isLoggable is not enabled to at - * least the Log.VERBOSE level for that tag at creation time then - * the addSplit and dumpToLog call will do nothing. - * - * @param tag the log tag to use while logging the timings - * @param label a string to be displayed with each log - */ - public void reset(String tag, String label) { - this.tag = tag; - this.label = label; - reset(); - } - - /** - * Clear and initialize a TimingLogger object that will log using - * the tag and label that was specified previously, either via - * the constructor or a call to reset(tag, label). If the - * Log.isLoggable is not enabled to at least the Log.VERBOSE - * level for that tag at creation time then the addSplit and - * dumpToLog call will do nothing. - */ - public void reset() { - disabled = false; // !Log.isLoggable(tag, Log.VERBOSE); - if (disabled) { - return; - } - if (splits == null) { - splits = new ArrayList<Long>(); - splitLabels = new ArrayList<String>(); - } else { - splits.clear(); - splitLabels.clear(); - } - addSplit(null); - } - - /** - * Add a split for the current time, labeled with splitLabel. If - * Log.isLoggable was not enabled to at least the Log.VERBOSE for - * the specified tag at construction or reset() time then this - * call does nothing. - * - * @param splitLabel a label to associate with this split. - */ - public void addSplit(String splitLabel) { - if (disabled) { - return; - } - long now = SystemClock.elapsedRealtime(); - splits.add(now); - splitLabels.add(splitLabel); - } - - /** - * Dumps the timings to the log using Timber.d(). If Log.isLoggable was - * not enabled to at least the Log.VERBOSE for the specified tag at - * construction or reset() time then this call does nothing. - */ - public void dumpToLog() { - if (disabled) { - return; - } - Timber.d("%s: begin", label); - final long first = splits.get(0); - long now = first; - for (int i = 1; i < splits.size(); i++) { - now = splits.get(i); - final String splitLabel = splitLabels.get(i); - final long prev = splits.get(i - 1); - Timber.d("%s: %s ms, %s", label, (now - prev), splitLabel); - } - Timber.d("%s: end, %s ms", label, (now - first)); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/TokenUtils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/TokenUtils.java deleted file mode 100644 index e08fdb9154..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/TokenUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - - -import android.content.Context; -import android.support.annotation.NonNull; - -import com.mapbox.mapboxsdk.Mapbox; - -public class TokenUtils { - - /** - * <p> - * Returns the Mapbox access token set in the app resources. - * </p> - * It will first search for a token in the Mapbox object. If not found it - * will then attempt to load the access token from the - * {@code res/values/dev.xml} development file. - * - * @param context The {@link Context} of the {@link android.app.Activity} or {@link android.app.Fragment}. - * @return The Mapbox access token or null if not found. - */ - public static String getMapboxAccessToken(@NonNull Context context) { - try { - // Read out AndroidManifest - String token = Mapbox.getAccessToken(); - if (token == null || token.isEmpty()) { - throw new IllegalArgumentException(); - } - return token; - } catch (Exception exception) { - // Use fallback on string resource, used for development - int tokenResId = context.getResources() - .getIdentifier("mapbox_access_token", "string", context.getPackageName()); - return tokenResId != 0 ? context.getString(tokenResId) : null; - } - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/ViewToBitmapUtil.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/ViewToBitmapUtil.java deleted file mode 100644 index e8091248f4..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/utils/ViewToBitmapUtil.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.utils; - -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.support.annotation.NonNull; -import android.view.View; - -/** - * Converts a View to a Bitmap so we can use an Android SDK View as a Symbol. - */ -public class ViewToBitmapUtil { - - public static Bitmap convertToBitmap(@NonNull View view) { - view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), - View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); - view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); - Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - view.draw(canvas); - return bitmap; - } -} |