4 Commits
Author SHA1 Message Date
adolfintel 21db852661 Release Alpha 3 2019-03-18 12:10:38 +01:00
adolfintel c11e261bba Aesthetic changes 2019-03-18 12:07:15 +01:00
adolfintel cff007f161 Added warning if location disabled 2019-03-16 10:48:05 +01:00
adolfintel 18be725cf3 Improved looks of notification 2019-03-15 19:31:09 +01:00
12 changed files with 152 additions and 15 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 59 KiB

+2 -2
View File
@@ -6,8 +6,8 @@ android {
applicationId "com.dosse.airpods"
minSdkVersion 23
targetSdkVersion 28
versionCode 2
versionName '0.2'
versionCode 3
versionName '0.3'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
@@ -50,7 +50,7 @@ public class MainActivity extends AppCompatActivity {
PackageManager p = getPackageManager();
p.setComponentEnabledSetting(new ComponentName(MainActivity.this,MainActivity.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Toast.makeText(getApplicationContext(),getString(R.string.hideClicked), Toast.LENGTH_LONG).show();
try{getApplicationContext().openFileOutput("hidden",MODE_PRIVATE).close();}catch(Throwable t){}
finish();
}
});
}
@@ -13,12 +13,15 @@ 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;
import android.widget.RemoteViews;
import java.util.ArrayList;
@@ -159,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
@@ -172,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);
@@ -191,12 +198,31 @@ 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);
notificationBig.setImageViewResource(R.id.rightPodImg,rightStatus<=10?R.drawable.right_pod:R.drawable.right_pod_disconnected);
notificationBig.setImageViewResource(R.id.podCaseImg,caseStatus<=10?R.drawable.pod_case:R.drawable.pod_case_disconnected);
if(System.currentTimeMillis()-lastSeenConnected<TIMEOUT_CONNECTED) {
notificationBig.setViewVisibility(R.id.leftPodText, View.VISIBLE);
notificationBig.setViewVisibility(R.id.rightPodText, View.VISIBLE);
notificationBig.setViewVisibility(R.id.podCaseText, View.VISIBLE);
notificationBig.setViewVisibility(R.id.leftPodUpdating, View.INVISIBLE);
notificationBig.setViewVisibility(R.id.rightPodUpdating, View.INVISIBLE);
notificationBig.setViewVisibility(R.id.podCaseUpdating, View.INVISIBLE);
notificationSmall.setViewVisibility(R.id.leftPodText, View.VISIBLE);
notificationSmall.setViewVisibility(R.id.rightPodText, View.VISIBLE);
notificationSmall.setViewVisibility(R.id.podCaseText, View.VISIBLE);
notificationSmall.setViewVisibility(R.id.leftPodUpdating, View.INVISIBLE);
notificationSmall.setViewVisibility(R.id.rightPodUpdating, View.INVISIBLE);
notificationSmall.setViewVisibility(R.id.podCaseUpdating, View.INVISIBLE);
notificationBig.setTextViewText(R.id.leftPodText, (leftStatus <= 10 ? (leftStatus * 10) + "%" : "") + ((chargeL && leftStatus < 10) ? "+" : ""));
notificationBig.setTextViewText(R.id.rightPodText, (rightStatus <= 10 ? (rightStatus * 10) + "%" : "") + ((chargeR && rightStatus < 10) ? "+" : ""));
notificationBig.setTextViewText(R.id.podCaseText, (caseStatus <= 10 ? (caseStatus * 10) + "%" : "") + (chargeCase ? "+" : ""));
@@ -204,12 +230,18 @@ public class PodsService extends Service {
notificationSmall.setTextViewText(R.id.rightPodText, (rightStatus <= 10 ? (rightStatus * 10) + "%" : "") + (chargeR ? "+" : ""));
notificationSmall.setTextViewText(R.id.podCaseText, (caseStatus <= 10 ? (caseStatus * 10) + "%" : "") + (chargeCase ? "+" : ""));
}else{
notificationBig.setTextViewText(R.id.leftPodText, "");
notificationBig.setTextViewText(R.id.rightPodText, "");
notificationBig.setTextViewText(R.id.podCaseText, "");
notificationSmall.setTextViewText(R.id.leftPodText, "");
notificationSmall.setTextViewText(R.id.rightPodText, "");
notificationSmall.setTextViewText(R.id.podCaseText, "");
notificationBig.setViewVisibility(R.id.leftPodText, View.INVISIBLE);
notificationBig.setViewVisibility(R.id.rightPodText, View.INVISIBLE);
notificationBig.setViewVisibility(R.id.podCaseText, View.INVISIBLE);
notificationBig.setViewVisibility(R.id.leftPodUpdating, View.VISIBLE);
notificationBig.setViewVisibility(R.id.rightPodUpdating, View.VISIBLE);
notificationBig.setViewVisibility(R.id.podCaseUpdating, View.VISIBLE);
notificationSmall.setViewVisibility(R.id.leftPodText, View.INVISIBLE);
notificationSmall.setViewVisibility(R.id.rightPodText, View.INVISIBLE);
notificationSmall.setViewVisibility(R.id.podCaseText, View.INVISIBLE);
notificationSmall.setViewVisibility(R.id.leftPodUpdating, View.VISIBLE);
notificationSmall.setViewVisibility(R.id.rightPodUpdating, View.VISIBLE);
notificationSmall.setViewVisibility(R.id.podCaseUpdating, View.VISIBLE);
}
mNotifyManager.notify(1,mBuilder.build());
}
@@ -17,7 +17,7 @@
android:layout_height="120dp"
android:src="@drawable/tick"
android:layout_alignParentTop="true"
android:id="@+id/mainTick"
android:id="@+id/tick"
android:layout_marginBottom="24dp"
/>
<TextView
@@ -27,14 +27,21 @@
android:layout_marginBottom="24dp"
android:text="@string/main1"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
android:layout_below="@id/mainTick"
android:layout_below="@id/tick"
/>
<TextView
android:id="@+id/supportedDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:layout_below="@id/main1"
android:text="@string/supportedDevices" />
<TextView
android:id="@+id/main2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="80dp"
android:layout_below="@id/main1"
android:layout_marginBottom="24dp"
android:layout_below="@id/supportedDevices"
android:text="@string/main2" />
<Button
android:layout_width="wrap_content"
@@ -44,6 +51,7 @@
android:id="@+id/mainHide"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>
</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="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"
@@ -31,6 +32,16 @@
android:id="@+id/leftPodText"
/>
<ProgressBar
android:id="@+id/leftPodUpdating"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="18dp"
android:layout_below="@id/leftPodImg"
android:gravity="center"
android:indeterminate="true"
/>
</RelativeLayout>
<RelativeLayout
@@ -56,6 +67,16 @@
android:id="@+id/rightPodText"
/>
<ProgressBar
android:id="@+id/rightPodUpdating"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="18dp"
android:layout_below="@id/rightPodImg"
android:gravity="center"
android:indeterminate="true"
/>
</RelativeLayout>
<RelativeLayout
@@ -81,6 +102,16 @@
android:id="@+id/podCaseText"
/>
<ProgressBar
android:id="@+id/podCaseUpdating"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="18dp"
android:layout_below="@id/podCaseImg"
android:gravity="center"
android:indeterminate="true"
/>
</RelativeLayout>
</RelativeLayout>
@@ -31,6 +31,15 @@
android:id="@+id/leftPodText"
/>
<ProgressBar
android:id="@+id/leftPodUpdating"
style="?android:attr/progressBarStyle"
android:layout_width="18dp"
android:layout_height="30dp"
android:layout_toRightOf="@id/leftPodImg"
android:indeterminate="true"
/>
</RelativeLayout>
<RelativeLayout
@@ -58,6 +67,15 @@
android:id="@+id/rightPodText"
/>
<ProgressBar
android:id="@+id/rightPodUpdating"
style="?android:attr/progressBarStyle"
android:layout_width="18dp"
android:layout_height="30dp"
android:layout_toRightOf="@id/rightPodImg"
android:indeterminate="true"
/>
</RelativeLayout>
<RelativeLayout
@@ -85,6 +103,15 @@
android:id="@+id/podCaseText"
/>
<ProgressBar
android:id="@+id/podCaseUpdating"
style="?android:attr/progressBarStyle"
android:layout_width="18dp"
android:layout_height="30dp"
android:layout_toRightOf="@id/podCaseImg"
android:indeterminate="true"
/>
</RelativeLayout>
@@ -8,4 +8,6 @@
<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>
<string name="supportedDevices">Dispositivi supportati:\n&#8226; Apple AirPods 1st gen</string>
</resources>
@@ -8,4 +8,6 @@
<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>
<string name="supportedDevices">Supported devices:\n&#8226; Apple AirPods 1st gen</string>
</resources>
+3
View File
@@ -14,6 +14,9 @@ The project is currently in Alpha.
* Respects your privacy
* Free and Open Source software
## Supported devices
* Apple AirPods 1st gen
## Project status
Right now, this project should be considered in alpha state. It was not extensively tested, it may not be stable or work at all on your device.