FairEmail/app/src/main/java/eu/faircode/email/ActivityBase.java

73 lines
2.6 KiB
Java
Raw Normal View History

2018-08-02 13:33:06 +00:00
package eu.faircode.email;
/*
This file is part of Safe email.
Safe email is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NetGuard is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018 by Marcel Bokhorst (M66B)
*/
import android.content.SharedPreferences;
2018-08-11 16:13:22 +00:00
import android.content.res.Configuration;
2018-08-02 13:33:06 +00:00
import android.os.Bundle;
import android.preference.PreferenceManager;
2018-08-04 15:37:42 +00:00
import android.util.Log;
2018-08-02 13:33:06 +00:00
2018-08-08 06:55:47 +00:00
import androidx.appcompat.app.AppCompatActivity;
2018-08-04 15:37:42 +00:00
abstract class ActivityBase extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
2018-08-02 13:33:06 +00:00
@Override
protected void onCreate(Bundle savedInstanceState) {
2018-08-04 15:37:42 +00:00
Log.i(Helper.TAG, "Create " + this.getClass().getName());
2018-08-02 13:33:06 +00:00
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
2018-08-08 06:55:47 +00:00
String theme = prefs.getString("theme", "light");
2018-08-04 15:37:42 +00:00
setTheme("light".equals(theme) ? R.style.AppThemeLight : R.style.AppThemeDark);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
2018-08-02 13:33:06 +00:00
super.onCreate(savedInstanceState);
}
2018-08-04 15:37:42 +00:00
2018-08-11 16:13:22 +00:00
@Override
protected void onResume() {
Log.i(Helper.TAG, "Resume " + this.getClass().getName());
super.onResume();
}
@Override
protected void onPause() {
Log.i(Helper.TAG, "Pause " + this.getClass().getName());
super.onPause();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.i(Helper.TAG, "Config " + this.getClass().getName());
super.onConfigurationChanged(newConfig);
}
2018-08-04 15:37:42 +00:00
@Override
protected void onDestroy() {
Log.i(Helper.TAG, "Destroy " + this.getClass().getName());
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Log.i(Helper.TAG, "Preference " + key + "=" + prefs.getAll().get(key));
2018-08-13 13:57:51 +00:00
if ("theme".equals(key) || "debug".equals(key))
2018-08-04 15:37:42 +00:00
recreate();
}
2018-08-02 13:33:06 +00:00
}