Cleaned up FormattingController
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>
This commit is contained in:
parent
15c97b28aa
commit
9123ba9632
@ -1,12 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
<LinearLayout
|
||||||
android:id="@+id/toolbar_bottom"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="fill_parent"
|
android:id="@+id/toolbar_bottom"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:elevation="3dp"
|
android:elevation="3dp"
|
||||||
android:background="@color/toolbar_background"
|
android:background="@color/toolbar_background"
|
||||||
@ -14,119 +15,114 @@
|
|||||||
app:theme="@style/LibreOfficeTheme.Toolbar"
|
app:theme="@style/LibreOfficeTheme.Toolbar"
|
||||||
tools:showIn="@layout/activity_main">
|
tools:showIn="@layout/activity_main">
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/formatting_toolbar"
|
android:id="@+id/formatting_toolbar"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_bold"
|
android:id="@+id/button_bold"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.25"
|
android:layout_weight="0.25"
|
||||||
android:background="@drawable/image_button_background"
|
android:background="@drawable/image_button_background"
|
||||||
android:paddingBottom="5dp"
|
android:paddingBottom="12dp"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="12dp"
|
||||||
android:src="@drawable/ic_format_bold"/>
|
android:src="@drawable/ic_format_bold"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_italic"
|
android:id="@+id/button_italic"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.25"
|
android:layout_weight="0.25"
|
||||||
android:background="@drawable/image_button_background"
|
android:background="@drawable/image_button_background"
|
||||||
android:paddingBottom="5dp"
|
android:paddingBottom="12dp"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="12dp"
|
||||||
android:src="@drawable/ic_format_italic"/>
|
android:src="@drawable/ic_format_italic"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_underlined"
|
android:id="@+id/button_underlined"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.25"
|
android:layout_weight="0.25"
|
||||||
android:background="@drawable/image_button_background"
|
android:background="@drawable/image_button_background"
|
||||||
android:paddingBottom="5dp"
|
android:paddingBottom="12dp"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="12dp"
|
||||||
android:src="@drawable/ic_format_underlined"/>
|
android:src="@drawable/ic_format_underlined"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_strikethrough"
|
android:id="@+id/button_strikethrough"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.25"
|
android:layout_weight="0.25"
|
||||||
android:background="@drawable/image_button_background"
|
android:background="@drawable/image_button_background"
|
||||||
android:paddingBottom="5dp"
|
android:paddingBottom="12dp"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="12dp"
|
||||||
android:src="@drawable/ic_format_strikethrough"/>
|
android:src="@drawable/ic_format_strikethrough"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_align_left"
|
android:id="@+id/button_align_left"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.25"
|
android:layout_weight="0.25"
|
||||||
android:background="@drawable/image_button_background"
|
android:background="@drawable/image_button_background"
|
||||||
android:paddingBottom="5dp"
|
android:paddingBottom="12dp"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="12dp"
|
||||||
android:src="@drawable/ic_format_align_left"/>
|
android:src="@drawable/ic_format_align_left"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_align_center"
|
android:id="@+id/button_align_center"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.25"
|
android:layout_weight="0.25"
|
||||||
android:background="@drawable/image_button_background"
|
android:background="@drawable/image_button_background"
|
||||||
android:paddingBottom="5dp"
|
android:paddingBottom="12dp"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="12dp"
|
||||||
android:src="@drawable/ic_format_align_center"/>
|
android:src="@drawable/ic_format_align_center"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_align_right"
|
android:id="@+id/button_align_right"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.25"
|
android:layout_weight="0.25"
|
||||||
android:background="@drawable/image_button_background"
|
android:background="@drawable/image_button_background"
|
||||||
android:paddingBottom="5dp"
|
android:paddingBottom="12dp"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="12dp"
|
||||||
android:src="@drawable/ic_format_align_right"/>
|
android:src="@drawable/ic_format_align_right"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_align_justify"
|
android:id="@+id/button_align_justify"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.25"
|
android:layout_weight="0.25"
|
||||||
android:background="@drawable/image_button_background"
|
android:background="@drawable/image_button_background"
|
||||||
android:paddingBottom="5dp"
|
android:paddingBottom="12dp"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="12dp"
|
||||||
android:src="@drawable/ic_format_align_justify"/>
|
android:src="@drawable/ic_format_align_justify"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/font_name_spinner"
|
android:id="@+id/font_name_spinner"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:minHeight="50dip"/>
|
android:minHeight="50dip"/>
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/font_size_spinner"
|
android:id="@+id/font_size_spinner"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:minHeight="50dip"/>
|
android:minHeight="50dip"/>
|
||||||
@ -136,25 +132,25 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/search_toolbar"
|
android:id="@+id/search_toolbar"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/search_string"
|
android:id="@+id/search_string"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="0.2"/>
|
android:layout_weight="0.2"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_search_up"
|
android:id="@+id/button_search_up"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="0.6"
|
android:layout_weight="0.6"
|
||||||
android:background="@drawable/image_button_background"
|
android:background="@drawable/image_button_background"
|
||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
@ -162,14 +158,13 @@
|
|||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_search_down"
|
android:id="@+id/button_search_down"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="0.6"
|
android:layout_weight="0.6"
|
||||||
android:background="@drawable/image_button_background"
|
android:background="@drawable/image_button_background"
|
||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
android:src="@drawable/ic_search_direction_up"/>
|
android:src="@drawable/ic_search_direction_up"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</android.support.v7.widget.Toolbar>
|
</LinearLayout>
|
||||||
|
@ -1,40 +1,35 @@
|
|||||||
package org.libreoffice;
|
package org.libreoffice;
|
||||||
|
|
||||||
import android.support.v7.widget.Toolbar;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
|
||||||
import org.libreoffice.kit.Document;
|
import org.libreoffice.kit.Document;
|
||||||
|
|
||||||
public class FormattingController implements View.OnClickListener {
|
class FormattingController implements View.OnClickListener {
|
||||||
private static final String LOGTAG = ToolbarController.class.getSimpleName();
|
private static final String LOGTAG = ToolbarController.class.getSimpleName();
|
||||||
|
|
||||||
private final Toolbar mToolbarBottom;
|
|
||||||
private LibreOfficeMainActivity mContext;
|
private LibreOfficeMainActivity mContext;
|
||||||
|
|
||||||
public FormattingController(LibreOfficeMainActivity context, Toolbar toolbarBottom) {
|
FormattingController(LibreOfficeMainActivity context) {
|
||||||
mToolbarBottom = toolbarBottom;
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
|
||||||
((ImageButton) context.findViewById(R.id.button_bold)).setOnClickListener(this);
|
mContext.findViewById(R.id.button_bold).setOnClickListener(this);
|
||||||
((ImageButton) context.findViewById(R.id.button_italic)).setOnClickListener(this);
|
mContext.findViewById(R.id.button_italic).setOnClickListener(this);
|
||||||
((ImageButton) context.findViewById(R.id.button_strikethrough)).setOnClickListener(this);
|
mContext.findViewById(R.id.button_strikethrough).setOnClickListener(this);
|
||||||
((ImageButton) context.findViewById(R.id.button_underlined)).setOnClickListener(this);
|
mContext.findViewById(R.id.button_underlined).setOnClickListener(this);
|
||||||
|
|
||||||
((ImageButton) context.findViewById(R.id.button_align_left)).setOnClickListener(this);
|
mContext.findViewById(R.id.button_align_left).setOnClickListener(this);
|
||||||
((ImageButton) context.findViewById(R.id.button_align_center)).setOnClickListener(this);
|
mContext.findViewById(R.id.button_align_center).setOnClickListener(this);
|
||||||
((ImageButton) context.findViewById(R.id.button_align_right)).setOnClickListener(this);
|
mContext.findViewById(R.id.button_align_right).setOnClickListener(this);
|
||||||
((ImageButton) context.findViewById(R.id.button_align_justify)).setOnClickListener(this);
|
mContext.findViewById(R.id.button_align_justify).setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
ImageButton button = (ImageButton) view;
|
ImageButton button = (ImageButton) view;
|
||||||
boolean selected = button.isSelected();
|
|
||||||
button.setSelected(selected);
|
|
||||||
|
|
||||||
if (selected) {
|
if (button.isSelected()) {
|
||||||
button.getBackground().setState(new int[]{-android.R.attr.state_selected});
|
button.getBackground().setState(new int[]{-android.R.attr.state_selected});
|
||||||
} else {
|
} else {
|
||||||
button.getBackground().setState(new int[]{android.R.attr.state_selected});
|
button.getBackground().setState(new int[]{android.R.attr.state_selected});
|
||||||
@ -65,15 +60,13 @@ public class FormattingController implements View.OnClickListener {
|
|||||||
case R.id.button_align_justify:
|
case R.id.button_align_justify:
|
||||||
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:JustifyPara"));
|
LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:JustifyPara"));
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onToggleStateChanged(final int type, final boolean selected) {
|
void onToggleStateChanged(final int type, final boolean selected) {
|
||||||
LOKitShell.getMainHandler().post(new Runnable() {
|
LOKitShell.getMainHandler().post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Integer buttonId = null;
|
Integer buttonId;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Document.BOLD:
|
case Document.BOLD:
|
||||||
buttonId = R.id.button_bold;
|
buttonId = R.id.button_bold;
|
||||||
@ -104,8 +97,7 @@ public class FormattingController implements View.OnClickListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LibreOfficeMainActivity activity = LibreOfficeMainActivity.mAppContext;
|
ImageButton button = (ImageButton) mContext.findViewById(buttonId);
|
||||||
ImageButton button = (ImageButton) activity.findViewById(buttonId);
|
|
||||||
button.setSelected(selected);
|
button.setSelected(selected);
|
||||||
if (selected) {
|
if (selected) {
|
||||||
button.getBackground().setState(new int[]{android.R.attr.state_selected});
|
button.getBackground().setState(new int[]{android.R.attr.state_selected});
|
||||||
@ -114,29 +106,5 @@ public class FormattingController implements View.OnClickListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*if (menuItem == null) {
|
|
||||||
Log.e(LOGTAG, "MenuItem not found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Drawable drawable;
|
|
||||||
if (pressed) {
|
|
||||||
Resources resources = mContext.getResources();
|
|
||||||
Drawable[] layers = new Drawable[2];
|
|
||||||
layers[0] = resources.getDrawable(R.drawable.icon_background);
|
|
||||||
layers[1] = resources.getDrawable(drawableId);
|
|
||||||
drawable = new LayerDrawable(layers);
|
|
||||||
} else {
|
|
||||||
drawable = mContext.getResources().getDrawable(drawableId);
|
|
||||||
}
|
|
||||||
|
|
||||||
final MenuItem fMenuItem = menuItem;
|
|
||||||
LOKitShell.getMainHandler().post(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
fMenuItem.setIcon(drawable);
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,12 +121,11 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
|
|||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar);
|
Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar);
|
||||||
Toolbar toolbarBottom = (Toolbar) findViewById(R.id.toolbar_bottom);
|
|
||||||
|
|
||||||
hideBottomToolbar();
|
hideBottomToolbar();
|
||||||
|
|
||||||
mToolbarController = new ToolbarController(this, getSupportActionBar(), toolbarTop);
|
mToolbarController = new ToolbarController(this, getSupportActionBar(), toolbarTop);
|
||||||
mFormattingController = new FormattingController(this, toolbarBottom);
|
mFormattingController = new FormattingController(this);
|
||||||
toolbarTop.setNavigationOnClickListener(new View.OnClickListener() {
|
toolbarTop.setNavigationOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
@ -458,8 +457,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
|
|||||||
LOKitShell.getMainHandler().post(new Runnable() {
|
LOKitShell.getMainHandler().post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Toolbar toolbarBottom = (Toolbar) findViewById(R.id.toolbar_bottom);
|
if (findViewById(R.id.toolbar_bottom).getVisibility() != View.VISIBLE) {
|
||||||
if (toolbarBottom.getVisibility() != View.VISIBLE) {
|
|
||||||
showSoftKeyboardDirect();
|
showSoftKeyboardDirect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user