From e02468f6e8b5d15635c2c9986ca249a8254192d1 Mon Sep 17 00:00:00 2001 From: "Andrzej J.R. Hunt" Date: Tue, 14 Aug 2012 12:59:22 +0200 Subject: [PATCH] Added rotation of presentation view. Change-Id: Iea68b7740c5e7cf9380c91b8b85ff02fd9c11b8e --- .../res/drawable-hdpi/handle_light.9.png | Bin 222 -> 203 bytes .../handle_vertical_default.9.png | Bin 0 -> 263 bytes .../drawable-hdpi/handle_vertical_light.9.png | Bin 0 -> 202 bytes android/sdremote/res/drawable-land/handle.xml | 9 + .../handle_vertical_default.9.png | Bin 0 -> 263 bytes .../drawable-mdpi/handle_vertical_light.9.png | Bin 0 -> 202 bytes .../handle_vertical_default.9.png | Bin 0 -> 263 bytes .../handle_vertical_light.9.png | Bin 0 -> 202 bytes .../res/layout-land/fragment_presentation.xml | 54 +++ .../sdremote/res/layout/activity_pairing.xml | 17 +- android/sdremote/res/values/strings.xml | 2 +- .../impressremote/PairingActivity.java | 41 +- .../impressremote/PresentationFragment.java | 359 +++++++++--------- .../impressremote/SelectorActivity.java | 5 +- .../impressremote/communication/Client.java | 5 + .../communication/CommunicationService.java | 16 + .../communication/NetworkClient.java | 11 +- .../communication/ServerFinder.java | 10 + 18 files changed, 339 insertions(+), 190 deletions(-) create mode 100644 android/sdremote/res/drawable-hdpi/handle_vertical_default.9.png create mode 100644 android/sdremote/res/drawable-hdpi/handle_vertical_light.9.png create mode 100644 android/sdremote/res/drawable-land/handle.xml create mode 100644 android/sdremote/res/drawable-mdpi/handle_vertical_default.9.png create mode 100644 android/sdremote/res/drawable-mdpi/handle_vertical_light.9.png create mode 100644 android/sdremote/res/drawable-xhdpi/handle_vertical_default.9.png create mode 100644 android/sdremote/res/drawable-xhdpi/handle_vertical_light.9.png create mode 100644 android/sdremote/res/layout-land/fragment_presentation.xml diff --git a/android/sdremote/res/drawable-hdpi/handle_light.9.png b/android/sdremote/res/drawable-hdpi/handle_light.9.png index b0d7bef534d61ac2fdc2359024bce04dd3434ab7..7d1b1c968bb97ae41b43454c292d24bb4a302a4f 100644 GIT binary patch delta 173 zcmcb|c$!hMGr-TCmrII^fq{Y7)59eQNb>`+5CKT%PmKG)O5F~p+x?qqAB z1_d6MMsCk{^&A^`m!Dvbkv@JXCoMqx?kClLe~F+fNf%aGscZivjGOsdXSRMn$FuF) z90jFy+hZK#t?zagswY2Qo^t18`J*Q>FC;X|i(<95D*G9K4v|0iS)Y^PIMe24%j)to YyDgixq^?0MdQy5SDb7qN}aLM^OYXz4}V^TBA${$*ne#URqZB}6vcz^WON7sF>9>F`U zEqa)D%FeZZf1!MDWPa0}%~rdoOnMcVuA=meN#_}3!mQ=oG1rcsT6yDT=zdKlouw-r s4c%G#D?*tm|7%XTKNU4RRiXr>mdKI;Vst0OHk30ssI2 diff --git a/android/sdremote/res/drawable-hdpi/handle_vertical_default.9.png b/android/sdremote/res/drawable-hdpi/handle_vertical_default.9.png new file mode 100644 index 0000000000000000000000000000000000000000..830493c1f90c040e03c113b2fc3d62f4608a060c GIT binary patch literal 263 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+k!3HE-=Cy!0EX7WqAsj$Z!;#Vf4nJ z@ErkR#;MwT(m=tLo-U3d7QI&|Z{$6!AmYOB))CER+!V~DeI)ymwKhYl4U=BRT){uV zDz5u_RF{ZM^k4L#5!?)y*%BcT8cr_3HM*-T<$}d27_9k0vY? zX<2hlz==y^Xq?8KgxhmJ|Sh}-;ZepqSJ-{;=@7_>wjJ_zgCuLC-o!PC{xWt~$( F69B;~VL$)? literal 0 HcmV?d00001 diff --git a/android/sdremote/res/drawable-hdpi/handle_vertical_light.9.png b/android/sdremote/res/drawable-hdpi/handle_vertical_light.9.png new file mode 100644 index 0000000000000000000000000000000000000000..8246c398347b150038b9ac9e69b4f9c23fa6006c GIT binary patch literal 202 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+k!3HE-=Cy!0EX7WqAsj$Z!;#Vf4nJ z@ErkR#;MwT(m=r+PZ!4!i{87Fck>=l;Bn#QX8k75bZM669tS;9*GJApt28V-pPlUQ z*JWXFNm=Kix7FLT-Oc=u>lq#^k+f|! + + + + + + + + \ No newline at end of file diff --git a/android/sdremote/res/drawable-mdpi/handle_vertical_default.9.png b/android/sdremote/res/drawable-mdpi/handle_vertical_default.9.png new file mode 100644 index 0000000000000000000000000000000000000000..830493c1f90c040e03c113b2fc3d62f4608a060c GIT binary patch literal 263 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+k!3HE-=Cy!0EX7WqAsj$Z!;#Vf4nJ z@ErkR#;MwT(m=tLo-U3d7QI&|Z{$6!AmYOB))CER+!V~DeI)ymwKhYl4U=BRT){uV zDz5u_RF{ZM^k4L#5!?)y*%BcT8cr_3HM*-T<$}d27_9k0vY? zX<2hlz==y^Xq?8KgxhmJ|Sh}-;ZepqSJ-{;=@7_>wjJ_zgCuLC-o!PC{xWt~$( F69B;~VL$)? literal 0 HcmV?d00001 diff --git a/android/sdremote/res/drawable-mdpi/handle_vertical_light.9.png b/android/sdremote/res/drawable-mdpi/handle_vertical_light.9.png new file mode 100644 index 0000000000000000000000000000000000000000..8246c398347b150038b9ac9e69b4f9c23fa6006c GIT binary patch literal 202 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+k!3HE-=Cy!0EX7WqAsj$Z!;#Vf4nJ z@ErkR#;MwT(m=r+PZ!4!i{87Fck>=l;Bn#QX8k75bZM669tS;9*GJApt28V-pPlUQ z*JWXFNm=Kix7FLT-Oc=u>lq#^k+f|!4nJ z@ErkR#;MwT(m=tLo-U3d7QI&|Z{$6!AmYOB))CER+!V~DeI)ymwKhYl4U=BRT){uV zDz5u_RF{ZM^k4L#5!?)y*%BcT8cr_3HM*-T<$}d27_9k0vY? zX<2hlz==y^Xq?8KgxhmJ|Sh}-;ZepqSJ-{;=@7_>wjJ_zgCuLC-o!PC{xWt~$( F69B;~VL$)? literal 0 HcmV?d00001 diff --git a/android/sdremote/res/drawable-xhdpi/handle_vertical_light.9.png b/android/sdremote/res/drawable-xhdpi/handle_vertical_light.9.png new file mode 100644 index 0000000000000000000000000000000000000000..8246c398347b150038b9ac9e69b4f9c23fa6006c GIT binary patch literal 202 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+k!3HE-=Cy!0EX7WqAsj$Z!;#Vf4nJ z@ErkR#;MwT(m=r+PZ!4!i{87Fck>=l;Bn#QX8k75bZM669tS;9*GJApt28V-pPlUQ z*JWXFNm=Kix7FLT-Oc=u>lq#^k+f|! + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/sdremote/res/layout/activity_pairing.xml b/android/sdremote/res/layout/activity_pairing.xml index 122dec613081..d2f06bdb40c8 100644 --- a/android/sdremote/res/layout/activity_pairing.xml +++ b/android/sdremote/res/layout/activity_pairing.xml @@ -5,24 +5,29 @@ android:orientation="vertical" > + android:layout_margin="10dip" + android:gravity="center" + android:text="@string/pairing_instructions_2_deviceName" /> + android:textAppearance="?android:attr/textAppearanceLarge" + android:textSize="75dip" /> \ No newline at end of file diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml index 523f53865faa..c86d5c92c94c 100644 --- a/android/sdremote/res/values/strings.xml +++ b/android/sdremote/res/values/strings.xml @@ -24,7 +24,7 @@ WI-FI Searching for computers… In Impress, click on the "Slideshow" menu and select "Impress Remote". - Choose "{1}" as your device. + Choose "{1}" as your device. Then input this PIN: \ No newline at end of file diff --git a/android/sdremote/src/org/libreoffice/impressremote/PairingActivity.java b/android/sdremote/src/org/libreoffice/impressremote/PairingActivity.java index 386098ca8af4..9298e437625f 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/PairingActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/PairingActivity.java @@ -8,26 +8,36 @@ */ package org.libreoffice.impressremote; +import java.text.MessageFormat; + import org.libreoffice.impressremote.communication.CommunicationService; +import org.libreoffice.impressremote.communication.CommunicationService.State; import android.app.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.content.LocalBroadcastManager; import android.widget.TextView; public class PairingActivity extends Activity { - + private CommunicationService mCommunicationService; + private boolean mIsBound = false; private TextView mPinText; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_pairing); + + bindService(new Intent(this, CommunicationService.class), mConnection, + Context.BIND_IMPORTANT); + mIsBound = true; mPinText = (TextView) findViewById(R.id.pairing_pin); @@ -46,6 +56,33 @@ public class PairingActivity extends Activity { // refreshLists(); } + private ServiceConnection mConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName aClassName, + IBinder aService) { + setContentView(R.layout.activity_pairing); + + ((TextView) findViewById(R.id.pairing_instruction2_deviceName)) + .setText(MessageFormat + .format(getResources() + .getString(R.string.pairing_instructions_2_deviceName), + mCommunicationService + .getDeviceName())); + + mCommunicationService = ((CommunicationService.CBinder) aService) + .getService(); + if (mCommunicationService.getState() == State.CONNECTING) { + mPinText.setText(mCommunicationService.getPairingPin()); + } + + } + + @Override + public void onServiceDisconnected(ComponentName aClassName) { + mCommunicationService = null; + } + }; + private BroadcastReceiver mListener = new BroadcastReceiver() { @Override diff --git a/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java b/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java index 4b759ef633e5..9f8d49aad71a 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java +++ b/android/sdremote/src/org/libreoffice/impressremote/PresentationFragment.java @@ -7,6 +7,7 @@ import pl.polidea.coverflow.AbstractCoverFlowImageAdapter; import pl.polidea.coverflow.CoverFlow; import android.app.Fragment; import android.content.Context; +import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -28,224 +29,236 @@ import android.widget.TextView; public class PresentationFragment extends Fragment { - private CoverFlow mTopView; - private ImageView mHandle; - private View mLayout; - private WebView mNotes; - private Context mContext; - private TextView mNumberText; + private CoverFlow mTopView; + private ImageView mHandle; + private View mLayout; + private WebView mNotes; + private Context mContext; + private TextView mNumberText; - private CommunicationService mCommunicationService; - private SlideShow mSlideShow; + private CommunicationService mCommunicationService; + private SlideShow mSlideShow; - private float mOriginalCoverflowWidth; - private float mOriginalCoverflowHeight; + private float mOriginalCoverflowWidth; + private float mOriginalCoverflowHeight; - private float mNewCoverflowWidth = 0; - private float mNewCoverflowHeight = 0; + private float mNewCoverflowWidth = 0; + private float mNewCoverflowHeight = 0; - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - mContext = container.getContext(); + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + mContext = container.getContext(); - View v = inflater.inflate(R.layout.fragment_presentation, container, - false); + View v = inflater.inflate(R.layout.fragment_presentation, container, + false); - mNotes = (WebView) v.findViewById(R.id.presentation_notes); + mNotes = (WebView) v.findViewById(R.id.presentation_notes); - String summary = "This is just a test
  • And item
  • And again
More text
Blabla
Blabla
blabla
Blabla"; - mNotes.loadData(summary, "text/html", null); - mNotes.setBackgroundColor(Color.TRANSPARENT); + String summary = "This is just a test
  • And item
  • And again
More text
Blabla
Blabla
blabla
Blabla"; + mNotes.loadData(summary, "text/html", null); + mNotes.setBackgroundColor(Color.TRANSPARENT); - // TextView aText = new TextView(); - // aText.setText + mTopView = (CoverFlow) v.findViewById(R.id.presentation_coverflow); - mTopView = (CoverFlow) v.findViewById(R.id.presentation_coverflow); + mLayout = v.findViewById(R.id.presentation_layout); - mLayout = v.findViewById(R.id.presentation_layout); + mNumberText = (TextView) v.findViewById(R.id.presentation_slidenumber); - mNumberText = (TextView) v.findViewById(R.id.presentation_slidenumber); + mHandle = (ImageView) v.findViewById(R.id.presentation_handle); + mHandle.setOnTouchListener(new SizeListener()); - mHandle = (ImageView) v.findViewById(R.id.presentation_handle); - mHandle.setOnTouchListener(new SizeListener()); + // Call again to set things up if necessary. + setCommunicationService(mCommunicationService); - // Call again to set things up if necessary. - setCommunicationService(mCommunicationService); + // Save the height/width for future reference + mOriginalCoverflowHeight = mTopView.getImageHeight(); + mOriginalCoverflowWidth = mTopView.getImageWidth(); - // Save the height/width for future reference - mOriginalCoverflowHeight = mTopView.getImageHeight(); - mOriginalCoverflowWidth = mTopView.getImageWidth(); + if (mNewCoverflowHeight != 0) { + ThumbnailAdapter aAdapter = (ThumbnailAdapter) mTopView + .getAdapter(); + aAdapter.setHeight(mNewCoverflowHeight); + mTopView.setImageHeight(mNewCoverflowHeight); + aAdapter.setWidth(mNewCoverflowWidth); + mTopView.setImageWidth(mNewCoverflowWidth); - if (mNewCoverflowHeight != 0) { - ThumbnailAdapter aAdapter = (ThumbnailAdapter) mTopView - .getAdapter(); - aAdapter.setHeight(mNewCoverflowHeight); - mTopView.setImageHeight(mNewCoverflowHeight); - aAdapter.setWidth(mNewCoverflowWidth); - mTopView.setImageWidth(mNewCoverflowWidth); + // We need to update the view now + aAdapter.notifyDataSetChanged(); + } + return v; + } - // We need to update the view now - aAdapter.notifyDataSetChanged(); - } - return v; - } + private void updateSlideNumberDisplay() { + int aSlide = mSlideShow.getCurrentSlide(); + mNumberText.setText((aSlide + 1) + "/" + mSlideShow.getSize()); + mNotes.loadData(mSlideShow.getNotes(aSlide), "text/html", null); + } - private void updateSlideNumberDisplay() { - int aSlide = mSlideShow.getCurrentSlide(); - mNumberText.setText((aSlide + 1) + "/" + mSlideShow.getSize()); - mNotes.loadData(mSlideShow.getNotes(aSlide), "text/html", null); - } + // -------------------------------------------------- RESIZING LISTENER ---- + private class SizeListener implements OnTouchListener { - // -------------------------------------------------- RESIZING LISTENER ---- - private class SizeListener implements OnTouchListener { + @Override + public boolean onTouch(View aView, MotionEvent aEvent) { - @Override - public boolean onTouch(View aView, MotionEvent aEvent) { + switch (aEvent.getAction()) { + case MotionEvent.ACTION_DOWN: + mHandle.setImageResource(R.drawable.handle_light); + break; + case MotionEvent.ACTION_UP: + mHandle.setImageResource(R.drawable.handle_default); + break; + case MotionEvent.ACTION_MOVE: + LayoutParams aParams = mTopView.getLayoutParams(); - switch (aEvent.getAction()) { - case MotionEvent.ACTION_DOWN: - mHandle.setImageResource(R.drawable.handle_light); - break; - case MotionEvent.ACTION_UP: - mHandle.setImageResource(R.drawable.handle_default); - break; - case MotionEvent.ACTION_MOVE: - LayoutParams aParams = mTopView.getLayoutParams(); - int aHeight = mTopView.getHeight(); - int aViewSize = mLayout.getHeight(); + final int DRAG_MARGIN = 120; - final int DRAG_MARGIN = 120; + boolean aPortrait = (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); - // Calculate height change, taking limits into account - int aDiff = (int) (aEvent.getY()); - if (aDiff + aHeight < DRAG_MARGIN) { - aDiff = DRAG_MARGIN - aHeight; - } else if ((aHeight + aDiff) > (aViewSize - DRAG_MARGIN)) { - aDiff = (aViewSize - DRAG_MARGIN) - aHeight; - } + int aFlowSize = mTopView.getHeight(); + int aViewSize = mLayout.getHeight(); - // Now deal with the internal height - AbstractCoverFlowImageAdapter aAdapter = (AbstractCoverFlowImageAdapter) mTopView - .getAdapter(); + // Calculate height change, taking limits into account + int aDiff = (int) (aPortrait ? aEvent.getY() : aEvent.getX()); + if (aDiff + aFlowSize < DRAG_MARGIN) { + aDiff = DRAG_MARGIN - aFlowSize; + } else if ((aFlowSize + aDiff) > (aViewSize - DRAG_MARGIN)) { + aDiff = (aViewSize - DRAG_MARGIN) - aFlowSize; + } - double aRatio = mOriginalCoverflowWidth - / mOriginalCoverflowHeight; - float aHeightNew = mTopView.getImageHeight() + aDiff; - float aWidthNew = (float) (aRatio * aHeightNew); + // Now deal with the internal height + AbstractCoverFlowImageAdapter aAdapter = (AbstractCoverFlowImageAdapter) mTopView + .getAdapter(); - // Too wide -- so scale down - if (aWidthNew > mLayout.getWidth() - 50) { - aWidthNew = mLayout.getWidth() - 50; - aHeightNew = (float) (aWidthNew / aRatio); - aDiff = (int) (aHeightNew - mTopView.getImageHeight()); - } + double aRatio = mOriginalCoverflowWidth + / mOriginalCoverflowHeight; + float aHeightNew; + float aWidthNew; + if (aPortrait) { + aHeightNew = mTopView.getImageHeight() + aDiff; + aWidthNew = (float) (aRatio * aHeightNew); + // Too wide -- so scale down + if (aWidthNew > mLayout.getWidth() - 50) { + aWidthNew = mLayout.getWidth() - 50; + aHeightNew = (float) (aWidthNew / aRatio); + aDiff = (int) (aHeightNew - mTopView.getImageHeight()); + } + } else { + aWidthNew = mTopView.getImageWidth(); + aHeightNew = (float) (aWidthNew / aRatio); + // Too High -- so scale down + if (aHeightNew > mLayout.getHeight() - 50) { + aHeightNew = mLayout.getHeight() - 50; + aWidthNew = (float) (aHeightNew / aRatio); + aDiff = (int) (aWidthNew - mTopView.getImageWidth()); + } + } - mNewCoverflowHeight = aHeightNew; - mNewCoverflowWidth = aWidthNew; + mNewCoverflowHeight = aHeightNew; + mNewCoverflowWidth = aWidthNew; - aAdapter.setHeight(aHeightNew); - mTopView.setImageHeight(aHeightNew); - aAdapter.setWidth(aWidthNew); - mTopView.setImageWidth(aWidthNew); + aAdapter.setHeight(aHeightNew); + mTopView.setImageHeight(aHeightNew); + aAdapter.setWidth(aWidthNew); + mTopView.setImageWidth(aWidthNew); - // Force an update of the view - aAdapter.notifyDataSetChanged(); + // Force an update of the view + aAdapter.notifyDataSetChanged(); - break; - } - // TODO Auto-generated method stub - return true; - } - } + break; + } + // TODO Auto-generated method stub + return true; + } + } - // ----------------------------------------------------- CLICK LISTENER ---- + // ----------------------------------------------------- CLICK LISTENER ---- - protected class ClickListener implements OnItemSelectedListener { + protected class ClickListener implements OnItemSelectedListener { - @Override - public void onItemSelected(AdapterView arg0, View arg1, - int aPosition, long arg3) { - if (mCommunicationService != null) - mCommunicationService.getTransmitter().gotoSlide(aPosition); - } + @Override + public void onItemSelected(AdapterView arg0, View arg1, + int aPosition, long arg3) { + if (mCommunicationService != null) + mCommunicationService.getTransmitter().gotoSlide(aPosition); + } - @Override - public void onNothingSelected(AdapterView arg0) { - } - } + @Override + public void onNothingSelected(AdapterView arg0) { + } + } - // ---------------------------------------------------- MESSAGE HANDLER ---- - public void setCommunicationService( - CommunicationService aCommunicationService) { - mCommunicationService = aCommunicationService; - if (mCommunicationService == null) - return; + // ---------------------------------------------------- MESSAGE HANDLER ---- + public void setCommunicationService( + CommunicationService aCommunicationService) { + mCommunicationService = aCommunicationService; + if (mCommunicationService == null) + return; - mSlideShow = mCommunicationService.getSlideShow(); - if (mTopView != null && mSlideShow != null) { - mTopView.setAdapter(new ThumbnailAdapter(mContext, mSlideShow)); - mTopView.setSelection(mSlideShow.getCurrentSlide(), true); - mTopView.setOnItemSelectedListener(new ClickListener()); - } + mSlideShow = mCommunicationService.getSlideShow(); + if (mTopView != null && mSlideShow != null) { + mTopView.setAdapter(new ThumbnailAdapter(mContext, mSlideShow)); + mTopView.setSelection(mSlideShow.getCurrentSlide(), true); + mTopView.setOnItemSelectedListener(new ClickListener()); + } - updateSlideNumberDisplay(); - } + updateSlideNumberDisplay(); + } - public void handleMessage(Message aMessage) { - Bundle aData = aMessage.getData(); - switch (aMessage.what) { - case CommunicationService.MSG_SLIDE_CHANGED: - int aSlide = aData.getInt("slide_number"); - mTopView.setSelection(aSlide, true); - updateSlideNumberDisplay(); - break; - case CommunicationService.MSG_SLIDE_PREVIEW: - int aNSlide = aData.getInt("slide_number"); - if (mTopView.getSelectedItemPosition() == aNSlide) { - // mTopView. // TODO: update the current item - } - break; + public void handleMessage(Message aMessage) { + Bundle aData = aMessage.getData(); + switch (aMessage.what) { + case CommunicationService.MSG_SLIDE_CHANGED: + int aSlide = aData.getInt("slide_number"); + mTopView.setSelection(aSlide, true); + updateSlideNumberDisplay(); + break; + case CommunicationService.MSG_SLIDE_PREVIEW: + int aNSlide = aData.getInt("slide_number"); + if (mTopView.getSelectedItemPosition() == aNSlide) { + // mTopView. // TODO: update the current item + } + break; - } - } + } + } - // ------------------------------------------------- THUMBNAIL ADAPTER ---- - protected class ThumbnailAdapter extends AbstractCoverFlowImageAdapter { + // ------------------------------------------------- THUMBNAIL ADAPTER ---- + protected class ThumbnailAdapter extends AbstractCoverFlowImageAdapter { - private Context mContext; + private Context mContext; - private SlideShow mSlideShow; + private SlideShow mSlideShow; - public ThumbnailAdapter(Context aContext, SlideShow aSlideShow) { - mContext = aContext; - mSlideShow = aSlideShow; - } + public ThumbnailAdapter(Context aContext, SlideShow aSlideShow) { + mContext = aContext; + mSlideShow = aSlideShow; + } - @Override - public int getCount() { - return mSlideShow.getSize(); - } + @Override + public int getCount() { + return mSlideShow.getSize(); + } - @Override - protected Bitmap createBitmap(int position) { - Bitmap aBitmap = mSlideShow.getImage(position); - final int borderWidth = 8; + @Override + protected Bitmap createBitmap(int position) { + Bitmap aBitmap = mSlideShow.getImage(position); + final int borderWidth = 8; - Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); - p.setShadowLayer(borderWidth, 0, 0, Color.BLACK); + Paint p = new Paint(Paint.ANTI_ALIAS_FLAG); + p.setShadowLayer(borderWidth, 0, 0, Color.BLACK); - RectF aRect = new RectF(borderWidth, borderWidth, borderWidth - + aBitmap.getWidth(), borderWidth - + aBitmap.getHeight()); - Bitmap aOut = Bitmap.createBitmap(aBitmap.getWidth() + 2 - * borderWidth, aBitmap.getHeight() + 2 - * borderWidth, aBitmap.getConfig()); - Canvas canvas = new Canvas(aOut); - canvas.drawColor(Color.TRANSPARENT); - canvas.drawRect(aRect, p); - canvas.drawBitmap(aBitmap, null, aRect, null); + RectF aRect = new RectF(borderWidth, borderWidth, borderWidth + + aBitmap.getWidth(), borderWidth + + aBitmap.getHeight()); + Bitmap aOut = Bitmap.createBitmap(aBitmap.getWidth() + 2 + * borderWidth, aBitmap.getHeight() + 2 + * borderWidth, aBitmap.getConfig()); + Canvas canvas = new Canvas(aOut); + canvas.drawColor(Color.TRANSPARENT); + canvas.drawRect(aRect, p); + canvas.drawBitmap(aBitmap, null, aRect, null); - return aOut; - } - } + return aOut; + } + } } diff --git a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java index a51df87b88be..a07896ffabec 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java @@ -158,9 +158,9 @@ public class SelectorActivity extends Activity { aLayout); TextView aText = (TextView) aView .findViewById(R.id.selector_sub_label); - aView.setOnClickListener(mClickListener); + aText.setOnClickListener(mClickListener); aText.setText(aServer.getName()); - aMap.put(aServer, aView); + aMap.put(aServer, aText); } } @@ -182,7 +182,6 @@ public class SelectorActivity extends Activity { @Override public void onClick(View aView) { - // TODO Auto-generated method stub mCommunicationService.stopFindingServers(); Server aDesiredServer = null; diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java index 2864b9db90b6..044d38a4ec2e 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java @@ -32,6 +32,7 @@ public abstract class Client { protected InputStream mInputStream; protected BufferedReader mReader; protected OutputStream mOutputStream; + protected String mPin = ""; public abstract void closeConnection(); @@ -79,6 +80,10 @@ public abstract class Client { } + public String getPin() { + return mPin; + } + /** * Send a valid JSON string to the server. * diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java index 73b6f3db3bf5..75634949e9dc 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java @@ -27,6 +27,22 @@ public class CommunicationService extends Service implements Runnable { private State mState = State.DISCONNECTED; + public State getState() { + return mState; + } + + public String getPairingPin() { + if (mClient != null) + return mClient.getPin(); + else + return ""; + } + + public String getDeviceName() { + return "Bob"; + // FIXME: get the device name somehow. + } + private State mStateDesired = State.DISCONNECTED; private Server mServerDesired = null; diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java index 33b600b02b62..1e04747c9d7d 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java @@ -17,7 +17,6 @@ import java.util.Random; import android.content.Context; import android.content.Intent; -import android.os.StrictMode; import android.support.v4.content.LocalBroadcastManager; /** @@ -33,10 +32,6 @@ public class NetworkClient extends Client { public NetworkClient(String ipAddress, Context aContext) { super(aContext); - // FIXME: eventually networking will be fully threaded. - StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() - .permitAll().build(); - StrictMode.setThreadPolicy(policy); try { mSocket = new Socket(ipAddress, PORT); mInputStream = mSocket.getInputStream(); @@ -45,10 +40,14 @@ public class NetworkClient extends Client { mOutputStream = mSocket.getOutputStream(); // Pairing. Random aRandom = new Random(); - String aPin = "" + aRandom.nextInt(10000); + String aPin = "" + (aRandom.nextInt(9000) + 1000); + while (aPin.length() < 4) { + aPin = "0" + aPin; // Add leading zeros if necessary + } Intent aIntent = new Intent( CommunicationService.MSG_PAIRING_STARTED); aIntent.putExtra("PIN", aPin); + mPin = aPin; LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent); // Send out String aName = "Bob"; // TODO: get the proper name diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java index 55b6f5472b49..4b7edbd91f61 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java @@ -8,6 +8,8 @@ import java.net.InetAddress; import java.net.SocketException; import java.util.HashMap; +import org.libreoffice.impressremote.communication.Server.Protocol; + import android.content.Context; import android.content.Intent; import android.support.v4.content.LocalBroadcastManager; @@ -93,6 +95,14 @@ public class ServerFinder { mFinishRequested = false; + // TODO: Remove for production + mServerList.put("10.0.2.2", + new Server(Protocol.NETWORK, "10.0.2.2", + "Android Emulator Localhost", System + .currentTimeMillis())); + Intent aIntent = new Intent(CommunicationService.MSG_SERVERLIST_CHANGED); + LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent); + if (mListenerThread == null) { mListenerThread = new Thread() { @Override