Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / android / source / src / java / org / libreoffice / ToolbarController.java
blobec00abb2808c746e00596cd146e9b69d2bf56ded
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9 package org.libreoffice;
11 import android.content.Context;
12 import android.content.res.Resources;
13 import android.graphics.Bitmap;
14 import android.graphics.BitmapFactory;
15 import android.graphics.drawable.BitmapDrawable;
16 import android.graphics.drawable.Drawable;
17 import android.graphics.drawable.LayerDrawable;
18 import android.support.v7.app.ActionBar;
19 import android.support.v7.widget.Toolbar;
20 import android.util.Log;
21 import android.view.Menu;
22 import android.view.MenuItem;
23 import android.view.View;
24 import android.widget.ImageButton;
25 import android.widget.Toast;
27 import org.libreoffice.canvas.ImageUtils;
28 import org.libreoffice.kit.Document;
30 import java.sql.SQLOutput;
31 import java.util.Arrays;
33 /**
34 * Controls the changes to the toolbar.
36 public class ToolbarController implements Toolbar.OnMenuItemClickListener {
37 private static final String LOGTAG = ToolbarController.class.getSimpleName();
38 private final Toolbar mToolbarTop;
40 private final ActionBar mActionBar;
41 private LibreOfficeMainActivity mContext;
42 private Menu mMainMenu;
44 public ToolbarController(LibreOfficeMainActivity context, ActionBar actionBar, Toolbar toolbarTop) {
45 mToolbarTop = toolbarTop;
46 mActionBar = actionBar;
47 mContext = context;
49 mToolbarTop.inflateMenu(R.menu.main);
50 mToolbarTop.setOnMenuItemClickListener(this);
51 switchToViewMode();
53 mMainMenu = mToolbarTop.getMenu();
56 public void disableMenuItem(final int menuItemId, final boolean disabled) {
57 LOKitShell.getMainHandler().post(new Runnable() {
58 public void run() {
59 MenuItem menuItem = mMainMenu.findItem(menuItemId);
60 if (menuItem != null) {
61 menuItem.setEnabled(!disabled);
62 } else {
63 Log.e(LOGTAG, "MenuItem not found.");
66 });
69 /**
70 * Change the toolbar to edit mode.
72 void switchToEditMode() {
73 if (!LOKitShell.isEditingEnabled())
74 return;
76 // Ensure the change is done on UI thread
77 LOKitShell.getMainHandler().post(new Runnable() {
78 @Override
79 public void run() {
80 mMainMenu.setGroupVisible(R.id.group_edit_actions, true);
81 mToolbarTop.setNavigationIcon(R.drawable.ic_check);
82 mToolbarTop.setTitle(null);
83 mToolbarTop.setLogo(null);
86 });
89 /**
90 * Change the toolbar to view mode.
92 void switchToViewMode() {
93 if (!LOKitShell.isEditingEnabled())
94 return;
96 // Ensure the change is done on UI thread
97 LOKitShell.getMainHandler().post(new Runnable() {
98 @Override
99 public void run() {
100 mMainMenu.setGroupVisible(R.id.group_edit_actions, false);
101 mToolbarTop.setNavigationIcon(R.drawable.lo_icon);
102 mToolbarTop.setTitle(null);
103 mToolbarTop.setLogo(null);
108 @Override
109 public boolean onMenuItemClick(MenuItem item) {
110 switch (item.getItemId()) {
111 case R.id.action_keyboard:
112 mContext.showSoftKeyboard();
113 break;
114 case R.id.action_format:
115 mContext.showFormattingToolbar();
116 break;
117 case R.id.action_about:
118 mContext.showAbout();
119 return true;
120 case R.id.action_save:
121 mContext.saveDocument();
122 return true;
123 case R.id.action_parts:
124 mContext.openDrawer();
125 return true;
126 case R.id.action_settings:
127 mContext.showSettings();
128 return true;
129 case R.id.action_search:
130 mContext.showSearchToolbar();
131 return true;
132 case R.id.action_undo:
133 LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Undo"));
134 return true;
135 case R.id.action_redo:
136 LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Redo"));
137 return true;
139 return false;
142 public void setupToolbars() {
143 LibreOfficeMainActivity activity = mContext;
144 if (activity.usesTemporaryFile()) {
145 disableMenuItem(R.id.action_save, true);
146 Toast.makeText(activity, activity.getString(R.string.temp_file_saving_disabled), Toast.LENGTH_LONG).show();
148 mMainMenu.findItem(R.id.action_parts).setVisible(activity.isDrawerEnabled());
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */