<commit_before>package org.codepond.wizardroid.layouts;

import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.softvelopment.wizardroid.activity.ActivityConstants;

import org.codepond.wizardroid.R;
import org.codepond.wizardroid.WizardFlow;
import org.codepond.wizardroid.WizardStep;
import org.codepond.wizardroid.WizardValidatable;
import org.codepond.wizardroid.helper.WizardStepXmlBean;
import org.codepond.wizardroid.helper.WizardXmlBean;
import org.codepond.wizardroid.helper.impl.WizardStepXmlBeanImpl;
import org.codepond.wizardroid.helper.impl.WizardXmlBeanImpl;
import org.codepond.wizardroid.helper.util.WizardStepXmlBeanComparator;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;

/**
 * Created by softvelopment on 7/3/15.
 *
 *  This class builds on the BasicWizardLayout class with the following
 *  improvements
 *
 *  Child claases that inherit from this should not have to implement/override
 *  onSetup() but should just override 2 methods
 *
 *  getWizardName  The name of the wizard in the wizard xml file
 *  getWizardFileResourceId  The id of the wizard file resource
 *
 */
public abstract class SoftvelopmentWizardLayout extends BasicWizardLayout implements WizardValidatable{

    private static final String TAG = SoftvelopmentWizardLayout.class.getSimpleName();

    public abstract String getWizardName();
    public abstract int getWizardFileResourceId();

    protected int width=0;
    protected int height=0;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View wizardLayout = super.onCreateView(inflater,container,savedInstanceState);
        if((width > 0) &&(height >0 ))
        {
            RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(width, height);
            wizardLayout.setLayoutParams(p);
            wizardLayout.requestLayout();
        }
        return wizardLayout;
    }

    @Override
    public WizardFlow onSetup()
    {
        if(this.getActivity() != null)
        {
            try {
                return buildWizard(getWizardName(), getActivity().getResources().openRawResource(getWizardFileResourceId()));
            }
            catch(XmlPullParserException xppe)
            {
                Log.e(TAG, "Unable to create wizard with name " + getWizardName(),xppe);
            }
            catch(IOException ioe)
            {
                Log.e(TAG, "Unable to create wizard with name " + getWizardName(),ioe);
            }
        }
        return null;
    }

    public WizardFlow buildWizard(String wizardName, InputStream instream)throws IOException, XmlPullParserException
    {
        WizardXmlBean wizardXmlBean = loadWizardFromXml(wizardName, instream);
        WizardFlow wizardFlow = null;
        if(wizardXmlBean != null)
        {

            WizardFlow.Builder wizardFlowBuilder = new WizardFlow.Builder();
            if((wizardXmlBean.getWizardFlowXmlBean().getWizardSteps() != null) &&(wizardXmlBean.getWizardFlowXmlBean().getWizardSteps().size()>0))
            {
                try {
                    //sort the wizard steps
                    Collections.sort(wizardXmlBean.getWizardFlowXmlBean().getWizardSteps(), new WizardStepXmlBeanComparator());
                    for(WizardStepXmlBean stepXmlBean:wizardXmlBean.getWizardFlowXmlBean().getWizardSteps())
                    {

                        wizardFlowBuilder.addStep((Class<? extends WizardStep>)Class.forName(stepXmlBean.getClassName()), stepXmlBean.isRequired());

                    }
                }<commit_msg>fixed defect to not make steps required by default<commit_after>package org.codepond.wizardroid.layouts;

import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.softvelopment.wizardroid.activity.ActivityConstants;

import org.codepond.wizardroid.R;
import org.codepond.wizardroid.WizardFlow;
import org.codepond.wizardroid.WizardStep;
import org.codepond.wizardroid.WizardValidatable;
import org.codepond.wizardroid.helper.WizardStepXmlBean;
import org.codepond.wizardroid.helper.WizardXmlBean;
import org.codepond.wizardroid.helper.impl.WizardStepXmlBeanImpl;
import org.codepond.wizardroid.helper.impl.WizardXmlBeanImpl;
import org.codepond.wizardroid.helper.util.WizardStepXmlBeanComparator;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;

/**
 * Created by softvelopment on 7/3/15.
 *
 *  This class builds on the BasicWizardLayout class with the following
 *  improvements
 *
 *  Child claases that inherit from this should not have to implement/override
 *  onSetup() but should just override 2 methods
 *
 *  getWizardName  The name of the wizard in the wizard xml file
 *  getWizardFileResourceId  The id of the wizard file resource
 *
 */
public abstract class SoftvelopmentWizardLayout extends BasicWizardLayout implements WizardValidatable{

    private static final String TAG = SoftvelopmentWizardLayout.class.getSimpleName();

    public abstract String getWizardName();
    public abstract int getWizardFileResourceId();

    protected int width=0;
    protected int height=0;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View wizardLayout = super.onCreateView(inflater,container,savedInstanceState);
        if((width > 0) &&(height >0 ))
        {
            RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(width, height);
            wizardLayout.setLayoutParams(p);
            wizardLayout.requestLayout();
        }
        return wizardLayout;
    }

    @Override
    public WizardFlow onSetup()
    {
        if(this.getActivity() != null)
        {
            try {
                return buildWizard(getWizardName(), getActivity().getResources().openRawResource(getWizardFileResourceId()));
            }
            catch(XmlPullParserException xppe)
            {
                Log.e(TAG, "Unable to create wizard with name " + getWizardName(),xppe);
            }
            catch(IOException ioe)
            {
                Log.e(TAG, "Unable to create wizard with name " + getWizardName(),ioe);
            }
        }
        return null;
    }

    public WizardFlow buildWizard(String wizardName, InputStream instream)throws IOException, XmlPullParserException
    {
        WizardXmlBean wizardXmlBean = loadWizardFromXml(wizardName, instream);
        WizardFlow wizardFlow = null;
        if(wizardXmlBean != null)
        {

            WizardFlow.Builder wizardFlowBuilder = new WizardFlow.Builder();
            if((wizardXmlBean.getWizardFlowXmlBean().getWizardSteps() != null) &&(wizardXmlBean.getWizardFlowXmlBean().getWizardSteps().size()>0))
            {
                try {
                    //sort the wizard steps
                    Collections.sort(wizardXmlBean.getWizardFlowXmlBean().getWizardSteps(), new WizardStepXmlBeanComparator());
                    for(WizardStepXmlBean stepXmlBean:wizardXmlBean.getWizardFlowXmlBean().getWizardSteps())
                    {

                        wizardFlowBuilder.addStep((Class<? extends WizardStep>)Class.forName(stepXmlBean.getClassName()));

                    }
                }
{'fraction_non_alphanumeric': 0.08584015103838892, 'fraction_numerical': 0.0032724984266834485, 'mean_word_length': 3.1667540639748295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2897407', 'n_tokens_mistral': 2256, 'n_tokens_neox': 2156, 'n_words': 459}