Fixed a further bug in the Listener cycle. Refactored image storage.
Change-Id: I2b3f9e2c46dafde4bd488bc95675c04e8806c9a4
This commit is contained in:
committed by
Michael Meeks
parent
597924e78a
commit
0aa7aa85a4
@@ -1,7 +1,5 @@
|
||||
package org.libreoffice.impressremote;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.libreoffice.impressremote.communication.CommunicationService;
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
@@ -23,11 +21,12 @@ import android.widget.TextView;
|
||||
|
||||
public class TestClient extends Activity {
|
||||
|
||||
private HashMap<Integer, Bitmap> mPreviewImages = new HashMap<Integer, Bitmap>();
|
||||
private boolean mCurrentPreviewImageMissing = false;
|
||||
|
||||
private boolean mIsBound = false;
|
||||
|
||||
private int mCurrentSlide = 0;
|
||||
|
||||
private CommunicationService mCommunicationService;
|
||||
|
||||
final Messenger mMessenger = new Messenger(new MessageHandler());
|
||||
@@ -141,22 +140,17 @@ public class TestClient extends Activity {
|
||||
case CommunicationService.MSG_SLIDE_CHANGED:
|
||||
int newSlide = aData.getInt("slide_number");
|
||||
mSlideLabel.setText("Slide " + newSlide);
|
||||
if (mPreviewImages.containsKey(newSlide)) {
|
||||
mImageView.setImageBitmap(mPreviewImages.get(newSlide));
|
||||
mCurrentPreviewImageMissing = false;
|
||||
} else {
|
||||
mCurrentPreviewImageMissing = true;
|
||||
}
|
||||
break;
|
||||
mCurrentPreviewImageMissing = true;
|
||||
// We continue on to try and update the image.
|
||||
case CommunicationService.MSG_SLIDE_PREVIEW:
|
||||
int aSlideNumber = aData.getInt("slide_number");
|
||||
byte[] aPreviewImage = aData.getByteArray("preview_image");
|
||||
Bitmap aBitmap = BitmapFactory.decodeByteArray(aPreviewImage,
|
||||
0, aPreviewImage.length);
|
||||
mPreviewImages.put(aSlideNumber, aBitmap);
|
||||
if (mCurrentPreviewImageMissing) {
|
||||
mImageView.setImageBitmap(aBitmap);
|
||||
mCurrentPreviewImageMissing = false;
|
||||
if ( mCurrentPreviewImageMissing ) {
|
||||
Bitmap aImage = mCommunicationService
|
||||
.getPreviewImage(aSlideNumber);
|
||||
if (aImage != null) {
|
||||
mImageView.setImageBitmap(aImage);
|
||||
mCurrentPreviewImageMissing = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@@ -2,6 +2,8 @@ package org.libreoffice.impressremote.communication;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.os.Messenger;
|
||||
@@ -72,4 +74,9 @@ public class CommunicationService extends Service {
|
||||
mClient.closeConnection();
|
||||
}
|
||||
|
||||
public Bitmap getPreviewImage(int aSlide) {
|
||||
return mReceiver.getPreviewImage(aSlide);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -10,22 +10,32 @@ package org.libreoffice.impressremote.communication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Base64;
|
||||
import android.util.SparseArray;
|
||||
|
||||
public class Receiver {
|
||||
|
||||
private Messenger mActivityMessenger;
|
||||
|
||||
private SparseArray<byte[]> mPreviewImages = new SparseArray<byte[]>();
|
||||
|
||||
public void setActivityMessenger(Messenger aActivityMessenger) {
|
||||
mActivityMessenger = aActivityMessenger;
|
||||
}
|
||||
|
||||
public Bitmap getPreviewImage(int aSlide) {
|
||||
byte[] aImage = mPreviewImages.get(aSlide);
|
||||
return BitmapFactory.decodeByteArray(aImage, 0, aImage.length);
|
||||
}
|
||||
|
||||
public void parseCommand(ArrayList<String> aCommand) {
|
||||
System.out.println("parsing " +aCommand.get(0));
|
||||
System.out.println("parsing " + aCommand.get(0));
|
||||
if (mActivityMessenger == null) {
|
||||
return;
|
||||
}
|
||||
@@ -46,11 +56,15 @@ public class Receiver {
|
||||
int aSlideNumber = Integer.parseInt(aCommand.get(1));
|
||||
String aImageString = aCommand.get(2);
|
||||
byte[] aImage = Base64.decode(aImageString, Base64.DEFAULT);
|
||||
|
||||
// Store image internally
|
||||
mPreviewImages.put(aSlideNumber, aImage);
|
||||
|
||||
// Notify the frontend
|
||||
Message aMessage = Message.obtain(null,
|
||||
CommunicationService.MSG_SLIDE_PREVIEW);
|
||||
Bundle aData = new Bundle();
|
||||
aData.putInt("slide_number", aSlideNumber);
|
||||
aData.putByteArray("preview_image", aImage);
|
||||
aMessage.setData(aData);
|
||||
try {
|
||||
mActivityMessenger.send(aMessage);
|
||||
|
@@ -43,6 +43,7 @@ namespace sd
|
||||
static void setup();
|
||||
static void presentationStarted( const css::uno::Reference<
|
||||
css::presentation::XSlideShowController > &rController );
|
||||
static void presentationStopped();
|
||||
void informListenerDestroyed();
|
||||
private:
|
||||
Server();
|
||||
@@ -54,7 +55,6 @@ namespace sd
|
||||
void execute();
|
||||
static Transmitter *pTransmitter;
|
||||
static rtl::Reference<Listener> mListener;
|
||||
static rtl::Reference<ImagePreparer> mPreparer;
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -25,22 +25,31 @@ using rtl::OStringBuffer;
|
||||
Listener::Listener( const ::rtl::Reference<Server>& rServer, sd::Transmitter *aTransmitter )
|
||||
: ::cppu::WeakComponentImplHelper1< XSlideShowListener >( m_aMutex ),
|
||||
mServer( rServer ),
|
||||
pTransmitter( NULL )
|
||||
pTransmitter( NULL ),
|
||||
mPreparer()
|
||||
{
|
||||
pTransmitter = aTransmitter;
|
||||
fprintf( stderr, "Listener created %p\n", this );
|
||||
}
|
||||
|
||||
Listener::~Listener()
|
||||
{
|
||||
fprintf( stderr, "Listener destroyed %p\n", this );
|
||||
}
|
||||
|
||||
void Listener::init( const css::uno::Reference< css::presentation::XSlideShowController >& aController)
|
||||
{
|
||||
fprintf( stderr, "Initing\n" );
|
||||
if ( aController.is() )
|
||||
{
|
||||
fprintf( stderr, "Is -- now copying refrerence.\n" );
|
||||
mController = css::uno::Reference< css::presentation::XSlideShowController >( aController );
|
||||
fprintf( stderr, "Registering listener\n" );
|
||||
aController->addSlideShowListener( this );
|
||||
fprintf( stderr, "Registered listener.\n" );
|
||||
|
||||
mPreparer.set( new ImagePreparer( aController, pTransmitter, mPreparer ) );
|
||||
mPreparer->launch();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -123,6 +132,13 @@ void SAL_CALL Listener::slideAnimationsEnded (void)
|
||||
|
||||
void SAL_CALL Listener::disposing (void)
|
||||
{
|
||||
fprintf( stderr, "disposing void\n" );
|
||||
if ( mPreparer.is() )
|
||||
{
|
||||
delete mPreparer.get();
|
||||
mPreparer = NULL;
|
||||
}
|
||||
|
||||
pTransmitter = NULL;
|
||||
if ( mController.is() )
|
||||
{
|
||||
@@ -136,6 +152,7 @@ void SAL_CALL Listener::disposing (
|
||||
const css::lang::EventObject& rEvent)
|
||||
throw (::com::sun::star::uno::RuntimeException)
|
||||
{
|
||||
fprintf( stderr, "disposing with Events\n" );
|
||||
(void) rEvent;
|
||||
dispose();
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "Server.hxx"
|
||||
#include "Transmitter.hxx"
|
||||
#include "ImagePreparer.hxx"
|
||||
|
||||
namespace css = ::com::sun::star;
|
||||
|
||||
@@ -63,6 +64,7 @@ private:
|
||||
rtl::Reference<Server> mServer;
|
||||
sd::Transmitter *pTransmitter;
|
||||
css::uno::Reference< css::presentation::XSlideShowController > mController;
|
||||
rtl::Reference<sd::ImagePreparer> mPreparer;
|
||||
};
|
||||
}
|
||||
#endif // _SD_IMPRESSREMOTE_LISTENER_HXX
|
||||
|
@@ -93,13 +93,10 @@ void Server::listenThread()
|
||||
}
|
||||
}
|
||||
// TODO: deal with transmision errors gracefully.
|
||||
fprintf( stderr, "done with transmitting\n" );
|
||||
mListener->disposing();
|
||||
mListener = NULL;
|
||||
|
||||
if ( mPreparer.is() )
|
||||
delete mPreparer.get();
|
||||
mPreparer = NULL;
|
||||
|
||||
delete pTransmitter;
|
||||
pTransmitter = NULL;
|
||||
fprintf( stderr, "Finished listening\n" );
|
||||
@@ -140,18 +137,21 @@ void Server::presentationStarted( const css::uno::Reference<
|
||||
{
|
||||
mListener = rtl::Reference<Listener>( new Listener( spServer, pTransmitter ) );
|
||||
mListener->init( rController );
|
||||
|
||||
mPreparer = rtl::Reference<ImagePreparer>( new ImagePreparer( rController, pTransmitter ) );
|
||||
mPreparer->launch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Server::presentationStopped()
|
||||
{
|
||||
if ( mListener.is() )
|
||||
{
|
||||
mListener->disposing();
|
||||
mListener = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Server *sd::Server::spServer = NULL;
|
||||
Transmitter *sd::Server::pTransmitter = NULL;
|
||||
rtl::Reference<Listener> sd::Server::mListener = NULL;
|
||||
rtl::Reference<ImagePreparer> sd::Server::mPreparer = NULL;
|
||||
|
||||
void Server::setup()
|
||||
{
|
||||
|
@@ -58,7 +58,6 @@
|
||||
#include "sdattr.hrc"
|
||||
#include "FactoryIds.hxx"
|
||||
#include "ViewShell.hxx"
|
||||
#include "Server.hxx"
|
||||
#include "SlideShowRestarter.hxx"
|
||||
#include "DrawController.hxx"
|
||||
#include <boost/bind.hpp>
|
||||
@@ -1074,7 +1073,6 @@ void SlideShow::activate( ViewShellBase& rBase )
|
||||
if( mxController.is() )
|
||||
mxController->activate();
|
||||
|
||||
Server::presentationStarted( mxController.get() );
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
|
@@ -79,7 +79,7 @@
|
||||
#include "canvas/elapsedtime.hxx"
|
||||
#include "avmedia/mediawindow.hxx"
|
||||
#include "svtools/colrdlg.hxx"
|
||||
|
||||
#include "Server.hxx"
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
using ::rtl::OUString;
|
||||
@@ -609,6 +609,7 @@ SlideshowImpl::~SlideshowImpl()
|
||||
|
||||
void SAL_CALL SlideshowImpl::disposing()
|
||||
{
|
||||
Server::presentationStopped();
|
||||
if( mxShow.is() && mpDoc )
|
||||
NotifyDocumentEvent( mpDoc, "OnEndPresentation" );
|
||||
|
||||
@@ -1508,6 +1509,7 @@ void SAL_CALL SlideshowImpl::resume() throw (RuntimeException)
|
||||
comphelper::anyToString( cppu::getCaughtException() ),
|
||||
RTL_TEXTENCODING_UTF8 )).getStr() );
|
||||
}
|
||||
Server::presentationStarted( this );
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user