Android : Record every touch in WebView including touching JavaScript elements. Android

on Sunday, August 31, 2014


So, what I am trying to do is to make a semi-automatic page monitor which alerts user when some part of screen has changed, and the biggest benefit of my app is that user can record some actions because some login or register forms are changing by clicking JavaScript element, not just by refreshing. What I've done so far is that I made zoomable WebView and programmed a button which starts and stops touch movement recording. Everything works like a charm, except when user presses JavaScript spinner. When it appears, my app stops recording touches, and also, android layout buttons hide. So, what I want to do is to force my touch recording system to respond to every possible element, event it 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 press on B spinner appears, and when you change different element from it, all page refreshes. As you can see there are three buttons on the bottom, and the middle one called Seka records touches.


http://i.stack.imgur.com/UJxjg.png


There is spinner that I've talked before. Ignore toast message


http://i.stack.imgur.com/ekWTo.png


Thanks in advance ! :)


0 comments:

Post a Comment