Revision 9881dc03
Added by Leszek Koltunski about 1 month ago
src/main/java/org/distorted/helpers/BaseActivity.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package org.distorted.helpers; |
11 | 11 |
|
12 |
import android.content.SharedPreferences; |
|
12 | 13 |
import android.content.res.Configuration; |
13 | 14 |
import android.os.Build; |
14 | 15 |
import android.os.Bundle; |
... | ... | |
19 | 20 |
import android.widget.LinearLayout; |
20 | 21 |
|
21 | 22 |
import androidx.appcompat.app.AppCompatActivity; |
23 |
import androidx.preference.PreferenceManager; |
|
22 | 24 |
|
23 | 25 |
import org.distorted.main.R; |
24 | 26 |
|
... | ... | |
26 | 28 |
|
27 | 29 |
public class BaseActivity extends AppCompatActivity |
28 | 30 |
{ |
31 |
protected static final int THEME_GREY = 0; |
|
32 |
protected static final int THEME_WHITE = 1; |
|
33 |
protected static final int THEME_GREEN = 2; |
|
34 |
|
|
35 |
public static final float RATIO_HID = 0.050f; |
|
29 | 36 |
public static final float RATIO_BAR = 0.080f; |
30 | 37 |
public static final int FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
31 | 38 |
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
... | ... | |
34 | 41 |
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
35 | 42 |
|
36 | 43 |
private int mCurrentApiVersion; |
44 |
protected int mCurrentTheme; |
|
37 | 45 |
protected int mScreenWidth, mScreenHeight; |
38 | 46 |
protected int mHeightLowerBar, mHeightUpperBar; |
47 |
protected SharedPreferences mPreferences; |
|
39 | 48 |
|
40 | 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
41 | 50 |
|
42 | 51 |
@Override |
43 | 52 |
protected void onCreate(Bundle savedState) |
44 | 53 |
{ |
45 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
54 |
mPreferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
55 |
mCurrentTheme = mPreferences.getInt("theme",THEME_GREY); |
|
56 |
|
|
57 |
switch(mCurrentTheme) |
|
58 |
{ |
|
59 |
case THEME_WHITE : setTheme(R.style.WhiteTheme); break; |
|
60 |
case THEME_GREEN : setTheme(R.style.GreenTheme); break; |
|
61 |
default : setTheme(R.style.GreyTheme); break; |
|
62 |
} |
|
63 |
|
|
64 |
android.util.Log.e("D", "current theme: "+mCurrentTheme); |
|
65 |
|
|
46 | 66 |
super.onCreate(savedState); |
47 | 67 |
} |
48 | 68 |
|
69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
70 |
|
|
71 |
public void changeThemeTo(int theme) |
|
72 |
{ |
|
73 |
mCurrentTheme = theme; |
|
74 |
|
|
75 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
76 |
editor.putInt("theme", mCurrentTheme ); |
|
77 |
editor.apply(); |
|
78 |
|
|
79 |
recreate(); |
|
80 |
} |
|
81 |
|
|
49 | 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
50 | 83 |
|
51 | 84 |
protected void getWindowWidth(Configuration conf) |
Also available in: Unified diff
common code from all activities to one BaseActivity