mirror of
https://invent.kde.org/network/kdeconnect-android.git
synced 2025-12-12 20:35:58 +01:00
Minor fixes (mostly cosmetic) as per Android Lint analysis
This commit is contained in:
@@ -3,7 +3,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.2.3'
|
||||
classpath 'com.android.tools.build:gradle:1.3.0'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,13 +49,14 @@ dependencies {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
compile 'com.android.support:support-v4:22.2.0'
|
||||
compile 'com.android.support:appcompat-v7:22.2.0'
|
||||
compile 'com.android.support:support-v4:22.2.1'
|
||||
compile 'com.android.support:appcompat-v7:22.2.1'
|
||||
compile 'com.android.support:design:22.2.1'
|
||||
|
||||
compile 'org.apache.mina:mina-core:2.0.9'
|
||||
compile 'org.apache.sshd:sshd-core:0.8.0'
|
||||
compile 'org.bouncycastle:bcprov-jdk16:1.46'
|
||||
|
||||
|
||||
androidTestCompile 'org.mockito:mockito-core:1.10.19'
|
||||
|
||||
// Because mockito has some problems with dex environment
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
android:baselineAligned="false"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="12dip"
|
||||
android:paddingStart="12dip"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingRight="?android:attr/scrollbarSize"
|
||||
android:paddingEnd="?android:attr/scrollbarSize"
|
||||
android:background="@drawable/abc_list_selector_holo_dark"
|
||||
android:orientation="vertical">
|
||||
<!-- We should use android:background="@android:/listChoiceBackgroundIndicator"
|
||||
|
||||
@@ -145,6 +145,7 @@
|
||||
android:layout_height="30dip"
|
||||
android:maxWidth="30dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginEnd="10dip"
|
||||
android:id="@+id/imageView"
|
||||
android:layout_weight="0"
|
||||
android:layout_gravity="left|center_vertical"
|
||||
|
||||
@@ -32,7 +32,7 @@ public abstract class BaseLink {
|
||||
|
||||
private final BaseLinkProvider linkProvider;
|
||||
private final String deviceId;
|
||||
private final ArrayList<PackageReceiver> receivers = new ArrayList<PackageReceiver>();
|
||||
private final ArrayList<PackageReceiver> receivers = new ArrayList<>();
|
||||
protected PrivateKey privateKey;
|
||||
|
||||
protected BaseLink(String deviceId, BaseLinkProvider linkProvider) {
|
||||
@@ -54,7 +54,7 @@ public abstract class BaseLink {
|
||||
|
||||
|
||||
public interface PackageReceiver {
|
||||
public void onPackageReceived(NetworkPackage np);
|
||||
void onPackageReceived(NetworkPackage np);
|
||||
}
|
||||
|
||||
public void addPackageReceiver(PackageReceiver pr) {
|
||||
|
||||
@@ -20,20 +20,17 @@
|
||||
|
||||
package org.kde.kdeconnect.Backends;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.kde.kdeconnect.Backends.BaseLink;
|
||||
import org.kde.kdeconnect.NetworkPackage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class BaseLinkProvider {
|
||||
|
||||
private final ArrayList<ConnectionReceiver> connectionReceivers = new ArrayList<ConnectionReceiver>();
|
||||
private final ArrayList<ConnectionReceiver> connectionReceivers = new ArrayList<>();
|
||||
|
||||
public interface ConnectionReceiver {
|
||||
public void onConnectionReceived(NetworkPackage identityPackage, BaseLink link);
|
||||
public void onConnectionLost(BaseLink link);
|
||||
void onConnectionReceived(NetworkPackage identityPackage, BaseLink link);
|
||||
void onConnectionLost(BaseLink link);
|
||||
}
|
||||
|
||||
public void addConnectionReceiver(ConnectionReceiver cr) {
|
||||
|
||||
@@ -38,9 +38,6 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.nio.channels.NotYetConnectedException;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class LanLink extends BaseLink {
|
||||
|
||||
|
||||
@@ -58,9 +58,9 @@ public class LanLinkProvider extends BaseLinkProvider {
|
||||
private final static int port = 1714;
|
||||
|
||||
private final Context context;
|
||||
private final HashMap<String, LanLink> visibleComputers = new HashMap<String, LanLink>();
|
||||
private final LongSparseArray<LanLink> nioSessions = new LongSparseArray<LanLink>();
|
||||
private final LongSparseArray<NioSocketConnector> nioConnectors = new LongSparseArray<NioSocketConnector>();
|
||||
private final HashMap<String, LanLink> visibleComputers = new HashMap<>();
|
||||
private final LongSparseArray<LanLink> nioSessions = new LongSparseArray<>();
|
||||
private final LongSparseArray<NioSocketConnector> nioConnectors = new LongSparseArray<>();
|
||||
|
||||
private NioSocketAcceptor tcpAcceptor = null;
|
||||
private NioDatagramAcceptor udpAcceptor = null;
|
||||
@@ -317,7 +317,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
||||
|
||||
String deviceListPrefs = PreferenceManager.getDefaultSharedPreferences(context).getString(
|
||||
KEY_CUSTOM_DEVLIST_PREFERENCE, "");
|
||||
ArrayList<String> iplist = new ArrayList<String>();
|
||||
ArrayList<String> iplist = new ArrayList<>();
|
||||
if (!deviceListPrefs.isEmpty()) {
|
||||
iplist = CustomDevicesActivity.deserializeIpList(deviceListPrefs);
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class BackgroundService extends Service {
|
||||
|
||||
private final ArrayList<BaseLinkProvider> linkProviders = new ArrayList<BaseLinkProvider>();
|
||||
private final ArrayList<BaseLinkProvider> linkProviders = new ArrayList<>();
|
||||
|
||||
private final HashMap<String, Device> devices = new HashMap<String, Device>();
|
||||
private final HashMap<String, Device> devices = new HashMap<>();
|
||||
|
||||
private final Device.PairingCallback devicePairingCallback = new Device.PairingCallback() {
|
||||
@Override
|
||||
@@ -286,7 +286,7 @@ public class BackgroundService extends Service {
|
||||
void onServiceStart(BackgroundService service);
|
||||
}
|
||||
|
||||
private final static ArrayList<InstanceCallback> callbacks = new ArrayList<InstanceCallback>();
|
||||
private final static ArrayList<InstanceCallback> callbacks = new ArrayList<>();
|
||||
|
||||
private final static Lock mutex = new ReentrantLock(true);
|
||||
|
||||
|
||||
@@ -28,11 +28,11 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -90,20 +90,20 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
}
|
||||
|
||||
public interface PairingCallback {
|
||||
abstract void incomingRequest();
|
||||
abstract void pairingSuccessful();
|
||||
abstract void pairingFailed(String error);
|
||||
abstract void unpaired();
|
||||
void incomingRequest();
|
||||
void pairingSuccessful();
|
||||
void pairingFailed(String error);
|
||||
void unpaired();
|
||||
}
|
||||
|
||||
private DeviceType deviceType;
|
||||
private PairStatus pairStatus;
|
||||
private ArrayList<PairingCallback> pairingCallback = new ArrayList<PairingCallback>();
|
||||
private final ArrayList<PairingCallback> pairingCallback = new ArrayList<>();
|
||||
private Timer pairingTimer;
|
||||
|
||||
private final ArrayList<BaseLink> links = new ArrayList<BaseLink>();
|
||||
private final HashMap<String, Plugin> plugins = new HashMap<String, Plugin>();
|
||||
private final HashMap<String, Plugin> failedPlugins = new HashMap<String, Plugin>();
|
||||
private final ArrayList<BaseLink> links = new ArrayList<>();
|
||||
private final HashMap<String, Plugin> plugins = new HashMap<>();
|
||||
private final HashMap<String, Plugin> failedPlugins = new HashMap<>();
|
||||
|
||||
private final SharedPreferences settings;
|
||||
|
||||
@@ -156,11 +156,13 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
|
||||
public Drawable getIcon()
|
||||
{
|
||||
int drawableId;
|
||||
switch (deviceType) {
|
||||
case Phone: return context.getResources().getDrawable(R.drawable.ic_device_phone);
|
||||
case Tablet: return context.getResources().getDrawable(R.drawable.ic_device_tablet);
|
||||
default: return context.getResources().getDrawable(R.drawable.ic_device_laptop);
|
||||
case Phone: drawableId = R.drawable.ic_device_phone;
|
||||
case Tablet: drawableId = R.drawable.ic_device_tablet;
|
||||
default: drawableId = R.drawable.ic_device_laptop;
|
||||
}
|
||||
return ContextCompat.getDrawable(context, drawableId);
|
||||
}
|
||||
|
||||
public DeviceType getDeviceType() {
|
||||
@@ -602,7 +604,7 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
boolean useEncryption = (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_PAIR) && isPaired());
|
||||
|
||||
//Make a copy to avoid concurrent modification exception if the original list changes
|
||||
ArrayList<BaseLink> mLinks = new ArrayList<BaseLink>(links);
|
||||
ArrayList<BaseLink> mLinks = new ArrayList<>(links);
|
||||
for (final BaseLink link : mLinks) {
|
||||
if (link == null) continue; //Since we made a copy, maybe somebody destroyed the link in the meanwhile
|
||||
if (useEncryption) {
|
||||
@@ -657,7 +659,7 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
final Plugin plugin = PluginFactory.instantiatePluginForDevice(context, pluginKey, this);
|
||||
if (plugin == null) {
|
||||
Log.e("KDE/addPlugin","could not instantiate plugin: "+pluginKey);
|
||||
failedPlugins.put(pluginKey, plugin);
|
||||
failedPlugins.put(pluginKey, null);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -770,7 +772,7 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
void onPluginsChanged(Device device);
|
||||
}
|
||||
|
||||
private final ArrayList<PluginsChangedListener> pluginsChangedListeners = new ArrayList<PluginsChangedListener>();
|
||||
private final ArrayList<PluginsChangedListener> pluginsChangedListeners = new ArrayList<>();
|
||||
|
||||
public void addPluginsChangedListener(PluginsChangedListener listener) {
|
||||
pluginsChangedListeners.add(listener);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DeviceHelper {
|
||||
//from https://github.com/meetup/android-device-names
|
||||
//Converted to java using:
|
||||
//cat android_models.properties | awk -F'=' '{sub(/ *$/, "", $1)} sub(/^ */, "", $2) { if ($2 != "") print "humanReadableNames.put(\""$1"\",\"" $2 "\");"}'
|
||||
private final static HashMap<String,String> humanReadableNames = new HashMap<String,String>();
|
||||
private final static HashMap<String,String> humanReadableNames = new HashMap<>();
|
||||
static {
|
||||
humanReadableNames.put("5860E","Coolpad Quattro 4G");
|
||||
humanReadableNames.put("831C","HTC One M8");
|
||||
|
||||
@@ -42,11 +42,6 @@ public class FilesHelper {
|
||||
/**
|
||||
* Converts any string into a string that is safe to use as a file name.
|
||||
* The result will only include ascii characters and numbers, and the "-","_", and "." characters.
|
||||
*
|
||||
* @param name
|
||||
* @param dirSeparators
|
||||
* @param maxFileLength
|
||||
* @return
|
||||
*/
|
||||
public static String toFileSystemSafeName(String name, boolean dirSeparators, int maxFileLength) {
|
||||
int size = name.length();
|
||||
|
||||
@@ -61,7 +61,7 @@ public class StorageHelper {
|
||||
*/
|
||||
public static List<StorageInfo> getStorageList() {
|
||||
|
||||
List<StorageInfo> list = new ArrayList<StorageInfo>();
|
||||
List<StorageInfo> list = new ArrayList<>();
|
||||
String def_path = Environment.getExternalStorageDirectory().getPath();
|
||||
boolean def_path_removable = Environment.isExternalStorageRemovable();
|
||||
String def_path_state = Environment.getExternalStorageState();
|
||||
@@ -69,7 +69,7 @@ public class StorageHelper {
|
||||
|| def_path_state.equals(Environment.MEDIA_MOUNTED_READ_ONLY);
|
||||
boolean def_path_readonly = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY);
|
||||
|
||||
HashSet<String> paths = new HashSet<String>();
|
||||
HashSet<String> paths = new HashSet<>();
|
||||
int cur_removable_number = 1;
|
||||
|
||||
if (def_path_available) {
|
||||
@@ -115,7 +115,7 @@ public class StorageHelper {
|
||||
|
||||
//Legacy code for Android < 4.0 that still didn't have /storage
|
||||
|
||||
ArrayList<String> entries = new ArrayList<String>();
|
||||
ArrayList<String> entries = new ArrayList<>();
|
||||
BufferedReader buf_reader = null;
|
||||
try {
|
||||
buf_reader = new BufferedReader(new FileReader("/proc/mounts"));
|
||||
|
||||
@@ -109,7 +109,7 @@ public class NetworkPackage {
|
||||
|
||||
public ArrayList<String> getStringList(String key) {
|
||||
JSONArray jsonArray = mBody.optJSONArray(key);
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
int length = jsonArray.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
try {
|
||||
|
||||
@@ -23,6 +23,7 @@ package org.kde.kdeconnect.Plugins.ClibpoardPlugin;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.widget.Button;
|
||||
|
||||
import org.kde.kdeconnect.NetworkPackage;
|
||||
@@ -41,16 +42,6 @@ public class ClipboardPlugin extends Plugin {
|
||||
return context.getResources().getString(R.string.pref_plugin_clipboard_desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return context.getResources().getDrawable(R.drawable.icon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSettings() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledByDefault() {
|
||||
//Disabled by default due to just one direction sync(incoming clipboard change) in early version of android.
|
||||
@@ -72,7 +63,6 @@ public class ClipboardPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public boolean onPackageReceived(NetworkPackage np) {
|
||||
|
||||
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_CLIPBOARD)) {
|
||||
return false;
|
||||
}
|
||||
@@ -82,11 +72,4 @@ public class ClipboardPlugin extends Plugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertDialog getErrorDialog(Activity deviceActivity) { return null; }
|
||||
|
||||
@Override
|
||||
public Button getInterfaceButton(Activity activity) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,6 @@ import org.kde.kdeconnect.BackgroundService;
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect.NetworkPackage;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class KeyListenerView extends View {
|
||||
|
||||
private String deviceId;
|
||||
@@ -91,7 +89,9 @@ public class KeyListenerView extends View {
|
||||
|
||||
@Override
|
||||
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
||||
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN;
|
||||
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ public class KeyListenerView extends View {
|
||||
@Override
|
||||
public void onServiceStart(BackgroundService service) {
|
||||
Device device = service.getDevice(deviceId);
|
||||
MousePadPlugin mousePadPlugin = (MousePadPlugin) device.getPlugin(MousePadPlugin.class);
|
||||
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||
if (mousePadPlugin == null) return;
|
||||
mousePadPlugin.sendKeyboardPacket(np);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
|
||||
|
||||
KeyListenerView keyListenerView;
|
||||
|
||||
static enum ClickType {
|
||||
enum ClickType {
|
||||
RIGHT, MIDDLE, NONE;
|
||||
static ClickType fromString(String s) {
|
||||
switch(s) {
|
||||
|
||||
@@ -23,6 +23,7 @@ package org.kde.kdeconnect.Plugins.MousePadPlugin;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import org.kde.kdeconnect.NetworkPackage;
|
||||
import org.kde.kdeconnect.Plugins.Plugin;
|
||||
@@ -42,7 +43,7 @@ public class MousePadPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return context.getResources().getDrawable(R.drawable.touchpad_plugin_action);
|
||||
return ContextCompat.getDrawable(context, R.drawable.touchpad_plugin_action);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
@@ -120,7 +121,7 @@ public class MprisActivity extends ActionBarActivity {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
final ArrayList<String> playerList = mpris.getPlayerList();
|
||||
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(MprisActivity.this,
|
||||
final ArrayAdapter<String> adapter = new ArrayAdapter<>(MprisActivity.this,
|
||||
android.R.layout.simple_spinner_item,
|
||||
playerList.toArray(new String[playerList.size()])
|
||||
);
|
||||
@@ -269,7 +270,7 @@ public class MprisActivity extends ActionBarActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
return true;
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
|
||||
import org.kde.kdeconnect.NetworkPackage;
|
||||
@@ -43,10 +44,10 @@ public class MprisPlugin extends Plugin {
|
||||
private long length = -1;
|
||||
private long lastPosition;
|
||||
private long lastPositionTime;
|
||||
private HashMap<String,Handler> playerStatusUpdated = new HashMap<String,Handler>();
|
||||
private HashMap<String,Handler> playerStatusUpdated = new HashMap<>();
|
||||
|
||||
private ArrayList<String> playerList = new ArrayList<String>();
|
||||
private HashMap<String,Handler> playerListUpdated = new HashMap<String,Handler>();
|
||||
private ArrayList<String> playerList = new ArrayList<>();
|
||||
private HashMap<String,Handler> playerListUpdated = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
@@ -60,7 +61,7 @@ public class MprisPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return context.getResources().getDrawable(R.drawable.mpris_plugin_action);
|
||||
return ContextCompat.getDrawable(context, R.drawable.mpris_plugin_action);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -67,8 +67,8 @@ public class NotificationFilterActivity extends ActionBarActivity {
|
||||
res.close();
|
||||
appDatabase.close();
|
||||
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
|
||||
android.R.layout.simple_list_item_multiple_choice,android.R.id.text1, appName);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_list_item_multiple_choice, android.R.id.text1, appName);
|
||||
listView.setAdapter(adapter);
|
||||
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
for (i = 0 ; i < isFiltered.length; i++){
|
||||
|
||||
@@ -37,7 +37,7 @@ public class NotificationReceiver extends NotificationListenerService {
|
||||
void onNotificationRemoved(StatusBarNotification statusBarNotification);
|
||||
}
|
||||
|
||||
private final ArrayList<NotificationListener> listeners = new ArrayList<NotificationListener>();
|
||||
private final ArrayList<NotificationListener> listeners = new ArrayList<>();
|
||||
|
||||
public void addListener(NotificationListener listener) {
|
||||
listeners.add(listener);
|
||||
@@ -71,7 +71,7 @@ public class NotificationReceiver extends NotificationListenerService {
|
||||
void onServiceStart(NotificationReceiver service);
|
||||
}
|
||||
|
||||
private final static ArrayList<InstanceCallback> callbacks = new ArrayList<InstanceCallback>();
|
||||
private final static ArrayList<InstanceCallback> callbacks = new ArrayList<>();
|
||||
|
||||
private final static Lock mutex = new ReentrantLock(true);
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ public class PluginFactory {
|
||||
|
||||
}
|
||||
|
||||
private static final Map<String, Class> availablePlugins = new TreeMap<String, Class>();
|
||||
private static final Map<String, PluginInfo> availablePluginsInfo = new TreeMap<String, PluginInfo>();
|
||||
private static final Map<String, Class> availablePlugins = new TreeMap<>();
|
||||
private static final Map<String, PluginInfo> availablePluginsInfo = new TreeMap<>();
|
||||
|
||||
static {
|
||||
//TODO: Use reflection to find all subclasses of Plugin, instead of adding them manually
|
||||
|
||||
@@ -48,6 +48,7 @@ import java.net.SocketException;
|
||||
import java.security.PublicKey;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
@@ -70,7 +71,7 @@ class SimplePasswordAuthenticator implements PasswordAuthenticator {
|
||||
|
||||
class SimplePublicKeyAuthenticator implements PublickeyAuthenticator {
|
||||
|
||||
private List<PublicKey> keys = new ArrayList<PublicKey>();
|
||||
private final List<PublicKey> keys = new ArrayList<>();
|
||||
|
||||
public void addKey(PublicKey key) {
|
||||
keys.add(key);
|
||||
@@ -111,7 +112,7 @@ class SimpleSftpServer {
|
||||
sshd.setFileSystemFactory(new SecureFileSystemFactory());
|
||||
//sshd.setShellFactory(new ProcessShellFactory(new String[] { "/bin/sh", "-i", "-l" }));
|
||||
sshd.setCommandFactory(new ScpCommandFactory());
|
||||
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
|
||||
sshd.setSubsystemFactories(Collections.singletonList((NamedFactory<Command>)new SftpSubsystem.Factory()));
|
||||
|
||||
sshd.setPasswordAuthenticator(passwordAuth);
|
||||
sshd.setPublickeyAuthenticator(keyAuth);
|
||||
@@ -192,7 +193,6 @@ class SimpleSftpServer {
|
||||
private String currDir = "/";
|
||||
private String rootDir = "/";
|
||||
private String userName;
|
||||
private boolean caseInsensitive = false;
|
||||
//
|
||||
public SecureFileSystemView(final String rootDir, final String userName) {
|
||||
super(userName);
|
||||
@@ -213,18 +213,18 @@ class SimpleSftpServer {
|
||||
//
|
||||
protected SshFile getFile(final String dir, final String file) {
|
||||
// get actual file object
|
||||
final boolean caseInsensitive = false;
|
||||
String physicalName = NativeSshFile.getPhysicalName("/", dir, file, caseInsensitive);
|
||||
File fileObj = new File(rootDir, physicalName); // chroot
|
||||
|
||||
// strip the root directory and return
|
||||
String userFileName = physicalName.substring("/".length() - 1);
|
||||
return new SecureSshFile(this, userFileName, fileObj, userName);
|
||||
return new SecureSshFile(userFileName, fileObj, userName);
|
||||
}
|
||||
}
|
||||
|
||||
class SecureSshFile extends NativeSshFile {
|
||||
//
|
||||
public SecureSshFile(final SecureFileSystemView view, final String fileName, final File file, final String userName) {
|
||||
public SecureSshFile(final String fileName, final File file, final String userName) {
|
||||
super(fileName, file, userName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,8 +76,8 @@ public class SftpPlugin extends Plugin {
|
||||
File root = new File("/");
|
||||
if (root.canExecute() && root.canRead()) {
|
||||
List<StorageHelper.StorageInfo> storageList = StorageHelper.getStorageList();
|
||||
ArrayList<String> paths = new ArrayList<String>();
|
||||
ArrayList<String> pathNames = new ArrayList<String>();
|
||||
ArrayList<String> paths = new ArrayList<>();
|
||||
ArrayList<String> pathNames = new ArrayList<>();
|
||||
|
||||
for (StorageHelper.StorageInfo storage : storageList) {
|
||||
paths.add(storage.path);
|
||||
|
||||
@@ -29,7 +29,6 @@ import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -121,8 +120,8 @@ public class ShareActivity extends ActionBarActivity {
|
||||
public void onServiceStart(final BackgroundService service) {
|
||||
|
||||
Collection<Device> devices = service.getDevices().values();
|
||||
final ArrayList<Device> devicesList = new ArrayList<Device>();
|
||||
final ArrayList<ListAdapter.Item> items = new ArrayList<ListAdapter.Item>();
|
||||
final ArrayList<Device> devicesList = new ArrayList<>();
|
||||
final ArrayList<ListAdapter.Item> items = new ArrayList<>();
|
||||
|
||||
items.add(new SectionItem(getString(R.string.share_to)));
|
||||
|
||||
@@ -155,7 +154,7 @@ public class ShareActivity extends ActionBarActivity {
|
||||
uriList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
|
||||
} else {
|
||||
Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
|
||||
uriList = new ArrayList<Uri>();
|
||||
uriList = new ArrayList<>();
|
||||
uriList.add(uri);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -57,7 +58,7 @@ public class SharePlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return context.getResources().getDrawable(R.drawable.share_plugin_action);
|
||||
return ContextCompat.getDrawable(context, R.drawable.share_plugin_action);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -92,7 +92,7 @@ public class TelephonyPlugin extends Plugin {
|
||||
}
|
||||
};
|
||||
|
||||
public void callBroadcastReceived(int state, String phoneNumber) {
|
||||
private void callBroadcastReceived(int state, String phoneNumber) {
|
||||
|
||||
//Log.e("TelephonyPlugin", "callBroadcastReceived");
|
||||
|
||||
@@ -157,7 +157,7 @@ public class TelephonyPlugin extends Plugin {
|
||||
lastState = state;
|
||||
}
|
||||
|
||||
public void smsBroadcastReceived(SmsMessage message) {
|
||||
private void smsBroadcastReceived(SmsMessage message) {
|
||||
|
||||
//Log.e("SmsBroadcastReceived", message.toString());
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
@@ -54,6 +55,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
|
||||
public void setSupportActionBar(@Nullable Toolbar toolbar) {
|
||||
getDelegate().setSupportActionBar(toolbar);
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
public MenuInflater getMenuInflater() {
|
||||
return getDelegate().getMenuInflater();
|
||||
|
||||
@@ -46,7 +46,7 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
public static final String KEY_CUSTOM_DEVLIST_PREFERENCE = "device_list_preference";
|
||||
private static final String IP_DELIM = ",";
|
||||
|
||||
ArrayList<String> ipAddressList = new ArrayList<String>();
|
||||
private ArrayList<String> ipAddressList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -60,7 +60,7 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
ipEntryBox.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
||||
addNewIp(v);
|
||||
addNewIp();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -70,7 +70,7 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, final int position, final long id) {
|
||||
Log.i(LOG_ID, "Item clicked pos: "+position+" id: "+id);
|
||||
Log.i(LOG_ID, "Item clicked pos: " + position + " id: " + id);
|
||||
// remove touched item after confirmation
|
||||
DialogInterface.OnClickListener confirmationListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@@ -94,7 +94,7 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
((ArrayAdapter)getListAdapter()).notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void addNewIp(View v) {
|
||||
private void addNewIp() {
|
||||
EditText ipEntryBox = (EditText)findViewById(R.id.ip_edittext);
|
||||
String enteredText = ipEntryBox.getText().toString().trim();
|
||||
if (!enteredText.equals("")) {
|
||||
@@ -115,7 +115,7 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
}
|
||||
}
|
||||
|
||||
void saveList() {
|
||||
private void saveList() {
|
||||
// add entry to list and save to preferences (unless empty)
|
||||
String serialized = "";
|
||||
if (!ipAddressList.isEmpty()) {
|
||||
@@ -127,7 +127,7 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
|
||||
}
|
||||
|
||||
static String serializeIpList(ArrayList<String> iplist) {
|
||||
public static String serializeIpList(ArrayList<String> iplist) {
|
||||
String serialized = "";
|
||||
for (String ipaddr : iplist) {
|
||||
serialized += IP_DELIM+ipaddr;
|
||||
@@ -139,7 +139,7 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
}
|
||||
|
||||
public static ArrayList<String> deserializeIpList(String serialized) {
|
||||
ArrayList<String> iplist = new ArrayList<String>();
|
||||
ArrayList<String> iplist = new ArrayList<>();
|
||||
Log.d(LOG_ID, serialized);
|
||||
for (String ipaddr : serialized.split(IP_DELIM)) {
|
||||
iplist.add(ipaddr);
|
||||
@@ -148,7 +148,7 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
return iplist;
|
||||
}
|
||||
|
||||
void initializeDeviceList(Context context){
|
||||
private void initializeDeviceList(Context context){
|
||||
String deviceListPrefs = PreferenceManager.getDefaultSharedPreferences(context).getString(
|
||||
KEY_CUSTOM_DEVLIST_PREFERENCE,
|
||||
"");
|
||||
|
||||
@@ -66,7 +66,7 @@ public class DeviceActivity extends ActionBarActivity {
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
ArrayList<ListAdapter.Item> items = new ArrayList<ListAdapter.Item>();
|
||||
ArrayList<ListAdapter.Item> items = new ArrayList<>();
|
||||
|
||||
if (!device.isReachable()) {
|
||||
//Not reachable, show unpair button
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.ArrayList;
|
||||
public class ListAdapter extends ArrayAdapter<ListAdapter.Item> {
|
||||
|
||||
public interface Item {
|
||||
public View inflateView(LayoutInflater layoutInflater);
|
||||
View inflateView(LayoutInflater layoutInflater);
|
||||
}
|
||||
|
||||
private final ArrayList<Item> items;
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
package org.kde.kdeconnect.UserInterface.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
@@ -50,7 +52,7 @@ public class SmallEntryItem implements ListAdapter.Item {
|
||||
titleView.setText(title);
|
||||
if (clickListener != null) {
|
||||
titleView.setOnClickListener(clickListener);
|
||||
v.setBackgroundDrawable(layoutInflater.getContext().getResources().getDrawable(R.drawable.abc_list_selector_holo_dark));
|
||||
v.setBackgroundDrawable(ContextCompat.getDrawable(layoutInflater.getContext(), R.drawable.abc_list_selector_holo_dark));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,10 +83,10 @@ public class MainActivity extends ActionBarActivity {
|
||||
}).start();
|
||||
break;
|
||||
case R.id.menu_settings:
|
||||
startActivity(new Intent(this,MainSettingsActivity.class));
|
||||
startActivity(new Intent(this, org.kde.kdeconnect.UserInterface.MainSettingsActivity.class));
|
||||
break;
|
||||
case R.id.menu_custom_device_list:
|
||||
startActivity(new Intent(this, CustomDevicesActivity.class));
|
||||
startActivity(new Intent(this, org.kde.kdeconnect.UserInterface.CustomDevicesActivity.class));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -116,7 +116,7 @@ public class MainActivity extends ActionBarActivity {
|
||||
public void onServiceStart(final BackgroundService service) {
|
||||
|
||||
Collection<Device> devices = service.getDevices().values();
|
||||
final ArrayList<ListAdapter.Item> items = new ArrayList<ListAdapter.Item>();
|
||||
final ArrayList<ListAdapter.Item> items = new ArrayList<>();
|
||||
|
||||
SectionItem section;
|
||||
|
||||
|
||||
@@ -115,15 +115,16 @@ public class MainSettingsActivity extends AppCompatPreferenceActivity {
|
||||
* It's safe to call this multiple time because doesn't override any previous value.
|
||||
* @param context the application context
|
||||
*/
|
||||
public static void initializeDeviceName(Context context){
|
||||
public static String initializeDeviceName(Context context){
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
// Could use prefrences.contains but would need to check for empty String anyway.
|
||||
String deviceName = preferences.getString(KEY_DEVICE_NAME_PREFERENCE, "");
|
||||
if (deviceName.isEmpty()){
|
||||
deviceName = DeviceHelper.getDeviceName();
|
||||
Log.i("MainSettingsActivity", "New device name: " + deviceName);
|
||||
preferences.edit().putString(KEY_DEVICE_NAME_PREFERENCE, deviceName).commit();
|
||||
preferences.edit().putString(KEY_DEVICE_NAME_PREFERENCE, deviceName).apply();
|
||||
}
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
|
||||
@@ -60,7 +60,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
final Device device = service.getDevice(deviceId);
|
||||
Set<String> plugins = PluginFactory.getAvailablePlugins();
|
||||
|
||||
final ArrayList<Preference> preferences = new ArrayList<Preference>();
|
||||
final ArrayList<Preference> preferences = new ArrayList<>();
|
||||
for (final String pluginKey : plugins) {
|
||||
|
||||
PluginFactory.PluginInfo info = PluginFactory.getPluginInfo(getBaseContext(), pluginKey);
|
||||
|
||||
@@ -22,18 +22,13 @@ package org.kde.kdeconnect;
|
||||
|
||||
import android.support.v4.util.LongSparseArray;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.util.Log;
|
||||
|
||||
import org.apache.mina.core.service.IoHandler;
|
||||
import org.apache.mina.core.service.IoHandlerAdapter;
|
||||
import org.apache.mina.core.session.IoSession;
|
||||
import org.apache.mina.transport.socket.nio.NioDatagramAcceptor;
|
||||
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
|
||||
import org.kde.kdeconnect.Backends.LanBackend.LanLink;
|
||||
import org.kde.kdeconnect.Backends.LanBackend.LanLinkProvider;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
Reference in New Issue
Block a user