Deleted files
This commit is contained in:
parent
c91ca6be43
commit
e65180b143
Binary file not shown.
|
Before Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 3.1 KiB |
@ -1,191 +0,0 @@
|
||||
package com.example.airquality;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.toolbox.JsonObjectRequest;
|
||||
import com.android.volley.toolbox.Volley;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AQActivity extends AppCompatActivity {
|
||||
private static final Map<String, double[]> cityCoordinates = new HashMap<>();
|
||||
static {
|
||||
cityCoordinates.put("Subotica", new double[]{46.1, 19.6667});
|
||||
cityCoordinates.put("Novi Sad", new double[]{45.2517, 19.8369});
|
||||
cityCoordinates.put("Beograd", new double[]{44.804, 20.4651});
|
||||
cityCoordinates.put("San Francisko", new double[]{37.7749, -122.4194});
|
||||
cityCoordinates.put("Sidnej", new double[]{-33.8679, 151.2073});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_aqactivity);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
|
||||
// Using toolbar as ActionBar
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
// Display application icon in the toolbar
|
||||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
getSupportActionBar().setLogo(R.drawable.weather_clear_symbolic);
|
||||
getSupportActionBar().setDisplayUseLogoEnabled(true);
|
||||
}
|
||||
|
||||
loadAQ();
|
||||
}
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
loadAQ();
|
||||
}
|
||||
|
||||
public boolean onCreateOptionsMenu(android.view.Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
|
||||
inflater.inflate(R.menu.menu_main, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(android.view.MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_aq:
|
||||
Intent intentAQ = new Intent(this, AQActivity.class);
|
||||
startActivity(intentAQ);
|
||||
return true;
|
||||
case R.id.menu_settings:
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
private String getAQIDescription(int aqi) {
|
||||
switch (aqi) {
|
||||
case 1: return "Good";
|
||||
case 2: return "Fair";
|
||||
case 3: return "Moderate";
|
||||
case 4: return "Poor";
|
||||
case 5: return "Very Poor";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
public void loadAQ(){
|
||||
String city = PreferencesManager.getCity(this);
|
||||
double[] coords = cityCoordinates.get(city);
|
||||
if (coords == null) {
|
||||
Toast.makeText(this, "Unknown city: " + city, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
String apiKey = getString(R.string.weather_api_key);
|
||||
String url = String.format(
|
||||
"https://api.openweathermap.org/data/2.5/air_pollution?lat=%.6f&lon=%.6f&appid=%s",
|
||||
coords[0], coords[1], apiKey
|
||||
);
|
||||
|
||||
RequestQueue queue = Volley.newRequestQueue(this);
|
||||
JsonObjectRequest request = new JsonObjectRequest(
|
||||
Request.Method.GET,
|
||||
url,
|
||||
null,
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
try {
|
||||
// Get JSON fields
|
||||
JSONObject listItem = response.getJSONArray("list").getJSONObject(0);
|
||||
int aqi = listItem.getJSONObject("main").getInt("aqi");
|
||||
|
||||
View rootLayout = findViewById(R.id.main);
|
||||
|
||||
int colorResId;
|
||||
switch (aqi) {
|
||||
case 1:
|
||||
colorResId = R.color.aqi_good;
|
||||
break;
|
||||
case 2:
|
||||
colorResId = R.color.aqi_fair;
|
||||
break;
|
||||
case 3:
|
||||
colorResId = R.color.aqi_moderate;
|
||||
break;
|
||||
case 4:
|
||||
colorResId = R.color.aqi_poor;
|
||||
break;
|
||||
case 5:
|
||||
colorResId = R.color.aqi_very_poor;
|
||||
break;
|
||||
default:
|
||||
colorResId = android.R.color.background_light;
|
||||
}
|
||||
|
||||
rootLayout.setBackgroundColor(getResources().getColor(colorResId));
|
||||
|
||||
JSONObject components = listItem.getJSONObject("components");
|
||||
double pm25 = components.getDouble("pm2_5");
|
||||
double pm10 = components.getDouble("pm10");
|
||||
double o3 = components.getDouble("o3");
|
||||
double co = components.getDouble("co");
|
||||
double no2 = components.getDouble("no2");
|
||||
|
||||
|
||||
TextView tvCity = findViewById(R.id.tvCity);
|
||||
TextView tvAQ = findViewById(R.id.tvAQ);
|
||||
TextView tvComponents = findViewById(R.id.tvComponents);
|
||||
|
||||
|
||||
String city = PreferencesManager.getCity(AQActivity.this);
|
||||
|
||||
|
||||
tvCity.setText("City: " + city);
|
||||
tvAQ.setText("AQI Index: " + aqi + " (" + getAQIDescription(aqi) + ")");
|
||||
tvComponents.setText(
|
||||
String.format("PM2.5: %.2f µg/m³\nPM10: %.2f µg/m³\nO₃: %.2f ppb\nCO: %.2f ppm\nNO₂: %.2f ppb",
|
||||
pm25, pm10, o3, co, no2)
|
||||
);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(AQActivity.this, "Failed to parse air data", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Toast.makeText(AQActivity.this, "Failed to load air pollution data", Toast.LENGTH_SHORT).show();
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
queue.add(request);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".AQActivity">
|
||||
|
||||
<!-- AppBar layout for using Toolbar as AppBar -->
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appBarLayout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<!-- ToolBar widget -->
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#0F9D58"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:theme="?attr/actionBarTheme"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:title="Air Pollution"
|
||||
app:titleTextColor="#ffff" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/appBarLayout"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:padding="20dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvCity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView"
|
||||
android:textSize="24sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvComponents"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView"
|
||||
android:textSize="24sp"
|
||||
android:layout_marginTop="20dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvAQ" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAQ"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView"
|
||||
android:textSize="24sp"
|
||||
android:layout_marginTop="20dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvCity" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user