Browse Source

Initial Commit from new workspace for android studio

tags/release-v3.0
Schoumi 5 years ago
commit
51dcba8f1a
92 changed files with 5352 additions and 0 deletions
  1. +7
    -0
      .gitignore
  2. +21
    -0
      BloodDonation.iml
  3. +93
    -0
      app/app.iml
  4. +22
    -0
      app/build.gradle
  5. +100
    -0
      app/src/main/AndroidManifest.xml
  6. +25
    -0
      app/src/main/java/fr/mobdev/blooddonation/App.java
  7. +466
    -0
      app/src/main/java/fr/mobdev/blooddonation/Database.java
  8. +10
    -0
      app/src/main/java/fr/mobdev/blooddonation/NetworkListener.java
  9. +314
    -0
      app/src/main/java/fr/mobdev/blooddonation/NetworkManager.java
  10. +7
    -0
      app/src/main/java/fr/mobdev/blooddonation/NewDonationListener.java
  11. +70
    -0
      app/src/main/java/fr/mobdev/blooddonation/PrefFragment.java
  12. +8
    -0
      app/src/main/java/fr/mobdev/blooddonation/RegisterListener.java
  13. +9
    -0
      app/src/main/java/fr/mobdev/blooddonation/SelectionModeListener.java
  14. +30
    -0
      app/src/main/java/fr/mobdev/blooddonation/activity/AboutActivity.java
  15. +260
    -0
      app/src/main/java/fr/mobdev/blooddonation/activity/DonationActivity.java
  16. +61
    -0
      app/src/main/java/fr/mobdev/blooddonation/activity/DonationInfoActivity.java
  17. +831
    -0
      app/src/main/java/fr/mobdev/blooddonation/activity/MainActivity.java
  18. +17
    -0
      app/src/main/java/fr/mobdev/blooddonation/activity/NotificationsActivity.java
  19. +32
    -0
      app/src/main/java/fr/mobdev/blooddonation/activity/PrefsActivity.java
  20. +123
    -0
      app/src/main/java/fr/mobdev/blooddonation/custom_object/DrawerAdapter.java
  21. +57
    -0
      app/src/main/java/fr/mobdev/blooddonation/custom_object/DrawerItem.java
  22. +85
    -0
      app/src/main/java/fr/mobdev/blooddonation/dialog/AddDonationDialog.java
  23. +121
    -0
      app/src/main/java/fr/mobdev/blooddonation/dialog/ConfirmDialog.java
  24. +118
    -0
      app/src/main/java/fr/mobdev/blooddonation/dialog/InformationDialog.java
  25. +536
    -0
      app/src/main/java/fr/mobdev/blooddonation/dialog/PostDonationDialog.java
  26. +9
    -0
      app/src/main/java/fr/mobdev/blooddonation/enums/Country.java
  27. +9
    -0
      app/src/main/java/fr/mobdev/blooddonation/enums/DonationType.java
  28. +9
    -0
      app/src/main/java/fr/mobdev/blooddonation/enums/DrawerItemType.java
  29. +8
    -0
      app/src/main/java/fr/mobdev/blooddonation/enums/SiteType.java
  30. +211
    -0
      app/src/main/java/fr/mobdev/blooddonation/objects/BloodSite.java
  31. +45
    -0
      app/src/main/java/fr/mobdev/blooddonation/objects/Donation.java
  32. +41
    -0
      app/src/main/java/fr/mobdev/blooddonation/objects/LatiLng.java
  33. +322
    -0
      app/src/main/java/fr/mobdev/blooddonation/service/AlarmReceiver.java
  34. +37
    -0
      app/src/main/java/fr/mobdev/blooddonation/service/BootReceiver.java
  35. BIN
      app/src/main/res/drawable-hdpi/ic_action_delete.png
  36. BIN
      app/src/main/res/drawable-hdpi/ic_launcher.png
  37. BIN
      app/src/main/res/drawable-hdpi/notif.png
  38. BIN
      app/src/main/res/drawable-ldpi/ic_action_delete.png
  39. BIN
      app/src/main/res/drawable-ldpi/ic_launcher.png
  40. BIN
      app/src/main/res/drawable-ldpi/notif.png
  41. BIN
      app/src/main/res/drawable-ldpi/what.png
  42. BIN
      app/src/main/res/drawable-mdpi/ic_action_delete.png
  43. BIN
      app/src/main/res/drawable-mdpi/ic_launcher.png
  44. BIN
      app/src/main/res/drawable-mdpi/notif.png
  45. BIN
      app/src/main/res/drawable-mdpi/what.png
  46. BIN
      app/src/main/res/drawable-xhdpi/ic_action_delete.png
  47. BIN
      app/src/main/res/drawable-xhdpi/ic_launcher.png
  48. BIN
      app/src/main/res/drawable-xhdpi/notif.png
  49. BIN
      app/src/main/res/drawable-xhdpi/what.png
  50. +8
    -0
      app/src/main/res/drawable/black_bottom.xml
  51. BIN
      app/src/main/res/drawable/blood.png
  52. BIN
      app/src/main/res/drawable/efs.png
  53. BIN
      app/src/main/res/drawable/ic_action_add.png
  54. BIN
      app/src/main/res/drawable/ic_action_delete.png
  55. BIN
      app/src/main/res/drawable/ic_drawer.png
  56. BIN
      app/src/main/res/drawable/ic_launcher.png
  57. BIN
      app/src/main/res/drawable/logo.png
  58. BIN
      app/src/main/res/drawable/mixed.png
  59. BIN
      app/src/main/res/drawable/notif.png
  60. BIN
      app/src/main/res/drawable/plasma.png
  61. BIN
      app/src/main/res/drawable/rhesus_checked.png
  62. +9
    -0
      app/src/main/res/drawable/rhesus_mark.xml
  63. BIN
      app/src/main/res/drawable/rhesus_unchecked.png
  64. BIN
      app/src/main/res/drawable/what.png
  65. +89
    -0
      app/src/main/res/layout/about.xml
  66. +59
    -0
      app/src/main/res/layout/add_donation_dialog.xml
  67. +17
    -0
      app/src/main/res/layout/confirm_dialog.xml
  68. +18
    -0
      app/src/main/res/layout/donation.xml
  69. +52
    -0
      app/src/main/res/layout/donation_info.xml
  70. +56
    -0
      app/src/main/res/layout/drawer_item.xml
  71. +49
    -0
      app/src/main/res/layout/help_dialog.xml
  72. +35
    -0
      app/src/main/res/layout/information_dialog.xml
  73. +290
    -0
      app/src/main/res/layout/init_view.xml
  74. +44
    -0
      app/src/main/res/layout/legend_dialog.xml
  75. +59
    -0
      app/src/main/res/layout/main_activity_google.xml
  76. +10
    -0
      app/src/main/res/layout/notif.xml
  77. +9
    -0
      app/src/main/res/layout/notifications.xml
  78. +36
    -0
      app/src/main/res/layout/post_donation_dialog.xml
  79. +12
    -0
      app/src/main/res/menu/donnation_menu.xml
  80. +8
    -0
      app/src/main/res/menu/init_menu.xml
  81. +8
    -0
      app/src/main/res/menu/main_menu.xml
  82. +11
    -0
      app/src/main/res/values-v11/styles.xml
  83. +12
    -0
      app/src/main/res/values-v14/styles.xml
  84. +6
    -0
      app/src/main/res/values-w820dp/dimens.xml
  85. +7
    -0
      app/src/main/res/values/dimens.xml
  86. +218
    -0
      app/src/main/res/values/strings.xml
  87. +20
    -0
      app/src/main/res/values/styles.xml
  88. +18
    -0
      app/src/main/res/xml/analytics.xml
  89. +55
    -0
      app/src/main/res/xml/preferences.xml
  90. +15
    -0
      build.gradle
  91. +7
    -0
      local.properties
  92. +1
    -0
      settings.gradle

+ 7
- 0
.gitignore View File

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

+ 21
- 0
BloodDonation.iml 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
- 0
app/app.iml 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
- 0
app/build.gradle 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'
}

+ 100
- 0
app/src/main/AndroidManifest.xml 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>

+ 25
- 0
app/src/main/java/fr/mobdev/blooddonation/App.java 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;
}
}

+ 466
- 0
app/src/main/java/fr/mobdev/blooddonation/Database.java 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);
}
}

}

+ 10
- 0
app/src/main/java/fr/mobdev/blooddonation/NetworkListener.java 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);
}

+ 314
- 0
app/src/main/java/fr/mobdev/blooddonation/NetworkManager.java 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;
}
}

+ 7
- 0
app/src/main/java/fr/mobdev/blooddonation/NewDonationListener.java View File

@@ -0,0 +1,7 @@
package fr.mobdev.blooddonation;

import java.util.EventListener;

public interface NewDonationListener extends EventListener {
public void needUpdate();
}

+ 70
- 0
app/src/main/java/fr/mobdev/blooddonation/PrefFragment.java 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();
}
}
}

+ 8
- 0
app/src/main/java/fr/mobdev/blooddonation/RegisterListener.java View File

@@ -0,0 +1,8 @@
package fr.mobdev.blooddonation;

import java.util.EventListener;

public interface RegisterListener extends EventListener {

void processNewRegistration();
}

+ 9
- 0
app/src/main/java/fr/mobdev/blooddonation/SelectionModeListener.java 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);
}

+ 30
- 0
app/src/main/java/fr/mobdev/blooddonation/activity/AboutActivity.java 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);
}
}

+ 260
- 0
app/src/main/java/fr/mobdev/blooddonation/activity/DonationActivity.java 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);
donation_list.setAdapter(adapter);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.donnation_menu, menu);
del_item = menu.findItem(R.id.action_del);
del_item.setVisible(false);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add:
addDonation();
return true;
case R.id.action_del:
askRemoveDonation();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void onBackPressed(){
if(isOnSelection)
{
listener.selectionModeChange(null);
}
else
{
finish();
}
}
private void addDonation()
{
AddDonationDialog dialog = new AddDonationDialog();
Bundle bundle = new Bundle();
bundle.putInt("siteId", -1);
dialog.setArguments(bundle);
dialog.setListener(new NewDonationListener() {
@Override
public void needUpdate() {
updateDonationList();
}
});
dialog.show(getSupportFragmentManager(), "add donation dialog");
}
private void askRemoveDonation()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.delete_donation_message)
.setCancelable(false)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
removeSelectedDonation();
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void removeSelectedDonation()
{
List<Donation> deletedList = new ArrayList<Donation>();
for(int i = 0; i<items.size(); i++)
{
DrawerItem item = items.get(i);
if(item.isSelected())
{
deletedList.add(donations.get(i));
}
}
Database.getInstance(this).deleteDonation(deletedList);
updateDonationList();
}
private void updateDonationList()
{
donations = Database.getInstance(this).getDonations();
items.clear();
for(Donation don : donations)
{
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
String texte = df.format(don.getDate().getTime());
texte += " - ";
texte += don.getCityName();
if(don.getCityName().length() > 0)
texte += " - ";
switch(don.getDonationType())
{
case TOTAL_BLOOD:
texte += getResources().getStringArray(R.array.donation_type)[0];
break;
case PLASMA:
texte += getResources().getStringArray(R.array.donation_type)[1];
break;
case PLATELET:
texte += getResources().getStringArray(R.array.donation_type)[2];
break;
default:
//do nothing
break;
}
DrawerItem item = new DrawerItem(DrawerItemType.STATE_NORMAL, texte, null);
items.add(item);
}
DrawerAdapter adapter = new DrawerAdapter(this,R.layout.drawer_item, 0, items);
donation_list.setAdapter(adapter);
}
}

+ 61
- 0
app/src/main/java/fr/mobdev/blooddonation/activity/DonationInfoActivity.java View File

@@ -0,0 +1,61 @@
package fr.mobdev.blooddonation.activity;

import java.util.HashMap;

import com.google.android.gms.analytics.GoogleAnalytics;

import fr.mobdev.blooddonation.Database;
import fr.mobdev.blooddonation.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class DonationInfoActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.donation_info);
HashMap<String, Object> maps = Database.getInstance(this).getUserInformation();
String userName = (String) maps.get("UserName");
String blood = (String) maps.get("BloodGroup");
String city = (String) maps.get("CityName");
int D = (Integer) maps.get("D");
int C = (Integer) maps.get("C");
int E = (Integer) maps.get("E");
int c = (Integer) maps.get("c");
int e = (Integer) maps.get("e");
int K = (Integer) maps.get("K");
TextView view = (TextView) findViewById(R.id.user_name);
view.setText(userName);
view = (TextView) findViewById(R.id.blood_group);
view.setText(blood);
view = (TextView) findViewById(R.id.city_name);
view.setText(city);
view = (TextView) findViewById(R.id.rhesus);
String rhesus = "D" + getStringFor(D) +" C" + getStringFor(C) +" E"+ getStringFor(E) +" c"+ getStringFor(c) +" e" + getStringFor(e) + " K"+getStringFor(K);
view.setText(rhesus);
getActionBar().setTitle(R.string.donation_info);
}
private String getStringFor(int plus)
{
if(plus == 0)
return "-";
else
return "+";
}
@Override
public void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
public void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
}

+ 831
- 0
app/src/main/java/fr/mobdev/blooddonation/activity/MainActivity.java View File

@@ -0,0 +1,831 @@
package fr.mobdev.blooddonation.activity;

import java.io.IOException;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener;
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.LocationSource;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

import fr.mobdev.blooddonation.Database;
import fr.mobdev.blooddonation.NetworkListener;
import fr.mobdev.blooddonation.NetworkManager;
import fr.mobdev.blooddonation.R;
import fr.mobdev.blooddonation.RegisterListener;
import fr.mobdev.blooddonation.custom_object.DrawerAdapter;
import fr.mobdev.blooddonation.custom_object.DrawerItem;
import fr.mobdev.blooddonation.dialog.ConfirmDialog;
import fr.mobdev.blooddonation.dialog.InformationDialog;
import fr.mobdev.blooddonation.dialog.PostDonationDialog;
import fr.mobdev.blooddonation.enums.Country;
import fr.mobdev.blooddonation.enums.DrawerItemType;
import fr.mobdev.blooddonation.enums.SiteType;
import fr.mobdev.blooddonation.objects.BloodSite;
import fr.mobdev.blooddonation.objects.LatiLng;
import fr.mobdev.blooddonation.service.AlarmReceiver;
import fr.mobdev.blooddonation.service.BootReceiver;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.preference.PreferenceManager;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.PopupMenu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.CheckedTextView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;


@SuppressLint({ "UseSparseArrays", "InflateParams" })
public class MainActivity extends FragmentActivity implements LocationSource {

private GoogleMap map;

private enum CORNER {
TOP_LEFT, TOP_RIGHT, BOT_LEFT, BOT_RIGHT
};

private Country country;
private Map<Country, LatLng> countryMap;
private SupportMapFragment mapFrag;
private NetworkListener listener;
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout;
private OnLocationChangedListener mapLocationListener;
private LocationListener locationListener;
private LocationManager locationManager;
private boolean isFirstLocation;
private Geocoder coder;
private int postCode;
private Map<Long, Marker> markerList;
private List<Long> notifications;
private boolean modify;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

modify = getIntent().getBooleanExtra("modify", false);
if (Database.getInstance(this).isFirstTime() || modify) {
setupFirstTime(modify);
} else {
setupMap();
if (savedInstanceState != null) {
boolean isFirstStart = savedInstanceState
.getBoolean("isFirstStart");
if (!isFirstStart) {
isFirstLocation = savedInstanceState.getBoolean("isFirstLocation");
final double latitude = savedInstanceState.getDouble("locationLatitude");
final double longitude = savedInstanceState.getDouble("locationLongitude");
final float zoom = savedInstanceState.getFloat("locationZoom");
postCode = savedInstanceState.getInt("posteCode");
new CountDownTimer(800, 800) {

@Override
public void onTick(long millisUntilFinished) {
}

@Override
public void onFinish() {
map.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(latitude, longitude)));
map.animateCamera(CameraUpdateFactory.zoomTo(zoom));
}
}.start();
} else {
isFirstLocation = true;
postCode = -1;
}

} else {
isFirstLocation = true;
postCode = -1;
}
}
}

protected void onDestroy() {
super.onDestroy();
stopUpdates();
}

protected void onResume() {
super.onResume();
startUpdates();
}

protected void onPause() {
super.onPause();
stopUpdates();
}
@Override
public void onStart() {
super.onStart();
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
@Override
public void onStop() {
super.onStop();
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
if (map != null) {
savedInstanceState.putBoolean("isFirstLocation", isFirstLocation);
savedInstanceState.putDouble("locationLatitude",
map.getCameraPosition().target.latitude);
savedInstanceState.putDouble("locationLatitude",
map.getCameraPosition().target.longitude);
savedInstanceState.putFloat("locationZoom",
map.getCameraPosition().zoom);
savedInstanceState.putInt("posteCode", postCode);
savedInstanceState.putBoolean("isFirstStart", false);
} else {
savedInstanceState.putBoolean("isFirstStart", true);
}
super.onSaveInstanceState(savedInstanceState);
}

private void setupFirstTime(final boolean modify) {
setContentView(R.layout.init_view);
Button bt = (Button) findViewById(R.id.validate_button);

CheckedTextView dView = (CheckedTextView) findViewById(R.id.blood_view_D);
CheckedTextView majCView = (CheckedTextView) findViewById(R.id.blood_view_C);
CheckedTextView majEView = (CheckedTextView) findViewById(R.id.blood_view_E);
CheckedTextView minCView = (CheckedTextView) findViewById(R.id.blood_view_c);
CheckedTextView minEView = (CheckedTextView) findViewById(R.id.blood_view_e);
CheckedTextView kView = (CheckedTextView) findViewById(R.id.blood_view_K);

OnClickListener listener = new OnClickListener() {

@Override
public void onClick(View v) {
CheckedTextView view = (CheckedTextView) v;
view.setChecked(!view.isChecked());

}
};
if(modify)
{
HashMap<String, Object> map = Database.getInstance(getApplicationContext()).getUserInformation();
Spinner blood_view = (Spinner) findViewById(R.id.blood_spinner);
List<String> group_array = new ArrayList<String>(Arrays.asList(getResources().getStringArray(R.array.blood_array)));
blood_view.setSelection(group_array.indexOf(map.get("BloodGroup")));
Spinner gender_view = (Spinner) findViewById(R.id.gender_spinner);
EditText name_view = (EditText) findViewById(R.id.name_text);
name_view.setText((String)map.get("UserName"));
EditText city_name_view = (EditText) findViewById(R.id.city_text);
city_name_view.setText((String)map.get("CityName"));
EditText postal_code_view = (EditText) findViewById(R.id.postal_text);
postal_code_view.setText((String)map.get("Postal"));
dView.setChecked((Integer)map.get("D") != 0);
majCView.setChecked((Integer)map.get("C") != 0);
majEView.setChecked((Integer)map.get("E") != 0);
minCView.setChecked((Integer)map.get("c") != 0);
minEView.setChecked((Integer)map.get("e") != 0);
kView.setChecked((Integer)map.get("K") != 0);
int gender = 0;
if (((Integer)map.get("Gender")).equals(0))
gender = 1;
gender_view.setSelection(gender);
}

dView.setOnClickListener(listener);
majCView.setOnClickListener(listener);
majEView.setOnClickListener(listener);
minCView.setOnClickListener(listener);
minEView.setOnClickListener(listener);
kView.setOnClickListener(listener);

bt.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Spinner blood_view = (Spinner) findViewById(R.id.blood_spinner);
Spinner gender_view = (Spinner) findViewById(R.id.gender_spinner);
EditText name_view = (EditText) findViewById(R.id.name_text);
EditText city_name_view = (EditText) findViewById(R.id.city_text);
EditText postal_code_view = (EditText) findViewById(R.id.postal_text);
CheckedTextView dView = (CheckedTextView) findViewById(R.id.blood_view_D);
CheckedTextView majCView = (CheckedTextView) findViewById(R.id.blood_view_C);
CheckedTextView majEView = (CheckedTextView) findViewById(R.id.blood_view_E);
CheckedTextView minCView = (CheckedTextView) findViewById(R.id.blood_view_c);
CheckedTextView minEView = (CheckedTextView) findViewById(R.id.blood_view_e);
CheckedTextView kView = (CheckedTextView) findViewById(R.id.blood_view_K);

String blood = blood_view.getSelectedItem().toString();
String gender = gender_view.getSelectedItem().toString();
boolean isMale = false;
if (gender.equals(getResources().getStringArray(
R.array.gender_array)[0]))
isMale = true;
else
isMale = false;
String name = name_view.getText().toString();
String city = city_name_view.getText().toString();
String postal = postal_code_view.getText().toString();

Database.getInstance(getApplicationContext()).updateUserInfo(
name, isMale, city, postal, blood, dView.isChecked(),
majCView.isChecked(), majEView.isChecked(),
minCView.isChecked(), minEView.isChecked(),
kView.isChecked());
invalidateOptionsMenu();
if(modify)
finish();
else
recreate();
}
});
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

private void setupMap() {
if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) != ConnectionResult.SUCCESS)
{
Dialog dial = GooglePlayServicesUtil.getErrorDialog(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this), this, 0);
dial.show();
return;
}
setContentView(R.layout.main_activity_google);

listener = new NetworkListener() {

@Override
public void bloodSiteListChanged(final List<BloodSite> sites) {
runOnUiThread(new Runnable() {

@Override
public void run() {
Database.getInstance(getApplicationContext()).addSitesToDb(sites);
AlarmReceiver.prepareNotifications(getApplicationContext());
addSitesOnMap();
}
});
}
};

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

AdView adView = (AdView) this.findViewById(R.id.adView);

AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
//.addTestDevice("8F034444A03B8D1EDF566827C314AE0D")
.addKeyword("Health").addKeyword("Blood").addKeyword("Sang")
.addKeyword("Santé").addKeyword("Donnation").addKeyword("Don")
.addKeyword("Medication").addKeyword("Medicament").build();

adView.loadAd(adRequest);

country = Country.FRANCE;
countryMap = new HashMap<Country, LatLng>();
markerList = new HashMap<Long, Marker>();
notifications = new ArrayList<Long>();

buildCountryMap();

mapFrag = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.maps_mv_map);
map = mapFrag.getMap();

map.setTrafficEnabled(false);
map.setIndoorEnabled(false);
map.setMyLocationEnabled(true);
map.setLocationSource(this);
map.setOnCameraChangeListener(new OnCameraChangeListener() {

@Override
public void onCameraChange(CameraPosition position) {
loadData();
}
});

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

@Override
public void onInfoWindowClick(Marker arg0) {
InformationDialog dialog = new InformationDialog();
Bundle args = new Bundle();
for (Long key : markerList.keySet()) {
if (markerList.get(key).equals(arg0)) {
args.putLong("siteId", key);
break;
}
}
dialog.setArguments(args);
dialog.show(getSupportFragmentManager(), "information dialog");
}
});

new CountDownTimer(500, 500) {

public void onTick(long millisUntilFinished) {
// do nothing
}

public void onFinish() {
initPosition();
BootReceiver.startNextChecking(getApplicationContext(), false);
}
}.start();

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
) {

/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}

/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};

ListView drawerList = (ListView) findViewById(R.id.left_drawer);

List<DrawerItem> items = new ArrayList<DrawerItem>();
items.add(new DrawerItem(DrawerItemType.STATE_SECTION,
getString(R.string.blood_donation), null));
items.add(new DrawerItem(DrawerItemType.STATE_NORMAL,
getString(R.string.donations), new OnClickListener() {

@Override
public void onClick(View v) {
Intent newIntent = new Intent(MainActivity.this,
DonationActivity.class);
startActivity(newIntent);
}
}));
items.add(new DrawerItem(DrawerItemType.STATE_NORMAL,
getString(R.string.donation_info), new OnClickListener() {

@Override
public void onClick(View v) {
Intent newIntent = new Intent(MainActivity.this,
DonationInfoActivity.class);
startActivity(newIntent);
}
}));
items.add(new DrawerItem(DrawerItemType.STATE_SECTION,
getString(R.string.tools), null));
items.add(new DrawerItem(DrawerItemType.STATE_NORMAL,
getString(R.string.legend), new OnClickListener() {

@Override
public void onClick(View v) {
openLegendDialog();
}
}));
items.add(new DrawerItem(DrawerItemType.STATE_NORMAL,
getString(R.string.preference), new OnClickListener() {

@Override
public void onClick(View v) {
Intent newIntent = new Intent(getApplicationContext(),
PrefsActivity.class);
startActivity(newIntent);
}
}));
items.add(new DrawerItem(DrawerItemType.STATE_SECTION,
getString(R.string.contacts), null));
items.add(new DrawerItem(DrawerItemType.STATE_NORMAL,
getString(R.string.post_numbers), new OnClickListener() {

@Override
public void onClick(View v) {
PostDonationDialog dialog = new PostDonationDialog();
Bundle bundle = new Bundle();
bundle.putInt("depId", postCode);
dialog.setArguments(bundle);
dialog.show(getSupportFragmentManager(),
"post donation phone number");
}
}));
items.add(new DrawerItem(DrawerItemType.STATE_NORMAL,
getString(R.string.about), new OnClickListener() {

@Override
public void onClick(View v) {
Intent newIntent = new Intent(getApplicationContext(),
AboutActivity.class);
startActivity(newIntent);
}
}));
DrawerAdapter drawerAdapter = new DrawerAdapter(this,
R.layout.drawer_item, 0, items);

drawerList.setAdapter(drawerAdapter);

mDrawerLayout.setDrawerListener(mDrawerToggle);

getActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
if (mDrawerToggle != null)
mDrawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (mDrawerToggle != null)
mDrawerToggle.onConfigurationChanged(newConfig);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (!Database.getInstance(this).isFirstTime() && !modify) {
if (mDrawerToggle != null
&& mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
}
else {
switch (item.getItemId()) {
case R.id.action_help:
showHelpDialog();
return true;
}
}
return super.onOptionsItemSelected(item);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
if (Database.getInstance(this).isFirstTime() || modify) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.init_menu, menu);
}
else
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu,menu);
MenuItem item = menu.findItem(R.id.action_notif);
ImageButton iv = (ImageButton) getLayoutInflater().inflate(R.layout.notif,null);