• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.monkeyrunner;
17 
18 import com.google.common.base.Preconditions;
19 
20 import com.android.chimpchat.core.IChimpView;
21 
22 import com.android.monkeyrunner.doc.MonkeyRunnerExported;
23 
24 import org.python.core.ArgParser;
25 import org.python.core.ClassDictInit;
26 import org.python.core.PyBoolean;
27 import org.python.core.PyInteger;
28 import org.python.core.PyList;
29 import org.python.core.PyObject;
30 import org.python.core.PyString;
31 
32 import java.util.List;
33 import java.util.logging.Logger;
34 
35 /*
36  * Jython wrapper for the ChimpView class
37  */
38 @MonkeyRunnerExported(doc = "Represents a view object.")
39 public class MonkeyView extends PyObject implements ClassDictInit {
40     private static final Logger LOG = Logger.getLogger(MonkeyView.class.getName());
41 
42     private IChimpView impl;
43 
classDictInit(PyObject dict)44     public static void classDictInit(PyObject dict) {
45         JythonUtils.convertDocAnnotationsForClass(MonkeyView.class, dict);
46     }
47 
MonkeyView(IChimpView impl)48     public MonkeyView(IChimpView impl) {
49         this.impl = impl;
50     }
51 
52     @MonkeyRunnerExported(doc = "Get the checked status of the view",
53                           returns = "A boolean value for whether the item is checked or not")
getChecked(PyObject[] args, String[] kws)54     public PyBoolean getChecked(PyObject[] args, String[] kws) {
55         ArgParser ap = JythonUtils.createArgParser(args, kws);
56         Preconditions.checkNotNull(ap);
57         return new PyBoolean(impl.getChecked());
58     }
59 
60     @MonkeyRunnerExported(doc = "Returns the class name of the view",
61                           returns = "The class name of the view as a string")
getViewClass(PyObject[] args, String[] kws)62     public PyString getViewClass(PyObject[] args, String[] kws) {
63         ArgParser ap = JythonUtils.createArgParser(args, kws);
64         Preconditions.checkNotNull(ap);
65         return new PyString(impl.getViewClass());
66     }
67 
68     @MonkeyRunnerExported(doc = "Returns the text contained by the view",
69                           returns = "The text contained in the view")
getText(PyObject[] args, String[] kws)70     public PyString getText(PyObject[] args, String[] kws) {
71         ArgParser ap = JythonUtils.createArgParser(args, kws);
72         Preconditions.checkNotNull(ap);
73         return new PyString(impl.getText());
74     }
75 
76     @MonkeyRunnerExported(doc = "Returns the location of the view in the form of a MonkeyRect",
77                           returns = "The location of the view as a MonkeyRect object")
getLocation(PyObject[] args, String[] kws)78     public MonkeyRect getLocation(PyObject[] args, String[] kws) {
79         ArgParser ap = JythonUtils.createArgParser(args, kws);
80         Preconditions.checkNotNull(ap);
81         return new MonkeyRect(impl.getLocation());
82     }
83 
84     @MonkeyRunnerExported(doc = "Returns the enabled status of the view",
85                           returns = "The enabled status of the view as a boolean")
getEnabled(PyObject[] args, String[] kws)86     public PyBoolean getEnabled(PyObject[] args, String[] kws) {
87         ArgParser ap = JythonUtils.createArgParser(args, kws);
88         Preconditions.checkNotNull(ap);
89         return new PyBoolean(impl.getEnabled());
90     }
91 
92     @MonkeyRunnerExported(doc = "Returns the selected status of the view",
93                           returns = "The selected status of the view as a boolean")
getSelected(PyObject[] args, String[] kws)94     public PyBoolean getSelected(PyObject[] args, String[] kws) {
95         ArgParser ap = JythonUtils.createArgParser(args, kws);
96         Preconditions.checkNotNull(ap);
97         return new PyBoolean(impl.getSelected());
98     }
99 
100     @MonkeyRunnerExported(doc = "Sets the selected status of the view",
101                           args = {"selected"},
102                           argDocs = { "The boolean value to set selected to" })
setSelected(PyObject[] args, String[] kws)103     public void setSelected(PyObject[] args, String[] kws) {
104         ArgParser ap = JythonUtils.createArgParser(args, kws);
105         Preconditions.checkNotNull(ap);
106 
107         PyBoolean pySelected = (PyBoolean) ap.getPyObject(0, new PyBoolean(false));
108         boolean selected = (Boolean) pySelected.__tojava__(Boolean.class);
109         impl.setSelected(selected);
110     }
111 
112     @MonkeyRunnerExported(doc = "Returns the focused status of the view",
113                           returns = "The focused status of the view as a boolean")
getFocused(PyObject[] args, String[] kws)114     public PyBoolean getFocused(PyObject[] args, String[] kws) {
115         ArgParser ap = JythonUtils.createArgParser(args, kws);
116         Preconditions.checkNotNull(ap);
117         return new PyBoolean(impl.getFocused());
118     }
119 
120     @MonkeyRunnerExported(doc = "Sets the focused status of the view",
121                           args = {"focused"},
122                           argDocs = { "The boolean value to set focused to" })
setFocused(PyObject[] args, String[] kws)123     public void setFocused(PyObject[] args, String[] kws) {
124         ArgParser ap = JythonUtils.createArgParser(args, kws);
125         Preconditions.checkNotNull(ap);
126 
127         PyBoolean pyFocused = (PyBoolean) ap.getPyObject(0, new PyBoolean(false));
128         boolean focused = (Boolean) pyFocused.__tojava__(Boolean.class);
129         impl.setFocused(focused);
130     }
131 
132     @MonkeyRunnerExported(doc = "Returns the parent of the current view",
133                           returns = "The parent of the view as a MonkeyView object")
getParent(PyObject[] args, String[] kws)134     public MonkeyView getParent(PyObject[] args, String[] kws) {
135         ArgParser ap = JythonUtils.createArgParser(args, kws);
136         Preconditions.checkNotNull(ap);
137         MonkeyView parent = new MonkeyView(impl.getParent());
138         return parent;
139     }
140 
141     @MonkeyRunnerExported(doc = "Returns the children of the current view",
142                           returns = "The children of the view as a list of MonkeyView objects")
getChildren(PyObject[] args, String[] kws)143     public PyList getChildren(PyObject[] args, String[] kws) {
144         ArgParser ap = JythonUtils.createArgParser(args, kws);
145         Preconditions.checkNotNull(ap);
146         List<IChimpView> chimpChildren = impl.getChildren();
147         PyList children = new PyList();
148         for (IChimpView child : chimpChildren) {
149             children.append(new MonkeyView(child));
150         }
151         return children;
152     }
153 
154     @MonkeyRunnerExported(doc = "Returns the accessibility ids of the current view",
155                           returns = "The accessibility ids of the view as a list of ints")
getAccessibilityIds(PyObject[] args, String[] kws)156     public PyList getAccessibilityIds(PyObject[] args, String[] kws) {
157         ArgParser ap = JythonUtils.createArgParser(args, kws);
158         Preconditions.checkNotNull(ap);
159         int[] ids = impl.getAccessibilityIds();
160         PyList pyIds = new PyList();
161         for (int i = 0; i < ids.length; i++) {
162             pyIds.append(new PyInteger(ids[i]));
163         }
164         return pyIds;
165     }
166 
167 }
168