This commit is contained in:
@@ -1274,15 +1274,30 @@ public class WebView extends AbsoluteLayout
|
|||||||
* overwritten with this WebView's picture data.
|
* overwritten with this WebView's picture data.
|
||||||
* @return True if the picture was successfully saved.
|
* @return True if the picture was successfully saved.
|
||||||
*/
|
*/
|
||||||
public boolean savePicture(Bundle b, File dest) {
|
public boolean savePicture(Bundle b, final File dest) {
|
||||||
if (dest == null || b == null) {
|
if (dest == null || b == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Picture p = capturePicture();
|
final Picture p = capturePicture();
|
||||||
|
// Use a temporary file while writing to ensure the destination file
|
||||||
|
// contains valid data.
|
||||||
|
final File temp = new File(dest.getPath() + ".writing");
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final FileOutputStream out = new FileOutputStream(dest);
|
FileOutputStream out = new FileOutputStream(temp);
|
||||||
p.writeToStream(out);
|
p.writeToStream(out);
|
||||||
out.close();
|
out.close();
|
||||||
|
// Writing the picture succeeded, rename the temporary file
|
||||||
|
// to the destination.
|
||||||
|
temp.renameTo(dest);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// too late to do anything about it.
|
||||||
|
} finally {
|
||||||
|
temp.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
// now update the bundle
|
// now update the bundle
|
||||||
b.putInt("scrollX", mScrollX);
|
b.putInt("scrollX", mScrollX);
|
||||||
b.putInt("scrollY", mScrollY);
|
b.putInt("scrollY", mScrollY);
|
||||||
@@ -1290,14 +1305,26 @@ public class WebView extends AbsoluteLayout
|
|||||||
b.putFloat("textwrapScale", mTextWrapScale);
|
b.putFloat("textwrapScale", mTextWrapScale);
|
||||||
b.putBoolean("overview", mInZoomOverview);
|
b.putBoolean("overview", mInZoomOverview);
|
||||||
return true;
|
return true;
|
||||||
} catch (FileNotFoundException e){
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
private void restoreHistoryPictureFields(Picture p, Bundle b) {
|
||||||
|
int sx = b.getInt("scrollX", 0);
|
||||||
|
int sy = b.getInt("scrollY", 0);
|
||||||
|
float scale = b.getFloat("scale", 1.0f);
|
||||||
|
mDrawHistory = true;
|
||||||
|
mHistoryPicture = p;
|
||||||
|
mScrollX = sx;
|
||||||
|
mScrollY = sy;
|
||||||
|
mHistoryWidth = Math.round(p.getWidth() * scale);
|
||||||
|
mHistoryHeight = Math.round(p.getHeight() * scale);
|
||||||
|
// as getWidth() / getHeight() of the view are not available yet, set up
|
||||||
|
// mActualScale, so that when onSizeChanged() is called, the rest will
|
||||||
|
// be set correctly
|
||||||
|
mActualScale = scale;
|
||||||
|
mInvActualScale = 1 / scale;
|
||||||
|
mTextWrapScale = b.getFloat("textwrapScale", scale);
|
||||||
|
mInZoomOverview = b.getBoolean("overview");
|
||||||
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1311,43 +1338,36 @@ public class WebView extends AbsoluteLayout
|
|||||||
if (src == null || b == null) {
|
if (src == null || b == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (src.exists()) {
|
if (!src.exists()) {
|
||||||
Picture p = null;
|
return false;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
final FileInputStream in = new FileInputStream(src);
|
final FileInputStream in = new FileInputStream(src);
|
||||||
p = Picture.createFromStream(in);
|
final Bundle copy = new Bundle(b);
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
final Picture p = Picture.createFromStream(in);
|
||||||
|
if (p != null) {
|
||||||
|
// Post a runnable on the main thread to update the
|
||||||
|
// history picture fields.
|
||||||
|
mPrivateHandler.post(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
restoreHistoryPictureFields(p, copy);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
try {
|
||||||
in.close();
|
in.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Nothing we can do now.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
} catch (FileNotFoundException e){
|
} catch (FileNotFoundException e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (RuntimeException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
if (p != null) {
|
|
||||||
int sx = b.getInt("scrollX", 0);
|
|
||||||
int sy = b.getInt("scrollY", 0);
|
|
||||||
float scale = b.getFloat("scale", 1.0f);
|
|
||||||
mDrawHistory = true;
|
|
||||||
mHistoryPicture = p;
|
|
||||||
mScrollX = sx;
|
|
||||||
mScrollY = sy;
|
|
||||||
mHistoryWidth = Math.round(p.getWidth() * scale);
|
|
||||||
mHistoryHeight = Math.round(p.getHeight() * scale);
|
|
||||||
// as getWidth() / getHeight() of the view are not
|
|
||||||
// available yet, set up mActualScale, so that when
|
|
||||||
// onSizeChanged() is called, the rest will be set
|
|
||||||
// correctly
|
|
||||||
mActualScale = scale;
|
|
||||||
mInvActualScale = 1 / scale;
|
|
||||||
mTextWrapScale = b.getFloat("textwrapScale", scale);
|
|
||||||
mInZoomOverview = b.getBoolean("overview");
|
|
||||||
invalidate();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore the state of this WebView from the given map used in
|
* Restore the state of this WebView from the given map used in
|
||||||
@@ -3339,6 +3359,7 @@ public class WebView extends AbsoluteLayout
|
|||||||
if (null == mWebViewCore) return; // CallbackProxy may trigger this
|
if (null == mWebViewCore) return; // CallbackProxy may trigger this
|
||||||
if (mDrawHistory && mWebViewCore.pictureReady()) {
|
if (mDrawHistory && mWebViewCore.pictureReady()) {
|
||||||
mDrawHistory = false;
|
mDrawHistory = false;
|
||||||
|
mHistoryPicture = null;
|
||||||
invalidate();
|
invalidate();
|
||||||
int oldScrollX = mScrollX;
|
int oldScrollX = mScrollX;
|
||||||
int oldScrollY = mScrollY;
|
int oldScrollY = mScrollY;
|
||||||
|
|||||||
Reference in New Issue
Block a user