# Path: android_env/components/action_type.py
# class ActionType(enum.IntEnum):
#   TOUCH = 0
#   LIFT = 1
#   REPEAT = 2
# 
# Path: android_env/components/utils.py
# def touch_position_to_pixel_position(
#     touch_position: np.ndarray,
#     width_height: Sequence[int],
# ) -> Tuple[int, int]:
# def transpose_pixels(frame: np.ndarray) -> np.ndarray:
# def orient_pixels(
#     frame: np.ndarray,
#     orientation: adb_pb2.AdbCall.Rotate.Orientation) -> np.ndarray:


import time
import android_env
import dm_env
import numpy as np
import pygame
from typing import Any, Dict
from absl import app
from absl import flags
from absl import logging
from android_env.components import action_type
from android_env.components import utils
from android_env.proto import adb_pb2
from android_env.proto import task_pb2
# Pygame args.
flags.DEFINE_list('screen_size', '480,720', 'Screen width, height in pixels.')
flags.DEFINE_float('frame_rate', 1.0/30.0, 'Frame rate in seconds.')

FLAGS = flags.FLAGS


def _get_action_from_event(
    event: pygame.event.Event,
    screen: pygame.Surface,
    orientation: adb_pb2.AdbCall.Rotate.Orientation) -> Dict[str, Any]:
  """Returns the current action by reading data from a pygame Event object."""

  act_type = action_type.ActionType.LIFT
  if event.type == pygame.MOUSEBUTTONDOWN:
    act_type = action_type.ActionType.TOUCH

  return {
      'action_type':
          np.array(act_type, dtype=np.int32),
      'touch_position':
          _scale_position(event.pos, screen, orientation),
  }


def _get_action_from_mouse(
    screen: pygame.Surface,
    orientation: adb_pb2.AdbCall.Rotate.Orientation) -> Dict[str, Any]:
  """Returns the current action by reading data from the mouse."""


# Path: android_env/components/action_type.py
# class ActionType(enum.IntEnum):
#   TOUCH = 0
#   LIFT = 1
#   REPEAT = 2
# 
# Path: android_env/components/utils.py
# def touch_position_to_pixel_position(
#     touch_position: np.ndarray,
#     width_height: Sequence[int],
# ) -> Tuple[int, int]:
# def transpose_pixels(frame: np.ndarray) -> np.ndarray:
# def orient_pixels(
#     frame: np.ndarray,
#     orientation: adb_pb2.AdbCall.Rotate.Orientation) -> np.ndarray:


# Path: examples/run_human_agent.py
import time
import android_env
import dm_env
import numpy as np
import pygame
from typing import Any, Dict
from absl import app
from absl import flags
from absl import logging
from android_env.components import action_type
from android_env.components import utils
from android_env.proto import adb_pb2
from android_env.proto import task_pb2

# Pygame args.
flags.DEFINE_list('screen_size', '480,720', 'Screen width, height in pixels.')
flags.DEFINE_float('frame_rate', 1.0/30.0, 'Frame rate in seconds.')

FLAGS = flags.FLAGS


def _get_action_from_event(
    event: pygame.event.Event,
    screen: pygame.Surface,
    orientation: adb_pb2.AdbCall.Rotate.Orientation) -> Dict[str, Any]:
  """Returns the current action by reading data from a pygame Event object."""

  act_type = action_type.ActionType.LIFT
  if event.type == pygame.MOUSEBUTTONDOWN:
    act_type = action_type.ActionType.TOUCH

  return {
      'action_type':
          np.array(act_type, dtype=np.int32),
      'touch_position':
          _scale_position(event.pos, screen, orientation),
  }


def _get_action_from_mouse(
    screen: pygame.Surface,
    orientation: adb_pb2.AdbCall.Rotate.Orientation) -> Dict[str, Any]:
  """Returns the current action by reading data from the mouse."""


  act_type = action_type.ActionType.LIFT