Comments (8)
Can I see some code?
Thanks,
Brandon
On Nov 2, 2012, at 3:55 AM, coder4567 [email protected] wrote:
hy,
I would like to thank u for this excellent webview selection, saved my life.
but I'm facing a small issue with the import.
When I use loadDataWithBaseURL the javascript import is not working,
any idea why?
I need to use loadDataWithBaseURL cause I'm making some modification to the html before loading it.
Thank u in advance for your time,—
Reply to this email directly or view it on GitHub.
from btandroidwebviewselection.
this is the method used:
public void loadSpineItemAtIndex(int spIndex) {
readingWV.loadData("", "text/html", "UTF-8");
spineLoading.show();
final int spine = spIndex;
// common unzip directory
new Thread(new Runnable() {
@Override
public void run() {
setChapterTitle("");
SpineItemRef spItem = bookSpine.getSpineItemRefWithOrder(spine);
ManifestItem manItem = bookManifest.getManifestItemWithId(spItem.getIdref());
String itemPath = bookContentsPath + "/" + manItem.getHref();
itemURL = "file://" + itemPath;
templateString = "";
File itemFile = new File(itemPath);
setPagingDimensions();
try {
org.jsoup.nodes.Document htmlDoc = Jsoup.parse(itemFile, "UTF-8");
Elements heads = htmlDoc.getElementsByTag("head");
Element head = heads.get(0);
String headString = head.toString();
headString = headString.substring("<head>".length());
int index = headString.indexOf("</head>");
headString = headString.substring(0, index);
String titleString = "";
try{
//attempt to get chapter title from <title> in <head>
Element title = head.getElementsByTag("title").get(0);
titleString = title.text();
} catch(Exception ex) {
ex.printStackTrace();
}
//get full path references to css files and edit them to be displayed correctly
Elements links = head.getElementsByTag("link");
for (Element link : links) {
String type = link.attr("type");
if (type.equalsIgnoreCase("text/css")) {
String href = link.attr("href");
if (href.startsWith("../")) {
href = href.substring(3);
}
String path = bookContentsPath + "/" + href;
path = URLDecoder.decode(path);
editCSSFileAtPath(path);
}
}
headString = headString + "<script src='jquery.js'></script>"+"<script src='rangy-core.js'></script>"+"<script src='rangy-serializer.js'></script>"+"<script src='android.selection.js'></script>";
Elements bodys = htmlDoc.getElementsByTag("body");
Element body = bodys.get(0);
String bodyString = body.toString();
bodyString = bodyString.substring("<body".length());
int aIndex = bodyString.indexOf(">");
bodyString = bodyString.substring(aIndex+1);
int bIndex = bodyString.indexOf("</body>");
bodyString = bodyString.substring(0, bIndex);
bodyString = bodyString.replaceAll("\n", " ");
//creating final html string to load into webview
templateString = getAssetsFileContents(getString(R.string.template_file));
templateString = templateString.replaceFirst("headplaceholder", headString);
String finalBody = "";
finalBody = "<div id='iReaderDiv'>" + bodyString+ "</div>";
templateString = templateString.replaceFirst("bodyplaceholder", finalBody);
} catch (Exception e) {
e.printStackTrace();
}
//////////////////////////////////////////////////////////////////////////////////
readingWV.post(new Runnable() {
@Override
public void run() {
readingWV.loadDataWithBaseURL(itemURL, templateString, "text/html", "UTF-8", null);
goToPage(readingWV.getCurrentPage());
spineLoading.hide();
}
});
}
}).start();
from btandroidwebviewselection.
public void loadSpineItemAtIndex(int spIndex) {
readingWV.loadData("", "text/html", "UTF-8");
spineLoading.show();
final int spine = spIndex;
// common unzip directory
new Thread(new Runnable() {
@Override
public void run() {
setChapterTitle("");
SpineItemRef spItem = bookSpine.getSpineItemRefWithOrder(spine);
ManifestItem manItem = bookManifest.getManifestItemWithId(spItem.getIdref());
String itemPath = bookContentsPath + "/" + manItem.getHref();
itemURL = "file://" + itemPath;
templateString = "";
content = "";
File itemFile = new File(itemPath);
setPagingDimensions();
try {
org.jsoup.nodes.Document htmlDoc = Jsoup.parse(itemFile, "UTF-8");
Elements heads = htmlDoc.getElementsByTag("head");
Element head = heads.get(0);
String headString = head.toString();
headString = headString.substring("<head>".length());
int index = headString.indexOf("</head>");
headString = headString.substring(0, index);
String titleString = "";
try{
//attempt to get chapter title from <title> in <head>
Element title = head.getElementsByTag("title").get(0);
titleString = title.text();
} catch(Exception ex) {
ex.printStackTrace();
}
//get full path references to css files and edit them to be displayed correctly
Elements links = head.getElementsByTag("link");
for (Element link : links) {
String type = link.attr("type");
if (type.equalsIgnoreCase("text/css")) {
String href = link.attr("href");
if (href.startsWith("../")) {
href = href.substring(3);
}
String path = bookContentsPath + "/" + href;
path = URLDecoder.decode(path);
editCSSFileAtPath(path);
}
}
headString = headString + "<script src='jquery.js'></script>"+"<script src='rangy-core.js'></script>"+"<script src='rangy-serializer.js'></script>"+"<script src='android.selection.js'></script>";
Elements bodys = htmlDoc.getElementsByTag("body");
Element body = bodys.get(0);
String bodyString = body.toString();
bodyString = bodyString.substring("<body".length());
int aIndex = bodyString.indexOf(">");
bodyString = bodyString.substring(aIndex+1);
int bIndex = bodyString.indexOf("</body>");
bodyString = bodyString.substring(0, bIndex);
bodyString = bodyString.replaceAll("\n", " ");
//creating final html string to load into webview
templateString = getAssetsFileContents(getString(R.string.template_file));
templateString = templateString.replaceFirst("headplaceholder", headString);
String finalBody = "";
finalBody = "<div id='iReaderDiv'>" + bodyString+ "</div>";
templateString = templateString.replaceFirst("bodyplaceholder", finalBody);
} catch (Exception e) {
e.printStackTrace();
}
//////////////////////////////////////////////////////////////////////////////////
readingWV.post(new Runnable() {
@Override
public void run() {
readingWV.loadDataWithBaseURL(itemURL, templateString, "text/html", "UTF-8", null);
goToPage(readingWV.getCurrentPage());
spineLoading.hide();
}
});
}
}).start();
from btandroidwebviewselection.
oh in the first line, there is some html that didn't show html body body /html
I removed the tags so it would show, thank u
from btandroidwebviewselection.
hy, look I'm not sure why the code is not showing, if u want give me ur mail and I can send it for u.
I will try one more time.
headString = headString + "<script type="text/javascript" src='jquery.js'></script>"+ "<script type="text/javascript" src='rangy-core.js'></script>" + "<script type=
"text/javascript" src='rangy-serializer.js'></script>" + "<script type="text/javascript" src='android.selection.js'></script>";
Elements bodys = htmlDoc.getElementsByTag("body");
Element body = bodys.get(0);
String bodyString = body.toString();
bodyString = bodyString.substring("<body".length());
int aIndex = bodyString.indexOf(">");
bodyString = bodyString.substring(aIndex+1);
int bIndex = bodyString.indexOf("");
bodyString = bodyString.substring(0, bIndex);
bodyString = bodyString.replaceAll("\n", " ");
//creating final html string to load into webview
templateString = getAssetsFileContents(getString(R.string.template_file));
templateString = templateString.replaceFirst("headplaceholder", headString);
String finalBody = "";
if (!readingWV.isBookLanguage()) { // arabic
finalBody = "
} else {
finalBody = "
}
templateString = templateString.replaceFirst("bodyplaceholder", finalBody);
//////////////////////////////////////////////////////////////////////////////////
readingWV.post(new Runnable() {
@OverRide
public void run() {
System.out.println("templateString"+templateString);
readingWV.loadDataWithBaseURL(itemURL, templateString, "text/html", "UTF-8", null);
from btandroidwebviewselection.
if I remove the content of templateString and put it in an html file in the assets and call loadUrl instead of loadDataWithBaseURL, the javascript content gets called, but I need to use loadDataWithBaseURL for I need to add the javascript file into the header.
Thanks in advance.
from btandroidwebviewselection.
the import worked finally, I had to use:
script type="text/javascript" src="file:///android_asset/jquery.js" script
script type="text/javascript" src="file:///android_asset/rangy-core.js" script
script type="text/javascript" src="file:///android_asset/rangy-serializer.js" script
script type="text/javascript" src="file:///android_asset/android.selection.js" script
instead of :
script src='jquery.js' script
script src='rangy-core.js' script
script src='rangy-serializer.js' script
script src='android.selection.js' script
I removed the tags so it can show.
from btandroidwebviewselection.
That makes sense. The files were using relative paths for the javascript imports.
On Nov 12, 2012, at 4:48 AM, coder4567 [email protected] wrote:
the import worked finally, I had to use:
script type="text/javascript" src="file:///android_asset/jquery.js" script
script type="text/javascript" src="file:///android_asset/rangy-core.js" script
script type="text/javascript" src="file:///android_asset/rangy-serializer.js" script
script type="text/javascript" src="file:///android_asset/android.selection.js" script
instead of :
script src='jquery.js' script
script src='rangy-core.js' script
script src='rangy-serializer.js' script
script src='android.selection.js' scriptI removed the tags so it can show.
—
Reply to this email directly or view it on GitHub.
from btandroidwebviewselection.
Related Issues (20)
- cursor not visible with gingerbread. HOT 6
- getting the html source from the selection HOT 7
- Selection in webview after zoom and get the selected word using js?
- jquery is not working when loading dynamically HOT 3
- Selection doesn't work on Samsung Galaxy S2 (Android 4.1.2) HOT 1
- how can I set the selection color? how can I change the color? HOT 2
- Add support for localization HOT 2
- Select text in complext web pages HOT 1
- License? HOT 1
- Not working as the data loaded from a web address.
- Not Properly working in Android KItkat HOT 3
- Not working on Galaxy S3
- Selection not working on Samsung Galaxy Tab2 HOT 5
- load Data method is not working HOT 2
- Arabic font problam HOT 1
- Selection works Very Slow
- Selection Problem on using loadDataWithBaseURL to load data HOT 2
- I dont know how to use BTAndroidWebView i tried BTWebView bt=new BTWebView(this); HOT 4
- CAB comes up context menu as well in lollipop device HOT 2
- Javascript call from WebView to Android and Vice Versa HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from btandroidwebviewselection.