ProgressBar And SnackBar and Check The Internet

 dependency  Progressbar:

Implementation 'com.kaopiz:kprogresshud:1.2.0'

implementation 'com.kaopiz:kprogresshud:1.2.0'



private KProgressHUD kProgressHUD;

try {

kProgressHUD = KProgressHUD.create(ActivityLogin.this)

.setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)

.setCancellable(false)

.setAnimationSpeed(2)

.setDimAmount(0.5f)

.show();

} catch (Exception e) {

e.printStackTrace();



if (kProgressHUD.isShowing())

kProgressHUD.dismiss();

}



    dependency  DisplaySnackBar:

                

      Implementation 'com.chootdev:csnackbar:1.4.0'    


  package com.example.reBLISS.helper;



import android.content.Context;

import com.chootdev.csnackbar.Align;
import com.chootdev.csnackbar.Duration;
import com.chootdev.csnackbar.Snackbar;
import com.chootdev.csnackbar.Type;

public class DisplaySnackBar {
Context context;
String message;
int type = 0;
public DisplaySnackBar(Context context) {
this.context = context;
}

public void DisplaySnackBar(String message, int type) {
this.type = type;
this.message = message;
showSnackBar();
}

private void showSnackBar() {
Type snacktype = null;
if (type == 0) {
snacktype = Type.SUCCESS;
} else if (type == 1) {
snacktype = Type.ERROR;
} else if (type == 2) {
snacktype = Type.UPDATE;
} else if (type == 3) {
snacktype = Type.WARNING;
}
Snackbar.with(context, null)
.type(snacktype)
.message(message)
.duration(Duration.SHORT)
.fillParent(true)
.textAlign(Align.CENTER)
.show();
}
}

     

private DisplaySnackBar displaySnackBar;
displaySnackBar = new DisplaySnackBar(this);
displaySnackBar.DisplaySnackBar("NO INTERNET CONNECTION", 1);


Check the Internet 

   <uses-permission android:name="android.permission.INTERNET" />


if (isConnected())

{
Toast.makeText(getApplicationContext(),"OK Internet",Toast.LENGTH_LONG).show();
}
else {

Toast.makeText(getApplicationContext(),"No Internet",Toast.LENGTH_LONG).show();

}
boolean isConnected() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

if (networkInfo != null) {
if (networkInfo.isConnected())
return true;
else
return false;
} else
return false;
}



















Comments