/*
 * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
 */
package kr.co.zumo.app.lifeplus.view.custom;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import kr.co.zumo.app.R;
import kr.co.zumo.app.lifeplus.util.StringUtil;

/**
 * SignUpButtonView
 *
 * layout 대신 style (SignUpButton) 을 이용한다.
 * 참고를 위해서 남겨둠.
 *
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 10. 2.]   [최초 작성]
 * @since 2018. 10. 2.
 */
@Deprecated
public class SignUpButtonView extends FrameLayout {

  protected String label;
  TextView labelText;
  View backgroundView;

  public SignUpButtonView(@NonNull Context context) {
    super(context);
    init(context, null);
  }

  public SignUpButtonView(@NonNull Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    init(context, attrs);
  }

  public SignUpButtonView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init(context, attrs);
  }


  @SuppressLint("ResourceType")
  private void init(Context context, AttributeSet attrs) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.sign_up_button_view, this);

    labelText = findViewById(R.id.text_view);
    backgroundView = findViewById(R.id.layout_background);

    int[] set = {
      android.R.attr.text        // idx 0
    };

    TypedArray a = context.obtainStyledAttributes(attrs, set);

    try {
      label = (String) a.getText(0);
    } finally {
      a.recycle();
    }

  }

  @Override
  protected void onFinishInflate() {
    super.onFinishInflate();

    if (StringUtil.isFull(label)) {
      labelText.setText(label);
    }

  }

  @Override
  public void setEnabled(boolean isEnable) {
    super.setEnabled(isEnable);
    backgroundView.setEnabled(isEnable);
    labelText.setEnabled(isEnable);
  }
}
