本文整理汇总了Java中nl.siegmann.epublib.domain.SpineReference类的典型用法代码示例。如果您正苦于以下问题:Java SpineReference类的具体用法?Java SpineReference怎么用?Java SpineReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpineReference类属于nl.siegmann.epublib.domain包,在下文中一共展示了SpineReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBindViewHolder
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
@Override
public void onBindViewHolder(ChapterViewHolder holder, int position) {
CompositeDisposable compositeDisposable = new CompositeDisposable();
holder.binding.webview.loadUrl(BLANK_URL);
holder.binding.webview.setUrlInterceptor(strategy.urlInterceptor);
SpineReference spineReference = epub.getBook().getSpine().getSpineReferences().get(position);
holder.binding.webview.loadEpubPage(epub, spineReference, epubView.getSettings());
Bridge bridge = new Bridge();
holder.binding.webview.setInternalBridge(bridge);
handleLocation(position, holder.binding.webview);
bridge.xPath()
.doOnNext(xPath -> {
EpubLocation location = EpubLocation.fromXPath(strategy.getCurrentChapter(), xPath);
strategy.setCurrentLocation(location);
})
.subscribeWith(new BaseDisposableObserver<>())
.addTo(compositeDisposable);
}
示例2: displayEpub
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
@Override
public void displayEpub(final Epub epub, EpubLocation location) {
if (location instanceof EpubLocation.ChapterLocation) {
int chapter = ((EpubLocation.ChapterLocation) location).chapter();
SpineReference spineReference = epub.getBook().getSpine().getSpineReferences().get(chapter);
binding.webview.loadEpubPage(epub, spineReference, epubView.getSettings());
setCurrentChapter(chapter);
}
binding.webview.gotoLocation(location);
binding.webview.setUrlInterceptor(url -> epubView.shouldOverrideUrlLoading(url));
binding.webview.bindToSettings(settings);
InternalEpubBridge bridge = new InternalEpubBridge();
binding.webview.setInternalBridge(bridge);
bridge.xPath().subscribe(xPath -> {
setCurrentLocation(EpubLocation.fromXPath(getCurrentChapter(), xPath));
});
VerticalContentBinderHelper.bind(binding);
}
开发者ID:smartmobilefactory,项目名称:EpubReaderAndroid,代码行数:23,代码来源:SingleChapterVerticalEpubDisplayStrategy.java
示例3: getHtml
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
private static String getHtml(Epub epub, SpineReference reference, EpubViewSettings settings) throws IOException {
InputStream inputStream = epub.getResourceContent(reference.getResource());
String rawHtml;
try {
rawHtml = new String(IOUtil.toByteArray(inputStream), "UTF-8");
} finally {
inputStream.close();
}
String injectBeforeBody = buildLibraryInternalInjections()
+ injectJavascriptConstants(epub, reference)
+ buildCustomCssString(settings)
+ injectJavascriptStartCode(settings);
String injectAfterBody = buildCustomScripsString(settings);
// add custom scripts at the end of the body
// this makes sure the dom tree is already present when the scripts are executed
rawHtml = rawHtml.replaceFirst("<body>", "<body>" + injectBeforeBody);
rawHtml = rawHtml.replaceFirst("</body>", injectAfterBody + "</body>");
return rawHtml;
}
示例4: checkSpineReferences
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
private static List<SpineReference> checkSpineReferences(Spine spine) {
List<SpineReference> result = new ArrayList<SpineReference>(spine.size());
Resource previousResource = null;
for(SpineReference spineReference: spine.getSpineReferences()) {
if(spineReference.getResource() == null
|| StringUtils.isBlank(spineReference.getResource().getHref())) {
continue;
}
if(previousResource == null
|| spineReference.getResource() == null
|| ( ! (spineReference.getResource().getHref().equals(previousResource.getHref())))) {
result.add(spineReference);
}
previousResource = spineReference.getResource();
}
return result;
}
示例5: generateSpineFromResources
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
/**
* Creates a spine out of all resources in the resources.
* The generated spine consists of all XHTML pages in order of their href.
*
* @param resources
* @return a spine created out of all resources in the resources.
*/
private static Spine generateSpineFromResources(Resources resources) {
Spine result = new Spine();
List<String> resourceHrefs = new ArrayList<String>();
resourceHrefs.addAll(resources.getAllHrefs());
Collections.sort(resourceHrefs, String.CASE_INSENSITIVE_ORDER);
for (String resourceHref: resourceHrefs) {
Resource resource = resources.getByHref(resourceHref);
if (resource.getMediaType() == MediatypeService.NCX) {
result.setTocResource(resource);
} else if (resource.getMediaType() == MediatypeService.XHTML) {
result.addSpineReference(new SpineReference(resource));
}
}
return result;
}
示例6: EPubReaderAdapter
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
public EPubReaderAdapter(FragmentManager fm, List<SpineReference> spineReferences,
Book book, String epubFilename, boolean isSmilAvilable) {
super(fm);
this.mSpineReferences = spineReferences;
this.mBook = book;
this.mEpubFileName = epubFilename;
this.mIsSmilAvailable = isSmilAvilable;
}
示例7: loadEpubPage
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
public void loadEpubPage(Epub epub, SpineReference spineReference, EpubViewSettings settings) {
if (settings == null) {
return;
}
loadEpubCompositeDisposable.clear();
settings.anySettingHasChanged()
// reload html when some settings changed
.filter(setting -> setting == EpubViewSettings.Setting.CUSTOM_FILES)
.startWith(EpubViewSettings.Setting.CUSTOM_FILES)
.flatMap(setting -> EpubDisplayHelper.loadHtmlData(this, epub, spineReference, settings)
.toObservable())
.subscribeWith(new BaseDisposableObserver<>())
.addTo(loadEpubCompositeDisposable);
}
示例8: getView
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
@Override
public View getView(int position, ViewGroup parent) {
CompositeDisposable compositeDisposable = chapterDisposables.get(position);
if (compositeDisposable == null) {
chapterDisposables.append(position, new CompositeDisposable());
compositeDisposable = chapterDisposables.get(position);
}
ItemEpubVerticalContentBinding binding = ItemEpubVerticalContentBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
binding.webview.setUrlInterceptor(strategy.urlInterceptor);
SpineReference spineReference = epub.getBook().getSpine().getSpineReferences().get(position);
binding.webview.loadEpubPage(epub, spineReference, epubView.getSettings());
handleLocation(position, binding.webview);
binding.webview.bindToSettings(epubView.getSettings());
InternalEpubBridge bridge = new InternalEpubBridge();
binding.webview.setInternalBridge(bridge);
bridge.xPath()
.doOnNext(xPath -> {
EpubLocation location = EpubLocation.fromXPath(strategy.getCurrentChapter(), xPath);
chapterLocations.append(position, location);
strategy.setCurrentLocation(location);
})
.subscribeWith(new BaseDisposableObserver<>())
.addTo(compositeDisposable);
compositeDisposable.add(VerticalContentBinderHelper.bind(binding));
return binding.root;
}
示例9: loadHtmlData
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
@CheckResult
public static Completable loadHtmlData(WebView webView, Epub epub, SpineReference spineReference, EpubViewSettings settings) {
WeakReference<WebView> webViewWeakReference = new WeakReference<>(webView);
return Single.fromCallable(() -> EpubDisplayHelper.getHtml(epub, spineReference, settings))
.doOnSubscribe(disposable -> {
webViewWeakReference.get().setTag(spineReference);
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSuccess(html -> {
WebView webViewReference = webViewWeakReference.get();
if (webViewReference == null) {
return;
}
boolean isAttachedToWindow = true;
if (Build.VERSION.SDK_INT >= 19) {
isAttachedToWindow = webViewReference.isAttachedToWindow();
}
if (webViewReference.getTag() == spineReference && isAttachedToWindow) {
String basePath = Uri.fromFile(epub.getOpfPath()).toString() + "//";
webViewReference.loadDataWithBaseURL(
basePath,
html,
"text/html",
"UTF-8",
"about:chapter"
);
}
})
.toCompletable();
}
示例10: injectJavascriptConstants
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
private static String injectJavascriptConstants(Epub epub, SpineReference reference) {
int chapterPosition = getChapterPosition(epub, reference);
return "<script type=\"text/javascript\">\n"
+ "var epubChapter = {\n"
+ " index: " + chapterPosition + ",\n"
+ " id: \"" + reference.getResource().getId() + "\",\n"
+ " href: \"" + reference.getResource().getHref() + "\",\n"
+ " title: \"" + reference.getResource().getTitle() + "\"\n"
+ "}\n"
+ "</script>\n";
}
示例11: getChapterPosition
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
private static int getChapterPosition(Epub epub, SpineReference reference) {
List<SpineReference> spineReferences = epub.getBook().getSpine().getSpineReferences();
for (int i = 0; i < spineReferences.size(); i++) {
SpineReference spineReference = spineReferences.get(i);
//noinspection StringEquality
if (spineReference.getResourceId() == reference.getResourceId()) {
return i;
}
if (spineReference.getResourceId().equals(reference.getResourceId())) {
return i;
}
}
return 0;
}
示例12: getSpinePositionForTocReference
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
/**
* @return -1 if toc position not found
*/
public int getSpinePositionForTocReference(TOCReference tocReference) {
List<SpineReference> spineReferences = getBook().getSpine().getSpineReferences();
for (int i = 0; i < spineReferences.size(); i++) {
SpineReference spineReference = spineReferences.get(i);
if (tocReference.getResourceId().equals(spineReference.getResourceId())) {
return i;
}
}
return -1;
}
示例13: getTocPositionForSpineReference
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
/**
* @return -1 if spine position not found
*/
public int getTocPositionForSpineReference(SpineReference spineReference) {
List<SpineReference> spineReferences = getBook().getSpine().getSpineReferences();
for (int i = 0; i < spineReferences.size(); i++) {
SpineReference spineReference2 = spineReferences.get(i);
if (spineReference2.getResourceId().equals(spineReference.getResourceId())) {
return getTocPositionForSpinePosition(i);
}
}
return -1;
}
示例14: shouldOverrideUrlLoading
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
public boolean shouldOverrideUrlLoading(String url) {
if (url.startsWith(Uri.fromFile(epub.getLocation()).toString())) {
// internal chapter change url
List<SpineReference> spineReferences = epub.getBook().getSpine().getSpineReferences();
for (int i = 0; i < spineReferences.size(); i++) {
SpineReference spineReference = spineReferences.get(i);
if (url.endsWith(spineReference.getResource().getHref())) {
gotoLocation(EpubLocation.fromChapter(i));
return true;
}
}
// chapter not found
// can not open the url
return true;
}
if (urlInterceptor != null && urlInterceptor.shouldOverrideUrlLoading(url)) {
return true;
}
try {
// try to open url with external app
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
getContext().startActivity(intent);
} catch (Exception e) {
// ignore
}
// we never want to load a new url in the same webview
return true;
}
示例15: writeSpineItems
import nl.siegmann.epublib.domain.SpineReference; //导入依赖的package包/类
/**
* List all spine references
* @throws IOException
* @throws IllegalStateException
* @throws IllegalArgumentException
*/
private static void writeSpineItems(Spine spine, XmlSerializer serializer) throws IllegalArgumentException, IllegalStateException, IOException {
for(SpineReference spineReference: spine.getSpineReferences()) {
serializer.startTag(NAMESPACE_OPF, OPFTags.itemref);
serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.idref, spineReference.getResourceId());
if (! spineReference.isLinear()) {
serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.linear, OPFValues.no);
}
serializer.endTag(NAMESPACE_OPF, OPFTags.itemref);
}
}