package com.xunao.effectdemo.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.xunao.effectdemo.R;
import com.xunao.effectdemo.adapter.WordCutAdapter;

import java.util.ArrayList;
import java.util.List;

public class WordCutActivity extends Activity {
    private final String TAG = "WordCutActivity";

    private List<String> wordList = new ArrayList<>();
    private LinearLayout llWordCut;
    private RecyclerView rvWordCut;
    private WordCutAdapter wordCutAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_word_cut);
        llWordCut = findViewById(R.id.ll_word_cut);
        llWordCut.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()){
                    case MotionEvent.ACTION_MOVE:
                        Log.i(TAG, "X:" + event.getX() + ",Y:" + event.getY());
                        break;
                }
                return true;
            }
        });
        rvWordCut = findViewById(R.id.rv_word_cut);

        wordList.add("b");
        wordList.add("u");
        wordList.add("r");
        wordList.add("g");
        wordList.add("b");
        wordList.add("u");
        wordList.add("r");
        wordList.add("g");
        wordList.add("e");
        wordList.add("r");
        wordList.add("e");
        wordList.add("r");
        wordList.add("b");

        // 设置横向布局
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false){
            @Override
            public boolean canScrollHorizontally() {
                return false;
            }
        };
        rvWordCut.setLayoutManager(linearLayoutManager);
        wordCutAdapter = new WordCutAdapter(wordList, this);
        rvWordCut.setAdapter(wordCutAdapter);

        if(wordCutAdapter.getItemCount() > 0) {
            RecyclerView.ViewHolder holder = rvWordCut.findViewHolderForAdapterPosition(0);
            if (holder != null && holder instanceof WordCutAdapter.ViewHolder) {
                WordCutAdapter.ViewHolder viewHolder = (WordCutAdapter.ViewHolder) holder;
                int[] location = new int[2];
                viewHolder.llSlideArea.getLocationOnScreen(location);
                Log.i(TAG, "---x:" + location[0] + ",y:" + location[1]);
                //使用坐标
            }else{
                Log.i(TAG, "yichang");
            }
        }else{
            Log.i(TAG, "未完成");
        }
    }
}