Refactor Receiver, Transmitter, Server and SlideShow classes.
Introduce the Protocol class which contains all static information about the remote protocol: server messages, client commands, etc. It will help to avoid duplicates and possible typos. Change-Id: Ic96a17899b3cec13c4081d671e2296c647bf328c
This commit is contained in:
committed by
Michael Meeks
parent
9f161a847a
commit
fa309d0e22
@@ -39,8 +39,8 @@ public class BlankScreenFragment extends SherlockFragment {
|
|||||||
View v = inflater.inflate(R.layout.fragment_blankscreen, container,
|
View v = inflater.inflate(R.layout.fragment_blankscreen, container,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
Bitmap aBitmap = mCommunicationService.getSlideShow().getImage(
|
Bitmap aBitmap = mCommunicationService.getSlideShow().getSlidePreview(
|
||||||
mCommunicationService.getSlideShow().getCurrentSlide());
|
mCommunicationService.getSlideShow().getCurrentSlideIndex());
|
||||||
|
|
||||||
// Process the image
|
// Process the image
|
||||||
final int borderWidth = 8;
|
final int borderWidth = 8;
|
||||||
@@ -74,14 +74,14 @@ public class BlankScreenFragment extends SherlockFragment {
|
|||||||
v.findViewById(R.id.blankscreen_slidepreview).setOnClickListener(
|
v.findViewById(R.id.blankscreen_slidepreview).setOnClickListener(
|
||||||
aListener);
|
aListener);
|
||||||
v.findViewById(R.id.blankscreen_return).setOnClickListener(aListener);
|
v.findViewById(R.id.blankscreen_return).setOnClickListener(aListener);
|
||||||
mCommunicationService.getTransmitter().blankScreen();
|
mCommunicationService.getTransmitter().setUpBlankScreen();
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
mCommunicationService.getTransmitter().resume();
|
mCommunicationService.getTransmitter().resumePresentation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -127,12 +127,12 @@ public class PresentationActivity extends SherlockFragmentActivity {
|
|||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||||
if (action == KeyEvent.ACTION_UP) {
|
if (action == KeyEvent.ACTION_UP) {
|
||||||
mCommunicationService.getTransmitter().nextTransition();
|
mCommunicationService.getTransmitter().performNextTransition();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||||
if (action == KeyEvent.ACTION_DOWN) {
|
if (action == KeyEvent.ACTION_DOWN) {
|
||||||
mCommunicationService.getTransmitter().previousTransition();
|
mCommunicationService.getTransmitter().performPreviousTransition();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -66,12 +66,12 @@ public class PresentationFragment extends SherlockFragment {
|
|||||||
mTopView.setAdapter(new ThumbnailAdapter(mContext,
|
mTopView.setAdapter(new ThumbnailAdapter(mContext,
|
||||||
mCommunicationService.getSlideShow()));
|
mCommunicationService.getSlideShow()));
|
||||||
mTopView.setSelection(mCommunicationService.getSlideShow()
|
mTopView.setSelection(mCommunicationService.getSlideShow()
|
||||||
.getCurrentSlide(), true);
|
.getCurrentSlideIndex(), true);
|
||||||
mTopView.setOnItemSelectedListener(new ClickListener());
|
mTopView.setOnItemSelectedListener(new ClickListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSlideNumberDisplay(mCommunicationService.getSlideShow()
|
updateSlideNumberDisplay(mCommunicationService.getSlideShow()
|
||||||
.getCurrentSlide());
|
.getCurrentSlideIndex());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,9 +151,9 @@ public class PresentationFragment extends SherlockFragment {
|
|||||||
private void updateSlideNumberDisplay(int aPosition) {
|
private void updateSlideNumberDisplay(int aPosition) {
|
||||||
// int aSlide = mCommunicationService.getSlideShow().getCurrentSlide();
|
// int aSlide = mCommunicationService.getSlideShow().getCurrentSlide();
|
||||||
mNumberText.setText((aPosition + 1) + "/"
|
mNumberText.setText((aPosition + 1) + "/"
|
||||||
+ mCommunicationService.getSlideShow().getSize());
|
+ mCommunicationService.getSlideShow().getSlidesCount());
|
||||||
mNotes.loadDataWithBaseURL(null, mCommunicationService.getSlideShow()
|
mNotes.loadDataWithBaseURL(null, mCommunicationService.getSlideShow()
|
||||||
.getNotes(aPosition), "text/html", "UTF-8", null);
|
.getSlideNotes(aPosition), "text/html", "UTF-8", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------- RESIZING LISTENER ----
|
// -------------------------------------------------- RESIZING LISTENER ----
|
||||||
@@ -241,7 +241,8 @@ public class PresentationFragment extends SherlockFragment {
|
|||||||
public void onItemSelected(AdapterView<?> arg0, View arg1,
|
public void onItemSelected(AdapterView<?> arg0, View arg1,
|
||||||
int aPosition, long arg3) {
|
int aPosition, long arg3) {
|
||||||
if (mCommunicationService != null)
|
if (mCommunicationService != null)
|
||||||
mCommunicationService.getTransmitter().gotoSlide(aPosition);
|
mCommunicationService.getTransmitter().setCurrentSlide(
|
||||||
|
aPosition);
|
||||||
lastUpdateTime = System.currentTimeMillis();
|
lastUpdateTime = System.currentTimeMillis();
|
||||||
updateSlideNumberDisplay(aPosition);
|
updateSlideNumberDisplay(aPosition);
|
||||||
}
|
}
|
||||||
@@ -278,7 +279,7 @@ public class PresentationFragment extends SherlockFragment {
|
|||||||
int aPosition = aIntent.getExtras().getInt("slide_number");
|
int aPosition = aIntent.getExtras().getInt("slide_number");
|
||||||
if ( aPosition == mTopView.getSelectedItemPosition() ) {
|
if ( aPosition == mTopView.getSelectedItemPosition() ) {
|
||||||
mNotes.loadDataWithBaseURL(null, mCommunicationService.getSlideShow()
|
mNotes.loadDataWithBaseURL(null, mCommunicationService.getSlideShow()
|
||||||
.getNotes(aPosition), "text/html", "UTF-8", null);
|
.getSlideNotes(aPosition), "text/html", "UTF-8", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,12 +298,12 @@ public class PresentationFragment extends SherlockFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return mSlideShow.getSize();
|
return mSlideShow.getSlidesCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Bitmap createBitmap(int position) {
|
protected Bitmap createBitmap(int position) {
|
||||||
return mSlideShow.getImage(position);
|
return mSlideShow.getSlidePreview(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -125,7 +125,7 @@ public class ThumbnailFragment extends SherlockFragment {
|
|||||||
public void onItemClick(AdapterView<?> parent, View v, int position,
|
public void onItemClick(AdapterView<?> parent, View v, int position,
|
||||||
long id) {
|
long id) {
|
||||||
if (mCommunicationService != null)
|
if (mCommunicationService != null)
|
||||||
mCommunicationService.getTransmitter().gotoSlide(position);
|
mCommunicationService.getTransmitter().setCurrentSlide(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ public class ThumbnailFragment extends SherlockFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return mSlideShow.getSize();
|
return mSlideShow.getSlidesCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -201,7 +201,7 @@ public class ThumbnailFragment extends SherlockFragment {
|
|||||||
aBorderWidth);
|
aBorderWidth);
|
||||||
|
|
||||||
if ((mSlideShow != null)
|
if ((mSlideShow != null)
|
||||||
&& (position == mSlideShow.getCurrentSlide())) {
|
&& (position == mSlideShow.getCurrentSlideIndex())) {
|
||||||
formatSelected(aImage, aText);
|
formatSelected(aImage, aText);
|
||||||
mCurrentImage = aImage;
|
mCurrentImage = aImage;
|
||||||
mCurrentText = aText;
|
mCurrentText = aText;
|
||||||
@@ -209,7 +209,7 @@ public class ThumbnailFragment extends SherlockFragment {
|
|||||||
formatUnselected(aImage, aText);
|
formatUnselected(aImage, aText);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap aBitmap = mSlideShow.getImage(position);
|
Bitmap aBitmap = mSlideShow.getSlidePreview(position);
|
||||||
// Width
|
// Width
|
||||||
int aWidth = (mGrid.getWidth()) / 3 - 20;
|
int aWidth = (mGrid.getWidth()) / 3 - 20;
|
||||||
aImage.setMaxWidth(aWidth);
|
aImage.setMaxWidth(aWidth);
|
||||||
|
@@ -0,0 +1,55 @@
|
|||||||
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
|
/*
|
||||||
|
* This file is part of the LibreOffice project.
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
package org.libreoffice.impressremote.communication;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
final class Protocol {
|
||||||
|
private Protocol() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Messages {
|
||||||
|
private Messages() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String SLIDESHOW_STARTED = "slideshow_started";
|
||||||
|
public static final String SLIDESHOW_FINISHED = "slideshow_finished";
|
||||||
|
public static final String SLIDE_UPDATED = "slide_updated";
|
||||||
|
public static final String SLIDE_PREVIEW = "slide_preview";
|
||||||
|
public static final String SLIDE_NOTES = "slide_notes";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Commands {
|
||||||
|
private Commands() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String TRANSITION_NEXT = "transition_next";
|
||||||
|
public static final String TRANSITION_PREVIOUS = "transition_previous";
|
||||||
|
public static final String GOTO_SLIDE = "goto_slide";
|
||||||
|
public static final String PRESENTATION_BLANK_SCREEN = "presentation_blank_screen";
|
||||||
|
public static final String PRESENTATION_RESUME = "presentation_resume";
|
||||||
|
public static final String PRESENTATION_START = "presentation_start";
|
||||||
|
public static final String PRESENTATION_STOP = "presentation_stop";
|
||||||
|
|
||||||
|
private static final String DELIMITER_PARAMETER = "\n";
|
||||||
|
private static final String DELIMITER_COMMAND = "\n\n";
|
||||||
|
|
||||||
|
public static String prepareCommand(String aCommand) {
|
||||||
|
return String.format("%s%s", aCommand, DELIMITER_COMMAND);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String prepareCommand(String... aParameters) {
|
||||||
|
String aCommand = TextUtils.join(DELIMITER_PARAMETER, aParameters);
|
||||||
|
|
||||||
|
return prepareCommand(aCommand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.libreoffice.impressremote.communication;
|
package org.libreoffice.impressremote.communication;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -16,106 +16,133 @@ import android.support.v4.content.LocalBroadcastManager;
|
|||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
|
||||||
public class Receiver {
|
public class Receiver {
|
||||||
|
private final Context mContext;
|
||||||
public Receiver(Context aContext) {
|
|
||||||
mContext = aContext;
|
|
||||||
mSlideShow = new SlideShow(mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
private SlideShow mSlideShow;
|
private SlideShow mSlideShow;
|
||||||
|
|
||||||
|
public Receiver(Context aContext) {
|
||||||
|
this.mContext = aContext;
|
||||||
|
this.mSlideShow = new SlideShow(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
public SlideShow getSlideShow() {
|
public SlideShow getSlideShow() {
|
||||||
return mSlideShow;
|
return mSlideShow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSlideShowRunning() {
|
public boolean isSlideShowRunning() {
|
||||||
return (mSlideShow.getSize() > 0);
|
return mSlideShow.getSlidesCount() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parseCommand(ArrayList<String> aCommand) {
|
public void parseCommand(List<String> aInstruction) {
|
||||||
if (aCommand.size() == 0)
|
if (aInstruction.isEmpty()) {
|
||||||
return; // E.g. if empty line received for whatever reason.
|
|
||||||
String aInstruction = aCommand.get(0);
|
|
||||||
if (aInstruction.equals("slideshow_started")) {
|
|
||||||
int aSlideShowlength = Integer.parseInt(aCommand.get(1));
|
|
||||||
int aCurrentSlide = Integer.parseInt(aCommand.get(2));
|
|
||||||
mSlideShow.setLength(aSlideShowlength);
|
|
||||||
mSlideShow.setCurrentSlide(aCurrentSlide);
|
|
||||||
// Intent aIntent = new Intent(mContext.getApplicationContext(),
|
|
||||||
// PresentationActivity.class);
|
|
||||||
// aIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
// aIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
||||||
// mContext.getApplicationContext().startActivity(aIntent);
|
|
||||||
Intent aIntent = new Intent(
|
|
||||||
CommunicationService.STATUS_CONNECTED_SLIDESHOW_RUNNING);
|
|
||||||
LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent);
|
|
||||||
aIntent = new Intent(
|
|
||||||
CommunicationService.MSG_SLIDE_CHANGED);
|
|
||||||
aIntent.putExtra("slide_number", aCurrentSlide);
|
|
||||||
LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent);
|
|
||||||
} else if (aInstruction.equals("slideshow_finished")) {
|
|
||||||
mSlideShow = new SlideShow(mContext);
|
|
||||||
// Intent aIntent = new Intent(mContext.getApplicationContext(),
|
|
||||||
// StartPresentationActivity.class);
|
|
||||||
// aIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
// aIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
||||||
// mContext.getApplicationContext().startActivity(aIntent);
|
|
||||||
Intent aIntent = new Intent(
|
|
||||||
CommunicationService.STATUS_CONNECTED_NOSLIDESHOW);
|
|
||||||
LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent);
|
|
||||||
} else {
|
|
||||||
if (mSlideShow == null)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (aInstruction.equals("slide_updated")) {
|
String aCommand = aInstruction.get(0);
|
||||||
|
|
||||||
int aSlideNumber = Integer.parseInt(aCommand.get(1));
|
if (aCommand.equals(Protocol.Messages.SLIDESHOW_STARTED)) {
|
||||||
|
startSlideShow(aInstruction);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mSlideShow.setCurrentSlide(aSlideNumber);
|
if (aCommand.equals(Protocol.Messages.SLIDESHOW_FINISHED)) {
|
||||||
|
finishSlideShow();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Intent aIntent = new Intent(
|
if (mSlideShow == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aCommand.equals(Protocol.Messages.SLIDE_UPDATED)) {
|
||||||
|
setUpCurrentSlide(aInstruction);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aCommand.equals(Protocol.Messages.SLIDE_PREVIEW)) {
|
||||||
|
setUpSlidePreview(aInstruction);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aCommand.equals(Protocol.Messages.SLIDE_NOTES)) {
|
||||||
|
setUpSlideNotes(aInstruction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startSlideShow(List<String> aInstruction) {
|
||||||
|
int aSlideShowSlidesCount = Integer.parseInt(aInstruction.get(1));
|
||||||
|
int aCurrentSlideIndex = Integer.parseInt(aInstruction.get(2));
|
||||||
|
|
||||||
|
mSlideShow.setSlidesCount(aSlideShowSlidesCount);
|
||||||
|
mSlideShow.setCurrentSlideIndex(aCurrentSlideIndex);
|
||||||
|
|
||||||
|
Intent aStatusConnectedSlideShowRunningIntent = new Intent(
|
||||||
|
CommunicationService.STATUS_CONNECTED_SLIDESHOW_RUNNING);
|
||||||
|
Intent aSlideChangedIntent = new Intent(
|
||||||
CommunicationService.MSG_SLIDE_CHANGED);
|
CommunicationService.MSG_SLIDE_CHANGED);
|
||||||
aIntent.putExtra("slide_number", aSlideNumber);
|
aSlideChangedIntent.putExtra("slide_number", aCurrentSlideIndex);
|
||||||
LocalBroadcastManager.getInstance(mContext).sendBroadcast(
|
|
||||||
aIntent);
|
|
||||||
} else if (aInstruction.equals("slide_preview")) {
|
|
||||||
int aSlideNumber = Integer.parseInt(aCommand.get(1));
|
|
||||||
String aImageString = aCommand.get(2);
|
|
||||||
try {
|
|
||||||
byte[] aImage = Base64.decode(aImageString, Base64.DEFAULT);
|
|
||||||
|
|
||||||
// Store image internally
|
LocalBroadcastManager.getInstance(mContext)
|
||||||
mSlideShow.putImage(aSlideNumber, aImage);
|
.sendBroadcast(aStatusConnectedSlideShowRunningIntent);
|
||||||
|
LocalBroadcastManager.getInstance(mContext)
|
||||||
|
.sendBroadcast(aSlideChangedIntent);
|
||||||
|
}
|
||||||
|
|
||||||
Intent aIntent = new Intent(
|
private void finishSlideShow() {
|
||||||
|
this.mSlideShow = new SlideShow(mContext);
|
||||||
|
|
||||||
|
Intent aStatusConnectedNoSlideShowIntent = new Intent(
|
||||||
|
CommunicationService.STATUS_CONNECTED_NOSLIDESHOW);
|
||||||
|
|
||||||
|
LocalBroadcastManager.getInstance(mContext)
|
||||||
|
.sendBroadcast(aStatusConnectedNoSlideShowIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpCurrentSlide(List<String> aInstruction) {
|
||||||
|
int aCurrentSlideIndex = Integer.parseInt(aInstruction.get(1));
|
||||||
|
|
||||||
|
mSlideShow.setCurrentSlideIndex(aCurrentSlideIndex);
|
||||||
|
|
||||||
|
Intent aSlideChangedIntent = new Intent(
|
||||||
|
CommunicationService.MSG_SLIDE_CHANGED);
|
||||||
|
aSlideChangedIntent.putExtra("slide_number", aCurrentSlideIndex);
|
||||||
|
|
||||||
|
LocalBroadcastManager.getInstance(mContext)
|
||||||
|
.sendBroadcast(aSlideChangedIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpSlidePreview(List<String> aInstruction) {
|
||||||
|
int aSlideIndex = Integer.parseInt(aInstruction.get(1));
|
||||||
|
String aImageAsString = aInstruction.get(2);
|
||||||
|
|
||||||
|
byte[] aImage = Base64.decode(aImageAsString, Base64.DEFAULT);
|
||||||
|
mSlideShow.setSlidePreview(aSlideIndex, aImage);
|
||||||
|
|
||||||
|
Intent aSlidePreviewChangedIntent = new Intent(
|
||||||
CommunicationService.MSG_SLIDE_PREVIEW);
|
CommunicationService.MSG_SLIDE_PREVIEW);
|
||||||
aIntent.putExtra("slide_number", aSlideNumber);
|
aSlidePreviewChangedIntent.putExtra("slide_number", aSlideIndex);
|
||||||
LocalBroadcastManager.getInstance(mContext).sendBroadcast(
|
|
||||||
aIntent);
|
LocalBroadcastManager.getInstance(mContext)
|
||||||
} catch (IllegalArgumentException e) {
|
.sendBroadcast(aSlidePreviewChangedIntent);
|
||||||
// Bad data - tough luck
|
|
||||||
}
|
|
||||||
} else if (aInstruction.equals("slide_notes")) {
|
|
||||||
int aSlideNumber = Integer.parseInt(aCommand.get(1));
|
|
||||||
StringBuilder aNotes = new StringBuilder();
|
|
||||||
for (int i = 2; i < aCommand.size(); i++) {
|
|
||||||
aNotes.append(aCommand.get(i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store image internally
|
private void setUpSlideNotes(List<String> aInstruction) {
|
||||||
mSlideShow.putNotes(aSlideNumber, aNotes.toString());
|
int aSlideIndex = Integer.parseInt(aInstruction.get(1));
|
||||||
|
StringBuilder aNotesBuilder = new StringBuilder();
|
||||||
|
for (int aNoteIndex = 2; aNoteIndex < aInstruction
|
||||||
|
.size(); aNoteIndex++) {
|
||||||
|
aNotesBuilder.append(aInstruction.get(aNoteIndex));
|
||||||
|
}
|
||||||
|
String aNotes = aNotesBuilder.toString();
|
||||||
|
|
||||||
Intent aIntent = new Intent(
|
mSlideShow.setSlideNotes(aSlideIndex, aNotes);
|
||||||
|
|
||||||
|
Intent aSlideNotesChangedIntent = new Intent(
|
||||||
CommunicationService.MSG_SLIDE_NOTES);
|
CommunicationService.MSG_SLIDE_NOTES);
|
||||||
aIntent.putExtra("slide_number", aSlideNumber);
|
aSlideNotesChangedIntent.putExtra("slide_number", aSlideIndex);
|
||||||
LocalBroadcastManager.getInstance(mContext).sendBroadcast(
|
|
||||||
aIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
LocalBroadcastManager.getInstance(mContext)
|
||||||
|
.sendBroadcast(aSlideNotesChangedIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,27 +12,28 @@ import android.os.Parcel;
|
|||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
public class Server implements Parcelable {
|
public class Server implements Parcelable {
|
||||||
|
private static final int SPECIAL_PARCELABLE_OBJECTS_BITMASK = 0;
|
||||||
|
|
||||||
public enum Protocol {
|
public static enum Protocol {
|
||||||
NETWORK, BLUETOOTH
|
NETWORK, BLUETOOTH
|
||||||
}
|
}
|
||||||
|
|
||||||
private Protocol mProtocol;
|
private final Protocol mProtocol;
|
||||||
private String mAddress;
|
private final String mAddress;
|
||||||
private String mName;
|
private final String mName;
|
||||||
private long mTimeDiscovered;
|
private final long mTimeDiscovered;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signifies a Server that shouldn't be automatically removed from the list.
|
* Signifies a Server that shouldn't be automatically removed from the list.
|
||||||
* Used e.g. for the emulator.
|
* Used e.g. for the emulator.
|
||||||
*/
|
*/
|
||||||
protected boolean mNoTimeout = false;
|
protected boolean mNoTimeout = false;
|
||||||
|
|
||||||
protected Server(Protocol aProtocol, String aAddress, String aName,
|
protected Server(Protocol aProtocol, String aAddress, String aName, long aTimeDiscovered) {
|
||||||
long aTimeDiscovered) {
|
this.mProtocol = aProtocol;
|
||||||
mProtocol = aProtocol;
|
this.mAddress = aAddress;
|
||||||
mAddress = aAddress;
|
this.mName = aName;
|
||||||
mName = aName;
|
this.mTimeDiscovered = aTimeDiscovered;
|
||||||
mTimeDiscovered = aTimeDiscovered;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Protocol getProtocol() {
|
public Protocol getProtocol() {
|
||||||
@@ -43,11 +44,6 @@ public class Server implements Parcelable {
|
|||||||
return mAddress;
|
return mAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a human friendly name for the server.
|
|
||||||
*
|
|
||||||
* @return The name.
|
|
||||||
*/
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return mName;
|
return mName;
|
||||||
}
|
}
|
||||||
@@ -57,25 +53,26 @@ public class Server implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getName() + '@' + Integer.toHexString(hashCode()) + ":{" + mAddress + "," + mName + "}";
|
return getClass().getName() + '@' + Integer
|
||||||
|
.toHexString(hashCode()) + ":{" + mAddress + "," + mName + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
return SPECIAL_PARCELABLE_OBJECTS_BITMASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel out, int flags) {
|
public void writeToParcel(Parcel parcel, int flags) {
|
||||||
out.writeString(mAddress);
|
parcel.writeString(mAddress);
|
||||||
out.writeString(mName);
|
parcel.writeString(mName);
|
||||||
out.writeString(mProtocol.name());
|
parcel.writeString(mProtocol.name());
|
||||||
out.writeLong(mTimeDiscovered);
|
parcel.writeLong(mTimeDiscovered);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<Server> CREATOR = new Parcelable.Creator<Server>() {
|
public static final Parcelable.Creator<Server> CREATOR = new Parcelable.Creator<Server>() {
|
||||||
public Server createFromParcel(Parcel in) {
|
public Server createFromParcel(Parcel parcel) {
|
||||||
return new Server(in);
|
return new Server(parcel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Server[] newArray(int size) {
|
public Server[] newArray(int size) {
|
||||||
@@ -83,11 +80,11 @@ public class Server implements Parcelable {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private Server(Parcel in) {
|
private Server(Parcel parcel) {
|
||||||
mAddress = in.readString();
|
this.mAddress = parcel.readString();
|
||||||
mName = in.readString();
|
this.mName = parcel.readString();
|
||||||
mProtocol = Protocol.valueOf(in.readString());
|
this.mProtocol = Protocol.valueOf(parcel.readString());
|
||||||
mTimeDiscovered = in.readLong();
|
this.mTimeDiscovered = parcel.readLong();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,8 +8,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.libreoffice.impressremote.communication;
|
package org.libreoffice.impressremote.communication;
|
||||||
|
|
||||||
import org.libreoffice.impressremote.R;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
@@ -19,38 +17,47 @@ import android.graphics.Paint;
|
|||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
|
import org.libreoffice.impressremote.R;
|
||||||
|
|
||||||
|
|
||||||
public class SlideShow {
|
public class SlideShow {
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
private SparseArray<Bitmap> mPreviews = new SparseArray<Bitmap>();
|
private int mSlidesCount;
|
||||||
private SparseArray<String> mNotes = new SparseArray<String>();
|
private int mCurrentSlideIndex;
|
||||||
|
|
||||||
private int mSize = 0;
|
private final SparseArray<Bitmap> mSlidePreviews;
|
||||||
private int mCurrentSlide = 0;
|
private final SparseArray<String> mSlideNotes;
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
protected SlideShow(Context aContext) {
|
public SlideShow(Context aContext) {
|
||||||
mContext = aContext;
|
this.mContext = aContext;
|
||||||
|
|
||||||
|
this.mSlidesCount = 0;
|
||||||
|
this.mCurrentSlideIndex = 0;
|
||||||
|
|
||||||
|
this.mSlidePreviews = new SparseArray<Bitmap>();
|
||||||
|
this.mSlideNotes = new SparseArray<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setLength(int aSize) {
|
public void setSlidesCount(int aSlidesCount) {
|
||||||
mSize = aSize;
|
this.mSlidesCount = aSlidesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize() {
|
public int getSlidesCount() {
|
||||||
return mSize;
|
return mSlidesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentSlide() {
|
public void setCurrentSlideIndex(int aCurrentSlideIndex) {
|
||||||
return mCurrentSlide;
|
this.mCurrentSlideIndex = aCurrentSlideIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setCurrentSlide(int aSlide) {
|
public int getCurrentSlideIndex() {
|
||||||
mCurrentSlide = aSlide;
|
return mCurrentSlideIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void putImage(int aSlide, byte[] aImage) {
|
public void setSlidePreview(int aSlideIndex, byte[] aSlidePreview) {
|
||||||
Bitmap aBitmap = BitmapFactory.decodeByteArray(aImage, 0, aImage.length);
|
Bitmap aBitmap = BitmapFactory
|
||||||
|
.decodeByteArray(aSlidePreview, 0, aSlidePreview.length);
|
||||||
final int borderWidth = 8;
|
final int borderWidth = 8;
|
||||||
|
|
||||||
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
|
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
@@ -67,21 +74,22 @@ public class SlideShow {
|
|||||||
canvas.drawRect(aRect, p);
|
canvas.drawRect(aRect, p);
|
||||||
canvas.drawBitmap(aBitmap, null, aRect, null);
|
canvas.drawBitmap(aBitmap, null, aRect, null);
|
||||||
|
|
||||||
mPreviews.put(aSlide, aOut);
|
mSlidePreviews.put(aSlideIndex, aOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getImage(int aSlide) {
|
public Bitmap getSlidePreview(int aSlideIndex) {
|
||||||
return mPreviews.get(aSlide);
|
return mSlidePreviews.get(aSlideIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void putNotes(int aSlide, String aNotes) {
|
public void setSlideNotes(int aSlideIndex, String aSlideNotes) {
|
||||||
mNotes.put(aSlide, aNotes);
|
mSlideNotes.put(aSlideIndex, aSlideNotes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNotes(int aSlide) {
|
public String getSlideNotes(int aSlideIndex) {
|
||||||
String aNote = mNotes.get(aSlide);
|
String aSlideNotes = mSlideNotes.get(aSlideIndex);
|
||||||
if (aNote != null) {
|
|
||||||
return aNote;
|
if (aSlideNotes != null) {
|
||||||
|
return aSlideNotes;
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -97,7 +105,7 @@ public class SlideShow {
|
|||||||
public class Timer {
|
public class Timer {
|
||||||
/**
|
/**
|
||||||
* This stores the starting time of the timer if running.
|
* This stores the starting time of the timer if running.
|
||||||
*
|
* <p/>
|
||||||
* If paused this stores how long the timer was previously running.
|
* If paused this stores how long the timer was previously running.
|
||||||
*/
|
*/
|
||||||
private long aTime = 0;
|
private long aTime = 0;
|
||||||
@@ -110,8 +118,8 @@ public class SlideShow {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether this timer should be a normal or a countdown timer.
|
* Set whether this timer should be a normal or a countdown timer.
|
||||||
* @param aIsCountdown
|
*
|
||||||
* Whether this should be a countdown timer.
|
* @param aIsCountdown Whether this should be a countdown timer.
|
||||||
*/
|
*/
|
||||||
public void setCountdown(boolean aIsCountdown) {
|
public void setCountdown(boolean aIsCountdown) {
|
||||||
mIsCountdown = aIsCountdown;
|
mIsCountdown = aIsCountdown;
|
||||||
@@ -124,8 +132,8 @@ public class SlideShow {
|
|||||||
/**
|
/**
|
||||||
* Set the countdown time. Can be set, and isn't lost, whatever mode
|
* Set the countdown time. Can be set, and isn't lost, whatever mode
|
||||||
* the timer is running in.
|
* the timer is running in.
|
||||||
* @param aCountdownTime
|
*
|
||||||
* The countdown time.
|
* @param aCountdownTime The countdown time.
|
||||||
*/
|
*/
|
||||||
public void setCountdownTime(long aCountdownTime) {
|
public void setCountdownTime(long aCountdownTime) {
|
||||||
mCountdownTime = aCountdownTime;
|
mCountdownTime = aCountdownTime;
|
||||||
@@ -170,6 +178,7 @@ public class SlideShow {
|
|||||||
/**
|
/**
|
||||||
* Get either how long this timer has been running, or how long the
|
* Get either how long this timer has been running, or how long the
|
||||||
* timer still has left to run.
|
* timer still has left to run.
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public long getTimeMillis() {
|
public long getTimeMillis() {
|
||||||
|
@@ -14,56 +14,65 @@ import android.graphics.Color;
|
|||||||
* Interface to send commands to the server.
|
* Interface to send commands to the server.
|
||||||
*/
|
*/
|
||||||
public class Transmitter {
|
public class Transmitter {
|
||||||
|
private final Client mClient;
|
||||||
private Client mClient;
|
|
||||||
|
|
||||||
public Transmitter(Client aClient) {
|
public Transmitter(Client aClient) {
|
||||||
mClient = aClient;
|
this.mClient = aClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void nextTransition() {
|
public void performNextTransition() {
|
||||||
mClient.sendCommand("transition_next\n\n");
|
mClient.sendCommand(Protocol.Commands
|
||||||
|
.prepareCommand(Protocol.Commands.TRANSITION_NEXT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void previousTransition() {
|
public void performPreviousTransition() {
|
||||||
|
mClient.sendCommand(Protocol.Commands
|
||||||
mClient.sendCommand("transition_previous\n\n");
|
.prepareCommand(Protocol.Commands.TRANSITION_PREVIOUS));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gotoSlide(int slide) {
|
public void setCurrentSlide(int slideIndex) {
|
||||||
mClient.sendCommand("goto_slide\n" + slide + "\n\n");
|
mClient.sendCommand(Protocol.Commands
|
||||||
|
.prepareCommand(Protocol.Commands.GOTO_SLIDE,
|
||||||
|
Integer.toString(slideIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blank the screen to the default colour (set server-side), which is
|
* Blank the screen to the default colour (set server-side), which is
|
||||||
* generally black. This is slightly faster than using
|
* generally black. This is slightly faster than using
|
||||||
* <code> blankScreen( colour ) </code>.
|
* <code> setUpBlankScreen( colour ) </code>.
|
||||||
*/
|
*/
|
||||||
public void blankScreen() {
|
public void setUpBlankScreen() {
|
||||||
mClient.sendCommand("presentation_blank_screen\n\n");
|
mClient.sendCommand(Protocol.Commands
|
||||||
|
.prepareCommand(Protocol.Commands.PRESENTATION_BLANK_SCREEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the screen to a specific colour. Only use if a non default colour is
|
* Set the screen to a specific colour. Only use if a non default colour is
|
||||||
* needed.
|
* needed.
|
||||||
*
|
*
|
||||||
* @param aColor
|
* @param aColor blank screen color
|
||||||
*/
|
*/
|
||||||
public void blankScreen(Color aColor) {
|
public void setUpBlankScreen(Color aColor) {
|
||||||
// FIXME: check how to get colour in integer form.
|
// FIXME: check how to get colour in integer form.
|
||||||
mClient.sendCommand("presentation_blank_screen\n" + aColor + "\n\n");
|
|
||||||
|
mClient.sendCommand(Protocol.Commands
|
||||||
|
.prepareCommand(Protocol.Commands.PRESENTATION_BLANK_SCREEN,
|
||||||
|
aColor.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resume() {
|
public void resumePresentation() {
|
||||||
mClient.sendCommand("presentation_resume\n\n");
|
mClient.sendCommand(Protocol.Commands
|
||||||
|
.prepareCommand(Protocol.Commands.PRESENTATION_RESUME));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startPresentation() {
|
public void startPresentation() {
|
||||||
mClient.sendCommand("presentation_start\n\n");
|
mClient.sendCommand(Protocol.Commands
|
||||||
|
.prepareCommand(Protocol.Commands.PRESENTATION_START));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopPresentation() {
|
public void stopPresentation() {
|
||||||
mClient.sendCommand("presentation_stop\n\n");
|
mClient.sendCommand(Protocol.Commands
|
||||||
|
.prepareCommand(Protocol.Commands.PRESENTATION_STOP));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user