21
21
import android .graphics .Color ;
22
22
import android .graphics .drawable .Drawable ;
23
23
import android .os .Bundle ;
24
+ import android .view .KeyEvent ;
24
25
import android .view .Menu ;
25
26
import android .view .MenuItem ;
26
27
import android .view .MotionEvent ;
27
28
import android .view .View ;
28
29
import android .view .ViewGroup ;
30
+ import android .view .inputmethod .EditorInfo ;
29
31
import android .webkit .ConsoleMessage ;
30
32
import android .webkit .WebChromeClient ;
31
33
import android .webkit .WebView ;
34
+ import android .widget .EditText ;
32
35
import android .widget .LinearLayout ;
33
36
import android .widget .PopupMenu ;
34
37
import android .widget .ScrollView ;
@@ -40,6 +43,7 @@ public class WebViewActivity extends BaseActivity {
40
43
private WebView webview ;
41
44
private LinearLayout consoleView ;
42
45
private ScrollView console_content ;
46
+ private EditText executeCodeInWebView ;
43
47
44
48
@ Override
45
49
protected void onCreate (Bundle savedInstanceState ) {
@@ -98,6 +102,22 @@ public boolean onConsoleMessage(ConsoleMessage console) {
98
102
&& getIntent ().getStringExtra ("type" ).equals ("file" )) {
99
103
webview .loadUrl ("file:" .concat (getIntent ().getStringExtra ("data" )));
100
104
}
105
+
106
+ executeCodeInWebView = findViewById (R .id .execute );
107
+ executeCodeInWebView .setOnEditorActionListener (
108
+ new TextView .OnEditorActionListener () {
109
+ @ Override
110
+ public boolean onEditorAction (TextView edittext , int action , KeyEvent event ) {
111
+ if (action == EditorInfo .IME_ACTION_DONE
112
+ || event .getAction () == KeyEvent .ACTION_DOWN
113
+ && event .getKeyCode () == KeyEvent .KEYCODE_ENTER ) {
114
+ webview .loadUrl ("javascript:" .concat (edittext .getText ().toString ()));
115
+ return true ;
116
+ }
117
+ return false ;
118
+ }
119
+ });
120
+
101
121
findViewById (R .id .console_slider )
102
122
.setOnTouchListener (
103
123
new View .OnTouchListener () {
@@ -159,7 +179,9 @@ public boolean onOptionsItemSelected(MenuItem arg0) {
159
179
item -> {
160
180
switch (item .getTitle ().toString ()) {
161
181
case "Clear Console Log" :
162
- consoleView .removeAllViews ();
182
+ if (consoleView != null ) {
183
+ consoleView .removeAllViews ();
184
+ }
163
185
break ;
164
186
}
165
187
return true ;
0 commit comments