1
1
package com .example .antidepression ;
2
2
3
- import androidx .appcompat .app .AppCompatActivity ;
4
-
3
+ import android .app .ListActivity ;
4
+ import android .content .Context ;
5
+ import android .content .Intent ;
6
+ import android .content .SharedPreferences ;
5
7
import android .os .Bundle ;
8
+ import android .widget .AdapterView ;
9
+ import android .widget .ArrayAdapter ;
10
+
11
+ public class MainActivity extends ListActivity {
6
12
7
- public class MainActivity extends AppCompatActivity {
13
+ public static final String APP_PREFERENCES_THEME = "theme" ;
14
+ public static final String IS_DARK_THEME = "isDarkTheme" ;
15
+ private SharedPreferences settings ;
16
+
17
+ String [] activities = {"About depression" , "Test" , "Advices" , "Thought catalog" , "Pleasure therapy" };
8
18
9
19
@ Override
10
20
protected void onCreate (Bundle savedInstanceState ) {
11
21
super .onCreate (savedInstanceState );
22
+
23
+ loadSettings ();
24
+ loadTheme ();
25
+
12
26
setContentView (R .layout .activity_main );
27
+
28
+ // создаем адаптер
29
+ ArrayAdapter <String > adapter = new ArrayAdapter <>(this ,
30
+ android .R .layout .simple_list_item_1 , activities );
31
+ setListAdapter (adapter );
32
+
33
+ AdapterView .OnItemClickListener itemListener = (parent , v , position , id ) -> {
34
+ String selectedItem = parent .getItemAtPosition (position ).toString ();
35
+ Intent intent ;
36
+ switch (selectedItem ) {
37
+ // case "About depression":
38
+ // intent = new Intent(getApplicationContext(), AboutDepressionActivity.class);
39
+ // break;
40
+ // case "Test":
41
+ // intent = new Intent(getApplicationContext(), TestActivity.class);
42
+ // break;
43
+ // case "Advices":
44
+ // intent = new Intent(getApplicationContext(), AdviceScreenSlidePagerActivity.class);
45
+ // break;
46
+ // case "Thought catalog":
47
+ // intent = new Intent(getApplicationContext(), NotesActivity.class);
48
+ // break;
49
+ case "Pleasure therapy" :
50
+ intent = new Intent (getApplicationContext (), PleasureActivity .class );
51
+ break ;
52
+ default :
53
+ intent = new Intent (getApplicationContext (), MainActivity .class );
54
+ break ;
55
+ }
56
+ startActivity (intent );
57
+ };
58
+ getListView ().setOnItemClickListener (itemListener );
59
+ // ImageView img= findViewById(R.id.imageView);
60
+ // Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.main_image);
61
+ // img.setImageURI(uri);
62
+ }
63
+
64
+ private void loadSettings () {
65
+ settings = this .getSharedPreferences (APP_PREFERENCES_THEME , Context .MODE_PRIVATE );
66
+ }
67
+
68
+ private void loadTheme () {
69
+ int theme = getThemeFromPreferences ();
70
+ setTheme (theme );
71
+ }
72
+
73
+ private void reloadTheme () {
74
+ int theme = getThemeFromPreferences ();
75
+ setTheme (theme );
76
+ MainActivity .this .recreate ();
77
+ }
78
+
79
+ private int getThemeFromPreferences () {
80
+ boolean darkTheme = settings .getBoolean (IS_DARK_THEME , false );
81
+ return darkTheme ? R .style .DarkTheme : R .style .LightTheme ;
13
82
}
14
83
}
0 commit comments