ScheduleLayout.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. package com.ivalentin.margolariak;
  2. import java.text.DateFormat;
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.ArrayList;
  6. import java.util.Calendar;
  7. import java.util.Date;
  8. import java.util.Locale;
  9. import android.annotation.SuppressLint;
  10. import android.app.Dialog;
  11. import android.content.DialogInterface;
  12. import android.content.DialogInterface.OnCancelListener;
  13. import android.content.DialogInterface.OnShowListener;
  14. import android.content.pm.PackageManager;
  15. import android.database.Cursor;
  16. import android.database.sqlite.SQLiteDatabase;
  17. import android.graphics.drawable.Drawable;
  18. import android.os.Bundle;
  19. import android.app.Fragment;
  20. import android.preference.PreferenceManager;
  21. import android.text.Editable;
  22. import android.text.TextWatcher;
  23. import android.util.Log;
  24. import android.view.Gravity;
  25. import android.view.LayoutInflater;
  26. import android.view.View;
  27. import android.view.Window;
  28. import android.view.View.OnClickListener;
  29. import android.view.ViewGroup;
  30. import android.view.WindowManager;
  31. import android.widget.Button;
  32. import android.widget.EditText;
  33. import android.widget.ImageView;
  34. import android.widget.LinearLayout;
  35. import android.widget.ScrollView;
  36. import android.widget.TextView;
  37. import org.osmdroid.api.IMapController;
  38. import org.osmdroid.config.Configuration;
  39. import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
  40. import org.osmdroid.util.GeoPoint;
  41. import org.osmdroid.views.MapView;
  42. import org.osmdroid.views.overlay.ItemizedIconOverlay;
  43. import org.osmdroid.views.overlay.OverlayItem;
  44. /**
  45. * Fragment to be inflated showing the festivals schedule.
  46. * Contains a date selector and a ScrollView with all the activities for the day.
  47. *
  48. * @author Inigo Valentin
  49. *
  50. */
  51. public class ScheduleLayout extends Fragment{
  52. private Bundle bund;
  53. private final String dates[] = new String[40];
  54. private int dateCount = 0;
  55. private int selected = 0;
  56. //Map stuff for the dialog
  57. private MapView mapView;
  58. private int route;
  59. private View view;
  60. private String markerName = "";
  61. /**
  62. * Run when the fragment is inflated.
  63. * Assigns views, gets the date and does the first call to the populateSchedule function.
  64. *
  65. * @param inflater A LayoutInflater to manage views
  66. * @param container The container View
  67. * @param savedInstanceState Bundle containing the state
  68. *
  69. * @see Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
  70. */
  71. @SuppressLint("InflateParams") //Throws unknown error when done properly.
  72. @Override
  73. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  74. Calendar calendar = Calendar.getInstance();
  75. String year = Integer.toString(calendar.get(Calendar.YEAR));
  76. //Set bundle for the map
  77. bund = savedInstanceState;
  78. //Load the layout
  79. view = inflater.inflate(R.layout.fragment_layout_schedule, null);
  80. view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
  81. @Override
  82. public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
  83. CustomScrollView sv = (CustomScrollView) v.findViewById(R.id.sv_schedule);
  84. Log.d("SV", "INVALIDATED");
  85. sv.invalidate();
  86. }
  87. });
  88. //Get schedule type
  89. TextView title = (TextView) view.findViewById(R.id.tv_schedule_type);
  90. Bundle bundle = this.getArguments();
  91. final int schedule = bundle.getInt(GM.SCHEDULE.KEY, GM.SCHEDULE.CITY);
  92. //Set the title
  93. if (schedule == GM.SCHEDULE.CITY) {
  94. ((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_lablanca_schedule));
  95. title.setText(R.string.menu_lablanca_schedule);
  96. }
  97. else{
  98. ((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_lablanca_gm_schedule));
  99. title.setText(R.string.menu_lablanca_gm_schedule);
  100. }
  101. ((MainActivity) getActivity()).setShareLink(getString(R.string.share_lablanca), GM.SHARE.LABLANCA);
  102. //Populate the dates array
  103. SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
  104. Cursor cursor;
  105. if (schedule == GM.SCHEDULE.MARGOLARIAK) {
  106. cursor = db.rawQuery("SELECT DISTINCT date(start) AS daydate FROM festival_event_gm WHERE strftime('%Y', start) = '" + year + "' AND strftime('%H', start) > '06' ORDER BY daydate;", null);
  107. }
  108. else{
  109. cursor = db.rawQuery("SELECT DISTINCT date(start) AS daydate FROM festival_event_vity WHERE strftime('%Y', start) = '" + year + "' AND strftime('%H', start) > '06' ORDER BY daydate;", null);
  110. }
  111. //Get current date in the same format as retrieved from the database
  112. DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
  113. Date today = Calendar.getInstance().getTime();
  114. String curDate = df.format(today);
  115. while (cursor.moveToNext()){
  116. if (dateCount < 40) {
  117. dates[dateCount] = cursor.getString(0);
  118. if (curDate.equals(cursor.getString(0))) {
  119. selected = dateCount;
  120. }
  121. }
  122. dateCount ++;
  123. }
  124. cursor.close();
  125. db.close();
  126. //Assign buttons
  127. Button btL = (Button) view.findViewById(R.id.bt_schedule_l);
  128. Button btR = (Button) view.findViewById(R.id.bt_schedule_r);
  129. btL.setOnClickListener(new OnClickListener() {
  130. @Override
  131. public void onClick(View v) {
  132. selected --;
  133. populateSchedule(schedule);
  134. }
  135. });
  136. btR.setOnClickListener(new OnClickListener() {
  137. @Override
  138. public void onClick(View v) {
  139. selected ++;
  140. populateSchedule(schedule);
  141. }
  142. });
  143. //Assign the filter text
  144. EditText etFilter = (EditText) view.findViewById(R.id.et_schedule_filter);
  145. etFilter.addTextChangedListener(new TextWatcher() {
  146. @Override
  147. public void afterTextChanged(Editable s) { }
  148. @Override
  149. public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
  150. @Override
  151. public void onTextChanged(CharSequence s, int start, int before, int count) {
  152. //Repopulate when the text is changed
  153. populateSchedule(schedule);
  154. }
  155. });
  156. //Populate the activity list
  157. populateSchedule(schedule);
  158. //Return the fragment view
  159. return view;
  160. }
  161. /**
  162. * Populates the list of activities with the ones in the selected day.
  163. *
  164. * @param schedule GM.SCHEDULE.GM or GM.SCHEDULE.CITY
  165. */
  166. @SuppressLint({"InflateParams", "SwitchIntDef"})
  167. //Views are added from a loop: I can't specify the parent when inflating.
  168. private int populateSchedule(final int schedule) {
  169. int eventCount = 0;
  170. //Hide or show buttons
  171. Button btNext = (Button) view.findViewById(R.id.bt_schedule_r);
  172. Button btPrevious = (Button) view.findViewById(R.id.bt_schedule_l);
  173. if (selected <= 0) {
  174. btPrevious.setVisibility(View.INVISIBLE);
  175. } else {
  176. btPrevious.setVisibility(View.VISIBLE);
  177. }
  178. if (selected >= dateCount - 1) {
  179. btNext.setVisibility(View.INVISIBLE);
  180. } else {
  181. btNext.setVisibility(View.VISIBLE);
  182. }
  183. //If there are no events,return now
  184. if (selected < 0 || selected >= dateCount) {
  185. return eventCount;
  186. }
  187. //Search filter
  188. String filter = ((EditText) view.findViewById(R.id.et_schedule_filter)).getText().toString().toLowerCase(Locale.US);
  189. Calendar calendar = Calendar.getInstance();
  190. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.US);
  191. try {
  192. calendar.setTime(dateFormat.parse(dates[selected] + " 06:00:00"));
  193. } catch (Exception ex) {
  194. Log.e("Datetime error", ex.toString());
  195. }
  196. SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
  197. String lang = GM.getLang();
  198. //A layout to be populated with one activity
  199. LinearLayout entry, list;
  200. //An inflater
  201. LayoutInflater factory = LayoutInflater.from(getActivity());
  202. //Views in each row
  203. TextView tvRowTitle, tvRowTime, tvRowDesc, tvRowPlace, tvRowId, tvRowAddress;
  204. //Set date selector texts
  205. TextView tvDayNumber = (TextView) view.findViewById(R.id.tv_schedule_day_number);
  206. TextView tvDayMonth = (TextView) view.findViewById(R.id.tv_schedule_day_month);
  207. TextView tvDayTitle = (TextView) view.findViewById(R.id.tv_schedule_day_title);
  208. tvDayNumber.setText(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
  209. switch (calendar.get(Calendar.MONTH)) {
  210. case 6:
  211. tvDayMonth.setText(getString(R.string.schedule_month_july));
  212. break;
  213. case 7:
  214. tvDayMonth.setText(getString(R.string.schedule_month_august));
  215. break;
  216. }
  217. if (schedule == GM.SCHEDULE.MARGOLARIAK) {
  218. Cursor cursorDay = db.rawQuery("SELECT name_" + lang + " FROM festival_day WHERE date(date) = '" + dates[selected] + "';", null);
  219. if (cursorDay.getCount() > 0) {
  220. cursorDay.moveToFirst();
  221. tvDayTitle.setText(cursorDay.getString(0));
  222. } else {
  223. tvDayTitle.setText("");
  224. }
  225. cursorDay.close();
  226. }
  227. //Get day end date
  228. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
  229. Calendar c = Calendar.getInstance();
  230. try {
  231. c.setTime(sdf.parse(dates[selected]));
  232. } catch (Exception ex) {
  233. Log.e("Date parsing error", ex.toString());
  234. return eventCount;
  235. }
  236. c.add(Calendar.DATE, 1); // number of days to add
  237. String endDate = sdf.format(c.getTime());
  238. String query = "";;
  239. if (schedule == GM.SCHEDULE.MARGOLARIAK) {
  240. query = "SELECT festival_event_gm.id, title_" + lang + ", description_" + lang + ", place, start, end, name_" + lang + ", address_" + lang + ", lat, lon FROM festival_event_gm, place WHERE place = place.id AND start >= '" + dates[selected] + " 06:00:00' AND start < '" + endDate + " 05:59:59'";
  241. }
  242. else {
  243. query = "SELECT festival_event_city.id, title_" + lang + ", description_" + lang + ", place, start, end, name_" + lang + ", address_" + lang + ", lat, lon FROM festival_event_city, place WHERE place = place.id AND start >= '" + dates[selected] + " 06:00:00' AND start < '" + endDate + " 05:59:59'";
  244. }
  245. if (filter.length() > 0) {
  246. query = query + "AND (title_" + lang + " like '%" + filter + "%' OR description_" + lang + " like '%" + filter + "%' OR name_" + lang + " like '%" + filter + "%' OR address_" + lang + " like '%" + filter + "%') ";
  247. }
  248. query = query + " ORDER BY start;";
  249. Cursor cursor = db.rawQuery(query, null);
  250. //Clear the list
  251. list = (LinearLayout) view.findViewById(R.id.ll_schedule_list);
  252. list.removeAllViews();
  253. while (cursor.moveToNext()) {
  254. eventCount++;
  255. entry = (LinearLayout) factory.inflate(R.layout.row_schedule, null);
  256. //Set id
  257. tvRowId = (TextView) entry.findViewById(R.id.tv_row_schedule_id);
  258. tvRowId.setText(cursor.getString(0));
  259. //Set title
  260. tvRowTitle = (TextView) entry.findViewById(R.id.tv_row_schedule_title);
  261. tvRowTitle.setText(cursor.getString(1));
  262. //Set description
  263. tvRowDesc = (TextView) entry.findViewById(R.id.tv_row_schedule_description);
  264. if (cursor.getString(2) == null || cursor.getString(2).length() <= 0 || cursor.getString(2).equals(cursor.getString(1))) {
  265. tvRowDesc.setVisibility(View.GONE);
  266. } else {
  267. tvRowDesc.setText(cursor.getString(2));
  268. }
  269. //Set place
  270. tvRowPlace = (TextView) entry.findViewById(R.id.tv_row_schedule_place);
  271. tvRowPlace.setText(cursor.getString(6));
  272. //Set address
  273. tvRowAddress = (TextView) entry.findViewById(R.id.tv_row_schedule_address);
  274. if (cursor.getString(7) == null || cursor.getString(7).length() <= 0 || cursor.getString(7).equals(cursor.getString(6))) {
  275. tvRowAddress.setVisibility(View.GONE);
  276. } else {
  277. tvRowAddress.setText(cursor.getString(7));
  278. }
  279. //Set icon
  280. if (schedule == GM.SCHEDULE.MARGOLARIAK) {
  281. ImageView pinPoint = (ImageView) entry.findViewById(R.id.iv_row_schedule_pinpoint);
  282. pinPoint.setImageResource(getResources().getIdentifier("com.ivalentin.margolariak:drawable/pinpoint_gm", null, null));
  283. }
  284. //Set time
  285. tvRowTime = (TextView) entry.findViewById(R.id.tv_row_schedule_time);
  286. String tm = cursor.getString(4).substring(cursor.getString(4).length() - 8, cursor.getString(4).length() - 3);
  287. tvRowTime.setText(tm);
  288. //Set clisk listener
  289. entry.setOnClickListener(new OnClickListener() {
  290. @Override
  291. public void onClick(View v) {
  292. TextView tvId = (TextView) v.findViewById(R.id.tv_row_schedule_id);
  293. int id = Integer.parseInt(tvId.getText().toString());
  294. showDialog(id, schedule);
  295. }
  296. });
  297. //Add the view
  298. list.addView(entry);
  299. }
  300. cursor.close();
  301. db.close();
  302. //Scroll to top
  303. try {
  304. ScrollView sw = (ScrollView) list.getParent().getParent();
  305. sw.scrollTo(0, 0);
  306. }
  307. catch(Exception ex){
  308. Log.e("Schedule scroll", "Culdnt get scrollview to scroll: " + ex.toString());
  309. }
  310. return eventCount;
  311. }
  312. /**
  313. * Shows a dialog with info about the selected event.
  314. *
  315. * @param id The event id
  316. * @param schedule GM.SCHEDULE.GM or GM.SCHEDULE.CITY
  317. */
  318. @SuppressWarnings("ConstantConditions")
  319. private void showDialog(final int id, final int schedule){
  320. //Create the dialog
  321. final Dialog dialog = new Dialog(getActivity());
  322. //Set up dialog window
  323. dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  324. dialog.setContentView(R.layout.dialog_schedule);
  325. //Date formatters
  326. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
  327. SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd-", Locale.US);
  328. SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm", Locale.US);
  329. //Set the custom dialog components - text, image and button
  330. TextView tvTitle = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_title);
  331. TextView tvDescription = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_description);
  332. TextView tvHost = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_host);
  333. TextView tvDate = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_date);
  334. TextView tvTime = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_time);
  335. TextView tvPlace = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_place);
  336. TextView tvAddress = (TextView) dialog.findViewById(R.id.tv_dialog_schedule_address);
  337. Button btClose = (Button) dialog.findViewById(R.id.bt_schedule_close);
  338. //Get info about the event
  339. SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
  340. String lang = GM.getLang();
  341. Cursor cursor;
  342. if (schedule == GM.SCHEDULE.MARGOLARIAK){
  343. cursor = db.rawQuery("SELECT festival_event_gm.id, title_" + lang + ", description_" + lang + ", place, route, start, end, name_" + lang + ", address_" + lang + ", lat, lon, host, sponsor FROM festival_event_gm, place WHERE place = place.id AND festival_event_gm.id = " + id + ";", null);
  344. }
  345. else{
  346. cursor = db.rawQuery("SELECT festival_event_city.id, title_" + lang + ", description_" + lang + ", place, route, start, end, name_" + lang + ", address_" + lang + ", lat, lon, host, sponsor FROM, sponsor festival_event_city, place WHERE place = place.id AND festival_event_city.id = " + id + ";", null);
  347. }
  348. if (cursor.getCount() > 0){
  349. cursor.moveToNext();
  350. //Set title
  351. tvTitle.setText(cursor.getString(1));
  352. markerName = cursor.getString(1);
  353. //Set description
  354. if (cursor.getString(2) != null && cursor.getString(2).length() > 0) {
  355. tvDescription.setText(cursor.getString(2));
  356. }
  357. else{
  358. tvDescription.setVisibility(View.GONE);
  359. }
  360. //Set host
  361. if (cursor.getString(10) != null){
  362. Cursor hostCursor = db.rawQuery("SELECT name_" + lang + " FROM people WHERE id = " + cursor.getString(10) + ";", null);
  363. if (hostCursor.moveToNext()){
  364. tvHost.setVisibility(View.VISIBLE);
  365. tvHost.setText(String.format(getString(R.string.schedule_host), hostCursor.getString(0)));
  366. }
  367. hostCursor.close();
  368. // TODO. Add sponsor.
  369. }
  370. else{
  371. tvHost.setVisibility(View.GONE);
  372. }
  373. //Set date
  374. try{
  375. Date day = dateFormat.parse(cursor.getString(4));
  376. Date date = new Date();
  377. //If the event is today, show "Today" instead of the date
  378. if (dayFormat.format(day).equals(dayFormat.format(date)))
  379. tvDate.setText(dialog.getContext().getString(R.string.today));
  380. else{
  381. Calendar cal = Calendar.getInstance();
  382. cal.setTime(date);
  383. cal.add(Calendar.HOUR_OF_DAY, 24);
  384. //If the event is tomorrow, show "Tomorrow" instead of the date
  385. if (dayFormat.format(cal.getTime()).equals(dayFormat.format(date))){
  386. tvDate.setText(dialog.getContext().getString(R.string.tomorrow));
  387. }
  388. //Else, show the date
  389. else{
  390. SimpleDateFormat printFormat;
  391. switch (lang){
  392. case "en":
  393. printFormat = new SimpleDateFormat("MMMM dd", Locale.US);
  394. tvDate.setText(printFormat.format(day));
  395. break;
  396. case "eu":
  397. printFormat = new SimpleDateFormat("MMMM dd", new Locale("eu", "ES"));
  398. tvDate.setText(printFormat.format(day));
  399. break;
  400. default:
  401. printFormat = new SimpleDateFormat("dd", new Locale("es", "ES"));
  402. String str = printFormat.format(day) + " de ";
  403. printFormat = new SimpleDateFormat("MMMM", new Locale("es", "ES"));
  404. str = str + printFormat.format(day);
  405. tvDate.setText(str);
  406. }
  407. }
  408. }
  409. }
  410. catch (Exception ex){
  411. Log.e("Error parsing date", ex.toString());
  412. }
  413. //Set time
  414. try{
  415. if (cursor.getString(6) == null || cursor.getString(6).length() == 0) {
  416. tvTime.setText(timeFormat.format(dateFormat.parse(cursor.getString(5))));
  417. }
  418. else {
  419. String time = timeFormat.format(dateFormat.parse(cursor.getString(5))) + " - " + timeFormat.format(dateFormat.parse(cursor.getString(6)));
  420. tvTime.setText(time);
  421. }
  422. }
  423. catch (ParseException ex){
  424. Log.e("Error parsing time", ex.toString());
  425. }
  426. //Set the place
  427. tvPlace.setText(cursor.getString(7));
  428. tvAddress.setText(cursor.getString(8));
  429. //Set up map
  430. // TODO if route...
  431. mapView = (MapView) dialog.findViewById(R.id.mv_dialog_schedule_map);
  432. mapView.setMultiTouchControls(true);
  433. IMapController mapController = mapView.getController();
  434. mapController.setZoom(15);
  435. GeoPoint center = new GeoPoint(cursor.getDouble(9), cursor.getDouble(10));
  436. mapController.setCenter(center);
  437. OverlayItem locationOverlayItem = new OverlayItem(cursor.getString(1), cursor.getString(7), center);
  438. Drawable locationMarker = this.getResources().getDrawable(R.drawable.pinpoint_map);
  439. locationOverlayItem.setMarker(locationMarker);
  440. final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
  441. items.add(locationOverlayItem);
  442. ItemizedIconOverlay locationOverlay = new ItemizedIconOverlay<OverlayItem>(items,
  443. new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
  444. public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
  445. return true;
  446. }
  447. public boolean onItemLongPress(final int index, final OverlayItem item) {
  448. return true;
  449. }
  450. }, getContext());
  451. this.mapView.getOverlays().add(locationOverlay);
  452. //Close the db connection
  453. cursor.close();
  454. db.close();
  455. //Set close button
  456. btClose.setOnClickListener(new OnClickListener() {
  457. @Override
  458. public void onClick(View v) {
  459. dialog.dismiss();
  460. }
  461. });
  462. //Actions to take when the dialog is cancelled
  463. dialog.setOnCancelListener(new OnCancelListener(){
  464. @Override
  465. public void onCancel(DialogInterface dialog) {
  466. }
  467. });
  468. //Show the dialog
  469. WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
  470. lp.copyFrom(dialog.getWindow().getAttributes());
  471. lp.width = WindowManager.LayoutParams.MATCH_PARENT;
  472. lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
  473. lp.gravity = Gravity.CENTER;
  474. lp.dimAmount = 0.0f;
  475. dialog.getWindow().setAttributes(lp);
  476. //Show dialog
  477. dialog.show();
  478. }
  479. }
  480. /**
  481. * Called when the activity is resumed.
  482. * Lets the map handle this situation.
  483. *
  484. * @see android.app.Fragment#onResume()
  485. */
  486. @Override
  487. public void onResume() {
  488. Configuration.getInstance().load(getContext(), PreferenceManager.getDefaultSharedPreferences(getContext()));
  489. super.onResume();
  490. }
  491. /**
  492. * Checks app permission to access the user location.
  493. * @return true if the permission has been granted, false otherwise.
  494. */
  495. private boolean checkLocationPermission(){
  496. return getContext().checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && getContext().checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
  497. }
  498. }