Commit 6414e7ce304837391bf9060d671b5309ebab2d7c
1 parent
5b2418c4
Fix URL parametres & add MAC address for calibration requests.
Showing
4 changed files
with
75 additions
and
65 deletions
Show diff stats
app/src/main/java/fr/utbm/lo53/p2017/positionningapp/BaseActivity.java
1 | 1 | package fr.utbm.lo53.p2017.positionningapp; |
2 | 2 | |
3 | +import android.content.Context; | |
3 | 4 | import android.content.Intent; |
5 | +import android.net.wifi.WifiInfo; | |
6 | +import android.net.wifi.WifiManager; | |
7 | +import android.os.Build; | |
4 | 8 | import android.os.Bundle; |
5 | 9 | import android.preference.PreferenceManager; |
6 | 10 | import android.support.annotation.Nullable; |
... | ... | @@ -8,6 +12,11 @@ import android.support.v7.app.AppCompatActivity; |
8 | 12 | import android.view.Menu; |
9 | 13 | import android.view.MenuItem; |
10 | 14 | |
15 | +import java.net.NetworkInterface; | |
16 | +import java.net.SocketException; | |
17 | +import java.util.Collections; | |
18 | +import java.util.List; | |
19 | + | |
11 | 20 | import fr.utbm.lo53.p2017.positionningapp.network.URLSolver; |
12 | 21 | |
13 | 22 | public abstract class BaseActivity extends AppCompatActivity { |
... | ... | @@ -71,4 +80,40 @@ public abstract class BaseActivity extends AppCompatActivity { |
71 | 80 | return urlSolver; |
72 | 81 | } |
73 | 82 | |
83 | + protected String getMacAddress() { | |
84 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | |
85 | + // Get MAC address prior to android 6.0 | |
86 | + WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); | |
87 | + WifiInfo wInfo = wifiManager.getConnectionInfo(); | |
88 | + return wInfo.getMacAddress(); | |
89 | + } else { | |
90 | + // Removed in Android 6.0 -> manually get MAC address | |
91 | + try { | |
92 | + List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces()); | |
93 | + for (NetworkInterface nif : all) { | |
94 | + if (!nif.getName().equalsIgnoreCase("wlan0")) continue; | |
95 | + | |
96 | + byte[] macBytes = nif.getHardwareAddress(); | |
97 | + if (macBytes == null) { | |
98 | + return ""; | |
99 | + } | |
100 | + | |
101 | + StringBuilder res1 = new StringBuilder(); | |
102 | + for (byte b : macBytes) { | |
103 | + //res1.append(Integer.toHexString(b & 0xFF) + ":"); | |
104 | + res1.append(String.format("%02X:", b)); | |
105 | + } | |
106 | + | |
107 | + if (res1.length() > 0) { | |
108 | + res1.deleteCharAt(res1.length() - 1); | |
109 | + } | |
110 | + return res1.toString(); | |
111 | + } | |
112 | + } catch (SocketException e) { | |
113 | + e.printStackTrace(); | |
114 | + } | |
115 | + return "02:00:00:00:00:00"; | |
116 | + } | |
117 | + } | |
118 | + | |
74 | 119 | } | ... | ... |
app/src/main/java/fr/utbm/lo53/p2017/positionningapp/Calibration.java
... | ... | @@ -52,11 +52,11 @@ public class Calibration extends BaseActivity { |
52 | 52 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
53 | 53 | spinner.setAdapter(adapter); |
54 | 54 | |
55 | - Map.setVisibility(Map.INVISIBLE); | |
56 | - setPointButton.setVisibility(setPointButton.INVISIBLE); | |
57 | - MapMarker.setVisibility(MapMarker.INVISIBLE); | |
58 | - cancelButton.setVisibility(cancelButton.INVISIBLE); | |
59 | - measureButton.setVisibility(measureButton.INVISIBLE); | |
55 | + Map.setVisibility(View.INVISIBLE); | |
56 | + setPointButton.setVisibility(View.INVISIBLE); | |
57 | + MapMarker.setVisibility(View.INVISIBLE); | |
58 | + cancelButton.setVisibility(View.INVISIBLE); | |
59 | + measureButton.setVisibility(View.INVISIBLE); | |
60 | 60 | |
61 | 61 | //Map.setMaxHeight(50); |
62 | 62 | |
... | ... | @@ -64,8 +64,8 @@ public class Calibration extends BaseActivity { |
64 | 64 | @Override |
65 | 65 | public boolean onTouch(View view, MotionEvent motionEvent) { |
66 | 66 | /*motionEvent.getAction()==motionEvent.ACTION_MOVE &&*/ |
67 | - if( setPointButton.getVisibility() == setPointButton.INVISIBLE && motionEvent.getX() <= Map.getWidth() && motionEvent.getY() <= Map.getHeight() && motionEvent.getX() >= 0 && motionEvent.getY() >= 0) { | |
68 | - MapMarker.setVisibility(MapMarker.VISIBLE); | |
67 | + if( setPointButton.getVisibility() == View.INVISIBLE && motionEvent.getX() <= Map.getWidth() && motionEvent.getY() <= Map.getHeight() && motionEvent.getX() >= 0 && motionEvent.getY() >= 0) { | |
68 | + MapMarker.setVisibility(View.VISIBLE); | |
69 | 69 | width = motionEvent.getX() / Map.getWidth(); |
70 | 70 | height = motionEvent.getY() / Map.getHeight(); |
71 | 71 | /*Snackbar.make(view, " X : " + height + " Y : " + width, Snackbar.LENGTH_LONG) |
... | ... | @@ -81,20 +81,20 @@ public class Calibration extends BaseActivity { |
81 | 81 | setPointButton.setOnClickListener(new View.OnClickListener() { |
82 | 82 | @Override |
83 | 83 | public void onClick(View v) { |
84 | - setPointButton.setVisibility(setPointButton.INVISIBLE); | |
85 | - cancelButton.setVisibility(cancelButton.VISIBLE); | |
86 | - measureButton.setVisibility(measureButton.VISIBLE); | |
87 | - spinner.setVisibility(spinner.INVISIBLE); | |
84 | + setPointButton.setVisibility(View.INVISIBLE); | |
85 | + cancelButton.setVisibility(View.VISIBLE); | |
86 | + measureButton.setVisibility(View.VISIBLE); | |
87 | + spinner.setVisibility(View.INVISIBLE); | |
88 | 88 | } |
89 | 89 | }); |
90 | 90 | cancelButton.setOnClickListener(new View.OnClickListener() { |
91 | 91 | @Override |
92 | 92 | public void onClick(View v) { |
93 | - setPointButton.setVisibility(setPointButton.VISIBLE); | |
94 | - cancelButton.setVisibility(cancelButton.INVISIBLE); | |
95 | - measureButton.setVisibility(measureButton.INVISIBLE); | |
96 | - MapMarker.setVisibility(MapMarker.INVISIBLE); | |
97 | - spinner.setVisibility(spinner.VISIBLE); | |
93 | + setPointButton.setVisibility(View.VISIBLE); | |
94 | + cancelButton.setVisibility(View.INVISIBLE); | |
95 | + measureButton.setVisibility(View.INVISIBLE); | |
96 | + MapMarker.setVisibility(View.INVISIBLE); | |
97 | + spinner.setVisibility(View.VISIBLE); | |
98 | 98 | } |
99 | 99 | }); |
100 | 100 | spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
... | ... | @@ -102,14 +102,14 @@ public class Calibration extends BaseActivity { |
102 | 102 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
103 | 103 | Log.i(TAG, String.format("Pos: %d, ID %d", position, id)); |
104 | 104 | map_id = id; |
105 | - Map.setVisibility(Map.VISIBLE); | |
106 | - setPointButton.setVisibility(setPointButton.VISIBLE); | |
105 | + Map.setVisibility(View.VISIBLE); | |
106 | + setPointButton.setVisibility(View.VISIBLE); | |
107 | 107 | } |
108 | 108 | |
109 | 109 | @Override |
110 | 110 | public void onNothingSelected(AdapterView<?> parent) { |
111 | - Map.setVisibility(Map.INVISIBLE); | |
112 | - setPointButton.setVisibility(setPointButton.INVISIBLE); | |
111 | + Map.setVisibility(View.INVISIBLE); | |
112 | + setPointButton.setVisibility(View.INVISIBLE); | |
113 | 113 | } |
114 | 114 | }); |
115 | 115 | } |
... | ... | @@ -123,11 +123,11 @@ public class Calibration extends BaseActivity { |
123 | 123 | } |
124 | 124 | |
125 | 125 | public void sendCalibrateRequest(final View v) { |
126 | - if(MapMarker.getVisibility()==MapMarker.INVISIBLE) { | |
126 | + if(MapMarker.getVisibility()== View.INVISIBLE) { | |
127 | 127 | Snackbar.make(v, "You need to set a point before measurement.", Snackbar.LENGTH_LONG) |
128 | 128 | .setAction("Action", null).show(); |
129 | 129 | } else { |
130 | - JsonRequest request = new JsonObjectRequest(Request.Method.GET,getURLSolver().calibrateURL(width,height,map_id),null, | |
130 | + JsonRequest request = new JsonObjectRequest(Request.Method.GET,getURLSolver().calibrateURL(getMacAddress(), width,height,map_id),null, | |
131 | 131 | new Response.Listener<JSONObject>() { |
132 | 132 | @Override |
133 | 133 | public void onResponse(JSONObject response) { | ... | ... |
app/src/main/java/fr/utbm/lo53/p2017/positionningapp/PositioningActivity.java
... | ... | @@ -176,7 +176,7 @@ public class PositioningActivity extends BaseActivity { |
176 | 176 | mapMarker.setX(mapView.getX() + x_on_map - mapMarker.getWidth()/2); |
177 | 177 | mapMarker.setY(mapView.getY() + y_on_map - mapMarker.getHeight()); |
178 | 178 | mapMarker.setVisibility(View.VISIBLE); |
179 | - mapView.setVisibility(mapView.VISIBLE); | |
179 | + mapView.setVisibility(View.VISIBLE); | |
180 | 180 | } |
181 | 181 | |
182 | 182 | private boolean hasCorrectMap(int mapId) { |
... | ... | @@ -184,14 +184,14 @@ public class PositioningActivity extends BaseActivity { |
184 | 184 | } |
185 | 185 | |
186 | 186 | private void getMap(int mapId) { |
187 | - mapView.setVisibility(mapView.INVISIBLE); | |
187 | + mapView.setVisibility(View.INVISIBLE); | |
188 | 188 | ImageRequest mapRequest = new ImageRequest( |
189 | 189 | getURLSolver().mapBytesURL(mapId), |
190 | 190 | new Response.Listener<Bitmap>() { |
191 | 191 | @Override |
192 | 192 | public void onResponse(Bitmap bitmap) { |
193 | 193 | mapView.setImageBitmap(bitmap); |
194 | - mapView.setVisibility(mapView.VISIBLE); | |
194 | + mapView.setVisibility(View.VISIBLE); | |
195 | 195 | Snackbar.make(mapView, "You need to set a point before measurement.", Snackbar.LENGTH_LONG) |
196 | 196 | .setAction("Action", null).show(); |
197 | 197 | } |
... | ... | @@ -204,40 +204,4 @@ public class PositioningActivity extends BaseActivity { |
204 | 204 | }); |
205 | 205 | queue.add(mapRequest); |
206 | 206 | } |
207 | - | |
208 | - protected String getMacAddress() { | |
209 | - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | |
210 | - // Get MAC address prior to android 6.0 | |
211 | - WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); | |
212 | - WifiInfo wInfo = wifiManager.getConnectionInfo(); | |
213 | - return wInfo.getMacAddress(); | |
214 | - } else { | |
215 | - // Removed in Android 6.0 -> manually get MAC address | |
216 | - try { | |
217 | - List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces()); | |
218 | - for (NetworkInterface nif : all) { | |
219 | - if (!nif.getName().equalsIgnoreCase("wlan0")) continue; | |
220 | - | |
221 | - byte[] macBytes = nif.getHardwareAddress(); | |
222 | - if (macBytes == null) { | |
223 | - return ""; | |
224 | - } | |
225 | - | |
226 | - StringBuilder res1 = new StringBuilder(); | |
227 | - for (byte b : macBytes) { | |
228 | - //res1.append(Integer.toHexString(b & 0xFF) + ":"); | |
229 | - res1.append(String.format("%02X:", b)); | |
230 | - } | |
231 | - | |
232 | - if (res1.length() > 0) { | |
233 | - res1.deleteCharAt(res1.length() - 1); | |
234 | - } | |
235 | - return res1.toString(); | |
236 | - } | |
237 | - } catch (SocketException e) { | |
238 | - e.printStackTrace(); | |
239 | - } | |
240 | - return "02:00:00:00:00:00"; | |
241 | - } | |
242 | - } | |
243 | 207 | } | ... | ... |
app/src/main/java/fr/utbm/lo53/p2017/positionningapp/network/URLSolver.java
... | ... | @@ -57,13 +57,14 @@ public class URLSolver implements SharedPreferences.OnSharedPreferenceChangeList |
57 | 57 | return b.build().toString(); |
58 | 58 | } |
59 | 59 | |
60 | - public String calibrateURL(float x, float y, long map_id) { | |
60 | + public String calibrateURL(String mac, float x, float y, long map_id) { | |
61 | 61 | Uri.Builder b = baseURL(); |
62 | 62 | b.appendPath("calibration") |
63 | 63 | .appendPath("request") |
64 | - .appendQueryParameter("x", String.format("%f",x)) | |
65 | - .appendQueryParameter("y", String.format("%f",y)) | |
66 | - .appendQueryParameter("map_id", String.format("%d", map_id)); | |
64 | + .appendQueryParameter("X", String.format("%f",x)) | |
65 | + .appendQueryParameter("Y", String.format("%f",y)) | |
66 | + .appendQueryParameter("CLIENT_MAC_ADDR", mac) | |
67 | + .appendQueryParameter("MAP_ID", String.format("%d", map_id)); | |
67 | 68 | return b.build().toString(); |
68 | 69 | } |
69 | 70 | ... | ... |