summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2012-07-23 14:53:06 +0200
committerMichael Meeks <michael.meeks@suse.com>2012-08-06 10:23:00 +0100
commitc67a772da68c75333b3aae73ee3d6f3f835552c5 (patch)
tree70394b98372594a5bd5f6a24b2cfca3848fafbac /android
parent3e0b7a7141c3ab6012f2f16811f8daecd6d84fa2 (diff)
Fixed thumbnail control. Changed thumbnail activity to fragment.
Change-Id: I4e8a9d37f3b418728404b7fab4f7b6e3c3b5e5b9
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/res/layout/activity_presentation.xml15
-rw-r--r--android/sdremote/res/layout/fragment_thumbnail.xml (renamed from android/sdremote/res/layout/activity_thumbnail.xml)0
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java102
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/TestClient.java2
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/ThumbnailActivity.java109
5 files changed, 138 insertions, 90 deletions
diff --git a/android/sdremote/res/layout/activity_presentation.xml b/android/sdremote/res/layout/activity_presentation.xml
index 0cdff5adb4cd..f482b3c246ef 100644
--- a/android/sdremote/res/layout/activity_presentation.xml
+++ b/android/sdremote/res/layout/activity_presentation.xml
@@ -1,14 +1,7 @@
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
- android:layout_height="match_parent" >
+ android:layout_height="match_parent"
+ android:id="@+id/framelayout" >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_centerVertical="true"
- android:text="@string/hello_world"
- tools:context=".PresentationActivity" />
-
-</RelativeLayout>
+</FrameLayout>
diff --git a/android/sdremote/res/layout/activity_thumbnail.xml b/android/sdremote/res/layout/fragment_thumbnail.xml
index 068ab7893317..068ab7893317 100644
--- a/android/sdremote/res/layout/activity_thumbnail.xml
+++ b/android/sdremote/res/layout/fragment_thumbnail.xml
diff --git a/android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java b/android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java
index b7e3b80c969c..45bfd75ede1a 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java
@@ -1,20 +1,98 @@
package org.libreoffice.impressremote;
-import android.os.Bundle;
+import org.libreoffice.impressremote.communication.CommunicationService;
+
import android.app.Activity;
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Messenger;
import android.view.Menu;
+import android.widget.FrameLayout;
public class PresentationActivity extends Activity {
+ private CommunicationService mCommunicationService;
+ private boolean mIsBound = false;
+ private FrameLayout mLayout;
+ ThumbnailActivity mThumbnailFragment;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_presentation);
+
+ bindService(new Intent(this, CommunicationService.class), mConnection,
+ Context.BIND_IMPORTANT);
+
+ FragmentManager fragmentManager = getFragmentManager();
+ FragmentTransaction fragmentTransaction = fragmentManager
+ .beginTransaction();
+ mThumbnailFragment = new ThumbnailActivity();
+ fragmentTransaction.add(R.id.framelayout, mThumbnailFragment,
+ "fragment_thumbnail");
+ fragmentTransaction.commit();
+
+ mLayout = (FrameLayout) findViewById(R.id.framelayout);
+
+ mIsBound = true;
+ }
+
+ // @Override
+ // public boolean onCreateOptionsMenu(Menu menu) {
+ // MenuInflater inflater = getMenuInflater();
+ // inflater.inflate(R.menu.main_activity, menu);
+ // return true;
+ // }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.activity_presentation, menu);
+ return true;
+ }
+
+ private ServiceConnection mConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName aClassName,
+ IBinder aService) {
+ mCommunicationService = ((CommunicationService.CBinder) aService)
+ .getService();
+ mCommunicationService.setActivityMessenger(mMessenger);
+ mThumbnailFragment.setCommunicationService(mCommunicationService);
+ // TODO: add mCommunicationSercie to all fragments.
+
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName aClassName) {
+ mCommunicationService = null;
+ }
+ };
+
+ final Messenger mMessenger = new Messenger(new MessageHandler());
+
+ protected class MessageHandler extends Handler {
+ @Override
+ public void handleMessage(Message aMessage) {
+ mThumbnailFragment.handleMessage(aMessage);
+ // Bundle aData = aMessage.getData();
+ // TODO: pass to fragments
+ // switch (aMessage.what) {
+ // case CommunicationService.MSG_SLIDE_CHANGED:
+ // int aSlide = aData.getInt("slide_number");
+ // break;
+ // case CommunicationService.MSG_SLIDE_PREVIEW:
+ // // int aNSlide = aData.getInt("slide_number");
+ // break;
+ //
+ // }
+ }
+ }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_presentation);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.activity_presentation, menu);
- return true;
- }
}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/TestClient.java b/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
index 0d2f3e0e95c2..f73e772d707b 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
@@ -151,7 +151,7 @@ public class TestClient extends Activity {
@Override
public void onClick(View v) {
Intent aIntent = new Intent(TestClient.this,
- ThumbnailActivity.class);
+ PresentationActivity.class);
startActivity(aIntent);
}
});
diff --git a/android/sdremote/src/org/libreoffice/impressremote/ThumbnailActivity.java b/android/sdremote/src/org/libreoffice/impressremote/ThumbnailActivity.java
index f295163a1b9c..3890ff3de37b 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/ThumbnailActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/ThumbnailActivity.java
@@ -11,18 +11,12 @@ package org.libreoffice.impressremote;
import org.libreoffice.impressremote.communication.CommunicationService;
import org.libreoffice.impressremote.communication.SlideShow;
-import android.app.Activity;
-import android.content.ComponentName;
+import android.app.Fragment;
import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.os.Bundle;
-import android.os.Handler;
-import android.os.IBinder;
import android.os.Message;
-import android.os.Messenger;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -32,47 +26,42 @@ import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
-public class ThumbnailActivity extends Activity {
+public class ThumbnailActivity extends Fragment {
private CommunicationService mCommunicationService;
- private boolean mIsBound = false;
private GridView mGrid;
private ImageView mCurrentImage;
private TextView mCurrentText;
private SlideShow mSlideShow;
+ private Context mContext;
@Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_thumbnail);
-
- bindService(new Intent(this, CommunicationService.class), mConnection,
- Context.BIND_ADJUST_WITH_ACTIVITY);
- mIsBound = true;
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ View v = inflater
+ .inflate(R.layout.fragment_thumbnail, container, false);
- mGrid = (GridView) findViewById(R.id.thumbnail_grid);
+ mGrid = (GridView) v.findViewById(R.id.thumbnail_grid);
mGrid.setOnItemClickListener(new ClickListener());
+ mContext = container.getContext();
+
+ return v;
}
@Override
- protected void onPause() {
- super.onPause();
- mCommunicationService.setActivityMessenger(null);
- if (mIsBound) {
- unbindService(mConnection);
- mIsBound = false;
- }
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
}
- // @Override
- // public boolean onCreateOptionsMenu(Menu menu) {
- // MenuInflater inflater = getMenuInflater();
- // inflater.inflate(R.menu.main_activity, menu);
- // return true;
- // }
+ @Override
+ public void onPause() {
+ super.onPause();
+ }
private void setSelected(int position) {
formatUnselected(mCurrentImage, mCurrentText);
@@ -92,7 +81,7 @@ public class ThumbnailActivity extends Activity {
R.color.thumbnail_border));
}
if (aText != null) {
- aText.setTypeface(Typeface.create(mCurrentText.getTypeface(),
+ aText.setTypeface(Typeface.create(aText.getTypeface(),
Typeface.NORMAL));
}
}
@@ -103,56 +92,42 @@ public class ThumbnailActivity extends Activity {
R.color.thumbnail_border_selected));
}
if (aText != null) {
- aText.setTypeface(Typeface.create(mCurrentText.getTypeface(),
+ aText.setTypeface(Typeface.create(aText.getTypeface(),
Typeface.BOLD));
}
}
// ------------------------------------------------- SERVICE CONNECTION ----
- final Messenger mMessenger = new Messenger(new MessageHandler());
-
- private ServiceConnection mConnection = new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName aClassName,
- IBinder aService) {
- mCommunicationService = ((CommunicationService.CBinder) aService)
- .getService();
- mCommunicationService.setActivityMessenger(mMessenger);
- mSlideShow = mCommunicationService.getSlideShow();
- mGrid.setAdapter(new ThumbnailAdapter(ThumbnailActivity.this,
- mSlideShow));
- }
-
- @Override
- public void onServiceDisconnected(ComponentName aClassName) {
- mCommunicationService = null;
- }
- };
// ----------------------------------------------------- CLICK LISTENER ----
protected class ClickListener implements AdapterView.OnItemClickListener {
public void onItemClick(AdapterView<?> parent, View v, int position,
long id) {
- mCommunicationService.getTransmitter().gotoSlide(position);
+ if (mCommunicationService != null)
+ mCommunicationService.getTransmitter().gotoSlide(position);
}
}
// ---------------------------------------------------- MESSAGE HANDLER ----
- protected class MessageHandler extends Handler {
- @Override
- public void handleMessage(Message aMessage) {
- Bundle aData = aMessage.getData();
- switch (aMessage.what) {
- case CommunicationService.MSG_SLIDE_CHANGED:
- int aSlide = aData.getInt("slide_number");
- setSelected(aSlide);
- break;
- case CommunicationService.MSG_SLIDE_PREVIEW:
- // int aNSlide = aData.getInt("slide_number");
- mGrid.invalidateViews();
- break;
- }
+ public void setCommunicationService(
+ CommunicationService aCommunicationService) {
+ mCommunicationService = aCommunicationService;
+ mSlideShow = mCommunicationService.getSlideShow();
+ mGrid.setAdapter(new ThumbnailAdapter(mContext, mSlideShow));
+ }
+
+ public void handleMessage(Message aMessage) {
+ Bundle aData = aMessage.getData();
+ switch (aMessage.what) {
+ case CommunicationService.MSG_SLIDE_CHANGED:
+ int aSlide = aData.getInt("slide_number");
+ setSelected(aSlide);
+ break;
+ case CommunicationService.MSG_SLIDE_PREVIEW:
+ mGrid.invalidateViews();
+ break;
+
}
}
@@ -201,6 +176,8 @@ public class ThumbnailActivity extends Activity {
if ((mSlideShow != null)
&& (position == mSlideShow.getCurrentSlide())) {
formatSelected(aImage, aText);
+ mCurrentImage = aImage;
+ mCurrentText = aText;
} else {
formatUnselected(aImage, aText);
}