HomeLayout.java 39 KB

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