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

Restructure Android TestApp #2567

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ MapboxGLAndroidSDK/src/main/assets/
local.properties

# Token file
MapboxGLAndroidSDKTestApp/src/main/res/raw/token.txt
MapboxGLAndroidSDK/src/main/res/raw/token.txt

# Twitter Fabric / Crashlytics
fabric.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk;

import android.os.Bundle;
import android.support.v4.app.Fragment;
Expand All @@ -7,6 +7,7 @@
import android.view.View;
import android.view.ViewGroup;

import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;

public class MapFragment extends Fragment {
Expand Down Expand Up @@ -36,7 +37,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
Log.v(TAG, "onCreateView");

// Create the map
mMap = (MapView) inflater.inflate(R.layout.fragment_main, container, true);
mMap = (MapView) inflater.inflate(R.layout.mapview, container, false);

// Set accessToken
mMap.setAccessToken(ApiAccess.getToken(container.getContext()));

// Need to pass on any saved state to the map
mMap.onCreate(savedInstanceState);
Expand Down Expand Up @@ -106,6 +110,15 @@ public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}

@Override
public void onLowMemory() {
Log.v(TAG, "OnLowMemory");

// Need to pass on to view
mMap.onLowMemory();
super.onLowMemory();
}

//
// Property methods
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ public class MapboxConstants {
// Default Locale for data processing (ex: String.toLowerCase(MAPBOX_LOCALE, "foo"))
public static final Locale MAPBOX_LOCALE = Locale.US;

// Key used to store access token in AndroidManifest.xml
public static final String KEY_META_DATA_MANIFEST = "com.mapbox.AccessToken";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.mapbox.mapboxsdk.utils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.constants.MapboxConstants;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ApiAccess {

public static String getToken(@NonNull Context context) {
String accessToken = getReleaseToken(context);
if (TextUtils.isEmpty(accessToken)) {
accessToken = getDevelopmentToken(context);
}
return accessToken;
}

private static String getReleaseToken(@NonNull Context context){
try {
PackageManager packageManager = context.getPackageManager();
ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
return appInfo.metaData.getString(MapboxConstants.KEY_META_DATA_MANIFEST);
} catch (Exception e) {
return null;
}
}

private static String getDevelopmentToken(@NonNull Context context) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().openRawResource(R.raw.token)));
return reader.readLine();
}catch (IOException e){
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<com.mapbox.mapboxsdk.views.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
null
4 changes: 2 additions & 2 deletions android/java/MapboxGLAndroidSDKTestApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ apply plugin: 'io.fabric'
apply plugin: 'checkstyle'

task accessToken {
def rawDir = new File("MapboxGLAndroidSDKTestApp/src/main/res/raw")
def rawDir = new File("MapboxGLAndroidSDK/src/main/res/raw")
rawDir.mkdirs()
def tokenFile = new File("MapboxGLAndroidSDKTestApp/src/main/res/raw/token.txt")
def tokenFile = new File("MapboxGLAndroidSDK/src/main/res/raw/token.txt")
if (!tokenFile.exists()) {
String token = "$System.env.MAPBOX_ACCESS_TOKEN"
if (token == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
import static android.support.test.espresso.matcher.ViewMatchers.withId;

/**
* Tests on SecondMapActivity.
* Tests on InfoWindowAdapterActivity.
*/
@RunWith(AndroidJUnit4.class)
@LargeTest
public class SecondMapActivityTest extends BaseTest {
public class InfoWindowAdapterActivityTest extends BaseTest {

@Rule
public ActivityTestRule<SecondMapActivity> mActivityRule = new ActivityTestRule<>(
SecondMapActivity.class);
public ActivityTestRule<InfoWindowAdapterActivity> mActivityRule = new ActivityTestRule<>(
InfoWindowAdapterActivity.class);

private SecondMapActivity mActivity = null;
private InfoWindowAdapterActivity mActivity = null;

@Before
public void setActivity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mapbox.mapboxsdk.testapp">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@drawable/icon_burned"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:supportsRtl="true">
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name="com.mapbox.mapboxsdk.testapp.MainActivity"
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.mapbox.mapboxsdk.testapp.SecondMapActivity" android:label="@string/activity_second"/>

<activity
android:name=".InfoWindowAdapterActivity"
android:label="@string/activity_infowindow_adapter" />

<activity
android:name=".MapFragmentActivity"
android:label="@string/activity_map_fragment" />

<meta-data
android:name="io.fabric.ApiKey"
android:value="9724157045ff7d083492c6d9ae03e60e8609d461" />

<meta-data
android:name="com.mapbox.AccessToken"
android:value="" />

</application>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,70 @@
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class InfoWindowAdapterActivity extends AppCompatActivity {

public class SecondMapActivity extends AppCompatActivity {

private static final String TAG = "SecondMapActivity";
private static final String TAG = "InfoWindowAdapter";

private MapView mMapView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_second);
setContentView(R.layout.activity_infowindow_adapter);

Toolbar toolbar = (Toolbar) findViewById(R.id.secondToolBar);
setSupportActionBar(toolbar);

ActionBar actionBar = getSupportActionBar();
if(actionBar!=null) {
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}

mMapView = (MapView) findViewById(R.id.secondMapView);
// Load the access token
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.token)));
String line = reader.readLine();
mMapView.setAccessToken(line);
} catch (IOException e) {
Log.e(TAG, "Error loading access token from token.txt: " + e.toString());
}

mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.onCreate(savedInstanceState);

mMapView.setStyleUrl(MapView.StyleUrls.EMERALD);

mMapView.setStyleUrl(MapView.StyleUrls.MAPBOX_STREETS);
mMapView.setInfoWindowAdapter(new MapView.InfoWindowAdapter() {

private int tenDp = (int) getResources().getDimension(R.dimen.attr_margin);

@Override
public View getInfoWindow(Marker marker) {
TextView textView = new TextView(SecondMapActivity.this);
TextView textView = new TextView(InfoWindowAdapterActivity.this);
textView.setText(marker.getTitle());
textView.setBackgroundColor(Color.WHITE);
textView.setTextColor(Color.WHITE);
textView.setBackgroundColor(Color.parseColor(marker.getSnippet()));
textView.setPadding(tenDp, tenDp, tenDp, tenDp);
return textView;
}
});

mMapView.addMarker(generateMarker("Andorra", 42.505777, 1.525294));
mMapView.addMarker(generateMarker("Luxembourg", 49.815273, 6.129583));
mMapView.addMarker(generateMarker("Monaco", 43.738418, 7.424616));
mMapView.addMarker(generateMarker("Vatican City", 41.902916, 12.453389));
mMapView.addMarker(generateMarker("San Marino", 43.942360, 12.457777));
mMapView.addMarker(generateMarker("Malta", 35.892110, 14.427795));
mMapView.addMarker(generateMarker("Liechtenstein", 47.166000, 9.555373));
mMapView.addMarker(generateMarker("Andorra", 42.505777, 1.52529, "#F44336"));
mMapView.addMarker(generateMarker("Luxembourg", 49.815273, 6.129583, "#3F51B5"));
mMapView.addMarker(generateMarker("Monaco", 43.738418, 7.424616, "#673AB7"));
mMapView.addMarker(generateMarker("Vatican City", 41.902916, 12.453389, "#009688"));
mMapView.addMarker(generateMarker("San Marino", 43.942360, 12.457777, "#795548"));
mMapView.addMarker(generateMarker("Liechtenstein", 47.166000, 9.555373, "#FF5722"));

mMapView.setCenterCoordinate(new LatLng(47.798202, 3.573781));
mMapView.setZoomLevel(3);
mMapView.setCenterCoordinate(new LatLng(47.798202, 7.573781));
mMapView.setZoomLevel(4);
}

private MarkerOptions generateMarker(String title, double lat, double lng){
private MarkerOptions generateMarker(String title, double lat, double lng, String color) {
MarkerOptions marker = new MarkerOptions();
marker.title(title);
marker.snippet(title);
marker.snippet(color);
marker.position(new LatLng(lat, lng));
return marker;
}
Expand All @@ -103,7 +91,7 @@ protected void onStop() {

// Called when our app goes into the background
@Override
public void onPause() {
public void onPause() {
super.onPause();

mMapView.onPause();
Expand Down
Loading