Fix crashes in android remote.

Several objects become invalid after ending show prematurely. Data
transmission may be flawed, don't rely on valid base64 etc.

Change-Id: I9bb6929b9cd6b3183948662b472f92e2fa67a7e6
This commit is contained in:
Thorsten Behrens
2012-11-24 14:59:56 +01:00
parent fa6be97997
commit c2c9d8a99b
4 changed files with 31 additions and 19 deletions

View File

@@ -95,7 +95,8 @@ public class PresentationActivity extends SherlockFragmentActivity {
Intent aIntent = new Intent(this, SelectorActivity.class); Intent aIntent = new Intent(this, SelectorActivity.class);
aIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); aIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(aIntent); startActivity(aIntent);
mCommunicationService.disconnect(); if ( mCommunicationService != null )
mCommunicationService.disconnect();
} }
@Override @Override
@@ -542,4 +543,4 @@ public class PresentationActivity extends SherlockFragmentActivity {
} }
}; };
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -119,13 +119,15 @@ public class PresentationFragment extends SherlockFragment {
if (mNewCoverflowHeight != 0) { if (mNewCoverflowHeight != 0) {
ThumbnailAdapter aAdapter = (ThumbnailAdapter) mTopView ThumbnailAdapter aAdapter = (ThumbnailAdapter) mTopView
.getAdapter(); .getAdapter();
aAdapter.setHeight(mNewCoverflowHeight); if ( aAdapter != null ) {
mTopView.setImageHeight(mNewCoverflowHeight); aAdapter.setHeight(mNewCoverflowHeight);
aAdapter.setWidth(mNewCoverflowWidth); mTopView.setImageHeight(mNewCoverflowHeight);
mTopView.setImageWidth(mNewCoverflowWidth); aAdapter.setWidth(mNewCoverflowWidth);
mTopView.setImageWidth(mNewCoverflowWidth);
// We need to update the view now // We need to update the view now
aAdapter.notifyDataSetChanged(); aAdapter.notifyDataSetChanged();
}
} }
IntentFilter aFilter = new IntentFilter( IntentFilter aFilter = new IntentFilter(

View File

@@ -83,16 +83,20 @@ public class Receiver {
} else if (aInstruction.equals("slide_preview")) { } else if (aInstruction.equals("slide_preview")) {
int aSlideNumber = Integer.parseInt(aCommand.get(1)); int aSlideNumber = Integer.parseInt(aCommand.get(1));
String aImageString = aCommand.get(2); String aImageString = aCommand.get(2);
byte[] aImage = Base64.decode(aImageString, Base64.DEFAULT); try {
byte[] aImage = Base64.decode(aImageString, Base64.DEFAULT);
// Store image internally // Store image internally
mSlideShow.putImage(aSlideNumber, aImage); mSlideShow.putImage(aSlideNumber, aImage);
Intent aIntent = new Intent( Intent aIntent = new Intent(
CommunicationService.MSG_SLIDE_PREVIEW); CommunicationService.MSG_SLIDE_PREVIEW);
aIntent.putExtra("slide_number", aSlideNumber); aIntent.putExtra("slide_number", aSlideNumber);
LocalBroadcastManager.getInstance(mContext).sendBroadcast( LocalBroadcastManager.getInstance(mContext).sendBroadcast(
aIntent); aIntent);
} catch (IllegalArgumentException e) {
// Bad data - tough luck
}
} else if (aInstruction.equals("slide_notes")) { } else if (aInstruction.equals("slide_notes")) {
int aSlideNumber = Integer.parseInt(aCommand.get(1)); int aSlideNumber = Integer.parseInt(aCommand.get(1));
String aNotes = new String(); String aNotes = new String();
@@ -114,4 +118,4 @@ public class Receiver {
} }
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -54,7 +54,12 @@ public class SlideShow {
return BitmapFactory.decodeResource(mContext.getResources(), return BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.image_loading); R.drawable.image_loading);
} }
return BitmapFactory.decodeByteArray(aImage, 0, aImage.length); Bitmap aBitmap = BitmapFactory.decodeByteArray(aImage, 0, aImage.length);
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) {
@@ -178,4 +183,4 @@ public class SlideShow {
} }
} }
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */