From 0d01d62f115ca0201f50a0c149435575ccd03371 Mon Sep 17 00:00:00 2001 From: Florian Staine Date: Mon, 5 Jun 2017 15:29:51 +0200 Subject: [PATCH] Periodic HTTP request --- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 1 + app/src/main/java/fr/utbm/lo53/p2017/positionningapp/PositioningActivity.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/src/main/res/layout/content_positioning.xml | 7 +++++++ 4 files changed, 63 insertions(+), 0 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6ea9c68..68f42f1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,5 +30,6 @@ dependencies { compile 'com.android.support:design:25.3.1' compile 'com.android.support:support-v4:25.3.1' compile 'com.android.support:support-vector-drawable:25.3.1' + compile 'com.android.volley:volley:1.0.0' testCompile 'junit:junit:4.12' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c02bd5e..d72be55 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + () { + @Override + public void onResponse(String response) { + // Display the first 500 characters of the response string. + textView.setText("Response is: "+ response.substring(0,500)); + } + }, new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + Log.d(TAG, error.getCause().toString()); + textView.clearComposingText(); + } + }); + + private final Handler handler = new Handler(); + private final Runnable runnable = new Runnable() { + @Override + public void run() { + // Add the request to the RequestQueue. + queue.add(stringRequest); + handler.postDelayed(this, 1000); + } + }; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -27,6 +70,16 @@ public class PositioningActivity extends BaseActivity { start_layout = (ConstraintLayout) findViewById(R.id.start_layout); hideAnimation = createFadeOutAndHideAnimation(); + + textView = (TextView) findViewById(R.id.ID_yolo); + + queue = Volley.newRequestQueue(this); + } + + @Override + protected void onDestroy() { + handler.removeCallbacks(runnable); + super.onDestroy(); } @Override @@ -39,6 +92,7 @@ public class PositioningActivity extends BaseActivity { public void startLocating(View v) { start_layout.startAnimation(hideAnimation); + handler.post(runnable); } private Animation createFadeOutAndHideAnimation() { diff --git a/app/src/main/res/layout/content_positioning.xml b/app/src/main/res/layout/content_positioning.xml index a6c36d6..42aeb62 100644 --- a/app/src/main/res/layout/content_positioning.xml +++ b/app/src/main/res/layout/content_positioning.xml @@ -23,6 +23,13 @@ android:layout_marginStart="8dp" android:layout_marginEnd="8dp" /> + +