1 /***
2 * Ambient - A music player for the Android platform
3 Copyright (C) 2007 Martin Vysny
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package sk.baka.ambient.activity;
20
21 import java.util.EnumMap;
22
23 import sk.baka.ambient.AmbientApplication;
24 import sk.baka.ambient.AppState;
25 import sk.baka.ambient.R;
26 import sk.baka.ambient.ZoomEnum;
27 import sk.baka.ambient.activity.main.MainActivity;
28 import android.app.Activity;
29 import android.content.Intent;
30 import android.os.Bundle;
31 import android.view.View;
32
33 /***
34 * Shows the About dialog.
35 *
36 * @author Martin Vysny
37 */
38 public final class ZoomActivity extends Activity {
39 @Override
40 protected void onCreate(Bundle icicle) {
41 super.onCreate(icicle);
42 setContentView(R.layout.zoom);
43 final View zoomButtonZoomIn = findViewById(R.id.zoomButtonZoomIn);
44 zoomButtonZoomIn.setOnClickListener(new ClickListener(ZoomEnum.Buttons,
45 -1));
46 final View zoomButtonZoomOut = findViewById(R.id.zoomButtonZoomOut);
47 zoomButtonZoomOut.setOnClickListener(new ClickListener(
48 ZoomEnum.Buttons, 1));
49 final View zoomListZoomIn = findViewById(R.id.zoomListViewZoomIn);
50 zoomListZoomIn.setOnClickListener(new ClickListener(
51 ZoomEnum.ListViewItems, -1));
52 final View zoomListZoomOut = findViewById(R.id.zoomListViewZoomOut);
53 zoomListZoomOut.setOnClickListener(new ClickListener(
54 ZoomEnum.ListViewItems, 1));
55 }
56
57 private class ClickListener implements View.OnClickListener {
58 private final ZoomEnum buttons;
59 private final int delta;
60
61 public ClickListener(ZoomEnum buttons, int delta) {
62 this.buttons = buttons;
63 this.delta = delta;
64 }
65
66 public void onClick(View v) {
67 final AppState startupState = AmbientApplication.getInstance()
68 .getStateHandler().getStartupState();
69 final EnumMap<ZoomEnum, Integer> zoom = startupState.zoom;
70 final int level = buttons.getLevel(zoom) + delta;
71 if (!buttons.levels.contains(level)) {
72 return;
73 }
74 startupState.setZoomLevel(buttons, level);
75 final Intent i = new Intent(ZoomActivity.this, MainActivity.class);
76 final EnumMap<ZoomEnum, Integer> newZoom = new EnumMap<ZoomEnum, Integer>(
77 ZoomEnum.class);
78 newZoom.put(buttons, level);
79 i.putExtra(MainActivity.INTENTKEY_ZOOM, newZoom);
80
81 startActivity(i);
82 finish();
83 }
84 }
85 }