Skip to content

Instantly share code, notes, and snippets.

// Don't forget to add the required permissions in your manifest file
fun gpsProvider() {
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)
}
fun networkProvider() {
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
@kostovtd
kostovtd / callbackFlow.kt
Created June 15, 2022 15:16
A dummy function which shows the usage of callbackFlow
fun myFunction(id: String): Flow<MyObject> =
callbackFlow {
firestoreEventListener = firestore.collection(MY_COLLECTION_PATH)
.document(id)
.addSnapshotListener { snapshot, _ ->
if (snapshot != null && snapshot.exists()) {
if (!snapshot.metadata.isFromCache) {
snapshot.toObject(MyFirestoreObject::class.java)?.let {
it.id = id
trySend(it)
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == REQUEST_PERMISSION) {
// for each permission check if the user granted/denied them
// you may want to group the rationale in a single dialog,
// this is just an example
for (int i = 0, len = permissions.length; i < len; i++) {
String permission = permissions[i];
if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
// user rejected the permission
private void writeObject(java.io.ObjectOutputStream out)
throws IOException;
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException;
private void readObjectNoData()
throws ObjectStreamException;
@kostovtd
kostovtd / Person.java
Created April 23, 2017 09:49
A Person POJO with Serializable interface.
import java.io.Serializable;
public class Person implements Serializable {
private String firstName;
private String lastName;
private int age;
public Person(String firstName, String lastName, int age) {
@kostovtd
kostovtd / Person.java
Created April 23, 2017 09:46
A Person POJO with Parcelable interface.
import android.os.Parcel;
import android.os.Parcelable;
public class Person implements Parcelable {
private String firstName;
private String lastName;
private int age;
<style name="CustomButtonStyleWaikawaGrey" parent="Theme.AppCompat">
<item name="colorButtonNormal">@color/waikawa_grey</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kostovtd.appshortcuts">
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- SETTINGS SHORTCUT -->
<shortcut
android:shortcutId="settings"
android:enabled="true"
android:shortcutShortLabel="@string/settings_shortcut_short_label"
android:shortcutLongLabel="@string/settings_shortcut_long_label"
android:shortcutDisabledMessage="@string/settings_shortcut_disabled_msg">
package com.kostovtd.appshortcuts;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;