77import android .os .AsyncTask ;
88import android .view .View ;
99import android .widget .ImageButton ;
10+ import android .widget .SeekBar ;
1011import android .widget .TextView ;
12+ import android .widget .Toast ;
1113
1214import com .atakmap .coremap .maps .coords .GeoPoint ;
1315
2931import java .net .HttpURLConnection ;
3032import java .net .MalformedURLException ;
3133import java .net .URL ;
34+ import java .util .Objects ;
3235
3336import javax .net .ssl .HttpsURLConnection ;
3437
@@ -48,6 +51,7 @@ public class WeatherDropDownReceiver extends DropDownReceiver implements
4851 public TextView textView3 ;
4952 public TextView textView4 ;
5053 public TextView textView5 ;
54+ public SeekBar seekBar ;
5155
5256
5357
@@ -74,7 +78,7 @@ public void disposeImpl() {
7478 /**************************** INHERITED METHODS *****************************/
7579
7680 @ Override
77- public void onReceive (Context context , Intent intent ) {
81+ public void onReceive (final Context context , Intent intent ) {
7882
7983 final String action = intent .getAction ();
8084 if (action == null )
@@ -89,32 +93,47 @@ public void onReceive(Context context, Intent intent) {
8993 textView2 = templateView .findViewById (R .id .textView2 );
9094 textView3 = templateView .findViewById (R .id .textView3 );
9195 textView4 = templateView .findViewById (R .id .textView4 );
92- // textView5 = templateView.findViewById(R.id.textView5);
96+ textView5 = templateView .findViewById (R .id .textView5 );
9397 imageButton = templateView .findViewById (R .id .imageButton );
98+ seekBar = templateView .findViewById (R .id .seekBar );
99+
94100
95- imageButton .setOnClickListener (new View .OnClickListener () {
96- @ Override
97- public void onClick (View view ) {
98101 Double lat = getMapView ().getSelfMarker ().getPoint ().getLatitude ();
99102 Double longt = getMapView ().getSelfMarker ().getPoint ().getLongitude ();
100103 Float latf = lat .floatValue ();
101104 Float longtf = longt .floatValue ();
102105 String slat = latf .toString ();
103106 String slongt = longtf .toString ();
104107
108+ imageButton .setOnClickListener (new View .OnClickListener () {
109+ @ Override
110+ public void onClick (View view ) {
111+ Double lat1 = getMapView ().getCenterPoint ().get ().getLatitude ();
112+ Double longt1 = getMapView ().getCenterPoint ().get ().getLongitude ();
113+ Float latf1 = lat1 .floatValue ();
114+ Float longtf1 = longt1 .floatValue ();
115+ String slat = latf1 .toString ();
116+ String slongt = longtf1 .toString ();
117+ String url1 = "https://api.open-meteo.com/v1/forecast?latitude=" + slat + "&longitude=" + slongt + "&daily=weathercode,temperature_2m_max,temperature_2m_min,precipitation_sum,precipitation_hours,windspeed_10m_max,windgusts_10m_max,winddirection_10m_dominant&windspeed_unit=ms&timezone=auto" ;
118+ new GetURLData ().execute (url1 );
119+ }
120+ });
121+
105122 String url = "https://api.open-meteo.com/v1/forecast?latitude=" + slat + "&longitude=" + slongt + "&daily=weathercode,temperature_2m_max,temperature_2m_min,precipitation_sum,precipitation_hours,windspeed_10m_max,windgusts_10m_max,winddirection_10m_dominant&windspeed_unit=ms&timezone=auto" ;
106123
124+ if (slat .isEmpty ()) {
125+ Toast .makeText (context , R .string .set_gps , Toast .LENGTH_SHORT ).show ();
126+ return ;}
107127 new GetURLData ().execute (url );
108128 // textView1.setText(url);
109- }
110- });
129+
111130 }
112131 }
113132 private class GetURLData extends AsyncTask <String , String , String > {
114133
115134 protected void onPreExecute () {
116135 super .onPreExecute ();
117- textView1 .setText ("Wait..." );
136+ textView1 .setText (R . string . wait );
118137 }
119138
120139 @ SuppressLint ("SuspiciousIndentation" )
@@ -153,8 +172,6 @@ protected String doInBackground(String... strings) {
153172 } catch (IOException e ) {
154173 e .printStackTrace ();
155174 }
156-
157-
158175 }
159176 return null ;
160177 }
@@ -170,64 +187,71 @@ protected void onPostExecute(String result) {
170187 String code = jsonObject .getJSONObject ("daily" ).getJSONArray ("weathercode" ).getString (0 );
171188 String tempmax = jsonObject .getJSONObject ("daily" ).getJSONArray ("temperature_2m_max" ).getString (0 );
172189 String tempmin = jsonObject .getJSONObject ("daily" ).getJSONArray ("temperature_2m_min" ).getString (0 );
173- // String precipits = jsonObject.getJSONObject("daily").getJSONArray("precipitation_sum").getString(0);
174- // String precipith = jsonObject.getJSONObject("daily").getJSONArray("precipitation_hours").getString(0);
190+ String precipits = jsonObject .getJSONObject ("daily" ).getJSONArray ("precipitation_sum" ).getString (0 );
191+ String precipith = jsonObject .getJSONObject ("daily" ).getJSONArray ("precipitation_hours" ).getString (0 );
175192
176- textView1 .setText ("Forecast: " + time .toString ());
193+ textView1 .setText (pluginContext . getString ( R . string . now ) + time .toString ());
177194 //textView2.setText(code.toString());
178- if (code == String .valueOf (0 )) textView3 .setText ("Clear Sky" . toString () );
195+ if (code == String .valueOf (0 )) textView3 .setText (R . string . clear_sky );
179196
180- if (code == String .valueOf (1 )) textView3 .setText ("Mainly Clear" . toString () );
181- if (code == String .valueOf (2 )) textView3 .setText ("Partly Cloudy" . toString () );
182- if (code == String .valueOf (3 )) textView3 .setText ("Overcast" . toString () );
197+ if (code == String .valueOf (1 )) textView3 .setText (R . string . mainly );
198+ if (code == String .valueOf (2 )) textView3 .setText (R . string . part );
199+ if (code == String .valueOf (3 )) textView3 .setText (R . string . overcast );
183200
184- if (code == String .valueOf (45 )) textView3 .setText ("Fog" . toString () );
185- if (code == String .valueOf (48 )) textView3 .setText ("Depositing Rime Fog" . toString () );
201+ if (code == String .valueOf (45 )) textView3 .setText (R . string . fog1 );
202+ if (code == String .valueOf (48 )) textView3 .setText (R . string . fog2 );
186203
187- if (code == String .valueOf (51 )) textView3 .setText ("Drizzle: Light" . toString () );
188- if (code == String .valueOf (53 )) textView3 .setText ("Drizzle: Moderate" . toString () );
204+ if (code == String .valueOf (51 )) textView3 .setText (R . string . driz3 );
205+ if (code == String .valueOf (53 )) textView3 .setText (R . string . driz2 );
189206 if (code == String .valueOf (55 ))
190- textView3 .setText ("Drizzle: Dense Intensity" . toString () );
207+ textView3 .setText (R . string . driz1 );
191208
192209 if (code == String .valueOf (56 ))
193- textView3 .setText ("Freezing Drizzle: Light" . toString () );
210+ textView3 .setText (R . string . frizdriz );
194211 if (code == String .valueOf (57 ))
195- textView3 .setText ("Freezing Drizzle: Dense Intensity" . toString () );
212+ textView3 .setText (R . string . frizdriz1 );
196213
197- if (code == String .valueOf (61 )) textView3 .setText ("Rain: Slight" . toString () );
198- if (code == String .valueOf (63 )) textView3 .setText ("Rain: Moderate" . toString () );
214+ if (code == String .valueOf (61 )) textView3 .setText (R . string . rain1 );
215+ if (code == String .valueOf (63 )) textView3 .setText (R . string . rain2 );
199216 if (code == String .valueOf (65 ))
200- textView3 .setText ("Rain: Heavy Intensity" . toString () );
217+ textView3 .setText (R . string . rain3 );
201218
202219 if (code == String .valueOf (66 ))
203- textView3 .setText ("Freezing Rain: Light" . toString () );
220+ textView3 .setText (R . string . freez1 );
204221 if (code == String .valueOf (67 ))
205- textView3 .setText ("Freezing Rain: Heavy Intensity" . toString () );
222+ textView3 .setText (R . string . frez2 );
206223
207- if (code == String .valueOf (71 )) textView3 .setText ("Snow Fall: Slight" . toString () );
208- if (code == String .valueOf (73 )) textView3 .setText ("Snow Fall: Moderate" . toString () );
224+ if (code == String .valueOf (71 )) textView3 .setText (R . string . snow1 );
225+ if (code == String .valueOf (73 )) textView3 .setText (R . string . snow2 );
209226 if (code == String .valueOf (75 ))
210- textView3 .setText ("Snow Fall: Heavy Intensity" . toString () );
227+ textView3 .setText (R . string . snow3 );
211228
212- if (code == String .valueOf (77 )) textView3 .setText ("Snow Grains" . toString () );
229+ if (code == String .valueOf (77 )) textView3 .setText (R . string . grain );
213230
214231 if (code == String .valueOf (80 ))
215- textView3 .setText ("Rain Showers: Slight" . toString () );
232+ textView3 .setText (R . string . rain6 );
216233 if (code == String .valueOf (81 ))
217- textView3 .setText ("Rain Showers: Moderate" . toString () );
234+ textView3 .setText (R . string . rain4 );
218235 if (code == String .valueOf (82 ))
219- textView3 .setText ("Rain Showers: Violent" . toString () );
236+ textView3 .setText (R . string . rain5 );
220237
221238 if (code == String .valueOf (85 ))
222- textView3 .setText ("Snow showers: Slight" . toString () );
223- if (code == String .valueOf (86 )) textView3 .setText ("Snow showers: Heavy" . toString () );
239+ textView3 .setText (R . string . snow4 );
240+ if (code == String .valueOf (86 )) textView3 .setText (R . string . show5 );
224241
225- if (code == String .valueOf (95 )) textView3 .setText ("Thunderstorm" . toString () );
242+ if (code == String .valueOf (95 )) textView3 .setText (R . string . thunder );
226243
227244 textView4 .setText (tempmin .toString () + "C" + "/" + tempmax .toString () + "C" );
228245
229- // if (precipits == String.valueOf(0)) textView5.setText("No precipitation");
230- //else textView5.setText("Precipitation: " + precipits.toString() + precipith.toString());
246+ //if (precipits == String.valueOf(0)) {
247+ // textView5.setText("No precipitation");}
248+
249+
250+ if (Objects .equals (precipits , "0.0" )) {
251+ textView5 .setText (R .string .nopre );
252+ } else {
253+ textView5 .setText (pluginContext .getString (R .string .precipit ) + precipits .toString () + pluginContext .getString (R .string .mm ) + precipith .toString () + pluginContext .getString (R .string .hour ));
254+ }
231255
232256
233257 String url1 = "https://nominatim.openstreetmap.org/reverse?format=json&lat=" + latitude + "&lon=" + longitude + "&zoom=14&addressdetails=1" ;
@@ -236,10 +260,9 @@ protected void onPostExecute(String result) {
236260 } catch (JSONException e ) {
237261 e .printStackTrace ();
238262 }
239-
240-
241263 }
242264
265+
243266 private class GetGeocodeData extends AsyncTask <String , String , String > {
244267
245268 @ SuppressLint ("SuspiciousIndentation" )
@@ -278,8 +301,6 @@ protected String doInBackground(String... strings) {
278301 } catch (IOException e ) {
279302 e .printStackTrace ();
280303 }
281-
282-
283304 }
284305 return null ;
285306 }
@@ -295,21 +316,17 @@ protected void onPostExecute(String result1) {
295316 //String city = jsonObject1.getString("city");
296317 //String state_district = jsonObject1.getString("state_district");
297318 //String state = jsonObject1.getString("state");
298- // textView2.setText(suburb + "," + village + "," + town + "," + city + "," + state_district + "," + state);
319+ // textView2.setText(suburb + "," + village + "," + town + "," + city + "," + state_district + "," + state);
299320 String display_name = jsonObject1 .getString ("display_name" );
300321 textView2 .setText (display_name );
301- } catch (JSONException e ) {
302- e .printStackTrace ();
322+ } catch (JSONException e ) {
323+ e .printStackTrace ();
303324 }
304325 }
305326
306327 }
307328 }
308329
309-
310-
311-
312-
313330 @ Override
314331 public void onDropDownSelectionRemoved () {
315332 }
0 commit comments