Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / android / source / src / java / org / libreoffice / FormattingController.java
blobb5534c2a22be82d2a4d8b9ceae6e131c11291443
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;
21 mContext = context;
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);
34 @Override
35 public void onClick(View view) {
36 ImageButton button = (ImageButton) view;
37 boolean selected = button.isSelected();
38 button.setSelected(selected);
40 if (selected) {
41 button.getBackground().setState(new int[]{-android.R.attr.state_selected});
42 } else {
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"));
49 break;
50 case R.id.button_italic:
51 LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Italic"));
52 break;
53 case R.id.button_strikethrough:
54 LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Strikeout"));
55 break;
56 case R.id.button_underlined:
57 LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Underline"));
58 break;
59 case R.id.button_align_left:
60 LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:LeftPara"));
61 break;
62 case R.id.button_align_center:
63 LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:CenterPara"));
64 break;
65 case R.id.button_align_right:
66 LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:RightPara"));
67 break;
68 case R.id.button_align_justify:
69 LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:JustifyPara"));
70 break;
71 default:
72 break;
76 public void onToggleStateChanged(final int type, final boolean selected) {
77 LOKitShell.getMainHandler().post(new Runnable() {
78 public void run() {
79 Integer buttonId = null;
80 switch (type) {
81 case Document.BOLD:
82 buttonId = R.id.button_bold;
83 break;
84 case Document.ITALIC:
85 buttonId = R.id.button_italic;
86 break;
87 case Document.UNDERLINE:
88 buttonId = R.id.button_underlined;
89 break;
90 case Document.STRIKEOUT:
91 buttonId = R.id.button_strikethrough;
92 break;
93 case Document.ALIGN_LEFT:
94 buttonId = R.id.button_align_left;
95 break;
96 case Document.ALIGN_CENTER:
97 buttonId = R.id.button_align_center;
98 break;
99 case Document.ALIGN_RIGHT:
100 buttonId = R.id.button_align_right;
101 break;
102 case Document.ALIGN_JUSTIFY:
103 buttonId = R.id.button_align_justify;
104 break;
105 default:
106 Log.e(LOGTAG, "Uncaptured state change type: " + type);
107 return;
110 LibreOfficeMainActivity activity = LibreOfficeMainActivity.mAppContext;
111 ImageButton button = (ImageButton) activity.findViewById(buttonId);
112 button.setSelected(selected);
113 if (selected) {
114 button.getBackground().setState(new int[]{android.R.attr.state_selected});
115 } else {
116 button.getBackground().setState(new int[]{-android.R.attr.state_selected});
122 /*if (menuItem == null) {
123 Log.e(LOGTAG, "MenuItem not found.");
124 return;
127 final Drawable drawable;
128 if (pressed) {
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);
134 } else {
135 drawable = mContext.getResources().getDrawable(drawableId);
138 final MenuItem fMenuItem = menuItem;
139 LOKitShell.getMainHandler().post(new Runnable() {
140 public void run() {
141 fMenuItem.setIcon(drawable);
143 });*/