GM.java 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  1. package com.ivalentin.margolariak;
  2. import android.graphics.Bitmap;
  3. import android.graphics.BitmapFactory;
  4. import android.util.Log;
  5. import java.text.DateFormat;
  6. import java.text.SimpleDateFormat;
  7. import java.util.Calendar;
  8. import java.util.Date;
  9. import java.util.Locale;
  10. /**
  11. * Final class that contains useful static values to be used across the app.
  12. *
  13. * @author Iñigo Valentin
  14. *
  15. */
  16. final class GM {
  17. /**
  18. * Contains info about the database.
  19. */
  20. final class DB {
  21. /**
  22. * Name of the database.
  23. */
  24. static final String NAME = "gmv3";
  25. /**
  26. * Initial version of the database.
  27. */
  28. static final int INITIAL_VERSION = 0;
  29. /**
  30. * Names of the tables of the database.
  31. */
  32. final class TABLE {
  33. /**
  34. * Name of the table "activity".
  35. */
  36. static final String ACTIVITY = "activity";
  37. /**
  38. * Name of the table "activity_comment".
  39. */
  40. static final String ACTIVITY_COMMENT = "activity_comment";
  41. /**
  42. * Name of the table "activity_image".
  43. */
  44. static final String ACTIVITY_IMAGE = "activity_image";
  45. /**
  46. * Name of the table "activity_itinerary".
  47. */
  48. static final String ACTIVITY_ITINERARY = "activity_itinerary";
  49. /**
  50. * Name of the table "activity_tag".
  51. */
  52. static final String ACTIVITY_TAG = "activity_tag";
  53. /**
  54. * Name of the table "album".
  55. */
  56. static final String ALBUM = "album";
  57. /**
  58. * Name of the table "festival".
  59. */
  60. static final String FESTIVAL = "festival";
  61. /**
  62. * Name of the table "festival_day".
  63. */
  64. static final String FESTIVAL_DAY = "festival_day";
  65. /**
  66. * Name of the table "festival_event_city".
  67. */
  68. static final String FESTIVAL_EVENT_CITY = "festival_event_city";
  69. /**
  70. * Name of the table "festival_event_gm".
  71. */
  72. static final String FESTIVAL_EVENT_GM = "festival_event_gm";
  73. /**
  74. * Name of the table "festival_event_image".
  75. */
  76. static final String FESTIVAL_EVENT_IMAGE = "festival_event_image";
  77. /**
  78. * Name of the table "festival_offer".
  79. */
  80. static final String FESTIVAL_OFFER = "festival_offer";
  81. /**
  82. * Name of the table "location".
  83. */
  84. static final String LOCATION = "location";
  85. /**
  86. * Name of the table "notification".
  87. */
  88. static final String NOTIFICATION = "notification";
  89. /**
  90. * Name of the table "people".
  91. */
  92. static final String PEOPLE = "people";
  93. /**
  94. * Name of the table "photo".
  95. */
  96. static final String PHOTO = "photo";
  97. /**
  98. * Name of the table "photo_album".
  99. */
  100. static final String PHOTO_ALBUM = "photo_album";
  101. /**
  102. * Name of the table "photo_comment".
  103. */
  104. static final String PHOTO_COMMENT = "photo_comment";
  105. /**
  106. * Name of the table "place".
  107. */
  108. static final String PLACE = "place";
  109. /**
  110. * Name of the table "post".
  111. */
  112. static final String POST = "post";
  113. /**
  114. * Name of the table "post_comment".
  115. */
  116. static final String POST_COMMENT = "post_comment";
  117. /**
  118. * Name of the table "post_image".
  119. */
  120. static final String POST_IMAGE = "post_image";
  121. /**
  122. * Name of the table "post_tag".
  123. */
  124. static final String POST_TAG = "post_tag";
  125. /**
  126. * Name of the table "route".
  127. */
  128. static final String ROUTE = "route";
  129. /**
  130. * Name of the table "route_point".
  131. */
  132. static final String ROUTE_POINT = "route_point";
  133. /**
  134. * Name of the table "settings".
  135. */
  136. static final String SETTINGS = "settings";
  137. /**
  138. * Name of the table "sponsor".
  139. */
  140. static final String SPONSOR = "sponsor";
  141. /**
  142. * Name of the table "version".
  143. */
  144. static final String VERSION = "version";
  145. }
  146. /**
  147. * Column types
  148. */
  149. final class COLUMN {
  150. /**
  151. * INT column.
  152. */
  153. static final int INT = 0;
  154. /**
  155. * VARCHAR column.
  156. */
  157. static final int VARCHAR = 1;
  158. /**
  159. * Datetime column.
  160. */
  161. static final int DATETIME = 2;
  162. }
  163. /**
  164. * Usefull queries
  165. */
  166. final class QUERY {
  167. /**
  168. * Queries to create tables.
  169. */
  170. final class CREATE {
  171. /**
  172. * Creates the table "activity" on the database.
  173. */
  174. static final String ACTIVITY = "CREATE TABLE IF NOT EXISTS activity (id INT, permalink VARCHAR, date DATETIME, city VARCHAR, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, text_es VARCHAR, text_en VARCHAR, text_eu VARCHAR, after_es VARCHAR, after_en VARCHAR, after_eu VARCHAR, price INT, inscription INT, max_people INT, album INT, dtime DATETIME, comments INT);";
  175. /**
  176. * Creates the table "activity_comment" on the database.
  177. */
  178. static final String ACTIVITY_COMMENT = "CREATE TABLE IF NOT EXISTS activity_comment (id INT, activity INT, text VARCHAR, dtime DATETIME, username VARCHAR, lang VARCHAR);";
  179. /**
  180. * Creates the table "activity_image" on the database.
  181. */
  182. static final String ACTIVITY_IMAGE = "CREATE TABLE IF NOT EXISTS activity_image (id INT, activity INT, image VARCHAR, idx INT);";
  183. /**
  184. * Creates the table "activity_itinerary" on the database.
  185. */
  186. static final String ACTIVITY_ITINERARY = "CREATE TABLE IF NOT EXISTS activity_itinerary (id INT, activity INT, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, start DATETIME, end DATETIME, place INT, route INT);";
  187. /**
  188. * Creates the table "activity_tag" on the database.
  189. */
  190. static final String ACTIVITY_TAG = "CREATE TABLE IF NOT EXISTS activity_tag (activity INT, tag VARCHAR);";
  191. /**
  192. * Creates the table "album" on the database.
  193. */
  194. static final String ALBUM = "CREATE TABLE IF NOT EXISTS album (id INT, permalink VARCHAR, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, open INT, time DATETIME);";
  195. /**
  196. * Creates the table "festival" on the database.
  197. */
  198. static final String FESTIVAL = "CREATE TABLE IF NOT EXISTS festival (id INT, year INT, text_es VARCHAR, text_en VARCHAR, text_eu VARCHAR, summary_es VARCHAR, summary_en VARCHAR, summary_eu VARCHAR, img VARCHAR);";
  199. /**
  200. * Creates the table "festival_day" on the database.
  201. */
  202. static final String FESTIVAL_DAY = "CREATE TABLE IF NOT EXISTS festival_day (id INT, date DATETIME, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, price INT, people INT, max_people INT);";
  203. /**
  204. * Creates the table "festival_event_city" on the database.
  205. */
  206. static final String FESTIVAL_EVENT_CITY = "CREATE TABLE IF NOT EXISTS festival_event_city (id INT, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, host INT, sponsor INT, place INT, route INT, start DATETIME, end DATETIME, interest INT);";
  207. /**
  208. * Creates the table "festival_event_gm" on the database.
  209. */
  210. static final String FESTIVAL_EVENT_GM = "CREATE TABLE IF NOT EXISTS festival_event_gm (id INT, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, host INT, sponsor INT, place INT, route INT, start DATETIME, end DATETIME, interest INT);";
  211. /**
  212. * Creates the table "festival_event_image" on the database.
  213. */
  214. static final String FESTIVAL_EVENT_IMAGE = "CREATE TABLE IF NOT EXISTS festival_event_image (id INT, event INT, image VARCHAR, idx INT);";
  215. /**
  216. * Creates the table "festival_offer" on the database.
  217. */
  218. static final String FESTIVAL_OFFER = "CREATE TABLE IF NOT EXISTS festival_offer (id INT, year INT, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, days INT, price INT);";
  219. /**
  220. * Creates the table "location" on the database.
  221. */
  222. static final String LOCATION = "CREATE TABLE IF NOT EXISTS location (dtime DATETIME, lat DOUBLE, lon DOUBLE);";
  223. /**
  224. * Creates the table "notification" on the database.
  225. */
  226. static final String NOTIFICATION = "CREATE TABLE IF NOT EXISTS notification (id INT, dtime DATETIME, duration INT, action VARCHAR, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, text_es VARCHAR, text_en VARCHAR, text_eu VARCHAR, internal INT, seen INT DEFAULT 0);";
  227. /**
  228. * Creates the table "people" on the database.
  229. */
  230. static final String PEOPLE = "CREATE TABLE IF NOT EXISTS people (id INT, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, link VARCHAR);";
  231. /**
  232. * Creates the table "photo" on the database.
  233. */
  234. static final String PHOTO = "CREATE TABLE IF NOT EXISTS photo (id INT, file VARCHAR, permalink VARCHAR, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, dtime DATETIME, uploaded DATETIME, place INT, width INT, height INT, size INT, username VARCHAR);";
  235. /**
  236. * Creates the table "photo_album" on the database.
  237. */
  238. static final String PHOTO_ALBUM = "CREATE TABLE IF NOT EXISTS photo_album (photo INT, album INT);";
  239. /**
  240. * Creates the table "photo_comment" on the database.
  241. */
  242. static final String PHOTO_COMMENT = "CREATE TABLE IF NOT EXISTS photo_comment (id INT, photo INT, text VARCHAR, dtime DATETIME, username VARCHAR, lang VARCHAR);";
  243. /**
  244. * Creates the table "place" on the database.
  245. */
  246. static final String PLACE = "CREATE TABLE IF NOT EXISTS place (id INT, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, address_es VARCHAR, address_en VARCHAR, address_eu VARCHAR, cp VARCHAR, lat FLOAT, lon FLOAT);";
  247. /**
  248. * Creates the table "post" on the database.
  249. */
  250. static final String POST = "CREATE TABLE IF NOT EXISTS post (id INT, permalink VARCHAR, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, text_es VARCHAR, text_en VARCHAR, text_eu VARCHAR, comments INT, username VARCHAR, dtime DATETIME);";
  251. /**
  252. * Creates the table "post_comment" on the database.
  253. */
  254. static final String POST_COMMENT = "CREATE TABLE IF NOT EXISTS post_comment (id INT, post INT, text VARCHAR, dtime DATETIME, username VARCHAR, lang VARCHAR);";
  255. /**
  256. * Creates the table "photo" on the database.
  257. */
  258. static final String POST_IMAGE = "CREATE TABLE IF NOT EXISTS post_image (id INT, post INT, image VARCHAR, idx INT);";
  259. /**
  260. * Creates the table "post_tag" on the database.
  261. */
  262. static final String POST_TAG = "CREATE TABLE IF NOT EXISTS post_tag (post INT, tag VARCHAR);";
  263. /**
  264. * Creates the table "route" on the database.
  265. */
  266. static final String ROUTE = "CREATE TABLE IF NOT EXISTS route (id INT, name VARCHAR, mins INT, c_lat DOUBLE, c_lon DOUBLE, zoom INT);";
  267. /**
  268. * Creates the table "route_point" on the database.
  269. */
  270. static final String ROUTE_POINT = "CREATE TABLE IF NOT EXISTS route_point (id INT, route INT, part INT, lat_o DOUBLE, lon_o DOUBLE, lat_d DOUBLE, lon_d DOUBLE, mins INT, visible INT);";
  271. /**
  272. * Creates the table "settings" on the database.
  273. */
  274. static final String SETTINGS = "CREATE TABLE IF NOT EXISTS settings (name VARCHAR, value VARCHAR);";
  275. /**
  276. * Creates the table "sponsor" on the database.
  277. */
  278. static final String SPONSOR = "CREATE TABLE IF NOT EXISTS sponsor (id INT, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, text_es VARCHAR, text_en VARCHAR, text_eu VARCHAR, image VARCHAR, address_es VARCHAR, address_en VARCHAR, address_eu VARCHAR, link VARCHAR, lat FLOAT, lon FLOAT);";
  279. /**
  280. * Creates the table "version" on the database.
  281. */
  282. static final String VERSION = "CREATE TABLE IF NOT EXISTS version (section VARCHAR, version INT);";
  283. }
  284. /**
  285. * Queries to remove tables.
  286. */
  287. final class DROP {
  288. /**
  289. * Deletes the table "activity" from the database.
  290. */
  291. static final String ACTIVITY = "DROP TABLE activity;";
  292. /**
  293. * Deletes the table "activity_comment" from the database.
  294. */
  295. static final String ACTIVITY_COMMENT = "DROP TABLE activity_comment;";
  296. /**
  297. * Deletes the table "activity_comment" from the database.
  298. */
  299. static final String ACTIVITY_IMAGE = "DROP TABLE activity_image;";
  300. /**
  301. * Deletes the table "activity_comment" from the database.
  302. */
  303. static final String ACTIVITY_ITINERARY = "DROP TABLE activity_itinerary;";
  304. /**
  305. * Deletes the table "activity_comment" from the database.
  306. */
  307. static final String ACTIVITY_TAG = "DROP TABLE activity_tag;";
  308. /**
  309. * Deletes the table "album" from the database.
  310. */
  311. static final String ALBUM = "DROP TABLE album;";
  312. /**
  313. * Deletes the table "festival" from the database.
  314. */
  315. static final String FESTIVAL = "DROP TABLE festival;";
  316. /**
  317. * Deletes the table "festival_day" from the database.
  318. */
  319. static final String FESTIVAL_DAY = "DROP TABLE festival_day;";
  320. /**
  321. * Deletes the table "festival_event_city" from the database.
  322. */
  323. static final String FESTIVAL_EVENT_CITY = "DROP TABLE festival_event_city;";
  324. /**
  325. * Deletes the table "festival_event_gm" from the database.
  326. */
  327. static final String FESTIVAL_EVENT_GM = "DROP TABLE festival_event_gm;";
  328. /**
  329. * Deletes the table "festival_event_image" from the database.
  330. */
  331. static final String FESTIVAL_EVENT_IMAGE = "DROP TABLE festival_event_image;";
  332. /**
  333. * Deletes the table "festival_offer" from the database.
  334. */
  335. static final String FESTIVAL_OFFER = "DROP TABLE festival_offer;";
  336. /**
  337. * Deletes the table "location" from the database.
  338. */
  339. static final String LOCATION = "DROP TABLE location;";
  340. /**
  341. * Deletes the table "notification" from the database.
  342. */
  343. static final String NOTIFICATION = "DROP TABLE notification;";
  344. /**
  345. * Deletes the table "people" from the database.
  346. */
  347. static final String PEOPLE = "DROP TABLE people;";
  348. /**
  349. * Deletes the table "photo" from the database.
  350. */
  351. static final String PHOTO = "DROP TABLE photo;";
  352. /**
  353. * Deletes the table "photo_album" from the database.
  354. */
  355. static final String PHOTO_ALBUM = "DROP TABLE photo_album;";
  356. /**
  357. * Deletes the table "photo_comment" from the database.
  358. */
  359. static final String PHOTO_COMMENT = "DROP TABLE photo_comment;";
  360. /**
  361. * Deletes the table "place" from the database.
  362. */
  363. static final String PLACE = "DROP TABLE place;";
  364. /**
  365. * Deletes the table "post" from the database.
  366. */
  367. static final String POST = "DROP TABLE post;";
  368. /**
  369. * Deletes the table "post_comment" from the database.
  370. */
  371. static final String POST_COMMENT = "DROP TABLE post_comment;";
  372. /**
  373. * Deletes the table "post_image" from the database.
  374. */
  375. static final String POST_IMAGE = "DROP TABLE post_image;";
  376. /**
  377. * Deletes the table "post_tag" from the database.
  378. */
  379. static final String POST_TAG = "DROP TABLE post_tag;";
  380. /**
  381. * Deletes the table "route" from the database.
  382. */
  383. static final String ROUTE = "DROP TABLE route;";
  384. /**
  385. * Deletes the table "route_point" from the database.
  386. */
  387. static final String ROUTE_POINT = "DROP TABLE route_point;";
  388. /**
  389. * Deletes the table "settings" from the database.
  390. */
  391. static final String SETTINGS = "DROP TABLE settings;";
  392. /**
  393. * Deletes the table "sponsor" from the database.
  394. */
  395. static final String SPONSOR = "DROP TABLE sponsor;";
  396. /**
  397. * Deletes the table "version" from the database.
  398. */
  399. static final String VERSION = "DROP TABLE version;";
  400. }
  401. /**
  402. * Queries to empty tables.
  403. */
  404. @SuppressWarnings("unused")
  405. final class EMPTY {
  406. /**
  407. * Empties the table "activity".
  408. */
  409. static final String ACTIVITY = "DELETE FROM activity;";
  410. /**
  411. * Empties the table "activity_comment".
  412. */
  413. static final String ACTIVITY_COMMENT = "DELETE FROM activity_comment;";
  414. /**
  415. * Empties the table "activity_image".
  416. */
  417. static final String ACTIVITY_IMAGE = "DELETE FROM activity_image;";
  418. /**
  419. * Empties the table "activity_itinerary".
  420. */
  421. static final String ACTIVITY_ITINERARY = "DELETE FROM activity_itinerary;";
  422. /**
  423. * Empties the table "activity_tag".
  424. */
  425. static final String ACTIVITY_TAG = "DELETE FROM activity_tag;";
  426. /**
  427. * Empties the table "album".
  428. */
  429. static final String ALBUM = "DELETE FROM album;";
  430. /**
  431. * Empties the table "festival".
  432. */
  433. static final String FESTIVAL = "DELETE FROM festival;";
  434. /**
  435. * Empties the table "festival_day".
  436. */
  437. static final String FESTIVAL_DAY = "DELETE FROM festival_day;";
  438. /**
  439. * Empties the table "festival_event_city".
  440. */
  441. static final String FESTIVAL_EVENT_CITY = "DELETE FROM festival_event_city;";
  442. /**
  443. * Empties the table "festival_event_gm".
  444. */
  445. static final String FESTIVAL_EVENT_GM = "DELETE FROM festival_event_gm;";
  446. /**
  447. * Empties the table "festival_event_image".
  448. */
  449. static final String FESTIVAL_EVENT_IMAGE = "DELETE FROM festival_event_image;";
  450. /**
  451. * Empties the table "festival_offer".
  452. */
  453. static final String FESTIVAL_OFFER = "DELETE FROM festival_offer;";
  454. /**
  455. * Empties the table "location".
  456. */
  457. static final String LOCATION = "DELETE FROM location;";
  458. /**
  459. * Empties the table "notification".
  460. */
  461. static final String NOTIFICATION = "DELETE FROM notification;";
  462. /**
  463. * Empties the table "people".
  464. */
  465. static final String PEOPLE = "DELETE FROM people;";
  466. /**
  467. * Empties the table "photo".
  468. */
  469. static final String PHOTO = "DELETE FROM photo;";
  470. /**
  471. * Empties the table "photo_album".
  472. */
  473. static final String PHOTO_ALBUM = "DELETE FROM photo_album;";
  474. /**
  475. * Empties the table "photo_comment".
  476. */
  477. static final String PHOTO_COMMENT = "DELETE FROM photo_comment;";
  478. /**
  479. * Empties the table "place".
  480. */
  481. static final String PLACE = "DELETE FROM place;";
  482. /**
  483. * Empties the table "post".
  484. */
  485. static final String POST = "DELETE FROM post;";
  486. /**
  487. * Empties the table "post_comment".
  488. */
  489. static final String POST_COMMENT = "DELETE FROM post_comment;";
  490. /**
  491. * Empties the table "post_image".
  492. */
  493. static final String POST_IMAGE = "DELETE FROM post_image;";
  494. /**
  495. * Empties the table "post_tag".
  496. */
  497. static final String POST_TAG = "DELETE FROM post_tag;";
  498. /**
  499. * Empties the table "route".
  500. */
  501. static final String ROUTE = "DELETE FROM route;";
  502. /**
  503. * Empties the table "route_point".
  504. */
  505. static final String ROUTE_POINT = "DELETE FROM route_point;";
  506. /**
  507. * Empties the table "settings".
  508. */
  509. static final String SETTINGS = "DELETE FROM settings;";
  510. /**
  511. * Empties the table "sponsor".
  512. */
  513. static final String SPONSOR = "DELETE FROM sponsor;";
  514. /**
  515. * Empties the table "version".
  516. */
  517. static final String VERSION = "DELETE FROM version;";
  518. }
  519. /**
  520. * Queries to remove and the recreate tables.
  521. */
  522. @SuppressWarnings("unused")
  523. final class RECREATE {
  524. /**
  525. * Deletes and then recreates the table "activity".
  526. */
  527. static final String ACTIVITY = GM.DB.QUERY.DROP.ACTIVITY + GM.DB.QUERY.CREATE.ACTIVITY;
  528. /**
  529. * Deletes and then recreates the table "activity_comment".
  530. */
  531. static final String ACTIVITY_COMMENT = GM.DB.QUERY.DROP.ACTIVITY_COMMENT + GM.DB.QUERY.CREATE.ACTIVITY_COMMENT;
  532. /**
  533. * Deletes and then recreates the table "activity_image".
  534. */
  535. static final String ACTIVITY_IMAGE = GM.DB.QUERY.DROP.ACTIVITY_IMAGE + GM.DB.QUERY.CREATE.ACTIVITY_IMAGE;
  536. /**
  537. * Deletes and then recreates the table "itinerary".
  538. */
  539. static final String ACTIVITY_ITINERARY = GM.DB.QUERY.DROP.ACTIVITY_ITINERARY + GM.DB.QUERY.CREATE.ACTIVITY_ITINERARY;
  540. /**
  541. * Deletes and then recreates the table "activity_tag".
  542. */
  543. static final String ACTIVITY_TAG = GM.DB.QUERY.DROP.ACTIVITY_TAG + GM.DB.QUERY.CREATE.ACTIVITY_TAG;
  544. /**
  545. * Deletes and then recreates the table "album".
  546. */
  547. static final String ALBUM = GM.DB.QUERY.DROP.ALBUM + GM.DB.QUERY.CREATE.ALBUM;
  548. /**
  549. * Deletes and then recreates the table "festival".
  550. */
  551. static final String FESTIVAL = GM.DB.QUERY.DROP.FESTIVAL + GM.DB.QUERY.CREATE.FESTIVAL;
  552. /**
  553. * Deletes and then recreates the table "festival_day".
  554. */
  555. static final String FESTIVAL_DAY = GM.DB.QUERY.DROP.FESTIVAL_DAY + GM.DB.QUERY.CREATE.FESTIVAL_DAY;
  556. /**
  557. * Deletes and then recreates the table "festival_event_city".
  558. */
  559. static final String FESTIVAL_EVENT_CITY = GM.DB.QUERY.DROP.FESTIVAL_EVENT_CITY + GM.DB.QUERY.CREATE.FESTIVAL_EVENT_CITY;
  560. /**
  561. * Deletes and then recreates the table "festival_event_gm".
  562. */
  563. static final String FESTIVAL_EVENT_GM = GM.DB.QUERY.DROP.FESTIVAL_EVENT_GM + GM.DB.QUERY.CREATE.FESTIVAL_EVENT_GM;
  564. /**
  565. * Deletes and then recreates the table "festival_event_image".
  566. */
  567. static final String FESTIVAL_EVENT_IMAGE = GM.DB.QUERY.DROP.FESTIVAL_EVENT_IMAGE + GM.DB.QUERY.CREATE.FESTIVAL_EVENT_IMAGE;
  568. /**
  569. * Deletes and then recreates the table "festival_offer".
  570. */
  571. static final String FESTIVAL_OFFER = GM.DB.QUERY.DROP.FESTIVAL_OFFER + GM.DB.QUERY.CREATE.FESTIVAL_OFFER;
  572. /**
  573. * Deletes and then recreates the table "location".
  574. */
  575. static final String LOCATION = GM.DB.QUERY.DROP.LOCATION + GM.DB.QUERY.CREATE.LOCATION;
  576. /**
  577. * Deletes and then recreates the table "notification".
  578. */
  579. static final String NOTIFICATION = GM.DB.QUERY.DROP.NOTIFICATION + GM.DB.QUERY.CREATE.NOTIFICATION;
  580. /**
  581. * Deletes and then recreates the table "people".
  582. */
  583. static final String PEOPLE = GM.DB.QUERY.DROP.PEOPLE + GM.DB.QUERY.CREATE.PEOPLE;
  584. /**
  585. * Deletes and then recreates the table "photo".
  586. */
  587. static final String PHOTO = GM.DB.QUERY.DROP.PHOTO + GM.DB.QUERY.CREATE.PHOTO;
  588. /**
  589. * Deletes and then recreates the table "photo_album".
  590. */
  591. static final String PHOTO_ALBUM = GM.DB.QUERY.DROP.PHOTO_ALBUM + GM.DB.QUERY.CREATE.PHOTO_ALBUM;
  592. /**
  593. * Deletes and then recreates the table "photo_comment".
  594. */
  595. static final String PHOTO_COMMENT = GM.DB.QUERY.DROP.PHOTO_COMMENT + GM.DB.QUERY.CREATE.PHOTO_COMMENT;
  596. /**
  597. * Deletes and then recreates the table "place".
  598. */
  599. static final String PLACE = GM.DB.QUERY.DROP.PLACE + GM.DB.QUERY.CREATE.PLACE;
  600. /**
  601. * Deletes and then recreates the table "post".
  602. */
  603. static final String POST = GM.DB.QUERY.DROP.POST + GM.DB.QUERY.CREATE.POST;
  604. /**
  605. * Deletes and then recreates the table "post_comment".
  606. */
  607. static final String POST_COMMENT = GM.DB.QUERY.DROP.POST_COMMENT + GM.DB.QUERY.CREATE.POST_COMMENT;
  608. /**
  609. * Deletes and then recreates the table "post_image".
  610. */
  611. static final String POST_IMAGE = GM.DB.QUERY.DROP.POST_IMAGE + GM.DB.QUERY.CREATE.POST_IMAGE;
  612. /**
  613. * Deletes and then recreates the table "post_tag".
  614. */
  615. static final String POST_TAG = GM.DB.QUERY.DROP.POST_TAG + GM.DB.QUERY.CREATE.POST_TAG;
  616. /**
  617. * Deletes and then recreates the table "route".
  618. */
  619. static final String ROUTE = GM.DB.QUERY.DROP.ROUTE + GM.DB.QUERY.CREATE.ROUTE;
  620. /**
  621. * Deletes and then recreates the table "route_point".
  622. */
  623. static final String ROUTE_PONT = GM.DB.QUERY.DROP.ROUTE_POINT + GM.DB.QUERY.CREATE.ROUTE_POINT;
  624. /**
  625. * Deletes and then recreates the table "settings".
  626. */
  627. static final String SETTINGS = GM.DB.QUERY.DROP.SETTINGS + GM.DB.QUERY.CREATE.SETTINGS;
  628. /**
  629. * Deletes and then recreates the table "sponsor".
  630. */
  631. static final String SPONSOR = GM.DB.QUERY.DROP.SPONSOR + GM.DB.QUERY.CREATE.SPONSOR;
  632. /**
  633. * Deletes and then recreates the table "version".
  634. */
  635. static final String VERSION = GM.DB.QUERY.DROP.VERSION + GM.DB.QUERY.CREATE.VERSION;
  636. }
  637. }
  638. }
  639. /**
  640. * Keys and values of data that the app needs to store.
  641. */
  642. static final class DATA {
  643. /**
  644. * Name of the file where data will be stored.
  645. */
  646. static final String DATA = "data";
  647. /**
  648. * Keys of data that the app needs to store.
  649. */
  650. static final class KEY {
  651. /**
  652. * Key of the data string to store the user id with.
  653. */
  654. static final String USER = "user_id";
  655. /**
  656. * Key of the data to store the previous app version with.
  657. */
  658. static final String PREVIOUS_APP_VERSION = "previous_app_version";
  659. /**
  660. * Key of the data to store if ther is a festival season.
  661. */
  662. static final String LABLANCA = "lablanca";
  663. /**
  664. * Key that indicates if comments can be posted.
  665. */
  666. static final String COMMENTS = "comments";
  667. /**
  668. * Key that indicates if photos can be uploaded.
  669. */
  670. static final String PHOTOS = "photos";
  671. }
  672. /**
  673. * Default values of data that the app needs to store.
  674. */
  675. static final class DEFAULT {
  676. /**
  677. * Default string for the user.
  678. */
  679. static final String USER = "";
  680. /**
  681. * Default value for the previous app version data.
  682. */
  683. static final int PREVIOUS_APP_VERSION = 0;
  684. /**
  685. * Default value for the data that indicates if it's festival season.
  686. */
  687. static final boolean LABLANCA = false;
  688. /**
  689. * Default value for the key that indicates if comments can be posted.
  690. */
  691. static final boolean COMMENTS = false;
  692. /**
  693. * Default value for the key that indicates if photos can be uploaded.
  694. */
  695. static final boolean PHOTOS = false;
  696. }
  697. }
  698. /**
  699. * Keys and values of the app settings.
  700. */
  701. static final class PREFERENCES {
  702. /**
  703. * Name of the file where preferences will be stored.
  704. */
  705. static final String PREFERNCES = "preferences";
  706. /**
  707. * Keys of the app settings.
  708. */
  709. static final class KEY {
  710. /**
  711. * Key to store the sync status.
  712. */
  713. static final String SYNC = "performBackgroundSyncs";
  714. /**
  715. * Key to store the notification preference status.
  716. */
  717. static final String NOTIFICATIONS = "recieveNotificacions";
  718. }
  719. /**
  720. * Default values of the app settings.
  721. */
  722. static final class DEFAULT {
  723. /**
  724. * Default value for the sync preference.
  725. */
  726. static final boolean SYNC = true;
  727. /**
  728. * Default value for the notification preference.
  729. */
  730. static final boolean NOTIFICATIONS = true;
  731. }
  732. }
  733. /**
  734. * Used URLs.
  735. */
  736. static class URL {
  737. /**
  738. * URL of the project on GitHub.
  739. */
  740. static final String GITHUB = "https://github.com/GasteizkoMargolariak/GasteizkoMargolariakApp";
  741. /**
  742. * URL of the Open Street Maps copyright.
  743. */
  744. static final String OSM_COPYRIGHT = "https://www.openstreetmap.org/copyright";
  745. /**
  746. * URL of the server.
  747. */
  748. //static final String SERVER = "https://margolariak.com";
  749. static final String SERVER = "http://192.168.1.101";
  750. }
  751. /**
  752. * Info about the API.
  753. */
  754. static final class API {
  755. /**
  756. * Name of the client.
  757. */
  758. static final String CLIENT = "com.ivalentin.margolariak";
  759. /**
  760. * URL of the server.
  761. */
  762. static final String SERVER = URL.SERVER;
  763. /**
  764. * Utilities for the Sync V3 API.
  765. */
  766. static final class SYNC {
  767. /**
  768. * Path to the API.
  769. */
  770. static final class PATH {
  771. /**
  772. * Path to the fast sync API.
  773. */
  774. static final String FAST= "/API/v3/fastsync.php";
  775. /**
  776. * Path to the regular sync API.
  777. */
  778. static final String COMPLETE= "/API/v3/sync.php";
  779. }
  780. /**
  781. * Keys fotr the API parameters.
  782. */
  783. static final class KEY {
  784. /**
  785. * Key for the client identifier.
  786. */
  787. static final String CLIENT = "client";
  788. /**
  789. * Key for the user identifier.
  790. */
  791. static final String USER = "user";
  792. /**
  793. * Key to indicate to the API if the sync is being performed on the foreground.
  794. */
  795. static final String FOREGROUND = "foreground";
  796. }
  797. }
  798. /**
  799. * Utilities for the Location V3 API.
  800. */
  801. static final class LOCATION {
  802. /**
  803. * Path to the API.
  804. */
  805. static final String PATH = "/API/v3/location.php";
  806. }
  807. /**
  808. * Utilities for the Notifications V3 API.
  809. */
  810. static final class NOTIFICATION {
  811. /**
  812. * Path to the API.
  813. */
  814. static final String PATH = "/API/v3/notifications.php";
  815. /**
  816. * Keys fotr the API parameters.
  817. */
  818. static final class KEY {
  819. /**
  820. * Key for the client identifier.
  821. */
  822. static final String CLIENT = "client";
  823. /**
  824. * Key for the user identifier.
  825. */
  826. static final String USER = "user";
  827. /**
  828. * Key for the action to perform with the API ("sync" or "version").
  829. */
  830. static final String TARGET = "target";
  831. }
  832. }
  833. /**
  834. * Utilities for the COMMENT V3 API.
  835. */
  836. static final class COMMENT {
  837. /**
  838. * Path to the API.
  839. */
  840. static final String PATH = "/API/v3/comment.php";
  841. /**
  842. * Keys fotr the API parameters.
  843. */
  844. static final class KEY {
  845. /**
  846. * Key for the client identifier.
  847. */
  848. static final String CLIENT = "client";
  849. /**
  850. * Key for the user identifier.
  851. */
  852. static final String USER = "user";
  853. /**
  854. * Key for the action to perform with the API ("sync" or "version").
  855. */
  856. static final String TARGET = "target";
  857. /**
  858. * Key to indicate the format of the data for the API to send.
  859. */
  860. static final String ID = "id";
  861. /**
  862. * Key to indicate the comment's username.
  863. */
  864. static final String USERNAME = "username";
  865. /**
  866. * Key to indicate the text.
  867. */
  868. static final String TEXT = "text";
  869. }
  870. }
  871. }
  872. /**
  873. * App permissions.
  874. */
  875. static final class PERMISSION {
  876. /**
  877. * Code for the location permission request
  878. */
  879. static final int LOCATION = 1;
  880. }
  881. /**
  882. * Periods to perform syncs.
  883. */
  884. static final class PERIOD_SYNC {
  885. /**
  886. * Period of time (in seconds) at the end of witch the app will perform a sync during the festivals.
  887. */
  888. static final int FESTIVALS = 20 * 60 * 1000;
  889. /**
  890. * Period of time (in seconds) at the end of witch the app will perform a sync if no festivals.
  891. */
  892. static final int NORMAL = 60 * 60 * 1000;
  893. }
  894. /**
  895. * Identifiers to differenciate schedules.
  896. */
  897. static final class SCHEDULE {
  898. /**
  899. * Key to pass as bundle.
  900. */
  901. static final String KEY = "schedule";
  902. /**
  903. * City schedule.
  904. */
  905. static final int CITY = 0;
  906. /**
  907. * Margolari schedule.
  908. */
  909. static final int MARGOLARIAK = 1;
  910. }
  911. /**
  912. * Extras to pass to the main activity to open notifications.
  913. */
  914. static final class EXTRA {
  915. /**
  916. * Title of the notification.
  917. */
  918. static final String TITLE = "title";
  919. /**
  920. * Text of the notification.
  921. */
  922. static final String TEXT = "text";
  923. /**
  924. * Action for the button in the notification.
  925. */
  926. static final String ACTION = "action";
  927. /**
  928. * Sections to open with the notification.
  929. */
  930. static final class SECTION {
  931. /**
  932. * Value for {@see GM.EXTRA.ACTION} that opens the lablanca section.
  933. */
  934. static final String LABLANCA = "lablanca";
  935. /**
  936. * Value for {@see GM.EXTRA.ACTION} that opens the official schedule.
  937. */
  938. static final String SCHEDULE = "cityschedule";
  939. /**
  940. * Value for {@see GM.EXTRA.ACTION} that opens the GM schedule.
  941. */
  942. static final String GMSCHEDULE = "gmschedule";
  943. /**
  944. * Value for {@see GM.EXTRA.ACTION} that opens the location secton.
  945. */
  946. static final String LOCATION = "location";
  947. /**
  948. * Value for {@see GM.EXTRA.ACTION} that opens the blog.
  949. */
  950. static final String BLOG = "blog";
  951. /**
  952. * Value for {@see GM.EXTRA.ACTION} that opens the activities section.
  953. */
  954. static final String ACTIVITIES = "activities";
  955. /**
  956. * Value for {@see GM.EXTRA.ACTION} that opens the gallery section.
  957. */
  958. static final String GALLERY = "gallery";
  959. }
  960. }
  961. /**
  962. * Identifiers for app sections.
  963. */
  964. static final class SECTION {
  965. /**
  966. * Constant for section "Home".
  967. */
  968. static final byte HOME = 0;
  969. /**
  970. * Constant for La Blanca section "Location".
  971. */
  972. static final byte LOCATION = 1;
  973. /**
  974. * Constant for section "La Blanca".
  975. */
  976. static final byte LABLANCA = 2;
  977. /**
  978. * Constant for La Blanca section "Festival schedule".
  979. */
  980. static final byte SCHEDULE = 20;
  981. /**
  982. * Constant for La Blanca section "Gasteizko Margolariak Schedule".
  983. */
  984. static final byte GM_SCHEDULE = 21;
  985. /**
  986. * Constant for section "Activities".
  987. */
  988. static final byte ACTIVITIES = 3;
  989. /**
  990. * Constant for section "Blog".
  991. */
  992. static final byte BLOG = 4;
  993. /**
  994. * Constant for section "Gallery".
  995. */
  996. static final byte GALLERY = 5;
  997. }
  998. /**
  999. * Keys for the location manager.
  1000. */
  1001. static class LOCATION {
  1002. /**
  1003. * Required accuracy for the location manager.
  1004. */
  1005. static class ACCURACY {
  1006. /**
  1007. * The desired accuracy of the GPS coordinates, used to provide location updates, in meters.
  1008. */
  1009. static final int SPACE = 10;
  1010. /**
  1011. * The desired accuracy of the GPS coordinates, used to provide location updates, in milliseconds.
  1012. */
  1013. static final int TIME = 10000;
  1014. }
  1015. /**
  1016. * Time interval to retrieve notifications.
  1017. */
  1018. static final int INTERVAL = 10000;
  1019. }
  1020. /**
  1021. * Data for the images.
  1022. */
  1023. static final class IMG {
  1024. /**
  1025. * Dimensions of the images in the database.
  1026. */
  1027. static final class SIZE {
  1028. /**
  1029. * Max width and height for miniature images.
  1030. */
  1031. static final int MINIATURE = 340;
  1032. /**
  1033. * Max width and height for preview images.
  1034. */
  1035. static final int PREVIEW = 600;
  1036. /**
  1037. * Max width and height for thumbnail images.
  1038. */
  1039. @SuppressWarnings("unused")
  1040. static final int THUMB = 180;
  1041. /**
  1042. * Max width and height for view images.
  1043. */
  1044. static final int VIEW = 800;
  1045. }
  1046. }
  1047. /**
  1048. * Programmatically loaded rows needs their margin to also be set programmatically.
  1049. */
  1050. static final class UI {
  1051. /**
  1052. * Margin for entries.
  1053. */
  1054. static final int ENTRY_MARGIN = 8;
  1055. }
  1056. /**
  1057. * URLs to be shared.
  1058. */
  1059. static final class SHARE {
  1060. static final String HOME = "https://www.margolariak.com";
  1061. static final String LABLANCA = HOME + "/lablanca/";
  1062. static final String ACTIVITIES = HOME + "/actividades/";
  1063. static final String BLOG = HOME + "/blog/";
  1064. static final String GALLERY = HOME + "/galeria/";
  1065. }
  1066. /**
  1067. * Gets the language code for sql queries.
  1068. * Only three values can be returned: es, eu, en.
  1069. * Defaults to es.
  1070. *
  1071. * @return Language two-letter code
  1072. */
  1073. public static String getLang(){
  1074. String currLang = Locale.getDefault().getISO3Language();
  1075. switch (currLang){
  1076. case "eng":
  1077. currLang = "en";
  1078. break;
  1079. case "eus":
  1080. currLang = "eu";
  1081. break;
  1082. default:
  1083. currLang = "es";
  1084. }
  1085. return currLang;
  1086. }
  1087. /**
  1088. * Formats a datetime format strings and returns a human readable date, depending on the language
  1089. *
  1090. * @param dateString String in a datetime format.
  1091. * @param lang Language (es, en, eu).
  1092. * @param includeDay Also returns the weekday.
  1093. * @param includeYear Also returns the year.
  1094. * @param includeTime Also returns the hour and minute.
  1095. *
  1096. * @return The fragment view
  1097. *
  1098. * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
  1099. */
  1100. static String formatDate(String dateString, String lang, boolean includeDay, boolean includeYear, boolean includeTime){
  1101. String output = "";
  1102. String dayNameEs[] = {"dummy", "Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"};
  1103. String dayNameEn[] = {"dummy", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  1104. String dayNameEu[] = {"dummy", "igandea", "astelehena", "asteartea", "asteazkena", "osteguna", "ostirala", "larumbata"};
  1105. String monthNameEs[] = {"enero", " febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"};
  1106. String monthNameEn[] = {"January", "February", "March", "April", "May", "June", "July", "Augost", "September", "Octuber", "November", "December"};
  1107. String monthNameEu[] = {"urtarrilaren", "otsailaren", "martxoaren", "apirilaren", "maiatzaren", "ekainaren", "uztailaren", "abuztuaren", "irailaren", "urriaren", "azaroaren", "abenduaren"};
  1108. if (!lang.equals("es") && !lang.equals("eu")){
  1109. lang = "en";
  1110. }
  1111. DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH);
  1112. SimpleDateFormat df;
  1113. Date date;
  1114. try{
  1115. date = format.parse(dateString);
  1116. df = new SimpleDateFormat("yyyy", Locale.US);
  1117. String year = df.format(date);
  1118. df = new SimpleDateFormat("hh:mm", Locale.US);
  1119. String time = df.format(date);
  1120. String dayName, monthName;
  1121. Calendar calendar = Calendar.getInstance();
  1122. calendar.setTime(date);
  1123. int dayNumber = calendar.get(Calendar.DAY_OF_WEEK);
  1124. int day = calendar.get(Calendar.DAY_OF_MONTH);
  1125. int monthNumber = calendar.get(Calendar.MONTH);
  1126. switch (lang){
  1127. case "es":
  1128. dayName = dayNameEs[dayNumber];
  1129. monthName = monthNameEs[monthNumber];
  1130. output = "";
  1131. if (includeDay){
  1132. output = dayName + ", ";
  1133. }
  1134. output = output + day + " de " + monthName;
  1135. if (includeYear){
  1136. output = output + " de " + year;
  1137. }
  1138. if (includeTime){
  1139. output = output + " a las " + time;
  1140. }
  1141. break;
  1142. case "eu":
  1143. dayName = dayNameEu[dayNumber];
  1144. monthName = monthNameEu[monthNumber];
  1145. output = "";
  1146. if (includeYear){
  1147. output = year + "ko";
  1148. }
  1149. output = output + monthName + " " + day + "an";
  1150. if (includeDay){
  1151. output = output + ", " + dayName;
  1152. }
  1153. if (includeTime){
  1154. output = output + " " + time + "etan";
  1155. }
  1156. break;
  1157. default:
  1158. dayName = dayNameEn[dayNumber];
  1159. monthName = monthNameEn[monthNumber];
  1160. output = "";
  1161. if (includeDay){
  1162. output = dayName + ", ";
  1163. }
  1164. output = output + monthName + " " + day;
  1165. if (includeYear){
  1166. output = output + ", " + year;
  1167. }
  1168. if (includeTime){
  1169. output = output + " " + time;
  1170. }
  1171. break;
  1172. }
  1173. }
  1174. catch(Exception ex){
  1175. Log.e("Date format error", ex.toString());
  1176. }
  1177. return output;
  1178. }
  1179. /**
  1180. * Creates a bitmap from a image.
  1181. *
  1182. * @param path Path of the image.
  1183. * @param size Max width and height.
  1184. * @return A bitmap with the image.
  1185. */
  1186. static Bitmap decodeSampledBitmapFromFile(String path, int size) { // BEST QUALITY MATCH
  1187. // First decode with inJustDecodeBounds=true to check dimensions
  1188. final BitmapFactory.Options options = new BitmapFactory.Options();
  1189. options.inJustDecodeBounds = true;
  1190. BitmapFactory.decodeFile(path, options);
  1191. // Calculate inSampleSize
  1192. // Raw height and width of image
  1193. final int height = options.outHeight;
  1194. final int width = options.outWidth;
  1195. options.inPreferredConfig = Bitmap.Config.RGB_565;
  1196. int inSampleSize = 1;
  1197. if (height > size) {
  1198. inSampleSize = Math.round((float)height / (float)size);
  1199. }
  1200. int expectedWidth = width / inSampleSize;
  1201. if (expectedWidth > size) {
  1202. //if(Math.round((float)width / (float)reqWidth) > inSampleSize) // If bigger SampSize..
  1203. inSampleSize = Math.round((float)width / (float)size);
  1204. }
  1205. options.inSampleSize = inSampleSize;
  1206. // Decode bitmap with inSampleSize set
  1207. options.inJustDecodeBounds = false;
  1208. return BitmapFactory.decodeFile(path, options);
  1209. }
  1210. }