1 package org
.libreoffice
;
3 import android
.content
.Context
;
4 import android
.support
.v7
.app
.ActionBar
;
5 import android
.support
.v7
.widget
.Toolbar
;
6 import android
.util
.Log
;
7 import android
.view
.Menu
;
8 import android
.view
.View
;
9 import android
.widget
.ImageButton
;
11 import org
.libreoffice
.kit
.Document
;
13 public class FormattingController
implements View
.OnClickListener
{
14 private static final String LOGTAG
= ToolbarController
.class.getSimpleName();
16 private final Toolbar mToolbarBottom
;
17 private LibreOfficeMainActivity mContext
;
19 public FormattingController(LibreOfficeMainActivity context
, Toolbar toolbarBottom
) {
20 mToolbarBottom
= toolbarBottom
;
23 ((ImageButton
) context
.findViewById(R
.id
.button_bold
)).setOnClickListener(this);
24 ((ImageButton
) context
.findViewById(R
.id
.button_italic
)).setOnClickListener(this);
25 ((ImageButton
) context
.findViewById(R
.id
.button_strikethrough
)).setOnClickListener(this);
26 ((ImageButton
) context
.findViewById(R
.id
.button_underlined
)).setOnClickListener(this);
28 ((ImageButton
) context
.findViewById(R
.id
.button_align_left
)).setOnClickListener(this);
29 ((ImageButton
) context
.findViewById(R
.id
.button_align_center
)).setOnClickListener(this);
30 ((ImageButton
) context
.findViewById(R
.id
.button_align_right
)).setOnClickListener(this);
31 ((ImageButton
) context
.findViewById(R
.id
.button_align_justify
)).setOnClickListener(this);
35 public void onClick(View view
) {
36 ImageButton button
= (ImageButton
) view
;
37 boolean selected
= button
.isSelected();
38 button
.setSelected(selected
);
41 button
.getBackground().setState(new int[]{-android
.R
.attr
.state_selected
});
43 button
.getBackground().setState(new int[]{android
.R
.attr
.state_selected
});
46 switch(button
.getId()) {
47 case R
.id
.button_bold
:
48 LOKitShell
.sendEvent(new LOEvent(LOEvent
.UNO_COMMAND
, ".uno:Bold"));
50 case R
.id
.button_italic
:
51 LOKitShell
.sendEvent(new LOEvent(LOEvent
.UNO_COMMAND
, ".uno:Italic"));
53 case R
.id
.button_strikethrough
:
54 LOKitShell
.sendEvent(new LOEvent(LOEvent
.UNO_COMMAND
, ".uno:Strikeout"));
56 case R
.id
.button_underlined
:
57 LOKitShell
.sendEvent(new LOEvent(LOEvent
.UNO_COMMAND
, ".uno:Underline"));
59 case R
.id
.button_align_left
:
60 LOKitShell
.sendEvent(new LOEvent(LOEvent
.UNO_COMMAND
, ".uno:LeftPara"));
62 case R
.id
.button_align_center
:
63 LOKitShell
.sendEvent(new LOEvent(LOEvent
.UNO_COMMAND
, ".uno:CenterPara"));
65 case R
.id
.button_align_right
:
66 LOKitShell
.sendEvent(new LOEvent(LOEvent
.UNO_COMMAND
, ".uno:RightPara"));
68 case R
.id
.button_align_justify
:
69 LOKitShell
.sendEvent(new LOEvent(LOEvent
.UNO_COMMAND
, ".uno:JustifyPara"));
76 public void onToggleStateChanged(final int type
, final boolean selected
) {
77 LOKitShell
.getMainHandler().post(new Runnable() {
79 Integer buttonId
= null;
82 buttonId
= R
.id
.button_bold
;
85 buttonId
= R
.id
.button_italic
;
87 case Document
.UNDERLINE
:
88 buttonId
= R
.id
.button_underlined
;
90 case Document
.STRIKEOUT
:
91 buttonId
= R
.id
.button_strikethrough
;
93 case Document
.ALIGN_LEFT
:
94 buttonId
= R
.id
.button_align_left
;
96 case Document
.ALIGN_CENTER
:
97 buttonId
= R
.id
.button_align_center
;
99 case Document
.ALIGN_RIGHT
:
100 buttonId
= R
.id
.button_align_right
;
102 case Document
.ALIGN_JUSTIFY
:
103 buttonId
= R
.id
.button_align_justify
;
106 Log
.e(LOGTAG
, "Uncaptured state change type: " + type
);
110 LibreOfficeMainActivity activity
= LibreOfficeMainActivity
.mAppContext
;
111 ImageButton button
= (ImageButton
) activity
.findViewById(buttonId
);
112 button
.setSelected(selected
);
114 button
.getBackground().setState(new int[]{android
.R
.attr
.state_selected
});
116 button
.getBackground().setState(new int[]{-android
.R
.attr
.state_selected
});
122 /*if (menuItem == null) {
123 Log.e(LOGTAG, "MenuItem not found.");
127 final Drawable drawable;
129 Resources resources = mContext.getResources();
130 Drawable[] layers = new Drawable[2];
131 layers[0] = resources.getDrawable(R.drawable.icon_background);
132 layers[1] = resources.getDrawable(drawableId);
133 drawable = new LayerDrawable(layers);
135 drawable = mContext.getResources().getDrawable(drawableId);
138 final MenuItem fMenuItem = menuItem;
139 LOKitShell.getMainHandler().post(new Runnable() {
141 fMenuItem.setIcon(drawable);