PageRenderTime 579ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/gulajava/ramalancuaca/modellogika/Parsers.java

https://gitlab.com/achmadalam.xirpl6/RamalanCuacaBukaan
Java | 129 lines | 82 code | 39 blank | 8 comment | 10 complexity | 34c735d161894ab5b9478f76fa1d5c44 MD5 | raw file
  1. package gulajava.ramalancuaca.modellogika;
  2. import android.content.Context;
  3. import android.location.Address;
  4. import android.location.Geocoder;
  5. import com.alibaba.fastjson.JSON;
  6. import java.util.List;
  7. import java.util.Locale;
  8. import gulajava.ramalancuaca.internets.modelnet.cuacaperhari.CuacaPerHari;
  9. import gulajava.ramalancuaca.internets.modelnet.cuacaperjam.CuacaPerJams;
  10. import gulajava.ramalancuaca.models.MsgHasilGeocoder;
  11. /**
  12. * Created by Gulajava Ministudio.
  13. */
  14. public class Parsers {
  15. private Context mContext;
  16. //GEOCODER AMBIL LOKASI DAN POSISI PENGGUNA ALAMATNYA JIKA ADA
  17. private Geocoder geocoderPengguna;
  18. private List<Address> addressListPengguna = null;
  19. private String gecoder_alamat = "";
  20. private String gecoder_namakota = "";
  21. private String alamatgabungan = "";
  22. public Parsers(Context context) {
  23. mContext = context;
  24. }
  25. //AMBIL GEOCODER LOKASI
  26. public MsgHasilGeocoder ambilGeocoderPengguna(String latitude, String longitude) {
  27. geocoderPengguna = new Geocoder(mContext, Locale.ENGLISH);
  28. double dolatitu = 0;
  29. double dolongi = 0;
  30. try {
  31. dolatitu = Double.valueOf(latitude);
  32. dolongi = Double.valueOf(longitude);
  33. } catch (Exception ex) {
  34. ex.printStackTrace();
  35. }
  36. try {
  37. addressListPengguna = geocoderPengguna.getFromLocation(dolatitu, dolongi, 1);
  38. if (addressListPengguna.size() > 0) {
  39. int panjangalamat = addressListPengguna.get(0).getMaxAddressLineIndex();
  40. if (panjangalamat > 0) {
  41. gecoder_alamat = addressListPengguna.get(0).getAddressLine(0);
  42. gecoder_namakota = addressListPengguna.get(0).getLocality();
  43. } else {
  44. gecoder_alamat = "";
  45. gecoder_namakota = "";
  46. alamatgabungan = "";
  47. }
  48. }
  49. } catch (Exception e) {
  50. e.printStackTrace();
  51. gecoder_alamat = "";
  52. gecoder_namakota = "";
  53. alamatgabungan = "";
  54. }
  55. if (gecoder_namakota != null && gecoder_namakota.length() > 0) {
  56. alamatgabungan = gecoder_namakota;
  57. if (gecoder_alamat != null && gecoder_alamat.length() > 0) {
  58. alamatgabungan = gecoder_alamat + ", " + gecoder_namakota;
  59. }
  60. } else {
  61. alamatgabungan = "";
  62. gecoder_namakota = "";
  63. }
  64. // Log.w("ALAMAT GABUNGAN", "ALAMAT " + alamatgabungan + " gecoder kota " + gecoder_namakota);
  65. MsgHasilGeocoder msgHasilGeocoder = new MsgHasilGeocoder();
  66. msgHasilGeocoder.setAlamatgabungan(alamatgabungan);
  67. msgHasilGeocoder.setAlamatPendek(gecoder_namakota);
  68. return msgHasilGeocoder;
  69. }
  70. //DESERIALISASI JSON DATA RAMALAN CUACA PER HARI
  71. public CuacaPerHari parseJSONCuacaHarian(String stringJson) {
  72. CuacaPerHari cuacaPerHari = null;
  73. try {
  74. cuacaPerHari = JSON.parseObject(stringJson, CuacaPerHari.class);
  75. } catch (Exception e) {
  76. e.printStackTrace();
  77. }
  78. return cuacaPerHari;
  79. }
  80. //DESERIALISASI JSON DATA RAMALAN CUACA PER JAM
  81. public CuacaPerJams parseJSONCuacaPerJAM(String stringJSON) {
  82. CuacaPerJams cuacaPerJams = null;
  83. try {
  84. cuacaPerJams = JSON.parseObject(stringJSON, CuacaPerJams.class);
  85. } catch (Exception e) {
  86. e.printStackTrace();
  87. }
  88. return cuacaPerJams;
  89. }
  90. }