Saving of WebView state
This commit is contained in:
parent
ec63970bde
commit
362aecfc7a
1 changed files with 52 additions and 36 deletions
|
@ -1,21 +1,27 @@
|
||||||
package net.osmand.plus.activities;
|
package net.osmand.plus.activities;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.view.MenuItemCompat;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
import android.webkit.WebViewClient;
|
||||||
|
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.pm.ActivityInfo;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.support.v4.view.MenuItemCompat;
|
|
||||||
import android.support.v7.widget.Toolbar;
|
|
||||||
import android.view.*;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
|
||||||
import net.osmand.plus.R;
|
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
import android.webkit.WebViewClient;
|
|
||||||
|
|
||||||
|
|
||||||
public class HelpActivity extends OsmandActionBarActivity {
|
public class HelpActivity extends OsmandActionBarActivity {
|
||||||
|
@ -27,7 +33,7 @@ public class HelpActivity extends OsmandActionBarActivity {
|
||||||
private static final int BACK = 2;
|
private static final int BACK = 2;
|
||||||
private static final int FORWARD = 3;
|
private static final int FORWARD = 3;
|
||||||
private static final int CLOSE = 4;
|
private static final int CLOSE = 4;
|
||||||
private WebView wv;
|
private WebView mWebView;
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,30 +59,30 @@ public class HelpActivity extends OsmandActionBarActivity {
|
||||||
}
|
}
|
||||||
getSupportActionBar().setTitle(title);
|
getSupportActionBar().setTitle(title);
|
||||||
setContentView(R.layout.help_activity);
|
setContentView(R.layout.help_activity);
|
||||||
wv = (WebView) findViewById(R.id.webView);
|
mWebView = (WebView) findViewById(R.id.webView);
|
||||||
wv.setFocusable(true);
|
mWebView.setFocusable(true);
|
||||||
wv.setFocusableInTouchMode(true);
|
mWebView.setFocusableInTouchMode(true);
|
||||||
wv.requestFocus(View.FOCUS_DOWN);
|
mWebView.requestFocus(View.FOCUS_DOWN);
|
||||||
wv.setOnTouchListener(new View.OnTouchListener() {
|
mWebView.setOnTouchListener(new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View view, MotionEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
if (!v.hasFocus()) {
|
if (!view.hasFocus()) {
|
||||||
v.requestFocus();
|
view.requestFocus();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
wv.setWebViewClient(new WebViewClient() {
|
mWebView.setWebViewClient(new WebViewClient() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
wv.requestFocus(View.FOCUS_DOWN);
|
mWebView.requestFocus(View.FOCUS_DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -84,7 +90,17 @@ public class HelpActivity extends OsmandActionBarActivity {
|
||||||
super.onLoadResource(view, url);
|
super.onLoadResource(view, url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
wv.loadUrl(FILE_ANDROID_ASSET_HELP + url);
|
if (savedInstanceState != null) {
|
||||||
|
mWebView.restoreState(savedInstanceState);
|
||||||
|
} else {
|
||||||
|
mWebView.loadUrl(FILE_ANDROID_ASSET_HELP + url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
|
mWebView.saveState(outState);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String readContent(String url) throws IOException {
|
public String readContent(String url) throws IOException {
|
||||||
|
@ -133,16 +149,16 @@ public class HelpActivity extends OsmandActionBarActivity {
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
case HOME:
|
case HOME:
|
||||||
wv.loadUrl(FILE_ANDROID_ASSET_HELP + "index.html");
|
mWebView.loadUrl(FILE_ANDROID_ASSET_HELP + "index.html");
|
||||||
return true;
|
return true;
|
||||||
case BACK:
|
case BACK:
|
||||||
if(wv.canGoBack()) {
|
if(mWebView.canGoBack()) {
|
||||||
wv.goBack();
|
mWebView.goBack();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case FORWARD:
|
case FORWARD:
|
||||||
if(wv.canGoForward()) {
|
if(mWebView.canGoForward()) {
|
||||||
wv.goForward();
|
mWebView.goForward();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case CLOSE:
|
case CLOSE:
|
||||||
|
|
Loading…
Reference in a new issue