/** * Using this method with Proguard may result it missing file behaviour. * Recommended {@link #loadRawResource(int)} instead. * * @param rawFileName a filename in your /raw/ directory i.e. "novoda.html" */ public void loadRawUrl(String rawFileName) { loadUrl(ANDROID_RAW_BASE_URL + "/" + rawFileName); }
/** * This will load an Activity hosting a webview to the provided URL * ensure you declare me in your manifest * <code><activity android:name="com.novoda.notils.widget.webview.ExternalUrlWebViewActivity" /></code> * * @param context Any context * @param url A valid url to navigate to */ public static void toUrl(Context context, String url) { toUrl(context, url, android.R.string.untitled); }
public RawWebView(Context context, AttributeSet attrs) { super(context, attrs); streamTils = new StreamTils(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle(getWebViewTitle()); createWebView(); setContentView(webView); enableJavascript(); enableCaching(); enableCustomClients(); zoomedOut(); webView.loadUrl(getUrl()); }
/** * @param rawResourceId the corresponding id of a filename in your /raw/ directory i.e. "R.raw.novoda" */ public void loadRawResource(int rawResourceId) { InputStream input = null; try { input = getResources().openRawResource(rawResourceId); String html = streamTils.loadFrom(input); loadRawData(html); } finally { streamTils.tryClose(input); } }
private void enableCaching() { webView.getSettings().setAppCachePath(getFilesDir() + getPackageName() + "/cache"); webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); }
private String getWebViewTitle() { String title = getIntent().getStringExtra(EXTRA_TITLE); return title == null ? "" : title; }
public void onProgressChanged(WebView view, int progress) { setProgress(progress * PROGRESS_RATIO); } });
public void loadRawData(String html) { loadDataWithBaseURL(ANDROID_RAW_BASE_URL, html, TEXT_HTML, DEFAULT_ENCODING, FAIL_URL); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); webView.loadRawResource(R.raw.software_licenses); }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Check if the key event was the Back button and if there's history if ((keyCode == KeyEvent.KEYCODE_BACK) && canGoBackInWebViewHistory()) { webView.goBack(); return true; } // If it wasn't the Back key or there's no web page history, bubble up to the default // system behavior (probably exit the activity) return super.onKeyDown(keyCode, event); }
/** * This will load an Activity hosting a webview to the provided URL * ensure you declare me in your manifest * <code><activity android:name="com.novoda.notils.widget.webview.ExternalUrlWebViewActivity" /></code> * * @param context Any context * @param url A valid url to navigate to * @param titleResId A String resource to display as the title */ public static void toUrl(Context context, String url, int titleResId) { toUrl(context, url, context.getString(titleResId)); }
public RawWebView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); streamTils = new StreamTils(); }
private String getUrl() { return getIntent().getStringExtra(EXTRA_URL); } }