LineageParts: Misc fixes and improvements
* Use Standardcharsets
* Use try-with-resource
* Explicitly cast where required
* Use Math.min / Math.max
* Instead of storing the Context, store the ContentResolver
* ReportingService: Store ApplicationContext in a variable and use that
instead of calling the method multiple times
Change-Id: Ic9a697e0b03b87f1bce91adfdbb828759fe2c548
diff --git a/src/org/lineageos/lineageparts/contributors/ContributorsCloudFragment.java b/src/org/lineageos/lineageparts/contributors/ContributorsCloudFragment.java
index 5e27c86..4f7e2a9 100644
--- a/src/org/lineageos/lineageparts/contributors/ContributorsCloudFragment.java
+++ b/src/org/lineageos/lineageparts/contributors/ContributorsCloudFragment.java
@@ -542,21 +542,18 @@
// Horizontal
canvas.drawText(name, x, y, paint);
} else {
+ canvas.save();
if (r == -1) {
// Vertical (-90 rotation)
- canvas.save();
canvas.translate(h, w - h);
canvas.rotate(-90, x, y);
- canvas.drawText(name, x, y, paint);
- canvas.restore();
} else {
// Vertical (+90 rotation)
- canvas.save();
canvas.translate(h/2, -h);
canvas.rotate(90, x, y);
- canvas.drawText(name, x, y, paint);
- canvas.restore();
}
+ canvas.drawText(name, x, y, paint);
+ canvas.restore();
}
// Calculate focus
@@ -825,19 +822,20 @@
}
List<SearchIndexableRaw> result = new ArrayList<>();
- Cursor c = db.rawQuery(
- "select id, username from metadata order by commits desc limit 100;", null);
- while (c.moveToNext()) {
- SearchIndexableRaw raw = new SearchIndexableRaw(context);
- raw.key = KEY_PREFIX + c.getString(0);
- raw.rank = 10;
- raw.title = c.getString(1);
- result.add(raw);
+ try (Cursor c = db.rawQuery(
+ "select id, username from metadata order by commits desc limit 100;",
+ null)) {
+ while (c.moveToNext()) {
+ SearchIndexableRaw raw = new SearchIndexableRaw(context);
+ raw.key = KEY_PREFIX + c.getString(0);
+ raw.rank = 10;
+ raw.title = c.getString(1);
+ result.add(raw);
+ }
}
- c.close();
db.close();
return result;
}
- };
+ };
}
diff --git a/src/org/lineageos/lineageparts/contributors/ContributorsCloudViewController.java b/src/org/lineageos/lineageparts/contributors/ContributorsCloudViewController.java
index df68c1d..3386a08 100644
--- a/src/org/lineageos/lineageparts/contributors/ContributorsCloudViewController.java
+++ b/src/org/lineageos/lineageparts/contributors/ContributorsCloudViewController.java
@@ -539,8 +539,8 @@
if (null != imageView) {
setScale(scale,
- (imageView.getRight()) / 2,
- (imageView.getBottom()) / 2,
+ (imageView.getRight()) / 2f,
+ (imageView.getBottom()) / 2f,
animate);
}
}
diff --git a/src/org/lineageos/lineageparts/gestures/KeyHandler.java b/src/org/lineageos/lineageparts/gestures/KeyHandler.java
index 21744dc..8875537 100644
--- a/src/org/lineageos/lineageparts/gestures/KeyHandler.java
+++ b/src/org/lineageos/lineageparts/gestures/KeyHandler.java
@@ -163,7 +163,7 @@
mContext.getContentResolver(),
LineageSettings.System.PROXIMITY_ON_WAKE, mDefaultProximity ? 1 : 0) == 1;
if (mProximityWakeSupported && proxWakeEnabled && mProximitySensor != null) {
- mGestureWakeLock.acquire(2 * mProximityTimeOut);
+ mGestureWakeLock.acquire(2L * mProximityTimeOut);
mEventHandler.sendMessageDelayed(msg, mProximityTimeOut);
processEvent(action);
} else {
diff --git a/src/org/lineageos/lineageparts/lineagestats/ReportingService.java b/src/org/lineageos/lineageparts/lineagestats/ReportingService.java
index 1fde57f..44279b3 100644
--- a/src/org/lineageos/lineageparts/lineagestats/ReportingService.java
+++ b/src/org/lineageos/lineageparts/lineagestats/ReportingService.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 The CyanogenMod Project
- * 2017 The LineageOS Project
+ * 2017-2022 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.
@@ -38,15 +38,17 @@
protected void onHandleIntent(Intent intent) {
JobScheduler js = getSystemService(JobScheduler.class);
- String deviceId = Utilities.getUniqueID(getApplicationContext());
+ Context context = getApplicationContext();
+
+ String deviceId = Utilities.getUniqueID(context);
String deviceName = Utilities.getDevice();
String deviceVersion = Utilities.getModVersion();
- String deviceCountry = Utilities.getCountryCode(getApplicationContext());
- String deviceCarrier = Utilities.getCarrier(getApplicationContext());
- String deviceCarrierId = Utilities.getCarrierId(getApplicationContext());
+ String deviceCountry = Utilities.getCountryCode(context);
+ String deviceCarrier = Utilities.getCarrier(context);
+ String deviceCarrierId = Utilities.getCarrierId(context);
- final int lineageOldJobId = AnonymousStats.getLastJobId(getApplicationContext());
- final int lineageOrgJobId = AnonymousStats.getNextJobId(getApplicationContext());
+ final int lineageOldJobId = AnonymousStats.getLastJobId(context);
+ final int lineageOrgJobId = AnonymousStats.getNextJobId(context);
if (DEBUG) Log.d(TAG, "scheduling job id: " + lineageOrgJobId);
diff --git a/src/org/lineageos/lineageparts/lineagestats/StatsUploadJobService.java b/src/org/lineageos/lineageparts/lineagestats/StatsUploadJobService.java
index 59af1ca..bfe7413 100644
--- a/src/org/lineageos/lineageparts/lineagestats/StatsUploadJobService.java
+++ b/src/org/lineageos/lineageparts/lineagestats/StatsUploadJobService.java
@@ -36,6 +36,7 @@
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Map;
@@ -163,7 +164,7 @@
urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
OutputStream os = urlConnection.getOutputStream();
- os.write(json.toString().getBytes("UTF-8"));
+ os.write(json.toString().getBytes(StandardCharsets.UTF_8));
os.close();
final int responseCode = urlConnection.getResponseCode();
diff --git a/src/org/lineageos/lineageparts/livedisplay/DisplayColor.java b/src/org/lineageos/lineageparts/livedisplay/DisplayColor.java
index 5e40770..b1a9878 100644
--- a/src/org/lineageos/lineageparts/livedisplay/DisplayColor.java
+++ b/src/org/lineageos/lineageparts/livedisplay/DisplayColor.java
@@ -212,7 +212,7 @@
IntervalSeekBar isb = (IntervalSeekBar)seekBar;
float fp = isb.getProgressFloat();
if (fromUser) {
- mCurrentColors[mIndex] = fp > 1.0f ? 1.0f : fp;
+ mCurrentColors[mIndex] = Math.min(fp, 1.0f);
updateColors(mCurrentColors);
}
diff --git a/src/org/lineageos/lineageparts/logo/PlatLogoActivity.java b/src/org/lineageos/lineageparts/logo/PlatLogoActivity.java
index 2a7a632..db5e815 100644
--- a/src/org/lineageos/lineageparts/logo/PlatLogoActivity.java
+++ b/src/org/lineageos/lineageparts/logo/PlatLogoActivity.java
@@ -202,8 +202,8 @@
// Draw LineageOS Logo drawable
canvas.save();
{
- canvas.translate((-360 / 2) * mRadius / BASE_SCALE,
- (-180 / 2) * mRadius / BASE_SCALE);
+ canvas.translate((-360 / 2f) * mRadius / BASE_SCALE,
+ (-180 / 2f) * mRadius / BASE_SCALE);
canvas.scale(mRadius / BASE_SCALE, mRadius / BASE_SCALE);
mLogo.draw(canvas);
}
diff --git a/src/org/lineageos/lineageparts/notificationlight/AlphaPatternDrawable.java b/src/org/lineageos/lineageparts/notificationlight/AlphaPatternDrawable.java
index 5500b7c..b2989ee 100644
--- a/src/org/lineageos/lineageparts/notificationlight/AlphaPatternDrawable.java
+++ b/src/org/lineageos/lineageparts/notificationlight/AlphaPatternDrawable.java
@@ -84,8 +84,8 @@
int height = bounds.height();
int width = bounds.width();
- numRectanglesHorizontal = (int) Math.ceil((width / mRectangleSize));
- numRectanglesVertical = (int) Math.ceil(height / mRectangleSize);
+ numRectanglesHorizontal = (int) Math.ceil((float) width / mRectangleSize);
+ numRectanglesVertical = (int) Math.ceil((float) height / mRectangleSize);
generatePatternBitmap();
}
diff --git a/src/org/lineageos/lineageparts/notificationlight/BatteryBrightnessPreference.java b/src/org/lineageos/lineageparts/notificationlight/BatteryBrightnessPreference.java
index bccb63b..4e1cc55 100644
--- a/src/org/lineageos/lineageparts/notificationlight/BatteryBrightnessPreference.java
+++ b/src/org/lineageos/lineageparts/notificationlight/BatteryBrightnessPreference.java
@@ -16,6 +16,7 @@
package org.lineageos.lineageparts.notificationlight;
+import android.content.ContentResolver;
import android.content.Context;
import android.os.UserHandle;
import android.util.AttributeSet;
@@ -25,23 +26,23 @@
public class BatteryBrightnessPreference extends BrightnessPreference {
private static final String TAG = "BatteryBrightnessPreference";
- private final Context mContext;
+ private final ContentResolver mResolver;
public BatteryBrightnessPreference(Context context, AttributeSet attrs) {
super(context, attrs);
- mContext = context;
+ mResolver = context.getContentResolver();
}
@Override
protected int getBrightnessSetting() {
- return LineageSettings.System.getIntForUser(mContext.getContentResolver(),
+ return LineageSettings.System.getIntForUser(mResolver,
LineageSettings.System.BATTERY_LIGHT_BRIGHTNESS_LEVEL,
LIGHT_BRIGHTNESS_MAXIMUM, UserHandle.USER_CURRENT);
}
@Override
protected void setBrightnessSetting(int brightness) {
- LineageSettings.System.putIntForUser(mContext.getContentResolver(),
+ LineageSettings.System.putIntForUser(mResolver,
LineageSettings.System.BATTERY_LIGHT_BRIGHTNESS_LEVEL,
brightness, UserHandle.USER_CURRENT);
}
diff --git a/src/org/lineageos/lineageparts/notificationlight/BatteryBrightnessZenPreference.java b/src/org/lineageos/lineageparts/notificationlight/BatteryBrightnessZenPreference.java
index b0eb32a..15a4e25 100644
--- a/src/org/lineageos/lineageparts/notificationlight/BatteryBrightnessZenPreference.java
+++ b/src/org/lineageos/lineageparts/notificationlight/BatteryBrightnessZenPreference.java
@@ -16,6 +16,7 @@
package org.lineageos.lineageparts.notificationlight;
+import android.content.ContentResolver;
import android.content.Context;
import android.os.UserHandle;
import android.util.AttributeSet;
@@ -25,23 +26,23 @@
public class BatteryBrightnessZenPreference extends BrightnessPreference {
private static final String TAG = "BatteryBrightnessZenPreference";
- private final Context mContext;
+ private final ContentResolver mResolver;
public BatteryBrightnessZenPreference(Context context, AttributeSet attrs) {
super(context, attrs);
- mContext = context;
+ mResolver = context.getContentResolver();
}
@Override
protected int getBrightnessSetting() {
- return LineageSettings.System.getIntForUser(mContext.getContentResolver(),
+ return LineageSettings.System.getIntForUser(mResolver,
LineageSettings.System.BATTERY_LIGHT_BRIGHTNESS_LEVEL_ZEN,
LIGHT_BRIGHTNESS_MAXIMUM, UserHandle.USER_CURRENT);
}
@Override
protected void setBrightnessSetting(int brightness) {
- LineageSettings.System.putIntForUser(mContext.getContentResolver(),
+ LineageSettings.System.putIntForUser(mResolver,
LineageSettings.System.BATTERY_LIGHT_BRIGHTNESS_LEVEL_ZEN,
brightness, UserHandle.USER_CURRENT);
}
diff --git a/src/org/lineageos/lineageparts/notificationlight/NotificationBrightnessPreference.java b/src/org/lineageos/lineageparts/notificationlight/NotificationBrightnessPreference.java
index ed2c78a..0d36bba 100644
--- a/src/org/lineageos/lineageparts/notificationlight/NotificationBrightnessPreference.java
+++ b/src/org/lineageos/lineageparts/notificationlight/NotificationBrightnessPreference.java
@@ -16,6 +16,7 @@
package org.lineageos.lineageparts.notificationlight;
+import android.content.ContentResolver;
import android.content.Context;
import android.os.UserHandle;
import android.util.AttributeSet;
@@ -25,23 +26,23 @@
public class NotificationBrightnessPreference extends BrightnessPreference {
private static final String TAG = "NotificationBrightnessPreference";
- private final Context mContext;
+ private final ContentResolver mResolver;
public NotificationBrightnessPreference(Context context, AttributeSet attrs) {
super(context, attrs);
- mContext = context;
+ mResolver = context.getContentResolver();
}
@Override
protected int getBrightnessSetting() {
- return LineageSettings.System.getIntForUser(mContext.getContentResolver(),
+ return LineageSettings.System.getIntForUser(mResolver,
LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL,
LIGHT_BRIGHTNESS_MAXIMUM, UserHandle.USER_CURRENT);
}
@Override
protected void setBrightnessSetting(int brightness) {
- LineageSettings.System.putIntForUser(mContext.getContentResolver(),
+ LineageSettings.System.putIntForUser(mResolver,
LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL,
brightness, UserHandle.USER_CURRENT);
}
diff --git a/src/org/lineageos/lineageparts/notificationlight/NotificationBrightnessZenPreference.java b/src/org/lineageos/lineageparts/notificationlight/NotificationBrightnessZenPreference.java
index 600c159..2871f1f 100644
--- a/src/org/lineageos/lineageparts/notificationlight/NotificationBrightnessZenPreference.java
+++ b/src/org/lineageos/lineageparts/notificationlight/NotificationBrightnessZenPreference.java
@@ -16,6 +16,7 @@
package org.lineageos.lineageparts.notificationlight;
+import android.content.ContentResolver;
import android.content.Context;
import android.os.UserHandle;
import android.util.AttributeSet;
@@ -25,23 +26,23 @@
public class NotificationBrightnessZenPreference extends BrightnessPreference {
private static final String TAG = "NotificationBrightnessZenPreference";
- private final Context mContext;
+ private final ContentResolver mResolver;
public NotificationBrightnessZenPreference(Context context, AttributeSet attrs) {
super(context, attrs);
- mContext = context;
+ mResolver = context.getContentResolver();
}
@Override
protected int getBrightnessSetting() {
- return LineageSettings.System.getIntForUser(mContext.getContentResolver(),
+ return LineageSettings.System.getIntForUser(mResolver,
LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_ZEN,
LIGHT_BRIGHTNESS_MAXIMUM, UserHandle.USER_CURRENT);
}
@Override
protected void setBrightnessSetting(int brightness) {
- LineageSettings.System.putIntForUser(mContext.getContentResolver(),
+ LineageSettings.System.putIntForUser(mResolver,
LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL_ZEN,
brightness, UserHandle.USER_CURRENT);
}
diff --git a/src/org/lineageos/lineageparts/notificationlight/NotificationLightSettings.java b/src/org/lineageos/lineageparts/notificationlight/NotificationLightSettings.java
index 3eb34c2..48463bf 100644
--- a/src/org/lineageos/lineageparts/notificationlight/NotificationLightSettings.java
+++ b/src/org/lineageos/lineageparts/notificationlight/NotificationLightSettings.java
@@ -319,8 +319,7 @@
}
}
- private void maybeDisplayApplicationHint(Context context)
- {
+ private void maybeDisplayApplicationHint(Context context) {
/* Display a pref explaining how to add apps */
if (mApplicationPrefList != null && mApplicationPrefList.getPreferenceCount() == 1) {
String summary = getResources().getString(
diff --git a/src/org/lineageos/lineageparts/profiles/SetupTriggersFragment.java b/src/org/lineageos/lineageparts/profiles/SetupTriggersFragment.java
index 88efa89..78d4ccf 100644
--- a/src/org/lineageos/lineageparts/profiles/SetupTriggersFragment.java
+++ b/src/org/lineageos/lineageparts/profiles/SetupTriggersFragment.java
@@ -118,7 +118,7 @@
TriggerPagerAdapter.TriggerFragments.values();
for (final TriggerPagerAdapter.TriggerFragments fragment : fragments) {
- if (fragment.getFragmentClass() == NfcTriggerFragment.class) {
+ if (fragment.getFragmentClass().equals(NfcTriggerFragment.class)) {
if (!getActivity().getPackageManager().hasSystemFeature(
PackageManager.FEATURE_NFC)) {
// device doesn't have NFC