View factory @type arg1: ClassType or dict @type arg2: View instance or AdbClient
(arg1, arg2, version=-1, forceviewserveruse=False, windowId=None, uiAutomatorHelper=None)
| 176 | |
| 177 | @staticmethod |
| 178 | def factory(arg1, arg2, version=-1, forceviewserveruse=False, windowId=None, uiAutomatorHelper=None): |
| 179 | """ |
| 180 | View factory |
| 181 | |
| 182 | @type arg1: ClassType or dict |
| 183 | @type arg2: View instance or AdbClient |
| 184 | """ |
| 185 | |
| 186 | if DEBUG_VIEW_FACTORY: |
| 187 | print("View.factory(%s, %s, %s, %s, %s, %s)" % ( |
| 188 | arg1, arg2, version, forceviewserveruse, windowId, uiAutomatorHelper), file=sys.stderr) |
| 189 | if type(arg1) == type: |
| 190 | cls = arg1 |
| 191 | attrs = None |
| 192 | else: |
| 193 | cls = None |
| 194 | attrs = arg1 |
| 195 | if isinstance(arg2, View): |
| 196 | view = arg2 |
| 197 | device = None |
| 198 | else: |
| 199 | device = arg2 |
| 200 | view = None |
| 201 | |
| 202 | if attrs and 'class' in attrs: |
| 203 | clazz = attrs['class'] |
| 204 | if DEBUG_VIEW_FACTORY: |
| 205 | print(" View.factory: creating View with specific class: %s" % clazz, file=sys.stderr) |
| 206 | if clazz == 'android.widget.TextView': |
| 207 | return TextView(attrs, device, version, forceviewserveruse, windowId, uiAutomatorHelper) |
| 208 | elif clazz == 'android.widget.EditText': |
| 209 | return EditText(attrs, device, version, forceviewserveruse, windowId, uiAutomatorHelper) |
| 210 | elif clazz == 'android.widget.ListView': |
| 211 | return ListView(attrs, device, version, forceviewserveruse, windowId, uiAutomatorHelper) |
| 212 | else: |
| 213 | return View(attrs, device, version, forceviewserveruse, windowId, uiAutomatorHelper) |
| 214 | elif cls: |
| 215 | if view: |
| 216 | return cls.__copy(view) |
| 217 | else: |
| 218 | return cls(attrs, device, version, forceviewserveruse, windowId, uiAutomatorHelper) |
| 219 | elif view: |
| 220 | return copy.copy(view) |
| 221 | else: |
| 222 | if DEBUG_VIEW_FACTORY: |
| 223 | print(" View.factory: creating generic View", file=sys.stderr) |
| 224 | return View(attrs, device, version, forceviewserveruse, windowId, uiAutomatorHelper) |
| 225 | |
| 226 | @classmethod |
| 227 | def __copy(cls, view): |