diff options
6 files changed, 47 insertions, 40 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java index fc0f7c623754..4cde89d1ece2 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java @@ -385,7 +385,7 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi stopTimer(); - disconnectComputer(); + // TODO: disconnect computer unbindService(); } @@ -394,10 +394,6 @@ public class SlideShowActivity extends SherlockFragmentActivity implements Servi mCommunicationService.getSlideShow().getTimer().stop(); } - private void disconnectComputer() { - mCommunicationService.disconnect(); - } - private void unbindService() { unbindService(this); } diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java index 51ca64c90996..e6dd88a9c85b 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java @@ -45,6 +45,7 @@ public class CommunicationService extends Service implements Runnable, MessagesL private boolean mBluetoothWasEnabled; + private Timer mTimer; private SlideShow mSlideShow; private Thread mThread; @@ -62,7 +63,8 @@ public class CommunicationService extends Service implements Runnable, MessagesL mBluetoothWasEnabled = false; - mSlideShow = new SlideShow(new Timer(this)); + mTimer = new Timer(this); + mSlideShow = new SlideShow(mTimer); mThread = new Thread(this); mThread.start(); @@ -247,7 +249,7 @@ public class CommunicationService extends Service implements Runnable, MessagesL @Override public void onSlideShowStart(int aSlidesCount, int aCurrentSlideIndex) { - mSlideShow.cleanUp(); + mSlideShow = new SlideShow(mTimer); mSlideShow.setSlidesCount(aSlidesCount); Intent aIntent = Intents.buildSlideShowRunningIntent(); @@ -258,7 +260,7 @@ public class CommunicationService extends Service implements Runnable, MessagesL @Override public void onSlideShowFinish() { - mSlideShow.cleanUp(); + mSlideShow = new SlideShow(mTimer); Intent aIntent = Intents.buildSlideShowStoppedIntent(); LocalBroadcastManager.getInstance(this).sendBroadcast(aIntent); diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/MessagesReceiver.java b/android/sdremote/src/org/libreoffice/impressremote/communication/MessagesReceiver.java index bb6de8fc8742..4d226d868183 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/MessagesReceiver.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/MessagesReceiver.java @@ -14,12 +14,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import android.text.TextUtils; import android.util.Base64; -import android.util.Log; class MessagesReceiver implements Runnable { private final BufferedReader mMessagesReader; diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java b/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java index f6aa6dd1b40e..19963686b09d 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java @@ -75,14 +75,6 @@ public class SlideShow { public Timer getTimer() { return mTimer; } - - public void cleanUp() { - mSlidesCount = 0; - mCurrentSlideIndex = 0; - - mSlidePreviewsBytes.clear(); - mSlideNotes.clear(); - } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java index dcfd6efc5ae1..021a4920fa3f 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java +++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java @@ -24,6 +24,7 @@ import android.widget.AdapterView; import android.widget.GridView; import com.actionbarsherlock.app.SherlockFragment; +import org.libreoffice.impressremote.communication.SlideShow; import org.libreoffice.impressremote.util.Intents; import org.libreoffice.impressremote.R; import org.libreoffice.impressremote.adapter.SlidesGridAdapter; @@ -63,17 +64,31 @@ public class SlidesGridFragment extends SherlockFragment implements ServiceConne } private void setUpSlidesGrid() { - SlidesGridAdapter aSlidesGridAdapter = new SlidesGridAdapter(getActivity(), - mCommunicationService.getSlideShow()); + if (!isAdded()) { + return; + } - getSlidesGrid().setAdapter(aSlidesGridAdapter); - getSlidesGrid().setOnItemClickListener(this); + GridView aSlidesGrid = getSlidesGrid(); + + aSlidesGrid.setAdapter(buildSlidesAdapter()); + aSlidesGrid.setOnItemClickListener(this); } private GridView getSlidesGrid() { return (GridView) getView().findViewById(R.id.grid_slides); } + private SlidesGridAdapter buildSlidesAdapter() { + SlideShow aSlideShow = mCommunicationService.getSlideShow(); + + return new SlidesGridAdapter(getActivity(), aSlideShow); + } + + @Override + public void onItemClick(AdapterView<?> aAdapterView, View aView, int aPosition, long aId) { + mCommunicationService.getTransmitter().setCurrentSlide(aPosition); + } + @Override public void onServiceDisconnected(ComponentName aComponentName) { mCommunicationService = null; @@ -93,11 +108,6 @@ public class SlidesGridFragment extends SherlockFragment implements ServiceConne getBroadcastManager().registerReceiver(mIntentsReceiver, aIntentFilter); } - @Override - public void onItemClick(AdapterView<?> aAdapterView, View aView, int aPosition, long aId) { - mCommunicationService.getTransmitter().setCurrentSlide(aPosition); - } - private static final class IntentsReceiver extends BroadcastReceiver { private final SlidesGridFragment mSlidesGridFragment; @@ -109,7 +119,6 @@ public class SlidesGridFragment extends SherlockFragment implements ServiceConne public void onReceive(Context aContext, Intent aIntent) { if (Intents.Actions.SLIDE_SHOW_RUNNING.equals(aIntent.getAction())) { mSlidesGridFragment.refreshSlidesGrid(); - return; } diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java index 3092503a8c10..838245a0d35b 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java +++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java @@ -21,8 +21,6 @@ import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.text.Html; import android.text.TextUtils; -import android.util.DisplayMetrics; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -70,10 +68,14 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn } private void setUpSlidesPager() { + if (!isAdded()) { + return; + } + ViewPager aSlidesPager = getSlidesPager(); aSlidesPager.setAdapter(buildSlidesAdapter()); - aSlidesPager.setPageMargin(getSlidesMarginInPx()); + aSlidesPager.setPageMargin(getSlidesMargin()); aSlidesPager.setOnPageChangeListener(this); setUpCurrentSlide(); @@ -89,12 +91,8 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn return new SlidesPagerAdapter(getActivity(), aSlideShow); } - private int getSlidesMarginInPx() { - int aPxUnit = TypedValue.COMPLEX_UNIT_PX; - float aSlideMarginInDp = getResources().getDimension(R.dimen.margin_slide); - DisplayMetrics aDisplayMetrics = getResources().getDisplayMetrics(); - - return (int) TypedValue.applyDimension(aPxUnit, aSlideMarginInDp, aDisplayMetrics); + private int getSlidesMargin() { + return getResources().getDimensionPixelSize(R.dimen.margin_slide); } private void setUpCurrentSlide() { @@ -186,21 +184,33 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn @Override public void onReceive(Context aContext, Intent aIntent) { - if (Intents.Actions.SLIDE_PREVIEW.equals(aIntent.getAction())) { - mSlidesPagerFragment.refreshSlidesPager(); + if (Intents.Actions.SLIDE_SHOW_RUNNING.equals(aIntent.getAction())) { + mSlidesPagerFragment.setUpSlidesPager(); + return; + } + + if (Intents.Actions.SLIDE_SHOW_STOPPED.equals(aIntent.getAction())) { + mSlidesPagerFragment.setUpSlidesPager(); return; } if (Intents.Actions.SLIDE_CHANGED.equals(aIntent.getAction())) { mSlidesPagerFragment.setUpCurrentSlide(); + return; + } + + if (Intents.Actions.SLIDE_PREVIEW.equals(aIntent.getAction())) { + mSlidesPagerFragment.refreshSlidesPager(); } } } private IntentFilter buildIntentsReceiverFilter() { IntentFilter aIntentFilter = new IntentFilter(); - aIntentFilter.addAction(Intents.Actions.SLIDE_PREVIEW); + aIntentFilter.addAction(Intents.Actions.SLIDE_SHOW_RUNNING); + aIntentFilter.addAction(Intents.Actions.SLIDE_SHOW_STOPPED); aIntentFilter.addAction(Intents.Actions.SLIDE_CHANGED); + aIntentFilter.addAction(Intents.Actions.SLIDE_PREVIEW); return aIntentFilter; } |