{- | Types used by the tool
-}
module Types(
-- * Types
-- ** Identification of the windows and views
ViewServerPort(..)
, WindowHash(..)
, ActivityName
-- ** Description of the windows and views
, Window
, View(..)
-- ** Configuration and output format
, Config(..)
, OutputFormat(..)
-- * Functions
, mkWindow
, windowHash
, activityName
, setViewProperty
, emptyView
, defaultConfig
) where
import System.Console.CmdTheLine.ArgVal
import Text.PrettyPrint
-- | Port ID
type ViewServerPort = Int
-- | Window hash generated by Android
type WindowHash = String
-- | Activity name
type ActivityName = String
-- | Output format
data OutputFormat = Raw -- ^ Raw text as generated
| Views
| Graphviz
| Opml
instance ArgVal OutputFormat where
pp Raw = text "raw"
pp Views = text "view"
pp Graphviz = text "graphviz"
pp Opml = text "opml"
parser "raw" = Right Raw
parser "view" = Right Views
parser "graphviz" = Right Graphviz
parser "opml" = Right Opml
parser _ = Left (text "Error parsing the output format")
-- | Configuration for a run of the tool
data Config = Config {
hostname :: String
, port :: ViewServerPort
, forward :: Bool
, mustListWindows :: Bool
, mustListViews :: Maybe WindowHash
, outputFormat :: OutputFormat
, outputFile :: Maybe FilePath
}
defaultConfig = Config {
hostname = "127.0.0.1"
, port = 4939
, forward = True
, mustListWindows = True
, mustListViews = Nothing
, outputFormat = Opml
, outputFile = Nothing
}
-- | Description of a window
data Window = W {windowHash :: !WindowHash, activityName :: !ActivityName} deriving(Eq,Read,Show)
mkWindow :: WindowHash -> ActivityName -> Window
mkWindow = W
type ViewID = String
-- | Description of a view
data View = V { mID :: ViewID
, top :: Int
, left :: Int
, height :: Int
, width :: Int
, scrollX :: Int
, scrollY :: Int
, paddingLeft :: Int
, paddingRight :: Int
, paddingTop :: Int
, paddingBottom :: Int
, marginLeft :: Int
, marginRight :: Int
, marginTop :: Int
, marginBottom :: Int
, baseline :: Int
, willNotDraw :: Bool
, hasFocus :: Bool
, layerType :: String
}
deriving(Eq,Show,Read)
emptyView = V { mID = ""
, top = 0
, left = 0
, height = 0
, width = 0
, scrollX = 0
, scrollY = 0
, paddingLeft = 0
, paddingRight = 0
, paddingTop = 0
, paddingBottom = 0
, marginLeft = minBound
, marginRight = minBound
, marginTop = minBound
, marginBottom = minBound
, baseline = 0
, willNotDraw = False
, hasFocus = False
, layerType ="NONE"
}
-- | Parse a view property and update the corresponding view field.
-- a property genrated by the view server is key=value converted to (key,value)
setViewProperty :: View -> (String,String) -> View
setViewProperty v ("layout:mLeft",theData) = v {left = read theData}
setViewProperty v ("layout:mTop",theData) = v {top = read theData}
setViewProperty v ("layout:getWidth()",theData) = v {width = read theData}
setViewProperty v ("layout:getHeight()",theData) = v {height = read theData}
setViewProperty v ("padding:mPaddingLeft",theData) = v {paddingLeft = read theData}
setViewProperty v ("padding:mPaddingRight",theData) = v {paddingRight = read theData}
setViewProperty v ("padding:mPaddingBottom",theData) = v {paddingBottom = read theData}
setViewProperty v ("padding:mPaddingTop",theData) = v {paddingTop = read theData}
setViewProperty v ("scrolling:mScrollX", theData) = v {scrollX = read theData}
setViewProperty v ("scrolling:mScrollY", theData) = v {scrollY = read theData}
setViewProperty v ("layout:layout_leftMargin",theData) = v {marginLeft = read theData}
setViewProperty v ("layout:layout_rightMargin",theData) = v {marginRight = read theData}
setViewProperty v ("layout:layout_bottomMargin",theData) = v {marginTop = read theData}
setViewProperty v ("layout:layout_topMargin",theData) = v {marginBottom = read theData}
setViewProperty v ("layout:getBaseline()",theData) = v {baseline = read theData}
setViewProperty v ("drawing:willNotDraw()","false") = v {willNotDraw = False}
setViewProperty v ("drawing:willNotDraw()","true") = v {willNotDraw = True}
setViewProperty v ("focus:hasFocus()","false") = v {hasFocus = False}
setViewProperty v ("focus:hasFocus()","true") = v {hasFocus = True}
setViewProperty v ("drawing:mLayerType",theData) = v {layerType = theData}
setViewProperty v _ = v