forked from amazingfate/loongoffice
It was coded pretty badly, so I cleaned it up. Most notably, it used a static instance of the Activity, which is a huge no-no which creates memory leaks. The irony is, it already had a reference to the Activity used correctly in the constructor. One memory-leak fixed, 29 more to go (LibreOfficeMainActivity holds that static Activity object which needs fixing). Also, simplified the "bottom toolbar" in preparation for the CoordinatorLayout implementation which will allow the activity to have fancy animations and smart interactions. Change-Id: I31aa117f6179910db73a5256b0a287357e1dec83 Reviewed-on: https://gerrit.libreoffice.org/33010 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: jan iversen <jani@documentfoundation.org>
111 lines
4.5 KiB
Java
111 lines
4.5 KiB
Java
package org.libreoffice;
|
|
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.widget.ImageButton;
|
|
|
|
import org.libreoffice.kit.Document;
|
|
|
|
class FormattingController implements View.OnClickListener {
|
|
private static final String LOGTAG = ToolbarController.class.getSimpleName();
|
|
|
|
private LibreOfficeMainActivity mContext;
|
|
|
|
FormattingController(LibreOfficeMainActivity context) {
|
|
mContext = context;
|
|
|
|
mContext.findViewById(R.id.button_bold).setOnClickListener(this);
|
|
mContext.findViewById(R.id.button_italic).setOnClickListener(this);
|
|
mContext.findViewById(R.id.button_strikethrough).setOnClickListener(this);
|
|
mContext.findViewById(R.id.button_underlined).setOnClickListener(this);
|
|
|
|
mContext.findViewById(R.id.button_align_left).setOnClickListener(this);
|
|
mContext.findViewById(R.id.button_align_center).setOnClickListener(this);
|
|
mContext.findViewById(R.id.button_align_right).setOnClickListener(this);
|
|
mContext.findViewById(R.id.button_align_justify).setOnClickListener(this);
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View view) {
|
|
ImageButton button = (ImageButton) view;
|
|
|
|
if (button.isSelected()) {
|
|
button.getBackground().setState(new int[]{-android.R.attr.state_selected});
|
|
} else {
|
|
button.getBackground().setState(new int[]{android.R.attr.state_selected});
|
|
}
|
|
|
|
switch(button.getId()) {
|
|
case R.id.button_bold:
|
|
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Bold"));
|
|
break;
|
|
case R.id.button_italic:
|
|
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Italic"));
|
|
break;
|
|
case R.id.button_strikethrough:
|
|
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Strikeout"));
|
|
break;
|
|
case R.id.button_underlined:
|
|
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Underline"));
|
|
break;
|
|
case R.id.button_align_left:
|
|
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:LeftPara"));
|
|
break;
|
|
case R.id.button_align_center:
|
|
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:CenterPara"));
|
|
break;
|
|
case R.id.button_align_right:
|
|
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:RightPara"));
|
|
break;
|
|
case R.id.button_align_justify:
|
|
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:JustifyPara"));
|
|
break;
|
|
}
|
|
}
|
|
|
|
void onToggleStateChanged(final int type, final boolean selected) {
|
|
LOKitShell.getMainHandler().post(new Runnable() {
|
|
public void run() {
|
|
Integer buttonId;
|
|
switch (type) {
|
|
case Document.BOLD:
|
|
buttonId = R.id.button_bold;
|
|
break;
|
|
case Document.ITALIC:
|
|
buttonId = R.id.button_italic;
|
|
break;
|
|
case Document.UNDERLINE:
|
|
buttonId = R.id.button_underlined;
|
|
break;
|
|
case Document.STRIKEOUT:
|
|
buttonId = R.id.button_strikethrough;
|
|
break;
|
|
case Document.ALIGN_LEFT:
|
|
buttonId = R.id.button_align_left;
|
|
break;
|
|
case Document.ALIGN_CENTER:
|
|
buttonId = R.id.button_align_center;
|
|
break;
|
|
case Document.ALIGN_RIGHT:
|
|
buttonId = R.id.button_align_right;
|
|
break;
|
|
case Document.ALIGN_JUSTIFY:
|
|
buttonId = R.id.button_align_justify;
|
|
break;
|
|
default:
|
|
Log.e(LOGTAG, "Uncaptured state change type: " + type);
|
|
return;
|
|
}
|
|
|
|
ImageButton button = (ImageButton) mContext.findViewById(buttonId);
|
|
button.setSelected(selected);
|
|
if (selected) {
|
|
button.getBackground().setState(new int[]{android.R.attr.state_selected});
|
|
} else {
|
|
button.getBackground().setState(new int[]{-android.R.attr.state_selected});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|