use of android.webkit.WebViewClient in project baker-android by bakerframework.
the class InfoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info);
// Here we allow the user to rotate the screen.
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
Intent intent = getIntent();
String url = intent.getStringExtra(MagazineActivity.MODAL_URL);
// Click on the CLOSE button.
findViewById(R.id.btnCloseInfo).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
InfoActivity.this.finish();
}
});
WebView webView = (WebView) this.findViewById(R.id.infoWebView);
webView.getSettings().setJavaScriptEnabled(true);
//Set zoom enabled/disabled
webView.getSettings().setSupportZoom(true);
//Support zoom like normal browsers
webView.getSettings().setUseWideViewPort(true);
//Disable zoom buttons
webView.getSettings().setDisplayZoomControls(false);
//Add zoom controls
webView.getSettings().setBuiltInZoomControls(true);
//Load the page on the maximum zoom out available.
webView.getSettings().setLoadWithOverviewMode(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.loadUrl(url);
}
use of android.webkit.WebViewClient in project baker-android by bakerframework.
the class MagazineActivity method setPagerView.
@SuppressLint("SetJavaScriptEnabled")
private void setPagerView(final BookJson book) {
String path = "file://".concat(Configuration.getMagazinesDirectory(this)).concat(File.separator).concat(book.getMagazineName());
if (STANDALONE_MODE) {
boolean fromAssets = !this.getResources().getBoolean(R.bool.sa_read_from_custom_directory);
if (fromAssets) {
path = "file:///android_asset".concat(File.separator).concat(getString(R.string.sa_books_directory)).concat(File.separator).concat(book.getMagazineName());
}
} else if (ENABLE_TUTORIAL) {
path = "file:///android_asset".concat(File.separator).concat("abaker_usage");
}
if (book.getLiveUrl() != null) {
path = book.getLiveUrl();
}
final String finalPath = path;
Log.d(this.getClass().toString(), "THE PATH FOR LOADING THE PAGES WILL BE: " + finalPath);
// ViewPager and its adapters use support library
// fragments, so use getSupportFragmentManager.
webViewPagerAdapter = new WebViewFragmentPagerAdapter(getSupportFragmentManager(), book, finalPath, this);
pager = (CustomWebViewPager) findViewById(R.id.pager);
pager.setAdapter(webViewPagerAdapter);
//Bind the title indicator to the adapter
LinePageIndicator indicator = (LinePageIndicator) findViewById(R.id.indicator);
if (!ENABLE_TUTORIAL) {
indicator.setVisibility(View.GONE);
}
indicator.setViewPager(pager);
indicator.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
if (hasElapsedTime) {
Long timeElapsed = System.currentTimeMillis() - startedTime;
if (timeElapsed > resources.getInteger(R.integer.ga_page_view_time_elapsed))
((ABakerApp) MagazineActivity.this.getApplication()).sendTimingEvent(metaBakerPageCategory, timeElapsed, getString(R.string.issue_page_view), metaBakerPageName);
((ABakerApp) MagazineActivity.this.getApplication()).sendEvent(metaBakerPageCategory, getString(R.string.issue_page_view), metaBakerPageName);
startedTime = 0L;
hasElapsedTime = false;
previousIndex = -1;
metaBakerPageName = "";
metaBakerPageCategory = "";
}
Log.d(this.getClass().getName(), "Loading page at index: " + position);
detectFirstOrLastPage();
if (resources.getBoolean(R.bool.ga_enable) && resources.getBoolean(R.bool.ga_register_page_view_event)) {
String page = finalPath + book.getMagazineName() + File.separator + book.getContents().get(position);
Map<String, String> tags = getBakerMetaTags(page);
if (tags.containsKey("baker-page-name")) {
String name = tags.get("baker-page-name");
String category = tags.containsKey("baker-page-category") ? tags.get("baker-page-category") : getString(R.string.issues_category);
name = (name.isEmpty()) ? book.getContents().get(position) : name;
category = (category.isEmpty()) ? getString(R.string.issues_category) : category;
if (resources.getBoolean(R.bool.ga_register_page_view_time_elapsed_event)) {
startedTime = System.currentTimeMillis();
hasElapsedTime = true;
previousIndex = position;
metaBakerPageName = name;
metaBakerPageCategory = category;
} else {
((ABakerApp) MagazineActivity.this.getApplication()).sendEvent(category, getString(R.string.issue_page_view), name);
}
}
}
}
});
CustomWebView viewIndex = (CustomWebView) findViewById(R.id.webViewIndex);
viewIndex.getSettings().setJavaScriptEnabled(true);
viewIndex.getSettings().setUseWideViewPort(true);
viewIndex.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String stringUrl) {
// mailto links will be handled by the OS.
if (stringUrl.startsWith("mailto:")) {
Uri uri = Uri.parse(stringUrl);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
} else {
try {
URL url = new URL(stringUrl);
// We try to remove the referrer string to avoid passing it to the server in case the URL is an external link.
String referrer = "";
if (url.getQuery() != null) {
Map<String, String> variables = Configuration.splitUrlQueryString(url);
String finalQueryString = "";
for (Map.Entry<String, String> entry : variables.entrySet()) {
if (entry.getKey().equals("referrer")) {
referrer = entry.getValue();
} else {
finalQueryString += entry.getKey() + "=" + entry.getValue() + "&";
}
}
if (!finalQueryString.isEmpty()) {
finalQueryString = "?" + finalQueryString.substring(0, finalQueryString.length() - 1);
}
stringUrl = stringUrl.replace("?" + url.getQuery(), finalQueryString);
}
if (!url.getProtocol().equals("file")) {
Log.d("REFERRER>>>", "THE REFERRER IS: " + referrer);
if (referrer.equals(MagazineActivity.this.getString(R.string.url_external_referrer))) {
Uri uri = Uri.parse(stringUrl);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
} else if (referrer.equals(MagazineActivity.this.getString(R.string.url_gindpubs_referrer))) {
MagazineActivity.this.openLinkInModal(stringUrl);
return true;
} else {
// We return false to tell the webview that we are not going to handle the URL override.
return false;
}
} else {
stringUrl = url.getPath().substring(url.getPath().lastIndexOf("/") + 1);
Log.d(">>>URL_DATA", "FINAL INTERNAL HTML FILENAME = " + stringUrl);
int index = MagazineActivity.this.getJsonBook().getContents().indexOf(stringUrl);
if (index != -1) {
Log.d(this.getClass().toString(), "Index to load: " + index + ", page: " + stringUrl);
MagazineActivity.this.getPager().setCurrentItem(index);
view.setVisibility(View.GONE);
} else {
// If the file DOES NOT exist, we won't load it.
File htmlFile = new File(url.getPath());
if (htmlFile.exists()) {
return false;
}
}
}
} catch (MalformedURLException ex) {
Log.d(">>>URL_DATA", ex.getMessage());
} catch (UnsupportedEncodingException ex) {
}
}
return true;
}
});
viewIndex.loadUrl(path + File.separator + "index.html");
viewIndex.setBackgroundColor(0x00000000);
viewIndex.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
}
use of android.webkit.WebViewClient in project baker-android by bakerframework.
the class ModalActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_modal);
// Here we allow the user to rotate the screen.
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
Intent intent = getIntent();
String url = intent.getStringExtra(MagazineActivity.MODAL_URL);
orientation = intent.getIntExtra(MagazineActivity.ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_SENSOR);
// Click on the CLOSE button.
findViewById(R.id.btnCloseModal).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ModalActivity.this.finish();
}
});
WebView webView = (WebView) this.findViewById(R.id.modalWebView);
webView.getSettings().setJavaScriptEnabled(true);
//Set zoom enabled/disabled
webView.getSettings().setSupportZoom(true);
//Support zoom like normal browsers
webView.getSettings().setUseWideViewPort(true);
//Disable zoom buttons
webView.getSettings().setDisplayZoomControls(false);
//Add zoom controls
webView.getSettings().setBuiltInZoomControls(true);
//Load the page on the maximum zoom out available.
webView.getSettings().setLoadWithOverviewMode(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.loadUrl(url);
}
use of android.webkit.WebViewClient in project baker-android by bakerframework.
the class GindActivity method loadingScreen.
private void loadingScreen() {
Log.d(this.getClass().getName(), "Showing loading screen.");
setContentView(R.layout.loading);
WebView webview = (WebView) findViewById(R.id.loadingWebView);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.setBackgroundColor(Color.TRANSPARENT);
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webview.loadUrl(getString(R.string.loadingUrl));
}
use of android.webkit.WebViewClient in project BGARefreshLayout-Android by bingoogolapple.
the class WebViewActivity method setListener.
@Override
protected void setListener() {
mRefreshLayout.setDelegate(this);
mContentWv.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
mRefreshLayout.endRefreshing();
}
});
findViewById(R.id.retweet).setOnClickListener(this);
findViewById(R.id.comment).setOnClickListener(this);
findViewById(R.id.praise).setOnClickListener(this);
}
Aggregations