wifi positioning changes

parent ebaa71f2
package com.sliit.blindvision;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Landing extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_landing);
Button btnWifiCalibration = findViewById(R.id.btn_wifi_calibration);
Button btnRouteFinder = findViewById(R.id.btn_route_finder);
btnWifiCalibration.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// For this example, let's open WiFi settings as calibration. Adjust this as needed.
startActivity(new Intent(Landing.this,StartingScreen.class));
}
});
btnRouteFinder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Landing.this, Route.class));
}
});
}
}
\ No newline at end of file
package com.sliit.blindvision;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.speech.tts.TextToSpeech;
import java.util.Locale;
import org.json.JSONObject;
import java.net.HttpURLConnection;
import java.net.URL;
import android.util.Log;
public class Route extends AppCompatActivity {
private WebView webView;
private TextView directionTextView;
private EditText ipEditText;
private Button setIpButton;
private static final String PREFS_NAME = "IP_PREFS";
private static final String IP_KEY = "IP_KEY";
private TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rout);
ipEditText = findViewById(R.id.ipEditText);
setIpButton = findViewById(R.id.setIpButton);
webView = findViewById(R.id.webView);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String savedIp = settings.getString(IP_KEY, "192.168.1.2");
ipEditText.setText(savedIp);
tts = new TextToSpeech(this, status -> {
if (status != TextToSpeech.ERROR) {
tts.setLanguage(Locale.US);
}
});
setIpButton.setOnClickListener(v -> {
String newIp = ipEditText.getText().toString();
if (!newIp.isEmpty()) {
// Save the new IP
SharedPreferences.Editor editor = settings.edit();
editor.putString(IP_KEY, newIp);
editor.apply();
// Update the WebView and direction fetcher with the new IP
Intent intent = getIntent();
finish();
startActivity(intent);
}
});
WebSettings webSettings = webView.getSettings();
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
directionTextView = findViewById(R.id.directionTextView);
// Load the video feed
webView.loadUrl("http://"+savedIp+":5005/video_feed");
// Fetch the direction results periodically
new Thread(() -> {
Log.d("direction", "starting");
while (true) {
try {
URL url = new URL("http://"+savedIp+":5005/direction");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
String result = Utils.streamToString(connection.getInputStream());
JSONObject jsonObject = new JSONObject(result);
Log.d("direction", jsonObject.toString());
// String direction = jsonObject.getString("direction");
//
// runOnUiThread(() -> directionTextView.setText(direction));
String direction = jsonObject.getString("direction");
runOnUiThread(() -> {
directionTextView.setText(direction);
tts.speak(direction, TextToSpeech.QUEUE_FLUSH, null, null); // Speak the direction
});
Thread.sleep(4000); // Fetch every 5 seconds
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
}
\ No newline at end of file
package com.sliit.blindvision;
import java.io.Serializable;
public class Router implements Serializable{
private String SSID;
private String BSSID;
public Router(String SSID, String BSSID) {
this.SSID = SSID;
this.BSSID = BSSID;
}
public String getSSID() {
return SSID;
}
public String getBSSID() {
return BSSID;
}
@Override
public String toString(){
return SSID;
}
@Override
public boolean equals(Object arg){
return ((Router) arg).getBSSID().equals(this.getBSSID());
}
@Override
public int hashCode(){
return this.BSSID.hashCode();
}
}
\ No newline at end of file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<Button
android:id="@+id/friendly_wifis_button"
android:enabled="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Choose Friendly Wifis" />
<EditText
android:id="@+id/position_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a new position name and calibrate"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/calibratebutton"
android:enabled="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Calibrate" />
<Button
android:id="@+id/finish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Update" />
<ListView
android:id="@+id/positionslist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#0000CC"
android:dividerHeight="0.1dp" >
</ListView>
</LinearLayout>
\ No newline at end of file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<TextView
android:id="@+id/heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<Button
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Start" />
<TextView
android:id="@+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/TextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="#ff0000"
android:textSize="30dp" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
\ No newline at end of file
package com.sliit.blindvision;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment