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 sk.baka.ambient.AmbientApplication;
22 import sk.baka.ambient.R;
23 import sk.baka.ambient.collection.Statistics;
24 import sk.baka.ambient.collection.TrackMetadataBean;
25 import sk.baka.ambient.collection.TrackOriginEnum;
26 import sk.baka.ambient.collection.local.MediaStoreCollection;
27 import sk.baka.ambient.commons.MiscUtils;
28 import sk.baka.ambient.library.Library;
29 import android.app.Activity;
30 import android.os.Bundle;
31 import android.widget.TextView;
32
33 /***
34 * Shows the statistics dialog.
35 *
36 * @author Martin Vysny
37 */
38 public final class StatisticsActivity extends Activity {
39 @Override
40 protected void onCreate(Bundle icicle) {
41 super.onCreate(icicle);
42 setContentView(R.layout.statisticsactivity);
43 final TextView statisticsText = (TextView) findViewById(R.id.statisticsText);
44 try {
45 statisticsText.setText(getText());
46 } catch (final Exception e) {
47 final AmbientApplication app = AmbientApplication.getInstance();
48 app.error(StatisticsActivity.class, true,
49 getString(R.string.error), e);
50 }
51 }
52
53 private String getText() {
54 final StringBuilder b = new StringBuilder();
55
56 final Runtime r = Runtime.getRuntime();
57 b.append(MiscUtils.format(R.string.statisticsVM, MiscUtils
58 .formatByteLength(r.maxMemory()), MiscUtils.formatByteLength(r
59 .freeMemory()), MiscUtils.formatByteLength(r.totalMemory())));
60 b.append("\n\n");
61
62 final Library l = AmbientApplication.getInstance().getLibrary();
63 final Statistics local = new MediaStoreCollection(getContentResolver())
64 .getStatistics();
65 final Statistics magnatune = l.getStatistics(TrackOriginEnum.Magnatune);
66 final Statistics total = new Statistics();
67 total.add(local);
68 total.add(magnatune);
69 b.append(MiscUtils.format(R.string.statisticsTracks1, total.tracks,
70 local.tracks, magnatune.tracks, getLen(total.length),
71 getLen(local.length), getLen(magnatune.length), getLen(total
72 .getAverageLength()), getLen(local.getAverageLength()),
73 getLen(magnatune.getAverageLength()), MiscUtils
74 .formatByteLength(local.fileSize)));
75 b.append('\n');
76 final int genres = l.getGenreCount();
77 b.append(MiscUtils.format(R.string.statisticsTracks2, total.albums,
78 local.albums, magnatune.albums, total.artists, local.artists,
79 magnatune.artists, genres));
80 return b.toString();
81 }
82
83 private static String getLen(final int len) {
84 final StringBuilder result = new StringBuilder(7);
85 TrackMetadataBean.appendDisplayableLength(len, result, false);
86 return result.toString();
87 }
88 }