Skip to content

Commit

Permalink
version code 2022 06 11 - update to version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Helli Kandra authored and Helli Kandra committed Nov 6, 2022
1 parent 117dfaf commit 3b59d51
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import android.os.AsyncTask;
import android.view.View;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

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

Expand All @@ -29,6 +31,7 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;

import javax.net.ssl.HttpsURLConnection;

Expand All @@ -48,6 +51,7 @@ public class WeatherDropDownReceiver extends DropDownReceiver implements
public TextView textView3;
public TextView textView4;
public TextView textView5;
public SeekBar seekBar;



Expand All @@ -74,7 +78,7 @@ public void disposeImpl() {
/**************************** INHERITED METHODS *****************************/

@Override
public void onReceive(Context context, Intent intent) {
public void onReceive(final Context context, Intent intent) {

final String action = intent.getAction();
if (action == null)
Expand All @@ -89,32 +93,47 @@ public void onReceive(Context context, Intent intent) {
textView2 = templateView.findViewById(R.id.textView2);
textView3 = templateView.findViewById(R.id.textView3);
textView4 = templateView.findViewById(R.id.textView4);
//textView5 = templateView.findViewById(R.id.textView5);
textView5 = templateView.findViewById(R.id.textView5);
imageButton = templateView.findViewById(R.id.imageButton);
seekBar = templateView.findViewById(R.id.seekBar);


imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Double lat = getMapView().getSelfMarker().getPoint().getLatitude();
Double longt = getMapView().getSelfMarker().getPoint().getLongitude();
Float latf = lat.floatValue();
Float longtf = longt.floatValue();
String slat = latf.toString();
String slongt = longtf.toString();

imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Double lat1 = getMapView().getCenterPoint().get().getLatitude();
Double longt1 = getMapView().getCenterPoint().get().getLongitude();
Float latf1 = lat1.floatValue();
Float longtf1 = longt1.floatValue();
String slat = latf1.toString();
String slongt = longtf1.toString();
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";
new GetURLData().execute(url1);
}
});

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";

if (slat.isEmpty()) {
Toast.makeText(context, R.string.set_gps, Toast.LENGTH_SHORT).show();
return;}
new GetURLData().execute(url);
// textView1.setText(url);
}
});

}
}
private class GetURLData extends AsyncTask <String, String, String> {

protected void onPreExecute() {
super.onPreExecute();
textView1.setText("Wait...");
textView1.setText(R.string.wait);
}

@SuppressLint("SuspiciousIndentation")
Expand Down Expand Up @@ -153,8 +172,6 @@ protected String doInBackground(String... strings) {
} catch (IOException e) {
e.printStackTrace();
}


}
return null;
}
Expand All @@ -170,64 +187,71 @@ protected void onPostExecute(String result) {
String code = jsonObject.getJSONObject("daily").getJSONArray("weathercode").getString(0);
String tempmax = jsonObject.getJSONObject("daily").getJSONArray("temperature_2m_max").getString(0);
String tempmin = jsonObject.getJSONObject("daily").getJSONArray("temperature_2m_min").getString(0);
//String precipits = jsonObject.getJSONObject("daily").getJSONArray("precipitation_sum").getString(0);
//String precipith = jsonObject.getJSONObject("daily").getJSONArray("precipitation_hours").getString(0);
String precipits = jsonObject.getJSONObject("daily").getJSONArray("precipitation_sum").getString(0);
String precipith = jsonObject.getJSONObject("daily").getJSONArray("precipitation_hours").getString(0);

textView1.setText("Forecast: " + time.toString());
textView1.setText(pluginContext.getString(R.string.now) + time.toString());
//textView2.setText(code.toString());
if (code == String.valueOf(0)) textView3.setText("Clear Sky".toString());
if (code == String.valueOf(0)) textView3.setText(R.string.clear_sky);

if (code == String.valueOf(1)) textView3.setText("Mainly Clear".toString());
if (code == String.valueOf(2)) textView3.setText("Partly Cloudy".toString());
if (code == String.valueOf(3)) textView3.setText("Overcast".toString());
if (code == String.valueOf(1)) textView3.setText(R.string.mainly);
if (code == String.valueOf(2)) textView3.setText(R.string.part);
if (code == String.valueOf(3)) textView3.setText(R.string.overcast);

if (code == String.valueOf(45)) textView3.setText("Fog".toString());
if (code == String.valueOf(48)) textView3.setText("Depositing Rime Fog".toString());
if (code == String.valueOf(45)) textView3.setText(R.string.fog1);
if (code == String.valueOf(48)) textView3.setText(R.string.fog2);

if (code == String.valueOf(51)) textView3.setText("Drizzle: Light".toString());
if (code == String.valueOf(53)) textView3.setText("Drizzle: Moderate".toString());
if (code == String.valueOf(51)) textView3.setText(R.string.driz3);
if (code == String.valueOf(53)) textView3.setText(R.string.driz2);
if (code == String.valueOf(55))
textView3.setText("Drizzle: Dense Intensity".toString());
textView3.setText(R.string.driz1);

if (code == String.valueOf(56))
textView3.setText("Freezing Drizzle: Light".toString());
textView3.setText(R.string.frizdriz);
if (code == String.valueOf(57))
textView3.setText("Freezing Drizzle: Dense Intensity".toString());
textView3.setText(R.string.frizdriz1);

if (code == String.valueOf(61)) textView3.setText("Rain: Slight".toString());
if (code == String.valueOf(63)) textView3.setText("Rain: Moderate".toString());
if (code == String.valueOf(61)) textView3.setText(R.string.rain1);
if (code == String.valueOf(63)) textView3.setText(R.string.rain2);
if (code == String.valueOf(65))
textView3.setText("Rain: Heavy Intensity".toString());
textView3.setText(R.string.rain3);

if (code == String.valueOf(66))
textView3.setText("Freezing Rain: Light".toString());
textView3.setText(R.string.freez1);
if (code == String.valueOf(67))
textView3.setText("Freezing Rain: Heavy Intensity".toString());
textView3.setText(R.string.frez2);

if (code == String.valueOf(71)) textView3.setText("Snow Fall: Slight".toString());
if (code == String.valueOf(73)) textView3.setText("Snow Fall: Moderate".toString());
if (code == String.valueOf(71)) textView3.setText(R.string.snow1);
if (code == String.valueOf(73)) textView3.setText(R.string.snow2);
if (code == String.valueOf(75))
textView3.setText("Snow Fall: Heavy Intensity".toString());
textView3.setText(R.string.snow3);

if (code == String.valueOf(77)) textView3.setText("Snow Grains".toString());
if (code == String.valueOf(77)) textView3.setText(R.string.grain);

if (code == String.valueOf(80))
textView3.setText("Rain Showers: Slight".toString());
textView3.setText(R.string.rain6);
if (code == String.valueOf(81))
textView3.setText("Rain Showers: Moderate".toString());
textView3.setText(R.string.rain4);
if (code == String.valueOf(82))
textView3.setText("Rain Showers: Violent".toString());
textView3.setText(R.string.rain5);

if (code == String.valueOf(85))
textView3.setText("Snow showers: Slight".toString());
if (code == String.valueOf(86)) textView3.setText("Snow showers: Heavy".toString());
textView3.setText(R.string.snow4);
if (code == String.valueOf(86)) textView3.setText(R.string.show5);

if (code == String.valueOf(95)) textView3.setText("Thunderstorm".toString());
if (code == String.valueOf(95)) textView3.setText(R.string.thunder);

textView4.setText(tempmin.toString() + "C" + "/" + tempmax.toString() + "C");

// if (precipits == String.valueOf(0)) textView5.setText("No precipitation");
//else textView5.setText("Precipitation: " + precipits.toString() + precipith.toString());
//if (precipits == String.valueOf(0)) {
// textView5.setText("No precipitation");}


if (Objects.equals(precipits, "0.0")) {
textView5.setText(R.string.nopre);
} else {
textView5.setText(pluginContext.getString(R.string.precipit) + precipits.toString() + pluginContext.getString(R.string.mm) + precipith.toString() + pluginContext.getString(R.string.hour));
}


String url1 = "https://nominatim.openstreetmap.org/reverse?format=json&lat=" + latitude + "&lon=" + longitude + "&zoom=14&addressdetails=1";
Expand All @@ -236,10 +260,9 @@ protected void onPostExecute(String result) {
} catch (JSONException e) {
e.printStackTrace();
}


}


private class GetGeocodeData extends AsyncTask<String, String, String> {

@SuppressLint("SuspiciousIndentation")
Expand Down Expand Up @@ -278,8 +301,6 @@ protected String doInBackground(String... strings) {
} catch (IOException e) {
e.printStackTrace();
}


}
return null;
}
Expand All @@ -295,21 +316,17 @@ protected void onPostExecute(String result1) {
//String city = jsonObject1.getString("city");
//String state_district = jsonObject1.getString("state_district");
//String state = jsonObject1.getString("state");
// textView2.setText(suburb + "," + village + "," + town + "," + city + "," + state_district + "," + state);
// textView2.setText(suburb + "," + village + "," + town + "," + city + "," + state_district + "," + state);
String display_name = jsonObject1.getString("display_name");
textView2.setText(display_name);
} catch (JSONException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}

}
}





@Override
public void onDropDownSelectionRemoved() {
}
Expand Down
23 changes: 18 additions & 5 deletions app/src/main/res/layout/main_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,47 @@
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Forecast:"
android:text="@string/forecast1"
android:textSize="26dp"
/>

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="City/Town"
android:text="@string/city_town"
android:textSize="18dp"
/>

<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Weather"
android:text="@string/weather"
android:textSize="36dp"
/>

<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Temp"
android:textSize="56dp"
android:text="@string/temperature_min_max"
android:textSize="25dp"
/>
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/precipitation"
android:textSize="25dp"
/>

<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="6"
android:progress="0" />

</LinearLayout>
</ScrollView>
42 changes: 40 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,46 @@
<string name="app_name">Weather</string>
<!-- description -->
<string name="app_desc">This plugin gets weather data from open-meteo API and parses it for the user</string>


<string name="set_gps">No GPS, set selfmarker</string>
<string name="wait">Wait...</string>
<string name="forecast">Forecast: </string>
<string name="now">TODAY: </string>
<string name="clear_sky">Clear Sky</string>
<string name="precipit">Precipitation: </string>
<string name="mm">mm in</string>
<string name="hour">hours</string>
<string name="nopre">No precipitation</string>
<string name="thunder">Thunderstorm</string>
<string name="driz1">Drizzle: Dense Intensity</string>
<string name="frizdriz">Freezing Drizzle: Light</string>
<string name="frizdriz1">Freezing Drizzle: Dense Intensity</string>
<string name="rain1">Rain: Slight</string>
<string name="rain2">Rain: Moderate</string>
<string name="rain3">Rain: Heavy Intensity</string>
<string name="driz2">Drizzle: Moderate</string>
<string name="driz3">Drizzle: Light</string>
<string name="fog1">Fog</string>
<string name="fog2">Depositing Rime Fog</string>
<string name="overcast">Overcast</string>
<string name="part">Partly Cloudy</string>
<string name="mainly">Mainly Clear</string>
<string name="freez1">Freezing Rain: Light</string>
<string name="frez2">Freezing Rain: Heavy Intensity</string>
<string name="snow1">Snow Fall: Slight</string>
<string name="snow2">Snow Fall: Moderate</string>
<string name="snow3">Snow Fall: Heavy Intensity</string>
<string name="show5">Snow showers: Heavy</string>
<string name="snow4">Snow showers: Slight</string>
<string name="rain5">Rain Showers: Violent</string>
<string name="rain4">Rain Showers: Moderate</string>
<string name="rain6">Rain Showers: Slight</string>
<string name="grain">Snow Grains</string>
<string name="precipitation">Precipitation</string>
<string name="temperature_min_max">Temperature min/max</string>
<string name="weather">Weather</string>
<string name="city_town">City/Town</string>
<string name="forecast1">Forecast:</string>
<string name="data1">\"Date: \"</string>


</resources>

0 comments on commit 3b59d51

Please sign in to comment.