Record every touch in the WebView, including touching JavaScript elements. Android
So I am trying to make a semi-automatic page monitor that alerts the user when some part of the screen has changed, and the biggest advantage of my application is that the user can record some actions because some login or form case changes when clicking a JavaScript element , not just renewing. What I have done so far is that I made a scalable WebView and programmed a button that starts and stops touch recording. Everything works like a charm, except when the user clicks a JavaScript counter. When it appears, my app stops recording touches and also hides the android layout buttons. So what I want to do is make my touch recording system respond to all possible elements, this event is written in JavaScript.Here is my code:
package com.example.automatikaandroidui;
import java.util.ArrayList;
import android.support.v7.app.ActionBarActivity;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.PointF;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements OnClickListener, OnTouchListener {
WebView webView;
Button mygtukasSeka;
boolean isPressed = false;
boolean halfWay = false;
boolean eile = false;
ArrayList<PointF> masyvas = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
masyvas = new ArrayList<PointF>();
webView = (WebView)findViewById(R.id.webView1);
webView.loadUrl("https://www.eregitra.lt/viesa/interv/Index.php");
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.setOnTouchListener(this);
mygtukasSeka = (Button)findViewById(R.id.mygtukas_seka);
mygtukasSeka.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.mygtukas_seka: {
TextView notify = (TextView)findViewById(R.id.ispek_irasyma);
if(!isPressed){
notify.setTextColor(Color.RED);
notify.setText("Įrašoma...");
isPressed = true;
}
else {
notify.setText("");
isPressed = false;
}
}
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getActionMasked()){
case MotionEvent.ACTION_DOWN : {
if(!halfWay && isPressed)
halfWay = true;
}
case MotionEvent.ACTION_UP : {
if(halfWay && isPressed){
PointF taskas = new PointF(event.getX(),event.getY());
masyvas.add(taskas);
halfWay = false;
Toast.makeText(MainActivity.this, taskas.x+" "+taskas.y, Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, masyvas.size()+"", Toast.LENGTH_SHORT).show();
}
}
}
if(isPressed){
if(eile)
eile = false;
else eile = true;
}
return eile;
}
}
And here are some screenshots: Here is the registration form. When you click on B the spinner will appear, and when you change another element from it, the whole page will refresh. As you can see, there are three buttons at the bottom and the second is Seka entries.
http://i.stack.imgur.com/UJxjg.png
There is the spinner I talked about earlier. Ignore the toast message
http://i.stack.imgur.com/ekWTo.png
Thanks in advance!:)
source to share
No one has answered this question yet
Check out similar questions: