Fixed thumbnail control. Changed thumbnail activity to fragment.

Change-Id: I4e8a9d37f3b418728404b7fab4f7b6e3c3b5e5b9
This commit is contained in:
Andrzej J.R. Hunt
2012-07-23 14:53:06 +02:00
committed by Michael Meeks
parent 3e0b7a7141
commit c67a772da6
9 changed files with 138 additions and 99 deletions

View File

@@ -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>

View File

@@ -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);
}
@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 boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_presentation, menu);
return true;
}
}

View File

@@ -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);
}
});

View File

@@ -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,48 +26,43 @@ 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 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) v.findViewById(R.id.thumbnail_grid);
mGrid.setOnItemClickListener(new ClickListener());
mContext = container.getContext();
return v;
}
@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;
mGrid = (GridView) findViewById(R.id.thumbnail_grid);
mGrid.setOnItemClickListener(new ClickListener());
}
@Override
protected void onPause() {
public void onPause() {
super.onPause();
mCommunicationService.setActivityMessenger(null);
if (mIsBound) {
unbindService(mConnection);
mIsBound = false;
}
}
// @Override
// public boolean onCreateOptionsMenu(Menu menu) {
// MenuInflater inflater = getMenuInflater();
// inflater.inflate(R.menu.main_activity, menu);
// return true;
// }
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);
}

View File

@@ -67,10 +67,6 @@ $(eval $(call gb_CppunitTest_use_libraries,sd_filters_test, \
$(gb_STDLIBS) \
))
$(eval $(call gb_CppunitTest_add_libs,sd_filters_test,\
$(shell pkg-config --libs glib-2.0 json-glib-1.0) \
))
$(eval $(call gb_CppunitTest_set_include,sd_filters_test,\
-I$(SRCDIR)/sd/source/ui/inc \
-I$(SRCDIR)/sd/inc \

View File

@@ -41,10 +41,6 @@ $(eval $(call gb_CppunitTest_use_api,sd_uimpress,\
udkapi \
))
$(eval $(call gb_CppunitTest_add_libs,sd_uimpress,\
$(shell pkg-config --libs glib-2.0 json-glib-1.0) \
))
$(eval $(call gb_CppunitTest_use_library_objects,sd_uimpress,sd))
$(eval $(call gb_CppunitTest_use_libraries,sd_uimpress,\

View File

@@ -58,7 +58,7 @@ void ImagePreparer::execute()
void ImagePreparer::sendPreview( sal_uInt32 aSlideNumber )
{
sal_uInt64 aSize;
uno::Sequence<sal_Int8> aImageData = preparePreview( aSlideNumber, 160, 120,
uno::Sequence<sal_Int8> aImageData = preparePreview( aSlideNumber, 140, 100,
aSize );
if ( !xController->isRunning() )
return;

View File

@@ -39,4 +39,3 @@ private:
}
#endif // _SD_IMPRESSREMOTE_RECEIVER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */