View Javadoc

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  package sk.baka.ambient;
19  
20  import java.io.Serializable;
21  import java.util.EnumMap;
22  
23  import sk.baka.ambient.activity.AmpacheClientBean;
24  import sk.baka.ambient.activity.main.MainActivity;
25  import sk.baka.ambient.playerservice.PlayerStateEnum;
26  import sk.baka.ambient.playlist.IPlaylistStrategy;
27  import sk.baka.ambient.playlist.Random;
28  import sk.baka.ambient.playlist.Repeat;
29  
30  /***
31   * A serializable application state.
32   * 
33   * @author Martin Vysny
34   */
35  public final class AppState implements Serializable {
36  	private static final long serialVersionUID = 6222503996948628518L;
37  
38  	/***
39  	 * The playlist strategy.
40  	 */
41  	public IPlaylistStrategy playlist;
42  
43  	/***
44  	 * State of playback.
45  	 */
46  	public PlayerStateEnum state = PlayerStateEnum.Stopped;
47  
48  	/***
49  	 * Position in playback, in milliseconds.
50  	 */
51  	public int position = 0;
52  
53  	/***
54  	 * The repeat state.
55  	 */
56  	public Repeat repeat = Repeat.NO;
57  
58  	/***
59  	 * The random state.
60  	 */
61  	public Random random = Random.NONE;
62  
63  	/***
64  	 * The {@link MainActivity} visible controller.
65  	 */
66  	public int visibleController = -1;
67  
68  	/***
69  	 * Are we online?
70  	 */
71  	public boolean online = false;
72  
73  	/***
74  	 * Is GUI zoomed?
75  	 */
76  	public EnumMap<ZoomEnum, Integer> zoom = new EnumMap<ZoomEnum, Integer>(
77  			ZoomEnum.class);
78  
79  	/***
80  	 * Merges zoom levels.
81  	 * @param zoom2 new zoom levels.
82  	 */
83  	public void setZoom(EnumMap<ZoomEnum, Integer> zoom2) {
84  		if (zoom == null) {
85  			zoom = new EnumMap<ZoomEnum, Integer>(ZoomEnum.class);
86  		}
87  		zoom.putAll(zoom2);
88  	}
89  
90  	/***
91  	 * Returns zoom level for given category.
92  	 * 
93  	 * @param category
94  	 *            the category to query.
95  	 * @param level
96  	 *            the level
97  	 */
98  	public void setZoomLevel(final ZoomEnum category, final int level) {
99  		if (zoom == null) {
100 			zoom = new EnumMap<ZoomEnum, Integer>(ZoomEnum.class);
101 		}
102 		category.setLevel(zoom, level);
103 	}
104 
105 	/***
106 	 * The Ampache client configuration.
107 	 */
108 	public AmpacheClientBean ampacheClient;
109 
110 	/***
111 	 * A welcome dialog was shown for this version of Ambient.
112 	 */
113 	public String welcomeVersion;
114 
115 	/***
116 	 * Implemented by components that are aware of the global application state.
117 	 * 
118 	 * @author Martin Vysny
119 	 */
120 	public static interface IAppStateAware {
121 		/***
122 		 * Cherry-picks values from the application state and reinitializes
123 		 * itself.
124 		 * 
125 		 * @param state
126 		 *            the just-loaded state
127 		 */
128 		void reinit(final AppState state);
129 
130 		/***
131 		 * Stores the components state into the global state. Must not alter
132 		 * settings not applicable for this component.
133 		 * 
134 		 * @param state
135 		 *            the object to store to.
136 		 */
137 		void storeState(final AppState state);
138 	}
139 }