GM.java 34 KB

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