-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add APL Viewport Mapper and Predicate
- Loading branch information
Showing
9 changed files
with
500 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
ask-sdk-core/src/com/amazon/ask/request/viewport/Density.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file | ||
except in compliance with the License. A copy of the License is located at | ||
http://aws.amazon.com/apache2.0/ | ||
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for | ||
the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.ask.request.viewport; | ||
|
||
public enum Density { | ||
XLOW, | ||
LOW, | ||
MEDIUM, | ||
HIGH, | ||
XHIGH, | ||
XXHIGH; | ||
} |
21 changes: 21 additions & 0 deletions
21
ask-sdk-core/src/com/amazon/ask/request/viewport/Orientation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file | ||
except in compliance with the License. A copy of the License is located at | ||
http://aws.amazon.com/apache2.0/ | ||
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for | ||
the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.ask.request.viewport; | ||
|
||
public enum Orientation { | ||
LANDSCAPE, | ||
EQUAL, | ||
PORTRAIT; | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
ask-sdk-core/src/com/amazon/ask/request/viewport/Size.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file | ||
except in compliance with the License. A copy of the License is located at | ||
http://aws.amazon.com/apache2.0/ | ||
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for | ||
the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.ask.request.viewport; | ||
|
||
public enum Size { | ||
XSMALL, | ||
SMALL, | ||
MEDIUM, | ||
LARGE, | ||
XLARGE; | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
ask-sdk-core/src/com/amazon/ask/request/viewport/ViewportProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file | ||
except in compliance with the License. A copy of the License is located at | ||
http://aws.amazon.com/apache2.0/ | ||
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for | ||
the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.ask.request.viewport; | ||
|
||
public enum ViewportProfile { | ||
HUB_ROUND_SMALL, | ||
HUB_LANDSCAPE_MEDIUM, | ||
HUB_LANDSCAPE_LARGE, | ||
MOBILE_LANDSCAPE_SMALL, | ||
MOBILE_PORTRAIT_SMALL, | ||
MOBILE_LANDSCAPE_MEDIUM, | ||
MOBILE_PORTRAIT_MEDIUM, | ||
TV_LANDSCAPE_XLARGE, | ||
TV_PORTRAIT_MEDIUM, | ||
TV_LANDSCAPE_MEDIUM, | ||
UNKNOWN_VIEWPORT_PROFILE; | ||
} |
148 changes: 148 additions & 0 deletions
148
ask-sdk-core/src/com/amazon/ask/request/viewport/ViewportUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file | ||
except in compliance with the License. A copy of the License is located at | ||
http://aws.amazon.com/apache2.0/ | ||
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for | ||
the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.ask.request.viewport; | ||
|
||
import com.amazon.ask.exception.AskSdkException; | ||
import com.amazon.ask.model.RequestEnvelope; | ||
import com.amazon.ask.model.interfaces.viewport.Shape; | ||
import com.amazon.ask.model.interfaces.viewport.ViewportState; | ||
|
||
public class ViewportUtils { | ||
|
||
public static ViewportProfile getViewportProfile(RequestEnvelope requestEnvelope) { | ||
ViewportState viewportState = requestEnvelope.getContext().getViewport(); | ||
Shape shape = viewportState.getShape(); | ||
int currentPixelWidth = viewportState.getCurrentPixelWidth().intValueExact(); | ||
int currentPixelHeight = viewportState.getCurrentPixelHeight().intValueExact(); | ||
int dpi = viewportState.getDpi().intValueExact(); | ||
Orientation orientation = getOrientation(currentPixelHeight, currentPixelWidth); | ||
|
||
if (shape == Shape.ROUND && | ||
orientation == Orientation.EQUAL && | ||
getSize(currentPixelHeight) == Size.XSMALL && | ||
getSize(currentPixelWidth) == Size.XSMALL && | ||
getDensity(dpi) == Density.LOW) { | ||
return ViewportProfile.HUB_ROUND_SMALL; | ||
|
||
} else if (shape == Shape.RECTANGLE && | ||
orientation == Orientation.LANDSCAPE && | ||
getSize(currentPixelWidth).ordinal() <= Size.MEDIUM.ordinal() && | ||
getSize(currentPixelHeight).ordinal() <= Size.SMALL.ordinal() && | ||
getDensity(dpi) == Density.LOW) { | ||
return ViewportProfile.HUB_LANDSCAPE_MEDIUM; | ||
|
||
} else if (shape == Shape.RECTANGLE && | ||
orientation == Orientation.LANDSCAPE && | ||
getSize(currentPixelWidth).ordinal() >= Size.LARGE.ordinal() && | ||
getSize(currentPixelHeight).ordinal() >= Size.SMALL.ordinal() && | ||
getDensity(dpi) == Density.LOW) { | ||
return ViewportProfile.HUB_LANDSCAPE_LARGE; | ||
|
||
} else if (shape == Shape.RECTANGLE && | ||
orientation == Orientation.LANDSCAPE && | ||
getSize(currentPixelWidth).ordinal() >= Size.MEDIUM.ordinal() && | ||
getSize(currentPixelHeight).ordinal() >= Size.SMALL.ordinal() && | ||
getDensity(dpi) == Density.MEDIUM) { | ||
return ViewportProfile.MOBILE_LANDSCAPE_MEDIUM; | ||
|
||
} else if (shape == Shape.RECTANGLE && | ||
orientation == Orientation.PORTRAIT && | ||
getSize(currentPixelWidth).ordinal() >= Size.SMALL.ordinal() && | ||
getSize(currentPixelHeight).ordinal() >= Size.MEDIUM.ordinal() && | ||
getDensity(dpi) == Density.MEDIUM) { | ||
return ViewportProfile.MOBILE_PORTRAIT_MEDIUM; | ||
|
||
} else if (shape == Shape.RECTANGLE && | ||
orientation == Orientation.LANDSCAPE && | ||
getSize(currentPixelWidth).ordinal() >= Size.SMALL.ordinal() && | ||
getSize(currentPixelHeight).ordinal() >= Size.XSMALL.ordinal() && | ||
getDensity(dpi) == Density.MEDIUM) { | ||
return ViewportProfile.MOBILE_LANDSCAPE_SMALL; | ||
|
||
} else if (shape == Shape.RECTANGLE && | ||
orientation == Orientation.PORTRAIT && | ||
getSize(currentPixelWidth).ordinal() >= Size.XSMALL.ordinal() && | ||
getSize(currentPixelHeight).ordinal() >= Size.SMALL.ordinal() && | ||
getDensity(dpi) == Density.MEDIUM) { | ||
return ViewportProfile.MOBILE_PORTRAIT_SMALL; | ||
|
||
} else if (shape == Shape.RECTANGLE && | ||
orientation == Orientation.LANDSCAPE && | ||
getSize(currentPixelWidth).ordinal() >= Size.XLARGE.ordinal() && | ||
getSize(currentPixelHeight).ordinal() >= Size.MEDIUM.ordinal() && | ||
getDensity(dpi).ordinal() >= Density.HIGH.ordinal()) { | ||
return ViewportProfile.TV_LANDSCAPE_XLARGE; | ||
|
||
} else if (shape == Shape.RECTANGLE && | ||
orientation == Orientation.PORTRAIT && | ||
getSize(currentPixelWidth) == Size.XSMALL && | ||
getSize(currentPixelHeight) == Size.XLARGE && | ||
getDensity(dpi).ordinal() >= Density.HIGH.ordinal()) { | ||
return ViewportProfile.TV_PORTRAIT_MEDIUM; | ||
|
||
} else if (shape == Shape.RECTANGLE && | ||
orientation == Orientation.LANDSCAPE && | ||
getSize(currentPixelWidth) == Size.MEDIUM && | ||
getSize(currentPixelHeight) == Size.SMALL && | ||
getDensity(dpi).ordinal() >= Density.HIGH.ordinal()) { | ||
return ViewportProfile.TV_LANDSCAPE_MEDIUM; | ||
} | ||
return ViewportProfile.UNKNOWN_VIEWPORT_PROFILE; | ||
} | ||
|
||
private static Density getDensity(int dpi) { | ||
if (isBetween(dpi, 0, 121)) { | ||
return Density.XLOW; | ||
} else if (isBetween(dpi, 121, 161)) { | ||
return Density.LOW; | ||
} else if (isBetween(dpi, 161, 241)) { | ||
return Density.MEDIUM; | ||
} else if (isBetween(dpi, 241, 321)) { | ||
return Density.HIGH; | ||
} else if (isBetween(dpi, 321, 481)) { | ||
return Density.XHIGH; | ||
} else if (dpi >= 481) { | ||
return Density.XXHIGH; | ||
} | ||
throw new AskSdkException("Unknown density dpi value " + dpi); | ||
} | ||
|
||
private static Orientation getOrientation(int height, int width) { | ||
if (height > width) { | ||
return Orientation.PORTRAIT; | ||
} else if (height < width) { | ||
return Orientation.LANDSCAPE; | ||
} | ||
return Orientation.EQUAL; | ||
} | ||
|
||
private static Size getSize(int dpi) { | ||
if (isBetween(dpi, 0, 600)) { | ||
return Size.XSMALL; | ||
} else if (isBetween(dpi, 600, 960)) { | ||
return Size.SMALL; | ||
} else if (isBetween(dpi, 960, 1280)) { | ||
return Size.MEDIUM; | ||
} else if (isBetween(dpi, 1280, 1920)) { | ||
return Size.LARGE; | ||
} else if (dpi >= 1920) { | ||
return Size.XLARGE; | ||
} | ||
throw new AskSdkException("Unknown size group value " + dpi); | ||
} | ||
|
||
private static boolean isBetween(int x, int lower, int upper) { | ||
return lower <= x && x < upper; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
3cb283f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@breedloj Hi there. I see the changes this new commit introduces to the SDK. Is there some more changes to come? Could you explain me how to test all those new components that the link to APL post on Alexa blog talks about? Thanks!
3cb283f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @javier-ochoa, thanks for keeping an eye on SDK update.
Basically your skill will receive APL related information from Input - RequestEnvelope - Context - ViewPort, including dpi, pixel height, pixel width, shape and etc.
You can leverage ViewPortUtils and Predicate to find out what kind of ViewportProfile it is, for example HUB_LANDSCAPE_MEDIUM which matches Medium Hub in developer console, and what RequestHandler should handle this request. Then you can build up APL Command, wire them up into Directive and send back response to device.
Enjoy!
3cb283f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javier-ochoa not sure if this helps but there are some samples in Node.js if you would like to test it quickly!
3cb283f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Chris-Liao @sungolivia Thank you guys for your help.
Perhaps you guys can provide some further help.
I went to the APL authoring tool and copied one example directly into my project.
Finally I just loaded that json into a RenderDocumentDirective and push it to the response.
I am testing it with the Alexa Developer Console but i dont seem to get anything out regardless of the HUB i use or even on the Extra Large TV mode. Is the ADC already working with APL directives?
This is the json log I get from the Developer Console and i can see that the directive is there:
Thank you!
3cb283f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @javier-ochoa , lets move this discussion to the Issues board so that it is helpful for other community members as well. Do you mind logging an issue with this content, so that we can investigate further? Thanks!!
3cb283f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nikhilym
issue opened => #153
Thank you.
3cb283f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can someone provide a working example with this how to build a response with a picture?
3cb283f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @BlockLabTV, would you also open an issue so we can keep track and help others?
3cb283f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is worth an issue since you probably won't add a sample just for me, just thought maybe someone already has published one somewhere and could share it with me.
3cb283f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @BlockLabTV , posting these requests/discussions on the 'issues' dashboard will make easier for the community to search through and respond faster, than on the release commits.
That being said, we currently do not have an APL sample to show case, but putting it on the issues/ user voice as feature request would drive either the community or the SDK developers to work on it, depending on the priorities.
3cb283f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> #154