3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 package de.dhbwloe.campusapp.fragments;
17 import android.graphics.Bitmap;
18 import android.graphics.BitmapFactory;
19 import android.graphics.Point;
20 import android.os.Bundle;
21 import android.os.Handler;
22 import android.support.v4.app.Fragment;
23 import android.view.Display;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.ViewGroup;
27 import android.widget.ImageView;
28 import android.widget.ProgressBar;
29 import android.widget.TextView;
31 import java.util.Date;
33 import de.dhbwloe.campusapp.CampusApp;
34 import de.dhbwloe.campusapp.CampusAppContext;
35 import de.dhbwloe.campusapp.CampusAppFragment;
36 import de.dhbwloe.campusapp.R;
37 import de.dhbwloe.campusapp.mensaplan.MensaplanManager;
38 import de.dhbwloe.campusapp.mensaplan.MensaplanManagerInterface;
39 import de.dhbwloe.campusapp.news.NewsManager;
40 import de.dhbwloe.campusapp.news.NewsManagerInterface;
41 import de.dhbwloe.campusapp.search.SearchIndices;
42 import de.dhbwloe.campusapp.vorlesungen.CalendarManager;
43 import de.dhbwloe.campusapp.vorlesungen.CalendarManagerInterface;
44 import de.dhbwloe.campusapp.vorlesungen.CourseEvent;
45 import de.dhbwloe.campusapp.vorlesungen.CourseGroup;
48 * A simple {@link Fragment} subclass.
50 public class SplashScreen extends CampusAppFragment {
51 private ProgressBar splashProgress;
52 private int progressCounter;
53 private Handler timerHandler = new Handler();
54 private Runnable timerRunnable;
57 public void onCreate(Bundle savedInstanceState) {
58 super.onCreate(savedInstanceState);
64 public void onSaveInstanceState(Bundle savedInstanceState) {
65 timerHandler.removeCallbacksAndMessages(null);
66 super.onSaveInstanceState(savedInstanceState);
70 public View onCreateView(LayoutInflater inflater, ViewGroup container,
71 Bundle savedInstanceState) {
72 View view = inflater.inflate(R.layout.fragment_splashscreen, container, false);
74 TextView versionView = (TextView) view.findViewById(R.id.version);
75 versionView.setText(CampusAppContext.APPVERSION);
77 splashProgress = (ProgressBar)view.findViewById(R.id.splashProgress);
78 splashProgress.setMax(20);
79 splashProgress.setProgress(0);
82 AppContext.setTitle("DHBW Lörrach");
84 ImageView splashImage = (ImageView)view.findViewById(R.id.splashImage);
85 BitmapFactory.Options dimensions = new BitmapFactory.Options();
86 Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dhbw_campus_hd, dimensions);
87 int height = dimensions.outHeight;
88 int width = dimensions.outWidth;
89 Display display = AppContext.getMainActivity().getWindowManager().getDefaultDisplay();
90 Point size = new Point();
91 display.getSize(size);
92 float scaleX = (float)size.x / (float)width;
93 float scaleY = (float)size.y / (float)height;
94 float scale = Math.max(scaleX, scaleY);
95 int newWidth = (int)(width*scale);
96 int newHeight = (int)(height*scale);
97 Bitmap newBitmap = Bitmap.createScaledBitmap(mBitmap, newWidth, newHeight, true);
98 splashImage.setImageBitmap(newBitmap);
100 timerRunnable = new Runnable() {
104 splashProgress.setProgress(progressCounter);
105 long now = (new Date()).getTime()/1000;
106 switch(progressCounter) {
108 AppContext.getDatabaseManager().initializeDatabase();
111 AppContext.addDefaultSearchIndexes();
114 String startCounter = AppContext.getDatabaseManager().getRuntimeCache("AppStartCounter");
115 if(startCounter == null || Integer.parseInt(startCounter) == 0) {
116 AppContext.getNavigationManager().navigatePage("FirstRun", null, false);
119 AppContext.getDatabaseManager().setRuntimeCache("AppStartCounter", Integer.toString(Integer.parseInt(startCounter) + 1));
122 String lastVLMFullSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastVLMFullSync");
123 String lastVLMPartialSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastVLMPartialSync");
124 long lastVLMFullSync, lastVLMPartialSync;
125 if(lastVLMFullSyncStr != null)
126 lastVLMFullSync = Long.parseLong(lastVLMFullSyncStr);
129 if(lastVLMPartialSyncStr != null)
130 lastVLMPartialSync = Long.parseLong(lastVLMPartialSyncStr);
132 lastVLMPartialSync = 0;
134 String kursTag = AppContext.getDatabaseManager().getRuntimeCache("CourseName");
135 if(kursTag == null || kursTag.isEmpty())
137 CalendarManager vpm = new CalendarManager(AppContext, kursTag);
139 if(lastVLMFullSync == 0 || now - lastVLMFullSync > (86400 * 14)) { // full sync every 14 days
140 vpm.performFullSynchronisation(new CalendarManagerInterface() {
142 public void onCalendarUpdateDone() {
143 long now = (new Date()).getTime() / 1000;
144 AppContext.getDatabaseManager().setRuntimeCache("LastVLMFullSync", Long.toString(now));
145 AppContext.getDatabaseManager().setRuntimeCache("LastVLMPartialSync", Long.toString(now));
146 timerHandler.postDelayed(timerRunnable, 100);
150 public void onCalendarUpdateFail(String errorMessage) {
151 timerHandler.postDelayed(timerRunnable, 100);
154 public SearchIndices onGenerateCalendarSearchIndices(CourseEvent event) {
155 CourseGroup group = event.getCourseGroup();
156 SearchIndices indices = new SearchIndices("Vorlesungsplan#Group"+group.getGroupId(), false);
157 indices.setUpdateTime(event.getEventFrom());
158 indices.setTarget("#Vorlesungsplan#groupid=" + group.getGroupId());
159 indices.setTitle("Vorlesungsplan " + event.getCourseName());
160 indices.setDescription("Vorlesung " + event.getEventTitle());
161 indices.addKeyWord(event.getGroupTitle());
162 indices.addKeyWord(event.getEventLocation());
167 else if(lastVLMPartialSync == 0 || now - lastVLMPartialSync > (86400)) { // partial sync every day
168 vpm.performFastSynchronisation(new CalendarManagerInterface() {
170 public void onCalendarUpdateDone() {
171 long now = (new Date()).getTime()/1000;
172 AppContext.getDatabaseManager().setRuntimeCache("LastVLMPartialSync", Long.toString(now));
173 timerHandler.postDelayed(timerRunnable, 100);
176 public void onCalendarUpdateFail(String errorMessage) {
177 timerHandler.postDelayed(timerRunnable, 100);
180 public SearchIndices onGenerateCalendarSearchIndices(CourseEvent event) {
181 CourseGroup group = event.getCourseGroup();
182 SearchIndices indices = new SearchIndices("Vorlesungsplan#Group"+group.getGroupId(), false);
183 indices.setUpdateTime(event.getEventFrom());
184 indices.setTarget("#Vorlesungsplan#groupid=" + group.getGroupId());
185 indices.setTitle(AppContext.getResString(R.string.search_vorlesungsplan_group_title, event.getCourseName()));
186 indices.setDescription(event.getEventTitle());
187 indices.addKeyWord(event.getGroupTitle());
188 indices.addKeyWord(event.getEventLocation());
197 String lastMPMSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastMPSync");
199 if(lastMPMSyncStr != null)
200 lastMPMSync = Long.parseLong(lastMPMSyncStr);
204 MensaplanManager mpm = new MensaplanManager(AppContext);
206 if(lastMPMSync == 0 || now - lastMPMSync > (86400 * 2)) { //sync every 2 days
207 mpm.performSynchronisation(new MensaplanManagerInterface() {
209 public void onMensaplanUpdateDone() {
210 long now = (new Date()).getTime() / 1000;
211 AppContext.getDatabaseManager().setRuntimeCache("LastMPSync", Long.toString(now));
212 timerHandler.postDelayed(timerRunnable, 100);
216 public void onMensaplanUpdateFail(String errorMessage) {
217 timerHandler.postDelayed(timerRunnable, 100);
226 final String syncSource = (progressCounter == 6 ? "DHBW" : "STUV");
227 String lastNewsSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastNewsSync_"+syncSource);
229 if(lastNewsSyncStr != null)
230 lastNewsSync = Long.parseLong(lastNewsSyncStr);
234 NewsManager nm = new NewsManager(AppContext, syncSource);
236 if(lastNewsSync == 0 || now - lastNewsSync > (86400 * 1)) { //sync every day
237 nm.performSynchronisation(new NewsManagerInterface() {
239 public void onNewsUpdateDone() {
240 long now = (new Date()).getTime() / 1000;
241 AppContext.getDatabaseManager().setRuntimeCache("LastNewsSync_"+syncSource, Long.toString(now));
242 timerHandler.postDelayed(timerRunnable, 100);
246 public void onNewsUpdateFail(String errorMessage) {
247 timerHandler.postDelayed(timerRunnable, 100);
255 String lastStuvSyncStr = AppContext.getDatabaseManager().getRuntimeCache("LastStuvSync");
257 if(lastStuvSyncStr != null)
258 lastStuvSync = Long.parseLong(lastStuvSyncStr);
262 final String calendarName = "STUV";
263 CalendarManager stuvsyncmgr = new CalendarManager(AppContext, calendarName);
265 if(lastStuvSync == 0 || now - lastStuvSync > (86400 * 3)) { // full sync every 3 days
266 stuvsyncmgr.performFullSynchronisation(new CalendarManagerInterface() {
268 public void onCalendarUpdateDone() {
269 long now = (new Date()).getTime() / 1000;
270 AppContext.getDatabaseManager().setRuntimeCache("LastStuvSync", Long.toString(now));
271 timerHandler.postDelayed(timerRunnable, 100);
275 public void onCalendarUpdateFail(String errorMessage) {
276 timerHandler.postDelayed(timerRunnable, 100);
280 public SearchIndices onGenerateCalendarSearchIndices(CourseEvent event) {
281 CourseGroup group = event.getCourseGroup();
282 SearchIndices indices = new SearchIndices("Vorlesungsplan#Group"+group.getGroupId(), false);
283 indices.setUpdateTime(event.getEventFrom());
284 indices.setTarget("#News#showevent=" + group.getGroupId() + "&course=" + calendarName);
285 indices.setTitle(calendarName+" Event: " + event.getCourseName());
286 indices.setDescription(event.getEventTitle());
287 indices.addKeyWord(event.getGroupTitle());
288 indices.addKeyWord(event.getEventLocation());
298 // some more tasks to do here?
301 ((CampusApp)AppContext.getMainActivity()).loadMainUi();
302 AppContext.getNavigationManager().navigatePage("Dashboard", null, false);
305 timerHandler.postDelayed(timerRunnable, 100);
313 public void onResume() {
315 timerHandler.postDelayed(timerRunnable, 500);