davinci: parts: clang-format everything
Change-Id: Iae92b7197a58b4353dafa7e24d67ebb5f096f2b5
This commit is contained in:
parent
a5fe3b11a6
commit
fed308cae8
@ -26,13 +26,13 @@ import org.lineageos.settings.doze.DozeUtils;
|
||||
import org.lineageos.settings.popupcamera.PopupCameraUtils;
|
||||
|
||||
public class BootCompletedReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
private static final String TAG = "XiaomiParts";
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
if (DEBUG) Log.d(TAG, "Received boot completed intent");
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "Received boot completed intent");
|
||||
DozeUtils.checkDozeService(context);
|
||||
PopupCameraUtils.startService(context);
|
||||
}
|
||||
|
@ -34,7 +34,8 @@ public class DozeService extends Service {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
if (DEBUG) Log.d(TAG, "Creating service");
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "Creating service");
|
||||
mProximitySensor = new ProximitySensor(this);
|
||||
mPickupSensor = new PickupSensor(this);
|
||||
|
||||
@ -46,13 +47,15 @@ public class DozeService extends Service {
|
||||
|
||||
@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();
|
||||
this.unregisterReceiver(mScreenStateReceiver);
|
||||
mProximitySensor.disable();
|
||||
@ -65,23 +68,23 @@ public class DozeService extends Service {
|
||||
}
|
||||
|
||||
private void onDisplayOn() {
|
||||
if (DEBUG) Log.d(TAG, "Display on");
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "Display on");
|
||||
if (DozeUtils.isPickUpEnabled(this)) {
|
||||
mPickupSensor.disable();
|
||||
}
|
||||
if (DozeUtils.isHandwaveGestureEnabled(this) ||
|
||||
DozeUtils.isPocketGestureEnabled(this)) {
|
||||
if (DozeUtils.isHandwaveGestureEnabled(this) || DozeUtils.isPocketGestureEnabled(this)) {
|
||||
mProximitySensor.disable();
|
||||
}
|
||||
}
|
||||
|
||||
private void onDisplayOff() {
|
||||
if (DEBUG) Log.d(TAG, "Display off");
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "Display off");
|
||||
if (DozeUtils.isPickUpEnabled(this)) {
|
||||
mPickupSensor.enable();
|
||||
}
|
||||
if (DozeUtils.isHandwaveGestureEnabled(this) ||
|
||||
DozeUtils.isPocketGestureEnabled(this)) {
|
||||
if (DozeUtils.isHandwaveGestureEnabled(this) || DozeUtils.isPocketGestureEnabled(this)) {
|
||||
mProximitySensor.enable();
|
||||
}
|
||||
}
|
||||
|
@ -21,14 +21,15 @@ import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
|
||||
public class DozeSettingsActivity extends PreferenceActivity {
|
||||
|
||||
private static final String TAG_DOZE = "doze";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content,
|
||||
new DozeSettingsFragment(), TAG_DOZE).commit();
|
||||
getFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(android.R.id.content, new DozeSettingsFragment(), TAG_DOZE)
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
@ -42,9 +42,8 @@ import androidx.preference.SwitchPreference;
|
||||
|
||||
import org.lineageos.settings.R;
|
||||
|
||||
public class DozeSettingsFragment extends PreferenceFragment implements OnPreferenceChangeListener,
|
||||
CompoundButton.OnCheckedChangeListener {
|
||||
|
||||
public class DozeSettingsFragment extends PreferenceFragment
|
||||
implements OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener {
|
||||
private TextView mTextView;
|
||||
private View mSwitchBar;
|
||||
|
||||
@ -62,8 +61,8 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
||||
final ActionBar actionBar = getActivity().getActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
SharedPreferences prefs = getActivity().getSharedPreferences("doze_settings",
|
||||
Activity.MODE_PRIVATE);
|
||||
SharedPreferences prefs =
|
||||
getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE);
|
||||
if (savedInstanceState == null && !prefs.getBoolean("first_help_shown", false)) {
|
||||
showHelp();
|
||||
}
|
||||
@ -75,10 +74,12 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
||||
mAlwaysOnDisplayPreference.setChecked(DozeUtils.isAlwaysOnEnabled(getActivity()));
|
||||
mAlwaysOnDisplayPreference.setOnPreferenceChangeListener(this);
|
||||
|
||||
PreferenceCategory pickupSensorCategory = (PreferenceCategory) getPreferenceScreen().
|
||||
findPreference(DozeUtils.CATEG_PICKUP_SENSOR);
|
||||
PreferenceCategory proximitySensorCategory = (PreferenceCategory) getPreferenceScreen().
|
||||
findPreference(DozeUtils.CATEG_PROX_SENSOR);
|
||||
PreferenceCategory pickupSensorCategory =
|
||||
(PreferenceCategory) getPreferenceScreen().findPreference(
|
||||
DozeUtils.CATEG_PICKUP_SENSOR);
|
||||
PreferenceCategory proximitySensorCategory =
|
||||
(PreferenceCategory) getPreferenceScreen().findPreference(
|
||||
DozeUtils.CATEG_PROX_SENSOR);
|
||||
|
||||
mPickUpPreference = (SwitchPreference) findPreference(DozeUtils.GESTURE_PICK_UP_KEY);
|
||||
mPickUpPreference.setEnabled(dozeEnabled);
|
||||
@ -107,10 +108,10 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
final View view = LayoutInflater.from(getContext()).inflate(R.layout.doze,
|
||||
container, false);
|
||||
public View onCreateView(
|
||||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View view =
|
||||
LayoutInflater.from(getContext()).inflate(R.layout.doze, container, false);
|
||||
((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState));
|
||||
return view;
|
||||
}
|
||||
@ -122,8 +123,8 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
||||
boolean dozeEnabled = DozeUtils.isDozeEnabled(getActivity());
|
||||
|
||||
mTextView = view.findViewById(R.id.switch_text);
|
||||
mTextView.setText(getString(dozeEnabled ?
|
||||
R.string.switch_bar_on : R.string.switch_bar_off));
|
||||
mTextView.setText(
|
||||
getString(dozeEnabled ? R.string.switch_bar_on : R.string.switch_bar_off));
|
||||
|
||||
mSwitchBar = view.findViewById(R.id.switch_bar);
|
||||
Switch switchWidget = mSwitchBar.findViewById(android.R.id.switch_widget);
|
||||
@ -187,7 +188,8 @@ public class DozeSettingsFragment extends PreferenceFragment implements OnPrefer
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
getActivity().getSharedPreferences("doze_settings", Activity.MODE_PRIVATE)
|
||||
getActivity()
|
||||
.getSharedPreferences("doze_settings", Activity.MODE_PRIVATE)
|
||||
.edit()
|
||||
.putBoolean("first_help_shown", true)
|
||||
.commit();
|
||||
|
@ -32,7 +32,6 @@ import static android.provider.Settings.Secure.DOZE_ALWAYS_ON;
|
||||
import static android.provider.Settings.Secure.DOZE_ENABLED;
|
||||
|
||||
public final class DozeUtils {
|
||||
|
||||
private static final String TAG = "DozeUtils";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
@ -48,15 +47,15 @@ public final class DozeUtils {
|
||||
protected static final String GESTURE_POCKET_KEY = "gesture_pocket";
|
||||
|
||||
public static void startService(Context context) {
|
||||
if (DEBUG) Log.d(TAG, "Starting service");
|
||||
context.startServiceAsUser(new Intent(context, DozeService.class),
|
||||
UserHandle.CURRENT);
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "Starting service");
|
||||
context.startServiceAsUser(new Intent(context, DozeService.class), UserHandle.CURRENT);
|
||||
}
|
||||
|
||||
protected static void stopService(Context context) {
|
||||
if (DEBUG) Log.d(TAG, "Stopping service");
|
||||
context.stopServiceAsUser(new Intent(context, DozeService.class),
|
||||
UserHandle.CURRENT);
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "Stopping service");
|
||||
context.stopServiceAsUser(new Intent(context, DozeService.class), UserHandle.CURRENT);
|
||||
}
|
||||
|
||||
public static void checkDozeService(Context context) {
|
||||
@ -70,8 +69,8 @@ public final class DozeUtils {
|
||||
protected static boolean getProxCheckBeforePulse(Context context) {
|
||||
try {
|
||||
Context con = context.createPackageContext("com.android.systemui", 0);
|
||||
int id = con.getResources().getIdentifier("doze_proximity_check_before_pulse",
|
||||
"bool", "com.android.systemui");
|
||||
int id = con.getResources().getIdentifier(
|
||||
"doze_proximity_check_before_pulse", "bool", "com.android.systemui");
|
||||
return con.getResources().getBoolean(id);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return false;
|
||||
@ -79,33 +78,33 @@ public final class DozeUtils {
|
||||
}
|
||||
|
||||
protected static boolean enableDoze(Context context, boolean enable) {
|
||||
return Settings.Secure.putInt(context.getContentResolver(),
|
||||
DOZE_ENABLED, enable ? 1 : 0);
|
||||
return Settings.Secure.putInt(context.getContentResolver(), DOZE_ENABLED, enable ? 1 : 0);
|
||||
}
|
||||
|
||||
public static boolean isDozeEnabled(Context context) {
|
||||
return Settings.Secure.getInt(context.getContentResolver(),
|
||||
DOZE_ENABLED, 1) != 0;
|
||||
return Settings.Secure.getInt(context.getContentResolver(), DOZE_ENABLED, 1) != 0;
|
||||
}
|
||||
|
||||
protected static void launchDozePulse(Context context) {
|
||||
if (DEBUG) Log.d(TAG, "Launch doze pulse");
|
||||
context.sendBroadcastAsUser(new Intent(DOZE_INTENT),
|
||||
new UserHandle(UserHandle.USER_CURRENT));
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "Launch doze pulse");
|
||||
context.sendBroadcastAsUser(
|
||||
new Intent(DOZE_INTENT), new UserHandle(UserHandle.USER_CURRENT));
|
||||
}
|
||||
|
||||
protected static boolean enableAlwaysOn(Context context, boolean enable) {
|
||||
return Settings.Secure.putIntForUser(context.getContentResolver(),
|
||||
DOZE_ALWAYS_ON, enable ? 1 : 0, UserHandle.USER_CURRENT);
|
||||
return Settings.Secure.putIntForUser(context.getContentResolver(), DOZE_ALWAYS_ON,
|
||||
enable ? 1 : 0, UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
protected static boolean isAlwaysOnEnabled(Context context) {
|
||||
final boolean enabledByDefault = context.getResources()
|
||||
.getBoolean(com.android.internal.R.bool.config_dozeAlwaysOnEnabled);
|
||||
final boolean enabledByDefault = context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_dozeAlwaysOnEnabled);
|
||||
|
||||
return Settings.Secure.getIntForUser(context.getContentResolver(),
|
||||
DOZE_ALWAYS_ON, alwaysOnDisplayAvailable(context) && enabledByDefault ? 1 : 0,
|
||||
UserHandle.USER_CURRENT) != 0;
|
||||
return Settings.Secure.getIntForUser(context.getContentResolver(), DOZE_ALWAYS_ON,
|
||||
alwaysOnDisplayAvailable(context) && enabledByDefault ? 1 : 0,
|
||||
UserHandle.USER_CURRENT)
|
||||
!= 0;
|
||||
}
|
||||
|
||||
protected static boolean alwaysOnDisplayAvailable(Context context) {
|
||||
@ -113,8 +112,7 @@ public final class DozeUtils {
|
||||
}
|
||||
|
||||
protected static boolean isGestureEnabled(Context context, String gesture) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getBoolean(gesture, false);
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(gesture, false);
|
||||
}
|
||||
|
||||
protected static boolean isPickUpEnabled(Context context) {
|
||||
|
@ -30,7 +30,6 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class PickupSensor implements SensorEventListener {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
private static final String TAG = "PickupSensor";
|
||||
|
||||
@ -50,13 +49,12 @@ public class PickupSensor implements SensorEventListener {
|
||||
mExecutorService = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
|
||||
private Future<?> submit(Runnable runnable) {
|
||||
return mExecutorService.submit(runnable);
|
||||
}
|
||||
private Future<?> submit(Runnable runnable) { return mExecutorService.submit(runnable); }
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
if (DEBUG) Log.d(TAG, "Got sensor event: " + event.values[0]);
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "Got sensor event: " + event.values[0]);
|
||||
|
||||
long delta = SystemClock.elapsedRealtime() - mEntryTimestamp;
|
||||
if (delta < MIN_PULSE_INTERVAL_MS) {
|
||||
@ -76,18 +74,17 @@ public class PickupSensor implements SensorEventListener {
|
||||
}
|
||||
|
||||
protected void enable() {
|
||||
if (DEBUG) Log.d(TAG, "Enabling");
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "Enabling");
|
||||
submit(() -> {
|
||||
mSensorManager.registerListener(this, mSensor,
|
||||
SensorManager.SENSOR_DELAY_NORMAL);
|
||||
mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
mEntryTimestamp = SystemClock.elapsedRealtime();
|
||||
});
|
||||
}
|
||||
|
||||
protected void disable() {
|
||||
if (DEBUG) Log.d(TAG, "Disabling");
|
||||
submit(() -> {
|
||||
mSensorManager.unregisterListener(this, mSensor);
|
||||
});
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "Disabling");
|
||||
submit(() -> { mSensorManager.unregisterListener(this, mSensor); });
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class ProximitySensor implements SensorEventListener {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
private static final String TAG = "ProximitySensor";
|
||||
|
||||
@ -54,9 +53,7 @@ public class ProximitySensor implements SensorEventListener {
|
||||
mExecutorService = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
|
||||
private Future<?> submit(Runnable runnable) {
|
||||
return mExecutorService.submit(runnable);
|
||||
}
|
||||
private Future<?> submit(Runnable runnable) { return mExecutorService.submit(runnable); }
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
@ -74,8 +71,8 @@ public class ProximitySensor implements SensorEventListener {
|
||||
private boolean shouldPulse(long timestamp) {
|
||||
long delta = timestamp - mInPocketTime;
|
||||
|
||||
if (DozeUtils.isHandwaveGestureEnabled(mContext) &&
|
||||
DozeUtils.isPocketGestureEnabled(mContext)) {
|
||||
if (DozeUtils.isHandwaveGestureEnabled(mContext)
|
||||
&& DozeUtils.isPocketGestureEnabled(mContext)) {
|
||||
return true;
|
||||
} else if (DozeUtils.isHandwaveGestureEnabled(mContext)) {
|
||||
return delta < HANDWAVE_MAX_DELTA_NS;
|
||||
@ -91,17 +88,16 @@ public class ProximitySensor implements SensorEventListener {
|
||||
}
|
||||
|
||||
protected void enable() {
|
||||
if (DEBUG) Log.d(TAG, "Enabling");
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "Enabling");
|
||||
submit(() -> {
|
||||
mSensorManager.registerListener(this, mSensor,
|
||||
SensorManager.SENSOR_DELAY_NORMAL);
|
||||
mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
});
|
||||
}
|
||||
|
||||
protected void disable() {
|
||||
if (DEBUG) Log.d(TAG, "Disabling");
|
||||
submit(() -> {
|
||||
mSensorManager.unregisterListener(this, mSensor);
|
||||
});
|
||||
if (DEBUG)
|
||||
Log.d(TAG, "Disabling");
|
||||
submit(() -> { mSensorManager.unregisterListener(this, mSensor); });
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user