diff --git a/parts/src/org/lineageos/settings/popupcamera/Constants.java b/parts/src/org/lineageos/settings/popupcamera/Constants.java index 8ee1cf2..339cd07 100644 --- a/parts/src/org/lineageos/settings/popupcamera/Constants.java +++ b/parts/src/org/lineageos/settings/popupcamera/Constants.java @@ -19,7 +19,7 @@ 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 CAMERA_EVENT_DELAY_TIME = 100; // ms public static final int MSG_CAMERA_CLOSED = 1001; public static final int MSG_CAMERA_OPEN = 1002; diff --git a/parts/src/org/lineageos/settings/popupcamera/PopupCameraPreferences.java b/parts/src/org/lineageos/settings/popupcamera/PopupCameraPreferences.java index c942722..070e6b2 100644 --- a/parts/src/org/lineageos/settings/popupcamera/PopupCameraPreferences.java +++ b/parts/src/org/lineageos/settings/popupcamera/PopupCameraPreferences.java @@ -21,7 +21,6 @@ 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"; diff --git a/parts/src/org/lineageos/settings/popupcamera/PopupCameraService.java b/parts/src/org/lineageos/settings/popupcamera/PopupCameraService.java index f5e8eaa..926ab0a 100644 --- a/parts/src/org/lineageos/settings/popupcamera/PopupCameraService.java +++ b/parts/src/org/lineageos/settings/popupcamera/PopupCameraService.java @@ -40,7 +40,6 @@ import org.lineageos.settings.utils.FileUtils; import vendor.xiaomi.hardware.motor.V1_0.IMotor; public class PopupCameraService extends Service implements Handler.Callback { - private static final String TAG = "PopupCameraService"; private static final boolean DEBUG = false; @@ -58,36 +57,36 @@ public class PopupCameraService extends Service implements Handler.Callback { 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); + @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); + } } - 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); + @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); + } } - mHandler.sendEmptyMessageDelayed(Constants.MSG_CAMERA_OPEN, - Constants.CAMERA_EVENT_DELAY_TIME); - } - } - }; + }; private SensorEventListener mFreeFallListener = new SensorEventListener() { @Override @@ -99,8 +98,7 @@ public class PopupCameraService extends Service implements Handler.Callback { } @Override - public void onAccuracyChanged(Sensor sensor, int accuracy) { - } + public void onAccuracyChanged(Sensor sensor, int accuracy) {} }; @Override @@ -110,12 +108,16 @@ public class PopupCameraService extends Service implements Handler.Callback { 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(); + 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++) { @@ -136,13 +138,15 @@ public class PopupCameraService extends Service implements Handler.Callback { @Override public int onStartCommand(Intent intent, int flags, int startId) { - if (DEBUG) Log.d(TAG, "Starting service"); + if (DEBUG) + Log.d(TAG, "Starting service"); return START_STICKY; } @Override public void onDestroy() { - if (DEBUG) Log.d(TAG, "Destroying service"); + if (DEBUG) + Log.d(TAG, "Destroying service"); super.onDestroy(); } @@ -164,8 +168,8 @@ public class PopupCameraService extends Service implements Handler.Callback { lightUp(); playSoundEffect(Constants.OPEN_CAMERA_STATE); mMotor.popupMotor(1); - mSensorManager.registerListener(mFreeFallListener, mFreeFallSensor, - SensorManager.SENSOR_DELAY_NORMAL); + mSensorManager.registerListener( + mFreeFallListener, mFreeFallSensor, SensorManager.SENSOR_DELAY_NORMAL); } else if (cameraState.equals(Constants.CLOSE_CAMERA_STATE) && mMotor.getMotorStatus() == Constants.MOTOR_STATUS_POPUP) { lightUp(); @@ -212,8 +216,7 @@ public class PopupCameraService extends Service implements Handler.Callback { if (state.equals(Constants.CLOSE_CAMERA_STATE)) { soundEffect++; } - mSoundPool.play(mSounds[soundEffect], 1.0f, 1.0f, 0, - 0, 1.0f); + mSoundPool.play(mSounds[soundEffect], 1.0f, 1.0f, 0, 0, 1.0f); } } @@ -229,12 +232,10 @@ public class PopupCameraService extends Service implements Handler.Callback { switch (msg.what) { case Constants.MSG_CAMERA_CLOSED: { updateMotor(Constants.CLOSE_CAMERA_STATE); - } - break; + } break; case Constants.MSG_CAMERA_OPEN: { updateMotor(Constants.OPEN_CAMERA_STATE); - } - break; + } break; } return true; } diff --git a/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsActivity.java b/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsActivity.java index 4f59aa2..a312cff 100644 --- a/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsActivity.java +++ b/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsActivity.java @@ -20,14 +20,15 @@ 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(); + 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 index dce35a0..701c9ca 100644 --- a/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsFragment.java +++ b/parts/src/org/lineageos/settings/popupcamera/PopupCameraSettingsFragment.java @@ -25,9 +25,8 @@ import androidx.preference.PreferenceFragment; import org.lineageos.settings.R; -public class PopupCameraSettingsFragment extends PreferenceFragment implements - OnPreferenceChangeListener { - +public class PopupCameraSettingsFragment + extends PreferenceFragment implements OnPreferenceChangeListener { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.popup_settings); diff --git a/parts/src/org/lineageos/settings/popupcamera/PopupCameraUtils.java b/parts/src/org/lineageos/settings/popupcamera/PopupCameraUtils.java index c9f681c..46c29c4 100644 --- a/parts/src/org/lineageos/settings/popupcamera/PopupCameraUtils.java +++ b/parts/src/org/lineageos/settings/popupcamera/PopupCameraUtils.java @@ -21,12 +21,11 @@ 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); + context.startServiceAsUser( + new Intent(context, PopupCameraService.class), UserHandle.CURRENT); } }