All Projects → emreeran → Locationlivedata

emreeran / Locationlivedata

A simple LiveData implementation of Android Location API

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Locationlivedata

Indoorgps
Position Calculating with Trilateration via Bluetooth Beacons(Estimote)
Stars: ✭ 59 (-27.16%)
Mutual labels:  location
Aacomponents
基于google Android Architecture Components 封装实现组件式MVP快速开发框架
Stars: ✭ 66 (-18.52%)
Mutual labels:  livedata
Elements
⚒ Modular components for RecyclerView development enforcing clean, reusable and testable code, with built-in support for paging and complex hierarchies of data.
Stars: ✭ 75 (-7.41%)
Mutual labels:  livedata
Jetpackmvvm
🐔🏀一个Jetpack结合MVVM的快速开发框架,基于MVVM模式集成谷歌官方推荐的JetPack组件库:LiveData、ViewModel、Lifecycle、Navigation组件 使用Kotlin语言,添加大量拓展函数,简化代码 加入Retrofit网络请求,协程,帮你简化各种操作,让你快速开发项目
Stars: ✭ 1,100 (+1258.02%)
Mutual labels:  livedata
Moviefinderusingmvvm Android
🔥 MVVM + Clean Architecture + Best Practices | 🍿Movie Finder is a sample Android application 📱to search movies using OMDb API which is built to demonstrate use of Modern Android development tools - (Kotlin, Coroutines, Kodein, Architecture Components, MVVM, Retrofit, Gson, Material Components) 😊😊😉
Stars: ✭ 66 (-18.52%)
Mutual labels:  livedata
Android Mvvm Rx3 Dagger2 Navcomponent
Implemented using MVVM, LiveData, Room, RX3, Dagger2, Coil, View Binding, Navigation Component and AndroidX
Stars: ✭ 72 (-11.11%)
Mutual labels:  livedata
Retrokotlin
Simple Android app to show how unit testing with MockWebServer and Architecture Components (ViewModel + LiveData)
Stars: ✭ 55 (-32.1%)
Mutual labels:  livedata
Locationhelper
Android library project that helps you to track user location and manage the updates.
Stars: ✭ 79 (-2.47%)
Mutual labels:  location
Easychatandroidclient
EasyChat是一个开源的社交类的App。主要包含消息、好友、群组等相关的IM核心功能。部分界面参照了QQ、微信等相关社交APP。EasyChat APP整体采用MVVM模式,基于JetPack(Lifecycle,LiveData,ViewModel,Room)构建
Stars: ✭ 64 (-20.99%)
Mutual labels:  livedata
React Hook Mighty Mouse
🐭 React hook that tracks mouse events on selected element - zero dependencies
Stars: ✭ 75 (-7.41%)
Mutual labels:  location
Hal
🔴 A non-deterministic finite-state machine for Android & JVM that won't let you down
Stars: ✭ 63 (-22.22%)
Mutual labels:  livedata
Githubprojectbrowser
This is a sample Android Project that is based on Clean Architecture
Stars: ✭ 64 (-20.99%)
Mutual labels:  livedata
Dagger2 Sample
A sample app to demo how to implement dagger in Android using Dagger Android Support library
Stars: ✭ 72 (-11.11%)
Mutual labels:  livedata
Blazerat
🔥 Control your Linux home computer with telegram bot.
Stars: ✭ 60 (-25.93%)
Mutual labels:  location
P5.geolocation
a geolocation and geofencing library for p5.js
Stars: ✭ 75 (-7.41%)
Mutual labels:  location
Tdcapp
Sample app which access the TDC (The Developer's Conference) REST API.
Stars: ✭ 55 (-32.1%)
Mutual labels:  livedata
Kotlin Pokedex
🌀 A Pokedex app using ViewModel, LiveData, Room and Navigation
Stars: ✭ 1,156 (+1327.16%)
Mutual labels:  livedata
Price Tracker
Price Tracking Application - An experimental Kotlin Android project with complex android app requirements.
Stars: ✭ 80 (-1.23%)
Mutual labels:  livedata
Ktarmor
👻 Android快速开发框架, KtArmor 寓意着 为Android 赋予战斗装甲, 方便开发者快速进行Android 开发。
Stars: ✭ 76 (-6.17%)
Mutual labels:  livedata
Dodo
React Native location sdk based on amap.
Stars: ✭ 72 (-11.11%)
Mutual labels:  location

LocationLiveData

Android Arsenal

A simple LiveData implementation of Android Location API.

Uses FusedLocationProviderClient as location client.

For more information on LiveData refer to this link.

Setup

Add repository

repositories {
    maven {
        url  "https://dl.bintray.com/emre/maven"
    }
}

Add lifecycle and locationlivedata to your dependencies:

dependencies {

    implementation "androidx.lifecycle:lifecycle-runtime:2.0.0-rc01"
    implementation "androidx.lifecycle:lifecycle-extensions:2.0.0-rc01"
    implementation "androidx.lifecycle:lifecycle-common-java8:2.0.0-rc01"
    kapt "androidx.lifecycle:lifecycle-compiler:2.0.0-rc01"

    implementation "com.emreeran.locationlivedata:locationlivedata:1.0.4"

    ...
}

Add location permissions to your manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.emreeran.locationlivedata">

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

    ...

</manifest>

Usage

Create LocationLiveData instance and start observing. All parameter except context are optional. Uses defaults of LocationRequest if not specified.

In Kotlin:

val locationLiveData = LocationLiveData.create(
        context,
        interval = 500,
        priority = LocationRequest.PRIORITY_HIGH_ACCURACY,
        expirationTime = 10000,
        fastestInterval = 100,
        maxWaitTime = 1000,
        numUpdates = 10,
        smallestDisplacement = 10f,
        onErrorCallback = object : LocationLiveData.OnErrorCallback {
            override fun onLocationSettingsException(e: ApiException) {
                if (e is ResolvableApiException){
                    // Location settings are not satisfied, but this can be fixed
                    // by showing the user a dialog.
                    try {
                        // Show the dialog by calling startResolutionForResult(),
                        // and check the result in onActivityResult().
                        e.startResolutionForResult([email protected], REQUEST_CHECK_SETTINGS)
                    } catch (sendEx: IntentSender.SendIntentException) {
                        // Ignore the error.
                    }
                }
            }

            override fun onPermissionsMissing() {
                // Show message
            }
        }
)

locationLiveData.observe(this, Observer {   // Where this is a lifecycle owner
    // Do something with location update
    currentLocation = it
})

In Java:

LocationLiveData locationLiveData = LocationLiveData.create(
        application,
        500L,                                       // Interval
        100L,                                       // Fastest interval
        LocationRequest.PRIORITY_HIGH_ACCURACY,     // Priority
        10F,                                        // Smallest displacement
        10000L,                                     // Expiration time
        10000L,                                     // Max wait time
        10,                                         // Number of updates
        new LocationLiveData.OnErrorCallback() {    // Error callbacks
            @Override
            public void onLocationSettingsException(@NotNull ApiException e) {
                if (e instanceof ResolvableApiException) {
                    // Location settings are not satisfied, but this can be fixed
                    // by showing the user a dialog.
                    try {
                        // Show the dialog by calling startResolutionForResult(),
                        // and check the result in onActivityResult().
                        ResolvableApiException resolvable = (ResolvableApiException) e;
                        resolvable.startResolutionForResult(MainActivity.this,
                                REQUEST_CHECK_SETTINGS);
                    } catch (IntentSender.SendIntentException sendEx) {
                        // Ignore the error.
                    }
                }
            }

            @Override
            public void onPermissionsMissing() {
                // Show message
            }
        }
);

locationLiveData.observe(this, (Observer<Location>) location -> {
        // Do something with location update
        currentLocation = location
});

License

Copyright 2018 Emre Eran

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements.  See the NOTICE file distributed with this work for
additional information regarding copyright ownership.  The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License.  You may obtain a copy of
the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
License for the specific language governing permissions and limitations under
the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].