From e99c3e7ea52c6b98107a935ba346a43bd014fba8 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sat, 6 Jun 2015 21:33:55 +0200 Subject: [PATCH] Public code. --- Les Horaires/.gitignore | 39 +++ Les Horaires/build.gradle | 61 +++++ Les Horaires/proguard-rules.pro | 17 ++ .../com/amine/horaires/ApplicationTest.java | 13 + Les Horaires/src/main/AndroidManifest.xml | 67 +++++ .../src/main/java/com/amine/horaires/App.java | 15 ++ .../java/com/amine/horaires/MainActivity.java | 132 ++++++++++ .../com/amine/horaires/OptionsActivity.java | 89 +++++++ .../com/amine/horaires/SearchAdapter.java | 88 +++++++ .../java/com/amine/horaires/ShopDisplay.java | 249 ++++++++++++++++++ .../java/com/amine/horaires/ShopSearch.java | 134 ++++++++++ .../java/com/amine/horaires/ShopUpdate.java | 144 ++++++++++ .../com/amine/horaires/UpdateAdapter.java | 98 +++++++ .../com/amine/horaires/bdd/FavorisBdd.java | 58 ++++ .../com/amine/horaires/bdd/FavorisDao.java | 159 +++++++++++ .../com/amine/horaires/models/Horaires.java | 112 ++++++++ .../java/com/amine/horaires/models/Shop.java | 240 +++++++++++++++++ .../amine/horaires/util/Configuration.java | 23 ++ .../com/amine/horaires/util/MyLocation.java | 129 +++++++++ .../java/com/amine/horaires/util/Parseur.java | 224 ++++++++++++++++ .../java/com/amine/horaires/util/Utils.java | 64 +++++ .../src/main/res/layout/activity_main.xml | 43 +++ .../src/main/res/layout/activity_more.xml | 74 ++++++ .../src/main/res/layout/fav_list_item.xml | 36 +++ .../src/main/res/layout/shop_display.xml | 148 +++++++++++ .../src/main/res/layout/shop_search.xml | 111 ++++++++ .../src/main/res/layout/spinner_item.xml | 10 + .../main/res/layout/update_horaire_item.xml | 40 +++ .../src/main/res/layout/update_shop.xml | 63 +++++ .../main/res/menu/main_activity_actions.xml | 11 + .../res/menu/main_activity_actions_main.xml | 10 + .../res/menu/main_activity_actions_shop.xml | 10 + .../src/main/res/mipmap-hdpi/call.png | Bin 0 -> 424 bytes .../src/main/res/mipmap-hdpi/handi.png | Bin 0 -> 18677 bytes .../mipmap-hdpi/ic_alarm_add_black_24dp.png | Bin 0 -> 686 bytes .../res/mipmap-hdpi/ic_cached_black_24dp.png | Bin 0 -> 460 bytes .../mipmap-hdpi/ic_clear_all_black_24dp.png | Bin 0 -> 187 bytes .../res/mipmap-hdpi/ic_create_black_24dp.png | Bin 0 -> 242 bytes .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 4313 bytes .../mipmap-hdpi/ic_turned_in_black_24dp.png | Bin 0 -> 265 bytes .../ic_turned_in_not_black_24dp.png | Bin 0 -> 322 bytes Les Horaires/src/main/res/mipmap-hdpi/map.png | Bin 0 -> 426 bytes .../src/main/res/mipmap-hdpi/parking.png | Bin 0 -> 8001 bytes .../src/main/res/mipmap-hdpi/plus.png | Bin 0 -> 517 bytes .../src/main/res/mipmap-hdpi/wifi.png | Bin 0 -> 16053 bytes .../src/main/res/mipmap-mdpi/call.png | Bin 0 -> 338 bytes .../src/main/res/mipmap-mdpi/handi.png | Bin 0 -> 18677 bytes .../mipmap-mdpi/ic_alarm_add_black_24dp.png | Bin 0 -> 471 bytes .../res/mipmap-mdpi/ic_cached_black_24dp.png | Bin 0 -> 341 bytes .../mipmap-mdpi/ic_clear_all_black_24dp.png | Bin 0 -> 162 bytes .../res/mipmap-mdpi/ic_create_black_24dp.png | Bin 0 -> 242 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2562 bytes .../mipmap-mdpi/ic_turned_in_black_24dp.png | Bin 0 -> 217 bytes .../ic_turned_in_not_black_24dp.png | Bin 0 -> 261 bytes Les Horaires/src/main/res/mipmap-mdpi/map.png | Bin 0 -> 331 bytes .../src/main/res/mipmap-mdpi/parking.png | Bin 0 -> 8001 bytes .../src/main/res/mipmap-mdpi/plus.png | Bin 0 -> 386 bytes .../src/main/res/mipmap-mdpi/wifi.png | Bin 0 -> 16053 bytes .../src/main/res/mipmap-xhdpi/call.png | Bin 0 -> 518 bytes .../src/main/res/mipmap-xhdpi/handi.png | Bin 0 -> 18677 bytes .../mipmap-xhdpi/ic_alarm_add_black_24dp.png | Bin 0 -> 901 bytes .../res/mipmap-xhdpi/ic_cached_black_24dp.png | Bin 0 -> 532 bytes .../mipmap-xhdpi/ic_clear_all_black_24dp.png | Bin 0 -> 179 bytes .../res/mipmap-xhdpi/ic_create_black_24dp.png | Bin 0 -> 299 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 6378 bytes .../mipmap-xhdpi/ic_turned_in_black_24dp.png | Bin 0 -> 316 bytes .../ic_turned_in_not_black_24dp.png | Bin 0 -> 358 bytes .../src/main/res/mipmap-xhdpi/map.png | Bin 0 -> 530 bytes .../src/main/res/mipmap-xhdpi/parking.png | Bin 0 -> 8001 bytes .../src/main/res/mipmap-xhdpi/plus.png | Bin 0 -> 605 bytes .../src/main/res/mipmap-xhdpi/wifi.png | Bin 0 -> 16053 bytes .../src/main/res/mipmap-xxhdpi/call.png | Bin 0 -> 705 bytes .../src/main/res/mipmap-xxhdpi/handi.png | Bin 0 -> 18677 bytes .../mipmap-xxhdpi/ic_alarm_add_black_24dp.png | Bin 0 -> 1236 bytes .../mipmap-xxhdpi/ic_cached_black_24dp.png | Bin 0 -> 778 bytes .../mipmap-xxhdpi/ic_clear_all_black_24dp.png | Bin 0 -> 207 bytes .../mipmap-xxhdpi/ic_create_black_24dp.png | Bin 0 -> 366 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 11371 bytes .../mipmap-xxhdpi/ic_turned_in_black_24dp.png | Bin 0 -> 390 bytes .../ic_turned_in_not_black_24dp.png | Bin 0 -> 464 bytes .../src/main/res/mipmap-xxhdpi/map.png | Bin 0 -> 704 bytes .../src/main/res/mipmap-xxhdpi/parking.png | Bin 0 -> 8001 bytes .../src/main/res/mipmap-xxhdpi/plus.png | Bin 0 -> 835 bytes .../src/main/res/mipmap-xxhdpi/wifi.png | Bin 0 -> 16053 bytes .../src/main/res/mipmap-xxxhdpi/handi.png | Bin 0 -> 18677 bytes .../ic_alarm_add_black_24dp.png | Bin 0 -> 1704 bytes .../mipmap-xxxhdpi/ic_cached_black_24dp.png | Bin 0 -> 957 bytes .../ic_clear_all_black_24dp.png | Bin 0 -> 220 bytes .../mipmap-xxxhdpi/ic_create_black_24dp.png | Bin 0 -> 406 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 17346 bytes .../ic_turned_in_black_24dp.png | Bin 0 -> 467 bytes .../ic_turned_in_not_black_24dp.png | Bin 0 -> 570 bytes .../src/main/res/mipmap-xxxhdpi/map.png | Bin 0 -> 911 bytes .../src/main/res/mipmap-xxxhdpi/parking.png | Bin 0 -> 8001 bytes .../src/main/res/mipmap-xxxhdpi/plus.png | Bin 0 -> 1054 bytes .../src/main/res/mipmap-xxxhdpi/wifi.png | Bin 0 -> 16053 bytes .../src/main/res/values-v21/strings.xml | 38 +++ .../src/main/res/values-v21/styles.xml | 24 ++ Les Horaires/src/main/res/values/strings.xml | 37 +++ Les Horaires/src/main/res/values/styles.xml | 29 ++ .../src/main/res/xml/changelog_master.xml | 21 ++ build.gradle | 19 ++ gradle.properties | 18 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 49896 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 164 ++++++++++++ gradlew.bat | 90 +++++++ settings.gradle | 1 + 108 files changed, 3158 insertions(+) create mode 100644 Les Horaires/.gitignore create mode 100644 Les Horaires/build.gradle create mode 100644 Les Horaires/proguard-rules.pro create mode 100644 Les Horaires/src/androidTest/java/com/amine/horaires/ApplicationTest.java create mode 100644 Les Horaires/src/main/AndroidManifest.xml create mode 100644 Les Horaires/src/main/java/com/amine/horaires/App.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/MainActivity.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/OptionsActivity.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/SearchAdapter.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/ShopDisplay.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/ShopSearch.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/ShopUpdate.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/UpdateAdapter.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/bdd/FavorisBdd.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/bdd/FavorisDao.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/models/Horaires.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/models/Shop.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/util/Configuration.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/util/MyLocation.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/util/Parseur.java create mode 100644 Les Horaires/src/main/java/com/amine/horaires/util/Utils.java create mode 100644 Les Horaires/src/main/res/layout/activity_main.xml create mode 100644 Les Horaires/src/main/res/layout/activity_more.xml create mode 100644 Les Horaires/src/main/res/layout/fav_list_item.xml create mode 100644 Les Horaires/src/main/res/layout/shop_display.xml create mode 100644 Les Horaires/src/main/res/layout/shop_search.xml create mode 100644 Les Horaires/src/main/res/layout/spinner_item.xml create mode 100644 Les Horaires/src/main/res/layout/update_horaire_item.xml create mode 100644 Les Horaires/src/main/res/layout/update_shop.xml create mode 100644 Les Horaires/src/main/res/menu/main_activity_actions.xml create mode 100644 Les Horaires/src/main/res/menu/main_activity_actions_main.xml create mode 100644 Les Horaires/src/main/res/menu/main_activity_actions_shop.xml create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/call.png create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/handi.png create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/ic_alarm_add_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/ic_cached_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/ic_clear_all_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/ic_create_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/ic_turned_in_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/ic_turned_in_not_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/map.png create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/parking.png create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/plus.png create mode 100644 Les Horaires/src/main/res/mipmap-hdpi/wifi.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/call.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/handi.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/ic_alarm_add_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/ic_cached_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/ic_clear_all_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/ic_create_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/ic_turned_in_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/ic_turned_in_not_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/map.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/parking.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/plus.png create mode 100644 Les Horaires/src/main/res/mipmap-mdpi/wifi.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/call.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/handi.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/ic_alarm_add_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/ic_cached_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/ic_clear_all_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/ic_create_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/ic_turned_in_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/ic_turned_in_not_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/map.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/parking.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/plus.png create mode 100644 Les Horaires/src/main/res/mipmap-xhdpi/wifi.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/call.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/handi.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/ic_alarm_add_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/ic_cached_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/ic_clear_all_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/ic_create_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/ic_turned_in_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/ic_turned_in_not_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/map.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/parking.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/plus.png create mode 100644 Les Horaires/src/main/res/mipmap-xxhdpi/wifi.png create mode 100644 Les Horaires/src/main/res/mipmap-xxxhdpi/handi.png create mode 100644 Les Horaires/src/main/res/mipmap-xxxhdpi/ic_alarm_add_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xxxhdpi/ic_cached_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xxxhdpi/ic_clear_all_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xxxhdpi/ic_create_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 Les Horaires/src/main/res/mipmap-xxxhdpi/ic_turned_in_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xxxhdpi/ic_turned_in_not_black_24dp.png create mode 100644 Les Horaires/src/main/res/mipmap-xxxhdpi/map.png create mode 100644 Les Horaires/src/main/res/mipmap-xxxhdpi/parking.png create mode 100644 Les Horaires/src/main/res/mipmap-xxxhdpi/plus.png create mode 100644 Les Horaires/src/main/res/mipmap-xxxhdpi/wifi.png create mode 100644 Les Horaires/src/main/res/values-v21/strings.xml create mode 100644 Les Horaires/src/main/res/values-v21/styles.xml create mode 100644 Les Horaires/src/main/res/values/strings.xml create mode 100644 Les Horaires/src/main/res/values/styles.xml create mode 100644 Les Horaires/src/main/res/xml/changelog_master.xml create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/Les Horaires/.gitignore b/Les Horaires/.gitignore new file mode 100644 index 0000000..ee765f9 --- /dev/null +++ b/Les Horaires/.gitignore @@ -0,0 +1,39 @@ +/build + +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build + +# built application files +*.apk +*.ap_ + +# files for the dex VM +*.dex + +# Java class files +*.class + +# generated files +bin/ +gen/ + +# Local configuration file (sdk path, etc) +local.properties + +# Eclipse stuff +.classpath +.project +.settings + +# Gradle stuff +.gradle/ +build/ +.idea/ +out/ +*.iml + +Thumbs.db diff --git a/Les Horaires/build.gradle b/Les Horaires/build.gradle new file mode 100644 index 0000000..45d606d --- /dev/null +++ b/Les Horaires/build.gradle @@ -0,0 +1,61 @@ +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.1.1' + } +} +apply plugin: 'com.android.application' + +repositories { + jcenter() +} + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" + + defaultConfig { + applicationId "com.amine.horaires" + minSdkVersion 14 + targetSdkVersion 22 + versionCode 39 + versionName "2.1.2" + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_6 + targetCompatibility JavaVersion.VERSION_1_6 + } + + lintOptions { + checkReleaseBuilds true + abortOnError false + } + + signingConfigs { + release { + } + } + + buildTypes { + release { + signingConfig signingConfigs.release + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:+' + compile 'com.android.support:support-v4:+' + compile 'com.android.support:recyclerview-v7:+' + compile 'com.google.android.gms:play-services:4.3.23' + compile 'com.melnykov:floatingactionbutton:1.2.0' + compile 'com.pnikosis:materialish-progress:1.5' + compile 'com.wdullaer:materialdatetimepicker:1.3.0' + compile 'de.cketti.library.changelog:ckchangelog:1.2.2' +} diff --git a/Les Horaires/proguard-rules.pro b/Les Horaires/proguard-rules.pro new file mode 100644 index 0000000..bef92eb --- /dev/null +++ b/Les Horaires/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:/Users/Amine/Desktop/android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/Les Horaires/src/androidTest/java/com/amine/horaires/ApplicationTest.java b/Les Horaires/src/androidTest/java/com/amine/horaires/ApplicationTest.java new file mode 100644 index 0000000..6ada1aa --- /dev/null +++ b/Les Horaires/src/androidTest/java/com/amine/horaires/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.amine.horaires; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/Les Horaires/src/main/AndroidManifest.xml b/Les Horaires/src/main/AndroidManifest.xml new file mode 100644 index 0000000..e568bb1 --- /dev/null +++ b/Les Horaires/src/main/AndroidManifest.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Les Horaires/src/main/java/com/amine/horaires/App.java b/Les Horaires/src/main/java/com/amine/horaires/App.java new file mode 100644 index 0000000..2bb59e8 --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/App.java @@ -0,0 +1,15 @@ +package com.amine.horaires; + +import android.app.Application; + +public class App extends Application { + + public App() { + super(); + } + + @Override + public void onCreate() { + super.onCreate(); + } +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/MainActivity.java b/Les Horaires/src/main/java/com/amine/horaires/MainActivity.java new file mode 100644 index 0000000..16ea1c3 --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/MainActivity.java @@ -0,0 +1,132 @@ +package com.amine.horaires; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.telephony.TelephonyManager; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.View; +import android.widget.TextView; +import com.amine.horaires.bdd.FavorisDao; +import com.amine.horaires.models.Shop; +import com.amine.horaires.util.Configuration; +import com.amine.horaires.util.Parseur; +import com.melnykov.fab.FloatingActionButton; +import de.cketti.library.changelog.ChangeLog; + +import java.util.ArrayList; + +public class MainActivity extends OptionsActivity { + + private static RecyclerView mRecyclerView; + private static RecyclerView.Adapter mAdapter; + private static ArrayList myDataset; + private static TextView emptyView; + + static void razOrFavs(Context c) { + FavorisDao dao = FavorisDao.getInstance(c); + dao.open(); + myDataset = dao.getAllFavoris(); + dao.close(); + + if (myDataset.isEmpty()) { + mRecyclerView.setVisibility(View.GONE); + emptyView.setVisibility(View.VISIBLE); + } else { + mAdapter = new SearchAdapter(myDataset, c); + mRecyclerView.setAdapter(mAdapter); + mRecyclerView.setVisibility(View.VISIBLE); + emptyView.setVisibility(View.GONE); + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + checkLocale(); + ChangeLog cl = new ChangeLog(this); + if (cl.isFirstRun()) { + cl.getLogDialog().show(); + } + + mRecyclerView = (RecyclerView) findViewById(R.id.favs_list); + emptyView = (TextView) findViewById(R.id.empty_list); + + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + fab.attachToRecyclerView(mRecyclerView); + + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final Intent i = new Intent(getBaseContext(), ShopSearch.class); + startActivityForResult(i, 0); + } + }); + + // use this setting to improve performance if you know that changes + // in content do not change the layout size of the RecyclerView + mRecyclerView.setHasFixedSize(true); + + // use a linear layout manager + RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this); + mRecyclerView.setLayoutManager(mLayoutManager); + + // specify an adapter (see also next example) + myDataset = new ArrayList(); + + razOrFavs(getBaseContext()); + } + + private void checkLocale() { + TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); + Configuration.pays = tm.getSimCountryIso().toUpperCase(); + if (Configuration.pays == null || Configuration.pays.equals("") || Configuration.pays.isEmpty()) + Configuration.pays = MainActivity.this.getResources().getConfiguration().locale.getCountry(); + + SharedPreferences settings = getSharedPreferences("UserInfo", 0); + if (settings.getString("Pays", "") == null || !settings.getString("Pays", "").equals(Configuration.pays)) { + settings = getSharedPreferences("UserInfo", 0); + SharedPreferences.Editor editor = settings.edit(); + editor.putString("Pays", Configuration.pays); + editor.apply(); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + switch (requestCode) { + case (0): { + if (resultCode == Activity.RESULT_OK) { + myDataset = new ArrayList(); + String result = data.getStringExtra("result"); + myDataset = new Parseur().parserShops(result); + if (myDataset.isEmpty()) { + mRecyclerView.setVisibility(View.GONE); + emptyView.setVisibility(View.VISIBLE); + } else { + mAdapter = new SearchAdapter(myDataset, getBaseContext()); + mRecyclerView.setAdapter(mAdapter); + mRecyclerView.setVisibility(View.VISIBLE); + emptyView.setVisibility(View.GONE); + } + } + break; + } + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.main_activity_actions_main, menu); + return super.onCreateOptionsMenu(menu); + } +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/OptionsActivity.java b/Les Horaires/src/main/java/com/amine/horaires/OptionsActivity.java new file mode 100644 index 0000000..456242a --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/OptionsActivity.java @@ -0,0 +1,89 @@ +package com.amine.horaires; + +import android.app.Dialog; +import android.content.Intent; +import android.net.Uri; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.Window; +import com.amine.horaires.bdd.FavorisDao; +import com.amine.horaires.models.Shop; +import com.amine.horaires.util.Configuration; + +class OptionsActivity extends AppCompatActivity { + MenuItem favMenu = null; + boolean isFav = false; + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.main_activity_actions, menu); + return super.onCreateOptionsMenu(menu); + } + + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_mail: + Intent intent = new Intent(Intent.ACTION_SENDTO); // it's not ACTION_SEND + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_SUBJECT, "Les Horaires"); + intent.setData(Uri.parse("mailto:amine.bou.dev@gmail.com")); // or just "mailto:" for blank + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this will make such that when user returns to your app, your app is displayed, instead of the email app. + startActivity(intent); + return true; + case R.id.action_about: + final Dialog dialog = new Dialog(this); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.setCancelable(true); + + // Content of the dialog + dialog.setContentView(R.layout.activity_more); + dialog.show(); + return true; + case R.id.action_reload: + MainActivity.razOrFavs(OptionsActivity.this); + return true; + case R.id.action_fav: + FavorisDao dao = FavorisDao.getInstance(OptionsActivity.this); + if (isFav) { + // REMOVE + dao.open(); + dao.deleteFavori(Configuration.currentShop.getId()); + dao.close(); + updateFavStatus(false); + } else { + dao.open(); + dao.insertFavori(Configuration.currentShop); + dao.close(); + updateFavStatus(true); + } + return true; + case android.R.id.home: + this.finish(); + return (true); + default: + return false; + } + } + + private void updateFavStatus(boolean state) { + if (state) { + favMenu.setIcon(R.mipmap.ic_turned_in_black_24dp); + } else { + favMenu.setIcon(R.mipmap.ic_turned_in_not_black_24dp); + } + } + + void updateFavStatus() { + FavorisDao dao = FavorisDao.getInstance(OptionsActivity.this); + dao.open(); + Shop sh = dao.getFavori(Configuration.currentShop.getId()); + dao.close(); + if (sh == null) { + updateFavStatus(false); + } else { + updateFavStatus(true); + } + } +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/SearchAdapter.java b/Les Horaires/src/main/java/com/amine/horaires/SearchAdapter.java new file mode 100644 index 0000000..318468c --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/SearchAdapter.java @@ -0,0 +1,88 @@ +package com.amine.horaires; + +import android.content.Context; +import android.content.Intent; +import android.os.Handler; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RelativeLayout; +import android.widget.TextView; +import com.amine.horaires.models.Shop; + +import java.util.ArrayList; + +public class SearchAdapter extends RecyclerView.Adapter { + private final ArrayList mDataset; + private final Context c; + + // Provide a suitable constructor (depends on the kind of dataset) + public SearchAdapter(ArrayList myDataset, Context c) { + mDataset = myDataset; + this.c = c; + } + + // Create new views (invoked by the layout manager) + @Override + public SearchAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, + int viewType) { + // create a new view + View v = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.fav_list_item, parent, false); + // set the view's size, margins, paddings and layout parameters + + return new ViewHolder((RelativeLayout) v, c, mDataset); + } + + // Replace the contents of a view (invoked by the layout manager) + @Override + public void onBindViewHolder(ViewHolder holder, final int position) { + // - get element from your dataset at this position + // - replace the contents of the view with that element + holder.shopAddr.setText(mDataset.get(position).getAdresse()); + holder.shopName.setText(mDataset.get(position).getName()); + } + + // Return the size of your dataset (invoked by the layout manager) + @Override + public int getItemCount() { + return mDataset.size(); + } + + // Provide a reference to the views for each data item + // Complex data items may need more than one view per item, and + // you provide access to all the views for a data item in a view holder + public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { + // each data item is just a string in this case + public final TextView shopName; + public final TextView shopAddr; + private final Context c; + private final ArrayList mDataset; + + public ViewHolder(RelativeLayout v, Context c, ArrayList mDataset) { + super(v); + v.setOnClickListener(this); + shopName = (TextView) v.findViewById(R.id.shop_name); + shopAddr = (TextView) v.findViewById(R.id.shop_adress); + this.c = c; + this.mDataset = mDataset; + } + + @Override + public void onClick(View view) { + final Intent i = new Intent(view.getContext(), ShopDisplay.class); + final Handler handler = new Handler(); + Runnable t = new Runnable() { + public void run() { + i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + i.putExtra("shop", mDataset.get(getLayoutPosition())); + c.startActivity(i); + } + }; + + handler.post(t); + } + + } +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/ShopDisplay.java b/Les Horaires/src/main/java/com/amine/horaires/ShopDisplay.java new file mode 100644 index 0000000..ae14cab --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/ShopDisplay.java @@ -0,0 +1,249 @@ +package com.amine.horaires; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; +import com.amine.horaires.bdd.FavorisDao; +import com.amine.horaires.models.Shop; +import com.amine.horaires.util.Configuration; +import com.amine.horaires.util.Parseur; +import com.amine.horaires.util.Utils; +import com.melnykov.fab.FloatingActionButton; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.util.List; +import java.util.Scanner; + +public class ShopDisplay extends OptionsActivity { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.shop_display); + Shop s = getIntent().getExtras().getParcelable("shop"); + + Configuration.currentShop = s; + + FavorisDao dao = FavorisDao.getInstance(ShopDisplay.this); + dao.open(); + List fs = dao.getAllFavoris(); + dao.close(); + + while (!isFav && !fs.isEmpty()) { + isFav = fs.remove(0).getId() == Configuration.currentShop.getId(); + } + if (isFav) { + SearchTask st = new SearchTask(); + st.execute(Utils.generateUrlForId(s.getId())); + s = Configuration.currentShop; + dao.open(); + dao.updateFavori(s); + dao.close(); + } + generateView(s); + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + + final Shop finalS = s; + fab.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + final Intent i = new Intent(getBaseContext(), ShopUpdate.class); + i.putExtra("shop", finalS); + startActivity(i); + } + }); + } + + private void generateView(final Shop s) { + Configuration.currentShop = s; + + ImageView imageResult = (ImageView) findViewById(R.id.imageView); + + ImageTask t = new ImageTask(imageResult); + t.execute(s.getHoraires()); + + TextView shopName = (TextView) findViewById(R.id.shopName); + TextView shopAddress = (TextView) findViewById(R.id.shopAdress); + TextView shopOpen = (TextView) findViewById(R.id.shopOpen); + TextView shopStatus = (TextView) findViewById(R.id.shopStatus); + ImageView wifi = (ImageView) findViewById(R.id.wifi); + ImageView parking = (ImageView) findViewById(R.id.parking); + ImageView access = (ImageView) findViewById(R.id.handi); + + shopName.setText(s.getName()); + shopAddress.setText(s.getAdresse()); + shopOpen.setText("Le magasin est " + (s.isOuvert() ? "ouvert" : "fermé")); + if (s.isOuvert()) { + shopStatus.setText(s.getOpenStatus()); + } + + if (!s.isWifi()) { + wifi.setAlpha((float) 0.1); + } + + if (!s.isAccesHandicape()) { + access.setAlpha((float) 0.1); + } + + if (!s.isParking()) { + parking.setAlpha((float) 0.1); + } + + findViewById(R.id.imageView).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(s.getUrl())); + startActivity(browserIntent); + } + }); + + findViewById(R.id.callButton).setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + String numeroAppeler = "tel:" + s.getTel(); + startActivity(new Intent(Intent.ACTION_DIAL, Uri + .parse(numeroAppeler))); + } + }); + + findViewById(R.id.gpsButton).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new + Intent(Intent.ACTION_VIEW, + Uri.parse("http://maps.google.com/maps?q=" + + s.getAdresse() + "@" + s.getLat() + "," + s.getLng() + "") + ); + startActivity(intent); + + } + }); + } + + // @todo: use this to update the shop if connected. + private boolean checkDeviceConnected() { + ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + // Need permission : android.permission.ACCESS_NETWORK_STATE + NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); + + return (networkInfo != null && networkInfo.isConnected()); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.main_activity_actions_shop, menu); + favMenu = menu.findItem(R.id.action_fav); + updateFavStatus(); + return super.onCreateOptionsMenu(menu); + } + + public class ImageTask extends AsyncTask { + private final ImageView contenu; + + public ImageTask(ImageView contenu) { + this.contenu = contenu; + } + + @Override + protected Bitmap doInBackground(String... params) { + URL url; + Bitmap b = null; + try { + url = new URL(params[0]); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + conn.setDoInput(true); + conn.connect(); + + InputStream is = conn.getInputStream(); + b = BitmapFactory.decodeStream(is); + + + is.close(); + conn.disconnect(); + + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (ProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return b; + } + + protected void onPostExecute(Bitmap b) { + this.contenu.setImageBitmap(b); + } + } + + private class SearchTask extends AsyncTask { + + @Override + protected String doInBackground(URL... params) { + HttpURLConnection conn = null; + InputStream is = null; + String contentAsString = ""; + + try { + URL url = params[0]; + conn = (HttpURLConnection) url.openConnection(); + conn.setReadTimeout(10000 /* milliseconds */); + conn.setConnectTimeout(15000 /* milliseconds */); + conn.setRequestMethod("GET"); + conn.setDoInput(true); + + // Starts the query + conn.connect(); + is = conn.getInputStream(); + + // Convert the InputStream into a String + + Scanner reader = new Scanner(is, "ISO-8859-1"); + while (reader.hasNextLine()) { + contentAsString = contentAsString + reader.nextLine(); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (ProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + // Makes sure that the InputStream is closed after the app is finished using it. + if (is != null) + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + if (conn != null) + conn.disconnect(); + } + return contentAsString; + } + + @Override + protected void onPostExecute(String string) { + super.onPostExecute(string); + Configuration.currentShop = new Parseur().parserShops(string).get(0); + } + } +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/ShopSearch.java b/Les Horaires/src/main/java/com/amine/horaires/ShopSearch.java new file mode 100644 index 0000000..ae4f1d8 --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/ShopSearch.java @@ -0,0 +1,134 @@ +package com.amine.horaires; + +import android.content.Intent; +import android.location.Location; +import android.os.AsyncTask; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.RelativeLayout; +import android.widget.Toast; +import com.amine.horaires.util.MyLocation; +import com.amine.horaires.util.Utils; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.util.Scanner; + +public class ShopSearch extends OptionsActivity { + private MyLocation myLocation; + private RelativeLayout loading; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.shop_search); + + final EditText name = (EditText) findViewById(R.id.name); + final EditText location = (EditText) findViewById(R.id.location); + loading = (RelativeLayout) findViewById(R.id.loading); + Button searchButton = (Button) findViewById(R.id.searchAction); + + // @todo form validation (empty ...) + searchButton.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + loading.setVisibility(View.VISIBLE); + SearchTask s = new SearchTask(); + s.execute(Utils.generateUrlForTextLocation(name.getText().toString(), location.getText().toString())); + } + }); + + findViewById(R.id.gpsAction).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + + loading.setVisibility(View.VISIBLE); + + MyLocation.LocationResult locationResult = new MyLocation.LocationResult() { + @Override + public void gotLocation(Location location) { + if (location == null) { + Toast.makeText(getApplicationContext(), "Petit soucis lors de la localisation", Toast.LENGTH_SHORT).show(); + } else { + URL url = Utils.generateUrlForLatLng(name.getText().toString(), location.getLatitude() + "", location.getLongitude() + ""); + SearchTask s = new SearchTask(); + s.execute(url); + } + } + }; + myLocation = new MyLocation(); + boolean gotLocation = myLocation.getLocation(getApplicationContext(), + locationResult); + if (!gotLocation) { + Toast.makeText(getApplicationContext(), "Erreur de localisation.", Toast.LENGTH_SHORT).show(); + } + } + }); + } + + private class SearchTask extends AsyncTask { + + @Override + protected String doInBackground(URL... params) { + HttpURLConnection conn = null; + InputStream is = null; + String contentAsString = ""; + + try { + URL url = params[0]; + conn = (HttpURLConnection) url.openConnection(); + conn.setReadTimeout(10000 /* milliseconds */); + conn.setConnectTimeout(15000 /* milliseconds */); + conn.setRequestMethod("GET"); + conn.setDoInput(true); + + // Starts the query + conn.connect(); + is = conn.getInputStream(); + + // Convert the InputStream into a String + + Scanner reader = new Scanner(is, "ISO-8859-1"); + while (reader.hasNextLine()) { + contentAsString = contentAsString + reader.nextLine(); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (ProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + // Makes sure that the InputStream is closed after the app is finished using it. + if (is != null) + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + if (conn != null) + conn.disconnect(); + } + return contentAsString; + } + + @Override + protected void onPostExecute(String string) { + super.onPostExecute(string); + + loading.setVisibility(View.GONE); + Intent resultIntent = new Intent(); + resultIntent.putExtra("result", string); + setResult(MainActivity.RESULT_OK, resultIntent); + finish(); + } + } +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/ShopUpdate.java b/Les Horaires/src/main/java/com/amine/horaires/ShopUpdate.java new file mode 100644 index 0000000..a735c4f --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/ShopUpdate.java @@ -0,0 +1,144 @@ +package com.amine.horaires; + +import android.os.AsyncTask; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.ListView; +import android.widget.RelativeLayout; +import android.widget.Toast; +import com.amine.horaires.models.Horaires; +import com.amine.horaires.models.Shop; +import com.amine.horaires.util.Utils; +import com.melnykov.fab.FloatingActionButton; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Scanner; + +public class ShopUpdate extends OptionsActivity { + private ArrayList h; + private RelativeLayout loading; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.update_shop); + + loading = (RelativeLayout) findViewById(R.id.loading); + + final Shop s = getIntent().getExtras().getParcelable("shop"); + + ListView hList = (ListView) findViewById(R.id.horaires_list); + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + Button save = (Button) findViewById(R.id.button); + + h = new ArrayList(); + + initializeHoraires(); + + final UpdateAdapter adapter = new UpdateAdapter(this, h, getFragmentManager()); + + hList.setAdapter(adapter); + + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Horaires h = adapter.getItem(adapter.getCount() - 1); + adapter.add(new Horaires(h)); + } + }); + + save.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + loading.setVisibility(View.VISIBLE); + + ArrayList> periodes = new ArrayList>(); + Collections.sort(h); + + String periodsString = ""; + int i = 0; + for (Horaires hor : h) { + periodsString += "&periods[0][" + i + "][day]=" + hor.getDay(); + periodsString += "&periods[0][" + i + "][from_h]=" + hor.getFrom_h(); + periodsString += "&periods[0][" + i + "][to_h]=" + hor.getTo_h(); + periodsString += "&periods[0][" + i + "][to_m]=" + hor.getTo_m(); + i++; + } + + // Toast.makeText(getApplicationContext(), "Cette fonctionnalité est en attente de validation par Les-horaires.fr", Toast.LENGTH_SHORT).show(); + UpdateTask u = new UpdateTask(); + u.execute(Utils.generateUrlForEdit(s.getId(), periodsString)); + + } + }); + } + + private void initializeHoraires() { + h.add(new Horaires(1)); + } + + private class UpdateTask extends AsyncTask { + + @Override + protected String doInBackground(URL... params) { + HttpURLConnection conn = null; + InputStream is = null; + String contentAsString = ""; + + try { + URL url = params[0]; + conn = (HttpURLConnection) url.openConnection(); + conn.setReadTimeout(10000 /* milliseconds */); + conn.setConnectTimeout(15000 /* milliseconds */); + conn.setRequestMethod("POST"); + conn.setDoInput(true); + conn.setDoOutput(true); + conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); + + // Starts the query + conn.connect(); + is = conn.getInputStream(); + + // Convert the InputStream into a String + + Scanner reader = new Scanner(is, "ISO-8859-1"); + while (reader.hasNextLine()) { + contentAsString = contentAsString + reader.nextLine(); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (ProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + // Makes sure that the InputStream is closed after the app is finished using it. + if (is != null) + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + if (conn != null) + conn.disconnect(); + } + return contentAsString; + } + + @Override + protected void onPostExecute(String string) { + loading.setVisibility(View.GONE); + super.onPostExecute(string); + Toast.makeText(getApplicationContext(), "Mise à jour effectuée!", Toast.LENGTH_SHORT).show(); + } + } +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/UpdateAdapter.java b/Les Horaires/src/main/java/com/amine/horaires/UpdateAdapter.java new file mode 100644 index 0000000..e0c9681 --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/UpdateAdapter.java @@ -0,0 +1,98 @@ +package com.amine.horaires; + +import android.app.FragmentManager; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.*; +import com.amine.horaires.models.Horaires; +import com.wdullaer.materialdatetimepicker.time.RadialPickerLayout; +import com.wdullaer.materialdatetimepicker.time.TimePickerDialog; + +import java.util.ArrayList; + +class UpdateAdapter extends ArrayAdapter { + + + private final ArrayList horaires; + private final Context context; + private final FragmentManager fm; + + public UpdateAdapter(Context context, ArrayList objects, FragmentManager fm) { + super(context, R.layout.update_horaire_item, objects); + this.context = context; + this.horaires = objects; + this.fm = fm; + } + + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View rowView = inflater.inflate(R.layout.update_horaire_item, parent, false); + final Horaires h = horaires.get(position); + final TextView timeFrom = (TextView) rowView.findViewById(R.id.from); + timeFrom.setText(String.format("%02d", h.getFrom_h()) + ":" + String.format("%02d", h.getFrom_m())); + final TextView timeTo = (TextView) rowView.findViewById(R.id.to); + timeTo.setText(String.format("%02d", h.getTo_h()) + ":" + String.format("%02d", h.getTo_m())); + String[] days = {"Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"}; + ArrayAdapter adapter = new ArrayAdapter(this.context, R.layout.spinner_item, days); + final Spinner s = (Spinner) rowView.findViewById(R.id.spinner); + s.setAdapter(adapter); + s.setSelection(h.getDay() - 1); + + s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + h.setDay(position + 1); + s.setSelection(position); + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + }); + + + timeFrom.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + TimePickerDialog f = TimePickerDialog.newInstance(new TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(RadialPickerLayout radialPickerLayout, int hours, int minutes) { + if (minutes % 5 == 0) { + timeFrom.setText(String.format("%02d", hours) + ":" + String.format("%02d", minutes)); + h.setFrom_h(hours); + h.setFrom_m(minutes); + } else { + Toast.makeText(context, "Merci d'utiliser des tranches de 5 minutes maximum", Toast.LENGTH_SHORT).show(); + } + } + }, h.getFrom_h(), h.getFrom_m(), true); + f.show(fm, "from"); + } + }); + + timeTo.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + TimePickerDialog t = TimePickerDialog.newInstance(new TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(RadialPickerLayout radialPickerLayout, int hours, int minutes) { + if (minutes % 5 == 0) { + timeTo.setText(String.format("%02d", hours) + ":" + String.format("%02d", minutes)); + h.setTo_h(hours); + h.setTo_m(minutes); + } else { + Toast.makeText(context, "Merci d'utiliser des tranches de 5 minutes maximum", Toast.LENGTH_SHORT).show(); + } + } + }, h.getTo_h(), h.getTo_m(), true); + t.show(fm, "to"); + } + }); + + return rowView; + } +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/bdd/FavorisBdd.java b/Les Horaires/src/main/java/com/amine/horaires/bdd/FavorisBdd.java new file mode 100644 index 0000000..f85a63c --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/bdd/FavorisBdd.java @@ -0,0 +1,58 @@ +package com.amine.horaires.bdd; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +class FavorisBdd extends SQLiteOpenHelper { + + private static final String TABLE_FAVORIS = "shop_favoris"; + private static final String COL_ID = "ID"; + private static final String COL_NOM = "Nom"; + private static final String COL_ADR = "Adresse"; + private static final String COL_ZIP = "Zip"; + private static final String COL_LAT = "Lat"; + private static final String COL_LNG = "Lng"; + private static final String COL_TEL = "Tel"; + private static final String COL_CITY = "City"; + private static final String COL_OUVERT = "Ouvert"; + private static final String COL_HORAIRES = "Horaires"; + private static final String COL_URL = "Url"; + private static final String COL_OPENSTATUS = "OpenStatus"; + private static final String COL_PARKING = "Parking"; + private static final String COL_WIFI = "Wifi"; + private static final String COL_HANDI = "Handi"; + private static final String COL_IDPOI = "IDPoi"; + + private static final String CREATE_BDD = "CREATE TABLE " + TABLE_FAVORIS + " (" + + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + + COL_NOM + " TEXT, " + + COL_ADR + " TEXT, " + + COL_ZIP + " INTEGER, " + + COL_LAT + " TEXT, " + + COL_LNG + " TEXT, " + + COL_TEL + " VARCHAR(40), " + + COL_CITY + " TEXT, " + + COL_OUVERT + " SHORT, " + + COL_HORAIRES + " TEXT, " + + COL_URL + " TEXT, " + + COL_OPENSTATUS + " TEXT, " + + COL_PARKING + " SHORT, " + + COL_WIFI + " SHORT, " + + COL_HANDI + " SHORT, " + + COL_IDPOI + " VARCHAR(40) NOT NULL);"; + + public FavorisBdd(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { + super(context, name, factory, version); + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL(CREATE_BDD); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + + } +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/bdd/FavorisDao.java b/Les Horaires/src/main/java/com/amine/horaires/bdd/FavorisDao.java new file mode 100644 index 0000000..d2f1ee5 --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/bdd/FavorisDao.java @@ -0,0 +1,159 @@ +package com.amine.horaires.bdd; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import com.amine.horaires.models.Shop; + +import java.util.ArrayList; + +public class FavorisDao { + private static final int VERSION_BDD = 1;// pour le onupgrade de BaseSQL + private static final String NOM_BDD = "shops.db"; + + private static final String TABLE_FAVORIS = "shop_favoris"; + private static final String COL_NOM = "Nom"; + private static final String COL_ADR = "Adresse"; + private static final String COL_ZIP = "Zip"; + private static final String COL_LAT = "Lat"; + private static final String COL_LNG = "Lng"; + private static final String COL_TEL = "Tel"; + private static final String COL_CITY = "City"; + private static final String COL_OUVERT = "Ouvert"; + private static final String COL_HORAIRES = "Horaires"; + private static final String COL_URL = "Url"; + private static final String COL_OPENSTATUS = "OpenStatus"; + private static final String COL_PARKING = "Parking"; + private static final String COL_WIFI = "Wifi"; + private static final String COL_HANDI = "Handi"; + private static final String COL_IDPOI = "IDPoi"; + + private static final int NUM_COL_NOM = 1; + private static final int NUM_COL_ADR = 2; + private static final int NUM_COL_ZIP = 3; + private static final int NUM_COL_LAT = 4; + private static final int NUM_COL_LNG = 5; + private static final int NUM_COL_TEL = 6; + private static final int NUM_COL_CITY = 7; + private static final int NUM_COL_OUVERT = 8; + private static final int NUM_COL_HORAIRES = 9; + private static final int NUM_COL_URL = 10; + private static final int NUM_COL_OPENSTATUS = 11; + private static final int NUM_COL_PARKING = 12; + private static final int NUM_COL_WIFI = 13; + private static final int NUM_COL_HANDI = 14; + private static final int NUM_COL_IDPOI = 15; + private static FavorisDao instance = null; + private final FavorisBdd maBaseSQLite; + private SQLiteDatabase bdd; + + private FavorisDao(Context context) { + maBaseSQLite = new FavorisBdd(context, NOM_BDD, null, VERSION_BDD); + } + + public static FavorisDao getInstance(Context c) { + if (instance == null) { + instance = new FavorisDao(c); + return instance; + } else { + return instance; + } + } + + public void open() { + bdd = maBaseSQLite.getWritableDatabase(); + } + + public void close() { + bdd.close(); + } + + public void insertFavori(Shop favori) { + ContentValues values = getContentValues(favori); + bdd.insert(TABLE_FAVORIS, null, values); + } + + private ContentValues getContentValues(Shop favori) { + ContentValues values = new ContentValues(); + values.put(COL_IDPOI, favori.getId()); + values.put(COL_NOM, favori.getName()); + values.put(COL_ADR, favori.getAdresse()); + values.put(COL_ZIP, favori.getZip()); + values.put(COL_LAT, favori.getLat()); + values.put(COL_LNG, favori.getLng()); + values.put(COL_TEL, favori.getTel()); + values.put(COL_CITY, favori.getCity()); + values.put(COL_OUVERT, favori.isOuvert()); + values.put(COL_HORAIRES, favori.getHoraires()); + values.put(COL_URL, favori.getUrl()); + values.put(COL_OPENSTATUS, favori.getOpenStatus()); + values.put(COL_PARKING, favori.isParking()); + values.put(COL_WIFI, favori.isWifi()); + values.put(COL_HANDI, favori.isAccesHandicape()); + return values; + } + + public void updateFavori(Shop favori) { + ContentValues values = getContentValues(favori); + bdd.update(TABLE_FAVORIS, values, COL_IDPOI + " LIKE " + "\"" + favori.getId() + "\"", null); + } + + public void deleteFavori(int id) { + bdd.delete(TABLE_FAVORIS, COL_IDPOI + " LIKE \"" + id + "\"", null); + } + + public Shop getFavori(int id) { + Cursor c = bdd.query(TABLE_FAVORIS, null, COL_IDPOI + " LIKE \"" + id + + "\"", null, null, null, null); + c.moveToFirst(); + Shop s = cursorToFavori(c); + c.close(); + return s; + } + + private Shop cursorToFavori(Cursor c) { + if (c.getCount() == 0) { + return null; + } else { + Shop f = new Shop(); + f.setId(c.getInt(NUM_COL_IDPOI)); + f.setName(c.getString(NUM_COL_NOM)); + f.setAdresse(c.getString(NUM_COL_ADR)); + f.setZip(c.getString(NUM_COL_ZIP)); + f.setLat(c.getString(NUM_COL_LAT)); + f.setLng(c.getString(NUM_COL_LNG)); + f.setTel(c.getString(NUM_COL_TEL)); + f.setCity(c.getString(NUM_COL_CITY)); + f.setOuvert(c.getShort(NUM_COL_OUVERT) != 0); + f.setHoraires(c.getString(NUM_COL_HORAIRES)); + f.setUrl(c.getString(NUM_COL_URL)); + f.setOpenStatus(c.getString(NUM_COL_OPENSTATUS)); + f.setParking(c.getShort(NUM_COL_PARKING) != 0); + f.setWifi(c.getShort(NUM_COL_WIFI) != 0); + f.setAccesHandicape(c.getShort(NUM_COL_HANDI) != 0); + f.setId(c.getInt(NUM_COL_IDPOI)); + return f; + } + } + + public ArrayList getAllFavoris() { + Cursor c = bdd.rawQuery("SELECT * FROM " + TABLE_FAVORIS, null); + return cursorToListeFavoris(c); + } + + private ArrayList cursorToListeFavoris(Cursor cursor) { + ArrayList list = new ArrayList(); + if (cursor.getCount() != 0) { + if (cursor.moveToFirst()) { + while (!cursor.isAfterLast()) { + + list.add(cursorToFavori(cursor)); + cursor.moveToNext(); + } + } + } + cursor.close(); + return list; + } +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/models/Horaires.java b/Les Horaires/src/main/java/com/amine/horaires/models/Horaires.java new file mode 100644 index 0000000..32e139e --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/models/Horaires.java @@ -0,0 +1,112 @@ +package com.amine.horaires.models; + +import android.support.annotation.NonNull; + +public class Horaires implements Comparable { + /* + periods[N][title] Title of N period - optional + periods[N][T][day] 1 (Monday) to 7 (Sunday) - Day of opening window T for period N + periods[N][T][from_h] 0 to 23 - Hour of beginning of opening window T for period N + periods[N][T][from_m] 0 to 59 (minutes) - Minute of beginning of opening window T for period N + periods[N][T][to_h] 0 to 32 (8am the next morning) - Hour of end of opening window T for period N + periods[N][T][to_m] 0 to 59 (minutes) - Minute of end of opening window T for period N + */ + + private int day; + private int from_h; + private int from_m; + private int to_h; + private int to_m; + + public Horaires(int day) { + this.day = day; + this.from_h = 8; + this.from_m = 0; + this.to_h = 18; + this.to_m = 0; + } + + public Horaires() { + this.day = 1; + this.from_h = 8; + this.from_m = 0; + this.to_h = 18; + this.to_m = 0; + } + + public Horaires(Horaires h) { + this.day = h.getDay(); + this.from_h = h.getFrom_h(); + this.from_m = h.getFrom_m(); + this.to_h = h.getTo_h(); + this.to_m = h.getTo_m(); + } + + public int getDay() { + return day; + } + + public void setDay(int day) { + this.day = day; + } + + public int getFrom_h() { + return from_h; + } + + public void setFrom_h(int from_h) { + this.from_h = from_h; + } + + public int getFrom_m() { + return from_m; + } + + public void setFrom_m(int from_m) { + this.from_m = from_m; + } + + public int getTo_h() { + return to_h; + } + + public void setTo_h(int to_h) { + this.to_h = to_h; + } + + public int getTo_m() { + return to_m; + } + + public void setTo_m(int to_m) { + this.to_m = to_m; + } + + + @Override + public int compareTo(@NonNull Object another) { + Horaires h = (Horaires) another; + return this.day - h.day; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Horaires horaires = (Horaires) o; + + return this.day == horaires.day; + + } + + @Override + public int hashCode() { + int result = day; + result = 31 * result + from_h; + result = 31 * result + from_m; + result = 31 * result + to_h; + result = 31 * result + to_m; + return result; + } +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/models/Shop.java b/Les Horaires/src/main/java/com/amine/horaires/models/Shop.java new file mode 100644 index 0000000..78d96b4 --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/models/Shop.java @@ -0,0 +1,240 @@ +package com.amine.horaires.models; + +import android.os.Parcel; +import android.os.Parcelable; + +public class Shop implements Parcelable { + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override + public Shop createFromParcel(Parcel source) { + return new Shop(source); + } + + @Override + public Shop[] newArray(int size) { + return new Shop[size]; + } + }; + private int id; + private String name; + private String adresse; + private String zip; + private String lat; + private String lng; + private String tel; + private String city; + private boolean ouvert; + private String horaires; + private String url; + private String openStatus; + private boolean parking; + private boolean wifi; + private boolean AccesHandicape; + + public Shop() { + } + + public Shop(int id, String name, String adresse, String zip, String lat, + String lng, String tel, String city, + boolean ouvert, String horaires, String url, String openStatus, + boolean parking, boolean wifi, boolean accesHandicape) { + this.id = id; + this.name = name; + this.adresse = adresse; + this.zip = zip; + this.lat = lat; + this.lng = lng; + this.tel = tel; + this.city = city; + this.ouvert = ouvert; + this.horaires = horaires; + this.url = url; + this.openStatus = openStatus; + this.parking = parking; + this.wifi = wifi; + AccesHandicape = accesHandicape; + } + + private Shop(Parcel in) { + id = in.readInt(); + name = in.readString(); + adresse = in.readString(); + zip = in.readString(); + lat = in.readString(); + lng = in.readString(); + tel = in.readString(); + city = in.readString(); + ouvert = in.readByte() != 0; + horaires = in.readString(); + url = in.readString(); + openStatus = in.readString(); + parking = in.readByte() != 0; + wifi = in.readByte() != 0; + AccesHandicape = in.readByte() != 0; + } + + @Override + public String toString() { + return "Shop{" + + "id=" + id + + ", name='" + name + '\'' + + ", adresse='" + adresse + '\'' + + ", zip='" + zip + '\'' + + ", lat='" + lat + '\'' + + ", lng='" + lng + '\'' + + ", tel='" + tel + '\'' + + ", city='" + city + '\'' + + ", ouvert=" + ouvert + + ", horaires='" + horaires + '\'' + + ", url='" + url + '\'' + + ", openStatus='" + openStatus + '\'' + + ", parking=" + parking + + ", wifi=" + wifi + + ", AccesHandicape=" + AccesHandicape + + '}'; + } + + public boolean isAccesHandicape() { + return AccesHandicape; + } + + public void setAccesHandicape(boolean accesHandicape) { + AccesHandicape = accesHandicape; + } + + public String getOpenStatus() { + return openStatus; + } + + public void setOpenStatus(String openStatus) { + this.openStatus = openStatus; + } + + public boolean isParking() { + return parking; + } + + public void setParking(boolean parking) { + this.parking = parking; + } + + public boolean isWifi() { + return wifi; + } + + public void setWifi(boolean wifi) { + this.wifi = wifi; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getTel() { + return tel; + } + + public void setTel(String tel) { + this.tel = tel; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAdresse() { + return adresse; + } + + public void setAdresse(String adresse) { + this.adresse = adresse; + } + + public String getLat() { + return lat; + } + + public void setLat(String lat) { + this.lat = lat; + } + + public String getLng() { + return lng; + } + + public void setLng(String lng) { + this.lng = lng; + } + + public boolean isOuvert() { + return ouvert; + } + + public void setOuvert(boolean ouvert) { + this.ouvert = ouvert; + } + + public String getHoraires() { + return horaires; + } + + public void setHoraires(String horaires) { + this.horaires = horaires; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getZip() { + return zip; + } + + public void setZip(String zip) { + this.zip = zip; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(id); + dest.writeString(name); + dest.writeString(adresse); + dest.writeString(zip); + dest.writeString(lat); + dest.writeString(lng); + dest.writeString(tel); + dest.writeString(city); + dest.writeByte((byte) (ouvert ? 1 : 0)); + dest.writeString(horaires); + dest.writeString(url); + dest.writeString(openStatus); + dest.writeByte((byte) (parking ? 1 : 0)); + dest.writeByte((byte) (wifi ? 1 : 0)); + dest.writeByte((byte) (AccesHandicape ? 1 : 0)); + } +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/util/Configuration.java b/Les Horaires/src/main/java/com/amine/horaires/util/Configuration.java new file mode 100644 index 0000000..5fd5767 --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/util/Configuration.java @@ -0,0 +1,23 @@ +package com.amine.horaires.util; + +import com.amine.horaires.models.Shop; + +public class Configuration { + // Cles necessaires pour l'api lesHorraires + public static final String key = "REPLACE_THIS_WITH_KEY"; + public static final String hashtag = "REPLACE_THIS_WITH_A_HASHTAG"; + public static String pays = "FR"; + public static Shop currentShop = null; + + public static String getAPIUrl() { + if (pays.equals("FR")) + return "http://www.les-horaires.fr"; + else if (pays.equals("GB")) + return "http://www.shopping-time.co.uk"; + else if (pays.equals("US")) + return "http://www.shopping-time.com"; + + return "http://www.les-horaires.fr"; + } + +} diff --git a/Les Horaires/src/main/java/com/amine/horaires/util/MyLocation.java b/Les Horaires/src/main/java/com/amine/horaires/util/MyLocation.java new file mode 100644 index 0000000..277ff91 --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/util/MyLocation.java @@ -0,0 +1,129 @@ +package com.amine.horaires.util; + +import android.content.Context; +import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.os.Bundle; +import android.util.Log; + +import java.util.Timer; +import java.util.TimerTask; + +// http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location-in-a/3145655#3145655 +public class MyLocation { + private Timer timer1; + private LocationManager lm; + private LocationResult locationResult; + private final LocationListener locationListenerGps = new LocationListener() { + public void onLocationChanged(Location location) { + timer1.cancel(); + locationResult.gotLocation(location); + lm.removeUpdates(this); + lm.removeUpdates(locationListenerNetwork); + } + + public void onProviderDisabled(String provider) { + } + + public void onProviderEnabled(String provider) { + } + + public void onStatusChanged(String provider, int status, Bundle extras) { + } + }; + private final LocationListener locationListenerNetwork = new LocationListener() { + public void onLocationChanged(Location location) { + timer1.cancel(); + locationResult.gotLocation(location); + lm.removeUpdates(this); + lm.removeUpdates(locationListenerGps); + } + + public void onProviderDisabled(String provider) { + } + + public void onProviderEnabled(String provider) { + } + + public void onStatusChanged(String provider, int status, Bundle extras) { + } + }; + private boolean gps_enabled = false; + private boolean network_enabled = false; + + public boolean getLocation(Context context, LocationResult result) { + locationResult = result; + if (lm == null) + lm = (LocationManager) context + .getSystemService(Context.LOCATION_SERVICE); + + try { + gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); + } catch (Exception ex) { + Log.w("LOC", "gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);"); + } + try { + network_enabled = lm + .isProviderEnabled(LocationManager.NETWORK_PROVIDER); + } catch (Exception ex) { + Log.w("LOC", "network_enabled = lm .isProviderEnabled(LocationManager.NETWORK_PROVIDER);"); + } + + if (!gps_enabled && !network_enabled) + return false; + + if (gps_enabled) + lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, + locationListenerGps); + if (network_enabled) + lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, + locationListenerNetwork); + timer1 = new Timer(); + timer1.schedule(new GetLastLocation(), 20000); + return true; + } + + public void cancelTimer() { + timer1.cancel(); + lm.removeUpdates(locationListenerGps); + lm.removeUpdates(locationListenerNetwork); + } + + public static abstract class LocationResult { + public abstract void gotLocation(Location location); + } + + private class GetLastLocation extends TimerTask { + @Override + public void run() { + lm.removeUpdates(locationListenerGps); + lm.removeUpdates(locationListenerNetwork); + + Location net_loc = null, gps_loc = null; + if (gps_enabled) + gps_loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); + if (network_enabled) + net_loc = lm + .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + + if (gps_loc != null && net_loc != null) { + if (gps_loc.getTime() > net_loc.getTime()) + locationResult.gotLocation(gps_loc); + else + locationResult.gotLocation(net_loc); + return; + } + + if (gps_loc != null) { + locationResult.gotLocation(gps_loc); + return; + } + if (net_loc != null) { + locationResult.gotLocation(net_loc); + return; + } + locationResult.gotLocation(null); + } + } +} \ No newline at end of file diff --git a/Les Horaires/src/main/java/com/amine/horaires/util/Parseur.java b/Les Horaires/src/main/java/com/amine/horaires/util/Parseur.java new file mode 100644 index 0000000..3cdd4f2 --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/util/Parseur.java @@ -0,0 +1,224 @@ +package com.amine.horaires.util; + +import com.amine.horaires.models.Shop; +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.ArrayList; + +/** + * Parseur qui permet de parcourir le fichier xml genere + */ +public class Parseur { + + /** + * Parcours le fichier xml , insere les donnees de l'utilisateur et son + * historique + * + * @return une arraylist de collections + */ + public ArrayList parserShops(String contenuDuFichier) { + final ArrayList listeMagasins = new ArrayList(); + + try { + + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser saxParser = factory.newSAXParser(); + + DefaultHandler handler = new DefaultHandler() { + Shop magasin; + + boolean url = false; + boolean name = false; + boolean address = false; + boolean ville = false; + boolean zip = false; + boolean lat = false; + boolean lng = false; + boolean tel = false; + boolean img = false; + boolean open = false; + boolean open_status = false; + boolean pmr = false; + boolean wifi = false; + boolean freepark = false; + + public void startElement(String uri, String localName, + String qName, Attributes attributes) + throws SAXException { + + if (qName.equalsIgnoreCase("shop")) + magasin = new Shop(); + + if (qName.equalsIgnoreCase("url")) + url = true; + + if (qName.equalsIgnoreCase("name")) + name = true; + + if (qName.equalsIgnoreCase("address")) + address = true; + + if (qName.equalsIgnoreCase("city")) + ville = true; + + if (qName.equalsIgnoreCase("zip")) + zip = true; + + if (qName.equalsIgnoreCase("lat")) + lat = true; + + if (qName.equalsIgnoreCase("lng")) + lng = true; + + if (qName.equalsIgnoreCase("tel")) + tel = true; + + if (qName.equalsIgnoreCase("img")) + img = true; + + if (qName.equalsIgnoreCase("open")) + open = true; + + if (qName.equalsIgnoreCase("open_status")) + open_status = true; + + if (qName.equalsIgnoreCase("pmr")) + pmr = true; + + if (qName.equalsIgnoreCase("pmr")) + pmr = true; + + if (qName.equalsIgnoreCase("wifi")) + wifi = true; + + if (qName.equalsIgnoreCase("freepark")) + freepark = true; + + if (qName.equalsIgnoreCase("shop")) { + int length = attributes.getLength(); + + for (int i = 0; i < length; i++) { + String nameA = attributes.getQName(i); + String valueA = attributes.getValue(i); + + if (nameA.compareTo("id") == 0) { + magasin.setId(Integer.parseInt(valueA)); + } + + } + } + } + + public void endElement(String uri, String localName, + String qName) throws SAXException { + + if (qName.equalsIgnoreCase("shop")) + listeMagasins.add(magasin); + + } + + public void characters(char ch[], int start, int length) + throws SAXException { + + if (url) { + magasin.setUrl(new String(ch, start, length)); + url = false; + } + + if (name) { + magasin.setName(new String(ch, start, length)); + name = false; + } + + if (address) { + magasin.setAdresse(new String(ch, start, length)); + address = false; + } + + if (ville) { + magasin.setCity(new String(ch, start, length)); + ville = false; + } + + if (zip) { + magasin.setZip(new String(ch, start, length)); + zip = false; + } + + if (lat) { + magasin.setLat(new String(ch, start, length)); + lat = false; + } + + if (lng) { + magasin.setLng(new String(ch, start, length)); + lng = false; + } + + if (tel) { + magasin.setTel(new String(ch, start, length)); + tel = false; + } + + if (img) { + magasin.setHoraires(new String(ch, start, length)); + img = false; + } + + if (open) { + magasin.setOuvert(new String(ch, start, length) + .compareTo("1") == 0); + open = false; + } + + if (open_status) { + magasin.setOpenStatus(new String(ch, start, length)); + open_status = false; + } + + if (pmr) { + magasin.setAccesHandicape(new String(ch, start, length) + .compareTo("1") == 0); + pmr = false; + } + + if (wifi) { + magasin.setWifi(new String(ch, start, length) + .compareTo("1") == 0); + wifi = false; + } + + if (freepark) { + magasin.setParking(new String(ch, start, length) + .compareTo("1") == 0); + freepark = false; + } + } + + }; + + InputStream inputStream = new ByteArrayInputStream( + contenuDuFichier.getBytes()); + Reader reader = new InputStreamReader(inputStream, "UTF-8"); + + InputSource is = new InputSource(reader); + is.setEncoding("UTF-8"); + + saxParser.parse(is, handler); + + } catch (Exception e) { + e.printStackTrace(); + } + + return listeMagasins; + } +} \ No newline at end of file diff --git a/Les Horaires/src/main/java/com/amine/horaires/util/Utils.java b/Les Horaires/src/main/java/com/amine/horaires/util/Utils.java new file mode 100644 index 0000000..fb2de9f --- /dev/null +++ b/Les Horaires/src/main/java/com/amine/horaires/util/Utils.java @@ -0,0 +1,64 @@ +package com.amine.horaires.util; + +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLEncoder; + +public class Utils { + public static URL generateUrlForTextLocation(String name, String location) { + try { + return new URL(Configuration.getAPIUrl() + "/api?key=" + + Configuration.key + "&h=" + Configuration.hashtag + + "&get=shops" + "&loc=" + URLEncoder.encode(location, "ISO-8859-1") + + "&name=" + URLEncoder.encode(name, "ISO-8859-1")); + } catch (MalformedURLException e) { + e.printStackTrace(); + return null; + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + return null; + } + } + + public static URL generateUrlForLatLng(String name, String lat, + String lng) { + try { + + return new URL(Configuration.getAPIUrl() + "/api?key=" + + Configuration.key + "&h=" + Configuration.hashtag + + "&get=shops" + "&lng=" + lng + "&lat=" + lat + "&name=" + + URLEncoder.encode(name, "ISO-8859-1") + "&order=distance"); + } catch (MalformedURLException e) { + e.printStackTrace(); + return null; + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + return null; + } + } + + public static URL generateUrlForId(int idPoi) { + try { + + return new URL(Configuration.getAPIUrl() + "/api?key=" + + Configuration.key + "&h=" + Configuration.hashtag + + "&get=shop" + "&id=" + idPoi); + } catch (MalformedURLException e) { + e.printStackTrace(); + return null; + } + } + + public static URL generateUrlForEdit(int idPoi, String periodsString) { + try { + + return new URL(Configuration.getAPIUrl() + "/api?key=" + + Configuration.key + "&h=" + Configuration.hashtag + + "&get=edit" + "&id=" + idPoi + periodsString); + } catch (MalformedURLException e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/Les Horaires/src/main/res/layout/activity_main.xml b/Les Horaires/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..9dbb986 --- /dev/null +++ b/Les Horaires/src/main/res/layout/activity_main.xml @@ -0,0 +1,43 @@ + + + + + + + + + diff --git a/Les Horaires/src/main/res/layout/activity_more.xml b/Les Horaires/src/main/res/layout/activity_more.xml new file mode 100644 index 0000000..32ed717 --- /dev/null +++ b/Les Horaires/src/main/res/layout/activity_more.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Les Horaires/src/main/res/layout/fav_list_item.xml b/Les Horaires/src/main/res/layout/fav_list_item.xml new file mode 100644 index 0000000..38d55eb --- /dev/null +++ b/Les Horaires/src/main/res/layout/fav_list_item.xml @@ -0,0 +1,36 @@ + + + + + + + \ No newline at end of file diff --git a/Les Horaires/src/main/res/layout/shop_display.xml b/Les Horaires/src/main/res/layout/shop_display.xml new file mode 100644 index 0000000..277a9fe --- /dev/null +++ b/Les Horaires/src/main/res/layout/shop_display.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Les Horaires/src/main/res/layout/shop_search.xml b/Les Horaires/src/main/res/layout/shop_search.xml new file mode 100644 index 0000000..4b240a9 --- /dev/null +++ b/Les Horaires/src/main/res/layout/shop_search.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + +