diff --git a/.gitignore b/.gitignore
index 8a30d25..fd8c042 100644
--- a/.gitignore
+++ b/.gitignore
@@ -396,3 +396,6 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
+
+# API
+Secrets.cs
diff --git a/android/XPrism/Hyperlink.cs b/android/XPrism/Hyperlink.cs
deleted file mode 100644
index e69de29..0000000
diff --git a/android/XPrism/XPrism/MainPage.xaml b/android/XPrism/XPrism/MainPage.xaml
index 7f4aac8..fff493f 100644
--- a/android/XPrism/XPrism/MainPage.xaml
+++ b/android/XPrism/XPrism/MainPage.xaml
@@ -6,10 +6,12 @@
-
-
-
+
+
+
+
+
-
+
diff --git a/android/XPrism/XPrism/MainPage.xaml.cs b/android/XPrism/XPrism/MainPage.xaml.cs
index f68de3e..26468bb 100644
--- a/android/XPrism/XPrism/MainPage.xaml.cs
+++ b/android/XPrism/XPrism/MainPage.xaml.cs
@@ -9,6 +9,12 @@ public MainPage()
Application.Current.UserAppTheme = AppTheme.Light;
}
+ public async void OnWeatherClicked(object sender, System.EventArgs e)
+ {
+ // 打开天气页面
+ await Navigation.PushAsync(new WeatherPage());
+ }
+
public async void OnSendClicked(object sender, System.EventArgs e)
{
// 打开发送页面
diff --git a/android/XPrism/XPrism/MauiProgram.cs b/android/XPrism/XPrism/MauiProgram.cs
index 00e48ea..884a15e 100644
--- a/android/XPrism/XPrism/MauiProgram.cs
+++ b/android/XPrism/XPrism/MauiProgram.cs
@@ -1,4 +1,6 @@
-namespace XPrism;
+using CommunityToolkit.Maui;
+
+namespace XPrism;
public static class MauiProgram
{
@@ -7,6 +9,7 @@ public static MauiApp CreateMauiApp()
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp()
+ .UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
});
diff --git a/android/XPrism/XPrism/Platforms/Android/MainApplication.cs b/android/XPrism/XPrism/Platforms/Android/MainApplication.cs
index ce4381f..bdc1526 100644
--- a/android/XPrism/XPrism/Platforms/Android/MainApplication.cs
+++ b/android/XPrism/XPrism/Platforms/Android/MainApplication.cs
@@ -3,7 +3,7 @@
namespace XPrism;
-[Application]
+[Application(UsesCleartextTraffic = true)]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
diff --git a/android/XPrism/XPrism/Resources/Images/material_weather_partly_cloudy.svg b/android/XPrism/XPrism/Resources/Images/material_weather_partly_cloudy.svg
new file mode 100644
index 0000000..03ba757
--- /dev/null
+++ b/android/XPrism/XPrism/Resources/Images/material_weather_partly_cloudy.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/android/XPrism/XPrism/Resources/Images/material_weather_partly_cloudy_white.svg b/android/XPrism/XPrism/Resources/Images/material_weather_partly_cloudy_white.svg
new file mode 100644
index 0000000..b6c2d69
--- /dev/null
+++ b/android/XPrism/XPrism/Resources/Images/material_weather_partly_cloudy_white.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/android/XPrism/XPrism/SendPage.xaml.cs b/android/XPrism/XPrism/SendPage.xaml.cs
index d37ac9b..6f2d16c 100644
--- a/android/XPrism/XPrism/SendPage.xaml.cs
+++ b/android/XPrism/XPrism/SendPage.xaml.cs
@@ -7,15 +7,15 @@ public SendPage()
InitializeComponent();
}
- void OnEditorTextChanged(object sender, TextChangedEventArgs e)
+ public void OnEditorTextChanged(object sender, TextChangedEventArgs e)
{
- string oldText = e.OldTextValue;
- string newText = e.NewTextValue;
- string myText = editor.Text;
+ //string oldText = e.OldTextValue;
+ //string newText = e.NewTextValue;
+ //string myText = editor.Text;
}
- void OnEditorCompleted(object sender, EventArgs e)
+ public void OnEditorCompleted(object sender, EventArgs e)
{
- string text = ((Editor)sender).Text;
+ //string text = ((Editor)sender).Text;
}
}
\ No newline at end of file
diff --git a/android/XPrism/XPrism/WeatherPage.xaml b/android/XPrism/XPrism/WeatherPage.xaml
new file mode 100644
index 0000000..f4bb4d6
--- /dev/null
+++ b/android/XPrism/XPrism/WeatherPage.xaml
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/XPrism/XPrism/WeatherPage.xaml.cs b/android/XPrism/XPrism/WeatherPage.xaml.cs
new file mode 100644
index 0000000..1df9e36
--- /dev/null
+++ b/android/XPrism/XPrism/WeatherPage.xaml.cs
@@ -0,0 +1,214 @@
+#define OPENWEATHERMAP // OPENWEATHERMAP or ACCUWEATHER
+
+using Android.App;
+using System.Text.Json;
+
+namespace XPrism;
+
+#if OPENWEATHERMAP
+public partial class WeatherPage : ContentPage
+{
+ public string url = "http://api.openweathermap.org/data/2.5/weather";
+ public string city = "";
+ public string apiKey = Secrets.OpenWeatherAPI; // Get your own API key from https://openweathermap.org/api
+ public string units = "metric";
+ public string lang = "zh_cn";
+ public string fullUrl = "";
+
+ public WeatherPage()
+ {
+ InitializeComponent();
+ cityLabel.Text = "N/A";
+ weatherLabel.Text = "N/A";
+ temperatureLabel.Text = "N/A";
+ windDirectionLabel.Text = "N/A";
+ windSpeedLabel.Text = "N/A";
+ humidityLabel.Text = "N/A";
+ reportTimeLabel.Text = "N/A";
+ sourceLabel.Text = "OpenWeatherMap";
+ }
+
+ public async void OnSearchClicked(object sender, System.EventArgs e)
+ {
+ city = cityEntry.Text;
+ if (city != "")
+ {
+ fullUrl = $"{url}?q={city}&appid={apiKey}&units={units}&lang={lang}";
+ HttpClient client = new HttpClient();
+ var response = await client.GetAsync(fullUrl);
+ if (response.IsSuccessStatusCode)
+ {
+ var content = await response.Content.ReadAsStringAsync();
+ var weather = JsonSerializer.Deserialize(content);
+ if (weather.cod != 200)
+ {
+ await DisplayAlert("错误", "城市名称错误", "确定");
+ return;
+ }
+ cityLabel.Text = city;
+ weatherLabel.Text = weather.weather[0].description;
+ temperatureLabel.Text = weather.main.temp.ToString() + "℃";
+ windDirectionLabel.Text = weather.wind.deg.ToString() + "°";
+ windSpeedLabel.Text = weather.wind.speed.ToString() + "m/s";
+ humidityLabel.Text = weather.main.humidity.ToString() + "%";
+ reportTimeLabel.Text = weather.dt.ToString();
+ }
+ else
+ {
+ await DisplayAlert("错误", "城市名称错误", "确定");
+ return;
+ }
+ }
+ }
+}
+class Weather
+{
+ public int cod { get; set; }
+ public WeatherMain main { get; set; }
+ public WeatherWind wind { get; set; }
+ public WeatherWeather[] weather { get; set; }
+ public int dt { get; set; }
+}
+class WeatherMain
+{
+ public float temp { get; set; }
+ public int humidity { get; set; }
+}
+class WeatherWind
+{
+ public float speed { get; set; }
+ public float deg { get; set; }
+}
+class WeatherWeather
+{
+ public string description { get; set; }
+}
+#endif
+#if ACCUWEATHER
+public partial class WeatherPage : ContentPage
+{
+ public string url = "http://dataservice.accuweather.com/currentconditions/v1/";
+ public string locationKey = "";
+ public string apiKey = Secrets.AccuWeatherAPI;
+ public string language = "zh-CN";
+ public string details = "true";
+ public string fullUrl = "";
+
+ public WeatherPage()
+ {
+ InitializeComponent();
+ cityLabel.Text = "N/A";
+ weatherLabel.Text = "N/A";
+ temperatureLabel.Text = "N/A";
+ windDirectionLabel.Text = "N/A";
+ windSpeedLabel.Text = "N/A";
+ humidityLabel.Text = "N/A";
+ reportTimeLabel.Text = "N/A";
+ }
+
+ public async void OnSearchClicked(object sender, System.EventArgs e)
+ {
+ switch (picker.SelectedIndex)
+ {
+ case 0:
+ locationKey = "101924";
+ break;
+ case 1:
+ locationKey = "106577";
+ break;
+ case 2:
+ locationKey = "58194";
+ break;
+ case 3:
+ locationKey = "102255";
+ break;
+ case 4:
+ locationKey = "106832";
+ break;
+ case 5:
+ locationKey = "106774";
+ break;
+ case 6:
+ locationKey = "105570";
+ break;
+ case 7:
+ locationKey = "105571";
+ break;
+ case 8:
+ locationKey = "102144";
+ break;
+ case 9:
+ locationKey = "103847";
+ break;
+ default:
+ locationKey = "";
+ fullUrl = "";
+ break;
+ }
+ if (locationKey != "")
+ {
+ fullUrl = $"{url}{locationKey}?apikey={apiKey}&language={language}&details={details}";
+ HttpClient client = new HttpClient();
+ var response = await client.GetAsync(fullUrl);
+ if (response.IsSuccessStatusCode)
+ {
+ var content = await response.Content.ReadAsStringAsync();
+ if (content == "[]")
+ {
+ cityLabel.Text = "N/A";
+ weatherLabel.Text = "N/A";
+ temperatureLabel.Text = "N/A";
+ windDirectionLabel.Text = "N/A";
+ windSpeedLabel.Text = "N/A";
+ humidityLabel.Text = "N/A";
+ reportTimeLabel.Text = "N/A";
+ return;
+ }
+ else
+ {
+ var weather = JsonSerializer.Deserialize(content);
+ cityLabel.Text = picker.Items[picker.SelectedIndex];
+ weatherLabel.Text = weather.WeatherText;
+ temperatureLabel.Text = weather.Temperature.Metric.Value.ToString() + "℃";
+ windDirectionLabel.Text = weather.Wind.Direction.Localized;
+ windSpeedLabel.Text = weather.Wind.Speed.Metric.Value.ToString() + "km/h";
+ humidityLabel.Text = weather.RelativeHumidity.ToString() + "%";
+ reportTimeLabel.Text = weather.LocalObservationDateTime.ToString();
+ }
+ }
+ }
+ }
+}
+
+public class Weather
+{
+ public DateTime LocalObservationDateTime { get; set; }
+ public string WeatherText { get; set; }
+ public Temperature_ Temperature { get; set; }
+ public Wind_ Wind { get; set; }
+ public int RelativeHumidity { get; set; }
+ public class Metric_
+ {
+ public double Value { get; set; }
+ public string Unit { get; set; }
+ }
+ public class Temperature_
+ {
+ public Metric_ Metric { get; set; }
+ }
+ public class Direction_
+ {
+ public string Localized { get; set; }
+ }
+ public class Speed_
+ {
+ public Metric_ Metric { get; set; }
+ }
+ public class Wind_
+ {
+ public Direction_ Direction { get; set; }
+ public Speed_ Speed { get; set; }
+ }
+
+}
+#endif
\ No newline at end of file
diff --git a/android/XPrism/XPrism/XPrism.csproj b/android/XPrism/XPrism/XPrism.csproj
index c95d8c2..a193d60 100644
--- a/android/XPrism/XPrism/XPrism.csproj
+++ b/android/XPrism/XPrism/XPrism.csproj
@@ -63,6 +63,9 @@
MSBuild:Compile
+
+ MSBuild:Compile
+