Runt
2022-05-04 27f180efca808046df3f3e917ee5f98d2d54849b
app/src/main/java/com/auto/lyric/service/FloatingWindowService.java
@@ -22,6 +22,7 @@
import androidx.annotation.Nullable;
import com.auto.lyric.R;
import com.auto.lyric.data.LyricObject;
import com.auto.lyric.data.LyricServer;
import com.auto.lyric.databinding.FloatViewBinding;
import com.auto.lyric.util.DeviceUtil;
@@ -195,6 +196,36 @@
        Log.e(TAG,"onStartCommand flags:"+flags+" startId:"+startId+ " intent:"+intent);
        manager.addView(binding.getRoot(),params);
        binding.lyric.setTextSize();
        binding.lyric.setOnTouchListener(new View.OnTouchListener() {
            float touchY; //当触摸歌词View时,保存为当前触点的Y轴坐标
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                float tt=event.getY();
                switch(event.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        break;
                    case MotionEvent.ACTION_MOVE:
                        touchY=tt-touchY;
                        binding.lyric.setOffsetY(binding.lyric.getOffsetY()+touchY);
                        Log.e("LyricView","offsety:"+binding.lyric.getOffsetY());
                        binding.lyric.invalidate();
                        break;
                    case MotionEvent.ACTION_UP:
                        if(binding.btnStart.getText().equals("开启") || pause) {
                            int index = binding.lyric.getIndexFromOffsetY(binding.lyric.getOffsetY());
                            binding.lyric.setIndex(index);
                            binding.lyric.setOffsetY(220 - index * (binding.lyric.getSIZEWORD() + 44));
                            LyricObject object = LyricServer.getLrc_map().get(index);
                            Log.e("LyricView", "object:" + object);
                            progress = object.begintime;
                            binding.lyric.invalidate();
                        }
                        break;
                }
                touchY=tt;
                return true;
            }
        });
        return super.onStartCommand(intent, flags, startId);
    }