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.JSONException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
@ -263,10 +264,7 @@ public class IITC_JSInterface {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
// activate clicked layer
((IITC_Mobile) mContext).getWebView().loadUrl("javascript: " +
"window.layerChooser.showLayer("
+ mLayerIds.get(mOverlayLayers[which]) + ","
+ isChecked + ");");
showLayer(mLayerIds.get(mOverlayLayers[which]), isChecked);
}
};
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
mOverlayIsActive[j] = disable;
list.setItemChecked(j, disable);
((IITC_Mobile) mContext).getWebView().loadUrl("javascript: " +
"window.layerChooser.showLayer("
+ mLayerIds.get(layer) + ","
+ disable + ");");
showLayer(mLayerIds.get(layer), disable);
}
++j;
}
@ -317,10 +312,7 @@ public class IITC_JSInterface {
@Override
public void onClick(DialogInterface dialog, int which) {
// activate clicked layer
((IITC_Mobile) mContext).getWebView().loadUrl("javascript: " +
"window.layerChooser.showLayer("
+ mLayerIds.get(mBaseLayers[which]) + ","
+ true + ");");
showLayer(mLayerIds.get(mBaseLayers[which]), true);
mActiveBaseLayer = which;
}
};
@ -344,4 +336,15 @@ public class IITC_JSInterface {
final AlertDialog dialog = d_s.create();
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 + ");");
}
});
}
}