landing page created

parent b6bad3a5
package com.sliit.blindvision;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
public class Locate extends Activity {
ArrayList<String> buildings;
DatabaseHelper db;
ArrayAdapter<String> arrayAdapter;
ArrayList<PositionData> positionsData;
String building;
TextView result;
Button locate;
public void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.locate);
db = new DatabaseHelper(this);
buildings = db.getBuildings();
locate = (Button) findViewById(R.id.locate);
result = (TextView) findViewById(R.id.result);
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, buildings);
locate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(getApplicationContext(), Scan.class);
intent.putExtra("isLearning", false);
startActivityForResult(intent,0);
}
});
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, buildings);
// Set The Adapter
if (buildings.size()==0) {
Toast.makeText(this, "No building data available.", Toast.LENGTH_LONG).show();
locate.setEnabled(false);
}
else{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setTitle("Choose building");
builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// the user clicked on colors[which]
building = buildings.get(which);
}
});
builder.show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
// TODO Auto-generated method stub
if(resultCode==RESULT_OK){
PositionData positionData = (PositionData) intent
.getSerializableExtra("PositionData");
positionsData=db.getReadings(building);
String closestPosition = null;
ArrayList<Router> wifis = db.getFriendlyWifis(building);
int min_distance = positionData.uDistance(positionsData.get(0), wifis);
int j=0;
closestPosition = positionsData.get(0).getName();
String res = "";
res += closestPosition + "\n" + min_distance;
res += "\n" + positionsData.get(0).toString();
for (int i = 1; i < positionsData.size(); i++) {
int distance = positionData.uDistance(positionsData.get(i), wifis);
res += "\n" + positionsData.get(i).getName() + "\n" + distance;
res += "\n" + positionsData.get(i).toString();
if (distance < min_distance) {
min_distance = distance;
j=i;
closestPosition = positionsData.get(i).getName();
}
}
if (min_distance == PositionData.MAX_DISTANCE){
closestPosition="OUT OF RANGE";
Toast.makeText(this,"You are out of range of the selected building",Toast.LENGTH_LONG).show();
}
result.setText("Nearest point : "+ closestPosition);
//////////////////////////////////////////////////
min_distance = positionData.uDistance(positionsData.get(0), wifis);
String closestPosition2 = null;
closestPosition2 = positionsData.get(0).getName();
res = "";
res += closestPosition2 + "\n" + min_distance;
res += "\n" + positionsData.get(0).toString();
for (int i = 1; i < positionsData.size(); i++) {
if(i!=j) {
int distance = positionData.uDistance(positionsData.get(i), wifis);
res += "\n" + positionsData.get(i).getName() + "\n" + distance;
res += "\n" + positionsData.get(i).toString();
closestPosition2 = positionsData.get(i).getName();//////////////////////////
if(closestPosition2.equals(closestPosition))
continue;
if (distance < min_distance) {
min_distance = distance;
closestPosition2 = positionsData.get(i).getName();
}
}
}
if (min_distance == PositionData.MAX_DISTANCE){
closestPosition2="OUT OF RANGE";
Toast.makeText(this,"You are out of range of the selected building",Toast.LENGTH_LONG).show();
}
res += "\nCurrent:\n" + positionData.toString();
Log.v("Result",res);
super.onActivityResult(requestCode, resultCode, intent);
}
}
public class CustomOnItemSelectedListener implements
AdapterView.OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
building = parent.getItemAtPosition(pos).toString();
locate.setEnabled(true);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
locate.setEnabled(false);
}
}
}
package com.sliit.blindvision;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<Button
android:id="@+id/btn_wifi_calibration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Open WiFi Calibration" />
<Button
android:id="@+id/btn_route_finder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Open Route Finder" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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/textHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/placename"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Calibrate" />
<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" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ScrollView>
</LinearLayout>
\ 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