protected EditText renderInternal()

in source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/input/TextInputRenderer.java [191:364]


    protected EditText renderInternal(
            RenderedAdaptiveCard renderedCard,
            Context context,
            ViewGroup viewGroup,
            BaseInputElement baseInputElement,
            String value,
            String placeHolder,
            final TextInputHandler textInputHandler,
            HostConfig hostConfig,
            TagContent tagContent,
            RenderArgs renderArgs,
            boolean hasSpecificValidation)
    {
        EditText editText = null;
        TextInput textInput = Util.tryCastTo(baseInputElement, TextInput.class);

        if (baseInputElement.GetIsRequired() || hasSpecificValidation)
        {
            editText = new ValidatedEditText(context, getColor(hostConfig.GetForegroundColor(ContainerStyle.Default, ForegroundColor.Attention, false)));
        }
        else
        {
            editText = new EditText(context);

            // if the Input.Text element is multiline with height "Stretch" change height to match the parent container
            int editTextHeight = (textInput != null && baseInputElement.GetHeight() == HeightType.Stretch && textInput.GetIsMultiline()) ?
                ViewGroup.LayoutParams.MATCH_PARENT :
                ViewGroup.LayoutParams.WRAP_CONTENT;

            editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, editTextHeight));
            // editText.addTextChangedListener(new UnvalidatedTextWatcher(textInputHandler));
        }

        editText.setFocusable(true);
        textInputHandler.setView(editText);
        renderedCard.registerInputHandler(textInputHandler, renderArgs.getContainerCardId());

        if (!TextUtils.isEmpty(value))
        {
            editText.setText(value);
        }

        if (!TextUtils.isEmpty(placeHolder))
        {
            editText.setHint(placeHolder);
        }
        editText.addTextChangedListener(new TextWatcher()
        {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after)
            {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count)
            {

            }

            @Override
            public void afterTextChanged(Editable s)
            {
                CardRendererRegistration.getInstance().notifyInputChange(textInputHandler.getId(), textInputHandler.getInput());
            }
        });

        LinearLayout textInputViewGroup = null;

        if (textInput != null)
        {
            BaseActionElement action = textInput.GetInlineAction();

            if (action != null)
            {
                if ((hostConfig.GetActions().getShowCard().getActionMode() == ActionMode.Inline) &&
                    (action.GetElementType() == ActionType.ShowCard))
                {
                    renderedCard.addWarning(new AdaptiveWarning(AdaptiveWarning.INTERACTIVITY_DISALLOWED, "Inline ShowCard not supported for InlineAction"));
                }
                else
                {
                    textInputViewGroup = new LinearLayout(context);
                    textInputViewGroup.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                    editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1));
                    textInputViewGroup.addView(editText);

                    Resources.Theme theme = context.getTheme();
                    TypedValue buttonStyle = new TypedValue();

                    String url = action.GetIconUrl();
                    if (url != null && !url.isEmpty())
                    {
                        ImageButton inlineButton = null;
                        // check for style from resources
                        if (theme.resolveAttribute(R.attr.adaptiveInlineActionImage, buttonStyle, true))
                        {
                            Context themedContext = new ContextThemeWrapper(context, R.style.adaptiveInlineActionImage);
                            inlineButton = new ImageButton(themedContext, null, 0);
                        }
                        else
                        {
                            inlineButton = new ImageButton(context);
                            inlineButton.setBackgroundColor(Color.TRANSPARENT);
                            inlineButton.setPadding(16, 0, 0, 8);
                        }
                        inlineButton.setEnabled(action.GetIsEnabled());

                        ContainerRenderer.applyTitleAndTooltip(action, inlineButton);

                        InlineActionIconImageLoaderAsync imageLoader = new InlineActionIconImageLoaderAsync(
                            renderedCard,
                            inlineButton,
                            url,
                            editText);

                        imageLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);

                        if (Util.isOfType(action, ExecuteAction.class) || Util.isOfType(action, SubmitAction.class) || action.GetElementType() == ActionType.Custom)
                        {
                            renderedCard.setCardForSubmitAction(Util.getViewId(inlineButton), renderArgs.getContainerCardId());
                        }

                        textInputViewGroup.addView(inlineButton, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0));
                    }
                    else
                    {
                        String title = action.GetTitle();
                        Button inlineButton = null;
                        // check for styles from references
                        if (theme.resolveAttribute(R.attr.adaptiveInlineAction, buttonStyle, true))
                        {
                            Context themedContext = new ContextThemeWrapper(context, R.style.adaptiveInlineAction);
                            inlineButton = new Button(themedContext, null, 0);
                        }
                        else
                        {
                            inlineButton = new Button(context);
                            inlineButton.setBackgroundColor(Color.TRANSPARENT);
                            inlineButton.setTextColor(Color.BLACK);
                            inlineButton.setPadding(16, 0, 0, 8);
                        }

                        inlineButton.setText(title);
                        inlineButton.setEnabled(action.GetIsEnabled());

                        if (!TextUtils.isEmpty(action.GetTooltip()))
                        {
                            TooltipCompat.setTooltipText(inlineButton, action.GetTooltip());
                        }

                        if (Util.isOfType(action, ExecuteAction.class) || Util.isOfType(action, SubmitAction.class) || action.GetElementType() == ActionType.Custom)
                        {
                            renderedCard.setCardForSubmitAction(Util.getViewId(inlineButton), renderArgs.getContainerCardId());
                        }

                        textInputViewGroup.addView(inlineButton, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0));
                    }
                    textInputViewGroup.setGravity(Gravity.CENTER);
                }
            }
        }


        View returnableView = editText;
        if (textInputViewGroup != null)
        {
            returnableView = textInputViewGroup;
        }

        viewGroup.addView(returnableView);

        return editText;
    }