diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2018-04-13 10:12:39 +0200 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2018-04-13 12:16:09 +0200 |
commit | 397ab623a2eaf83509681b1ffe8c5777961eab28 (patch) | |
tree | 4fa1f998807c5bf8dbf06a63632cfbbf495a8208 | |
parent | ff11cb20163caddf5e31ebdaeaafa0e1a9e456ec (diff) | |
download | qtlocation-mapboxgl-upstream/lp-fragment-freeze.tar.gz |
[android] - fragment freeze native setupupstream/lp-fragment-freeze
11 files changed, 225 insertions, 3 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java index 8aa4c7fd09..990d7d7e85 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java @@ -14,6 +14,8 @@ import com.mapbox.mapboxsdk.utils.MapFragmentUtils; import java.util.ArrayList; import java.util.List; +import timber.log.Timber; + /** * Support Fragment wrapper around a map view. * <p> @@ -136,6 +138,7 @@ public class SupportMapFragment extends Fragment implements OnMapReadyCallback { @Override public void onStop() { super.onStop(); + Timber.e("OnStop"); map.onStop(); } @@ -154,6 +157,7 @@ public class SupportMapFragment extends Fragment implements OnMapReadyCallback { @Override public void onDestroyView() { super.onDestroyView(); + Timber.e("OnDestroyView"); map.onDestroy(); mapReadyCallbackList.clear(); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/build.gradle b/platform/android/MapboxGLAndroidSDKTestApp/build.gradle index 30e989c79b..3a3628aa8b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/build.gradle +++ b/platform/android/MapboxGLAndroidSDKTestApp/build.gradle @@ -1,4 +1,6 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion androidVersions.compileSdkVersion @@ -54,6 +56,7 @@ android { dependencies { api(project(':MapboxGLAndroidSDK')) implementation dependenciesList.mapboxJavaServices + implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" implementation dependenciesList.mapboxJavaTurf @@ -72,11 +75,15 @@ dependencies { androidTestImplementation dependenciesList.testRules androidTestImplementation dependenciesList.testEspressoCore androidTestImplementation dependenciesList.testEspressoIntents + compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } apply from: "${rootDir}/gradle/gradle-make.gradle" apply from: "${rootDir}/gradle/gradle-config.gradle" apply from: "${rootDir}/gradle/gradle-checkstyle.gradle" apply from: "${rootDir}/gradle/gradle-lint.gradle" +repositories { + mavenCentral() +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 442635f909..82f18ca5d2 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -14,9 +14,8 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> <activity - android:name=".activity.FeatureOverviewActivity" - android:label="@string/app_name" - android:launchMode="singleTop"> + android:name="com.mapbox.mapboxsdk.testapp.mapboxfreezerepro.MainActivity" + android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> @@ -24,6 +23,11 @@ </intent-filter> </activity> <activity + android:name=".activity.FeatureOverviewActivity" + android:label="@string/app_name" + android:launchMode="singleTop"> + </activity> + <activity android:name=".activity.infowindow.InfoWindowActivity" android:description="@string/description_info_window" android:label="@string/activity_info_window"> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/MainActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/MainActivity.kt new file mode 100644 index 0000000000..03377e2fb4 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/MainActivity.kt @@ -0,0 +1,49 @@ +package com.mapbox.mapboxsdk.testapp.mapboxfreezerepro + +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import com.mapbox.mapboxsdk.testapp.R +import com.mapbox.mapboxsdk.testapp.mapboxfreezerepro.views.EmptyView +import com.mapbox.mapboxsdk.testapp.mapboxfreezerepro.views.MapView +import kotlinx.android.synthetic.main.activity_main.* +import timber.log.Timber + +class MainActivity : AppCompatActivity() { + + private var empty = true + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + fragmentContainer.addView(EmptyView(this)) + button.setOnClickListener { + Timber.e("removeAllViews") + + if (!empty) { + val fragment = supportFragmentManager.findFragmentByTag(com.mapbox.mapboxsdk.testapp.mapboxfreezerepro.views.TAG) + if (fragment != null) { + supportFragmentManager.beginTransaction() + .remove(fragment) + .commitNowAllowingStateLoss() + } + } + + fragmentContainer.removeAllViews() + if (empty) { + fragmentContainer.addView( + MapView( + this + ) + ) + empty = false + } else { + fragmentContainer.addView( + EmptyView( + this + ) + ) + empty = true + } + } + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/fragment/CustomMapFragment.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/fragment/CustomMapFragment.kt new file mode 100644 index 0000000000..4cf6fd7260 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/fragment/CustomMapFragment.kt @@ -0,0 +1,41 @@ +package com.mapbox.mapboxsdk.testapp.mapboxfreezerepro.fragment + +import android.os.Bundle +import android.view.View +import com.mapbox.mapboxsdk.maps.SupportMapFragment +import timber.log.Timber + +class CustomMapFragment : SupportMapFragment() { + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + getMapAsync { map -> + map.cameraPosition + with(map.uiSettings) { + isAttributionEnabled = false + isCompassEnabled = false + isLogoEnabled = false + isDeselectMarkersOnTap = false + isScrollGesturesEnabled = false + isZoomGesturesEnabled = false + isTiltGesturesEnabled = false + isRotateGesturesEnabled = false + isDoubleTapGesturesEnabled = false + } + } + } + + override fun onDestroy() { + super.onDestroy() + Timber.e("onDestroy") + } + + override fun onDestroyView() { + super.onDestroyView() + Timber.e("onDestroyView") + } + + override fun onStop() { + super.onStop() + Timber.e("onStop") + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/views/EmptyView.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/views/EmptyView.kt new file mode 100644 index 0000000000..d20b5334ea --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/views/EmptyView.kt @@ -0,0 +1,14 @@ +package com.mapbox.mapboxsdk.testapp.mapboxfreezerepro.views + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import android.widget.FrameLayout +import com.mapbox.mapboxsdk.testapp.R + +class EmptyView(context: Context, attributeSet: AttributeSet? = null) : FrameLayout(context, attributeSet) { + + init { + View.inflate(context, R.layout.empty_view, this) + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/views/MapView.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/views/MapView.kt new file mode 100644 index 0000000000..764de0937f --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/views/MapView.kt @@ -0,0 +1,44 @@ +package com.mapbox.mapboxsdk.testapp.mapboxfreezerepro.views + +import android.content.Context +import android.support.v4.app.FragmentManager +import android.support.v7.app.AppCompatActivity +import android.util.AttributeSet +import android.widget.FrameLayout +import android.view.View +import com.mapbox.mapboxsdk.testapp.R +import com.mapbox.mapboxsdk.testapp.mapboxfreezerepro.fragment.CustomMapFragment +import timber.log.Timber + +const val TAG = "tag" +class MapView(context: Context, + attrs: AttributeSet? = null) : FrameLayout(context, attrs) { + + private val fragmentManager: FragmentManager + + init { + fragmentManager = (context as AppCompatActivity).supportFragmentManager + View.inflate(context, R.layout.map_view, this) + } + + override fun onAttachedToWindow() { + super.onAttachedToWindow() + Timber.e("onAttachedToWindow") + val fragment = CustomMapFragment() + fragmentManager.beginTransaction() + .add( + R.id.mapContainer, fragment, + TAG + ) + .commit() + } + + override fun onDetachedFromWindow() { + super.onDetachedFromWindow() + Timber.e("onDetachedToWindow") +// val fragment = fragmentManager.findFragmentByTag(TAG) +// fragmentManager.beginTransaction() +// .remove(fragment) +// .commitNowAllowingStateLoss() + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000000..f7ddc7c0a5 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/container" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <FrameLayout + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <FrameLayout + android:id="@+id/fragmentContainer" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_marginStart="8dp"/> + + + <Button + android:id="@+id/button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Press Me" + android:layout_gravity="center_horizontal|bottom" + /> + + </FrameLayout> + +</RelativeLayout> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/empty_view.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/empty_view.xml new file mode 100644 index 0000000000..85bfb590a1 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/empty_view.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout + xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" + android:layout_height="match_parent"> + + + <TextView + android:id="@+id/infoText" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Info" + /> + +</RelativeLayout> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/map_view.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/map_view.xml new file mode 100644 index 0000000000..e9d04c0264 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/map_view.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<merge xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:mapbox="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <FrameLayout + android:id="@+id/mapContainer" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:clipChildren="false" + android:clipToPadding="false"/> + + +</merge> diff --git a/platform/android/build.gradle b/platform/android/build.gradle index 6cd9505447..9dbb9e3243 100644 --- a/platform/android/build.gradle +++ b/platform/android/build.gradle @@ -1,4 +1,5 @@ buildscript { + ext.kotlin_version = '1.2.31' repositories { jcenter() @@ -6,6 +7,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } |