Commit 6f380d34 authored by Jeremy JAMET's avatar Jeremy JAMET

Fix disappear of floating button

parent d9476798
......@@ -12,8 +12,8 @@ import androidx.core.content.ContextCompat;
public class NotificationBuilder {
private static final String CHANNEL_ID_KEYBOARD = "com.kunzisoft.keyboard.notification.channel";
private static final String CHANNEL_NAME_KEYBOARD = "Keyboard switcher notification";
public static final String CHANNEL_ID_KEYBOARD = "com.kunzisoft.keyboard.notification.channel";
public static final String CHANNEL_NAME_KEYBOARD = "Keyboard switcher notification";
private NotificationManager mNotificationManager;
private int notificationId = 45;
......@@ -34,12 +34,12 @@ public class NotificationBuilder {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID_KEYBOARD)
.setSmallIcon(R.drawable.ic_notification_white_24dp)
.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
.setContentTitle(context.getString(R.string.notification_title))
.setContentTitle(context.getString(R.string.notification_keyboard_title))
.setAutoCancel(false)
.setOngoing(true)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
.setContentText(context.getString(R.string.notification_content_text))
.setContentText(context.getString(R.string.notification_keyboard_content_text))
.setContentIntent(Utilities.getPendingIntent(context, 500L)); // Trick 500ms delay to show th dialog
mNotificationManager.cancel(notificationId);
......
......@@ -21,9 +21,11 @@ import android.widget.ImageView;
import com.kunzisoft.keyboard.switcher.utils.Utilities;
import androidx.annotation.ColorRes;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static com.kunzisoft.keyboard.switcher.NotificationBuilder.CHANNEL_ID_KEYBOARD;
public class OverlayShowingService extends Service implements OnTouchListener, OnClickListener {
......@@ -53,6 +55,19 @@ public class OverlayShowingService extends Service implements OnTouchListener, O
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// To keep the service on top
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID_KEYBOARD)
.setSmallIcon(R.drawable.ic_notification_button_white_24dp)
.setColor(ContextCompat.getColor(this, R.color.colorPrimary))
.setContentTitle(getString(R.string.notification_floating_button_title))
.setContentText(getString(R.string.notification_floating_button_content_text))
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setVisibility(NotificationCompat.VISIBILITY_SECRET);
startForeground(56, builder.build());
}
preferences = PreferenceManager.getDefaultSharedPreferences(this);
if (preferences.getBoolean(getString(R.string.settings_floating_button_key), false)) {
......
......@@ -19,6 +19,10 @@ import androidx.appcompat.app.AppCompatActivity;
*/
public class BootUpActivity extends AppCompatActivity{
private void stopFloatingButtonService() {
stopService(new Intent(this, OverlayShowingService.class));
}
private void startFloatingButtonService() {
startService(new Intent(this, OverlayShowingService.class));
}
......@@ -35,6 +39,7 @@ public class BootUpActivity extends AppCompatActivity{
notificationBuilder.createKeyboardNotification(this);
}
stopFloatingButtonService();
if (preferences.getBoolean(getString(R.string.settings_floating_button_key), false)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Settings.canDrawOverlays(getApplicationContext())) {
......
......@@ -6,7 +6,6 @@ import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.text.Html;
import android.text.SpannableStringBuilder;
import com.kunzisoft.keyboard.switcher.R;
......@@ -47,9 +46,12 @@ public class WarningFloatingButtonDialog extends DialogFragment {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
stringBuilder.append(getString(R.string.floating_button_warning));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
stringBuilder.append("\n\n").append(getString(R.string.floating_button_notification_warning));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& !Settings.canDrawOverlays(getActivity())) {
stringBuilder.append("\n\n").append(Html.fromHtml(getString(R.string.floating_button_above_screen)));
stringBuilder.append("\n\n").append(getString(R.string.floating_button_above_screen));
}
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
......
......@@ -35,8 +35,7 @@ public class PreferenceActivity extends AppCompatActivity implements WarningFloa
if(preferenceFragment == null)
preferenceFragment = new PreferenceFragment();
Intent bootUpIntent = new Intent(this, BootUpActivity.class);
startActivity(bootUpIntent);
startActivity(new Intent(this, BootUpActivity.class));
getSupportFragmentManager()
.beginTransaction()
......
......@@ -226,13 +226,25 @@ public class PreferenceFragment extends ChromaPreferenceFragmentCompat
------ Floating Button Service ------
*/
private void stopFloatingButtonService() {
if (getActivity() != null) {
getActivity().stopService(new Intent(getActivity(), OverlayShowingService.class));
}
}
private void startFloatingButtonService() {
if (getActivity() != null) {
getActivity().startService(new Intent(getActivity(), OverlayShowingService.class));
Intent floatingButtonService = new Intent(getActivity(), OverlayShowingService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
getActivity().startForegroundService(floatingButtonService);
} else {
getActivity().startService(floatingButtonService);
}
}
}
void startFloatingButtonAndCheckButton() {
stopFloatingButtonService();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (drawOverlayPermissionAllowed()) {
startFloatingButtonService();
......@@ -248,9 +260,7 @@ public class PreferenceFragment extends ChromaPreferenceFragmentCompat
}
void stopFloatingButtonAndUncheckedButton() {
if (getActivity() != null) {
getActivity().stopService(new Intent(getActivity(), OverlayShowingService.class));
}
stopFloatingButtonService();
if (preferenceFloatingButton != null)
preferenceFloatingButton.setChecked(false);
}
......
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group>
<path
android:fillColor="#ffffff"
android:strokeWidth="0.9774369"
android:pathData="M 12 2 A 10 10 0 0 0 2 12 A 10 10 0 0 0 12 22 A 10 10 0 0 0 22 12 A 10 10 0 0 0
12 2 z M 6.5664062 8 L 15.433594 8 C 15.747452 8 16 8.2548956 16 8.5722656 L 16
9.6210938 L 14.757812 9.6210938 L 14.757812 9.4375 C 14.757814 9.34516 14.683117
9.2714844 14.591797 9.2714844 L 13.767578 9.2714844 C 13.676249 9.2714844
13.603516 9.3451 13.603516 9.4375 L 13.603516 9.6210938 L 12.642578 9.6210938 L
12.642578 9.4375 C 12.642578 9.34516 12.569836 9.2714844 12.478516 9.2714844 L
11.654297 9.2714844 C 11.562968 9.2714844 11.488281 9.3451 11.488281 9.4375 L
11.488281 9.6210938 L 10.333984 9.6210938 L 10.333984 9.4375 C 10.333984 9.34516
10.261242 9.2714844 10.169922 9.2714844 L 9.3457031 9.2714844 C 9.2543819
9.2714844 9.1816406 9.3451 9.1816406 9.4375 L 9.1816406 9.6210938 L 8.21875
9.6210938 L 8.21875 9.4375 C 8.21875 9.34516 8.1460085 9.2714844 8.0546875
9.2714844 L 7.2304688 9.2714844 C 7.1391474 9.2714844 7.0644531 9.3451 7.0644531
9.4375 L 7.0644531 10.271484 C 7.0644531 10.363804 7.1391478 10.439453 7.2304688
10.439453 L 7.6035156 10.439453 L 7.6035156 11.214844 L 7.4238281 11.214844 C
7.3325072 11.214844 7.2578125 11.290413 7.2578125 11.382812 L 7.2578125
12.216797 C 7.2578124 12.309217 7.3325071 12.382812 7.4238281 12.382812 L
7.6035156 12.382812 L 7.6035156 15 L 6.5664062 15 C 6.2525478 15 6 14.745094 6
14.427734 L 6 8.5722656 C 6 8.2548956 6.2525479 8 6.5664062 8 z M 8.5664062 10 L
17.433594 10 C 17.747452 10 18 10.254896 18 10.572266 L 18 16.427734 C 18
16.745104 17.747452 17 17.433594 17 L 8.5664062 17 C 8.252548 17 8 16.745104 8
16.427734 L 8 10.572266 C 8 10.254896 8.2525481 10 8.5664062 10 z M 9.3183594
11.361328 C 9.2270381 11.361328 9.1542969 11.434944 9.1542969 11.527344 L
9.1542969 12.359375 C 9.1542969 12.451725 9.2270384 12.527344 9.3183594
12.527344 L 10.142578 12.527344 C 10.233899 12.527344 10.308594 12.451775
10.308594 12.359375 L 10.308594 11.527344 C 10.308594 11.434894 10.233898
11.361328 10.142578 11.361328 L 9.3183594 11.361328 z M 11.433594 11.361328 C
11.342265 11.361328 11.269531 11.434944 11.269531 11.527344 L 11.269531
12.359375 C 11.269531 12.451725 11.342274 12.527344 11.433594 12.527344 L
12.257812 12.527344 C 12.349142 12.527344 12.421874 12.451775 12.421875
12.359375 L 12.421875 11.527344 C 12.421875 11.434894 12.349133 11.361328
12.257812 11.361328 L 11.433594 11.361328 z M 13.742188 11.361328 C 13.650858
11.361328 13.578126 11.434944 13.578125 11.527344 L 13.578125 12.359375 C
13.578125 12.451725 13.650867 12.527344 13.742188 12.527344 L 14.566406
12.527344 C 14.657735 12.527344 14.730469 12.451775 14.730469 12.359375 L
14.730469 11.527344 C 14.730469 11.434894 14.657726 11.361328 14.566406
11.361328 L 13.742188 11.361328 z M 15.857422 11.361328 C 15.766094 11.361328
15.691406 11.434944 15.691406 11.527344 L 15.691406 12.359375 C 15.691406
12.451725 15.766102 12.527344 15.857422 12.527344 L 16.681641 12.527344 C
16.772973 12.527344 16.845703 12.451775 16.845703 12.359375 L 16.845703
11.527344 C 16.845703 11.434894 16.772961 11.361328 16.681641 11.361328 L
15.857422 11.361328 z M 9.5117188 13.306641 C 9.4203977 13.306641 9.3457031
13.380256 9.3457031 13.472656 L 9.3457031 14.304688 C 9.3457031 14.397117
9.4203976 14.472656 9.5117188 14.472656 L 10.335938 14.472656 C 10.427264
14.472656 10.5 14.397087 10.5 14.304688 L 10.5 13.472656 C 10.5 13.380206
10.427257 13.306641 10.335938 13.306641 L 9.5117188 13.306641 z M 11.625
13.306641 C 11.533671 13.306641 11.460938 13.380256 11.460938 13.472656 L
11.460938 14.304688 C 11.460936 14.397117 11.53368 14.472656 11.625 14.472656 L
12.449219 14.472656 C 12.54055 14.472656 12.615234 14.397087 12.615234 14.304688
L 12.615234 13.472656 C 12.615234 13.380206 12.540539 13.306641 12.449219
13.306641 L 11.625 13.306641 z M 13.550781 13.306641 C 13.459459 13.306641
13.384766 13.380256 13.384766 13.472656 L 13.384766 14.304688 C 13.384766
14.397117 13.459461 14.472656 13.550781 14.472656 L 14.375 14.472656 C 14.466329
14.472656 14.539062 14.397087 14.539062 14.304688 L 14.539062 13.472656 C
14.539064 13.380206 14.46632 13.306641 14.375 13.306641 L 13.550781 13.306641 z
M 15.664062 13.306641 C 15.572736 13.306641 15.5 13.380256 15.5 13.472656 L 15.5
14.304688 C 15.5 14.397117 15.572743 14.472656 15.664062 14.472656 L 16.488281
14.472656 C 16.57961 14.472656 16.654297 14.397087 16.654297 14.304688 L
16.654297 13.472656 C 16.654297 13.380206 16.579601 13.306641 16.488281
13.306641 L 15.664062 13.306641 z M 10.308594 15.25 C 10.202049 15.25 10.115234
15.335619 10.115234 15.443359 L 10.115234 16.027344 C 10.115234 16.135114
10.202054 16.222656 10.308594 16.222656 L 15.691406 16.222656 C 15.797938
16.222656 15.884766 16.135074 15.884766 16.027344 L 15.884766 15.443359 C
15.884766 15.335579 15.797948 15.25 15.691406 15.25 L 10.308594 15.25 z" />
</group>
</vector>
\ No newline at end of file
......@@ -4,10 +4,8 @@
android:viewportHeight="24"
android:width="24dp"
android:height="24dp">
<group
android:translateY="-168">
<group
android:translateY="168">
<group>
<group>
<path
android:pathData="M2.9277344 5.0390625C2.4137914 5.0390625 2 5.4528469 2 5.9667969L2 15.447266C2 15.961206 2.4137914 16.375 2.9277344 16.375l1.6972656 0 0 -4.238281 -0.2949219 0c-0.149538 0 -0.2714844 -0.119991 -0.2714843 -0.269531l0 -1.34961c0 -0.14954 0.1219463 -0.271484 0.2714843 -0.271484l0.2949219 0 0 -1.2578128 -0.6113281 0c-0.149538 0 -0.2695313 -0.1219543 -0.2695313 -0.2714843l0 -1.3496094c0 -0.14954 0.1199933 -0.2695313 0.2695313 -0.2695313l1.3496093 0c0.149538 0 0.2714844 0.1199913 0.2714844 0.2695313l0 0.296875 1.5742188 0 0 -0.296875c0 -0.14954 0.1199932 -0.2695313 0.2695312 -0.2695313l1.3496094 0c0.149538 0 0.2695312 0.1199913 0.2695312 0.2695313l0 0.296875 1.8906248 0 0 -0.296875c0 -0.14954 0.119996 -0.2695313 0.269531 -0.2695313l1.34961 0c0.149538 0 0.269531 0.1199913 0.269531 0.2695313l0 0.296875 1.574219 0 0 -0.296875c0 -0.14954 0.119993 -0.2695313 0.269531 -0.2695313l1.349609 0c0.149538 0 0.271485 0.1199913 0.271485 0.2695313l0 0.296875 2.033203 0 0 -1.6972656c0 -0.51395 -0.413791 -0.9277344 -0.927734 -0.9277344l-14.5195316 0z"
android:fillColor="#ffffff"
......@@ -15,8 +13,7 @@
android:strokeLineCap="round"
android:strokeMiterLimit="4" />
</group>
<group
android:translateY="168">
<group>
<path
android:pathData="M6.5527344 8.6640625C6.0387914 8.6640625 5.625 9.0778539 5.625 9.5917969l0 9.4804691C5.625 19.586209 6.0387914 20 6.5527344 20L21.072266 20C21.586209 20 22 19.586209 22 19.072266L22 9.5917969C22 9.0778539 21.586209 8.6640625 21.072266 8.6640625l-14.5195316 0zm1.2304687 2.2031255l1.3496094 0c0.149538 0 0.2714844 0.119981 0.2714844 0.269531l0 1.349609c0 0.14953 -0.1219464 0.271484 -0.2714844 0.271484l-1.3496094 0c-0.1495379 0 -0.2695312 -0.121954 -0.2695312 -0.271484l0 -1.349609c0 -0.14955 0.1199933 -0.269531 0.2695312 -0.269531zm3.4648439 0l1.349609 0c0.149538 0 0.269532 0.119981 0.269532 0.269531l0 1.349609c-0.000002 0.14953 -0.119994 0.271484 -0.269532 0.271484l-1.349609 0c-0.149537 0 -0.269531 -0.121954 -0.269531 -0.271484l0 -1.349609c0 -0.14955 0.119994 -0.269531 0.269531 -0.269531zm3.779297 0l1.349609 0c0.149534 0 0.269531 0.119981 0.269531 0.269531l0 1.349609c0 0.14953 -0.119997 0.271484 -0.269531 0.271484l-1.349609 0c-0.149538 0 -0.269532 -0.121954 -0.269532 -0.271484l0 -1.349609c0.000002 -0.14955 0.119994 -0.269531 0.269532 -0.269531zm3.46289 0l1.34961 0c0.149541 0 0.271484 0.119981 0.271484 0.269531l0 1.349609c0 0.14953 -0.121943 0.271484 -0.271484 0.271484l-1.34961 0c-0.149539 0 -0.269531 -0.121954 -0.269531 -0.271484l0 -1.349609c0 -0.14955 0.119992 -0.269531 0.269531 -0.269531zm-10.3906246 3.15039l1.3496094 0c0.1495368 0 0.2695312 0.119981 0.2695312 0.269531l0 1.34961c0 0.14954 -0.1199943 0.269531 -0.2695312 0.269531l-1.3496094 0c-0.149538 0 -0.2714844 -0.119991 -0.2714844 -0.269531l0 -1.34961c0 -0.14955 0.1219464 -0.269531 0.2714844 -0.269531zm3.4628906 0l1.349609 0c0.149537 0 0.269532 0.119981 0.269532 0.269531l0 1.34961c0 0.14954 -0.119995 0.269531 -0.269532 0.269531l-1.349609 0c-0.149538 0 -0.269531 -0.119991 -0.269531 -0.269531l0 -1.34961c0 -0.14955 0.119993 -0.269531 0.269531 -0.269531zm3.150391 0l1.349609 0c0.14954 0 0.269531 0.119981 0.269531 0.269531l0 1.34961c0 0.14954 -0.119991 0.269531 -0.269531 0.269531l-1.349609 0c-0.149538 0 -0.271485 -0.119991 -0.271485 -0.269531l0 -1.34961c0 -0.14955 0.121947 -0.269531 0.271485 -0.269531zm3.46289 0l1.34961 0c0.14954 0 0.269531 0.119981 0.269531 0.269531l0 1.34961c0 0.14954 -0.119991 0.269531 -0.269531 0.269531l-1.34961 0c-0.149538 0 -0.269531 -0.119991 -0.269531 -0.269531l0 -1.34961c0 -0.14955 0.119993 -0.269531 0.269531 -0.269531zm-8.7714841 3.148438l8.8164061 0c0.174464 0 0.314453 0.139973 0.314453 0.314453l0 0.945312c0 0.17446 -0.139989 0.314453 -0.314453 0.314453l-8.8164061 0c-0.1744608 0 -0.3164063 -0.139993 -0.3164063 -0.314453l0 -0.945312c0 -0.17448 0.1419455 -0.314453 0.3164063 -0.314453z"
android:fillColor="#ffffff"
......
......@@ -6,8 +6,11 @@
<string name="hint_text_test">test area</string>
<string name="notification_title">Switch the keyboard</string>
<string name="notification_content_text">Tap to select the default keyboard.</string>
<string name="notification_keyboard_title">Switch the keyboard</string>
<string name="notification_keyboard_content_text">Tap to select the default keyboard.</string>
<string name="notification_floating_button_title">Keyboard button</string>
<string name="notification_floating_button_content_text">Keyboard floating button service activated.</string>
<string name="general">General</string>
......@@ -38,7 +41,8 @@
<string name="error_overlay_permission_request">Your system is not able to open the overlay permission request dialog.</string>
<string name="floating_button_warning">This feature may be unstable in last versions of Android (Lollipop and following).\n\nThe floating button may disappear if the system does not fully accept the \"Allow display over the app\" feature.</string>
<string name="floating_button_warning">This feature may be unstable in last versions of Android (Lollipop and following).</string>
<string name="floating_button_notification_warning">The display of an additional notification is essential to keep the button visible in your version of Android (O and following).</string>
<string name="floating_button_above_screen">You must accept the permissions to permit the floating button to be drawing over other apps.</string>
<string name="settings_floating_button_position_key" translatable="false">settings_floating_button_position_key</string>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment