davinci: parts: Add a warning dialog for manual calibrations
Change-Id: Id764e1cbe1a8c535c0039938097465d9a0dcd02b
This commit is contained in:
parent
cf282db685
commit
d738bb5729
28
parts/res/layout/popup_calibration_warning.xml
Normal file
28
parts/res/layout/popup_calibration_warning.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2020 The LineageOS Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="8dp">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/popup_calibration_warning_hide"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/popup_calibration_warning_hide" />
|
||||
</LinearLayout>
|
@ -28,6 +28,9 @@
|
||||
<string name="popup_sound_cangmen">Cabin door</string>
|
||||
<string name="popup_calibration_title">Calibration</string>
|
||||
<string name="popup_calibration_summary">Calibrate the popup camera motor</string>
|
||||
<string name="popup_calibration_warning_title">Motor calibration</string>
|
||||
<string name="popup_calibration_warning_text">Unnecessary use of calibration may cause permanent damage. It is recommended to calibrate the popup camera motor only in case of it not moving properly or it being in incorrect position!</string>
|
||||
<string name="popup_calibration_warning_hide">Do not show again</string>
|
||||
|
||||
<!-- Popup camera strings -->
|
||||
<string name="popup_camera_tip">Warning</string>
|
||||
|
@ -16,8 +16,16 @@
|
||||
|
||||
package org.lineageos.settings.popupcamera;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
@ -59,9 +67,48 @@ public class PopupCameraSettingsFragment extends PreferenceFragment
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (MOTOR_CALIBRATION_KEY.equals(preference.getKey())) {
|
||||
SharedPreferences prefs = getActivity().getSharedPreferences(
|
||||
MOTOR_CALIBRATION_KEY, Activity.MODE_PRIVATE);
|
||||
if (!prefs.getBoolean("popup_calibration_warning_hidden", false)) {
|
||||
MotorCalibrationWarningDialog fragment = new MotorCalibrationWarningDialog();
|
||||
fragment.show(getFragmentManager(), "motor_calibration_warning_dialog");
|
||||
} else {
|
||||
mPopupCameraService.calibrateMotor();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private class MotorCalibrationWarningDialog extends DialogFragment {
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
View view = getActivity().getLayoutInflater().inflate(
|
||||
R.layout.popup_calibration_warning, null);
|
||||
CheckBox hideDialog = (CheckBox) view.findViewById(R.id.popup_calibration_warning_hide);
|
||||
|
||||
hideDialog.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
||||
getActivity()
|
||||
.getSharedPreferences(MOTOR_CALIBRATION_KEY, Activity.MODE_PRIVATE)
|
||||
.edit()
|
||||
.putBoolean("popup_calibration_warning_hidden", isChecked)
|
||||
.commit();
|
||||
}
|
||||
});
|
||||
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.popup_calibration_warning_title)
|
||||
.setMessage(R.string.popup_calibration_warning_text)
|
||||
.setView(view)
|
||||
.setPositiveButton(R.string.popup_camera_calibrate_now,
|
||||
(dialog, which) -> {
|
||||
mPopupCameraService.calibrateMotor();
|
||||
dialog.cancel();
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.cancel())
|
||||
.create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user