package net.yaht.m.tryview;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 *
 * Created by lisp on ...
 *
 */

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        // Part I, default usage - using Android Layout Manager (and compiled .xml resources);
        setContentView(R.layout.empty_linear);

        // Part II, constructing layout with code;
        // makeLayoutWithCode();

        // Part III, let's go through RoundB.java and it's Custom component logic (roundb_linear.xml);

        // Part III.5, RoundB with code;
        // makeRoundBWithCode();

    }

    protected void makeLayoutWithCode() {

        // NOTE: lets make our labels (i.e. view objects)...
        TextView _lm_lbl_1 = new TextView(this);
        _lm_lbl_1.setText("Label, Mixed 1, Code");
        _lm_lbl_1.setBackgroundColor(Color.parseColor("#00ff00"));

        TextView _lm_lbl_2 = new TextView(this);
        _lm_lbl_2.setText("Label, Mixed 2, Code");
        _lm_lbl_2.setBackgroundColor(Color.parseColor("#00ffff"));

        TextView _lm_lbl_3 = new TextView(this);
        _lm_lbl_3.setText("Label, Mixed 3, Code");
        _lm_lbl_3.setBackgroundColor(Color.parseColor("#ffff00"));

        // NOTE: default linear layout params;
        LinearLayout _ll_container = new LinearLayout(this);
        _ll_container.setOrientation(LinearLayout.VERTICAL);

        LinearLayout.LayoutParams _ll_params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT
        );
        _ll_container.setLayoutParams(_ll_params);

        // NOTE: specific view params (for every single view in layout);
        LinearLayout.LayoutParams _lm_lbl_1_layout_params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
        );
        _lm_lbl_1_layout_params.gravity = Gravity.RIGHT;
        _lm_lbl_1.setLayoutParams(_lm_lbl_1_layout_params);

        // NOTE: this one wraps content
        _ll_container.addView(_lm_lbl_1);

        // NOTE: the 2nd one doesn't, i.e. follows parent layout definitions (MATCH_PARENT)...
        _ll_container.addView(_lm_lbl_2);

        // NOTE: can we try with Relative Layout code construction!? :)
        // setContentView(R.layout.<name>) is more convenient way according to me?

        setContentView(_ll_container);
    }

    protected void makeRoundBWithCode() {

        // NOTE: default layout params - linear, vertical;
        LinearLayout _ll_container = new LinearLayout(this);
        _ll_container.setOrientation(LinearLayout.VERTICAL);

        LinearLayout.LayoutParams _ll_params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT
        );
        _ll_container.setLayoutParams(_ll_params);

        // our custom component...
        RoundB _rb = new RoundB(this);

        LinearLayout.LayoutParams _rb_layout_params = new LinearLayout.LayoutParams(
                100,
                100
        );
        _rb_layout_params.gravity = Gravity.CENTER;
        _rb.setLayoutParams(_rb_layout_params);

        // component to container
        _ll_container.addView(_rb);;

        setContentView(_ll_container);

    }

}