davinci: parts: Add popup camera sound effects and LED toggle

Change-Id: Iaf66650ae68d2680fa0c9b933f2c4e634bc21e74
This commit is contained in:
jhenrique09 2019-11-26 18:37:29 +00:00 committed by Arian
parent 932a2bcad0
commit 65c44dd66e
No known key found for this signature in database
GPG Key ID: 48029380598CE3B9
11 changed files with 305 additions and 0 deletions

View File

@ -59,5 +59,27 @@
</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>

View File

@ -0,0 +1,11 @@
<?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>

View File

@ -0,0 +1,52 @@
<?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>

View File

@ -0,0 +1,29 @@
<?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 effects</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>
</resources>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
android:defaultValue="true"
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:key="popup_sound_effect"
android:summary="%s"
android:title="@string/popup_sound_title" />
</PreferenceScreen>

View File

@ -34,4 +34,5 @@ public class Constants {
public static final String FRONT_CAMERA_ID = "1"; public static final String FRONT_CAMERA_ID = "1";
public static final String BLUE_LED_PATH = "/sys/class/leds/blue/brightness"; public static final String BLUE_LED_PATH = "/sys/class/leds/blue/brightness";
public static final String GREEN_LED_PATH = "/sys/class/leds/green/brightness"; public static final String GREEN_LED_PATH = "/sys/class/leds/green/brightness";
public static final String POPUP_SOUND_PATH = "/system/media/audio/ui/";
} }

View File

@ -0,0 +1,44 @@
/*
* 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);
}
}

View File

@ -24,6 +24,8 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener; import android.hardware.SensorEventListener;
import android.hardware.SensorManager; import android.hardware.SensorManager;
import android.hardware.camera2.CameraManager; import android.hardware.camera2.CameraManager;
import android.media.AudioAttributes;
import android.media.SoundPool;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Message; import android.os.Message;
@ -42,13 +44,16 @@ public class PopupCameraService extends Service implements Handler.Callback {
private static final String TAG = "PopupCameraService"; private static final String TAG = "PopupCameraService";
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private int[] mSounds;
private long mClosedEvent; private long mClosedEvent;
private long mOpenEvent; private long mOpenEvent;
private Handler mHandler = new Handler(this); private Handler mHandler = new Handler(this);
private IMotor mMotor = null; private IMotor mMotor = null;
private PopupCameraPreferences mPopupCameraPreferences;
private SensorManager mSensorManager; private SensorManager mSensorManager;
private Sensor mFreeFallSensor; private Sensor mFreeFallSensor;
private SoundPool mSoundPool;
private CameraManager.AvailabilityCallback availabilityCallback = private CameraManager.AvailabilityCallback availabilityCallback =
new CameraManager.AvailabilityCallback() { new CameraManager.AvailabilityCallback() {
@ -103,6 +108,19 @@ public class PopupCameraService extends Service implements Handler.Callback {
cameraManager.registerAvailabilityCallback(availabilityCallback, null); cameraManager.registerAvailabilityCallback(availabilityCallback, null);
mSensorManager = getSystemService(SensorManager.class); mSensorManager = getSystemService(SensorManager.class);
mFreeFallSensor = mSensorManager.getDefaultSensor(Constants.FREE_FALL_SENSOR_ID); 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 { try {
mMotor = IMotor.getService(); mMotor = IMotor.getService();
int status = mMotor.getMotorStatus(); int status = mMotor.getMotorStatus();
@ -138,12 +156,14 @@ public class PopupCameraService extends Service implements Handler.Callback {
if (cameraState.equals(Constants.OPEN_CAMERA_STATE) if (cameraState.equals(Constants.OPEN_CAMERA_STATE)
&& mMotor.getMotorStatus() == Constants.MOTOR_STATUS_TAKEBACK) { && mMotor.getMotorStatus() == Constants.MOTOR_STATUS_TAKEBACK) {
lightUp(); lightUp();
playSoundEffect(Constants.OPEN_CAMERA_STATE);
mMotor.popupMotor(1); mMotor.popupMotor(1);
mSensorManager.registerListener(mFreeFallListener, mFreeFallSensor, mSensorManager.registerListener(mFreeFallListener, mFreeFallSensor,
SensorManager.SENSOR_DELAY_NORMAL); SensorManager.SENSOR_DELAY_NORMAL);
} else if (cameraState.equals(Constants.CLOSE_CAMERA_STATE) } else if (cameraState.equals(Constants.CLOSE_CAMERA_STATE)
&& mMotor.getMotorStatus() == Constants.MOTOR_STATUS_POPUP) { && mMotor.getMotorStatus() == Constants.MOTOR_STATUS_POPUP) {
lightUp(); lightUp();
playSoundEffect(Constants.CLOSE_CAMERA_STATE);
mMotor.takebackMotor(1); mMotor.takebackMotor(1);
mSensorManager.unregisterListener(mFreeFallListener, mFreeFallSensor); mSensorManager.unregisterListener(mFreeFallListener, mFreeFallSensor);
} }
@ -164,6 +184,17 @@ public class PopupCameraService extends Service implements Handler.Callback {
} }
} }
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() { public void goBackHome() {
Intent homeIntent = new Intent(Intent.ACTION_MAIN); Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME); homeIntent.addCategory(Intent.CATEGORY_HOME);

View File

@ -0,0 +1,33 @@
/*
* 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();
}
}

View File

@ -0,0 +1,50 @@
/*
* 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.view.MenuItem;
import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.PreferenceFragment;
import org.lineageos.settings.R;
public class PopupCameraSettingsFragment extends PreferenceFragment implements
OnPreferenceChangeListener {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.popup_settings);
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
}
@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;
}
}

View File

@ -204,3 +204,17 @@ vendor/bin/hw/vendor.xiaomi.hardware.motor@1.0-service
vendor/lib64/hw/vendor.xiaomi.hardware.motor@1.0-impl.so vendor/lib64/hw/vendor.xiaomi.hardware.motor@1.0-impl.so
vendor/lib64/mi.motor.daemon.so vendor/lib64/mi.motor.daemon.so
vendor/lib64/vendor.xiaomi.hardware.motor@1.0.so vendor/lib64/vendor.xiaomi.hardware.motor@1.0.so
# Camera (popup sound effects)
media/audio/ui/popup_cangmen_down.ogg
media/audio/ui/popup_cangmen_up.ogg
media/audio/ui/popup_chilun_down.ogg
media/audio/ui/popup_chilun_up.ogg
media/audio/ui/popup_jijia_down.ogg
media/audio/ui/popup_jijia_up.ogg
media/audio/ui/popup_mofa_down.ogg
media/audio/ui/popup_mofa_up.ogg
media/audio/ui/popup_muqin_down.ogg
media/audio/ui/popup_muqin_up.ogg
media/audio/ui/popup_yingyan_down.ogg
media/audio/ui/popup_yingyan_up.ogg