8
8
import android .content .Intent ;
9
9
import android .os .Build ;
10
10
import android .os .Bundle ;
11
+ import android .support .annotation .NonNull ;
11
12
import android .support .annotation .Nullable ;
13
+ import android .support .design .button .MaterialButton ;
14
+ import android .support .design .widget .BottomSheetBehavior ;
15
+ import android .support .design .widget .BottomSheetDialog ;
12
16
import android .support .v7 .widget .Toolbar ;
13
17
import android .util .Log ;
14
18
import android .view .View ;
15
19
import android .view .View .OnClickListener ;
16
20
import android .widget .Button ;
17
21
import android .widget .RadioButton ;
18
22
import android .widget .RadioGroup ;
23
+ import android .widget .TextView ;
19
24
20
25
import com .catherine .materialdesignapp .R ;
26
+ import com .catherine .materialdesignapp .components .BottomSheetItem ;
21
27
import com .catherine .materialdesignapp .content_providers .CallLogDao ;
22
- import com .catherine .materialdesignapp .content_providers .UserDictionaryDao ;
23
28
import com .catherine .materialdesignapp .listeners .OnRequestPermissionsListener ;
24
- import com .catherine .materialdesignapp .models .Word ;
25
29
import com .catherine .materialdesignapp .services .MusicPlayerJobScheduler ;
26
30
import com .catherine .materialdesignapp .services .MusicPlayerService ;
27
31
28
32
import java .util .List ;
33
+ import java .util .Locale ;
29
34
30
35
import static com .catherine .materialdesignapp .services .BusyJobs .JOB_MUSIC_PLAYER ;
31
36
@@ -37,6 +42,9 @@ private enum ServiceType {
37
42
}
38
43
39
44
private ServiceType selectedServiceType = ServiceType .BACKGROUND ;
45
+ // private BottomSheetBehavior behavior;
46
+ private BottomSheetDialog bottomSheetDialog ;
47
+ private CallLogDao callLogDao ;
40
48
41
49
@ Override
42
50
protected void onCreate (Bundle savedInstanceState ) {
@@ -57,6 +65,7 @@ protected void onCreate(Bundle savedInstanceState) {
57
65
btn_content_providers .setOnClickListener (this );
58
66
59
67
68
+ // radio buttons
60
69
RadioGroup rg_service_switch = findViewById (R .id .rg_service_switch );
61
70
RadioButton rbn_foreground_service = findViewById (R .id .rbn_foreground_service );
62
71
RadioButton rbn_job_scheduler = findViewById (R .id .rbn_job_scheduler );
@@ -81,12 +90,62 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
81
90
}
82
91
83
92
});
93
+
94
+
95
+ // bottom sheet dialog
96
+ bottomSheetDialog = new BottomSheetDialog (this );
97
+ View view = getLayoutInflater ().inflate (R .layout .bottom_sheet_app_components , null );
98
+ bottomSheetDialog .setContentView (view );
99
+
100
+ String [] titles = getResources ().getStringArray (R .array .app_components_bottom_sheet_array );
101
+ BottomSheetItem item_create = bottomSheetDialog .findViewById (R .id .item_create );
102
+ item_create .setTitle (titles [0 ]);
103
+ item_create .setOnClickListener (this );
104
+ BottomSheetItem item_read = bottomSheetDialog .findViewById (R .id .item_read );
105
+ item_read .setTitle (titles [1 ]);
106
+ item_read .setOnClickListener (this );
107
+ BottomSheetItem item_update = bottomSheetDialog .findViewById (R .id .item_update );
108
+ item_update .setTitle (titles [2 ]);
109
+ item_update .setOnClickListener (this );
110
+ BottomSheetItem item_delete = bottomSheetDialog .findViewById (R .id .item_delete );
111
+ item_delete .setTitle (titles [3 ]);
112
+ item_delete .setOnClickListener (this );
113
+
114
+ // bottom sheet another version
115
+ // View bottomSheet = findViewById(R.id.bottom_sheet);
116
+ // behavior = BottomSheetBehavior.from(bottomSheet);
117
+ // behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
118
+ // behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
119
+ // @Override
120
+ // public void onStateChanged(@NonNull View bottomSheet, int newState) {
121
+ // Log.d(TAG, String.format(Locale.US, "bottomSheet: %d", newState));
122
+ // }
123
+ //
124
+ // @Override
125
+ // public void onSlide(@NonNull View bottomSheet, float slideOffset) {
126
+ // }
127
+ // });
128
+ // behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
129
+ // String[] titles = getResources().getStringArray(R.array.app_components_bottom_sheet_array);
130
+ // TextView tv_create = findViewById(R.id.tv_create);
131
+ // tv_create.setText(titles[0]);
132
+ // tv_create.setOnClickListener(this);
133
+ // TextView tv_read = findViewById(R.id.tv_read);
134
+ // tv_read.setText(titles[1]);
135
+ // tv_read.setOnClickListener(this);
136
+ // TextView tv_update = findViewById(R.id.tv_update);
137
+ // tv_update.setText(titles[2]);
138
+ // tv_update.setOnClickListener(this);
139
+ // TextView tv_delete = findViewById(R.id.tv_delete);
140
+ // tv_delete.setText(titles[3]);
141
+ // tv_delete.setOnClickListener(this);
84
142
}
85
143
86
144
@ Override
87
145
public void onClick (View v ) {
88
146
switch (v .getId ()) {
89
147
case R .id .btn_start_service :
148
+ // behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
90
149
if (selectedServiceType == ServiceType .BACKGROUND ) {
91
150
startService (true );
92
151
} else if (selectedServiceType == ServiceType .FOREGROUND ) {
@@ -96,6 +155,7 @@ public void onClick(View v) {
96
155
}
97
156
break ;
98
157
case R .id .btn_stop_service :
158
+ // behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
99
159
if (selectedServiceType == ServiceType .BACKGROUND ) {
100
160
stopService ();
101
161
} else if (selectedServiceType == ServiceType .FOREGROUND ) {
@@ -105,21 +165,26 @@ public void onClick(View v) {
105
165
}
106
166
break ;
107
167
case R .id .btn_broadcast_receivers :
168
+ // behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
108
169
// TODO add one more broadcast receiver
109
170
break ;
110
171
case R .id .btn_content_providers :
111
- // UserDictionaryDao dao = new UserDictionaryDao();
112
- // dao.query();
113
- //
114
- // Word word = new Word("new word", 999, "new shortcut", "en_US");
115
- // dao.insert(word);
116
-
117
172
String [] permissions = {Manifest .permission .READ_CALL_LOG , Manifest .permission .WRITE_CALL_LOG };
118
173
getPermissions (permissions , new OnRequestPermissionsListener () {
119
174
@ Override
120
175
public void onGranted () {
121
- CallLogDao callLogDao = new CallLogDao ();
122
- callLogDao .read ();
176
+ // if (behavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
177
+ // callLogDao = new CallLogDao();
178
+ // behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
179
+ // } else
180
+ // behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
181
+
182
+ if (bottomSheetDialog .isShowing ()) {
183
+ bottomSheetDialog .closeOptionsMenu ();
184
+ } else {
185
+ callLogDao = new CallLogDao ();
186
+ bottomSheetDialog .show ();
187
+ }
123
188
}
124
189
125
190
@ Override
@@ -132,6 +197,24 @@ public void onRetry() {
132
197
Log .d (TAG , "onRetry" );
133
198
}
134
199
});
200
+ break ;
201
+ case R .id .item_create :
202
+ // behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
203
+ bottomSheetDialog .closeOptionsMenu ();
204
+ break ;
205
+ case R .id .item_read :
206
+ // behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
207
+ bottomSheetDialog .closeOptionsMenu ();
208
+ callLogDao .read ();
209
+ break ;
210
+ case R .id .item_update :
211
+ // behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
212
+ bottomSheetDialog .closeOptionsMenu ();
213
+ break ;
214
+ case R .id .item_delete :
215
+ // behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
216
+ bottomSheetDialog .closeOptionsMenu ();
217
+
135
218
break ;
136
219
}
137
220
}
0 commit comments