diff options
author | Artur Dryomov <artur.dryomov@gmail.com> | 2013-07-17 00:27:04 +0300 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2013-07-25 18:01:56 +0100 |
commit | 043a580648ebf3f8fb50bfce9bf03cbfdcda1fd2 (patch) | |
tree | 5fe6f5cbc6b3bdde3771deea42c62bcbae68b8b3 /android | |
parent | 1e680128df72a5f7c7226b8874d21a579899de7e (diff) |
Add a basic slides pager UI.
Change-Id: I0ef53ca7bbcf5eab2bb131a88c687e302f80dc41
Diffstat (limited to 'android')
8 files changed, 295 insertions, 2 deletions
diff --git a/android/sdremote/res/drawable/background_grid_slide.xml b/android/sdremote/res/drawable/background_grid_slide.xml index dc390bb82287..9c76602557d4 100644 --- a/android/sdremote/res/drawable/background_grid_slide.xml +++ b/android/sdremote/res/drawable/background_grid_slide.xml @@ -6,7 +6,7 @@ <stroke android:width="1dp" - android:color="@color/stroke_slide"/> + android:color="@color/stroke_grid_slide"/> <padding android:left="1dp" diff --git a/android/sdremote/res/drawable/background_pager_slide.xml b/android/sdremote/res/drawable/background_pager_slide.xml new file mode 100644 index 000000000000..c65e4249ef1e --- /dev/null +++ b/android/sdremote/res/drawable/background_pager_slide.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android"> + + <solid + android:color="@android:color/transparent" /> + + <stroke + android:width="3dp" + android:color="@color/stroke_pager_slide"/> + + <padding + android:left="0dp" + android:top="1dp" + android:right="0dp" + android:bottom="2dp"/> + +</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 new file mode 100644 index 000000000000..14e5cf104e3c --- /dev/null +++ b/android/sdremote/res/layout/fragment_slides_pager.xml @@ -0,0 +1,13 @@ +<?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"> + + <android.support.v4.view.ViewPager + android:id="@+id/pager_slides" + android:padding="@dimen/padding_slides_pager" + android:layout_centerInParent="true" + android:layout_width="match_parent" + android:layout_height="@dimen/height_slides_pager"/> + +</RelativeLayout> diff --git a/android/sdremote/res/layout/view_pager_slide.xml b/android/sdremote/res/layout/view_pager_slide.xml new file mode 100644 index 000000000000..0ebb367455e8 --- /dev/null +++ b/android/sdremote/res/layout/view_pager_slide.xml @@ -0,0 +1,7 @@ +<?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: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 59281e2192e6..fbc2e441327f 100644 --- a/android/sdremote/res/values/colors.xml +++ b/android/sdremote/res/values/colors.xml @@ -5,7 +5,8 @@ <color name="background_action_bar_divider">#55ffffff</color> <color name="background_slide_index">#7f000000</color> - <color name="stroke_slide">#65000000</color> + <color name="stroke_grid_slide">#65000000</color> + <color name="stroke_pager_slide">#35000000</color> <color name="orange">#EE4400</color> <color name="grey">#303030</color> diff --git a/android/sdremote/res/values/dimens.xml b/android/sdremote/res/values/dimens.xml index b026b3264a55..b73555f52401 100644 --- a/android/sdremote/res/values/dimens.xml +++ b/android/sdremote/res/values/dimens.xml @@ -4,6 +4,7 @@ <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_horizontal_list_item">8dp</dimen> @@ -16,6 +17,7 @@ <dimen name="padding_vertical_edit">8dp</dimen> <dimen name="margin_vertical_action_bar_divider">12dp</dimen> + <dimen name="margin_slide">8dp</dimen> <dimen name="width_action_bar_divider">0.5dp</dimen> <dimen name="width_slides_grid_column">90dp</dimen> @@ -26,4 +28,6 @@ <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/src/org/libreoffice/impressremote/SlidesPagerAdapter.java b/android/sdremote/src/org/libreoffice/impressremote/SlidesPagerAdapter.java new file mode 100644 index 000000000000..bb7065f57ef4 --- /dev/null +++ b/android/sdremote/src/org/libreoffice/impressremote/SlidesPagerAdapter.java @@ -0,0 +1,62 @@ +package org.libreoffice.impressremote; + +import android.content.Context; +import android.support.v4.view.PagerAdapter; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; + +import org.libreoffice.impressremote.communication.SlideShow; + +public class SlidesPagerAdapter extends PagerAdapter { + private final LayoutInflater mLayoutInflater; + + private final SlideShow mSlideShow; + + public SlidesPagerAdapter(Context aContext, SlideShow aSlideShow) { + mLayoutInflater = buildLayoutInflater(aContext); + + mSlideShow = aSlideShow; + } + + private LayoutInflater buildLayoutInflater(Context aContext) { + return (LayoutInflater) aContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + } + @Override + public int getCount() { + return mSlideShow.getSlidesCount(); + } + + @Override + public Object instantiateItem(ViewGroup aViewGroup, int aPosition) { + ImageView aSlideView = (ImageView) getView(aViewGroup); + + aSlideView.setImageBitmap(mSlideShow.getSlidePreview(aPosition)); + + aViewGroup.addView(aSlideView); + + return aSlideView; + } + + private View getView(ViewGroup aViewGroup) { + return mLayoutInflater.inflate(R.layout.view_pager_slide, aViewGroup, false); + } + + @Override + public void destroyItem(ViewGroup aViewGroup, int aPosition, Object aObject) { + View aView = (View) aObject; + + aViewGroup.removeView(aView); + } + + @Override + public boolean isViewFromObject(View aView, Object aObject) { + return aView == aObject; + } + + @Override + public int getItemPosition(Object aObject) { + return POSITION_NONE; + } +} diff --git a/android/sdremote/src/org/libreoffice/impressremote/SlidesPagerFragment.java b/android/sdremote/src/org/libreoffice/impressremote/SlidesPagerFragment.java new file mode 100644 index 000000000000..fd1ea3c4c2ae --- /dev/null +++ b/android/sdremote/src/org/libreoffice/impressremote/SlidesPagerFragment.java @@ -0,0 +1,189 @@ +/* -*- 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; + +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.content.LocalBroadcastManager; +import android.support.v4.view.ViewPager; +import android.util.TypedValue; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.actionbarsherlock.app.SherlockFragment; +import org.libreoffice.impressremote.communication.CommunicationService; + +public class SlidesPagerFragment extends SherlockFragment implements ServiceConnection, ViewPager.OnPageChangeListener { + private CommunicationService mCommunicationService; + private BroadcastReceiver mIntentsReceiver; + + public static SlidesPagerFragment newInstance() { + return new SlidesPagerFragment(); + } + + @Override + public View onCreateView(LayoutInflater aInflater, ViewGroup aContainer, Bundle aSavedInstanceState) { + return aInflater.inflate(R.layout.fragment_slides_pager, aContainer, false); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + bindService(); + } + + private void bindService() { + Intent aServiceIntent = new Intent(getActivity(), CommunicationService.class); + + 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(); + + mCommunicationService.getTransmitter().startPresentation(); + + setUpSlidesPager(); + } + + private void setUpSlidesPager() { + SlidesPagerAdapter aSlidesPagerAdapter = new SlidesPagerAdapter(getActivity(), + mCommunicationService.getSlideShow()); + + getSlidesPager().setAdapter(aSlidesPagerAdapter); + + getSlidesPager().setPageMargin(getSlidesMarginInPx()); + + getSlidesPager().setOnPageChangeListener(this); + } + + private ViewPager getSlidesPager() { + return (ViewPager) getView().findViewById(R.id.pager_slides); + } + + private int getSlidesMarginInPx() { + float aSlideMarginInDp = getResources().getDimension(R.dimen.margin_slide); + + return (int) TypedValue + .applyDimension(TypedValue.COMPLEX_UNIT_PX, aSlideMarginInDp, + getResources().getDisplayMetrics()); + } + + @Override + public void onPageScrolled(int aPosition, float aPositionOffset, int aPositionOffsetPixels) { + } + + @Override + public void onPageSelected(int aPosition) { + mCommunicationService.getTransmitter().setCurrentSlide(aPosition); + } + + @Override + public void onPageScrollStateChanged(int aState) { + } + + @Override + public void onServiceDisconnected(ComponentName aComponentName) { + mCommunicationService = null; + } + + @Override + public void onResume() { + super.onResume(); + + registerIntentsReceiver(); + } + + private void registerIntentsReceiver() { + mIntentsReceiver = new IntentsReceiver(this); + IntentFilter aIntentFilter = buildIntentsReceiverFilter(); + + getBroadcastManager().registerReceiver(mIntentsReceiver, aIntentFilter); + } + + private static final class IntentsReceiver extends BroadcastReceiver { + private final SlidesPagerFragment mSlidesGridFragment; + + private IntentsReceiver(SlidesPagerFragment aSlidesGridFragment) { + mSlidesGridFragment = aSlidesGridFragment; + } + + @Override + public void onReceive(Context aContext, Intent aIntent) { + if (Intents.Actions.SLIDE_PREVIEW.equals(aIntent.getAction())) { + mSlidesGridFragment.refreshSlidesGrid(); + } + } + } + + private IntentFilter buildIntentsReceiverFilter() { + IntentFilter aIntentFilter = new IntentFilter(); + aIntentFilter.addAction(Intents.Actions.SLIDE_PREVIEW); + + return aIntentFilter; + } + + private LocalBroadcastManager getBroadcastManager() { + Context aContext = getActivity().getApplicationContext(); + + return LocalBroadcastManager.getInstance(aContext); + } + + private void refreshSlidesGrid() { + getSlidesPager().getAdapter().notifyDataSetChanged(); + } + + @Override + public void onPause() { + super.onPause(); + + unregisterIntentsReceiver(); + } + + private void unregisterIntentsReceiver() { + try { + getBroadcastManager().unregisterReceiver(mIntentsReceiver); + } catch (IllegalArgumentException e) { + // Receiver not registered. + // Fixed in Honeycomb: Android’s issue #6191. + } + } + + @Override + public void onDestroy() { + super.onDestroy(); + + unbindService(); + } + + private void unbindService() { + if (!isServiceBound()) { + return; + } + + getActivity().unbindService(this); + } + + private boolean isServiceBound() { + return mCommunicationService != null; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |