Clover Coverage Report - Subsonic-Android Coverage Report
Coverage timestamp: ven dic 19 2014 17:57:13 EST
../../../../../img/srcFileCovDistChart9.png 32% of files have more coverage
123   268   37   8,79
28   203   0,3   14
14     2,64  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  MainActivity       Line # 44 123 37 86,1% 0.8606061
 
No Tests
 
1    /*
2    This file is part of Subsonic.
3   
4    Subsonic is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8   
9    Subsonic is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12    GNU General Public License for more details.
13   
14    You should have received a copy of the GNU General Public License
15    along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
16   
17    Copyright 2009 (C) Sindre Mehus
18    */
19   
20    package net.sourceforge.subsonic.androidapp.activity;
21   
22    import java.util.Arrays;
23   
24    import net.sourceforge.subsonic.androidapp.R;
25    import net.sourceforge.subsonic.androidapp.service.DownloadService;
26    import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
27    import net.sourceforge.subsonic.androidapp.util.Constants;
28    import net.sourceforge.subsonic.androidapp.util.MergeAdapter;
29    import net.sourceforge.subsonic.androidapp.util.Util;
30    import net.sourceforge.subsonic.androidapp.util.FileUtil;
31    import android.content.Intent;
32    import android.content.SharedPreferences;
33    import android.os.Bundle;
34    import android.preference.PreferenceManager;
35    import android.view.ContextMenu;
36    import android.view.LayoutInflater;
37    import android.view.MenuItem;
38    import android.view.View;
39    import android.widget.AdapterView;
40    import android.widget.ImageButton;
41    import android.widget.ListView;
42    import android.widget.TextView;
43   
 
44    public class MainActivity extends SubsonicTabActivity {
45   
46    private static final int MENU_GROUP_SERVER = 10;
47    private static final int MENU_ITEM_SERVER_1 = 101;
48    private static final int MENU_ITEM_SERVER_2 = 102;
49    private static final int MENU_ITEM_SERVER_3 = 103;
50    private static final int MENU_ITEM_OFFLINE = 104;
51   
52    private String theme;
53   
54    private static boolean infoDialogDisplayed;
55   
56    /**
57    * Called when the activity is first created.
58    */
 
59  10 toggle @Override
60    public void onCreate(Bundle savedInstanceState) {
61  10 super.onCreate(savedInstanceState);
62  10 if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) {
63  0 exit();
64    }
65  10 setContentView(R.layout.main);
66   
67  10 loadSettings();
68   
69  10 View buttons = LayoutInflater.from(this).inflate(R.layout.main_buttons, null);
70   
71  10 final View serverButton = buttons.findViewById(R.id.main_select_server);
72  10 final TextView serverTextView = (TextView) serverButton.findViewById(R.id.main_select_server_2);
73   
74  10 final View albumsTitle = buttons.findViewById(R.id.main_albums);
75  10 final View albumsNewestButton = buttons.findViewById(R.id.main_albums_newest);
76  10 final View albumsRandomButton = buttons.findViewById(R.id.main_albums_random);
77  10 final View albumsHighestButton = buttons.findViewById(R.id.main_albums_highest);
78  10 final View albumsRecentButton = buttons.findViewById(R.id.main_albums_recent);
79  10 final View albumsFrequentButton = buttons.findViewById(R.id.main_albums_frequent);
80   
81  10 final View dummyView = findViewById(R.id.main_dummy);
82   
83  10 int instance = Util.getActiveServer(this);
84  10 String name = Util.getServerName(this, instance);
85  10 serverTextView.setText(name);
86   
87  10 ListView list = (ListView) findViewById(R.id.main_list);
88   
89  10 MergeAdapter adapter = new MergeAdapter();
90  10 adapter.addViews(Arrays.asList(serverButton), true);
91  10 if (!Util.isOffline(this)) {
92  8 adapter.addView(albumsTitle, false);
93  8 adapter.addViews(Arrays.asList(albumsNewestButton, albumsRandomButton, albumsHighestButton, albumsRecentButton, albumsFrequentButton), true);
94    }
95  10 list.setAdapter(adapter);
96  10 registerForContextMenu(dummyView);
97   
98  10 list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
 
99  7 toggle @Override
100    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
101  7 if (view == serverButton) {
102  4 dummyView.showContextMenu();
103  3 } else if (view == albumsNewestButton) {
104  2 showAlbumList("newest");
105  1 } else if (view == albumsRandomButton) {
106  0 showAlbumList("random");
107  1 } else if (view == albumsHighestButton) {
108  0 showAlbumList("highest");
109  1 } else if (view == albumsRecentButton) {
110  1 showAlbumList("recent");
111  0 } else if (view == albumsFrequentButton) {
112  0 showAlbumList("frequent");
113    }
114    }
115    });
116   
117    // Title: Subsonic
118  10 setTitle(R.string.common_appname);
119   
120    // Button 1: shuffle
121  10 ImageButton actionShuffleButton = (ImageButton)findViewById(R.id.action_button_1);
122  10 actionShuffleButton.setImageResource(R.drawable.ic_menu_shuffle);
123  10 actionShuffleButton.setOnClickListener(new View.OnClickListener() {
 
124  2 toggle @Override
125    public void onClick(View view) {
126  2 Intent intent = new Intent(MainActivity.this, DownloadActivity.class);
127  2 intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true);
128  2 Util.startActivityWithoutTransition(MainActivity.this, intent);
129    }
130    });
131   
132    // Button 2: search
133  10 ImageButton actionSearchButton = (ImageButton)findViewById(R.id.action_button_2);
134  10 actionSearchButton.setImageResource(R.drawable.ic_menu_search);
135  10 actionSearchButton.setOnClickListener(new View.OnClickListener() {
 
136  0 toggle @Override
137    public void onClick(View view) {
138  0 Intent intent = new Intent(MainActivity.this, SearchActivity.class);
139  0 intent.putExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, true);
140  0 Util.startActivityWithoutTransition(MainActivity.this, intent);
141    }
142    });
143   
144    // Button 3: menu
145  10 ImageButton actionMenuButton = (ImageButton)findViewById(R.id.action_button_3);
146  10 actionMenuButton.setImageResource(R.drawable.ic_menu_moreoverflow);
147  10 actionMenuButton.setOnClickListener(new View.OnClickListener() {
 
148  4 toggle @Override
149    public void onClick(View view) {
150  4 openOptionsMenu();
151    }
152    });
153   
154    // Remember the current theme.
155  10 theme = Util.getTheme(this);
156   
157  10 showInfoDialog();
158    }
159   
 
160  10 toggle private void loadSettings() {
161  10 PreferenceManager.setDefaultValues(this, R.xml.settings, false);
162  10 SharedPreferences prefs = Util.getPreferences(this);
163  10 if (!prefs.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION)) {
164  1 SharedPreferences.Editor editor = prefs.edit();
165  1 editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory().getPath());
166  1 editor.commit();
167    }
168    }
169   
 
170  14 toggle @Override
171    protected void onResume() {
172  14 super.onResume();
173   
174    // Restart activity if theme has changed.
175  14 if (theme != null && !theme.equals(Util.getTheme(this))) {
176  1 restart();
177    }
178    }
179   
 
180  4 toggle @Override
181    public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
182  4 super.onCreateContextMenu(menu, view, menuInfo);
183   
184  4 MenuItem menuItem1 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_1, MENU_ITEM_SERVER_1, Util.getServerName(this, 1));
185  4 MenuItem menuItem2 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_2, MENU_ITEM_SERVER_2, Util.getServerName(this, 2));
186  4 MenuItem menuItem3 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_3, MENU_ITEM_SERVER_3, Util.getServerName(this, 3));
187  4 MenuItem menuItem4 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_OFFLINE, MENU_ITEM_OFFLINE, Util.getServerName(this, 0));
188  4 menu.setGroupCheckable(MENU_GROUP_SERVER, true, true);
189  4 menu.setHeaderTitle(R.string.main_select_server);
190   
191  4 switch (Util.getActiveServer(this)) {
192  1 case 0:
193  1 menuItem4.setChecked(true);
194  1 break;
195  1 case 1:
196  1 menuItem1.setChecked(true);
197  1 break;
198  1 case 2:
199  1 menuItem2.setChecked(true);
200  1 break;
201  1 case 3:
202  1 menuItem3.setChecked(true);
203  1 break;
204    }
205    }
206   
 
207  4 toggle @Override
208    public boolean onContextItemSelected(MenuItem menuItem) {
209  4 switch (menuItem.getItemId()) {
210  1 case MENU_ITEM_OFFLINE:
211  1 setActiveServer(0);
212  1 break;
213  1 case MENU_ITEM_SERVER_1:
214  1 setActiveServer(1);
215  1 break;
216  1 case MENU_ITEM_SERVER_2:
217  1 setActiveServer(2);
218  1 break;
219  1 case MENU_ITEM_SERVER_3:
220  1 setActiveServer(3);
221  1 break;
222  0 default:
223  0 return super.onContextItemSelected(menuItem);
224    }
225   
226    // Restart activity
227  4 restart();
228  4 return true;
229    }
230   
 
231  4 toggle private void setActiveServer(int instance) {
232  4 if (Util.getActiveServer(this) != instance) {
233  4 DownloadService service = getDownloadService();
234  4 if (service != null) {
235  4 service.clearIncomplete();
236    }
237  4 Util.setActiveServer(this, instance);
238    }
239    }
240   
 
241  5 toggle private void restart() {
242  5 Intent intent = new Intent(this, MainActivity.class);
243  5 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
244  5 Util.startActivityWithoutTransition(this, intent);
245    }
246   
 
247  0 toggle private void exit() {
248  0 stopService(new Intent(this, DownloadServiceImpl.class));
249  0 finish();
250    }
251   
 
252  10 toggle private void showInfoDialog() {
253  10 if (!infoDialogDisplayed) {
254  1 infoDialogDisplayed = true;
255  1 if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) {
256  1 Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text);
257    }
258    }
259    }
260   
 
261  3 toggle private void showAlbumList(String type) {
262  3 Intent intent = new Intent(this, SelectAlbumActivity.class);
263  3 intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type);
264  3 intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 20);
265  3 intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
266  3 Util.startActivityWithoutTransition(this, intent);
267    }
268    }