Commit ddcb73aa authored by Jeremy JAMET's avatar Jeremy JAMET

Add lock floating button feature

parent b7c501ab
......@@ -40,6 +40,8 @@ public class OverlayShowingService extends Service implements OnTouchListener, O
private boolean moving;
private WindowManager wm;
private boolean lockedButton;
@Override
public IBinder onBind(Intent intent) {
return null;
......@@ -55,7 +57,8 @@ public class OverlayShowingService extends Service implements OnTouchListener, O
if (preferences.getBoolean(getString(R.string.settings_floating_button_key), false)) {
// check Button Position
boolean isAtRight = preferences.getBoolean(getString(R.string.settings_position_button_key), true);
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);
......@@ -134,9 +137,11 @@ public class OverlayShowingService extends Service implements OnTouchListener, O
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
float y = event.getRawY();
float y = 0;
if (!lockedButton)
y = event.getRawY();
if (event.getAction() == MotionEvent.ACTION_DOWN) {
moving = false;
getPositionOnScreen();
......@@ -148,8 +153,6 @@ public class OverlayShowingService extends Service implements OnTouchListener, O
int[] topLeftLocationOnScreen = new int[2];
topLeftView.getLocationOnScreen(topLeftLocationOnScreen);
float y = event.getRawY();
WindowManager.LayoutParams params = (LayoutParams) overlayedButton.getLayoutParams();
int newX = (int) (offsetX);
......
......@@ -24,7 +24,7 @@ public class PreferenceFragment extends ChromaPreferenceFragmentCompat
/* https://stackoverflow.com/questions/7569937/unable-to-add-window-android-view-viewrootw44da9bc0-permission-denied-for-t
code to post/handler request for permission
*/
public final static int REQUEST_CODE = 6517;
private final static int REQUEST_CODE = 6517;
private Intent notificationService;
private Intent floatingButtonService;
......@@ -40,11 +40,10 @@ public class PreferenceFragment extends ChromaPreferenceFragmentCompat
notificationService = new Intent(getActivity(), KeyboardNotificationService.class);
// add listeners for non-default actions
Preference preference = findPreference(getString(R.string.settings_ime_available_key));
preference.setOnPreferenceClickListener(this);
preference = findPreference(getString(R.string.settings_ime_change_key));
preference.setOnPreferenceClickListener(this);
findPreference(getString(R.string.settings_ime_available_key))
.setOnPreferenceClickListener(this);
findPreference(getString(R.string.settings_ime_change_key))
.setOnPreferenceClickListener(this);
preferenceNotification = (SwitchPreference) findPreference(getString(R.string.settings_notification_key));
preferenceNotification.setOnPreferenceChangeListener(this);
......@@ -52,8 +51,10 @@ public class PreferenceFragment extends ChromaPreferenceFragmentCompat
preferenceFloatingButton = (SwitchPreference) findPreference(getString(R.string.settings_floating_button_key));
preferenceFloatingButton.setOnPreferenceChangeListener(this);
preference = findPreference(getString(R.string.settings_position_button_key));
preference.setOnPreferenceChangeListener(this);
findPreference(getString(R.string.settings_floating_button_position_key))
.setOnPreferenceChangeListener(this);
findPreference(getString(R.string.settings_floating_button_lock_key))
.setOnPreferenceChangeListener(this);
}
@Override
......@@ -111,11 +112,18 @@ public class PreferenceFragment extends ChromaPreferenceFragmentCompat
}
}
if (preference.getKey().equals(getString(R.string.settings_position_button_key))) {
if (preference.getKey().equals(getString(R.string.settings_floating_button_position_key))) {
SwitchPreference switchPreference = (SwitchPreference) preference;
switchPreference.setChecked((Boolean) newValue);
restartFloatingButtonService();
}
if (preference.getKey().equals(getString(R.string.settings_floating_button_lock_key))) {
SwitchPreference switchPreference = (SwitchPreference) preference;
switchPreference.setChecked((Boolean) newValue);
restartFloatingButtonService();
}
return false;
}
......
......@@ -39,9 +39,11 @@ In these cases, the application may be superfluous.</string>
<string name="floating_button_warning">This feature may be unstable in last versions of Android (Lollipop 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_position_button_key" translatable="false">settings_position_button_key</string>
<string name="settings_position_button_title">Button position</string>
<string name="settings_position_button_description">Button position at right</string>
<string name="settings_floating_button_position_key" translatable="false">settings_floating_button_position_key</string>
<string name="settings_floating_button_position_title">Button position</string>
<string name="settings_floating_button_lock_key" translatable="false">settings_floating_button_lock_key</string>
<string name="settings_floating_button_lock_title">Lock button</string>
<string name="settings_colors_key" translatable="false">settings_colors_key</string>
<string name="settings_colors_title">Button colors</string>
......
......@@ -34,10 +34,15 @@
android:title="@string/settings_floating_button_title"
android:defaultValue="false"/>
<SwitchPreference
android:key="@string/settings_position_button_key"
android:title="@string/settings_position_button_title"
android:key="@string/settings_floating_button_position_key"
android:title="@string/settings_floating_button_position_title"
android:dependency="@string/settings_floating_button_key"
android:defaultValue="true"/>
<SwitchPreference
android:key="@string/settings_floating_button_lock_key"
android:title="@string/settings_floating_button_lock_title"
android:dependency="@string/settings_floating_button_key"
android:defaultValue="false"/>
<com.kunzisoft.androidclearchroma.ChromaPreferenceCompat
xmlns:chroma="http://schemas.android.com/apk/res-auto"
android:key="@string/settings_colors_key"
......
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