Skip to content

Commit 3b59d51

Browse files
Helli KandraHelli Kandra
authored andcommitted
version code 2022 06 11 - update to version 1.2
1 parent 117dfaf commit 3b59d51

File tree

3 files changed

+127
-59
lines changed

3 files changed

+127
-59
lines changed

app/src/main/java/com/atakmap/android/weather/WeatherDropDownReceiver.java

Lines changed: 69 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import android.os.AsyncTask;
88
import android.view.View;
99
import android.widget.ImageButton;
10+
import android.widget.SeekBar;
1011
import android.widget.TextView;
12+
import android.widget.Toast;
1113

1214
import com.atakmap.coremap.maps.coords.GeoPoint;
1315

@@ -29,6 +31,7 @@
2931
import java.net.HttpURLConnection;
3032
import java.net.MalformedURLException;
3133
import java.net.URL;
34+
import java.util.Objects;
3235

3336
import 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
}

app/src/main/res/layout/main_layout.xml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,47 @@
3030
android:id="@+id/textView1"
3131
android:layout_width="match_parent"
3232
android:layout_height="wrap_content"
33-
android:text="Forecast:"
33+
android:text="@string/forecast1"
3434
android:textSize="26dp"
3535
/>
3636

3737
<TextView
3838
android:id="@+id/textView2"
3939
android:layout_width="match_parent"
4040
android:layout_height="wrap_content"
41-
android:text="City/Town"
41+
android:text="@string/city_town"
4242
android:textSize="18dp"
4343
/>
4444

4545
<TextView
4646
android:id="@+id/textView3"
4747
android:layout_width="match_parent"
4848
android:layout_height="wrap_content"
49-
android:text="Weather"
49+
android:text="@string/weather"
5050
android:textSize="36dp"
5151
/>
5252

5353
<TextView
5454
android:id="@+id/textView4"
5555
android:layout_width="match_parent"
5656
android:layout_height="wrap_content"
57-
android:text="Temp"
58-
android:textSize="56dp"
57+
android:text="@string/temperature_min_max"
58+
android:textSize="25dp"
59+
/>
60+
<TextView
61+
android:id="@+id/textView5"
62+
android:layout_width="match_parent"
63+
android:layout_height="wrap_content"
64+
android:text="@string/precipitation"
65+
android:textSize="25dp"
5966
/>
6067

68+
<SeekBar
69+
android:id="@+id/seekBar"
70+
android:layout_width="match_parent"
71+
android:layout_height="wrap_content"
72+
android:max="6"
73+
android:progress="0" />
6174

6275
</LinearLayout>
6376
</ScrollView>

app/src/main/res/values/strings.xml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,46 @@
44
<string name="app_name">Weather</string>
55
<!-- description -->
66
<string name="app_desc">This plugin gets weather data from open-meteo API and parses it for the user</string>
7-
8-
7+
<string name="set_gps">No GPS, set selfmarker</string>
8+
<string name="wait">Wait...</string>
9+
<string name="forecast">Forecast: </string>
10+
<string name="now">TODAY: </string>
11+
<string name="clear_sky">Clear Sky</string>
12+
<string name="precipit">Precipitation: </string>
13+
<string name="mm">mm in</string>
14+
<string name="hour">hours</string>
15+
<string name="nopre">No precipitation</string>
16+
<string name="thunder">Thunderstorm</string>
17+
<string name="driz1">Drizzle: Dense Intensity</string>
18+
<string name="frizdriz">Freezing Drizzle: Light</string>
19+
<string name="frizdriz1">Freezing Drizzle: Dense Intensity</string>
20+
<string name="rain1">Rain: Slight</string>
21+
<string name="rain2">Rain: Moderate</string>
22+
<string name="rain3">Rain: Heavy Intensity</string>
23+
<string name="driz2">Drizzle: Moderate</string>
24+
<string name="driz3">Drizzle: Light</string>
25+
<string name="fog1">Fog</string>
26+
<string name="fog2">Depositing Rime Fog</string>
27+
<string name="overcast">Overcast</string>
28+
<string name="part">Partly Cloudy</string>
29+
<string name="mainly">Mainly Clear</string>
30+
<string name="freez1">Freezing Rain: Light</string>
31+
<string name="frez2">Freezing Rain: Heavy Intensity</string>
32+
<string name="snow1">Snow Fall: Slight</string>
33+
<string name="snow2">Snow Fall: Moderate</string>
34+
<string name="snow3">Snow Fall: Heavy Intensity</string>
35+
<string name="show5">Snow showers: Heavy</string>
36+
<string name="snow4">Snow showers: Slight</string>
37+
<string name="rain5">Rain Showers: Violent</string>
38+
<string name="rain4">Rain Showers: Moderate</string>
39+
<string name="rain6">Rain Showers: Slight</string>
40+
<string name="grain">Snow Grains</string>
41+
<string name="precipitation">Precipitation</string>
42+
<string name="temperature_min_max">Temperature min/max</string>
43+
<string name="weather">Weather</string>
44+
<string name="city_town">City/Town</string>
45+
<string name="forecast1">Forecast:</string>
46+
<string name="data1">\"Date: \"</string>
947

1048

1149
</resources>

0 commit comments

Comments
 (0)