Commit f1048119b960d14d9ec84220e0b4f0483a35f116
1 parent
0c3834bb
Improve UI
Showing
4 changed files
with
71 additions
and
35 deletions
Show diff stats
app/src/main/java/fr/utbm/lo53/p2017/positionningapp/Calibration.java
... | ... | @@ -13,6 +13,7 @@ import android.widget.ArrayAdapter; |
13 | 13 | import android.widget.Button; |
14 | 14 | import android.widget.ImageView; |
15 | 15 | import android.widget.Spinner; |
16 | +import android.widget.TextView; | |
16 | 17 | |
17 | 18 | import com.android.volley.Request; |
18 | 19 | import com.android.volley.RequestQueue; |
... | ... | @@ -20,6 +21,7 @@ import com.android.volley.Response; |
20 | 21 | import com.android.volley.VolleyError; |
21 | 22 | import com.android.volley.toolbox.JsonObjectRequest; |
22 | 23 | import com.android.volley.toolbox.JsonRequest; |
24 | +import com.android.volley.toolbox.StringRequest; | |
23 | 25 | import com.android.volley.toolbox.Volley; |
24 | 26 | |
25 | 27 | import org.json.JSONException; |
... | ... | @@ -46,6 +48,8 @@ public class Calibration extends BaseActivity { |
46 | 48 | final Button cancelButton = (Button) findViewById(R.id.cancelButton); |
47 | 49 | final Button measureButton = (Button) findViewById(R.id.measureButton); |
48 | 50 | final Spinner spinner = (Spinner) findViewById(R.id.spinner); |
51 | + final TextView txt_spinner = (TextView) findViewById(R.id.txt_select_floor); | |
52 | + | |
49 | 53 | queue = Volley.newRequestQueue(this); |
50 | 54 | |
51 | 55 | ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.map_choices, android.R.layout.simple_spinner_dropdown_item); |
... | ... | @@ -85,6 +89,7 @@ public class Calibration extends BaseActivity { |
85 | 89 | cancelButton.setVisibility(View.VISIBLE); |
86 | 90 | measureButton.setVisibility(View.VISIBLE); |
87 | 91 | spinner.setVisibility(View.INVISIBLE); |
92 | + txt_spinner.setVisibility(View.INVISIBLE); | |
88 | 93 | } |
89 | 94 | }); |
90 | 95 | cancelButton.setOnClickListener(new View.OnClickListener() { |
... | ... | @@ -95,6 +100,7 @@ public class Calibration extends BaseActivity { |
95 | 100 | measureButton.setVisibility(View.INVISIBLE); |
96 | 101 | MapMarker.setVisibility(View.INVISIBLE); |
97 | 102 | spinner.setVisibility(View.VISIBLE); |
103 | + txt_spinner.setVisibility(View.VISIBLE); | |
98 | 104 | } |
99 | 105 | }); |
100 | 106 | spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
... | ... | @@ -127,34 +133,51 @@ public class Calibration extends BaseActivity { |
127 | 133 | Snackbar.make(v, "You need to set a point before measurement.", Snackbar.LENGTH_LONG) |
128 | 134 | .setAction("Action", null).show(); |
129 | 135 | } else { |
130 | - JsonRequest request = new JsonObjectRequest(Request.Method.GET,getURLSolver().calibrateURL(getMacAddress(), width,height,map_id),null, | |
131 | - new Response.Listener<JSONObject>() { | |
132 | - @Override | |
133 | - public void onResponse(JSONObject response) { | |
134 | - try { | |
135 | - String x = response.getString("calibration"); | |
136 | - if(x.equals("try_again")){ | |
137 | - Snackbar.make(v, "An error with the server occurred, please try again", Snackbar.LENGTH_LONG) | |
138 | - .setAction("Action", null).show(); | |
139 | - }else{ | |
140 | - Snackbar.make(v, "Calibration completed", Snackbar.LENGTH_LONG) | |
141 | - .setAction("Action", null).show(); | |
142 | - } | |
143 | - } catch (JSONException e) { | |
144 | - Log.e(TAG, e.toString()); | |
145 | - Snackbar.make(v, "Could not parse the response !", Snackbar.LENGTH_LONG) | |
146 | - .setAction("Action", null).show(); | |
147 | - } | |
148 | - } | |
149 | - }, | |
150 | - new Response.ErrorListener() { | |
136 | + StringRequest request = new StringRequest(Request.Method.GET, getURLSolver().calibrateURL(getMacAddress(), width,height,map_id), | |
137 | + new Response.Listener<String>() { | |
151 | 138 | @Override |
152 | - public void onErrorResponse(VolleyError error) { | |
153 | - Snackbar.make(v, "Error: " + error.getMessage(), Snackbar.LENGTH_LONG) | |
139 | + public void onResponse(String response) { | |
140 | + Snackbar.make(v, "Calibration request sent successfully", Snackbar.LENGTH_SHORT) | |
154 | 141 | .setAction("Action", null).show(); |
155 | - Log.i(TAG, "Error during calibration request"); | |
156 | 142 | } |
157 | - }); | |
143 | + }, new Response.ErrorListener() { | |
144 | + @Override | |
145 | + public void onErrorResponse(VolleyError error) { | |
146 | + Snackbar.make(v, "Error during calibration request", Snackbar.LENGTH_LONG) | |
147 | + .setAction("Action", null).show(); | |
148 | + error.printStackTrace(); | |
149 | + } | |
150 | + }); | |
151 | + | |
152 | +// JsonRequest request = new JsonObjectRequest(Request.Method.GET,getURLSolver().calibrateURL(getMacAddress(), width,height,map_id),null, | |
153 | +// new Response.Listener<JSONObject>() { | |
154 | +// @Override | |
155 | +// public void onResponse(JSONObject response) { | |
156 | +// try { | |
157 | +// String x = response.getString("calibration"); | |
158 | +// if(x.equals("try_again")){ | |
159 | +// Snackbar.make(v, "An error with the server occurred, please try again", Snackbar.LENGTH_LONG) | |
160 | +// .setAction("Action", null).show(); | |
161 | +// }else{ | |
162 | +// Snackbar.make(v, "Calibration completed", Snackbar.LENGTH_LONG) | |
163 | +// .setAction("Action", null).show(); | |
164 | +// } | |
165 | +// } catch (JSONException e) { | |
166 | +// Log.e(TAG, e.toString()); | |
167 | +// Snackbar.make(v, "Could not parse the response !", Snackbar.LENGTH_LONG) | |
168 | +// .setAction("Action", null).show(); | |
169 | +// } | |
170 | +// } | |
171 | +// }, | |
172 | +// new Response.ErrorListener() { | |
173 | +// @Override | |
174 | +// public void onErrorResponse(VolleyError error) { | |
175 | +// Snackbar.make(v, "Error during calibration request", Snackbar.LENGTH_LONG) | |
176 | +// .setAction("Action", null).show(); | |
177 | +// error.printStackTrace(); | |
178 | +// } | |
179 | +// }); | |
180 | + | |
158 | 181 | queue.add(request); |
159 | 182 | Log.i("TAG", String.format("Request : %s", request.getUrl())); |
160 | 183 | } | ... | ... |
app/src/main/java/fr/utbm/lo53/p2017/positionningapp/PositioningActivity.java
... | ... | @@ -44,7 +44,7 @@ public class PositioningActivity extends BaseActivity { |
44 | 44 | |
45 | 45 | private boolean isLocating = false; |
46 | 46 | |
47 | - private Integer mapId = null; | |
47 | + private int mapId = 0; | |
48 | 48 | |
49 | 49 | private final Handler handler = new Handler(); |
50 | 50 | private final Runnable runnable = new Runnable() { |
... | ... | @@ -61,7 +61,6 @@ public class PositioningActivity extends BaseActivity { |
61 | 61 | float x = (float) response.getDouble("x"); |
62 | 62 | float y = (float) response.getDouble("y"); |
63 | 63 | int mapId = response.getInt("map"); |
64 | - imageLoading.setVisibility(View.GONE); | |
65 | 64 | if (hasCorrectMap(mapId)) { |
66 | 65 | putPoint(x, y); |
67 | 66 | } else { |
... | ... | @@ -74,10 +73,7 @@ public class PositioningActivity extends BaseActivity { |
74 | 73 | }, new Response.ErrorListener() { |
75 | 74 | @Override |
76 | 75 | public void onErrorResponse(VolleyError error) { |
77 | - // TODO: Remove random position | |
78 | - Random r = new Random(); | |
79 | - putPoint(r.nextFloat(), r.nextFloat()); | |
80 | - Snackbar.make(mapView, "Error during positioning request", Snackbar.LENGTH_LONG).show(); | |
76 | + Snackbar.make(mapView, "Error during positioning request", Snackbar.LENGTH_LONG).show(); | |
81 | 77 | } |
82 | 78 | }); |
83 | 79 | Log.v(TAG, "" + locateRequest); |
... | ... | @@ -167,15 +163,16 @@ public class PositioningActivity extends BaseActivity { |
167 | 163 | mapMarker.setX(mapView.getX() + x_on_map - mapMarker.getWidth()/2); |
168 | 164 | mapMarker.setY(mapView.getY() + y_on_map - mapMarker.getHeight()); |
169 | 165 | mapMarker.setVisibility(View.VISIBLE); |
170 | - mapView.setVisibility(View.VISIBLE); | |
166 | + imageLoading.setVisibility(View.INVISIBLE); | |
171 | 167 | } |
172 | 168 | |
173 | 169 | private boolean hasCorrectMap(int mapId) { |
174 | - return (this.mapId != null && this.mapId.equals(mapId)); | |
170 | + return this.mapId == mapId; | |
175 | 171 | } |
176 | 172 | |
177 | 173 | private void getMap(final int mapId) { |
178 | - mapView.setVisibility(View.INVISIBLE); | |
174 | + imageLoading.clearAnimation(); | |
175 | + imageLoading.setVisibility(View.INVISIBLE); | |
179 | 176 | ImageRequest mapRequest = new ImageRequest( |
180 | 177 | getURLSolver().mapBytesURL(mapId), |
181 | 178 | new Response.Listener<Bitmap>() { |
... | ... | @@ -190,7 +187,10 @@ public class PositioningActivity extends BaseActivity { |
190 | 187 | }, 0, 0, null, |
191 | 188 | new Response.ErrorListener() { |
192 | 189 | public void onErrorResponse(VolleyError error) { |
193 | - Snackbar.make(mapView, "Can't load map !", Snackbar.LENGTH_LONG) | |
190 | + PositioningActivity.this.mapId = 1; | |
191 | + mapView.setImageResource(R.drawable.map); | |
192 | + mapView.setVisibility(View.VISIBLE); | |
193 | + Snackbar.make(mapView, "Loading default map...", Snackbar.LENGTH_LONG) | |
194 | 194 | .setAction("Action", null).show(); |
195 | 195 | } |
196 | 196 | }); | ... | ... |
app/src/main/res/layout/content_calibration.xml
... | ... | @@ -101,4 +101,15 @@ |
101 | 101 | android:layout_marginLeft="8dp" |
102 | 102 | app:layout_constraintLeft_toLeftOf="parent" /> |
103 | 103 | |
104 | + <TextView | |
105 | + android:id="@+id/txt_select_floor" | |
106 | + android:layout_width="wrap_content" | |
107 | + android:layout_height="wrap_content" | |
108 | + android:layout_marginBottom="7dp" | |
109 | + android:layout_marginLeft="8dp" | |
110 | + android:text="@string/txt_select_floor" | |
111 | + android:textAppearance="@android:style/TextAppearance.Material.Menu" | |
112 | + app:layout_constraintBottom_toTopOf="@+id/spinner" | |
113 | + app:layout_constraintLeft_toLeftOf="parent" /> | |
114 | + | |
104 | 115 | </android.support.constraint.ConstraintLayout> | ... | ... |
app/src/main/res/values/strings.xml