/* * Copyright (C) 2010-2013 Geometer Plus <contact@geometerplus.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ package org.geometerplus.android.fbreader; import org.geometerplus.android.fbreader.image.ImageViewActivity; import org.geometerplus.fbreader.bookmodel.FBHyperlinkType; import org.geometerplus.fbreader.fbreader.FBReaderApp; import org.geometerplus.zlibrary.text.view.ZLTextHyperlink; import org.geometerplus.zlibrary.text.view.ZLTextHyperlinkRegionSoul; import org.geometerplus.zlibrary.text.view.ZLTextImageRegionSoul; import org.geometerplus.zlibrary.text.view.ZLTextRegion; import org.geometerplus.zlibrary.text.view.ZLTextWordRegionSoul; import android.content.Intent; import android.net.Uri; import com.yamin.reader.activity.CoreReadActivity; public class ProcessHyperlinkAction extends FBAndroidAction { public ProcessHyperlinkAction(CoreReadActivity baseActivity, FBReaderApp fbreader) { super(baseActivity, fbreader); } @Override public boolean isEnabled() { return Reader.getTextView().getSelectedRegion() != null; } @Override protected void run(Object ... params) { final ZLTextRegion region = Reader.getTextView().getSelectedRegion(); if (region == null) { return; } final ZLTextRegion.Soul soul = region.getSoul(); if (soul instanceof ZLTextHyperlinkRegionSoul) { Reader.getTextView().hideSelectedRegionBorder(); Reader.getViewWidget().repaint(); final ZLTextHyperlink hyperlink = ((ZLTextHyperlinkRegionSoul)soul).Hyperlink; switch (hyperlink.Type) { case FBHyperlinkType.EXTERNAL: //openInBrowser(hyperlink.Id); break; case FBHyperlinkType.INTERNAL: Reader.Collection.markHyperlinkAsVisited(Reader.Model.Book, hyperlink.Id); Reader.tryOpenFootnote(hyperlink.Id); break; } } else if (soul instanceof ZLTextImageRegionSoul) { Reader.getTextView().hideSelectedRegionBorder(); Reader.getViewWidget().repaint(); final String url = ((ZLTextImageRegionSoul)soul).ImageElement.URL; if (url != null) { try { final Intent intent = new Intent(); intent.setClass(BaseActivity, ImageViewActivity.class); intent.setData(Uri.parse(url)); intent.putExtra( ImageViewActivity.BACKGROUND_COLOR_KEY, Reader.ImageViewBackgroundOption.getValue().intValue() ); OrientationUtil.startActivity(BaseActivity, intent); } catch (Exception e) { e.printStackTrace(); } } } else if (soul instanceof ZLTextWordRegionSoul) { //DictionaryUtil.openWordInDictionary( //BaseActivity, ((ZLTextWordRegionSoul)soul).Word, region //); } } }