Merge branch 'master' of github.com:sagidayan/TheSocialNotework-Android
This commit is contained in:
commit
bae59c7332
5 changed files with 154 additions and 53 deletions
|
@ -2,8 +2,11 @@ package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
//import android.app.Fragment;
|
//import android.app.Fragment;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
@ -19,15 +22,23 @@ import com.google.android.gms.maps.GoogleMap;
|
||||||
import com.google.android.gms.maps.MapFragment;
|
import com.google.android.gms.maps.MapFragment;
|
||||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||||
import com.google.android.gms.maps.SupportMapFragment;
|
import com.google.android.gms.maps.SupportMapFragment;
|
||||||
|
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
||||||
|
import com.google.android.gms.maps.model.CameraPosition;
|
||||||
import com.google.android.gms.maps.model.LatLng;
|
import com.google.android.gms.maps.model.LatLng;
|
||||||
|
import com.google.android.gms.maps.model.Marker;
|
||||||
import com.google.android.gms.maps.model.MarkerOptions;
|
import com.google.android.gms.maps.model.MarkerOptions;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Timer;
|
||||||
|
|
||||||
|
|
||||||
public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
|
@ -40,24 +51,10 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
private GPSUtils gpsUtils;
|
private GPSUtils gpsUtils;
|
||||||
private MainActivity mainActivity;
|
private MainActivity mainActivity;
|
||||||
|
|
||||||
// TODO: Rename and change types of parameters
|
|
||||||
private String mParam1;
|
public GmapFragment() {}
|
||||||
private String mParam2;
|
|
||||||
|
|
||||||
|
|
||||||
public GmapFragment() {
|
|
||||||
// Required empty public constructor
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this factory method to create a new instance of
|
|
||||||
* this fragment using the provided parameters.
|
|
||||||
*
|
|
||||||
* @param param1 Parameter 1.
|
|
||||||
* @param param2 Parameter 2.
|
|
||||||
* @return A new instance of fragment GmapFragment.
|
|
||||||
*/
|
|
||||||
// TODO: Rename and change types and number of parameters
|
|
||||||
public static GmapFragment newInstance(String param1, String param2) {
|
public static GmapFragment newInstance(String param1, String param2) {
|
||||||
GmapFragment fragment = new GmapFragment();
|
GmapFragment fragment = new GmapFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
@ -67,13 +64,13 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GoogleMap getMap() {
|
||||||
|
return mMap;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (getArguments() != null) {
|
|
||||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
|
||||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
|
||||||
}
|
|
||||||
mainActivity = (MainActivity) getActivity();
|
mainActivity = (MainActivity) getActivity();
|
||||||
|
|
||||||
gpsUtils = mainActivity.getGPSUtils();
|
gpsUtils = mainActivity.getGPSUtils();
|
||||||
|
@ -105,23 +102,29 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMapReady(GoogleMap googleMap) {
|
public void onMapReady(GoogleMap googleMap) {
|
||||||
|
|
||||||
mMap = googleMap;
|
mMap = googleMap;
|
||||||
|
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCameraChange(CameraPosition cameraPosition) {
|
||||||
|
if (cameraPosition.zoom > 14) {
|
||||||
|
getMap().animateCamera(CameraUpdateFactory.zoomTo(14));
|
||||||
|
}
|
||||||
|
if (cameraPosition.zoom < 8) {
|
||||||
|
getMap().animateCamera(CameraUpdateFactory.zoomTo(8));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
VolleyUtilSingleton.getInstance(getActivity()).get(mainActivity.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, mainActivity.genericErrorListener);
|
VolleyUtilSingleton.getInstance(getActivity()).get(mainActivity.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, mainActivity.genericErrorListener);
|
||||||
|
// VolleyUtilSingleton.getInstance(getActivity()).get(mainActivity.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, mainActivity.genericErrorListener);
|
||||||
LatLng userLocation = new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude());
|
LatLng userLocation = new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude());
|
||||||
mMap.addMarker(new MarkerOptions().position(userLocation).title("I Am Here!"));
|
// mMap.addMarker(new MarkerOptions().position(userLocation).title("I Am Here!"));
|
||||||
if (ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
// TODO: Consider calling
|
|
||||||
// ActivityCompat#requestPermissions
|
|
||||||
// here to request the missing permissions, and then overriding
|
|
||||||
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
|
||||||
// int[] grantResults)
|
|
||||||
// to handle the case where the user grants the permission. See the documentation
|
|
||||||
// for ActivityCompat#requestPermissions for more details.
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mMap.setMyLocationEnabled(true);
|
mMap.setMyLocationEnabled(true);
|
||||||
|
@ -143,36 +146,87 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
for (int i = 0; i < noteObjectsArray.length(); i++) {
|
for (int i = 0; i < noteObjectsArray.length(); i++) {
|
||||||
JSONObject noteObject = noteObjectsArray.getJSONObject(i);
|
JSONObject noteObject = noteObjectsArray.getJSONObject(i);
|
||||||
time.setTime(noteObject.getLong("created_at"));
|
time.setTime(noteObject.getLong("created_at"));
|
||||||
|
|
||||||
listOfNotes.add(mainActivity.getNoteFromJsonObj(noteObject, time));
|
listOfNotes.add(mainActivity.getNoteFromJsonObj(noteObject, time));
|
||||||
}
|
}
|
||||||
addNotesToMap(listOfNotes);
|
new getMarkersFromNotes(mMap).execute(listOfNotes);
|
||||||
// noteList.setAdapter(noteListAdapter);
|
// noteList.setAdapter(noteListAdapter);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "newNoteSuccess:" + e.getMessage());
|
Log.e(TAG, "newNoteSuccess:" + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void addNotesToMap(List<Note> listOfNotes) {
|
|
||||||
for(Note note : listOfNotes){
|
|
||||||
String title = note.getTitle();
|
public Bitmap getBitmapFromURL(String imageUrl) {
|
||||||
float lat = note.getLat();
|
|
||||||
float lng = note.getLon();
|
try {
|
||||||
mMap.addMarker(new MarkerOptions().position(new LatLng(lat,lng)).title(title));
|
URL url = new URL(imageUrl);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.connect();
|
||||||
|
InputStream input = connection.getInputStream();
|
||||||
|
Bitmap myBitmap = BitmapFactory.decodeStream(input);
|
||||||
|
Log.d(TAG, "image: " + myBitmap.toString());
|
||||||
|
return Bitmap.createScaledBitmap(myBitmap, 80, 80, false);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
private class getMarkersFromNotes extends AsyncTask<List<Note>, MarkerOptions, List<MarkerOptions>> {
|
||||||
* This interface must be implemented by activities that contain this
|
GoogleMap mMap;
|
||||||
* fragment to allow an interaction in this fragment to be communicated
|
// GmapFragment gmap;
|
||||||
* to the activity and potentially other fragments contained in that
|
|
||||||
* activity.
|
public getMarkersFromNotes(GoogleMap map) {
|
||||||
* <p/>
|
mMap = map;
|
||||||
* See the Android Training lesson <a href=
|
// gmap = GmapFragment.
|
||||||
* "http://developer.android.com/training/basics/fragments/communicating.html"
|
// mMap = GmapFragment.getMap();
|
||||||
* >Communicating with Other Fragments</a> for more information.
|
Log.d(TAG, "in async ctor");
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(MarkerOptions... mo) {
|
||||||
|
mMap.addMarker(mo[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(List<MarkerOptions> markerOptionList) {
|
||||||
|
for (MarkerOptions mo : markerOptionList) {
|
||||||
|
mMap.addMarker(mo);
|
||||||
|
}
|
||||||
|
Log.d(TAG, "in async post");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<MarkerOptions> doInBackground(List<Note>... listOfNotes) {
|
||||||
|
Log.d(TAG, "in async BG");
|
||||||
|
|
||||||
|
String url = "http://www.aljazeera.com/mritems/images/site/DefaultAvatar.jpg";
|
||||||
|
List<MarkerOptions> markerOptionList = new ArrayList<>();
|
||||||
|
// for (int i = 0 ; i< listOfNotes.length; i++)
|
||||||
|
for (Note n : listOfNotes[0]) {
|
||||||
|
// markerOptionList.add(
|
||||||
|
MarkerOptions mo = new MarkerOptions()
|
||||||
|
.title(n.getTitle())
|
||||||
|
.position(new LatLng(n.getLat(), n.getLon()))
|
||||||
|
.snippet(n.getBody())
|
||||||
|
.icon(BitmapDescriptorFactory.fromBitmap(getBitmapFromURL(url)));
|
||||||
|
publishProgress(mo);
|
||||||
|
// );
|
||||||
|
|
||||||
|
}
|
||||||
|
return markerOptionList;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by JERLocal on 7/2/2016.
|
* Created by aranza on 7/2/2016.
|
||||||
*/
|
*/
|
||||||
public class HeavyWorker extends AsyncTask< String , Context , Void > {
|
public class HeavyWorker extends AsyncTask< String , Context , Void > {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by aran on 5/26/16.
|
||||||
|
*/
|
||||||
|
import com.android.volley.toolbox.ImageLoader.ImageCache;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.support.v4.util.LruCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class to extend the LruCache class - for better image caching
|
||||||
|
*/
|
||||||
|
public class LruBitmapCache extends LruCache<String, Bitmap> implements ImageCache {
|
||||||
|
public static int getDefaultLruCacheSize() {
|
||||||
|
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
|
||||||
|
final int cacheSize = maxMemory / 8;
|
||||||
|
|
||||||
|
return cacheSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LruBitmapCache() {
|
||||||
|
this(getDefaultLruCacheSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
public LruBitmapCache(int sizeInKiloBytes) {
|
||||||
|
super(sizeInKiloBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int sizeOf(String key, Bitmap value) {
|
||||||
|
return value.getRowBytes() * value.getHeight() / 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Bitmap getBitmap(String url) {
|
||||||
|
return get(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void putBitmap(String url, Bitmap bitmap) {
|
||||||
|
put(url, bitmap);
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.StrictMode;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
@ -59,6 +60,9 @@ public class MainActivity extends AppCompatActivity
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
gmapFragment = new GmapFragment();
|
gmapFragment = new GmapFragment();
|
||||||
personalFragment = new PersonalFragment();
|
personalFragment = new PersonalFragment();
|
||||||
|
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||||
|
StrictMode.setThreadPolicy(policy);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class VolleyUtilSingleton {
|
||||||
|
|
||||||
private static VolleyUtilSingleton mInstance;
|
private static VolleyUtilSingleton mInstance;
|
||||||
private RequestQueue mRequestQueue;
|
private RequestQueue mRequestQueue;
|
||||||
// private ImageLoader mImageLoader;
|
private ImageLoader mImageLoader;
|
||||||
private static Context mCtx;
|
private static Context mCtx;
|
||||||
private final String TAG = "VolleyUtilSingleton";
|
private final String TAG = "VolleyUtilSingleton";
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public class VolleyUtilSingleton {
|
||||||
mCtx = context;
|
mCtx = context;
|
||||||
mRequestQueue = getRequestQueue();
|
mRequestQueue = getRequestQueue();
|
||||||
|
|
||||||
// mImageLoader = new ImageLoader(this.mRequestQueue,new LruBitmapCache());
|
mImageLoader = new ImageLoader(this.mRequestQueue,new LruBitmapCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized VolleyUtilSingleton getInstance(Context context) {
|
public static synchronized VolleyUtilSingleton getInstance(Context context) {
|
||||||
|
@ -52,9 +52,9 @@ public class VolleyUtilSingleton {
|
||||||
getRequestQueue().add(req);
|
getRequestQueue().add(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public ImageLoader getImageLoader() {
|
public ImageLoader getImageLoader() {
|
||||||
// return mImageLoader;
|
return mImageLoader;
|
||||||
// }
|
}
|
||||||
|
|
||||||
public void newUser(String url, JSONObject body) {
|
public void newUser(String url, JSONObject body) {
|
||||||
JsonObjectRequest request =
|
JsonObjectRequest request =
|
||||||
|
|
Loading…
Reference in a new issue