Commit 5b2418c40c339b516ee4a25fa4402e1323c9be7d
1 parent
6cecd44a
Hide map before loading & add loading anim
Showing
5 changed files
with
53 additions
and
31 deletions
Show diff stats
app/src/main/java/fr/utbm/lo53/p2017/positionningapp/PositioningActivity.java
... | ... | @@ -8,6 +8,7 @@ import android.os.Build; |
8 | 8 | import android.os.Bundle; |
9 | 9 | import android.os.Handler; |
10 | 10 | import android.support.constraint.ConstraintLayout; |
11 | +import android.support.design.widget.Snackbar; | |
11 | 12 | import android.support.v7.widget.Toolbar; |
12 | 13 | import android.util.Log; |
13 | 14 | import android.view.Menu; |
... | ... | @@ -16,8 +17,9 @@ import android.view.View; |
16 | 17 | import android.view.animation.AccelerateInterpolator; |
17 | 18 | import android.view.animation.AlphaAnimation; |
18 | 19 | import android.view.animation.Animation; |
20 | +import android.view.animation.AnimationUtils; | |
21 | +import android.view.animation.RotateAnimation; | |
19 | 22 | import android.widget.ImageView; |
20 | -import android.widget.TextView; | |
21 | 23 | |
22 | 24 | import com.android.volley.Request; |
23 | 25 | import com.android.volley.RequestQueue; |
... | ... | @@ -41,8 +43,8 @@ public class PositioningActivity extends BaseActivity { |
41 | 43 | private static final String TAG = "PositioningActivity"; |
42 | 44 | |
43 | 45 | private ConstraintLayout start_layout; |
44 | - private TextView textView; | |
45 | 46 | private ImageView mapView; |
47 | + private ImageView imageLoading; | |
46 | 48 | |
47 | 49 | private Animation hideAnimation; |
48 | 50 | |
... | ... | @@ -67,16 +69,15 @@ public class PositioningActivity extends BaseActivity { |
67 | 69 | try { |
68 | 70 | float x = (float) response.getDouble("x"); |
69 | 71 | float y = (float) response.getDouble("y"); |
70 | - int mapId = response.getInt("map_id"); | |
72 | + int mapId = response.getInt("map"); | |
73 | + imageLoading.setVisibility(View.GONE); | |
71 | 74 | if (hasCorrectMap(mapId)) { |
72 | 75 | putPoint(x, y); |
73 | - textView.setText(""); | |
74 | 76 | } else { |
75 | 77 | getMap(mapId); |
76 | 78 | } |
77 | 79 | } catch (JSONException e) { |
78 | - Log.e(TAG, e.toString()); | |
79 | - textView.setText("Could not parse the response !"); | |
80 | + Log.e(TAG, "Could not parse the response: " + e.toString()); | |
80 | 81 | } |
81 | 82 | } |
82 | 83 | }, new Response.ErrorListener() { |
... | ... | @@ -85,8 +86,7 @@ public class PositioningActivity extends BaseActivity { |
85 | 86 | // TODO: Remove random position |
86 | 87 | Random r = new Random(); |
87 | 88 | putPoint(r.nextFloat(), r.nextFloat()); |
88 | - textView.setText("Error: " + error.getMessage()); | |
89 | - Log.i(TAG, "Error during location request"); | |
89 | + Snackbar.make(mapView, "Error during positioning request", Snackbar.LENGTH_LONG).show(); | |
90 | 90 | } |
91 | 91 | }); |
92 | 92 | Log.v(TAG, "" + locateRequest); |
... | ... | @@ -106,10 +106,10 @@ public class PositioningActivity extends BaseActivity { |
106 | 106 | start_layout = (ConstraintLayout) findViewById(R.id.start_layout); |
107 | 107 | initFadeOutAndHideAnimation(); |
108 | 108 | |
109 | - textView = (TextView) findViewById(R.id.ID_yolo); | |
110 | - | |
111 | 109 | mapView = (ImageView) findViewById(R.id.map); |
112 | 110 | |
111 | + imageLoading = (ImageView) findViewById(R.id.img_loading); | |
112 | + | |
113 | 113 | queue = Volley.newRequestQueue(this); |
114 | 114 | } |
115 | 115 | |
... | ... | @@ -140,8 +140,13 @@ public class PositioningActivity extends BaseActivity { |
140 | 140 | if (isLocating) { |
141 | 141 | return; |
142 | 142 | } |
143 | - | |
144 | 143 | isLocating = true; |
144 | + | |
145 | + final Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate); | |
146 | + rotate.setDuration(1500); | |
147 | + imageLoading.setVisibility(View.VISIBLE); | |
148 | + imageLoading.startAnimation(rotate); | |
149 | + | |
145 | 150 | start_layout.startAnimation(hideAnimation); |
146 | 151 | |
147 | 152 | handler.post(runnable); |
... | ... | @@ -179,19 +184,22 @@ public class PositioningActivity extends BaseActivity { |
179 | 184 | } |
180 | 185 | |
181 | 186 | private void getMap(int mapId) { |
187 | + mapView.setVisibility(mapView.INVISIBLE); | |
182 | 188 | ImageRequest mapRequest = new ImageRequest( |
183 | - getURLSolver().mapDataURL(mapId), | |
189 | + getURLSolver().mapBytesURL(mapId), | |
184 | 190 | new Response.Listener<Bitmap>() { |
185 | 191 | @Override |
186 | 192 | public void onResponse(Bitmap bitmap) { |
187 | 193 | mapView.setImageBitmap(bitmap); |
188 | 194 | mapView.setVisibility(mapView.VISIBLE); |
195 | + Snackbar.make(mapView, "You need to set a point before measurement.", Snackbar.LENGTH_LONG) | |
196 | + .setAction("Action", null).show(); | |
189 | 197 | } |
190 | 198 | }, 0, 0, null, |
191 | 199 | new Response.ErrorListener() { |
192 | 200 | public void onErrorResponse(VolleyError error) { |
193 | - mapView.setImageResource(R.drawable.map2); | |
194 | - textView.setText("Can't load map!!!"); | |
201 | + Snackbar.make(mapView, "Can't load map !", Snackbar.LENGTH_LONG) | |
202 | + .setAction("Action", null).show(); | |
195 | 203 | } |
196 | 204 | }); |
197 | 205 | queue.add(mapRequest); | ... | ... |
app/src/main/java/fr/utbm/lo53/p2017/positionningapp/network/URLSolver.java
... | ... | @@ -46,14 +46,14 @@ public class URLSolver implements SharedPreferences.OnSharedPreferenceChangeList |
46 | 46 | |
47 | 47 | private Uri.Builder baseURL() { |
48 | 48 | Uri.Builder builder = new Uri.Builder(); |
49 | - return builder.scheme("http").encodedAuthority(hostname + ":" + port); | |
49 | + return builder.scheme("http").encodedAuthority(hostname + ":" + port).appendPath("positioning_server"); | |
50 | 50 | } |
51 | 51 | |
52 | 52 | public String locateURL(String mac) { |
53 | 53 | Uri.Builder b = baseURL(); |
54 | 54 | b.appendPath("positioning") |
55 | 55 | .appendPath("request") |
56 | - .appendQueryParameter("mac", mac); | |
56 | + .appendQueryParameter("CLIENT_MAC_ADDR", mac); | |
57 | 57 | return b.build().toString(); |
58 | 58 | } |
59 | 59 | |
... | ... | @@ -67,9 +67,11 @@ public class URLSolver implements SharedPreferences.OnSharedPreferenceChangeList |
67 | 67 | return b.build().toString(); |
68 | 68 | } |
69 | 69 | |
70 | - public String mapDataURL(int mapId) { | |
70 | + public String mapBytesURL(int mapId) { | |
71 | 71 | Uri.Builder b = baseURL(); |
72 | - b.appendPath("static").appendPath("map.png"); | |
72 | + b.appendPath("map") | |
73 | + .appendPath("byte") | |
74 | + .appendQueryParameter("MAP_ID", String.format("%d", mapId)); | |
73 | 75 | return b.build().toString(); |
74 | 76 | } |
75 | 77 | } | ... | ... |
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<rotate xmlns:android="http://schemas.android.com/apk/res/android" | |
3 | + android:fromDegrees="0" | |
4 | + android:interpolator="@android:anim/linear_interpolator" | |
5 | + android:pivotX="50%" | |
6 | + android:pivotY="50%" | |
7 | + android:repeatCount="infinite" | |
8 | + android:toDegrees="360" /> | ... | ... |
369 Bytes
app/src/main/res/layout/content_positioning.xml
... | ... | @@ -14,11 +14,10 @@ |
14 | 14 | android:layout_height="wrap_content" |
15 | 15 | android:layout_marginEnd="8dp" |
16 | 16 | android:layout_marginLeft="0dp" |
17 | - android:layout_marginRight="8dp" | |
17 | + android:layout_marginRight="0dp" | |
18 | 18 | android:layout_marginStart="8dp" |
19 | - android:layout_marginTop="8dp" | |
19 | + android:layout_marginTop="0dp" | |
20 | 20 | android:adjustViewBounds="true" |
21 | - android:scaleType="fitXY" | |
22 | 21 | android:visibility="invisible" |
23 | 22 | app:layout_constraintLeft_toLeftOf="parent" |
24 | 23 | app:layout_constraintRight_toRightOf="parent" |
... | ... | @@ -46,16 +45,6 @@ |
46 | 45 | app:layout_constraintVertical_bias="0.0" |
47 | 46 | app:srcCompat="@drawable/map_marker" /> |
48 | 47 | |
49 | - <TextView | |
50 | - android:id="@+id/ID_yolo" | |
51 | - android:layout_width="wrap_content" | |
52 | - android:layout_height="wrap_content" | |
53 | - android:text="TextView" | |
54 | - android:textAppearance="@style/TextAppearance.AppCompat.Medium" | |
55 | - tools:layout_editor_absoluteX="0dp" | |
56 | - android:layout_marginTop="0dp" | |
57 | - app:layout_constraintTop_toBottomOf="@+id/start_layout" /> | |
58 | - | |
59 | 48 | <android.support.constraint.ConstraintLayout |
60 | 49 | android:id="@+id/start_layout" |
61 | 50 | android:layout_width="0dp" |
... | ... | @@ -93,4 +82,19 @@ |
93 | 82 | app:layout_constraintTop_toTopOf="parent" /> |
94 | 83 | </android.support.constraint.ConstraintLayout> |
95 | 84 | |
85 | + <ImageView | |
86 | + android:id="@+id/img_loading" | |
87 | + android:layout_width="wrap_content" | |
88 | + android:layout_height="wrap_content" | |
89 | + android:visibility="invisible" | |
90 | + app:srcCompat="@drawable/ic_autorenew_black_24dp" | |
91 | + android:layout_marginRight="8dp" | |
92 | + app:layout_constraintRight_toRightOf="parent" | |
93 | + android:layout_marginLeft="8dp" | |
94 | + app:layout_constraintLeft_toLeftOf="parent" | |
95 | + app:layout_constraintTop_toTopOf="parent" | |
96 | + android:layout_marginTop="8dp" | |
97 | + app:layout_constraintBottom_toBottomOf="parent" | |
98 | + android:layout_marginBottom="8dp" /> | |
99 | + | |
96 | 100 | </android.support.constraint.ConstraintLayout> | ... | ... |