handle edit-text events correctly

This commit is contained in:
Philipp Schaefer
2013-05-09 13:20:38 +02:00
parent 77010fc8ed
commit 2e50b4fedd
2 changed files with 10 additions and 32 deletions

View File

@ -20,11 +20,9 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Rect;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Toast; import android.widget.Toast;
@ -37,7 +35,6 @@ public class IITC_Mobile extends Activity {
private boolean user_loc = false; private boolean user_loc = false;
private LocationManager loc_mngr = null; private LocationManager loc_mngr = null;
private LocationListener loc_listener = null; private LocationListener loc_listener = null;
private boolean keyboad_open = false;
private boolean fullscreen_mode = false; private boolean fullscreen_mode = false;
private boolean fullscreen_actionbar = false; private boolean fullscreen_actionbar = false;
private ActionBar actionBar; private ActionBar actionBar;
@ -81,30 +78,6 @@ public class IITC_Mobile extends Activity {
}; };
sharedPref.registerOnSharedPreferenceChangeListener(listener); sharedPref.registerOnSharedPreferenceChangeListener(listener);
// we need this one to prevent location updates to javascript when
// keyboard is open
// it closes on updates
iitc_view.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
// r will be populated with the coordinates of your view
// that area still visible.
iitc_view.getWindowVisibleDisplayFrame(r);
int screenHeight = iitc_view.getRootView().getHeight();
int heightDiff = screenHeight - (r.bottom - r.top);
boolean visible = heightDiff > screenHeight / 3;
if (visible == true) {
Log.d("iitcm", "Open Keyboard...");
IITC_Mobile.this.keyboad_open = true;
} else {
Log.d("iitcm", "Close Keyboard...");
IITC_Mobile.this.keyboad_open = false;
}
}
});
// Acquire a reference to the system Location Manager // Acquire a reference to the system Location Manager
loc_mngr = (LocationManager) this loc_mngr = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE); .getSystemService(Context.LOCATION_SERVICE);
@ -359,11 +332,9 @@ public class IITC_Mobile extends Activity {
// throw away all positions with accuracy > 100 meters // throw away all positions with accuracy > 100 meters
// should avoid gps glitches // should avoid gps glitches
if (loc.getAccuracy() < 100) { if (loc.getAccuracy() < 100) {
if (keyboad_open == false) { iitc_view.loadUrl("javascript: "
iitc_view.loadUrl("javascript: " + "window.plugin.userLocation.updateLocation( "
+ "window.plugin.userLocation.updateLocation( " + loc.getLatitude() + ", " + loc.getLongitude() + ");");
+ loc.getLatitude() + ", " + loc.getLongitude() + ");");
}
} }
} }

View File

@ -73,6 +73,13 @@ public class IITC_WebView extends WebView {
@Override @Override
public void loadUrl(String url) { public void loadUrl(String url) {
// if in edit text mode, don't load javascript otherwise the keyboard closes.
HitTestResult testResult = this.getHitTestResult();
if (url.startsWith("javascript:") && testResult != null && testResult.getType() == HitTestResult.EDIT_TEXT_TYPE)
{
Log.d("iitcm", "in insert mode. do not load script.");
return;
}
if (!url.startsWith("javascript:")) { if (!url.startsWith("javascript:")) {
// force https if enabled in settings // force https if enabled in settings
SharedPreferences sharedPref = PreferenceManager SharedPreferences sharedPref = PreferenceManager