From 77ff33712cc0ad4d4432e4eeaadc7a0d11b9ecfd Mon Sep 17 00:00:00 2001 From: chan24 <aakaschan24@gmail.com> Date: Mon, 27 Mar 2017 13:14:59 +0530 Subject: [PATCH] maps --- .idea/gradle.xml | 2 +- .idea/misc.xml | 2 +- .idea/modules.xml | 2 +- app/build.gradle | 3 +- app/src/debug/res/values/google_maps_api.xml | 21 +++++++++ app/src/main/AndroidManifest.xml | 24 +++++++++- .../chan24/smartplanner/LoginActivity.java | 4 ++ .../chan24/smartplanner/MapsActivity.java | 46 +++++++++++++++++++ app/src/main/res/layout/activity_maps.xml | 8 ++++ app/src/main/res/values/strings.xml | 1 + .../release/res/values/google_maps_api.xml | 22 +++++++++ 11 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 app/src/debug/res/values/google_maps_api.xml create mode 100644 app/src/main/java/com/example/chan24/smartplanner/MapsActivity.java create mode 100644 app/src/main/res/layout/activity_maps.xml create mode 100644 app/src/release/res/values/google_maps_api.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml index fe72da5..0e23f8e 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -5,7 +5,7 @@ <GradleProjectSettings> <option name="distributionType" value="LOCAL" /> <option name="externalProjectPath" value="$PROJECT_DIR$" /> - <option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.14.1" /> + <option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.14.1" /> <option name="modules"> <set> <option value="$PROJECT_DIR$" /> diff --git a/.idea/misc.xml b/.idea/misc.xml index fbb6828..5d19981 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ <ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Remove" /> </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/build/classes" /> </component> <component name="ProjectType"> diff --git a/.idea/modules.xml b/.idea/modules.xml index 2b7958a..280fece 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ <project version="4"> <component name="ProjectModuleManager"> <modules> - <module fileurl="file://$PROJECT_DIR$/Smart Planner.iml" filepath="$PROJECT_DIR$/Smart Planner.iml" /> + <module fileurl="file://$PROJECT_DIR$/SmartPlanner.iml" filepath="$PROJECT_DIR$/SmartPlanner.iml" /> <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> </modules> </component> diff --git a/app/build.gradle b/app/build.gradle index c43db8f..74d6bb5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,6 +25,7 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.1.0' - testCompile 'junit:junit:4.12' compile 'com.android.volley:volley:1.0.0' + compile 'com.google.android.gms:play-services:10.0.1' + testCompile 'junit:junit:4.12' } diff --git a/app/src/debug/res/values/google_maps_api.xml b/app/src/debug/res/values/google_maps_api.xml new file mode 100644 index 0000000..a4e4102 --- /dev/null +++ b/app/src/debug/res/values/google_maps_api.xml @@ -0,0 +1,21 @@ +<resources> + <!-- + TODO: Before you run your application, you need a Google Maps API key. + + To get one, follow this link, follow the directions and press "Create" at the end: + + https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=0A:28:96:D7:DC:0E:9A:A4:08:7E:EB:25:FC:89:B6:7F:E3:33:0B:E8%3Bcom.example.chan24.smartplanner + + You can also add your credentials to an existing key, using this line: + 0A:28:96:D7:DC:0E:9A:A4:08:7E:EB:25:FC:89:B6:7F:E3:33:0B:E8;com.example.chan24.smartplanner + + Alternatively, follow the directions here: + https://developers.google.com/maps/documentation/android/start#get-key + + Once you have your key (it starts with "AIza"), replace the "google_maps_key" + string in this file. + --> + <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false"> + AIzaSyCiYMdcQTAJIqgGOcbY88Oq5EYpwfJUyk0 + </string> +</resources> diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d7a91d4..1feaaa1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,13 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.chan24.smartplanner"> + <!-- + The ACCESS_COARSE/FINE_LOCATION permissions are not required to use + Google Maps Android API v2, but you must specify either coarse or fine + location permissions for the 'MyLocation' functionality. + --> + <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> + <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" @@ -16,7 +23,22 @@ </intent-filter> </activity> <activity android:name=".RegisterActivity" /> - <activity android:name=".UserArea"></activity> + <activity android:name=".UserArea" /> + <!-- + The API key for Google Maps-based APIs is defined as a string resource. + (See the file "res/values/google_maps_api.xml"). + Note that the API key is linked to the encryption key used to sign the APK. + You need a different API key for each encryption key, including the release key that is used to + sign the APK for publishing. + You can define the keys for the debug and release targets in src/debug/ and src/release/. + --> + <meta-data + android:name="com.google.android.geo.API_KEY" + android:value="@string/google_maps_key" /> + + <activity + android:name=".MapsActivity" + android:label="@string/title_activity_maps"></activity> </application> </manifest> \ No newline at end of file diff --git a/app/src/main/java/com/example/chan24/smartplanner/LoginActivity.java b/app/src/main/java/com/example/chan24/smartplanner/LoginActivity.java index b1dcad6..4671f65 100644 --- a/app/src/main/java/com/example/chan24/smartplanner/LoginActivity.java +++ b/app/src/main/java/com/example/chan24/smartplanner/LoginActivity.java @@ -1,8 +1,11 @@ package com.example.chan24.smartplanner; +import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.view.View; +import android.widget.Button; public class LoginActivity extends AppCompatActivity { @@ -10,5 +13,6 @@ public class LoginActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); + } } diff --git a/app/src/main/java/com/example/chan24/smartplanner/MapsActivity.java b/app/src/main/java/com/example/chan24/smartplanner/MapsActivity.java new file mode 100644 index 0000000..78c1778 --- /dev/null +++ b/app/src/main/java/com/example/chan24/smartplanner/MapsActivity.java @@ -0,0 +1,46 @@ +package com.example.chan24.smartplanner; + +import android.support.v4.app.FragmentActivity; +import android.os.Bundle; + +import com.google.android.gms.maps.CameraUpdateFactory; +import com.google.android.gms.maps.GoogleMap; +import com.google.android.gms.maps.OnMapReadyCallback; +import com.google.android.gms.maps.SupportMapFragment; +import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.MarkerOptions; + +public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { + + private GoogleMap mMap; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_maps); + // Obtain the SupportMapFragment and get notified when the map is ready to be used. + SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() + .findFragmentById(R.id.map); + mapFragment.getMapAsync(this); + } + + + /** + * Manipulates the map once available. + * This callback is triggered when the map is ready to be used. + * This is where we can add markers or lines, add listeners or move the camera. In this case, + * we just add a marker near Sydney, Australia. + * If Google Play services is not installed on the device, the user will be prompted to install + * it inside the SupportMapFragment. This method will only be triggered once the user has + * installed Google Play services and returned to the app. + */ + @Override + public void onMapReady(GoogleMap googleMap) { + mMap = googleMap; + + // Add a marker in Sydney and move the camera + LatLng sydney = new LatLng(-34, 151); + mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); + mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); + } +} diff --git a/app/src/main/res/layout/activity_maps.xml b/app/src/main/res/layout/activity_maps.xml new file mode 100644 index 0000000..47d7f50 --- /dev/null +++ b/app/src/main/res/layout/activity_maps.xml @@ -0,0 +1,8 @@ +<fragment xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:map="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/map" + android:name="com.google.android.gms.maps.SupportMapFragment" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context="com.example.chan24.smartplanner.MapsActivity" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 996b2bc..6669eb8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,4 @@ <resources> <string name="app_name">SmartPlanner</string> + <string name="title_activity_maps">Map</string> </resources> diff --git a/app/src/release/res/values/google_maps_api.xml b/app/src/release/res/values/google_maps_api.xml new file mode 100644 index 0000000..fa88c61 --- /dev/null +++ b/app/src/release/res/values/google_maps_api.xml @@ -0,0 +1,22 @@ +<resources> + <!-- + TODO: Before you release your application, you need a Google Maps API key. + + To do this, you can either add your release key credentials to your existing + key, or create a new key. + + Note that this file specifies the API key for the release build target. + If you have previously set up a key for the debug target with the debug signing certificate, + you will also need to set up a key for your release certificate. + + Follow the directions here: + + https://developers.google.com/maps/documentation/android/signup + + Once you have your key (it starts with "AIza"), replace the "google_maps_key" + string in this file. + --> + <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false"> + YOUR_KEY_HERE + </string> +</resources> -- GitLab