blob: 87c4a94bf4b290d9898ef217f94475f728034d61 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.libreoffice.impressremote.activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import org.libreoffice.impressremote.R;
import org.libreoffice.impressremote.fragment.SlidesGridFragment;
import org.libreoffice.impressremote.fragment.SlidesPagerFragment;
public class SlideShowActivity extends SherlockFragmentActivity {
private static enum Mode {
PAGER, GRID
}
private Mode mMode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mMode = Mode.PAGER;
setUpHomeButton();
setUpFragment();
}
private void setUpHomeButton() {
getSupportActionBar().setHomeButtonEnabled(true);
}
private void setUpFragment() {
switch (mMode) {
case PAGER:
setUpFragment(SlidesPagerFragment.newInstance());
break;
case GRID:
setUpFragment(SlidesGridFragment.newInstance());
break;
default:
setUpFragment(SlidesPagerFragment.newInstance());
break;
}
}
private void setUpFragment(Fragment aFragment) {
FragmentTransaction aTransaction = getSupportFragmentManager().beginTransaction();
aTransaction.replace(android.R.id.content, aFragment);
aTransaction.commit();
}
@Override
public boolean onCreateOptionsMenu(Menu aMenu) {
getSupportMenuInflater().inflate(getActionBarMenuResourceId(), aMenu);
return true;
}
private int getActionBarMenuResourceId() {
switch (mMode) {
case PAGER:
return R.menu.menu_action_bar_slide_show_pager;
case GRID:
return R.menu.menu_action_bar_slide_show_grid;
default:
return R.menu.menu_action_bar_slide_show_pager;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem aMenuItem) {
switch (aMenuItem.getItemId()) {
case R.id.menu_slides_grid:
mMode = Mode.GRID;
setUpFragment();
refreshActionBarMenu();
return true;
case R.id.menu_slides_pager:
mMode = Mode.PAGER;
setUpFragment();
refreshActionBarMenu();
return true;
default:
return super.onOptionsItemSelected(aMenuItem);
}
}
private void refreshActionBarMenu() {
supportInvalidateOptionsMenu();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|