bug 706383 - Save screenshot in bundle r=dougt

This commit is contained in:
Brad Lassey 2011-11-30 21:28:05 -05:00
parent e6e954cf8c
commit 46014e0aa6
2 changed files with 24 additions and 36 deletions

View File

@ -101,6 +101,7 @@ abstract public class GeckoApp
public static final String SAVED_STATE_URI = "uri";
public static final String SAVED_STATE_TITLE = "title";
public static final String SAVED_STATE_VIEWPORT = "viewport";
public static final String SAVED_STATE_SCREEN = "screen";
private LinearLayout mMainLayout;
private AbsoluteLayout mGeckoLayout;
@ -134,6 +135,7 @@ abstract public class GeckoApp
public String mLastUri;
public String mLastTitle;
public String mLastViewport;
public byte[] mLastScreen;
private Vector<View> mPluginViews = new Vector<View>();
@ -550,12 +552,6 @@ abstract public class GeckoApp
}
}
public static String getStartupBitmapFilePath() {
File file = new File(GeckoAppShell.getCacheDir(),
"lastScreen.png");
return file.toString();
}
public String getLastViewport() {
return mLastViewport;
}
@ -564,13 +560,15 @@ abstract public class GeckoApp
super.onSaveInstanceState(outState);
if (outState == null)
outState = new Bundle();
rememberLastScreen();
outState.putString(SAVED_STATE_URI, mLastUri);
outState.putString(SAVED_STATE_TITLE, mLastTitle);
outState.putString(SAVED_STATE_VIEWPORT, mLastViewport);
outState.putByteArray(SAVED_STATE_SCREEN, mLastScreen);
}
private void rememberLastScreen(boolean sync) {
private void rememberLastScreen() {
if (mUserDefinedProfile)
return;
@ -588,15 +586,10 @@ abstract public class GeckoApp
mLastViewport = mSoftwareLayerClient.getGeckoViewportMetrics().toJSON();
mLastUri = lastHistoryEntry.mUri;
mLastTitle = lastHistoryEntry.mTitle;
GeckoEvent event = new GeckoEvent();
event.mType = GeckoEvent.SAVE_STATE;
event.mCharacters = getStartupBitmapFilePath();
if (sync)
GeckoAppShell.sendEventToGeckoSync(event);
else
GeckoAppShell.sendEventToGecko(event);
Bitmap bitmap = mSoftwareLayerClient.getBitmap();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0, bos);
mLastScreen = bos.toByteArray();
}
private void maybeCancelFaviconLoad(Tab tab) {
@ -1242,6 +1235,7 @@ abstract public class GeckoApp
mLastUri = savedInstanceState.getString(SAVED_STATE_URI);
mLastTitle = savedInstanceState.getString(SAVED_STATE_TITLE);
mLastViewport = savedInstanceState.getString(SAVED_STATE_VIEWPORT);
mLastScreen = savedInstanceState.getByteArray(SAVED_STATE_SCREEN);
}
if (Build.VERSION.SDK_INT >= 9) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()

View File

@ -50,12 +50,12 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.AsyncTask;
import android.os.Environment;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
/**
@ -70,7 +70,6 @@ public class PlaceholderLayerClient extends LayerClient {
private boolean mViewportUnknown;
private int mWidth, mHeight, mFormat;
private ByteBuffer mBuffer;
private FetchImageTask mTask;
private PlaceholderLayerClient(Context context) {
mContext = context;
@ -88,6 +87,7 @@ public class PlaceholderLayerClient extends LayerClient {
} else {
mViewport = new ViewportMetrics();
}
loadScreenshot();
}
public static PlaceholderLayerClient createInstance(Context context) {
@ -99,22 +99,14 @@ public class PlaceholderLayerClient extends LayerClient {
GeckoAppShell.freeDirectBuffer(mBuffer);
mBuffer = null;
}
if (mTask != null) {
mTask.cancel(false);
mTask = null;
}
}
private class FetchImageTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... unused) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap bitmap = BitmapFactory.decodeFile(GeckoApp.getStartupBitmapFilePath(),
options);
boolean loadScreenshot() {
if (GeckoApp.mAppContext.mLastScreen == null)
return false;
Bitmap bitmap = BitmapFactory.decodeStream(new ByteArrayInputStream(GeckoApp.mAppContext.mLastScreen));
if (bitmap == null)
return null;
return false;
Bitmap.Config config = bitmap.getConfig();
@ -133,11 +125,10 @@ public class PlaceholderLayerClient extends LayerClient {
getLayerController().setPageSize(mViewport.getPageSize());
}
return null;
return true;
}
@Override
protected void onPostExecute(Void unused) {
void showScreenshot() {
BufferedCairoImage image = new BufferedCairoImage(mBuffer, mWidth, mHeight, mFormat);
SingleTileLayer tileLayer = new SingleTileLayer(image);
@ -147,7 +138,6 @@ public class PlaceholderLayerClient extends LayerClient {
getLayerController().setRoot(tileLayer);
}
}
@Override
public void geometryChanged() { /* no-op */ }
@ -164,7 +154,11 @@ public class PlaceholderLayerClient extends LayerClient {
BufferedCairoImage image = new BufferedCairoImage(mBuffer, mWidth, mHeight, mFormat);
SingleTileLayer tileLayer = new SingleTileLayer(image);
beginTransaction(tileLayer);
tileLayer.setOrigin(PointUtils.round(mViewport.getDisplayportOrigin()));
endTransaction(tileLayer);
layerController.setRoot(tileLayer);
}
}