package com.oo.eye.activity;

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.app.baselibrary.base.common.BaseActivity;
import com.oo.eye.EyeConfig;
import com.oo.eye.R;
import com.oo.eye.adapter.PopuAdapter;
import com.oo.eye.bean.StudentBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Date : 2018/8/28.
 * Author:  cxh
 */

public class SinglePeopleTestActivity extends BaseActivity {
    @BindView(R.id.begin_test)
    TextView mBeginTest;
    @BindView(R.id.selete_area_tv)
    TextView mSeleteAreaTv;
    @BindView(R.id.selete_area_lay)
    LinearLayout mSeleteAreaLay;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_singletest;
    }

    @Override
    protected void init() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.selete_area_lay, R.id.do_search, R.id.begin_test})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.selete_area_lay:
                showPopWindow();
                break;
            case R.id.do_search:
                break;
            case R.id.begin_test:
                ArrayList<StudentBean> list = new ArrayList<>();
                StudentBean student = new StudentBean();
                student.setRealname("游客");
                list.add(student);
                EyeConfig.getInstance().setStudents(list);
                startActivity(BeforeEyeTestActivity.class);
                break;
        }
    }

    private void showPopWindow() {
        try {
            View conview = View.inflate(this, R.layout.popu_list, null);
            PopupWindow popupWindow = new PopupWindow(conview, RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
            popupWindow.setFocusable(true);
            popupWindow.setOutsideTouchable(true);
            ColorDrawable cd = new ColorDrawable(0x00ffffff);// 背景颜色全透明
            popupWindow.setBackgroundDrawable(cd);
            ListView listView = (ListView) conview.findViewById(R.id.list_view);
            listView.setAdapter(new PopuAdapter(this,null));
            int[] location = new int[2];
            mSeleteAreaLay.getLocationOnScreen(location);
//            popupWindow.setAnimationStyle(R.style.style_pop_animation);// 动画效果必须放在showAsDropDown()方法上边，否则无效
            conview.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            int xoff = -(conview.getMeasuredWidth() / 2 - mSeleteAreaLay.getWidth() / 2);
            popupWindow.showAsDropDown(mSeleteAreaLay, xoff, 0);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
