From 2ca5d59ee2a25707050476b9492c3a088632a3e2 Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Wed, 6 Jul 2016 20:30:57 +0300 Subject: [PATCH 1/2] Merge branch 'master' of https://github.com/sagidayan/TheSocialNotework-Android # Conflicts: # .idea/libraries/animated_vector_drawable_23_3_0.xml # .idea/libraries/appcompat_v7_23_3_0.xml # .idea/libraries/design_23_3_0.xml # .idea/libraries/recyclerview_v7_23_3_0.xml # .idea/libraries/support_annotations_23_4_0.xml # .idea/libraries/support_v4_23_3_0.xml # .idea/libraries/support_vector_drawable_23_3_0.xml # app/src/main/AndroidManifest.xml # app/src/main/res/values/strings.xml --- .../animated_vector_drawable_23_3_0.xml | 13 --- .idea/libraries/appcompat_v7_23_3_0.xml | 16 ---- .idea/libraries/design_23_3_0.xml | 16 ---- .idea/libraries/recyclerview_v7_23_3_0.xml | 16 ---- .../libraries/support_annotations_23_3_0.xml | 12 --- .idea/libraries/support_v4_23_3_0.xml | 17 ---- .../support_vector_drawable_23_3_0.xml | 13 --- app/build.gradle | 7 +- app/src/main/AndroidManifest.xml | 33 ++++++-- .../sagi/thesocialnotework/MainActivity.java | 82 +++++++++++++++++-- .../sagi/thesocialnotework/MapsActivity.java | 68 --------------- app/src/main/res/layout/activity_maps.xml | 9 -- app/src/main/res/layout/fragment_gmap.xml | 21 +++++ app/src/main/res/values/strings.xml | 1 + 14 files changed, 127 insertions(+), 197 deletions(-) delete mode 100644 .idea/libraries/animated_vector_drawable_23_3_0.xml delete mode 100644 .idea/libraries/appcompat_v7_23_3_0.xml delete mode 100644 .idea/libraries/design_23_3_0.xml delete mode 100644 .idea/libraries/recyclerview_v7_23_3_0.xml delete mode 100644 .idea/libraries/support_annotations_23_3_0.xml delete mode 100644 .idea/libraries/support_v4_23_3_0.xml delete mode 100644 .idea/libraries/support_vector_drawable_23_3_0.xml delete mode 100644 app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MapsActivity.java delete mode 100644 app/src/main/res/layout/activity_maps.xml create mode 100644 app/src/main/res/layout/fragment_gmap.xml diff --git a/.idea/libraries/animated_vector_drawable_23_3_0.xml b/.idea/libraries/animated_vector_drawable_23_3_0.xml deleted file mode 100644 index b3f679b..0000000 --- a/.idea/libraries/animated_vector_drawable_23_3_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/appcompat_v7_23_3_0.xml b/.idea/libraries/appcompat_v7_23_3_0.xml deleted file mode 100644 index da50caa..0000000 --- a/.idea/libraries/appcompat_v7_23_3_0.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/design_23_3_0.xml b/.idea/libraries/design_23_3_0.xml deleted file mode 100644 index 26dbcf3..0000000 --- a/.idea/libraries/design_23_3_0.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/recyclerview_v7_23_3_0.xml b/.idea/libraries/recyclerview_v7_23_3_0.xml deleted file mode 100644 index b353d5e..0000000 --- a/.idea/libraries/recyclerview_v7_23_3_0.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_annotations_23_3_0.xml b/.idea/libraries/support_annotations_23_3_0.xml deleted file mode 100644 index fd1ab9e..0000000 --- a/.idea/libraries/support_annotations_23_3_0.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_v4_23_3_0.xml b/.idea/libraries/support_v4_23_3_0.xml deleted file mode 100644 index 98d1b53..0000000 --- a/.idea/libraries/support_v4_23_3_0.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_vector_drawable_23_3_0.xml b/.idea/libraries/support_vector_drawable_23_3_0.xml deleted file mode 100644 index 2d70087..0000000 --- a/.idea/libraries/support_vector_drawable_23_3_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index b0751b4..6750108 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,8 +22,9 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:23.3.0' - compile 'com.android.support:design:23.3.0' + compile 'com.android.support:appcompat-v7:23.4.0' + compile 'com.android.support:design:23.4.0' compile 'com.android.volley:volley:1.0.0' - compile 'com.android.support:support-v4:23.3.0' + compile 'com.android.support:support-v4:23.4.0' + compile 'com.google.android.gms:play-services:9.2.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 330e51d..ff7708a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,6 @@ - @@ -21,23 +20,39 @@ android:theme="@style/AppTheme"> + android:noHistory="true" + android:theme="@style/AppTheme.NoActionBar"> - - + - + android:theme="@style/AppTheme.NoActionBar" /> + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java index 7761f25..5242ac1 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java @@ -17,14 +17,29 @@ import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; +import com.android.volley.Response; +import com.android.volley.VolleyError; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { - protected final String TAG = "[TSN / MainActivity]"; + protected static final String TAG = "[TSN / MainActivity]"; protected String userId; private GPSUtils gpsUtils; private boolean locationPermission; public static ProgressDialog progress; + private GmapFragment gmapFragment; + private PersonalFragment personalFragment; + public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api"; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -32,6 +47,8 @@ public class MainActivity extends AppCompatActivity setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); + gmapFragment = new GmapFragment(); + personalFragment = new PersonalFragment(); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @@ -58,7 +75,7 @@ public class MainActivity extends AppCompatActivity //Change Layout Log.d(TAG, "Changing Fragment to Personal Activity"); - PersonalFragment personalFragment = new PersonalFragment(); +// PersonalFragment personalFragment = new PersonalFragment(); personalFragment.setArguments(b); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.fragment_container, personalFragment); @@ -104,15 +121,26 @@ public class MainActivity extends AppCompatActivity @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { - // Handle navigation view item clicks here. + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + Bundle b = new Bundle(); + int id = item.getItemId(); if (id == R.id.nav_explore) { // Handle the camera action } else if (id == R.id.nav_map) { - +// + Log.d(TAG,"Before going to map"); +// gmapFragment.("note_list", (ArrayList) listOfNotes); +// gmapFragment.put("user_lat", gpsUtils.getLatitude()); +// gmapFragment.putExtra("user_lng", gpsUtils.getLongitude()); + ft.replace(R.id.fragment_container, gmapFragment); + ft.commit(); } else if (id == R.id.nav_personal) { + Log.d(TAG,"Before going to personal"); + ft.replace(R.id.fragment_container, personalFragment); + ft.commit(); } else if (id == R.id.nav_settings) { } else if (id == R.id.nav_logout) { @@ -122,7 +150,9 @@ public class MainActivity extends AppCompatActivity DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; - }public GPSUtils getGPSUtils() { + } + + public GPSUtils getGPSUtils() { return this.gpsUtils; } @@ -149,6 +179,48 @@ public class MainActivity extends AppCompatActivity } } + // //Generic response ErrorListener + Response.ErrorListener genericErrorListener = new Response.ErrorListener() { + @Override + public void onErrorResponse(VolleyError error) { + Log.d(TAG, "genericErrorListener"); + error.printStackTrace(); + } + }; + public Note getNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException { +// List listOfNotes = new ArrayList<>(); + + Note note = new Note( + noteObject.getString("id"), + Float.parseFloat(noteObject.getJSONObject("location").getString("lat")), + Float.parseFloat(noteObject.getJSONObject("location").getString("lng")), + noteObject.getJSONObject("location").getString("address"), + noteObject.getString("title"), + noteObject.getString("body"), + time.toString(), + noteObject.getBoolean("is_public"), + noteObject.getInt("likes"), + jsonArrayToStringArray(noteObject.getJSONArray("tags")) + ); + return note; +// listOfNotes.add(addNote); + + } + + public ArrayList jsonArrayToStringArray(JSONArray jArray) { + ArrayList stringArray = new ArrayList(); + for (int i = 0, count = jArray.length(); i < count; i++) { + try { + JSONObject jsonObject = jArray.getJSONObject(i); + stringArray.add(jsonObject.toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + return stringArray; + } + + public String getUserId(){return userId;} } diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MapsActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MapsActivity.java deleted file mode 100644 index 9841f90..0000000 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MapsActivity.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.android_app.matan.ara.sagi.thesocialnotework; - -import android.content.Intent; -import android.support.v4.app.FragmentActivity; -import android.os.Bundle; -import android.util.Log; -import android.widget.Toast; - -//import com.google.android.gms.maps.CameraUpdateFactory; -//import com.google.android.gms.maps.GoogleMap; -//import com.google.android.gms.maps.OnMapReadyCallback; -//import com.google.android.gms.maps.SupportMapFragment; -//import com.google.android.gms.maps.model.LatLng; -//import com.google.android.gms.maps.model.MarkerOptions; - -import java.util.ArrayList; -// -//public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { -//// -//// private GoogleMap mMap; -//// private ArrayList listOfNotes; -//// private float userLat, userLng; -// -// @Override -// protected void onCreate(Bundle savedInstanceState) { -// super.onCreate(savedInstanceState); -// setContentView(R.layout.activity_maps); -// // Obtain the SupportMapFragment and get notified when the map is ready to be used. -// SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() -// .findFragmentById(R.id.map); -// mapFragment.getMapAsync(this); -// -// Log.d("Tag","in maps create"); -// listOfNotes = getIntent().getParcelableArrayListExtra("note_list"); -// userLat = getIntent().getFloatExtra("user_lat", -34); -// userLng = getIntent().getFloatExtra("user_lng", 151); -// Toast.makeText(this, listOfNotes.get(1).title, Toast.LENGTH_LONG).show(); -// } -// -// -// /** -// * Manipulates the map once available. -// * This callback is triggered when the map is ready to be used. -// * This is where we can add markers or lines, add listeners or move the camera. In this case, -// * we just add a marker near Sydney, Australia. -// * If Google Play services is not installed on the device, the user will be prompted to install -// * it inside the SupportMapFragment. This method will only be triggered once the user has -// * installed Google Play services and returned to the app. -// */ -// @Override -// public void onMapReady(GoogleMap googleMap) { -// mMap = googleMap; -// -// LatLng userLocation = new LatLng(userLat,userLng); -// LatLng noteLocation = null; -// -// for (Note note :listOfNotes){ -// noteLocation = new LatLng(note.getLat(),note.getLon()); -// mMap.addMarker(new MarkerOptions().position(noteLocation).title(note.getTitle())); -// } -// // Add a marker in Sydney and move the camera -//// LatLng sydney = new LatLng(-34, 151); -//// mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); -// mMap.addMarker(new MarkerOptions().position(userLocation).title("I Am Here!")); -// -// mMap.moveCamera(CameraUpdateFactory.newLatLng(userLocation)); -// } -//} diff --git a/app/src/main/res/layout/activity_maps.xml b/app/src/main/res/layout/activity_maps.xml deleted file mode 100644 index 4cb5c87..0000000 --- a/app/src/main/res/layout/activity_maps.xml +++ /dev/null @@ -1,9 +0,0 @@ - diff --git a/app/src/main/res/layout/fragment_gmap.xml b/app/src/main/res/layout/fragment_gmap.xml new file mode 100644 index 0000000..c0a1fc9 --- /dev/null +++ b/app/src/main/res/layout/fragment_gmap.xml @@ -0,0 +1,21 @@ + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 600e848..8ee5a08 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -37,5 +37,6 @@ Hello blank fragment Password should be at least 4 chars long + Map From 446389953b48c1c7378c64b23a820639297ef4ca Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Wed, 6 Jul 2016 20:31:24 +0300 Subject: [PATCH 2/2] added Gmap fragment --- .../sagi/thesocialnotework/GmapFragment.java | 165 ++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java new file mode 100644 index 0000000..34966f0 --- /dev/null +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java @@ -0,0 +1,165 @@ +package com.android_app.matan.ara.sagi.thesocialnotework; + +import android.content.Context; +import android.location.Location; +import android.net.Uri; +import android.os.Bundle; +//import android.app.Fragment; +import android.support.v4.app.Fragment; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.android.volley.Response; +import com.google.android.gms.maps.CameraUpdateFactory; +import com.google.android.gms.maps.GoogleMap; +import com.google.android.gms.maps.MapFragment; +import com.google.android.gms.maps.OnMapReadyCallback; +import com.google.android.gms.maps.SupportMapFragment; +import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.MarkerOptions; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + +public class GmapFragment extends Fragment implements OnMapReadyCallback { + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM2 = "param2"; + private static final String TAG = "[TSN / GmapFragment]"; + private GoogleMap mMap; + private GPSUtils gpsUtils; + private MainActivity mainActivity; + + // TODO: Rename and change types of parameters + private String mParam1; + 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) { + GmapFragment fragment = new GmapFragment(); + Bundle args = new Bundle(); + args.putString(ARG_PARAM1, param1); + args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mParam1 = getArguments().getString(ARG_PARAM1); + mParam2 = getArguments().getString(ARG_PARAM2); + } + mainActivity = (MainActivity)getActivity(); + + gpsUtils = mainActivity.getGPSUtils(); + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_gmap, container, false); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + SupportMapFragment frag = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.mapFragment); + frag.getMapAsync(this); + } + + + @Override + public void onAttach(Context context) { + super.onAttach(context); + } + + @Override + public void onDetach() { + super.onDetach(); + } + + @Override + public void onMapReady(GoogleMap googleMap) { + + mMap = googleMap; + + VolleyUtilSingleton.getInstance(getActivity()).get(mainActivity.BASE_URL + "/note/all?uid=" +mainActivity.getUserId() , getNotesSuccessListener, mainActivity.genericErrorListener); + + LatLng userLocation = new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude()); + mMap.addMarker(new MarkerOptions().position(userLocation).title("I Am Here!")); + mMap.moveCamera(CameraUpdateFactory.newLatLng(userLocation)); + + } + + //response listener for getting all user notes + Response.Listener getNotesSuccessListener = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + Log.d(TAG, "getNotesSuccessListener: " + response.toString()); + List listOfNotes = new ArrayList<>(); + + try { + //need to get all notes and add to listOfNotes + JSONArray noteObjectsArray = response.getJSONArray("notes"); + Date time = new Date(); + for (int i = 0; i < noteObjectsArray.length(); i++) { + JSONObject noteObject = noteObjectsArray.getJSONObject(i); + time.setTime(noteObject.getLong("created_at")); + + listOfNotes.add(mainActivity.getNoteFromJsonObj(noteObject, time)); + } + addNotesToMap(listOfNotes); +// noteList.setAdapter(noteListAdapter); + } catch (Exception e) { + Log.e(TAG, "newNoteSuccess:" + e.getMessage()); + } + } + }; + + private void addNotesToMap(List listOfNotes) { + for(Note note : listOfNotes){ + String title = note.getTitle(); + float lat = note.getLat(); + float lng = note.getLon(); + mMap.addMarker(new MarkerOptions().position(new LatLng(lat,lng)).title(title)); + } + } + + + /** + * This interface must be implemented by activities that contain this + * fragment to allow an interaction in this fragment to be communicated + * to the activity and potentially other fragments contained in that + * activity. + *

+ * See the Android Training lesson Communicating with Other Fragments for more information. + */ + +}