better colours in night mode

master
Mateusz Lubecki 2023-10-03 11:32:57 +02:00
rodzic f8dbcff362
commit 4641945295
14 zmienionych plików z 100 dodań i 21 usunięć

Wyświetl plik

@ -1 +0,0 @@
Pogoda.cc

Wyświetl plik

@ -7,11 +7,11 @@
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Pixel_API_24.avd" />
<value value="$USER_HOME$/.android/avd/Pixel_4_XL_API_28.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-05-08T12:49:38.695730Z" />
<timeTargetWasSelectedWithDropDown value="2023-10-01T07:46:55.840082Z" />
</component>
</project>

Wyświetl plik

@ -24,6 +24,7 @@
<entry key="app/src/main/res/layout/fragment_wind.xml" value="0.3645833333333333" />
<entry key="app/src/main/res/layout/spinner_item.xml" value="0.28306159420289856" />
<entry key="app/src/main/res/menu/main_activity_menu.xml" value="0.3651041666666667" />
<entry key="app/src/main/res/mipmap-anydpi-v26/ic_launcher_icon.xml" value="0.3335" />
</map>
</option>
</component>

Wyświetl plik

@ -3,7 +3,7 @@ plugins {
}
android {
compileSdkVersion 31
compileSdkVersion 33
buildToolsVersion "30.0.3"
apply plugin: "androidx.navigation.safeargs"
@ -11,9 +11,9 @@ android {
defaultConfig {
applicationId "cc.pogoda.mobile.meteosystem"
minSdkVersion 24
targetSdkVersion 31
versionCode 18
versionName "0.18-beta"
targetSdkVersion 33
versionCode 19
versionName "0.19"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Wyświetl plik

@ -26,6 +26,7 @@ import cc.pogoda.mobile.meteosystem.file.FileNames;
import cc.pogoda.mobile.meteosystem.service.GetAllStationsService;
import cc.pogoda.mobile.meteosystem.type.AllStationsReceivedEvent;
import cc.pogoda.mobile.meteosystem.type.AvailableParameters;
import cc.pogoda.mobile.meteosystem.type.ThemeColours;
import cc.pogoda.mobile.meteosystem.type.WeatherStation;
import cc.pogoda.mobile.meteosystem.type.WeatherStationListEvent;
import cc.pogoda.mobile.meteosystem.type.web.Summary;
@ -77,6 +78,15 @@ public class Main extends Application {
*/
private HashMap<String, AvailableParameters> hashmapAllStationSystemNameToAvailParameters = null;
public ThemeColours getThemeColours() {
return themeColours;
}
/**
* Used everywhere, where a colour of any element is set programatically (not globally from the theme)
*/
private ThemeColours themeColours;
public File getDirectory() {
return directory;
}
@ -138,6 +148,8 @@ public class Main extends Application {
favouritiesFile = new FavouritiesFile(fileNames);
themeColours = new ThemeColours();
// Download all stations from API in background via JobIntentService. Results are send
//back with Broadcast receiver.
startGetAllStationsService();

Wyświetl plik

@ -1,6 +1,10 @@
package cc.pogoda.mobile.meteosystem.activity;
import android.app.PendingIntent;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;

Wyświetl plik

@ -8,8 +8,10 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageButton;
@ -18,6 +20,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.color.MaterialColors;
import org.greenrobot.eventbus.EventBus;
import org.threeten.bp.LocalDateTime;
import org.threeten.bp.format.DateTimeFormatter;
@ -34,6 +38,7 @@ import cc.pogoda.mobile.meteosystem.activity.handler.MainActImageButtonFavourite
import cc.pogoda.mobile.meteosystem.activity.handler.MainActImageButtonSettingsClickEvent;
import cc.pogoda.mobile.meteosystem.config.AppConfiguration;
import cc.pogoda.mobile.meteosystem.file.CopyLog;
import cc.pogoda.mobile.meteosystem.type.ThemeColours;
public class MainActivity extends AppCompatActivity {
@ -93,6 +98,42 @@ public class MainActivity extends AppCompatActivity {
settingsButton.setOnClickListener(
new MainActImageButtonSettingsClickEvent(this, main.getConfFile()));
ThemeColours colours = ((Main) getApplication()).getThemeColours();
TypedValue typedValue = new TypedValue();
Resources.Theme theme = getTheme();
//MaterialColors.getColor(, R.attr.colorOnPrimary);
theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
TypedArray arr = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary});
colours.colorPrimary = arr.getColor(0, -1);
arr.recycle();
theme.resolveAttribute(R.attr.colorPrimaryVariant, typedValue, true);
arr = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimaryVariant});
colours.colorPrimaryVariant = arr.getColor(0, -1);
arr.recycle();
theme.resolveAttribute(R.attr.colorOnPrimary, typedValue, true);
arr = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorOnPrimary});
colours.colorOnPrimary = arr.getColor(0, -1);
arr.recycle();
theme.resolveAttribute(R.attr.colorSecondary, typedValue, true);
arr = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorSecondary});
colours.colorSecondary = arr.getColor(0, -1);
arr.recycle();
theme.resolveAttribute(R.attr.colorSecondaryVariant, typedValue, true);
arr = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorSecondaryVariant});
colours.colorSecondaryVariant = arr.getColor(0, -1);
arr.recycle();
theme.resolveAttribute(R.attr.colorOnSecondary, typedValue, true);
arr = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorOnSecondary});
colours.colorOnSecondary = arr.getColor(0, -1);
arr.recycle();
}
@Override

Wyświetl plik

@ -48,7 +48,7 @@ public class StationDetailsSummaryActivity extends AppCompatActivity {
elems = new StationSummaryActElements();
int color = ContextCompat.getColor(this, android.R.color.secondary_text_light);
int color = main.getThemeColours().colorOnSecondary;
Summary summary = null;
SummaryDao summary_dao = new SummaryDao();

Wyświetl plik

@ -2,6 +2,7 @@ package cc.pogoda.mobile.meteosystem.activity;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
@ -60,6 +61,8 @@ public class StationDetailsWindRoseActivity extends AppCompatActivity {
elements.maxGust = findViewById(R.id.textViewWindRoseMaxHourGust);
elements.minAverage = findViewById(R.id.textViewWindRoseMinHourSpeed);
elements.pressure = findViewById(R.id.textViewWindRosePressure);
elements.goodColor = ((Main) getApplication()).getThemeColours().colorOnSecondary;
elements.badColor = Color.RED;
elements.setActivity(this);
// create the handler which will update the screen in background
@ -67,12 +70,6 @@ public class StationDetailsWindRoseActivity extends AppCompatActivity {
SummaryDao summary_dao = new SummaryDao();
// // get the set of current values to preconfigure all elements on this activity
// summary = summary_dao.getStationSummary(station.getSystemName());
//
// // update parameters (like turn the wind direction arrow)
// elements.updateFromSummary(summary, station.getAvailableParameters());
handler = new Handler();
// check if this station is on favourites list

Wyświetl plik

@ -18,6 +18,7 @@ import java.util.Vector;
import cc.pogoda.mobile.meteosystem.activity.updater.thread.FavouritesStationSummaryUpdaterThread;
import cc.pogoda.mobile.meteosystem.dao.AvailableParametersDao;
import cc.pogoda.mobile.meteosystem.type.AvailableParameters;
import cc.pogoda.mobile.meteosystem.type.ThemeColours;
import cc.pogoda.mobile.meteosystem.type.web.AvailableParametersWeb;
import cc.pogoda.mobile.meteosystem.type.web.QualityFactor;
import cc.pogoda.mobile.meteosystem.type.web.Summary;
@ -56,11 +57,17 @@ public class FavouritesStationDetailsOnListUpdater implements Runnable {
*/
private boolean enabled;
public FavouritesStationDetailsOnListUpdater(Handler _handler, HashMap<String, Summary> _station_system_name_to_summary, HashMap<String, AvailableParameters> _avail_params) {
/**
* Used everywhere, where a colour of any element is set programatically (not globally from the theme)
*/
private ThemeColours themeColours;
public FavouritesStationDetailsOnListUpdater(Handler _handler, HashMap<String, Summary> _station_system_name_to_summary, HashMap<String, AvailableParameters> _avail_params, ThemeColours _themeColours) {
handler = _handler;
stationsToUpdate = new HashMap<>();
availParams = _avail_params;
stationNameSummary = _station_system_name_to_summary;
themeColours = _themeColours;
}
public boolean isEnabled() {
@ -139,7 +146,7 @@ public class FavouritesStationDetailsOnListUpdater implements Runnable {
toUpdate.setTextColor(Color.RED);
}
else {
toUpdate.setTextColor(androidx.activity.R.color.secondary_text_default_material_light);
toUpdate.setTextColor(themeColours.colorPrimary);
}
}
else {

Wyświetl plik

@ -163,7 +163,11 @@ public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
handler = new Handler(Looper.getMainLooper());
favsUpdater = new FavouritesStationDetailsOnListUpdater(handler, main.getHashmapFavStationSystemNameToSummary(), main.getHashmapAllStationSystemNameToAvailParameters());
favsUpdater = new FavouritesStationDetailsOnListUpdater(
handler,
main.getHashmapFavStationSystemNameToSummary(),
main.getHashmapAllStationSystemNameToAvailParameters(),
main.getThemeColours());
handler.postDelayed(favsUpdater, 100);
favsUpdater.setEnabled(true);

Wyświetl plik

@ -115,12 +115,14 @@ public class StationWindRoseActElements implements StationActivityElements {
if (!no_data && !data.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
windSpeed.setText(average_speed);
windSpeed.setTextColor(goodColor);
} else {
windSpeed.setText("---");
}
if (!no_data && !data.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
windGusts.setText(gusts_speed);
windGusts.setTextColor(goodColor);
} else {
windGusts.setText("---");
@ -128,6 +130,7 @@ public class StationWindRoseActElements implements StationActivityElements {
if (!no_data && !data.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
windDirection.setText(String.valueOf(data.direction) + activity.getResources().getString(R.string.degrees_sign));
windDirection.setTextColor(goodColor);
} else {
windDirection.setText("---");
}

Wyświetl plik

@ -0,0 +1,11 @@
package cc.pogoda.mobile.meteosystem.type;
public class ThemeColours {
public int colorPrimary;
public int colorPrimaryVariant;
public int colorOnPrimary;
public int colorSecondary;
public int colorSecondaryVariant;
public int colorOnSecondary;
}

Wyświetl plik

@ -2,15 +2,15 @@
<!-- Base application theme. -->
<style name="Theme.Meteosystem" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorPrimary">@color/white</item>
<item name="colorPrimaryVariant">@color/white</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<item name="colorOnSecondary">@color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:statusBarColor" tools:targetApi="l">@color/black</item>
<!-- Customize your theme here. -->
</style>
</resources>