fdo#62591 - change Impress remote slide previews building
* Store bitmaps directly instead of byte arrays. * Store bitmaps with shadows instead of one set with shadows and another without them. This change should optimize memory usage a bit. Change-Id: Ied7ce57a660438a06167e8984d16a6f26ebd8c23 Reviewed-on: https://gerrit.libreoffice.org/2917 Reviewed-by: Michael Meeks <michael.meeks@suse.com> Tested-by: Michael Meeks <michael.meeks@suse.com>
This commit is contained in:
committed by
Michael Meeks
parent
1a843cc54d
commit
514d6c6fb6
@@ -21,10 +21,7 @@ import android.content.IntentFilter;
|
|||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.RectF;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
@@ -38,7 +35,6 @@ import android.widget.AdapterView;
|
|||||||
import android.widget.AdapterView.OnItemSelectedListener;
|
import android.widget.AdapterView.OnItemSelectedListener;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockFragment;
|
import com.actionbarsherlock.app.SherlockFragment;
|
||||||
|
|
||||||
public class PresentationFragment extends SherlockFragment {
|
public class PresentationFragment extends SherlockFragment {
|
||||||
@@ -306,24 +302,7 @@ public class PresentationFragment extends SherlockFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Bitmap createBitmap(int position) {
|
protected Bitmap createBitmap(int position) {
|
||||||
Bitmap aBitmap = mSlideShow.getImage(position);
|
return mSlideShow.getImage(position);
|
||||||
final int borderWidth = 8;
|
|
||||||
|
|
||||||
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
||||||
p.setShadowLayer(borderWidth, 0, 0, Color.BLACK);
|
|
||||||
|
|
||||||
RectF aRect = new RectF(borderWidth, borderWidth, borderWidth
|
|
||||||
+ aBitmap.getWidth(), borderWidth
|
|
||||||
+ aBitmap.getHeight());
|
|
||||||
Bitmap aOut = Bitmap.createBitmap(aBitmap.getWidth() + 2
|
|
||||||
* borderWidth, aBitmap.getHeight() + 2
|
|
||||||
* borderWidth, aBitmap.getConfig());
|
|
||||||
Canvas canvas = new Canvas(aOut);
|
|
||||||
canvas.drawColor(getResources().getColor(R.color.light_grey));
|
|
||||||
canvas.drawRect(aRect, p);
|
|
||||||
canvas.drawBitmap(aBitmap, null, aRect, null);
|
|
||||||
|
|
||||||
return aOut;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,17 +9,20 @@
|
|||||||
package org.libreoffice.impressremote.communication;
|
package org.libreoffice.impressremote.communication;
|
||||||
|
|
||||||
import org.libreoffice.impressremote.R;
|
import org.libreoffice.impressremote.R;
|
||||||
import org.libreoffice.impressremote.Globals;
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.RectF;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
|
|
||||||
public class SlideShow {
|
public class SlideShow {
|
||||||
|
|
||||||
private SparseArray<byte[]> mPreviewImages = new SparseArray<byte[]>();
|
private SparseArray<Bitmap> mPreviews = new SparseArray<Bitmap>();
|
||||||
private SparseArray<String> mNotes = new SparseArray<String>();
|
private SparseArray<String> mNotes = new SparseArray<String>();
|
||||||
|
|
||||||
private int mSize = 0;
|
private int mSize = 0;
|
||||||
@@ -47,28 +50,28 @@ public class SlideShow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void putImage(int aSlide, byte[] aImage) {
|
protected void putImage(int aSlide, byte[] aImage) {
|
||||||
mPreviewImages.put(aSlide, aImage);
|
Bitmap aBitmap = BitmapFactory.decodeByteArray(aImage, 0, aImage.length);
|
||||||
|
final int borderWidth = 8;
|
||||||
|
|
||||||
|
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
|
p.setShadowLayer(borderWidth, 0, 0, Color.BLACK);
|
||||||
|
|
||||||
|
RectF aRect = new RectF(borderWidth, borderWidth, borderWidth
|
||||||
|
+ aBitmap.getWidth(), borderWidth
|
||||||
|
+ aBitmap.getHeight());
|
||||||
|
Bitmap aOut = Bitmap.createBitmap(aBitmap.getWidth() + 2
|
||||||
|
* borderWidth, aBitmap.getHeight() + 2
|
||||||
|
* borderWidth, aBitmap.getConfig());
|
||||||
|
Canvas canvas = new Canvas(aOut);
|
||||||
|
canvas.drawColor(mContext.getResources().getColor(R.color.light_grey));
|
||||||
|
canvas.drawRect(aRect, p);
|
||||||
|
canvas.drawBitmap(aBitmap, null, aRect, null);
|
||||||
|
|
||||||
|
mPreviews.put(aSlide, aOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getImage(int aSlide) {
|
public Bitmap getImage(int aSlide) {
|
||||||
byte[] aImage = mPreviewImages.get(aSlide);
|
return mPreviews.get(aSlide);
|
||||||
if (aImage == null) {
|
|
||||||
return BitmapFactory.decodeResource(mContext.getResources(),
|
|
||||||
R.drawable.image_loading);
|
|
||||||
}
|
|
||||||
Bitmap aBitmap = null;
|
|
||||||
try {
|
|
||||||
aBitmap = BitmapFactory.decodeByteArray(aImage, 0, aImage.length);
|
|
||||||
} catch (OutOfMemoryError e) {
|
|
||||||
Log.e(Globals.TAG, "Bitmap decoding error byte length: " + aImage.length +
|
|
||||||
"first 4 bytes: " + aImage[0] + " " + aImage[1] + " " + aImage[2] + " " + aImage[3] +
|
|
||||||
"Exception " + e);
|
|
||||||
}
|
|
||||||
if (aBitmap == null) {
|
|
||||||
return BitmapFactory.decodeResource(mContext.getResources(),
|
|
||||||
R.drawable.image_loading);
|
|
||||||
}
|
|
||||||
return aBitmap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void putNotes(int aSlide, String aNotes) {
|
protected void putNotes(int aSlide, String aNotes) {
|
||||||
|
Reference in New Issue
Block a user