.XML File
<RelativeLayout android:orientation="vertical"
android:layout_marginBottom="65dip" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<WebView android:id="@+id/WebView01" android:background="#77CC0000"
android:layout_height="260dip" android:scrollbars="vertical"
android:focusableInTouchMode="false" android:layout_width="fill_parent"
android:focusable="true" android:isScrollContainer="false"
android:layout_marginTop="50dip" android:layout_alignParentBottom="true"
android:visibility="gone" />
</RelativeLayout>
.Java File
mSilence.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
webView.setVisibility(View.VISIBLE);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new AndroidBridge(), "android");
webView.setVerticalScrollBarEnabled(false);
webView.loadUrl("file:///android_asset/index.html");
}
});
handler = new Handler() {
public void handleMessage(Message msg) {
go = msg.obj.toString();
Log.v("log_tag", "PASS " + msg.obj.toString()
+ " result will be shown" + go);
}
};
private class AndroidBridge {
public void sendResults(final String arg) {
Message msg = new Message();
msg.obj = arg;
handler.sendMessage(msg);
}
public void readyForJavascript(final String arg) {
webView.loadUrl("javascript:SpinningWheel.addSlot({"
+ "1:'1',2: '2',3: '3',4:'4',5:'5',6:'6',"
+ "7:'7',8:'8',9:'9',10:'10',11:'11',12:'12'});");
String slotText = null;
for (int i = 1; i <= 60; i++) {
slotText = slotText + Integer.toString(i) + ":'" + i + "', ";
}
// to remove the last comma
slotText = slotText.substring(0, slotText.length() - 2);
Log.v("log_tag", "Slot text line: " + slotText);
mHour = "javascript:SpinningWheel.addSlot({ " + slotText + "});";
Log.v("log_tag", "Final Slot text: " + mHour);
webView.loadUrl(mHour);
webView.loadUrl("javascript:SpinningWheel.addSlot({ "
+ "1: 'AM', 2: 'PM'});");
webView.loadUrl("javascript:SpinningWheel.open();");
}
}
<RelativeLayout android:orientation="vertical"
android:layout_marginBottom="65dip" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<WebView android:id="@+id/WebView01" android:background="#77CC0000"
android:layout_height="260dip" android:scrollbars="vertical"
android:focusableInTouchMode="false" android:layout_width="fill_parent"
android:focusable="true" android:isScrollContainer="false"
android:layout_marginTop="50dip" android:layout_alignParentBottom="true"
android:visibility="gone" />
</RelativeLayout>
.Java File
mSilence.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
webView.setVisibility(View.VISIBLE);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new AndroidBridge(), "android");
webView.setVerticalScrollBarEnabled(false);
webView.loadUrl("file:///android_asset/index.html");
}
});
handler = new Handler() {
public void handleMessage(Message msg) {
go = msg.obj.toString();
Log.v("log_tag", "PASS " + msg.obj.toString()
+ " result will be shown" + go);
}
};
private class AndroidBridge {
public void sendResults(final String arg) {
Message msg = new Message();
msg.obj = arg;
handler.sendMessage(msg);
}
public void readyForJavascript(final String arg) {
webView.loadUrl("javascript:SpinningWheel.addSlot({"
+ "1:'1',2: '2',3: '3',4:'4',5:'5',6:'6',"
+ "7:'7',8:'8',9:'9',10:'10',11:'11',12:'12'});");
String slotText = null;
for (int i = 1; i <= 60; i++) {
slotText = slotText + Integer.toString(i) + ":'" + i + "', ";
}
// to remove the last comma
slotText = slotText.substring(0, slotText.length() - 2);
Log.v("log_tag", "Slot text line: " + slotText);
mHour = "javascript:SpinningWheel.addSlot({ " + slotText + "});";
Log.v("log_tag", "Final Slot text: " + mHour);
webView.loadUrl(mHour);
webView.loadUrl("javascript:SpinningWheel.addSlot({ "
+ "1: 'AM', 2: 'PM'});");
webView.loadUrl("javascript:SpinningWheel.open();");
}
}
No comments:
Post a Comment