Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduces an idx folder containing an IDX template, enabling users to open Android tutorials directly in the IDX IDE. #1757

Merged
merged 8 commits into from
Aug 23, 2024
28 changes: 28 additions & 0 deletions idx/open-in-idx-template/README.md
wangela marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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/idx/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/idx/open-in-idx-template
&giturl=https://github.com/googlemaps-samples/android-samples
&subdir=tutorials/java/CurrentPlaceDetailsOnMap/
&launchactivity=com.example.currentplacedetailsonmap/.MapsActivityCurrentPlace
&apikey=AIXXXXXXXXXXXXXXsg
wangela marked this conversation as resolved.
Show resolved Hide resolved
```

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.

<a href="https://idx.google.com/new?template=https://github.com/googlemaps-samples/android-samples/idx/open-in-idx-template&giturl=https://github.com/googlemaps-samples/android-samples&subdir=tutorials/java/CurrentPlaceDetailsOnMap/&launchactivity=com.example.currentplacedetailsonmap/.MapsActivityCurrentPlace">
<img
alt="Open in IDX"
src="https://www.gstatic.com/monospace/230815/openinprojectidx.png"
width="170"
/>
</a>
34 changes: 34 additions & 0 deletions idx/open-in-idx-template/devNix.j2
Original file line number Diff line number Diff line change
@@ -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 }}";
}
];
};
};
}
35 changes: 35 additions & 0 deletions idx/open-in-idx-template/idx-template.json
Original file line number Diff line number Diff line change
@@ -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": ["Backend"],
wangela marked this conversation as resolved.
Show resolved Hide resolved
"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"
}
}
26 changes: 26 additions & 0 deletions idx/open-in-idx-template/idx-template.nix
Original file line number Diff line number Diff line change
@@ -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"
'';
}