1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
;
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
;
49 mToolbarTop
.inflateMenu(R
.menu
.main
);
50 mToolbarTop
.setOnMenuItemClickListener(this);
53 mMainMenu
= mToolbarTop
.getMenu();
56 public void disableMenuItem(final int menuItemId
, final boolean disabled
) {
57 LOKitShell
.getMainHandler().post(new Runnable() {
59 MenuItem menuItem
= mMainMenu
.findItem(menuItemId
);
60 if (menuItem
!= null) {
61 menuItem
.setEnabled(!disabled
);
63 Log
.e(LOGTAG
, "MenuItem not found.");
70 * Change the toolbar to edit mode.
72 void switchToEditMode() {
73 if (!LOKitShell
.isEditingEnabled())
76 // Ensure the change is done on UI thread
77 LOKitShell
.getMainHandler().post(new Runnable() {
80 mMainMenu
.setGroupVisible(R
.id
.group_edit_actions
, true);
81 mToolbarTop
.setNavigationIcon(R
.drawable
.ic_check
);
82 mToolbarTop
.setTitle(null);
83 mToolbarTop
.setLogo(null);
90 * Change the toolbar to view mode.
92 void switchToViewMode() {
93 if (!LOKitShell
.isEditingEnabled())
96 // Ensure the change is done on UI thread
97 LOKitShell
.getMainHandler().post(new Runnable() {
100 mMainMenu
.setGroupVisible(R
.id
.group_edit_actions
, false);
101 mToolbarTop
.setNavigationIcon(R
.drawable
.lo_icon
);
102 mToolbarTop
.setTitle(null);
103 mToolbarTop
.setLogo(null);
109 public boolean onMenuItemClick(MenuItem item
) {
110 switch (item
.getItemId()) {
111 case R
.id
.action_keyboard
:
112 mContext
.showSoftKeyboard();
114 case R
.id
.action_format
:
115 mContext
.showFormattingToolbar();
117 case R
.id
.action_about
:
118 mContext
.showAbout();
120 case R
.id
.action_save
:
121 mContext
.saveDocument();
123 case R
.id
.action_parts
:
124 mContext
.openDrawer();
126 case R
.id
.action_settings
:
127 mContext
.showSettings();
129 case R
.id
.action_search
:
130 mContext
.showSearchToolbar();
132 case R
.id
.action_undo
:
133 LOKitShell
.sendEvent(new LOEvent(LOEvent
.UNO_COMMAND
, ".uno:Undo"));
135 case R
.id
.action_redo
:
136 LOKitShell
.sendEvent(new LOEvent(LOEvent
.UNO_COMMAND
, ".uno:Redo"));
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: */