diff options
author | Artur Dryomov <artur.dryomov@gmail.com> | 2013-07-21 20:43:41 +0300 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2013-07-25 18:02:00 +0100 |
commit | e43a151549b7f87cb1c1c1165b9777697fd9c1d7 (patch) | |
tree | 410dc0270268f50fe9e22de9384caa0b4b78e5f0 /android | |
parent | Improve the ComputerConnectionFragment. (diff) | |
download | core-e43a151549b7f87cb1c1c1165b9777697fd9c1d7.tar.gz core-e43a151549b7f87cb1c1c1165b9777697fd9c1d7.zip |
Improve the SlideShowActivity.
* Enable up navigation.
* Show the current slide index properly.
* Show thumbnail if slide was not loaded yet.
Change-Id: I234dc1e583c8549b6a1c069d7e2294726d5e29d1
Diffstat (limited to 'android')
9 files changed, 195 insertions, 28 deletions
diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml index 072c406ea223..5bc029878737 100644 --- a/android/sdremote/res/values/strings.xml +++ b/android/sdremote/res/values/strings.xml @@ -32,4 +32,6 @@ <string name="hint_ip_address">IP address</string> <string name="hint_name">Name</string> + <string name="mask_slide_show_progress">Slide %1$d from %2$d</string> + </resources> diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java index 87c4a94bf4b2..7de2ee4049af 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SlideShowActivity.java @@ -8,24 +8,38 @@ */ package org.libreoffice.impressremote.activity; +import android.content.BroadcastReceiver; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.ServiceConnection; import android.os.Bundle; +import android.os.IBinder; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; +import android.support.v4.content.LocalBroadcastManager; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; import org.libreoffice.impressremote.R; +import org.libreoffice.impressremote.communication.CommunicationService; +import org.libreoffice.impressremote.communication.SlideShow; import org.libreoffice.impressremote.fragment.SlidesGridFragment; import org.libreoffice.impressremote.fragment.SlidesPagerFragment; +import org.libreoffice.impressremote.util.Intents; -public class SlideShowActivity extends SherlockFragmentActivity { +public class SlideShowActivity extends SherlockFragmentActivity implements ServiceConnection { private static enum Mode { PAGER, GRID } private Mode mMode; + private CommunicationService mCommunicationService; + private IntentsReceiver mIntentsReceiver; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -33,8 +47,9 @@ public class SlideShowActivity extends SherlockFragmentActivity { mMode = Mode.PAGER; setUpHomeButton(); - setUpFragment(); + + bindService(); } private void setUpHomeButton() { @@ -42,29 +57,117 @@ public class SlideShowActivity extends SherlockFragmentActivity { } private void setUpFragment() { + setUpFragment(buildFragment()); + } + + private Fragment buildFragment() { switch (mMode) { case PAGER: - setUpFragment(SlidesPagerFragment.newInstance()); - break; + return SlidesPagerFragment.newInstance(); case GRID: - setUpFragment(SlidesGridFragment.newInstance()); - break; + return SlidesGridFragment.newInstance(); default: - setUpFragment(SlidesPagerFragment.newInstance()); - break; + return SlidesPagerFragment.newInstance(); } } private void setUpFragment(Fragment aFragment) { FragmentTransaction aTransaction = getSupportFragmentManager().beginTransaction(); + aTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out); aTransaction.replace(android.R.id.content, aFragment); aTransaction.commit(); } + private void bindService() { + Intent aIntent = Intents.buildCommunicationServiceIntent(this); + bindService(aIntent, this, Context.BIND_AUTO_CREATE); + } + + @Override + public void onServiceConnected(ComponentName mComponentName, IBinder aBinder) { + CommunicationService.CBinder aServiceBinder = (CommunicationService.CBinder) aBinder; + mCommunicationService = aServiceBinder.getService(); + + startSlideShow(); + } + + private void startSlideShow() { + mCommunicationService.getTransmitter().startPresentation(); + } + + @Override + protected void onStart() { + super.onStart(); + + registerIntentsReceiver(); + } + + private void registerIntentsReceiver() { + mIntentsReceiver = new IntentsReceiver(this); + IntentFilter aIntentFilter = buildIntentsReceiverFilter(); + + getBroadcastManager().registerReceiver(mIntentsReceiver, aIntentFilter); + } + + private static final class IntentsReceiver extends BroadcastReceiver { + private final SlideShowActivity mSlideShowActivity; + + private IntentsReceiver(SlideShowActivity aSlideShowActivity) { + mSlideShowActivity = aSlideShowActivity; + } + + @Override + public void onReceive(Context aContext, Intent aIntent) { + if (Intents.Actions.SLIDE_CHANGED.equals(aIntent.getAction())) { + mSlideShowActivity.setUpSlideShowInformation(); + } + } + } + + private IntentFilter buildIntentsReceiverFilter() { + IntentFilter aIntentFilter = new IntentFilter(); + aIntentFilter.addAction(Intents.Actions.SLIDE_CHANGED); + + return aIntentFilter; + } + + private LocalBroadcastManager getBroadcastManager() { + return LocalBroadcastManager.getInstance(getApplicationContext()); + } + + private void setUpSlideShowInformation() { + if (!isServiceBound()) { + return; + } + + getSupportActionBar().setTitle(buildSlideShowProgress()); + getSupportActionBar().setSubtitle(buildSlideShowTimerProgress()); + } + + private String buildSlideShowProgress() { + SlideShow aSlideShow = mCommunicationService.getSlideShow(); + + int aCurrentSlideIndex = aSlideShow.getHumanCurrentSlideIndex(); + int aSlidesCount = aSlideShow.getSlidesCount(); + + return getString(R.string.mask_slide_show_progress, aCurrentSlideIndex, aSlidesCount); + } + + private String buildSlideShowTimerProgress() { + return null; + } + + @Override + protected void onResume() { + super.onResume(); + + setUpSlideShowInformation(); + } + @Override public boolean onCreateOptionsMenu(Menu aMenu) { getSupportMenuInflater().inflate(getActionBarMenuResourceId(), aMenu); @@ -104,6 +207,11 @@ public class SlideShowActivity extends SherlockFragmentActivity { return true; + case android.R.id.home: + navigateUp(); + + return true; + default: return super.onOptionsItemSelected(aMenuItem); } @@ -112,6 +220,50 @@ public class SlideShowActivity extends SherlockFragmentActivity { private void refreshActionBarMenu() { supportInvalidateOptionsMenu(); } + + private void navigateUp() { + finish(); + } + + @Override + protected void onStop() { + super.onStop(); + + unregisterIntentsReceiver(); + } + + private void unregisterIntentsReceiver() { + try { + getBroadcastManager().unregisterReceiver(mIntentsReceiver); + } catch (IllegalArgumentException e) { + // Receiver not registered. + // Fixed in Honeycomb: Android’s issue #6191. + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + unbindService(); + } + + private void unbindService() { + if (!isServiceBound()) { + return; + } + + unbindService(this); + } + + private boolean isServiceBound() { + return mCommunicationService != null; + } + + @Override + public void onServiceDisconnected(ComponentName aComponentName) { + mCommunicationService = null; + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersAdapter.java b/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersAdapter.java index ea9010af7f09..9f16976fd24c 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersAdapter.java +++ b/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersAdapter.java @@ -26,8 +26,7 @@ public class ComputersAdapter extends ArrayAdapter<Server> { public ComputersAdapter(Context aContext) { super(aContext, R.layout.list_item); - mLayoutInflater = (LayoutInflater) aContext - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mLayoutInflater = LayoutInflater.from(aContext); } @Override @@ -44,8 +43,7 @@ public class ComputersAdapter extends ArrayAdapter<Server> { return aConvertView; } - return mLayoutInflater - .inflate(R.layout.list_item, aParentViewGroup, false); + return mLayoutInflater.inflate(R.layout.list_item, aParentViewGroup, false); } private String buildListItemText(int aPosition) { diff --git a/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersPagerAdapter.java b/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersPagerAdapter.java index 5a4ddaada85a..4a15ab349347 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersPagerAdapter.java +++ b/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersPagerAdapter.java @@ -1,3 +1,11 @@ +/* -*- 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.adapter; import android.support.v4.app.Fragment; @@ -40,3 +48,5 @@ public class ComputersPagerAdapter extends FragmentPagerAdapter { return PAGER_SIZE; } } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesGridAdapter.java b/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesGridAdapter.java index 45ccb55067a7..f7f7a010b8ab 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesGridAdapter.java +++ b/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesGridAdapter.java @@ -25,15 +25,11 @@ public class SlidesGridAdapter extends BaseAdapter { private final SlideShow mSlideShow; public SlidesGridAdapter(Context aContext, SlideShow aSlideShow) { - mLayoutInflater = buildLayoutInflater(aContext); + mLayoutInflater = LayoutInflater.from(aContext); mSlideShow = aSlideShow; } - private LayoutInflater buildLayoutInflater(Context aContext) { - return (LayoutInflater) aContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - } - @Override public int getCount() { return mSlideShow.getSlidesCount(); @@ -57,8 +53,7 @@ public class SlidesGridAdapter extends BaseAdapter { if (isSlidePreviewAvailable(aPosition)) { aSlideViewHolder.aSlidePreview.setImageBitmap(mSlideShow.getSlidePreview(aPosition)); } else { - aSlideViewHolder.aSlidePreview.setImageResource( - R.drawable.slide_unknown); + aSlideViewHolder.aSlidePreview.setImageResource(R.drawable.slide_unknown); } aSlideViewHolder.aSlideIndex.setText(buildSlideIndex(aPosition)); diff --git a/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java b/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java index 9aec981e928a..352e7a89f849 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java +++ b/android/sdremote/src/org/libreoffice/impressremote/adapter/SlidesPagerAdapter.java @@ -24,14 +24,11 @@ public class SlidesPagerAdapter extends PagerAdapter { private final SlideShow mSlideShow; public SlidesPagerAdapter(Context aContext, SlideShow aSlideShow) { - mLayoutInflater = buildLayoutInflater(aContext); + mLayoutInflater = LayoutInflater.from(aContext); mSlideShow = aSlideShow; } - private LayoutInflater buildLayoutInflater(Context aContext) { - return (LayoutInflater) aContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - } @Override public int getCount() { return mSlideShow.getSlidesCount(); @@ -41,7 +38,12 @@ public class SlidesPagerAdapter extends PagerAdapter { public Object instantiateItem(ViewGroup aViewGroup, int aPosition) { ImageView aSlideView = (ImageView) getView(aViewGroup); - aSlideView.setImageBitmap(mSlideShow.getSlidePreview(aPosition)); + if (isSlidePreviewAvailable(aPosition)) { + aSlideView.setImageBitmap(mSlideShow.getSlidePreview(aPosition)); + } + else { + aSlideView.setImageResource(R.drawable.slide_unknown); + } aViewGroup.addView(aSlideView); @@ -52,6 +54,10 @@ public class SlidesPagerAdapter extends PagerAdapter { return mLayoutInflater.inflate(R.layout.view_pager_slide, aViewGroup, false); } + private boolean isSlidePreviewAvailable(int aSlideIndex) { + return mSlideShow.getSlidePreview(aSlideIndex) != null; + } + @Override public void destroyItem(ViewGroup aViewGroup, int aPosition, Object aObject) { View aView = (View) aObject; @@ -66,6 +72,8 @@ public class SlidesPagerAdapter extends PagerAdapter { @Override public int getItemPosition(Object aObject) { + // TODO: think about it, seems like a hack + return POSITION_NONE; } } diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java b/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java index f8ae6d898265..79852c507b68 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java @@ -48,6 +48,10 @@ public class SlideShow { return mCurrentSlideIndex; } + public int getHumanCurrentSlideIndex() { + return getCurrentSlideIndex() + 1; + } + public void setSlidePreview(int aSlideIndex, byte[] aSlidePreviewBytes) { Bitmap aSlidePreview = BitmapFactory .decodeByteArray(aSlidePreviewBytes, 0, aSlidePreviewBytes.length); diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java index 6c0fe8795979..ebc9a24d02ef 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java +++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesGridFragment.java @@ -61,8 +61,6 @@ public class SlidesGridFragment extends SherlockFragment implements ServiceConne mCommunicationService = aServiceBinder.getService(); - mCommunicationService.getTransmitter().startPresentation(); - setUpSlidesGrid(); } diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java index c3ebb2c9e6ab..cb9872f6c20b 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java +++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java @@ -61,8 +61,6 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn mCommunicationService = aServiceBinder.getService(); - mCommunicationService.getTransmitter().startPresentation(); - setUpSlidesPager(); } @@ -72,6 +70,8 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn getSlidesPager().setAdapter(aSlidesPagerAdapter); + getSlidesPager().setCurrentItem(mCommunicationService.getSlideShow().getCurrentSlideIndex()); + getSlidesPager().setPageMargin(getSlidesMarginInPx()); getSlidesPager().setOnPageChangeListener(this); |