Initial Commit from new workspace for android studio

This commit is contained in:
Schoumi 2015-04-16 17:58:19 +02:00
commit 51dcba8f1a
92 changed files with 5352 additions and 0 deletions

7
.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
app/build/*
build/*
.gradle/*
.idea/*
gradle/*
gradlew*
import-summary.txt

21
BloodDonation.iml Normal file
View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

93
app/app.iml Normal file
View file

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="BloodDonation" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":app" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="play-services-6.5.87" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
</component>
</module>

22
app/build.gradle Normal file
View file

@ -0,0 +1,22 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "fr.mobdev.blooddonation"
minSdkVersion 11
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:support-v4:21.0.3'
}

View file

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.mobdev.blooddonation"
android:versionCode="4"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<supports-screens
android:largeScreens="false"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="false" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:name=".App"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library
android:name="com.google.android.maps"
android:required="false" />
<!-- google Maps API -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBtxQBjEu5XZ0Gw_ObqTx-iCaCsLth4Id8" />
<activity
android:name=".activity.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.AboutActivity"
android:parentActivityName=".activity.MainActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".activity.PrefsActivity"
android:parentActivityName=".activity.MainActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".activity.DonationActivity"
android:parentActivityName=".activity.MainActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".activity.DonationInfoActivity"
android:parentActivityName=".activity.MainActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<receiver android:name=".service.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:name=".service.AlarmReceiver" />
<activity
android:name=".activity.NotificationsActivity"
android:label="@string/title_activity_notifications"
android:parentActivityName=".activity.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="fr.mobdev.blooddonation.activity.MainActivity" />
</activity>
</application>
</manifest>

View file

@ -0,0 +1,25 @@
package fr.mobdev.blooddonation;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import android.app.Application;
public class App extends Application {
private Tracker tracker;
public void onCreate(){
super.onCreate();
tracker = null;
getTracker();
}
synchronized Tracker getTracker() {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
if(tracker == null)
tracker = analytics.newTracker(R.xml.analytics);
return tracker;
}
}

View file

@ -0,0 +1,466 @@
package fr.mobdev.blooddonation;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.TimeZone;
import fr.mobdev.blooddonation.enums.Country;
import fr.mobdev.blooddonation.enums.DonationType;
import fr.mobdev.blooddonation.enums.SiteType;
import fr.mobdev.blooddonation.objects.BloodSite;
import fr.mobdev.blooddonation.objects.Donation;
import fr.mobdev.blooddonation.objects.LatiLng;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class Database extends SQLiteOpenHelper {
private static Database instance;
public static Database getInstance(Context context)
{
if(instance == null)
instance = new Database(context, "BloodDonation.db", null, 2);
return instance;
}
private Database(Context context, String name, CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("Create table if not exists user (" +
"id integer primary key autoincrement, name varchar(1024), city varchar(1024), postal varchar(10), gender INTEGER, blood varchar(10), D INTEGER, C INTEGER, E INTEGER, min_c INTEGER, min_e INTEGER, K INTEGER" +
",latitude REAL, longitude REAL);");
db.execSQL("Create table if not exists site (" +
"id integer primary key autoincrement, country INTEGER, address varchar(1024), city varchar(1024), details varchar(4096), mail varchar(1024), phone varchar(1024),"
+"siteName varchar(1024), siteId INTEGER, date INTEGER, latitude REAL, longitude REAL, type INTEGER, schedule INTEGER" +
");");
db.execSQL("Create table if not exists donation (" +
"id integer primary key autoincrement, date INTEGER, siteId INTEGER, city varchar(1024), donation_type INTEGER" +
");");
db.execSQL("Create table if not exists notification (" +
"id integer primary key autoincrement, siteId INTEGER " +
");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//nothing to do right now
if(oldVersion == 1 && newVersion == 2)
{
db.execSQL("Create table if not exists notification (" +
"id integer primary key autoincrement, siteId INTEGER " +
");");
}
}
public void updateUserInfo(String name, boolean isMale, String city, String postal, String blood, boolean D, boolean C, boolean E, boolean c, boolean e, boolean K) {
ContentValues values = new ContentValues();
values.put("name", name);
values.put("city", city);
values.put("postal", postal);
values.put("blood", blood);
values.put("gender", isMale);
values.put("D",D);
values.put("C",C);
values.put("E",E);
values.put("min_c",c);
values.put("min_e",e);
values.put("K",K);
values.put("latitude", 0);
values.put("longitude", 0);
if(!isFirstTime())
{
int userId = -1;
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
cursor.moveToFirst();
userId = cursor.getInt(0);
String whereClause = "id = ?";
String[] whereArgs = new String[1];
whereArgs[0] = String.valueOf(userId);
getWritableDatabase().update("user", values, whereClause, whereArgs);
}
else
{
getWritableDatabase().insert("user", null, values);
}
}
public void updateUserLoc(double latitude, double longitude)
{
ContentValues values = new ContentValues();
values.put("latitude", latitude);
values.put("longitude", longitude);
int userId = -1;
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
cursor.moveToFirst();
userId = cursor.getInt(0);
String whereClause = "id = ?";
String[] whereArgs = new String[1];
whereArgs[0] = String.valueOf(userId);
getWritableDatabase().update("user", values, whereClause, whereArgs);
}
public boolean isFirstTime() {
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
if(cursor.getCount() != 0)
return false;
return true;
}
public void addSitesToDb(List<BloodSite> sites) {
//remove existing site in the list
List<BloodSite> oldList = getBloodSites(-1);
List<BloodSite> removeList = new ArrayList<BloodSite>();
for(BloodSite site : sites)
{
if(oldList.contains(site))
{
removeList.add(site);
}
else
{
ContentValues values = new ContentValues();
values.put("address", site.getAddress());
values.put("city", site.getCityName());
values.put("details", site.getDetails());
values.put("mail", site.getMail());
values.put("phone", site.getPhone());
values.put("siteName", site.getSiteName());
values.put("siteId", site.getSiteId());
values.put("country", site.getCountry().ordinal());
if(site.getDate()!=null)
values.put("date", site.getDate().getTimeInMillis());
else
values.put("date", -1);
values.put("latitude", site.getLoc().latitude);
values.put("longitude", site.getLoc().longitude);
values.put("type", site.getType().ordinal());
getWritableDatabase().insert("site", null, values);
}
}
sites.removeAll(removeList);
}
public List<Donation> getDonations() {
List<Donation> donations = new ArrayList<Donation>();
String orderBy = "date ASC";
Cursor cursor = getReadableDatabase().query("donation", null, null, null, null, null, orderBy);
while(cursor.moveToNext())
{
int col = 0;
int donationId = cursor.getInt(col++);
long date = cursor.getLong(col++);
int siteId = cursor.getInt(col++);
String city_name = cursor.getString(col++);
int donation_type = cursor.getInt(col++);
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
cal.setTimeInMillis(date);
Donation donation = new Donation(DonationType.values()[donation_type], cal, siteId, donationId, city_name);
donations.add(donation);
}
return donations;
}
public void deleteDonation(List<Donation> deletedList) {
for(Donation donation : deletedList)
{
String whereClause = "id = ?";
String[] whereArgs = new String[1];
whereArgs[0] = String.valueOf(donation.getDonationId());
getWritableDatabase().delete("donation", whereClause, whereArgs);
}
}
public void addDonation(Donation donation) {
ContentValues values = new ContentValues();
values.put("siteId", donation.getSiteId());
values.put("date", donation.getDate().getTimeInMillis());
values.put("donation_type", donation.getDonationType().ordinal());
values.put("city", donation.getCityName());
getWritableDatabase().insert("donation", null, values);
}
public HashMap<String, Object> getUserInformation()
{
HashMap<String, Object> maps = new HashMap<String, Object>();
if(!isFirstTime())
{
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
cursor.moveToFirst();
int col = 1;
maps.put("UserName", cursor.getString(col++));//1
maps.put("CityName", cursor.getString(col++));//2
maps.put("Postal", cursor.getString(col++));//3
maps.put("Gender", cursor.getInt(col++));//4
maps.put("BloodGroup", cursor.getString(col++));//5
maps.put("D", cursor.getInt(col++));
maps.put("C", cursor.getInt(col++));
maps.put("E", cursor.getInt(col++));
maps.put("c", cursor.getInt(col++));
maps.put("e", cursor.getInt(col++));
maps.put("K", cursor.getInt(col++));
}
return maps;
}
public List<BloodSite> getBloodSites(long siteId) {
ArrayList<BloodSite> list = new ArrayList<BloodSite>();
String whereClause = null;
String[] whereArgs = null;
if(siteId != -1)
{
whereClause = "id = ?";
whereArgs = new String[1];
whereArgs[0] = String.valueOf(siteId);
}
Cursor cursor = getReadableDatabase().query("site", null, whereClause, whereArgs, null, null, null);
while(cursor.moveToNext())
{
int col = 0;
long dbId = cursor.getLong(col++);
int ordinal =cursor.getInt(col++);
BloodSite site = new BloodSite(Country.values()[ordinal]);
site.setDbId(dbId);
site.setAddress(cursor.getString(col++));
site.setCityName(cursor.getString(col++));
site.setDetails(cursor.getString(col++));
site.setMail(cursor.getString(col++));
site.setPhone(cursor.getString(col++));
site.setSiteName(cursor.getString(col++));
site.setSiteId(cursor.getLong(col++));
long time = cursor.getLong(col++);
if(time == -1)
site.setDate(null);
else
{
Calendar date = Calendar.getInstance();
date.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
date.setTimeInMillis(time);
site.setDate(date);
}
double lat = cursor.getDouble(col++);
double lon = cursor.getDouble(col++);
site.setLoc(new LatiLng(lat, lon));
site.setType(SiteType.values()[cursor.getInt(col++)]);
list.add(site);
}
return list;
}
public BloodSite getPastUnregisteredDonation() {
String whereClause = "schedule = ? and date < ?";
String[] whereArgs = new String[2];
whereArgs[0] = String.valueOf(1);
Calendar dateTime = Calendar.getInstance();
dateTime.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
dateTime.set(Calendar.HOUR_OF_DAY, 0);
dateTime.set(Calendar.MILLISECOND, 0);
dateTime.set(Calendar.MINUTE, 0);
dateTime.set(Calendar.SECOND, 0);
whereArgs[1] = String.valueOf(dateTime.getTimeInMillis());
String orderBy = "date ASC";
BloodSite site = null;
Cursor cursor = getReadableDatabase().query("site", null, whereClause, whereArgs, null, null, orderBy);
if(cursor.moveToFirst())
{
int col = 0;
long dbId = cursor.getLong(col++);
int ordinal = cursor.getInt(col++);
site = new BloodSite(Country.values()[ordinal]);
site.setDbId(dbId);
site.setAddress(cursor.getString(col++));
site.setCityName(cursor.getString(col++));
site.setDetails(cursor.getString(col++));
site.setMail(cursor.getString(col++));
site.setPhone(cursor.getString(col++));
site.setSiteName(cursor.getString(col++));
site.setSiteId(cursor.getLong(col++));
long time = cursor.getLong(col++);
if(time == -1)
site.setDate(null);
else
{
Calendar date = Calendar.getInstance();
date.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
date.setTimeInMillis(time);
site.setDate(date);
}
double lat = cursor.getDouble(col++);
double lon = cursor.getDouble(col++);
site.setLoc(new LatiLng(lat, lon));
site.setType(SiteType.values()[cursor.getInt(col++)]);
}
return site;
}
public List<BloodSite> getNotifications()
{
Cursor cursor = getWritableDatabase().query("notification",null,null,null,null,null,null);
List<Long> oldNotif = new ArrayList<Long>();
List<BloodSite> sites = new ArrayList<BloodSite>();
Calendar cal = Calendar.getInstance();
while(cursor.moveToNext())
{
Long id = cursor.getLong(1);
List<BloodSite> site = getBloodSites(id);
//for each siteId found check if date is passed and if it was remove item from the notifications
if(site.size() == 1 && cal.compareTo(site.get(0).getDate()) > 0)
{
oldNotif.add(id);
}
else
{
if(site.size() > 0)
sites.add(site.get(0));
}
}
removeNotifications(oldNotif);
return sites;
}
public void removeNotifications(List<Long> notificationIds)
{
String args[] = new String[1];
String clause = "id = ?";
for(Long id : notificationIds)
{
args[0] = String.valueOf(id);
getWritableDatabase().delete("notification", clause, args);
}
}
public void sheduleDonation(long siteId, boolean scheduling)
{
String whereClause = "id = ? ";
String[] whereArgs = new String[1];
whereArgs[0] = String.valueOf(siteId);
ContentValues values = new ContentValues();
if(scheduling)
values.put("schedule", 1);
else
values.put("schedule", 0);
getWritableDatabase().update("site", values, whereClause, whereArgs);
}
public List<BloodSite> getBloodSites(LatiLng NE, LatiLng SW) {
List<BloodSite> list = new ArrayList<BloodSite>();
String whereClause = "latitude < ? and latitude > ? and longitude < ? and longitude > ? ";
String[] whereArgs = new String[4];
whereArgs[0] = String.valueOf(NE.latitude);
whereArgs[1] = String.valueOf(SW.latitude);
whereArgs[2] = String.valueOf(NE.longitude);
whereArgs[3] = String.valueOf(SW.longitude);
Calendar dateTime = Calendar.getInstance();
dateTime.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
dateTime.set(Calendar.HOUR_OF_DAY, 0);
dateTime.set(Calendar.MILLISECOND, 0);
dateTime.set(Calendar.MINUTE, 0);
dateTime.set(Calendar.SECOND, 0);
long dateInMillis = dateTime.getTimeInMillis();
Cursor cursor = getReadableDatabase().query("site", null, whereClause, whereArgs, null, null, null);
while(cursor.moveToNext())
{
int col = 0;
long dbId = cursor.getLong(col++);
int ordinal =cursor.getInt(col++);
BloodSite site = new BloodSite(Country.values()[ordinal]);
site.setDbId(dbId);
site.setAddress(cursor.getString(col++));
site.setCityName(cursor.getString(col++));
site.setDetails(cursor.getString(col++));
site.setMail(cursor.getString(col++));
site.setPhone(cursor.getString(col++));
site.setSiteName(cursor.getString(col++));
site.setSiteId(cursor.getLong(col++));
long time = cursor.getLong(col++);
if(time == -1)
site.setDate(null);
else
{
Calendar date = Calendar.getInstance();
date.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
date.setTimeInMillis(time);
site.setDate(date);
}
double lat = cursor.getDouble(col++);
double lon = cursor.getDouble(col++);
site.setLoc(new LatiLng(lat, lon));
site.setType(SiteType.values()[cursor.getInt(col++)]);
if(site.getDate() == null || site.getDate().getTimeInMillis() >= dateInMillis)
list.add(site);
}
return list;
}
public LatiLng getUserLastLocation() {
String[] columns = new String[2];
columns[0] = "latitude";
columns[1] = "longitude";
Cursor cursor = getReadableDatabase().query("user",columns,null,null,null,null,null);
cursor.moveToFirst();
LatiLng loc = new LatiLng(cursor.getDouble(0),cursor.getDouble(1));
return loc;
}
public Calendar getLastDonationDate() {
// TODO
String[] columns = new String[1];
columns[0] = "date";
String orderBy = "date DESC";
Cursor cursor = getReadableDatabase().query("donation", columns, null, null, null, null, orderBy);
if(cursor.moveToFirst())
{
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(cursor.getLong(0));
return cal;
}
return null;
}
public void addNotifications(List<Long> newNotifications) {
for(Long id : newNotifications)
{
ContentValues values = new ContentValues();
values.put("siteId", id);
getWritableDatabase().insert("notification", null, values);
}
}
}

View file

@ -0,0 +1,10 @@
package fr.mobdev.blooddonation;
import java.util.EventListener;
import java.util.List;
import fr.mobdev.blooddonation.objects.BloodSite;
public interface NetworkListener extends EventListener{
void bloodSiteListChanged(List<BloodSite> sites);
}

View file

@ -0,0 +1,314 @@
package fr.mobdev.blooddonation;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.util.Log;
import fr.mobdev.blooddonation.enums.Country;
import fr.mobdev.blooddonation.enums.SiteType;
import fr.mobdev.blooddonation.objects.BloodSite;
import fr.mobdev.blooddonation.objects.LatiLng;
public class NetworkManager {
private NetworkListener listener;
private static NetworkManager instance;
private Context context;
private static int id;
private List<Integer> idList;
private NetworkManager(NetworkListener listener,Context context)
{
this.listener = listener;
this.context = context;
idList = new ArrayList<Integer>();
}
public static NetworkManager getInstance(NetworkListener listener, Context context){
if (instance == null)
instance = new NetworkManager(listener,context);
if(listener != instance.getListener())
instance.setListener(listener);
return instance;
}
private NetworkListener getListener()
{
return listener;
}
private void setListener(NetworkListener listener)
{
this.listener = listener;
}
public void loadFromNet(final Country ctr,final LatiLng nECorner, final LatiLng sWCorner)
{
if(!isConnectedToInternet(context))
return;
new Thread(new Runnable() {
@Override
public void run() {
List<BloodSite> sites = null;
int refreshId = id++;
idList.add(refreshId);
if(ctr == Country.FRANCE)
{
sites = loadFrenchData(nECorner,sWCorner);
}
if(idList.size() != 0 && idList.get(idList.size()-1) == refreshId)
{
listener.bloodSiteListChanged(sites);
}
}
}).start();
}
public List<BloodSite> loadFrenchData(LatiLng nECorner, LatiLng sWCorner)
{
List<BloodSite> siteList = new ArrayList<BloodSite>();
String urlstr = "http://carte.dondusang.com/gmap_regionchanged.php?"
+"nelat="+nECorner.latitude
+"&nelon="+nECorner.longitude
+"&swlat="+sWCorner.latitude
+"&swlon="+sWCorner.longitude
+"&marker=2&fb=facebook&t1=0&t2=10";
Log.v("Url",urlstr);
//getData
URL url = null;
try {
url = new URL(urlstr);
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
URLConnection connect = null;
InputStream stream = null;
try {
if(isConnectedToInternet(context))
{
connect = url.openConnection();
stream = connect.getInputStream();
}
} catch (IOException e1) {
e1.printStackTrace();
}
if(stream != null)
{
InputStreamReader isr = new InputStreamReader(stream);
BufferedReader br = new BufferedReader(isr);
boolean isReading = true;
String data;
String jsonStr = "";
do
{
try {
data = br.readLine();
if(data != null)
jsonStr+=data;
else
isReading = false;
if(idList.get(idList.size()-1) != id-1)
{
return null;
}
} catch (IOException e) {
e.printStackTrace();
isReading = false;
}
}while(isReading);
//parseJSon
try {
JSONObject rootObject = new JSONObject(jsonStr); // Parse the JSON to a JSONObject
int nbResults = rootObject.getInt("num_results");
for(int j=0; j < nbResults; j++) { // Iterate each element in the elements array
JSONObject site = rootObject.getJSONObject(String.valueOf(j)); // Get the element object
long siteId = -1; //obtain with c_id
Calendar date = null;//obtain with c_date
String siteName = null; //obtain with lp_libconv
String address = null;//obtain by parsing text
String details = null;//obtain by parsing text
String cityName = null;//obtain with ville
String phone = null;//obtain with num_tel
String mail = null;
double latitude = site.getDouble("lat"); // Get duration sub object
double longitude = site.getDouble("lon"); // Get distance sub object
String text = site.getString("text");
String ico = site.getString("icon");
if(site.has("c_id"))
siteId = site.getInt("c_id");
if(site.has("lp_libconv"))
siteName = site.getString("lp_libconv");
if(site.has("c_date") && site.getLong("c_date") > 0)
{
date = Calendar.getInstance();
date.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
date.setTimeInMillis(site.getLong("c_date")*1000);
}
if(site.has("ville"))
cityName = site.getString("ville");
if(site.has("num_tel"))
phone = site.getString("num_tel");
if(site.has("adr_mail"))
mail = site.getString("adr_mail");
SiteType type;
if(ico.startsWith("efs"))
type = SiteType.efs;
else if(ico.startsWith("rou"))
type = SiteType.mobile_blood;
else if(ico.startsWith("jau"))
type = SiteType.mobile_plasma;
else
type = SiteType.mobile_blood_plasma;
//parse text for adress and details
text = text.replaceAll("<br>", "\n");
text = text.replaceAll("<br/>","\n");
text = text.replaceAll("<br >", "\n");
text = text.replaceAll("<br />","\n");
text = text.replaceAll("<b>","");
text = text.replaceAll("</b>","");
text = text.replaceAll("&aacute;", "á");
text = text.replaceAll("&agrave;", "à");
text = text.replaceAll("&acirc;", "â");
text = text.replaceAll("&atild;", "ã");
text = text.replaceAll("&auml;", "ä");
text = text.replaceAll("&eacute;", "é");
text = text.replaceAll("&egrave;", "è");
text = text.replaceAll("&ecirc;", "ê");
text = text.replaceAll("&euml;", "ë");
text = text.replaceAll("&igrave;", "ì");
text = text.replaceAll("&iacute;", "í");
text = text.replaceAll("&icirc;", "î");
text = text.replaceAll("&iuml;", "ï");
text = text.replaceAll("&oacute;", "ó");
text = text.replaceAll("&ograve;", "ò");
text = text.replaceAll("&ocirc;", "ô");
text = text.replaceAll("&otild;", "õ");
text = text.replaceAll("&ouml;", "ö");
text = text.replaceAll("&ugrave;", "ù");
text = text.replaceAll("&uacute;", "ú");
text = text.replaceAll("&ucirc;", "û");
text = text.replaceAll("&uuml;", "ü");
text = text.replaceAll("&quot;", "\"");
text = text.replaceAll("&#039;", "'");
text = text.replaceAll("\r", "\n");
text = text.replaceAll("\n ", "\n");
String balise = "<div id=\"gbadresse\">";
if(site.has("lp_ad3"))
{
text = text.substring(text.indexOf(">")+1);
details = text.substring(0,text.indexOf("</div>"));
text = text.substring(text.indexOf("</div>"));
text = text.substring(text.indexOf(balise)+balise.length());
address = text.substring(0, text.indexOf("</div>"));
}
else if(site.has("lp_libconv"))
{
text = text.replaceAll("<span style=\"color:#C62B2B\">", "");
text = text.replaceAll("</span>", "");
String div = "<div>";
text = text.substring(text.indexOf(div)+div.length());
text = text.substring(text.indexOf(div)+div.length());
details = text.substring(0,text.indexOf("</div>"));
text = text.substring(text.indexOf(balise)+balise.length());
address = text.substring(0, text.indexOf("</div>"));
}
BloodSite newSite = new BloodSite(Country.FRANCE);
newSite.setSiteId(siteId);
newSite.setDate(date);
newSite.setSiteName(siteName);
newSite.setLoc(new LatiLng(latitude,longitude));
newSite.setType(type);
newSite.setCityName(cityName);
newSite.setPhone(phone);
newSite.setMail(mail);
newSite.setAddress(address);
newSite.setDetails(details);
if(siteList.contains(newSite))
{
String begin = newSite.getDetails();
begin = begin.substring(0,begin.indexOf("à"));
begin = begin.substring(begin.indexOf("h")-2, begin.indexOf("h")+3);
int newBeginHour = Integer.valueOf(begin.substring(0,2)) * 1000 * 60 *60 + Integer.valueOf(begin.substring(3,5))*1000*60;
BloodSite oldSite = siteList.get(siteList.indexOf(newSite));
begin = oldSite.getDetails();
begin = begin.substring(0,begin.indexOf("à"));
begin = begin.substring(begin.indexOf("h")-2, begin.indexOf("h")+3);
int beginHour = Integer.valueOf(begin.substring(0,2)) * 1000 * 60 *60 + Integer.valueOf(begin.substring(3,5))*1000*60;
if(beginHour > newBeginHour)
{
String newDetails = oldSite.getDetails();
newDetails = newDetails.substring(newDetails.lastIndexOf("de"),newDetails.lastIndexOf("h")+3);
newSite.setDetails(newSite.getDetails()+newDetails);
siteList.remove(oldSite);
siteList.add(newSite);
}
else
{
String newDetails = newSite.getDetails();
newDetails = newDetails.substring(newDetails.lastIndexOf("de"),newDetails.lastIndexOf("h")+3);
oldSite.setDetails(oldSite.getDetails()+newDetails);
}
}
else
{
siteList.add(newSite);
}
}
} catch (JSONException e) {
// JSON Parsing error
e.printStackTrace();
}
}
//build Blood Site and construct list
return siteList;
}
private boolean isConnectedToInternet(Context context)
{
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo != null)
{
State networkState = networkInfo.getState();
if (networkState.equals(State.CONNECTED))
{
return true;
}
}
return false;
}
}

View file

@ -0,0 +1,7 @@
package fr.mobdev.blooddonation;
import java.util.EventListener;
public interface NewDonationListener extends EventListener {
public void needUpdate();
}

View file

@ -0,0 +1,70 @@
package fr.mobdev.blooddonation;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import fr.mobdev.blooddonation.activity.MainActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
public class PrefFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
Preference pref = findPreference("info_change");
pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent newIntent = new Intent(getActivity(), MainActivity.class);
newIntent.putExtra("modify", true);
startActivity(newIntent);
return true;
}
});
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key) {
if(key.equals("deactivate_localisation"))
{
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
//update user location to the location in his profile
HashMap<String,Object> userData = Database.getInstance(getActivity()).getUserInformation();
Geocoder coder = new Geocoder(getActivity());
String city = (String) userData.get("CityName");
String postal = (String) userData.get("Postal");
try {
List<Address> addr = coder.getFromLocationName(city+" "+postal, 1);
if(!addr.isEmpty())
{
Database.getInstance(getActivity()).updateUserLoc(addr.get(0).getLatitude(), addr.get(0).getLongitude());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
}
}

View file

@ -0,0 +1,8 @@
package fr.mobdev.blooddonation;
import java.util.EventListener;
public interface RegisterListener extends EventListener {
void processNewRegistration();
}

View file

@ -0,0 +1,9 @@
package fr.mobdev.blooddonation;
import java.util.EventListener;
import android.view.View;
public interface SelectionModeListener extends EventListener {
void selectionModeChange(View v);
}

View file

@ -0,0 +1,30 @@
package fr.mobdev.blooddonation.activity;
import com.google.android.gms.analytics.GoogleAnalytics;
import fr.mobdev.blooddonation.R;
import android.app.Activity;
import android.os.Bundle;
public class AboutActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
getActionBar().setTitle(R.string.about);
}
@Override
public void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
public void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
}

View file

@ -0,0 +1,260 @@
package fr.mobdev.blooddonation.activity;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import com.google.android.gms.analytics.GoogleAnalytics;
import fr.mobdev.blooddonation.Database;
import fr.mobdev.blooddonation.NewDonationListener;
import fr.mobdev.blooddonation.R;
import fr.mobdev.blooddonation.SelectionModeListener;
import fr.mobdev.blooddonation.custom_object.DrawerAdapter;
import fr.mobdev.blooddonation.custom_object.DrawerItem;
import fr.mobdev.blooddonation.dialog.AddDonationDialog;
import fr.mobdev.blooddonation.enums.DrawerItemType;
import fr.mobdev.blooddonation.objects.Donation;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemLongClickListener;
public class DonationActivity extends FragmentActivity {
ListView donation_list;
List<Donation> donations;
SelectionModeListener listener;
boolean isOnSelection;
List<DrawerItem> items;
MenuItem del_item;
Context context;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.donation);
donation_list = (ListView) findViewById(R.id.donation_list);
items = new ArrayList<DrawerItem>();
isOnSelection = false;
context = this;
listener = new SelectionModeListener() {
@Override
public void selectionModeChange(View v) {
isOnSelection = !isOnSelection;
if(isOnSelection)
{
for(DrawerItem item:items)
{
item.setType(DrawerItemType.STATE_CHECK);
}
selectView(v);
del_item.setVisible(true);
DrawerAdapter adapter = new DrawerAdapter(context,R.layout.drawer_item, 0, items);
donation_list.setAdapter(adapter);
}
else
{
for(DrawerItem item:items)
{
item.setType(DrawerItemType.STATE_NORMAL);
item.setSelected(false);
}
del_item.setVisible(false);
DrawerAdapter adapter = new DrawerAdapter(context,R.layout.drawer_item, 0, items);
donation_list.setAdapter(adapter);
}
}
};
donation_list.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View v, int pos, long id) {
if(!isOnSelection)
{
listener.selectionModeChange(v);
}
else
{
selectView(v);
}
return true;
}
});
donation_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int arg2, long id) {
selectView(v);
}
});
updateDonationList();
getActionBar().setTitle(R.string.donations);
}
@Override
public void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
public void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
private void selectView(View v)
{
if(isOnSelection)
{
TextView view = (TextView) v.findViewById(R.id.pos);
long donationId = Integer.valueOf((String) view.getText());
for(DrawerItem item:items)
{
item.setType(DrawerItemType.STATE_CHECK);
if(item.getPos() == donationId)
{
item.setSelected(!item.isSelected());
}
}
DrawerAdapter adapter = new DrawerAdapter(context,R.layout.drawer_item, 0, items);