Skip to content

Commit

Permalink
Nearby Places in Android Device
Browse files Browse the repository at this point in the history
  • Loading branch information
vedantkingh committed Aug 5, 2023
1 parent 42aefa1 commit 6ad4ee9
Show file tree
Hide file tree
Showing 14 changed files with 395 additions and 5 deletions.
5 changes: 2 additions & 3 deletions .idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'org.jsoup:jsoup:1.14.3'

// Load Images from URL
implementation 'com.github.bumptech.glide:glide:4.15.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.15.1'
}


Expand Down
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
android:icon="@drawable/lvc_logo"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".NearbyPlacesActivity"
android:exported="false"
android:screenOrientation="landscape"
android:theme="@style/AppTheme"/>
<activity
android:name=".SplashActivity"
android:exported="true"
Expand All @@ -47,6 +52,9 @@
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
<!-- <meta-data-->
<!-- android:name="com.gsoc.vedantsingh.locatedvoicecms.MyAppGlideModule"-->
<!-- android:value="GlideModule" />-->

<provider
android:name=".data.POIsProvider"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gsoc.vedantsingh.locatedvoicecms;

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public class MyAppGlideModule extends AppGlideModule {
// No need to implement any methods, keep this class empty.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.gsoc.vedantsingh.locatedvoicecms;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;

import com.gsoc.vedantsingh.locatedvoicecms.beans.PlaceInfo;
import com.gsoc.vedantsingh.locatedvoicecms.utils.NearbyPlacesAdapter;

import java.util.ArrayList;
import java.util.List;

public class NearbyPlacesActivity extends AppCompatActivity {
ListView placesList;
ImageButton closeButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nearby_places);

placesList = findViewById(R.id.placesListView);
closeButton = findViewById(R.id.closeButton);

closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});

List<PlaceInfo> nearbyPlaces = getIntent().getParcelableArrayListExtra("nearbyPlacesList");
Log.d("Nearby", nearbyPlaces.get(0).getTitle());

if (nearbyPlaces != null && !nearbyPlaces.isEmpty()) {
ListView listView = findViewById(R.id.placesListView);
NearbyPlacesAdapter adapter = new NearbyPlacesAdapter(this, nearbyPlaces);
listView.setAdapter(adapter);
} else {
Toast.makeText(this, "Click on a POI to view Nearby Places", Toast.LENGTH_SHORT).show();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.preference.PreferenceManager;
import android.speech.RecognizerIntent;
import android.util.DisplayMetrics;
Expand Down Expand Up @@ -359,6 +360,11 @@ public void onResponse(Call<WikipediaGeoSearchResponse> call, Response<Wikipedia
e.printStackTrace();
}
executorService.shutdown();

Intent intent = new Intent(getActivity(), NearbyPlacesActivity.class);
intent.putParcelableArrayListExtra("nearbyPlacesList", (ArrayList<? extends Parcelable>) nearbyPlaces);
startActivity(intent);

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public void onCreate(Bundle savedInstanceState) {
bindPreferenceSummaryToValue(findPreference("pref_kiosk_mode"));
bindPreferenceSummaryToValue(findPreference("ServerIp"));
bindPreferenceSummaryToValue(findPreference("ServerPort"));
bindPreferenceSummaryToValue(findPreference("AIServerIP"));
bindPreferenceSummaryToValue(findPreference("AIServerPort"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.gsoc.vedantsingh.locatedvoicecms.beans;

public class PlaceInfo {
import android.os.Parcel;
import android.os.Parcelable;

public class PlaceInfo implements Parcelable {
private String title;
private String description;
private String imageLink;
Expand All @@ -12,6 +15,24 @@ public PlaceInfo(String title, String description, String imageLink) {
this.imageLink = imageLink;
}

protected PlaceInfo(Parcel in) {
title = in.readString();
description = in.readString();
imageLink = in.readString();
}

public static final Creator<PlaceInfo> CREATOR = new Creator<PlaceInfo>() {
@Override
public PlaceInfo createFromParcel(Parcel in) {
return new PlaceInfo(in);
}

@Override
public PlaceInfo[] newArray(int size) {
return new PlaceInfo[size];
}
};

public String getTitle() {
return title;
}
Expand All @@ -35,4 +56,16 @@ public String getImageLink() {
public void setImageLink(String imageLink) {
this.imageLink = imageLink;
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(title);
dest.writeString(description);
dest.writeString(imageLink);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package com.gsoc.vedantsingh.locatedvoicecms.utils;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.gsoc.vedantsingh.locatedvoicecms.R;
import com.gsoc.vedantsingh.locatedvoicecms.beans.PlaceInfo;
import com.jcraft.jsch.Session;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class NearbyPlacesAdapter extends BaseAdapter {
List<PlaceInfo> nearbyPlaces;
Context context;
Session session = null;

public NearbyPlacesAdapter(Context context, List<PlaceInfo> nearbyPlaces) {
this.nearbyPlaces = nearbyPlaces;
this.context = context;
}

@Override
public int getCount() {
return this.nearbyPlaces.size();
}

@Override
public Object getItem(int position) {
return this.nearbyPlaces.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
final PlaceInfo currentPlace = this.nearbyPlaces.get(position);
ViewHolder viewHolder;

if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.nearby_places_item, parent, false);
viewHolder = new ViewHolder(convertView, context);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}

if (currentPlace == null) {
Log.e("Nearby Places", "currentPlace is null at position: " + position);
return convertView; // Return the view as is, as there's no data to display
}

Log.d("Nearby Places", "Title: " + currentPlace.getTitle());
Log.d("Nearby Places", "Description: " + currentPlace.getDescription());
Log.d("Nearby Places", "ImageLink: " + currentPlace.getImageLink());

if (!TextUtils.isEmpty(currentPlace.getImageLink())) {
Glide.with(context)
.load(currentPlace.getImageLink())
.error(R.drawable.baseline_image_24)
.into(viewHolder.placeImage);
} else {
// Handle the case when the imageLink is null or empty.
// For example, you can set a placeholder image like this:
viewHolder.placeImage.setImageResource(R.drawable.baseline_image_24);
}

viewHolder.placeName.setText(currentPlace.getTitle());
viewHolder.placeDescription.setText(currentPlace.getDescription().toString());

return convertView;
}

public class ViewHolder{
TextView placeName, placeDescription;
ImageView placeImage;
ViewHolder(View rootView, Context context){
placeImage = rootView.findViewById(R.id.placeImage);
placeName = rootView.findViewById(R.id.placeName);
placeDescription = rootView.findViewById(R.id.placeDescription);

rootView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String place = placeName.getText().toString();
GetSessionTask getSessionTask = new GetSessionTask(context);
getSessionTask.execute();

String command = "echo 'search=" + place + "' > /tmp/query.txt";

ExecutorService executorService = Executors.newSingleThreadExecutor();
SearchNearbyPlaceTask searchTask = new SearchNearbyPlaceTask(session, context, command);
Future<Void> future = executorService.submit(searchTask);
try {
future.get();
} catch (Exception e) {
e.printStackTrace();
}
executorService.shutdown();
}
});
}
}

public class SearchNearbyPlaceTask implements Callable<Void> {
private String command;
private Session session;
private Context context;

public SearchNearbyPlaceTask(Session session, Context context, String command) {
this.command = command;
this.session = session;
this.context = context;
}

@Override
public Void call() throws Exception {
try {
LGUtils.setConnectionWithLiquidGalaxy(session, command, context);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

private class GetSessionTask extends AsyncTask<Void, Void, Void> {

private final Context context;

public GetSessionTask(Context context) {
this.context = context;
}

@Override
protected void onPreExecute() {
super.onPreExecute();
}

@Override
protected Void doInBackground(Void... params) {
if (context != null) {
session = LGUtils.getSession(context);
}
return null;
}

@Override
protected void onPostExecute(Void success) {
super.onPostExecute(success);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.media.AudioAttributes;
import android.media.AudioManager;
Expand All @@ -15,6 +16,7 @@
import androidx.core.content.res.ResourcesCompat;

import android.os.Build;
import android.preference.PreferenceManager;
import android.text.Html;
import android.util.DisplayMetrics;
import android.util.Log;
Expand Down Expand Up @@ -423,8 +425,12 @@ public static void playBarkAudioFromText(final Context context, final String tex

Log.d("BARK", "playBarkAudioFromText");

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String aiServerIp = prefs.getString("AIServerIP", "172.28.26.84");
String aiServerPort = prefs.getString("AIServerPort", "5000");

// Send the API request to the server and get the audio file
String command = "curl -X POST -H \"Content-Type: application/json\" -d '{\"text\":\"" + text + "\"}' " + "http://172.28.26.84:5000/synthesize";
String command = "curl -X POST -H \"Content-Type: application/json\" -d '{\"text\":\"" + text + "\"}' " + "http://" + aiServerIp + ":" + aiServerPort + "/synthesize";
byte[] response = LGUtils.executeAudioCommandWithResponse(session, command, context);
File audioFile = saveAudioFile(context, response);
// if (audioFile != null) {
Expand Down
Loading

0 comments on commit 6ad4ee9

Please sign in to comment.