/*******************************************************************************
* Copyright (c) 2011 Michel DAVID mimah35-at-gmail.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package fr.gotorennes;
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.os.Build;
import android.util.Log;
import fr.gotorennes.AbstractMapActivity.Itineraire;
import fr.gotorennes.persistence.BusDao;
import fr.gotorennes.remote.BikeStationService;
import fr.gotorennes.remote.BusStationService;
import fr.gotorennes.remote.EquipementService;
import fr.gotorennes.remote.EquipementStatusService;
import fr.gotorennes.remote.LineAlertService;
import fr.gotorennes.remote.MetroStationService;
import fr.gotorennes.remote.PointDeVenteService;
import fr.gotorennes.remote.RelayParkService;
import fr.gotorennes.util.UpdateUtils;
public class GoToRennes {
private static GoToRennes instance;
private BusDao busDao;
private BusStationService busStationService;
private RelayParkService relayParkService;
private BikeStationService bikeStationService;
private MetroStationService metroStationService;
private LineAlertService lineAlertService;
private PointDeVenteService pointDeVenteService;
private EquipementService equipementService;
private EquipementStatusService equipementStatusService;
private GoogleAnalyticsTracker tracker;
private Resources resources;
private GoToRennes(Context context, ProgressDialog progress) {
busDao = BusDao.getInstance(context, progress);
busStationService = BusStationService.getInstance(context);
relayParkService = RelayParkService.getInstance(context);
bikeStationService = BikeStationService.getInstance(context);
metroStationService = MetroStationService.getInstance(context);
lineAlertService = LineAlertService.getInstance(context);
pointDeVenteService = PointDeVenteService.getInstance(context);
equipementService = EquipementService.getInstance(context);
equipementStatusService = EquipementStatusService.getInstance(context);
try {
tracker = GoogleAnalyticsTracker.getInstance();
tracker.start("UA-8486636-2", 20, context);
initTrackerWithUserData(context);
}
catch (Exception ex) {
Log.e("GoToRennes", "Error init ads " + ex.getMessage());
}
resources = context.getResources();
UpdateUtils.checkUpdate(context);
}
private void initTrackerWithUserData(Context context) {
// only 5 Custom Variables allowed!
// 1 - Application version
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
String appVersion = packageInfo.versionName;
tracker.setCustomVar(1, "app_version", appVersion, 1);
} catch (NameNotFoundException e) {
}
// 2 - Android version
String androidVersion = Build.VERSION.RELEASE;
tracker.setCustomVar(1, "os_rel", androidVersion, 1);
// 3 - Android SDK
String sdk = Build.VERSION.SDK;
tracker.setCustomVar(1, "sdk_version", sdk, 1);
// 4 - Device
String device = Build.PRODUCT;
tracker.setCustomVar(1, "device", device, 1);
}
public BusDao getBusDao() {
return busDao;
}
public BusStationService getBusStationService() {
return busStationService;
}
public RelayParkService getRelayParkService() {
return relayParkService;
}
public BikeStationService getBikeStationService() {
return bikeStationService;
}
public MetroStationService getMetroStationService() {
return metroStationService;
}
public LineAlertService getLineAlertService() {
return lineAlertService;
}
public PointDeVenteService getPointDeVenteService() {
return pointDeVenteService;
}
public EquipementService getEquipementService() {
return equipementService;
}
public EquipementStatusService getEquipementStatusService() {
return equipementStatusService;
}
public void track(String name) {
tracker.trackPageView(name);
}
public void trackEvent(String source, String name) {
tracker.trackEvent("Clics", source, name, 1);
}
public void stop() {
tracker.stop();
}
public String getString(int id) {
return resources.getString(id);
}
public static synchronized GoToRennes getInstance(Context context, ProgressDialog progress) {
if (instance == null) {
instance = new GoToRennes(context, progress);
}
return instance;
}
public Itineraire itineraireCourant;
}