Use android support lib fragments
This commit is contained in:
@@ -27,4 +27,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
compile project(':lib')
|
||||
compile 'com.android.support:support-annotations:21.0.0'
|
||||
compile 'com.android.support:support-v4:21.0.0'
|
||||
compile 'com.android.support:appcompat-v7:21.0.0'
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<activity
|
||||
android:name="com.mapbox.mapboxgl.app.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize">
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
package com.mapbox.mapboxgl.app;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mapbox.mapboxgl.lib.MapView;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
public class MainActivity extends ActionBarActivity {
|
||||
|
||||
//
|
||||
// Static members
|
||||
@@ -20,91 +15,20 @@ public class MainActivity extends Activity {
|
||||
// Tag used for logging
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
//
|
||||
// Instance members
|
||||
//
|
||||
|
||||
// The map
|
||||
private MapView mMapView;
|
||||
|
||||
//
|
||||
// Lifecycle events
|
||||
//
|
||||
|
||||
// Called when the activity is created
|
||||
// Called when activity is created
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.v(TAG, "onCreate");
|
||||
|
||||
// Show the app icon
|
||||
//getActionBar().setHomeButtonEnabled(true);
|
||||
|
||||
// Load the layout
|
||||
setContentView(R.layout.activity_main);
|
||||
mMapView = (MapView) findViewById(R.id.map);
|
||||
|
||||
// Load the API key
|
||||
mMapView.setAccessToken("pk.eyJ1IjoibGpiYWRlIiwiYSI6IlJSQ0FEZ2MifQ.7mE4aOegldh3595AG9dxpQ");
|
||||
|
||||
// Need to pass on any saved state to the map
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
// Called when the activity is destroyed
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.v(TAG, "onDestroy");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onDestroy();
|
||||
}
|
||||
|
||||
// Called when the activity is visible
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
Log.v(TAG, "onStart");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onStart();
|
||||
}
|
||||
|
||||
// Called when the activity is invisible
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
Log.v(TAG, "onStop");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onStop();
|
||||
}
|
||||
|
||||
// Called when the activity is in the background
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
Log.v(TAG, "onPause");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onPause();
|
||||
}
|
||||
|
||||
// Called when the activity is no longer in the background
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
Log.v(TAG, "onResume");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onResume();
|
||||
}
|
||||
|
||||
// Called before activity is destroyed
|
||||
@Override
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
Log.v(TAG, "onSaveInstanceState");
|
||||
|
||||
// Need to retrieve any saved state from the map
|
||||
mMapView.onSaveInstanceState(outState);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.mapbox.mapboxgl.app;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapbox.mapboxgl.lib.LonLat;
|
||||
import com.mapbox.mapboxgl.lib.MapView;
|
||||
|
||||
public class MapFragment extends Fragment {
|
||||
|
||||
//
|
||||
// Static members
|
||||
//
|
||||
|
||||
// Tag used for logging
|
||||
private static final String TAG = "MapFragment";
|
||||
|
||||
// The map
|
||||
private MapView mMapView;
|
||||
|
||||
//
|
||||
// Lifecycle events
|
||||
//
|
||||
|
||||
// Called when the fragment is created
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
Log.v(TAG, "onCreateView");
|
||||
|
||||
// Create the map
|
||||
mMapView = (MapView) inflater.inflate(R.layout.fragment_main, container, true);
|
||||
|
||||
// Load the API key
|
||||
mMapView.setAccessToken("pk.eyJ1IjoibGpiYWRlIiwiYSI6IlJSQ0FEZ2MifQ.7mE4aOegldh3595AG9dxpQ");
|
||||
|
||||
// Need to pass on any saved state to the map
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
|
||||
// Return the map as the root view
|
||||
return mMapView;
|
||||
}
|
||||
|
||||
// Called when the fragment is destroyed
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
Log.v(TAG, "onDestroyView");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onDestroy();
|
||||
mMapView = null;
|
||||
}
|
||||
|
||||
// Called when the fragment is visible
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Log.v(TAG, "onStart");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onStart();
|
||||
}
|
||||
|
||||
// Called when the fragment is invisible
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
Log.v(TAG, "onStop");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onStop();
|
||||
}
|
||||
|
||||
// Called when the fragment is in the background
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
Log.v(TAG, "onPause");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onPause();
|
||||
}
|
||||
|
||||
// Called when the fragment is no longer in the background
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Log.v(TAG, "onResume");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onResume();
|
||||
}
|
||||
|
||||
// Called before fragment is destroyed
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
Log.v(TAG, "onSaveInstanceState");
|
||||
|
||||
// Need to retrieve any saved state from the map
|
||||
mMapView.onSaveInstanceState(outState);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
//
|
||||
// Property methods
|
||||
//
|
||||
|
||||
public MapView getMapView() {
|
||||
return mMapView;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,7 @@
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context="${packageName}.${activityClass}">
|
||||
|
||||
<view
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
class="com.mapbox.mapboxgl.lib.MapView"
|
||||
android:id="@+id/map"
|
||||
app:styleUrl="asset://styles/styles/bright-v6.json"/>
|
||||
|
||||
</merge>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="${packageName}.${activityClass}"
|
||||
android:name="com.mapbox.mapboxgl.app.MapFragment"
|
||||
android:id="@+id/map_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
6
android/java/app/src/main/res/layout/fragment_main.xml
Normal file
6
android/java/app/src/main/res/layout/fragment_main.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.mapbox.mapboxgl.lib.MapView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/map"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:styleUrl="asset://styles/styles/bright-v6.json" />
|
||||
@@ -1,11 +0,0 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 11+. This theme completely replaces
|
||||
AppBaseTheme from res/values/styles.xml on API 11+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
|
||||
<!-- API 11 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -1,12 +0,0 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 14+. This theme completely replaces
|
||||
AppBaseTheme from BOTH res/values/styles.xml and
|
||||
res/values-v11/styles.xml on API 14+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
|
||||
<!-- API 14 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -4,7 +4,7 @@
|
||||
Base application theme, dependent on API level. This theme is replaced
|
||||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Light">
|
||||
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
|
||||
<!--
|
||||
Theme customizations available in newer API levels can go in
|
||||
res/values-vXX/styles.xml, while customizations related to
|
||||
|
||||
@@ -32,4 +32,5 @@ android {
|
||||
dependencies {
|
||||
compile 'commons-io:commons-io:2.4'
|
||||
compile 'com.android.support:support-annotations:21.0.0'
|
||||
compile 'com.android.support:support-v4:21.0.0'
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mapbox.mapboxgl.lib;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
Reference in New Issue
Block a user