mirror of
https://github.com/adolfintel/OpenPods.git
synced 2026-09-14 14:56:11 -04:00
Added warning if location disabled
This commit is contained in:
@@ -13,10 +13,12 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.os.ParcelUuid;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@@ -160,10 +162,16 @@ public class PodsService extends Service {
|
||||
private static final long TIMEOUT_CONNECTED=30000;
|
||||
private static boolean maybeConnected =true;
|
||||
private class NotificationThread extends Thread{
|
||||
private boolean isLocationEnabled(){
|
||||
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||
return service!=null&&service.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
||||
}
|
||||
public void run(){
|
||||
boolean notificationShowing=false;
|
||||
RemoteViews notificationBig=new RemoteViews(getPackageName(),R.layout.status_big);
|
||||
RemoteViews notificationSmall=new RemoteViews(getPackageName(),R.layout.status_small);
|
||||
RemoteViews locationDisabledBig=new RemoteViews(getPackageName(),R.layout.location_disabled_big);
|
||||
RemoteViews locationDisabledSmall=new RemoteViews(getPackageName(),R.layout.location_disabled_small);
|
||||
NotificationManager mNotifyManager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationCompat.Builder mBuilder=new NotificationCompat.Builder(PodsService.this,TAG);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { //on oreo and newer, create a notification channel
|
||||
@@ -173,8 +181,6 @@ public class PodsService extends Service {
|
||||
channel.setShowBadge(true);
|
||||
mNotifyManager.createNotificationChannel(channel);
|
||||
}
|
||||
mBuilder.setCustomContentView(notificationSmall);
|
||||
mBuilder.setCustomBigContentView(notificationBig);
|
||||
mBuilder.setShowWhen(false);
|
||||
mBuilder.setOngoing(true);
|
||||
mBuilder.setSmallIcon(R.drawable.left_pod);
|
||||
@@ -192,6 +198,13 @@ public class PodsService extends Service {
|
||||
mNotifyManager.cancel(1);
|
||||
}
|
||||
}
|
||||
if(isLocationEnabled()) {
|
||||
mBuilder.setCustomContentView(notificationSmall);
|
||||
mBuilder.setCustomBigContentView(notificationBig);
|
||||
}else{
|
||||
mBuilder.setCustomContentView(locationDisabledSmall);
|
||||
mBuilder.setCustomBigContentView(locationDisabledBig);
|
||||
}
|
||||
if(notificationShowing){
|
||||
if(ENABLE_LOGGING) Log.d(TAG,"Left: "+leftStatus+(chargeL?"+":"")+" "+"Right: "+rightStatus+(chargeR?"+":"")+" "+"Case: "+caseStatus+(chargeCase?"+":""));
|
||||
notificationBig.setImageViewResource(R.id.leftPodImg,leftStatus<=10?R.drawable.left_pod:R.drawable.left_pod_disconnected);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="120dp"
|
||||
android:padding="12dp"
|
||||
android:gravity="center"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:text="@string/locationDisabledText"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="70dp"
|
||||
android:padding="12dp"
|
||||
android:gravity="center"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:text="@string/locationDisabledText"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -6,6 +6,7 @@
|
||||
android:gravity="center"
|
||||
>
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -8,4 +8,5 @@
|
||||
<string name="mainHide">Nascondi app</string>
|
||||
<string name="hideClicked">L\'icona sarà rimossa presto</string>
|
||||
<string name="noBtText">Questo dispositivo non supporta Bluetooth LE</string>
|
||||
<string name="locationDisabledText">Attiva la posizione per permttere a OpenPods di leggere lo stato</string>
|
||||
</resources>
|
||||
@@ -8,4 +8,5 @@
|
||||
<string name="mainHide">Hide app</string>
|
||||
<string name="hideClicked">The icon will disappear soon</string>
|
||||
<string name="noBtText">It looks like this device doesn\'t have Bluetooth LE</string>
|
||||
<string name="locationDisabledText">You need to turn on Location to allow OpenPods to read the status</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user