diff --git a/open-in-idx-template/README.md b/open-in-idx-template/README.md new file mode 100644 index 000000000..c087d2bab --- /dev/null +++ b/open-in-idx-template/README.md @@ -0,0 +1,28 @@ +## Open in Project IDX + +## How to use the template + +This template allows opening Google Maps Platform Android tutorial code samples in IDX IDE. To open a code sample in IDX, go to `https://idx.google.com/new?template=https://github.com/googlemaps-samples/android-samples/open-in-idx-template` and provide the gitUrl, subdir and the name of the activity to launch as query params. + +``` +https://idx.google.com/new +?template=https://github.com/googlemaps-samples/android-samples/open-in-idx-template +&giturl=https://github.com/googlemaps-samples/android-samples +&subdir=tutorials/java/CurrentPlaceDetailsOnMap/ +&launchactivity=com.example.currentplacedetailsonmap/.MapsActivityCurrentPlace +&apikey=AIzaXXXXXXXXXXXXXXXX +``` + +Please review the template parameters in idx-template.json file. If a parameter is not provided in the link as a query param, the default value specified in the `idx-template.json` file will be used. If the parameter doesn't specify a default value and a value is not provided as a query param, the IDX workspace creation dialog asks for the value. + +There is no default value for the API Key. You must provide it as a query parameter or alternatively in the IDX workspace creation dialog. + +The example below demonstates how you could open a code sample in IDX. The link in the example will open the code sample specified by the default values in idx-template.json and you'd be asked to provide an API Key on IDX workspace creation dialog. + + + Open in IDX + \ No newline at end of file diff --git a/open-in-idx-template/devNix.j2 b/open-in-idx-template/devNix.j2 new file mode 100644 index 000000000..077e357c4 --- /dev/null +++ b/open-in-idx-template/devNix.j2 @@ -0,0 +1,34 @@ +# To learn more about how to use Nix to configure your environment +# see: https://developers.google.com/idx/guides/customize-idx-env +{ pkgs, ... }: { + # Which nixpkgs channel to use. + channel = "stable-23.11"; # or "unstable" + # Use https://search.nixos.org/packages to find packages + packages = [ + pkgs.jdk21 + ]; + # Sets environment variables in the workspace + env = {}; + idx = { + workspace = { + onCreate = { + build-and-wait = "./gradlew assembleDebug && adb -s emulator-5554 wait-for-device"; + default.openFiles = [ "README.md" ]; + }; + onStart = { + wait-for-adb = "adb -s emulator-5554 wait-for-device"; + }; + }; + previews = { + enable = true; + previews = [ + { + command = ["./gradlew" "--continuous" "installDebug"]; + id = "android"; + manager = "gradle"; + activity = "{{ launch_activity }}"; + } + ]; + }; + }; +} \ No newline at end of file diff --git a/open-in-idx-template/idx-template.json b/open-in-idx-template/idx-template.json new file mode 100644 index 000000000..e69710d5f --- /dev/null +++ b/open-in-idx-template/idx-template.json @@ -0,0 +1,35 @@ +{ + "name": "Open in IDX for Maps SDK for Android Samples", + "description": "This template allows opening Android tutorials in IDX IDE", + "categories": ["Mobile"], + "icon": "https://developers.google.com/static/maps/images/maps-icon.svg", + "publisher": "Google LLC", + "params": [ + { + "id": "apikey", + "name": "API KEY", + "type": "text" + }, + { + "id": "giturl", + "name": "Git Url", + "type": "text", + "default": "https://github.com/googlemaps-samples/android-samples" + }, + { + "id": "subdir", + "name": "Project Subfolder", + "type": "text", + "default": "tutorials/java/MapWithMarker/" + }, + { + "id": "launchactivity", + "name": "Android Activity to launch", + "type": "text", + "default": "com.example.mapwithmarker/.MapsMarkerActivity" + } + ], + "host": { + "virtualization": "true" + } + } \ No newline at end of file diff --git a/open-in-idx-template/idx-template.nix b/open-in-idx-template/idx-template.nix new file mode 100644 index 000000000..ed230f863 --- /dev/null +++ b/open-in-idx-template/idx-template.nix @@ -0,0 +1,26 @@ +{ pkgs, apikey, giturl, subdir, launchactivity,... }: { + packages = [ + pkgs.git + pkgs.sdkmanager + pkgs.j2cli + ]; + bootstrap = '' + mkdir -p "$WS_NAME" tmp + + git clone --depth 1 ${giturl} tmp + + mv tmp/${subdir}/* "$WS_NAME" + + chmod -R +w "$WS_NAME" + mkdir -p "$WS_NAME/.idx/" + + # Create a secrets.properties file in the repo and replace the MAPS_API_KEY property with said value + touch $WS_NAME/secrets.properties + echo "MAPS_API_KEY=\"${apikey}\"" > $WS_NAME/secrets.properties + + # We create a dev.nix that builds the subproject specified at template instantiation + launch_activity=${launchactivity} j2 --format=env ${./devNix.j2} -o $WS_NAME/.idx/dev.nix + + mv "$WS_NAME" "$out" + ''; +} \ No newline at end of file