diff options
author | Artur Dryomov <artur.dryomov@gmail.com> | 2013-07-27 23:17:50 +0300 |
---|---|---|
committer | Artur Dryomov <artur.dryomov@gmail.com> | 2013-07-29 04:13:11 +0300 |
commit | 766b6f5b14b517e178c9b86611d0edb7582e1ede (patch) | |
tree | 166a197de9c1bb7a3d7054858e763d378f8de8cd /android | |
parent | a92fa984ae24dc25283d4b6805cff01bf00117e5 (diff) |
Add notes support.
It is not possible at moment to add borders to slides previews because
ViewPager has no constant height and ignores wrap_content property. The
current solution seems to be the best.
Change-Id: I14b41e0bda578d2ffcdb1c887d633c6201aa383a
Diffstat (limited to 'android')
8 files changed, 169 insertions, 34 deletions
diff --git a/android/sdremote/res/drawable/underline_header.xml b/android/sdremote/res/drawable/underline_header.xml new file mode 100644 index 000000000000..cee5b99459c6 --- /dev/null +++ b/android/sdremote/res/drawable/underline_header.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> + + <size + android:width="10000dp" + android:height="1dp"/> + + <solid + android:color="@color/background_header"/> + +</shape>
\ No newline at end of file diff --git a/android/sdremote/res/layout/fragment_slides_pager.xml b/android/sdremote/res/layout/fragment_slides_pager.xml index 14e5cf104e3c..20b43365dcf7 100644 --- a/android/sdremote/res/layout/fragment_slides_pager.xml +++ b/android/sdremote/res/layout/fragment_slides_pager.xml @@ -1,13 +1,79 @@ <?xml version="1.0" encoding="utf-8"?> -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent"> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:gravity="center" + android:paddingTop="@dimen/padding_slides_pager" + android:paddingBottom="@dimen/padding_slides_pager" + android:layout_width="match_parent" + android:layout_height="match_parent"> <android.support.v4.view.ViewPager android:id="@+id/pager_slides" - android:padding="@dimen/padding_slides_pager" - android:layout_centerInParent="true" + android:layout_weight="4" android:layout_width="match_parent" - android:layout_height="@dimen/height_slides_pager"/> + android:layout_height="0dp"/> -</RelativeLayout> + <ViewAnimator + android:id="@+id/view_animator" + android:inAnimation="@android:anim/fade_in" + android:outAnimation="@android:anim/fade_out" + android:layout_weight="3" + android:layout_width="match_parent" + android:layout_height="0dp"> + + <View + android:id="@+id/view_empty" + android:layout_width="match_parent" + android:layout_height="match_parent"/> + + <LinearLayout + android:id="@+id/layout_notes" + android:orientation="vertical" + android:paddingLeft="@dimen/padding_slides_pager" + android:paddingRight="@dimen/padding_slides_pager" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <TextView + android:text="@string/header_notes" + android:textAllCaps="true" + android:textStyle="bold" + android:textColor="@color/background_header" + android:drawableBottom="@drawable/underline_header" + android:drawablePadding="4dp" + android:paddingLeft="@dimen/padding_header" + android:paddingTop="@dimen/padding_header" + android:gravity="left" + android:layout_width="fill_parent" + android:layout_height="wrap_content"/> + + <ScrollView + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + + <TextSwitcher + android:id="@+id/text_switcher_notes" + android:inAnimation="@android:anim/fade_in" + android:outAnimation="@android:anim/fade_out" + android:paddingTop="@dimen/padding_slide_notes" + android:paddingLeft="@dimen/padding_slide_notes" + android:paddingRight="@dimen/padding_slide_notes" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content"/> + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content"/> + + </TextSwitcher> + + </ScrollView> + + </LinearLayout> + + </ViewAnimator> + +</LinearLayout> diff --git a/android/sdremote/res/layout/view_pager_slide.xml b/android/sdremote/res/layout/view_pager_slide.xml index 0ebb367455e8..6ca8f916ea89 100644 --- a/android/sdremote/res/layout/view_pager_slide.xml +++ b/android/sdremote/res/layout/view_pager_slide.xml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/image_slide_preview" - android:background="@drawable/background_pager_slide" - android:adjustViewBounds="true" + android:scaleType="fitCenter" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
\ No newline at end of file diff --git a/android/sdremote/res/values/colors.xml b/android/sdremote/res/values/colors.xml index ed05f91ee040..f43e8f1e0caf 100644 --- a/android/sdremote/res/values/colors.xml +++ b/android/sdremote/res/values/colors.xml @@ -3,6 +3,7 @@ <color name="background_action_bar">#e46f1f</color> <color name="background_action_bar_divider">#55ffffff</color> + <color name="background_header">@color/background_action_bar</color> <color name="background_slide_index">#7f000000</color> <color name="stroke_grid_slide">#65000000</color> diff --git a/android/sdremote/res/values/dimens.xml b/android/sdremote/res/values/dimens.xml index d4c2e5b07b04..9a079a65e0ae 100644 --- a/android/sdremote/res/values/dimens.xml +++ b/android/sdremote/res/values/dimens.xml @@ -1,11 +1,18 @@ <?xml version="1.0" encoding="utf-8"?> <resources> + <!-- It is a good practice to follow official design metrics. --> + <!-- http://developer.android.com/design/style/metrics-grids.html --> + <dimen name="padding_action_bar_button_drawable">8dp</dimen> <dimen name="padding_creation_layout">16dp</dimen> <dimen name="padding_slides_grid">4dp</dimen> <dimen name="padding_slides_pager">16dp</dimen> <dimen name="padding_slide">4dp</dimen> + <dimen name="padding_header_underline">4dp</dimen> + <dimen name="padding_slides_pager_layout">8dp</dimen> + <dimen name="padding_header">8dp</dimen> + <dimen name="padding_slide_notes">8dp</dimen> <dimen name="padding_horizontal_list_item">8dp</dimen> <dimen name="padding_horizontal_connection_layout">40dp</dimen> @@ -29,6 +36,4 @@ <dimen name="spacing_slides_grid">4dp</dimen> - <dimen name="height_slides_pager">250dp</dimen> - </resources>
\ No newline at end of file diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml index 5bc029878737..16c1de821d6f 100644 --- a/android/sdremote/res/values/strings.xml +++ b/android/sdremote/res/values/strings.xml @@ -32,6 +32,8 @@ <string name="hint_ip_address">IP address</string> <string name="hint_name">Name</string> + <string name="header_notes">Notes</string> + <string name="mask_slide_show_progress">Slide %1$d from %2$d</string> </resources> diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java b/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java index a216dfc8f0eb..0b9b1d6dc61a 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/SlideShow.java @@ -65,11 +65,11 @@ public class SlideShow { public String getSlideNotes(int aSlideIndex) { String aSlideNotes = mSlideNotes.get(aSlideIndex); - if (aSlideNotes != null) { - return aSlideNotes; - } else { + if (aSlideNotes == null) { return ""; } + + return aSlideNotes; } public Timer getTimer() { diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java index cb9872f6c20b..adbc74ba50d5 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java +++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/SlidesPagerFragment.java @@ -17,13 +17,21 @@ import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; import android.support.v4.content.LocalBroadcastManager; +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; +import android.widget.TextSwitcher; +import android.widget.TextView; +import android.widget.ViewAnimator; 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.SlidesPagerAdapter; @@ -50,52 +58,94 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn } private void bindService() { - Intent aServiceIntent = new Intent(getActivity(), CommunicationService.class); - + Intent aServiceIntent = Intents.buildCommunicationServiceIntent(getActivity()); getActivity().bindService(aServiceIntent, this, Context.BIND_AUTO_CREATE); } @Override public void onServiceConnected(ComponentName aComponentName, IBinder aBinder) { CommunicationService.CBinder aServiceBinder = (CommunicationService.CBinder) aBinder; - mCommunicationService = aServiceBinder.getService(); setUpSlidesPager(); } private void setUpSlidesPager() { - SlidesPagerAdapter aSlidesPagerAdapter = new SlidesPagerAdapter(getActivity(), - mCommunicationService.getSlideShow()); - - getSlidesPager().setAdapter(aSlidesPagerAdapter); - - getSlidesPager().setCurrentItem(mCommunicationService.getSlideShow().getCurrentSlideIndex()); - - getSlidesPager().setPageMargin(getSlidesMarginInPx()); + ViewPager aSlidesPager = getSlidesPager(); - getSlidesPager().setOnPageChangeListener(this); + aSlidesPager.setAdapter(buildSlidesAdapter()); + aSlidesPager.setCurrentItem(mCommunicationService.getSlideShow().getCurrentSlideIndex()); + aSlidesPager.setPageMargin(getSlidesMarginInPx()); + aSlidesPager.setOnPageChangeListener(this); } private ViewPager getSlidesPager() { return (ViewPager) getView().findViewById(R.id.pager_slides); } + private PagerAdapter buildSlidesAdapter() { + SlideShow aSlideShow = mCommunicationService.getSlideShow(); + + 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(TypedValue.COMPLEX_UNIT_PX, aSlideMarginInDp, - getResources().getDisplayMetrics()); + return (int) TypedValue.applyDimension(aPxUnit, aSlideMarginInDp, aDisplayMetrics); } @Override - public void onPageScrolled(int aPosition, float aPositionOffset, int aPositionOffsetPixels) { + public void onPageSelected(int aPosition) { + mCommunicationService.getTransmitter().setCurrentSlide(aPosition); + + setUpSlideNotes(aPosition); + } + + private void setUpSlideNotes(int aSlideIndex) { + if (areSlideNotesAvailable(aSlideIndex)) { + showSlideNotes(aSlideIndex); + } + else { + hideSlideNotes(); + } + } + + private boolean areSlideNotesAvailable(int aSlideIndex) { + String aSlideNotes = mCommunicationService.getSlideShow().getSlideNotes(aSlideIndex); + + return !TextUtils.isEmpty(Html.fromHtml(aSlideNotes).toString().trim()); + } + + private void showSlideNotes(int aSlideIndex) { + ViewAnimator aViewAnimator = (ViewAnimator) getView().findViewById(R.id.view_animator); + ViewGroup aNotesLayout = (ViewGroup) getView().findViewById(R.id.layout_notes); + + if (aViewAnimator.getDisplayedChild() != aViewAnimator.indexOfChild(aNotesLayout)) { + aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aNotesLayout)); + } + + setSlideNotes(aSlideIndex); + } + + private void setSlideNotes(int aSlideIndex) { + TextSwitcher aSlideNotesTextSwitcher = (TextSwitcher) getView().findViewById(R.id.text_switcher_notes); + String aSlideNotes = mCommunicationService.getSlideShow().getSlideNotes(aSlideIndex); + + aSlideNotesTextSwitcher.setText(Html.fromHtml(aSlideNotes)); + } + + private void hideSlideNotes() { + ViewAnimator aViewAnimator = (ViewAnimator) getView().findViewById(R.id.view_animator); + View aEmptyView = getView().findViewById(R.id.view_empty); + + aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aEmptyView)); } @Override - public void onPageSelected(int aPosition) { - mCommunicationService.getTransmitter().setCurrentSlide(aPosition); + public void onPageScrolled(int aPosition, float aPositionOffset, int aPositionOffsetPixels) { } @Override @@ -131,7 +181,7 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn @Override public void onReceive(Context aContext, Intent aIntent) { if (Intents.Actions.SLIDE_PREVIEW.equals(aIntent.getAction())) { - mSlidesGridFragment.refreshSlidesGrid(); + mSlidesGridFragment.refreshSlidesPager(); } } } @@ -149,7 +199,7 @@ public class SlidesPagerFragment extends SherlockFragment implements ServiceConn return LocalBroadcastManager.getInstance(aContext); } - private void refreshSlidesGrid() { + private void refreshSlidesPager() { getSlidesPager().getAdapter().notifyDataSetChanged(); } |