From 65c44dd66ef973a9ad31c28ffff6da0e71a8345d Mon Sep 17 00:00:00 2001 From: jhenrique09 Date: Tue, 26 Nov 2019 18:37:29 +0000 Subject: [PATCH] davinci: parts: Add popup camera sound effects and LED toggle Change-Id: Iaf66650ae68d2680fa0c9b933f2c4e634bc21e74 --- parts/AndroidManifest.xml | 22 ++++++++ parts/res/drawable/ic_settings_popup.xml | 11 ++++ parts/res/values/arrays.xml | 52 +++++++++++++++++++ parts/res/values/strings.xml | 29 +++++++++++ parts/res/xml/popup_settings.xml | 18 +++++++ .../settings/popupcamera/Constants.java | 1 + .../popupcamera/PopupCameraPreferences.java | 44 ++++++++++++++++ .../popupcamera/PopupCameraService.java | 31 +++++++++++ .../PopupCameraSettingsActivity.java | 33 ++++++++++++ .../PopupCameraSettingsFragment.java | 50 ++++++++++++++++++ proprietary-files.txt | 14 +++++ 11 files changed, 305 insertions(+) create mode 100644 parts/res/drawable/ic_settings_popup.xml create mode 100644 parts/res/values/arrays.xml create mode 100644 parts/res/values/strings.xml create mode 100644 parts/res/xml/popup_settings.xml create mode 100644 parts/src/org/lineageos/settings/popupcamera/PopupCameraPreferences.java create mode 100644 parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsActivity.java create mode 100644 parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsFragment.java diff --git a/parts/AndroidManifest.xml b/parts/AndroidManifest.xml index 91b54a2..33f323d 100644 --- a/parts/AndroidManifest.xml +++ b/parts/AndroidManifest.xml @@ -59,5 +59,27 @@ + + + + + + + + + + + diff --git a/parts/res/drawable/ic_settings_popup.xml b/parts/res/drawable/ic_settings_popup.xml new file mode 100644 index 0000000..d593eb2 --- /dev/null +++ b/parts/res/drawable/ic_settings_popup.xml @@ -0,0 +1,11 @@ + + + + diff --git a/parts/res/values/arrays.xml b/parts/res/values/arrays.xml new file mode 100644 index 0000000..7d2191e --- /dev/null +++ b/parts/res/values/arrays.xml @@ -0,0 +1,52 @@ + + + + + @string/action_none + @string/popup_sound_muqin + @string/popup_sound_yingyan + @string/popup_sound_mofa + @string/popup_sound_jijia + @string/popup_sound_chilun + @string/popup_sound_cangmen + + + + popup_muqin_up.ogg + popup_muqin_down.ogg + popup_yingyan_up.ogg + popup_yingyan_down.ogg + popup_mofa_up.ogg + popup_mofa_down.ogg + popup_jijia_up.ogg + popup_jijia_down.ogg + popup_chilun_up.ogg + popup_chilun_down.ogg + popup_cangmen_up.ogg + popup_cangmen_down.ogg + + + + -1 + 0 + 2 + 4 + 6 + 8 + 10 + + diff --git a/parts/res/values/strings.xml b/parts/res/values/strings.xml new file mode 100644 index 0000000..849fb12 --- /dev/null +++ b/parts/res/values/strings.xml @@ -0,0 +1,29 @@ + + + + + Front camera effects + Camera LED + Enable LED light while the front camera appears and retracts + Sound effects + Xylophone + Condor + Magic + Mecha + Gearwheel + Cabin door + diff --git a/parts/res/xml/popup_settings.xml b/parts/res/xml/popup_settings.xml new file mode 100644 index 0000000..b7b80bd --- /dev/null +++ b/parts/res/xml/popup_settings.xml @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/parts/src/org/lineageos/settings/popupcamera/Constants.java b/parts/src/org/lineageos/settings/popupcamera/Constants.java index ec5cca6..07946d6 100644 --- a/parts/src/org/lineageos/settings/popupcamera/Constants.java +++ b/parts/src/org/lineageos/settings/popupcamera/Constants.java @@ -34,4 +34,5 @@ public class Constants { public static final String FRONT_CAMERA_ID = "1"; 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 POPUP_SOUND_PATH = "/system/media/audio/ui/"; } diff --git a/parts/src/org/lineageos/settings/popupcamera/PopupCameraPreferences.java b/parts/src/org/lineageos/settings/popupcamera/PopupCameraPreferences.java new file mode 100644 index 0000000..c942722 --- /dev/null +++ b/parts/src/org/lineageos/settings/popupcamera/PopupCameraPreferences.java @@ -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); + } +} diff --git a/parts/src/org/lineageos/settings/popupcamera/PopupCameraService.java b/parts/src/org/lineageos/settings/popupcamera/PopupCameraService.java index 27598d7..faa663d 100644 --- a/parts/src/org/lineageos/settings/popupcamera/PopupCameraService.java +++ b/parts/src/org/lineageos/settings/popupcamera/PopupCameraService.java @@ -24,6 +24,8 @@ 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; @@ -42,13 +44,16 @@ public class PopupCameraService extends Service implements Handler.Callback { private static final String TAG = "PopupCameraService"; private static final boolean DEBUG = false; + private int[] mSounds; private long mClosedEvent; private long mOpenEvent; private Handler mHandler = new Handler(this); private IMotor mMotor = null; + private PopupCameraPreferences mPopupCameraPreferences; private SensorManager mSensorManager; private Sensor mFreeFallSensor; + private SoundPool mSoundPool; private CameraManager.AvailabilityCallback availabilityCallback = new CameraManager.AvailabilityCallback() { @@ -103,6 +108,19 @@ public class PopupCameraService extends Service implements Handler.Callback { 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(); @@ -138,12 +156,14 @@ public class PopupCameraService extends Service implements Handler.Callback { if (cameraState.equals(Constants.OPEN_CAMERA_STATE) && mMotor.getMotorStatus() == Constants.MOTOR_STATUS_TAKEBACK) { 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) && mMotor.getMotorStatus() == Constants.MOTOR_STATUS_POPUP) { lightUp(); + playSoundEffect(Constants.CLOSE_CAMERA_STATE); mMotor.takebackMotor(1); 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() { Intent homeIntent = new Intent(Intent.ACTION_MAIN); homeIntent.addCategory(Intent.CATEGORY_HOME); diff --git a/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsActivity.java b/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsActivity.java new file mode 100644 index 0000000..4f59aa2 --- /dev/null +++ b/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsActivity.java @@ -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(); + } +} diff --git a/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsFragment.java b/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsFragment.java new file mode 100644 index 0000000..dce35a0 --- /dev/null +++ b/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsFragment.java @@ -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; + } +} diff --git a/proprietary-files.txt b/proprietary-files.txt index 2b04e8f..295e454 100644 --- a/proprietary-files.txt +++ b/proprietary-files.txt @@ -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/mi.motor.daemon.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