Skip to content

Instantly share code, notes, and snippets.

View andreikastsiuk's full-sized avatar
🤓
Student forever

Andrei Kastsiuk andreikastsiuk

🤓
Student forever
View GitHub Profile
@andreikastsiuk
andreikastsiuk / logcat.md
Created July 3, 2018 10:58
Logcat Color

Custom Logcat Color

  • ASSERT -> #A800FF
  • DEBUG -> #3D9D2A
  • ERROR -> #D80D15
  • INFO -> #003CC8
  • VERBOSE -> #BBBBBB
@andreikastsiuk
andreikastsiuk / utils.java
Last active July 3, 2018 11:02
Distance between two points on the map
public class PositionUtils {
public static float calculateHaversineDistance(double lat1, double lon1, double lat2, double lon2) {
final double p = 0.017453292519943295; // Math.PI / 180
final double earthRad2 = 12742000f; // 2 * R; R = 6371 km
final double lat1p = lat1 * p;
final double lat2p = lat2 * p;
double a = 0.5 - Math.cos(lat2p - lat1p) / 2 +
Math.cos(lat1p) * Math.cos(lat2p) *
(1 - Math.cos((lon2 - lon1) * p)) / 2;
return (float) (earthRad2 * Math.asin(Math.sqrt(a)));
@andreikastsiuk
andreikastsiuk / utils.java
Last active July 3, 2018 11:02
Method that checks Play Services availability
private boolean checkPlayServices() {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
.show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
@andreikastsiuk
andreikastsiuk / utils.java
Last active July 3, 2018 11:02
Bubble sort on Java
private static Integer[] bubble(Integer[] integers) {
for (int curr = 0; curr < integers.length; ++curr) {
for (int other = curr + 1; other < integers.length; ++other) {
if (integers[curr] > integers[other]) {
int tmp = integers[curr];
integers[curr] = integers[other];
integers[other] = tmp;
}
}
}
private static volatile DoubleCheckedLockingSingleton sInstance;
public static DoubleCheckedLockingSingleton getInstance() {
if (sInstance == null) {
synchronized (DoubleCheckedLockingSingleton.class) {
if (sInstance == null) {
sInstance = new DoubleCheckedLockingSingleton();
}
}
}
import org.reactivestreams.Publisher;
import io.reactivex.Flowable;
import io.reactivex.FlowableTransformer;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.ObservableTransformer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
public void openEmailAppsChooser() {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
Intent chooser = Intent.createChooser(intent, "test1");
if(intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
}
@andreikastsiuk
andreikastsiuk / notificationIcon.java
Created September 24, 2018 14:22
Fixed Push Notification Icon showing White Android
Notification notification = new NotificationCompat.Builder(this);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
notification.setSmallIcon(R.drawable.icon_transperent);
notification.setColor(getResources().getColor(R.color.notification_color));
} else {
notification.setSmallIcon(R.drawable.icon);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
((ViewGroup) findViewById(R.id.llRoot)).getLayoutTransition()
.enableTransitionType(LayoutTransition.CHANGING);
}
@andreikastsiuk
andreikastsiuk / ArchLifecycleApp.kt
Created October 8, 2018 14:16
Getting an event when app is in background/foreground
class ArchLifecycleApp : Application(), LifecycleObserver {
override fun onCreate() {
super.onCreate()
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
}
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun onAppBackgrounded() {
Log.d("TAG", "App in background")