GM.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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. final class DB {
  18. final class QUERY {
  19. final class CREATE {
  20. 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);";
  21. static final String ACTIVITY_COMMENT = "CREATE TABLE IF NOT EXISTS activity_comment (id INT, activity INT, text VARCHAR, dtime DATETIME, username VARCHAR, lang VARCHAR);";
  22. static final String ACTIVITY_IMAGE = "CREATE TABLE IF NOT EXISTS activity_image (id INT, activity INT, image VARCHAR, idx INT);";
  23. 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);";
  24. static final String ACTIVITY_TAG = "CREATE TABLE IF NOT EXISTS activity_tag (activity INT, tag VARCHAR);";
  25. 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);";
  26. 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);";
  27. 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);";
  28. 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);";
  29. static final String FESTIVAL_EVENT_IMAGE = "CREATE TABLE IF NOT EXISTS festival_event_image (id INT, event INT, image VARCHAR, idx INT);";
  30. 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);";
  31. static final String LOCATION = "CREATE TABLE IF NOT EXISTS location (id INT, dtime DATETIME, lat FLOAT, lon FLOAT, manual INT);";
  32. 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);";
  33. static final String PEOPLE = "CREATE TABLE IF NOT EXISTS people (id INT, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, link VARCHAR);";
  34. 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);";
  35. static final String PHOTO_ALBUM = "CREATE TABLE IF NOT EXISTS photo_album (photo INT, album INT);";
  36. static final String PHOTO_COMMENT = "CREATE TABLE IF NOT EXISTS photo_comment (id INT, photo INT, text VARCHAR, dtime DATETIME, username VARCHAR, lang VARCHAR);";
  37. 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);";
  38. 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, dtime DATETIME, comments INT, username VARCHAR);";
  39. static final String POST_COMMENT = "CREATE TABLE IF NOT EXISTS post_comment (id INT, post INT, text VARCHAR, dtime DATETIME, username VARCHAR, lang VARCHAR);";
  40. static final String POST_IMAGE = "CREATE TABLE IF NOT EXISTS post_image (id INT, post INT, image VARCHAR, idx INT);";
  41. static final String POST_TAG = "CREATE TABLE IF NOT EXISTS post_tag (post INT, tag VARCHAR);";
  42. static final String SETTINGS = "CREATE TABLE IF NOT EXISTS settings (name VARCHAR, value VARCHAR);";
  43. 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);";
  44. static final String VERSION = "CREATE TABLE IF NOT EXISTS version (section VARCHAR, version INT);";
  45. }
  46. final class DROP {
  47. static final String ACTIVITY = "DROP TABLE activity;";
  48. static final String ACTIVITY_COMMENT = "DROP TABLE activity_comment;";
  49. static final String ACTIVITY_IMAGE = "DROP TABLE activity_image;";
  50. static final String ACTIVITY_ITINERARY = "DROP TABLE activity_itinerary;";
  51. static final String ACTIVITY_TAG = "DROP TABLE activity_tag;";
  52. static final String ALBUM = "DROP TABLE album;";
  53. static final String FESTIVAL = "DROP TABLE festival;";
  54. static final String FESTIVAL_DAY = "DROP TABLE festival_day;";
  55. static final String FESTIVAL_EVENT = "DROP TABLE festival_event;";
  56. static final String FESTIVAL_EVENT_IMAGE = "DROP TABLE festival_event_image;";
  57. static final String FESTIVAL_OFFER = "DROP TABLE festival_offer;";
  58. static final String LOCATION = "DROP TABLE location;";
  59. static final String NOTIFICATION = "DROP TABLE notification;";
  60. static final String PEOPLE = "DROP TABLE people;";
  61. static final String PHOTO = "DROP TABLE photo;";
  62. static final String PHOTO_ALBUM = "DROP TABLE photo_album;";
  63. static final String PHOTO_COMMENT = "DROP TABLE photo_comment;";
  64. static final String PLACE = "DROP TABLE place;";
  65. static final String POST = "DROP TABLE post;";
  66. static final String POST_COMMENT = "DROP TABLE post_comment;";
  67. static final String POST_IMAGE = "DROP TABLE post_image;";
  68. static final String POST_TAG = "DROP TABLE post_tag;";
  69. static final String SETTINGS = "DROP TABLE settings;";
  70. static final String SPONSOR = "DROP TABLE sponsor;";
  71. static final String VERSION = "DROP TABLE version;";
  72. }
  73. final class RECREATE {
  74. static final String ACTIVITY = GM.DB.QUERY.DROP.ACTIVITY + GM.DB.QUERY.CREATE.ACTIVITY;
  75. static final String ACTIVITY_COMMENT = GM.DB.QUERY.DROP.ACTIVITY_COMMENT + GM.DB.QUERY.CREATE.ACTIVITY_COMMENT;
  76. static final String ACTIVITY_IMAGE = GM.DB.QUERY.DROP.ACTIVITY_IMAGE + GM.DB.QUERY.CREATE.ACTIVITY_IMAGE;
  77. static final String ACTIVITY_ITINERARY = GM.DB.QUERY.DROP.ACTIVITY_ITINERARY + GM.DB.QUERY.CREATE.ACTIVITY_ITINERARY;
  78. static final String ACTIVITY_TAG = GM.DB.QUERY.DROP.ACTIVITY_TAG + GM.DB.QUERY.CREATE.ACTIVITY_TAG;
  79. static final String ALBUM = GM.DB.QUERY.DROP.ALBUM + GM.DB.QUERY.CREATE.ALBUM;
  80. static final String FESTIVAL = GM.DB.QUERY.DROP.FESTIVAL + GM.DB.QUERY.CREATE.FESTIVAL;
  81. static final String FESTIVAL_DAY = GM.DB.QUERY.DROP.FESTIVAL_DAY + GM.DB.QUERY.CREATE.FESTIVAL_DAY;
  82. static final String FESTIVAL_EVENT = GM.DB.QUERY.DROP.FESTIVAL_EVENT + GM.DB.QUERY.CREATE.FESTIVAL_EVENT;
  83. static final String FESTIVAL_EVENT_IMAGE = GM.DB.QUERY.DROP.FESTIVAL_EVENT_IMAGE + GM.DB.QUERY.CREATE.FESTIVAL_EVENT_IMAGE;
  84. static final String FESTIVAL_OFFER = GM.DB.QUERY.DROP.FESTIVAL_OFFER + GM.DB.QUERY.CREATE.FESTIVAL_OFFER;
  85. static final String LOCATION = GM.DB.QUERY.DROP.LOCATION + GM.DB.QUERY.CREATE.LOCATION;
  86. static final String NOTIFICATION = GM.DB.QUERY.DROP.NOTIFICATION + GM.DB.QUERY.CREATE.NOTIFICATION;
  87. static final String PEOPLE = GM.DB.QUERY.DROP.PEOPLE + GM.DB.QUERY.CREATE.PEOPLE;
  88. static final String PHOTO = GM.DB.QUERY.DROP.PHOTO + GM.DB.QUERY.CREATE.PHOTO;
  89. static final String PHOTO_ALBUM = GM.DB.QUERY.DROP.PHOTO_ALBUM + GM.DB.QUERY.CREATE.PHOTO_ALBUM;
  90. static final String PHOTO_COMMENT = GM.DB.QUERY.DROP.PHOTO_COMMENT + GM.DB.QUERY.CREATE.PHOTO_COMMENT;
  91. static final String PLACE = GM.DB.QUERY.DROP.PLACE + GM.DB.QUERY.CREATE.PLACE;
  92. static final String POST = GM.DB.QUERY.DROP.POST + GM.DB.QUERY.CREATE.POST;
  93. static final String POST_COMMENT = GM.DB.QUERY.DROP.POST_COMMENT + GM.DB.QUERY.CREATE.POST_COMMENT;
  94. static final String POST_IMAGE = GM.DB.QUERY.DROP.POST_IMAGE + GM.DB.QUERY.CREATE.POST_IMAGE;
  95. static final String POST_TAG = GM.DB.QUERY.DROP.POST_TAG + GM.DB.QUERY.CREATE.POST_TAG;
  96. static final String SETTINGS = GM.DB.QUERY.DROP.SETTINGS + GM.DB.QUERY.CREATE.SETTINGS;
  97. static final String SPONSOR = GM.DB.QUERY.DROP.SPONSOR + GM.DB.QUERY.CREATE.SPONSOR;
  98. static final String VERSION = GM.DB.QUERY.DROP.VERSION + GM.DB.QUERY.CREATE.VERSION;
  99. }
  100. }
  101. }
  102. static final String CLIENT = "com.ivalentin.margolariak";
  103. /**
  104. * Address where the web server is
  105. */
  106. static final String SERVER = "http://margolariak.com";
  107. static final String SERVER_SYNC = "/API/v1/sync.php";
  108. static final String SERVER_SYNC_KEY_CLIENT = "client";
  109. static final String SERVER_SYNC_KEY_USER = "user";
  110. static final String SERVER_SYNC_KEY_ACTION = "action";
  111. static final String SERVER_SYNC_KEY_SECTION = "section";
  112. static final String SERVER_SYNC_KEY_VERSION = "version";
  113. static final String SERVER_SYNC_KEY_FOREGROUND = "foreground";
  114. static final String SERVER_SYNC_KEY_FORMAT = "format";
  115. static final String SERVER_SYNC_KEY_LANG = "lang";
  116. static final String SERVER_SYNC_VALUE_ACTION = "sync";
  117. static final String SERVER_SYNC_VALUE_SECTION = "all";
  118. static final String SERVER_SYNC_VALUE_FORMAT = "json";
  119. /**
  120. * Code for the location permission request
  121. */
  122. static final int PERMISSION_LOCATION = 1;
  123. /**
  124. * Period of time (in seconds) at the end of witch the app will perform a sync.
  125. */
  126. static final int PERIOD_SYNC = 20 * 60 * 1000;
  127. /**
  128. * Name of the preference to store the user code with.
  129. */
  130. static final String USER_CODE = "prefcode";
  131. /**
  132. * Constant to diferentiate schedules".
  133. */
  134. static final String SCHEDULE = "schedule";
  135. /**
  136. * Constant to set extras on the main intent.
  137. */
  138. static final String EXTRA_TITLE = "title";
  139. /**
  140. * Constant to set extras on the main intent.
  141. */
  142. static final String EXTRA_TEXT = "text";
  143. /**
  144. * Constant to set extras on the main intent.
  145. */
  146. static final String EXTRA_ACTION = "action";
  147. /**
  148. * Value for {@see GM.EXTRA_ACTION} that opens the lablanca section.
  149. */
  150. static final String EXTRA_ACTION_LABLANCA = "lablanca";
  151. /**
  152. * Value for {@see GM.EXTRA_ACTION} that opens the official schedule.
  153. */
  154. static final String EXTRA_ACTION_CITYSCHEDULE = "cityschedule";
  155. /**
  156. * Value for {@see GM.EXTRA_ACTION} that opens the GM schedule.
  157. */
  158. static final String EXTRA_ACTION_GMSCHEDULE = "gmschedule";
  159. /**
  160. * Value for {@see GM.EXTRA_ACTION} that opens the location secton.
  161. */
  162. static final String EXTRA_ACTION_LOCATION = "location";
  163. /**
  164. * Value for {@see GM.EXTRA_ACTION} that opens the blog.
  165. */
  166. static final String EXTRA_ACTION_BLOG = "blog";
  167. /**
  168. * Value for {@see GM.EXTRA_ACTION} that opens the activities section.
  169. */
  170. static final String EXTRA_ACTION_ACTIVITIES = "activities";
  171. /**
  172. * Value for {@see GM.EXTRA_ACTION} that opens the gallery section.
  173. */
  174. static final String EXTRA_ACTION_GALLERY = "gallery";
  175. /**
  176. * Constant for section "Home".
  177. */
  178. static final byte SECTION_HOME = 0;
  179. /**
  180. * Constant for La Blanca section "Location".
  181. */
  182. static final byte SECTION_LOCATION = 1;
  183. /**
  184. * Constant for section "La Blanca".
  185. */
  186. static final byte SECTION_LABLANCA = 2;
  187. /**
  188. * Constant for La Blanca section "Festival schedule".
  189. */
  190. static final byte SECTION_LABLANCA_SCHEDULE = 20;
  191. /**
  192. * Constant for La Blanca section "Gasteizko Margolariak Schedule".
  193. */
  194. static final byte SECTION_LABLANCA_GM_SCHEDULE = 21;
  195. /**
  196. * Constant for section "Activities".
  197. */
  198. static final byte SECTION_ACTIVITIES = 3;
  199. /**
  200. * Constant for section "Blog".
  201. */
  202. static final byte SECTION_BLOG = 4;
  203. /**
  204. * Constant for section "Gallery".
  205. */
  206. static final byte SECTION_GALLERY = 5;
  207. /**
  208. * Name of the preference group for the app.
  209. */
  210. static final String PREF = "gmpreferences";
  211. /**
  212. * Name of the preference to store the database version with.
  213. */
  214. static final String PREF_DB_VERSION = "prefDbVersion";
  215. /**
  216. * Name of the preference to store the setting that allows user to upload comments.
  217. */
  218. static final String PREF_DB_PHOTOS = "prefDbPhotos";
  219. /**
  220. * Name of the preference that indicates if we are on festivals.
  221. */
  222. static final String PREF_DB_FESTIVALS = "prefDbFestivals";
  223. /**
  224. * Name of the preference indicating if the user wants to to receive notifications intended for the general public.
  225. */
  226. static final String PREF_NOTIFICATION = "prefNotification";
  227. /**
  228. * Default value of the preference indicating if the user wants to to receive notifications intended for the general public.
  229. */
  230. static final int DEFAULT_PREF_NOTIFICATION = 1;
  231. /**
  232. * Header of a preference to indicate received notifications.
  233. */
  234. static final String NOTIFICATION_SEEN_ ="notificationSeen";
  235. /**
  236. * Default value for the {//@link GM.PREF_DB_VERSION} preference
  237. */
  238. static final int DEFAULT_PREF_DB_VERSION = -2;
  239. /**
  240. * Name of the preference to store GM location's latitude.
  241. */
  242. static final String PREF_GM_LATITUDE = "gmlat";
  243. /**
  244. * Name of the preference to store GM location's longitude.
  245. */
  246. static final String PREF_GM_LONGITUDE = "gmlon";
  247. /**
  248. * Name of the preference to store GM last location timestamp.
  249. */
  250. static final String PREF_GM_LOCATION = "gmlocationtime";
  251. /**
  252. * Name of the preference to store GM last location timestamp.
  253. */
  254. static final String DEFAULT_PREF_GM_LOCATION = "19700101000000";
  255. /**
  256. * Name of the preference indicating if the user wants to perform background syncs.
  257. */
  258. static final String PREFERENCE_SYNC_SYNC = "pref_sync_sync";
  259. /**
  260. * Default value for PREFERENCE_SYNC_SYNC.
  261. */
  262. static final boolean DEFAULT_PREFERENCE_SYNC_SYNC = true;
  263. /**
  264. * Name of the preference indicating if the user wants to to receive notifications intended for the general public.
  265. */
  266. static final String PREFERENCE_SYNC_NOTIFICATIONS = "pref_sync_notifications";
  267. /**
  268. * Default value for PREFERENCE_SYNC_NOTIFICATIONS.
  269. */
  270. static final boolean DEFAULT_PREFERENCE_SYNC_NOTIFICATIONS = true;
  271. /**
  272. * Name of the SharedPreference that stores how many kb have been sent in the foreground.
  273. */
  274. static final String STORAGE_TRAFFIC_FG_SENT = "storage_traffic_fg_sent";
  275. /**
  276. * Name of the SharedPreference that stores how many kb have been received in the foreground.
  277. */
  278. static final String STORAGE_TRAFFIC_FG_RECEIVED = "storage_traffic_fg_received";
  279. /**
  280. * Name of the SharedPreference that stores how many kb have been sent in the background.
  281. */
  282. static final String STORAGE_TRAFFIC_BG_SENT = "storage_traffic_bg_received";
  283. /**
  284. * Name of the SharedPreference that stores how many kb have been received in the background.
  285. */
  286. static final String STORAGE_TRAFFIC_BG_RECEIVED = "storage_traffic_bg_received";
  287. static final String KEY_PREFERENCE_SYNC = "preference_key_sync";
  288. static final String KEY_PREFERENCE_NOTIFICATION = "preference_key_notification";
  289. static final String KEY_PREFERENCE_DATA = "preference_key_data";
  290. static final String KEY_PREFERENCE_VERSION = "preference_key_version";
  291. static final String KEY_PREFERENCE_SOURCE = "preference_key_source";
  292. static final String KEY_PREFERENCE_FEEDBACK = "preference_key_feedback";
  293. static final int INTERVAL_LOCATION = 240000; //4 min
  294. static final int INTERVAL_SYNC_FESTIVALS = 600000; //10 min
  295. static final int INTERVAL_SYNC_NO_FESTIVALS = 3600000; //60 min
  296. /**
  297. * Name of the database
  298. */
  299. static final String DB_NAME = "gm";
  300. /**
  301. * The desired accuracy of the GPS coordinates, used to provide location updates, in meters.
  302. */
  303. static final int LOCATION_ACCURACY_SPACE = 10;
  304. /**
  305. * The desired accuracy of the GPS coordinates, used to provide location updates, in milliseconds.
  306. */
  307. static final int LOCATION_ACCURACY_TIME = 10000;
  308. /**
  309. * Dimensions of the images in the database.
  310. */
  311. static final int IMG_MINIATURE = 340;
  312. static final int IMG_PREVIEW = 600;
  313. static final int IMG_THUMB = 180;
  314. static final int IMG_VIEW = 800;
  315. /**
  316. * Gets the language code for sql queries.
  317. * Only three values can be returned: es, eu, en.
  318. * Defaults to es.
  319. *
  320. * @return Language two-letter code
  321. */
  322. public static String getLang(){
  323. String currLang = Locale.getDefault().getISO3Language();//getDisplayLanguage();
  324. switch (currLang){
  325. case "eng":
  326. currLang = "en";
  327. break;
  328. case "eus":
  329. currLang = "eu";
  330. break;
  331. default:
  332. currLang = "es";
  333. }
  334. return currLang;
  335. }
  336. /**
  337. * Formats a datetime format strings and returns a human readable date, depending on the language
  338. *
  339. * @param dateString String in a datetime format
  340. * @param lang Language (es, en, eu)
  341. * @param includeTime Also returns the hour and minutes
  342. *
  343. * @return The fragment view
  344. *
  345. * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
  346. */
  347. public static String formatDate(String dateString, String lang, boolean includeTime){
  348. String output = "";
  349. String dayNameEs[] = {"dummy", "Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"};
  350. String dayNameEn[] = {"dummy", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  351. String dayNameEu[] = {"dummy", "igandea", "astelehena", "asteartea", "asteazkena", "osteguna", "ostirala", "larumbata"};
  352. String monthNameEs[] = {"enero", " febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"};
  353. String monthNameEn[] = {"January", "February", "March", "April", "May", "June", "July", "Augost", "September", "Octuber", "November", "December"};
  354. String monthNameEu[] = {"urtarrilaren", "otsailaren", "martxoaren", "apirilaren", "maiatzaren", "ekainaren", "uztailaren", "abuztuaren", "irailaren", "urriaren", "azaroaren", "abenduaren"};
  355. if (!lang.equals("es") && !lang.equals("eu")){
  356. lang = "en";
  357. }
  358. DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH);
  359. SimpleDateFormat df;
  360. Date date;
  361. try{
  362. date = format.parse(dateString);
  363. df = new SimpleDateFormat("yyyy", Locale.US);
  364. String year = df.format(date);
  365. df = new SimpleDateFormat("hh:mm", Locale.US);
  366. String time = df.format(date);
  367. String dayName, monthName;
  368. Calendar calendar = Calendar.getInstance();
  369. calendar.setTime(date);
  370. int dayNumber = calendar.get(Calendar.DAY_OF_WEEK);
  371. int day = calendar.get(Calendar.DAY_OF_MONTH);
  372. int monthNumber = calendar.get(Calendar.MONTH);
  373. switch (lang){
  374. case "es":
  375. dayName = dayNameEs[dayNumber];
  376. monthName = monthNameEs[monthNumber];
  377. output = dayName + ", " + day + " de " + monthName + " de " + year;
  378. if (includeTime){
  379. output = output + " a las " + time;
  380. }
  381. break;
  382. case "eu":
  383. dayName = dayNameEu[dayNumber];
  384. monthName = monthNameEu[monthNumber];
  385. output = year + "ko" + monthName + " " + day + "an, " + dayName;
  386. if (includeTime){
  387. output = output + " " + time + "etan";
  388. }
  389. break;
  390. default:
  391. dayName = dayNameEn[dayNumber];
  392. monthName = monthNameEn[monthNumber];
  393. output = dayName + ", " + monthName + " " + day + ", " + year;
  394. if (includeTime){
  395. output = output + " " + time;
  396. }
  397. break;
  398. }
  399. }
  400. catch(Exception ex){
  401. Log.e("Date format error", ex.toString());
  402. }
  403. return output;
  404. }
  405. public static Bitmap decodeSampledBitmapFromFile(String path, int size) { // BEST QUALITY MATCH
  406. // First decode with inJustDecodeBounds=true to check dimensions
  407. final BitmapFactory.Options options = new BitmapFactory.Options();
  408. options.inJustDecodeBounds = true;
  409. BitmapFactory.decodeFile(path, options);
  410. // Calculate inSampleSize
  411. // Raw height and width of image
  412. final int height = options.outHeight;
  413. final int width = options.outWidth;
  414. options.inPreferredConfig = Bitmap.Config.RGB_565;
  415. int inSampleSize = 1;
  416. if (height > size) {
  417. inSampleSize = Math.round((float)height / (float)size);
  418. }
  419. int expectedWidth = width / inSampleSize;
  420. if (expectedWidth > size) {
  421. //if(Math.round((float)width / (float)reqWidth) > inSampleSize) // If bigger SampSize..
  422. inSampleSize = Math.round((float)width / (float)size);
  423. }
  424. options.inSampleSize = inSampleSize;
  425. // Decode bitmap with inSampleSize set
  426. options.inJustDecodeBounds = false;
  427. return BitmapFactory.decodeFile(path, options);
  428. }
  429. }