2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-02 15:15:09 +00:00

Make final where possible

This commit is contained in:
Nicolas Fella
2018-10-27 00:01:30 +02:00
parent a49a145d69
commit e1096f5bc8
29 changed files with 54 additions and 53 deletions

View File

@@ -51,9 +51,9 @@ public abstract class BasePairingHandler {
} }
protected Device mDevice; protected final Device mDevice;
protected PairStatus mPairStatus; protected PairStatus mPairStatus;
protected PairingHandlerCallback mCallback; protected final PairingHandlerCallback mCallback;
protected BasePairingHandler(Device device, PairingHandlerCallback callback) { protected BasePairingHandler(Device device, PairingHandlerCallback callback) {
this.mDevice = device; this.mDevice = device;

View File

@@ -52,7 +52,7 @@ public class BluetoothLink extends BaseLink {
private boolean continueAccepting = true; private boolean continueAccepting = true;
private Thread receivingThread = new Thread(new Runnable() { private final Thread receivingThread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View File

@@ -221,7 +221,7 @@ public class BluetoothLinkProvider extends BaseLinkProvider {
private class ClientRunnable extends BroadcastReceiver implements Runnable { private class ClientRunnable extends BroadcastReceiver implements Runnable {
private boolean continueProcessing = true; private boolean continueProcessing = true;
private Map<BluetoothDevice, Thread> connectionThreads = new HashMap<>(); private final Map<BluetoothDevice, Thread> connectionThreads = new HashMap<>();
void stopProcessing() { void stopProcessing() {
continueProcessing = false; continueProcessing = false;

View File

@@ -63,7 +63,7 @@ public class LanLink extends BaseLink {
private volatile Socket socket = null; private volatile Socket socket = null;
private LinkDisconnectedCallback callback; private final LinkDisconnectedCallback callback;
@Override @Override
public void disconnect() { public void disconnect() {

View File

@@ -85,7 +85,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
private boolean listening = false; private boolean listening = false;
// To prevent infinte loop between Android < IceCream because both device can only broadcast identity package but cannot connect via TCP // To prevent infinte loop between Android < IceCream because both device can only broadcast identity package but cannot connect via TCP
private ArrayList<InetAddress> reverseConnectionBlackList = new ArrayList<>(); private final ArrayList<InetAddress> reverseConnectionBlackList = new ArrayList<>();
@Override // SocketClosedCallback @Override // SocketClosedCallback
public void linkDisconnected(LanLink brokenLink) { public void linkDisconnected(LanLink brokenLink) {

View File

@@ -76,7 +76,7 @@ public class Device implements BaseLink.PacketReceiver {
private PairStatus pairStatus; private PairStatus pairStatus;
private final CopyOnWriteArrayList<PairingCallback> pairingCallback = new CopyOnWriteArrayList<>(); private final CopyOnWriteArrayList<PairingCallback> pairingCallback = new CopyOnWriteArrayList<>();
private Map<String, BasePairingHandler> pairingHandlers = new HashMap<>(); private final Map<String, BasePairingHandler> pairingHandlers = new HashMap<>();
private final CopyOnWriteArrayList<BaseLink> links = new CopyOnWriteArrayList<>(); private final CopyOnWriteArrayList<BaseLink> links = new CopyOnWriteArrayList<>();
@@ -621,7 +621,7 @@ public class Device implements BaseLink.PacketReceiver {
} }
} }
private SendPacketStatusCallback defaultCallback = new SendPacketStatusCallback() { private final SendPacketStatusCallback defaultCallback = new SendPacketStatusCallback() {
@Override @Override
public void onSuccess() { public void onSuccess() {
} }

View File

@@ -4,7 +4,7 @@ package org.kde.kdeconnect.Helpers;
import java.security.SecureRandom; import java.security.SecureRandom;
public class RandomHelper { public class RandomHelper {
public static SecureRandom secureRandom = new SecureRandom(); public static final SecureRandom secureRandom = new SecureRandom();
private static final char[] symbols = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + private static final char[] symbols = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"abcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyz" +

View File

@@ -212,7 +212,7 @@ public class SMSHelper {
* Represent an ID used to uniquely identify a message thread * Represent an ID used to uniquely identify a message thread
*/ */
public static class ThreadID { public static class ThreadID {
Integer threadID; final Integer threadID;
static final String lookupColumn = Telephony.Sms.THREAD_ID; static final String lookupColumn = Telephony.Sms.THREAD_ID;
public ThreadID(Integer threadID) { public ThreadID(Integer threadID) {
@@ -319,8 +319,8 @@ public class SMSHelper {
private static MessageLooper singleton = null; private static MessageLooper singleton = null;
private static Looper looper = null; private static Looper looper = null;
private static Lock looperReadyLock = new ReentrantLock(); private static final Lock looperReadyLock = new ReentrantLock();
private static Condition looperReady = looperReadyLock.newCondition(); private static final Condition looperReady = looperReadyLock.newCondition();
private MessageLooper() { private MessageLooper() {
setName("MessageHelperLooper"); setName("MessageHelperLooper");

View File

@@ -40,7 +40,7 @@ public class BatteryPlugin extends Plugin {
private static final int THRESHOLD_EVENT_NONE = 0; private static final int THRESHOLD_EVENT_NONE = 0;
private static final int THRESHOLD_EVENT_BATTERY_LOW = 1; private static final int THRESHOLD_EVENT_BATTERY_LOW = 1;
private NetworkPacket batteryInfo = new NetworkPacket(PACKET_TYPE_BATTERY); private final NetworkPacket batteryInfo = new NetworkPacket(PACKET_TYPE_BATTERY);
@Override @Override
public String getDisplayName() { public String getDisplayName() {

View File

@@ -37,7 +37,7 @@ public class ClipboardListener {
void clipboardChanged(String content); void clipboardChanged(String content);
} }
private HashSet<ClipboardObserver> observers = new HashSet<>(); private final HashSet<ClipboardObserver> observers = new HashSet<>();
private final Context context; private final Context context;
private String currentContent; private String currentContent;

View File

@@ -45,7 +45,7 @@ public class ClipboardPlugin extends Plugin {
return true; return true;
} }
private ClipboardListener.ClipboardObserver observer = content -> { private final ClipboardListener.ClipboardObserver observer = content -> {
NetworkPacket np = new NetworkPacket(ClipboardPlugin.PACKET_TYPE_CLIPBOARD); NetworkPacket np = new NetworkPacket(ClipboardPlugin.PACKET_TYPE_CLIPBOARD);
np.set("content", content); np.set("content", content);
device.sendPacket(np); device.sendPacket(np);

View File

@@ -3,7 +3,7 @@ package org.kde.kdeconnect.Plugins.MousePadPlugin;
import android.view.inputmethod.BaseInputConnection; import android.view.inputmethod.BaseInputConnection;
class KeyInputConnection extends BaseInputConnection { class KeyInputConnection extends BaseInputConnection {
private KeyListenerView view; private final KeyListenerView view;
public KeyInputConnection(KeyListenerView targetView, boolean fullEditor) { public KeyInputConnection(KeyListenerView targetView, boolean fullEditor) {
super(targetView, fullEditor); super(targetView, fullEditor);

View File

@@ -36,7 +36,7 @@ public class KeyListenerView extends View {
private String deviceId; private String deviceId;
public static SparseIntArray SpecialKeysMap = new SparseIntArray(); public static final SparseIntArray SpecialKeysMap = new SparseIntArray();
static { static {
int i = 0; int i = 0;

View File

@@ -39,11 +39,12 @@ public class PointerAccelerationProfileFactory {
// Higher values will reduce the amount of noise in the speed calculation // Higher values will reduce the amount of noise in the speed calculation
// but will also increase latency until the acceleration kicks in. // but will also increase latency until the acceleration kicks in.
// 150ms seemed like a nice middle ground. // 150ms seemed like a nice middle ground.
long freshThreshold = 150; final long freshThreshold = 150;
private static class TouchDeltaEvent { private static class TouchDeltaEvent {
float x, y; final float x;
long time; final float y;
final long time;
TouchDeltaEvent(float x, float y, long t) { TouchDeltaEvent(float x, float y, long t) {
this.x = x; this.x = x;
this.y = y; this.y = y;
@@ -51,7 +52,7 @@ public class PointerAccelerationProfileFactory {
} }
} }
private TouchDeltaEvent[] touchEventHistory = new TouchDeltaEvent[32]; private final TouchDeltaEvent[] touchEventHistory = new TouchDeltaEvent[32];
/* add an event to the touchEventHistory array, shifting everything else in the array. */ /* add an event to the touchEventHistory array, shifting everything else in the array. */
private void addHistory(float deltaX, float deltaY, long eventTime) { private void addHistory(float deltaX, float deltaY, long eventTime) {
@@ -124,7 +125,7 @@ public class PointerAccelerationProfileFactory {
/* Pointer acceleration with mouse_delta = touch_delta * ( touch_speed ^ exponent ) /* Pointer acceleration with mouse_delta = touch_delta * ( touch_speed ^ exponent )
* It is similar to x.org server's Polynomial pointer acceleration profile. */ * It is similar to x.org server's Polynomial pointer acceleration profile. */
private static class PolynomialProfile extends SpeedBasedAccelerationProfile { private static class PolynomialProfile extends SpeedBasedAccelerationProfile {
float exponent; final float exponent;
PolynomialProfile(float exponent) { PolynomialProfile(float exponent) {
this.exponent = exponent; this.exponent = exponent;

View File

@@ -84,7 +84,7 @@ final class AlbumArtCache {
/** /**
* A list of plugins to notify on fetched album art * A list of plugins to notify on fetched album art
*/ */
private static ArrayList<MprisPlugin> registeredPlugins = new ArrayList<>(); private static final ArrayList<MprisPlugin> registeredPlugins = new ArrayList<>();
/** /**
* Initializes the disk cache. Needs to be called at least once before trying to use the cache * Initializes the disk cache. Needs to be called at least once before trying to use the cache
@@ -242,9 +242,9 @@ final class AlbumArtCache {
} }
private static final class FetchURLTask extends AsyncTask<Void, Void, Boolean> { private static final class FetchURLTask extends AsyncTask<Void, Void, Boolean> {
private URL url; private final URL url;
private InputStream input; private InputStream input;
private DiskLruCache.Editor cacheItem; private final DiskLruCache.Editor cacheItem;
private OutputStream output; private OutputStream output;
/** /**

View File

@@ -55,7 +55,7 @@ public class MprisMediaSession implements SharedPreferences.OnSharedPreferenceCh
private final static int MPRIS_MEDIA_NOTIFICATION_ID = 0x91b70463; // echo MprisNotification | md5sum | head -c 8 private final static int MPRIS_MEDIA_NOTIFICATION_ID = 0x91b70463; // echo MprisNotification | md5sum | head -c 8
private final static String MPRIS_MEDIA_SESSION_TAG = "org.kde.kdeconnect_tp.media_session"; private final static String MPRIS_MEDIA_SESSION_TAG = "org.kde.kdeconnect_tp.media_session";
private static MprisMediaSession instance = new MprisMediaSession(); private static final MprisMediaSession instance = new MprisMediaSession();
public static MprisMediaSession getInstance() { public static MprisMediaSession getInstance() {
return instance; return instance;
@@ -69,20 +69,20 @@ public class MprisMediaSession implements SharedPreferences.OnSharedPreferenceCh
private String notificationDevice = null; private String notificationDevice = null;
private MprisPlugin.MprisPlayer notificationPlayer = null; private MprisPlugin.MprisPlayer notificationPlayer = null;
//Holds the device ids for which we can display a notification //Holds the device ids for which we can display a notification
private HashSet<String> mprisDevices = new HashSet<>(); private final HashSet<String> mprisDevices = new HashSet<>();
private Context context; private Context context;
private MediaSessionCompat mediaSession; private MediaSessionCompat mediaSession;
//Callback for mpris plugin updates //Callback for mpris plugin updates
private Handler mediaNotificationHandler = new Handler(Looper.getMainLooper()) { private final Handler mediaNotificationHandler = new Handler(Looper.getMainLooper()) {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
updateMediaNotification(); updateMediaNotification();
} }
}; };
//Callback for control via the media session API //Callback for control via the media session API
private MediaSessionCompat.Callback mediaSessionCallback = new MediaSessionCompat.Callback() { private final MediaSessionCompat.Callback mediaSessionCallback = new MediaSessionCompat.Callback() {
@Override @Override
public void onPlay() { public void onPlay() {
notificationPlayer.play(); notificationPlayer.play();

View File

@@ -204,11 +204,11 @@ public class MprisPlugin extends Plugin {
private final static String PACKET_TYPE_MPRIS = "kdeconnect.mpris"; private final static String PACKET_TYPE_MPRIS = "kdeconnect.mpris";
private final static String PACKET_TYPE_MPRIS_REQUEST = "kdeconnect.mpris.request"; private final static String PACKET_TYPE_MPRIS_REQUEST = "kdeconnect.mpris.request";
private HashMap<String, MprisPlayer> players = new HashMap<>(); private final HashMap<String, MprisPlayer> players = new HashMap<>();
private boolean supportAlbumArtPayload = false; private boolean supportAlbumArtPayload = false;
private HashMap<String, Handler> playerStatusUpdated = new HashMap<>(); private final HashMap<String, Handler> playerStatusUpdated = new HashMap<>();
private HashMap<String, Handler> playerListUpdated = new HashMap<>(); private final HashMap<String, Handler> playerListUpdated = new HashMap<>();
@Override @Override
public String getDisplayName() { public String getDisplayName() {

View File

@@ -29,9 +29,9 @@ import android.support.annotation.RequiresApi;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
class MprisReceiverPlayer { class MprisReceiverPlayer {
private MediaController controller; private final MediaController controller;
private String name; private final String name;
private boolean isPlaying; private boolean isPlaying;

View File

@@ -6,9 +6,9 @@ import java.util.ArrayList;
import java.util.UUID; import java.util.UUID;
class RepliableNotification { class RepliableNotification {
String id = UUID.randomUUID().toString(); final String id = UUID.randomUUID().toString();
PendingIntent pendingIntent; PendingIntent pendingIntent;
ArrayList<android.app.RemoteInput> remoteInputs = new ArrayList<>(); final ArrayList<android.app.RemoteInput> remoteInputs = new ArrayList<>();
String packageName; String packageName;
String tag; String tag;
} }

View File

@@ -49,8 +49,8 @@ public class RemoteKeyboardPlugin extends Plugin {
/** /**
* Track and expose plugin instances to allow for a 'connected'-indicator in the IME: * Track and expose plugin instances to allow for a 'connected'-indicator in the IME:
*/ */
private static ArrayList<RemoteKeyboardPlugin> instances = new ArrayList<>(); private static final ArrayList<RemoteKeyboardPlugin> instances = new ArrayList<>();
private static ReentrantLock instancesLock = new ReentrantLock(true); private static final ReentrantLock instancesLock = new ReentrantLock(true);
private static ArrayList<RemoteKeyboardPlugin> getInstances() { private static ArrayList<RemoteKeyboardPlugin> getInstances() {
return instances; return instances;
@@ -70,7 +70,7 @@ public class RemoteKeyboardPlugin extends Plugin {
return instances.size() > 0; return instances.size() > 0;
} }
private static SparseIntArray specialKeyMap = new SparseIntArray(); private static final SparseIntArray specialKeyMap = new SparseIntArray();
static { static {
int i = 0; int i = 0;

View File

@@ -41,8 +41,8 @@ public class RunCommandPlugin extends Plugin {
private final static String PACKET_TYPE_RUNCOMMAND = "kdeconnect.runcommand"; private final static String PACKET_TYPE_RUNCOMMAND = "kdeconnect.runcommand";
private final static String PACKET_TYPE_RUNCOMMAND_REQUEST = "kdeconnect.runcommand.request"; private final static String PACKET_TYPE_RUNCOMMAND_REQUEST = "kdeconnect.runcommand.request";
private ArrayList<JSONObject> commandList = new ArrayList<>(); private final ArrayList<JSONObject> commandList = new ArrayList<>();
private ArrayList<CommandsChangedCallback> callbacks = new ArrayList<>(); private final ArrayList<CommandsChangedCallback> callbacks = new ArrayList<>();
private final ArrayList<CommandEntry> commandItems = new ArrayList<>(); private final ArrayList<CommandEntry> commandItems = new ArrayList<>();
private boolean canAddCommand; private boolean canAddCommand;

View File

@@ -147,10 +147,10 @@ public class SMSPlugin extends Plugin {
private long mostRecentTimestamp = 0; private long mostRecentTimestamp = 0;
// Since the mostRecentTimestamp is accessed both from the plugin's thread and the ContentObserver // Since the mostRecentTimestamp is accessed both from the plugin's thread and the ContentObserver
// thread, make sure that access is coherent // thread, make sure that access is coherent
private Lock mostRecentTimestampLock = new ReentrantLock(); private final Lock mostRecentTimestampLock = new ReentrantLock();
private class MessageContentObserver extends ContentObserver { private class MessageContentObserver extends ContentObserver {
SMSPlugin mPlugin; final SMSPlugin mPlugin;
/** /**
* Create a ContentObserver to watch the Messages database. onChange is called for * Create a ContentObserver to watch the Messages database. onChange is called for

View File

@@ -45,10 +45,10 @@ import java.io.FileNotFoundException;
class ShareNotification { class ShareNotification {
private final String filename; private final String filename;
private NotificationManager notificationManager; private final NotificationManager notificationManager;
private int notificationId; private final int notificationId;
private NotificationCompat.Builder builder; private NotificationCompat.Builder builder;
private Device device; private final Device device;
public ShareNotification(Device device, String filename) { public ShareNotification(Device device, String filename) {
this.device = device; this.device = device;

View File

@@ -38,7 +38,7 @@ class Sink {
private boolean mute; private boolean mute;
private int maxVolume; private int maxVolume;
private List<UpdateListener> listeners; private final List<UpdateListener> listeners;
Sink(JSONObject obj) throws JSONException { Sink(JSONObject obj) throws JSONException {
listeners = new ArrayList<>(); listeners = new ArrayList<>();

View File

@@ -138,7 +138,7 @@ public class SystemvolumeFragment extends ListFragment implements Sink.UpdateLis
private class UIListener implements SeekBar.OnSeekBarChangeListener, ImageButton.OnClickListener { private class UIListener implements SeekBar.OnSeekBarChangeListener, ImageButton.OnClickListener {
private Sink sink; private final Sink sink;
private UIListener(Sink sink) { private UIListener(Sink sink) {
this.sink = sink; this.sink = sink;

View File

@@ -41,8 +41,8 @@ public class SystemvolumePlugin extends Plugin {
void sinksChanged(); void sinksChanged();
} }
private HashMap<String, Sink> sinks; private final HashMap<String, Sink> sinks;
private ArrayList<SinkListener> listeners; private final ArrayList<SinkListener> listeners;
public SystemvolumePlugin() { public SystemvolumePlugin() {
sinks = new HashMap<>(); sinks = new HashMap<>();

View File

@@ -76,7 +76,7 @@ public class CustomDevicesActivity extends AppCompatActivity {
} }
private boolean dialogAlreadyShown = false; private boolean dialogAlreadyShown = false;
private AdapterView.OnItemClickListener onClickListener = (parent, view, position, id) -> { private final AdapterView.OnItemClickListener onClickListener = (parent, view, position, id) -> {
if (dialogAlreadyShown) { if (dialogAlreadyShown) {
return; return;

View File

@@ -349,7 +349,7 @@ public class MainActivity extends AppCompatActivity {
void onNameChanged(String newName); void onNameChanged(String newName);
} }
private Set<NameChangeCallback> nameChangeSubscribers = new HashSet<>(); private final Set<NameChangeCallback> nameChangeSubscribers = new HashSet<>();
public void addNameChangeCallback(NameChangeCallback cb) { public void addNameChangeCallback(NameChangeCallback cb) {
nameChangeSubscribers.add(cb); nameChangeSubscribers.add(cb);

View File

@@ -108,7 +108,7 @@ class LanLinkTest extends AndroidTestCase {
class Downloader extends Thread { class Downloader extends Thread {
NetworkPacket np; NetworkPacket np;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
void setNetworkPacket(NetworkPacket networkPacket) { void setNetworkPacket(NetworkPacket networkPacket) {
this.np = networkPacket; this.np = networkPacket;