HomeLayout.java 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. package com.ivalentin.margolariak;
  2. import java.io.File;
  3. import java.text.DateFormat;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Calendar;
  6. import java.util.Locale;
  7. import android.annotation.SuppressLint;
  8. import android.Manifest;
  9. import android.app.Activity;
  10. import android.content.Context;
  11. import android.content.Intent;
  12. import android.content.SharedPreferences;
  13. import android.content.pm.PackageManager;
  14. import android.database.Cursor;
  15. import android.database.sqlite.SQLiteDatabase;
  16. import android.graphics.Bitmap;
  17. import android.graphics.BitmapFactory;
  18. import android.app.Fragment;
  19. import android.location.Criteria;
  20. import android.location.Location;
  21. import android.location.LocationListener;
  22. import android.location.LocationManager;
  23. import android.net.Uri;
  24. import android.os.Bundle;
  25. import android.app.FragmentManager;
  26. import android.app.FragmentTransaction;
  27. import android.support.v4.app.ActivityCompat;
  28. import android.text.Html;
  29. import android.util.Log;
  30. import android.view.LayoutInflater;
  31. import android.view.MenuItem;
  32. import android.view.View;
  33. import android.view.View.OnClickListener;
  34. import android.view.ViewGroup;
  35. import android.widget.Button;
  36. import android.widget.ImageView;
  37. import android.widget.LinearLayout;
  38. import android.widget.TextView;
  39. import android.widget.Toast;
  40. /**
  41. * Section that will be seen when the app is started.
  42. * Contains info from almost every other section.
  43. *
  44. * @author Iñigo Valentin
  45. *
  46. * @see Fragment
  47. *
  48. */
  49. @SuppressWarnings("UnusedReturnValue")
  50. public class HomeLayout extends Fragment implements LocationListener {
  51. //The location manager
  52. private LocationManager locationManager;
  53. @Override
  54. public boolean onOptionsItemSelected(MenuItem item) {
  55. return false;
  56. }
  57. private View view;
  58. /**
  59. * Run when the fragment is inflated.
  60. * Assigns views, gets the date and does the first call to the {//@link populate function}.
  61. *
  62. * @param inflater A LayoutInflater to handle the views
  63. * @param container The parent View
  64. * @param savedInstanceState Bundle with the saved state
  65. *
  66. * @return The fragment view
  67. *
  68. * @see android.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
  69. */
  70. @SuppressLint("InflateParams") //Throws unknown error when done properly.
  71. @Override
  72. public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
  73. //Load the layout.
  74. view = inflater.inflate(R.layout.fragment_layout_home, null);
  75. //Request location permissions if not set
  76. if (ActivityCompat.checkSelfPermission(view.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(view.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  77. ActivityCompat.requestPermissions(this.getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, GM.PERMISSION.LOCATION);
  78. }
  79. //Set Location manager
  80. locationManager = (LocationManager) view.getContext().getSystemService(Context.LOCATION_SERVICE);
  81. if (!(ActivityCompat.checkSelfPermission(view.getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(view.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
  82. locationManager.requestLocationUpdates(locationManager.getBestProvider(new Criteria(), true), GM.LOCATION.ACCURACY.TIME, GM.LOCATION.ACCURACY.SPACE, this);
  83. onLocationChanged(locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER));
  84. }
  85. //Set the title
  86. ((MainActivity) getActivity()).setSectionTitle(view.getContext().getString(R.string.menu_home));
  87. setUpLablanca(view);
  88. //Set up the blog section
  89. setUpBlog(view);
  90. //Set up activities sections
  91. if (setUpFutureActivities(view) == 0) {
  92. setUpPastActivities(view);
  93. }
  94. //Set up the gallery section
  95. setUpGallery(view);
  96. //Asynchronously set up location section
  97. //This will trigger onLocationChanged, that will trigger setUpLocation
  98. new HomeSectionLocation(view).execute();
  99. //Set up schedule sections
  100. setUpSchedule(1, view);
  101. setUpSchedule(0, view);
  102. //Setup the social section
  103. setUpSocial(view);
  104. //Return the view itself.
  105. return view;
  106. }
  107. /**
  108. * Populates the schedule sections of the home screen.
  109. *
  110. * @return The number of entries shown.
  111. */
  112. @SuppressLint("InflateParams")
  113. private int setUpSchedule(int gm, View view) {
  114. int count = 0;
  115. SharedPreferences data = view.getContext().getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
  116. if (!data.getBoolean(GM.DATA.KEY.LABLANCA, GM.DATA.DEFAULT.LABLANCA)) {
  117. return count;
  118. }
  119. SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
  120. Calendar calendar = Calendar.getInstance();
  121. Calendar calendarEnd;
  122. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
  123. String nowString = dateFormat.format(calendar.getTime());
  124. String endString;
  125. String query;
  126. //An inflater
  127. LayoutInflater factory = LayoutInflater.from(getActivity());
  128. //Views in each row
  129. TextView tvRowTitle, tvRowTime, tvRowPlace, tvRowId;
  130. Button btSchedule;
  131. //Assign layouts
  132. LinearLayout section, listNow, listNext, now, next, entry;
  133. if (gm == 1) {
  134. section = (LinearLayout) view.findViewById(R.id.ll_home_section_gmschedule);
  135. listNow = (LinearLayout) view.findViewById(R.id.ll_home_section_gmschedule_now_list);
  136. listNext = (LinearLayout) view.findViewById(R.id.ll_home_section_gmschedule_later_list);
  137. now = (LinearLayout) view.findViewById(R.id.ll_home_section_gmschedule_now_content);
  138. next = (LinearLayout) view.findViewById(R.id.ll_home_section_gmschedule_later_content);
  139. btSchedule = (Button) view.findViewById(R.id.bt_home_gm);
  140. btSchedule.setOnClickListener(new OnClickListener() {
  141. @Override
  142. public void onClick(View v) {
  143. ((MainActivity) getActivity()).loadSection(GM.SECTION.GM_SCHEDULE);
  144. }
  145. });
  146. } else {
  147. section = (LinearLayout) view.findViewById(R.id.ll_home_section_cityschedule);
  148. listNow = (LinearLayout) view.findViewById(R.id.ll_home_section_cityschedule_now_list);
  149. listNext = (LinearLayout) view.findViewById(R.id.ll_home_section_cityschedule_later_list);
  150. now = (LinearLayout) view.findViewById(R.id.ll_home_section_cityschedule_now_content);
  151. next = (LinearLayout) view.findViewById(R.id.ll_home_section_cityschedule_later_content);
  152. }
  153. //Set query for current events
  154. String lang = GM.getLang();
  155. calendarEnd = calendar;
  156. calendarEnd.add(Calendar.MINUTE, -40);
  157. endString = dateFormat.format(calendarEnd.getTime());
  158. query = "SELECT festival_event.id, title_" + lang + ", description_" + lang + ", place, start, end, name_" + lang + ", address_" + lang + ", lat, lon FROM festival_event, place WHERE place = place.id AND ((start <= '" + nowString + "' AND end > '" + nowString + "') OR (start > '" + endString + "' AND start < '" + nowString + "')) AND gm = " + gm + " ORDER BY start LIMIT 2";
  159. //Execute query and loop
  160. Cursor cursorNow = db.rawQuery(query, null);
  161. if (cursorNow.getCount() == 0) {
  162. now.setVisibility(View.GONE);
  163. }
  164. while (cursorNow.moveToNext()) {
  165. count++;
  166. entry = (LinearLayout) factory.inflate(R.layout.row_home_schedule, null);
  167. //Set id
  168. tvRowId = (TextView) entry.findViewById(R.id.tv_row_home_schedule_id);
  169. tvRowId.setText(cursorNow.getString(0));
  170. //Set title
  171. tvRowTitle = (TextView) entry.findViewById(R.id.tv_row_home_schedule_title);
  172. tvRowTitle.setText(cursorNow.getString(1));
  173. //Set place
  174. tvRowPlace = (TextView) entry.findViewById(R.id.tv_row_home_schedule_place);
  175. tvRowPlace.setText(cursorNow.getString(6));
  176. //Set icon
  177. if (gm == GM.SECTION.GM_SCHEDULE) {
  178. ImageView pinPoint = (ImageView) entry.findViewById(R.id.iv_row_home_schedule_pinpoint);
  179. pinPoint.setImageResource(getResources().getIdentifier("com.ivalentin.gm:drawable/pinpoint_gm", null, null));
  180. }
  181. //Set time
  182. tvRowTime = (TextView) entry.findViewById(R.id.tv_row_home_schedule_time);
  183. tvRowTime.setVisibility(View.GONE);
  184. //Add the view
  185. listNow.addView(entry);
  186. }
  187. cursorNow.close();
  188. //Prepare query for upcaming events
  189. calendarEnd = calendar;
  190. calendarEnd.add(Calendar.MINUTE, 320);
  191. endString = dateFormat.format(calendarEnd.getTime());
  192. query = "SELECT festival_event.id, title_" + lang + ", description_" + lang + ", place, start, end, name_" + lang + ", address_" + lang + ", lat, lon FROM festival_event, place WHERE place = place.id AND start > '" + nowString + "' AND start < '" + endString + "' AND gm = " + gm + " ORDER BY start LIMIT 2";
  193. //Execute query and loop
  194. Cursor cursorNext = db.rawQuery(query, null);
  195. if (cursorNext.getCount() == 0) {
  196. next.setVisibility(View.GONE);
  197. }
  198. while (cursorNext.moveToNext()) {
  199. count++;
  200. entry = (LinearLayout) factory.inflate(R.layout.row_home_schedule, null);
  201. //Set id
  202. tvRowId = (TextView) entry.findViewById(R.id.tv_row_home_schedule_id);
  203. tvRowId.setText(cursorNext.getString(0));
  204. //Set title
  205. tvRowTitle = (TextView) entry.findViewById(R.id.tv_row_home_schedule_title);
  206. tvRowTitle.setText(cursorNext.getString(1));
  207. //Set place
  208. tvRowPlace = (TextView) entry.findViewById(R.id.tv_row_home_schedule_place);
  209. tvRowPlace.setText(cursorNext.getString(6));
  210. //Set icon
  211. if (gm == GM.SECTION.GM_SCHEDULE) {
  212. ImageView pinPoint = (ImageView) entry.findViewById(R.id.iv_row_home_schedule_pinpoint);
  213. pinPoint.setImageResource(getResources().getIdentifier("com.ivalentin.gm:drawable/pinpoint_gm", null, null));
  214. }
  215. //Set time
  216. tvRowTime = (TextView) entry.findViewById(R.id.tv_row_home_schedule_time);
  217. String tm = cursorNext.getString(4).substring(cursorNext.getString(4).length() - 8, cursorNext.getString(4).length() - 3);
  218. tvRowTime.setText(tm);
  219. //Add the view
  220. listNext.addView(entry);
  221. }
  222. cursorNext.close();
  223. if (count > 0) {
  224. section.setVisibility(View.VISIBLE);
  225. if (gm == 1) {
  226. section.setOnClickListener(new OnClickListener() {
  227. @Override
  228. public void onClick(View v) {
  229. ((MainActivity) getActivity()).loadSection(GM.SECTION.GM_SCHEDULE);
  230. }
  231. });
  232. } else {
  233. section.setOnClickListener(new OnClickListener() {
  234. @Override
  235. public void onClick(View v) {
  236. ((MainActivity) getActivity()).loadSection(GM.SECTION.SCHEDULE);
  237. }
  238. });
  239. }
  240. }
  241. db.close();
  242. return count;
  243. }
  244. /**
  245. * Populates the Social section of the home screen.
  246. */
  247. private void setUpSocial(View view) {
  248. ImageView phone = (ImageView) view.findViewById(R.id.iv_home_section_social_phone);
  249. ImageView mail = (ImageView) view.findViewById(R.id.iv_home_section_social_mail);
  250. ImageView whatsapp = (ImageView) view.findViewById(R.id.iv_home_section_social_whatsapp);
  251. ImageView facebook = (ImageView) view.findViewById(R.id.iv_home_section_social_facebook);
  252. ImageView twitter = (ImageView) view.findViewById(R.id.iv_home_section_social_twitter);
  253. ImageView googleplus = (ImageView) view.findViewById(R.id.iv_home_section_social_googleplus);
  254. ImageView youtube = (ImageView) view.findViewById(R.id.iv_home_section_social_youtube);
  255. ImageView instagram = (ImageView) view.findViewById(R.id.iv_home_section_social_instagram);
  256. phone.setOnClickListener(new View.OnClickListener() {
  257. @Override
  258. public void onClick(View v) {
  259. String url = v.getContext().getString(R.string.social_phone_link);
  260. Intent intent = new Intent(Intent.ACTION_DIAL);
  261. intent.setData(Uri.parse(url));
  262. startActivity(intent);
  263. }
  264. });
  265. mail.setOnClickListener(new View.OnClickListener() {
  266. @Override
  267. public void onClick(View v) {
  268. String url = v.getContext().getString(R.string.social_mail_link);
  269. Intent i = new Intent(Intent.ACTION_VIEW);
  270. i.setData(Uri.parse(url));
  271. startActivity(i);
  272. }
  273. });
  274. whatsapp.setOnClickListener(new View.OnClickListener() {
  275. @Override
  276. public void onClick(View v) {
  277. try {
  278. Uri mUri = Uri.parse(getString(R.string.social_whatsapp_link));
  279. Intent mIntent = new Intent(Intent.ACTION_SENDTO, mUri);
  280. mIntent.setPackage(getString(R.string.social_whatsapp_package));
  281. mIntent.putExtra(getString(R.string.social_whatsapp_chat), true);
  282. startActivity(mIntent);
  283. } catch (Exception e) {
  284. Toast.makeText(v.getContext(), getString(R.string.social_whatsapp_error), Toast.LENGTH_LONG).show();
  285. }
  286. }
  287. });
  288. facebook.setOnClickListener(new View.OnClickListener() {
  289. @Override
  290. public void onClick(View v) {
  291. String url = v.getContext().getString(R.string.social_facebook_link);
  292. Intent i = new Intent(Intent.ACTION_VIEW);
  293. i.setData(Uri.parse(url));
  294. startActivity(i);
  295. }
  296. });
  297. twitter.setOnClickListener(new View.OnClickListener() {
  298. @Override
  299. public void onClick(View v) {
  300. String url = v.getContext().getString(R.string.social_twitter_link);
  301. Intent i = new Intent(Intent.ACTION_VIEW);
  302. i.setData(Uri.parse(url));
  303. startActivity(i);
  304. }
  305. });
  306. googleplus.setOnClickListener(new View.OnClickListener() {
  307. @Override
  308. public void onClick(View v) {
  309. String url = v.getContext().getString(R.string.social_googleplus_link);
  310. Intent i = new Intent(Intent.ACTION_VIEW);
  311. i.setData(Uri.parse(url));
  312. startActivity(i);
  313. }
  314. });
  315. youtube.setOnClickListener(new View.OnClickListener() {
  316. @Override
  317. public void onClick(View v) {
  318. String url = v.getContext().getString(R.string.social_youtube_link);
  319. Intent i = new Intent(Intent.ACTION_VIEW);
  320. i.setData(Uri.parse(url));
  321. startActivity(i);
  322. }
  323. });
  324. instagram.setOnClickListener(new View.OnClickListener() {
  325. @Override
  326. public void onClick(View v) {
  327. String url = v.getContext().getString(R.string.social_instagram_link);
  328. Intent i = new Intent(Intent.ACTION_VIEW);
  329. i.setData(Uri.parse(url));
  330. startActivity(i);
  331. }
  332. });
  333. }
  334. /**
  335. * Populates the La Blanca section of the home screen.
  336. *
  337. * @return True if the section has been shown, false otherwise.
  338. */
  339. @SuppressWarnings("ResultOfMethodCallIgnored")
  340. private boolean setUpLablanca(View view) {
  341. SharedPreferences preferences = view.getContext().getSharedPreferences(GM.DATA.DATA, Context.MODE_PRIVATE);
  342. Boolean set = false;
  343. if (preferences.getBoolean(GM.DATA.KEY.LABLANCA, GM.DATA.DEFAULT.LABLANCA)) {
  344. LinearLayout llSection = (LinearLayout) view.findViewById(R.id.ll_home_section_lablanca);
  345. TextView tvText = (TextView) view.findViewById(R.id.tv_home_section_lablanca_text);
  346. ImageView ivImage = (ImageView) view.findViewById(R.id.iv_home_section_lablanca_image);
  347. //Set click listener
  348. llSection.setOnClickListener(new OnClickListener() {
  349. @Override
  350. public void onClick(View v) {
  351. ((MainActivity) getActivity()).loadSection(GM.SECTION.LABLANCA);
  352. }
  353. });
  354. //Get data from the database of the future activities
  355. SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
  356. int year = Calendar.getInstance().get(Calendar.YEAR);
  357. String lang = GM.getLang();
  358. Cursor cursor = db.rawQuery("SELECT text_" + lang + ", img FROM festival WHERE year = " + year + ";", null);
  359. if (cursor.getCount() > 0) {
  360. cursor.moveToFirst();
  361. llSection.setVisibility(View.VISIBLE);
  362. //Enable menu entries
  363. //this.getActivity().findViewById(R.id.menu_lablanca_gm_schedule).setVisibility(View.VISIBLE);
  364. //this.getActivity().findViewById(R.id.menu_lablanca_schedule).setVisibility(View.VISIBLE);
  365. //Set text
  366. String text = Html.fromHtml(cursor.getString(0)).toString();
  367. String shortText = text.substring(0, 80);
  368. if (text.equals(shortText)) {
  369. tvText.setText(text);
  370. }
  371. else{
  372. shortText = shortText + "...";
  373. tvText.setText(shortText);
  374. }
  375. set = true;
  376. //Set image
  377. String image = cursor.getString(1);
  378. if (image != null && image.length() > 0){
  379. //Check if image exists
  380. File f;
  381. f = new File(this.getActivity().getFilesDir().toString() + "/img/fiestas/preview/" + image);
  382. if (f.exists()) {
  383. //If the image exists, set it.
  384. Bitmap myBitmap = BitmapFactory.decodeFile(this.getActivity().getFilesDir().toString() + "/img/fiestas/preview/" + image);
  385. ivImage.setImageBitmap(myBitmap);
  386. } else {
  387. //If not, create directories and download asynchronously
  388. File fpath;
  389. fpath = new File(this.getActivity().getFilesDir().toString() + "/img/fiestas/preview/");
  390. fpath.mkdirs();
  391. new DownloadImage(GM.API.SERVER + "/img/fiestas/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/fiestas/preview/" + image, ivImage, GM.IMG.SIZE.PREVIEW).execute();
  392. }
  393. }
  394. else {
  395. ivImage.setVisibility(View.GONE);
  396. }
  397. }
  398. cursor.close();
  399. db.close();
  400. }
  401. return set;
  402. }
  403. /**
  404. * Populates the Location section of the home screen.
  405. *
  406. * @return True if the section has been shown, false otherwise.
  407. */
  408. private boolean setUpLocation(Location location, View view) {
  409. try {
  410. Double lat, lon;
  411. SQLiteDatabase db = getActivity().openOrCreateDatabase(GM.DB.NAME, Activity.MODE_PRIVATE, null);
  412. Cursor cursor;
  413. cursor = db.rawQuery("SELECT lat, lon FROM location WHERE dtime >= Datetime('now', '-10 minutes') ORDER BY dtime DESC LIMIT 1;", null);
  414. if (cursor.getCount() == 0){
  415. cursor.close();
  416. db.close();
  417. return false;
  418. }
  419. else {
  420. cursor.moveToFirst();
  421. lat = cursor.getDouble(0);
  422. lon = cursor.getDouble(1);
  423. cursor.close();
  424. db.close();
  425. Double distance = Distance.calculateDistance(lat, lon, location.getLatitude(), location.getLongitude());
  426. TextView text = (TextView) view.findViewById(R.id.tv_home_section_location_distance);
  427. if (distance <= 2) {
  428. distance = 1000 * distance;
  429. text.setText(String.format(getString(R.string.home_section_location_text_short), distance.intValue(), (int) (0.012 * distance.intValue())));
  430. } else {
  431. text.setText(String.format(getString(R.string.home_section_location_text_long), String.format(Locale.US, "%.02f", distance)));
  432. }
  433. return true;
  434. }
  435. }
  436. catch (Exception ex){
  437. Log.e("Location", "Couldn't set up home location section: " + ex.toString());
  438. }
  439. return false;
  440. }
  441. /**
  442. * Populates the Gallery section of the home screen.
  443. * Loads four photos.
  444. * Tapping them takes to the respective album, tapping anywhere else, to the gallery section.
  445. *
  446. * @return The number of entries shown
  447. */
  448. @SuppressWarnings("ResultOfMethodCallIgnored")
  449. private int setUpGallery(View view) {
  450. int counter = 0;
  451. //Set onClick listener of section
  452. LinearLayout llGallery = (LinearLayout) view.findViewById(R.id.ll_home_section_gallery);
  453. //Set click listener
  454. llGallery.setOnClickListener(new OnClickListener() {
  455. @Override
  456. public void onClick(View v) {
  457. ((MainActivity) getActivity()).loadSection(GM.SECTION.GALLERY);
  458. }
  459. });
  460. //Assign views
  461. ImageView ivPhoto[] = new ImageView[4];
  462. ivPhoto[0] = (ImageView) view.findViewById(R.id.iv_home_section_gallery_0);
  463. ivPhoto[1] = (ImageView) view.findViewById(R.id.iv_home_section_gallery_1);
  464. ivPhoto[2] = (ImageView) view.findViewById(R.id.iv_home_section_gallery_2);
  465. ivPhoto[3] = (ImageView) view.findViewById(R.id.iv_home_section_gallery_3);
  466. //Get data from the database of the future activities
  467. SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
  468. Cursor cursor = db.rawQuery("SELECT id, album, file, uploaded FROM photo, photo_album WHERE id = photo ORDER BY uploaded DESC LIMIT 4;", null);
  469. while (cursor.moveToNext()) {
  470. //Set id
  471. ivPhoto[counter].setTag(R.string.key_0, cursor.getString(0));
  472. ivPhoto[counter].setTag(R.string.key_1, cursor.getString(1));
  473. //Set image
  474. String image = cursor.getString(2);
  475. //Check if image exists
  476. File f;
  477. f = new File(this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image);
  478. if (f.exists()) {
  479. //If the image exists, set it.
  480. Bitmap myBitmap = BitmapFactory.decodeFile(this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image);
  481. ivPhoto[counter].setImageBitmap(myBitmap);
  482. } else {
  483. //If not, create directories and download asynchronously
  484. File fpath;
  485. fpath = new File(this.getActivity().getFilesDir().toString() + "/img/galeria/preview/");
  486. fpath.mkdirs();
  487. new DownloadImage(GM.API.SERVER + "/img/galeria/preview/" + image, this.getActivity().getFilesDir().toString() + "/img/galeria/preview/" + image, ivPhoto[counter], GM.IMG.SIZE.PREVIEW).execute();
  488. }
  489. //Set listeners for images
  490. ivPhoto[counter].setOnClickListener(new View.OnClickListener() {
  491. @Override
  492. public void onClick(View v) {
  493. Fragment fragment = new AlbumLayout();
  494. Bundle bundle = new Bundle();
  495. int photoId = Integer.parseInt((String) v.getTag(R.string.key_0));
  496. int albumId = Integer.parseInt((String) v.getTag(R.string.key_1));
  497. bundle.putInt("album", albumId);
  498. bundle.putInt("photo", photoId);
  499. fragment.setArguments(bundle);
  500. FragmentManager fm = HomeLayout.this.getActivity().getFragmentManager();
  501. FragmentTransaction ft = fm.beginTransaction();
  502. ft.replace(R.id.activity_main_content_fragment, fragment);
  503. ft.addToBackStack("album_" + albumId);
  504. ft.commit();
  505. }
  506. });
  507. counter++;
  508. }
  509. //Close db
  510. cursor.close();
  511. db.close();
  512. return counter;
  513. }
  514. /**
  515. * Populates the Past Activities section of the home screen.
  516. * Makes the section visible and adds two rows with the two last activities.
  517. * Tapping them takes to the post, tapping anywhere else, to the blog section.
  518. *
  519. * @return The number of entries shown
  520. */
  521. @SuppressLint("InflateParams") //Throws unknown error when done properly.
  522. @SuppressWarnings("ResultOfMethodCallIgnored")
  523. private int setUpPastActivities(View view) {
  524. int counter = 0;
  525. String lang = GM.getLang();
  526. //Get data from the database of the future activities
  527. SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
  528. Cursor cursor = db.rawQuery("SELECT id, date, city, title_" + lang + " AS title, text_" + lang + " AS text, price, after_" + lang + " AS after FROM activity WHERE date < date('now') ORDER BY date DESC LIMIT 2;", null);
  529. //Show section
  530. LinearLayout llActivitiesPast = (LinearLayout) view.findViewById(R.id.ll_home_section_activities_past);
  531. llActivitiesPast.setVisibility(View.VISIBLE);
  532. //Set click listener
  533. llActivitiesPast.setOnClickListener(new OnClickListener() {
  534. @Override
  535. public void onClick(View v) {
  536. ((MainActivity) getActivity()).loadSection(GM.SECTION.ACTIVITIES);
  537. }
  538. });
  539. LinearLayout llList = (LinearLayout) view.findViewById(R.id.ll_home_section_activities_past_content);
  540. LinearLayout entry;
  541. //An inflater
  542. LayoutInflater factory = LayoutInflater.from(getActivity());
  543. //Print rows
  544. while (cursor.moveToNext()) {
  545. //Create a new row
  546. entry = (LinearLayout) factory.inflate(R.layout.row_home_activities, null);
  547. //Set margins
  548. LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  549. layoutParams.setMargins(GM.UI.ENTRY_MARGIN, GM.UI.ENTRY_MARGIN, GM.UI.ENTRY_MARGIN, GM.UI.ENTRY_MARGIN);
  550. entry.setLayoutParams(layoutParams);
  551. //Set title
  552. TextView tvTitle = (TextView) entry.findViewById(R.id.tv_row_home_activity_title);
  553. tvTitle.setText(cursor.getString(3));
  554. //Set city
  555. TextView tvCity = (TextView) entry.findViewById(R.id.tv_row_home_activity_city);
  556. tvCity.setText(cursor.getString(2));
  557. //Hide price
  558. TextView tvPrice = (TextView) entry.findViewById(R.id.tv_row_home_activity_price);
  559. tvPrice.setVisibility(View.GONE);
  560. //tvPrice.setText(cursor.getString(5) + "€");
  561. //Set text
  562. String text;
  563. if (cursor.getString(6) == null || cursor.getString(6).length() < 1) {
  564. text = Html.fromHtml(cursor.getString(4)).toString();
  565. } else {
  566. text = Html.fromHtml(cursor.getString(6)).toString();
  567. }
  568. TextView tvText = (TextView) entry.findViewById(R.id.tv_row_home_activity_text);
  569. tvText.setText(text);
  570. //Set date
  571. TextView tvDate = (TextView) entry.findViewById(R.id.tv_row_home_activity_date);
  572. tvDate.setText(GM.formatDate(cursor.getString(1) + " 00:00:00", lang, true, true, false));
  573. //Set hidden id
  574. TextView tvId = (TextView) entry.findViewById(R.id.tv_row_home_activity_hidden);
  575. tvId.setText(cursor.getString(0));
  576. //Get image
  577. ImageView iv = (ImageView) entry.findViewById(R.id.iv_row_home_activity);
  578. Cursor cursorImage = db.rawQuery("SELECT image FROM activity_image WHERE activity = " + cursor.getString(0) + " ORDER BY idx LIMIT 1;", null);
  579. if (cursorImage.getCount() > 0) {
  580. cursorImage.moveToFirst();
  581. String image = cursorImage.getString(0);
  582. //Check if image exists
  583. File f;
  584. f = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image);
  585. if (f.exists()) {
  586. //If the image exists, set it.
  587. Bitmap myBitmap = BitmapFactory.decodeFile(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image);
  588. iv.setImageBitmap(myBitmap);
  589. } else {
  590. //If not, create directories and download asynchronously
  591. File fpath;
  592. fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/");
  593. fpath.mkdirs();
  594. new DownloadImage(GM.API.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv, GM.IMG.SIZE.MINIATURE).execute();
  595. }
  596. }
  597. cursorImage.close();
  598. //Set onCLickListener
  599. entry.setOnClickListener(new View.OnClickListener() {
  600. @Override
  601. public void onClick(View v) {
  602. //Toast.makeText(getActivity(), "OPENING POST", Toast.LENGTH_LONG).show();
  603. Fragment fragment = new ActivityPastLayout();
  604. Bundle bundle = new Bundle();
  605. //Pass post id
  606. int id = Integer.parseInt(((TextView) v.findViewById(R.id.tv_row_home_activity_hidden)).getText().toString());
  607. bundle.putInt("activity", id);
  608. fragment.setArguments(bundle);
  609. FragmentManager fm = HomeLayout.this.getActivity().getFragmentManager();
  610. FragmentTransaction ft = fm.beginTransaction();
  611. ft.replace(R.id.activity_main_content_fragment, fragment);
  612. ft.addToBackStack("activity_" + id);
  613. ft.commit();
  614. }
  615. });
  616. //Add to the list
  617. llList.addView(entry);
  618. counter++;
  619. }
  620. //Close db
  621. cursor.close();
  622. db.close();
  623. return counter;
  624. }
  625. /**
  626. * Populates the Future activities section of the home screen.
  627. * If there are future activities, makes the section visible.
  628. * Adds two rows with the two next activities.
  629. * Tapping them takes to the post, tapping anywhere else, to the blog section.
  630. *
  631. * @return The number of entries shown
  632. */
  633. @SuppressLint("InflateParams") //Throws unknown error when done properly.
  634. @SuppressWarnings("ResultOfMethodCallIgnored")
  635. private int setUpFutureActivities(View view) {
  636. int counter = 0;
  637. String lang = GM.getLang();
  638. LinearLayout llList = (LinearLayout) view.findViewById(R.id.ll_home_section_activities_future_content);
  639. LinearLayout entry;
  640. //An inflater
  641. LayoutInflater factory = LayoutInflater.from(getActivity());
  642. //Get data from the database of the future activities
  643. SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
  644. Cursor cursor = db.rawQuery("SELECT id, date, city, title_" + lang + " AS title, text_" + lang + " AS text, price FROM activity WHERE date >= date('now') ORDER BY date LIMIT 2;", null);
  645. //If there are future activities...
  646. if (cursor.getCount() > 0) {
  647. //Show section
  648. LinearLayout llActivitiesFuture = (LinearLayout) view.findViewById(R.id.ll_home_section_activities_future);
  649. llActivitiesFuture.setVisibility(View.VISIBLE);
  650. //Set click listener
  651. llActivitiesFuture.setOnClickListener(new OnClickListener() {
  652. @Override
  653. public void onClick(View v) {
  654. ((MainActivity) getActivity()).loadSection(GM.SECTION.ACTIVITIES);
  655. }
  656. });
  657. //Print rows
  658. while (cursor.moveToNext()) {
  659. //Create a new row
  660. entry = (LinearLayout) factory.inflate(R.layout.row_home_activities, null);
  661. //Set margins
  662. LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  663. layoutParams.setMargins(GM.UI.ENTRY_MARGIN, GM.UI.ENTRY_MARGIN, GM.UI.ENTRY_MARGIN, GM.UI.ENTRY_MARGIN);
  664. entry.setLayoutParams(layoutParams);
  665. //Set title
  666. TextView tvTitle = (TextView) entry.findViewById(R.id.tv_row_home_activity_title);
  667. tvTitle.setText(cursor.getString(3));
  668. //Set city
  669. TextView tvCity = (TextView) entry.findViewById(R.id.tv_row_home_activity_city);
  670. tvCity.setText(cursor.getString(2));
  671. //Set price
  672. TextView tvPrice = (TextView) entry.findViewById(R.id.tv_row_home_activity_price);
  673. tvPrice.setText(String.format(getString(R.string.price), cursor.getInt(5)));
  674. //Set text
  675. String text = Html.fromHtml(cursor.getString(4)).toString();
  676. TextView tvText = (TextView) entry.findViewById(R.id.tv_row_home_activity_text);
  677. tvText.setText(text);
  678. //Set date
  679. TextView tvDate = (TextView) entry.findViewById(R.id.tv_row_home_activity_date);
  680. tvDate.setText(GM.formatDate(cursor.getString(1) + " 00:00:00", lang, true, false, false));
  681. //Set hidden id
  682. TextView tvId = (TextView) entry.findViewById(R.id.tv_row_home_activity_hidden);
  683. tvId.setText(cursor.getString(0));
  684. //Get image
  685. ImageView iv = (ImageView) entry.findViewById(R.id.iv_row_home_activity);
  686. Cursor cursorImage = db.rawQuery("SELECT image FROM activity_image WHERE activity = " + cursor.getString(0) + " ORDER BY idx LIMIT 1;", null);
  687. if (cursorImage.getCount() > 0) {
  688. cursorImage.moveToFirst();
  689. String image = cursorImage.getString(0);
  690. //Check if image exists
  691. File f;
  692. f = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image);
  693. if (f.exists()) {
  694. //If the image exists, set it.
  695. Bitmap myBitmap = BitmapFactory.decodeFile(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image);
  696. iv.setImageBitmap(myBitmap);
  697. } else {
  698. //If not, create directories and download asynchronously
  699. File fpath;
  700. fpath = new File(this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/");
  701. fpath.mkdirs();
  702. new DownloadImage(GM.API.SERVER + "/img/actividades/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/actividades/miniature/" + image, iv, GM.IMG.SIZE.MINIATURE).execute();
  703. }
  704. }
  705. cursorImage.close();
  706. //Set onCLickListener
  707. entry.setOnClickListener(new View.OnClickListener() {
  708. @Override
  709. public void onClick(View v) {
  710. Fragment fragment = new ActivityFutureLayout();
  711. Bundle bundle = new Bundle();
  712. //Pass post id
  713. int id = Integer.parseInt(((TextView) v.findViewById(R.id.tv_row_home_activity_hidden)).getText().toString());
  714. bundle.putInt("activity", id);
  715. fragment.setArguments(bundle);
  716. FragmentManager fm = HomeLayout.this.getActivity().getFragmentManager();
  717. FragmentTransaction ft = fm.beginTransaction();
  718. ft.replace(R.id.activity_main_content_fragment, fragment);
  719. ft.addToBackStack("activity_" + id);
  720. ft.commit();
  721. }
  722. });
  723. //Add to the list
  724. llList.addView(entry);
  725. counter++;
  726. }
  727. }
  728. //Close db
  729. cursor.close();
  730. db.close();
  731. return counter;
  732. }
  733. /**
  734. * Populates the Blog section of the home screen.
  735. * Adds two rows with the two latest posts. Tapping them takes to the post, tapping anywhere else, to the blog section.
  736. *
  737. * @return The number of entries shown
  738. */
  739. @SuppressLint("InflateParams") //Throws unknown error when done properly.
  740. @SuppressWarnings("ResultOfMethodCallIgnored")
  741. private int setUpBlog(View view) {
  742. int counter = 0;
  743. String lang = GM.getLang();
  744. LinearLayout llBlog = (LinearLayout) view.findViewById(R.id.ll_home_section_blog);
  745. llBlog.setOnClickListener(new OnClickListener() {
  746. @Override
  747. public void onClick(View v) {
  748. ((MainActivity) getActivity()).loadSection(GM.SECTION.BLOG);
  749. }
  750. });
  751. //Assign elements
  752. LinearLayout llList = (LinearLayout) view.findViewById(R.id.ll_home_section_blog_content);
  753. LinearLayout entry;
  754. //An inflater
  755. LayoutInflater factory = LayoutInflater.from(getActivity());
  756. SQLiteDatabase db = SQLiteDatabase.openDatabase(getActivity().getDatabasePath(GM.DB.NAME).getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READONLY);
  757. final Cursor cursor;
  758. //Get data from the database
  759. cursor = db.rawQuery("SELECT id, title_" + lang + " AS title, text_" + lang + " AS text, dtime FROM post ORDER BY dtime DESC LIMIT 2;", null);
  760. //Loop
  761. while (cursor.moveToNext()) {
  762. //Create a new row
  763. entry = (LinearLayout) factory.inflate(R.layout.row_home_blog, null);
  764. //Set margins
  765. LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  766. layoutParams.setMargins(GM.UI.ENTRY_MARGIN, GM.UI.ENTRY_MARGIN, GM.UI.ENTRY_MARGIN, GM.UI.ENTRY_MARGIN);
  767. entry.setLayoutParams(layoutParams);
  768. //Set title
  769. TextView tvTitle = (TextView) entry.findViewById(R.id.tv_row_home_blog_title);
  770. tvTitle.setText(cursor.getString(1));
  771. //Set text
  772. String text = Html.fromHtml(cursor.getString(2)).toString();
  773. TextView tvText = (TextView) entry.findViewById(R.id.tv_row_home_blog_text);
  774. tvText.setText(text);
  775. //Set date
  776. TextView tvDate = (TextView) entry.findViewById(R.id.tv_row_home_blog_date);
  777. tvDate.setText(GM.formatDate(cursor.getString(3), lang, true, true, false));
  778. //Set hidden id
  779. TextView tvId = (TextView) entry.findViewById(R.id.tv_row_home_blog_hidden);
  780. tvId.setText(cursor.getString(0));
  781. //Get image
  782. ImageView iv = (ImageView) entry.findViewById(R.id.iv_row_home_blog_image);
  783. Cursor cursorImage = db.rawQuery("SELECT image FROM post_image WHERE post = " + cursor.getString(0) + " ORDER BY idx LIMIT 1;", null);
  784. if (cursorImage.getCount() > 0) {
  785. cursorImage.moveToFirst();
  786. String image = cursorImage.getString(0);
  787. //Check if image exists
  788. File f;
  789. f = new File(this.getActivity().getFilesDir().toString() + "/img/blog/miniature/" + image);
  790. if (f.exists()) {
  791. //If the image exists, set it.
  792. Bitmap myBitmap = BitmapFactory.decodeFile(this.getActivity().getFilesDir().toString() + "/img/blog/miniature/" + image);
  793. iv.setImageBitmap(myBitmap);
  794. } else {
  795. //If not, create directories and download asynchronously
  796. File fpath;
  797. fpath = new File(this.getActivity().getFilesDir().toString() + "/img/blog/miniature/");
  798. fpath.mkdirs();
  799. new DownloadImage(GM.API.SERVER + "/img/blog/miniature/" + image, this.getActivity().getFilesDir().toString() + "/img/blog/miniature/" + image, iv, GM.IMG.SIZE.MINIATURE).execute();
  800. }
  801. }
  802. cursorImage.close();
  803. //Set onCLickListener
  804. entry.setOnClickListener(new View.OnClickListener() {
  805. @Override
  806. public void onClick(View v) {
  807. Fragment fragment = new PostLayout();
  808. Bundle bundle = new Bundle();
  809. //Pass post id
  810. int id = Integer.parseInt(((TextView) v.findViewById(R.id.tv_row_home_blog_hidden)).getText().toString());
  811. bundle.putInt("post", id);
  812. fragment.setArguments(bundle);
  813. FragmentManager fm = HomeLayout.this.getActivity().getFragmentManager();
  814. FragmentTransaction ft = fm.beginTransaction();
  815. ft.replace(R.id.activity_main_content_fragment, fragment);
  816. ft.addToBackStack("post_" + id);
  817. ft.commit();
  818. }
  819. });
  820. //Add to the list
  821. llList.addView(entry);
  822. counter++;
  823. }
  824. //Close database
  825. cursor.close();
  826. db.close();
  827. return counter;
  828. }
  829. /**
  830. * Called when the user location changes.
  831. * Recalculates the list of around events and calls updateLocation() to
  832. * update the distance in the location section.
  833. *
  834. * @param location The new location
  835. *
  836. * @see android.location.LocationListener#onLocationChanged(android.location.Location)
  837. */
  838. @Override
  839. public void onLocationChanged(Location location) {
  840. setUpLocation(location, view);
  841. }
  842. /**
  843. * Called when the location provider changes it's state.
  844. * Recalculates the list of events in the around section.
  845. *
  846. * @param provider The name of the provider
  847. * @param status Status code of the provider
  848. * @param extras Extras passed
  849. *
  850. * @see android.location.LocationListener#onStatusChanged(java.lang.String, int, android.os.Bundle)
  851. */
  852. @Override
  853. public void onStatusChanged(String provider, int status, Bundle extras) {
  854. //populateAround();
  855. }
  856. /**
  857. * Called when a location provider is enabled.
  858. * Recalculates the list of events.
  859. *
  860. * @param provider The name of the provider
  861. *
  862. * @see android.location.LocationListener#onProviderEnabled(java.lang.String)
  863. */
  864. @Override
  865. public void onProviderEnabled(String provider) {
  866. //populateAround();
  867. }
  868. /**
  869. * Called when a location provider is disabled.
  870. * Recalculates the list of events.
  871. *
  872. * @param provider The name of the provider
  873. *
  874. * @see android.location.LocationListener#onProviderDisabled(java.lang.String)
  875. */
  876. @Override
  877. public void onProviderDisabled(String provider) {
  878. //populateAround();
  879. }
  880. /**
  881. * Called when the fragment is paused.
  882. * Stops the location manager
  883. * @see android.app.Fragment#onPause()
  884. */
  885. @Override
  886. public void onPause() {
  887. if (!(ActivityCompat.checkSelfPermission(view.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(view.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
  888. locationManager.removeUpdates(this);
  889. }
  890. super.onPause();
  891. }
  892. /**
  893. * Called when the fragment is destroyed.
  894. * Stops the location manager
  895. * @see android.app.Fragment#onDestroy()
  896. */
  897. @Override
  898. public void onDestroy() {
  899. try {
  900. if (!(ActivityCompat.checkSelfPermission(view.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(view.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
  901. locationManager.removeUpdates(this);
  902. }
  903. }
  904. catch (Exception ex){
  905. Log.e("Location manager", "Unable to stop location manager on destroy: " + ex.toString());
  906. }
  907. super.onDestroy();
  908. }
  909. /**
  910. * Called when the fragment is brought back into the foreground.
  911. * Resumes the map and the location manager.
  912. *
  913. * @see android.app.Fragment#onResume()
  914. */
  915. @Override
  916. public void onResume(){
  917. if (!(ActivityCompat.checkSelfPermission(view.getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(view.getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
  918. locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
  919. }
  920. super.onResume();
  921. }
  922. }