package com.mapzen.tangram.viewholder;

import android.content.Context;
import android.util.Log;
import android.view.TextureView;

import androidx.annotation.NonNull;

import com.mapzen.tangram.BuildConfig;

public class TextureViewHolderFactory implements GLViewHolderFactory {
    /**
     * Responsible to create an instance of {@link TextureViewHolder} which holds
     * an instance of {@link TextureView} for map display.
     * @param context Application Context
     * @return {@link TextureViewHolder}
     */
    @Override
    @NonNull
    public GLViewHolder build(Context context) {
        TextureView textureView = new TextureView(context);
        TextureViewHolder textureViewHolder = new TextureViewHolder(textureView);

        textureViewHolder.setEGLContextClientVersion(2);
        textureViewHolder.setPreserveEGLContextOnPause(true);
        try {
            textureViewHolder.setEGLConfigChooser(new ConfigChooser(8, 8, 8, 0, 16, 8));
            return textureViewHolder;
        } catch(IllegalArgumentException e) {
            // TODO: print available configs to check whether we could support them
            Log.e(BuildConfig.TAG, "EGLConfig 8-8-8-0 not supported");
        }
        try {
            textureViewHolder.setEGLConfigChooser(new ConfigChooser(8, 8, 8, 8, 16, 8));
            return textureViewHolder;
        } catch(IllegalArgumentException e) {
            Log.e(BuildConfig.TAG, "EGLConfig 8-8-8-8 not supported");
        }
        try {
            textureViewHolder.setEGLConfigChooser(new ConfigChooser(5, 6, 5, 0, 16, 8));
            return textureViewHolder;
        } catch(IllegalArgumentException e) {
            Log.e(BuildConfig.TAG, "EGLConfig 5-6-5-0 not supported");
        }
        return null;
    }
}

@@ -268,24 +268,515 @@
 erFactory %7B%0A
+%0A    private final boolean translucent;%0A%0A    /**%0A     * Create a %7B@link GLViewHolderFactory%7D that builds a %7B@link TextureViewHolder%7D.%0A     * @param translucent Enables translucency in the %7B@link TextureView%7D%0A     */%0A    public TextureViewHolderFactory(boolean translucent) %7B%0A        this.translucent = translucent;%0A    %7D%0A%0A    /**%0A     * Create a %7B@link GLViewHolderFactory%7D that builds a %7B@link TextureViewHolder%7D.%0A     */%0A    public TextureViewHolderFactory() %7B%0A        this(false);%0A    %7D%0A%0A
     /**%0A    
@@ -1345,378 +1345,54 @@
 e);%0A
-        try %7B%0A            textureViewHolder.setEGLConfigChooser(new ConfigChooser(8, 8, 8, 0, 16, 8));%0A            return textureViewHolder;%0A        %7D catch(IllegalArgumentException e) %7B%0A            // TODO: print available configs to check whether we could support them%0A            Log.e(BuildConfig.TAG, %22EGLConfig 8-8-8-0 not supported%22);%0A        %7D%0A        try %7B%0A    
+%0A        int alphaBits = translucent ? 8 : 0;%0A
     
@@ -1460,17 +1460,25 @@
 , 8, 8, 
-8
+alphaBits
 , 16, 8)
@@ -1492,452 +1492,78 @@
     
-    return textureViewHolder;%0A        %7D catch(IllegalArgumentException e) %7B%0A            Log.e(BuildConfig.TAG, %22EGLConfig 8-8-8-8 not supported%22);%0A        %7D%0A        try %7B%0A            textureViewHolder.setEGLConfigChooser(new ConfigChooser(5, 6, 5, 0, 16, 8));%0A            return textureViewHolder;%0A        %7D catch(IllegalArgumentException e) %7B%0A            Log.e(BuildConfig.TAG, %22EGLConfig 5-6-5-0 not supported%22);%0A        %7D%0A        return null
+textureView.setOpaque(!translucent);%0A%0A        return textureViewHolder
 ;%0A  

Add configuration to enable translucent TextureView surfaces (#2244)