sm6150-common: Strip popupcamera from parts
Change-Id: I379111b22be9062ee797979960feb3087299cffa
This commit is contained in:
parent
01ac282586
commit
302ce901c0
@ -14,10 +14,7 @@ android_app {
|
|||||||
privileged: true,
|
privileged: true,
|
||||||
|
|
||||||
static_libs: [
|
static_libs: [
|
||||||
"androidx.core_core",
|
|
||||||
"androidx.preference_preference",
|
|
||||||
"org.lineageos.settings.resources",
|
"org.lineageos.settings.resources",
|
||||||
"vendor.xiaomi.hardware.motor-V1.0-java",
|
|
||||||
],
|
],
|
||||||
|
|
||||||
optimize: {
|
optimize: {
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
android:sharedUserId="android.uid.system">
|
android:sharedUserId="android.uid.system">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
|
||||||
<protected-broadcast android:name="com.android.systemui.doze.pulse" />
|
<protected-broadcast android:name="com.android.systemui.doze.pulse" />
|
||||||
@ -46,10 +45,6 @@
|
|||||||
android:permission="XiaomiDozeService">
|
android:permission="XiaomiDozeService">
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service android:name=".popupcamera.PopupCameraService"
|
|
||||||
android:permission="PopupCameraService">
|
|
||||||
</service>
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".doze.DozeSettingsActivity"
|
android:name=".doze.DozeSettingsActivity"
|
||||||
android:label="@string/ambient_display_title"
|
android:label="@string/ambient_display_title"
|
||||||
@ -60,27 +55,5 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".popupcamera.PopupCameraSettingsActivity"
|
|
||||||
android:label="@string/popup_title"
|
|
||||||
android:theme="@style/Theme.Main">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="com.android.settings.action.IA_SETTINGS" />
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="com.android.settings.category"
|
|
||||||
android:value="com.android.settings.category.ia.system" />
|
|
||||||
<meta-data
|
|
||||||
android:name="com.android.settings.icon"
|
|
||||||
android:resource="@drawable/ic_settings_popup" />
|
|
||||||
<meta-data
|
|
||||||
android:name="com.android.settings.summary"
|
|
||||||
android:resource="@string/summary_empty" />
|
|
||||||
<meta-data
|
|
||||||
android:name="com.android.settings.order"
|
|
||||||
android:value="-255" />
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
-keep class org.lineageos.settings.doze.* {
|
-keep class org.lineageos.settings.doze.* {
|
||||||
*;
|
*;
|
||||||
}
|
}
|
||||||
|
|
||||||
-keep class org.lineageos.settings.popupcamera.* {
|
|
||||||
*;
|
|
||||||
}
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:height="24dp"
|
|
||||||
android:width="24dp"
|
|
||||||
android:tint="?android:attr/colorControlNormal"
|
|
||||||
android:viewportWidth="24"
|
|
||||||
android:viewportHeight="24">
|
|
||||||
<path android:fillColor="#000" android:pathData="M15.9,18.45C17.25,18.45 18.35,17.35 18.35,16C18.35,14.65 17.25,13.55 15.9,13.55C14.54,13.55 13.45,14.65 13.45,16C13.45,17.35 14.54,18.45 15.9,18.45M21.1,16.68L22.58,17.84C22.71,17.95 22.75,18.13 22.66,18.29L21.26,20.71C21.17,20.86 21,20.92 20.83,20.86L19.09,20.16C18.73,20.44 18.33,20.67 17.91,20.85L17.64,22.7C17.62,22.87 17.47,23 17.3,23H14.5C14.32,23 14.18,22.87 14.15,22.7L13.89,20.85C13.46,20.67 13.07,20.44 12.71,20.16L10.96,20.86C10.81,20.92 10.62,20.86 10.54,20.71L9.14,18.29C9.05,18.13 9.09,17.95 9.22,17.84L10.7,16.68L10.65,16L10.7,15.31L9.22,14.16C9.09,14.05 9.05,13.86 9.14,13.71L10.54,11.29C10.62,11.13 10.81,11.07 10.96,11.13L12.71,11.84C13.07,11.56 13.46,11.32 13.89,11.15L14.15,9.29C14.18,9.13 14.32,9 14.5,9H17.3C17.47,9 17.62,9.13 17.64,9.29L17.91,11.15C18.33,11.32 18.73,11.56 19.09,11.84L20.83,11.13C21,11.07 21.17,11.13 21.26,11.29L22.66,13.71C22.75,13.86 22.71,14.05 22.58,14.16L21.1,15.31L21.15,16L21.1,16.68M6.69,8.07C7.56,8.07 8.26,7.37 8.26,6.5C8.26,5.63 7.56,4.92 6.69,4.92A1.58,1.58 0 0,0 5.11,6.5C5.11,7.37 5.82,8.07 6.69,8.07M10.03,6.94L11,7.68C11.07,7.75 11.09,7.87 11.03,7.97L10.13,9.53C10.08,9.63 9.96,9.67 9.86,9.63L8.74,9.18L8,9.62L7.81,10.81C7.79,10.92 7.7,11 7.59,11H5.79C5.67,11 5.58,10.92 5.56,10.81L5.4,9.62L4.64,9.18L3.5,9.63C3.41,9.67 3.3,9.63 3.24,9.53L2.34,7.97C2.28,7.87 2.31,7.75 2.39,7.68L3.34,6.94L3.31,6.5L3.34,6.06L2.39,5.32C2.31,5.25 2.28,5.13 2.34,5.03L3.24,3.47C3.3,3.37 3.41,3.33 3.5,3.37L4.63,3.82L5.4,3.38L5.56,2.19C5.58,2.08 5.67,2 5.79,2H7.59C7.7,2 7.79,2.08 7.81,2.19L8,3.38L8.74,3.82L9.86,3.37C9.96,3.33 10.08,3.37 10.13,3.47L11.03,5.03C11.09,5.13 11.07,5.25 11,5.32L10.03,6.06L10.06,6.5L10.03,6.94Z"/>
|
|
||||||
</vector>
|
|
@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:height="24dp"
|
|
||||||
android:width="24dp"
|
|
||||||
android:tint="?android:attr/colorControlNormal"
|
|
||||||
android:viewportWidth="24"
|
|
||||||
android:viewportHeight="24">
|
|
||||||
<path android:fillColor="#000" android:pathData="M6,6.9L3.87,4.78L5.28,3.37L7.4,5.5L6,6.9M13,1V4H11V1H13M20.13,4.78L18,6.9L16.6,5.5L18.72,3.37L20.13,4.78M4.5,10.5V12.5H1.5V10.5H4.5M19.5,10.5H22.5V12.5H19.5V10.5M6,20H18A2,2 0 0,1 20,22H4A2,2 0 0,1 6,20M12,5A6,6 0 0,1 18,11V19H6V11A6,6 0 0,1 12,5M12,7A4,4 0 0,0 8,11V17H16V11A4,4 0 0,0 12,7Z" />
|
|
||||||
</vector>
|
|
@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:height="24dp"
|
|
||||||
android:width="24dp"
|
|
||||||
android:tint="?android:attr/colorControlNormal"
|
|
||||||
android:viewportWidth="24"
|
|
||||||
android:viewportHeight="24">
|
|
||||||
<path android:fillColor="#000" android:pathData="M14,3.23V5.29C16.89,6.15 19,8.83 19,12C19,15.17 16.89,17.84 14,18.7V20.77C18,19.86 21,16.28 21,12C21,7.72 18,4.14 14,3.23M16.5,12C16.5,10.23 15.5,8.71 14,7.97V16C15.5,15.29 16.5,13.76 16.5,12M3,9V15H7L12,20V4L7,9H3Z" />
|
|
||||||
</vector>
|
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:tint="?android:attr/colorControlNormal"
|
|
||||||
android:viewportWidth="24.0"
|
|
||||||
android:viewportHeight="24.0">
|
|
||||||
<path
|
|
||||||
android:fillColor="#FFFFFFFF"
|
|
||||||
android:pathData="M10,20L5,20v2h5v2l3,-3 -3,-3v2zM14,20v2h5v-2h-5zM12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -1.99,0.9 -1.99,2S10.9,8 12,8zM17,0L7,0C5.9,0 5,0.9 5,2v14c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2L19,2c0,-1.1 -0.9,-2 -2,-2zM7,2h10v10.5c0,-1.67 -3.33,-2.5 -5,-2.5s-5,0.83 -5,2.5L7,2z" />
|
|
||||||
</vector>
|
|
@ -1,52 +0,0 @@
|
|||||||
<?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.
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
<string-array name="popupcamera_effects_entries">
|
|
||||||
<item>@string/action_none</item>
|
|
||||||
<item>@string/popup_sound_muqin</item>
|
|
||||||
<item>@string/popup_sound_yingyan</item>
|
|
||||||
<item>@string/popup_sound_mofa</item>
|
|
||||||
<item>@string/popup_sound_jijia</item>
|
|
||||||
<item>@string/popup_sound_chilun</item>
|
|
||||||
<item>@string/popup_sound_cangmen</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array name="popupcamera_effects_names" translatable="false">
|
|
||||||
<item>popup_muqin_up.ogg</item>
|
|
||||||
<item>popup_muqin_down.ogg</item>
|
|
||||||
<item>popup_yingyan_up.ogg</item>
|
|
||||||
<item>popup_yingyan_down.ogg</item>
|
|
||||||
<item>popup_mofa_up.ogg</item>
|
|
||||||
<item>popup_mofa_down.ogg</item>
|
|
||||||
<item>popup_jijia_up.ogg</item>
|
|
||||||
<item>popup_jijia_down.ogg</item>
|
|
||||||
<item>popup_chilun_up.ogg</item>
|
|
||||||
<item>popup_chilun_down.ogg</item>
|
|
||||||
<item>popup_cangmen_up.ogg</item>
|
|
||||||
<item>popup_cangmen_down.ogg</item>
|
|
||||||
</string-array>
|
|
||||||
|
|
||||||
<string-array name="popupcamera_effects_values">
|
|
||||||
<item>-1</item>
|
|
||||||
<item>0</item>
|
|
||||||
<item>2</item>
|
|
||||||
<item>4</item>
|
|
||||||
<item>6</item>
|
|
||||||
<item>8</item>
|
|
||||||
<item>10</item>
|
|
||||||
</string-array>
|
|
||||||
</resources>
|
|
@ -1,42 +0,0 @@
|
|||||||
<?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.
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
<!-- Popup camera settings -->
|
|
||||||
<string name="popup_title">Front camera settings</string>
|
|
||||||
<string name="popup_led_title">Camera LED</string>
|
|
||||||
<string name="popup_led_summary">Enable LED light while the front camera appears and retracts</string>
|
|
||||||
<string name="popup_sound_title">Sound effects</string>
|
|
||||||
<string name="popup_sound_muqin">Xylophone</string>
|
|
||||||
<string name="popup_sound_yingyan">Condor</string>
|
|
||||||
<string name="popup_sound_mofa">Magic</string>
|
|
||||||
<string name="popup_sound_jijia">Mecha</string>
|
|
||||||
<string name="popup_sound_chilun">Gearwheel</string>
|
|
||||||
<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>
|
|
||||||
|
|
||||||
<!-- Popup camera strings -->
|
|
||||||
<string name="popup_camera_tip">Warning</string>
|
|
||||||
<string name="popup_camera_takeback_failed_calibrate">Couldn\'t close front camera. Try calibrating the motor.</string>
|
|
||||||
<string name="popup_camera_popup_failed_calibrate">Couldn\'t open front camera. Try calibrating the motor.</string>
|
|
||||||
<string name="popup_camera_calibrate_running">Front camera cannot be used during calibration.</string>
|
|
||||||
<string name="popup_camera_calibrate_now">Calibrate</string>
|
|
||||||
<string name="popup_camera_calibrate_failed">Couldn\'t calibrate</string>
|
|
||||||
<string name="popup_camera_calibrate_success">Calibrated successfully. You can open the front camera now.</string>
|
|
||||||
</resources>
|
|
@ -1,26 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:icon="@drawable/ic_popup_light"
|
|
||||||
android:key="popup_led_effect"
|
|
||||||
android:summary="@string/popup_led_summary"
|
|
||||||
android:title="@string/popup_led_title" />
|
|
||||||
|
|
||||||
<ListPreference
|
|
||||||
android:defaultValue="0"
|
|
||||||
android:entries="@array/popupcamera_effects_entries"
|
|
||||||
android:entryValues="@array/popupcamera_effects_values"
|
|
||||||
android:icon="@drawable/ic_popup_sound"
|
|
||||||
android:key="popup_sound_effect"
|
|
||||||
android:summary="%s"
|
|
||||||
android:title="@string/popup_sound_title" />
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="motor_calibration"
|
|
||||||
android:title="@string/popup_calibration_title"
|
|
||||||
android:summary="@string/popup_calibration_summary"
|
|
||||||
android:icon="@drawable/ic_popup_calibration" />
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
|
@ -23,7 +23,6 @@ import android.content.Intent;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.lineageos.settings.doze.DozeUtils;
|
import org.lineageos.settings.doze.DozeUtils;
|
||||||
import org.lineageos.settings.popupcamera.PopupCameraUtils;
|
|
||||||
|
|
||||||
public class BootCompletedReceiver extends BroadcastReceiver {
|
public class BootCompletedReceiver extends BroadcastReceiver {
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
@ -34,6 +33,5 @@ public class BootCompletedReceiver extends BroadcastReceiver {
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
Log.d(TAG, "Received boot completed intent");
|
Log.d(TAG, "Received boot completed intent");
|
||||||
DozeUtils.checkDozeService(context);
|
DozeUtils.checkDozeService(context);
|
||||||
PopupCameraUtils.startService(context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.lineageos.settings.popupcamera;
|
|
||||||
|
|
||||||
public class Constants {
|
|
||||||
public static final int FREE_FALL_SENSOR_ID = 33171042;
|
|
||||||
|
|
||||||
public static final int CAMERA_EVENT_DELAY_TIME = 100; // ms
|
|
||||||
public static final int MSG_CAMERA_CLOSED = 1001;
|
|
||||||
public static final int MSG_CAMERA_OPEN = 1002;
|
|
||||||
|
|
||||||
public static final int MOTOR_STATUS_POPUP_OK = 11;
|
|
||||||
public static final int MOTOR_STATUS_POPUP_JAMMED = 12;
|
|
||||||
public static final int MOTOR_STATUS_TAKEBACK_OK = 13;
|
|
||||||
public static final int MOTOR_STATUS_TAKEBACK_JAMMED = 14;
|
|
||||||
public static final int MOTOR_STATUS_PRESSED = 15;
|
|
||||||
public static final int MOTOR_STATUS_CALIB_OK = 17;
|
|
||||||
public static final int MOTOR_STATUS_CALIB_ERROR = 18;
|
|
||||||
public static final int MOTOR_STATUS_REQUEST_CALIB = 19;
|
|
||||||
|
|
||||||
public static final String CLOSE_CAMERA_STATE = "0";
|
|
||||||
public static final String OPEN_CAMERA_STATE = "1";
|
|
||||||
|
|
||||||
public static final String FRONT_CAMERA_ID = "1";
|
|
||||||
public static final String LEFT_LED_BREATH_PATH = "/sys/class/leds/left/breath";
|
|
||||||
public static final String LEFT_LED_PATH = "/sys/class/leds/left/brightness";
|
|
||||||
public static final String RIGHT_LED_PATH = "/sys/class/leds/right/brightness";
|
|
||||||
public static final String POPUP_SOUND_PATH = "/system/media/audio/ui/";
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.lineageos.settings.popupcamera;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
|
|
||||||
public class PopupCameraPreferences {
|
|
||||||
private static final String TAG = "PopupCameraUtils";
|
|
||||||
private static final boolean DEBUG = false;
|
|
||||||
private static final String LED_EFFECT_KEY = "popup_led_effect";
|
|
||||||
private static final boolean LED_EFFECT_DEFAULT_VALUE = true;
|
|
||||||
private static final String SOUND_EFFECT_KEY = "popup_sound_effect";
|
|
||||||
private static final String SOUND_EFFECT_DEFAULT_VALUE = "0";
|
|
||||||
private SharedPreferences mSharedPrefs;
|
|
||||||
|
|
||||||
public PopupCameraPreferences(Context context) {
|
|
||||||
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSoundEffect() {
|
|
||||||
return mSharedPrefs.getString(SOUND_EFFECT_KEY, SOUND_EFFECT_DEFAULT_VALUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLedAllowed() {
|
|
||||||
return mSharedPrefs.getBoolean(LED_EFFECT_KEY, LED_EFFECT_DEFAULT_VALUE);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,390 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.lineageos.settings.popupcamera;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Service;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.hardware.Sensor;
|
|
||||||
import android.hardware.SensorEvent;
|
|
||||||
import android.hardware.SensorEventListener;
|
|
||||||
import android.hardware.SensorManager;
|
|
||||||
import android.hardware.camera2.CameraManager;
|
|
||||||
import android.media.AudioAttributes;
|
|
||||||
import android.media.SoundPool;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.SystemClock;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.WindowManager;
|
|
||||||
|
|
||||||
import org.lineageos.settings.R;
|
|
||||||
import org.lineageos.settings.utils.FileUtils;
|
|
||||||
|
|
||||||
import vendor.xiaomi.hardware.motor.V1_0.IMotor;
|
|
||||||
import vendor.xiaomi.hardware.motor.V1_0.IMotorCallback;
|
|
||||||
import vendor.xiaomi.hardware.motor.V1_0.MotorEvent;
|
|
||||||
|
|
||||||
public class PopupCameraService extends Service implements Handler.Callback {
|
|
||||||
private static final String TAG = "PopupCameraService";
|
|
||||||
private static final boolean DEBUG = false;
|
|
||||||
|
|
||||||
private int[] mSounds;
|
|
||||||
private boolean mMotorBusy = false;
|
|
||||||
private long mClosedEvent;
|
|
||||||
private long mOpenEvent;
|
|
||||||
|
|
||||||
private Handler mHandler = new Handler(this);
|
|
||||||
private IMotor mMotor = null;
|
|
||||||
private IMotorCallback mMotorStatusCallback;
|
|
||||||
private boolean mMotorCalibrating = false;
|
|
||||||
private boolean mErrorDialogShowing;
|
|
||||||
private final Object mLock = new Object();
|
|
||||||
private PopupCameraPreferences mPopupCameraPreferences;
|
|
||||||
private SensorManager mSensorManager;
|
|
||||||
private Sensor mFreeFallSensor;
|
|
||||||
private SoundPool mSoundPool;
|
|
||||||
|
|
||||||
private CameraManager.AvailabilityCallback availabilityCallback =
|
|
||||||
new CameraManager.AvailabilityCallback() {
|
|
||||||
@Override
|
|
||||||
public void onCameraAvailable(@NonNull String cameraId) {
|
|
||||||
super.onCameraAvailable(cameraId);
|
|
||||||
if (cameraId.equals(Constants.FRONT_CAMERA_ID)) {
|
|
||||||
mClosedEvent = SystemClock.elapsedRealtime();
|
|
||||||
if (SystemClock.elapsedRealtime() - mOpenEvent
|
|
||||||
< Constants.CAMERA_EVENT_DELAY_TIME
|
|
||||||
&& mHandler.hasMessages(Constants.MSG_CAMERA_OPEN)) {
|
|
||||||
mHandler.removeMessages(Constants.MSG_CAMERA_OPEN);
|
|
||||||
}
|
|
||||||
mHandler.sendEmptyMessageDelayed(
|
|
||||||
Constants.MSG_CAMERA_CLOSED, Constants.CAMERA_EVENT_DELAY_TIME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCameraUnavailable(@NonNull String cameraId) {
|
|
||||||
super.onCameraAvailable(cameraId);
|
|
||||||
if (cameraId.equals(Constants.FRONT_CAMERA_ID)) {
|
|
||||||
mOpenEvent = SystemClock.elapsedRealtime();
|
|
||||||
if (SystemClock.elapsedRealtime() - mClosedEvent
|
|
||||||
< Constants.CAMERA_EVENT_DELAY_TIME
|
|
||||||
&& mHandler.hasMessages(Constants.MSG_CAMERA_CLOSED)) {
|
|
||||||
mHandler.removeMessages(Constants.MSG_CAMERA_CLOSED);
|
|
||||||
}
|
|
||||||
mHandler.sendEmptyMessageDelayed(
|
|
||||||
Constants.MSG_CAMERA_OPEN, Constants.CAMERA_EVENT_DELAY_TIME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private SensorEventListener mFreeFallListener = new SensorEventListener() {
|
|
||||||
@Override
|
|
||||||
public void onSensorChanged(SensorEvent event) {
|
|
||||||
if (event.values[0] == 2.0f) {
|
|
||||||
try {
|
|
||||||
mMotor.takebackMotorShortly();
|
|
||||||
mSensorManager.unregisterListener(mFreeFallListener, mFreeFallSensor);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
goBackHome();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
CameraManager cameraManager = getSystemService(CameraManager.class);
|
|
||||||
cameraManager.registerAvailabilityCallback(availabilityCallback, null);
|
|
||||||
mSensorManager = getSystemService(SensorManager.class);
|
|
||||||
mFreeFallSensor = mSensorManager.getDefaultSensor(Constants.FREE_FALL_SENSOR_ID);
|
|
||||||
mPopupCameraPreferences = new PopupCameraPreferences(this);
|
|
||||||
mSoundPool =
|
|
||||||
new SoundPool.Builder()
|
|
||||||
.setMaxStreams(1)
|
|
||||||
.setAudioAttributes(
|
|
||||||
new AudioAttributes.Builder()
|
|
||||||
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
|
|
||||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
|
||||||
.setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
|
|
||||||
.build())
|
|
||||||
.build();
|
|
||||||
String[] soundNames = getResources().getStringArray(R.array.popupcamera_effects_names);
|
|
||||||
mSounds = new int[soundNames.length];
|
|
||||||
for (int i = 0; i < soundNames.length; i++) {
|
|
||||||
mSounds[i] = mSoundPool.load(Constants.POPUP_SOUND_PATH + soundNames[i], 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mMotor = IMotor.getService();
|
|
||||||
int status = mMotor.getMotorStatus();
|
|
||||||
if (status == Constants.MOTOR_STATUS_POPUP_OK
|
|
||||||
|| status == Constants.MOTOR_STATUS_TAKEBACK_JAMMED) {
|
|
||||||
mMotor.takebackMotor(1);
|
|
||||||
Thread.sleep(1200);
|
|
||||||
}
|
|
||||||
mMotorStatusCallback = new MotorStatusCallback();
|
|
||||||
mMotor.setMotorCallback(mMotorStatusCallback);
|
|
||||||
} catch (InterruptedException | RemoteException e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class MotorStatusCallback extends IMotorCallback.Stub {
|
|
||||||
public MotorStatusCallback() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNotify(MotorEvent event) {
|
|
||||||
int status = event.vaalue;
|
|
||||||
int cookie = event.cookie;
|
|
||||||
if (DEBUG)
|
|
||||||
Log.d(TAG, "onNotify: cookie=" + cookie + ", status=" + status);
|
|
||||||
synchronized (mLock) {
|
|
||||||
if (status == Constants.MOTOR_STATUS_CALIB_OK
|
|
||||||
|| status == Constants.MOTOR_STATUS_CALIB_ERROR) {
|
|
||||||
showCalibrationResult(status);
|
|
||||||
} else if (status == Constants.MOTOR_STATUS_PRESSED) {
|
|
||||||
updateMotor(Constants.CLOSE_CAMERA_STATE);
|
|
||||||
goBackHome();
|
|
||||||
} else if (status == Constants.MOTOR_STATUS_POPUP_JAMMED
|
|
||||||
|| status == Constants.MOTOR_STATUS_TAKEBACK_JAMMED) {
|
|
||||||
showErrorDialog();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void calibrateMotor() {
|
|
||||||
synchronized (mLock) {
|
|
||||||
if (mMotorCalibrating)
|
|
||||||
return;
|
|
||||||
if (mMotor == null) {
|
|
||||||
try {
|
|
||||||
mMotor = IMotor.getService();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
if (mMotor == null)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
mMotorCalibrating = true;
|
|
||||||
mMotor.calibration();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
mHandler.postDelayed(() -> mMotorCalibrating = false, 7000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
||||||
if (DEBUG)
|
|
||||||
Log.d(TAG, "Starting service");
|
|
||||||
return START_STICKY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
if (DEBUG)
|
|
||||||
Log.d(TAG, "Destroying service");
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinder onBind(Intent intent) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateMotor(String cameraState) {
|
|
||||||
if (mMotor == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Runnable r = () -> {
|
|
||||||
mMotorBusy = true;
|
|
||||||
try {
|
|
||||||
int status = mMotor.getMotorStatus();
|
|
||||||
if (DEBUG)
|
|
||||||
Log.d(TAG, "updateMotor: status=" + status + ", cameraState=" + cameraState);
|
|
||||||
if (cameraState.equals(Constants.OPEN_CAMERA_STATE)
|
|
||||||
&& (status == Constants.MOTOR_STATUS_TAKEBACK_OK
|
|
||||||
|| status == Constants.MOTOR_STATUS_CALIB_OK)) {
|
|
||||||
lightUp();
|
|
||||||
playSoundEffect(Constants.OPEN_CAMERA_STATE);
|
|
||||||
mMotor.popupMotor(1);
|
|
||||||
mSensorManager.registerListener(
|
|
||||||
mFreeFallListener, mFreeFallSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
|
||||||
} else if (cameraState.equals(Constants.CLOSE_CAMERA_STATE)
|
|
||||||
&& status == Constants.MOTOR_STATUS_POPUP_OK) {
|
|
||||||
lightUp();
|
|
||||||
playSoundEffect(Constants.CLOSE_CAMERA_STATE);
|
|
||||||
mMotor.takebackMotor(1);
|
|
||||||
mSensorManager.unregisterListener(mFreeFallListener, mFreeFallSensor);
|
|
||||||
} else {
|
|
||||||
mMotorBusy = false;
|
|
||||||
if (status == Constants.MOTOR_STATUS_POPUP_JAMMED
|
|
||||||
|| status == Constants.MOTOR_STATUS_TAKEBACK_JAMMED
|
|
||||||
|| status == Constants.MOTOR_STATUS_CALIB_ERROR
|
|
||||||
|| status == Constants.MOTOR_STATUS_REQUEST_CALIB) {
|
|
||||||
showErrorDialog();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
mHandler.postDelayed(() -> mMotorBusy = false, 1200);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (mMotorBusy) {
|
|
||||||
mHandler.postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (mMotorBusy) {
|
|
||||||
mHandler.postDelayed(this, 100);
|
|
||||||
} else {
|
|
||||||
mHandler.post(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
} else {
|
|
||||||
mHandler.post(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void lightUp() {
|
|
||||||
if (mPopupCameraPreferences.isLedAllowed()) {
|
|
||||||
String ledBreathing = FileUtils.readOneLine(Constants.LEFT_LED_BREATH_PATH);
|
|
||||||
String ledBrightness = FileUtils.readOneLine(Constants.LEFT_LED_PATH);
|
|
||||||
|
|
||||||
FileUtils.writeLine(Constants.LEFT_LED_BREATH_PATH, "0");
|
|
||||||
FileUtils.writeLine(Constants.LEFT_LED_PATH, "255");
|
|
||||||
FileUtils.writeLine(Constants.RIGHT_LED_PATH, "255");
|
|
||||||
|
|
||||||
mHandler.postDelayed(() -> {
|
|
||||||
if (ledBreathing.equals("1")) {
|
|
||||||
FileUtils.writeLine(Constants.LEFT_LED_BREATH_PATH, ledBreathing);
|
|
||||||
} else {
|
|
||||||
FileUtils.writeLine(Constants.LEFT_LED_PATH, ledBrightness);
|
|
||||||
}
|
|
||||||
FileUtils.writeLine(Constants.RIGHT_LED_PATH, "0");
|
|
||||||
}, 1200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showCalibrationResult(int status) {
|
|
||||||
if (mErrorDialogShowing) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mErrorDialogShowing = true;
|
|
||||||
mHandler.post(() -> {
|
|
||||||
Resources res = getResources();
|
|
||||||
int dialogMessageResId = mMotorCalibrating
|
|
||||||
? R.string.popup_camera_calibrate_running
|
|
||||||
: (status == Constants.MOTOR_STATUS_CALIB_OK
|
|
||||||
? R.string.popup_camera_calibrate_success
|
|
||||||
: R.string.popup_camera_calibrate_failed);
|
|
||||||
AlertDialog.Builder alertDialogBuilder =
|
|
||||||
new AlertDialog.Builder(this, R.style.SystemAlertDialogTheme);
|
|
||||||
alertDialogBuilder.setMessage(res.getString(dialogMessageResId));
|
|
||||||
alertDialogBuilder.setPositiveButton(android.R.string.ok, null);
|
|
||||||
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
||||||
alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
|
|
||||||
alertDialog.setCancelable(false);
|
|
||||||
alertDialog.setCanceledOnTouchOutside(false);
|
|
||||||
alertDialog.show();
|
|
||||||
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
||||||
@Override
|
|
||||||
public void onDismiss(DialogInterface dialogInterface) {
|
|
||||||
mErrorDialogShowing = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showErrorDialog() {
|
|
||||||
if (mErrorDialogShowing) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mErrorDialogShowing = true;
|
|
||||||
goBackHome();
|
|
||||||
mHandler.post(() -> {
|
|
||||||
Resources res = getResources();
|
|
||||||
String cameraState = "-1";
|
|
||||||
int dialogMessageResId = cameraState.equals(Constants.CLOSE_CAMERA_STATE)
|
|
||||||
? R.string.popup_camera_takeback_failed_calibrate
|
|
||||||
: R.string.popup_camera_popup_failed_calibrate;
|
|
||||||
AlertDialog alertDialog =
|
|
||||||
new AlertDialog.Builder(this, R.style.SystemAlertDialogTheme)
|
|
||||||
.setTitle(res.getString(R.string.popup_camera_tip))
|
|
||||||
.setMessage(res.getString(dialogMessageResId))
|
|
||||||
.setPositiveButton(res.getString(R.string.popup_camera_calibrate_now),
|
|
||||||
(dialog, which) -> calibrateMotor())
|
|
||||||
.setNegativeButton(res.getString(android.R.string.cancel), null)
|
|
||||||
.create();
|
|
||||||
alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
|
||||||
alertDialog.setCanceledOnTouchOutside(false);
|
|
||||||
alertDialog.show();
|
|
||||||
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
||||||
@Override
|
|
||||||
public void onDismiss(DialogInterface dialogInterface) {
|
|
||||||
mErrorDialogShowing = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void playSoundEffect(String state) {
|
|
||||||
int soundEffect = Integer.parseInt(mPopupCameraPreferences.getSoundEffect());
|
|
||||||
if (soundEffect != -1) {
|
|
||||||
if (state.equals(Constants.CLOSE_CAMERA_STATE)) {
|
|
||||||
soundEffect++;
|
|
||||||
}
|
|
||||||
mSoundPool.play(mSounds[soundEffect], 1.0f, 1.0f, 0, 0, 1.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void goBackHome() {
|
|
||||||
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
|
|
||||||
homeIntent.addCategory(Intent.CATEGORY_HOME);
|
|
||||||
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
startActivityAsUser(homeIntent, null, UserHandle.CURRENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handleMessage(Message msg) {
|
|
||||||
switch (msg.what) {
|
|
||||||
case Constants.MSG_CAMERA_CLOSED: {
|
|
||||||
updateMotor(Constants.CLOSE_CAMERA_STATE);
|
|
||||||
} break;
|
|
||||||
case Constants.MSG_CAMERA_OPEN: {
|
|
||||||
updateMotor(Constants.OPEN_CAMERA_STATE);
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.lineageos.settings.popupcamera;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.preference.PreferenceActivity;
|
|
||||||
|
|
||||||
public class PopupCameraSettingsActivity extends PreferenceActivity {
|
|
||||||
private static final String TAG_POPUPCAMERA = "popupcamera";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
getFragmentManager()
|
|
||||||
.beginTransaction()
|
|
||||||
.replace(android.R.id.content, new PopupCameraSettingsFragment(), TAG_POPUPCAMERA)
|
|
||||||
.commit();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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 androidx.preference.Preference;
|
|
||||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
|
||||||
import androidx.preference.Preference.OnPreferenceClickListener;
|
|
||||||
import androidx.preference.PreferenceFragment;
|
|
||||||
|
|
||||||
import org.lineageos.settings.R;
|
|
||||||
|
|
||||||
public class PopupCameraSettingsFragment extends PreferenceFragment
|
|
||||||
implements OnPreferenceChangeListener, OnPreferenceClickListener {
|
|
||||||
private Preference mCalibrationPreference;
|
|
||||||
private static final String MOTOR_CALIBRATION_KEY = "motor_calibration";
|
|
||||||
|
|
||||||
private PopupCameraService mPopupCameraService = new PopupCameraService();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
|
||||||
addPreferencesFromResource(R.xml.popup_settings);
|
|
||||||
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
||||||
|
|
||||||
mCalibrationPreference = (Preference) findPreference(MOTOR_CALIBRATION_KEY);
|
|
||||||
mCalibrationPreference.setOnPreferenceClickListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
if (item.getItemId() == android.R.id.home) {
|
|
||||||
getActivity().onBackPressed();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
|
||||||
if (MOTOR_CALIBRATION_KEY.equals(preference.getKey())) {
|
|
||||||
MotorCalibrationWarningDialog fragment = new MotorCalibrationWarningDialog();
|
|
||||||
fragment.show(getFragmentManager(), "motor_calibration_warning_dialog");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MotorCalibrationWarningDialog extends DialogFragment {
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
||||||
return new AlertDialog.Builder(getActivity())
|
|
||||||
.setTitle(R.string.popup_calibration_warning_title)
|
|
||||||
.setMessage(R.string.popup_calibration_warning_text)
|
|
||||||
.setPositiveButton(R.string.popup_camera_calibrate_now,
|
|
||||||
(dialog, which) -> {
|
|
||||||
mPopupCameraService.calibrateMotor();
|
|
||||||
dialog.cancel();
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.cancel())
|
|
||||||
.create();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.lineageos.settings.popupcamera;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
|
|
||||||
public class PopupCameraUtils {
|
|
||||||
private static final String TAG = "PopupCameraUtils";
|
|
||||||
private static final boolean DEBUG = false;
|
|
||||||
|
|
||||||
public static void startService(Context context) {
|
|
||||||
context.startServiceAsUser(
|
|
||||||
new Intent(context, PopupCameraService.class), UserHandle.CURRENT);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,160 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 The CyanogenMod 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.lineageos.settings.utils;
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public final class FileUtils {
|
|
||||||
private static final String TAG = "FileUtils";
|
|
||||||
|
|
||||||
private FileUtils() {
|
|
||||||
// This class is not supposed to be instantiated
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the first line of text from the given file.
|
|
||||||
* Reference {@link BufferedReader#readLine()} for clarification on what a line is
|
|
||||||
*
|
|
||||||
* @return the read line contents, or null on failure
|
|
||||||
*/
|
|
||||||
public static String readOneLine(String fileName) {
|
|
||||||
String line = null;
|
|
||||||
BufferedReader reader = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
reader = new BufferedReader(new FileReader(fileName), 512);
|
|
||||||
line = reader.readLine();
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
Log.w(TAG, "No such file " + fileName + " for reading", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Could not read from file " + fileName, e);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (reader != null) {
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Ignored, not much we can do anyway
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the given value into the given file
|
|
||||||
*
|
|
||||||
* @return true on success, false on failure
|
|
||||||
*/
|
|
||||||
public static boolean writeLine(String fileName, String value) {
|
|
||||||
BufferedWriter writer = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
writer = new BufferedWriter(new FileWriter(fileName));
|
|
||||||
writer.write(value);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
Log.w(TAG, "No such file " + fileName + " for writing", e);
|
|
||||||
return false;
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Could not write to file " + fileName, e);
|
|
||||||
return false;
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (writer != null) {
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Ignored, not much we can do anyway
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the given file exists
|
|
||||||
*
|
|
||||||
* @return true if exists, false if not
|
|
||||||
*/
|
|
||||||
public static boolean fileExists(String fileName) {
|
|
||||||
final File file = new File(fileName);
|
|
||||||
return file.exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the given file is readable
|
|
||||||
*
|
|
||||||
* @return true if readable, false if not
|
|
||||||
*/
|
|
||||||
public static boolean isFileReadable(String fileName) {
|
|
||||||
final File file = new File(fileName);
|
|
||||||
return file.exists() && file.canRead();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the given file is writable
|
|
||||||
*
|
|
||||||
* @return true if writable, false if not
|
|
||||||
*/
|
|
||||||
public static boolean isFileWritable(String fileName) {
|
|
||||||
final File file = new File(fileName);
|
|
||||||
return file.exists() && file.canWrite();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes an existing file
|
|
||||||
*
|
|
||||||
* @return true if the delete was successful, false if not
|
|
||||||
*/
|
|
||||||
public static boolean delete(String fileName) {
|
|
||||||
final File file = new File(fileName);
|
|
||||||
boolean ok = false;
|
|
||||||
try {
|
|
||||||
ok = file.delete();
|
|
||||||
} catch (SecurityException e) {
|
|
||||||
Log.w(TAG, "SecurityException trying to delete " + fileName, e);
|
|
||||||
}
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renames an existing file
|
|
||||||
*
|
|
||||||
* @return true if the rename was successful, false if not
|
|
||||||
*/
|
|
||||||
public static boolean rename(String srcPath, String dstPath) {
|
|
||||||
final File srcFile = new File(srcPath);
|
|
||||||
final File dstFile = new File(dstPath);
|
|
||||||
boolean ok = false;
|
|
||||||
try {
|
|
||||||
ok = srcFile.renameTo(dstFile);
|
|
||||||
} catch (SecurityException e) {
|
|
||||||
Log.w(TAG, "SecurityException trying to rename " + srcPath + " to " + dstPath, e);
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
Log.e(TAG, "NullPointerException trying to rename " + srcPath + " to " + dstPath, e);
|
|
||||||
}
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user