changed the way background image is downloaded

fix/get-all-stations-hangout
Mateusz Lubecki 2021-11-26 10:13:46 +01:00
rodzic 93aab76863
commit 6423966f9f
13 zmienionych plików z 132 dodań i 41 usunięć

Wyświetl plik

@ -99,6 +99,7 @@ public class MainActivity extends AppCompatActivity {
fromFavs.setDisplayedLocation(fromAllStations.getDisplayedLocation());
fromFavs.setTimezone(fromAllStations.getTimezone());
fromFavs.setCallsignSsid(fromAllStations.getCallsignSsid());
fromFavs.setStationNameTextColor(fromAllStations.getStationNameTextColor());
// there is no need to delete and put object on the list once again
// as a list does not make a copy of the object. It (ArrayList) keeps

Wyświetl plik

@ -11,6 +11,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.icu.text.LocaleDisplayNames;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -33,9 +34,11 @@ import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActWindDirection
import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActWindSpeedPlotsButtonClickEvent;
import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActSummaryButtonClickEvent;
import cc.pogoda.mobile.pogodacc.activity.handler.StationDetailsActWindRoseButtonClickEvent;
import cc.pogoda.mobile.pogodacc.activity.updater.StationBackgroundImageUpdater;
import cc.pogoda.mobile.pogodacc.config.AppConfiguration;
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
import cc.pogoda.mobile.pogodacc.type.WeatherStationListEvent;
import cc.pogoda.mobile.pogodacc.web.StationBackgroundDownloader;
public class StationDetailsActivity extends AppCompatActivity {
@ -87,41 +90,12 @@ public class StationDetailsActivity extends AppCompatActivity {
*/
int selectedLn = 0;
/**
* This class downloads the background JPG image from the internet and
*/
private class DownloadImage implements Runnable {
ImageView iv;
String image_url;
Bitmap bitmap;
public DownloadImage(ImageView background, String url) {
iv = background;
image_url = url;
}
@Override
public void run() {
try {
InputStream in = new java.net.URL(image_url).openStream();
bitmap = BitmapFactory.decodeStream(in);
iv.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Handler handler;
public StationDetailsActivity() {
stationName = null;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_station_details, menu);
@ -277,11 +251,12 @@ public class StationDetailsActivity extends AppCompatActivity {
stationSponsorUrl.setText(station.getSponsorUrl());
stationMoreInfo.setText(station.getMoreInfo());
DownloadImage downloadImage = new DownloadImage(topBackground, station.getImageUrl());
Thread t = new Thread(downloadImage);
StationBackgroundDownloader downloader = new StationBackgroundDownloader(station);
Thread t = new Thread(downloader);
t.start();
//runOnUiThread(downloadImage);
handler = new Handler();
handler.postDelayed(new StationBackgroundImageUpdater(topBackground, stationName, station, downloader, handler), 100);
if (station_lat > 0.0f && station_lon > 0.0f) {
// europe

Wyświetl plik

@ -3,6 +3,7 @@ package cc.pogoda.mobile.pogodacc.activity.trend.pressure;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -53,7 +54,15 @@ public class PressureTrendFragment extends Fragment {
eightHours = root.findViewById(R.id.textViewPressureTrendEightHoursVal);
pressureTrendViewModel.getStationName().observe(getViewLifecycleOwner(), s -> {
if (s.length() < 18) {
stationName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 38);
}
else {
stationName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28);
}
stationName.setText(s);
});
pressureTrendViewModel.getLastMeasuremenetTime().observe(getViewLifecycleOwner(), s -> {

Wyświetl plik

@ -3,6 +3,7 @@ package cc.pogoda.mobile.pogodacc.activity.trend.temperature;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -72,6 +73,14 @@ public class TemperatureTrendFragment extends Fragment {
textViewTemperatureTrendEightHoursHVal = root.findViewById(R.id.textViewTemperatureTrendEightHoursHVal);
temperatureTrendViewModel.getDisplayedStationName().observe(getViewLifecycleOwner(), s -> {
if (s.length() < 18) {
textViewTemperatureTrendStationName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 38);
}
else {
textViewTemperatureTrendStationName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28);
}
textViewTemperatureTrendStationName.setText(s);
});

Wyświetl plik

@ -3,6 +3,7 @@ package cc.pogoda.mobile.pogodacc.activity.trend.wind;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -64,6 +65,13 @@ public class WindTrendFragment extends Fragment {
textViewWindTrendEightHoursGustsVal = root.findViewById(R.id.textViewTemperatureTrendEightHoursHVal);
windTrendViewModel.getDisplayedStationName().observe(getViewLifecycleOwner(), s -> {
if (s.length() < 18) {
textViewWindTrendStationName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 38);
}
else {
textViewWindTrendStationName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28);
}
textViewWindTrendStationName.setText(s);
});

Wyświetl plik

@ -0,0 +1,47 @@
package cc.pogoda.mobile.pogodacc.activity.updater;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.InputStream;
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
import cc.pogoda.mobile.pogodacc.web.StationBackgroundDownloader;
public class StationBackgroundImageUpdater implements Runnable{
ImageView iv;
TextView station_name;
WeatherStation station;
StationBackgroundDownloader downloader;
Handler handler;
public StationBackgroundImageUpdater(ImageView _background, TextView _station_name, WeatherStation _station, StationBackgroundDownloader _downloader, Handler _handler) {
iv = _background;
station = _station;
station_name = _station_name;
downloader = _downloader;
handler = _handler;
}
@Override
public void run() {
Bitmap bitmap = downloader.getBitmap();
if (bitmap != null) {
station_name.setTextColor(station.getStationNameTextColor());
station_name.setText(station.getDisplayedName());
iv.setImageBitmap(bitmap);
}
else {
handler.postDelayed(this, 200);
}
}
}

Wyświetl plik

@ -73,7 +73,12 @@ public class WeatherStation implements Serializable {
}
public int getStationNameTextColor() {
return stationNameTextColor;
if (stationNameTextColor == 0) {
return -16777216;
}
else {
return stationNameTextColor;
}
}
public void setStationNameTextColor(int stationNameTextColor) {

Wyświetl plik

@ -0,0 +1,39 @@
package cc.pogoda.mobile.pogodacc.web;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import java.io.IOException;
import java.io.InputStream;
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
public class StationBackgroundDownloader implements Runnable {
private WeatherStation station;
public Bitmap getBitmap() {
return bitmap;
}
private Bitmap bitmap;
public StationBackgroundDownloader(WeatherStation _wx_station) {
station = _wx_station;
bitmap = null;
}
@Override
public void run() {
InputStream in = null;
try {
in = new java.net.URL(station.getImageUrl()).openStream();
bitmap = BitmapFactory.decodeStream(in);
} catch (IOException e) {
e.printStackTrace();
bitmap = null;
}
}
}

Wyświetl plik

@ -13,7 +13,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
android:textSize="20sp" />
<Button
android:id="@+id/station_button"

Wyświetl plik

@ -12,9 +12,7 @@
android:id="@+id/buttonSelectStationExport"
android:layout_width="362dp"
android:layout_height="47dp"
android:layout_marginStart="28dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="21dp"
android:backgroundTint="#56039BE5"
android:text="@string/select_station_export"
app:layout_constraintEnd_toEndOf="parent"
@ -61,13 +59,10 @@
android:id="@+id/datePickerExportStartDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="81dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="82dp"
android:calendarViewShown="false"
android:datePickerMode="spinner"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />

Wyświetl plik

@ -12,6 +12,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="---"
android:textAlignment="center"
android:textSize="38sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

Wyświetl plik

@ -12,6 +12,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="---"
android:textAlignment="center"
android:textSize="38sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

Wyświetl plik

@ -12,6 +12,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="---"
android:textAlignment="center"
android:textSize="38sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"