call WebView method in UI thread (thx for the hint fkloft)

This commit is contained in:
Philipp Schaefer 2013-09-05 18:34:12 +02:00
parent a4d6107235
commit c89fe648f8

View File

@ -5,6 +5,7 @@ import java.util.HashMap;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
@ -263,10 +264,7 @@ public class IITC_JSInterface {
@Override @Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) { public void onClick(DialogInterface dialog, int which, boolean isChecked) {
// activate clicked layer // activate clicked layer
((IITC_Mobile) mContext).getWebView().loadUrl("javascript: " + showLayer(mLayerIds.get(mOverlayLayers[which]), isChecked);
"window.layerChooser.showLayer("
+ mLayerIds.get(mOverlayLayers[which]) + ","
+ isChecked + ");");
} }
}; };
d_m.setMultiChoiceItems(mOverlayLayers, mOverlayIsActive, m_listener); d_m.setMultiChoiceItems(mOverlayLayers, mOverlayIsActive, m_listener);
@ -297,10 +295,7 @@ public class IITC_JSInterface {
// uncheck the item + set the boolean in the isActive array // uncheck the item + set the boolean in the isActive array
mOverlayIsActive[j] = disable; mOverlayIsActive[j] = disable;
list.setItemChecked(j, disable); list.setItemChecked(j, disable);
((IITC_Mobile) mContext).getWebView().loadUrl("javascript: " + showLayer(mLayerIds.get(layer), disable);
"window.layerChooser.showLayer("
+ mLayerIds.get(layer) + ","
+ disable + ");");
} }
++j; ++j;
} }
@ -317,10 +312,7 @@ public class IITC_JSInterface {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
// activate clicked layer // activate clicked layer
((IITC_Mobile) mContext).getWebView().loadUrl("javascript: " + showLayer(mLayerIds.get(mBaseLayers[which]), true);
"window.layerChooser.showLayer("
+ mLayerIds.get(mBaseLayers[which]) + ","
+ true + ");");
mActiveBaseLayer = which; mActiveBaseLayer = which;
} }
}; };
@ -344,4 +336,15 @@ public class IITC_JSInterface {
final AlertDialog dialog = d_s.create(); final AlertDialog dialog = d_s.create();
dialog.show(); dialog.show();
} }
private void showLayer(final String id, final boolean enable) {
((Activity) mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
((IITC_Mobile) mContext).getWebView().loadUrl("javascript: " +
"window.layerChooser.showLayer("
+ id + "," + enable + ");");
}
});
}
} }