<% const type = locals.type; const properties = locals.properties; const doc = locals.doc; -%> // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import android.support.annotation.Keep; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; <% if (type === 'symbol') { -%> import com.mapbox.mapboxsdk.style.types.Formatted; import com.mapbox.mapboxsdk.style.types.FormattedSection; <% } -%> /** * <%- doc %> * * @see The online documentation */ @UiThread public class <%- camelize(type) %>Layer extends Layer { /** * Creates a <%- camelize(type) %>Layer. * * @param nativePtr pointer used by core */ @Keep <%- camelize(type) %>Layer(long nativePtr) { super(nativePtr); } <% if (type === 'background') { -%> /** * Creates a <%- camelize(type) %>Layer. * * @param layerId the id of the layer */ public <%- camelize(type) %>Layer(String layerId) { super(); initialize(layerId); } @Keep protected native void initialize(String layerId); <% } else { -%> /** * Creates a <%- camelize(type) %>Layer. * * @param layerId the id of the layer * @param sourceId the id of the source */ public <%- camelize(type) %>Layer(String layerId, String sourceId) { super(); initialize(layerId, sourceId); } @Keep protected native void initialize(String layerId, String sourceId); /** * Set the source layer. * * @param sourceLayer the source layer to set */ public void setSourceLayer(String sourceLayer) { checkThread(); nativeSetSourceLayer(sourceLayer); } /** * Set the source Layer. * * @param sourceLayer the source layer to set * @return This */ @NonNull public <%- camelize(type) %>Layer withSourceLayer(String sourceLayer) { setSourceLayer(sourceLayer); return this; } <% } -%> <% if (type !== 'background' && type !== 'custom') { -%> /** * Get the source id. * * @return id of the source */ @NonNull public String getSourceId() { checkThread(); return nativeGetSourceId(); } <% } -%> <% if (type !== 'background' && type !== 'raster' && type !== 'hillshade') { -%> /** * Get the source layer. * * @return sourceLayer the source layer to get */ @NonNull public String getSourceLayer() { checkThread(); return nativeGetSourceLayer(); } /** * Set a single expression filter. * * @param filter the expression filter to set */ public void setFilter(@NonNull Expression filter) { checkThread(); nativeSetFilter(filter.toArray()); } /** * Set a single expression filter. * * @param filter the expression filter to set * @return This */ @NonNull public <%- camelize(type) %>Layer withFilter(@NonNull Expression filter) { setFilter(filter); return this; } /** * Get a single expression filter. * * @return the expression filter to get */ @Nullable public Expression getFilter() { checkThread(); JsonElement jsonElement = nativeGetFilter(); if (jsonElement != null) { return Expression.Converter.convert(jsonElement); } else { return null; } } <% } -%> /** * Set a property or properties. * * @param properties the var-args properties * @return This */ @NonNull public <%- camelize(type) %>Layer withProperties(@NonNull PropertyValue... properties) { setProperties(properties); return this; } // Property getters <% for (const property of properties) { -%> /** * Get the <%- camelize(property.name) %> property * * @return property wrapper value around <%- propertyType(property) %> */ @NonNull @SuppressWarnings("unchecked") public PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() { checkThread(); <% if (property.name === 'text-field' && property.type === 'formatted') { -%> PropertyValue propertyValue = new PropertyValue<>("text-field", nativeGetTextField()); if (propertyValue.isExpression()) { return (PropertyValue) propertyValue; } else { String text = null; Formatted formatted = (Formatted) nativeGetTextField(); if (formatted != null) { StringBuilder builder = new StringBuilder(); for (FormattedSection section : formatted.getFormattedSections()) { builder.append(section.getText()); } text = builder.toString(); } return (PropertyValue) new PropertyValue("text-field", text); } <% } else { -%> return (PropertyValue<<%- propertyType(property) %>>) new PropertyValue("<%- property.name %>", nativeGet<%- camelize(property.name) %>()); <% } -%> } <% if (property.name === 'text-field' && property.type === 'formatted') { -%> /** * Get the <%- camelize(property.name) %> property as {@link Formatted} object * * @return property wrapper value around <%- propertyType(property) %> * @see Expression#format(Expression.FormatEntry...) */ @NonNull @SuppressWarnings("unchecked") public PropertyValue getFormatted<%- camelize(property.name) %>() { checkThread(); return (PropertyValue) new PropertyValue("<%- property.name %>", nativeGet<%- camelize(property.name) %>()); } <% } -%> <% if (property.type == 'color') { -%> /** * <%- property.doc %> * * @return int representation of a rgba string color * @throws RuntimeException thrown if property isn't a value */ @ColorInt public int get<%- camelize(property.name) %>AsInt() { checkThread(); PropertyValue<<%- propertyType(property) %>> value = get<%- camelize(property.name) %>(); if (value.isValue()) { return rgbaToColor(value.getValue()); } else { throw new RuntimeException("<%- property.name %> was set as a Function"); } } <% } -%> <% if (property.transition) { -%> /** * Get the <%- camelize(property.name) %> property transition options * * @return transition options for <%- propertyType(property) %> */ @NonNull public TransitionOptions get<%- camelize(property.name) %>Transition() { checkThread(); return nativeGet<%- camelize(property.name) %>Transition(); } /** * Set the <%- camelize(property.name) %> property transition options * * @param options transition options for <%- propertyType(property) %> */ public void set<%- camelize(property.name) %>Transition(@NonNull TransitionOptions options) { checkThread(); nativeSet<%- camelize(property.name) %>Transition(options.getDuration(), options.getDelay()); } <% } -%> <% } -%> <% for (const property of properties) { -%> @NonNull @Keep private native Object nativeGet<%- camelize(property.name) %>(); <% if (property.transition) { -%> @NonNull @Keep private native TransitionOptions nativeGet<%- camelize(property.name) %>Transition(); @Keep private native void nativeSet<%- camelize(property.name) %>Transition(long duration, long delay); <% } -%> <% } -%> @Override @Keep protected native void finalize() throws Throwable; }