├── mapviewpager ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ └── attrs.xml │ │ └── layout │ │ │ ├── mapviewpager_top.xml │ │ │ ├── mapviewpager_bottom.xml │ │ │ ├── mapviewpager_left.xml │ │ │ └── mapviewpager_right.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── github │ │ └── nitrico │ │ └── mapviewpager │ │ └── MapViewPager.java ├── proguard-rules.pro ├── install.gradle ├── bintray.gradle └── build.gradle ├── settings.gradle ├── sample ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── bools.xml │ │ │ ├── integers.xml │ │ │ ├── colors.xml │ │ │ ├── styles.xml │ │ │ └── strings.xml │ │ ├── values-land │ │ │ ├── bools.xml │ │ │ └── integers.xml │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ ├── menu │ │ │ ├── main.xml │ │ │ └── fragment.xml │ │ ├── drawable │ │ │ ├── ic_close.xml │ │ │ ├── ic_close_dark.xml │ │ │ └── ic_github.xml │ │ └── layout │ │ │ ├── activity_sample_1.xml │ │ │ ├── activity_sample_2.xml │ │ │ ├── fragment_sample_1.xml │ │ │ ├── fragment_sample_2.xml │ │ │ └── activity_main.xml │ │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── nitrico │ │ │ └── mvp │ │ │ ├── sample1 │ │ │ ├── Sample1Fragment.java │ │ │ ├── Sample1Activity.java │ │ │ └── Sample1Adapter.java │ │ │ ├── sample2 │ │ │ ├── Sample2Activity.java │ │ │ ├── Sample2Fragment.java │ │ │ └── Sample2Adapter.java │ │ │ ├── MainActivity.java │ │ │ └── Utils.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── MapViewPager.apk ├── screenshot1.png ├── screenshot2.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── CHANGELOG.md ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── gradlew ├── README.md └── LICENSE.txt /mapviewpager/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':mapviewpager' 2 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /src/main/res/values/keys.xml 3 | -------------------------------------------------------------------------------- /MapViewPager.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nitrico/MapViewPager/HEAD/MapViewPager.apk -------------------------------------------------------------------------------- /screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nitrico/MapViewPager/HEAD/screenshot1.png -------------------------------------------------------------------------------- /screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nitrico/MapViewPager/HEAD/screenshot2.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nitrico/MapViewPager/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sample/src/main/res/values/bools.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | true 4 | 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values-land/bools.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | false 4 | 5 | 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | 4 | Version 1.0.0 (2016-01-30) 5 | -------------------------- 6 | Initial release 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values-land/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0 4 | 5 | 6 | -------------------------------------------------------------------------------- /mapviewpager/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | MapViewPager 4 | 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nitrico/MapViewPager/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nitrico/MapViewPager/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nitrico/MapViewPager/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nitrico/MapViewPager/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nitrico/MapViewPager/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .idea 3 | .gradle 4 | /local.properties 5 | /.idea/workspace.xml 6 | /.idea/libraries 7 | .DS_Store 8 | /build 9 | /captures 10 | /app/src/main/res/values/keys.xml 11 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #607D8B 4 | #455A64 5 | #FF5252 6 | 7 | 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /mapviewpager/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_close.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_close_dark.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/fragment.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 9 | 10 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /mapviewpager/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_sample_1.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\nitrico\Android\SDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /mapviewpager/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\nitrico\Android\SDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.github.nitrico.mvp" 9 | minSdkVersion 14 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile project(':mapviewpager') 24 | compile 'com.android.support:appcompat-v7:23.1.1' 25 | compile 'com.android.support:cardview-v7:23.1.1' 26 | compile 'com.google.android.gms:play-services-maps:8.4.0' 27 | } 28 | -------------------------------------------------------------------------------- /mapviewpager/src/main/res/layout/mapviewpager_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 13 | 14 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /mapviewpager/src/main/res/layout/mapviewpager_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 13 | 14 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /mapviewpager/src/main/res/layout/mapviewpager_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 13 | 14 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /mapviewpager/src/main/res/layout/mapviewpager_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 13 | 14 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_github.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | MapViewPager 4 | Miguel Ángel Moreno 5 | https://github.com/nitrico/mapviewpager 6 | 7 | GitHub project 8 | Share 9 | 10 | Sample 1 11 | Sample 2 12 | 13 | 14 | 15 | 16 | Item 1 17 | Item 2 18 | 19 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 20 | 21 | 22 | -------------------------------------------------------------------------------- /mapviewpager/install.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.github.dcendents.android-maven' 2 | 3 | group = mavenGroupId 4 | 5 | install { 6 | repositories.mavenInstaller { 7 | // This generates POM.xml with proper parameters 8 | pom { 9 | project { 10 | packaging 'aar' 11 | groupId mavenGroupId 12 | artifactId artifact 13 | 14 | // Add your description here 15 | name libraryName 16 | description libraryDescription 17 | url siteUrl 18 | 19 | // Set your license 20 | licenses { 21 | license { 22 | name licenseName 23 | url licenseUrl 24 | } 25 | } 26 | developers { 27 | developer { 28 | id developerId 29 | name developerName 30 | email developerEmail 31 | } 32 | } 33 | scm { 34 | connection gitUrl 35 | developerConnection gitUrl 36 | url siteUrl 37 | 38 | } 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mapviewpager/bintray.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.jfrog.bintray' 2 | 3 | version = libraryVersion 4 | 5 | task sourcesJar(type: Jar) { 6 | from android.sourceSets.main.java.srcDirs 7 | classifier = 'sources' 8 | } 9 | 10 | /*task javadoc(type: Javadoc) { 11 | source = android.sourceSets.main.java.srcDirs 12 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 13 | } 14 | 15 | task javadocJar(type: Jar, dependsOn: javadoc) { 16 | from javadoc.destinationDir 17 | classifier = 'javadoc' 18 | }*/ 19 | 20 | artifacts { 21 | //archives javadocJar 22 | archives sourcesJar 23 | } 24 | 25 | Properties properties = new Properties() 26 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 27 | 28 | bintray { 29 | user = properties.getProperty('bintray.user') 30 | key = properties.getProperty('bintray.key') 31 | configurations = ['archives'] 32 | pkg { 33 | repo = bintrayRepo 34 | name = bintrayName 35 | desc = libraryDescription 36 | websiteUrl = siteUrl 37 | vcsUrl = gitUrl 38 | licenses = allLicenses 39 | publish = true 40 | publicDownloadNumbers = true 41 | version { 42 | desc = libraryDescription 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_sample_2.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | 16 | 17 | 21 | 22 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /mapviewpager/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | ext { 4 | libraryName = 'mapviewpager' 5 | libraryVersion = '1.0.0' 6 | libraryDescription = 'Android library that connects ViewPager fragments with Google Maps markers.' 7 | 8 | mavenGroupId = 'com.github.nitrico.mapviewpager' 9 | artifact = libraryName 10 | 11 | siteUrl = 'https://github.com/nitrico/mapviewpager' 12 | gitUrl = 'https://github.com/nitrico/mapviewpager.git' 13 | 14 | bintrayRepo = 'maven' 15 | bintrayName = libraryName 16 | 17 | developerId = 'moreno' 18 | developerName = 'Miguel Ángel Moreno' 19 | developerEmail = 'nitrico@gmail.com' 20 | 21 | licenseName = 'The Apache Software License, Version 2.0' 22 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 23 | allLicenses = ["Apache-2.0"] 24 | } 25 | 26 | android { 27 | compileSdkVersion 23 28 | buildToolsVersion "23.0.2" 29 | 30 | defaultConfig { 31 | minSdkVersion 9 32 | targetSdkVersion 23 33 | versionCode 1 34 | versionName '1.0.0' 35 | } 36 | buildTypes { 37 | release { 38 | minifyEnabled false 39 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 40 | } 41 | } 42 | } 43 | 44 | dependencies { 45 | compile 'com.android.support:appcompat-v7:23.1.1' 46 | compile 'com.google.android.gms:play-services-maps:8.4.0' 47 | } 48 | 49 | apply from: 'install.gradle' 50 | apply from: 'bintray.gradle' 51 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/fragment_sample_1.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 12 | 13 | 23 | 24 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/nitrico/mvp/sample1/Sample1Fragment.java: -------------------------------------------------------------------------------- 1 | package com.github.nitrico.mvp.sample1; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | import com.github.nitrico.mvp.R; 10 | 11 | public class Sample1Fragment extends android.support.v4.app.Fragment { 12 | 13 | private TextView title; 14 | private int index; 15 | 16 | public Sample1Fragment() { } 17 | 18 | public static Sample1Fragment newInstance(int i) { 19 | Sample1Fragment f = new Sample1Fragment(); 20 | Bundle args = new Bundle(); 21 | args.putInt("INDEX", i); 22 | f.setArguments(args); 23 | return f; 24 | } 25 | 26 | @Nullable 27 | @Override 28 | public View onCreateView(LayoutInflater inflater, 29 | @Nullable ViewGroup container, 30 | @Nullable Bundle savedInstanceState) { 31 | View view = inflater.inflate(R.layout.fragment_sample_1, container, false); 32 | title = (TextView) view.findViewById(R.id.title); 33 | return view; 34 | } 35 | 36 | @Override 37 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 38 | super.onActivityCreated(savedInstanceState); 39 | Bundle args = getArguments(); 40 | if (args != null) index = args.getInt("INDEX", 0); 41 | 42 | title.setText(Sample1Adapter.TITLES[index]); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/nitrico/mvp/sample1/Sample1Activity.java: -------------------------------------------------------------------------------- 1 | package com.github.nitrico.mvp.sample1; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import com.github.nitrico.mapviewpager.MapViewPager; 7 | import com.github.nitrico.mvp.R; 8 | 9 | public class Sample1Activity extends AppCompatActivity implements MapViewPager.Callback { 10 | 11 | private MapViewPager mapViewPager; 12 | 13 | @Override 14 | protected void onCreate(@Nullable Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_sample_1); 17 | mapViewPager = (MapViewPager) findViewById(R.id.mapViewPager); 18 | 19 | Sample1Adapter adapter = new Sample1Adapter(getSupportFragmentManager()); 20 | mapViewPager.start(this, adapter, this); 21 | } 22 | 23 | @Override 24 | public void onMapViewPagerReady() { 25 | /*mapViewPager.getMarker(1) 26 | .setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)); 27 | mapViewPager.getViewPager().addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { 28 | @Override 29 | public void onPageSelected(int position) { 30 | for (int i=0; i 10 | 11 | 22 | 23 | 27 | 28 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/nitrico/mvp/sample2/Sample2Activity.java: -------------------------------------------------------------------------------- 1 | package com.github.nitrico.mvp.sample2; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.view.ViewPager; 6 | import android.support.v7.app.AppCompatActivity; 7 | import com.github.nitrico.mapviewpager.MapViewPager; 8 | import com.github.nitrico.mvp.R; 9 | import com.github.nitrico.mvp.Utils; 10 | import com.google.android.gms.maps.SupportMapFragment; 11 | 12 | public class Sample2Activity extends AppCompatActivity implements MapViewPager.Callback { 13 | 14 | private ViewPager viewPager; 15 | private MapViewPager mvp; 16 | 17 | @Override 18 | protected void onCreate(@Nullable Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_sample_2); 21 | 22 | SupportMapFragment map = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); 23 | viewPager = (ViewPager) findViewById(R.id.viewPager); 24 | viewPager.setPageMargin(Utils.dp(this, 18)); 25 | Utils.setMargins(viewPager, 0, 0, 0, Utils.getNavigationBarHeight(this)); 26 | 27 | mvp = new MapViewPager.Builder(this) 28 | .mapFragment(map) 29 | .viewPager(viewPager) 30 | .position(2) 31 | .adapter(new Sample2Adapter(getSupportFragmentManager())) 32 | .callback(this) 33 | .build(); 34 | } 35 | 36 | @Override 37 | public void onMapViewPagerReady() { 38 | mvp.getMap().setPadding( 39 | 0, 40 | Utils.dp(this, 40), 41 | Utils.getNavigationBarWidth(this), 42 | viewPager.getHeight() + Utils.getNavigationBarHeight(this)); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 9 | 12 | 13 | 14 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 37 | 38 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/nitrico/mvp/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.nitrico.mvp; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.Menu; 8 | import android.view.MenuItem; 9 | import android.view.View; 10 | import com.github.nitrico.mvp.sample1.Sample1Activity; 11 | import com.github.nitrico.mvp.sample2.Sample2Activity; 12 | 13 | public class MainActivity extends AppCompatActivity { 14 | 15 | public static final String URL = "https://github.com/nitrico/mapviewpager"; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main); 21 | 22 | findViewById(R.id.card1).setOnClickListener(new View.OnClickListener() { 23 | @Override 24 | public void onClick(View v) { 25 | startActivity(new Intent(MainActivity.this, Sample1Activity.class)); 26 | } 27 | }); 28 | 29 | findViewById(R.id.card2).setOnClickListener(new View.OnClickListener() { 30 | @Override 31 | public void onClick(View v) { 32 | startActivity(new Intent(MainActivity.this, Sample2Activity.class)); 33 | } 34 | }); 35 | 36 | } 37 | 38 | @Override 39 | public boolean onCreateOptionsMenu(Menu menu) { 40 | getMenuInflater().inflate(R.menu.main, menu); 41 | return super.onCreateOptionsMenu(menu); 42 | } 43 | 44 | @Override 45 | public boolean onOptionsItemSelected(MenuItem item) { 46 | switch (item.getItemId()) { 47 | case R.id.github: 48 | Intent intent = new Intent(Intent.ACTION_VIEW); 49 | intent.setData(Uri.parse(URL)); 50 | startActivity(intent); 51 | return true; 52 | } 53 | return super.onOptionsItemSelected(item); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/nitrico/mvp/sample2/Sample2Fragment.java: -------------------------------------------------------------------------------- 1 | package com.github.nitrico.mvp.sample2; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v4.view.ViewCompat; 7 | import android.support.v7.widget.Toolbar; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import com.github.nitrico.mvp.R; 12 | 13 | public class Sample2Fragment extends Fragment { 14 | 15 | private Toolbar toolbar; 16 | private int index; 17 | 18 | public Sample2Fragment() { } 19 | 20 | public static Sample2Fragment newInstance(int i) { 21 | Sample2Fragment f = new Sample2Fragment(); 22 | Bundle args = new Bundle(); 23 | args.putInt("INDEX", i); 24 | f.setArguments(args); 25 | return f; 26 | } 27 | 28 | @Nullable 29 | @Override 30 | public View onCreateView(LayoutInflater inflater, 31 | @Nullable ViewGroup container, 32 | @Nullable Bundle savedInstanceState) { 33 | View view = inflater.inflate(R.layout.fragment_sample_2, container, false); 34 | toolbar = (Toolbar) view.findViewById(R.id.toolbar); 35 | return view; 36 | } 37 | 38 | @Override 39 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 40 | super.onActivityCreated(savedInstanceState); 41 | Bundle args = getArguments(); 42 | if (args != null) index = args.getInt("INDEX", 0); 43 | 44 | ViewCompat.setElevation(getView(), 10f); 45 | ViewCompat.setElevation(toolbar, 4f); 46 | 47 | toolbar.setTitle(Sample2Adapter.PAGE_TITLES[index]); 48 | toolbar.inflateMenu(R.menu.fragment); 49 | toolbar.setNavigationOnClickListener(new View.OnClickListener() { 50 | @Override 51 | public void onClick(View v) { 52 | getActivity().onBackPressed(); 53 | } 54 | }); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/nitrico/mvp/Utils.java: -------------------------------------------------------------------------------- 1 | package com.github.nitrico.mvp; 2 | 3 | import android.content.Context; 4 | import android.content.res.Configuration; 5 | import android.content.res.Resources; 6 | import android.os.Build; 7 | import android.util.DisplayMetrics; 8 | import android.util.TypedValue; 9 | import android.view.View; 10 | import android.view.ViewConfiguration; 11 | import android.view.ViewGroup; 12 | 13 | public class Utils { 14 | 15 | public static boolean isPortrait(Context context) { 16 | Configuration config = context.getResources().getConfiguration(); 17 | return config.orientation == Configuration.ORIENTATION_PORTRAIT; 18 | } 19 | 20 | public static int dp(Context context, int dp) { 21 | DisplayMetrics dm = context.getResources().getDisplayMetrics(); 22 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, dm); 23 | } 24 | 25 | public static void setMargins(View view, int left, int top, int right, int bottom) { 26 | if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { 27 | ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); 28 | params.setMargins(left, top, right, bottom); 29 | view.requestLayout(); 30 | } 31 | } 32 | 33 | public static boolean hasNavigationBar(Context context) { 34 | if (Build.VERSION.SDK_INT < 19) return false; // could have but won't be translucent 35 | return !ViewConfiguration.get(context).hasPermanentMenuKey(); 36 | } 37 | 38 | public static int getNavigationBarHeight(Context context) { 39 | if (!hasNavigationBar(context)) return 0; 40 | Resources r = context.getResources(); 41 | DisplayMetrics dm = r.getDisplayMetrics(); 42 | Configuration config = r.getConfiguration(); 43 | boolean canMove = dm.widthPixels != dm.heightPixels && config.smallestScreenWidthDp < 600; 44 | if (canMove && config.orientation == Configuration.ORIENTATION_LANDSCAPE) return 0; 45 | String s = isPortrait(context) ? "navigation_bar_height" : "navigation_bar_height_landscape"; 46 | int id = r.getIdentifier(s, "dimen", "android"); 47 | if (id > 0) return r.getDimensionPixelSize(id); 48 | return 0; 49 | } 50 | 51 | public static int getNavigationBarWidth(Context context) { 52 | if (!hasNavigationBar(context)) return 0; 53 | Resources r = context.getResources(); 54 | DisplayMetrics dm = r.getDisplayMetrics(); 55 | Configuration config = r.getConfiguration(); 56 | boolean canMove = dm.widthPixels != dm.heightPixels && config.smallestScreenWidthDp < 600; 57 | if (canMove && config.orientation == Configuration.ORIENTATION_LANDSCAPE) { 58 | int id = r.getIdentifier("navigation_bar_width", "dimen", "android"); 59 | if (id > 0) return r.getDimensionPixelSize(id); 60 | } 61 | return 0; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/nitrico/mvp/sample2/Sample2Adapter.java: -------------------------------------------------------------------------------- 1 | package com.github.nitrico.mvp.sample2; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import com.github.nitrico.mapviewpager.MapViewPager; 6 | import com.google.android.gms.maps.model.CameraPosition; 7 | import com.google.android.gms.maps.model.LatLng; 8 | import java.util.LinkedList; 9 | import java.util.List; 10 | 11 | public class Sample2Adapter extends MapViewPager.MultiAdapter { 12 | 13 | public static final String[] PAGE_TITLES = { "England", "France", "Spain", 14 | "Portugal", "Italy", "Belgium" }; 15 | 16 | public static final String[] ENGLAND_TITLES = { "London" }; 17 | public static final String[] FRANCE_TITLES = { "Paris" }; 18 | public static final String[] SPAIN_TITLES = { "Barcelona", "Madrid", "Valencia" }; 19 | public static final String[] PORTUGAL_TITLES = { }; 20 | public static final String[] ITALY_TITLES = { "Milan", "Rome" }; 21 | public static final String[] BELGIUM_TITLES = { "Brussels" }; 22 | 23 | public static final CameraPosition LONDON 24 | = CameraPosition.fromLatLngZoom(new LatLng(51.5287352,-0.381784), 6f); 25 | public static final CameraPosition PARIS 26 | = CameraPosition.fromLatLngZoom(new LatLng(48.859,2.2074722), 6f); 27 | public static final CameraPosition BARCELONA 28 | = CameraPosition.fromLatLngZoom(new LatLng(41.3948976,2.0787274), 6f); 29 | public static final CameraPosition MADRID 30 | = CameraPosition.fromLatLngZoom(new LatLng(40.4381311,-3.8196227), 6f); 31 | public static final CameraPosition VALENCIA 32 | = CameraPosition.fromLatLngZoom(new LatLng(39.4079665,-0.5015975), 6f); 33 | public static final CameraPosition MILAN 34 | = CameraPosition.fromLatLngZoom(new LatLng(45.4628329,9.107692), 6f); 35 | public static final CameraPosition ROME 36 | = CameraPosition.fromLatLngZoom(new LatLng(41.9102415,12.3959121), 6f); 37 | public static final CameraPosition BRUSSELS 38 | = CameraPosition.fromLatLngZoom(new LatLng(50.8550625,4.3053499), 6f); 39 | 40 | private LinkedList england; 41 | private LinkedList france; 42 | private LinkedList spain; 43 | private LinkedList portugal; 44 | private LinkedList italy; 45 | private LinkedList belgium; 46 | 47 | public Sample2Adapter(FragmentManager fm) { 48 | super(fm); 49 | 50 | // camera positions 51 | england = new LinkedList<>(); 52 | france = new LinkedList<>(); 53 | spain = new LinkedList<>(); 54 | portugal = new LinkedList<>(); 55 | italy = new LinkedList<>(); 56 | belgium = new LinkedList<>(); 57 | 58 | england.add(LONDON); 59 | france.add(PARIS); 60 | spain.add(BARCELONA); 61 | spain.add(MADRID); 62 | spain.add(VALENCIA); 63 | italy.add(MILAN); 64 | italy.add(ROME); 65 | belgium.add(BRUSSELS); 66 | } 67 | 68 | @Override 69 | public int getCount() { 70 | return PAGE_TITLES.length; 71 | } 72 | 73 | @Override 74 | public Fragment getItem(int position) { 75 | return Sample2Fragment.newInstance(position); 76 | } 77 | 78 | @Override 79 | public CharSequence getPageTitle(int position) { 80 | return PAGE_TITLES[position]; 81 | } 82 | 83 | @Override 84 | public String getMarkerTitle(int page, int position) { 85 | switch (page) { 86 | case 0: return ENGLAND_TITLES[position]; 87 | case 1: return FRANCE_TITLES[position]; 88 | case 2: return SPAIN_TITLES[position]; 89 | case 3: return PORTUGAL_TITLES[position]; 90 | case 4: return ITALY_TITLES[position]; 91 | case 5: return BELGIUM_TITLES[position]; 92 | } 93 | return null; 94 | } 95 | 96 | @Override 97 | public List getCameraPositions(int page) { 98 | switch (page) { 99 | case 0: return england; 100 | case 1: return france; 101 | case 2: return spain; 102 | case 3: return portugal; 103 | case 4: return italy; 104 | case 5: return belgium; 105 | } 106 | return null; 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 14 | 15 | 25 | 30 | 36 | 43 | 44 | 45 | 46 | 56 | 61 | 67 | 74 | 75 | 76 | 77 | 84 | 93 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Download](https://api.bintray.com/packages/moreno/maven/mapviewpager/images/download.svg)](https://bintray.com/moreno/maven/mapviewpager/_latestVersion) 2 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-MapViewPager-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/3087) 3 | [![License](https://img.shields.io/:License-Apache-orange.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) 4 | 5 | # MapViewPager 6 | 7 | Android library that connects ViewPager fragments with Google Maps markers. 8 | 9 | ![screenshot](https://raw.githubusercontent.com/nitrico/mapviewpager/master/screenshot1.png) 10 | ![screenshot](https://raw.githubusercontent.com/nitrico/mapviewpager/master/screenshot2.png) 11 | 12 | Check out the **[sample apk](https://github.com/nitrico/mapviewpager/raw/master/MapViewPager.apk)** ! 13 | 14 | #### Notice 15 | * **Not fully tested yet**, but it works perfectly on my Nexus 5 running Marshmallow. 16 | * Only `android.support.v4.app.Fragment` and `SupportMapFragment` supported right now. 17 | * It is my first Android lib. Tips, suggestions and requests are all welcome. 18 | 19 | 20 | ## Features 21 | 22 | * Supports any amount of markers per fragment. 23 | * Default camera position (for fragments with 0 or *more than 1* markers) automatically calculated. 24 | 25 | 26 | ## Download 27 | 28 | #### Gradle 29 | 30 | ```gradle 31 | dependencies { 32 | compile 'com.android.support:appcompat-v7:23.1.1' 33 | compile 'com.google.android.gms:play-services-maps:8.4.0' 34 | compile 'com.github.nitrico.mapviewpager:mapviewpager:1.0.0' 35 | } 36 | ``` 37 | 38 | 39 | ## Usage 40 | 41 | > Don't forget to add the right **permissions** and your Google Maps **API key** to your `AndroidManifest.xml` file. 42 | 43 | Create a ViewPager adapter extending from **MapViewPager.Adapter** or **MapViewPager.MultiAdapter** and override method 44 | `CameraPosition getCameraPosition(int position)` or `List getCameraPositions(int position)` returning the markers camera position for each fragment. 45 | 46 | > To create a CameraPosition: `CameraPosition.fromLatLngZoom(new LatLng(latitude, longitude), zoom);` 47 | 48 | Include the view in your xml layout 49 | ```xml 50 | 58 | ``` 59 | 60 | Find the view in your activity and then call `mapViewPager.start(this, adapter)` or `mapViewPager.start(this, adapter, callback)` passing the AppCompatActivity (or FragmentActivity) and MapViewPager.Adapter (or MapViewPager.MultiAdapter) instances. You can also pass a **MapViewPager.Callback** instance to get notified when the GoogleMap object is created and working. 61 | 62 | #### Builder 63 | 64 | If you want more control on how to display the map and the ViewPager, for example to overlap each other, you can add a `` and a `` to your activity layout and then and pass them to create the MapViewPager object using the **MapViewPager.Builder** class: 65 | 66 | ```java 67 | MapViewPager mvp = new MapViewPager.Builder(this) // this is Context 68 | .mapFragment(mapFragment) // mapFragment is SupportMapFragment 69 | .viewPager(viewPager) // viewPager is ViewPager 70 | .adapter(adapter) // adapter is MapViewPager.Adapter or MapViewPager.MultiAdapter 71 | .position(initialPosition) // Optional initialPosition is int 72 | .callback(callback) // Optional callback is MapViewPager.Callback 73 | .markersAlpha(alpha) // Optional 74 | .mapPadding(left, top, right, bottom) // Optional 75 | .mapOffset(offset) // Optional 76 | .build(); 77 | ``` 78 | 79 | > Remember that mapFragment is a Fragment, not a View! To find it: `mapFragment = (SupportMapFragment) activity.getSupportFragmentManager().findFragmentById(R.id.mapFragment);` 80 | 81 | Check the examples in the [sample folder](https://github.com/nitrico/mapviewpager/tree/master/sample). 82 | 83 | 84 | ## Documentation 85 | 86 | #### XML attributes 87 | 88 | They are all optional. 89 | 90 | |Attribute|Format|Default|Description| 91 | |---|---|---|---| 92 | |viewPagerWeight|integer|`1`|Weight of the viewpager in the layout| 93 | |mapWeight|integer|`1`|Weight of the map in the layout| 94 | |mapGravity|integer (0..3)|`1`|Position of the map in the layout: 0=left, 1=top, 2=right, 3=bottom| 95 | |mapOffset|dimension|`32dp`|Map *padding* for multiple markers on the map| 96 | |mapPaddingLeft|dimension|`0dp`|Left map padding| 97 | |mapPaddingTop|dimension|`0dp`|Top map padding| 98 | |mapPaddingRight|dimension|`0dp`|Right map padding| 99 | |mapPaddingBottom|dimension|`0dp`|Bottom map padding| 100 | |markersAlpha|float (0..1)|`0.4`|Opacity of markers when deactivated| 101 | 102 | #### Public methods 103 | 104 | ```java 105 | void start(@NonNull FragmentActivity activity, 106 | @NonNull MapViewPager.AbsAdapter mapAdapter) 107 | void start(@NonNull FragmentActivity activity, 108 | @NonNull MapViewPager.AbsAdapter mapAdapter, 109 | @Nullable MapViewPager.Callback callback) 110 | void start(@NonNull FragmentActivity activity, 111 | @NonNull MapViewPager.AbsAdapter mapAdapter, 112 | int initialPosition) 113 | void start(@NonNull FragmentActivity activity, 114 | @NonNull MapViewPager.AbsAdapter mapAdapter, 115 | int initialPosition, 116 | @Nullable MapViewPager.Callback callback) 117 | 118 | GoogleMap getMap() 119 | SupportMapFragment getMapFragment() 120 | ViewPager getViewPager() 121 | CameraUpdate getDefaultPosition() 122 | 123 | // when adapter extends MapViewPager.Adapter 124 | Marker getMarker(int position) 125 | List getMarkers() 126 | 127 | // when adapter extends MapViewPager.MultiAdapter 128 | Marker getMarker(int page, int position) 129 | List getMarkers(int page) 130 | List> getAllMarkers() 131 | CameraUpdate getDefaultPosition(int page) 132 | List getDefaultPositions() 133 | ``` 134 | **Warning!** In order to avoid `NullPointerException`s when calling any of those getters before the actual GoogleMap object is created, you should use them _only after_ `onMapViewPagerReady()` method in the callback is called. 135 | 136 | To override in **MapViewPager.Callback** effective classes 137 | ```java 138 | void onMapViewPagerReady() 139 | ``` 140 | 141 | To override in **MapViewPager.Adapter** effective classes 142 | ```java 143 | CameraPosition getCameraPosition(int position) 144 | ``` 145 | 146 | To override in **MapViewPager.MultiAdapter** effective classes 147 | ```java 148 | List getCameraPositions(int page) 149 | String getMarkerTitle(int page, int position) 150 | ``` 151 | Both adapters extends from `FragmentStatePagerAdapter`, so you also need to override 152 | ```java 153 | CharSequence getPageTitle(int position) // this will be used as marker title in MapViewPager.Adapter 154 | Fragment getItem(int position) 155 | int getCount() 156 | ``` 157 | 158 | ## Author 159 | 160 | ##### Miguel Ángel Moreno 161 | 162 | I'm available to be hired, Contact me! 163 | 164 | |[Email](mailto:nitrico@gmail.com)|[Facebook](https://www.facebook.com/miguelangelmoreno)|[Google+](https://plus.google.com/+Miguel%C3%81ngelMorenoS)|[Linked.in](https://www.linkedin.com/in/morenomiguelangel)|[Twitter](https://twitter.com/nitrico/) 165 | |---|---|---|---|---| 166 | 167 | 168 | ## License 169 | ```txt 170 | Copyright 2016 Miguel Ángel Moreno 171 | 172 | Licensed under the Apache License, Version 2.0 (the "License"); 173 | you may not use this file except in compliance with the License. 174 | You may obtain a copy of the License at 175 | 176 | http://www.apache.org/licenses/LICENSE-2.0 177 | 178 | Unless required by applicable law or agreed to in writing, software 179 | distributed under the License is distributed on an "AS IS" BASIS, 180 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 181 | See the License for the specific language governing permissions and 182 | limitations under the License. 183 | ``` 184 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /mapviewpager/src/main/java/com/github/nitrico/mapviewpager/MapViewPager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Miguel Ángel Moreno 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.nitrico.mapviewpager; 18 | 19 | import android.content.Context; 20 | import android.content.res.TypedArray; 21 | import android.support.annotation.NonNull; 22 | import android.support.annotation.Nullable; 23 | import android.support.v4.app.FragmentActivity; 24 | import android.support.v4.app.FragmentManager; 25 | import android.support.v4.app.FragmentStatePagerAdapter; 26 | import android.support.v4.view.ViewPager; 27 | import android.util.AttributeSet; 28 | import android.util.DisplayMetrics; 29 | import android.util.TypedValue; 30 | import android.view.LayoutInflater; 31 | import android.view.View; 32 | import android.widget.FrameLayout; 33 | import android.widget.LinearLayout; 34 | import com.google.android.gms.maps.CameraUpdate; 35 | import com.google.android.gms.maps.CameraUpdateFactory; 36 | import com.google.android.gms.maps.GoogleMap; 37 | import com.google.android.gms.maps.OnMapReadyCallback; 38 | import com.google.android.gms.maps.SupportMapFragment; 39 | import com.google.android.gms.maps.model.BitmapDescriptorFactory; 40 | import com.google.android.gms.maps.model.CameraPosition; 41 | import com.google.android.gms.maps.model.LatLng; 42 | import com.google.android.gms.maps.model.LatLngBounds; 43 | import com.google.android.gms.maps.model.Marker; 44 | import com.google.android.gms.maps.model.MarkerOptions; 45 | import java.util.LinkedList; 46 | import java.util.List; 47 | 48 | public class MapViewPager extends FrameLayout implements OnMapReadyCallback { 49 | 50 | public interface Callback { 51 | void onMapViewPagerReady(); 52 | } 53 | 54 | public static abstract class AbsAdapter extends FragmentStatePagerAdapter { 55 | public AbsAdapter(FragmentManager fm) { 56 | super(fm); 57 | } 58 | } 59 | 60 | public static abstract class Adapter extends AbsAdapter { 61 | public Adapter(FragmentManager fm) { 62 | super(fm); 63 | } 64 | public abstract CameraPosition getCameraPosition(int position); 65 | } 66 | 67 | public static abstract class MultiAdapter extends AbsAdapter { 68 | public MultiAdapter(FragmentManager fm) { 69 | super(fm); 70 | } 71 | public abstract List getCameraPositions(int page); 72 | public abstract String getMarkerTitle(int page, int position); 73 | } 74 | 75 | 76 | private static final float DEFAULT_ALPHA = 0.4f; 77 | private float markersAlpha = DEFAULT_ALPHA; 78 | private int mapGravity = 1; 79 | private int mapWeight = 1, pagerWeight = 1; 80 | private int mapPaddingLeft, mapPaddingTop, mapPaddingRight, mapPaddingBottom; 81 | private int mapOffset; 82 | 83 | private GoogleMap map; 84 | private SupportMapFragment mapFragment; 85 | private ViewPager viewPager; 86 | private AbsAdapter adapter; 87 | private Callback callback; 88 | 89 | protected CameraUpdate defaultPosition; 90 | private List defaultPositions; 91 | protected List markers; 92 | private List> allMarkers; 93 | 94 | private int initialPosition; 95 | private boolean hidden = false; 96 | 97 | 98 | public MapViewPager(Context context) { 99 | super(context); // not calling initialize(context) to use it with Builder 100 | } 101 | 102 | public MapViewPager(Context context, AttributeSet attrs) { 103 | super(context, attrs); 104 | initialize(context, attrs); 105 | } 106 | 107 | public MapViewPager(Context context, AttributeSet attrs, int defStyleAttr) { 108 | super(context, attrs, defStyleAttr); 109 | initialize(context, attrs); 110 | } 111 | 112 | private void initialize(Context context, AttributeSet attrs) { 113 | mapOffset = dp(32); 114 | if (attrs != null) { 115 | TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MapViewPager, 0, 0); 116 | try { 117 | markersAlpha = a.getFloat(R.styleable.MapViewPager_markersAlpha, DEFAULT_ALPHA); 118 | pagerWeight = a.getInteger(R.styleable.MapViewPager_viewPagerWeight, 1); 119 | mapWeight = a.getInteger(R.styleable.MapViewPager_mapWeight, 1); 120 | mapGravity = a.getInteger(R.styleable.MapViewPager_mapGravity, 1); 121 | mapOffset = a.getDimensionPixelSize(R.styleable.MapViewPager_mapOffset, mapOffset); 122 | mapPaddingLeft = a.getDimensionPixelSize(R.styleable.MapViewPager_mapPaddingLeft, 0); 123 | mapPaddingTop = a.getDimensionPixelSize(R.styleable.MapViewPager_mapPaddingTop, 0); 124 | mapPaddingRight = a.getDimensionPixelSize(R.styleable.MapViewPager_mapPaddingRight, 0); 125 | mapPaddingBottom = a.getDimensionPixelSize(R.styleable.MapViewPager_mapPaddingBottom, 0); 126 | } finally { 127 | a.recycle(); 128 | } 129 | } 130 | LayoutInflater inflater = LayoutInflater.from(context); 131 | switch (mapGravity) { 132 | case 0: inflater.inflate(R.layout.mapviewpager_left, this); break; 133 | case 1: inflater.inflate(R.layout.mapviewpager_top, this); break; 134 | case 2: inflater.inflate(R.layout.mapviewpager_right, this); break; 135 | case 3: inflater.inflate(R.layout.mapviewpager_bottom, this); break; 136 | } 137 | } 138 | 139 | public void start(@NonNull FragmentActivity activity, 140 | @NonNull AbsAdapter mapAdapter) { 141 | start(activity, mapAdapter, 0, null); 142 | } 143 | 144 | public void start(@NonNull FragmentActivity activity, 145 | @NonNull AbsAdapter mapAdapter, 146 | @Nullable Callback callback) { 147 | start(activity, mapAdapter, 0, callback); 148 | } 149 | 150 | public void start(@NonNull FragmentActivity activity, 151 | @NonNull AbsAdapter mapAdapter, 152 | int initialPosition) { 153 | start(activity, mapAdapter, initialPosition, null); 154 | } 155 | 156 | public void start(@NonNull FragmentActivity activity, 157 | @NonNull AbsAdapter mapAdapter, 158 | int initialPosition, 159 | @Nullable Callback callback) { 160 | this.initialPosition = initialPosition; 161 | this.callback = callback; 162 | adapter = mapAdapter; 163 | mapFragment = (SupportMapFragment) activity.getSupportFragmentManager().findFragmentById(R.id.map); 164 | viewPager = (ViewPager) findViewById(R.id.pager); 165 | setWeights(); 166 | mapFragment.getMapAsync(this); 167 | } 168 | 169 | @Override 170 | public void onMapReady(GoogleMap googleMap) { 171 | map = googleMap; 172 | map.setPadding(mapPaddingLeft, mapPaddingTop, mapPaddingRight, mapPaddingBottom); 173 | viewPager.setAdapter(adapter); 174 | viewPager.setCurrentItem(initialPosition); 175 | viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { 176 | @Override 177 | public void onPageSelected(int position) { 178 | moveTo(position, true); 179 | } 180 | }); 181 | populate(); 182 | if (callback != null) callback.onMapViewPagerReady(); 183 | moveTo(viewPager.getCurrentItem(), false); 184 | moveTo(viewPager.getCurrentItem(), true); 185 | } 186 | 187 | 188 | private void populate() { 189 | if (adapter instanceof MultiAdapter) populateMulti((MultiAdapter) adapter); 190 | else populateSingle((Adapter) adapter); 191 | } 192 | 193 | private void populateSingle(Adapter adapter) { 194 | map.clear(); 195 | markers = new LinkedList<>(); 196 | for (int i = 0; i < adapter.getCount(); i++) { 197 | CameraPosition cp = adapter.getCameraPosition(i); 198 | if (cp != null) { 199 | MarkerOptions mo = createMarkerOptions(cp, adapter.getPageTitle(i).toString()); 200 | markers.add(map.addMarker(mo)); 201 | } 202 | else markers.add(null); 203 | } 204 | map.setOnMarkerClickListener(createMarkerClickListenerSingle(adapter)); 205 | initDefaultPosition(); 206 | } 207 | 208 | private void populateMulti(final MultiAdapter adapter) { 209 | map.clear(); 210 | allMarkers = new LinkedList<>(); 211 | for (int page = 0; page < adapter.getCount(); page++) { 212 | LinkedList pageMarkers = new LinkedList<>(); 213 | if (adapter.getCameraPositions(page) != null) { 214 | for (int i = 0; i < adapter.getCameraPositions(page).size(); i++) { 215 | CameraPosition cp = adapter.getCameraPositions(page).get(i); 216 | if (cp != null) { 217 | MarkerOptions mo = createMarkerOptions(cp, adapter.getMarkerTitle(page, i)); 218 | pageMarkers.add(map.addMarker(mo)); 219 | } 220 | else pageMarkers.add(null); 221 | } 222 | } 223 | allMarkers.add(pageMarkers); 224 | } 225 | map.setOnMarkerClickListener(createMarkerClickListenerMulti(adapter)); 226 | initDefaultPositions(adapter); 227 | } 228 | 229 | private void moveTo(int page, boolean animate) { 230 | if (adapter instanceof MultiAdapter) moveToMulti(page, animate); 231 | else moveToSingle((Adapter) adapter, page, animate); 232 | } 233 | 234 | private void moveToSingle(Adapter adapter, int index, boolean animate) { 235 | CameraPosition cp = adapter.getCameraPosition(index); 236 | CameraUpdate cu; 237 | if (cp != null && cp.target != null 238 | && cp.target.latitude != 0.0 239 | && cp.target.longitude != 0.0) { 240 | cu = CameraUpdateFactory.newCameraPosition(cp); 241 | if (hidden) showMarkers(); 242 | if (markers.get(index) != null) markers.get(index).showInfoWindow(); 243 | } 244 | else { 245 | cu = defaultPosition; 246 | hideInfoWindowSingle(); 247 | } 248 | if (animate) map.animateCamera(cu); 249 | else map.moveCamera(cu); 250 | } 251 | 252 | private void moveToMulti(int page, boolean animate) { 253 | CameraUpdate cu = defaultPositions.get(page); 254 | if (cu == null) cu = defaultPosition; 255 | if (animate) map.animateCamera(cu); 256 | else map.moveCamera(cu); 257 | hideInfoWindowMulti(); 258 | if (allMarkers.get(page) != null 259 | && allMarkers.get(page).size() == 1 260 | && allMarkers.get(page).get(0) != null) { // this page has only one marker 261 | allMarkers.get(page).get(0).showInfoWindow(); 262 | } 263 | showMarkersForPage(page); 264 | } 265 | 266 | private void initDefaultPosition() { 267 | LatLngBounds.Builder builder = new LatLngBounds.Builder(); 268 | for (Marker marker : markers) if (marker != null) builder.include(marker.getPosition()); 269 | LatLngBounds bounds = builder.build(); 270 | defaultPosition = CameraUpdateFactory.newLatLngBounds(bounds, mapOffset); 271 | } 272 | 273 | private void initDefaultPositions(final MultiAdapter adapter) { 274 | // each page 275 | defaultPositions = new LinkedList<>(); 276 | for (int i = 0; i < adapter.getCount() ; i++) { 277 | defaultPositions.add(getDefaultPagePosition(adapter, i)); 278 | } 279 | // global 280 | LinkedList all = new LinkedList<>(); 281 | for (List list : allMarkers) if (list != null) all.addAll(list); 282 | LatLngBounds.Builder builder = new LatLngBounds.Builder(); 283 | for (Marker marker : all) if (marker != null) builder.include(marker.getPosition()); 284 | LatLngBounds bounds = builder.build(); 285 | defaultPosition = CameraUpdateFactory.newLatLngBounds(bounds, mapOffset); 286 | } 287 | 288 | private CameraUpdate getDefaultPagePosition(final MultiAdapter adapter, int page) { 289 | if (allMarkers.get(page).size() == 0) 290 | return null; 291 | if (allMarkers.get(page).size() == 1) 292 | return CameraUpdateFactory.newCameraPosition(adapter.getCameraPositions(page).get(0)); 293 | // more than 1 marker on this page 294 | LatLngBounds.Builder builder = new LatLngBounds.Builder(); 295 | for (Marker marker : allMarkers.get(page)) if (marker != null) builder.include(marker.getPosition()); 296 | LatLngBounds bounds = builder.build(); 297 | return CameraUpdateFactory.newLatLngBounds(bounds, mapOffset); 298 | } 299 | 300 | private GoogleMap.OnMarkerClickListener createMarkerClickListenerSingle(final Adapter adapter) { 301 | return new GoogleMap.OnMarkerClickListener() { 302 | @Override 303 | public boolean onMarkerClick(Marker marker) { 304 | for (int i = 0; i < adapter.getCount(); i++) { 305 | CameraPosition cp = adapter.getCameraPosition(i); 306 | if (cp != null && cp.target != null 307 | && cp.target.latitude == marker.getPosition().latitude 308 | && cp.target.longitude == marker.getPosition().longitude) { 309 | viewPager.setCurrentItem(i); 310 | marker.showInfoWindow(); 311 | return true; 312 | } 313 | } 314 | return false; 315 | } 316 | }; 317 | } 318 | 319 | private GoogleMap.OnMarkerClickListener createMarkerClickListenerMulti(final MultiAdapter adapter) { 320 | return new GoogleMap.OnMarkerClickListener() { 321 | @Override 322 | public boolean onMarkerClick(Marker marker) { 323 | for (int page = 0; page < adapter.getCount(); page++) { 324 | if (adapter.getCameraPositions(page) != null) { 325 | for (int i = 0; i < adapter.getCameraPositions(page).size(); i++) { 326 | CameraPosition cp = adapter.getCameraPositions(page).get(i); 327 | if (cp != null && cp.target != null 328 | && cp.target.latitude == marker.getPosition().latitude 329 | && cp.target.longitude == marker.getPosition().longitude) { 330 | if (marker.isInfoWindowShown()) { // this doesn't seem to work !! 331 | viewPager.setCurrentItem(page); 332 | return true; 333 | } 334 | else { 335 | viewPager.setCurrentItem(page); 336 | map.animateCamera(CameraUpdateFactory.newCameraPosition(cp)); 337 | marker.showInfoWindow(); 338 | return true; 339 | } 340 | } 341 | } 342 | } 343 | } 344 | return false; 345 | } 346 | }; 347 | } 348 | 349 | private MarkerOptions createMarkerOptions(CameraPosition cp, String title) { 350 | if (cp == null || cp.target == null) return null; 351 | return new MarkerOptions() 352 | .position(new LatLng(cp.target.latitude, cp.target.longitude)) 353 | .title(title) 354 | .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)); 355 | } 356 | 357 | private void showMarkers() { 358 | for (Marker marker : markers) if (marker != null) marker.setAlpha(1.0f); 359 | } 360 | 361 | private void showMarkersForPage(int page) { 362 | // make all translucent 363 | for (List list : allMarkers) { 364 | for (Marker marker : list) { 365 | if (marker != null) marker.setAlpha(markersAlpha); 366 | } 367 | } 368 | // make this page ones opaque 369 | for (Marker marker : allMarkers.get(page)) { 370 | if (marker != null) marker.setAlpha(1.0f); 371 | } 372 | } 373 | 374 | private void hideInfoWindowMulti() { 375 | for (List list : allMarkers) { 376 | if (list != null) { 377 | for (Marker marker : list) { 378 | if (marker != null) marker.hideInfoWindow(); 379 | } 380 | } 381 | } 382 | } 383 | 384 | private void hideInfoWindowSingle() { 385 | hidden = true; 386 | for (Marker marker : markers) { 387 | if (marker != null) { 388 | marker.hideInfoWindow(); 389 | marker.setAlpha(markersAlpha); 390 | } 391 | } 392 | } 393 | 394 | private void setWeights() { 395 | // viewPager 396 | LinearLayout.LayoutParams pagerParams = new LinearLayout.LayoutParams( 397 | LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, mapWeight); 398 | viewPager.setLayoutParams(pagerParams); 399 | // mapFragment 400 | View mapView = mapFragment.getView(); 401 | if (mapView != null) { 402 | LinearLayout.LayoutParams mapParams = new LinearLayout.LayoutParams( 403 | LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, pagerWeight); 404 | mapView.setLayoutParams(mapParams); 405 | } 406 | } 407 | 408 | private int dp(int dp) { 409 | DisplayMetrics dm = getResources().getDisplayMetrics(); 410 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, dm); 411 | } 412 | 413 | 414 | 415 | // general getters 416 | 417 | public GoogleMap getMap() { 418 | return map; 419 | } 420 | 421 | public SupportMapFragment getMapFragment() { 422 | return mapFragment; 423 | } 424 | 425 | public ViewPager getViewPager() { 426 | return viewPager; 427 | } 428 | 429 | public CameraUpdate getDefaultPosition() { 430 | return defaultPosition; 431 | } 432 | 433 | 434 | // single getters 435 | 436 | public Marker getMarker(int position) { 437 | return markers.get(position); 438 | } 439 | 440 | public List getMarkers() { 441 | return markers; 442 | } 443 | 444 | 445 | // multi getters 446 | 447 | public Marker getMarker(int page, int position) { 448 | if (allMarkers.get(page) != null) return allMarkers.get(page).get(position); 449 | return null; 450 | } 451 | 452 | public List getMarkers(int page) { 453 | return allMarkers.get(page); 454 | } 455 | 456 | public List> getAllMarkers() { 457 | return allMarkers; 458 | } 459 | 460 | public CameraUpdate getDefaultPosition(int page) { 461 | return defaultPositions.get(page); 462 | } 463 | 464 | public List getDefaultPositions() { 465 | return defaultPositions; 466 | } 467 | 468 | 469 | 470 | // Builder 471 | 472 | private MapViewPager(Builder builder, Context context) { 473 | super(context); 474 | // check that requited fields are provided 475 | if (context == null) throw new IllegalArgumentException("context can't be null"); 476 | if (builder.mapFragment == null) throw new IllegalArgumentException("mapFragment can't be null"); 477 | if (builder.viewPager == null) throw new IllegalArgumentException("viewPager can't be null"); 478 | if (builder.adapter == null) throw new IllegalArgumentException("adapter can't be null"); 479 | mapFragment = builder.mapFragment; 480 | viewPager = builder.viewPager; 481 | adapter = builder.adapter; 482 | callback = builder.callback; 483 | initialPosition = builder.position; 484 | markersAlpha = builder.markersAlpha; 485 | mapPaddingLeft = builder.mapPaddingLeft; 486 | mapPaddingTop = builder.mapPaddingTop; 487 | mapPaddingRight = builder.mapPaddingRight; 488 | mapPaddingBottom = builder.mapPaddingBottom; 489 | mapOffset = builder.mapOffset != 0 ? builder.mapOffset : dp(32); 490 | mapFragment.getMapAsync(this); 491 | } 492 | 493 | public static class Builder { 494 | 495 | private Context context; 496 | private SupportMapFragment mapFragment; 497 | private ViewPager viewPager; 498 | private AbsAdapter adapter; 499 | private Callback callback; 500 | private int position; 501 | private float markersAlpha = DEFAULT_ALPHA; 502 | private int mapOffset; 503 | private int mapPaddingLeft, mapPaddingTop, mapPaddingRight, mapPaddingBottom; 504 | 505 | public Builder(@NonNull Context context) { 506 | this.context = context; 507 | } 508 | 509 | public Builder mapFragment(@NonNull SupportMapFragment mapFragment) { 510 | this.mapFragment = mapFragment; 511 | return this; 512 | } 513 | 514 | public Builder viewPager(@NonNull ViewPager viewPager) { 515 | this.viewPager = viewPager; 516 | return this; 517 | } 518 | 519 | public Builder adapter(@NonNull AbsAdapter adapter) { 520 | this.adapter = adapter; 521 | return this; 522 | } 523 | 524 | public Builder callback(@Nullable Callback callback) { 525 | this.callback = callback; 526 | return this; 527 | } 528 | 529 | public Builder position(int position) { 530 | this.position = position; 531 | return this; 532 | } 533 | 534 | public Builder markersAlpha(float alpha) { 535 | this.markersAlpha = alpha; 536 | return this; 537 | } 538 | 539 | public Builder mapOffset(int mapOffset) { 540 | this.mapOffset = mapOffset; 541 | return this; 542 | } 543 | 544 | public Builder mapPadding(int mapPaddingLeft, 545 | int mapPaddingTop, 546 | int mapPaddingRight, 547 | int mapPaddingBottom) { 548 | this.mapPaddingLeft = mapPaddingLeft; 549 | this.mapPaddingTop = mapPaddingTop; 550 | this.mapPaddingRight = mapPaddingRight; 551 | this.mapPaddingBottom = mapPaddingBottom; 552 | return this; 553 | } 554 | 555 | public MapViewPager build() { 556 | return new MapViewPager(this, context); 557 | } 558 | 559 | } 560 | 561 | } 562 | --------------------------------------------------------------------------------