Commit 9f191e2e authored by Jeremy JAMET's avatar Jeremy JAMET

Refactor BootUpActivity

parent fcff6d6d
......@@ -39,7 +39,7 @@ public class OverlayShowingService extends Service implements OnTouchListener, O
private int originalXPos;
private int originalYPos;
private boolean moving;
private WindowManager wm;
private WindowManager windowManager;
private boolean lockedButton;
......@@ -61,7 +61,7 @@ public class OverlayShowingService extends Service implements OnTouchListener, O
boolean isAtRight = preferences.getBoolean(getString(R.string.settings_floating_button_position_key), true);
lockedButton = preferences.getBoolean(getString(R.string.settings_floating_button_lock_key), false);
wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
overlayedButton = new ImageView(this);
@ColorRes int color = preferences.getInt(getString(R.string.settings_colors_key), ContextCompat.getColor(this, R.color.colorPrimary));
......@@ -98,7 +98,7 @@ public class OverlayShowingService extends Service implements OnTouchListener, O
yPositionToSave = preferences.getInt(Y_POSITION_PREFERENCE_KEY, 0);
params.y = yPositionToSave;
}
wm.addView(overlayedButton, params);
windowManager.addView(overlayedButton, params);
topLeftView = new View(this);
LayoutParams topLeftParams =
......@@ -116,7 +116,7 @@ public class OverlayShowingService extends Service implements OnTouchListener, O
topLeftParams.y = 0;
topLeftParams.width = 0;
topLeftParams.height = 0;
wm.addView(topLeftView, topLeftParams);
windowManager.addView(topLeftView, topLeftParams);
}
}
......@@ -172,7 +172,7 @@ public class OverlayShowingService extends Service implements OnTouchListener, O
params.y = newY - (topLeftLocationOnScreen[1]);
yPositionToSave = params.y;
wm.updateViewLayout(overlayedButton, params);
windowManager.updateViewLayout(overlayedButton, params);
moving = true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
saveYPreferencePosition();
......@@ -200,8 +200,8 @@ public class OverlayShowingService extends Service implements OnTouchListener, O
if (overlayedButton != null) {
saveYPreferencePosition();
wm.removeView(overlayedButton);
wm.removeView(topLeftView);
windowManager.removeView(overlayedButton);
windowManager.removeView(topLeftView);
overlayedButton = null;
topLeftView = null;
}
......
......@@ -6,19 +6,22 @@ import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Settings;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import com.kunzisoft.keyboard.switcher.KeyboardNotificationService;
import com.kunzisoft.keyboard.switcher.OverlayShowingService;
import com.kunzisoft.keyboard.switcher.R;
import androidx.appcompat.app.AppCompatActivity;
/**
* Utility class to show keyboard button at startup
*/
public class BootUpActivity extends AppCompatActivity{
private Intent floatingButtonService;
private void startFloatingButtonService() {
Intent floatingButtonService = new Intent(this, OverlayShowingService.class);
startService(floatingButtonService);
}
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -32,24 +35,17 @@ public class BootUpActivity extends AppCompatActivity{
}
if (preferences.getBoolean(getString(R.string.settings_floating_button_key), false)) {
floatingButtonService = new Intent(this, OverlayShowingService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkDrawOverlayPermission();
if (Settings.canDrawOverlays(getApplicationContext())) {
startFloatingButtonService();
}
finish();
} else {
startService(floatingButtonService);
startFloatingButtonService();
finish();
}
} else {
finish();
}
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void checkDrawOverlayPermission() {
/* Do nothing here if not permitted */
if (Settings.canDrawOverlays(getApplicationContext())) {
startService(floatingButtonService);
}
finish();
}
}
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