Skip to content

Instantly share code, notes, and snippets.

View pyadav's full-sized avatar
🐢
learning new stuff

Praveen Yadav pyadav

🐢
learning new stuff
View GitHub Profile
@pyadav
pyadav / SplashScreen.java
Created August 8, 2016 03:39 — forked from guptasanchit90/SplashScreen.java
A SplashScreen using RxAndroid
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Observer;
import rx.Subscription;
import android.content.Context;
import android.os.AsyncTask;
import ai.api.AIConfiguration;
import ai.api.AIDataService;
import ai.api.AIListener;
import ai.api.AIService;
import ai.api.AIServiceException;
import ai.api.model.AIError;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
/**
* Dialog helper class
*/
public class DestructiveDialog {
public DestructiveDialog(Context context, String title, String message, String positive, String negative, final DialogListener dialogListener) {
@pyadav
pyadav / LocationHelper.java
Created August 8, 2016 03:41 — forked from guptasanchit90/LocationHelper.java
Check location enabled or not
public class LocationHelper{
public static boolean isLocationEnabled(Context context) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// Check GPS status
boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
// Check network status
boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
return false;
}
@pyadav
pyadav / NetworkUtils.java
Created August 8, 2016 03:41
Check if internet is connected or not
public class NetworkUtils{
public static boolean isNetworkConnected(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
return (networkInfo != null && networkInfo.isConnectedOrConnecting());
}
}
@pyadav
pyadav / FragmentHelper.java
Created August 8, 2016 03:41 — forked from guptasanchit90/FragmentHelper.java
Check if fragment is visible and still not destroyed
public class FragmentHelper {
public static boolean isFragmentVisible(WeakReference<Fragment> fragment) {
if (fragment!=null && fragment.get() != null && fragment.get().getActivity() != null &&
fragment.get()
.isVisible()
&& !fragment.get().isRemoving()) {
return true;
}
return false;
}
package <Package Name>;
import android.content.Context;
import android.graphics.Typeface;
import android.text.TextUtils;
public class FontUtils {
/**
* Loads the desired font.
*
@pyadav
pyadav / PreferenceHelper.java
Created August 8, 2016 03:41 — forked from guptasanchit90/PreferenceHelper.java
A preference helper class for android.
package <Package Name>;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import java.util.Map;
import java.util.Set;
public class PreferenceHelper {
@pyadav
pyadav / rxjava.java
Created August 8, 2016 03:43 — forked from yongjhih/rxjava.java
RxJava
Observable.merge(Observable.from(getRawSelfPosts()), Observable.from(getRawFriendPosts()), Observable.from(getRawNearbyPosts(activity)))
.distinct((post) -> post.getObjectId())
.subscribeOn(Schedulers.io());
getRawPostsObs(activity).map((post) -> postToCardModel(post));
new RxList(getRawPostsObs(activity));
getPostsObs(activity).toList().toBlocking().single();
@pyadav
pyadav / code.java
Created August 8, 2016 03:44
rxjava
Observable.just("")
.subscribeOn(Schedulers.immediate()).observeOn(Schedulers.io()).doOnSubscribe(() -> {
//tv1.setText("fe");
})
.map(x -> {
InitVo initVo = qrHttp.init();
return initVo;
})
.map(initVo -> {