ScheduleLayout.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. package com.ivalentin.gm;
  2. import java.text.DateFormat;
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Calendar;
  6. import java.util.Date;
  7. import java.util.Locale;
  8. import com.google.android.gms.maps.CameraUpdate;
  9. import com.google.android.gms.maps.CameraUpdateFactory;
  10. import com.google.android.gms.maps.GoogleMap;
  11. import com.google.android.gms.maps.MapView;
  12. import com.google.android.gms.maps.MapsInitializer;
  13. import com.google.android.gms.maps.OnMapReadyCallback;
  14. import com.google.android.gms.maps.model.LatLng;
  15. import com.google.android.gms.maps.model.MarkerOptions;
  16. import android.annotation.SuppressLint;
  17. import android.app.Dialog;
  18. import android.content.Context;
  19. import android.content.DialogInterface;
  20. import android.content.DialogInterface.OnCancelListener;
  21. import android.content.DialogInterface.OnShowListener;
  22. import android.database.Cursor;
  23. import android.database.sqlite.SQLiteDatabase;
  24. import android.graphics.drawable.Drawable;
  25. import android.os.Bundle;
  26. import android.support.v4.app.Fragment;
  27. import android.support.v4.content.res.ResourcesCompat;
  28. import android.text.Editable;
  29. import android.text.TextWatcher;
  30. import android.util.Log;
  31. import android.view.LayoutInflater;
  32. import android.view.View;
  33. import android.view.Window;
  34. import android.view.View.OnClickListener;
  35. import android.view.ViewGroup;
  36. import android.view.WindowManager;
  37. import android.widget.Button;
  38. import android.widget.EditText;
  39. import android.widget.LinearLayout;
  40. import android.widget.TextView;
  41. /**
  42. * Fragment to be inflated showing the festivals schedule.
  43. * Contains a date selector and a ScrollView with all the activities for the day.
  44. *
  45. * @author Inigo Valentin
  46. *
  47. */
  48. public class ScheduleLayout extends Fragment implements OnMapReadyCallback{
  49. //Array with data about the days of the festival
  50. private String[][] days = new String[GM.TOTAL_DAYS][4];
  51. //Currently selected day
  52. private int selected;
  53. //Indicates official schedule
  54. private int schedule;
  55. //Arrow buttons
  56. private Button btL, btR;
  57. //TextViews in the date selector
  58. private TextView tvDayNumber, tvDayTitle, tvDayMonth;
  59. //Map stuff for the dialog
  60. private MapView mapView;
  61. private Bundle bund;
  62. private GoogleMap map;
  63. private LatLng location;
  64. private View view;
  65. private String markerName = "";
  66. /**
  67. * Run when the fragment is inflated.
  68. * Assigns views, gets the date and does the first call to the populateSchedule function.
  69. *
  70. * @param inflater A LayoutInflater to manage views
  71. * @param container The container View
  72. * @param savedInstanceState Bundle containing the state
  73. *
  74. * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
  75. */
  76. @SuppressLint("InflateParams") //Throws unknown error when done properly.
  77. @Override
  78. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  79. //Set bundle for the map
  80. bund = savedInstanceState;
  81. //Load the layout
  82. view = inflater.inflate(R.layout.fragment_layout_schedule, null);
  83. //Get schedule type
  84. Bundle bundle = this.getArguments();
  85. schedule = bundle.getInt(GM.SCHEDULE, GM.SECTION_LABLANCA_SCHEDULE);
  86. //Set the title
  87. if (schedule == GM.SECTION_LABLANCA_SCHEDULE)
  88. ((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_lablanca_schedule));
  89. else
  90. ((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_lablanca_gm_schedule));
  91. //Populate days array
  92. days[GM.DAY_25] = new String[] {"2015-07-25", "25", getString(R.string.month_07), getString(R.string.day_title_25)};
  93. days[GM.DAY_4] = new String[] {"2015-08-04", "4", getString(R.string.month_08), getString(R.string.day_title_4)};
  94. days[GM.DAY_5] = new String[] {"2015-08-05", "5", getString(R.string.month_08), getString(R.string.day_title_5)};
  95. days[GM.DAY_6] = new String[] {"2015-08-06", "6", getString(R.string.month_08), getString(R.string.day_title_6)};
  96. days[GM.DAY_7] = new String[] {"2015-08-07", "7", getString(R.string.month_08), getString(R.string.day_title_7)};
  97. days[GM.DAY_8] = new String[] {"2015-08-08", "8", getString(R.string.month_08), getString(R.string.day_title_8)};
  98. days[GM.DAY_9] = new String[] {"2015-08-09", "9", getString(R.string.month_08), getString(R.string.day_title_9)};
  99. //Assign parent layout
  100. final LinearLayout list = (LinearLayout) view.findViewById(R.id.ll_schedule_list);
  101. //Assign textViews
  102. tvDayNumber = (TextView) view.findViewById(R.id.tv_schedule_day_number);
  103. tvDayMonth = (TextView) view.findViewById(R.id.tv_schedule_day_month);
  104. tvDayTitle = (TextView) view.findViewById(R.id.tv_schedule_day_title);
  105. //Assign buttons
  106. btL = (Button) view.findViewById(R.id.bt_schedule_l);
  107. btR = (Button) view.findViewById(R.id.bt_schedule_r);
  108. btL.setOnClickListener(new OnClickListener() {
  109. @Override
  110. public void onClick(View v) {
  111. if (selected > GM.DAY_25){
  112. selected --;
  113. //If August 4 selected and GM schedule, skip
  114. if (selected == GM.DAY_4 && schedule != GM.SECTION_LABLANCA_SCHEDULE)
  115. selected --;
  116. String filter = ((EditText) view.findViewById(R.id.et_schedule_filter)).getText().toString();
  117. populateSchedule(selected, list, schedule, filter);
  118. }
  119. }
  120. });
  121. btR.setOnClickListener(new OnClickListener() {
  122. @Override
  123. public void onClick(View v) {
  124. if (selected < GM.DAY_9){
  125. selected ++;
  126. //If August 4 selected and GM schedule, skip
  127. if (selected == GM.DAY_4 && schedule != GM.SECTION_LABLANCA_SCHEDULE)
  128. selected ++;
  129. String filter = ((EditText) view.findViewById(R.id.et_schedule_filter)).getText().toString();
  130. populateSchedule(selected, list, schedule, filter);
  131. }
  132. }
  133. });
  134. //Assign the filter text
  135. EditText etFilter = (EditText) view.findViewById(R.id.et_schedule_filter);
  136. etFilter.addTextChangedListener(new TextWatcher() {
  137. @Override
  138. public void afterTextChanged(Editable s) { }
  139. @Override
  140. public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
  141. @Override
  142. public void onTextChanged(CharSequence s, int start, int before, int count) {
  143. //Repopulate when the text is changed
  144. populateSchedule(selected, list, schedule, s.toString());
  145. }
  146. });
  147. //Get the date
  148. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
  149. Date date = new Date();
  150. String curDate = dateFormat.format(date);
  151. //Try to find out if the current date is before, after, or in the middle of the festivals.
  152. try {
  153. if (dateFormat.parse(curDate).before(dateFormat.parse(days[GM.DAY_25][0]))){
  154. selected = GM.DAY_25;
  155. }
  156. else if (dateFormat.parse(curDate).after(dateFormat.parse(days[GM.DAY_9][0]))){
  157. selected = GM.DAY_9;
  158. }
  159. else{
  160. for (int i = 0; i < GM.TOTAL_DAYS; i++){
  161. if (curDate.equals(days[i][0])){
  162. selected = i;
  163. }
  164. }
  165. }
  166. //If August 4 and Margolari schedule, move one day forward
  167. if (selected == GM.DAY_4 && schedule != GM.SECTION_LABLANCA_SCHEDULE){
  168. selected ++;
  169. }
  170. }
  171. catch (ParseException e) {
  172. selected = GM.DAY_25;
  173. Log.e("Error selecting date", e.toString());
  174. }
  175. //Populate the activity list
  176. populateSchedule(selected, list, schedule, "");
  177. //Return the fragment view
  178. return view;
  179. }
  180. /**
  181. * Populates the list of activities with the ones n the selected day.
  182. *
  183. * @param selected The day to show activities from
  184. * @param list The layout where the items will be added
  185. * @param schedule GM.SECTION_SCHEDULE if city schedule, GM.SECTION_GM_SCHEDULE if gm schedule
  186. * @param f Search filter texts
  187. */
  188. @SuppressLint("InflateParams") //Views are added from a loop: I can't specify the parent when inflating.
  189. private void populateSchedule(int selected, LinearLayout list, int schedule, String f){
  190. //A layout to be populated with one activity
  191. LinearLayout entry, content;
  192. //The filter
  193. String filter = f.toLowerCase(Locale.US);
  194. //An inflater
  195. LayoutInflater factory = LayoutInflater.from(getActivity());
  196. //Views in each row
  197. TextView tvRowTitle, tvRowTime, tvRowDesc, tvRowPlace, tvRowId;
  198. //Icon next to the location text
  199. Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.pinpoint, null);
  200. //icon.setBounds(0, 0, 80, 80);
  201. //Set date selector texts
  202. tvDayNumber.setText(days[selected][1]);
  203. tvDayMonth.setText(days[selected][2]);
  204. tvDayTitle.setText(days[selected][3]);
  205. //Show or hide the arrow buttons
  206. switch (selected){
  207. case GM.DAY_25:
  208. btL.setVisibility(View.INVISIBLE);
  209. btR.setVisibility(View.VISIBLE);
  210. break;
  211. case GM.DAY_9:
  212. btL.setVisibility(View.VISIBLE);
  213. btR.setVisibility(View.INVISIBLE);
  214. break;
  215. default:
  216. btL.setVisibility(View.VISIBLE);
  217. btR.setVisibility(View.VISIBLE);
  218. }
  219. //Read from database
  220. SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB_NAME, Context.MODE_PRIVATE, null);
  221. Cursor cursor;
  222. //Elements to parse, format and operate with dates
  223. Calendar cal;
  224. Date maxDate, minDate;
  225. String maxDateStr, minDateStr;
  226. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
  227. SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
  228. cal = Calendar.getInstance();
  229. //Get date of the selected daye
  230. try {
  231. cal.setTime(dayFormat.parse(days[selected][0]));
  232. } catch (ParseException e) {
  233. Log.e("Error parsing date", e.toString());
  234. }
  235. //Set margins so the days goes from 6:00 in the morning to 5:59 the next day, instead of from 00:00 to 23:59
  236. cal.add(Calendar.HOUR_OF_DAY, 6);
  237. minDate = cal.getTime();
  238. //If its the last day, include events of the next one
  239. if (selected == GM.DAY_9)
  240. cal.add(Calendar.HOUR_OF_DAY, 36);
  241. else
  242. cal.add(Calendar.HOUR_OF_DAY, 24);
  243. maxDate = cal.getTime();
  244. maxDateStr = dateFormat.format(maxDate);
  245. minDateStr = dateFormat.format(minDate);
  246. //Get data from database
  247. if (schedule == GM.SECTION_LABLANCA_GM_SCHEDULE)
  248. cursor = db.rawQuery("SELECT event.id, event.name, event.description, event.place, place.id, place.name, event.start FROM " + GM.DB_EVENT + ", " + GM.DB_PLACE + " WHERE " + GM.DB_EVENT_GM + " = 1 AND place.id = event.place AND start BETWEEN '" + minDateStr + "' AND '" + maxDateStr + "' AND (lower(event.name) LIKE '%" + filter + "%' OR lower(event.description) LIKE '%" + filter + "%' OR lower(place.name) LIKE '%" + filter + "%') ORDER BY " + GM.DB_EVENT_START + ";", null);
  249. else
  250. cursor = db.rawQuery("SELECT event.id, event.name, event.description, event.place, place.id, place.name, event.start FROM " + GM.DB_EVENT + ", " + GM.DB_PLACE + " WHERE " + GM.DB_EVENT_SCHEDULE + " = 1 AND place.id = event.place AND start BETWEEN '" + minDateStr + "' AND '" + maxDateStr + "' AND (lower(event.name) LIKE '%" + filter + "%' OR lower(event.description) LIKE '%" + filter + "%' OR lower(place.name) LIKE '%" + filter + "%') ORDER BY " + GM.DB_EVENT_START + ";", null);
  251. //Clear the list
  252. list.removeAllViews();
  253. //Loop
  254. while (cursor.moveToNext()){
  255. //Create a new row
  256. entry = (LinearLayout) factory.inflate(R.layout.row_schedule, null);
  257. //Set id
  258. tvRowId = (TextView) entry.findViewById(R.id.tv_row_schedule_id);
  259. tvRowId.setText(cursor.getString(0));
  260. //Set title
  261. tvRowTitle = (TextView) entry.findViewById(R.id.tv_row_schedule_title);
  262. tvRowTitle.setText(cursor.getString(1));
  263. //Set description
  264. tvRowDesc = (TextView) entry.findViewById(R.id.tv_row_schedule_description);
  265. tvRowDesc.setText(cursor.getString(2));
  266. //Set place
  267. tvRowPlace = (TextView) entry.findViewById(R.id.tv_row_schedule_place);
  268. tvRowPlace.setText(cursor.getString(5));
  269. icon.setBounds(0, 0, (int) (tvRowPlace.getTextSize() * 1.5), (int) (tvRowPlace.getTextSize() * 1.5));
  270. tvRowPlace.setCompoundDrawables(icon, null, null, null);
  271. //Set time
  272. tvRowTime = (TextView) entry.findViewById(R.id.tv_row_schedule_time);
  273. String tm = cursor.getString(6).substring(cursor.getString(6).length() - 8, cursor.getString(6).length() - 3);
  274. tvRowTime.setText(tm);
  275. //Set onClick event
  276. content = (LinearLayout) entry.findViewById(R.id.ll_row_schedule_content);
  277. content.setOnClickListener(new OnClickListener(){
  278. @Override
  279. public void onClick(View v) {
  280. TextView tvName = (TextView) v.findViewById(R.id.tv_row_schedule_id);
  281. int id = Integer.parseInt(tvName.getText().toString());
  282. showDialog(id);
  283. }
  284. });
  285. //Add to the list
  286. list.addView(entry);
  287. }
  288. //Invalidate the list so it is redrawn
  289. list.invalidate();
  290. //Close cursor and database
  291. cursor.close();
  292. db.close();
  293. }
  294. /**
  295. * Shows a dialog with info about the selected event.
  296. *
  297. * @param id The event id
  298. */
  299. private void showDialog(final int id){
  300. //Create the dialog
  301. final Dialog dialog = new Dialog(getActivity());
  302. //Set up dialog window
  303. dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  304. dialog.setContentView(R.layout.dialog_schedule);
  305. //Date formatters
  306. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
  307. SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd-", Locale.US);
  308. SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.US);
  309. //Set the custom dialog components - text, image and button
  310. TextView tvTitle = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_title);
  311. TextView tvDescription = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_description);
  312. TextView tvHost = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_host);
  313. TextView tvDate = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_date);
  314. TextView tvTime = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_time);
  315. TextView tvPlace = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_place);
  316. TextView tvAddress = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_address);
  317. Button btClose = (Button) dialog.findViewById(R.id.bt_schedule_close);
  318. //Get info about the event
  319. SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB_NAME, Context.MODE_PRIVATE, null);
  320. Cursor cursor = db.rawQuery("SELECT event.id, event.name, description, start, end, place.name, address, lat, lon, host FROM event, place WHERE place.id = event.place AND event.id = " + id + ";", null);
  321. if (cursor.getCount() > 0){
  322. cursor.moveToNext();
  323. //Set title
  324. tvTitle.setText(cursor.getString(1));
  325. markerName = cursor.getString(1);
  326. //Set description
  327. tvDescription.setText(cursor.getString(2));
  328. //Set host
  329. if (cursor.getString(9) != null){
  330. Cursor hostCursor = db.rawQuery("SELECT name FROM people WHERE id = " + cursor.getString(9) + ";", null);
  331. if (hostCursor.moveToNext()){
  332. tvHost.setVisibility(View.VISIBLE);
  333. tvHost.setText(String.format(getString(R.string.schedule_host), hostCursor.getString(0)));
  334. }
  335. }
  336. else{
  337. tvHost.setVisibility(View.GONE);
  338. }
  339. //Set date
  340. try{
  341. Date day = dateFormat.parse(cursor.getString(3));
  342. Date date = new Date();
  343. //If the event is today, show "Today" instead of the date
  344. if (dayFormat.format(day).equals(dayFormat.format(date)))
  345. tvDate.setText(dialog.getContext().getString(R.string.today));
  346. else{
  347. Calendar cal = Calendar.getInstance();
  348. cal.setTime(date);
  349. cal.add(Calendar.HOUR_OF_DAY, 24);
  350. //If the event is tomorrow, show "Tomorrow" instead of the date
  351. if (dayFormat.format(cal.getTime()).equals(dayFormat.format(date))){
  352. tvDate.setText(dialog.getContext().getString(R.string.tomorrow));
  353. }
  354. //Else, show the date
  355. else{
  356. SimpleDateFormat printFormat = new SimpleDateFormat("dd MMMM", Locale.US);
  357. tvDate.setText(printFormat.format(day));
  358. }
  359. }
  360. }
  361. catch (Exception ex){
  362. Log.e("Error parsing date", ex.toString());
  363. }
  364. //Set time
  365. try{
  366. if (cursor.getString(4) == null)
  367. tvTime.setText(timeFormat.format(dateFormat.parse(cursor.getString(3))));
  368. else
  369. tvTime.setText(timeFormat.format(dateFormat.parse(cursor.getString(3))) + " - " + timeFormat.format(dateFormat.parse(cursor.getString(4))));
  370. }
  371. catch (ParseException ex){
  372. Log.e("Error parsing time", ex.toString());
  373. }
  374. //Set the place
  375. tvPlace.setText(cursor.getString(5));
  376. tvAddress.setText(cursor.getString(6));
  377. //Set up map
  378. location = new LatLng(Double.parseDouble(cursor.getString(7)), Double.parseDouble(cursor.getString(8)));
  379. mapView = (MapView) dialog.findViewById(R.id.mv_dialog_schedule_map);
  380. mapView.onCreate(bund);
  381. //Close the db connection
  382. cursor.close();
  383. db.close();
  384. //Set close button
  385. btClose.setOnClickListener(new OnClickListener() {
  386. @Override
  387. public void onClick(View v) {
  388. dialog.dismiss();
  389. }
  390. });
  391. //Actions to take when the dialog is cancelled
  392. dialog.setOnCancelListener(new OnCancelListener(){
  393. @Override
  394. public void onCancel(DialogInterface dialog) {
  395. if (map != null)
  396. map.setMyLocationEnabled(false);
  397. if (mapView != null){
  398. mapView.onResume();
  399. mapView.onDestroy();
  400. }
  401. }
  402. });
  403. //Show the dialog
  404. WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
  405. lp.dimAmount = 0.0f;
  406. dialog.show();
  407. //Start the map
  408. startMap();
  409. mapView.onResume();
  410. dialog.setOnShowListener(new OnShowListener(){
  411. @Override
  412. public void onShow(DialogInterface dialog) {
  413. // Gets to GoogleMap from the MapView and does initialization stuff
  414. startMap();
  415. }
  416. });
  417. }
  418. }
  419. /**
  420. * Starts the map in the dialog.
  421. */
  422. private void startMap(){
  423. mapView.getMapAsync(this);
  424. }
  425. /**
  426. * Called when the fragment is brought back into the foreground.
  427. * Resumes the map and the location manager.
  428. *
  429. * @see android.support.v4.app.Fragment#onResume()
  430. */
  431. @Override
  432. public void onResume() {
  433. if (mapView != null)
  434. mapView.onResume();
  435. if (map != null)
  436. map.setMyLocationEnabled(true);
  437. super.onResume();
  438. }
  439. /**
  440. * Called when the fragment is destroyed.
  441. * Finishes the map.
  442. *
  443. * @see android.support.v4.app.Fragment#onDestroy()
  444. */
  445. @Override
  446. public void onDestroy() {
  447. super.onDestroy();
  448. if (map != null)
  449. map.setMyLocationEnabled(false);
  450. if (mapView != null){
  451. mapView.onResume();
  452. mapView.onDestroy();
  453. }
  454. }
  455. /**
  456. * Called when the fragment is paused.
  457. * Finishes the map.
  458. *
  459. * @see android.support.v4.app.Fragment#onPause()
  460. */
  461. @Override
  462. public void onPause() {
  463. super.onDestroy();
  464. if (map != null)
  465. map.setMyLocationEnabled(false);
  466. if (mapView != null){
  467. mapView.onPause();
  468. }
  469. }
  470. /**
  471. * Called in a situation of low memory.
  472. * Lets the map handle this situation.
  473. *
  474. * @see android.support.v4.app.Fragment#onLowMemory()
  475. */
  476. @Override
  477. public void onLowMemory() {
  478. super.onLowMemory();
  479. if (mapView != null){
  480. mapView.onResume();
  481. mapView.onLowMemory();
  482. }
  483. }
  484. /**
  485. * Called when the map is ready to be displayed.
  486. * Sets the map options and a marker for the map.
  487. *
  488. * @param googleMap The map to be shown
  489. *
  490. * @see com.google.android.gms.maps.OnMapReadyCallback#onMapReady(com.google.android.gms.maps.GoogleMap)
  491. */
  492. @Override
  493. public void onMapReady(GoogleMap googleMap) {
  494. this.map = googleMap;
  495. map.setMyLocationEnabled(true);
  496. map.getUiSettings().setMyLocationButtonEnabled(false);
  497. map.setMyLocationEnabled(true);
  498. // Needs to call MapsInitializer before doing any CameraUpdateFactory calls
  499. try {
  500. MapsInitializer.initialize(this.getActivity());
  501. CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(location, 14);
  502. map.animateCamera(cameraUpdate);
  503. } catch (Exception e) {
  504. Log.e("Error initializing maps", e.toString());
  505. }
  506. //Set GM marker
  507. MarkerOptions mo = new MarkerOptions();
  508. mo.title(markerName);
  509. mo.position(location);
  510. map.addMarker(mo);
  511. }
  512. }