Home

Awesome

GPS Status

中文看这里

Download

Add it in your build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Add the dependency in the form:

dependencies {
    compile 'com.github.hzw1199:AndroidGpsStatus:1.2'
}

Features

Usage

Layout

GpsStatusTextView

<com.adam.gpsstatus.GpsStatusTextView
    android:id="@+id/gpsText"
    android:layout_width="wrap_content"
    android:layout_height="48dp"
    android:text="GPS"
    android:textSize="24sp"
    android:textStyle="bold"
    android:gravity="center_vertical"
    app:colorClosed="@color/gps_icon_red"
    app:colorFixed="@color/gps_icon_green"
    app:colorUnFixed="@color/gps_icon_yellow"/>
Attributeformatdescribedefault
colorClosedcolortext color while GPS is closed#F44336
colorFixedcolortext color while GPS is fixed#4CAF50
colorUnFixedcolortext color while GPS is searching satellites#F4B400

GpsStatusImageView

<com.adam.gpsstatus.GpsStatusImageView
    android:id="@+id/gpsImage"
    android:layout_width="48dp"
    android:layout_height="48dp"
    app:drawable0="@drawable/ic_gps_0_24dp"
    app:drawable1="@drawable/ic_gps_1_24dp"
    app:drawable2="@drawable/ic_gps_2_24dp"
    app:drawable3="@drawable/ic_gps_3_24dp"
    app:thr_1_2="4"
    app:thr_2_3="7" />
Attributeformatdescribedefault
drawable0referencedrawable while GPS closedic_gps_0_24dp
drawable1referencedrawable while GPS signal is weakic_gps_1_24dp
drawable2referencedrawable while GPS signal is mediumic_gps_2_24dp
drawable3referencedrawable while GPS signal is strongic_gps_3_24dp
thr_1_2integerthreshold of satellite number from weak to medium4
thr_2_3integerthreshold of satellite number from medium to strong7

Set Up

You only need to define GpsStatusTextView or GpsStatusImageView in layout, but still need to do the following in the code:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
GpsStatusProxy proxy;
proxy = GpsStatusProxy.getInstance(getApplicationContext());
proxy.register();
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, listener);
LocationListener listener = new LocationListener() {
    @Override
    public void onLocationChanged(Location location) {
        proxy.notifyLocation(location);
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }

    @Override
    public void onProviderEnabled(String provider) {

    }

    @Override
    public void onProviderDisabled(String provider) {

    }
};
proxy.unRegister();

License

The MIT License (MIT)

Copyright (c) 2017 AndroidGpsStatus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.