2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 06:05:12 +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 PairingHandlerCallback mCallback;
protected final PairingHandlerCallback mCallback;
protected BasePairingHandler(Device device, PairingHandlerCallback callback) {
this.mDevice = device;

View File

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

View File

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

View File

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

View File

@@ -85,7 +85,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
private boolean listening = false;
// 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
public void linkDisconnected(LanLink brokenLink) {

View File

@@ -76,7 +76,7 @@ public class Device implements BaseLink.PacketReceiver {
private PairStatus pairStatus;
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<>();
@@ -621,7 +621,7 @@ public class Device implements BaseLink.PacketReceiver {
}
}
private SendPacketStatusCallback defaultCallback = new SendPacketStatusCallback() {
private final SendPacketStatusCallback defaultCallback = new SendPacketStatusCallback() {
@Override
public void onSuccess() {
}

View File

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

View File

@@ -212,7 +212,7 @@ public class SMSHelper {
* Represent an ID used to uniquely identify a message thread
*/
public static class ThreadID {
Integer threadID;
final Integer threadID;
static final String lookupColumn = Telephony.Sms.THREAD_ID;
public ThreadID(Integer threadID) {
@@ -319,8 +319,8 @@ public class SMSHelper {
private static MessageLooper singleton = null;
private static Looper looper = null;
private static Lock looperReadyLock = new ReentrantLock();
private static Condition looperReady = looperReadyLock.newCondition();
private static final Lock looperReadyLock = new ReentrantLock();
private static final Condition looperReady = looperReadyLock.newCondition();
private MessageLooper() {
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_BATTERY_LOW = 1;
private NetworkPacket batteryInfo = new NetworkPacket(PACKET_TYPE_BATTERY);
private final NetworkPacket batteryInfo = new NetworkPacket(PACKET_TYPE_BATTERY);
@Override
public String getDisplayName() {

View File

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

View File

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

View File

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

View File

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

View File

@@ -39,11 +39,12 @@ public class PointerAccelerationProfileFactory {
// Higher values will reduce the amount of noise in the speed calculation
// but will also increase latency until the acceleration kicks in.
// 150ms seemed like a nice middle ground.
long freshThreshold = 150;
final long freshThreshold = 150;
private static class TouchDeltaEvent {
float x, y;
long time;
final float x;
final float y;
final long time;
TouchDeltaEvent(float x, float y, long t) {
this.x = x;
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. */
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 )
* It is similar to x.org server's Polynomial pointer acceleration profile. */
private static class PolynomialProfile extends SpeedBasedAccelerationProfile {
float exponent;
final float exponent;
PolynomialProfile(float exponent) {
this.exponent = exponent;

View File

@@ -84,7 +84,7 @@ final class AlbumArtCache {
/**
* 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
@@ -242,9 +242,9 @@ final class AlbumArtCache {
}
private static final class FetchURLTask extends AsyncTask<Void, Void, Boolean> {
private URL url;
private final URL url;
private InputStream input;
private DiskLruCache.Editor cacheItem;
private final DiskLruCache.Editor cacheItem;
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 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() {
return instance;
@@ -69,20 +69,20 @@ public class MprisMediaSession implements SharedPreferences.OnSharedPreferenceCh
private String notificationDevice = null;
private MprisPlugin.MprisPlayer notificationPlayer = null;
//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 MediaSessionCompat mediaSession;
//Callback for mpris plugin updates
private Handler mediaNotificationHandler = new Handler(Looper.getMainLooper()) {
private final Handler mediaNotificationHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
updateMediaNotification();
}
};
//Callback for control via the media session API
private MediaSessionCompat.Callback mediaSessionCallback = new MediaSessionCompat.Callback() {
private final MediaSessionCompat.Callback mediaSessionCallback = new MediaSessionCompat.Callback() {
@Override
public void onPlay() {
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_REQUEST = "kdeconnect.mpris.request";
private HashMap<String, MprisPlayer> players = new HashMap<>();
private final HashMap<String, MprisPlayer> players = new HashMap<>();
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
public String getDisplayName() {

View File

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

View File

@@ -6,9 +6,9 @@ import java.util.ArrayList;
import java.util.UUID;
class RepliableNotification {
String id = UUID.randomUUID().toString();
final String id = UUID.randomUUID().toString();
PendingIntent pendingIntent;
ArrayList<android.app.RemoteInput> remoteInputs = new ArrayList<>();
final ArrayList<android.app.RemoteInput> remoteInputs = new ArrayList<>();
String packageName;
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:
*/
private static ArrayList<RemoteKeyboardPlugin> instances = new ArrayList<>();
private static ReentrantLock instancesLock = new ReentrantLock(true);
private static final ArrayList<RemoteKeyboardPlugin> instances = new ArrayList<>();
private static final ReentrantLock instancesLock = new ReentrantLock(true);
private static ArrayList<RemoteKeyboardPlugin> getInstances() {
return instances;
@@ -70,7 +70,7 @@ public class RemoteKeyboardPlugin extends Plugin {
return instances.size() > 0;
}
private static SparseIntArray specialKeyMap = new SparseIntArray();
private static final SparseIntArray specialKeyMap = new SparseIntArray();
static {
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_REQUEST = "kdeconnect.runcommand.request";
private ArrayList<JSONObject> commandList = new ArrayList<>();
private ArrayList<CommandsChangedCallback> callbacks = new ArrayList<>();
private final ArrayList<JSONObject> commandList = new ArrayList<>();
private final ArrayList<CommandsChangedCallback> callbacks = new ArrayList<>();
private final ArrayList<CommandEntry> commandItems = new ArrayList<>();
private boolean canAddCommand;

View File

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

View File

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

View File

@@ -38,7 +38,7 @@ class Sink {
private boolean mute;
private int maxVolume;
private List<UpdateListener> listeners;
private final List<UpdateListener> listeners;
Sink(JSONObject obj) throws JSONException {
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 Sink sink;
private final Sink sink;
private UIListener(Sink sink) {
this.sink = sink;

View File

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

View File

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

View File

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

View File

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