Commit 494bb9f5 authored by Marcel Odumorek's avatar Marcel Odumorek

v2

parent 12510d69
......@@ -23,10 +23,11 @@ android {
minSdkVersion 20
targetSdkVersion 29
versionCode 1
versionName "0.0.1"
versionName "0.0.2"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
......@@ -48,6 +49,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
......@@ -57,20 +59,22 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.2.1'
implementation 'com.android.support:appcompat-v7:24.2.1' // appcompat library
implementation 'com.android.support:design:24.2.1'
implementation('com.mapbox.mapboxsdk:mapbox-android-sdk:8.2.1') {
exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-telemetry'
}
implementation 'com.android.support:appcompat-v7:24.2.1'
// Mapbox Services SDK dependency to retrieve direction routes
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:4.8.0'
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:4.8.0'
// Mapbox Buildings Plugin for showing and customizing 3D buildin
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-building-v7:0.5.0'
// implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-building-v7:0.5.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v8:0.3.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.6.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-places-v8:0.9.0'
// implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v8:0.3.0'
// implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.6.0'
// implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-places-v8:0.9.0'
implementation('com.mapbox.mapboxsdk:mapbox-android-geocoder:1.0.0@aar') {
transitive = true
}
......@@ -79,4 +83,7 @@ dependencies {
implementation 'com.github.arimorty:floatingsearchview:2.1.1'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
}
......@@ -3,11 +3,9 @@
package="com.creanet.najdidefibrilator">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
......@@ -19,27 +17,20 @@
<activity android:name=".Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".ItemDetailActivity"
android:parentActivityName=".MainActivity">
<!-- The meta-data tag is required if you support API level 15 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
<activity android:name=".ItemDetailActivity">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="cdab3bede992f0330e60a95ffa2ace1493d99414" />
......
package com.creanet.najdidefibrilator;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.google.gson.JsonSyntaxException;
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.FeatureCollection;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.geometry.LatLng;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
public class BottomSheetListFragment extends BottomSheetDialogFragment implements View.OnClickListener {
private Context context;
private FeatureCollection featureCollection;
public static final String TAG = "ActionBottomDialog";
private ItemClickListener mListener;
public static BottomSheetListFragment newInstance() {
return new BottomSheetListFragment();
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.bottom_sheet, container, false);
}
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ListView listView = (ListView) getView().findViewById(R.id.list_bottom_sheet);
try {
getFeatureCollectionFromJson();
} catch (Exception exception) {
Log.e("MapActivity", "onCreate: " + exception);
Toast.makeText(context, "Failed to load file", Toast.LENGTH_LONG).show();
}
List<Feature> featureList = featureCollection.features();
ArrayList<DefibrilatorModel> defibrilatorModels = new ArrayList<DefibrilatorModel>();
DefAdapter adapter = new DefAdapter(getApplicationContext(),defibrilatorModels );
for (int x = 0; x < featureList.size(); x++) {
Feature singleLocation = featureList.get(x);
String singleLocationPerson = singleLocation.getStringProperty("person");
String singleLocationDesc = singleLocation.getStringProperty("description");
String singleLocationCity = singleLocation.getStringProperty("city");
String singleLocationAddress = singleLocation.getStringProperty("address");
String singleLocationTel = singleLocation.getStringProperty("tel");
String singleLocationEmail = singleLocation.getStringProperty("email");
String singleLocationHours = singleLocation.getStringProperty("hours");
String singleLocationImage = singleLocation.getStringProperty("images");
Number singleLocationId = singleLocation.getNumberProperty("id");
Point singleLocationPosition = (Point) singleLocation.geometry();
LatLng singleLocationLatLng = new LatLng(singleLocationPosition.latitude(), singleLocationPosition.longitude());
defibrilatorModels.add(new DefibrilatorModel(
singleLocationLatLng,
singleLocationPerson,
singleLocationDesc,
singleLocationCity,
singleLocationAddress,
singleLocationTel,
singleLocationEmail,
singleLocationHours,
singleLocationImage,
singleLocationId
));
}
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
}
});
}
private void getFeatureCollectionFromJson() throws IOException {
File initialFile = new File(getApplicationContext().getFilesDir().getPath() + "/Locations", "locations.geojson");
try {
featureCollection = FeatureCollection.fromJson(loadGeoJson());
Log.e("gFCFJ", "JSON OPENED SUCCESFULLY");
} catch (IllegalStateException | JsonSyntaxException exception) {
Log.e("gFCFJK", "getFeatureCollectionFromJson error");
exception.printStackTrace();
}
}
private String loadGeoJson() {
try {
File root = new File(getApplicationContext().getFilesDir().getPath() + "/Locations", "locations.geojson");
InputStream is = new FileInputStream(root);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
return new String(buffer, "UTF-8");
} catch (Exception exception) {
Log.e("MapActivity", "Exception Loading GeoJSON: " + exception.toString());
exception.printStackTrace();
return null;
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof ItemClickListener) {
mListener = (ItemClickListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement ItemClickListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
@Override public void onClick(View view) {
TextView tvSelected = (TextView) view;
mListener.onItemClick(tvSelected.getText().toString());
Log.e("BottomSheetDialog","Clicked on item");
}
public interface ItemClickListener {
void onItemClick(String item);
}
}
package com.creanet.najdidefibrilator;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
public class DefAdapter extends ArrayAdapter<DefibrilatorModel> {
private String imageName;
public DefAdapter(Context context,ArrayList<DefibrilatorModel> def){
super(context,0,def);
}
@Override
public View getView(int position,View convertView,ViewGroup parent){
DefibrilatorModel defibrilatorModel = getItem(position);
if(convertView == null){
convertView = LayoutInflater.from(getContext()).inflate(R.layout.single_item, parent, false);
}
// try {
// URL url = new URL(defibrilatorModel.getImage());
// URLConnection conn = url.openConnection();
// InputStream in = conn.getInputStream();
// } catch (IOException e) {
// e.printStackTrace();
// }
DefibrilatorModel model = getItem(position);
ImageView image = convertView.findViewById(R.id.emoji);
if (model != null) {
Picasso.get().load(model.getImage()).into(image);
}
Button detail = (Button) convertView.findViewById(R.id.detailbutton);
detail.setTag(position);
detail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int position = (Integer) view.getTag();
Context context = view.getContext();
DefibrilatorModel defibrilatorModel1 = getItem(position);
Intent intent = new Intent(context,ItemDetailActivity.class);
intent.putExtra("title",defibrilatorModel.getId().toString());
intent.putExtra("desc",defibrilatorModel.getDesc());
intent.putExtra("address",defibrilatorModel.getAddress());
intent.putExtra("image",defibrilatorModel.getImage());
context.startActivity(intent);
}
});
TextView address = (TextView) convertView.findViewById(R.id.address);
TextView id = (TextView) convertView.findViewById(R.id.city);
ImageView img = (ImageView) convertView.findViewById(R.id.emoji);
address.setText(defibrilatorModel.getAddress());
id.setText(defibrilatorModel.getId().toString());
// img.setImageBitmap(loadImageFromStorage(directory.getAbsolutePath()));
// new DownloadImages().execute(defibrilatorModel.getImage());
imageName = defibrilatorModel.getId().toString();
return convertView;
}
// private class DownloadImages extends AsyncTask<String, Void, Bitmap> {
// private String TAG = "DownloadImage";
// private Bitmap downloadImageBitmap(String sUrl) {
// Bitmap bitmap = null;
// try {
// InputStream inputStream = new URL(sUrl).openStream(); // Download Image from URL
// bitmap = BitmapFactory.decodeStream(inputStream); // Decode Bitmap
// inputStream.close();
// } catch (Exception e) {
// Log.d(TAG, "Exception 1, Something went wrong!");
// e.printStackTrace();
// }
// return bitmap;
// }
//
// @Override
// protected Bitmap doInBackground(String... params) {
// return downloadImageBitmap(params[0]);
// }
//
// protected void onPostExecute(Bitmap result) {
// saveImages(result);
// }
// }
//
// private String saveImages(Bitmap bitmapImage){
// Context base;
// ContextWrapper cw = new ContextWrapper(getApplicationContext());
// File directory = cw.getDir("images",Context.MODE_PRIVATE);
// File path = new File(directory,imageName+".jpg");
//
// FileOutputStream fos = null;
// try {
// fos = new FileOutputStream(path);
// bitmapImage.compress(Bitmap.CompressFormat.JPEG,100,fos);
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// } finally {
// try {
// fos.close();
// Log.e("Adapter",directory.getAbsolutePath());
// } catch (IOException e){
// e.printStackTrace();
// }
// }
// return directory.getAbsolutePath();
// }
// private void loadImageFromStorage(String path){
// try {
// File f = new File(path,imageName+".jpg");
// Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// }
// }
}
......@@ -2,11 +2,13 @@ package com.creanet.najdidefibrilator;
import com.mapbox.mapboxsdk.geometry.LatLng;
import org.json.JSONObject;
public class DefibrilatorModel {
private LatLng location;
private String name;
private String address;
private String person;
private String address1;
private String city;
private String desc;
private String tel;
......@@ -14,11 +16,12 @@ public class DefibrilatorModel {
private String hours;
private String image;
private Number id;
private String distance;
public DefibrilatorModel(LatLng location,String name,String address,String city,String desc,String tel,String email,String hours, String image, Number id){
public DefibrilatorModel(LatLng location,String person,String address,String city,String desc,String tel,String email,String hours, String image, Number id){
this.location = location;
this.name = name;
this.address = address;
this.person = person;
this.address1 = address;
this.city = city;
this.desc = desc;
this.tel = tel;
......@@ -33,11 +36,11 @@ public class DefibrilatorModel {
public Number getId(){return id;}
public void setId(){this.id = id;}
public String getName(){return name;}
public void setName(){this.name = name;}
public String getPerson(){return person;}
public void setPerson(){this.person = person;}
public String getAddress(){return address;}
public void setAddress(){this.address = address;}
public String getAddress(){return address1;}
public void setAddress(){this.address1 = address1;}
public String getCity(){return city;}
public void setCity(){this.city = city;}
......@@ -57,4 +60,11 @@ public class DefibrilatorModel {
public String getImage(){return image;}
public void setImage(){this.image = image;}
public String getDistance() {
return distance;
}
public void setDistance(String distance) {
this.distance = distance;
}
}
package com.creanet.najdidefibrilator;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.NavUtils;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
public class ItemDetailActivity extends AppCompatActivity {
private Boolean wereStarted;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.item_detail);
Intent intent = getIntent();
String title = intent.getStringExtra("title");
String desc = intent.getStringExtra("desc");
String address = intent.getStringExtra("address");
String imageUrl = intent.getStringExtra("image");
ImageView imageView = (ImageView) findViewById(R.id.poster);
Toolbar toolbar = (Toolbar) findViewById(R.id.detail_toolbar);
toolbar.setTitle("ID:" + title);
setSupportActionBar(toolbar);
Picasso.get().load(imageUrl).fit().into(imageView);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own detail action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
// Show the Up button in the action bar.
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
Intent intent = getIntent();
// wereStarted = intent.getBooleanExtra("wereStarted",true);
// Log.e("ItemDetailActivity",wereStarted.toString());
// savedInstanceState is non-null when there is fragment state
// saved from previous configurations of this activity
// (e.g. when rotating the screen from portrait to landscape).
// In this case, the fragment will automatically be re-added
// to its container so we don't need to manually add it.
// For more information, see the Fragments API guide at:
//
// http://developer.android.com/guide/components/fragments.html
//
// if (savedInstanceState == null) {
// // Create the detail fragment and add it to the activity
// // using a fragment transaction.
// Bundle arguments = new Bundle();
// arguments.putString(ItemDetailFragment.ARG_ITEM_ID,
// getIntent().getStringExtra(ItemDetailFragment.ARG_ITEM_ID));
// ItemDetailFragment fragment = new ItemDetailFragment();
// fragment.setArguments(arguments);
// getSupportFragmentManager().beginTransaction()
// .add(R.id.item_detail_container, fragment)
// .commit();
// }
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
Intent intent = NavUtils.getParentActivityIntent(this);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
// intent.putExtra("wereStarted",wereStarted);
// Log.e("Going back",wereStarted.toString());
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
navigateUpTo(new Intent(this, MainActivity.class));
return true;
}
......
This diff is collapsed.
package com.creanet.najdidefibrilator;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.util.JsonReader;
import android.util.Log;
import android.widget.Toast;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.ResponseBody;
public class Parser {
private Context context;
public static void Parse(Context context) {
String response = "";
OkHttpClient client = new OkHttpClient();
String sBody = null;
Request request = new Request.Builder().url("http://defibrilokator.creanet.sk/api/points-geojson").build();
ResponseBody responseBody = null;
JsonReader reader;
try {
responseBody = client.newCall(request).execute().body();
response = responseBody.string().trim();
sBody = response;
Gson gson = new GsonBuilder()
.setLenient()
.create();
} catch (IOException e) {
Log.e("Parse func error", "stack trace");
e.printStackTrace();
}
Log.e("Parse", "Printing parsed json");
Log.e("responeBody", "Printing");
System.out.println(response);
makeFileAndWrite(sBody,context);
}
public static void makeFileAndWrite(String sBody, Context context) {
String sFileName = "locations.geojson";
try {
File root = new File(context.getFilesDir().getPath(), sFileName);
if (!root.exists()) {
root.mkdirs();
}
Log.e("Printing", "internal storage directory");
System.out.println(root.toString());
FileWriter writer = new FileWriter(root);
Log.e("Printing", "sBody");
writer.append(sBody);
Log.e("mFAW", "Written content");
System.out.println(sBody);
writer.flush();
writer.close();
Log.e("MKFAWR","SAVED");
} catch (IOException e) {
e.printStackTrace();
}
}
}
package com.creanet.najdidefibrilator;
import android.Manifest;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings;
import android.util.JsonReader;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
......@@ -17,15 +26,24 @@ import androidx.core.content.ContextCompat;
import com.bumptech.glide.Glide;
import com.crashlytics.android.Crashlytics;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.File;
import java.io.FileWriter;