[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 3 commits - android/Bootstrap android/experimental include/LibreOfficeKit include/sfx2 libreofficekit/source sfx2/source sw/inc sw/source
Siqi Liu
me at siqi.fr
Mon Apr 13 07:01:28 PDT 2015
android/Bootstrap/src/org/libreoffice/kit/Document.java | 10 +
android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java | 23 +++
android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java | 6
android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java | 63 +++++++++-
android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/ImageUtils.java | 24 +++
include/LibreOfficeKit/LibreOfficeKitEnums.h | 9 +
include/sfx2/objsh.hxx | 11 +
include/sfx2/unoctitm.hxx | 2
libreofficekit/source/gtk/lokdocview.cxx | 6
sfx2/source/control/unoctitm.cxx | 55 ++++++--
sfx2/source/doc/objcont.cxx | 12 +
sw/inc/docsh.hxx | 5
sw/source/uibase/app/docsh.cxx | 19 +++
13 files changed, 230 insertions(+), 15 deletions(-)
New commits:
commit d7e7111d5cfd881c91c666666d1634000def4521
Author: Siqi Liu <me at siqi.fr>
Date: Mon Apr 13 16:00:08 2015 +0200
minor indent change
Change-Id: I594f99721ab58abcfe4ac73ee71c3231a4f100ca
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index 41a20fe..d610ff4 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -1052,9 +1052,9 @@ void SfxDispatchController_Impl::InterceptLOKStateChangeEvent(const SfxObjectShe
}
if (aEvent.FeatureURL.Path == "Bold" ||
- aEvent.FeatureURL.Path == "Italic" ||
- aEvent.FeatureURL.Path == "Underline" ||
- aEvent.FeatureURL.Path == "StrikeOut") {
+ aEvent.FeatureURL.Path == "Italic" ||
+ aEvent.FeatureURL.Path == "Underline" ||
+ aEvent.FeatureURL.Path == "StrikeOut") {
OUStringBuffer aBuffer;
aBuffer.append(aEvent.FeatureURL.Complete);
commit 567231ebf9cf937a7a9d6c98eac4d5bc46f0bce1
Author: Siqi Liu <me at siqi.fr>
Date: Mon Apr 13 15:56:36 2015 +0200
LOK_STATE_CHANGED callback implemented with sfx events interception.
Change-Id: I2fdbb5bc8325761ac3dc567fcc5b51712dc5858e
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
index 1d38882..b443a21 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
@@ -4,6 +4,7 @@ import android.content.Intent;
import android.graphics.PointF;
import android.graphics.RectF;
import android.net.Uri;
+import android.util.Log;
import org.libreoffice.canvas.SelectionHandle;
import org.libreoffice.kit.Document;
@@ -73,19 +74,26 @@ public class InvalidationHandler implements Document.MessageCallback {
LibreOfficeMainActivity.mAppContext.startActivity(urlIntent);
break;
case Document.CALLBACK_STATE_CHANGED:
- Log.d("Document.CALLBACK_STATE_CHANGED: " + payload);
- String[] parts = payload.split(":");
- boolean pressed = Boolean.parseBoolean(parts[1]);
- if (parts[0].equals("Bold")) {
- LOKitShell.getToolbarController().onToggleStateChanged(Document.BOLD, pressed);
- } else if (parts[0].equals("Italic")) {
- LOKitShell.getToolbarController().onToggleStateChanged(Document.ITALIC, pressed);
- } else if (parts[0].equals("Underline")) {
- LOKitShell.getToolbarController().onToggleStateChanged(Document.UNDERLINE, pressed);
- } else if (parts[0].equals("Strikeout")) {
- LOKitShell.getToolbarController().onToggleStateChanged(Document.STRIKEOUT, pressed);
- }
+ stateChanged(payload);
break;
+ default:
+ Log.d(LOGTAG, "LOK_CALLBACK uncatched: " + messageID + " : " + payload);
+ }
+ }
+
+ private void stateChanged(String payload) {
+ String[] parts = payload.split("=");
+ boolean pressed = Boolean.parseBoolean(parts[1]);
+ if (parts[0].equals(".uno:Bold")) {
+ LOKitShell.getToolbarController().onToggleStateChanged(Document.BOLD, pressed);
+ } else if (parts[0].equals(".uno:Italic")) {
+ LOKitShell.getToolbarController().onToggleStateChanged(Document.ITALIC, pressed);
+ } else if (parts[0].equals(".uno:Underline")) {
+ LOKitShell.getToolbarController().onToggleStateChanged(Document.UNDERLINE, pressed);
+ } else if (parts[0].equals(".uno:StrikeOut")) {
+ LOKitShell.getToolbarController().onToggleStateChanged(Document.STRIKEOUT, pressed);
+ } else {
+ Log.d(LOGTAG, "LOK_CALLBACK_STATE_CHANGED type uncatched: " + payload);
}
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java
index 34eff3f..1201b40 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java
@@ -72,7 +72,13 @@ public class ToolbarController {
icon = ImageUtils.bitmapToPressed(icon);
}
- menuItem.setIcon(new BitmapDrawable(mContext.getResources(), icon));
+ final MenuItem fMenuItem = menuItem;
+ final Bitmap fIcon = icon;
+ LOKitShell.getMainHandler().post(new Runnable() {
+ public void run() {
+ fMenuItem.setIcon(new BitmapDrawable(mContext.getResources(), fIcon));
+ }
+ });
}
public void setOptionMenu(Menu menu) {
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index e8d2b59..d4d1b4c 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -102,7 +102,14 @@ typedef enum
* User clicked on an hyperlink that should be handled by other
* applications accordingly.
*/
- LOK_CALLBACK_HYPERLINK_CLICKED
+ LOK_CALLBACK_HYPERLINK_CLICKED,
+
+ /**
+ * Emit state update to the client.
+ * For example, when cursor is on bold text, this callback is triggered
+ * with payload: ".uno:Bold=true"
+ */
+ LOK_CALLBACK_STATE_CHANGED
}
LibreOfficeKitCallbackType;
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index b92656e..a3745dc 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -49,6 +49,9 @@
#include <set>
#include <o3tl/typed_flags_set.hxx>
+#define LOK_USE_UNSTABLE_API
+#include <LibreOfficeKit/LibreOfficeKitTypes.h>
+
class SbxValue;
class SvxMacro;
class SbxArray;
@@ -698,6 +701,14 @@ public:
SAL_DLLPRIVATE void CancelCheckOut( );
SAL_DLLPRIVATE void CheckIn( );
SAL_DLLPRIVATE ::com::sun::star::uno::Sequence< ::com::sun::star::document::CmisVersion > GetCmisVersions();
+
+ /**
+ * Interface shared by document shell. Allow LOK calls from sfx.
+ * Default behavior doesn't do anything. relevant SfxObjectShells should override
+ * the default behavior and implements LOK calls.
+ */
+ virtual void libreOfficeKitCallback(int nType, const char* pPayload) const;
+ virtual bool isTiledRendering() const;
};
#define SFX_GLOBAL_CLASSID \
diff --git a/include/sfx2/unoctitm.hxx b/include/sfx2/unoctitm.hxx
index 97d12da..70122ee 100644
--- a/include/sfx2/unoctitm.hxx
+++ b/include/sfx2/unoctitm.hxx
@@ -175,6 +175,8 @@ public:
void UnBindController();
SfxDispatcher* GetDispatcher();
void SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame);
+
+ void InterceptLOKStateChangeEvent(const SfxObjectShell* objSh, const ::com::sun::star::frame::FeatureStateEvent& aEvent) const;
};
#endif
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 7430511..ac94f15 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -857,6 +857,8 @@ const char* LOKDocView_Impl::callbackTypeToString(int nType)
return "LOK_CALLBACK_GRAPHIC_SELECTION";
case LOK_CALLBACK_HYPERLINK_CLICKED:
return "LOK_CALLBACK_HYPERLINK_CLICKED";
+ case LOK_CALLBACK_STATE_CHANGED:
+ return "LOK_CALLBACK_STATE_CHANGED";
}
return 0;
}
@@ -937,6 +939,10 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
gtk_show_uri(NULL, pCallback->m_aPayload.c_str(), GDK_CURRENT_TIME, &pError);
#endif
}
+ case LOK_CALLBACK_STATE_CHANGED:
+ {
+ g_info(pCallback->m_aPayload.c_str());
+ }
break;
default:
g_assert(false);
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index 0d98a25..41a20fe 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -68,6 +68,9 @@
#include <iostream>
#include <map>
+#include <sal/log.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util;
@@ -973,8 +976,7 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt
pLastState = pState;
}
- ::cppu::OInterfaceContainerHelper* pContnr = pDispatch->GetListeners().getContainer ( aDispatchURL.Complete );
- if ( bNotify && pContnr )
+ if (bNotify)
{
::com::sun::star::uno::Any aState;
if ( ( eState >= SfxItemState::DEFAULT ) && pState && !IsInvalidItem( pState ) && !pState->ISA(SfxVoidItem) )
@@ -1015,16 +1017,24 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt
aEvent.Requery = sal_False;
aEvent.State = aState;
- ::cppu::OInterfaceIteratorHelper aIt( *pContnr );
- while( aIt.hasMoreElements() )
- {
- try
- {
- static_cast< ::com::sun::star::frame::XStatusListener *>(aIt.next())->statusChanged( aEvent );
- }
- catch (const ::com::sun::star::uno::RuntimeException&)
+ if (pDispatcher && pDispatcher->GetFrame()) {
+ InterceptLOKStateChangeEvent(
+ pDispatcher->GetFrame()->GetObjectShell(), aEvent);
+ }
+
+ ::cppu::OInterfaceContainerHelper* pContnr = pDispatch->GetListeners().getContainer ( aDispatchURL.Complete );
+ if (pContnr) {
+ ::cppu::OInterfaceIteratorHelper aIt( *pContnr );
+ while( aIt.hasMoreElements() )
{
- aIt.remove();
+ try
+ {
+ static_cast< ::com::sun::star::frame::XStatusListener *>(aIt.next())->statusChanged( aEvent );
+ }
+ catch (const ::com::sun::star::uno::RuntimeException&)
+ {
+ aIt.remove();
+ }
}
}
}
@@ -1035,4 +1045,27 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt
StateChanged( nSID, eState, pState, 0 );
}
+void SfxDispatchController_Impl::InterceptLOKStateChangeEvent(const SfxObjectShell* objSh, const ::com::sun::star::frame::FeatureStateEvent& aEvent) const
+{
+ if (!objSh || !objSh->isTiledRendering()) {
+ return;
+ }
+
+ if (aEvent.FeatureURL.Path == "Bold" ||
+ aEvent.FeatureURL.Path == "Italic" ||
+ aEvent.FeatureURL.Path == "Underline" ||
+ aEvent.FeatureURL.Path == "StrikeOut") {
+
+ OUStringBuffer aBuffer;
+ aBuffer.append(aEvent.FeatureURL.Complete);
+ aBuffer.append("=");
+ bool bTemp = false;
+ aEvent.State >>= bTemp;
+ aBuffer.append(bTemp);
+
+ OUString payload = aBuffer.makeStringAndClear();
+ objSh->libreOfficeKitCallback(LOK_CALLBACK_STATE_CHANGED, payload.toUtf8().getStr());
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx
index f9a25a3..16e28c0 100644
--- a/sfx2/source/doc/objcont.cxx
+++ b/sfx2/source/doc/objcont.cxx
@@ -76,6 +76,10 @@
#include "querytemplate.hxx"
#include <boost/scoped_array.hpp>
+#include <LibreOfficeKit/LibreOfficeKitTypes.h>
+
+#include <typeinfo>
+
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -639,4 +643,12 @@ bool SfxObjectShell::IsModifyPasswordEntered()
return pImp->m_bModifyPasswordEntered;
}
+void SfxObjectShell::libreOfficeKitCallback(SAL_UNUSED_PARAMETER int nType, SAL_UNUSED_PARAMETER const char* pPayload) const {
+ SAL_WARN("tiled-rendering", "LOK callback interface not overridden for SfxObjectShell subclass typeId: " << typeid(*this).name());
+}
+bool SfxObjectShell::isTiledRendering() const {
+ SAL_WARN("tiled-rendering", "LOK callback interface not overridden for SfxObjectShell subclass typeId: " << typeid(*this).name());
+ return false;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx
index 9fbb874..81b0d40 100644
--- a/sw/inc/docsh.hxx
+++ b/sw/inc/docsh.hxx
@@ -29,6 +29,8 @@
#include <svl/lstner.hxx>
#include <svtools/embedhlp.hxx>
+#define LOK_USE_UNSTABLE_API
+#include <LibreOfficeKit/LibreOfficeKitTypes.h>
class SwDoc;
class SfxDocumentInfoDialog;
@@ -311,6 +313,9 @@ public:
virtual void SetChangeRecording( bool bActivate ) SAL_OVERRIDE;
virtual bool SetProtectionPassword( const OUString &rPassword ) SAL_OVERRIDE;
virtual bool GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash ) SAL_OVERRIDE;
+
+ virtual void libreOfficeKitCallback(int nType, const char* pPayload) const SAL_OVERRIDE;
+ virtual bool isTiledRendering() const SAL_OVERRIDE;
};
/** Find the right DocShell and create a new one:
diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx
index a6d1739..18d7e82 100644
--- a/sw/source/uibase/app/docsh.cxx
+++ b/sw/source/uibase/app/docsh.cxx
@@ -72,6 +72,7 @@
#include <docstyle.hxx>
#include <doc.hxx>
#include <docfunc.hxx>
+#include <drawdoc.hxx>
#include <IDocumentUndoRedo.hxx>
#include <IDocumentSettingAccess.hxx>
#include <IDocumentLinksAdministration.hxx>
@@ -121,6 +122,9 @@
#include <sfx2/Metadatable.hxx>
#include <calbck.hxx>
+#include <sal/log.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::script;
@@ -1296,4 +1300,19 @@ bool SwDocShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal
return bRes;
}
+void SwDocShell::libreOfficeKitCallback(int nType, const char* pPayload) const
+{
+ if (!m_pDoc) {
+ return;
+ }
+
+ SwDrawModel* pDrawModel = m_pDoc->getIDocumentDrawModelAccess().GetDrawModel();
+ pDrawModel->libreOfficeKitCallback(nType, pPayload);
+}
+
+bool SwDocShell::isTiledRendering() const {
+ SwDrawModel* pDrawModel = m_pDoc->getIDocumentDrawModelAccess().GetDrawModel();
+ return pDrawModel->isTiledRendering();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 97ece54f1eedf39d551b816c30552d26506ef3bf
Author: Siqi Liu <me at siqi.fr>
Date: Fri Apr 10 13:11:31 2015 +0200
java part handles received statechange callback
Change-Id: I29f0db2b053c277d6f6418081bdf9ceab7ee8fa5
diff --git a/android/Bootstrap/src/org/libreoffice/kit/Document.java b/android/Bootstrap/src/org/libreoffice/kit/Document.java
index 5d97656..6c0ee54 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Document.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Document.java
@@ -31,6 +31,15 @@ public class Document {
public static final int MOUSE_BUTTON_UP = 1;
public static final int MOUSE_MOVE = 2;
+
+ /**
+ * State change types
+ */
+ public static final int BOLD = 0;
+ public static final int ITALIC = 1;
+ public static final int UNDERLINE = 2;
+ public static final int STRIKEOUT = 3;
+
/**
* Callback message types
*/
@@ -42,6 +51,7 @@ public class Document {
public static final int CALLBACK_CURSOR_VISIBLE = 5;
public static final int CALLBACK_GRAPHIC_SELECTION = 6;
public static final int CALLBACK_HYPERLINK_CLICKED = 7;
+ public static final int CALLBACK_STATE_CHANGED = 8;
/**
* Set text selection types
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
index 1fdc681..1d38882 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
@@ -68,11 +68,24 @@ public class InvalidationHandler implements Document.MessageCallback {
if (!payload.startsWith("http://") && !payload.startsWith("https://")) {
payload = "http://" + payload;
}
-
Intent urlIntent = new Intent(Intent.ACTION_VIEW);
urlIntent.setData(Uri.parse(payload));
LibreOfficeMainActivity.mAppContext.startActivity(urlIntent);
break;
+ case Document.CALLBACK_STATE_CHANGED:
+ Log.d("Document.CALLBACK_STATE_CHANGED: " + payload);
+ String[] parts = payload.split(":");
+ boolean pressed = Boolean.parseBoolean(parts[1]);
+ if (parts[0].equals("Bold")) {
+ LOKitShell.getToolbarController().onToggleStateChanged(Document.BOLD, pressed);
+ } else if (parts[0].equals("Italic")) {
+ LOKitShell.getToolbarController().onToggleStateChanged(Document.ITALIC, pressed);
+ } else if (parts[0].equals("Underline")) {
+ LOKitShell.getToolbarController().onToggleStateChanged(Document.UNDERLINE, pressed);
+ } else if (parts[0].equals("Strikeout")) {
+ LOKitShell.getToolbarController().onToggleStateChanged(Document.STRIKEOUT, pressed);
+ }
+ break;
}
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 61ec014..1a8c970 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -19,6 +19,7 @@ import android.widget.ListView;
import android.widget.Toast;
import org.libreoffice.overlay.DocumentOverlay;
+
import org.mozilla.gecko.ZoomConstraints;
import org.mozilla.gecko.gfx.GeckoLayerClient;
import org.mozilla.gecko.gfx.LayerView;
@@ -69,6 +70,7 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
+ mToolbarController.setOptionMenu(menu);
return super.onCreateOptionsMenu(menu);
}
@@ -141,7 +143,7 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
- mToolbarController = new ToolbarController(getSupportActionBar(), toolbar);
+ mToolbarController = new ToolbarController(this, getSupportActionBar(), toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
@@ -176,6 +178,8 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
// create TextCursorLayer
mDocumentOverlay = new DocumentOverlay(mAppContext, layerView);
+
+
}
private boolean copyFileToTemp() {
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java
index 358617f..34eff3f 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/ToolbarController.java
@@ -8,22 +8,77 @@
*/
package org.libreoffice;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.BitmapDrawable;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import org.libreoffice.canvas.ImageUtils;
+import org.libreoffice.kit.Document;
/**
* Controls the changes to the toolbar.
*/
public class ToolbarController {
+ private static final String LOGTAG = ToolbarController.class.getSimpleName();
private final Toolbar mToolbar;
private final ActionBar mActionBar;
+ private Menu mOptionsMenu;
+ private Context mContext;
- public ToolbarController(ActionBar actionBar, Toolbar toolbar) {
+ public ToolbarController(Context context, ActionBar actionBar, Toolbar toolbar) {
mToolbar = toolbar;
mActionBar = actionBar;
+ mContext = context;
switchToViewMode();
}
+ public void onToggleStateChanged(int type, boolean pressed) {
+ MenuItem menuItem = null;
+ Bitmap icon = null;
+ switch (type) {
+ case Document.BOLD:
+ menuItem = mOptionsMenu.findItem(R.id.action_bold);
+ icon = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.action_bold);
+ break;
+ case Document.ITALIC:
+ menuItem = mOptionsMenu.findItem(R.id.action_italic);
+ icon = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.action_italic);
+ break;
+ case Document.UNDERLINE:
+ menuItem = mOptionsMenu.findItem(R.id.action_underline);
+ icon = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.action_underline);
+ break;
+ case Document.STRIKEOUT:
+ menuItem = mOptionsMenu.findItem(R.id.action_strikeout);
+ icon = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.action_strikeout);
+ break;
+ default:
+ Log.e(LOGTAG, "Uncaptured state change type: " + type);
+ return;
+ }
+
+ if (menuItem == null) {
+ Log.e(LOGTAG, "MenuItem not found.");
+ return;
+ }
+
+ if (pressed) {
+ icon = ImageUtils.bitmapToPressed(icon);
+ }
+
+ menuItem.setIcon(new BitmapDrawable(mContext.getResources(), icon));
+ }
+
+ public void setOptionMenu(Menu menu) {
+ mOptionsMenu = menu;
+ }
+
/**
* Change the toolbar to edit mode.
*/
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/ImageUtils.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/ImageUtils.java
new file mode 100644
index 0000000..fd62444
--- /dev/null
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/ImageUtils.java
@@ -0,0 +1,24 @@
+package org.libreoffice.canvas;
+
+import android.graphics.Bitmap;
+import android.graphics.Color;
+
+public class ImageUtils {
+ /**
+ * Convert transparent pixels to gray ones.
+ */
+ public static Bitmap bitmapToPressed(Bitmap input) {
+ Bitmap op = Bitmap.createBitmap(input.getWidth(), input.getHeight(), input.getConfig());
+ for(int i=0; i<op.getWidth(); i++){
+ for(int j=0; j<op.getHeight(); j++){
+ int p = input.getPixel(i, j);
+ // assign gray color if the pixel in input is transparent.
+ int newColor = Color.alpha(p) == 0 ? Color.argb(255, 200, 200, 200) : p;
+ op.setPixel(i, j, newColor);
+ }
+ }
+
+ return op;
+ }
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list