1
1
package com .jstech .fluenterp ;
2
2
3
+ import android .Manifest ;
4
+ import android .content .Context ;
3
5
import android .content .DialogInterface ;
4
6
import android .content .Intent ;
7
+ import android .content .pm .PackageManager ;
8
+ import android .net .ConnectivityManager ;
9
+ import android .net .NetworkInfo ;
5
10
import android .net .Uri ;
6
11
import android .os .Build ;
7
12
import android .os .Bundle ;
8
13
import android .os .Handler ;
9
14
import android .support .annotation .NonNull ;
10
15
import android .support .annotation .RequiresApi ;
11
16
import android .support .design .widget .Snackbar ;
17
+ import android .support .v4 .app .ActivityCompat ;
18
+ import android .support .v4 .content .ContextCompat ;
12
19
import android .support .v7 .app .AlertDialog ;
13
20
import android .support .v7 .widget .GridLayoutManager ;
14
21
import android .support .v7 .widget .RecyclerView ;
@@ -117,6 +124,19 @@ public void onWindowFocusChanged(boolean hasFocus) {
117
124
expandableList .setIndicatorBoundsRelative (expandableList .getRight ()- 80 , expandableList .getWidth ());
118
125
}
119
126
127
+ boolean isConnection (){
128
+ boolean connected ;
129
+ ConnectivityManager connectivityManager = (ConnectivityManager )getSystemService (Context .CONNECTIVITY_SERVICE );
130
+ if (connectivityManager .getNetworkInfo (ConnectivityManager .TYPE_MOBILE ).getState () == NetworkInfo .State .CONNECTED ||
131
+ connectivityManager .getNetworkInfo (ConnectivityManager .TYPE_WIFI ).getState () == NetworkInfo .State .CONNECTED ) {
132
+ connected = true ;
133
+ }
134
+ else {
135
+ connected = false ;
136
+ }
137
+ return connected ;
138
+ }
139
+
120
140
@ Override
121
141
protected void onCreate (Bundle savedInstanceState ) {
122
142
super .onCreate (savedInstanceState );
@@ -131,6 +151,53 @@ protected void onCreate(Bundle savedInstanceState) {
131
151
mDrawer = findViewById (R .id .drawer_layout );
132
152
mDrawer .setTouchMode (ElasticDrawer .TOUCH_MODE_BEZEL );
133
153
setupToolbar ();
154
+
155
+ if (ContextCompat .checkSelfPermission (MainActivity .this ,
156
+ android .Manifest .permission .ACCESS_NETWORK_STATE )
157
+ != PackageManager .PERMISSION_GRANTED ) {
158
+
159
+ // Permission is not granted
160
+ if (!ActivityCompat .shouldShowRequestPermissionRationale (MainActivity .this ,
161
+ Manifest .permission .ACCESS_NETWORK_STATE )) {
162
+
163
+ // No explanation needed; request the permission
164
+ ActivityCompat .requestPermissions (MainActivity .this ,
165
+ new String []{Manifest .permission .ACCESS_NETWORK_STATE },
166
+ 101 );
167
+ }
168
+ }
169
+
170
+
171
+ if (ContextCompat .checkSelfPermission (MainActivity .this ,
172
+ android .Manifest .permission .READ_EXTERNAL_STORAGE )
173
+ != PackageManager .PERMISSION_GRANTED ) {
174
+
175
+ // Permission is not granted
176
+ if (!ActivityCompat .shouldShowRequestPermissionRationale (MainActivity .this ,
177
+ Manifest .permission .READ_EXTERNAL_STORAGE )) {
178
+
179
+ // No explanation needed; request the permission
180
+ ActivityCompat .requestPermissions (MainActivity .this ,
181
+ new String []{Manifest .permission .READ_EXTERNAL_STORAGE },
182
+ 101 );
183
+ }
184
+ }
185
+
186
+ if (ContextCompat .checkSelfPermission (MainActivity .this ,
187
+ android .Manifest .permission .WRITE_EXTERNAL_STORAGE )
188
+ != PackageManager .PERMISSION_GRANTED ) {
189
+
190
+ // Permission is not granted
191
+ if (!ActivityCompat .shouldShowRequestPermissionRationale (MainActivity .this ,
192
+ Manifest .permission .WRITE_EXTERNAL_STORAGE )) {
193
+
194
+ // No explanation needed; request the permission
195
+ ActivityCompat .requestPermissions (MainActivity .this ,
196
+ new String []{Manifest .permission .WRITE_EXTERNAL_STORAGE },
197
+ 101 );
198
+ }
199
+ }
200
+
134
201
//Activity
135
202
initMainContent ();
136
203
strTCode = "" ;
@@ -171,6 +238,10 @@ public void onClick(View v) {
171
238
mMenuAdapter = new ExpandableListAdapter (this , listDataHeader , listDataChild );
172
239
// setting list adapter
173
240
expandableList .setAdapter (mMenuAdapter );
241
+ if (!isConnection ()){
242
+ Snackbar .make ( findViewById (R .id .content ), "It seems you are not connected to the network!" , Snackbar .LENGTH_LONG ).show ();
243
+
244
+ }
174
245
expandableList .setOnChildClickListener (new ExpandableListView .OnChildClickListener () {
175
246
@ Override
176
247
public boolean onChildClick (ExpandableListView expandableListView ,
@@ -682,8 +753,10 @@ public void onClick(DialogInterface dialog, int which) {
682
753
Objects .requireNonNull (dialog .getWindow ()).getAttributes ().windowAnimations = R .style .DialogThemeModified ;
683
754
dialog .show ();
684
755
Button bNeg = dialog .getButton (DialogInterface .BUTTON_NEGATIVE );
756
+ //noinspection deprecation
685
757
bNeg .setTextColor (getResources ().getColor (R .color .splashback ));
686
758
Button bPos = dialog .getButton (DialogInterface .BUTTON_POSITIVE );
759
+ //noinspection deprecation
687
760
bPos .setTextColor (getResources ().getColor (R .color .splashback ));
688
761
break ;
689
762
}
0 commit comments